Importing spam
On Fri, Mar 12, 2021 at 4:46 AM, Yao, Jiewen<jiewen.yao@intel.com> wrote:Can we merge the common part between X64 and AArch64 into one Common.c?> -----Original Message-----> From: Kun Qin <kun.q@outlook.com>> Sent: Saturday, December 19, 2020 2:50 AM> To: devel@edk2.groups.io> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>; Sami Mujawar> Venkatesh <supreeth.venkatesh@arm.com>> Subject: [PATCH v1 02/15] StandaloneMmPkg: StandaloneMmCoreHobLib:> Extend support for x64 Mm Core>> This change adds support of x64 version of StandaloneMmCoreHobLib. It> brings in global variable "gHobList" through StandaloneMmCoreEntryPoint> and imports implementation from DxeCoreHobLib.inf to support x64 Mm> Core.>> Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>> Cc: Sami Mujawar <sami.mujawar@arm.com>> Cc: Jiewen Yao <jiewen.yao@intel.com>> Cc: Supreeth Venkatesh <supreeth.venkatesh@arm.com>>> Signed-off-by: Kun Qin <kun.q@outlook.com>> ---> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/{ =>> AArch64}/StandaloneMmCoreHobLib.c | 6 +-> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/{ =>> X64}/StandaloneMmCoreHobLib.c | 426 ++++++++++---------->> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCore> HobLib.inf | 8 +-> 3 files changed, 215 insertions(+), 225 deletions(-)>> diff --git> a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCo> reHobLib.c> b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/AArch64/Standal> oneMmCoreHobLib.c> similarity index 96%> copy from> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCore> HobLib.c> copy to> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/AArch64/Standalon> eMmCoreHobLib.c> index e3d4743b63f2..006bff816e39 100644> ---> a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCo> reHobLib.c> +++> b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/AArch64/Standal> oneMmCoreHobLib.c> @@ -13,14 +13,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent> #include <Library/HobLib.h>> #include <Library/DebugLib.h>> #include <Library/BaseMemoryLib.h>> +#include <Library/StandaloneMmCoreEntryPoint.h>>> #include <Guid/MemoryAllocationHob.h>>> -//> -// Cache copy of HobList pointer.> -//> -VOID *gHobList = NULL;> -> /**> Returns the pointer to the HOB list.>> diff --git> a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCo> reHobLib.c> b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/Standalone> MmCoreHobLib.c> similarity index 70%> rename from> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCore> HobLib.c> rename to> StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/StandaloneM> mCoreHobLib.c> index e3d4743b63f2..69b20bf07a21 100644> ---> a/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCo> reHobLib.c> +++> b/StandaloneMmPkg/Library/StandaloneMmCoreHobLib/X64/Standalone> MmCoreHobLib.c> @@ -13,14 +13,10 @@ SPDX-License-Identifier: BSD-2-Clause-Patent> #include <Library/HobLib.h>> #include <Library/DebugLib.h>> #include <Library/BaseMemoryLib.h>> +#include <Library/StandaloneMmCoreEntryPoint.h>>> #include <Guid/MemoryAllocationHob.h>>> -//> -// Cache copy of HobList pointer.> -//> -VOID *gHobList = NULL;> -> /**> Returns the pointer to the HOB list.>> @@ -203,48 +199,13 @@ GetBootModeHob (> return HandOffHob->BootMode;> }>> -VOID *> -CreateHob (> - IN UINT16 HobType,> - IN UINT16 HobLength> - )> -{> - EFI_HOB_HANDOFF_INFO_TABLE *HandOffHob;> - EFI_HOB_GENERIC_HEADER *HobEnd;> - EFI_PHYSICAL_ADDRESS FreeMemory;> - VOID *Hob;> -> - HandOffHob = GetHobList ();> -> - HobLength = (UINT16)((HobLength + 0x7) & (~0x7));> -> - FreeMemory = HandOffHob->EfiFreeMemoryTop - HandOffHob-> >EfiFreeMemoryBottom;> -> - if (FreeMemory < HobLength) {> - return NULL;> - }> -> - Hob = (VOID*) (UINTN) HandOffHob->EfiEndOfHobList;> - ((EFI_HOB_GENERIC_HEADER*) Hob)->HobType = HobType;> - ((EFI_HOB_GENERIC_HEADER*) Hob)->HobLength = HobLength;> - ((EFI_HOB_GENERIC_HEADER*) Hob)->Reserved = 0;> -> - HobEnd = (EFI_HOB_GENERIC_HEADER*) ((UINTN)Hob + HobLength);> - HandOffHob->EfiEndOfHobList = (EFI_PHYSICAL_ADDRESS) (UINTN)> HobEnd;> -> - HobEnd->HobType = EFI_HOB_TYPE_END_OF_HOB_LIST;> - HobEnd->HobLength = sizeof (EFI_HOB_GENERIC_HEADER);> - HobEnd->Reserved = 0;> - HobEnd++;> - HandOffHob->EfiFreeMemoryBottom = (EFI_PHYSICAL_ADDRESS) (UINTN)> HobEnd;> -> - return Hob;> -}> -> /**> Builds a HOB for a loaded PE32 module.>> This function builds a HOB for a loaded PE32 module.> + It can only be invoked during PEI phase;> + for MM phase, it will ASSERT() because PEI HOB is read-only for MM> phase.> +> If ModuleName is NULL, then ASSERT().> If there is no additional space for HOB creation, then ASSERT().>> @@ -263,31 +224,51 @@ BuildModuleHob (> IN EFI_PHYSICAL_ADDRESS EntryPoint> )> {> - EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;> + //> + // PEI HOB is read only for MM phase> + //> + ASSERT (FALSE);> +}>> - ASSERT (((MemoryAllocationModule & (EFI_PAGE_SIZE - 1)) == 0) &&> - ((ModuleLength & (EFI_PAGE_SIZE - 1)) == 0));> +/**> + Builds a HOB that describes a chunk of system memory with Owner GUID.>> - Hob = CreateHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, sizeof> (EFI_HOB_MEMORY_ALLOCATION_MODULE));> + This function builds a HOB that describes a chunk of system memory.> + It can only be invoked during PEI phase;> + for MM phase, it will ASSERT() since PEI HOB is read-only for MM phase.>> - CopyGuid (&(Hob->MemoryAllocationHeader.Name),> &gEfiHobMemoryAllocModuleGuid);> - Hob->MemoryAllocationHeader.MemoryBaseAddress => MemoryAllocationModule;> - Hob->MemoryAllocationHeader.MemoryLength = ModuleLength;> - Hob->MemoryAllocationHeader.MemoryType = EfiBootServicesCode;> + If there is no additional space for HOB creation, then ASSERT().>> + @param ResourceType The type of resource described by this HOB.> + @param ResourceAttribute The resource attributes of the memory> described by this HOB.> + @param PhysicalStart The 64 bit physical address of memory> described by this HOB.> + @param NumberOfBytes The length of the memory described by this> HOB in bytes.> + @param OwnerGUID GUID for the owner of this resource.> +> +**/> +VOID> +EFIAPI> +BuildResourceDescriptorWithOwnerHob (> + IN EFI_RESOURCE_TYPE ResourceType,> + IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,> + IN EFI_PHYSICAL_ADDRESS PhysicalStart,> + IN UINT64 NumberOfBytes,> + IN EFI_GUID *OwnerGUID> + )> +{> //> - // Zero the reserved space to match HOB spec> + // PEI HOB is read only for MM phase> //> - ZeroMem (Hob->MemoryAllocationHeader.Reserved, sizeof (Hob-> >MemoryAllocationHeader.Reserved));> -> - CopyGuid (&Hob->ModuleName, ModuleName);> - Hob->EntryPoint = EntryPoint;> + ASSERT (FALSE);> }>> /**> Builds a HOB that describes a chunk of system memory.>> This function builds a HOB that describes a chunk of system memory.> + It can only be invoked during PEI phase;> + for MM phase, it will ASSERT() because PEI HOB is read-only for MM> phase.> +> If there is no additional space for HOB creation, then ASSERT().>> @param ResourceType The type of resource described by this HOB.> @@ -305,31 +286,32 @@ BuildResourceDescriptorHob (> IN UINT64 NumberOfBytes> )> {> - EFI_HOB_RESOURCE_DESCRIPTOR *Hob;> -> - Hob = CreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, sizeof> (EFI_HOB_RESOURCE_DESCRIPTOR));> - ASSERT (Hob != NULL);> -> - Hob->ResourceType = ResourceType;> - Hob->ResourceAttribute = ResourceAttribute;> - Hob->PhysicalStart = PhysicalStart;> - Hob->ResourceLength = NumberOfBytes;> + //> + // PEI HOB is read only for MM phase> + //> + ASSERT (FALSE);> }>> /**> - Builds a GUID HOB with a certain data length.> + Builds a customized HOB tagged with a GUID for identification and> returns> + the start address of GUID HOB data.>> This function builds a customized HOB tagged with a GUID for> identification> and returns the start address of GUID HOB data so that caller can fill the> customized data.> The HOB Header and Name field is already stripped.> + It can only be invoked during PEI phase.> + For MM phase, it will ASSERT() because PEI HOB is read-only for MM> phase.> +> If Guid is NULL, then ASSERT().> If there is no additional space for HOB creation, then ASSERT().> - If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().> + If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().> + HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is> 0xFFF8.>> @param Guid The GUID to tag the customized HOB.> @param DataLength The size of the data payload for the GUID HOB.>> - @return The start address of GUID HOB data.> + @retval NULL The GUID HOB could not be allocated.> + @retval others The start address of GUID HOB data.>> **/> VOID *> @@ -339,35 +321,36 @@ BuildGuidHob (> IN UINTN DataLength> )> {> - EFI_HOB_GUID_TYPE *Hob;> -> //> - // Make sure that data length is not too long.> + // PEI HOB is read only for MM phase> //> - ASSERT (DataLength <= (0xffff - sizeof (EFI_HOB_GUID_TYPE)));> -> - Hob = CreateHob (EFI_HOB_TYPE_GUID_EXTENSION, (UINT16) (sizeof> (EFI_HOB_GUID_TYPE) + DataLength));> - CopyGuid (&Hob->Name, Guid);> - return Hob + 1;> + ASSERT (FALSE);> + return NULL;> }>> -> /**> - Copies a data buffer to a newly-built HOB.> + Builds a customized HOB tagged with a GUID for identification, copies the> input data to the HOB> + data field, and returns the start address of the GUID HOB data.>> - This function builds a customized HOB tagged with a GUID for> identification,> - copies the input data to the HOB data field and returns the start address> of the GUID HOB data.> + This function builds a customized HOB tagged with a GUID for> identification and copies the input> + data to the HOB data field and returns the start address of the GUID HOB> data. It can only be> + invoked during PEI phase; for MM phase, it will ASSERT() because PEI> HOB is read-only for MM phase.> The HOB Header and Name field is already stripped.> + It can only be invoked during PEI phase.> + For MM phase, it will ASSERT() because PEI HOB is read-only for MM> phase.> +> If Guid is NULL, then ASSERT().> If Data is NULL and DataLength > 0, then ASSERT().> If there is no additional space for HOB creation, then ASSERT().> - If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().> + If DataLength > (0xFFF8 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().> + HobLength is UINT16 and multiples of 8 bytes, so the max HobLength is> 0xFFF8.>> @param Guid The GUID to tag the customized HOB.> @param Data The data to be copied into the data field of the GUID> HOB.> @param DataLength The size of the data payload for the GUID HOB.>> - @return The start address of GUID HOB data.> + @retval NULL The GUID HOB could not be allocated.> + @retval others The start address of GUID HOB data.>> **/> VOID *> @@ -378,20 +361,22 @@ BuildGuidDataHob (> IN UINTN DataLength> )> {> - VOID *HobData;> -> - ASSERT (Data != NULL || DataLength == 0);> -> - HobData = BuildGuidHob (Guid, DataLength);> -> - return CopyMem (HobData, Data, DataLength);> + //> + // PEI HOB is read only for MM phase> + //> + ASSERT (FALSE);> + return NULL;> }>> /**> Builds a Firmware Volume HOB.>> This function builds a Firmware Volume HOB.> + It can only be invoked during PEI phase;> + for MM phase, it will ASSERT() because PEI HOB is read-only for MM> phase.> +> If there is no additional space for HOB creation, then ASSERT().> + If the FvImage buffer is not at its required alignment, then ASSERT()