From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by mx.groups.io with SMTP id smtpd.web11.555.1619658523548330405 for ; Wed, 28 Apr 2021 18:08:44 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=none, err=permanent DNS error (domain: byosoft.com.cn, ip: 58.240.74.242, mailfrom: gaoliming@byosoft.com.cn) Received: from DESKTOPS6D0PVI ([58.246.60.130]) (envelope-sender ) by 192.168.6.13 with ESMTP for ; Thu, 29 Apr 2021 09:08:36 +0800 X-WM-Sender: gaoliming@byosoft.com.cn X-Originating-IP: 58.246.60.130 X-WM-AuthFlag: YES X-WM-AuthUser: gaoliming@byosoft.com.cn From: "gaoliming" To: "'Rebecca Cran'" , Cc: "'Jiewen Yao'" , "'Jian J Wang'" , "'Michael D Kinney'" , "'Zhiguang Liu'" , "'Ard Biesheuvel'" , "'Sami Mujawar'" References: <20210428204415.25454-1-rebecca@nuviainc.com> <20210428204415.25454-2-rebecca@nuviainc.com> In-Reply-To: <20210428204415.25454-2-rebecca@nuviainc.com> Subject: =?UTF-8?B?5Zue5aSNOiBbUEFUQ0ggMS8zXSBNZGVQa2cvQmFzZUxpYjogQWRkIHN1cHBvcnQgZm9yIEFSTXY4LjUgUk5HIGluc3RydWN0aW9ucw==?= Date: Thu, 29 Apr 2021 09:08:36 +0800 Message-ID: <003d01d73c94$2e7e6260$8b7b2720$@byosoft.com.cn> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQHJWI+mSQVVRLNPL5r2vr3WHcj6eQDoBmFqqt82lIA= Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable Content-Language: zh-cn Rebecca: Can you submit one BZ for this new feature?=20 Thanks Liming > -----=D3=CA=BC=FE=D4=AD=BC=FE----- > =B7=A2=BC=FE=C8=CB: Rebecca Cran > =B7=A2=CB=CD=CA=B1=BC=E4: 2021=C4=EA4=D4=C229=C8=D5 4:44 > =CA=D5=BC=FE=C8=CB: devel@edk2.groups.io > =B3=AD=CB=CD: Rebecca Cran ; Jiewen Yao > ; Jian J Wang ; Michael D > Kinney ; Liming Gao > ; Zhiguang Liu ; Ard > Biesheuvel ; Sami Mujawar > > =D6=F7=CC=E2: [PATCH 1/3] MdePkg/BaseLib: Add support for ARMv8.5 RNG > instructions >=20 > Add support for the optional ARMv8.5 RNDR and RNDRRS instructions that > are a part of FEAT_RNG to BaseLib, and add a function to read the = ISAR0 > register which indicates whether the CPU supports FEAT_RNG. >=20 > Signed-off-by: Rebecca Cran > --- > MdePkg/Library/BaseLib/BaseLib.inf | 4 ++ > MdePkg/Include/Library/BaseLib.h | 47 > +++++++++++++++++ > MdePkg/Library/BaseLib/BaseLibInternals.h | 6 +++ > MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.S | 29 +++++++++++ > MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.asm | 28 ++++++++++ > MdePkg/Library/BaseLib/AArch64/ArmRng.S | 51 > ++++++++++++++++++ > MdePkg/Library/BaseLib/AArch64/ArmRng.asm | 55 > ++++++++++++++++++++ > 7 files changed, 220 insertions(+) >=20 > diff --git a/MdePkg/Library/BaseLib/BaseLib.inf > b/MdePkg/Library/BaseLib/BaseLib.inf > index b76f3af380ea..7f582079d786 100644 > --- a/MdePkg/Library/BaseLib/BaseLib.inf > +++ b/MdePkg/Library/BaseLib/BaseLib.inf > @@ -380,6 +380,8 @@ [Sources.AARCH64] > AArch64/SetJumpLongJump.S | GCC > AArch64/CpuBreakpoint.S | GCC > AArch64/SpeculationBarrier.S | GCC > + AArch64/ArmRng.S | GCC > + AArch64/ArmReadIdIsar0.S | GCC >=20 > AArch64/MemoryFence.asm | MSFT > AArch64/SwitchStack.asm | MSFT > @@ -389,6 +391,8 @@ [Sources.AARCH64] > AArch64/SetJumpLongJump.asm | MSFT > AArch64/CpuBreakpoint.asm | MSFT > AArch64/SpeculationBarrier.asm | MSFT > + AArch64/ArmRng.asm | MSFT > + AArch64/ArmReadIdIsar0.asm | MSFT >=20 > [Sources.RISCV64] > Math64.c > diff --git a/MdePkg/Include/Library/BaseLib.h > b/MdePkg/Include/Library/BaseLib.h > index 7253997a6f8c..60cf559b0849 100644 > --- a/MdePkg/Include/Library/BaseLib.h > +++ b/MdePkg/Include/Library/BaseLib.h > @@ -7519,4 +7519,51 @@ PatchInstructionX86 ( > ); >=20 > #endif // defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) > + > +#if defined (MDE_CPU_AARCH64) > + > +/** > + Reads the ID_AA64ISAR0 Register. > + > + @return The contents of the ID_AA64ISAR0 Register > + > +**/ > +UINT64 > +EFIAPI > +ArmReadIdIsar0 ( > + VOID > + ); > + > +/** > + Generates a random number using the RNDR instruction. > + > + @param[out] The generated random number > + > + @retval TRUE Success: a random number was successfully generated > + @retval FALSE Failure: a random number was unable to be generated > + > +**/ > +BOOLEAN > +EFIAPI > +ArmRndr ( > + OUT UINT64 *Rand > + ); > + > +/** > + Generates a random number using the RNDRRS instruction. > + > + @param[out] The generated random number > + > + @retval TRUE Success: a random number was successfully generated > + @retval FALSE Failure: a random number was unable to be generated > + > +**/ > +BOOLEAN > +EFIAPI > +ArmRndrrs ( > + OUT UINT64 *Rand > + ); > + What usage is for this API ArmRndrrs()? I don't see it is used in = RngLib.=20 Thanks Liming > +#endif // defined (MDE_CPU_AARCH64) > + > #endif // !defined (__BASE_LIB__) > diff --git a/MdePkg/Library/BaseLib/BaseLibInternals.h > b/MdePkg/Library/BaseLib/BaseLibInternals.h > index 6837d67d90cf..4ae79a4e7ab4 100644 > --- a/MdePkg/Library/BaseLib/BaseLibInternals.h > +++ b/MdePkg/Library/BaseLib/BaseLibInternals.h > @@ -862,6 +862,12 @@ InternalX86RdRand64 ( > OUT UINT64 *Rand > ); >=20 > +#elif defined (MDE_CPU_AARCH64) > + > +// RNDR, Random Number > +#define RNDR S3_3_C2_C4_0 > +#define RNDRRS S3_3_C2_C4_1 > + > #else >=20 > #endif > diff --git a/MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.S > b/MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.S > new file mode 100644 > index 000000000000..b31e565c7955 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.S > @@ -0,0 +1,29 @@ > +#-----------------------------------------------------------------------= --- ---- > +# > +# ArmReadIdIsar0() for AArch64 > +# > +# Copyright (c) 2021, NUVIA Inc. All rights reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +#-----------------------------------------------------------------------= --- ---- > + > +.text > +.p2align 2 > +GCC_ASM_EXPORT(ArmReadIdIsar0) > + > +#/** > +# Reads the ID_AA64ISAR0 Register. > +# > +#**/ > +#UINT64 > +#EFIAPI > +#ArmReadIdIsar0 ( > +# VOID > +# ); > +# > +ASM_PFX(ArmReadIdIsar0): > + mrs x0, id_aa64isar0_el1 // Read ID_AA64ISAR0 Register > + ret > + > + > diff --git a/MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.asm > b/MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.asm > new file mode 100644 > index 000000000000..1f1d15626cc2 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/AArch64/ArmReadIdIsar0.asm > @@ -0,0 +1,28 @@ > +;-----------------------------------------------------------------------= --- ---- > +; > +; ArmReadIdIsar0() for AArch64 > +; > +; Copyright (c) 2021, NUVIA Inc. All rights reserved.
> +; > +; SPDX-License-Identifier: BSD-2-Clause-Patent > +; > +;-----------------------------------------------------------------------= --- ---- > + > + EXPORT ArmReadIdIsar0 > + AREA BaseLib_LowLevel, CODE, READONLY > + > +;/** > +; Reads the ID_AA64ISAR0 Register. > +; > +;**/ > +;UINT64 > +;EFIAPI > +;ArmReadIdIsar0 ( > +; VOID > +; ); > +; > +ArmReadIdIsar0 > + mrs x0, id_aa64isar0_el1 // Read ID_AA64ISAR0 Register > + ret > + > + END > diff --git a/MdePkg/Library/BaseLib/AArch64/ArmRng.S > b/MdePkg/Library/BaseLib/AArch64/ArmRng.S > new file mode 100644 > index 000000000000..fc2adb660d21 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/AArch64/ArmRng.S > @@ -0,0 +1,51 @@ > +#-----------------------------------------------------------------------= --- ---- > +# > +# ArmRndr() and ArmRndrrs() for AArch64 > +# > +# Copyright (c) 2021, NUVIA Inc. All rights reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +#-----------------------------------------------------------------------= --- ---- > + > +#include "BaseLibInternals.h" > + > +.text > +.p2align 2 > +GCC_ASM_EXPORT(ArmRndr) > +GCC_ASM_EXPORT(ArmRndrrs) > + > +#/** > +# Generates a random number using RNDR. > +# Returns TRUE on success; FALSE on failure. > +# > +#**/ > +#BOOLEAN > +#EFIAPI > +#ArmRndr ( > +# OUT UINT64 *Rand > +# ); > +# > +ASM_PFX(ArmRndr): > + mrs x1, RNDR > + str x1, [x0] > + cset x0, ne // RNDR sets NZCV to 0b0100 on failure > + ret > + > + > +#/** > +# Generates a random number using RNDRRS > +# Returns TRUE on success; FALSE on failure. > +# > +#**/ > +#BOOLEAN > +#EFIAPI > +#ArmRndrrs ( > +# OUT UINT64 *Rand > +# ); > +# > +ASM_PFX(ArmRndrrs): > + mrs x1, RNDRRS > + str x1, [x0] > + cset x0, ne // RNDRRS sets NZCV to 0b0100 on failure > + ret > diff --git a/MdePkg/Library/BaseLib/AArch64/ArmRng.asm > b/MdePkg/Library/BaseLib/AArch64/ArmRng.asm > new file mode 100644 > index 000000000000..ed8d1a81bdfe > --- /dev/null > +++ b/MdePkg/Library/BaseLib/AArch64/ArmRng.asm > @@ -0,0 +1,55 @@ > +;-----------------------------------------------------------------------= --- ---- > +; > +; ArmRndr() and ArmRndrrs() for AArch64 > +; > +; Copyright (c) 2021, NUVIA Inc. All rights reserved.
> +; > +; SPDX-License-Identifier: BSD-2-Clause-Patent > +; > +;-----------------------------------------------------------------------= --- ---- > + > +#include "BaseLibInternals.h" > + > + EXPORT ArmRndr > + EXPORT ArmRndrrs > + AREA BaseLib_LowLevel, CODE, READONLY > + > + > +;/** > +; Generates a random number using RNDR. > +; Returns TRUE on success; FALSE on failure. > +; > +;**/ > +;BOOLEAN > +;EFIAPI > +;ArmRndr ( > +; OUT UINT64 *Rand > +; ); > +; > +ArmRndr > + mrs x1, RNDR > + str x1, [x0] > + cset x0, ne // RNDR sets NZCV to 0b0100 on failure > + ret > + > + END > + > +;/** > +; Generates a random number using RNDRRS. > +; Returns TRUE on success; FALSE on failure. > +; > +;**/ > +;BOOLEAN > +;EFIAPI > +;ArmRndrrs ( > +; OUT UINT64 *Rand > +; ); > +; > +ArmRndrrs > + mrs x1, RNDRRS > + str x1, [x0] > + cset x0, ne // RNDRRS sets NZCV to 0b0100 on failure > + ret > + > + END > + > -- > 2.26.2