From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) by mx.groups.io with SMTP id smtpd.web10.10838.1623150803216748384 for ; Tue, 08 Jun 2021 04:13:23 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=v2dy92Fy; spf=pass (domain: nuviainc.com, ip: 209.85.128.46, mailfrom: leif@nuviainc.com) Received: by mail-wm1-f46.google.com with SMTP id k5-20020a05600c1c85b02901affeec3ef8so1702713wms.0 for ; Tue, 08 Jun 2021 04:13:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=5updyIJn7MqY9HuB+Qvo/yyBrp7MIVjtSqoaCzk2xCo=; b=v2dy92FyKXeS4IZxv4pUWgAeRCsTs6lkPlXPUo5AkLPCLQKFSqBGO2BvRIlznXUk1l 0CuqblVsydJIdWHqz3/M5cW8ms80XSVK4q4kCsIKQ9vDiMP7s/n7lLkRF5zotX+agq3S 6ojGLTaiOYjaN20Mcqh/r/OTetuyekvN4Q8lrOueHrTcXO/tq4Wz02StALkwlmLgpz1f 1SOO5FahyxBtpPpeKkkFVpAfLbg446qGN8jRdGXI5+XOX4+UWh5S+kcIvP7ONs/1dzwC pLI2jyWOFD+Qu7xopZEIAHp978sDs5GOtIBrJ/kf0lZ5G3AWOk/ovbM/sRA9i5jzTXV8 aFWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=5updyIJn7MqY9HuB+Qvo/yyBrp7MIVjtSqoaCzk2xCo=; b=ahr9Klk8UGzksEGU0hC1cZDYk+Pi5Go57S5N9yHtuCwPnlDoXAiqtnKPjmG0FW0w1Z KQhruGdYyHsgRiBqtrgH7uog5C80OAopjM0/s+2DVRoCXGQ0oZWb3fW9V/m4iuLIrfPs OJn/kIGaKIDSn5JO2BXcBjPSX90iTUv3rlv2C9GbMg6XecLPQX/fKRQIagKisznmseTw ogf9WtKPFgATswOOP0UcpGfLqjERtZ7NIf2kpexr45V+DZchxDcev3ArLMHdPnWYdPPk b+px2PVkpEtrk5F0byrq4tfx3iA5n83OxtbpYgf7V5kxeC8cWDe1pSI4n8zrRCt9z5OW ZqrA== X-Gm-Message-State: AOAM532WISMF35jeUwymWiagdNmWpwqKn11dWUfyiYc3UY9GMA4ohNp/ RVzfG4T90ihYiqa1bYNYprtZng== X-Google-Smtp-Source: ABdhPJwUpILLre29atA2NfT43pL41qvWfds0O7DsCU1pskLPyUN41myz2FX+7WiIbwDv28G4X7ctGQ== X-Received: by 2002:a05:600c:4f10:: with SMTP id l16mr24218wmq.5.1623150801585; Tue, 08 Jun 2021 04:13:21 -0700 (PDT) Return-Path: Received: from leviathan (cpc1-cmbg19-2-0-cust915.5-4.cable.virginm.net. [82.27.183.148]) by smtp.gmail.com with ESMTPSA id i2sm16768493wmo.40.2021.06.08.04.13.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jun 2021 04:13:21 -0700 (PDT) Date: Tue, 8 Jun 2021 12:13:19 +0100 From: "Leif Lindholm" To: Nhi Pham Cc: devel@edk2.groups.io, Vu Nguyen , Thang Nguyen , Chuong Tran , Phong Vo , Michael D Kinney , Ard Biesheuvel , Nate DeSimone Subject: Re: [edk2-platforms][PATCH v2 19/32] AmpereAltraPkg: Add Random Number Generator Support Message-ID: <20210608111319.zyuxb5ewefpwkqpd@leviathan> References: <20210526100724.5359-1-nhi@os.amperecomputing.com> <20210526100724.5359-21-nhi@os.amperecomputing.com> MIME-Version: 1.0 In-Reply-To: <20210526100724.5359-21-nhi@os.amperecomputing.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, May 26, 2021 at 17:07:11 +0700, Nhi Pham wrote: > From: Vu Nguyen > > This change is to produce RNG protocol which is required by several > modules. > > Cc: Thang Nguyen > Cc: Chuong Tran > Cc: Phong Vo > Cc: Leif Lindholm > Cc: Michael D Kinney > Cc: Ard Biesheuvel > Cc: Nate DeSimone > > Signed-off-by: Vu Nguyen > --- > Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc | 5 + > Platform/Ampere/JadePkg/Jade.fdf | 5 + > Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.inf | 43 +++++ > Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.c | 164 ++++++++++++++++++++ > Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.uni | 10 ++ > Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxeExtra.uni | 9 ++ > 6 files changed, 236 insertions(+) > > diff --git a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc > index 33f5fe7af544..930bbb5d385b 100755 > --- a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc > +++ b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dsc.inc > @@ -682,6 +682,11 @@ [Components.common] > MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf > Silicon/Ampere/AmpereAltraPkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf > > + # > + # Random Number Generator Support > + # > + Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.inf > + > # > # Bds > # > diff --git a/Platform/Ampere/JadePkg/Jade.fdf b/Platform/Ampere/JadePkg/Jade.fdf > index 6820a197568b..ef24e6f1f8e0 100755 > --- a/Platform/Ampere/JadePkg/Jade.fdf > +++ b/Platform/Ampere/JadePkg/Jade.fdf > @@ -304,6 +304,11 @@ [FV.FvMain] > # > INF Drivers/ASpeed/ASpeedGopBinPkg/ASpeedAst2500GopDxe.inf > > + # > + # Random Number Generator Support > + # > + INF Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.inf > + > # > # UEFI application (Shell Embedded Boot Loader) > # > diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.inf b/Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.inf > new file mode 100644 > index 000000000000..d3d2c20436a0 > --- /dev/null > +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.inf > @@ -0,0 +1,43 @@ > +## @file > +# > +# Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION = 0x0001001B > + BASE_NAME = RngDxe > + FILE_GUID = 4FCC006E-C740-4027-BC97-787907C8D286 > + MODULE_TYPE = DXE_DRIVER > + VERSION_STRING = 1.0 > + ENTRY_POINT = RngDriverEntry > + MODULE_UNI_FILE = RngDxe.uni > + > +[Sources.common] > + RngDxe.c > + > +[Packages] > + MdePkg/MdePkg.dec > + Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec > + > +[LibraryClasses] > + BaseLib > + DebugLib > + TrngLib > + UefiBootServicesTableLib > + UefiDriverEntryPoint > + UefiLib > + > +[Guids] > + gEfiRngAlgorithmRaw ## SOMETIMES_PRODUCES ## GUID # Unique ID of the algorithm for RNG > + > +[Protocols] > + gEfiRngProtocolGuid ## PRODUCES > + > +[UserExtensions.TianoCore."ExtraFiles"] > + RngDxeExtra.uni > + > +[Depex] > + TRUE > diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.c b/Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.c > new file mode 100644 > index 000000000000..bb8140cfeb2f > --- /dev/null > +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.c > @@ -0,0 +1,164 @@ > +/** @file > + > + Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +/** > + Returns information about the random number generation implementation. > + > + @param[in] This A pointer to the EFI_RNG_PROTOCOL instance. > + @param[in,out] RNGAlgorithmListSize On input, the size in bytes of RNGAlgorithmList. > + On output with a return code of EFI_SUCCESS, the size > + in bytes of the data returned in RNGAlgorithmList. On output > + with a return code of EFI_BUFFER_TOO_SMALL, > + the size of RNGAlgorithmList required to obtain the list. > + @param[out] RNGAlgorithmList A caller-allocated memory buffer filled by the driver > + with one EFI_RNG_ALGORITHM element for each supported > + RNG algorithm. The list must not change across multiple > + calls to the same driver. The first algorithm in the list > + is the default algorithm for the driver. > + > + @retval EFI_SUCCESS The RNG algorithm list was returned successfully. > + @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect. > + @retval EFI_BUFFER_TOO_SMALL The buffer RNGAlgorithmList is too small to hold the result. > + > +**/ > +EFI_STATUS > +EFIAPI > +RngGetInfo ( > + IN EFI_RNG_PROTOCOL *This, > + IN OUT UINTN *RNGAlgorithmListSize, > + OUT EFI_RNG_ALGORITHM *RNGAlgorithmList > + ) > +{ > + if (This == NULL || RNGAlgorithmListSize == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + if (*RNGAlgorithmListSize < sizeof (EFI_RNG_ALGORITHM)) { > + *RNGAlgorithmListSize = sizeof (EFI_RNG_ALGORITHM); > + return EFI_BUFFER_TOO_SMALL; > + } > + > + if (RNGAlgorithmList == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + *RNGAlgorithmListSize = sizeof (EFI_RNG_ALGORITHM); > + CopyGuid (RNGAlgorithmList, &gEfiRngAlgorithmRaw); > + > + return EFI_SUCCESS; > +} > + > +/** > + Produces and returns an RNG value using either the default or specified RNG algorithm. > + > + @param[in] This A pointer to the EFI_RNG_PROTOCOL instance. > + @param[in] RNGAlgorithm A pointer to the EFI_RNG_ALGORITHM that identifies the RNG > + algorithm to use. May be NULL in which case the function will > + use its default RNG algorithm. > + @param[in] RNGValueLength The length in bytes of the memory buffer pointed to by > + RNGValue. The driver shall return exactly this numbers of bytes. > + @param[out] RNGValue A caller-allocated memory buffer filled by the driver with the > + resulting RNG value. > + > + @retval EFI_SUCCESS The RNG value was returned successfully. > + @retval EFI_UNSUPPORTED The algorithm specified by RNGAlgorithm is not supported by > + this driver. > + @retval EFI_DEVICE_ERROR An RNG value could not be retrieved due to a hardware or > + firmware error. > + @retval EFI_INVALID_PARAMETER RNGValue is NULL or RNGValueLength is zero. > + > +**/ > +EFI_STATUS > +EFIAPI > +RngGetRNG ( > + IN EFI_RNG_PROTOCOL *This, > + IN EFI_RNG_ALGORITHM *RNGAlgorithm, OPTIONAL > + IN UINTN RNGValueLength, > + OUT UINT8 *RNGValue > + ) > +{ > + EFI_STATUS Status; > + > + if (This == NULL || RNGValueLength == 0 || RNGValue == NULL) { > + return EFI_INVALID_PARAMETER; > + } > + > + // > + // We only support the raw algorithm, so reject requests for anything else > + // > + if (RNGAlgorithm != NULL && > + !CompareGuid (RNGAlgorithm, &gEfiRngAlgorithmRaw)) > + { { on preceding line. With that: Reviewed-by: Leif Lindholm / Leif > + return EFI_UNSUPPORTED; > + } > + > + Status = GenerateRandomNumbers (RNGValue, RNGValueLength); > + if (EFI_ERROR (Status)) { > + DEBUG (( > + DEBUG_ERROR, > + "%a:%d Failed to generate a random number. \n", > + __FUNCTION__, > + __LINE__ > + )); > + return Status; > + } > + > + return EFI_SUCCESS; > +} > + > +/* > + * The Random Number Generator (RNG) protocol > + */ > +EFI_RNG_PROTOCOL mRng = { > + RngGetInfo, > + RngGetRNG > +}; > + > +/** > + The user Entry Point for the Random Number Generator (RNG) driver. > + > + @param[in] ImageHandle The firmware allocated handle for the EFI image. > + @param[in] SystemTable A pointer to the EFI System Table. > + > + @retval EFI_SUCCESS The entry point is executed successfully. > + @retval EFI_NOT_SUPPORTED Platform does not support RNG. > + @retval Other Some error occurs when executing this entry point. > + > +**/ > +EFI_STATUS > +EFIAPI > +RngDriverEntry ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_SYSTEM_TABLE *SystemTable > + ) > +{ > + EFI_STATUS Status; > + EFI_HANDLE Handle; > + > + // > + // Install UEFI RNG (Random Number Generator) Protocol > + // > + Handle = NULL; > + Status = gBS->InstallMultipleProtocolInterfaces ( > + &Handle, > + &gEfiRngProtocolGuid, > + &mRng, > + NULL > + ); > + > + return Status; > +} > diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.uni b/Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.uni > new file mode 100644 > index 000000000000..cd9dde97a236 > --- /dev/null > +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxe.uni > @@ -0,0 +1,10 @@ > +// > +// Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
> +// > +// SPDX-License-Identifier: BSD-2-Clause-Patent > +// > + > + > +#string STR_MODULE_ABSTRACT #language en-US "Produces UEFI Random Number Generator protocol" > + > +#string STR_MODULE_DESCRIPTION #language en-US "This module will produce UEFI Random Number Generator protocol." > diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxeExtra.uni b/Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxeExtra.uni > new file mode 100644 > index 000000000000..9a3696b25442 > --- /dev/null > +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/RngDxe/RngDxeExtra.uni > @@ -0,0 +1,9 @@ > +// > +// Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
> +// > +// SPDX-License-Identifier: BSD-2-Clause-Patent > +// > + > +#string STR_PROPERTIES_MODULE_NAME > +#language en-US > +"Ampere UEFI Random Number Generator DXE" > -- > 2.17.1 >