Re: [edk2] [PATCH v2 01/11] StandaloneMmPkg: add HobLib implementation for MM_STANDALONE modules
Reviewed-by: jiewen@intel.com > -Original Message- > From: Ard Biesheuvel [mailto:ard.biesheu...@linaro.org] > Sent: Wednesday, January 16, 2019 12:22 PM > To: edk2-devel@lists.01.org > Cc: Ard Biesheuvel ; Achin Gupta > ; Yao, Jiewen ; Supreeth > Venkatesh ; Leif Lindholm > ; Jagadeesh Ujja ; > Thomas Panakamattam Abraham ; Sami > Mujawar > Subject: [PATCH v2 01/11] StandaloneMmPkg: add HobLib implementation > for MM_STANDALONE modules > > This HobLib code is based on the staging implementation of > StandaloneMmPkg, with the following changes: > - drop the unused AArch64/StandaloneMmCoreHobLibInternal.c source file > - remove hack from HobLibConstructor() > - update code comments referring the MM core > > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Jagadeesh Ujja > Signed-off-by: Ard Biesheuvel > --- > StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c > | 649 > > StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.inf > | 45 ++ > 2 files changed, 694 insertions(+) > > diff --git > a/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c > b/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c > new file mode 100644 > index ..cc1a08166470 > --- /dev/null > +++ > b/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c > @@ -0,0 +1,649 @@ > +/** @file > + HOB Library implementation for Standalone MM Core. > + > +Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved. > +Copyright (c) 2017 - 2018, ARM Limited. All rights reserved. > +Copyright (c) 2018, Linaro, Ltd. All rights reserved. > + > +This program and the accompanying materials > +are licensed and made available under the terms and conditions of the BSD > License > +which accompanies this distribution. The full text of the license may be > found at > +http://opensource.org/licenses/bsd-license.php. > + > +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > BASIS, > +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > EXPRESS OR IMPLIED. > + > +**/ > + > +#include > + > +#include > +#include > +#include > +#include > + > +// > +// Cache copy of HobList pointer. > +// > +STATIC VOID *gHobList = NULL; > + > +/** > + The constructor function caches the pointer to HOB list. > + > + The constructor function gets the start address of HOB list from system > configuration table. > + It will ASSERT() if that operation fails and it will always return > EFI_SUCCESS. > + > + @param ImageHandle The firmware allocated handle for the > image. > + @param MmSystemTable A pointer to the MM System Table. > + > + @retval EFI_SUCCESS The constructor successfully gets HobList. > + @retval Other value The constructor can't get HobList. > + > +**/ > +EFI_STATUS > +EFIAPI > +HobLibConstructor ( > + IN EFI_HANDLE ImageHandle, > + IN EFI_MM_SYSTEM_TABLE*MmSystemTable > + ) > +{ > + UINTN Index; > + > + for (Index = 0; Index < gMmst->NumberOfTableEntries; Index++) { > +if (CompareGuid (&gEfiHobListGuid, > &gMmst->MmConfigurationTable[Index].VendorGuid)) { > + gHobList = gMmst->MmConfigurationTable[Index].VendorTable; > + break; > +} > + } > + return EFI_SUCCESS; > +} > + > +/** > + Returns the pointer to the HOB list. > + > + This function returns the pointer to first HOB in the list. > + If the pointer to the HOB list is NULL, then ASSERT(). > + > + @return The pointer to the HOB list. > + > +**/ > +VOID * > +EFIAPI > +GetHobList ( > + VOID > + ) > +{ > + UINTN Index; > + > + if (gHobList == NULL) { > +for (Index = 0; Index < gMmst->NumberOfTableEntries; Index++) { > + if (CompareGuid (&gEfiHobListGuid, > &gMmst->MmConfigurationTable[Index].VendorGuid)) { > +gHobList = gMmst->MmConfigurationTable[Index].VendorTable; > +break; > + } > +} > + } > + ASSERT (gHobList != NULL); > + return gHobList; > +} > + > +/** > + Returns the next instance of a HOB type from the starting HOB. > + > + This function searches the first instance of a HOB type from the starting > HOB pointer. > + If there does not exist such HOB type from the starting HOB pointer, it > will return NULL. > + In contrast with macro GET_NEXT_HOB(), this function does not skip the > starting HOB pointer > + unconditionally: it returns HobStart back if HobStart itself meets the > requirement; > + caller is required to use GET_NEXT_HOB() if it wishes to skip current > HobStart. > + > + If HobStart is NULL, then ASSERT(). > + > + @param Type The HOB type to return. > + @param HobStart The starting HOB pointer to search from. > + > + @return The next instance of a HOB type from the starting HOB. > + > +**/ > +VOID * > +EFIAPI > +GetNextHob ( > + IN UINT16 Type, > + IN CONST VOID *HobStart > + ) > +{ > + EFI_PEI_HOB_POINTERS Hob; > + > + ASSERT (HobStart != NULL); > + > +
[edk2] [PATCH v2 01/11] StandaloneMmPkg: add HobLib implementation for MM_STANDALONE modules
This HobLib code is based on the staging implementation of StandaloneMmPkg, with the following changes: - drop the unused AArch64/StandaloneMmCoreHobLibInternal.c source file - remove hack from HobLibConstructor() - update code comments referring the MM core Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jagadeesh Ujja Signed-off-by: Ard Biesheuvel --- StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c | 649 StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.inf | 45 ++ 2 files changed, 694 insertions(+) diff --git a/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c b/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c new file mode 100644 index ..cc1a08166470 --- /dev/null +++ b/StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.c @@ -0,0 +1,649 @@ +/** @file + HOB Library implementation for Standalone MM Core. + +Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved. +Copyright (c) 2017 - 2018, ARM Limited. All rights reserved. +Copyright (c) 2018, Linaro, Ltd. All rights reserved. + +This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php. + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include + +#include +#include +#include +#include + +// +// Cache copy of HobList pointer. +// +STATIC VOID *gHobList = NULL; + +/** + The constructor function caches the pointer to HOB list. + + The constructor function gets the start address of HOB list from system configuration table. + It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. + + @param ImageHandle The firmware allocated handle for the image. + @param MmSystemTable A pointer to the MM System Table. + + @retval EFI_SUCCESS The constructor successfully gets HobList. + @retval Other value The constructor can't get HobList. + +**/ +EFI_STATUS +EFIAPI +HobLibConstructor ( + IN EFI_HANDLE ImageHandle, + IN EFI_MM_SYSTEM_TABLE*MmSystemTable + ) +{ + UINTN Index; + + for (Index = 0; Index < gMmst->NumberOfTableEntries; Index++) { +if (CompareGuid (&gEfiHobListGuid, &gMmst->MmConfigurationTable[Index].VendorGuid)) { + gHobList = gMmst->MmConfigurationTable[Index].VendorTable; + break; +} + } + return EFI_SUCCESS; +} + +/** + Returns the pointer to the HOB list. + + This function returns the pointer to first HOB in the list. + If the pointer to the HOB list is NULL, then ASSERT(). + + @return The pointer to the HOB list. + +**/ +VOID * +EFIAPI +GetHobList ( + VOID + ) +{ + UINTN Index; + + if (gHobList == NULL) { +for (Index = 0; Index < gMmst->NumberOfTableEntries; Index++) { + if (CompareGuid (&gEfiHobListGuid, &gMmst->MmConfigurationTable[Index].VendorGuid)) { +gHobList = gMmst->MmConfigurationTable[Index].VendorTable; +break; + } +} + } + ASSERT (gHobList != NULL); + return gHobList; +} + +/** + Returns the next instance of a HOB type from the starting HOB. + + This function searches the first instance of a HOB type from the starting HOB pointer. + If there does not exist such HOB type from the starting HOB pointer, it will return NULL. + In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer + unconditionally: it returns HobStart back if HobStart itself meets the requirement; + caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart. + + If HobStart is NULL, then ASSERT(). + + @param Type The HOB type to return. + @param HobStart The starting HOB pointer to search from. + + @return The next instance of a HOB type from the starting HOB. + +**/ +VOID * +EFIAPI +GetNextHob ( + IN UINT16 Type, + IN CONST VOID *HobStart + ) +{ + EFI_PEI_HOB_POINTERS Hob; + + ASSERT (HobStart != NULL); + + Hob.Raw = (UINT8 *) HobStart; + // + // Parse the HOB list until end of list or matching type is found. + // + while (!END_OF_HOB_LIST (Hob)) { +if (Hob.Header->HobType == Type) { + return Hob.Raw; +} +Hob.Raw = GET_NEXT_HOB (Hob); + } + return NULL; +} + +/** + Returns the first instance of a HOB type among the whole HOB list. + + This function searches the first instance of a HOB type among the whole HOB list. + If there does not exist such HOB type in the HOB list, it will return NULL. + + If the pointer to the HOB list is NULL, then ASSERT(). + + @param Type The HOB type to return. + + @return The next instance of a HOB type from the starting HOB. + +**/ +VOID * +EFIAPI +GetFirstHob ( + IN UINT16