> + #ifdef MDE_CPU_AARCH64
> + // Check FEAT_RNG before advertising PcdCpuRngSupportedAlgorithm.
> + if (ArmHasRngExt ()) {
Usually, we don't prefer use "#ifdef" in a common code.
Instead, the general pattern is to define Architecture specific directory, and
move architecture specific doe there.
Thank you
Yao Jiewen
> -----Original Message-----
> From: [email protected] <[email protected]>
> Sent: Wednesday, June 29, 2022 11:03 PM
> To: [email protected]
> Cc: Sami Mujawar <[email protected]>; Leif Lindholm
> <[email protected]>; Ard Biesheuvel <[email protected]>;
> Rebecca Cran <[email protected]>; Kinney, Michael D
> <[email protected]>; Gao, Liming <[email protected]>; Yao,
> Jiewen <[email protected]>; Wang, Jian J <[email protected]>
> Subject: [PATCH v3 20/21] SecurityPkg/RngDxe: Add Arm support of RngDxe
>
> From: Pierre Gondois <[email protected]>
>
> Bugzilla: 3668 (https://bugzilla.tianocore.org/show_bug.cgi?id=3668)
>
> Add RngDxe support for Arm. This implementation uses the TrngLib
> to support the RawAlgorithm and doens't support the RNDR instruction.
>
> Signed-off-by: Pierre Gondois <[email protected]>
> ---
> SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c | 8 ++++++--
> SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf | 9 ++++++---
> SecurityPkg/SecurityPkg.dsc | 2 +-
> 3 files changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c
> b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c
> index ffa32a29dc6a..4775252d30b6 100644
> --- a/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c
> +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/ArmRngDxe.c
> @@ -22,6 +22,7 @@
>
> **/
>
> +#include <Library/ArmLib.h>
> #include <Library/BaseLib.h>
> #include <Library/BaseMemoryLib.h>
> #include <Library/UefiBootServicesTableLib.h>
> @@ -55,8 +56,9 @@ RngInitAvailableAlgoArray (
> UINT16 MajorRevision;
> UINT16 MinorRevision;
>
> - // Check RngGetBytes() before advertising PcdCpuRngSupportedAlgorithm.
> - if (!EFI_ERROR (RngGetBytes (sizeof (Rand), (UINT8 *)&Rand))) {
> + #ifdef MDE_CPU_AARCH64
> + // Check FEAT_RNG before advertising PcdCpuRngSupportedAlgorithm.
> + if (ArmHasRngExt ()) {
> CopyMem (
> &mAvailableAlgoArray[mAvailableAlgoArrayCount],
> PcdGetPtr (PcdCpuRngSupportedAlgorithm),
> @@ -75,6 +77,8 @@ RngInitAvailableAlgoArray (
> DEBUG_CODE_END ();
> }
>
> + #endif
> +
> // Raw algorithm (Trng)
> if (!EFI_ERROR (GetTrngVersion (&MajorRevision, &MinorRevision))) {
> CopyMem (
> diff --git a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
> b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
> index d2d0ff9ebb98..599a3085102d 100644
> --- a/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
> +++ b/SecurityPkg/RandomNumberGenerator/RngDxe/RngDxe.inf
> @@ -27,7 +27,7 @@ [Defines]
> #
> # The following information is for reference only and not required by the
> build
> tools.
> #
> -# VALID_ARCHITECTURES = IA32 X64 AARCH64
> +# VALID_ARCHITECTURES = IA32 X64 AARCH64 ARM
> #
>
> [Sources.common]
> @@ -40,7 +40,7 @@ [Sources.IA32, Sources.X64]
> Rand/AesCore.c
> Rand/AesCore.h
>
> -[Sources.AARCH64]
> +[Sources.AARCH64, Sources.ARM]
> ArmRngDxe.c
> ArmTrng.c
>
> @@ -49,6 +49,9 @@ [Packages]
> MdePkg/MdePkg.dec
> SecurityPkg/SecurityPkg.dec
>
> +[Packages.AARCH64, Packages.ARM]
> + ArmPkg/ArmPkg.dec
> +
> [LibraryClasses]
> UefiLib
> UefiBootServicesTableLib
> @@ -58,7 +61,7 @@ [LibraryClasses]
> TimerLib
> RngLib
>
> -[LibraryClasses.AARCH64]
> +[LibraryClasses.AARCH64, LibraryClasses.ARM]
> TrngLib
>
> [Guids]
> diff --git a/SecurityPkg/SecurityPkg.dsc b/SecurityPkg/SecurityPkg.dsc
> index 490076542a33..882d639489ea 100644
> --- a/SecurityPkg/SecurityPkg.dsc
> +++ b/SecurityPkg/SecurityPkg.dsc
> @@ -292,7 +292,7 @@ [Components.IA32, Components.X64,
> Components.ARM, Components.AARCH64]
> SecurityPkg/EnrollFromDefaultKeysApp/EnrollFromDefaultKeysApp.inf
>
> SecurityPkg/VariableAuthenticated/SecureBootDefaultKeysDxe/SecureBootDefa
> ultKeysDxe.inf
>
> -[Components.IA32, Components.X64, Components.AARCH64]
> +[Components.IA32, Components.X64, Components.AARCH64,
> Components.ARM]
> #
> # Random Number Generator
> #
> --
> 2.25.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#91632): https://edk2.groups.io/g/devel/message/91632
Mute This Topic: https://groups.io/mt/92066759/21656
Group Owner: [email protected]
Unsubscribe: https://edk2.groups.io/g/devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-