Re: [Patch v2 0/2] Use RngLib instead of TimerLib for OpensslLib
Matthew Carlson
I included a null lib and I was including the wrong version of Rng anyway.
I think that would make sense to split them into two different DSC files. Typo fixed, good spot! -- - Matthew Carlson
|
|
Re: [PATCH v13 45/46] UefiCpuPkg/MpInitLib: Prepare SEV-ES guest APs for OS use
Laszlo Ersek
On 07/31/20 16:47, Tom Lendacky wrote:
On 7/31/20 9:44 AM, Tom Lendacky wrote:I got the separate copy; I'll report back sometime next week.On 7/31/20 8:36 AM, Tom Lendacky wrote:Looking at the formatting, I'm not sure if Thunderbird messed up theOn 7/31/20 7:43 AM, Laszlo Ersek wrote:Hi Laszlo,Hi Tom,Hi Laszlo, Thanks! Laszlo diff --git a/UefiCpuPkg/Library/MpInitLib/DxeMpLib.c
|
|
Re: [PATCH v3 0/3] Use RngLib instead of TimerLib for OpensslLib
Michael D Kinney
Hi Matt,
toggle quoted messageShow quoted text
1) BaseRngLibTimerLib a) The comments incorrectly list delays in ms instead of us. b) Did you consider use of GetPerformanceCounterProperties()? I also do not seen an explanation of the delay values used. (why not smaller or larger values). At a minimum, the file header should state it only works if the rate of the perf counter from TimerLib is much greater than 1MHz. 2) BaseRngLibDxe a) This is not a lib of type Base. I recommend the name DxeRngLibRngProtocol. b) Has a "MU_CHANGE" comment that can be removed c) GenerateRandomNumberViaNist800Algorithm() assigns values in declaration. Init should be moved into statements. d) How would gBS aver be NULL? The INF lists the BootServicesTableLib as a dependency, so the constructer is always run before the services are used. I think these checks can be removed. e) Minor code style issues. if statements should have { as end of line. With the addition of DxeRngLibRngProtocol to MdePkg, I think the CryptoPkg DSC can be updated to use this RngLib instance from the Crypto DXE mododule. Best regards, Mike
-----Original Message-----
|
|
Re: [PATCH 1/1] Add BhyvePkg, to support the bhyve hypervisor
Laszlo Ersek
Hi Sean,
thank you for reporting this. I apologize for the breakage. Please see my comments below. (Rebecca and the stewards should read on as well, please.) On 07/31/20 19:32, Sean Brogan wrote: This patch as committed is breaking CI. It was not captured in PRYup, both Rebecca and myself put the package through CI.  BhyvePkg which is nested inside OvmfPkg ( a violation of DEC spec:Indeed! I've been unaware of this: An EDK II Package (directory) is a directory that contains an EDK IIThank you for teaching me this. This is the first time in my 8-9-ish years with edk2 that I'm participating in the addition of a (not-quite) top-level package. We originally intended BhyvePkg to be stand-alone, but that was not welcomed by many. So we pushed it into OvmfPkg/Bhyve (note: no "Pkg" suffix on the "Bhyve" subdirectory). While doing so, we should have eliminated the separate DEC file. Namely, if we compare both DEC files now: - OvmfPkg/OvmfPkg.dec - OvmfPkg/Bhyve/BhyvePkg.dec there are not many differences (in fact only changes and additions in BhyvePkg.dec matter, removals (= trimming) don't): - some copyright notices, - the BhyveFwCtlLib lib class, - a different default value for PcdDebugIoPort. That's all. So it should not be hard for Rebecca to incorporate these changes into the "main" OvmfPkg/OvmfPkg.dec file. And, the PcdDebugIoPort value change actually belongs in "OvmfPkg/Bhyve/BhyvePkgX64.dsc". Furthermore, the new Bhyve DEC file -- which should be removed -- is referenced in the following INF files only: - Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf - Bhyve/BhyveRfbDxe/BhyveRfbDxe.inf - Bhyve/Library/BhyveFwCtlLib/BhyveFwCtlLib.inf Those INF files should be re-pointed to the main OvmfPkg.dec file. 4) does not support CI so it is not tested but now that it is in theBoth the individual errors and the nested package situation (which indeed violates the DEC spec) should hopefully be resolved by the suggestions above. Regarding actual actions: I'm going to be away for a short while now. Plus, I'm not entirely sure what exactly is being prevented by the current state of the tree (i.e., how grave the regression is). (1) If the current issue interferes with work on, and usability of, other packages (that is, anything *not* OvmfPkg), then I would request that one of the stewards please revert 656419f922c0 ("Add BhyvePkg, to support the bhyve hypervisor", 2020-07-31). For such a revert, please add at once: Acked-by: Laszlo Ersek <lersek@...> This is because the IRL stuff I've got queued up does not allow me to participate in the revert, urgently, either from the reviewer side, or even from the submitter side. (I wouldn't like to simply push a revert without formal review, and I don't have time to *post* the revert urgently). I was about to disappear for a bit, and logged back in only because I snuck a peek on the mailing list archive, and noticed the problem report. After the revert, Rebecca and I can collaborate on the next version of the patch (I can review that incrementally against the one being reverted under this option). (2) If, on the other hand, the current issue is restricted to OvmfPkg (and even OvmfPkg platforms other than bhyve can be built), then I'd like to ask that we keep commit 656419f922c0, and that Rebecca please submit an incremental fix (per the above suggestions, assuming they work). ... Upon re-reading your comment "causing the other packages to fail", I think we have case (1); if that's right, then please proceed accordingly. Thank you, and again I apologize for the mess. :( Laszlo
|
|
Re: [Patch v2 0/2] Use RngLib instead of TimerLib for OpensslLib
Michael D Kinney
Hi Matt,  I know you can use the Null lib and have the module be function. The Package DSC is for build verification. Does not have to be functional. We already have examples in the Security using a Null BaseCryptLib to improve build verification performance, but of course those security modules as built would not run.  I know one goal is to build functional binaries from the CryptoPkg. Perhaps that should be a different DSC file?  The typo is True -> TRUE and False -> FALSE  Mike Â
From: macarl via [] <macarl=microsoft.com@[]>
Sent: Friday, July 31, 2020 1:16 PM To: Kinney, Michael D <michael.d.kinney@...>; devel@edk2.groups.io Subject: Re: [edk2-devel] [Patch v2 0/2] Use RngLib instead of TimerLib for OpensslLib  Hey Mike!    Calls RandomNumber64 to fill    a buffer of arbitrary size with random bytes. Â
  @param[in]   Length        Size of the buffer, in bytes,  to fill with.    @param[out]  RandBuffer    Pointer to the buffer to store the random result. Â
  @retval True        Random bytes generation succeeded.    @retval False       Failed to request random bytes.   --
|
|
Re: [PATCH 1/1] Add BhyvePkg, to support the bhyve hypervisor
Rebecca Cran
On 7/31/20 11:32 AM, Sean Brogan wrote:
This patch as committed is breaking CI. It was not captured in PR because the PR optimizes to detect packages impacted by the commits and the BhyvePkg addition is not depended on by other packages (that are in CI). BhyvePkg which is nested inside OvmfPkg ( a violation of DEC spec:  see https://edk2-docs.gitbook.io/edk-ii-dec-specification/2_dec_file_overview paragraph 4) does not support CI so it is not tested but now that it is in the edk2 tree it is causing the other packages to fail. Sorry. I've replicated the errors locally, and will see if I can work around them. -- Rebecca Cran
|
|
[PATCH v3 3/3] MdePkg: BaseRngLibDxe: Add RngLib that uses RngDxe
Matthew Carlson
From: Matthew Carlson <macarl@...>
Cc: Michael D Kinney <michael.d.kinney@...> Cc: Liming Gao <liming.gao@...> Cc: Zhiguang Liu <zhiguang.liu@...> Signed-off-by: Matthew Carlson <matthewfcarlson@...> --- MdePkg/Library/BaseRngLibDxe/RngDxeLib.c | 216 ++++++++++++++++++++ MdePkg/Library/BaseRngLibDxe/BaseRngLibDxe.inf | 38 ++++ MdePkg/MdePkg.dsc | 4 +- 3 files changed, 257 insertions(+), 1 deletion(-) diff --git a/MdePkg/Library/BaseRngLibDxe/RngDxeLib.c b/MdePkg/Library/Base= RngLibDxe/RngDxeLib.c new file mode 100644 index 000000000000..45bd6bad8f7a --- /dev/null +++ b/MdePkg/Library/BaseRngLibDxe/RngDxeLib.c @@ -0,0 +1,216 @@ +/** @file=0D + Provides an implementation of the library class RngLib that uses the Rng = protocol.=0D +=0D +Copyright (c) Microsoft Corporation. All rights reserved.=0D +SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +MU_CHANGE: New file=0D +=0D +**/=0D +#include <Uefi.h>=0D +#include <Library/UefiBootServicesTableLib.h>=0D +#include <Library/DebugLib.h>=0D +#include <Library/RngLib.h>=0D +#include <Protocol/Rng.h>=0D +=0D +/**=0D +Routine Description:=0D +=0D + Generates a random number via the NIST=0D + 800-9A algorithm. Refer to=0D + http://csrc.nist.gov/groups/STM/cavp/documents/drbg/DRBGVS.pdf=0D + for more information.=0D +=0D + Arguments:=0D +=0D + Buffer -- Buffer to receive the random number.=0D + BufferSize -- Number of bytes in Buffer.=0D +=0D +Return Value:=0D +=0D + EFI_SUCCESS or underlying failure code.=0D +=0D +**/=0D +EFI_STATUS=0D +EFIAPI=0D +GenerateRandomNumberViaNist800Algorithm(=0D + OUT UINT8* Buffer,=0D + IN UINTN BufferSize=0D + )=0D +{=0D + EFI_STATUS Status =3D EFI_SUCCESS;=0D + EFI_RNG_PROTOCOL* RngProtocol =3D NULL;=0D +=0D + if (Buffer =3D=3D NULL)=0D + {=0D + DEBUG((DEBUG_ERROR, "[%a] Buffer =3D=3D NULL.\n", __FUNCTION__));=0D + return EFI_INVALID_PARAMETER;=0D + }=0D +=0D + if (gBS =3D=3D NULL)=0D + {=0D + DEBUG((DEBUG_ERROR, "[%a] GenerateRandomNumber, gBS =3D=3D NULL. Ca= lled too soon.\n", __FUNCTION__));=0D + return EFI_LOAD_ERROR;=0D + }=0D +=0D + Status =3D gBS->LocateProtocol(&gEfiRngProtocolGuid, NULL, (VOID **)&Rng= Protocol);=0D + if (EFI_ERROR(Status) || RngProtocol =3D=3D NULL)=0D + {=0D + DEBUG((DEBUG_ERROR, "[%a] Could not locate RNG prototocol, Status = =3D %r\n", __FUNCTION__, Status));=0D + return Status;=0D + }=0D +=0D + Status =3D RngProtocol->GetRNG(RngProtocol, &gEfiRngAlgorithmSp80090Ctr2= 56Guid, BufferSize, Buffer);=0D + DEBUG((DEBUG_INFO, "[%a] GetRNG algorithm CTR-256 - Status =3D %r\n", __= FUNCTION__, Status));=0D + if(!EFI_ERROR(Status))=0D + {=0D + return Status;=0D + }=0D +=0D + Status =3D RngProtocol->GetRNG(RngProtocol, &gEfiRngAlgorithmSp80090Hmac= 256Guid, BufferSize, Buffer);=0D + DEBUG((DEBUG_INFO, "[%a] GetRNG algorithm HMAC-256 - Status =3D %r\n", _= _FUNCTION__, Status));=0D + if(!EFI_ERROR(Status))=0D + {=0D + return Status;=0D + }=0D +=0D + Status =3D RngProtocol->GetRNG(RngProtocol, &gEfiRngAlgorithmSp80090Hash= 256Guid, BufferSize, Buffer);=0D + DEBUG((DEBUG_INFO, "[%a] GetRNG algorithm Hash-256 - Status =3D %r\n", _= _FUNCTION__, Status));=0D + if(!EFI_ERROR(Status))=0D + {=0D + return Status;=0D + }=0D + // If we get to this point, we have failed=0D + DEBUG((DEBUG_ERROR, "[%a] GetRNG() failed, staus =3D %r\n", __FUNCTION__= , Status));=0D +=0D + return Status;=0D +}// GenerateRandomNumberViaNist800Algorithm()=0D +=0D +=0D +/**=0D + Generates a 16-bit random number.=0D +=0D + if Rand is NULL, return FALSE.=0D +=0D + @param[out] Rand Buffer pointer to store the 16-bit random value.=0D +=0D + @retval TRUE Random number generated successfully.=0D + @retval FALSE Failed to generate the random number.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +GetRandomNumber16 (=0D + OUT UINT16 *Rand=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + if (Rand =3D=3D NULL)=0D + {=0D + return FALSE;=0D + }=0D +=0D + Status =3D GenerateRandomNumberViaNist800Algorithm ((UINT8 *)Rand, 2);=0D + if (EFI_ERROR(Status))=0D + {=0D + return FALSE;=0D + }=0D + return TRUE;=0D +}=0D +=0D +/**=0D + Generates a 32-bit random number.=0D +=0D + if Rand is NULL, return FALSE.=0D +=0D + @param[out] Rand Buffer pointer to store the 32-bit random value.=0D +=0D + @retval TRUE Random number generated successfully.=0D + @retval FALSE Failed to generate the random number.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +GetRandomNumber32 (=0D + OUT UINT32 *Rand=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + if (Rand =3D=3D NULL)=0D + {=0D + return FALSE;=0D + }=0D +=0D + Status =3D GenerateRandomNumberViaNist800Algorithm ((UINT8 *)Rand, 4);=0D + if (EFI_ERROR(Status))=0D + {=0D + return FALSE;=0D + }=0D + return TRUE;=0D +}=0D +=0D +/**=0D + Generates a 64-bit random number.=0D +=0D + if Rand is NULL, return FALSE.=0D +=0D + @param[out] Rand Buffer pointer to store the 64-bit random value.=0D +=0D + @retval TRUE Random number generated successfully.=0D + @retval FALSE Failed to generate the random number.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +GetRandomNumber64 (=0D + OUT UINT64 *Rand=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + if (Rand =3D=3D NULL)=0D + {=0D + return FALSE;=0D + }=0D +=0D + Status =3D GenerateRandomNumberViaNist800Algorithm ((UINT8 *)Rand, 8);=0D + if (EFI_ERROR(Status))=0D + {=0D + return FALSE;=0D + }=0D + return TRUE;=0D +}=0D +=0D +/**=0D + Generates a 128-bit random number.=0D +=0D + if Rand is NULL, return FALSE.=0D +=0D + @param[out] Rand Buffer pointer to store the 128-bit random value.=0D +=0D + @retval TRUE Random number generated successfully.=0D + @retval FALSE Failed to generate the random number.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +GetRandomNumber128 (=0D + OUT UINT64 *Rand=0D + )=0D +{=0D + EFI_STATUS Status;=0D +=0D + if (Rand =3D=3D NULL)=0D + {=0D + return FALSE;=0D + }=0D +=0D + Status =3D GenerateRandomNumberViaNist800Algorithm ((UINT8 *)Rand, 16);= =0D + if (EFI_ERROR(Status))=0D + {=0D + return FALSE;=0D + }=0D + return TRUE;=0D +}=0D diff --git a/MdePkg/Library/BaseRngLibDxe/BaseRngLibDxe.inf b/MdePkg/Librar= y/BaseRngLibDxe/BaseRngLibDxe.inf new file mode 100644 index 000000000000..819a106b1376 --- /dev/null +++ b/MdePkg/Library/BaseRngLibDxe/BaseRngLibDxe.inf @@ -0,0 +1,38 @@ +# @file=0D +# Provides implementation of the library class RngLib that uses the RngPro= tocol=0D +#=0D +# @copyright=0D +# Copyright (c) Microsoft Corporation. All rights reserved.=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +# MU_CHANGE: New file=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010017=0D + BASE_NAME =3D BaseRngLibDxe=0D + FILE_GUID =3D FF9F84C5-A33E-44E3-9BB5-0D654B2D4149=0D + MODULE_TYPE =3D DXE_DRIVER=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D RngLib|DXE_DRIVER UEFI_APPLICATION UEFI_DRIVER=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D +=0D +[Sources]=0D + RngDxeLib.c=0D +=0D +[LibraryClasses]=0D + DebugLib=0D + UefiBootServicesTableLib=0D +=0D +[Protocols]=0D + gEfiRngProtocolGuid ## CONSUMES=0D +=0D +[Depex]=0D + gEfiRngProtocolGuid=0D +=0D +[Guids]=0D + gEfiRngAlgorithmSp80090Ctr256Guid ## CONSUMES=0D + gEfiRngAlgorithmSp80090Hash256Guid ## CONSUMES=0D + gEfiRngAlgorithmSp80090Hmac256Guid ## CONSUMES=0D diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index d7ba3a730909..837a0047400e 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -62,8 +62,10 @@ MdePkg/Library/BasePostCodeLibPort80/BasePostCodeLibPort80.inf=0D MdePkg/Library/BasePrintLib/BasePrintLib.inf=0D MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.i= nf=0D - MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf=0D + MdePkg/Library/BaseRngLibDxe/BaseRngLibDxe.inf=0D MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf=0D + MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf=0D +=0D MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf=0D MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf=0D MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf=0D --=20 2.27.0.windows.1
|
|
[PATCH v3 2/3] MdePkg: TimerRngLib: Added RngLib that uses TimerLib
Matthew Carlson
From: Matthew Carlson <macarl@...>
Added a new RngLib that provides random numbers from the TimerLib using the performance counter. This is meant to be used for OpenSSL to replicate past behavior. This should not be used in production as a real source of entropy. Cc: Michael D Kinney <michael.d.kinney@...> Cc: Liming Gao <liming.gao@...> Cc: Zhiguang Liu <zhiguang.liu@...> Signed-off-by: Matthew Carlson <matthewfcarlson@...> --- MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c | 154 +++++++++++= +++++++++ MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf | 38 +++++ MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.uni | 17 +++ MdePkg/MdePkg.dsc | 3 +- 4 files changed, 211 insertions(+), 1 deletion(-) diff --git a/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c b/MdePkg/Libra= ry/BaseRngLibTimerLib/RngLibTimer.c new file mode 100644 index 000000000000..8244a740555c --- /dev/null +++ b/MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c @@ -0,0 +1,154 @@ +/** @file=0D + BaseRng Library that uses the TimerLib to provide reasonably random numb= ers.=0D + Do not use this on a production system.=0D +=0D + Copyright (c) Microsoft Corporation.=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#include <Base.h>=0D +#include <Library/BaseLib.h>=0D +#include <Library/DebugLib.h>=0D +#include <Library/TimerLib.h>=0D +=0D +=0D +/**=0D + Generates a 16-bit random number.=0D +=0D + if Rand is NULL, then ASSERT().=0D +=0D + @param[out] Rand Buffer pointer to store the 16-bit random value.=0D +=0D + @retval TRUE Random number generated successfully.=0D + @retval FALSE Failed to generate the random number.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +GetRandomNumber16 (=0D + OUT UINT16 *Rand=0D + )=0D +{=0D + UINT32 Index;=0D + UINT8* RandPtr;=0D +=0D + ASSERT (Rand !=3D NULL);=0D +=0D + if (NULL =3D=3D Rand) {=0D + return FALSE;=0D + }=0D +=0D + RandPtr =3D (UINT8 *) Rand;=0D + // Get 2 bytes of random ish data=0D + // This should take around 10ms=0D + for (Index =3D 0; Index < 2; Index ++) {=0D + *RandPtr =3D (UINT8) (GetPerformanceCounter () & 0xFF);=0D + MicroSecondDelay (5); // delay to give chance for performance counter = to catch up=0D + RandPtr++;=0D + }=0D + return TRUE;=0D +}=0D +=0D +/**=0D + Generates a 32-bit random number.=0D +=0D + if Rand is NULL, then ASSERT().=0D +=0D + @param[out] Rand Buffer pointer to store the 32-bit random value.=0D +=0D + @retval TRUE Random number generated successfully.=0D + @retval FALSE Failed to generate the random number.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +GetRandomNumber32 (=0D + OUT UINT32 *Rand=0D + )=0D +{=0D + UINT32 Index;=0D + UINT8* RandPtr;=0D +=0D + ASSERT (Rand !=3D NULL);=0D +=0D + if (NULL =3D=3D Rand) {=0D + return FALSE;=0D + }=0D +=0D + RandPtr =3D (UINT8 *) Rand;=0D + // Get 4 bytes of random ish data=0D + // This should take around 20ms=0D + for (Index =3D 0; Index < 4; Index ++) {=0D + *RandPtr =3D (UINT8) (GetPerformanceCounter () & 0xFF);=0D + MicroSecondDelay (5); // delay to give chance for performance counter = to catch up=0D + RandPtr++;=0D + }=0D + return TRUE;=0D +}=0D +=0D +/**=0D + Generates a 64-bit random number.=0D +=0D + if Rand is NULL, then ASSERT().=0D +=0D + @param[out] Rand Buffer pointer to store the 64-bit random value.=0D +=0D + @retval TRUE Random number generated successfully.=0D + @retval FALSE Failed to generate the random number.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +GetRandomNumber64 (=0D + OUT UINT64 *Rand=0D + )=0D +{=0D + UINT32 Index;=0D + UINT8* RandPtr;=0D +=0D + ASSERT (Rand !=3D NULL);=0D +=0D + if (NULL =3D=3D Rand) {=0D + return FALSE;=0D + }=0D +=0D + RandPtr =3D (UINT8 *) Rand;=0D + // Get 8 bytes of random ish data=0D + // This should take around 40ms=0D + for (Index =3D 0; Index < 8; Index ++) {=0D + *RandPtr =3D (UINT8) (GetPerformanceCounter () & 0xFF);=0D + MicroSecondDelay (5); // delay to give chance for performance counter = to catch up=0D + RandPtr++;=0D + }=0D +=0D + return TRUE;=0D +}=0D +=0D +/**=0D + Generates a 128-bit random number.=0D +=0D + if Rand is NULL, then ASSERT().=0D +=0D + @param[out] Rand Buffer pointer to store the 128-bit random value.=0D +=0D + @retval TRUE Random number generated successfully.=0D + @retval FALSE Failed to generate the random number.=0D +=0D +**/=0D +BOOLEAN=0D +EFIAPI=0D +GetRandomNumber128 (=0D + OUT UINT64 *Rand=0D + )=0D +{=0D + ASSERT (Rand !=3D NULL);=0D + // This should take around 80ms=0D +=0D + // Read first 64 bits=0D + if (!GetRandomNumber64 (Rand)) {=0D + return FALSE;=0D + }=0D +=0D + // Read second 64 bits=0D + return GetRandomNumber64 (++Rand);=0D +}=0D diff --git a/MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf b/Mde= Pkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf new file mode 100644 index 000000000000..0d20fd13c1da --- /dev/null +++ b/MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf @@ -0,0 +1,38 @@ +## @file=0D +# Instance of RNG (Random Number Generator) Library.=0D +#=0D +# BaseRng Library that uses the TimerLib to provide reasonably random num= bers.=0D +# Do not use this on a production system as this uses the system performa= nce=0D +# counter rather than a true source of random in addition to have a weak = random=0D +# algorithm.=0D +#=0D +# Copyright (c) Microsoft Corporation. All rights reserved.<BR>=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D BaseRngLibTimerLib=0D + MODULE_UNI_FILE =3D BaseRngLibTimerLib.uni=0D + FILE_GUID =3D 74950C45-10FC-4AB5-B114-49C87C17409B= =0D + MODULE_TYPE =3D BASE=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D RngLib=0D + CONSTRUCTOR =3D BaseRngLibConstructor=0D +=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64=0D +#=0D +=0D +[Sources]=0D + RngLibTimer.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D +=0D +[LibraryClasses]=0D + BaseLib=0D + TimerLib=0D diff --git a/MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.uni b/Mde= Pkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.uni new file mode 100644 index 000000000000..766a8e0ddf97 --- /dev/null +++ b/MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.uni @@ -0,0 +1,17 @@ +// /** @file=0D +// Instance of RNG (Random Number Generator) Library.=0D +//=0D +// BaseRng Library that uses TimerLib's performance counter=0D +// to provide random numbers.=0D +//=0D +// Copyright (c) Microsoft Corporation=0D +//=0D +// SPDX-License-Identifier: BSD-2-Clause-Patent=0D +//=0D +// **/=0D +=0D +=0D +#string STR_MODULE_ABSTRACT #language en-US "Instance of RNG L= ibrary"=0D +=0D +#string STR_MODULE_DESCRIPTION #language en-US "BaseRng Library t= hat uses the TimerLib to provide low-entropy random numbers"=0D +=0D diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index 472fa3777412..d7ba3a730909 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -62,6 +62,8 @@ MdePkg/Library/BasePostCodeLibPort80/BasePostCodeLibPort80.inf=0D MdePkg/Library/BasePrintLib/BasePrintLib.inf=0D MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.i= nf=0D + MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf=0D + MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf=0D MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf=0D MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf=0D MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf=0D @@ -69,7 +71,6 @@ MdePkg/Library/BaseUefiDecompressLib/BaseUefiTianoCustomDecompressLib.in= f=0D MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf=0D MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf=0D - MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf=0D =0D MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf=0D MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf=0D --=20 2.27.0.windows.1
|
|
[PATCH v3 1/3] CryptoPkg: OpensslLib: Use RngLib to generate entropy in rand_pool
Matthew Carlson
From: Matthew Carlson <macarl@...>
Changes OpenSSL to no longer depend on TimerLib and instead use RngLib. This allows platforms to decide for themsevles what sort of entropy source they provide to OpenSSL and TlsLib. Cc: Jiewen Yao <jiewen.yao@...> Cc: Jian J Wang <jian.j.wang@...> Cc: Xiaoyu Lu <xiaoyux.lu@...> Signed-off-by: Matthew Carlson <matthewfcarlson@...> --- CryptoPkg/Library/OpensslLib/rand_pool.c | 203 ++---------------= --- CryptoPkg/Library/OpensslLib/rand_pool_noise.c | 29 --- CryptoPkg/Library/OpensslLib/rand_pool_noise_tsc.c | 43 ----- CryptoPkg/CryptoPkg.dsc | 1 + CryptoPkg/Library/OpensslLib/OpensslLib.inf | 15 +- CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf | 15 +- CryptoPkg/Library/OpensslLib/rand_pool_noise.h | 29 --- 7 files changed, 22 insertions(+), 313 deletions(-) diff --git a/CryptoPkg/Library/OpensslLib/rand_pool.c b/CryptoPkg/Library/O= pensslLib/rand_pool.c index 9e0179b03490..b3ff03b2aa13 100644 --- a/CryptoPkg/Library/OpensslLib/rand_pool.c +++ b/CryptoPkg/Library/OpensslLib/rand_pool.c @@ -11,53 +11,18 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <openssl/aes.h>=0D =0D #include <Uefi.h>=0D -#include <Library/TimerLib.h>=0D -=0D -#include "rand_pool_noise.h"=0D -=0D -/**=0D - Get some randomness from low-order bits of GetPerformanceCounter results= .=0D - And combine them to the 64-bit value=0D -=0D - @param[out] Rand Buffer pointer to store the 64-bit random value.=0D -=0D - @retval TRUE Random number generated successfully.=0D - @retval FALSE Failed to generate.=0D -**/=0D -STATIC=0D -BOOLEAN=0D -EFIAPI=0D -GetRandNoise64FromPerformanceCounter(=0D - OUT UINT64 *Rand=0D - )=0D -{=0D - UINT32 Index;=0D - UINT32 *RandPtr;=0D -=0D - if (NULL =3D=3D Rand) {=0D - return FALSE;=0D - }=0D -=0D - RandPtr =3D (UINT32 *) Rand;=0D -=0D - for (Index =3D 0; Index < 2; Index ++) {=0D - *RandPtr =3D (UINT32) (GetPerformanceCounter () & 0xFF);=0D - MicroSecondDelay (10);=0D - RandPtr++;=0D - }=0D -=0D - return TRUE;=0D -}=0D +#include <Library/RngLib.h>=0D =0D /**=0D Calls RandomNumber64 to fill=0D a buffer of arbitrary size with random bytes.=0D + This is a shim layer to RngLib.=0D =0D @param[in] Length Size of the buffer, in bytes, to fill with.= =0D @param[out] RandBuffer Pointer to the buffer to store the random res= ult.=0D =0D - @retval EFI_SUCCESS Random bytes generation succeeded.=0D - @retval EFI_NOT_READY Failed to request random bytes.=0D + @retval True Random bytes generation succeeded.=0D + @retval False Failed to request random bytes.=0D =0D **/=0D STATIC=0D @@ -73,17 +38,17 @@ RandGetBytes ( =0D Ret =3D FALSE;=0D =0D + if (RandBuffer =3D=3D NULL) {=0D + DEBUG((DEBUG_ERROR, "[OPENSSL_RAND_POOL] NULL RandBuffer. No random nu= mbers are generated and your system is not secure\n"));=0D + ASSERT(FALSE); // Since we can't generate random numbers, we should as= sert. Otherwise we will just blow up later.=0D + return Ret;=0D + }=0D +=0D +=0D while (Length > 0) {=0D - //=0D - // Get random noise from platform.=0D - // If it failed, fallback to PerformanceCounter=0D - // If you really care about security, you must override=0D - // GetRandomNoise64FromPlatform.=0D - //=0D - Ret =3D GetRandomNoise64 (&TempRand);=0D - if (Ret =3D=3D FALSE) {=0D - Ret =3D GetRandNoise64FromPerformanceCounter (&TempRand);=0D - }=0D + // Use RngLib to get random number=0D + Ret =3D GetRandomNumber64(&TempRand);=0D +=0D if (!Ret) {=0D return Ret;=0D }=0D @@ -100,125 +65,6 @@ RandGetBytes ( return Ret;=0D }=0D =0D -/**=0D - Creates a 128bit random value that is fully forward and backward predict= ion resistant,=0D - suitable for seeding a NIST SP800-90 Compliant.=0D - This function takes multiple random numbers from PerformanceCounter to e= nsure reseeding=0D - and performs AES-CBC-MAC over the data to compute the seed value.=0D -=0D - @param[out] SeedBuffer Pointer to a 128bit buffer to store the rando= m seed.=0D -=0D - @retval TRUE Random seed generation succeeded.=0D - @retval FALSE Failed to request random bytes.=0D -=0D -**/=0D -STATIC=0D -BOOLEAN=0D -EFIAPI=0D -RandGetSeed128 (=0D - OUT UINT8 *SeedBuffer=0D - )=0D -{=0D - BOOLEAN Ret;=0D - UINT8 RandByte[16];=0D - UINT8 Key[16];=0D - UINT8 Ffv[16];=0D - UINT8 Xored[16];=0D - UINT32 Index;=0D - UINT32 Index2;=0D - AES_KEY AESKey;=0D -=0D - //=0D - // Chose an arbitrary key and zero the feed_forward_value (FFV)=0D - //=0D - for (Index =3D 0; Index < 16; Index++) {=0D - Key[Index] =3D (UINT8) Index;=0D - Ffv[Index] =3D 0;=0D - }=0D -=0D - AES_set_encrypt_key (Key, 16 * 8, &AESKey);=0D -=0D - //=0D - // Perform CBC_MAC over 32 * 128 bit values, with 10us gaps between 128 = bit value=0D - // The 10us gaps will ensure multiple reseeds within the system time wit= h a large=0D - // design margin.=0D - //=0D - for (Index =3D 0; Index < 32; Index++) {=0D - MicroSecondDelay (10);=0D - Ret =3D RandGetBytes (16, RandByte);=0D - if (!Ret) {=0D - return Ret;=0D - }=0D -=0D - //=0D - // Perform XOR operations on two 128-bit value.=0D - //=0D - for (Index2 =3D 0; Index2 < 16; Index2++) {=0D - Xored[Index2] =3D RandByte[Index2] ^ Ffv[Index2];=0D - }=0D -=0D - AES_encrypt (Xored, Ffv, &AESKey);=0D - }=0D -=0D - for (Index =3D 0; Index < 16; Index++) {=0D - SeedBuffer[Index] =3D Ffv[Index];=0D - }=0D -=0D - return Ret;=0D -}=0D -=0D -/**=0D - Generate high-quality entropy source.=0D -=0D - @param[in] Length Size of the buffer, in bytes, to fill with.=0D - @param[out] Entropy Pointer to the buffer to store the entropy da= ta.=0D -=0D - @retval EFI_SUCCESS Entropy generation succeeded.=0D - @retval EFI_NOT_READY Failed to request random data.=0D -=0D -**/=0D -STATIC=0D -BOOLEAN=0D -EFIAPI=0D -RandGenerateEntropy (=0D - IN UINTN Length,=0D - OUT UINT8 *Entropy=0D - )=0D -{=0D - BOOLEAN Ret;=0D - UINTN BlockCount;=0D - UINT8 Seed[16];=0D - UINT8 *Ptr;=0D -=0D - BlockCount =3D Length / 16;=0D - Ptr =3D (UINT8 *) Entropy;=0D -=0D - //=0D - // Generate high-quality seed for DRBG Entropy=0D - //=0D - while (BlockCount > 0) {=0D - Ret =3D RandGetSeed128 (Seed);=0D - if (!Ret) {=0D - return Ret;=0D - }=0D - CopyMem (Ptr, Seed, 16);=0D -=0D - BlockCount--;=0D - Ptr =3D Ptr + 16;=0D - }=0D -=0D - //=0D - // Populate the remained data as request.=0D - //=0D - Ret =3D RandGetSeed128 (Seed);=0D - if (!Ret) {=0D - return Ret;=0D - }=0D - CopyMem (Ptr, Seed, (Length % 16));=0D -=0D - return Ret;=0D -}=0D -=0D /*=0D * Add random bytes to the pool to acquire requested amount of entropy=0D *=0D @@ -238,7 +84,7 @@ size_t rand_pool_acquire_entropy(RAND_POOL *pool) buffer =3D rand_pool_add_begin(pool, bytes_needed);=0D =0D if (buffer !=3D NULL) {=0D - Ret =3D RandGenerateEntropy(bytes_needed, buffer);=0D + Ret =3D RandGetBytes(bytes_needed, buffer);=0D if (FALSE =3D=3D Ret) {=0D rand_pool_add_end(pool, 0, 0);=0D } else {=0D @@ -257,13 +103,8 @@ size_t rand_pool_acquire_entropy(RAND_POOL *pool) */=0D int rand_pool_add_nonce_data(RAND_POOL *pool)=0D {=0D - struct {=0D - UINT64 Rand;=0D - UINT64 TimerValue;=0D - } data =3D { 0 };=0D -=0D - RandGetBytes(8, (UINT8 *)&(data.Rand));=0D - data.TimerValue =3D GetPerformanceCounter();=0D + UINT8 data[16];=0D + RandGetBytes(sizeof(data), data);=0D =0D return rand_pool_add(pool, (unsigned char*)&data, sizeof(data), 0);=0D }=0D @@ -275,13 +116,8 @@ int rand_pool_add_nonce_data(RAND_POOL *pool) */=0D int rand_pool_add_additional_data(RAND_POOL *pool)=0D {=0D - struct {=0D - UINT64 Rand;=0D - UINT64 TimerValue;=0D - } data =3D { 0 };=0D -=0D - RandGetBytes(8, (UINT8 *)&(data.Rand));=0D - data.TimerValue =3D GetPerformanceCounter();=0D + UINT8 data[16];=0D + RandGetBytes(sizeof(data), data);=0D =0D return rand_pool_add(pool, (unsigned char*)&data, sizeof(data), 0);=0D }=0D @@ -313,4 +149,3 @@ void rand_pool_cleanup(void) void rand_pool_keep_random_devices_open(int keep)=0D {=0D }=0D -=0D diff --git a/CryptoPkg/Library/OpensslLib/rand_pool_noise.c b/CryptoPkg/Lib= rary/OpensslLib/rand_pool_noise.c deleted file mode 100644 index 212834e27acc..000000000000 --- a/CryptoPkg/Library/OpensslLib/rand_pool_noise.c +++ /dev/null @@ -1,29 +0,0 @@ -/** @file=0D - Provide rand noise source.=0D -=0D -Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>=0D -SPDX-License-Identifier: BSD-2-Clause-Patent=0D -=0D -**/=0D -=0D -#include <Library/BaseLib.h>=0D -=0D -/**=0D - Get 64-bit noise source=0D -=0D - @param[out] Rand Buffer pointer to store 64-bit noise source=0D -=0D - @retval FALSE Failed to generate=0D -**/=0D -BOOLEAN=0D -EFIAPI=0D -GetRandomNoise64 (=0D - OUT UINT64 *Rand=0D - )=0D -{=0D - //=0D - // Return FALSE will fallback to use PerformanceCounter to=0D - // generate noise.=0D - //=0D - return FALSE;=0D -}=0D diff --git a/CryptoPkg/Library/OpensslLib/rand_pool_noise_tsc.c b/CryptoPkg= /Library/OpensslLib/rand_pool_noise_tsc.c deleted file mode 100644 index 4158106231fd..000000000000 --- a/CryptoPkg/Library/OpensslLib/rand_pool_noise_tsc.c +++ /dev/null @@ -1,43 +0,0 @@ -/** @file=0D - Provide rand noise source.=0D -=0D -Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>=0D -SPDX-License-Identifier: BSD-2-Clause-Patent=0D -=0D -**/=0D -=0D -#include <Library/BaseLib.h>=0D -#include <Library/DebugLib.h>=0D -#include <Library/TimerLib.h>=0D -=0D -/**=0D - Get 64-bit noise source=0D -=0D - @param[out] Rand Buffer pointer to store 64-bit noise source=0D -=0D - @retval TRUE Get randomness successfully.=0D - @retval FALSE Failed to generate=0D -**/=0D -BOOLEAN=0D -EFIAPI=0D -GetRandomNoise64 (=0D - OUT UINT64 *Rand=0D - )=0D -{=0D - UINT32 Index;=0D - UINT32 *RandPtr;=0D -=0D - if (NULL =3D=3D Rand) {=0D - return FALSE;=0D - }=0D -=0D - RandPtr =3D (UINT32 *)Rand;=0D -=0D - for (Index =3D 0; Index < 2; Index ++) {=0D - *RandPtr =3D (UINT32) ((AsmReadTsc ()) & 0xFF);=0D - RandPtr++;=0D - MicroSecondDelay (10);=0D - }=0D -=0D - return TRUE;=0D -}=0D diff --git a/CryptoPkg/CryptoPkg.dsc b/CryptoPkg/CryptoPkg.dsc index 1af78468a19c..0490eeb7e22f 100644 --- a/CryptoPkg/CryptoPkg.dsc +++ b/CryptoPkg/CryptoPkg.dsc @@ -60,6 +60,7 @@ BaseCryptLib|CryptoPkg/Library/BaseCryptLibNull/BaseCryptLibNull.inf=0D TlsLib|CryptoPkg/Library/TlsLibNull/TlsLibNull.inf=0D HashApiLib|CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.inf=0D + RngLib|MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf=0D =0D [LibraryClasses.ARM, LibraryClasses.AARCH64]=0D #=0D diff --git a/CryptoPkg/Library/OpensslLib/OpensslLib.inf b/CryptoPkg/Librar= y/OpensslLib/OpensslLib.inf index dbbe5386a10c..4baad565564c 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLib.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLib.inf @@ -571,22 +571,9 @@ $(OPENSSL_PATH)/ssl/statem/statem_local.h=0D # Autogenerated files list ends here=0D buildinf.h=0D - rand_pool_noise.h=0D ossl_store.c=0D rand_pool.c=0D =0D -[Sources.Ia32]=0D - rand_pool_noise_tsc.c=0D -=0D -[Sources.X64]=0D - rand_pool_noise_tsc.c=0D -=0D -[Sources.ARM]=0D - rand_pool_noise.c=0D -=0D -[Sources.AARCH64]=0D - rand_pool_noise.c=0D -=0D [Packages]=0D MdePkg/MdePkg.dec=0D CryptoPkg/CryptoPkg.dec=0D @@ -594,7 +581,7 @@ [LibraryClasses]=0D BaseLib=0D DebugLib=0D - TimerLib=0D + RngLib=0D PrintLib=0D =0D [LibraryClasses.ARM]=0D diff --git a/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf b/CryptoPkg/= Library/OpensslLib/OpensslLibCrypto.inf index 616ccd9f62d1..3557711bd85a 100644 --- a/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf +++ b/CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf @@ -520,22 +520,9 @@ $(OPENSSL_PATH)/crypto/x509v3/v3_admis.h=0D # Autogenerated files list ends here=0D buildinf.h=0D - rand_pool_noise.h=0D ossl_store.c=0D rand_pool.c=0D =0D -[Sources.Ia32]=0D - rand_pool_noise_tsc.c=0D -=0D -[Sources.X64]=0D - rand_pool_noise_tsc.c=0D -=0D -[Sources.ARM]=0D - rand_pool_noise.c=0D -=0D -[Sources.AARCH64]=0D - rand_pool_noise.c=0D -=0D [Packages]=0D MdePkg/MdePkg.dec=0D CryptoPkg/CryptoPkg.dec=0D @@ -543,7 +530,7 @@ [LibraryClasses]=0D BaseLib=0D DebugLib=0D - TimerLib=0D + RngLib=0D PrintLib=0D =0D [LibraryClasses.ARM]=0D diff --git a/CryptoPkg/Library/OpensslLib/rand_pool_noise.h b/CryptoPkg/Lib= rary/OpensslLib/rand_pool_noise.h deleted file mode 100644 index 75acc686a9f1..000000000000 --- a/CryptoPkg/Library/OpensslLib/rand_pool_noise.h +++ /dev/null @@ -1,29 +0,0 @@ -/** @file=0D - Provide rand noise source.=0D -=0D -Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>=0D -SPDX-License-Identifier: BSD-2-Clause-Patent=0D -=0D -**/=0D -=0D -#ifndef __RAND_POOL_NOISE_H__=0D -#define __RAND_POOL_NOISE_H__=0D -=0D -#include <Uefi/UefiBaseType.h>=0D -=0D -/**=0D - Get 64-bit noise source.=0D -=0D - @param[out] Rand Buffer pointer to store 64-bit noise source=0D -=0D - @retval TRUE Get randomness successfully.=0D - @retval FALSE Failed to generate=0D -**/=0D -BOOLEAN=0D -EFIAPI=0D -GetRandomNoise64 (=0D - OUT UINT64 *Rand=0D - );=0D -=0D -=0D -#endif // __RAND_POOL_NOISE_H__=0D --=20 2.27.0.windows.1
|
|
[PATCH v3 0/3] Use RngLib instead of TimerLib for OpensslLib
Matthew Carlson
From: Matthew Carlson <macarl@...>
Fixes Bugzilla#1871 https://github.com/tianocore/edk2/pull/845 Matthew Carlson (3): CryptoPkg: OpensslLib: Use RngLib to generate entropy in rand_pool MdePkg: TimerRngLib: Added RngLib that uses TimerLib MdePkg: BaseRngLibDxe: Add RngLib that uses RngDxe CryptoPkg/Library/OpensslLib/rand_pool.c | 203 ++---------------- CryptoPkg/Library/OpensslLib/rand_pool_noise.c | 29 --- CryptoPkg/Library/OpensslLib/rand_pool_noise_tsc.c | 43 ---- MdePkg/Library/BaseRngLibDxe/RngDxeLib.c | 216 ++++++++++++++++++++ MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c | 154 ++++++++++++++ CryptoPkg/CryptoPkg.dsc | 1 + CryptoPkg/Library/OpensslLib/OpensslLib.inf | 15 +- CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf | 15 +- CryptoPkg/Library/OpensslLib/rand_pool_noise.h | 29 --- MdePkg/Library/BaseRngLibDxe/BaseRngLibDxe.inf | 38 ++++ MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf | 38 ++++ MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.uni | 17 ++ MdePkg/MdePkg.dsc | 5 +- 13 files changed, 489 insertions(+), 314 deletions(-) delete mode 100644 CryptoPkg/Library/OpensslLib/rand_pool_noise.c delete mode 100644 CryptoPkg/Library/OpensslLib/rand_pool_noise_tsc.c create mode 100644 MdePkg/Library/BaseRngLibDxe/RngDxeLib.c create mode 100644 MdePkg/Library/BaseRngLibTimerLib/RngLibTimer.c delete mode 100644 CryptoPkg/Library/OpensslLib/rand_pool_noise.h create mode 100644 MdePkg/Library/BaseRngLibDxe/BaseRngLibDxe.inf create mode 100644 MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.inf create mode 100644 MdePkg/Library/BaseRngLibTimerLib/BaseRngLibTimerLib.uni -- 2.27.0.windows.1
|
|
Re: [Patch v2 0/2] Use RngLib instead of TimerLib for OpensslLib
Matthew Carlson
Hey Mike!   Calls RandomNumber64 to fill
  a buffer of arbitrary size with random bytes.
  @param[in]   Length        Size of the buffer, in bytes,  to fill with.
  @param[out]  RandBuffer    Pointer to the buffer to store the random result.
  @retval True        Random bytes generation succeeded.
  @retval False       Failed to request random bytes.
Â
--
|
|
Re: [PATCH] SimicsOpenBoardPkg: Update usage of functions to be removed
Agyeman, Prince
Reviewed-by: Prince Agyeman <prince.agyeman@...>
toggle quoted messageShow quoted text
-----Original Message-----
From: Zhang, Shenglei <shenglei.zhang@...> Sent: Tuesday, July 28, 2020 8:34 PM To: devel@edk2.groups.io Cc: Agyeman, Prince <prince.agyeman@...> Subject: [PATCH] SimicsOpenBoardPkg: Update usage of functions to be removed REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2777 With some functions to be deprecated, their usage in platforms should also be updated. Cc: Agyeman Prince <prince.agyeman@...> Signed-off-by: Shenglei Zhang <shenglei.zhang@...> --- .../Library/BoardBdsHookLib/BoardBdsHookLib.c | 2 +- .../Intel/SimicsOpenBoardPkg/SimicsDxe/Platform.c | 4 ++-- .../Intel/SimicsOpenBoardPkg/SimicsPei/MemDetect.c | 6 +++--- .../Intel/SimicsOpenBoardPkg/SimicsPei/Platform.c | 12 ++++++------ 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Platform/Intel/SimicsOpenBoardPkg/Library/BoardBdsHookLib/BoardBdsHookLib.c b/Platform/Intel/SimicsOpenBoardPkg/Library/BoardBdsHookLib/BoardBdsHookLib.c index 1058dbf3..ba4d2b02 100644 --- a/Platform/Intel/SimicsOpenBoardPkg/Library/BoardBdsHookLib/BoardBdsHookLib.c +++ b/Platform/Intel/SimicsOpenBoardPkg/Library/BoardBdsHookLib/BoardBds +++ HookLib.c @@ -1206,7 +1206,7 @@ VisitingFileSystemInstance ( NULL, &mEmuVariableEventReg ); - PcdSet64 (PcdEmuVariableEvent, (UINT64)(UINTN) mEmuVariableEvent); + PcdSet64S (PcdEmuVariableEvent, (UINT64)(UINTN) mEmuVariableEvent); return EFI_SUCCESS; } diff --git a/Platform/Intel/SimicsOpenBoardPkg/SimicsDxe/Platform.c b/Platform/Intel/SimicsOpenBoardPkg/SimicsDxe/Platform.c index b7fd4d1f..c856ff44 100644 --- a/Platform/Intel/SimicsOpenBoardPkg/SimicsDxe/Platform.c +++ b/Platform/Intel/SimicsOpenBoardPkg/SimicsDxe/Platform.c @@ -669,9 +669,9 @@ ExecutePlatformConfig ( // // Pass the preferred resolution to GraphicsConsoleDxe via dynamic PCDs. // - PcdSet32 (PcdVideoHorizontalResolution, + PcdSet32S (PcdVideoHorizontalResolution, PlatformConfig.HorizontalResolution); - PcdSet32 (PcdVideoVerticalResolution, + PcdSet32S (PcdVideoVerticalResolution, PlatformConfig.VerticalResolution); } diff --git a/Platform/Intel/SimicsOpenBoardPkg/SimicsPei/MemDetect.c b/Platform/Intel/SimicsOpenBoardPkg/SimicsPei/MemDetect.c index 60aa54be..127afffc 100644 --- a/Platform/Intel/SimicsOpenBoardPkg/SimicsPei/MemDetect.c +++ b/Platform/Intel/SimicsOpenBoardPkg/SimicsPei/MemDetect.c @@ -155,7 +155,7 @@ GetFirstNonAddress ( if (mBootMode != BOOT_ON_S3_RESUME) { DEBUG ((EFI_D_INFO, "%a: disabling 64-bit PCI host aperture\n", __FUNCTION__)); - PcdSet64 (PcdPciMmio64Size, 0); + PcdSet64S (PcdPciMmio64Size, 0); } // @@ -187,8 +187,8 @@ GetFirstNonAddress ( // the GCD memory space map through our PciHostBridgeLib instance; here we // only need to set the PCDs. // - PcdSet64 (PcdPciMmio64Base, Pci64Base); - PcdSet64 (PcdPciMmio64Size, Pci64Size); + PcdSet64S (PcdPciMmio64Base, Pci64Base); + PcdSet64S (PcdPciMmio64Size, Pci64Size); DEBUG ((EFI_D_INFO, "%a: Pci64Base=0x%Lx Pci64Size=0x%Lx\n", __FUNCTION__, Pci64Base, Pci64Size)); } diff --git a/Platform/Intel/SimicsOpenBoardPkg/SimicsPei/Platform.c b/Platform/Intel/SimicsOpenBoardPkg/SimicsPei/Platform.c index 0bec76e4..6963f39a 100644 --- a/Platform/Intel/SimicsOpenBoardPkg/SimicsPei/Platform.c +++ b/Platform/Intel/SimicsOpenBoardPkg/SimicsPei/Platform.c @@ -257,8 +257,8 @@ MemMapInitialization ( // PciSize = 0xFC000000 - PciBase; AddIoMemoryBaseSizeHob (PciBase, PciSize); - PcdSet64 (PcdPciMmio32Base, PciBase); - PcdSet64 (PcdPciMmio32Size, PciSize); + PcdSet64S (PcdPciMmio32Base, PciBase); PcdSet64S (PcdPciMmio32Size, + PciSize); AddIoMemoryBaseSizeHob (0xFEC00000, SIZE_4KB); AddIoMemoryBaseSizeHob (0xFED00000, SIZE_1KB); if (mHostBridgeDevId == INTEL_ICH10_DEVICE_ID) { @@ -300,8 +300,8 @@ MemMapInitialization ( PciIoBase, PciIoSize ); - PcdSet64 (PcdPciIoBase, PciIoBase); - PcdSet64 (PcdPciIoSize, PciIoSize); + PcdSet64S (PcdPciIoBase, PciIoBase); + PcdSet64S (PcdPciIoSize, PciIoSize); // // Add flash range. @@ -367,7 +367,7 @@ MiscInitialization ( ASSERT (FALSE); return; } - PcdSet16 (PcdSimicsX58HostBridgePciDevId, mHostBridgeDevId); + PcdSet16S (PcdSimicsX58HostBridgePciDevId, mHostBridgeDevId); // // If the appropriate IOspace enable bit is set, assume the ACPI PMBA @@ -483,7 +483,7 @@ ReserveEmuVariableNvStore ( VariableStore, (2 * PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / 1024 )); - PcdSet64 (PcdEmuVariableNvStoreReserved, VariableStore); + PcdSet64S (PcdEmuVariableNvStoreReserved, VariableStore); } -- 2.18.0.windows.1
|
|
Re: [PATCH 1/1] Add BhyvePkg, to support the bhyve hypervisor
Sean
This patch as committed is breaking CI. It was not captured in PR because the PR optimizes to detect packages impacted by the commits and the BhyvePkg addition is not depended on by other packages (that are in CI). BhyvePkg which is nested inside OvmfPkg ( a violation of DEC spec: see https://edk2-docs.gitbook.io/edk-ii-dec-specification/2_dec_file_overview paragraph 4) does not support CI so it is not tested but now that it is in the edk2 tree it is causing the other packages to fail.
toggle quoted messageShow quoted text
You can see the ReadMe badge showing the broken state of edk2 master. The build with logs can be seen here https://dev.azure.com/tianocore/edk2-ci/_build/results?buildId=10494&view=logs&j=ec42d809-3c3b-54a9-276c-e54a8b9aaee9&t=596e0656-4def-5804-b10b-1585519aa2e8 and some of the relevant failures are added below. ERROR - Error Duplicate guid: 24A2D66F-EEDD-4086-9042-F26E4797EE69 (2) GUID: 24A2D66F-EEDD-4086-9042-F26E4797EE69 NAME: gRootBridgesConnectedEventGroupGuid FILE: /home/vsts/work/1/s/OvmfPkg/OvmfPkg.dec GUID: 24A2D66F-EEDD-4086-9042-F26E4797EE69 NAME: gRootBridgesConnectedEventGroupGuid FILE: /home/vsts/work/1/s/OvmfPkg/Bhyve/BhyvePkg.dec ERROR - Error Duplicate name: gEfiLegacyBiosProtocolGuid (2) GUID: DB9A1E3D-45CB-4ABB-853B-E5387FDB2E2D NAME: gEfiLegacyBiosProtocolGuid FILE: /home/vsts/work/1/s/OvmfPkg/OvmfPkg.dec GUID: DB9A1E3D-45CB-4ABB-853B-E5387FDB2E2D NAME: gEfiLegacyBiosProtocolGuid FILE: /home/vsts/work/1/s/OvmfPkg/Bhyve/BhyvePkg.dec ERROR - Error Duplicate name: gIoMmuAbsentProtocolGuid (2) GUID: F8775D50-8ABD-4ADF-92AC-853E51F6C8DC NAME: gIoMmuAbsentProtocolGuid FILE: /home/vsts/work/1/s/OvmfPkg/OvmfPkg.dec GUID: F8775D50-8ABD-4ADF-92AC-853E51F6C8DC NAME: gIoMmuAbsentProtocolGuid FILE: /home/vsts/work/1/s/OvmfPkg/Bhyve/BhyvePkg.dec ERROR - Error Duplicate name: gOvmfPlatformConfigGuid (2) GUID: 7235C51C-0C80-4CAB-87AC-3B084A6304B1 NAME: gOvmfPlatformConfigGuid FILE: /home/vsts/work/1/s/OvmfPkg/OvmfPkg.dec GUID: 7235C51C-0C80-4CAB-87AC-3B084A6304B1 NAME: gOvmfPlatformConfigGuid FILE: /home/vsts/work/1/s/OvmfPkg/Bhyve/BhyvePkg.dec ERROR - Error Duplicate name: gRootBridgesConnectedEventGroupGuid (2) GUID: 24A2D66F-EEDD-4086-9042-F26E4797EE69 NAME: gRootBridgesConnectedEventGroupGuid FILE: /home/vsts/work/1/s/OvmfPkg/OvmfPkg.dec GUID: 24A2D66F-EEDD-4086-9042-F26E4797EE69 NAME: gRootBridgesConnectedEventGroupGuid FILE: /home/vsts/work/1/s/OvmfPkg/Bhyve/BhyvePkg.dec ERROR - Error Duplicate name: gUefiOvmfPkgTokenSpaceGuid (2) GUID: 93BB96AF-B9F2-4EB8-9462-E0BA74564236 NAME: gUefiOvmfPkgTokenSpaceGuid FILE: /home/vsts/work/1/s/OvmfPkg/OvmfPkg.dec GUID: 93BB96AF-B9F2-4EB8-9462-E0BA74564236 NAME: gUefiOvmfPkgTokenSpaceGuid FILE: /home/vsts/work/1/s/OvmfPkg/Bhyve/BhyvePkg.dec ERROR - Error Duplicate name: gVirtioDeviceProtocolGuid (2) GUID: FA920010-6785-4941-B6EC-498C579F160A NAME: gVirtioDeviceProtocolGuid FILE: /home/vsts/work/1/s/OvmfPkg/OvmfPkg.dec GUID: FA920010-6785-4941-B6EC-498C579F160A NAME: gVirtioDeviceProtocolGuid FILE: /home/vsts/work/1/s/OvmfPkg/Bhyve/BhyvePkg.dec ERROR - Error Duplicate name: gVirtioMmioTransportGuid (2) GUID: 837DCA9E-E874-4D82-B29A-23FE0E23D1E2 NAME: gVirtioMmioTransportGuid FILE: /home/vsts/work/1/s/OvmfPkg/OvmfPkg.dec GUID: 837DCA9E-E874-4D82-B29A-23FE0E23D1E2 NAME: gVirtioMmioTransportGuid FILE: /home/vsts/work/1/s/OvmfPkg/Bhyve/BhyvePkg.dec and ERROR - Dependency Check: Invalid Dependency INF: OvmfPkg/Bhyve/Library/BhyveFwCtlLib/BhyveFwCtlLib.inf depends on pkg OvmfPkg/Bhyve/BhyvePkg.dec ERROR - Dependency Check: Invalid Dependency INF: OvmfPkg/Bhyve/BhyveRfbDxe/BhyveRfbDxe.inf depends on pkg OvmfPkg/Bhyve/BhyvePkg.dec ERROR - Dependency Check: Invalid Dependency INF: OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf depends on pkg OvmfPkg/Bhyve/BhyvePkg.dec The errors can be easily resolved but the nested packages is a bigger problem. Thanks Sean
On 7/31/2020 6:10 AM, Laszlo Ersek wrote:
On 07/31/20 15:07, Laszlo Ersek wrote:On 07/31/20 07:17, Rebecca Cran wrote:... We should have updated the subject line fromOn 7/13/20 2:25 PM, Rebecca Cran wrote:Thanks for the ping.On 7/13/20 12:09 PM, Laszlo Ersek wrote:Can you please ping me when the PatchCheck.py problem has been solved,Will do.
|
|
[PATCH] Check return status on calls to GetTime()
Grant Likely <grant.likely@...>
Not all platforms implement GetTime(), but the SCT just assumes calls to
GetTime will be successful. If GetTime() doesn't return EFI_SUCCESS, then the EFI_TIME value will be uninitialized data. Fix by checking the GetTime() return code. If it doesn't return EFI_SUCCESS, then use the traditional 1/1/1970 epoch so that the test report at least looks sane, but it is obvious that we don't have a valid timestamp. Fixes: https://bugzilla.tianocore.org/show_bug.cgi?id=2870 Cc: G Edhaya Chandran <Edhaya.Chandran@...> Cc: Heinrich Schuchardt <xypron.glpk@...> Cc: Samer El-Haj-Mahmoud <samer.el-haj-mahmoud@...> Signed-off-by: Grant Likely <grant.likely@...> --- .../SimpleNetwork/SimpleNetworkENTSTestCase.c | 26 +++++++++++++------ .../MiscBootServicesBBTestFunction.c | 8 ++++-- .../DriverBindingBBTestFunction.c | 5 +++- .../SCT/Drivers/StandardTest/StandardTest.c | 11 +++++--- .../Framework/ENTS/EasDispatcher/Core/Eas.c | 9 +++++-- .../ENTS/EasDispatcher/Exec/EasCmdDisp.c | 20 +++++++++----- 6 files changed, 57 insertions(+), 22 deletions(-) diff --git a/uefi-sct/SctPkg/TestCase/RIVL/Protocol/SimpleNetwork/SimpleNetworkENTSTestCase.c b/uefi-sct/SctPkg/TestCase/RIVL/Protocol/SimpleNetwork/SimpleNetworkENTSTestCase.c index 9c8d2a70..5579be7e 100644 --- a/uefi-sct/SctPkg/TestCase/RIVL/Protocol/SimpleNetwork/SimpleNetworkENTSTestCase.c +++ b/uefi-sct/SctPkg/TestCase/RIVL/Protocol/SimpleNetwork/SimpleNetworkENTSTestCase.c @@ -24,6 +24,8 @@ Abstract: #include "SimpleNetworkENTSTestCase.h" +static EFI_TIME Epoch = { .Year = 1970, .Month = 1, .Day = 1 }; + // // SimpleNetwork.Start // @@ -928,7 +930,8 @@ Returns: Status = EFI_SUCCESS; tBS->Stall (5000); - tRT->GetTime (&BeginTime, NULL); + if (tRT->GetTime (&BeginTime, NULL) != EFI_SUCCESS) + BeginTime = Epoch; for (Index = 0; Index < 1;) { Status = SimpleNetwork->Transmit ( SimpleNetwork, @@ -964,7 +967,8 @@ Returns: } } - tRT->GetTime (&BeginTime, NULL); + if (tRT->GetTime (&BeginTime, NULL) != EFI_SUCCESS) + BeginTime = Epoch; for (Index = 1; Index < TransmitPattern1Number;) { Status = SimpleNetwork->Transmit ( @@ -1002,7 +1006,8 @@ Returns: } End: - tRT->GetTime (&EndTime, NULL); + if (tRT->GetTime (&EndTime, NULL) != EFI_SUCCESS) + EndTime = Epoch; *TransmitPattern1Status = Status; @@ -1125,7 +1130,8 @@ Returns: Status = EFI_SUCCESS; tBS->Stall (5000); - tRT->GetTime (&BeginTime, NULL); + if (tRT->GetTime (&BeginTime, NULL) != EFI_SUCCESS) + BeginTime = Epoch; for (Index = 0; Index < 1;) { Status = SimpleNetwork->Transmit ( SimpleNetwork, @@ -1161,7 +1167,8 @@ Returns: } } - tRT->GetTime (&BeginTime, NULL); + if (tRT->GetTime (&BeginTime, NULL) != EFI_SUCCESS) + BeginTime = Epoch; for (Index = 1; Index < TransmitPattern2Number;) { Status = SimpleNetwork->Transmit ( @@ -1199,7 +1206,8 @@ Returns: } End: - tRT->GetTime (&EndTime, NULL); + if (tRT->GetTime (&EndTime, NULL) != EFI_SUCCESS) + EndTime = Epoch; *TransmitPattern1Status = Status; @@ -1326,7 +1334,8 @@ Returns: } } - tRT->GetTime (&BeginTime, NULL); + if (tRT->GetTime (&BeginTime, NULL) != EFI_SUCCESS) + BeginTime = Epoch; for (Index = 1; Index < ReceivePattern1Number;) { *ReceivePattern1BufferSize = BufferSizeOrg; @@ -1346,7 +1355,8 @@ Returns: } } - tRT->GetTime (&EndTime, NULL); + if (tRT->GetTime (&EndTime, NULL) != EFI_SUCCESS) + EndTime = Epoch; *ReceivePattern1Status = Status; diff --git a/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MiscBootServices/BlackBoxTest/MiscBootServicesBBTestFunction.c b/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MiscBootServices/BlackBoxTest/MiscBootServicesBBTestFunction.c index 1d231d8c..3a530282 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MiscBootServices/BlackBoxTest/MiscBootServicesBBTestFunction.c +++ b/uefi-sct/SctPkg/TestCase/UEFI/EFI/BootServices/MiscBootServices/BlackBoxTest/MiscBootServicesBBTestFunction.c @@ -27,6 +27,8 @@ Abstract: #include "SctLib.h" #include "MiscBootServicesBBTestMain.h" +static EFI_TIME Epoch = { .Year = 1970, .Month = 1, .Day = 1 }; + /** * Entrypoint for gtBS->SetWatchdogTimer() Interface Test. * @param This a pointer of EFI_BB_TEST_PROTOCOL. @@ -821,13 +823,15 @@ BBTestStallInterfaceTest ( // // 4.2.2.1 Stall must succeed. // - gtRT->GetTime (&StartTime, NULL); + if (gtRT->GetTime (&StartTime, NULL) != EFI_SUCCESS) + StartTime = Epoch; OldTpl = gtBS->RaiseTPL (TplArray[Index]); Status = gtBS->Stall ( 10000000 ); gtBS->RestoreTPL (OldTpl); - gtRT->GetTime (&EndTime, NULL); + if (gtRT->GetTime (&EndTime, NULL) != EFI_SUCCESS) + EndTime = Epoch; if (Status == EFI_SUCCESS) { AssertionType = EFI_TEST_ASSERTION_PASSED; } else { diff --git a/uefi-sct/SctPkg/TestCase/UEFI/IHV/Protocol/DriverBinding/BlackBoxTest/DriverBindingBBTestFunction.c b/uefi-sct/SctPkg/TestCase/UEFI/IHV/Protocol/DriverBinding/BlackBoxTest/DriverBindingBBTestFunction.c index bf675feb..4ab52dcd 100644 --- a/uefi-sct/SctPkg/TestCase/UEFI/IHV/Protocol/DriverBinding/BlackBoxTest/DriverBindingBBTestFunction.c +++ b/uefi-sct/SctPkg/TestCase/UEFI/IHV/Protocol/DriverBinding/BlackBoxTest/DriverBindingBBTestFunction.c @@ -36,6 +36,8 @@ static const UINTN MonthLengths[2][12] = { { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } }; +static EFI_TIME Epoch = { .Year = 1970, .Month = 1, .Day = 1 }; + #define MINS_PER_HOUR 60 #define HOURS_PER_DAY 24 #define SECS_PER_MIN 60 @@ -1052,7 +1054,8 @@ EndLogging ( WriteLogFile (Private, DashLine, SYSTEMLOG); WriteLogFile (Private, DashLine, CASELOG); - gtRT->GetTime (&CurrentTime, NULL); + if (gtRT->GetTime (&CurrentTime, NULL) != EFI_SUCCESS) + CurrentTime = Epoch; DBSPrint (Buffer, EFI_MAX_PRINT_BUFFER, L"Test Finished: %t\n", &CurrentTime); WriteLogFile (Private, Buffer, SYSTEMLOG); diff --git a/uefi-sct/SctPkg/TestInfrastructure/SCT/Drivers/StandardTest/StandardTest.c b/uefi-sct/SctPkg/TestInfrastructure/SCT/Drivers/StandardTest/StandardTest.c index 84025457..836f072a 100644 --- a/uefi-sct/SctPkg/TestInfrastructure/SCT/Drivers/StandardTest/StandardTest.c +++ b/uefi-sct/SctPkg/TestInfrastructure/SCT/Drivers/StandardTest/StandardTest.c @@ -30,6 +30,8 @@ Abstract: #include "StandardTest.h" #include <Library/EntsLib.h> +static EFI_TIME Epoch = { .Year = 1970, .Month = 1, .Day = 1 }; + // // Prototypes // @@ -1081,7 +1083,8 @@ Returns: StslWriteLogFile (Private, Buffer); CurrentTime = &Private->StartTime; - tRT->GetTime (CurrentTime, NULL); + if (tRT->GetTime (CurrentTime, NULL) != EFI_SUCCESS) + *CurrentTime = Epoch; } else { StslWriteLogFile (Private, DashLine); @@ -1118,7 +1121,8 @@ Returns: StslWriteLogFileName (Private); CurrentTime = &Private->StartTime; - tRT->GetTime (CurrentTime, NULL); + if (tRT->GetTime (CurrentTime, NULL) != EFI_SUCCESS) + *CurrentTime = Epoch; SctSPrint (Buffer, EFI_MAX_PRINT_BUFFER, L"Test Started: %t\n", CurrentTime); StslWriteLogFile (Private, Buffer); @@ -1238,7 +1242,8 @@ Returns: StslWriteLogFileName (Private); - tRT->GetTime (&CurrentTime, NULL); + if (tRT->GetTime (&CurrentTime, NULL) != EFI_SUCCESS) + CurrentTime = Epoch; SecondsElapsed = SecondsElapsedFromBaseYear ( Private->StartTime.Year, diff --git a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasDispatcher/Core/Eas.c b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasDispatcher/Core/Eas.c index 28f5ed4a..60b1c4dc 100644 --- a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasDispatcher/Core/Eas.c +++ b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasDispatcher/Core/Eas.c @@ -23,9 +23,12 @@ Abstract: --*/ +#include "Sct.h" #include "Sct.h" #include EFI_TEST_PROTOCOL_DEFINITION (EntsMonitorProtocol) +static EFI_TIME Epoch = { .Year = 1970, .Month = 1, .Day = 1 }; + STATIC EFI_STATUS AgentTestMain ( @@ -310,7 +313,8 @@ DelaySctAgentCmdPost ( } SctAgentCmdDelayedPost->CmdReturn = CmdReturn; SctAgentCmdDelayedPost->Cmd.ComdResult = CmdResult; - tRT->GetTime (&SctAgentCmdDelayedPost->StartTime, NULL); + if (tRT->GetTime (&SctAgentCmdDelayedPost->StartTime, NULL) != EFI_SUCCESS) + SctAgentCmdDelayedPost->StartTime = Epoch; return Status; } @@ -327,7 +331,8 @@ PostSctAgentDelayedCmd ( return EFI_SUCCESS; } - tRT->GetTime (&SctAgentCmdDelayedPost->EndTime, NULL); + if (tRT->GetTime (&SctAgentCmdDelayedPost->EndTime, NULL) != EFI_SUCCESS) + SctAgentCmdDelayedPost->EndTime = Epoch; Status = RecordMessage ( &SctAgentCmdDelayedPost->Cmd.ComdRuntimeInfo, diff --git a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasDispatcher/Exec/EasCmdDisp.c b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasDispatcher/Exec/EasCmdDisp.c index 1ff6d569..cb6f08cf 100644 --- a/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasDispatcher/Exec/EasCmdDisp.c +++ b/uefi-sct/SctPkg/TestInfrastructure/SCT/Framework/ENTS/EasDispatcher/Exec/EasCmdDisp.c @@ -50,6 +50,8 @@ Abstract: EFI_CPU_ARCH_PROTOCOL *Cpu = NULL; +static EFI_TIME Epoch = { .Year = 1970, .Month = 1, .Day = 1 }; + // // Local Function Definition // @@ -132,9 +134,11 @@ Returns: // // Perform EFTP operation. // - tRT->GetTime (&StartTime, NULL); + if (tRT->GetTime (&StartTime, NULL) != EFI_SUCCESS) + StartTime = Epoch; Status = EftpDispatchFileTransferComd (FileCmdType); - tRT->GetTime (&EndTime, NULL); + if (tRT->GetTime (&EndTime, NULL) != EFI_SUCCESS) + EndTime = Epoch; if (Status == EFI_OUT_OF_RESOURCES) { return EFI_OUT_OF_RESOURCES; @@ -365,9 +369,11 @@ Returns: // // Execute Shell Command // - tRT->GetTime (&StartTime, NULL); + if (tRT->GetTime (&StartTime, NULL) != EFI_SUCCESS) + StartTime = Epoch; Status = SctShellExecute (&mImageHandle, (gEasFT->Cmd)->ComdArg, FALSE, NULL, NULL);; - tRT->GetTime (&EndTime, NULL); + if (tRT->GetTime (&EndTime, NULL) != EFI_SUCCESS) + EndTime = Epoch; EFI_ENTS_DEBUG ((EFI_ENTS_D_TRACE, L"dispatch:(%s)", (gEasFT->Cmd)->ComdArg)); SctPrint (L"dispatch:(%s) - %r\n", (gEasFT->Cmd)->ComdArg, Status); if (Status == EFI_OUT_OF_RESOURCES) { @@ -1483,9 +1489,11 @@ Returns: // // Resume SCT execution by executing "sct -c" in sct passive mode. // - tRT->GetTime (&StartTime, NULL); + if (tRT->GetTime (&StartTime, NULL) != EFI_SUCCESS) + StartTime = Epoch; Status = SctShellExecute (&mImageHandle, (gEasFT->Cmd)->ComdArg, FALSE, NULL, NULL);; - tRT->GetTime (&EndTime, NULL); + if (tRT->GetTime (&EndTime, NULL) != EFI_SUCCESS) + EndTime = Epoch; EFI_ENTS_DEBUG ((EFI_ENTS_D_TRACE, L"dispatch:(%s)", (gEasFT->Cmd)->ComdArg)); SctPrint (L"dispatch:(%s) - %r\n", (gEasFT->Cmd)->ComdArg, Status); if (Status == EFI_OUT_OF_RESOURCES) { -- 2.20.1
|
|
[PATCH 8/8] DynamicTablesPkg: Remove GET_OBJECT_LIST
Tomas Pilar (tpilar)
Replace macro-generated accessor functions in DynamicTables
generators with TableHelperLib helpers that are compatible with v1.1 revision of Configuration Manager Protocol. Cc: Sami Mujawar <Sami.Mujawar@...> Cc: Alexei Fedorov <Alexei.Fedorov@...> Signed-off-by: Tomas Pilar <tomas@...> --- .../DynamicTableFactoryDxe.c | 1 - .../DynamicTableManagerDxe.c | 34 +- .../Include/ConfigurationManagerHelper.h | 126 -- .../Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c | 34 +- .../Acpi/Arm/AcpiFadtLibArm/FadtGenerator.c | 199 +--- .../Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c | 234 ++-- .../Acpi/Arm/AcpiIortLibArm/IortGenerator.c | 1058 +++++------------ .../Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c | 304 ++--- .../Acpi/Arm/AcpiMcfgLibArm/McfgGenerator.c | 100 +- .../Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c | 287 ++--- .../Acpi/Arm/AcpiRawLibArm/RawGenerator.c | 1 - .../Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c | 35 +- .../Acpi/Arm/AcpiSratLibArm/SratGenerator.c | 437 +++---- 13 files changed, 785 insertions(+), 2065 deletions(-) delete mode 100644 DynamicTablesPkg/Include/ConfigurationManagerHelper.h diff --git a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c index d1432348f0..b8f3e1c877 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c +++ b/DynamicTablesPkg/Drivers/DynamicTableFactoryDxe/DynamicTableFactoryDxe.c @@ -15,7 +15,6 @@ // Module specific include files. #include <AcpiTableGenerator.h> #include <ConfigurationManagerObject.h> -#include <ConfigurationManagerHelper.h> #include <DeviceTreeTableGenerator.h> #include <Library/TableHelperLib.h> #include <Protocol/ConfigurationManagerProtocol.h> diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c index b194a38659..ae827fdf2c 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c @@ -8,6 +8,7 @@ **/ #include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> #include <Library/PcdLib.h> #include <Library/UefiBootServicesTableLib.h> #include <Protocol/AcpiTable.h> @@ -15,22 +16,12 @@ // Module specific include files. #include <AcpiTableGenerator.h> #include <ConfigurationManagerObject.h> -#include <ConfigurationManagerHelper.h> #include <DeviceTreeTableGenerator.h> #include <Library/TableHelperLib.h> #include <Protocol/ConfigurationManagerProtocol.h> #include <Protocol/DynamicTableFactoryProtocol.h> #include <SmbiosTableGenerator.h> -/** This macro expands to a function that retrieves the ACPI Table - List from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceStandard, - EStdObjAcpiTableList, - CM_STD_OBJ_ACPI_TABLE_INFO - ) - /** A helper function to build and install a single ACPI table. This is a helper function that invokes the Table generator interface @@ -516,12 +507,7 @@ ProcessAcpiTables ( return Status; } - Status = GetEStdObjAcpiTableList ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &AcpiTableInfo, - &AcpiTableCount - ); + Status = CfgMgrCountObjects (EStdObjAcpiTableList, &AcpiTableCount); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -546,6 +532,9 @@ ProcessAcpiTables ( AcpiTableCount )); + CfgMgrGetObjects ( + EStdObjAcpiTableList, CM_NULL_TOKEN, (VOID**)&AcpiTableInfo, &AcpiTableCount); + // Check if mandatory ACPI tables are present. Status = VerifyMandatoryTablesArePresent ( AcpiTableInfo, @@ -558,7 +547,7 @@ ProcessAcpiTables ( " Status = %r\n", Status )); - return Status; + goto EXIT; } // Add the FADT Table first. @@ -578,7 +567,7 @@ ProcessAcpiTables ( " Status = %r\n", Status )); - return Status; + goto EXIT; } break; } @@ -626,10 +615,12 @@ ProcessAcpiTables ( " Status = %r\n", Status )); - return Status; + goto EXIT; } } // for +EXIT: + FreePool(AcpiTableInfo); return Status; } @@ -697,11 +688,6 @@ DynamicTableManagerDxeInitialize ( Status = CfgMgrGetInfo (&CfgMgrInfo); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: Failed to get Configuration Manager info. Status = %r\n", - Status - )); return Status; } diff --git a/DynamicTablesPkg/Include/ConfigurationManagerHelper.h b/DynamicTablesPkg/Include/ConfigurationManagerHelper.h deleted file mode 100644 index 29f34a0434..0000000000 --- a/DynamicTablesPkg/Include/ConfigurationManagerHelper.h +++ /dev/null @@ -1,126 +0,0 @@ -/** @file - - Copyright (c) 2017 - 2019, ARM Limited. All rights reserved. - - SPDX-License-Identifier: BSD-2-Clause-Patent - - @par Glossary: - - Cm or CM - Configuration Manager - - Obj or OBJ - Object -**/ - -#ifndef CONFIGURATION_MANAGER_HELPER_H_ -#define CONFIGURATION_MANAGER_HELPER_H_ - -/** The GET_OBJECT_LIST macro expands to a function that is used to retrieve - an object or an object list from the Configuration Manager using the - Configuration Manager Protocol interface. - - The macro expands to a function which has the following prototype: - - STATIC - EFI_STATUS - EFIAPI - Get<CmObjectId> ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, - IN CONST CM_OBJECT_TOKEN Token OPTIONAL, - OUT Type ** List, - OUT UINT32 * Count OPTIONAL - ); - - Generated function parameters: - @param [in] CfgMgrProtocol Pointer to the Configuration Manager protocol - interface. - @param [in] Token Reference token for the Object. - @param [out] List Pointer to the Object list. - @param [out] Count Count of the objects returned in the list. - - Macro Parameters: - @param [in] CmObjectNameSpace The Object Namespace - @param [in] CmObjectId Object Id. - @param [in] Type Structure used to describe the Object. - - @retval EFI_SUCCESS Success. - @retval EFI_INVALID_PARAMETER A parameter is invalid. - @retval EFI_NOT_FOUND The required object information is not found. - @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration - Manager is less than the Object size for the - requested object. -**/ -#define GET_OBJECT_LIST(CmObjectNameSpace, CmObjectId, Type) \ -STATIC \ -EFI_STATUS \ -EFIAPI \ -Get##CmObjectId ( \ - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, \ - IN CONST CM_OBJECT_TOKEN Token OPTIONAL, \ - OUT Type ** List, \ - OUT UINT32 * CONST Count OPTIONAL \ - ) \ -{ \ - EFI_STATUS Status; \ - CM_OBJ_DESCRIPTOR CmObjectDesc; \ - UINT32 ObjCount = 0; \ - if (List == NULL) { \ - Status = EFI_INVALID_PARAMETER; \ - DEBUG (( \ - DEBUG_ERROR, \ - "ERROR: Get" #CmObjectId ": Invalid out parameter for" \ - " object list. Status = %r\n", \ - Status \ - )); \ - goto error_handler; \ - } \ - Status = CfgMgrProtocol->GetObject ( \ - CfgMgrProtocol, \ - CREATE_CM_OBJECT_ID ( \ - CmObjectNameSpace, \ - CmObjectId \ - ), \ - Token, \ - &CmObjectDesc \ - ); \ - if (EFI_ERROR (Status)) { \ - DEBUG (( \ - DEBUG_INFO, \ - "INFO: Get" #CmObjectId ": Platform does not implement " \ - #CmObjectId ". Status = %r\n", \ - Status \ - )); \ - *List = NULL; \ - goto error_handler; \ - } \ - if (CmObjectDesc.ObjectId != \ - CREATE_CM_OBJECT_ID (CmObjectNameSpace, CmObjectId)) { \ - DEBUG (( \ - DEBUG_ERROR, \ - "ERROR: Get" #CmObjectId ": " #CmObjectId \ - ": Invalid ObjectId = 0x%x\n, expected Id = 0x%x\n", \ - CmObjectDesc.ObjectId, \ - CREATE_CM_OBJECT_ID (CmObjectNameSpace, CmObjectId) \ - )); \ - ASSERT (FALSE); \ - Status = EFI_INVALID_PARAMETER; \ - goto error_handler; \ - } \ - if (CmObjectDesc.Size < (sizeof (Type) * CmObjectDesc.Count)) { \ - DEBUG (( \ - DEBUG_ERROR, \ - "ERROR: Get" #CmObjectId ": " #CmObjectId \ - ": Buffer too small, size = 0x%x\n", \ - CmObjectDesc.Size \ - )); \ - ASSERT (FALSE); \ - Status = EFI_BAD_BUFFER_SIZE; \ - goto error_handler; \ - } \ - ObjCount = CmObjectDesc.Count; \ - *List = (Type*)CmObjectDesc.Data; \ -error_handler: \ - if (Count != NULL) { \ - *Count = ObjCount; \ - } \ - return Status; \ -} - -#endif // CONFIGURATION_MANAGER_HELPER_H_ diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c index 21a7f9bf64..b6a1dc0ddf 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c @@ -12,6 +12,7 @@ #include <IndustryStandard/DebugPort2Table.h> #include <Library/AcpiLib.h> #include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> #include <Library/PL011UartLib.h> #include <Protocol/AcpiTable.h> #include <Protocol/SerialIo.h> @@ -19,7 +20,6 @@ // Module specific include files. #include <AcpiTableGenerator.h> #include <ConfigurationManagerObject.h> -#include <ConfigurationManagerHelper.h> #include <Library/TableHelperLib.h> #include <Protocol/ConfigurationManagerProtocol.h> @@ -166,15 +166,6 @@ DBG2_TABLE AcpiDbg2 = { #pragma pack() -/** This macro expands to a function that retrieves the Serial - debug port information from the Configuration Manager -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjSerialDebugPortInfo, - CM_ARM_SERIAL_PORT_INFO - ); - /** Initialize the PL011/SBSA UART with the parameters obtained from the Configuration Manager. @@ -285,21 +276,14 @@ BuildDbg2Table ( return EFI_INVALID_PARAMETER; } + // Pointers to allocated memory *Table = NULL; - Status = GetEArmObjSerialDebugPortInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &SerialPortInfo, - NULL - ); + Status = CfgMgrGetSimpleObject ( + EArmObjSerialDebugPortInfo, (VOID **)&SerialPortInfo); + if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: DBG2: Failed to get serial port information. Status = %r\n", - Status - )); - goto error_handler; + return Status; } if (SerialPortInfo->BaseAddress == 0) { @@ -335,11 +319,6 @@ BuildDbg2Table ( AcpiTableInfo, sizeof (DBG2_TABLE)); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: DBG2: Failed to add ACPI header. Status = %r\n", - Status - )); goto error_handler; } @@ -372,6 +351,7 @@ BuildDbg2Table ( *Table = (EFI_ACPI_DESCRIPTION_HEADER*)&AcpiDbg2; error_handler: + FreePool(SerialPortInfo); return Status; } diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiFadtLibArm/FadtGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiFadtLibArm/FadtGenerator.c index febaca3dae..8b523b0e3d 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiFadtLibArm/FadtGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiFadtLibArm/FadtGenerator.c @@ -11,12 +11,12 @@ #include <Library/AcpiLib.h> #include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> #include <Protocol/AcpiTable.h> // Module specific include files. #include <AcpiTableGenerator.h> #include <ConfigurationManagerObject.h> -#include <ConfigurationManagerHelper.h> #include <Library/TableHelperLib.h> #include <Protocol/ConfigurationManagerProtocol.h> @@ -198,47 +198,8 @@ EFI_ACPI_6_3_FIXED_ACPI_DESCRIPTION_TABLE AcpiFadt = { #pragma pack() -/** This macro expands to a function that retrieves the Power - Management Profile Information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjPowerManagementProfileInfo, - CM_ARM_POWER_MANAGEMENT_PROFILE_INFO - ); - -/** This macro expands to a function that retrieves the Boot - Architecture Information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjBootArchInfo, - CM_ARM_BOOT_ARCH_INFO - ); - -/** This macro expands to a function that retrieves the Hypervisor - Vendor ID from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjHypervisorVendorIdentity, - CM_ARM_HYPERVISOR_VENDOR_ID - ); - -/** This macro expands to a function that retrieves the Fixed - feature flags for the platform from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjFixedFeatureFlags, - CM_ARM_FIXED_FEATURE_FLAGS - ); - /** Update the Power Management Profile information in the FADT Table. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. - @retval EFI_SUCCESS Success. @retval EFI_INVALID_PARAMETER A parameter is invalid. @retval EFI_NOT_FOUND The required object was not found. @@ -249,30 +210,16 @@ GET_OBJECT_LIST ( STATIC EFI_STATUS EFIAPI -FadtAddPmProfileInfo ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol -) +FadtAddPmProfileInfo (VOID) { EFI_STATUS Status; CM_ARM_POWER_MANAGEMENT_PROFILE_INFO * PmProfile; - ASSERT (CfgMgrProtocol != NULL); - // Get the Power Management Profile from the Platform Configuration Manager - Status = GetEArmObjPowerManagementProfileInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &PmProfile, - NULL - ); + Status = CfgMgrGetSimpleObject ( + EArmObjPowerManagementProfileInfo, (VOID **)&PmProfile); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: FADT: Failed to get Power Management Profile information." \ - " Status = %r\n", - Status - )); - goto error_handler; + return Status; } DEBUG (( @@ -283,15 +230,13 @@ FadtAddPmProfileInfo ( AcpiFadt.PreferredPmProfile = PmProfile->PowerManagementProfile; -error_handler: - return Status; + FreePool(PmProfile); + + return EFI_SUCCESS; } /** Updates the Boot Architecture information in the FADT Table. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. - @retval EFI_SUCCESS Success. @retval EFI_INVALID_PARAMETER A parameter is invalid. @retval EFI_NOT_FOUND The required object was not found. @@ -302,29 +247,15 @@ error_handler: STATIC EFI_STATUS EFIAPI -FadtAddBootArchInfo ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol -) +FadtAddBootArchInfo (VOID) { EFI_STATUS Status; CM_ARM_BOOT_ARCH_INFO * BootArchInfo; - ASSERT (CfgMgrProtocol != NULL); - // Get the Boot Architecture flags from the Platform Configuration Manager - Status = GetEArmObjBootArchInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &BootArchInfo, - NULL - ); + Status = CfgMgrGetSimpleObject (EArmObjBootArchInfo, (VOID **)&BootArchInfo); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: FADT: Failed to get Boot Architecture flags. Status = %r\n", - Status - )); - goto error_handler; + return Status; } DEBUG (( @@ -335,15 +266,13 @@ FadtAddBootArchInfo ( AcpiFadt.ArmBootArch = BootArchInfo->BootArchFlags; -error_handler: - return Status; + FreePool(BootArchInfo); + + return EFI_SUCCESS; } /** Update the Hypervisor Vendor ID in the FADT Table. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. - @retval EFI_SUCCESS Success. @retval EFI_INVALID_PARAMETER A parameter is invalid. @retval EFI_NOT_FOUND The required object was not found. @@ -354,38 +283,16 @@ error_handler: STATIC EFI_STATUS EFIAPI -FadtAddHypervisorVendorId ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol -) +FadtAddHypervisorVendorId (VOID) { EFI_STATUS Status; CM_ARM_HYPERVISOR_VENDOR_ID * HypervisorVendorInfo; - ASSERT (CfgMgrProtocol != NULL); - // Get the Hypervisor Vendor ID from the Platform Configuration Manager - Status = GetEArmObjHypervisorVendorIdentity ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &HypervisorVendorInfo, - NULL - ); + Status = CfgMgrGetSimpleObject ( + EArmObjHypervisorVendorIdentity, (VOID **) &HypervisorVendorInfo); if (EFI_ERROR (Status)) { - if (Status == EFI_NOT_FOUND) { - DEBUG (( - DEBUG_INFO, - "INFO: FADT: Platform does not have a Hypervisor Vendor ID." - "Status = %r\n", - Status - )); - } else { - DEBUG (( - DEBUG_ERROR, - "ERROR: FADT: Failed to get Hypervisor Vendor ID. Status = %r\n", - Status - )); - } - goto error_handler; + return Status; } DEBUG (( @@ -396,8 +303,9 @@ FadtAddHypervisorVendorId ( AcpiFadt.HypervisorVendorIdentity = HypervisorVendorInfo->HypervisorVendorId; -error_handler: - return Status; + FreePool (HypervisorVendorInfo); + + return EFI_SUCCESS; } /** Update the Fixed Feature Flags in the FADT Table. @@ -415,38 +323,17 @@ error_handler: STATIC EFI_STATUS EFIAPI -FadtAddFixedFeatureFlags ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol -) +FadtAddFixedFeatureFlags (VOID) { EFI_STATUS Status; CM_ARM_FIXED_FEATURE_FLAGS * FixedFeatureFlags; - ASSERT (CfgMgrProtocol != NULL); - // Get the Fixed feature flags from the Platform Configuration Manager - Status = GetEArmObjFixedFeatureFlags ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &FixedFeatureFlags, - NULL - ); + + Status = CfgMgrGetSimpleObject ( + EArmObjFixedFeatureFlags, (VOID **)&FixedFeatureFlags); if (EFI_ERROR (Status)) { - if (Status == EFI_NOT_FOUND) { - DEBUG (( - DEBUG_INFO, - "INFO: FADT: Platform does not define additional Fixed feature flags." - "Status = %r\n", - Status - )); - } else { - DEBUG (( - DEBUG_ERROR, - "ERROR: FADT: Failed to get Fixed feature flags. Status = %r\n", - Status - )); - } - goto error_handler; + return Status; } DEBUG (( @@ -467,8 +354,9 @@ FadtAddFixedFeatureFlags ( AcpiFadt.Flags |= (FixedFeatureFlags->Flags & VALID_HARDWARE_REDUCED_FLAG_MASK); -error_handler: - return Status; + FreePool (FixedFeatureFlags); + + return EFI_SUCCESS; } /** Construct the FADT table. @@ -507,7 +395,6 @@ BuildFadtTable ( ASSERT (This != NULL); ASSERT (AcpiTableInfo != NULL); - ASSERT (CfgMgrProtocol != NULL); ASSERT (Table != NULL); ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID); ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature); @@ -533,30 +420,25 @@ BuildFadtTable ( AcpiTableInfo, sizeof (EFI_ACPI_6_3_FIXED_ACPI_DESCRIPTION_TABLE)); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: FADT: Failed to add ACPI header. Status = %r\n", - Status - )); return Status; } // Update PmProfile Info - Status = FadtAddPmProfileInfo (CfgMgrProtocol); + Status = FadtAddPmProfileInfo (); if (EFI_ERROR (Status)) { - goto error_handler; + return Status; } // Update BootArch Info - Status = FadtAddBootArchInfo (CfgMgrProtocol); + Status = FadtAddBootArchInfo (); if (EFI_ERROR (Status)) { - goto error_handler; + return Status; } // Add the Hypervisor Vendor Id if present // Note if no hypervisor is present the zero bytes // will be placed in this field. - Status = FadtAddHypervisorVendorId (CfgMgrProtocol); + Status = FadtAddHypervisorVendorId (); if (EFI_ERROR (Status)) { if (Status == EFI_NOT_FOUND) { DEBUG (( @@ -570,11 +452,11 @@ BuildFadtTable ( "ERROR: FADT: Error reading Hypervisor Vendor ID, Status = %r", Status )); - goto error_handler; + return Status; } } - Status = FadtAddFixedFeatureFlags (CfgMgrProtocol); + Status = FadtAddFixedFeatureFlags (); if (EFI_ERROR (Status)) { if (Status == EFI_NOT_FOUND) { DEBUG (( @@ -582,20 +464,19 @@ BuildFadtTable ( "INFO: FADT: No Fixed feature flags found," \ " assuming no additional flags are defined for the platform.\n" )); - Status = EFI_SUCCESS; } else { DEBUG (( DEBUG_ERROR, "ERROR: FADT: Error reading Fixed feature flags, Status = %r", Status )); - goto error_handler; + return Status; } } - *Table = (EFI_ACPI_DESCRIPTION_HEADER*)&AcpiFadt; -error_handler: - return Status; + *Table = (EFI_ACPI_DESCRIPTION_HEADER *) &AcpiFadt; + + return EFI_SUCCESS; } /** This macro defines the FADT Table Generator revision. diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c index 4af410fb5b..119265187a 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c @@ -17,7 +17,6 @@ // Module specific include files. #include <AcpiTableGenerator.h> #include <ConfigurationManagerObject.h> -#include <ConfigurationManagerHelper.h> #include <Library/TableHelperLib.h> #include <Protocol/ConfigurationManagerProtocol.h> @@ -32,49 +31,11 @@ Requirements: - EArmObjGTBlockTimerFrameInfo (OPTIONAL) */ -/** This macro expands to a function that retrieves the Generic - Timer Information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjGenericTimerInfo, - CM_ARM_GENERIC_TIMER_INFO - ); - -/** This macro expands to a function that retrieves the SBSA Generic - Watchdog Timer Information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjPlatformGenericWatchdogInfo, - CM_ARM_GENERIC_WATCHDOG_INFO - ); - -/** This macro expands to a function that retrieves the Platform Generic - Timer Block Information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjPlatformGTBlockInfo, - CM_ARM_GTBLOCK_INFO - ); - -/** This macro expands to a function that retrieves the Generic - Timer Block Timer Frame Information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjGTBlockTimerFrameInfo, - CM_ARM_GTBLOCK_TIMER_FRAME_INFO - ); - /** Add the Generic Timer Information to the GTDT table. Also update the Platform Timer offset information if the platform implements platform timers. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. @param [in] Gtdt Pointer to the GTDT Table. @param [in] PlatformTimerCount Platform timer count. @param [in] AcpiTableRevision Acpi Revision targeted by the platform. @@ -90,7 +51,6 @@ STATIC EFI_STATUS EFIAPI AddGenericTimerInfo ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN EFI_ACPI_6_3_GENERIC_TIMER_DESCRIPTION_TABLE * CONST Gtdt, IN CONST UINT32 PlatformTimerCount, IN CONST UINT32 AcpiTableRevision @@ -99,24 +59,13 @@ AddGenericTimerInfo ( EFI_STATUS Status; CM_ARM_GENERIC_TIMER_INFO * GenericTimerInfo; - ASSERT (CfgMgrProtocol != NULL); - ASSERT (Gtdt != NULL); - - Status = GetEArmObjGenericTimerInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &GenericTimerInfo, - NULL - ); + ASSERT (Gtdt != NULL); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: GTDT: Failed to get GenericTimerInfo. Status = %r\n", - Status - )); - return Status; - } + Status = CfgMgrGetSimpleObject ( + EArmObjGenericTimerInfo, (VOID **)&GenericTimerInfo); + if (EFI_ERROR (Status)) { + return Status; + } Gtdt->CntControlBasePhysicalAddress = GenericTimerInfo->CounterControlBaseAddress; @@ -140,7 +89,9 @@ AddGenericTimerInfo ( Gtdt->VirtualPL2TimerFlags = GenericTimerInfo->VirtualPL2TimerFlags; } - return Status; + FreePool (GenericTimerInfo); + + return EFI_SUCCESS; } /** Add the SBSA Generic Watchdog Timers to the GTDT table. @@ -148,26 +99,36 @@ AddGenericTimerInfo ( @param [in] Gtdt Pointer to the GTDT Table. @param [in] WatchdogOffset Offset to the watchdog information in the GTDT Table. - @param [in] WatchdogInfoList Pointer to the watchdog information list. - @param [in] WatchdogCount Platform timer count. **/ STATIC VOID AddGenericWatchdogList ( IN EFI_ACPI_6_3_GENERIC_TIMER_DESCRIPTION_TABLE * CONST Gtdt, - IN CONST UINT32 WatchdogOffset, - IN CONST CM_ARM_GENERIC_WATCHDOG_INFO * WatchdogInfoList, - IN UINT32 WatchdogCount + IN CONST UINT32 WatchdogOffset ) { EFI_ACPI_6_3_GTDT_SBSA_GENERIC_WATCHDOG_STRUCTURE * Watchdog; + UINT32 WatchdogCount; + VOID *WatchdogInfoList; + CM_ARM_GENERIC_WATCHDOG_INFO *Cursor; + EFI_STATUS Status; ASSERT (Gtdt != NULL); - ASSERT (WatchdogInfoList != NULL); + + Status = CfgMgrGetObjects ( + EArmObjPlatformGenericWatchdogInfo, + CM_NULL_TOKEN, + &WatchdogInfoList, + &WatchdogCount); + + if (EFI_ERROR(Status)) { + return; + } Watchdog = (EFI_ACPI_6_3_GTDT_SBSA_GENERIC_WATCHDOG_STRUCTURE *) ((UINT8*)Gtdt + WatchdogOffset); + Cursor = WatchdogInfoList; while (WatchdogCount-- != 0) { // Add watchdog entry DEBUG ((DEBUG_INFO, "GTDT: Watchdog = 0x%p\n", Watchdog)); @@ -176,14 +137,16 @@ AddGenericWatchdogList ( sizeof (EFI_ACPI_6_3_GTDT_SBSA_GENERIC_WATCHDOG_STRUCTURE); Watchdog->Reserved = EFI_ACPI_RESERVED_BYTE; Watchdog->RefreshFramePhysicalAddress = - WatchdogInfoList->RefreshFrameAddress; + Cursor->RefreshFrameAddress; Watchdog->WatchdogControlFramePhysicalAddress = - WatchdogInfoList->ControlFrameAddress; - Watchdog->WatchdogTimerGSIV = WatchdogInfoList->TimerGSIV; - Watchdog->WatchdogTimerFlags = WatchdogInfoList->Flags; + Cursor->ControlFrameAddress; + Watchdog->WatchdogTimerGSIV = Cursor->TimerGSIV; + Watchdog->WatchdogTimerFlags = Cursor->Flags; Watchdog++; - WatchdogInfoList++; + Cursor++; } // for + + FreePool (WatchdogInfoList); } /** @@ -313,8 +276,6 @@ AddGTBlockTimerFrames ( /** Add the GT Block Timers in the GTDT Table. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. @param [in] Gtdt Pointer to the GTDT Table. @param [in] GTBlockOffset Offset of the GT Block information in the GTDT Table. @@ -328,7 +289,6 @@ AddGTBlockTimerFrames ( STATIC EFI_STATUS AddGTBlockList ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN EFI_ACPI_6_3_GENERIC_TIMER_DESCRIPTION_TABLE * CONST Gtdt, IN CONST UINT32 GTBlockOffset, IN CONST CM_ARM_GTBLOCK_INFO * GTBlockInfo, @@ -351,12 +311,11 @@ AddGTBlockList ( while (BlockTimerCount-- != 0) { DEBUG ((DEBUG_INFO, "GTDT: GTBlock = 0x%p\n", GTBlock)); - Status = GetEArmObjGTBlockTimerFrameInfo ( - CfgMgrProtocol, - GTBlockInfo->GTBlockTimerFrameToken, - >BlockTimerFrameList, - >BlockTimerFrameCount - ); + Status = CfgMgrGetObjects ( + EArmObjGTBlockTimerFrameInfo, + GTBlockInfo->GTBlockTimerFrameToken, + NULL, + >BlockTimerFrameCount); if (EFI_ERROR (Status) || (GTBlockTimerFrameCount != GTBlockInfo->GTBlockTimerFrameCount)) { DEBUG (( @@ -397,18 +356,20 @@ AddGTBlockList ( GtBlockFrame = (EFI_ACPI_6_3_GTDT_GT_BLOCK_TIMER_STRUCTURE*) ((UINT8*)GTBlock + GTBlock->GTBlockTimerOffset); + CfgMgrGetObjects ( + EArmObjGTBlockTimerFrameInfo, + GTBlockInfo->GTBlockTimerFrameToken, + (VOID **)>BlockTimerFrameList, + >BlockTimerFrameCount); + // Add GT Block Timer frames Status = AddGTBlockTimerFrames ( GtBlockFrame, GTBlockTimerFrameList, GTBlockTimerFrameCount ); + FreePool (GTBlockTimerFrameList); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: GTDT: Failed to add Generic Timer Frames. Status = %r\n", - Status - )); return Status; } @@ -458,7 +419,6 @@ BuildGtdtTable ( UINT32 PlatformTimerCount; UINT32 WatchdogCount; UINT32 BlockTimerCount; - CM_ARM_GENERIC_WATCHDOG_INFO * WatchdogInfoList; CM_ARM_GTBLOCK_INFO * GTBlockInfo; EFI_ACPI_6_3_GENERIC_TIMER_DESCRIPTION_TABLE * Gtdt; UINT32 Idx; @@ -467,7 +427,6 @@ BuildGtdtTable ( ASSERT (This != NULL); ASSERT (AcpiTableInfo != NULL); - ASSERT (CfgMgrProtocol != NULL); ASSERT (Table != NULL); ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID); ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature); @@ -485,46 +444,15 @@ BuildGtdtTable ( return EFI_INVALID_PARAMETER; } - *Table = NULL; - Status = GetEArmObjPlatformGTBlockInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - >BlockInfo, - &BlockTimerCount - ); - if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: GTDT: Failed to Get Platform GT Block Information." \ - " Status = %r\n", - Status - )); - goto error_handler; - } - - Status = GetEArmObjPlatformGenericWatchdogInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &WatchdogInfoList, - &WatchdogCount - ); + Status = CfgMgrGetObjects ( + EArmObjPlatformGTBlockInfo, + CM_NULL_TOKEN, + (VOID **)>BlockInfo, + &BlockTimerCount); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: GTDT: Failed to Get Platform Generic Watchdog Information." \ - " Status = %r\n", - Status - )); - goto error_handler; + return Status; } - DEBUG (( - DEBUG_INFO, - "GTDT: BlockTimerCount = %d, WatchdogCount = %d\n", - BlockTimerCount, - WatchdogCount - )); - // Calculate the GTDT Table Size PlatformTimerCount = 0; TableSize = sizeof (EFI_ACPI_6_3_GENERIC_TIMER_DESCRIPTION_TABLE); @@ -558,6 +486,20 @@ BuildGtdtTable ( )); } + WatchdogCount = 0; + Status = CfgMgrCountObjects ( + EArmObjPlatformGenericWatchdogInfo, &WatchdogCount); + if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { + goto error_handler; + } + + DEBUG (( + DEBUG_INFO, + "GTDT: BlockTimerCount = %d, WatchdogCount = %d\n", + BlockTimerCount, + WatchdogCount + )); + WatchdogOffset = 0; if (WatchdogCount != 0) { WatchdogOffset = TableSize; @@ -572,20 +514,12 @@ BuildGtdtTable ( )); } - *Table = (EFI_ACPI_DESCRIPTION_HEADER*)AllocateZeroPool (TableSize); - if (*Table == NULL) { + Gtdt = AllocateZeroPool (TableSize); + if (Gtdt == NULL) { Status = EFI_OUT_OF_RESOURCES; - DEBUG (( - DEBUG_ERROR, - "ERROR: GTDT: Failed to allocate memory for GTDT Table, Size = %d," \ - " Status = %r\n", - TableSize, - Status - )); goto error_handler; } - Gtdt = (EFI_ACPI_6_3_GENERIC_TIMER_DESCRIPTION_TABLE*)*Table; DEBUG (( DEBUG_INFO, "GTDT: Gtdt = 0x%p TableSize = 0x%x\n", @@ -595,20 +529,11 @@ BuildGtdtTable ( Status = AddAcpiHeader (This, &Gtdt->Header, AcpiTableInfo, TableSize); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: GTDT: Failed to add ACPI header. Status = %r\n", - Status - )); goto error_handler; } Status = AddGenericTimerInfo ( - CfgMgrProtocol, - Gtdt, - PlatformTimerCount, - AcpiTableInfo->AcpiTableRevision - ); + Gtdt, PlatformTimerCount, AcpiTableInfo->AcpiTableRevision); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -619,13 +544,7 @@ BuildGtdtTable ( } if (BlockTimerCount != 0) { - Status = AddGTBlockList ( - CfgMgrProtocol, - Gtdt, - GTBlockOffset, - GTBlockInfo, - BlockTimerCount - ); + Status = AddGTBlockList (Gtdt, GTBlockOffset, GTBlockInfo, BlockTimerCount); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -637,21 +556,19 @@ BuildGtdtTable ( } if (WatchdogCount != 0) { - AddGenericWatchdogList ( - Gtdt, - WatchdogOffset, - WatchdogInfoList, - WatchdogCount - ); + AddGenericWatchdogList (Gtdt, WatchdogOffset); } + FreePool (GTBlockInfo); + + *Table = (EFI_ACPI_DESCRIPTION_HEADER *)Gtdt; return Status; error_handler: - if (*Table != NULL) { - FreePool (*Table); - *Table = NULL; + if (Gtdt != NULL) { + FreePool (Gtdt); } + FreePool (GTBlockInfo); return Status; } @@ -677,7 +594,6 @@ FreeGtdtTableResources ( { ASSERT (This != NULL); ASSERT (AcpiTableInfo != NULL); - ASSERT (CfgMgrProtocol != NULL); ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID); ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature); diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c index 97f86ddb30..dc518238c7 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c @@ -20,7 +20,6 @@ // Module specific include files. #include <AcpiTableGenerator.h> #include <ConfigurationManagerObject.h> -#include <ConfigurationManagerHelper.h> #include <Library/TableHelperLib.h> #include <Protocol/ConfigurationManagerProtocol.h> @@ -42,244 +41,82 @@ Requirements: - EArmObjGicItsIdentifierArray */ -/** This macro expands to a function that retrieves the ITS - Group node information from the Configuration Manager. +/* + Function type that evaluates the size of a node and sets + the node pointer to the next node. Used in iteration over + node lists. */ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjItsGroup, - CM_ARM_ITS_GROUP_NODE - ); - -/** This macro expands to a function that retrieves the - Named Component node information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjNamedComponent, - CM_ARM_NAMED_COMPONENT_NODE - ); - -/** This macro expands to a function that retrieves the - Root Complex node information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjRootComplex, - CM_ARM_ROOT_COMPLEX_NODE - ); - -/** This macro expands to a function that retrieves the - SMMU v1/v2 node information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjSmmuV1SmmuV2, - CM_ARM_SMMUV1_SMMUV2_NODE - ); - -/** This macro expands to a function that retrieves the - SMMU v3 node information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjSmmuV3, - CM_ARM_SMMUV3_NODE - ); - -/** This macro expands to a function that retrieves the - PMCG node information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjPmcg, - CM_ARM_PMCG_NODE - ); - -/** This macro expands to a function that retrieves the - ITS Identifier Array information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjGicItsIdentifierArray, - CM_ARM_ITS_IDENTIFIER - ); - -/** This macro expands to a function that retrieves the - Id Mapping Array information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjIdMappingArray, - CM_ARM_ID_MAPPING - ); - -/** This macro expands to a function that retrieves the - SMMU Interrupt Array information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjSmmuInterruptArray, - CM_ARM_SMMU_INTERRUPT - ); +typedef UINT32 (EFIAPI *INDEX_NODE)(VOID ** Node); -/** Returns the size of the ITS Group node. - - @param [in] Node Pointer to ITS Group node. +/** Returns the size of the ITS Group node, increments + to the next node. + @param [in,out] Ptr Pointer to ITS Group node. @retval Size of the ITS Group Node. **/ STATIC UINT32 GetItsGroupNodeSize ( - IN CONST CM_ARM_ITS_GROUP_NODE * Node + IN OUT VOID ** Ptr ) { - ASSERT (Node != NULL); + ASSERT (Ptr != NULL && *Ptr != NULL); + + CM_ARM_ITS_GROUP_NODE *Node = *Ptr; + *Ptr = Node + 1; /* Size of ITS Group Node + Size of ITS Identifier array */ - return (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE) + - (Node->ItsIdCount * sizeof (UINT32))); -} - -/** Returns the total size required for the ITS Group nodes and - updates the Node Indexer. - - This function calculates the size required for the node group - and also populates the Node Indexer array with offsets for the - individual nodes. - - @param [in] NodeStartOffset Offset from the start of the - IORT where this node group starts. - @param [in] NodeList Pointer to ITS Group node list. - @param [in] NodeCount Count of the ITS Group nodes. - @param [in, out] NodeIndexer Pointer to the next Node Indexer. - - @retval Total size of the ITS Group Nodes. -**/ -STATIC -UINT64 -GetSizeofItsGroupNodes ( - IN CONST UINT32 NodeStartOffset, - IN CONST CM_ARM_ITS_GROUP_NODE * NodeList, - IN UINT32 NodeCount, - IN OUT IORT_NODE_INDEXER ** CONST NodeIndexer - ) -{ - UINT64 Size; - - ASSERT (NodeList != NULL); - - Size = 0; - while (NodeCount-- != 0) { - (*NodeIndexer)->Token = NodeList->Token; - (*NodeIndexer)->Object = (VOID*)NodeList; - (*NodeIndexer)->Offset = (UINT32)(Size + NodeStartOffset); - DEBUG (( - DEBUG_INFO, - "IORT: Node Indexer = %p, Token = %p, Object = %p, Offset = 0x%x\n", - *NodeIndexer, - (*NodeIndexer)->Token, - (*NodeIndexer)->Object, - (*NodeIndexer)->Offset - )); - - Size += GetItsGroupNodeSize (NodeList); - (*NodeIndexer)++; - NodeList++; - } - return Size; + return (UINT32) ( + sizeof (EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE) + + (Node->ItsIdCount) * sizeof (UINT32)); } -/** Returns the size of the Named Component node. - - @param [in] Node Pointer to Named Component node. +/** Returns the size of the Named Component node and + point to the next node + @param [in,out] Ptr Pointer to Named Component node. @retval Size of the Named Component node. **/ STATIC UINT32 GetNamedComponentNodeSize ( - IN CONST CM_ARM_NAMED_COMPONENT_NODE * Node + IN OUT VOID ** Ptr ) { - ASSERT (Node != NULL); + ASSERT (Ptr != NULL && *Ptr != NULL); + + CM_ARM_NAMED_COMPONENT_NODE * Node = *Ptr; + *Ptr = Node + 1; /* Size of Named Component node + Size of ID mapping array + Size of ASCII string + 'padding to 32-bit word aligned'. */ + return (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_NAMED_COMP_NODE) + - (Node->IdMappingCount * + ((Node->IdMappingCount * sizeof (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE)) + - ALIGN_VALUE (AsciiStrSize (Node->ObjectName), 4)); -} - -/** Returns the total size required for the Named Component nodes and - updates the Node Indexer. - - This function calculates the size required for the node group - and also populates the Node Indexer array with offsets for the - individual nodes. - - @param [in] NodeStartOffset Offset from the start of the - IORT where this node group starts. - @param [in] NodeList Pointer to Named Component node list. - @param [in] NodeCount Count of the Named Component nodes. - @param [in, out] NodeIndexer Pointer to the next Node Indexer. - - @retval Total size of the Named Component nodes. -**/ -STATIC -UINT64 -GetSizeofNamedComponentNodes ( - IN CONST UINT32 NodeStartOffset, - IN CONST CM_ARM_NAMED_COMPONENT_NODE * NodeList, - IN UINT32 NodeCount, - IN OUT IORT_NODE_INDEXER ** CONST NodeIndexer - ) -{ - UINT64 Size; - - ASSERT (NodeList != NULL); - - Size = 0; - while (NodeCount-- != 0) { - (*NodeIndexer)->Token = NodeList->Token; - (*NodeIndexer)->Object = (VOID*)NodeList; - (*NodeIndexer)->Offset = (UINT32)(Size + NodeStartOffset); - DEBUG (( - DEBUG_INFO, - "IORT: Node Indexer = %p, Token = %p, Object = %p, Offset = 0x%x\n", - *NodeIndexer, - (*NodeIndexer)->Token, - (*NodeIndexer)->Object, - (*NodeIndexer)->Offset - )); - - Size += GetNamedComponentNodeSize (NodeList); - (*NodeIndexer)++; - NodeList++; - } - - return Size; + ALIGN_VALUE (AsciiStrSize (Node->ObjectName), 4))); } -/** Returns the size of the Root Complex node. - - @param [in] Node Pointer to Root Complex node. +/** Returns the size of the Root Complex node and point + to the next node. + @param [in,out] Ptr Pointer to Root Complex node. @retval Size of the Root Complex node. **/ STATIC UINT32 GetRootComplexNodeSize ( - IN CONST CM_ARM_ROOT_COMPLEX_NODE * Node + IN OUT VOID ** Ptr ) { - ASSERT (Node != NULL); + ASSERT (Ptr != NULL && *Ptr != NULL); + + CM_ARM_ROOT_COMPLEX_NODE *Node = *Ptr; + *Ptr = Node + 1; /* Size of Root Complex node + Size of ID mapping array @@ -289,69 +126,22 @@ GetRootComplexNodeSize ( sizeof (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE))); } -/** Returns the total size required for the Root Complex nodes and - updates the Node Indexer. - - This function calculates the size required for the node group - and also populates the Node Indexer array with offsets for the - individual nodes. - - @param [in] NodeStartOffset Offset from the start of the - IORT where this node group starts. - @param [in] NodeList Pointer to Root Complex node list. - @param [in] NodeCount Count of the Root Complex nodes. - @param [in, out] NodeIndexer Pointer to the next Node Indexer. - - @retval Total size of the Root Complex nodes. -**/ -STATIC -UINT64 -GetSizeofRootComplexNodes ( - IN CONST UINT32 NodeStartOffset, - IN CONST CM_ARM_ROOT_COMPLEX_NODE * NodeList, - IN UINT32 NodeCount, - IN OUT IORT_NODE_INDEXER ** CONST NodeIndexer - ) -{ - UINT64 Size; - - ASSERT (NodeList != NULL); - - Size = 0; - while (NodeCount-- != 0) { - (*NodeIndexer)->Token = NodeList->Token; - (*NodeIndexer)->Object = (VOID*)NodeList; - (*NodeIndexer)->Offset = (UINT32)(Size + NodeStartOffset); - DEBUG (( - DEBUG_INFO, - "IORT: Node Indexer = %p, Token = %p, Object = %p, Offset = 0x%x\n", - *NodeIndexer, - (*NodeIndexer)->Token, - (*NodeIndexer)->Object, - (*NodeIndexer)->Offset - )); - - Size += GetRootComplexNodeSize (NodeList); - (*NodeIndexer)++; - NodeList++; - } - - return Size; -} - -/** Returns the size of the SMMUv1/SMMUv2 node. - - @param [in] Node Pointer to SMMUv1/SMMUv2 node list. +/** Returns the size of the SMMUv1/SMMUv2 node and point + to the next node. + @param [in,out] Ptr Pointer to SMMUv1/SMMUv2 node list. @retval Size of the SMMUv1/SMMUv2 node. **/ STATIC UINT32 GetSmmuV1V2NodeSize ( - IN CONST CM_ARM_SMMUV1_SMMUV2_NODE * Node + IN OUT VOID **Ptr ) { - ASSERT (Node != NULL); + ASSERT (Ptr != NULL && *Ptr != NULL); + + CM_ARM_SMMUV1_SMMUV2_NODE * Node = *Ptr; + *Ptr = Node + 1; /* Size of SMMU v1/SMMU v2 node + Size of ID mapping array + @@ -367,68 +157,22 @@ GetSmmuV1V2NodeSize ( sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT))); } -/** Returns the total size required for the SMMUv1/SMMUv2 nodes and - updates the Node Indexer. - - This function calculates the size required for the node group - and also populates the Node Indexer array with offsets for the - individual nodes. - - @param [in] NodeStartOffset Offset from the start of the - IORT where this node group starts. - @param [in] NodeList Pointer to SMMUv1/SMMUv2 node list. - @param [in] NodeCount Count of the SMMUv1/SMMUv2 nodes. - @param [in, out] NodeIndexer Pointer to the next Node Indexer. - - @retval Total size of the SMMUv1/SMMUv2 nodes. -**/ -STATIC -UINT64 -GetSizeofSmmuV1V2Nodes ( - IN CONST UINT32 NodeStartOffset, - IN CONST CM_ARM_SMMUV1_SMMUV2_NODE * NodeList, - IN UINT32 NodeCount, - IN OUT IORT_NODE_INDEXER ** CONST NodeIndexer - ) -{ - UINT64 Size; - - ASSERT (NodeList != NULL); - - Size = 0; - while (NodeCount-- != 0) { - (*NodeIndexer)->Token = NodeList->Token; - (*NodeIndexer)->Object = (VOID*)NodeList; - (*NodeIndexer)->Offset = (UINT32)(Size + NodeStartOffset); - DEBUG (( - DEBUG_INFO, - "IORT: Node Indexer = %p, Token = %p, Object = %p, Offset = 0x%x\n", - *NodeIndexer, - (*NodeIndexer)->Token, - (*NodeIndexer)->Object, - (*NodeIndexer)->Offset - )); - - Size += GetSmmuV1V2NodeSize (NodeList); - (*NodeIndexer)++; - NodeList++; - } - return Size; -} - -/** Returns the size of the SMMUv3 node. - - @param [in] Node Pointer to SMMUv3 node list. +/** Returns the size of the SMMUv3 node and point to the next + node. + @param [in,out] Ptr Pointer to SMMUv3 node list. @retval Total size of the SMMUv3 nodes. **/ STATIC UINT32 GetSmmuV3NodeSize ( - IN CONST CM_ARM_SMMUV3_NODE * Node + IN OUT VOID ** Ptr ) { - ASSERT (Node != NULL); + ASSERT (Ptr != NULL && *Ptr != NULL); + + CM_ARM_SMMUV3_NODE *Node = *Ptr; + *Ptr = Node + 1; /* Size of SMMU v1/SMMU v2 node + Size of ID mapping array @@ -438,68 +182,22 @@ GetSmmuV3NodeSize ( sizeof (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE))); } -/** Returns the total size required for the SMMUv3 nodes and - updates the Node Indexer. - - This function calculates the size required for the node group - and also populates the Node Indexer array with offsets for the - individual nodes. - - @param [in] NodeStartOffset Offset from the start of the - IORT where this node group starts. - @param [in] NodeList Pointer to SMMUv3 node list. - @param [in] NodeCount Count of the SMMUv3 nodes. - @param [in, out] NodeIndexer Pointer to the next Node Indexer. - - @retval Total size of the SMMUv3 nodes. -**/ -STATIC -UINT64 -GetSizeofSmmuV3Nodes ( - IN CONST UINT32 NodeStartOffset, - IN CONST CM_ARM_SMMUV3_NODE * NodeList, - IN UINT32 NodeCount, - IN OUT IORT_NODE_INDEXER ** CONST NodeIndexer - ) -{ - UINT64 Size; - - ASSERT (NodeList != NULL); - - Size = 0; - while (NodeCount-- != 0) { - (*NodeIndexer)->Token = NodeList->Token; - (*NodeIndexer)->Object = (VOID*)NodeList; - (*NodeIndexer)->Offset = (UINT32)(Size + NodeStartOffset); - DEBUG (( - DEBUG_INFO, - "IORT: Node Indexer = %p, Token = %p, Object = %p, Offset = 0x%x\n", - *NodeIndexer, - (*NodeIndexer)->Token, - (*NodeIndexer)->Object, - (*NodeIndexer)->Offset - )); - - Size += GetSmmuV3NodeSize (NodeList); - (*NodeIndexer)++; - NodeList++; - } - return Size; -} - -/** Returns the size of the PMCG node. - - @param [in] Node Pointer to PMCG node. +/** Returns the size of the PMCG node and point to the next + node. + @param [in,out] Ptr Pointer to PMCG node. @retval Size of the PMCG node. **/ STATIC UINT32 GetPmcgNodeSize ( - IN CONST CM_ARM_PMCG_NODE * Node + IN OUT VOID ** Ptr ) { - ASSERT (Node != NULL); + ASSERT (Ptr != NULL && *Ptr != NULL); + + CM_ARM_PMCG_NODE * Node = *Ptr; + *Ptr = Node + 1; /* Size of PMCG node + Size of ID mapping array @@ -509,38 +207,49 @@ GetPmcgNodeSize ( sizeof (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE))); } -/** Returns the total size required for the PMCG nodes and - updates the Node Indexer. +/** Returns the total size required for a group of IORT nodes. The configuration + manager objects specified by object id must contain CM_OBJECT_TOKEN as + their first field. This function calculates the size required for the node group and also populates the Node Indexer array with offsets for the individual nodes. + @param [in] ObjectId The configuration manager object id of + nodes that are to be summed. @param [in] NodeStartOffset Offset from the start of the IORT where this node group starts. - @param [in] NodeList Pointer to PMCG node list. - @param [in] NodeCount Count of the PMCG nodes. @param [in, out] NodeIndexer Pointer to the next Node Indexer. + @param [in] GetNodeSize The function to determine the size of a single node + of the appropriate type determined by object id. - @retval Total size of the PMCG nodes. + @retval Total size of the group of nodes **/ STATIC UINT64 -GetSizeofPmcgNodes ( - IN CONST UINT32 NodeStartOffset, - IN CONST CM_ARM_PMCG_NODE * NodeList, - IN UINT32 NodeCount, - IN OUT IORT_NODE_INDEXER ** CONST NodeIndexer +GetSizeOfNodes ( + IN CONST CM_OBJECT_ID ObjectId, + IN CONST UINT32 NodeStartOffset, + IN OUT IORT_NODE_INDEXER ** CONST NodeIndexer, + IN CONST INDEX_NODE IndexNode ) { - UINT64 Size; - - ASSERT (NodeList != NULL); + UINT64 Size; + EFI_STATUS Status; + VOID *NodeList; + UINT32 NodeCount; + VOID *Cursor; + + Status = CfgMgrGetObjects (ObjectId, CM_NULL_TOKEN, &NodeList, &NodeCount); + if (EFI_ERROR(Status)) { + return 0; + } + Cursor = NodeList; Size = 0; while (NodeCount-- != 0) { - (*NodeIndexer)->Token = NodeList->Token; - (*NodeIndexer)->Object = (VOID*)NodeList; + (*NodeIndexer)->Token = *(CM_OBJECT_TOKEN *) Cursor; // CM_OBJECT_TOKEN is always the first element of a node + (*NodeIndexer)->Object = Cursor; (*NodeIndexer)->Offset = (UINT32)(Size + NodeStartOffset); DEBUG (( DEBUG_INFO, @@ -551,10 +260,11 @@ GetSizeofPmcgNodes ( (*NodeIndexer)->Offset )); - Size += GetPmcgNodeSize (NodeList); + Size += IndexNode (&Cursor); (*NodeIndexer)++; - NodeList++; } + + FreePool (NodeList); return Size; } @@ -631,14 +341,14 @@ STATIC EFI_STATUS AddIdMappingArray ( IN CONST ACPI_TABLE_GENERATOR * CONST This, - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE * IdMapArray, IN UINT32 IdCount, IN CONST CM_OBJECT_TOKEN IdMappingToken ) { EFI_STATUS Status; - CM_ARM_ID_MAPPING * IdMappings; + VOID * IdMappings; + CM_ARM_ID_MAPPING * Cursor; UINT32 IdMappingCount; ACPI_IORT_GENERATOR * Generator; @@ -647,18 +357,12 @@ AddIdMappingArray ( Generator = (ACPI_IORT_GENERATOR*)This; // Get the Id Mapping Array - Status = GetEArmObjIdMappingArray ( - CfgMgrProtocol, - IdMappingToken, - &IdMappings, - &IdMappingCount - ); + Status = CfgMgrGetObjects ( + EArmObjIdMappingArray, + IdMappingToken, + &IdMappings, + &IdMappingCount); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: IORT: Failed to get Id Mapping array. Status = %r\n", - Status - )); return Status; } @@ -667,15 +371,17 @@ AddIdMappingArray ( DEBUG_ERROR, "ERROR: IORT: Failed to get the required number of Id Mappings.\n" )); - return EFI_NOT_FOUND; + Status = EFI_NOT_FOUND; + goto EXIT; } + Cursor = IdMappings; // Populate the Id Mapping array while (IdCount-- != 0) { Status = GetNodeOffsetReferencedByToken ( Generator->NodeIndexer, Generator->IortNodeCount, - IdMappings->OutputReferenceToken, + Cursor->OutputReferenceToken, &IdMapArray->OutputReference ); if (EFI_ERROR (Status)) { @@ -684,22 +390,24 @@ AddIdMappingArray ( "ERROR: IORT: Failed to get Output Reference for ITS Identifier array." "Reference Token = %p" " Status = %r\n", - IdMappings->OutputReferenceToken, + Cursor->OutputReferenceToken, Status )); - return Status; + goto EXIT; } - IdMapArray->InputBase = IdMappings->InputBase; - IdMapArray->NumIds = IdMappings->NumIds; - IdMapArray->OutputBase = IdMappings->OutputBase; - IdMapArray->Flags = IdMappings->Flags; + IdMapArray->InputBase = Cursor->InputBase; + IdMapArray->NumIds = Cursor->NumIds; + IdMapArray->OutputBase = Cursor->OutputBase; + IdMapArray->Flags = Cursor->Flags; IdMapArray++; - IdMappings++; + Cursor++; } // Id Mapping array - return EFI_SUCCESS; +EXIT: + FreePool (IdMappings); + return Status; } /** Update the ITS Group Node Information. @@ -722,10 +430,9 @@ STATIC EFI_STATUS AddItsGroupNodes ( IN CONST ACPI_TABLE_GENERATOR * CONST This, - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN CONST EFI_ACPI_6_0_IO_REMAPPING_TABLE * Iort, IN CONST UINT32 NodesStartOffset, - IN CONST CM_ARM_ITS_GROUP_NODE * NodeList, + IN VOID * NodeList, IN UINT32 NodeCount ) { @@ -736,6 +443,7 @@ AddItsGroupNodes ( UINT32 ItsIdentifierCount; UINT32 IdIndex; UINT64 NodeLength; + CM_ARM_ITS_GROUP_NODE *Node; ASSERT (Iort != NULL); @@ -743,7 +451,8 @@ AddItsGroupNodes ( NodesStartOffset); while (NodeCount-- != 0) { - NodeLength = GetItsGroupNodeSize (NodeList); + Node = (CM_ARM_ITS_GROUP_NODE *) NodeList; + NodeLength = GetItsGroupNodeSize (&NodeList); // Advances NodeList if (NodeLength > MAX_UINT16) { Status = EFI_INVALID_PARAMETER; DEBUG (( @@ -765,22 +474,16 @@ AddItsGroupNodes ( ItsGroupNode->Node.IdReference = 0; // IORT specific data - ItsGroupNode->NumItsIdentifiers = NodeList->ItsIdCount; + ItsGroupNode->NumItsIdentifiers = Node->ItsIdCount; ItsIds = (UINT32*)((UINT8*)ItsGroupNode + sizeof (EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE)); - Status = GetEArmObjGicItsIdentifierArray ( - CfgMgrProtocol, - NodeList->ItsIdToken, - &ItsIdentifier, - &ItsIdentifierCount - ); + Status = CfgMgrGetObjects ( + EArmObjGicItsIdentifierArray, + Node->ItsIdToken, + (VOID **)&ItsIdentifier, + &ItsIdentifierCount); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: IORT: Failed to get ITS Identifier array. Status = %r\n", - Status - )); return Status; } @@ -789,7 +492,8 @@ AddItsGroupNodes ( DEBUG_ERROR, "ERROR: IORT: Failed to get the required number of ITS Identifiers.\n" )); - return EFI_NOT_FOUND; + Status = EFI_NOT_FOUND; + goto EXIT; } // Populate the ITS identifier array @@ -800,10 +504,11 @@ AddItsGroupNodes ( // Next IORT Group Node ItsGroupNode = (EFI_ACPI_6_0_IO_REMAPPING_ITS_NODE*)((UINT8*)ItsGroupNode + ItsGroupNode->Node.Length); - NodeList++; } // IORT Group Node - return EFI_SUCCESS; +EXIT: + FreePool (ItsIdentifier); + return Status; } /** Update the Named Component Node Information. @@ -812,8 +517,6 @@ AddItsGroupNodes ( table. @param [in] This Pointer to the table Generator. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. @param [in] Iort Pointer to IORT table structure. @param [in] NodesStartOffset Offset for the start of the Named Component Nodes. @@ -829,10 +532,9 @@ STATIC EFI_STATUS AddNamedComponentNodes ( IN CONST ACPI_TABLE_GENERATOR * CONST This, - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN CONST EFI_ACPI_6_0_IO_REMAPPING_TABLE * Iort, IN CONST UINT32 NodesStartOffset, - IN CONST CM_ARM_NAMED_COMPONENT_NODE * NodeList, + IN VOID * NodeList, IN UINT32 NodeCount ) { @@ -842,6 +544,7 @@ AddNamedComponentNodes ( CHAR8 * ObjectName; UINTN ObjectNameLength; UINT64 NodeLength; + CM_ARM_NAMED_COMPONENT_NODE * Node; ASSERT (Iort != NULL); @@ -849,7 +552,8 @@ AddNamedComponentNodes ( NodesStartOffset); while (NodeCount-- != 0) { - NodeLength = GetNamedComponentNodeSize (NodeList); + Node = (CM_ARM_NAMED_COMPONENT_NODE*) NodeList; + NodeLength = GetNamedComponentNodeSize (&NodeList); // Advances NodeList if (NodeLength > MAX_UINT16) { Status = EFI_INVALID_PARAMETER; DEBUG (( @@ -867,20 +571,20 @@ AddNamedComponentNodes ( NcNode->Node.Length = (UINT16)NodeLength; NcNode->Node.Revision = 2; NcNode->Node.Reserved = EFI_ACPI_RESERVED_DWORD; - NcNode->Node.NumIdMappings = NodeList->IdMappingCount; + NcNode->Node.NumIdMappings = Node->IdMappingCount; - ObjectNameLength = AsciiStrLen (NodeList->ObjectName) + 1; + ObjectNameLength = AsciiStrLen (Node->ObjectName) + 1; NcNode->Node.IdReference = (UINT32)(sizeof (EFI_ACPI_6_0_IO_REMAPPING_NAMED_COMP_NODE) + (ALIGN_VALUE (ObjectNameLength, 4))); // Named Component specific data - NcNode->Flags = NodeList->Flags; - NcNode->CacheCoherent = NodeList->CacheCoherent; - NcNode->AllocationHints = NodeList->AllocationHints; + NcNode->Flags = Node->Flags; + NcNode->CacheCoherent = Node->CacheCoherent; + NcNode->AllocationHints = Node->AllocationHints; NcNode->Reserved = EFI_ACPI_RESERVED_WORD; - NcNode->MemoryAccessFlags = NodeList->MemoryAccessFlags; - NcNode->AddressSizeLimit = NodeList->AddressSizeLimit; + NcNode->MemoryAccessFlags = Node->MemoryAccessFlags; + NcNode->AddressSizeLimit = Node->AddressSizeLimit; // Copy the object name ObjectName = (CHAR8*)((UINT8*)NcNode + @@ -888,7 +592,7 @@ AddNamedComponentNodes ( Status = AsciiStrCpyS ( ObjectName, ObjectNameLength, - NodeList->ObjectName + Node->ObjectName ); if (EFI_ERROR (Status)) { DEBUG (( @@ -899,19 +603,14 @@ AddNamedComponentNodes ( return Status; } - if ((NodeList->IdMappingCount > 0) && - (NodeList->IdMappingToken != CM_NULL_TOKEN)) { + if ((Node->IdMappingCount > 0) && + (Node->IdMappingToken != CM_NULL_TOKEN)) { // Ids for Named Component IdMapArray = (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE*)((UINT8*)NcNode + NcNode->Node.IdReference); Status = AddIdMappingArray ( - This, - CfgMgrProtocol, - IdMapArray, - NodeList->IdMappingCount, - NodeList->IdMappingToken - ); + This, IdMapArray, Node->IdMappingCount, Node->IdMappingToken); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -925,7 +624,6 @@ AddNamedComponentNodes ( // Next Named Component Node NcNode = (EFI_ACPI_6_0_IO_REMAPPING_NAMED_COMP_NODE*)((UINT8*)NcNode + NcNode->Node.Length); - NodeList++; } // Named Component Node return EFI_SUCCESS; @@ -936,8 +634,6 @@ AddNamedComponentNodes ( This function updates the Root Complex node information in the IORT table. @param [in] This Pointer to the table Generator. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. @param [in] Iort Pointer to IORT table structure. @param [in] NodesStartOffset Offset for the start of the Root Complex Nodes. @@ -953,10 +649,9 @@ STATIC EFI_STATUS AddRootComplexNodes ( IN CONST ACPI_TABLE_GENERATOR * CONST This, - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN CONST EFI_ACPI_6_0_IO_REMAPPING_TABLE * Iort, IN CONST UINT32 NodesStartOffset, - IN CONST CM_ARM_ROOT_COMPLEX_NODE * NodeList, + IN VOID * NodeList, IN UINT32 NodeCount ) { @@ -964,6 +659,7 @@ AddRootComplexNodes ( EFI_ACPI_6_0_IO_REMAPPING_RC_NODE * RcNode; EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE * IdMapArray; UINT64 NodeLength; + CM_ARM_ROOT_COMPLEX_NODE * Node; ASSERT (Iort != NULL); @@ -971,7 +667,8 @@ AddRootComplexNodes ( NodesStartOffset); while (NodeCount-- != 0) { - NodeLength = GetRootComplexNodeSize (NodeList); + Node = (CM_ARM_ROOT_COMPLEX_NODE *) NodeList; + NodeLength = GetRootComplexNodeSize (&NodeList); // Advances NodeList if (NodeLength > MAX_UINT16) { Status = EFI_INVALID_PARAMETER; DEBUG (( @@ -989,33 +686,28 @@ AddRootComplexNodes ( RcNode->Node.Length = (UINT16)NodeLength; RcNode->Node.Revision = 1; RcNode->Node.Reserved = EFI_ACPI_RESERVED_DWORD; - RcNode->Node.NumIdMappings = NodeList->IdMappingCount; + RcNode->Node.NumIdMappings = Node->IdMappingCount; RcNode->Node.IdReference = sizeof (EFI_ACPI_6_0_IO_REMAPPING_RC_NODE); // Root Complex specific data - RcNode->CacheCoherent = NodeList->CacheCoherent; - RcNode->AllocationHints = NodeList->AllocationHints; + RcNode->CacheCoherent = Node->CacheCoherent; + RcNode->AllocationHints = Node->AllocationHints; RcNode->Reserved = EFI_ACPI_RESERVED_WORD; - RcNode->MemoryAccessFlags = NodeList->MemoryAccessFlags; - RcNode->AtsAttribute = NodeList->AtsAttribute; - RcNode->PciSegmentNumber = NodeList->PciSegmentNumber; - RcNode->MemoryAddressSize = NodeList->MemoryAddressSize; + RcNode->MemoryAccessFlags = Node->MemoryAccessFlags; + RcNode->AtsAttribute = Node->AtsAttribute; + RcNode->PciSegmentNumber = Node->PciSegmentNumber; + RcNode->MemoryAddressSize = Node->MemoryAddressSize; RcNode->Reserved1[0] = EFI_ACPI_RESERVED_BYTE; RcNode->Reserved1[1] = EFI_ACPI_RESERVED_BYTE; RcNode->Reserved1[2] = EFI_ACPI_RESERVED_BYTE; - if ((NodeList->IdMappingCount > 0) && - (NodeList->IdMappingToken != CM_NULL_TOKEN)) { + if ((Node->IdMappingCount > 0) && + (Node->IdMappingToken != CM_NULL_TOKEN)) { // Ids for Root Complex IdMapArray = (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE*)((UINT8*)RcNode + RcNode->Node.IdReference); Status = AddIdMappingArray ( - This, - CfgMgrProtocol, - IdMapArray, - NodeList->IdMappingCount, - NodeList->IdMappingToken - ); + This, IdMapArray, Node->IdMappingCount, Node->IdMappingToken); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -1029,7 +721,6 @@ AddRootComplexNodes ( // Next Root Complex Node RcNode = (EFI_ACPI_6_0_IO_REMAPPING_RC_NODE*)((UINT8*)RcNode + RcNode->Node.Length); - NodeList++; } // Root Complex Node return EFI_SUCCESS; @@ -1040,8 +731,6 @@ AddRootComplexNodes ( This function retrieves the InterruptArray object referenced by the InterruptToken and updates the SMMU InterruptArray. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. @param [in, out] InterruptArray Pointer to an array of Interrupts. @param [in] InterruptCount Number of entries in the InterruptArray. @param [in] InterruptToken Reference Token for retrieving the SMMU @@ -1054,31 +743,25 @@ AddRootComplexNodes ( STATIC EFI_STATUS AddSmmuInterrruptArray ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN OUT EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT * InterruptArray, IN UINT32 InterruptCount, IN CONST CM_OBJECT_TOKEN InterruptToken ) { EFI_STATUS Status; - CM_ARM_SMMU_INTERRUPT * SmmuInterrupt; + CM_ARM_SMMU_INTERRUPT * Cursor; + VOID * SmmuInterrupt; UINT32 SmmuInterruptCount; ASSERT (InterruptArray != NULL); // Get the SMMU Interrupt Array - Status = GetEArmObjSmmuInterruptArray ( - CfgMgrProtocol, - InterruptToken, - &SmmuInterrupt, - &SmmuInterruptCount - ); + Status = CfgMgrGetObjects ( + EArmObjSmmuInterruptArray, + InterruptToken, + &SmmuInterrupt, + &SmmuInterruptCount); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: IORT: Failed to get SMMU Interrupt array. Status = %r\n", - Status - )); return Status; } @@ -1087,25 +770,27 @@ AddSmmuInterrruptArray ( DEBUG_ERROR, "ERROR: IORT: Failed to get the required number of SMMU Interrupts.\n" )); - return EFI_NOT_FOUND; + Status = EFI_NOT_FOUND; + goto EXIT; } + Cursor = SmmuInterrupt; // Populate the Id Mapping array while (InterruptCount-- != 0) { - InterruptArray->Interrupt = SmmuInterrupt->Interrupt; - InterruptArray->InterruptFlags = SmmuInterrupt->Flags; + InterruptArray->Interrupt = Cursor->Interrupt; + InterruptArray->InterruptFlags = Cursor->Flags; InterruptArray++; - SmmuInterrupt++; + Cursor++; } // Id Mapping array +EXIT: + FreePool (SmmuInterrupt); return EFI_SUCCESS; } /** Update the SMMU v1/v2 Node Information. @param [in] This Pointer to the table Generator. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. @param [in] Iort Pointer to IORT table structure. @param [in] NodesStartOffset Offset for the start of the SMMU v1/v2 Nodes. @@ -1121,10 +806,9 @@ STATIC EFI_STATUS AddSmmuV1V2Nodes ( IN CONST ACPI_TABLE_GENERATOR * CONST This, - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN CONST EFI_ACPI_6_0_IO_REMAPPING_TABLE * Iort, IN CONST UINT32 NodesStartOffset, - IN CONST CM_ARM_SMMUV1_SMMUV2_NODE * NodeList, + IN VOID * NodeList, IN UINT32 NodeCount ) { @@ -1135,6 +819,7 @@ AddSmmuV1V2Nodes ( EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT * ContextInterruptArray; EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT * PmuInterruptArray; UINT64 NodeLength; + CM_ARM_SMMUV1_SMMUV2_NODE * Node; ASSERT (Iort != NULL); @@ -1142,7 +827,8 @@ AddSmmuV1V2Nodes ( NodesStartOffset); while (NodeCount-- != 0) { - NodeLength = GetSmmuV1V2NodeSize (NodeList); + Node = (CM_ARM_SMMUV1_SMMUV2_NODE*) NodeList; + NodeLength = GetSmmuV1V2NodeSize (&NodeList); // Advances NodeList if (NodeLength > MAX_UINT16) { Status = EFI_INVALID_PARAMETER; DEBUG (( @@ -1159,25 +845,25 @@ AddSmmuV1V2Nodes ( SmmuNode->Node.Length = (UINT16)NodeLength; SmmuNode->Node.Revision = 0; SmmuNode->Node.Reserved = EFI_ACPI_RESERVED_DWORD; - SmmuNode->Node.NumIdMappings = NodeList->IdMappingCount; + SmmuNode->Node.NumIdMappings = Node->IdMappingCount; SmmuNode->Node.IdReference = sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU_NODE) + - (NodeList->ContextInterruptCount * + (Node->ContextInterruptCount * sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT)) + - (NodeList->PmuInterruptCount * + (Node->PmuInterruptCount * sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT)); // SMMU v1/v2 specific data - SmmuNode->Base = NodeList->BaseAddress; - SmmuNode->Span = NodeList->Span; - SmmuNode->Model = NodeList->Model; - SmmuNode->Flags = NodeList->Flags; + SmmuNode->Base = Node->BaseAddress; + SmmuNode->Span = Node->Span; + SmmuNode->Model = Node->Model; + SmmuNode->Flags = Node->Flags; // Reference to Global Interrupt Array SmmuNode->GlobalInterruptArrayRef = OFFSET_OF (EFI_ACPI_6_0_IO_REMAPPING_SMMU_NODE, SMMU_NSgIrpt); // Context Interrupt - SmmuNode->NumContextInterrupts = NodeList->ContextInterruptCount; + SmmuNode->NumContextInterrupts = Node->ContextInterruptCount; SmmuNode->ContextInterruptArrayRef = sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU_NODE); ContextInterruptArray = @@ -1185,26 +871,24 @@ AddSmmuV1V2Nodes ( sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU_NODE)); // PMU Interrupt - SmmuNode->NumPmuInterrupts = NodeList->PmuInterruptCount; + SmmuNode->NumPmuInterrupts = Node->PmuInterruptCount; SmmuNode->PmuInterruptArrayRef = SmmuNode->ContextInterruptArrayRef + - (NodeList->ContextInterruptCount * + (Node->ContextInterruptCount * sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT)); PmuInterruptArray = (EFI_ACPI_6_0_IO_REMAPPING_SMMU_INT*)((UINT8*)SmmuNode + SmmuNode->PmuInterruptArrayRef); - SmmuNode->SMMU_NSgIrpt = NodeList->SMMU_NSgIrpt; - SmmuNode->SMMU_NSgIrptFlags = NodeList->SMMU_NSgIrptFlags; - SmmuNode->SMMU_NSgCfgIrpt = NodeList->SMMU_NSgCfgIrpt; - SmmuNode->SMMU_NSgCfgIrptFlags = NodeList->SMMU_NSgCfgIrptFlags; + SmmuNode->SMMU_NSgIrpt = Node->SMMU_NSgIrpt; + SmmuNode->SMMU_NSgIrptFlags = Node->SMMU_NSgIrptFlags; + SmmuNode->SMMU_NSgCfgIrpt = Node->SMMU_NSgCfgIrpt; + SmmuNode->SMMU_NSgCfgIrptFlags = Node->SMMU_NSgCfgIrptFlags; // Add Context Interrupt Array Status = AddSmmuInterrruptArray ( - CfgMgrProtocol, - ContextInterruptArray, - SmmuNode->NumContextInterrupts, - NodeList->ContextInterruptToken - ); + ContextInterruptArray, + SmmuNode->NumContextInterrupts, + Node->ContextInterruptToken); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -1216,13 +900,11 @@ AddSmmuV1V2Nodes ( // Add PMU Interrupt Array if ((SmmuNode->NumPmuInterrupts > 0) && - (NodeList->PmuInterruptToken != CM_NULL_TOKEN)) { + (Node->PmuInterruptToken != CM_NULL_TOKEN)) { Status = AddSmmuInterrruptArray ( - CfgMgrProtocol, - PmuInterruptArray, - SmmuNode->NumPmuInterrupts, - NodeList->PmuInterruptToken - ); + PmuInterruptArray, + SmmuNode->NumPmuInterrupts, + Node->PmuInterruptToken); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -1233,18 +915,13 @@ AddSmmuV1V2Nodes ( } } - if ((NodeList->IdMappingCount > 0) && - (NodeList->IdMappingToken != CM_NULL_TOKEN)) { + if ((Node->IdMappingCount > 0) && + (Node->IdMappingToken != CM_NULL_TOKEN)) { // Ids for SMMU v1/v2 Node IdMapArray = (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE*)((UINT8*)SmmuNode + SmmuNode->Node.IdReference); Status = AddIdMappingArray ( - This, - CfgMgrProtocol, - IdMapArray, - NodeList->IdMappingCount, - NodeList->IdMappingToken - ); + This, IdMapArray, Node->IdMappingCount, Node->IdMappingToken); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -1257,7 +934,6 @@ AddSmmuV1V2Nodes ( // Next SMMU v1/v2 Node SmmuNode = (EFI_ACPI_6_0_IO_REMAPPING_SMMU_NODE*)((UINT8*)SmmuNode + SmmuNode->Node.Length); - NodeList++; } // SMMU v1/v2 Node return EFI_SUCCESS; @@ -1268,8 +944,6 @@ AddSmmuV1V2Nodes ( This function updates the SMMUv3 node information in the IORT table. @param [in] This Pointer to the table Generator. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. @param [in] Iort Pointer to IORT table structure. @param [in] NodesStartOffset Offset for the start of the SMMUv3 Nodes. @param [in] NodeList Pointer to an array of SMMUv3 Node Objects. @@ -1283,10 +957,9 @@ STATIC EFI_STATUS AddSmmuV3Nodes ( IN CONST ACPI_TABLE_GENERATOR * CONST This, - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN CONST EFI_ACPI_6_0_IO_REMAPPING_TABLE * Iort, IN CONST UINT32 NodesStartOffset, - IN CONST CM_ARM_SMMUV3_NODE * NodeList, + IN VOID * NodeList, IN UINT32 NodeCount ) { @@ -1294,6 +967,7 @@ AddSmmuV3Nodes ( EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE * SmmuV3Node; EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE * IdMapArray; UINT64 NodeLength; + CM_ARM_SMMUV3_NODE * Node; ASSERT (Iort != NULL); @@ -1301,7 +975,8 @@ AddSmmuV3Nodes ( NodesStartOffset); while (NodeCount-- != 0) { - NodeLength = GetSmmuV3NodeSize (NodeList); + Node = (CM_ARM_SMMUV3_NODE*) NodeList; + NodeLength = GetSmmuV3NodeSize (&NodeList); // Advances NodeList if (NodeLength > MAX_UINT16) { Status = EFI_INVALID_PARAMETER; DEBUG (( @@ -1318,24 +993,24 @@ AddSmmuV3Nodes ( SmmuV3Node->Node.Length = (UINT16)NodeLength; SmmuV3Node->Node.Revision = 2; SmmuV3Node->Node.Reserved = EFI_ACPI_RESERVED_DWORD; - SmmuV3Node->Node.NumIdMappings = NodeList->IdMappingCount; + SmmuV3Node->Node.NumIdMappings = Node->IdMappingCount; SmmuV3Node->Node.IdReference = sizeof (EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE); // SMMUv3 specific data - SmmuV3Node->Base = NodeList->BaseAddress; - SmmuV3Node->Flags = NodeList->Flags; + SmmuV3Node->Base = Node->BaseAddress; + SmmuV3Node->Flags = Node->Flags; SmmuV3Node->Reserved = EFI_ACPI_RESERVED_WORD; - SmmuV3Node->VatosAddress = NodeList->VatosAddress; - SmmuV3Node->Model = NodeList->Model; - SmmuV3Node->Event = NodeList->EventInterrupt; - SmmuV3Node->Pri = NodeList->PriInterrupt; - SmmuV3Node->Gerr = NodeList->GerrInterrupt; - SmmuV3Node->Sync = NodeList->SyncInterrupt; + SmmuV3Node->VatosAddress = Node->VatosAddress; + SmmuV3Node->Model = Node->Model; + SmmuV3Node->Event = Node->EventInterrupt; + SmmuV3Node->Pri = Node->PriInterrupt; + SmmuV3Node->Gerr = Node->GerrInterrupt; + SmmuV3Node->Sync = Node->SyncInterrupt; if ((SmmuV3Node->Flags & EFI_ACPI_IORT_SMMUv3_FLAG_PROXIMITY_DOMAIN) != 0) { // The Proximity Domain Valid flag is set to 1 - SmmuV3Node->ProximityDomain = NodeList->ProximityDomain; + SmmuV3Node->ProximityDomain = Node->ProximityDomain; } else { SmmuV3Node->ProximityDomain = 0; } @@ -1346,21 +1021,16 @@ AddSmmuV3Nodes ( // the DeviceID mapping index field is ignored. SmmuV3Node->DeviceIdMappingIndex = 0; } else { - SmmuV3Node->DeviceIdMappingIndex = NodeList->DeviceIdMappingIndex; + SmmuV3Node->DeviceIdMappingIndex = Node->DeviceIdMappingIndex; } - if ((NodeList->IdMappingCount > 0) && - (NodeList->IdMappingToken != CM_NULL_TOKEN)) { + if ((Node->IdMappingCount > 0) && + (Node->IdMappingToken != CM_NULL_TOKEN)) { // Ids for SMMUv3 node IdMapArray = (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE*)((UINT8*)SmmuV3Node + SmmuV3Node->Node.IdReference); Status = AddIdMappingArray ( - This, - CfgMgrProtocol, - IdMapArray, - NodeList->IdMappingCount, - NodeList->IdMappingToken - ); + This, IdMapArray, Node->IdMappingCount, Node->IdMappingToken); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -1374,7 +1044,6 @@ AddSmmuV3Nodes ( // Next SMMUv3 Node SmmuV3Node = (EFI_ACPI_6_0_IO_REMAPPING_SMMU3_NODE*)((UINT8*)SmmuV3Node + SmmuV3Node->Node.Length); - NodeList++; } // SMMUv3 Node return EFI_SUCCESS; @@ -1385,8 +1054,6 @@ AddSmmuV3Nodes ( This function updates the PMCG node information in the IORT table. @param [in] This Pointer to the table Generator. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. @param [in] Iort Pointer to IORT table structure. @param [in] NodesStartOffset Offset for the start of the PMCG Nodes. @param [in] NodeList Pointer to an array of PMCG Node Objects. @@ -1400,10 +1067,9 @@ STATIC EFI_STATUS AddPmcgNodes ( IN CONST ACPI_TABLE_GENERATOR * CONST This, - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN CONST EFI_ACPI_6_0_IO_REMAPPING_TABLE * Iort, IN CONST UINT32 NodesStartOffset, - IN CONST CM_ARM_PMCG_NODE * NodeList, + IN VOID * NodeList, IN UINT32 NodeCount ) { @@ -1412,6 +1078,7 @@ AddPmcgNodes ( EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE * IdMapArray; ACPI_IORT_GENERATOR * Generator; UINT64 NodeLength; + CM_ARM_PMCG_NODE * Node; ASSERT (Iort != NULL); @@ -1420,7 +1087,8 @@ AddPmcgNodes ( NodesStartOffset); while (NodeCount-- != 0) { - NodeLength = GetPmcgNodeSize (NodeList); + Node = (CM_ARM_PMCG_NODE*) NodeList; + NodeLength = GetPmcgNodeSize (&NodeList); // Advances NodeList if (NodeLength > MAX_UINT16) { Status = EFI_INVALID_PARAMETER; DEBUG (( @@ -1437,18 +1105,18 @@ AddPmcgNodes ( PmcgNode->Node.Length = (UINT16)NodeLength; PmcgNode->Node.Revision = 1; PmcgNode->Node.Reserved = EFI_ACPI_RESERVED_DWORD; - PmcgNode->Node.NumIdMappings = NodeList->IdMappingCount; + PmcgNode->Node.NumIdMappings = Node->IdMappingCount; PmcgNode->Node.IdReference = sizeof (EFI_ACPI_6_0_IO_REMAPPING_PMCG_NODE); // PMCG specific data - PmcgNode->Base = NodeList->BaseAddress; - PmcgNode->OverflowInterruptGsiv = NodeList->OverflowInterrupt; - PmcgNode->Page1Base = NodeList->Page1BaseAddress; + PmcgNode->Base = Node->BaseAddress; + PmcgNode->OverflowInterruptGsiv = Node->OverflowInterrupt; + PmcgNode->Page1Base = Node->Page1BaseAddress; Status = GetNodeOffsetReferencedByToken ( Generator->NodeIndexer, Generator->IortNodeCount, - NodeList->ReferenceToken, + Node->ReferenceToken, &PmcgNode->NodeReference ); if (EFI_ERROR (Status)) { @@ -1457,25 +1125,20 @@ AddPmcgNodes ( "ERROR: IORT: Failed to get Output Reference for PMCG Node." "Reference Token = %p" " Status = %r\n", - NodeList->ReferenceToken, + Node->ReferenceToken, Status )); return Status; } - if ((NodeList->IdMappingCount > 0) && - (NodeList->IdMappingToken != CM_NULL_TOKEN)) { + if ((Node->IdMappingCount > 0) && + (Node->IdMappingToken != CM_NULL_TOKEN)) { // Ids for PMCG node IdMapArray = (EFI_ACPI_6_0_IO_REMAPPING_ID_TABLE*)((UINT8*)PmcgNode + PmcgNode->Node.IdReference); Status = AddIdMappingArray ( - This, - CfgMgrProtocol, - IdMapArray, - NodeList->IdMappingCount, - NodeList->IdMappingToken - ); + This, IdMapArray, Node->IdMappingCount, Node->IdMappingToken); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -1489,7 +1152,6 @@ AddPmcgNodes ( // Next PMCG Node PmcgNode = (EFI_ACPI_6_0_IO_REMAPPING_PMCG_NODE*)((UINT8*)PmcgNode + PmcgNode->Node.Length); - NodeList++; } // PMCG Node return EFI_SUCCESS; @@ -1547,20 +1209,13 @@ BuildIortTable ( UINT32 SmmuV3Offset; UINT32 PmcgOffset; - CM_ARM_ITS_GROUP_NODE * ItsGroupNodeList; - CM_ARM_NAMED_COMPONENT_NODE * NamedComponentNodeList; - CM_ARM_ROOT_COMPLEX_NODE * RootComplexNodeList; - CM_ARM_SMMUV1_SMMUV2_NODE * SmmuV1V2NodeList; - CM_ARM_SMMUV3_NODE * SmmuV3NodeList; - CM_ARM_PMCG_NODE * PmcgNodeList; - + VOID * NodeList; EFI_ACPI_6_0_IO_REMAPPING_TABLE * Iort; IORT_NODE_INDEXER * NodeIndexer; ACPI_IORT_GENERATOR * Generator; ASSERT (This != NULL); ASSERT (AcpiTableInfo != NULL); - ASSERT (CfgMgrProtocol != NULL); ASSERT (Table != NULL); ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID); ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature); @@ -1579,136 +1234,68 @@ BuildIortTable ( } Generator = (ACPI_IORT_GENERATOR*)This; + + // Pointers to allocated memory *Table = NULL; // Get the ITS group node info - Status = GetEArmObjItsGroup ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &ItsGroupNodeList, - &ItsGroupNodeCount - ); + Status = CfgMgrCountObjects (EArmObjItsGroup, &ItsGroupNodeCount); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: IORT: Failed to get ITS Group Node Info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } // Add the ITS group node count IortNodeCount = ItsGroupNodeCount; // Get the Named component node info - Status = GetEArmObjNamedComponent ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &NamedComponentNodeList, - &NamedComponentNodeCount - ); + Status = CfgMgrCountObjects (EArmObjNamedComponent, &NamedComponentNodeCount); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: IORT: Failed to get Named Component Node Info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } // Add the Named Component group count IortNodeCount += NamedComponentNodeCount; // Get the Root complex node info - Status = GetEArmObjRootComplex ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &RootComplexNodeList, - &RootComplexNodeCount - ); + Status = CfgMgrCountObjects (EArmObjRootComplex, &RootComplexNodeCount); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: IORT: Failed to get Root Complex Node Info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } // Add the Root Complex node count IortNodeCount += RootComplexNodeCount; // Get the SMMU v1/v2 node info - Status = GetEArmObjSmmuV1SmmuV2 ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &SmmuV1V2NodeList, - &SmmuV1V2NodeCount - ); + Status = CfgMgrCountObjects (EArmObjSmmuV1SmmuV2, &SmmuV1V2NodeCount); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: IORT: Failed to get SMMUv1/SMMUv2 Node Info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } // Add the SMMU v1/v2 node count IortNodeCount += SmmuV1V2NodeCount; // Get the SMMUv3 node info - Status = GetEArmObjSmmuV3 ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &SmmuV3NodeList, - &SmmuV3NodeCount - ); + Status = CfgMgrCountObjects (EArmObjSmmuV3, &SmmuV3NodeCount); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: IORT: Failed to get SMMUv3 Node Info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } // Add the SMMUv3 node count IortNodeCount += SmmuV3NodeCount; // Get the PMCG node info - Status = GetEArmObjPmcg ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &PmcgNodeList, - &PmcgNodeCount - ); + Status = CfgMgrCountObjects (EArmObjPmcg, &PmcgNodeCount); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: IORT: Failed to get PMCG Node Info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } // Add the PMCG node count IortNodeCount += PmcgNodeCount; // Allocate Node Indexer array - NodeIndexer = (IORT_NODE_INDEXER*)AllocateZeroPool ( - (sizeof (IORT_NODE_INDEXER) * - IortNodeCount) - ); + NodeIndexer = AllocateZeroPool ((sizeof (IORT_NODE_INDEXER) * IortNodeCount)); if (NodeIndexer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - DEBUG (( - DEBUG_ERROR, - "ERROR: IORT: Failed to allocate memory for Node Indexer" \ - " Status = %r\n", - Status - )); - goto error_handler; + return EFI_OUT_OF_RESOURCES; } DEBUG ((DEBUG_INFO, "INFO: NodeIndexer = %p\n", NodeIndexer)); @@ -1721,13 +1308,10 @@ BuildIortTable ( // ITS Group Nodes if (ItsGroupNodeCount > 0) { ItsGroupOffset = (UINT32)TableSize; - // Size of ITS Group node list. - NodeSize = GetSizeofItsGroupNodes ( - ItsGroupOffset, - ItsGroupNodeList, - ItsGroupNodeCount, - &NodeIndexer - ); + + NodeSize = GetSizeOfNodes ( + EArmObjItsGroup, ItsGroupOffset, &NodeIndexer, GetItsGroupNodeSize); + if (NodeSize > MAX_UINT32) { Status = EFI_INVALID_PARAMETER; DEBUG (( @@ -1751,13 +1335,13 @@ BuildIortTable ( // Named Component Nodes if (NamedComponentNodeCount > 0) { NamedComponentOffset = (UINT32)TableSize; - // Size of Named Component node list. - NodeSize = GetSizeofNamedComponentNodes ( - NamedComponentOffset, - NamedComponentNodeList, - NamedComponentNodeCount, - &NodeIndexer - ); + + NodeSize = GetSizeOfNodes ( + EArmObjNamedComponent, + NamedComponentOffset, + &NodeIndexer, + GetNamedComponentNodeSize); + if (NodeSize > MAX_UINT32) { Status = EFI_INVALID_PARAMETER; DEBUG (( @@ -1781,13 +1365,13 @@ BuildIortTable ( // Root Complex Nodes if (RootComplexNodeCount > 0) { RootComplexOffset = (UINT32)TableSize; - // Size of Root Complex node list. - NodeSize = GetSizeofRootComplexNodes ( - RootComplexOffset, - RootComplexNodeList, - RootComplexNodeCount, - &NodeIndexer - ); + + NodeSize = GetSizeOfNodes ( + EArmObjRootComplex, + RootComplexOffset, + &NodeIndexer, + GetRootComplexNodeSize); + if (NodeSize > MAX_UINT32) { Status = EFI_INVALID_PARAMETER; DEBUG (( @@ -1811,13 +1395,9 @@ BuildIortTable ( // SMMUv1/SMMUv2 Nodes if (SmmuV1V2NodeCount > 0) { SmmuV1V2Offset = (UINT32)TableSize; - // Size of SMMUv1/SMMUv2 node list. - NodeSize = GetSizeofSmmuV1V2Nodes ( - SmmuV1V2Offset, - SmmuV1V2NodeList, - SmmuV1V2NodeCount, - &NodeIndexer - ); + + NodeSize = GetSizeOfNodes ( + EArmObjSmmuV1SmmuV2, SmmuV1V2Offset, &NodeIndexer, GetSmmuV1V2NodeSize); if (NodeSize > MAX_UINT32) { Status = EFI_INVALID_PARAMETER; DEBUG (( @@ -1841,13 +1421,9 @@ BuildIortTable ( // SMMUv3 Nodes if (SmmuV3NodeCount > 0) { SmmuV3Offset = (UINT32)TableSize; - // Size of SMMUv3 node list. - NodeSize = GetSizeofSmmuV3Nodes ( - SmmuV3Offset, - SmmuV3NodeList, - SmmuV3NodeCount, - &NodeIndexer - ); + + NodeSize = GetSizeOfNodes ( + EArmObjSmmuV3, SmmuV3Offset, &NodeIndexer, GetSmmuV3NodeSize); if (NodeSize > MAX_UINT32) { Status = EFI_INVALID_PARAMETER; DEBUG (( @@ -1871,13 +1447,9 @@ BuildIortTable ( // PMCG Nodes if (PmcgNodeCount > 0) { PmcgOffset = (UINT32)TableSize; - // Size of PMCG node list. - NodeSize = GetSizeofPmcgNodes ( - PmcgOffset, - PmcgNodeList, - PmcgNodeCount, - &NodeIndexer - ); + + NodeSize = GetSizeOfNodes ( + EArmObjPmcg, PmcgOffset, &NodeIndexer, GetPmcgNodeSize); if (NodeSize > MAX_UINT32) { Status = EFI_INVALID_PARAMETER; DEBUG (( @@ -1920,21 +1492,12 @@ BuildIortTable ( } // Allocate the Buffer for IORT table - *Table = (EFI_ACPI_DESCRIPTION_HEADER*)AllocateZeroPool (TableSize); - if (*Table == NULL) { + Iort = AllocateZeroPool (TableSize); + if (Iort == NULL) { Status = EFI_OUT_OF_RESOURCES; - DEBUG (( - DEBUG_ERROR, - "ERROR: IORT: Failed to allocate memory for IORT Table, Size = %d," \ - " Status = %r\n", - TableSize, - Status - )); goto error_handler; } - Iort = (EFI_ACPI_6_0_IO_REMAPPING_TABLE*)*Table; - DEBUG (( DEBUG_INFO, "IORT: Iort = 0x%p TableSize = 0x%lx\n", @@ -1944,11 +1507,6 @@ BuildIortTable ( Status = AddAcpiHeader (This, &Iort->Header, AcpiTableInfo, (UINT32) TableSize); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: IORT: Failed to add ACPI header. Status = %r\n", - Status - )); goto error_handler; } @@ -1958,14 +1516,10 @@ BuildIortTable ( Iort->Reserved = EFI_ACPI_RESERVED_DWORD; if (ItsGroupNodeCount > 0) { + CfgMgrGetSimpleObject(EArmObjItsGroup, &NodeList); Status = AddItsGroupNodes ( - This, - CfgMgrProtocol, - Iort, - ItsGroupOffset, - ItsGroupNodeList, - ItsGroupNodeCount - ); + This, Iort, ItsGroupOffset, NodeList, ItsGroupNodeCount); + FreePool (NodeList); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -1977,14 +1531,10 @@ BuildIortTable ( } if (NamedComponentNodeCount > 0) { + CfgMgrGetSimpleObject(EArmObjNamedComponent, &NodeList); Status = AddNamedComponentNodes ( - This, - CfgMgrProtocol, - Iort, - NamedComponentOffset, - NamedComponentNodeList, - NamedComponentNodeCount - ); + This, Iort, NamedComponentOffset, NodeList, NamedComponentNodeCount); + FreePool (NodeList); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -1996,14 +1546,10 @@ BuildIortTable ( } if (RootComplexNodeCount > 0) { + CfgMgrGetSimpleObject(EArmObjRootComplex, &NodeList); Status = AddRootComplexNodes ( - This, - CfgMgrProtocol, - Iort, - RootComplexOffset, - RootComplexNodeList, - RootComplexNodeCount - ); + This, Iort, RootComplexOffset, NodeList, RootComplexNodeCount); + FreePool (NodeList); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -2015,14 +1561,10 @@ BuildIortTable ( } if (SmmuV1V2NodeCount > 0) { + CfgMgrGetSimpleObject(EArmObjSmmuV1SmmuV2, &NodeList); Status = AddSmmuV1V2Nodes ( - This, - CfgMgrProtocol, - Iort, - SmmuV1V2Offset, - SmmuV1V2NodeList, - SmmuV1V2NodeCount - ); + This, Iort, SmmuV1V2Offset, NodeList, SmmuV1V2NodeCount); + FreePool (NodeList); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -2034,14 +1576,10 @@ BuildIortTable ( } if (SmmuV3NodeCount > 0) { + CfgMgrGetSimpleObject(EArmObjSmmuV3, &NodeList); Status = AddSmmuV3Nodes ( - This, - CfgMgrProtocol, - Iort, - SmmuV3Offset, - SmmuV3NodeList, - SmmuV3NodeCount - ); + This, Iort, SmmuV3Offset, NodeList, SmmuV3NodeCount); + FreePool (NodeList); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -2053,14 +1591,9 @@ BuildIortTable ( } if (PmcgNodeCount > 0) { - Status = AddPmcgNodes ( - This, - CfgMgrProtocol, - Iort, - PmcgOffset, - PmcgNodeList, - PmcgNodeCount - ); + CfgMgrGetSimpleObject(EArmObjPmcg, &NodeList); + Status = AddPmcgNodes (This, Iort, PmcgOffset, NodeList, PmcgNodeCount); + FreePool (NodeList); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -2071,6 +1604,8 @@ BuildIortTable ( } } + *Table = (EFI_ACPI_DESCRIPTION_HEADER*) Iort; + return EFI_SUCCESS; error_handler: @@ -2078,11 +1613,10 @@ error_handler: FreePool (Generator->NodeIndexer); Generator->NodeIndexer = NULL; } - - if (*Table != NULL) { - FreePool (*Table); - *Table = NULL; + if (Iort != NULL) { + FreePool (Iort); } + return Status; } diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c index ab42c96b06..0d75a24724 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c @@ -17,7 +17,6 @@ // Module specific include files. #include <AcpiTableGenerator.h> #include <ConfigurationManagerObject.h> -#include <ConfigurationManagerHelper.h> #include <Library/TableHelperLib.h> #include <Protocol/ConfigurationManagerProtocol.h> @@ -33,54 +32,6 @@ Requirements: - EArmObjGicItsInfo (OPTIONAL) */ -/** This macro expands to a function that retrieves the GIC - CPU interface Information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjGicCInfo, - CM_ARM_GICC_INFO - ); - -/** This macro expands to a function that retrieves the GIC - Distributor Information from the Configuration Manager. -*/ - -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjGicDInfo, - CM_ARM_GICD_INFO - ); - -/** This macro expands to a function that retrieves the GIC - MSI Frame Information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjGicMsiFrameInfo, - CM_ARM_GIC_MSI_FRAME_INFO - ); - -/** This macro expands to a function that retrieves the GIC - Redistributor Information from the Configuration Manager. -*/ - -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjGicRedistributorInfo, - CM_ARM_GIC_REDIST_INFO - ); - -/** This macro expands to a function that retrieves the GIC - Interrupt Translation Service Information from the - Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjGicItsInfo, - CM_ARM_GIC_ITS_INFO - ); - /** This function updates the GIC CPU Interface Information in the EFI_ACPI_6_3_GIC_STRUCTURE structure. @@ -215,15 +166,21 @@ STATIC EFI_STATUS AddGICCList ( IN EFI_ACPI_6_3_GIC_STRUCTURE * Gicc, - IN CONST CM_ARM_GICC_INFO * GicCInfo, - IN UINT32 GicCCount, IN CONST UINT8 MadtRev ) { BOOLEAN IsAcpiProcUidDuplicated; + CM_ARM_GICC_INFO *Cursor; + VOID *GicCInfo; + UINT32 GicCCount; ASSERT (Gicc != NULL); - ASSERT (GicCInfo != NULL); + + EFI_STATUS Status = + CfgMgrGetObjects (EArmObjGicCInfo, CM_NULL_TOKEN, &GicCInfo, &GicCCount); + if (EFI_ERROR (Status)) { + return Status; + } IsAcpiProcUidDuplicated = FindDuplicateValue ( GicCInfo, @@ -234,31 +191,40 @@ AddGICCList ( // Duplicate ACPI Processor UID was found so the GICC info provided // is invalid if (IsAcpiProcUidDuplicated) { + FreePool (GicCInfo); return EFI_INVALID_PARAMETER; } + Cursor = GicCInfo; while (GicCCount-- != 0) { - AddGICC (Gicc++, GicCInfo++, MadtRev); + AddGICC (Gicc++, Cursor++, MadtRev); } + FreePool (GicCInfo); return EFI_SUCCESS; } /** Update the GIC Distributor Information in the MADT Table. @param [in] Gicd Pointer to GIC Distributor structure. - @param [in] GicDInfo Pointer to the GIC Distributor Information. **/ STATIC VOID AddGICD ( - EFI_ACPI_6_3_GIC_DISTRIBUTOR_STRUCTURE * CONST Gicd, - CONST CM_ARM_GICD_INFO * CONST GicDInfo -) + EFI_ACPI_6_3_GIC_DISTRIBUTOR_STRUCTURE * CONST Gicd + ) { + EFI_STATUS Status; + CM_ARM_GICD_INFO *GicDInfo; + ASSERT (Gicd != NULL); ASSERT (GicDInfo != NULL); + Status = CfgMgrGetSimpleObject (EArmObjGicDInfo, (VOID **)&GicDInfo); + if (EFI_ERROR (Status)) { + return; + } + // UINT8 Type Gicd->Type = EFI_ACPI_6_3_GICD; // UINT8 Length @@ -279,6 +245,8 @@ AddGICD ( Gicd->Reserved2[0] = EFI_ACPI_RESERVED_BYTE; Gicd->Reserved2[1] = EFI_ACPI_RESERVED_BYTE; Gicd->Reserved2[2] = EFI_ACPI_RESERVED_BYTE; + + FreePool (GicDInfo); } /** Update the GIC MSI Frame Information. @@ -310,23 +278,32 @@ AddGICMsiFrame ( /** Add the GIC MSI Frame Information to the MADT Table. @param [in] GicMsiFrame Pointer to GIC MSI Frame structure list. - @param [in] GicMsiFrameInfo Pointer to the GIC MSI Frame info list. - @param [in] GicMsiFrameCount Count of GIC MSI Frames. **/ STATIC VOID AddGICMsiFrameInfoList ( - IN EFI_ACPI_6_3_GIC_MSI_FRAME_STRUCTURE * GicMsiFrame, - IN CONST CM_ARM_GIC_MSI_FRAME_INFO * GicMsiFrameInfo, - IN UINT32 GicMsiFrameCount -) + IN EFI_ACPI_6_3_GIC_MSI_FRAME_STRUCTURE * GicMsiFrame + ) { + EFI_STATUS Status; + VOID *GicMsiInfo; + CM_ARM_GIC_MSI_FRAME_INFO *Cursor; + UINT32 GicMsiCount; + ASSERT (GicMsiFrame != NULL); - ASSERT (GicMsiFrameInfo != NULL); - while (GicMsiFrameCount-- != 0) { - AddGICMsiFrame (GicMsiFrame++, GicMsiFrameInfo++); + Status = CfgMgrGetObjects ( + EArmObjGicMsiFrameInfo, CM_NULL_TOKEN, &GicMsiInfo, &GicMsiCount); + if (EFI_ERROR(Status)) { + return; + } + + Cursor = GicMsiInfo; + while (GicMsiCount-- != 0) { + AddGICMsiFrame (GicMsiFrame++, Cursor++); } + + FreePool (GicMsiInfo); } /** Update the GIC Redistributor Information. @@ -355,23 +332,32 @@ AddGICRedistributor ( /** Add the GIC Redistributor Information to the MADT Table. @param [in] Gicr Pointer to GIC Redistributor structure list. - @param [in] GicRInfo Pointer to the GIC Distributor info list. - @param [in] GicRCount Count of GIC Distributors. **/ STATIC VOID AddGICRedistributorList ( - IN EFI_ACPI_6_3_GICR_STRUCTURE * Gicr, - IN CONST CM_ARM_GIC_REDIST_INFO * GicRInfo, - IN UINT32 GicRCount + IN EFI_ACPI_6_3_GICR_STRUCTURE * Gicr ) { + CM_ARM_GIC_REDIST_INFO *Cursor; + VOID *GicRInfo; + UINT32 GicRCount; + EFI_STATUS Status; + ASSERT (Gicr != NULL); - ASSERT (GicRInfo != NULL); + Status = CfgMgrGetObjects ( + EArmObjGicRedistributorInfo, CM_NULL_TOKEN, &GicRInfo, &GicRCount); + if (EFI_ERROR (Status)) { + return; + } + + Cursor = GicRInfo; while (GicRCount-- != 0) { - AddGICRedistributor (Gicr++, GicRInfo++); + AddGICRedistributor (Gicr++, Cursor++); } + + FreePool (GicRInfo); } /** Update the GIC Interrupt Translation Service Information @@ -401,23 +387,32 @@ AddGICInterruptTranslationService ( to the MADT Table. @param [in] GicIts Pointer to GIC ITS structure list. - @param [in] GicItsInfo Pointer to the GIC ITS list. - @param [in] GicItsCount Count of GIC ITS. **/ STATIC VOID AddGICItsList ( - IN EFI_ACPI_6_3_GIC_ITS_STRUCTURE * GicIts, - IN CONST CM_ARM_GIC_ITS_INFO * GicItsInfo, - IN UINT32 GicItsCount + IN EFI_ACPI_6_3_GIC_ITS_STRUCTURE * GicIts ) { + CM_ARM_GIC_ITS_INFO *Cursor; + VOID *GicItsInfo; + UINT32 GicItsCount; + EFI_STATUS Status; + ASSERT (GicIts != NULL); - ASSERT (GicItsInfo != NULL); + Status = CfgMgrGetObjects ( + EArmObjGicItsInfo, CM_NULL_TOKEN, &GicItsInfo, &GicItsCount); + if (EFI_ERROR(Status)) { + return; + } + + Cursor = GicItsInfo; while (GicItsCount-- != 0) { - AddGICInterruptTranslationService (GicIts++, GicItsInfo++); + AddGICInterruptTranslationService (GicIts++, Cursor++); } + + FreePool (GicItsInfo); } /** Construct the MADT ACPI table. @@ -454,16 +449,13 @@ BuildMadtTable ( { EFI_STATUS Status; UINT32 TableSize; + UINT32 GicCCount; UINT32 GicDCount; UINT32 GicMSICount; UINT32 GicRedistCount; UINT32 GicItsCount; - CM_ARM_GICC_INFO * GicCInfo; - CM_ARM_GICD_INFO * GicDInfo; - CM_ARM_GIC_MSI_FRAME_INFO * GicMSIInfo; - CM_ARM_GIC_REDIST_INFO * GicRedistInfo; - CM_ARM_GIC_ITS_INFO * GicItsInfo; + UINT32 GicCOffset; UINT32 GicDOffset; UINT32 GicMSIOffset; @@ -474,7 +466,6 @@ BuildMadtTable ( ASSERT (This != NULL); ASSERT (AcpiTableInfo != NULL); - ASSERT (CfgMgrProtocol != NULL); ASSERT (Table != NULL); ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID); ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature); @@ -492,21 +483,12 @@ BuildMadtTable ( return EFI_INVALID_PARAMETER; } + // Allocated memory pointers *Table = NULL; - Status = GetEArmObjGicCInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &GicCInfo, - &GicCCount - ); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: MADT: Failed to get GICC Info. Status = %r\n", - Status - )); - goto error_handler; + Status = CfgMgrCountObjects (EArmObjGicCInfo, &GicCCount); + if (EFI_ERROR(Status)) { + return Status; } if (GicCCount == 0) { @@ -515,23 +497,12 @@ BuildMadtTable ( "ERROR: MADT: GIC CPU Interface information not provided.\n" )); ASSERT (GicCCount != 0); - Status = EFI_INVALID_PARAMETER; - goto error_handler; + return EFI_INVALID_PARAMETER; } - Status = GetEArmObjGicDInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &GicDInfo, - &GicDCount - ); + Status = CfgMgrCountObjects (EArmObjGicDInfo, &GicDCount); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: MADT: Failed to get GICD Info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } if (GicDCount == 0) { @@ -540,8 +511,7 @@ BuildMadtTable ( "ERROR: MADT: GIC Distributor information not provided.\n" )); ASSERT (GicDCount != 0); - Status = EFI_INVALID_PARAMETER; - goto error_handler; + return EFI_INVALID_PARAMETER; } if (GicDCount > 1) { @@ -552,53 +522,22 @@ BuildMadtTable ( GicDCount )); ASSERT (GicDCount <= 1); - Status = EFI_INVALID_PARAMETER; - goto error_handler; + return EFI_INVALID_PARAMETER; } - Status = GetEArmObjGicMsiFrameInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &GicMSIInfo, - &GicMSICount - ); + Status = CfgMgrCountObjects (EArmObjGicMsiFrameInfo, &GicMSICount); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: MADT: Failed to get GIC MSI Info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } - Status = GetEArmObjGicRedistributorInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &GicRedistInfo, - &GicRedistCount - ); + Status = CfgMgrCountObjects (EArmObjGicRedistributorInfo, &GicRedistCount); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: MADT: Failed to get GIC Redistributor Info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } - Status = GetEArmObjGicItsInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &GicItsInfo, - &GicItsCount - ); + Status = CfgMgrCountObjects (EArmObjGicItsInfo, &GicItsCount); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: MADT: Failed to get GIC ITS Info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } TableSize = sizeof (EFI_ACPI_6_3_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER); @@ -619,21 +558,11 @@ BuildMadtTable ( TableSize += (sizeof (EFI_ACPI_6_3_GIC_ITS_STRUCTURE) * GicItsCount); // Allocate the Buffer for MADT table - *Table = (EFI_ACPI_DESCRIPTION_HEADER*)AllocateZeroPool (TableSize); - if (*Table == NULL) { - Status = EFI_OUT_OF_RESOURCES; - DEBUG (( - DEBUG_ERROR, - "ERROR: MADT: Failed to allocate memory for MADT Table, Size = %d," \ - " Status = %r\n", - TableSize, - Status - )); - goto error_handler; + Madt = AllocateZeroPool (TableSize); + if (Madt == NULL) { + return EFI_OUT_OF_RESOURCES; } - Madt = (EFI_ACPI_6_3_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER*)*Table; - DEBUG (( DEBUG_INFO, "MADT: Madt = 0x%p TableSize = 0x%x\n", @@ -643,20 +572,13 @@ BuildMadtTable ( Status = AddAcpiHeader (This, &Madt->Header, AcpiTableInfo, TableSize); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: MADT: Failed to add ACPI header. Status = %r\n", - Status - )); goto error_handler; } Status = AddGICCList ( - (EFI_ACPI_6_3_GIC_STRUCTURE*)((UINT8*)Madt + GicCOffset), - GicCInfo, - GicCCount, - Madt->Header.Revision - ); + (EFI_ACPI_6_3_GIC_STRUCTURE *)((UINT8 *)Madt + GicCOffset), + Madt->Header.Revision); + if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -666,42 +588,25 @@ BuildMadtTable ( goto error_handler; } - AddGICD ( - (EFI_ACPI_6_3_GIC_DISTRIBUTOR_STRUCTURE*)((UINT8*)Madt + GicDOffset), - GicDInfo - ); + AddGICD ((VOID *)((UINT8 *)Madt + GicDOffset)); if (GicMSICount != 0) { - AddGICMsiFrameInfoList ( - (EFI_ACPI_6_3_GIC_MSI_FRAME_STRUCTURE*)((UINT8*)Madt + GicMSIOffset), - GicMSIInfo, - GicMSICount - ); + AddGICMsiFrameInfoList ((VOID *)((UINT8 *)Madt + GicMSIOffset)); } if (GicRedistCount != 0) { - AddGICRedistributorList ( - (EFI_ACPI_6_3_GICR_STRUCTURE*)((UINT8*)Madt + GicRedistOffset), - GicRedistInfo, - GicRedistCount - ); + AddGICRedistributorList ((VOID *)((UINT8 *)Madt + GicRedistOffset)); } if (GicItsCount != 0) { - AddGICItsList ( - (EFI_ACPI_6_3_GIC_ITS_STRUCTURE*)((UINT8*)Madt + GicItsOffset), - GicItsInfo, - GicItsCount - ); + AddGICItsList ((VOID *)((UINT8 *)Madt + GicItsOffset)); } + *Table = (EFI_ACPI_DESCRIPTION_HEADER*)Madt; return EFI_SUCCESS; error_handler: - if (*Table != NULL) { - FreePool (*Table); - *Table = NULL; - } + FreePool (Madt); return Status; } @@ -727,7 +632,6 @@ FreeMadtTableResources ( { ASSERT (This != NULL); ASSERT (AcpiTableInfo != NULL); - ASSERT (CfgMgrProtocol != NULL); ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID); ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature); diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiMcfgLibArm/McfgGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiMcfgLibArm/McfgGenerator.c index a486e2297a..0283ea11f5 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiMcfgLibArm/McfgGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiMcfgLibArm/McfgGenerator.c @@ -18,7 +18,6 @@ // Module specific include files. #include <AcpiTableGenerator.h> #include <ConfigurationManagerObject.h> -#include <ConfigurationManagerHelper.h> #include <Library/TableHelperLib.h> #include <Protocol/ConfigurationManagerProtocol.h> @@ -48,50 +47,52 @@ typedef #pragma pack() -/** Retrieve the PCI Configuration Space Information. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjPciConfigSpaceInfo, - CM_ARM_PCI_CONFIG_SPACE_INFO - ); - /** Add the PCI Enhanced Configuration Space Information to the MCFG Table. @param [in] Mcfg Pointer to MCFG Table. @param [in] PciCfgSpaceOffset Offset for the PCI Configuration Space Info structure in the MCFG Table. - @param [in] PciCfgSpaceInfoList Pointer to the PCI Configuration Space - Info List. - @param [in] PciCfgSpaceCount Count of PCI Configuration Space Info. **/ STATIC VOID AddPciConfigurationSpaceList ( IN MCFG_TABLE * CONST Mcfg, - IN CONST UINT32 PciCfgSpaceOffset, - IN CONST CM_ARM_PCI_CONFIG_SPACE_INFO * PciCfgSpaceInfoList, - IN UINT32 PciCfgSpaceCount + IN CONST UINT32 PciCfgSpaceOffset ) { - MCFG_CFG_SPACE_ADDR * PciCfgSpace; + MCFG_CFG_SPACE_ADDR *PciCfgSpace; + CM_ARM_PCI_CONFIG_SPACE_INFO *Cursor; + VOID *PciCfgSpaceInfoList; + UINT32 PciCfgSpaceCount; + EFI_STATUS Status; ASSERT (Mcfg != NULL); - ASSERT (PciCfgSpaceInfoList != NULL); + + Status = CfgMgrGetObjects ( + EArmObjPciConfigSpaceInfo, + CM_NULL_TOKEN, + &PciCfgSpaceInfoList, + &PciCfgSpaceCount); + if (EFI_ERROR (Status)) { + return; + } PciCfgSpace = (MCFG_CFG_SPACE_ADDR *)((UINT8*)Mcfg + PciCfgSpaceOffset); + Cursor = PciCfgSpaceInfoList; while (PciCfgSpaceCount-- != 0) { // Add PCI Configuration Space entry - PciCfgSpace->BaseAddress = PciCfgSpaceInfoList->BaseAddress; + PciCfgSpace->BaseAddress = Cursor->BaseAddress; PciCfgSpace->PciSegmentGroupNumber = - PciCfgSpaceInfoList->PciSegmentGroupNumber; - PciCfgSpace->StartBusNumber = PciCfgSpaceInfoList->StartBusNumber; - PciCfgSpace->EndBusNumber = PciCfgSpaceInfoList->EndBusNumber; + Cursor->PciSegmentGroupNumber; + PciCfgSpace->StartBusNumber = Cursor->StartBusNumber; + PciCfgSpace->EndBusNumber = Cursor->EndBusNumber; PciCfgSpace->Reserved = EFI_ACPI_RESERVED_DWORD; PciCfgSpace++; - PciCfgSpaceInfoList++; + Cursor++; } + + FreePool (PciCfgSpaceInfoList); } /** Construct the MCFG ACPI table. @@ -152,20 +153,14 @@ BuildMcfgTable ( return EFI_INVALID_PARAMETER; } + // Pointers to allocated memory *Table = NULL; - Status = GetEArmObjPciConfigSpaceInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &PciConfigSpaceInfoList, - &ConfigurationSpaceCount - ); + PciConfigSpaceInfoList = NULL; + + Status = + CfgMgrCountObjects (EArmObjPciConfigSpaceInfo, &ConfigurationSpaceCount); if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, - "ERROR: MCFG: Failed to get PCI Configuration Space Information." \ - " Status = %r\n", - Status - )); - goto error_handler; + return Status; } if (ConfigurationSpaceCount == 0) { @@ -174,9 +169,8 @@ BuildMcfgTable ( "ERROR: MCFG: Configuration Space Count = %d\n", ConfigurationSpaceCount )); - Status = EFI_INVALID_PARAMETER; ASSERT (ConfigurationSpaceCount != 0); - goto error_handler; + return EFI_INVALID_PARAMETER; } DEBUG (( @@ -189,20 +183,11 @@ BuildMcfgTable ( TableSize = sizeof (MCFG_TABLE) + ((sizeof (MCFG_CFG_SPACE_ADDR) * ConfigurationSpaceCount)); - *Table = (EFI_ACPI_DESCRIPTION_HEADER*)AllocateZeroPool (TableSize); - if (*Table == NULL) { - Status = EFI_OUT_OF_RESOURCES; - DEBUG (( - DEBUG_ERROR, - "ERROR: MCFG: Failed to allocate memory for MCFG Table, Size = %d," \ - " Status = %r\n", - TableSize, - Status - )); - goto error_handler; + Mcfg = AllocateZeroPool (TableSize); + if (Mcfg == NULL) { + return EFI_OUT_OF_RESOURCES; } - Mcfg = (MCFG_TABLE*)*Table; DEBUG (( DEBUG_INFO, "MCFG: Mcfg = 0x%p TableSize = 0x%x\n", @@ -212,30 +197,19 @@ BuildMcfgTable ( Status = AddAcpiHeader (This, &Mcfg->Header, AcpiTableInfo, TableSize); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: MCFG: Failed to add ACPI header. Status = %r\n", - Status - )); goto error_handler; } Mcfg->Reserved = EFI_ACPI_RESERVED_QWORD; - AddPciConfigurationSpaceList ( - Mcfg, - sizeof (MCFG_TABLE), - PciConfigSpaceInfoList, - ConfigurationSpaceCount - ); + AddPciConfigurationSpaceList (Mcfg, sizeof (MCFG_TABLE)); + + *Table = (EFI_ACPI_DESCRIPTION_HEADER*) Mcfg; return EFI_SUCCESS; error_handler: - if (*Table != NULL) { - FreePool (*Table); - *Table = NULL; - } + FreePool (Mcfg); return Status; } diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c index 99eb6e0929..0722b469f0 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c @@ -21,7 +21,6 @@ // Module specific include files. #include <AcpiTableGenerator.h> #include <ConfigurationManagerObject.h> -#include <ConfigurationManagerHelper.h> #include <Library/TableHelperLib.h> #include <Protocol/ConfigurationManagerProtocol.h> @@ -39,56 +38,6 @@ - EArmObjGicCInfo (REQUIRED) */ -/** - This macro expands to a function that retrieves the Processor Hierarchy - information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjProcHierarchyInfo, - CM_ARM_PROC_HIERARCHY_INFO - ); - -/** - This macro expands to a function that retrieves the cache information - from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjCacheInfo, - CM_ARM_CACHE_INFO - ); - -/** - This macro expands to a function that retrieves the ID information for - Processor Hierarchy Nodes from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjProcNodeIdInfo, - CM_ARM_PROC_NODE_ID_INFO - ); - -/** - This macro expands to a function that retrieves the cross-CM-object- - reference information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjCmRef, - CM_ARM_OBJ_REF - ); - -/** - This macro expands to a function that retrieves the GIC CPU interface - information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjGicCInfo, - CM_ARM_GICC_INFO - ); - /** Returns the size of the PPTT Processor Hierarchy Node (Type 0) given a Processor Hierarchy Info CM object. @@ -279,8 +228,6 @@ DetectCyclesInTopology ( Update the array of private resources for a given Processor Hierarchy Node. @param [in] Generator Pointer to the PPTT Generator. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. @param [in] PrivResArray Pointer to the array of private resources. @param [in] PrivResCount Number of private resources. @param [in] PrivResArrayToken Reference Token for the CM_ARM_OBJ_REF @@ -294,20 +241,19 @@ STATIC EFI_STATUS AddPrivateResources ( IN CONST ACPI_PPTT_GENERATOR * CONST Generator, - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN UINT32 * PrivResArray, IN UINT32 PrivResCount, IN CONST CM_OBJECT_TOKEN PrivResArrayToken ) { EFI_STATUS Status; - CM_ARM_OBJ_REF * CmObjRefs; + CM_ARM_OBJ_REF * Cursor; + VOID * CmObjRefs; UINT32 CmObjRefCount; PPTT_NODE_INDEXER * PpttNodeFound; ASSERT ( (Generator != NULL) && - (CfgMgrProtocol != NULL) && (PrivResArray != NULL) && (PrivResCount != 0) ); @@ -327,12 +273,8 @@ AddPrivateResources ( CmObjRefCount = 0; // Get the CM Object References - Status = GetEArmObjCmRef ( - CfgMgrProtocol, - PrivResArrayToken, - &CmObjRefs, - &CmObjRefCount - ); + Status = CfgMgrGetObjects ( + EArmObjCmRef, PrivResArrayToken, (VOID **)&CmObjRefs, &CmObjRefCount); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -356,11 +298,12 @@ AddPrivateResources ( PrivResArrayToken, Status )); - return Status; + goto EXIT; } + Cursor = CmObjRefs; while (PrivResCount-- != 0) { - if (CmObjRefs->ReferenceToken == CM_NULL_TOKEN) { + if (Cursor->ReferenceToken == CM_NULL_TOKEN) { Status = EFI_INVALID_PARAMETER; DEBUG (( DEBUG_ERROR, @@ -368,7 +311,7 @@ AddPrivateResources ( "private resource. Status = %r\n", Status )); - return Status; + goto EXIT; } // The Node indexer has the Processor hierarchy nodes at the begining @@ -378,7 +321,7 @@ AddPrivateResources ( Generator->CacheStructIndexedList, (Generator->ProcTopologyStructCount - Generator->ProcHierarchyNodeCount), - CmObjRefs->ReferenceToken, + Cursor->ReferenceToken, &PpttNodeFound ); if (EFI_ERROR (Status)) { @@ -386,19 +329,21 @@ AddPrivateResources ( DEBUG_ERROR, "ERROR: PPTT: Failed to get a private resource with Token = %p from " \ "Node Indexer. Status = %r\n", - CmObjRefs->ReferenceToken, + Cursor->ReferenceToken, Status )); - return Status; + goto EXIT; } // Update the offset of the private resources in the Processor // Hierarchy Node structure *(PrivResArray++) = PpttNodeFound->Offset; - CmObjRefs++; + Cursor++; } - return EFI_SUCCESS; +EXIT: + FreePool (CmObjRefs); + return Status; } /** @@ -485,7 +430,6 @@ STATIC EFI_STATUS AddProcHierarchyNodes ( IN CONST ACPI_PPTT_GENERATOR * CONST Generator, - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN CONST EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_HEADER * Pptt, IN CONST UINT32 NodesStartOffset ) @@ -508,7 +452,6 @@ AddProcHierarchyNodes ( ASSERT ( (Generator != NULL) && - (CfgMgrProtocol != NULL) && (Pptt != NULL) ); @@ -533,6 +476,9 @@ AddProcHierarchyNodes ( UniqueGicCRefCount = 0; + // Pointers to allocated memory + GicCInfoList = NULL; + while (NodeCount-- != 0) { ProcInfoNode = (CM_ARM_PROC_HIERARCHY_INFO*)ProcNodeIterator->Object; @@ -632,12 +578,11 @@ AddProcHierarchyNodes ( )); return Status; } else { - Status = GetEArmObjGicCInfo ( - CfgMgrProtocol, - ProcInfoNode->GicCToken, - &GicCInfoList, - &GicCInfoCount - ); + Status = CfgMgrGetObjects ( + EArmObjGicCInfo, + ProcInfoNode->GicCToken, + (VOID **)&GicCInfoList, + &GicCInfoCount); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -664,6 +609,7 @@ AddProcHierarchyNodes ( ProcInfoNode->Token, Status )); + FreePool (GicCInfoList); return Status; } @@ -673,6 +619,7 @@ AddProcHierarchyNodes ( // Increment the reference count for the number of // Unique GICC objects that were retrieved. UniqueGicCRefCount++; + FreePool (GicCInfoList); } ProcStruct->NumberOfPrivateResources = ProcInfoNode->NoOfPrivateResources; @@ -683,7 +630,6 @@ AddProcHierarchyNodes ( // Populate the private resources array Status = AddPrivateResources ( Generator, - CfgMgrProtocol, PrivateResources, ProcStruct->NumberOfPrivateResources, ProcInfoNode->PrivateResourcesArrayToken @@ -707,18 +653,8 @@ AddProcHierarchyNodes ( // Knowing the total number of GICC references made and that all GICC Token // references are unique, we can test if no GICC instances have been left out. - Status = GetEArmObjGicCInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &GicCInfoList, - &GicCInfoCount - ); + Status = CfgMgrCountObjects (EArmObjGicCInfo, &GicCInfoCount); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: PPTT: Failed to get GICC Info. Status = %r\n", - Status - )); return Status; } @@ -749,8 +685,6 @@ AddProcHierarchyNodes ( the Configuration Manager and adds this information to the PPTT table. @param [in] Generator Pointer to the PPTT Generator. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. @param [in] Pptt Pointer to PPTT table structure. @param [in] NodesStartOffset Offset from the start of PPTT table to the start of Cache Type Structures. @@ -763,7 +697,6 @@ STATIC EFI_STATUS AddCacheTypeStructures ( IN CONST ACPI_PPTT_GENERATOR * CONST Generator, - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN CONST EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_HEADER * Pptt, IN CONST UINT32 NodesStartOffset ) @@ -775,11 +708,8 @@ AddCacheTypeStructures ( PPTT_NODE_INDEXER * CacheNodeIterator; UINT32 NodeCount; - ASSERT ( - (Generator != NULL) && - (CfgMgrProtocol != NULL) && - (Pptt != NULL) - ); + ASSERT (Generator != NULL); + ASSERT (Pptt != NULL); CacheStruct = (EFI_ACPI_6_3_PPTT_STRUCTURE_CACHE*)((UINT8*)Pptt + NodesStartOffset); @@ -971,8 +901,6 @@ AddCacheTypeStructures ( the Configuration Manager and and adds this information to the PPTT table. @param [in] Generator Pointer to the PPTT Generator. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. @param [in] Pptt Pointer to PPTT table structure. @param [in] NodesStartOffset Offset from the start of PPTT table to the start of ID Type Structures. @@ -985,7 +913,6 @@ STATIC EFI_STATUS AddIdTypeStructures ( IN CONST ACPI_PPTT_GENERATOR * CONST Generator, - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN CONST EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_HEADER * Pptt, IN CONST UINT32 NodesStartOffset ) @@ -998,7 +925,6 @@ AddIdTypeStructures ( ASSERT ( (Generator != NULL) && - (CfgMgrProtocol != NULL) && (Pptt != NULL) ); @@ -1074,10 +1000,7 @@ BuildPpttTable ( UINT32 CacheStructOffset; UINT32 IdStructOffset; - CM_ARM_PROC_HIERARCHY_INFO * ProcHierarchyNodeList; - CM_ARM_CACHE_INFO * CacheStructList; - CM_ARM_PROC_NODE_ID_INFO * IdStructList; - + VOID * NodeList; ACPI_PPTT_GENERATOR * Generator; // Pointer to the Node Indexer array @@ -1088,7 +1011,6 @@ BuildPpttTable ( ASSERT ( (This != NULL) && (AcpiTableInfo != NULL) && - (CfgMgrProtocol != NULL) && (Table != NULL) && (AcpiTableInfo->TableGeneratorId == This->GeneratorID) && (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature) @@ -1108,23 +1030,12 @@ BuildPpttTable ( } Generator = (ACPI_PPTT_GENERATOR*)This; - *Table = NULL; // Get the processor hierarchy info and update the processor topology // structure count with Processor Hierarchy Nodes (Type 0) - Status = GetEArmObjProcHierarchyInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &ProcHierarchyNodeList, - &ProcHierarchyNodeCount - ); + Status = CfgMgrCountObjects (EArmObjProcHierarchyInfo, &ProcHierarchyNodeCount); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: PPTT: Failed to get processor hierarchy info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } ProcTopologyStructCount = ProcHierarchyNodeCount; @@ -1132,19 +1043,9 @@ BuildPpttTable ( // Get the cache info and update the processor topology structure count with // Cache Type Structures (Type 1) - Status = GetEArmObjCacheInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &CacheStructList, - &CacheStructCount - ); + Status = CfgMgrCountObjects (EArmObjCacheInfo, &CacheStructCount); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: PPTT: Failed to get cache info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } ProcTopologyStructCount += CacheStructCount; @@ -1152,38 +1053,18 @@ BuildPpttTable ( // Get the processor hierarchy node ID info and update the processor topology // structure count with ID Structures (Type 2) - Status = GetEArmObjProcNodeIdInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &IdStructList, - &IdStructCount - ); + Status = CfgMgrCountObjects (EArmObjProcNodeIdInfo, &IdStructCount); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: PPTT: Failed to get processor hierarchy node ID info. " \ - "Status = %r\n", - Status - )); - goto error_handler; + return Status; } ProcTopologyStructCount += IdStructCount; Generator->IdStructCount = IdStructCount; // Allocate Node Indexer array - NodeIndexer = (PPTT_NODE_INDEXER*)AllocateZeroPool ( - sizeof (PPTT_NODE_INDEXER) * - ProcTopologyStructCount - ); + NodeIndexer = AllocateZeroPool (sizeof (PPTT_NODE_INDEXER) * ProcTopologyStructCount); if (NodeIndexer == NULL) { - Status = EFI_OUT_OF_RESOURCES; - DEBUG (( - DEBUG_ERROR, - "ERROR: PPTT: Failed to allocate memory for Node Indexer. Status = %r\n ", - Status - )); - goto error_handler; + return EFI_OUT_OF_RESOURCES; } DEBUG ((DEBUG_INFO, "INFO: NodeIndexer = %p\n", NodeIndexer)); @@ -1197,12 +1078,14 @@ BuildPpttTable ( if (Generator->ProcHierarchyNodeCount != 0) { ProcHierarchyNodeOffset = TableSize; Generator->ProcHierarchyNodeIndexedList = NodeIndexer; + + CfgMgrGetSimpleObject(EArmObjProcHierarchyInfo, &NodeList); TableSize += GetSizeofProcHierarchyNodes ( - ProcHierarchyNodeOffset, - ProcHierarchyNodeList, - Generator->ProcHierarchyNodeCount, - &NodeIndexer - ); + ProcHierarchyNodeOffset, + NodeList, + Generator->ProcHierarchyNodeCount, + &NodeIndexer); + FreePool (NodeList); DEBUG (( DEBUG_INFO, @@ -1220,33 +1103,32 @@ BuildPpttTable ( if (Generator->CacheStructCount != 0) { CacheStructOffset = TableSize; Generator->CacheStructIndexedList = NodeIndexer; + + CfgMgrGetSimpleObject(EArmObjCacheInfo, &NodeList); TableSize += GetSizeofCacheTypeStructs ( - CacheStructOffset, - CacheStructList, - Generator->CacheStructCount, - &NodeIndexer - ); - DEBUG (( - DEBUG_INFO, - " CacheStructCount = %d\n" \ - " CacheStructOffset = 0x%x\n" \ - " CacheStructIndexedList = 0x%p\n", - Generator->CacheStructCount, - CacheStructOffset, - Generator->CacheStructIndexedList - )); + CacheStructOffset, NodeList, Generator->CacheStructCount, &NodeIndexer); + FreePool (NodeList); + + DEBUG ( + (DEBUG_INFO, + " CacheStructCount = %d\n" + " CacheStructOffset = 0x%x\n" + " CacheStructIndexedList = 0x%p\n", + Generator->CacheStructCount, + CacheStructOffset, + Generator->CacheStructIndexedList)); } // Include the size of ID Type Structures and index them if (Generator->IdStructCount != 0) { IdStructOffset = TableSize; Generator->IdStructIndexedList = NodeIndexer; + + CfgMgrGetSimpleObject (EArmObjProcNodeIdInfo, &NodeList); TableSize += GetSizeofIdStructs ( - IdStructOffset, - IdStructList, - Generator->IdStructCount, - &NodeIndexer - ); + IdStructOffset, NodeList, Generator->IdStructCount, &NodeIndexer); + FreePool (NodeList); + DEBUG (( DEBUG_INFO, " IdStructCount = %d\n" \ @@ -1268,21 +1150,12 @@ BuildPpttTable ( )); // Allocate the Buffer for the PPTT table - *Table = (EFI_ACPI_DESCRIPTION_HEADER*)AllocateZeroPool (TableSize); - if (*Table == NULL) { + Pptt = AllocateZeroPool (TableSize); + if (Pptt == NULL) { Status = EFI_OUT_OF_RESOURCES; - DEBUG (( - DEBUG_ERROR, - "ERROR: PPTT: Failed to allocate memory for PPTT Table. " \ - "Size = %d. Status = %r\n", - TableSize, - Status - )); goto error_handler; } - Pptt = (EFI_ACPI_6_3_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_HEADER*)*Table; - DEBUG (( DEBUG_INFO, "PPTT: Pptt = 0x%p. TableSize = 0x%x\n", @@ -1293,22 +1166,12 @@ BuildPpttTable ( // Add ACPI header Status = AddAcpiHeader (This, &Pptt->Header, AcpiTableInfo, TableSize); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: PPTT: Failed to add ACPI header. Status = %r\n", - Status - )); goto error_handler; } // Add Processor Hierarchy Nodes (Type 0) to the generated table if (Generator->ProcHierarchyNodeCount != 0) { - Status = AddProcHierarchyNodes ( - Generator, - CfgMgrProtocol, - Pptt, - ProcHierarchyNodeOffset - ); + Status = AddProcHierarchyNodes (Generator, Pptt, ProcHierarchyNodeOffset); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -1321,12 +1184,7 @@ BuildPpttTable ( // Add Cache Type Structures (Type 1) to the generated table if (Generator->CacheStructCount != 0) { - Status = AddCacheTypeStructures ( - Generator, - CfgMgrProtocol, - Pptt, - CacheStructOffset - ); + Status = AddCacheTypeStructures (Generator, Pptt, CacheStructOffset); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -1339,12 +1197,7 @@ BuildPpttTable ( // Add ID Type Structures (Type 2) to the generated table if (Generator->IdStructCount != 0) { - Status = AddIdTypeStructures ( - Generator, - CfgMgrProtocol, - Pptt, - IdStructOffset - ); + Status = AddIdTypeStructures (Generator, Pptt, IdStructOffset); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -1366,6 +1219,7 @@ BuildPpttTable ( goto error_handler; } + *Table = (EFI_ACPI_DESCRIPTION_HEADER*)Pptt; return Status; error_handler: @@ -1374,9 +1228,8 @@ error_handler: Generator->NodeIndexer = NULL; } - if (*Table != NULL) { - FreePool (*Table); - *Table = NULL; + if (Pptt != NULL) { + FreePool (Pptt); } return Status; diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiRawLibArm/RawGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiRawLibArm/RawGenerator.c index 2facfaa048..2a8e392d84 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiRawLibArm/RawGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiRawLibArm/RawGenerator.c @@ -12,7 +12,6 @@ // Module specific include files. #include <AcpiTableGenerator.h> #include <ConfigurationManagerObject.h> -#include <ConfigurationManagerHelper.h> #include <Library/TableHelperLib.h> #include <Protocol/ConfigurationManagerProtocol.h> diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c index 46f53f819a..0a7e9da96e 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c @@ -14,12 +14,12 @@ #include <IndustryStandard/SerialPortConsoleRedirectionTable.h> #include <Library/AcpiLib.h> #include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> #include <Protocol/AcpiTable.h> // Module specific include files. #include <AcpiTableGenerator.h> #include <ConfigurationManagerObject.h> -#include <ConfigurationManagerHelper.h> #include <Library/TableHelperLib.h> #include <Protocol/ConfigurationManagerProtocol.h> @@ -83,15 +83,6 @@ EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE AcpiSpcr = { #pragma pack() -/** This macro expands to a function that retrieves the Serial - Port Information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjSerialConsolePortInfo, - CM_ARM_SERIAL_PORT_INFO - ) - /** Construct the SPCR ACPI table. This function invokes the Configuration Manager protocol interface @@ -131,7 +122,6 @@ BuildSpcrTable ( ASSERT (This != NULL); ASSERT (AcpiTableInfo != NULL); - ASSERT (CfgMgrProtocol != NULL); ASSERT (Table != NULL); ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID); ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature); @@ -149,21 +139,10 @@ BuildSpcrTable ( return EFI_INVALID_PARAMETER; } - *Table = NULL; - - Status = GetEArmObjSerialConsolePortInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &SerialPortInfo, - NULL - ); + Status = CfgMgrGetSimpleObject ( + EArmObjSerialConsolePortInfo, (VOID **)&SerialPortInfo); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: SPCR: Failed to get serial port information. Status = %r\n", - Status - )); - goto error_handler; + return Status; } if (SerialPortInfo->BaseAddress == 0) { @@ -207,11 +186,6 @@ BuildSpcrTable ( AcpiTableInfo, sizeof (EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE)); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: SPCR: Failed to add ACPI header. Status = %r\n", - Status - )); goto error_handler; } @@ -268,6 +242,7 @@ BuildSpcrTable ( *Table = (EFI_ACPI_DESCRIPTION_HEADER*)&AcpiSpcr; error_handler: + FreePool (SerialPortInfo); return Status; } diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSratLibArm/SratGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSratLibArm/SratGenerator.c index fda0837f32..28cc8f9e8e 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSratLibArm/SratGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSratLibArm/SratGenerator.c @@ -21,7 +21,6 @@ // Module specific include files. #include <AcpiTableGenerator.h> #include <ConfigurationManagerObject.h> -#include <ConfigurationManagerHelper.h> #include <Library/TableHelperLib.h> #include <Protocol/ConfigurationManagerProtocol.h> @@ -38,65 +37,6 @@ - EArmObjDeviceHandlePci (OPTIONAL) */ -/** This macro expands to a function that retrieves the GIC - CPU interface Information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjGicCInfo, - CM_ARM_GICC_INFO - ); - -/** This macro expands to a function that retrieves the GIC - Interrupt Translation Service Information from the - Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjGicItsInfo, - CM_ARM_GIC_ITS_INFO - ); - -/** - This macro expands to a function that retrieves the Memory Affinity - information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjMemoryAffinityInfo, - CM_ARM_MEMORY_AFFINITY_INFO - ); - -/** - This macro expands to a function that retrieves the Generic Initiator Affinity - information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjGenericInitiatorAffinityInfo, - CM_ARM_GENERIC_INITIATOR_AFFINITY_INFO - ); - -/** - This macro expands to a function that retrieves the ACPI Device Handle - information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjDeviceHandleAcpi, - CM_ARM_DEVICE_HANDLE_ACPI - ); - -/** - This macro expands to a function that retrieves the PCI Device Handle - information from the Configuration Manager. -*/ -GET_OBJECT_LIST ( - EObjNameSpaceArm, - EArmObjDeviceHandlePci, - CM_ARM_DEVICE_HANDLE_PCI - ); - /** Return the PCI Device information in BDF format @@ -123,147 +63,163 @@ GetBdf ( /** Add the GICC Affinity Structures in the SRAT Table. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. @param [in] Srat Pointer to the SRAT Table. @param [in] GicCAffOffset Offset of the GICC Affinity information in the SRAT Table. - @param [in] GicCInfo Pointer to the GIC CPU Information list. - @param [in] GicCCount Count of GIC CPU Interfaces. @retval EFI_SUCCESS Table generated successfully. **/ STATIC EFI_STATUS AddGICCAffinity ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN EFI_ACPI_6_3_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER * CONST Srat, - IN CONST UINT32 GicCAffOffset, - IN CONST CM_ARM_GICC_INFO * GicCInfo, - IN UINT32 GicCCount + IN CONST UINT32 GicCAffOffset ) { - EFI_ACPI_6_3_GICC_AFFINITY_STRUCTURE * GicCAff; + EFI_ACPI_6_3_GICC_AFFINITY_STRUCTURE *GicCAff; + VOID *GicCInfo; + CM_ARM_GICC_INFO *Cursor; + UINT32 GicCCount; + EFI_STATUS Status; ASSERT (Srat != NULL); - ASSERT (GicCInfo != NULL); + + Status = + CfgMgrGetObjects (EArmObjGicCInfo, CM_NULL_TOKEN, &GicCInfo, &GicCCount); + if (EFI_ERROR (Status)) { + return Status; + } GicCAff = (EFI_ACPI_6_3_GICC_AFFINITY_STRUCTURE *)((UINT8*)Srat + GicCAffOffset); + Cursor = GicCInfo; while (GicCCount-- != 0) { DEBUG ((DEBUG_INFO, "SRAT: GicCAff = 0x%p\n", GicCAff)); GicCAff->Type = EFI_ACPI_6_3_GICC_AFFINITY; GicCAff->Length = sizeof (EFI_ACPI_6_3_GICC_AFFINITY_STRUCTURE); - GicCAff->ProximityDomain = GicCInfo->ProximityDomain; - GicCAff->AcpiProcessorUid = GicCInfo->AcpiProcessorUid; - GicCAff->Flags = GicCInfo->AffinityFlags; - GicCAff->ClockDomain = GicCInfo->ClockDomain; + GicCAff->ProximityDomain = Cursor->ProximityDomain; + GicCAff->AcpiProcessorUid = Cursor->AcpiProcessorUid; + GicCAff->Flags = Cursor->AffinityFlags; + GicCAff->ClockDomain = Cursor->ClockDomain; // Next GicCAff++; - GicCInfo++; + Cursor++; }// while + + FreePool (GicCInfo); return EFI_SUCCESS; } /** Add the GIC ITS Affinity Structures in the SRAT Table. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. @param [in] Srat Pointer to the SRAT Table. @param [in] GicItsAffOffset Offset of the GIC ITS Affinity information in the SRAT Table. - @param [in] GicItsInfo Pointer to the GIC ITS Information list. - @param [in] GicItsCount Count of GIC ITS. @retval EFI_SUCCESS Table generated successfully. **/ STATIC EFI_STATUS AddGICItsAffinity ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN EFI_ACPI_6_3_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER * CONST Srat, - IN CONST UINT32 GicItsAffOffset, - IN CONST CM_ARM_GIC_ITS_INFO * GicItsInfo, - IN UINT32 GicItsCount + IN CONST UINT32 GicItsAffOffset ) { - EFI_ACPI_6_3_GIC_ITS_AFFINITY_STRUCTURE * GicItsAff; + EFI_ACPI_6_3_GIC_ITS_AFFINITY_STRUCTURE *GicItsAff; + CM_ARM_GIC_ITS_INFO *Cursor; + VOID *GicItsInfo; + UINT32 GicItsCount; + EFI_STATUS Status; ASSERT (Srat != NULL); - ASSERT (GicItsInfo != NULL); + + Status = CfgMgrGetObjects ( + EArmObjGicItsInfo, CM_NULL_TOKEN, (VOID **)&GicItsInfo, &GicItsCount); + if (EFI_ERROR (Status)) { + return Status; + } GicItsAff = (EFI_ACPI_6_3_GIC_ITS_AFFINITY_STRUCTURE *)((UINT8*)Srat + GicItsAffOffset); + Cursor = GicItsInfo; while (GicItsCount-- != 0) { DEBUG ((DEBUG_INFO, "SRAT: GicItsAff = 0x%p\n", GicItsAff)); GicItsAff->Type = EFI_ACPI_6_3_GIC_ITS_AFFINITY; GicItsAff->Length = sizeof (EFI_ACPI_6_3_GIC_ITS_AFFINITY_STRUCTURE); - GicItsAff->ProximityDomain = GicItsInfo->ProximityDomain; + GicItsAff->ProximityDomain = Cursor->ProximityDomain; GicItsAff->Reserved[0] = EFI_ACPI_RESERVED_BYTE; GicItsAff->Reserved[1] = EFI_ACPI_RESERVED_BYTE; - GicItsAff->ItsId = GicItsInfo->GicItsId; + GicItsAff->ItsId = Cursor->GicItsId; // Next GicItsAff++; - GicItsInfo++; + Cursor++; }// while + + FreePool (GicItsInfo); return EFI_SUCCESS; } /** Add the Memory Affinity Structures in the SRAT Table. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - Protocol Interface. @param [in] Srat Pointer to the SRAT Table. @param [in] MemAffOffset Offset of the Memory Affinity information in the SRAT Table. - @param [in] MemAffInfo Pointer to the Memory Affinity Information list. - @param [in] MemAffCount Count of Memory Affinity objects. @retval EFI_SUCCESS Table generated successfully. **/ STATIC EFI_STATUS AddMemoryAffinity ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN EFI_ACPI_6_3_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER * CONST Srat, - IN CONST UINT32 MemAffOffset, - IN CONST CM_ARM_MEMORY_AFFINITY_INFO * MemAffInfo, - IN UINT32 MemAffCount + IN CONST UINT32 MemAffOffset ) { - EFI_ACPI_6_3_MEMORY_AFFINITY_STRUCTURE * MemAff; + EFI_ACPI_6_3_MEMORY_AFFINITY_STRUCTURE *MemAff; + CM_ARM_MEMORY_AFFINITY_INFO *Cursor; + VOID *MemAffInfo; + UINT32 MemAffCount; + EFI_STATUS Status; ASSERT (Srat != NULL); - ASSERT (MemAffInfo != NULL); + + Status = CfgMgrGetObjects ( + EArmObjMemoryAffinityInfo, CM_NULL_TOKEN, &MemAffInfo, &MemAffCount); + if (EFI_ERROR (Status)) { + return Status; + } MemAff = (EFI_ACPI_6_3_MEMORY_AFFINITY_STRUCTURE *)((UINT8*)Srat + MemAffOffset); + + Cursor = MemAffInfo; while (MemAffCount-- != 0) { DEBUG ((DEBUG_INFO, "SRAT: MemAff = 0x%p\n", MemAff)); MemAff->Type = EFI_ACPI_6_3_MEMORY_AFFINITY; MemAff->Length = sizeof (EFI_ACPI_6_3_MEMORY_AFFINITY_STRUCTURE); - MemAff->ProximityDomain = MemAffInfo->ProximityDomain; + MemAff->ProximityDomain = Cursor->ProximityDomain; MemAff->Reserved1 = EFI_ACPI_RESERVED_WORD; - MemAff->AddressBaseLow = (UINT32)(MemAffInfo->BaseAddress & MAX_UINT32); - MemAff->AddressBaseHigh = (UINT32)(MemAffInfo->BaseAddress >> 32); - MemAff->LengthLow = (UINT32)(MemAffInfo->Length & MAX_UINT32); - MemAff->LengthHigh = (UINT32)(MemAffInfo->Length >> 32); + MemAff->AddressBaseLow = (UINT32)(Cursor->BaseAddress & MAX_UINT32); + MemAff->AddressBaseHigh = (UINT32)(Cursor->BaseAddress >> 32); + MemAff->LengthLow = (UINT32)(Cursor->Length & MAX_UINT32); + MemAff->LengthHigh = (UINT32)(Cursor->Length >> 32); MemAff->Reserved2 = EFI_ACPI_RESERVED_DWORD; - MemAff->Flags = MemAffInfo->Flags; + MemAff->Flags = Cursor->Flags; MemAff->Reserved3 = EFI_ACPI_RESERVED_QWORD; // Next MemAff++; - MemAffInfo++; + Cursor++; }// while + + FreePool (MemAffInfo); return EFI_SUCCESS; } @@ -290,11 +246,8 @@ AddMemoryAffinity ( STATIC EFI_STATUS AddGenericInitiatorAffinity ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN EFI_ACPI_6_3_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER * CONST Srat, - IN CONST UINT32 GenInitAffOff, - IN CONST CM_ARM_GENERIC_INITIATOR_AFFINITY_INFO * GenInitAffInfo, - IN UINT32 GenInitAffCount + IN CONST UINT32 GenInitAffOff ) { EFI_STATUS Status; @@ -302,13 +255,25 @@ AddGenericInitiatorAffinity ( CM_ARM_DEVICE_HANDLE_ACPI * DeviceHandleAcpi; CM_ARM_DEVICE_HANDLE_PCI * DeviceHandlePci; UINT32 DeviceHandleCount; + CM_ARM_GENERIC_INITIATOR_AFFINITY_INFO * Cursor; + VOID * GenInitAffInfo; + UINT32 GenInitAffCount; ASSERT (Srat != NULL); - ASSERT (GenInitAffInfo != NULL); + + Status = CfgMgrGetObjects ( + EArmObjGenericInitiatorAffinityInfo, + CM_NULL_TOKEN, + &GenInitAffInfo, + &GenInitAffCount); + if (EFI_ERROR (Status)) { + return Status; + } GenInitAff = (EFI_ACPI_6_3_GENERIC_INITIATOR_AFFINITY_STRUCTURE *)( (UINT8*)Srat + GenInitAffOff); + Cursor = GenInitAffInfo; while (GenInitAffCount-- != 0) { DEBUG ((DEBUG_INFO, "SRAT: GenInitAff = 0x%p\n", GenInitAff)); @@ -316,35 +281,35 @@ AddGenericInitiatorAffinity ( GenInitAff->Length = sizeof (EFI_ACPI_6_3_GENERIC_INITIATOR_AFFINITY_STRUCTURE); GenInitAff->Reserved1 = EFI_ACPI_RESERVED_WORD; - GenInitAff->DeviceHandleType = GenInitAffInfo->DeviceHandleType; - GenInitAff->ProximityDomain = GenInitAffInfo->ProximityDomain; + GenInitAff->DeviceHandleType = Cursor->DeviceHandleType; + GenInitAff->ProximityDomain = Cursor->ProximityDomain; - if (GenInitAffInfo->DeviceHandleToken == CM_NULL_TOKEN) { + if (Cursor->DeviceHandleToken == CM_NULL_TOKEN) { DEBUG (( DEBUG_ERROR, "ERROR: SRAT: Invalid Device Handle Token.\n" )); ASSERT (0); - return EFI_INVALID_PARAMETER; + Status = EFI_INVALID_PARAMETER; + goto EXIT; } - if (GenInitAffInfo->DeviceHandleType == EFI_ACPI_6_3_ACPI_DEVICE_HANDLE) { - Status = GetEArmObjDeviceHandleAcpi ( - CfgMgrProtocol, - GenInitAffInfo->DeviceHandleToken, - &DeviceHandleAcpi, - &DeviceHandleCount - ); + if (Cursor->DeviceHandleType == EFI_ACPI_6_3_ACPI_DEVICE_HANDLE) { + Status = CfgMgrGetObjects ( + EArmObjDeviceHandleAcpi, + Cursor->DeviceHandleToken, + (VOID **) &DeviceHandleAcpi, + &DeviceHandleCount); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, "ERROR: SRAT: Failed to get ACPI Device Handle Inf." " DeviceHandleToken = %p." " Status = %r\n", - GenInitAffInfo->DeviceHandleToken, + Cursor->DeviceHandleToken, Status )); - return Status; + goto EXIT; } // We are expecting only one device handle. @@ -357,24 +322,24 @@ AddGenericInitiatorAffinity ( GenInitAff->DeviceHandle.Acpi.Reserved[1] = EFI_ACPI_RESERVED_BYTE; GenInitAff->DeviceHandle.Acpi.Reserved[2] = EFI_ACPI_RESERVED_BYTE; GenInitAff->DeviceHandle.Acpi.Reserved[3] = EFI_ACPI_RESERVED_BYTE; - } else if (GenInitAffInfo->DeviceHandleType == + FreePool (DeviceHandleAcpi); + } else if (Cursor->DeviceHandleType == EFI_ACPI_6_3_PCI_DEVICE_HANDLE) { - Status = GetEArmObjDeviceHandlePci ( - CfgMgrProtocol, - GenInitAffInfo->DeviceHandleToken, - &DeviceHandlePci, - &DeviceHandleCount - ); + Status = CfgMgrGetObjects ( + EArmObjDeviceHandlePci, + Cursor->DeviceHandleToken, + (VOID **) &DeviceHandlePci, + &DeviceHandleCount); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, "ERROR: SRAT: Failed to get ACPI Device Handle Inf." " DeviceHandleToken = %p." " Status = %r\n", - GenInitAffInfo->DeviceHandleToken, + Cursor->DeviceHandleToken, Status )); - return Status; + goto EXIT; } // We are expecting only one device handle @@ -384,6 +349,8 @@ AddGenericInitiatorAffinity ( GenInitAff->DeviceHandle.Pci.PciSegment = DeviceHandlePci->SegmentNumber; GenInitAff->DeviceHandle.Pci.PciBdfNumber = GetBdf (DeviceHandlePci); + FreePool (DeviceHandlePci); + GenInitAff->DeviceHandle.Pci.Reserved[0] = EFI_ACPI_RESERVED_BYTE; GenInitAff->DeviceHandle.Pci.Reserved[1] = EFI_ACPI_RESERVED_BYTE; GenInitAff->DeviceHandle.Pci.Reserved[2] = EFI_ACPI_RESERVED_BYTE; @@ -405,15 +372,18 @@ AddGenericInitiatorAffinity ( return EFI_INVALID_PARAMETER; } - GenInitAff->Flags = GenInitAffInfo->Flags; + GenInitAff->Flags = Cursor->Flags; GenInitAff->Reserved2[0] = EFI_ACPI_RESERVED_BYTE; GenInitAff->Reserved2[1] = EFI_ACPI_RESERVED_BYTE; // Next GenInitAff++; - GenInitAffInfo++; + Cursor++; }// while - return EFI_SUCCESS; + +EXIT: + FreePool (GenInitAffInfo); + return Status; } /** Construct the SRAT ACPI table. @@ -450,6 +420,7 @@ BuildSratTable ( ) { EFI_STATUS Status; + UINT32 TableSize; UINT32 GicCCount; UINT32 GicItsCount; @@ -461,21 +432,13 @@ BuildSratTable ( UINT32 MemAffOffset; UINT32 GenInitiatorAffOffset; - CM_ARM_GICC_INFO * GicCInfo; - CM_ARM_GIC_ITS_INFO * GicItsInfo; - CM_ARM_MEMORY_AFFINITY_INFO * MemAffInfo; - CM_ARM_GENERIC_INITIATOR_AFFINITY_INFO * GenInitiatorAffInfo; - EFI_ACPI_6_3_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER * Srat; - ASSERT ( - (This != NULL) && - (AcpiTableInfo != NULL) && - (CfgMgrProtocol != NULL) && - (Table != NULL) && - (AcpiTableInfo->TableGeneratorId == This->GeneratorID) && - (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature) - ); + ASSERT (This != NULL); + ASSERT (AcpiTableInfo != NULL); + ASSERT (Table != NULL); + ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID); + ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature); if ((AcpiTableInfo->AcpiTableRevision < This->MinAcpiTableRevision) || (AcpiTableInfo->AcpiTableRevision > This->AcpiTableRevision)) { @@ -490,21 +453,9 @@ BuildSratTable ( return EFI_INVALID_PARAMETER; } - *Table = NULL; - - Status = GetEArmObjGicCInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &GicCInfo, - &GicCCount - ); + Status = CfgMgrCountObjects (EArmObjGicCInfo, &GicCCount); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: SRAT: Failed to get GICC Info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } if (GicCCount == 0) { @@ -513,54 +464,23 @@ BuildSratTable ( "ERROR: SRAT: GIC CPU Interface information not provided.\n" )); ASSERT (0); - Status = EFI_INVALID_PARAMETER; - goto error_handler; + return EFI_INVALID_PARAMETER; } - Status = GetEArmObjGicItsInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &GicItsInfo, - &GicItsCount - ); + Status = CfgMgrCountObjects (EArmObjGicItsInfo, &GicItsCount); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: SRAT: Failed to get GIC ITS Info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } - Status = GetEArmObjMemoryAffinityInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &MemAffInfo, - &MemAffCount - ); + Status = CfgMgrCountObjects (EArmObjMemoryAffinityInfo, &MemAffCount); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: SRAT: Failed to get Memory Affinity Info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } - Status = GetEArmObjGenericInitiatorAffinityInfo ( - CfgMgrProtocol, - CM_NULL_TOKEN, - &GenInitiatorAffInfo, - &GenInitiatorAffCount - ); + Status = CfgMgrCountObjects ( + EArmObjGenericInitiatorAffinityInfo, &GenInitiatorAffCount); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: SRAT: Failed to get Generic Initiator Affinity Info." - " Status = %r\n", - Status - )); - goto error_handler; + return Status; } // Calculate the size of the SRAT table @@ -588,35 +508,15 @@ BuildSratTable ( } // Allocate the Buffer for SRAT table - *Table = (EFI_ACPI_DESCRIPTION_HEADER*)AllocateZeroPool (TableSize); - if (*Table == NULL) { - Status = EFI_OUT_OF_RESOURCES; - DEBUG (( - DEBUG_ERROR, - "ERROR: SRAT: Failed to allocate memory for SRAT Table, Size = %d," \ - " Status = %r\n", - TableSize, - Status - )); - goto error_handler; + Srat = AllocateZeroPool (TableSize); + if (Srat == NULL) { + return EFI_OUT_OF_RESOURCES; } - Srat = (EFI_ACPI_6_3_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER*)*Table; - - DEBUG (( - DEBUG_INFO, - "SRAT: Srat = 0x%p TableSize = 0x%x\n", - Srat, - TableSize - )); + DEBUG ((DEBUG_INFO, "SRAT: Srat = 0x%p TableSize = 0x%x\n", Srat, TableSize)); Status = AddAcpiHeader (This, &Srat->Header, AcpiTableInfo, TableSize); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: SRAT: Failed to add ACPI header. Status = %r\n", - Status - )); goto error_handler; } @@ -625,86 +525,33 @@ BuildSratTable ( Srat->Reserved1 = 1; Srat->Reserved2 = EFI_ACPI_RESERVED_QWORD; - Status = AddGICCAffinity ( - CfgMgrProtocol, - Srat, - GicCAffOffset, - GicCInfo, - GicCCount - ); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: SRAT: Failed to add GICC Affinity structures. Status = %r\n", - Status - )); - goto error_handler; - } + AddGICCAffinity (Srat, GicCAffOffset); if (GicItsCount != 0) { - Status = AddGICItsAffinity ( - CfgMgrProtocol, - Srat, - GicItsAffOffset, - GicItsInfo, - GicItsCount - ); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: SRAT: Failed to add GIC ITS Affinity structures. Status = %r\n", - Status - )); - goto error_handler; - } + AddGICItsAffinity (Srat, GicItsAffOffset); } if (MemAffCount != 0) { - Status = AddMemoryAffinity ( - CfgMgrProtocol, - Srat, - MemAffOffset, - MemAffInfo, - MemAffCount - ); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: SRAT: Failed to add Memory Affinity structures. Status = %r\n", - Status - )); - goto error_handler; - } + AddMemoryAffinity (Srat, MemAffOffset); } if (GenInitiatorAffCount != 0) { - Status = AddGenericInitiatorAffinity ( - CfgMgrProtocol, - Srat, - GenInitiatorAffOffset, - GenInitiatorAffInfo, - GenInitiatorAffCount - ); + Status = AddGenericInitiatorAffinity (Srat, GenInitiatorAffOffset); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: SRAT: Failed to add Generic Initiator Affinity structures." - " Status = %r\n", - Status - )); + DEBUG ( + (DEBUG_ERROR, + "ERROR: SRAT: Failed to add Generic Initiator Affinity structures." + " Status = %r\n", + Status)); goto error_handler; } } + *Table = (EFI_ACPI_DESCRIPTION_HEADER*)Srat; return Status; error_handler: - - if (*Table != NULL) { - FreePool (*Table); - *Table = NULL; - } - + FreePool (Srat); return Status; } @@ -728,13 +575,11 @@ FreeSratTableResources ( IN OUT EFI_ACPI_DESCRIPTION_HEADER ** CONST Table ) { - ASSERT ( - (This != NULL) && - (AcpiTableInfo != NULL) && - (CfgMgrProtocol != NULL) && - (AcpiTableInfo->TableGeneratorId == This->GeneratorID) && - (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature) - ); + ASSERT (This != NULL); + ASSERT (AcpiTableInfo != NULL); + ASSERT (CfgMgrProtocol != NULL); + ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID); + ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature); if ((Table == NULL) || (*Table == NULL)) { DEBUG ((DEBUG_ERROR, "ERROR: SRAT: Invalid Table Pointer\n")); -- 2.25.1
|
|
[PATCH 7/8] DynamicTablesPkg: Simplify AddAcpiHeader, CfgMgrGetInfo
Tomas Pilar (tpilar)
Simplify the methods to use the other object getter methods.
The methods no longer need CfgMgr context parameter, the getter helpers retrieve the singleton platform protocol. The CfgMgrGetInfo always allocates the memory that is passed to the caller. Cc: Sami Mujawar <Sami.Mujawar@...> Cc: Alexei Fedorov <Alexei.Fedorov@...> Signed-off-by: Tomas Pilar <tomas@...> --- .../DynamicTableManagerDxe.c | 20 ++-- .../Include/Library/TableHelperLib.h | 23 ++--- .../Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c | 10 +- .../Acpi/Arm/AcpiFadtLibArm/FadtGenerator.c | 12 +-- .../Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c | 8 +- .../Acpi/Arm/AcpiIortLibArm/IortGenerator.c | 8 +- .../Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c | 8 +- .../Acpi/Arm/AcpiMcfgLibArm/McfgGenerator.c | 8 +- .../Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c | 8 +- .../Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c | 10 +- .../Acpi/Arm/AcpiSratLibArm/SratGenerator.c | 8 +- .../Common/TableHelperLib/TableHelper.c | 97 ++++--------------- .../Common/TableHelperLib/TableHelperLib.inf | 3 +- 13 files changed, 56 insertions(+), 167 deletions(-) diff --git a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c index e27dcaf374..b194a38659 100644 --- a/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c +++ b/DynamicTablesPkg/Drivers/DynamicTableManagerDxe/DynamicTableManagerDxe.c @@ -661,7 +661,7 @@ DynamicTableManagerDxeInitialize ( { EFI_STATUS Status; EDKII_CONFIGURATION_MANAGER_PROTOCOL * CfgMgrProtocol; - CM_STD_OBJ_CONFIGURATION_MANAGER_INFO * CfgMfrInfo; + CM_STD_OBJ_CONFIGURATION_MANAGER_INFO * CfgMgrInfo; EDKII_DYNAMIC_TABLE_FACTORY_PROTOCOL * TableFactoryProtocol; // Locate the Dynamic Table Factory @@ -695,7 +695,7 @@ DynamicTableManagerDxeInitialize ( return Status; } - Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo); + Status = CfgMgrGetInfo (&CfgMgrInfo); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, @@ -708,15 +708,17 @@ DynamicTableManagerDxeInitialize ( DEBUG (( DEBUG_INFO, "INFO: Configuration Manager Version = 0x%x, OemID = %c%c%c%c%c%c\n", - CfgMfrInfo->Revision, - CfgMfrInfo->OemId[0], - CfgMfrInfo->OemId[1], - CfgMfrInfo->OemId[2], - CfgMfrInfo->OemId[3], - CfgMfrInfo->OemId[4], - CfgMfrInfo->OemId[5] + CfgMgrInfo->Revision, + CfgMgrInfo->OemId[0], + CfgMgrInfo->OemId[1], + CfgMgrInfo->OemId[2], + CfgMgrInfo->OemId[3], + CfgMgrInfo->OemId[4], + CfgMgrInfo->OemId[5] )); + FreePool(CfgMgrInfo); + Status = ProcessAcpiTables (TableFactoryProtocol, CfgMgrProtocol); if (EFI_ERROR (Status)) { DEBUG (( diff --git a/DynamicTablesPkg/Include/Library/TableHelperLib.h b/DynamicTablesPkg/Include/Library/TableHelperLib.h index 9269e77377..0dce81827b 100644 --- a/DynamicTablesPkg/Include/Library/TableHelperLib.h +++ b/DynamicTablesPkg/Include/Library/TableHelperLib.h @@ -194,33 +194,26 @@ CfgMgrGetObjects ( OUT UINT32 * ItemCount OPTIONAL ); -/** The GetCgfMgrInfo function gets the CM_STD_OBJ_CONFIGURATION_MANAGER_INFO +/** The CfgMgrGetInfo function gets the CM_STD_OBJ_CONFIGURATION_MANAGER_INFO object from the Configuration Manager. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager protocol - interface. @param [out] CfgMfrInfo Pointer to the Configuration Manager Info object structure. @retval EFI_SUCCESS The object is returned. - @retval EFI_INVALID_PARAMETER The Object ID is invalid. @retval EFI_NOT_FOUND The requested Object is not found. - @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration - Manager is less than the Object size. **/ EFI_STATUS EFIAPI -GetCgfMgrInfo ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, +CfgMgrGetInfo ( OUT CM_STD_OBJ_CONFIGURATION_MANAGER_INFO ** CfgMfrInfo ); -/** The AddAcpiHeader function updates the ACPI header structure. It uses the - ACPI table Generator and the Configuration Manager protocol to obtain the - information required for constructing the header. +/** The AddAcpiHeader function updates the ACPI header structure pointed by + the AcpiHeader. It utilizes the ACPI table Generator and the Configuration + Manager protocol to obtain any information required for constructing the + header. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - protocol interface. @param [in] Generator Pointer to the ACPI table Generator. @param [in,out] AcpiHeader Pointer to the ACPI table header to be updated. @@ -230,14 +223,10 @@ GetCgfMgrInfo ( @retval EFI_SUCCESS The ACPI table is updated successfully. @retval EFI_INVALID_PARAMETER A parameter is invalid. @retval EFI_NOT_FOUND The required object information is not found. - @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration - Manager is less than the Object size for the - requested object. **/ EFI_STATUS EFIAPI AddAcpiHeader ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN CONST ACPI_TABLE_GENERATOR * CONST Generator, IN OUT EFI_ACPI_DESCRIPTION_HEADER * CONST AcpiHeader, IN CONST CM_STD_OBJ_ACPI_TABLE_INFO * CONST AcpiTableInfo, diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c index 51c843d25f..21a7f9bf64 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiDbg2LibArm/Dbg2Generator.c @@ -330,12 +330,10 @@ BuildDbg2Table ( } Status = AddAcpiHeader ( - CfgMgrProtocol, - This, - (EFI_ACPI_DESCRIPTION_HEADER*)&AcpiDbg2, - AcpiTableInfo, - sizeof (DBG2_TABLE) - ); + This, + (EFI_ACPI_DESCRIPTION_HEADER *)&AcpiDbg2, + AcpiTableInfo, + sizeof (DBG2_TABLE)); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiFadtLibArm/FadtGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiFadtLibArm/FadtGenerator.c index b748c982b2..febaca3dae 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiFadtLibArm/FadtGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiFadtLibArm/FadtGenerator.c @@ -528,19 +528,17 @@ BuildFadtTable ( *Table = NULL; Status = AddAcpiHeader ( - CfgMgrProtocol, - This, - (EFI_ACPI_DESCRIPTION_HEADER*)&AcpiFadt, - AcpiTableInfo, - sizeof (EFI_ACPI_6_3_FIXED_ACPI_DESCRIPTION_TABLE) - ); + This, + (EFI_ACPI_DESCRIPTION_HEADER *)&AcpiFadt, + AcpiTableInfo, + sizeof (EFI_ACPI_6_3_FIXED_ACPI_DESCRIPTION_TABLE)); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, "ERROR: FADT: Failed to add ACPI header. Status = %r\n", Status )); - goto error_handler; + return Status; } // Update PmProfile Info diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c index c109f2ac20..4af410fb5b 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiGtdtLibArm/GtdtGenerator.c @@ -593,13 +593,7 @@ BuildGtdtTable ( TableSize )); - Status = AddAcpiHeader ( - CfgMgrProtocol, - This, - &Gtdt->Header, - AcpiTableInfo, - TableSize - ); + Status = AddAcpiHeader (This, &Gtdt->Header, AcpiTableInfo, TableSize); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c index 65d006c89e..97f86ddb30 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiIortLibArm/IortGenerator.c @@ -1942,13 +1942,7 @@ BuildIortTable ( TableSize )); - Status = AddAcpiHeader ( - CfgMgrProtocol, - This, - &Iort->Header, - AcpiTableInfo, - (UINT32)TableSize - ); + Status = AddAcpiHeader (This, &Iort->Header, AcpiTableInfo, (UINT32) TableSize); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c index 2651ca1541..ab42c96b06 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiMadtLibArm/MadtGenerator.c @@ -641,13 +641,7 @@ BuildMadtTable ( TableSize )); - Status = AddAcpiHeader ( - CfgMgrProtocol, - This, - &Madt->Header, - AcpiTableInfo, - TableSize - ); + Status = AddAcpiHeader (This, &Madt->Header, AcpiTableInfo, TableSize); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiMcfgLibArm/McfgGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiMcfgLibArm/McfgGenerator.c index 1293ac8e43..a486e2297a 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiMcfgLibArm/McfgGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiMcfgLibArm/McfgGenerator.c @@ -210,13 +210,7 @@ BuildMcfgTable ( TableSize )); - Status = AddAcpiHeader ( - CfgMgrProtocol, - This, - &Mcfg->Header, - AcpiTableInfo, - TableSize - ); + Status = AddAcpiHeader (This, &Mcfg->Header, AcpiTableInfo, TableSize); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c index d70fc59e75..99eb6e0929 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiPpttLibArm/PpttGenerator.c @@ -1291,13 +1291,7 @@ BuildPpttTable ( )); // Add ACPI header - Status = AddAcpiHeader ( - CfgMgrProtocol, - This, - &Pptt->Header, - AcpiTableInfo, - TableSize - ); + Status = AddAcpiHeader (This, &Pptt->Header, AcpiTableInfo, TableSize); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c index 4b2580da7d..46f53f819a 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSpcrLibArm/SpcrGenerator.c @@ -202,12 +202,10 @@ BuildSpcrTable ( DEBUG ((DEBUG_INFO, " Interrupt = %d\n", SerialPortInfo->Interrupt)); Status = AddAcpiHeader ( - CfgMgrProtocol, - This, - (EFI_ACPI_DESCRIPTION_HEADER*)&AcpiSpcr, - AcpiTableInfo, - sizeof (EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE) - ); + This, + (EFI_ACPI_DESCRIPTION_HEADER *)&AcpiSpcr, + AcpiTableInfo, + sizeof (EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE)); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSratLibArm/SratGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSratLibArm/SratGenerator.c index 620e2929ef..fda0837f32 100644 --- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSratLibArm/SratGenerator.c +++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSratLibArm/SratGenerator.c @@ -610,13 +610,7 @@ BuildSratTable ( TableSize )); - Status = AddAcpiHeader ( - CfgMgrProtocol, - This, - &Srat->Header, - AcpiTableInfo, - TableSize - ); + Status = AddAcpiHeader (This, &Srat->Header, AcpiTableInfo, TableSize); if (EFI_ERROR (Status)) { DEBUG (( DEBUG_ERROR, diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c index 18c0e95e0d..2f266feb9c 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c @@ -392,74 +392,30 @@ CfgMgrRemoveObject ( } -/** The GetCgfMgrInfo function gets the CM_STD_OBJ_CONFIGURATION_MANAGER_INFO - object from the Configuration Manager. +/** The CfgMgrGetInfo function gets the CM_STD_OBJ_CONFIGURATION_MANAGER_INFO + object from the Configuration Manager. The caller is responsible for freeing + the memory allocated by this function. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager protocol - interface. - @param [out] CfgMfrInfo Pointer to the Configuration Manager Info + @param [out] CfgMgrInfo Pointer to the Configuration Manager Info object structure. @retval EFI_SUCCESS The object is returned. - @retval EFI_INVALID_PARAMETER The Object ID is invalid. @retval EFI_NOT_FOUND The requested Object is not found. - @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration - Manager is less than the Object size. + @retval EFI_INVALID_PARAMETER CfgMgrInfo is NULL. **/ EFI_STATUS EFIAPI -GetCgfMgrInfo ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, - OUT CM_STD_OBJ_CONFIGURATION_MANAGER_INFO ** CfgMfrInfo +CfgMgrGetInfo ( + OUT CM_STD_OBJ_CONFIGURATION_MANAGER_INFO ** CfgMgrInfo ) { - EFI_STATUS Status; - CM_OBJ_DESCRIPTOR CmObjectDesc; - - ASSERT (CfgMgrProtocol != NULL); - ASSERT (CfgMfrInfo != NULL); - - *CfgMfrInfo = NULL; - - Status = CfgMgrProtocol->GetObject ( - CfgMgrProtocol, - CREATE_CM_STD_OBJECT_ID (EStdObjCfgMgrInfo), - CM_NULL_TOKEN, - &CmObjectDesc - ); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: Failed to Get Configuration Manager Info. Status = %r\n", - Status - )); - return Status; - } - - if (CmObjectDesc.ObjectId != CREATE_CM_STD_OBJECT_ID (EStdObjCfgMgrInfo)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: EStdObjCfgMgrInfo: Invalid ObjectId = 0x%x, expected Id = 0x%x\n", - CmObjectDesc.ObjectId, - CREATE_CM_STD_OBJECT_ID (EStdObjCfgMgrInfo) - )); - ASSERT (FALSE); + if (CfgMgrInfo == NULL) { return EFI_INVALID_PARAMETER; } - if (CmObjectDesc.Size < - (sizeof (CM_STD_OBJ_CONFIGURATION_MANAGER_INFO) * CmObjectDesc.Count)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: EStdObjCfgMgrInfo: Buffer too small, size = 0x%x\n", - CmObjectDesc.Size - )); - ASSERT (FALSE); - return EFI_BAD_BUFFER_SIZE; - } + *CfgMgrInfo = NULL; - *CfgMfrInfo = (CM_STD_OBJ_CONFIGURATION_MANAGER_INFO*)CmObjectDesc.Data; - return Status; + return CfgMgrGetSimpleObject (EStdObjCfgMgrInfo, (VOID **)CfgMgrInfo); } /** The AddAcpiHeader function updates the ACPI header structure pointed by @@ -467,8 +423,6 @@ GetCgfMgrInfo ( Manager protocol to obtain any information required for constructing the header. - @param [in] CfgMgrProtocol Pointer to the Configuration Manager - protocol interface. @param [in] Generator Pointer to the ACPI table Generator. @param [in,out] AcpiHeader Pointer to the ACPI table header to be updated. @@ -478,14 +432,10 @@ GetCgfMgrInfo ( @retval EFI_SUCCESS The ACPI table is updated successfully. @retval EFI_INVALID_PARAMETER A parameter is invalid. @retval EFI_NOT_FOUND The required object information is not found. - @retval EFI_BAD_BUFFER_SIZE The size returned by the Configuration - Manager is less than the Object size for the - requested object. **/ EFI_STATUS EFIAPI AddAcpiHeader ( - IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST CfgMgrProtocol, IN CONST ACPI_TABLE_GENERATOR * CONST Generator, IN OUT EFI_ACPI_DESCRIPTION_HEADER * CONST AcpiHeader, IN CONST CM_STD_OBJ_ACPI_TABLE_INFO * CONST AcpiTableInfo, @@ -495,27 +445,17 @@ AddAcpiHeader ( EFI_STATUS Status; CM_STD_OBJ_CONFIGURATION_MANAGER_INFO * CfgMfrInfo; - ASSERT (CfgMgrProtocol != NULL); - ASSERT (Generator != NULL); - ASSERT (AcpiHeader != NULL); - ASSERT (Length >= sizeof (EFI_ACPI_DESCRIPTION_HEADER)); - - if ((CfgMgrProtocol == NULL) || - (Generator == NULL) || + if ((Generator == NULL) || (AcpiHeader == NULL) || - (Length < sizeof (EFI_ACPI_DESCRIPTION_HEADER)) - ) { + (Length < sizeof (EFI_ACPI_DESCRIPTION_HEADER))) { + DEBUG ((DEBUG_ERROR, + "ERROR: Cannot add ACPI header [Invalid Pamrameter].\n")); return EFI_INVALID_PARAMETER; } - Status = GetCgfMgrInfo (CfgMgrProtocol, &CfgMfrInfo); + Status = CfgMgrGetInfo (&CfgMfrInfo); if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_ERROR, - "ERROR: Failed to get Configuration Manager info. Status = %r\n", - Status - )); - goto error_handler; + return Status; } // UINT32 Signature @@ -555,8 +495,9 @@ AddAcpiHeader ( // UINT32 CreatorRevision AcpiHeader->CreatorRevision = Generator->CreatorRevision; -error_handler: - return Status; + FreePool (CfgMfrInfo); + + return EFI_SUCCESS; } /** diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf index 0fbc1fe5b2..4ee478dab9 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf @@ -32,6 +32,5 @@ [Protocols] gEfiSerialIoProtocolGuid - -[Guids] + gEdkiiConfigurationManagerProtocolGuid -- 2.25.1
|
|
[PATCH 6/8] DynamicTablesPkg/TableHelperLib: User friendly strings
Tomas Pilar (tpilar)
Add user friendly strings for CmObjectIds to TableHelperLib
and add debug print invocations to common helper methods. Cc: Sami Mujawar <Sami.Mujawar@...> Cc: Alexei Fedorov <Alexei.Fedorov@...> Signed-off-by: Tomas Pilar <tomas@...> --- .../ConfigurationManagerDumpApp.c | 13 +-- .../ConfigurationManagerDumpApp.h | 8 -- .../ConfigurationManagerDumpApp.inf | 3 +- .../ConfigurationObjectStrings.c | 50 ---------- .../Include/Library/TableHelperLib.h | 12 +++ .../ConfigurationObjectStrings.c | 92 +++++++++++++++++++ .../Common/TableHelperLib/TableHelperLib.inf | 1 + 7 files changed, 109 insertions(+), 70 deletions(-) delete mode 100644 DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.h delete mode 100644 DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationObjectStrings.c create mode 100644 DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationObjectStrings.c diff --git a/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.c b/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.c index 15936c78c1..20977c1b82 100644 --- a/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.c +++ b/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.c @@ -1,10 +1,9 @@ #include <Uefi.h> #include <Library/UefiLib.h> #include <Library/UefiBootServicesTableLib.h> +#include <Library/TableHelperLib.h> #include <Protocol/ConfigurationManagerProtocol.h> -#include "ConfigurationManagerDumpApp.h" - EDKII_CONFIGURATION_MANAGER_PROTOCOL *mCfgMgr; EFI_STATUS @@ -33,10 +32,7 @@ UefiMain( continue; } - Print ( - L"<%s>::<%s>\n", - ObjectNameSpaceString[EObjNameSpaceStandard], - StdObjectString[ObjectId - EObjNameSpaceStandard]); + Print (L"<%s>\n", CmObjectIdName (ObjectId)); Print ( L"Id=%x Size=0x%x at=%p count=%d\n", @@ -54,10 +50,7 @@ UefiMain( continue; } - Print ( - L"<%s>::<%s>\n", - ObjectNameSpaceString[EObjNameSpaceArm], - ArmObjectString[ObjectId - EObjNameSpaceArm]); + Print (L"<%s>\n", CmObjectIdName(ObjectId)); Print ( L"Id=%x Size=0x%x at=%p count=%d\n", diff --git a/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.h b/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.h deleted file mode 100644 index 5017d55b4a..0000000000 --- a/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef CONFIGURATION_MANAGER_DUMP_APP_H_ -#define CONFIGURATION_MANAGER_DUMP_APP_H_ - -extern CHAR16 *ArmObjectString[]; -extern CHAR16 *ObjectNameSpaceString[]; -extern CHAR16 *StdObjectString[]; - -#endif diff --git a/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.inf b/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.inf index 9f8beb916d..f930ca3dcb 100644 --- a/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.inf +++ b/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.inf @@ -23,8 +23,6 @@ [Sources] ConfigurationManagerDumpApp.c - ConfigurationManagerDumpApp.h - ConfigurationObjectStrings.c [Packages] MdePkg/MdePkg.dec @@ -32,6 +30,7 @@ DynamicTablesPkg/DynamicTablesPkg.dec [LibraryClasses] + TableHelperLib UefiLib UefiBootServicesTableLib UefiApplicationEntryPoint diff --git a/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationObjectStrings.c b/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationObjectStrings.c deleted file mode 100644 index ad8dbb6354..0000000000 --- a/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationObjectStrings.c +++ /dev/null @@ -1,50 +0,0 @@ - -CHAR16 *ArmObjectString[] = { - L"Reserved", - L"Boot Architecture Info", - L"CPU Info", - L"Power Management Profile Info", - L"GIC CPU Interface Info", - L"GIC Distributor Info", - L"GIC MSI Frame Info", - L"GIC Redistributor Info", - L"GIC ITS Info", - L"Serial Console Port Info", - L"Serial Debug Port Info", - L"Generic Timer Info", - L"Platform GT Block Info", - L"Generic Timer Block Frame Info", - L"Platform Generic Watchdog", - L"PCI Configuration Space Info", - L"Hypervisor Vendor Id", - L"Fixed feature flags for FADT", - L"ITS Group", - L"Named Component", - L"Root Complex", - L"SMMUv1 or SMMUv2", - L"SMMUv3", - L"PMCG", - L"GIC ITS Identifier Array", - L"ID Mapping Array", - L"SMMU Interrupt Array", - L"Processor Hierarchy Info", - L"Cache Info", - L"Processor Node ID Info", - L"CM Object Reference", - L"Memory Affinity Info", - L"Device Handle Acpi", - L"Device Handle Pci", - L"Generic Initiator Affinity" -}; - -CHAR16 *ObjectNameSpaceString[] = { - L"Standard Objects Namespace", - L"ARM Objects Namespace", - L"OEM Objects Namespace" -}; - -CHAR16 *StdObjectString[] = { - L"Configuration Manager Info", - L"ACPI table Info List", - L"SMBIOS table Info List" -}; diff --git a/DynamicTablesPkg/Include/Library/TableHelperLib.h b/DynamicTablesPkg/Include/Library/TableHelperLib.h index 0d3d1bbd60..9269e77377 100644 --- a/DynamicTablesPkg/Include/Library/TableHelperLib.h +++ b/DynamicTablesPkg/Include/Library/TableHelperLib.h @@ -24,6 +24,18 @@ UINTN EFIAPI GetNewToken(); +/** + Returns the user friendly name for the given ObjectId. + + @param[in] CmObjectId The id of the configuration manager object + @return User friendly name for object id. +**/ +const CHAR16* +EFIAPI +CmObjectIdName( + IN CONST CM_OBJECT_ID CmObjectrId + ); + /** Return the count of objects of a given ObjectId. diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationObjectStrings.c b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationObjectStrings.c new file mode 100644 index 0000000000..e4c0e77633 --- /dev/null +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/ConfigurationObjectStrings.c @@ -0,0 +1,92 @@ +/** @file + ConfigurationObjectStrings.c + + Copyright (c) 2020, ARM Limited. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include <ConfigurationManagerObject.h> + +const CHAR16 *ArmObjectString[] = { + L"Reserved", + L"Boot Architecture Info", + L"CPU Info", + L"Power Management Profile Info", + L"GIC CPU Interface Info", + L"GIC Distributor Info", + L"GIC MSI Frame Info", + L"GIC Redistributor Info", + L"GIC ITS Info", + L"Serial Console Port Info", + L"Serial Debug Port Info", + L"Generic Timer Info", + L"Platform GT Block Info", + L"Generic Timer Block Frame Info", + L"Platform Generic Watchdog", + L"PCI Configuration Space Info", + L"Hypervisor Vendor Id", + L"Fixed feature flags for FADT", + L"ITS Group", + L"Named Component", + L"Root Complex", + L"SMMUv1 or SMMUv2", + L"SMMUv3", + L"PMCG", + L"GIC ITS Identifier Array", + L"ID Mapping Array", + L"SMMU Interrupt Array", + L"Processor Hierarchy Info", + L"Cache Info", + L"Processor Node ID Info", + L"CM Object Reference", + L"Memory Affinity Info", + L"Device Handle Acpi", + L"Device Handle Pci", + L"Generic Initiator Affinity" +}; + +const CHAR16 *ObjectNameSpaceString[] = { + L"Standard Objects Namespace", + L"ARM Objects Namespace", + L"OEM Objects Namespace" +}; + +const CHAR16 *StdObjectString[] = { + L"Configuration Manager Info", + L"ACPI table Info List", + L"SMBIOS table Info List" +}; + +const CHAR16* UnknownObject = L"Unknown Object"; + +/** + Returns the user friendly name for the given ObjectId. + + @param[in] CmObjectId The id of the configuration manager object + @return User friendly name for object id. +**/ +const CHAR16* +EFIAPI +CmObjectIdName( + IN CONST CM_OBJECT_ID CmObjectId + ) +{ + switch (GET_CM_NAMESPACE_ID(CmObjectId)) { + case EObjNameSpaceStandard: + if (CmObjectId < EStdObjMax) { + return StdObjectString[CmObjectId - EObjNameSpaceStandard]; + } else { + return UnknownObject; + } + case EObjNameSpaceArm: + if (CmObjectId < EArmObjMax) { + return ArmObjectString[CmObjectId - EObjNameSpaceArm]; + } else { + return UnknownObject; + } + default: + return UnknownObject; + } + + return UnknownObject; +} diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf index e12380073e..0fbc1fe5b2 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf @@ -16,6 +16,7 @@ [Sources] TableHelper.c + ConfigurationObjectStrings.c [Packages] MdePkg/MdePkg.dec -- 2.25.1
|
|
[PATCH 5/8] DynamicTablesPkg: Add CfgMgrProtocol helper functions
Tomas Pilar (tpilar)
Add functions abstracting adding and removing of objects using
the ConfigurationManagerProtocol to TableHelperLib. Also add helpers for writing component library constructors for component libraries populating a ConfigurationManager. Cc: Sami Mujawar <Sami.Mujawar@...> Cc: Alexei Fedorov <Alexei.Fedorov@...> Signed-off-by: Tomas Pilar <tomas@...> --- .../Include/Library/TableHelperLib.h | 170 ++++++++ .../Common/TableHelperLib/TableHelper.c | 379 +++++++++++++++++- .../Common/TableHelperLib/TableHelperLib.inf | 6 + 3 files changed, 554 insertions(+), 1 deletion(-) diff --git a/DynamicTablesPkg/Include/Library/TableHelperLib.h b/DynamicTablesPkg/Include/Library/TableHelperLib.h index e4a8dfa046..0d3d1bbd60 100644 --- a/DynamicTablesPkg/Include/Library/TableHelperLib.h +++ b/DynamicTablesPkg/Include/Library/TableHelperLib.h @@ -12,6 +12,176 @@ #ifndef TABLE_HELPER_LIB_H_ #define TABLE_HELPER_LIB_H_ +#include <Protocol/ConfigurationManagerProtocol.h> + +/** + Get a unique token that can be used for configuration object + cross referencing. + + @retval Unique arbitrary cross reference token. +**/ +UINTN +EFIAPI +GetNewToken(); + +/** + Return the count of objects of a given ObjectId. + + @param[in] CmObjectId The id of the desired configuration objects. + @param[out] ItemCount Number of objects with given ObjectId. +**/ +EFI_STATUS +EFIAPI +CfgMgrCountObjects ( + IN CONST CM_OBJECT_ID CmObjectId, + OUT UINT32 *ItemCount + ); + +/** + Get a single object form the configuration manager with the + matching ObjectId regardless of any cross reference tokens. + + @param[in] CmObjectId The id of the desired configuration object + @param[out] Buffer Buffer containing the payload of the CmObject. + + @retval EFI_SUCCESS Payload was successfully returned + @retval EFI_NOT_FOUND There was no such object + @retval EFI_UNSUPPORTED ConfigurationManangerProtocol is not installed +**/ +EFI_STATUS +EFIAPI +CfgMgrGetSimpleObject( + IN CONST CM_OBJECT_ID CmObjectId, + OUT VOID ** Buffer + ); + +/** + Prototype for an initialiser function to be used by component + libraries that are linked as NULL libraries to a Configuration + Manager binary and used to populate said Configuration Manager + with objects. + + @param[in] CfgMgrProtocol The newly installed ConfigurationManagerProtocol + that can be used by the library to populate the + Configuration Manager with objects. +**/ +typedef EFI_STATUS (EFIAPI *CFG_MGR_COMPONENT_LIB_INIT) ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CfgMgrProtocol + ); + +/** + Register a callback inintialiser to be called when a configuration + manager is installed. The initialiser function is expected to + populate the newly installed configuration manager with objects when + called. + + This helper should be used by component libraries that want to + provide configuration objects and are to be linked in as NULL + libraries into the configuration manager binary. + + @param[in] InitFunction An initialiser function that will be called when + a configuration manager becomes available. + @retval EFI_OUT_OF_RESOURCES Failed to allocate necessary memory. + @retval EFI_SUCCESS Registration was successful. +**/ +EFI_STATUS +EFIAPI +RegisterForCfgManager ( + IN CONST CFG_MGR_COMPONENT_LIB_INIT InitFunction + ); + +/** + Remove a configuration object from the configuration manager. If a + cross reference token is supplied, only objects referenced by that + token will be removed. If a token is not supplied, all objects of the + given type will be removed. + + @param[in] CmObjectId The id of the object that is to be removed. + @param[in] Token Unique cross-reference token of the object to be removed. + + @retval EFI_UNSUPPORTED There is no configuration manager installed. + @retval EFI_NOT_FOUND The combination of id and token was not found in the + configuration manager. + @retval EFI_SUCCESS Object was successfully deleted. +**/ +EFI_STATUS +EFIAPI +CfgMgrRemoveObject ( + IN CONST CM_OBJECT_ID CmObjectId, + IN CONST CM_OBJECT_TOKEN Token OPTIONAL + ); + +/** + Add an instance of object to the configuration manager. If an object with + the specified object id and token already exists in the manager, append the + provided object to the existing list. Otherwise, create a new list with this + object being the only member. + + @param[in] CmObjectId The id of the object that is to be added. + @param[in] Token The unique cross-reference token for this object. + @param[in] Buffer The instance of the object being added. + @param[in] BufferSize Size of Buffer in bytes. + + @retval EFI_OUT_OF_RESOURCES Failed to allocate required memory when appending data + @retval EFI_UNSUPPORTED There is no Configuration Manager installed + @retval EFI_SUCCESS Object was successfully added to the Configuration Manager +**/ +EFI_STATUS +EFIAPI +CfgMgrAddObject ( + IN CONST CM_OBJECT_ID CmObjectId, + IN CONST CM_OBJECT_TOKEN Token OPTIONAL, + IN VOID * Buffer, + IN UINTN BufferSize + ); + +/** + Add multiple objects of the same type/token to the configuration manager. + If an object with the specified object id and token already exists in the + manager, append the provided objects to the existing list. Otherwise, create + a new list. + + @param[in] CmObjectId The id of the object that is to be added. + @param[in] Token The unique cross-reference token for this object. + @param[in] Buffer The instance of the objects being added. + @param[in] BufferSize Size of Buffer in bytes. + @param[in] ItemCount Number of instances of object in the Buffer. + + @retval EFI_OUT_OF_RESOURCES Failed to allocate required memory when appending data. + @retval EFI_UNSUPPORTED There is no Configuration Manager installed. + @retval EFI_SUCCESS Object was successfully added to the Configuration Manager. +**/ +EFI_STATUS +EFIAPI +CfgMgrAddObjects ( + IN CONST CM_OBJECT_ID CmObjectId, + IN CONST CM_OBJECT_TOKEN Token OPTIONAL, + IN VOID * Buffer, + IN UINTN BufferSize, + IN UINT32 ItemCount + ); + +/** + Retrieve an object with a given id from the installed configuration + manager. If a token is not specified, returns all objects of given + id, regardless of token. The methods unwraps the CmObject abstraction + and only returns the payloads. + + @param[in] CmObjectId The id of the desired configuration objects. + @param[in] Token Optional cross reference token. If not supplied, all. + objects of the given id are returned. + @param[out] Buffer Buffer containing a number of payloads of CmObjects. + @param[out] ItemCount The count of payloads in Buffer. +**/ +EFI_STATUS +EFIAPI +CfgMgrGetObjects ( + IN CONST CM_OBJECT_ID CmObjectId, + IN CONST CM_OBJECT_TOKEN Token OPTIONAL, + OUT VOID ** Buffer OPTIONAL, + OUT UINT32 * ItemCount OPTIONAL + ); + /** The GetCgfMgrInfo function gets the CM_STD_OBJ_CONFIGURATION_MANAGER_INFO object from the Configuration Manager. diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c index fc6cf3b088..18c0e95e0d 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelper.c @@ -6,9 +6,13 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include <Protocol/AcpiTable.h> + #include <Library/BaseLib.h> -#include <Library/DebugLib.h> #include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/PrintLib.h> // Module specific include files. #include <AcpiTableGenerator.h> @@ -16,6 +20,378 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #include <Library/TableHelperLib.h> #include <Protocol/ConfigurationManagerProtocol.h> +/** + Get a unique token that can be used for configuration object + cross referencing. + + @retval Unique arbitrary cross reference token +**/ +UINTN +EFIAPI +GetNewToken() +{ + UINTN Token; + EFI_STATUS Status = gBS->GetNextMonotonicCount(&Token); + if (EFI_ERROR(Status)) { + return CM_NULL_TOKEN; + } + + return Token; +} + +/** + Event callback for executing the registered component library + inintialiser with the newly installed ConfigurationManagerProtocol + as the only parameter. +**/ +STATIC +VOID +EFIAPI +ComponentInitEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + ASSERT (Context != NULL); + + CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CfgMgrProtocol; + CFG_MGR_COMPONENT_LIB_INIT InitFunction = Context; + + EFI_STATUS Status = gBS->LocateProtocol ( + &gEdkiiConfigurationManagerProtocolGuid, + NULL, + (VOID **) &CfgMgrProtocol); + + + if (EFI_ERROR(Status)) { // Should never happen + gBS->CloseEvent(Event); + RegisterForCfgManager(InitFunction); + return; + } + + InitFunction(CfgMgrProtocol); +} + +/** + Register a callback inintialiser to be called when a configuration + manager is installed. The initialiser function is expected to + populate the newly installed configuration manager with objects when + called. + + This helper should be used by component libraries that want to + provide configuration objects and are to be linked in as NULL + libraries into the configuration manager binary. + + @param[in] InitFunction An initialiser function that will be called when + a configuration manager becomes available. + @retval EFI_OUT_OF_RESOURCES Failed to allocate necessary memory + @retval EFI_SUCCESS Registration was successful +**/ +EFI_STATUS +EFIAPI +RegisterForCfgManager ( + CONST CFG_MGR_COMPONENT_LIB_INIT InitFunction + ) +{ + EFI_STATUS Status = EFI_NOT_STARTED; + EFI_EVENT InitEvent; + VOID *Registration; + + ASSERT(InitFunction != NULL); + + Status = gBS->CreateEvent ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + ComponentInitEvent, + InitFunction, + &InitEvent); + + if (EFI_ERROR(Status)) { + return Status; + } + + Status = gBS->RegisterProtocolNotify ( + &gEdkiiConfigurationManagerProtocolGuid, + InitEvent, + &Registration); + + if (EFI_ERROR(Status)) { + gBS->CloseEvent(InitEvent); + } + + return Status; +} + +/** + Return the count of objects of a given ObjectId. + If there are no objects, ItemCount is set to zero. + + @param[in] CmObjectId The id of the desired configuration objects. + @param[out] ItemCount Number of objects with given ObjectId. +**/ +EFI_STATUS +EFIAPI +CfgMgrCountObjects ( + IN CONST CM_OBJECT_ID CmObjectId, + OUT UINT32 *ItemCount + ) +{ + EFI_STATUS Status = EFI_NOT_STARTED; + + Status = CfgMgrGetObjects (CmObjectId, CM_NULL_TOKEN, NULL, ItemCount); + if (Status == EFI_NOT_FOUND) { + *ItemCount = 0; + } + + return Status; +} + +/** + Retrieve an object with a given id from the installed configuration + manager. If a token is not specified, returns all objects of given + id, regardless of token. The methods unwraps the CmObject abstraction + and only returns the payloads. + + If Buffer is not NULL, the data will be returned in allocated memory. The + caller must free this memory when they are done with the data. + + If ItemCount is not NULL, the count of items matching the criteria + is returned. + + @param[in] CmObjectId The id of the desired configuration objects + @param[in] Token Optional cross reference token. If not supplied, all + objects of the given id are returned. + @param[out] Buffer Buffer containing a number of payloads of CmObjects. + @param[out] ItemCount The count of payloads in Buffer +**/ +EFI_STATUS +EFIAPI +CfgMgrGetObjects ( + IN CONST CM_OBJECT_ID CmObjectId, + IN CONST CM_OBJECT_TOKEN Token OPTIONAL, + OUT VOID ** Buffer OPTIONAL, + OUT UINT32 * ItemCount OPTIONAL + ) +{ + EDKII_CONFIGURATION_MANAGER_PROTOCOL *CfgMgr; + EFI_STATUS Status; + + Status = gBS->LocateProtocol ( + &gEdkiiConfigurationManagerProtocolGuid, NULL, (VOID **) &CfgMgr); + if (EFI_ERROR(Status)) { + DEBUG ((DEBUG_ERROR, "ERROR: No Configuration Manager Protocol Found!\n")); + return EFI_UNSUPPORTED; + } + + CM_OBJ_DESCRIPTOR Object; + + Status = CfgMgr->GetObject(CfgMgr, CmObjectId, Token, &Object); + if (EFI_ERROR(Status)) { + if (Status != EFI_NOT_FOUND) { + DEBUG ( + (DEBUG_ERROR, + "ERROR: FADT: Failed to get <%s> [%r]\n", + CmObjectIdName (CmObjectId), + Status)); + } + + return Status; + } + + if (Buffer) { + *Buffer = AllocateCopyPool (Object.Size, Object.Data); + if (Buffer == NULL) { + return EFI_OUT_OF_RESOURCES; + } + } + + if (ItemCount) { + *ItemCount = Object.Count; + } + + if (CfgMgr->Revision >= CREATE_REVISION(1, 1)) { + CfgMgr->FreeObject(CfgMgr, &Object); + } + + return EFI_SUCCESS; +} + +/** + Get a single object form the configuration manager with the + matching ObjectId regardless of any cross reference tokens. + + @param[in] CmObjectId The id of the desired configuration object + @param[out] Buffer Buffer containing the payload of the CmObject. + + @retval EFI_SUCCESS Payload was successfully returned + @retval EFI_NOT_FOUND There was no such object + @retval EFI_UNSUPPORTED ConfigurationManangerProtocol is not installed +**/ +EFI_STATUS +EFIAPI +CfgMgrGetSimpleObject( + IN CONST CM_OBJECT_ID CmObjectId, + OUT VOID ** Buffer + ) +{ + EFI_STATUS Status; + + Status = CfgMgrGetObjects(CmObjectId, CM_NULL_TOKEN, Buffer, NULL); + if (Status == EFI_NOT_FOUND) { + DEBUG ((DEBUG_ERROR, + "ERROR: Failed to get <%s> [%r]\n", + CmObjectIdName (CmObjectId), + Status)); + } + return Status; +} + +/** + Add an instance of object to the configuration manager. If an object with + the specified object id and token already exists in the manager, append the + provided object to the existing list. Otherwise, create a new list with this + object being the only member. + + @param[in] CmObjectId The id of the object that is to be added + @param[in] Token The unique cross-reference token for this object + @param[in] Buffer The instance of the object being added + @param[in] BufferSize Size of Buffer in bytes + + @retval EFI_OUT_OF_RESOURCES Failed to allocate required memory when appending data + @retval EFI_UNSUPPORTED There is no Configuration Manager installed + @retval EFI_SUCCESS Object was successfully added to the Configuration Manager +**/ +EFI_STATUS +EFIAPI +CfgMgrAddObject ( + IN CONST CM_OBJECT_ID CmObjectId, + IN CONST CM_OBJECT_TOKEN Token OPTIONAL, + IN VOID * Buffer, + IN UINTN BufferSize + ) +{ + EFI_STATUS Status; + EDKII_CONFIGURATION_MANAGER_PROTOCOL *CfgMgrProtocol; + CM_OBJ_DESCRIPTOR CurrentObject = { 0 }; + CM_OBJ_DESCRIPTOR NewObject; + + ASSERT(Buffer != NULL); + ASSERT(BufferSize != 0); + + Status = gBS->LocateProtocol ( + &gEdkiiConfigurationManagerProtocolGuid, NULL, (VOID **) &CfgMgrProtocol); + + if (EFI_ERROR(Status)) { + return EFI_UNSUPPORTED; + } + + Status = CfgMgrProtocol->GetObject ( + CfgMgrProtocol, CmObjectId, Token, &CurrentObject); + + NewObject.ObjectId = CmObjectId; + NewObject.Count = 1 + CurrentObject.Count; + NewObject.Size = BufferSize +CurrentObject.Size; + + NewObject.Data = AllocateZeroPool(NewObject.Size); + if (NewObject.Data == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + CopyMem(NewObject.Data, CurrentObject.Data, CurrentObject.Size); // NOP if CurrentObject does not exist + CopyMem((UINT8 *) NewObject.Data + CurrentObject.Size, Buffer, BufferSize); + + Status = + CfgMgrProtocol->SetObject (CfgMgrProtocol, CmObjectId, Token, &NewObject); + + FreePool (NewObject.Data); + return Status; +} + +/** + Add multiple objects of the same type/token to the configuration manager. + If an object with the specified object id and token already exists in the + manager, append the provided objects to the existing list. Otherwise, create + a new list. + + @param[in] CmObjectId The id of the object that is to be added. + @param[in] Token The unique cross-reference token for this object. + @param[in] Buffer The instance of the objects being added. + @param[in] BufferSize Size of Buffer in bytes. + @param[in] ItemCount Number of instances of object in the Buffer. + + @retval EFI_OUT_OF_RESOURCES Failed to allocate required memory when appending data. + @retval EFI_UNSUPPORTED There is no Configuration Manager installed. + @retval EFI_SUCCESS Object was successfully added to the Configuration Manager. +**/ +EFI_STATUS +EFIAPI +CfgMgrAddObjects ( + IN CONST CM_OBJECT_ID CmObjectId, + IN CONST CM_OBJECT_TOKEN Token OPTIONAL, + IN VOID * Buffer, + IN UINTN BufferSize, + IN UINT32 ItemCount + ) +{ + UINTN Index; + UINT8 *Cursor = Buffer; + UINTN ItemSize = BufferSize / ItemCount; + EFI_STATUS Status = EFI_NOT_STARTED; + + for (Index = 0; Index < ItemCount; Index++) { + Status = CfgMgrAddObject(CmObjectId, Token, Cursor, ItemSize); + if (EFI_ERROR(Status)) { + return Status; + } + Cursor += ItemSize; + } + + return EFI_SUCCESS; +} + +/** + Remove a configuration object from the configuration manager. If a + cross reference token is supplied, only objects referenced by that + token will be removed. If a token is not supplied, all objects of the + given type will be removed. + + @param[in] CmObjectId The id of object that is to be removed + @param[in] Token Unique cross-reference token of the object to be removed + + @retval EFI_UNSUPPORTED There is no configuration manager installed + @retval EFI_NOT_FOUND The combination of id and token was not found in the + configuration manager + @retval EFI_SUCCESS Object was successfully deleted +**/ +EFI_STATUS +EFIAPI +CfgMgrRemoveObject ( + IN CONST CM_OBJECT_ID CmObjectId, + IN CONST CM_OBJECT_TOKEN Token OPTIONAL + ) +{ + EFI_STATUS Status = EFI_NOT_STARTED; + EDKII_CONFIGURATION_MANAGER_PROTOCOL *CfgMgrProtocol; + CM_OBJ_DESCRIPTOR CurrentObject; + + Status = gBS->LocateProtocol ( + &gEdkiiConfigurationManagerProtocolGuid, NULL, (VOID **) &CfgMgrProtocol); + + if (EFI_ERROR(Status)) { + return EFI_UNSUPPORTED; + } + + Status = CfgMgrProtocol->GetObject ( + CfgMgrProtocol, CmObjectId, Token, &CurrentObject); + + if (EFI_ERROR(Status)) { + return Status; + } + + return CfgMgrProtocol->SetObject (CfgMgrProtocol, CmObjectId, Token, NULL); +} + + /** The GetCgfMgrInfo function gets the CM_STD_OBJ_CONFIGURATION_MANAGER_INFO object from the Configuration Manager. @@ -44,6 +420,7 @@ GetCgfMgrInfo ( ASSERT (CfgMfrInfo != NULL); *CfgMfrInfo = NULL; + Status = CfgMgrProtocol->GetObject ( CfgMgrProtocol, CREATE_CM_STD_OBJECT_ID (EStdObjCfgMgrInfo), diff --git a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf index 26d82e6850..e12380073e 100644 --- a/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf +++ b/DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf @@ -23,8 +23,14 @@ [LibraryClasses] BaseLib + BaseMemoryLib + DebugLib + PrintLib + MemoryAllocationLib + UefiBootServicesTableLib [Protocols] + gEfiSerialIoProtocolGuid [Guids] -- 2.25.1
|
|
[PATCH 4/8] DynamicTablesPkg: Update ConfigurationManagerProtocol
Tomas Pilar (tpilar)
The Configuration Manager Protocol is updated to include
a FreeObject function that must be used by the callers to GetObject to clean up any dynamic allocations and other resources reserved by the Configuration Manager in the process of fulfilling the request in GetObject. A NULL inline static FreeObject function is provided for the ease of transition for v1.0 managers. Cc: Sami Mujawar <Sami.Mujawar@...> Cc: Alexei Fedorov <Alexei.Fedorov@...> Signed-off-by: Tomas Pilar <tomas@...> --- .../Protocol/ConfigurationManagerProtocol.h | 83 ++++++++++++++++++- 1 file changed, 80 insertions(+), 3 deletions(-) diff --git a/DynamicTablesPkg/Include/Protocol/ConfigurationManagerProtocol.h b/DynamicTablesPkg/Include/Protocol/ConfigurationManagerProtocol.h index 7de1be3b23..72bf3c79bc 100644 --- a/DynamicTablesPkg/Include/Protocol/ConfigurationManagerProtocol.h +++ b/DynamicTablesPkg/Include/Protocol/ConfigurationManagerProtocol.h @@ -25,7 +25,7 @@ /** This macro defines the Configuration Manager Protocol Revision. */ -#define EDKII_CONFIGURATION_MANAGER_PROTOCOL_REVISION CREATE_REVISION (1, 0) +#define EDKII_CONFIGURATION_MANAGER_PROTOCOL_REVISION CREATE_REVISION (1, 1) #pragma pack(1) @@ -35,10 +35,18 @@ typedef struct ConfigurationManagerProtocol EDKII_CONFIGURATION_MANAGER_PROTOCOL; typedef struct PlatformRepositoryInfo EDKII_PLATFORM_REPOSITORY_INFO; -/** The GetObject function defines the interface implemented by the +/** The GetObject function defines the interface of the Configuration Manager Protocol for returning the Configuration Manager Objects. + If Token is CM_NULL_TOKEN, the function provides in its output all + the objects of the given CmObjectId. If the Token is not CM_NULL_TOKEN, + the function provides only those object that match both the CmObjectId + and Token. + + The memory in CmObject.Data may be static or dynamic. The caller of this + function must call FreeObject on the CmObject populated by this function. + @param [in] This Pointer to the Configuration Manager Protocol. @param [in] CmObjectId The Configuration Manager Object ID. @param [in] Token An optional token identifying the object. If @@ -62,10 +70,24 @@ EFI_STATUS IN OUT CM_OBJ_DESCRIPTOR * CONST CmObject ); -/** The SetObject function defines the interface implemented by the +/** The SetObject function defines the interface of the Configuration Manager Protocol for updating the Configuration Manager Objects. + If Token is CM_NULL_TOKEN, and CmObject is not NULL, then the objects + in the configuration manager that match the CmObjectId and do not + have an associated cross reference Token are replaced by the contents of + CmObject. + + If Token is not CM_NULL_TOKEN and CmObject is not NULL, then the objects + that match both CmObjectId and Token in the configuration manager are + replaced with the contents of CmObject. + + If CmObject is NULL, then objects that match the CmObjectId and Token + are removed from the configuration manager. If Token is also CM_NULL_TOKEN, + then all objects of given CmObjectId are removed, regardless of their + cross-reference Token. + @param [in] This Pointer to the Configuration Manager Protocol. @param [in] CmObjectId The Configuration Manager Object ID. @param [in] Token An optional token identifying the object. If @@ -90,6 +112,29 @@ EFI_STATUS IN CM_OBJ_DESCRIPTOR * CONST CmObject ); +/** The FreeObject function defines the interface of the + Configuration Manager Protocol for correctly freeing resources + that have been reserved by calls to the GetObject interface. + + The caller of GetObject must use this function to dispose of CmObject + populated by the GetObject call when the CmObject is no longer needed. + + If an implementation of the Configuration Manager Protocol does not + use dynamically allocated memory, this function should simply return + EFI_SUCCESS. + + @param [in] This Pointer to the Configuration Manager Protocol + @param [in] CmObject Pointer to the CmObject that has been populated + by the GetObject function and is to be destroyed. + @retval EFI_SUCCESS The CmObject was successfully destroyed +**/ +typedef +EFI_STATUS +(EFIAPI * EDKII_CONFIGURATION_MANAGER_FREE_OBJECT) ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST This, + IN CM_OBJ_DESCRIPTOR * CmObject + ); + /** The EDKII_CONFIGURATION_MANAGER_PROTOCOL structure describes the Configuration Manager Protocol interface. */ @@ -111,12 +156,44 @@ typedef struct ConfigurationManagerProtocol { provisioned by the Configuration Manager. */ EDKII_PLATFORM_REPOSITORY_INFO * PlatRepoInfo; + + /** The interface used to destroy CmObject instances + populated by calls to GetObject + */ + EDKII_CONFIGURATION_MANAGER_FREE_OBJECT FreeObject; } EDKII_CONFIGURATION_MANAGER_PROTOCOL; /** The Configuration Manager Protocol GUID. */ extern EFI_GUID gEdkiiConfigurationManagerProtocolGuid; +/** Inline NULL implementation of FreeObject for backward compatibility + of configuration managers that do not require to deallocate any + memory following a call to GetObject. + + @param[in] This Pointer to Configuration Manager Protocol instance + @param[in] CmObject Pointer to CmObject populated by GetObject + + @retval EFI_SUCCESS Successfully handled CmObject. + @retval EFI_INVALID_PARAMETER CmObject is NULL. + @retval EFI_INVALID_PARAMETER This is NULL. + @retval EFI_INVALID_PARAMETER CmObject is not valid. +**/ +static +inline +EFI_STATUS +EFIAPI EdkiiCfgMgrFreeObjectNull ( + IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL * CONST This, + IN CM_OBJ_DESCRIPTOR * CmObject + ) +{ + if (!This || !CmObject) { + return EFI_INVALID_PARAMETER; + } + + return EFI_SUCCESS; +} + #pragma pack() #endif // CONFIGURATION_MANAGER_PROTOCOL_H_ -- 2.25.1
|
|
[PATCH 3/8] DynamicTablesPkg: Add ConfigurationManagerDumpApp
Tomas Pilar (tpilar)
Simple application to dump the contents of the configuration
manager loaded in the platform to the screen. There is no provision in the ConfigurationManagerProtocol for informing consumers of the contents of the database, so the app scans through the known namespaces using the GetObject method. Cc: Sami Mujawar <Sami.Mujawar@...> Cc: Alexei Fedorov <Alexei.Fedorov@...> Signed-off-by: Tomas Pilar <tomas@...> --- .../ConfigurationManagerDumpApp.c | 76 +++++++++++++++++++ .../ConfigurationManagerDumpApp.h | 8 ++ .../ConfigurationManagerDumpApp.inf | 42 ++++++++++ .../ConfigurationObjectStrings.c | 50 ++++++++++++ DynamicTablesPkg/DynamicTablesPkg.dsc | 6 ++ 5 files changed, 182 insertions(+) create mode 100644 DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.c create mode 100644 DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.h create mode 100644 DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.inf create mode 100644 DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationObjectStrings.c diff --git a/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.c b/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.c new file mode 100644 index 0000000000..15936c78c1 --- /dev/null +++ b/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.c @@ -0,0 +1,76 @@ +#include <Uefi.h> +#include <Library/UefiLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Protocol/ConfigurationManagerProtocol.h> + +#include "ConfigurationManagerDumpApp.h" + +EDKII_CONFIGURATION_MANAGER_PROTOCOL *mCfgMgr; + +EFI_STATUS +EFIAPI +UefiMain( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE * SystemTable + ) +{ + EFI_STATUS Status = gBS->LocateProtocol ( + &gEdkiiConfigurationManagerProtocolGuid, NULL, (VOID **)&mCfgMgr); + + UINTN ObjectId; + CM_OBJ_DESCRIPTOR CmObject; + UINTN Count = 0; + + + if (EFI_ERROR(Status)) { + Print(L"No Configuration Manager installed!\n"); + return EFI_UNSUPPORTED; + } + + for (ObjectId = EObjNameSpaceStandard; ObjectId < EStdObjMax; ObjectId++) { + Status = mCfgMgr->GetObject (mCfgMgr, ObjectId, CM_NULL_TOKEN, &CmObject); + if (EFI_ERROR(Status)) { + continue; + } + + Print ( + L"<%s>::<%s>\n", + ObjectNameSpaceString[EObjNameSpaceStandard], + StdObjectString[ObjectId - EObjNameSpaceStandard]); + + Print ( + L"Id=%x Size=0x%x at=%p count=%d\n", + CmObject.ObjectId, + CmObject.Size, + CmObject.Count, + CmObject.Count); + + Count++; + } + + for (ObjectId = EObjNameSpaceArm; ObjectId < EArmObjMax; ObjectId++) { + Status = mCfgMgr->GetObject (mCfgMgr, ObjectId, CM_NULL_TOKEN, &CmObject); + if (EFI_ERROR(Status)) { + continue; + } + + Print ( + L"<%s>::<%s>\n", + ObjectNameSpaceString[EObjNameSpaceArm], + ArmObjectString[ObjectId - EObjNameSpaceArm]); + + Print ( + L"Id=%x Size=0x%x at=%p count=%d\n", + CmObject.ObjectId, + CmObject.Size, + CmObject.Count, + CmObject.Count); + + Count++; + } + + Print(L"Found %d objects\n", Count); + return EFI_SUCCESS; +} + + diff --git a/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.h b/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.h new file mode 100644 index 0000000000..5017d55b4a --- /dev/null +++ b/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.h @@ -0,0 +1,8 @@ +#ifndef CONFIGURATION_MANAGER_DUMP_APP_H_ +#define CONFIGURATION_MANAGER_DUMP_APP_H_ + +extern CHAR16 *ArmObjectString[]; +extern CHAR16 *ObjectNameSpaceString[]; +extern CHAR16 *StdObjectString[]; + +#endif diff --git a/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.inf b/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.inf new file mode 100644 index 0000000000..9f8beb916d --- /dev/null +++ b/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.inf @@ -0,0 +1,42 @@ +## @file +# Application that will dump the contents of the configuration +# manager. +# +# Copyright (c) 2020, ARM Limited. All rights reserved. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010019 + BASE_NAME = ConfigurationManagerDumpApp + FILE_GUID = 1E12FA81-8465-4D78-918F-735DB8CB828B + MODULE_TYPE = UEFI_APPLICATION + VERSION_STRING = 1.0 + ENTRY_POINT = UefiMain + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = ARM AARCH64 +# + +[Sources] + ConfigurationManagerDumpApp.c + ConfigurationManagerDumpApp.h + ConfigurationObjectStrings.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + DynamicTablesPkg/DynamicTablesPkg.dec + +[LibraryClasses] + UefiLib + UefiBootServicesTableLib + UefiApplicationEntryPoint + +[Protocols] + gEdkiiConfigurationManagerProtocolGuid # PROTOCOL PRODUCES + + diff --git a/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationObjectStrings.c b/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationObjectStrings.c new file mode 100644 index 0000000000..ad8dbb6354 --- /dev/null +++ b/DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationObjectStrings.c @@ -0,0 +1,50 @@ + +CHAR16 *ArmObjectString[] = { + L"Reserved", + L"Boot Architecture Info", + L"CPU Info", + L"Power Management Profile Info", + L"GIC CPU Interface Info", + L"GIC Distributor Info", + L"GIC MSI Frame Info", + L"GIC Redistributor Info", + L"GIC ITS Info", + L"Serial Console Port Info", + L"Serial Debug Port Info", + L"Generic Timer Info", + L"Platform GT Block Info", + L"Generic Timer Block Frame Info", + L"Platform Generic Watchdog", + L"PCI Configuration Space Info", + L"Hypervisor Vendor Id", + L"Fixed feature flags for FADT", + L"ITS Group", + L"Named Component", + L"Root Complex", + L"SMMUv1 or SMMUv2", + L"SMMUv3", + L"PMCG", + L"GIC ITS Identifier Array", + L"ID Mapping Array", + L"SMMU Interrupt Array", + L"Processor Hierarchy Info", + L"Cache Info", + L"Processor Node ID Info", + L"CM Object Reference", + L"Memory Affinity Info", + L"Device Handle Acpi", + L"Device Handle Pci", + L"Generic Initiator Affinity" +}; + +CHAR16 *ObjectNameSpaceString[] = { + L"Standard Objects Namespace", + L"ARM Objects Namespace", + L"OEM Objects Namespace" +}; + +CHAR16 *StdObjectString[] = { + L"Configuration Manager Info", + L"ACPI table Info List", + L"SMBIOS table Info List" +}; diff --git a/DynamicTablesPkg/DynamicTablesPkg.dsc b/DynamicTablesPkg/DynamicTablesPkg.dsc index 346fa8ccdd..367e06a855 100644 --- a/DynamicTablesPkg/DynamicTablesPkg.dsc +++ b/DynamicTablesPkg/DynamicTablesPkg.dsc @@ -30,6 +30,11 @@ PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf + UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf + UefiLib|MdePkg/Library/UefiLib/UefiLib.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf + [LibraryClasses.ARM, LibraryClasses.AARCH64] NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf @@ -38,6 +43,7 @@ [Components.common] DynamicTablesPkg/Library/Common/TableHelperLib/TableHelperLib.inf + DynamicTablesPkg/Applications/ConfigurationManagerDumpApp/ConfigurationManagerDumpApp.inf [BuildOptions] *_*_*_CC_FLAGS = -DDISABLE_NEW_DEPRECATED_INTERFACES -- 2.25.1
|
|