[PATCH v1 04/41] PrmPkg/PrmConfigDxe: Add initial driver
Michael Kubacki
From: Michael Kubacki <michael.kubacki@...>
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3812 This driver serves as a generic PRM configuration driver. Its primary role is to prepare PRM resources published by PRM module configuration libraries for OS runtime. As such, it locates all PRM Configuration Protocol instances and consumes the information to ready those resources. For example, set runtime memory attributes on MMIO ranges and convert physical addresses to virtual addresses in PRM buffers. Cc: Andrew Fish <afish@...> Cc: Kang Gao <kang.gao@...> Cc: Michael D Kinney <michael.d.kinney@...> Cc: Michael Kubacki <michael.kubacki@...> Cc: Leif Lindholm <leif@...> Cc: Benjamin You <benjamin.you@...> Cc: Liu Yun <yun.y.liu@...> Cc: Ankit Sinha <ankit.sinha@...> Cc: Nate DeSimone <nathaniel.l.desimone@...> Signed-off-by: Michael Kubacki <michael.kubacki@...> --- PrmPkg/PrmConfigDxe/PrmConfigDxe.c | 559 ++++++++++++ PrmPkg/PrmLoaderDxe/PrmLoaderDxe.c | 925 ++++++++++++++++++++ PrmPkg/PrmConfigDxe/PrmConfigDxe.inf | 48 + PrmPkg/PrmLoaderDxe/PrmAcpiTable.h | 97 ++ PrmPkg/PrmLoaderDxe/PrmLoader.h | 51 ++ PrmPkg/PrmLoaderDxe/PrmLoaderDxe.inf | 59 ++ 6 files changed, 1739 insertions(+) diff --git a/PrmPkg/PrmConfigDxe/PrmConfigDxe.c b/PrmPkg/PrmConfigDxe/Prm= ConfigDxe.c new file mode 100644 index 000000000000..cb38146bc9e0 --- /dev/null +++ b/PrmPkg/PrmConfigDxe/PrmConfigDxe.c @@ -0,0 +1,559 @@ +/** @file + + This file contains the implementation for a Platform Runtime Mechanism= (PRM) configuration driver. + + Copyright (c) Microsoft Corporation + Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/DxeServicesTableLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiRuntimeServicesTableLib.h> +#include <Library/UefiLib.h> + +#include <PiDxe.h> +#include <PrmContextBuffer.h> +#include <PrmDataBuffer.h> +#include <PrmMmio.h> +#include <Protocol/PrmConfig.h> + +#define _DBGMSGID_ "[PRMCONFIG]" + +STATIC UINTN mMaxRuntimeMmioRangeCount; +STATIC UINTN mMaxStaticDataBufferCount; + +STATIC PRM_RUNTIME_MMIO_RANGES **mRuntimeMmioRanges; +STATIC PRM_DATA_BUFFER ***mStaticDataBuffers; + +/** + Converts the runtime memory range physical addresses to virtual addres= ses. + + @param[in] RuntimeMmioRanges A pointer to a PRM_RUNTIME_MMIO_RANGES= buffer. + +**/ +VOID +ConvertRuntimeMemoryRangeAddresses ( + IN PRM_RUNTIME_MMIO_RANGES *RuntimeMmioRanges + ) +{ + UINTN Index; + + if (RuntimeMmioRanges =3D=3D NULL || RuntimeMmioRanges->Count =3D=3D 0= ) { + return; + } + + for (Index =3D 0; Index < (UINTN) RuntimeMmioRanges->Count; Index++) { + RuntimeMmioRanges->Range[Index].VirtualBaseAddress =3D RuntimeMmioRa= nges->Range[Index].PhysicalBaseAddress; + gRT->ConvertPointer (0x0, (VOID **) &(RuntimeMmioRanges->Range[Index= ].VirtualBaseAddress)); + } +} + +/** + Sets the runtime memory range attributes. + + The EFI_MEMORY_RUNTIME attribute is set for each PRM_RUNTIME_MMIO_RANG= E present + in the buffer provided. + + @param[in] RuntimeMmioRanges A pointer to a PRM_RUNTIME_MMIO_RANG= ES buffer. + +**/ +VOID +SetRuntimeMemoryRangeAttributes ( + IN PRM_RUNTIME_MMIO_RANGES *RuntimeMmioRanges + ) +{ + EFI_STATUS Status; + EFI_STATUS Status2; + UINTN Index; + EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor; + + DEBUG ((DEBUG_INFO, "%a %a - Entry.\n", _DBGMSGID_, __FUNCTION__)); + + if (RuntimeMmioRanges =3D=3D NULL || RuntimeMmioRanges->Count =3D=3D 0= ) { + return; + } + + for (Index =3D 0; Index < (UINTN) RuntimeMmioRanges->Count; Index++) { + DEBUG (( + DEBUG_INFO, " %a %a: Runtime MMIO Range [%d].\n", _DBGMSGID_,= __FUNCTION__, Index)); + DEBUG (( + DEBUG_INFO, + " %a %a: Physical address =3D 0x%016x. Length =3D 0x%x.\n", + _DBGMSGID_, + __FUNCTION__, + RuntimeMmioRanges->Range[Index].PhysicalBaseAddress, + RuntimeMmioRanges->Range[Index].Length + )); + + // Runtime memory ranges should cover ranges on a page boundary + ASSERT ((RuntimeMmioRanges->Range[Index].PhysicalBaseAddress & EFI_P= AGE_MASK) =3D=3D 0); + ASSERT ((RuntimeMmioRanges->Range[Index].Length & EFI_PAGE_MASK) =3D= =3D 0); + + Status2 =3D EFI_NOT_FOUND; + Status =3D gDS->GetMemorySpaceDescriptor (RuntimeMmioRanges->Range[I= ndex].PhysicalBaseAddress, &Descriptor); + if (!EFI_ERROR (Status) && + ( + (Descriptor.GcdMemoryType !=3D EfiGcdMemoryTypeMemoryMappedIo &&= Descriptor.GcdMemoryType !=3D EfiGcdMemoryTypeReserved) || + ((Descriptor.Length & EFI_PAGE_MASK) !=3D 0) + ) + ) { + Status2 =3D gDS->RemoveMemorySpace ( + RuntimeMmioRanges->Range[Index].PhysicalBaseAddr= ess, + Descriptor.Length + ); + } + + if (Status =3D=3D EFI_NOT_FOUND || !EFI_ERROR (Status2)) { + Status =3D gDS->AddMemorySpace ( + EfiGcdMemoryTypeMemoryMappedIo, + RuntimeMmioRanges->Range[Index].PhysicalBaseAddres= s, + (UINT64) RuntimeMmioRanges->Range[Index].Length, + EFI_MEMORY_UC | EFI_MEMORY_RUNTIME + ); + ASSERT_EFI_ERROR (Status); + + Status =3D gDS->AllocateMemorySpace ( + EfiGcdAllocateAddress, + EfiGcdMemoryTypeMemoryMappedIo, + 0, + (UINT64) RuntimeMmioRanges->Range[Index].Length, + &RuntimeMmioRanges->Range[Index].PhysicalBaseAddre= ss, + gImageHandle, + NULL + ); + ASSERT_EFI_ERROR (Status); + } + + Status =3D gDS->GetMemorySpaceDescriptor (RuntimeMmioRanges->Range[I= ndex].PhysicalBaseAddress, &Descriptor); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + " %a %a: Error [%r] finding descriptor for runtime memory r= ange 0x%016x.\n", + _DBGMSGID_, + __FUNCTION__, + Status, + RuntimeMmioRanges->Range[Index].PhysicalBaseAddress + )); + continue; + } + if ((Descriptor.Attributes & EFI_MEMORY_RUNTIME) !=3D 0) { + continue; + } + + Status =3D gDS->SetMemorySpaceAttributes ( + RuntimeMmioRanges->Range[Index].PhysicalBaseAddress, + (UINT64) RuntimeMmioRanges->Range[Index].Length, + Descriptor.Attributes | EFI_MEMORY_RUNTIME + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + " %a %a: Error [%r] setting descriptor for runtime memory r= ange 0x%016x.\n", + _DBGMSGID_, + __FUNCTION__, + Status, + RuntimeMmioRanges->Range[Index].PhysicalBaseAddress + )); + } else { + DEBUG ((DEBUG_INFO, " %a %a: Successfully set runtime attribu= te for the MMIO range.\n", _DBGMSGID_, __FUNCTION__)); + } + } +} + +/** + Stores pointers or pointer to resources that should be converted in th= e virtual address change event. + +**/ +VOID +StoreVirtualMemoryAddressChangePointers ( + VOID + ) +{ + EFI_STATUS Status; + UINTN BufferIndex; + UINTN HandleCount; + UINTN HandleIndex; + UINTN RangeIndex; + UINTN StaticDataBufferIndex; + EFI_HANDLE *HandleBuffer; + PRM_CONFIG_PROTOCOL *PrmConfigProtocol; + PRM_CONTEXT_BUFFER *CurrentContextBuffer; + + DEBUG ((DEBUG_INFO, "%a %a - Entry.\n", _DBGMSGID_, __FUNCTION__)); + + RangeIndex =3D 0; + StaticDataBufferIndex =3D 0; + + mRuntimeMmioRanges =3D AllocateRuntimeZeroPool (sizeof (*mRuntimeMmioR= anges) * mMaxRuntimeMmioRangeCount); + if (mRuntimeMmioRanges =3D=3D NULL && mMaxRuntimeMmioRangeCount > 0) { + DEBUG (( + DEBUG_ERROR, + " %a %a: Memory allocation for runtime MMIO pointer array failed.= \n", + _DBGMSGID_, + __FUNCTION__ + )); + ASSERT (FALSE); + return; + } + + mStaticDataBuffers =3D AllocateRuntimeZeroPool (sizeof (*mStaticDataBu= ffers) * mMaxStaticDataBufferCount); + if (mStaticDataBuffers =3D=3D NULL && mMaxStaticDataBufferCount > 0) { + DEBUG (( + DEBUG_ERROR, + " %a %a: Memory allocation for PRM static data buffer pointer arr= ay failed.\n", + _DBGMSGID_, + __FUNCTION__ + )); + ASSERT (FALSE); + return; + } + + HandleBuffer =3D NULL; + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gPrmConfigProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (!EFI_ERROR (Status)) { + for (HandleIndex =3D 0; HandleIndex < HandleCount; HandleIndex++) { + Status =3D gBS->HandleProtocol ( + HandleBuffer[HandleIndex], + &gPrmConfigProtocolGuid, + (VOID **) &PrmConfigProtocol + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status) || PrmConfigProtocol =3D=3D NULL) { + continue; + } + + for (BufferIndex =3D 0; BufferIndex < PrmConfigProtocol->ModuleCon= textBuffers.BufferCount; BufferIndex++) { + CurrentContextBuffer =3D &(PrmConfigProtocol->ModuleContextBuffe= rs.Buffer[BufferIndex]); + + if (CurrentContextBuffer->StaticDataBuffer !=3D NULL) { + if (StaticDataBufferIndex >=3D mMaxStaticDataBufferCount) { + Status =3D EFI_BUFFER_TOO_SMALL; + DEBUG (( + DEBUG_ERROR, + " %a %a: Index out of bounds - Actual count (%d) of PRM d= ata buffers exceeds maximum count (%d).\n", + _DBGMSGID_, + __FUNCTION__, + StaticDataBufferIndex + 1, + mMaxStaticDataBufferCount + )); + ASSERT_EFI_ERROR (Status); + return; + } + mStaticDataBuffers[StaticDataBufferIndex++] =3D &CurrentContex= tBuffer->StaticDataBuffer; + } + } + if (PrmConfigProtocol->ModuleContextBuffers.RuntimeMmioRanges !=3D= NULL) { + if (RangeIndex >=3D mMaxRuntimeMmioRangeCount) { + Status =3D EFI_BUFFER_TOO_SMALL; + DEBUG (( + DEBUG_ERROR, + " %a %a: Index out of bounds - Actual count (%d) of runtime= MMIO ranges exceeds maximum count (%d).\n", + _DBGMSGID_, + __FUNCTION__, + RangeIndex + 1, + mMaxRuntimeMmioRangeCount + )); + ASSERT_EFI_ERROR (Status); + return; + } + mRuntimeMmioRanges[RangeIndex++] =3D PrmConfigProtocol->ModuleCo= ntextBuffers.RuntimeMmioRanges; + } + } + DEBUG (( + DEBUG_INFO, + " %a %a: %d MMIO ranges buffers saved for future virtual memory c= onversion.\n", + _DBGMSGID_, + __FUNCTION__, + RangeIndex + )); + DEBUG (( + DEBUG_INFO, + " %a %a: %d static buffers saved for future virtual memory conver= sion.\n", + _DBGMSGID_, + __FUNCTION__, + StaticDataBufferIndex + )); + } +} + +/** + Validates a data buffer for a PRM module. + + Verifies the buffer header signature is valid and the length meets the= minimum size. + + @param[in] PrmDataBuffer A pointer to the data buffer for thi= s PRM module. + + @retval EFI_SUCCESS The data buffer was validated succes= sfully. + @retval EFI_INVALID_PARAMETER The pointer given for PrmDataBuffer = is NULL. + @retval EFI_NOT_FOUND The data buffer signature is not val= id. + @retval EFI_BUFFER_TOO_SMALL The buffer size is too small. + +**/ +EFI_STATUS +ValidatePrmDataBuffer ( + IN CONST PRM_DATA_BUFFER *PrmDataBuffer + ) +{ + if (PrmDataBuffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (PrmDataBuffer->Header.Signature !=3D PRM_DATA_BUFFER_HEADER_SIGNAT= URE) { + DEBUG ((DEBUG_ERROR, " %a %a: The PRM data buffer signature is inva= lid. PRM module.\n", _DBGMSGID_, __FUNCTION__)); + return EFI_NOT_FOUND; + } + if (PrmDataBuffer->Header.Length < sizeof (PRM_DATA_BUFFER_HEADER)) { + DEBUG ((DEBUG_ERROR, " %a %a: The PRM data buffer length is invalid= .\n", _DBGMSGID_, __FUNCTION__)); + return EFI_BUFFER_TOO_SMALL; + } + + return EFI_SUCCESS; +} + +/** + Validates a PRM context buffer. + + Verifies the buffer header signature is valid and the GUID is set to a= non-zero value. + + @param[in] PrmContextBuffer A pointer to the context buffer for = this PRM handler. + + @retval EFI_SUCCESS The context buffer was validated suc= cessfully. + @retval EFI_INVALID_PARAMETER The pointer given for ContextBuffer = is NULL. + @retval EFI_NOT_FOUND The proper value for a field was not= found. + +**/ +EFI_STATUS +ValidatePrmContextBuffer ( + IN CONST PRM_CONTEXT_BUFFER *PrmContextBuffer + ) +{ + if (PrmContextBuffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + if (PrmContextBuffer->Signature !=3D PRM_CONTEXT_BUFFER_SIGNATURE) { + DEBUG ((DEBUG_ERROR, " %a %a: The PRM context buffer signature is i= nvalid.\n", _DBGMSGID_, __FUNCTION__)); + return EFI_NOT_FOUND; + } + + if (IsZeroGuid (&PrmContextBuffer->HandlerGuid)) { + DEBUG ((DEBUG_ERROR, " %a %a: The PRM context buffer GUID is zero.\= n", _DBGMSGID_, __FUNCTION__)); + return EFI_NOT_FOUND; + } + + if (PrmContextBuffer->StaticDataBuffer !=3D NULL && EFI_ERROR (Validat= ePrmDataBuffer (PrmContextBuffer->StaticDataBuffer))) { + DEBUG (( + DEBUG_ERROR, + " %a %a: Error in static buffer for PRM handler %g.\n", + _DBGMSGID_, + __FUNCTION__, + &PrmContextBuffer->HandlerGuid + )); + return EFI_NOT_FOUND; + } + + return EFI_SUCCESS; +} + +/** + Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE. + + This is notification function converts any registered PRM_RUNTIME_MMIO= _RANGE + addresses to a virtual address. + + @param[in] Event Event whose notification function is being in= voked. + @param[in] Context Pointer to the notification function's contex= t. + +**/ +VOID +EFIAPI +PrmConfigVirtualAddressChangeEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + UINTN Index; + + // + // Convert static data buffer pointers + // + for (Index =3D 0; Index < mMaxStaticDataBufferCount; Index++) { + gRT->ConvertPointer (0x0, (VOID **) mStaticDataBuffers[Index]); + } + + // + // Convert runtime MMIO ranges + // + for (Index =3D 0; Index < mMaxRuntimeMmioRangeCount; Index++) { + ConvertRuntimeMemoryRangeAddresses (mRuntimeMmioRanges[Index]); + } +} + +/** + The PRM Config END_OF_DXE protocol notification event handler. + + Finds all of the PRM_CONFIG_PROTOCOL instances installed at end of DXE= and + marks all PRM_RUNTIME_MMIO_RANGE entries as EFI_MEMORY_RUNTIME. + + @param[in] Event Event whose notification function is being= invoked. + @param[in] Context The pointer to the notification function's= context, + which is implementation-dependent. + + @retval EFI_SUCCESS The function executed successfully + +**/ +EFI_STATUS +EFIAPI +PrmConfigEndOfDxeNotification ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + UINTN HandleCount; + UINTN BufferIndex; + UINTN HandleIndex; + EFI_HANDLE *HandleBuffer; + PRM_CONTEXT_BUFFER *CurrentContextBuffer; + PRM_CONFIG_PROTOCOL *PrmConfigProtocol; + + DEBUG ((DEBUG_INFO, "%a %a - Entry.\n", _DBGMSGID_, __FUNCTION__)); + + HandleBuffer =3D NULL; + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gPrmConfigProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (!EFI_ERROR (Status)) { + for (HandleIndex =3D 0; HandleIndex < HandleCount; HandleIndex++) { + Status =3D gBS->HandleProtocol ( + HandleBuffer[HandleIndex], + &gPrmConfigProtocolGuid, + (VOID **) &PrmConfigProtocol + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status) || PrmConfigProtocol =3D=3D NULL) { + continue; + } + + DEBUG (( + DEBUG_INFO, + " %a %a: Found PRM configuration protocol for PRM module %g.\n"= , + _DBGMSGID_, + __FUNCTION__, + &PrmConfigProtocol->ModuleContextBuffers.ModuleGuid + )); + + DEBUG ((DEBUG_INFO, " %a %a: Validating module context buffer= s...\n", _DBGMSGID_, __FUNCTION__)); + for (BufferIndex =3D 0; BufferIndex < PrmConfigProtocol->ModuleCon= textBuffers.BufferCount; BufferIndex++) { + CurrentContextBuffer =3D &(PrmConfigProtocol->ModuleContextBuffe= rs.Buffer[BufferIndex]); + + Status =3D ValidatePrmContextBuffer (CurrentContextBuffer); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + " %a %a: Context buffer validation failed for PRM han= dler %g.\n", + _DBGMSGID_, + __FUNCTION__, + CurrentContextBuffer->HandlerGuid + )); + } + if (CurrentContextBuffer->StaticDataBuffer !=3D NULL) { + mMaxStaticDataBufferCount++; + } + } + DEBUG ((DEBUG_INFO, " %a %a: Module context buffer validation= complete.\n", _DBGMSGID_, __FUNCTION__)); + + if (PrmConfigProtocol->ModuleContextBuffers.RuntimeMmioRanges !=3D= NULL) { + DEBUG (( + DEBUG_INFO, + " %a %a: Found %d PRM runtime MMIO ranges to convert.\n", + _DBGMSGID_, + __FUNCTION__, + PrmConfigProtocol->ModuleContextBuffers.RuntimeMmioRanges->Co= unt + )); + SetRuntimeMemoryRangeAttributes (PrmConfigProtocol->ModuleContex= tBuffers.RuntimeMmioRanges); + mMaxRuntimeMmioRangeCount++; + } + } + + StoreVirtualMemoryAddressChangePointers (); + } + + if (HandleBuffer !=3D NULL) { + gBS->FreePool (HandleBuffer); + } + gBS->CloseEvent(Event); + + return EFI_SUCCESS; +} + +/** + The entry point for this module. + + @param[in] ImageHandle The firmware allocated handle for the EFI = image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Others An error occurred when executing this entr= y point. + +**/ +EFI_STATUS +EFIAPI +PrmConfigEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_EVENT Event; + + DEBUG ((DEBUG_INFO, "%a %a - Entry.\n", _DBGMSGID_, __FUNCTION__)); + + // + // Register a notification function to change memory attributes at end= of DXE + // + Event =3D NULL; + Status =3D gBS->CreateEventEx( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + PrmConfigEndOfDxeNotification, + NULL, + &gEfiEndOfDxeEventGroupGuid, + &Event + ); + ASSERT_EFI_ERROR (Status); + + // + // Register a notification function for virtual address change + // + Event =3D NULL; + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + PrmConfigVirtualAddressChangeEvent, + NULL, + &gEfiEventVirtualAddressChangeGuid, + &Event + ); + ASSERT_EFI_ERROR (Status); + + return EFI_SUCCESS; +} diff --git a/PrmPkg/PrmLoaderDxe/PrmLoaderDxe.c b/PrmPkg/PrmLoaderDxe/Prm= LoaderDxe.c new file mode 100644 index 000000000000..b43e6d6bf078 --- /dev/null +++ b/PrmPkg/PrmLoaderDxe/PrmLoaderDxe.c @@ -0,0 +1,925 @@ +/** @file + + This file contains the implementation for a Platform Runtime Mechanism= (PRM) + loader driver. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include "PrmAcpiTable.h" +#include "PrmLoader.h" + +#include <IndustryStandard/Acpi.h> +#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/PrmContextBufferLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiLib.h> +#include <Protocol/AcpiTable.h> +#include <Protocol/LoadedImage.h> +#include <Protocol/PrmConfig.h> + +#include <PrmContextBuffer.h> +#include <PrmMmio.h> +#include <PrmModuleUpdate.h> + +LIST_ENTRY mPrmModuleList; + +// Todo: Potentially refactor mPrmHandlerCount and mPrmModuleCount into = localized structures +// in the future. +UINT32 mPrmHandlerCount; +UINT32 mPrmModuleCount; + +/** + Gets a pointer to the export directory in a given PE/COFF image. + + @param[in] ImageExportDirectory A pointer to an export directo= ry table in a PE/COFF image. + @param[in] PeCoffLoaderImageContext A pointer to a PE_COFF_LOADER_= IMAGE_CONTEXT structure that contains the + PE/COFF image context for the = Image containing the PRM Module Export + Descriptor table. + @param[out] ExportDescriptor A pointer to a pointer to the = PRM Module Export Descriptor table found + in the ImageExportDirectory gi= ven. + + @retval EFI_SUCCESS The PRM Module Export Descript= or table was found successfully. + @retval EFI_INVALID_PARAMETER A required parameter is NULL. + @retval EFI_NOT_FOUND The PRM Module Export Descript= or table was not found in the given + ImageExportDirectory. + +**/ +EFI_STATUS +GetPrmModuleExportDescriptorTable ( + IN EFI_IMAGE_EXPORT_DIRECTORY *ImageExportDirectory, + IN PE_COFF_LOADER_IMAGE_CONTEXT *PeCoffLoaderImageContext, + OUT PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT **ExportDescriptor + ) +{ + UINTN Index; + EFI_PHYSICAL_ADDRESS CurrentImageAddress; + UINT16 PrmModuleExportDescriptorOrdin= al; + CONST CHAR8 *CurrentExportName; + UINT16 *OrdinalTable; + UINT32 *ExportNamePointerTable; + UINT32 *ExportAddressTable; + PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT *TempExportDescriptor; + + DEBUG ((DEBUG_INFO, "%a %a - Entry.\n", _DBGMSGID_, __FUNCTION__)); + + *ExportDescriptor =3D NULL; + + if (ImageExportDirectory =3D=3D NULL || + PeCoffLoaderImageContext =3D=3D NULL || + PeCoffLoaderImageContext->ImageAddress =3D=3D 0 || + ExportDescriptor =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + DEBUG (( + DEBUG_INFO, + " %a %a: %d exported names found in this image.\n", + _DBGMSGID_, + __FUNCTION__, + ImageExportDirectory->NumberOfNames + )); + + // + // The export name pointer table and export ordinal table form two par= allel arrays associated by index. + // + CurrentImageAddress =3D PeCoffLoaderImageContext->ImageAddress; + ExportAddressTable =3D (UINT32 *) ((UINTN) CurrentImageAddress + Image= ExportDirectory->AddressOfFunctions); + ExportNamePointerTable =3D (UINT32 *) ((UINTN) CurrentImageAddress + I= mageExportDirectory->AddressOfNames); + OrdinalTable =3D (UINT16 *) ((UINTN) CurrentImageAddress + ImageExport= Directory->AddressOfNameOrdinals); + + for (Index =3D 0; Index < ImageExportDirectory->NumberOfNames; Index++= ) { + CurrentExportName =3D (CONST CHAR8 *) ((UINTN) CurrentImageAddress += ExportNamePointerTable[Index]); + DEBUG (( + DEBUG_INFO, + " %a %a: Export Name[0x%x] - %a.\n", + _DBGMSGID_, + __FUNCTION__, + Index, + CurrentExportName + )); + if ( + AsciiStrnCmp ( + PRM_STRING(PRM_MODULE_EXPORT_DESCRIPTOR_NAME), + CurrentExportName, + AsciiStrLen (PRM_STRING(PRM_MODULE_EXPORT_DESCRIPTOR_NAME)) + ) =3D=3D 0) { + PrmModuleExportDescriptorOrdinal =3D OrdinalTable[Index]; + DEBUG (( + DEBUG_INFO, + " %a %a: PRM Module Export Descriptor found. Ordinal =3D %d.\n"= , + _DBGMSGID_, + __FUNCTION__, + PrmModuleExportDescriptorOrdinal + )); + if (PrmModuleExportDescriptorOrdinal >=3D ImageExportDirectory->Nu= mberOfFunctions) { + DEBUG ((DEBUG_ERROR, "%a %a: The PRM Module Export Descriptor or= dinal value is invalid.\n", _DBGMSGID_, __FUNCTION__)); + return EFI_NOT_FOUND; + } + TempExportDescriptor =3D (PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT *) (= (UINTN) CurrentImageAddress + ExportAddressTable[PrmModuleExportDescripto= rOrdinal]); + if (TempExportDescriptor->Signature =3D=3D PRM_MODULE_EXPORT_DESCR= IPTOR_SIGNATURE) { + *ExportDescriptor =3D TempExportDescriptor; + DEBUG ((DEBUG_INFO, " %a %a: PRM Module Export Descriptor found= at 0x%x.\n", _DBGMSGID_, __FUNCTION__, (UINTN) ExportDescriptor)); + } else { + DEBUG (( + DEBUG_INFO, + " %a %a: PRM Module Export Descriptor found at 0x%x but signa= ture check failed.\n", + _DBGMSGID_, + __FUNCTION__, + (UINTN) TempExportDescriptor + )); + } + DEBUG ((DEBUG_INFO, " %a %a: Exiting export iteration since expor= t descriptor found.\n", _DBGMSGID_, __FUNCTION__)); + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + +/** + Gets a pointer to the export directory in a given PE/COFF image. + + @param[in] Image A pointer to a PE32/COFF image= base address that is loaded into memory + and already relocated to the m= emory base address. RVAs in the image given + should be valid. + @param[in] PeCoffLoaderImageContext A pointer to a PE_COFF_LOADER_= IMAGE_CONTEXT structure that contains the + PE/COFF image context for the = Image given. + @param[out] ImageExportDirectory A pointer to a pointer to the = export directory found in the Image given. + + @retval EFI_SUCCESS The export directory was found= successfully. + @retval EFI_INVALID_PARAMETER A required parameter is NULL. + @retval EFI_UNSUPPORTED The PE/COFF image given is not= supported as a PRM Module. + @retval EFI_NOT_FOUND The image export directory cou= ld not be found for this image. + +**/ +EFI_STATUS +GetExportDirectoryInPeCoffImage ( + IN VOID *Image, + IN PE_COFF_LOADER_IMAGE_CONTEXT *PeCoffLoaderImageContext, + OUT EFI_IMAGE_EXPORT_DIRECTORY **ImageExportDirectory + ) +{ + UINT16 Magic; + UINT32 NumberOfRvaAndSizes; + EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION OptionalHeaderPtrUnion; + EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry; + EFI_IMAGE_EXPORT_DIRECTORY *ExportDirectory; + EFI_IMAGE_SECTION_HEADER *SectionHeader; + + if (Image =3D=3D NULL || PeCoffLoaderImageContext =3D=3D NULL || Image= ExportDirectory =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + DirectoryEntry =3D NULL; + ExportDirectory =3D NULL; + + // + // NOTE: For backward compatibility, use the Machine field to identify= a PE32/PE32+ + // image instead of using the Magic field. Some systems might ge= nerate a PE32+ + // image with PE32 magic. + // + switch (PeCoffLoaderImageContext->Machine) { + case EFI_IMAGE_MACHINE_IA32: + // Todo: Add EFI_IMAGE_MACHINE_ARMT + // + // Assume PE32 image with IA32 Machine field. + // + Magic =3D EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC; + break; + case EFI_IMAGE_MACHINE_X64: + // + // Assume PE32+ image with X64 Machine field + // + Magic =3D EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; + break; + default: + // + // For unknown Machine field, use Magic in optional header + // + DEBUG (( + DEBUG_WARN, + "%a %a: The machine type for this image is not valid for a PRM mod= ule.\n", + _DBGMSGID_, + __FUNCTION__ + )); + return EFI_UNSUPPORTED; + } + + OptionalHeaderPtrUnion.Pe32 =3D (EFI_IMAGE_NT_HEADERS32 *) ( + (UINTN) Image + + PeCoffLoaderImageContext->PeCoffHeader= Offset + ); + + // + // Check the PE/COFF Header Signature. Determine if the image is valid= and/or a TE image. + // + if (OptionalHeaderPtrUnion.Pe32->Signature !=3D EFI_IMAGE_NT_SIGNATURE= ) { + DEBUG ((DEBUG_ERROR, "%a %a: The PE signature is not valid for the c= urrent image.\n", _DBGMSGID_, __FUNCTION__)); + return EFI_UNSUPPORTED; + } + + SectionHeader =3D (EFI_IMAGE_SECTION_HEADER *) ( + (UINTN) Image + + PeCoffLoaderImageContext->PeCoffHeaderOffset + + sizeof (UINT32) + + sizeof (EFI_IMAGE_FILE_HEADER) + + PeCoffLoaderImageContext->SizeOfHeaders + ); + if (Magic =3D=3D EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + // + // Use the PE32 offset to get the Export Directory Entry + // + NumberOfRvaAndSizes =3D OptionalHeaderPtrUnion.Pe32->OptionalHeader.= NumberOfRvaAndSizes; + DirectoryEntry =3D (EFI_IMAGE_DATA_DIRECTORY *) &(OptionalHeaderPtrU= nion.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXPORT]= ); + } else if (OptionalHeaderPtrUnion.Pe32->OptionalHeader.Magic =3D=3D EF= I_IMAGE_NT_OPTIONAL_HDR64_MAGIC) { + // + // Use the PE32+ offset get the Export Directory Entry + // + NumberOfRvaAndSizes =3D OptionalHeaderPtrUnion.Pe32Plus->OptionalHea= der.NumberOfRvaAndSizes; + DirectoryEntry =3D (EFI_IMAGE_DATA_DIRECTORY *) &(OptionalHeaderPtrU= nion.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_EXP= ORT]); + } else { + return EFI_UNSUPPORTED; + } + + if (NumberOfRvaAndSizes <=3D EFI_IMAGE_DIRECTORY_ENTRY_EXPORT || Direc= toryEntry->VirtualAddress =3D=3D 0) { + // + // The export directory is not present + // + return EFI_NOT_FOUND; + } else if (((UINT32) (~0) - DirectoryEntry->VirtualAddress) < Director= yEntry->Size) { + // + // The directory address overflows + // + DEBUG ((DEBUG_ERROR, "%a %a: The export directory entry in this imag= e results in overflow.\n", _DBGMSGID_, __FUNCTION__)); + return EFI_UNSUPPORTED; + } else { + DEBUG ((DEBUG_INFO, "%a %a: Export Directory Entry found in the imag= e at 0x%x.\n", _DBGMSGID_, __FUNCTION__, (UINTN) OptionalHeaderPtrUnion.P= e32)); + DEBUG ((DEBUG_INFO, " %a %a: Directory Entry Virtual Address =3D 0x= %x.\n", _DBGMSGID_, __FUNCTION__, DirectoryEntry->VirtualAddress)); + + ExportDirectory =3D (EFI_IMAGE_EXPORT_DIRECTORY *) ((UINTN) Image + = DirectoryEntry->VirtualAddress); + DEBUG (( + DEBUG_INFO, + " %a %a: Export Directory Table found successfully at 0x%x. Name = address =3D 0x%x. Name =3D %a.\n", + _DBGMSGID_, + __FUNCTION__, + (UINTN) ExportDirectory, + ((UINTN) Image + ExportDirectory->Name), + (CHAR8 *) ((UINTN) Image + ExportDirectory->Name) + )); + } + *ImageExportDirectory =3D ExportDirectory; + + return EFI_SUCCESS; +} + +/** + Returns the image major and image minor version in a given PE/COFF ima= ge. + + @param[in] Image A pointer to a PE32/COFF image= base address that is loaded into memory + and already relocated to the m= emory base address. RVAs in the image given + should be valid. + @param[in] PeCoffLoaderImageContext A pointer to a PE_COFF_LOADER_= IMAGE_CONTEXT structure that contains the + PE/COFF image context for the = Image given. + @param[out] ImageMajorVersion A pointer to a UINT16 buffer t= o hold the image major version. + @param[out] ImageMinorVersion A pointer to a UINT16 buffer t= o hold the image minor version. + + @retval EFI_SUCCESS The image version was read suc= cessfully. + @retval EFI_INVALID_PARAMETER A required parameter is NULL. + @retval EFI_UNSUPPORTED The PE/COFF image given is not= supported. + +**/ +EFI_STATUS +GetImageVersionInPeCoffImage ( + IN VOID *Image, + IN PE_COFF_LOADER_IMAGE_CONTEXT *PeCoffLoaderImageContext, + OUT UINT16 *ImageMajorVersion, + OUT UINT16 *ImageMinorVersion + ) +{ + EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION OptionalHeaderPtrUnion; + UINT16 Magic; + + DEBUG ((DEBUG_INFO, " %a %a - Entry.\n", _DBGMSGID_, __FUNCTION__))= ; + + if (Image =3D=3D NULL || PeCoffLoaderImageContext =3D=3D NULL || Image= MajorVersion =3D=3D NULL || ImageMinorVersion =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // NOTE: For backward compatibility, use the Machine field to identify= a PE32/PE32+ + // image instead of using the Magic field. Some systems might ge= nerate a PE32+ + // image with PE32 magic. + // + switch (PeCoffLoaderImageContext->Machine) { + case EFI_IMAGE_MACHINE_IA32: + // Todo: Add EFI_IMAGE_MACHINE_ARMT + // + // Assume PE32 image with IA32 Machine field. + // + Magic =3D EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC; + break; + case EFI_IMAGE_MACHINE_X64: + // + // Assume PE32+ image with X64 Machine field + // + Magic =3D EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC; + break; + default: + // + // For unknown Machine field, use Magic in optional header + // + DEBUG (( + DEBUG_WARN, + "%a %a: The machine type for this image is not valid for a PRM mod= ule.\n", + _DBGMSGID_, + __FUNCTION__ + )); + return EFI_UNSUPPORTED; + } + + OptionalHeaderPtrUnion.Pe32 =3D (EFI_IMAGE_NT_HEADERS32 *) ( + (UINTN) Image + + PeCoffLoaderImageContext->PeCoffHeader= Offset + ); + // + // Check the PE/COFF Header Signature. Determine if the image is valid= and/or a TE image. + // + if (OptionalHeaderPtrUnion.Pe32->Signature !=3D EFI_IMAGE_NT_SIGNATURE= ) { + DEBUG ((DEBUG_ERROR, "%a %a: The PE signature is not valid for the c= urrent image.\n", _DBGMSGID_, __FUNCTION__)); + return EFI_UNSUPPORTED; + } + + if (Magic =3D=3D EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) { + // + // Use the PE32 offset to get the Export Directory Entry + // + *ImageMajorVersion =3D OptionalHeaderPtrUnion.Pe32->OptionalHeader.M= ajorImageVersion; + *ImageMinorVersion =3D OptionalHeaderPtrUnion.Pe32->OptionalHeader.M= inorImageVersion; + } else { + // + // Use the PE32+ offset to get the Export Directory Entry + // + *ImageMajorVersion =3D OptionalHeaderPtrUnion.Pe32Plus->OptionalHead= er.MajorImageVersion; + *ImageMinorVersion =3D OptionalHeaderPtrUnion.Pe32Plus->OptionalHead= er.MinorImageVersion; + } + + DEBUG ((DEBUG_INFO, " %a %a - Image Major Version: 0x%02x.\n", _D= BGMSGID_, __FUNCTION__, *ImageMajorVersion)); + DEBUG ((DEBUG_INFO, " %a %a - Image Minor Version: 0x%02x.\n", _D= BGMSGID_, __FUNCTION__, *ImageMinorVersion)); + + return EFI_SUCCESS; +} + +/** + Creates a new PRM Module Image Context linked list entry. + + @retval PrmModuleImageContextListEntry If successful, a pointer a PRM= Module Image Context linked list entry + otherwise, NULL is returned. + +**/ +STATIC +PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY * +CreateNewPrmModuleImageContextListEntry ( + VOID + ) +{ + PRM_MODULE_IMAGE_CONTEXT *PrmModuleImageContext; + PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY *PrmModuleImageContextListEntr= y; + + DEBUG ((DEBUG_INFO, "%a %a - Entry.\n", _DBGMSGID_, __FUNCTION__)); + + PrmModuleImageContext =3D AllocateZeroPool (sizeof (*PrmModuleImageCon= text)); + if (PrmModuleImageContext =3D=3D NULL) { + return NULL; + } + DEBUG (( + DEBUG_INFO, + " %a %a: Allocated PrmModuleImageContext at 0x%x of size 0x%x bytes= .\n", + _DBGMSGID_, + __FUNCTION__, + (UINTN) PrmModuleImageContext, + sizeof (*PrmModuleImageContext) + )); + + PrmModuleImageContextListEntry =3D AllocateZeroPool (sizeof (*PrmModul= eImageContextListEntry)); + if (PrmModuleImageContextListEntry =3D=3D NULL) { + FreePool (PrmModuleImageContext); + return NULL; + } + DEBUG (( + DEBUG_INFO, + " %a %a: Allocated PrmModuleImageContextListEntry at 0x%x of size 0= x%x bytes.\n", + _DBGMSGID_, + __FUNCTION__, + (UINTN) PrmModuleImageContextListEntry, + sizeof (*PrmModuleImageContextListEntry) + )); + + PrmModuleImageContextListEntry->Signature =3D PRM_MODULE_IMAGE_CONTEXT= _LIST_ENTRY_SIGNATURE; + PrmModuleImageContextListEntry->Context =3D PrmModuleImageContext; + + return PrmModuleImageContextListEntry; +} + +/** + Discovers all PRM Modules loaded during the DXE boot phase. + + Each PRM Module discovered is placed into a linked list so the list ca= n br processsed in the future. + + @retval EFI_SUCCESS All PRM Modules were discovere= d successfully. + @retval EFI_NOT_FOUND The gEfiLoadedImageProtocolGui= d protocol could not be found. + @retval EFI_OUT_OF_RESOURCES Insufficient memory resources = to allocate the new PRM Context + linked list nodes. + +**/ +EFI_STATUS +DiscoverPrmModules ( + VOID + ) +{ + EFI_STATUS Status; + PRM_MODULE_IMAGE_CONTEXT TempPrmModuleImageContext; + PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY *PrmModuleImageContextListEntr= y; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImageProtocol; + EFI_HANDLE *HandleBuffer; + UINTN HandleCount; + UINTN Index; + + DEBUG ((DEBUG_INFO, "%a %a - Entry.\n", _DBGMSGID_, __FUNCTION__)); + + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiLoadedImageProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (EFI_ERROR (Status) && (HandleCount =3D=3D 0)) { + DEBUG ((DEBUG_ERROR, "%a %a: No LoadedImageProtocol instances found!= \n", _DBGMSGID_, __FUNCTION__)); + return EFI_NOT_FOUND; + } + + for (Index =3D 0; Index < HandleCount; Index++) { + Status =3D gBS->HandleProtocol ( + HandleBuffer[Index], + &gEfiLoadedImageProtocolGuid, + (VOID **) &LoadedImageProtocol + ); + if (EFI_ERROR (Status)) { + continue; + } + + ZeroMem (&TempPrmModuleImageContext, sizeof (TempPrmModuleImageConte= xt)); + TempPrmModuleImageContext.PeCoffImageContext.Handle =3D LoadedIma= geProtocol->ImageBase; + TempPrmModuleImageContext.PeCoffImageContext.ImageRead =3D PeCoffLoa= derImageReadFromMemory; + + Status =3D PeCoffLoaderGetImageInfo (&TempPrmModuleImageContext.PeCo= ffImageContext); + if (EFI_ERROR (Status) || TempPrmModuleImageContext.PeCoffImageConte= xt.ImageError !=3D IMAGE_ERROR_SUCCESS) { + DEBUG (( + DEBUG_WARN, + "%a %a: ImageHandle 0x%016lx is not a valid PE/COFF image. It ca= nnot be considered a PRM module.\n", + _DBGMSGID_, + __FUNCTION__, + (EFI_PHYSICAL_ADDRESS) (UINTN) LoadedImageProtocol->ImageBase + )); + continue; + } + if (TempPrmModuleImageContext.PeCoffImageContext.IsTeImage) { + // A PRM Module is not allowed to be a TE image + continue; + } + + // Attempt to find an export table in this image + Status =3D GetExportDirectoryInPeCoffImage ( + LoadedImageProtocol->ImageBase, + &TempPrmModuleImageContext.PeCoffImageContext, + &TempPrmModuleImageContext.ExportDirectory + ); + if (EFI_ERROR (Status)) { + continue; + } + + // Attempt to find the PRM Module Export Descriptor in the export ta= ble + Status =3D GetPrmModuleExportDescriptorTable ( + TempPrmModuleImageContext.ExportDirectory, + &TempPrmModuleImageContext.PeCoffImageContext, + &TempPrmModuleImageContext.ExportDescriptor + ); + if (EFI_ERROR (Status)) { + continue; + } + // A PRM Module Export Descriptor was successfully found, this is co= nsidered a PRM Module. + + // + // Create a new PRM Module image context node + // + PrmModuleImageContextListEntry =3D CreateNewPrmModuleImageContextLis= tEntry (); + if (PrmModuleImageContextListEntry =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + CopyMem ( + PrmModuleImageContextListEntry->Context, + &TempPrmModuleImageContext, + sizeof (*(PrmModuleImageContextListEntry->Context)) + ); + InsertTailList (&mPrmModuleList, &PrmModuleImageContextListEntry->Li= nk); + mPrmHandlerCount +=3D TempPrmModuleImageContext.ExportDescriptor->Nu= mberPrmHandlers; + mPrmModuleCount++; // Todo: Match with global variable refactor chan= ge in the future + DEBUG ((DEBUG_INFO, "%a %a: New PRM Module inserted into list to be = processed.\n", _DBGMSGID_, __FUNCTION__)); + } + + return EFI_SUCCESS; +} + +/** + Gets the address of an entry in an image export table by ASCII name. + + @param[in] ExportName A pointer to an ASCII name str= ing of the entry name. + @param[in] ImageBaseAddress The base address of the PE/COF= F image. + @param[in] ImageExportDirectory A pointer to the export direct= ory in the image. + @param[out] ExportPhysicalAddress A pointer that will be updated= with the address of the address of the + export entry if found. + + @retval EFI_SUCCESS The export entry was found suc= cessfully. + @retval EFI_INVALID_PARAMETER A required pointer argument is= NULL. + @retval EFI_NOT_FOUND An entry with the given Export= Name was not found. + +**/ +EFI_STATUS +GetExportEntryAddress ( + IN CONST CHAR8 *ExportName, + IN EFI_PHYSICAL_ADDRESS ImageBaseAddress, + IN EFI_IMAGE_EXPORT_DIRECTORY *ImageExportDirectory, + OUT EFI_PHYSICAL_ADDRESS *ExportPhysicalAddress + ) +{ + UINTN ExportNameIndex; + UINT16 CurrentExportOrdinal; + UINT32 *ExportAddressTable; + UINT32 *ExportNamePointerTable; + UINT16 *OrdinalTable; + CONST CHAR8 *ExportNameTablePointerName; + + if (ExportName =3D=3D NULL || ImageBaseAddress =3D=3D 0 || ImageExport= Directory =3D=3D NULL || ExportPhysicalAddress =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + *ExportPhysicalAddress =3D 0; + + ExportAddressTable =3D (UINT32 *) ((UINTN) ImageBaseAddress + ImageExp= ortDirectory->AddressOfFunctions); + ExportNamePointerTable =3D (UINT32 *) ((UINTN) ImageBaseAddress + Imag= eExportDirectory->AddressOfNames); + OrdinalTable =3D (UINT16 *) ((UINTN) ImageBaseAddress + ImageExportDir= ectory->AddressOfNameOrdinals); + + for (ExportNameIndex =3D 0; ExportNameIndex < ImageExportDirectory->Nu= mberOfNames; ExportNameIndex++) { + ExportNameTablePointerName =3D (CONST CHAR8 *) ((UINTN) ImageBaseAdd= ress + ExportNamePointerTable[ExportNameIndex]); + + if (AsciiStrnCmp (ExportName, ExportNameTablePointerName, PRM_HANDLE= R_NAME_MAXIMUM_LENGTH) =3D=3D 0) { + CurrentExportOrdinal =3D OrdinalTable[ExportNameIndex]; + + ASSERT (CurrentExportOrdinal < ImageExportDirectory->NumberOfFunct= ions); + if (CurrentExportOrdinal >=3D ImageExportDirectory->NumberOfFuncti= ons) { + DEBUG ((DEBUG_ERROR, " %a %a: The export ordinal value is inval= id.\n", _DBGMSGID_, __FUNCTION__)); + break; + } + + *ExportPhysicalAddress =3D (EFI_PHYSICAL_ADDRESS) ((UINTN) ImageBa= seAddress + ExportAddressTable[CurrentExportOrdinal]); + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + +/** + Processes a list of PRM context entries to build a PRM ACPI table. + + The ACPI table buffer is allocated and the table structure is built in= side this function. + + @param[out] PrmAcpiDescriptionTable A pointer to a pointer to a bu= ffer that is allocated within this function + and will contain the PRM ACPI = table. In case of an error in this function, + *PrmAcpiDescriptorTable will b= e NULL. + + @retval EFI_SUCCESS All PRM Modules were processed= to construct the PRM ACPI table successfully. + @retval EFI_INVALID_PARAMETER THe parameter PrmAcpiDescripti= onTable is NULL. + @retval EFI_OUT_OF_RESOURCES Insufficient memory resources = to allocate the PRM ACPI table boot services + memory data buffer. + +**/ +EFI_STATUS +ProcessPrmModules ( + OUT PRM_ACPI_DESCRIPTION_TABLE **PrmAcpiDescriptionTable + ) +{ + EFI_IMAGE_EXPORT_DIRECTORY *CurrentImageExportDirectory; + PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT *CurrentExportDescriptorStruct= ; + LIST_ENTRY *Link; + PRM_ACPI_DESCRIPTION_TABLE *PrmAcpiTable; + PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY *TempListEntry; + CONST CHAR8 *CurrentExportDescriptorHandle= rName; + + PRM_CONTEXT_BUFFER *CurrentContextBuffer; + PRM_MODULE_CONTEXT_BUFFERS *CurrentModuleContextBuffers; + PRM_MODULE_INFORMATION_STRUCT *CurrentModuleInfoStruct; + PRM_HANDLER_INFORMATION_STRUCT *CurrentHandlerInfoStruct; + + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS CurrentImageAddress; + UINTN HandlerIndex; + UINT32 PrmAcpiDescriptionTableBufferS= ize; + + UINT64 HandlerPhysicalAddress; + + DEBUG ((DEBUG_INFO, "%a %a - Entry.\n", _DBGMSGID_, __FUNCTION__)); + + if (PrmAcpiDescriptionTable =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + Link =3D NULL; + *PrmAcpiDescriptionTable =3D NULL; + + DEBUG ((DEBUG_INFO, " %a %a: %d total PRM modules to process.\n", _DB= GMSGID_, __FUNCTION__, mPrmModuleCount)); + DEBUG ((DEBUG_INFO, " %a %a: %d total PRM handlers to process.\n", _D= BGMSGID_, __FUNCTION__, mPrmHandlerCount)); + + PrmAcpiDescriptionTableBufferSize =3D (OFFSET_OF (PRM_ACPI_DESCRIPTION= _TABLE, PrmModuleInfoStructure) + + (OFFSET_OF (PRM_MODULE_INFORMATI= ON_STRUCT, HandlerInfoStructure) * mPrmModuleCount) + + (sizeof (PRM_HANDLER_INFORMATION= _STRUCT) * mPrmHandlerCount) + ); + DEBUG ((DEBUG_INFO, " %a %a: Total PRM ACPI table size: 0x%x.\n", _DB= GMSGID_, __FUNCTION__, PrmAcpiDescriptionTableBufferSize)); + + PrmAcpiTable =3D AllocateZeroPool ((UINTN) PrmAcpiDescriptionTableBuff= erSize); + if (PrmAcpiTable =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + PrmAcpiTable->Header.Signature =3D PRM_TABLE_SIGNATURE; + PrmAcpiTable->Header.Length =3D PrmAcpiDescriptionTableBuffe= rSize; + PrmAcpiTable->Header.Revision =3D PRM_TABLE_REVISION; + PrmAcpiTable->Header.Checksum =3D 0x0; + CopyMem (&PrmAcpiTable->Header.OemId, PcdGetPtr (PcdAcpiDefaultOemId),= sizeof (PrmAcpiTable->Header.OemId)); + PrmAcpiTable->Header.OemTableId =3D PcdGet64 (PcdAcpiDefaultOemT= ableId); + PrmAcpiTable->Header.OemRevision =3D PcdGet32 (PcdAcpiDefaultOemR= evision); + PrmAcpiTable->Header.CreatorId =3D PcdGet32 (PcdAcpiDefaultCrea= torId); + PrmAcpiTable->Header.CreatorRevision =3D PcdGet32 (PcdAcpiDefaultCrea= torRevision); + PrmAcpiTable->PrmModuleInfoOffset =3D OFFSET_OF (PRM_ACPI_DESCRIPT= ION_TABLE, PrmModuleInfoStructure); + PrmAcpiTable->PrmModuleInfoCount =3D mPrmModuleCount; + + // + // Iterate across all PRM Modules on the list + // + CurrentModuleInfoStruct =3D &PrmAcpiTable->PrmModuleInfoStructure[0]; + EFI_LIST_FOR_EACH(Link, &mPrmModuleList) + { + TempListEntry =3D CR(Link, PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY, Link= , PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY_SIGNATURE); + CurrentImageAddress =3D TempListEntry->Context->PeCoffImageContext.I= mageAddress; + CurrentImageExportDirectory =3D TempListEntry->Context->ExportDirect= ory; + CurrentExportDescriptorStruct =3D TempListEntry->Context->ExportDesc= riptor; + + DEBUG (( + DEBUG_INFO, + " %a %a: PRM Module - %a with %d handlers.\n", + _DBGMSGID_, + __FUNCTION__, + (CHAR8 *) ((UINTN) CurrentImageAddress + CurrentImageExportDirecto= ry->Name), + CurrentExportDescriptorStruct->NumberPrmHandlers + )); + + CurrentModuleInfoStruct->StructureRevision =3D PRM_MODULE_INFORMATIO= N_STRUCT_REVISION; + CurrentModuleInfoStruct->StructureLength =3D ( + OFFSET_OF (PRM_MODULE_INFOR= MATION_STRUCT, HandlerInfoStructure) + + (CurrentExportDescriptorStr= uct->NumberPrmHandlers * sizeof (PRM_HANDLER_INFORMATION_STRUCT)) + ); + CopyGuid (&CurrentModuleInfoStruct->Identifier, &CurrentExportDescri= ptorStruct->ModuleGuid); + CurrentModuleInfoStruct->HandlerCount =3D (UINT32) CurrentExpo= rtDescriptorStruct->NumberPrmHandlers; + CurrentModuleInfoStruct->HandlerInfoOffset =3D OFFSET_OF (PRM_MODUL= E_INFORMATION_STRUCT, HandlerInfoStructure); + + CurrentModuleInfoStruct->MajorRevision =3D 0; + CurrentModuleInfoStruct->MinorRevision =3D 0; + Status =3D GetImageVersionInPeCoffImage ( + (VOID *) (UINTN) CurrentImageAddress, + &TempListEntry->Context->PeCoffImageContext, + &CurrentModuleInfoStruct->MajorRevision, + &CurrentModuleInfoStruct->MinorRevision + ); + ASSERT_EFI_ERROR (Status); + + Status =3D GetExportEntryAddress ( + PRM_STRING (PRM_MODULE_UPDATE_LOCK_DESCRIPTOR_NAME), + CurrentImageAddress, + CurrentImageExportDirectory, + (EFI_PHYSICAL_ADDRESS *) &(CurrentModuleInfoStruct->Modu= leUpdateLock) + ); + ASSERT_EFI_ERROR (Status); + if (!EFI_ERROR (Status)) { + DEBUG (( + DEBUG_INFO, + " %a %a: Found PRM module update lock physical address at 0x%= 016x.\n", + _DBGMSGID_, + __FUNCTION__, + CurrentModuleInfoStruct->ModuleUpdateLock + )); + } + + // It is currently valid for a PRM module not to use a context buffe= r + Status =3D GetModuleContextBuffers ( + ByModuleGuid, + &CurrentModuleInfoStruct->Identifier, + &CurrentModuleContextBuffers + ); + ASSERT (!EFI_ERROR (Status) || Status =3D=3D EFI_NOT_FOUND); + if (!EFI_ERROR (Status) && CurrentModuleContextBuffers !=3D NULL) { + CurrentModuleInfoStruct->RuntimeMmioRanges =3D (UINT64) (UINTN) Cu= rrentModuleContextBuffers->RuntimeMmioRanges; + } + + // + // Iterate across all PRM handlers in the PRM Module + // + for (HandlerIndex =3D 0; HandlerIndex < CurrentExportDescriptorStruc= t->NumberPrmHandlers; HandlerIndex++) { + CurrentHandlerInfoStruct =3D &(CurrentModuleInfoStruct->HandlerInf= oStructure[HandlerIndex]); + + CurrentHandlerInfoStruct->StructureRevision =3D PRM_HANDLER_INFORM= ATION_STRUCT_REVISION; + CurrentHandlerInfoStruct->StructureLength =3D sizeof (PRM_HANDLER_= INFORMATION_STRUCT); + CopyGuid ( + &CurrentHandlerInfoStruct->Identifier, + &CurrentExportDescriptorStruct->PrmHandlerExportDescriptors[Hand= lerIndex].PrmHandlerGuid + ); + + CurrentExportDescriptorHandlerName =3D (CONST CHAR8 *) CurrentExpo= rtDescriptorStruct->PrmHandlerExportDescriptors[HandlerIndex].PrmHandlerN= ame; + + Status =3D GetContextBuffer ( + &CurrentHandlerInfoStruct->Identifier, + CurrentModuleContextBuffers, + &CurrentContextBuffer + ); + if (!EFI_ERROR (Status)) { + CurrentHandlerInfoStruct->PrmContextBuffer =3D (UINT64) CurrentC= ontextBuffer; + } + + Status =3D GetExportEntryAddress ( + CurrentExportDescriptorHandlerName, + CurrentImageAddress, + CurrentImageExportDirectory, + &HandlerPhysicalAddress + ); + ASSERT_EFI_ERROR (Status); + if (!EFI_ERROR (Status)) { + CurrentHandlerInfoStruct->PhysicalAddress =3D HandlerPhysicalAdd= ress; + DEBUG (( + DEBUG_INFO, + " %a %a: Found %a handler physical address at 0x%016x.\n", + _DBGMSGID_, + __FUNCTION__, + CurrentExportDescriptorHandlerName, + CurrentHandlerInfoStruct->PhysicalAddress + )); + } + } + CurrentModuleInfoStruct =3D (PRM_MODULE_INFORMATION_STRUCT *) ((UINT= N) CurrentModuleInfoStruct + CurrentModuleInfoStruct->StructureLength); + } + *PrmAcpiDescriptionTable =3D PrmAcpiTable; + + return EFI_SUCCESS; +} + +/** + Publishes the PRM ACPI table (PRMT). + + @param[in] PrmAcpiDescriptionTable A pointer to a buffer with a c= ompletely populated and valid PRM + ACPI description table. + + @retval EFI_SUCCESS The PRM ACPI was installed suc= cessfully. + @retval EFI_INVALID_PARAMETER THe parameter PrmAcpiDescripti= onTable is NULL or the table signature + in the table provided is inval= id. + @retval EFI_NOT_FOUND The protocol gEfiAcpiTableProt= ocolGuid could not be found. + @retval EFI_OUT_OF_RESOURCES Insufficient memory resources = to allocate the PRM ACPI table buffer. + +**/ +EFI_STATUS +PublishPrmAcpiTable ( + IN PRM_ACPI_DESCRIPTION_TABLE *PrmAcpiDescriptionTable + ) +{ + EFI_STATUS Status; + EFI_ACPI_TABLE_PROTOCOL *AcpiTableProtocol; + UINTN TableKey; + + if (PrmAcpiDescriptionTable =3D=3D NULL || PrmAcpiDescriptionTable->He= ader.Signature !=3D PRM_TABLE_SIGNATURE) { + return EFI_INVALID_PARAMETER; + } + + Status =3D gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOI= D **) &AcpiTableProtocol); + if (!EFI_ERROR (Status)) { + TableKey =3D 0; + // + // Publish the PRM ACPI table. The table checksum will be computed d= uring installation. + // + Status =3D AcpiTableProtocol->InstallAcpiTable ( + AcpiTableProtocol, + PrmAcpiDescriptionTable, + PrmAcpiDescriptionTable->Header.Length= , + &TableKey + ); + if (!EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a %a: The PRMT ACPI table was installed succ= essfully.\n", _DBGMSGID_, __FUNCTION__)); + } + } + ASSERT_EFI_ERROR (Status); + + return Status; +} + +/** + The PRM Loader END_OF_DXE protocol notification event handler. + + All PRM Modules that are eligible for dispatch should have been loaded= the DXE Dispatcher at the + time of this function invocation. + + The main responsibilities of the PRM Loader are executed from this fun= ction which include 3 phases: + 1.) Disover PRM Modules - Find all PRM modules loaded during DXE dis= patch and insert a PRM Module + Context entry into a linked list to be handed off to phase 2. + 2.) Process PRM Modules - Build a GUID to PRM handler mapping for ea= ch module that is described in the + PRM ACPI table so the OS can resolve a PRM Handler GUID to the c= orresponding PRM Handler physical address. + 3.) Publish PRM ACPI Table - Publish the PRM ACPI table with the inf= ormation gathered in the phase 2. + + @param[in] Event Event whose notification funct= ion is being invoked. + @param[in] Context The pointer to the notificatio= n function's context, + which is implementation-depend= ent. + + @retval EFI_SUCCESS The function executed successf= ully + +**/ +EFI_STATUS +EFIAPI +PrmLoaderEndOfDxeNotification ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + PRM_ACPI_DESCRIPTION_TABLE *PrmAcpiDescriptionTable; + + DEBUG ((DEBUG_INFO, "%a %a - Entry.\n", _DBGMSGID_, __FUNCTION__)); + + InitializeListHead (&mPrmModuleList); + + Status =3D DiscoverPrmModules (); + ASSERT_EFI_ERROR (Status); + + Status =3D ProcessPrmModules (&PrmAcpiDescriptionTable); + ASSERT_EFI_ERROR (Status); + + Status =3D PublishPrmAcpiTable (PrmAcpiDescriptionTable); + ASSERT_EFI_ERROR (Status); + + if (PrmAcpiDescriptionTable !=3D NULL) { + FreePool (PrmAcpiDescriptionTable); + } + gBS->CloseEvent (Event); + + return EFI_SUCCESS; +} + +/** + The entry point for this module. + + @param ImageHandle The firmware allocated handle for the EFI image= . + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Others An error occurred when executing this entry poi= nt. + +**/ +EFI_STATUS +EFIAPI +PrmLoaderEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_EVENT EndOfDxeEvent; + + DEBUG ((DEBUG_INFO, "%a %a - Entry.\n", _DBGMSGID_, __FUNCTION__)); + + // + // Discover and process installed PRM modules at the End of DXE + // The PRM ACPI table is published if one or PRM modules are discovere= d + // + Status =3D gBS->CreateEventEx( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + PrmLoaderEndOfDxeNotification, + NULL, + &gEfiEndOfDxeEventGroupGuid, + &EndOfDxeEvent + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a %a: EndOfDxe callback registration failed! = %r.\n", _DBGMSGID_, __FUNCTION__, Status)); + ASSERT_EFI_ERROR (Status); + } + + return EFI_SUCCESS; +} diff --git a/PrmPkg/PrmConfigDxe/PrmConfigDxe.inf b/PrmPkg/PrmConfigDxe/P= rmConfigDxe.inf new file mode 100644 index 000000000000..88613c146a0b --- /dev/null +++ b/PrmPkg/PrmConfigDxe/PrmConfigDxe.inf @@ -0,0 +1,48 @@ +## @file +# PRM Configuration Driver +# +# This driver configures PRM Module settings during the boot services e= nvironment. +# +# Copyright (c) Microsoft Corporation +# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PrmConfigDxe + FILE_GUID =3D 18D93D57-0B00-4213-B0A2-A2FF5EC214E4 + MODULE_TYPE =3D DXE_RUNTIME_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D PrmConfigEntryPoint + +[Sources] + PrmConfigDxe.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + PrmPkg/PrmPkg.dec + +[Guids] + gEfiEndOfDxeEventGroupGuid + gEfiEventVirtualAddressChangeGuid + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + DxeServicesTableLib + MemoryAllocationLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiRuntimeServicesTableLib + UefiLib + +[Protocols] + gPrmConfigProtocolGuid + +[Depex] + TRUE diff --git a/PrmPkg/PrmLoaderDxe/PrmAcpiTable.h b/PrmPkg/PrmLoaderDxe/Prm= AcpiTable.h new file mode 100644 index 000000000000..6b9099ca7ba7 --- /dev/null +++ b/PrmPkg/PrmLoaderDxe/PrmAcpiTable.h @@ -0,0 +1,97 @@ +/** @file + + Definition for the Platform Runtime Mechanism (PRM) ACPI table (PRMT). + + Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PRMT_ACPI_TABLE_H_ +#define PRMT_ACPI_TABLE_H_ + +#include <Base.h> +#include <IndustryStandard/Acpi10.h> + +#define PRM_TABLE_SIGNATURE SIGNATURE_32 ('P', 'R'= , 'M', 'T') + +#define PRM_TABLE_REVISION 0x0 +#define PRM_MODULE_INFORMATION_STRUCT_REVISION 0x00 +#define PRM_HANDLER_INFORMATION_STRUCT_REVISION 0x00 + +#pragma pack(push, 1) + +// +// Platform Runtime Mechanism (PRM) ACPI Table (PRMT) structures +// +typedef struct { + UINT16 StructureRevision; ///< R= evision of this structure + UINT16 StructureLength; ///< L= ength in bytes of this structure + GUID Identifier; ///< G= UID of the PRM handler for this structure + UINT64 PhysicalAddress; ///< P= hysical address of this PRM handler + UINT64 PrmContextBuffer; ///< P= hysical address of the context buffer for this + ///< P= RM handler (PRM_CONTEXT_BUFFER *) + UINT64 StaticDataBuffer; ///< P= hysical address of the static data buffer for + ///< t= his PRM handler (PRM_DATA_BUFFER *) + UINT64 AcpiParameterBuffer; ///< P= hysical address of the parameter buffer + ///< f= or this PRM handler (PRM_DATA_BUFFER *) + ///< t= hat is only used in the case of _DSM invocation. + ///< I= f _DSM invocation is not used, this value is + ///< i= gnored. +} PRM_HANDLER_INFORMATION_STRUCT; + +typedef struct { + UINT16 StructureRevision; ///< R= evision of this structure + UINT16 StructureLength; ///< L= ength in bytes of this structure including the + ///< v= ariable length PRM Handler Info array + GUID Identifier; ///< G= UID of the PRM module for this structure + UINT16 MajorRevision; ///< P= RM module major revision + UINT16 MinorRevision; ///< P= RM module minor revision + UINT16 HandlerCount; ///< N= umber of entries in the Handler Info array + UINT32 HandlerInfoOffset; ///< O= ffset in bytes from the beginning of this + ///< s= tructure to the Handler Info array + UINT64 ModuleUpdateLock; ///< P= hysical address of the PRM Module Update Lock + ///< d= escriptor (PRM_MODULE_UPDATE_LOCK_DESCRIPTOR *) + UINT64 RuntimeMmioRanges; ///< P= hysical address of the PRM MMIO Ranges + ///< s= tructure (PRM_MODULE_RUNTIME_MMIO_RANGES *) + PRM_HANDLER_INFORMATION_STRUCT HandlerInfoStructure[1]; +} PRM_MODULE_INFORMATION_STRUCT; + +typedef struct { + EFI_ACPI_DESCRIPTION_HEADER Header; ///< S= tandard ACPI description header + UINT32 PrmModuleInfoOffset; ///< O= ffset in bytes from the beginning of this + ///< s= tructure to the PRM Module Info array + UINT32 PrmModuleInfoCount; ///< N= umber of entries in the PRM Module Info array + PRM_MODULE_INFORMATION_STRUCT PrmModuleInfoStructure[1]; +} PRM_ACPI_DESCRIPTION_TABLE; + +#pragma pack(pop) + +// +// Helper macros to build PRM Information structures +// +// Todo: Revisit whether to use; currently both macros are not used +// +#define PRM_MODULE_INFORMATION_STRUCTURE(ModuleGuid, ModuleRevision, Han= dlerCount, PrmHanderInfoStructureArray) { \ + { = \ + PRM_MODULE_INFORMATION_STRUCT_REVISION, = /* UINT16 StructureRevision; */ \ + (OFFSET_OF (PRM_MODULE_INFORMATION_STRUCT, HandlerInfoStructure) += (HandlerCount * sizeof (PRM_HANDLER_INFORMATION_STRUCT))) /* UINT16 = StructureLength; */ \ + ModuleGuid, = /* GUID ModuleGuid; */ \ + ModuleRevision, = /* UINT16 ModuleRevision */ \ + HandlerCount, = /* UINT16 HandlerCount */ \ + OFFSET_OF (PRM_MODULE_INFORMATION_STRUCT, HandlerInfoOffset), = /* UINT32 HandlerInfoOffset */ \ + PrmHanderInfoStructureArray = /* PRM_HANDLER_INFORMATION_STRUCT HandlerInfoStructure */ \ + } \ + } + +#define PRM_HANDLER_INFORMATION_STRUCTURE(HandlerGuid, PhysicalAddress) = { \ + { = \ + PRM_HANDLER_INFORMATION_STRUCT_REVISION, = /* UINT16 StructureRevision; */ \ + sizeof (PRM_HANDLER_INFORMATION_STRUCT), = /* UINT16 StructureLength; */ \ + HandlerGuid, = /* GUID HandlerGuid; */ \ + PhysicalAddress, = /* UINT64 PhysicalAddress */ \ + } \ + } + +#endif // _PRMT_ACPI_TABLE_H_ diff --git a/PrmPkg/PrmLoaderDxe/PrmLoader.h b/PrmPkg/PrmLoaderDxe/PrmLoa= der.h new file mode 100644 index 000000000000..1356c7a0c923 --- /dev/null +++ b/PrmPkg/PrmLoaderDxe/PrmLoader.h @@ -0,0 +1,51 @@ +/** @file + + Definitions specific to the Platform Runtime Mechanism (PRM) loader.x + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PRM_LOADER_H_ +#define PRM_LOADER_H_ + +#include <IndustryStandard/PeImage.h> +#include <Library/PeCoffLib.h> + +#include <PrmExportDescriptor.h> + +#define _DBGMSGID_ "[PRMLOADER]" +#define PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY_SIGNATURE SIGNATURE_32('P','= R','M','E') + +#pragma pack(push, 1) + +typedef struct { + PE_COFF_LOADER_IMAGE_CONTEXT PeCoffImageContext; + EFI_IMAGE_EXPORT_DIRECTORY *ExportDirectory; + PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT *ExportDescriptor; +} PRM_MODULE_IMAGE_CONTEXT; + +typedef struct { + UINTN Signature; + LIST_ENTRY Link; + PRM_MODULE_IMAGE_CONTEXT *Context; +} PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY; + +#pragma pack(pop) + +// +// Iterate through the double linked list. NOT delete safe. +// +#define EFI_LIST_FOR_EACH(Entry, ListHead) \ + for(Entry =3D (ListHead)->ForwardLink; Entry !=3D (ListHead); Entry =3D= Entry->ForwardLink) + +// +// Iterate through the double linked list. This is delete-safe. +// Don't touch NextEntry. +// +#define EFI_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \ + for(Entry =3D (ListHead)->ForwardLink, NextEntry =3D Entry->ForwardLin= k;\ + Entry !=3D (ListHead); Entry =3D NextEntry, NextEntry =3D Entry->F= orwardLin + +#endif diff --git a/PrmPkg/PrmLoaderDxe/PrmLoaderDxe.inf b/PrmPkg/PrmLoaderDxe/P= rmLoaderDxe.inf new file mode 100644 index 000000000000..643e1a7989f2 --- /dev/null +++ b/PrmPkg/PrmLoaderDxe/PrmLoaderDxe.inf @@ -0,0 +1,59 @@ +## @file +# PRM Loader Driver +# +# This driver discovers PRM Modules loaded in memory and places those m= odules and the +# PRM handlers within those modules into a PRMT ACPI table such that th= e handlers are +# made available for invocation in the OS. +# +# Copyright (c) Microsoft Corporation +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D PrmLoaderDxe + FILE_GUID =3D 226A500A-E14F-414A-A956-40E5762D3D1= E + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D PrmLoaderEntryPoint + +[Sources] + PrmAcpiTable.h + PrmLoader.h + PrmLoaderDxe.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + PrmPkg/PrmPkg.dec + +[Guids] + gEfiEndOfDxeEventGroupGuid + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + PeCoffLib + PrmContextBufferLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiLib + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemId ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemTableId ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemRevision ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId ## CONSU= MES + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision ## CONSU= MES + +[Protocols] + gEfiAcpiTableProtocolGuid + gEfiLoadedImageProtocolGuid + gPrmConfigProtocolGuid + +[Depex] + TRUE --=20 2.28.0.windows.1 |
|
[PATCH v1 03/41] PrmPkg/PrmContextBufferLib: Add initial library instance
Michael Kubacki
From: Michael Kubacki <michael.kubacki@...>
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3812 This library is introduced to add a general abstraction for PRM context buffer management. Cc: Andrew Fish <afish@...> Cc: Kang Gao <kang.gao@...> Cc: Michael D Kinney <michael.d.kinney@...> Cc: Michael Kubacki <michael.kubacki@...> Cc: Leif Lindholm <leif@...> Cc: Benjamin You <benjamin.you@...> Cc: Liu Yun <yun.y.liu@...> Cc: Ankit Sinha <ankit.sinha@...> Cc: Nate DeSimone <nathaniel.l.desimone@...> Signed-off-by: Michael Kubacki <michael.kubacki@...> --- PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.c | 196 += +++++++++++++++++++ PrmPkg/Include/Library/PrmContextBufferLib.h | 99 += +++++++++ PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.inf | 35 += +++ 3 files changed, 330 insertions(+) diff --git a/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib= .c b/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.c new file mode 100644 index 000000000000..1a1a15b5cdbb --- /dev/null +++ b/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.c @@ -0,0 +1,196 @@ +/** @file + + The PRM Buffer Context library provides a general abstraction for cont= ext buffer management. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/PrmContextBufferLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Protocol/PrmConfig.h> + +#define _DBGMSGID_ "[PRMCONTEXTBUFFERLIB]" + +/** + Finds a PRM context buffer for the given PRM handler GUID. + + Note: PRM_MODULE_CONTEXT_BUFFERS is at the PRM module level while PRM_= CONTEXT_BUFFER is at the PRM handler level. + + @param[in] HandlerGuid A pointer to the PRM handler G= UID. + @param[in] ModuleContextBuffers A pointer to the PRM context b= uffers structure for the PRM module. + @param[out] PrmModuleContextBuffer A pointer to a pointer that wi= ll be set to the PRM context buffer + if successfully found. + + @retval EFI_SUCCESS The PRM context buffer was fou= nd. + @retval EFI_INVALID_PARAMETER A required parameter pointer i= s NULL. + @retval EFI_NOT_FOUND The context buffer for the giv= en PRM handler GUID could not be found. + +**/ +EFI_STATUS +FindContextBufferInModuleBuffers ( + IN CONST EFI_GUID *HandlerGuid, + IN CONST PRM_MODULE_CONTEXT_BUFFERS *ModuleContextBuffers, + OUT CONST PRM_CONTEXT_BUFFER **ContextBuffer + ) +{ + UINTN Index; + + DEBUG ((DEBUG_INFO, " %a %a - Entry.\n", _DBGMSGID_, __FUNCTION__))= ; + + if (HandlerGuid =3D=3D NULL || ModuleContextBuffers =3D=3D NULL || Con= textBuffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + for (Index =3D 0; Index < ModuleContextBuffers->BufferCount; Index++) = { + if (CompareGuid (&ModuleContextBuffers->Buffer[Index].HandlerGuid, H= andlerGuid)) { + *ContextBuffer =3D &ModuleContextBuffers->Buffer[Index]; + return EFI_SUCCESS; + } + } + + return EFI_NOT_FOUND; +} + +/** + Returns a PRM context buffers structure for the given PRM search type. + + This function allows a caller to get the context buffers structure for= a PRM module with either the PRM module + GUID or the GUID for a PRM handler in the module. + + Note: PRM_MODULE_CONTEXT_BUFFERS is at the PRM module level while PRM_= CONTEXT_BUFFER is at the PRM handler level. + + @param[in] GuidSearchType The type of GUID passed in the= Guid argument. + @param[in] Guid A pointer to the GUID of a PRM= module or PRM handler. The actual GUID type + will be interpreted based on t= he value passed in GuidSearchType. + @param[out] PrmModuleContextBuffers A pointer to a pointer that wi= ll be set to the PRM context buffers + structure if successfully foun= d. + + @retval EFI_SUCCESS The PRM context buffers struct= ure was found. + @retval EFI_INVALID_PARAMETER A required parameter pointer i= s NULL. + @retval EFI_NOT_FOUND The context buffers for the gi= ven GUID could not be found. + +**/ +EFI_STATUS +GetModuleContextBuffers ( + IN PRM_GUID_SEARCH_TYPE GuidSearchType, + IN CONST EFI_GUID *Guid, + OUT CONST PRM_MODULE_CONTEXT_BUFFERS **PrmModuleContextBuffers + ) +{ + EFI_STATUS Status; + UINTN HandleCount; + UINTN Index; + EFI_HANDLE *HandleBuffer; + PRM_CONFIG_PROTOCOL *PrmConfigProtocol; + CONST PRM_CONTEXT_BUFFER *PrmContextBuffer; + + DEBUG ((DEBUG_INFO, " %a %a - Entry.\n", _DBGMSGID_, __FUNCTION__))= ; + + if (Guid =3D=3D NULL || PrmModuleContextBuffers =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + *PrmModuleContextBuffers =3D NULL; + + Status =3D gBS->LocateHandleBuffer ( + ByProtocol, + &gPrmConfigProtocolGuid, + NULL, + &HandleCount, + &HandleBuffer + ); + if (!EFI_ERROR (Status)) { + for (Index =3D 0; Index < HandleCount; Index++) { + Status =3D gBS->HandleProtocol ( + HandleBuffer[Index], + &gPrmConfigProtocolGuid, + (VOID **) &PrmConfigProtocol + ); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status) || PrmConfigProtocol =3D=3D NULL) { + continue; + } + + if (GuidSearchType =3D=3D ByModuleGuid) { + if (CompareGuid (&PrmConfigProtocol->ModuleContextBuffers.Module= Guid, Guid)) { + DEBUG (( + DEBUG_INFO, + " %a %a: Found a PRM configuration protocol for PRM mod= ule %g.\n", + _DBGMSGID_, + __FUNCTION__, + Guid + )); + + *PrmModuleContextBuffers =3D &PrmConfigProtocol->ModuleContext= Buffers; + return EFI_SUCCESS; + } + } else { + Status =3D FindContextBufferInModuleBuffers (Guid, &PrmConfigPro= tocol->ModuleContextBuffers, &PrmContextBuffer); + if (!EFI_ERROR (Status)) { + *PrmModuleContextBuffers =3D &PrmConfigProtocol->ModuleContext= Buffers; + return EFI_SUCCESS; + } + } + } + } + + DEBUG (( + DEBUG_INFO, + " %a %a: Could not locate a PRM configuration protocol for PRM = handler %g.\n", + _DBGMSGID_, + __FUNCTION__, + Guid + )); + + return EFI_NOT_FOUND; +} + +/** + Returns a PRM context buffer for the given PRM handler. + + @param[in] PrmHandlerGuid A pointer to the GUID for the = PRM handler. + @param[in] PrmModuleContextBuffers A pointer to a PRM_MODULE_CONT= EXT_BUFFERS structure. If this optional + parameter is provided, the han= dler context buffer will be searched for in this + buffer structure which saves t= ime by not performing a global search for the + module buffer structure. + @param[out] PrmContextBuffer A pointer to a pointer that wi= ll be set to the PRM context buffer + if successfully found. + + @retval EFI_SUCCESS The PRM context buffer was fou= nd. + @retval EFI_INVALID_PARAMETER A required parameter pointer i= s NULL. + @retval EFI_NOT_FOUND The context buffer for the PRM= handler could not be found. + +**/ +EFI_STATUS +GetContextBuffer ( + IN CONST EFI_GUID *PrmHandlerGuid, + IN CONST PRM_MODULE_CONTEXT_BUFFERS *PrmModuleContextBuffers OPTI= ONAL, + OUT CONST PRM_CONTEXT_BUFFER **PrmContextBuffer + ) +{ + EFI_STATUS Status; + CONST PRM_MODULE_CONTEXT_BUFFERS *ContextBuffers; + + DEBUG ((DEBUG_INFO, " %a %a - Entry.\n", _DBGMSGID_, __FUNCTION__))= ; + + if (PrmHandlerGuid =3D=3D NULL || PrmContextBuffer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + *PrmContextBuffer =3D NULL; + + if (PrmModuleContextBuffers =3D=3D NULL) { + Status =3D GetModuleContextBuffers (ByHandlerGuid, PrmHandlerGuid, &= ContextBuffers); + if (EFI_ERROR (Status)) { + return EFI_NOT_FOUND; + } + } else { + ContextBuffers =3D PrmModuleContextBuffers; + } + Status =3D FindContextBufferInModuleBuffers (PrmHandlerGuid, ContextBu= ffers, PrmContextBuffer); + + return Status; +} diff --git a/PrmPkg/Include/Library/PrmContextBufferLib.h b/PrmPkg/Includ= e/Library/PrmContextBufferLib.h new file mode 100644 index 000000000000..93dcd1e76642 --- /dev/null +++ b/PrmPkg/Include/Library/PrmContextBufferLib.h @@ -0,0 +1,99 @@ +/** @file + + The PRM Buffer Context library provides a general abstraction for cont= ext buffer management. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PRM_CONTEXT_BUFFER_LIB_H_ +#define PRM_CONTEXT_BUFFER_LIB_H_ + +#include <Base.h> +#include <PrmContextBuffer.h> +#include <Uefi.h> + +typedef enum { + /// + /// Search by the PRM module GUID + /// + ByModuleGuid, + /// + /// Search by the PRM handler GUID + /// + ByHandlerGuid +} PRM_GUID_SEARCH_TYPE; + +/** + Finds a PRM context buffer for the given PRM handler GUID. + + Note: PRM_MODULE_CONTEXT_BUFFERS is at the PRM module level while PRM_= CONTEXT_BUFFER is at the PRM handler level. + + @param[in] HandlerGuid A pointer to the PRM handler G= UID. + @param[in] ModuleContextBuffers A pointer to the PRM context b= uffers structure for the PRM module. + @param[out] PrmModuleContextBuffer A pointer to a pointer that wi= ll be set to the PRM context buffer + if successfully found. + + @retval EFI_SUCCESS The PRM context buffer was fou= nd. + @retval EFI_INVALID_PARAMETER A required parameter pointer i= s NULL. + @retval EFI_NOT_FOUND The context buffer for the giv= en PRM handler GUID could not be found. + +**/ +EFI_STATUS +FindContextBufferInModuleBuffers ( + IN CONST EFI_GUID *HandlerGuid, + IN CONST PRM_MODULE_CONTEXT_BUFFERS *ModuleContextBuffers, + OUT CONST PRM_CONTEXT_BUFFER **ContextBuffer + ); + +/** + Returns a PRM context buffers structure for the given PRM search type. + + This function allows a caller to get the context buffers structure for= a PRM module with either the PRM module + GUID or the GUID for a PRM handler in the module. + + Note: PRM_MODULE_CONTEXT_BUFFERS is at the PRM module level while PRM_= CONTEXT_BUFFER is at the PRM handler level. + + @param[in] GuidSearchType The type of GUID passed in the= Guid argument. + @param[in] Guid A pointer to the GUID of a PRM= module or PRM handler. The actual GUID type + will be interpreted based on t= he value passed in GuidSearchType. + @param[out] PrmModuleContextBuffers A pointer to a pointer that wi= ll be set to the PRM context buffers + structure if successfully foun= d. + + @retval EFI_SUCCESS The PRM context buffers struct= ure was found. + @retval EFI_INVALID_PARAMETER A required parameter pointer i= s NULL. + @retval EFI_NOT_FOUND The context buffers for the gi= ven GUID could not be found. + +**/ +EFI_STATUS +GetModuleContextBuffers ( + IN PRM_GUID_SEARCH_TYPE GuidSearchType, + IN CONST EFI_GUID *Guid, + OUT CONST PRM_MODULE_CONTEXT_BUFFERS **PrmModuleContextBuffers + ); + +/** + Returns a PRM context buffer for the given PRM handler. + + @param[in] PrmHandlerGuid A pointer to the GUID for the = PRM handler. + @param[in] PrmModuleContextBuffers A pointer to a PRM_MODULE_CONT= EXT_BUFFERS structure. If this optional + parameter is provided, the han= dler context buffer will be searched for in this + buffer structure which saves t= ime by not performing a global search for the + module buffer structure. + @param[out] PrmContextBuffer A pointer to a pointer that wi= ll be set to the PRM context buffer + if successfully found. + + @retval EFI_SUCCESS The PRM context buffer was fou= nd. + @retval EFI_INVALID_PARAMETER A required parameter pointer i= s NULL. + @retval EFI_NOT_FOUND The context buffer for the PRM= handler could not be found. + +**/ +EFI_STATUS +GetContextBuffer ( + IN CONST EFI_GUID *PrmHandlerGuid, + IN CONST PRM_MODULE_CONTEXT_BUFFERS *PrmModuleContextBuffers OPTI= ONAL, + OUT CONST PRM_CONTEXT_BUFFER **PrmContextBuffer + ); + +#endif diff --git a/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib= .inf b/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.inf new file mode 100644 index 000000000000..16ed1edfe36a --- /dev/null +++ b/PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.inf @@ -0,0 +1,35 @@ +## @file +# PRM Context Buffer Library +# +# Provides a general abstraction for PRM context buffer management. +# +# Copyright (c) Microsoft Corporation +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D DxePrmContextBufferLib + FILE_GUID =3D 49828E93-29FA-4665-B8B1-19BA4059D140 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D PrmContextBufferLib|DXE_DRIVER UEFI_DRIVER UEF= I_APPLICATION + +[Sources] + DxePrmContextBufferLib.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + PrmPkg/PrmPkg.dec + +[Protocols] + gPrmConfigProtocolGuid + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + UefiBootServicesTableLib --=20 2.28.0.windows.1 |
|
[PATCH v1 02/41] PrmPkg: Add PrmConfig protocol interface
Michael Kubacki
From: Michael Kubacki <michael.kubacki@...>
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3812 The PRM Configuration protocol is used by PRM module configuration libraries to describe their resources so that a generic PRM Configuration DXE driver can prepare those resources for OS runtime. Therefore, multiple instances are expected in the system per boot with approximately one instance per PRM module. All PRM Configuration Protocol instances must be installed prior to end of DXE. Cc: Andrew Fish <afish@...> Cc: Kang Gao <kang.gao@...> Cc: Michael D Kinney <michael.d.kinney@...> Cc: Michael Kubacki <michael.kubacki@...> Cc: Leif Lindholm <leif@...> Cc: Benjamin You <benjamin.you@...> Cc: Liu Yun <yun.y.liu@...> Cc: Ankit Sinha <ankit.sinha@...> Cc: Nate DeSimone <nathaniel.l.desimone@...> Signed-off-by: Michael Kubacki <michael.kubacki@...> --- PrmPkg/Include/Protocol/PrmConfig.h | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/PrmPkg/Include/Protocol/PrmConfig.h b/PrmPkg/Include/Protoco= l/PrmConfig.h new file mode 100644 index 000000000000..d90fe5a0dd73 --- /dev/null +++ b/PrmPkg/Include/Protocol/PrmConfig.h @@ -0,0 +1,32 @@ +/** @file + + PRM Configuration protocol + + PRM Configuration protocol is used by PRM module configuration librari= es to + describe their resources so that a generic PRM Configuration DXE drive= r can prepare those + resources for OS runtime. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PRM_CONFIG_H_ +#define PRM_CONFIG_H_ + +#include <PrmContextBuffer.h> +#include <Uefi.h> + +typedef struct _PRM_CONFIG_PROTOCOL PRM_CONFIG_PROTOCOL; + +#define PRM_CONFIG_PROTOCOL_SIGNATURE SIGNATURE_32('P','M','C','P') +#define PRM_CONFIG_PROTOCOL_VERSION 1 + +struct _PRM_CONFIG_PROTOCOL +{ + PRM_MODULE_CONTEXT_BUFFERS ModuleContextBuffers; +}; + +extern EFI_GUID gPrmConfigProtocolGuid; + +#endif --=20 2.28.0.windows.1 |
|
[PATCH v1 01/41] PrmPkg: Add package and include headers
Michael Kubacki
From: Michael Kubacki <michael.kubacki@...>
REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3812 Adds a new package to maintain Platform Runtime Mechanism (PRM) support. This package is intended to include generic code that provides a common infrastructure to support PRM in firmware and a collection of sample PRM modules that demonstrate how to use the interfaces and other package resources to author a PRM module. The following initial headers are included in this commit: * Prm.h - Includes common content for PRM with no dependencies on other PRM header files. * PrmContextBuffer.h - Includes definitions for PRM context buffers. Context buffers are standardized structures that point to various resources available to a PRM handler during its execution. * PrmDataBuffer.h - Includes definitions for PRM data buffers. Within the context of PRM, these data buffers are composed of a generic header followed by a variable length blob of arbitrary data. * PrmExportDescriptor.h - Includes definitions for creating PRM export descriptors. A PRM export descriptor is a structure referenced in the export table of PRM module that contains PRM-specific metadata about the module. * PrmMmio.h - Includes definitions for describing MMIO ranges uses by PRM modules. * PrmModule.h - Includes definitions commonly used by PRM module authors. This file is provided to serve as a convenient include for PRM module authors. * PrmOsServices.h - Includes content specific to PRM OS services. OS Services will not planned to be present in the final version of PRM. The OS Services have been reduced to a simple debug print function. So this is currently planned to be a temporary file to support debugging during PRM development. Note: Modules built for the UEFI environment can be built by Visual Studio and non-Visual Studio toolchains. However, PRM modules are currently only supported on Visual Studio toolchain due to usage of export tables. Cc: Andrew Fish <afish@...> Cc: Kang Gao <kang.gao@...> Cc: Michael D Kinney <michael.d.kinney@...> Cc: Michael Kubacki <michael.kubacki@...> Cc: Leif Lindholm <leif@...> Cc: Benjamin You <benjamin.you@...> Cc: Liu Yun <yun.y.liu@...> Cc: Ankit Sinha <ankit.sinha@...> Cc: Nate DeSimone <nathaniel.l.desimone@...> Signed-off-by: Michael Kubacki <michael.kubacki@...> --- PrmPkg/Include/Prm.h | 46 +++++++ PrmPkg/Include/PrmContextBuffer.h | 131 ++++++++++++++++++++ PrmPkg/Include/PrmDataBuffer.h | 50 ++++++++ PrmPkg/Include/PrmExportDescriptor.h | 87 +++++++++++++ PrmPkg/Include/PrmMmio.h | 45 +++++++ PrmPkg/Include/PrmModule.h | 68 ++++++++++ PrmPkg/Include/PrmModuleUpdate.h | 46 +++++++ PrmPkg/Include/PrmOsServices.h | 45 +++++++ PrmPkg/PrmPkg.dec | 49 ++++++++ PrmPkg/PrmPkg.uni | 10 ++ 10 files changed, 577 insertions(+) diff --git a/PrmPkg/Include/Prm.h b/PrmPkg/Include/Prm.h new file mode 100644 index 000000000000..0e3ccfffa333 --- /dev/null +++ b/PrmPkg/Include/Prm.h @@ -0,0 +1,46 @@ +/** @file + + Common Platform Runtime Mechanism (PRM) definitions. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PRM_H_ +#define PRM_H_ + +#include <Uefi.h> +#include <PrmContextBuffer.h> + +#if defined(_MSC_VER) + #define PRM_EXPORT_API __declspec(dllexport) +#else + #define PRM_EXPORT_API +#endif + +#define PRM_HANDLER_NAME_MAXIMUM_LENGTH 128 + +#define PRM_STRING_(x) #x +#define PRM_STRING(x) PRM_STRING_(x) + +/** + A Platform Runtime Mechanism (PRM) handler function. + + @param[in] ParameterBuffer A pointer to a buffer with arb= itrary data that is allocated and populated + by the PRM handler caller. + @param[in] ContextBuffer A pointer to a buffer with arb= itrary data that is allocated in the firmware + boot environment. + + @retval EFI_STATUS The PRM handler executed successfully. + @retval Others An error occurred in the PRM handler. + +**/ +typedef +EFI_STATUS +(EFIAPI PRM_HANDLER) ( + IN VOID *ParameterBuffer OPTIONAL, + IN PRM_CONTEXT_BUFFER *ContextBuffer OPTIONAL + ); + +#endif diff --git a/PrmPkg/Include/PrmContextBuffer.h b/PrmPkg/Include/PrmContex= tBuffer.h new file mode 100644 index 000000000000..8f8144545e64 --- /dev/null +++ b/PrmPkg/Include/PrmContextBuffer.h @@ -0,0 +1,131 @@ +/** @file + + Definitions for the Platform Runtime Mechanism (PRM) context buffer st= ructures. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PRM_CONTEXT_BUFFER_H_ +#define PRM_CONTEXT_BUFFER_H_ + +#include <PrmDataBuffer.h> +#include <PrmMmio.h> +#include <Uefi.h> + +#define PRM_CONTEXT_BUFFER_SIGNATURE SIGNATURE_32('P','R','M','= C') +#define PRM_CONTEXT_BUFFER_INTERFACE_VERSION 1 + +#pragma pack(push, 1) + +// +// This is the context buffer structure that is passed to a PRM handler. +// +// At OS runtime, the OS will allocate and populate this structure and +// place virtual addresses in the pointer fields. +// +// It is also reused internally in FW (in the PRM_MODULE_CONTEXT_BUFFERS= structure) +// to track context buffers within a given PRM module. In that internal = usage, +// the addresses will be physical addresses. +// +typedef struct { + /// + /// Signature of this interface. + /// + UINT32 Signature; + + /// + /// Version of this interface. + /// + UINT16 Version; + + /// + /// Reserved field. + /// + UINT16 Reserved; + + /// + /// The GUID of the PRM handler represented by this context instance. + /// + EFI_GUID HandlerGuid; + + /// + /// A virtual address pointer to the static data buffer allocated for + /// the PRM handler represented by this context instance. + /// + /// The static buffer is intended to be populated in the PRM module + /// configuration library and treated as read-only data at OS runtime. + /// + /// This pointer may be NULL if a static data buffer is not needed. + /// + PRM_DATA_BUFFER *StaticDataBuffer; + + /// + /// A virtual address pointer to an array of PRM_RUNTIME_MMIO_RANGE + /// structures that describe MMIO physical address ranges mapped to + /// virtual memory addresses for access at OS runtime. + /// + /// This pointer is ignored in firmware internal usage of this structu= re + /// as this field is present to allow a PRM handler to get the list + /// of MMIO ranges described as accessible by its PRM module. + /// + /// The module list of MMIO ranges is specified by the PRM configurati= on + /// code as a single array in PRM_MODULE_CONTEXT_BUFFERS. + /// + /// The OS is responsible for ensuring the pointer to the array in thi= s + /// structure is converted to a virtual address during construction of + /// of the context buffer in the OS. + /// + /// This pointer may be NULL if runtime memory ranges are not needed. + /// + PRM_RUNTIME_MMIO_RANGES *RuntimeMmioRanges; +} PRM_CONTEXT_BUFFER; + +// +// A firmware internal data structure used to track context buffer and +// runtime MMIO range usage across a PRM module. +// +typedef struct +{ + /// + /// The GUID of the PRM module. + /// + EFI_GUID ModuleGuid; + + /// + /// The number of PRM context buffers in ContextBuffers[]. + /// This count should equal the number of PRM handlers in the module b= eing configured. + /// + UINTN BufferCount; + + /// + /// A pointer to an array of PRM context buffers + /// + PRM_CONTEXT_BUFFER *Buffer; + + /// The MMIO ranges are defined in the firmware boot environment. + /// The addresses within the PRM_RUNTIME_MMIO_RANGES structure will + /// be converted to virtual addresses by firmware. + + /// + /// A physical address pointer to an array of PRM_RUNTIME_MMIO_RANGE + /// structures that describe memory ranges that need to be mapped to + /// virtual memory addresses for access at OS runtime. + /// + /// This is a consolidated array of MMIO ranges accessed by any PRM + /// handler in the PRM module at OS runtime. The MMIO range physical + /// addresses registered here will automatically be converted to the + /// corresponding virtual address in the structure by PRM infrastructu= re + /// code. No action is required to convert MMIO range base physical + /// addresses to virtual addresses by either the PRM configuration cod= e + /// or the OS. + /// + /// This pointer may be NULL if runtime memory ranges are not needed. + /// + PRM_RUNTIME_MMIO_RANGES *RuntimeMmioRanges; +} PRM_MODULE_CONTEXT_BUFFERS; + +#pragma pack(pop) + +#endif diff --git a/PrmPkg/Include/PrmDataBuffer.h b/PrmPkg/Include/PrmDataBuffe= r.h new file mode 100644 index 000000000000..70d690ca5446 --- /dev/null +++ b/PrmPkg/Include/PrmDataBuffer.h @@ -0,0 +1,50 @@ +/** @file + + Definitions for the Platform Runtime Mechanism (PRM) data buffer struc= tures. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PRM_DATA_BUFFER_H_ +#define PRM_DATA_BUFFER_H_ + +#include <Uefi.h> + +#define PRM_DATA_BUFFER_HEADER_SIGNATURE SIGNATURE_32('P','R','M','= D') + +#pragma pack(push, 1) + +/// +/// A generic header that describes the PRM data buffer. +/// +typedef struct { + /// + /// PRM Data Buffer signature. + /// + UINT32 Signature; + /// + /// Length of the entire data buffer, including the size of the header= . + /// + UINT32 Length; +} PRM_DATA_BUFFER_HEADER; + +/// +/// A PRM data buffer is a generic header followed by variable length ar= bitrary data. +/// +typedef struct { + /// + /// The header is required at the beginning of every PRM data buffer. + /// + PRM_DATA_BUFFER_HEADER Header; + + /// + /// The beginning of data immediately follows the header. + /// + UINT8 Data[1]; +} PRM_DATA_BUFFER; + +#pragma pack(pop) + +#endif diff --git a/PrmPkg/Include/PrmExportDescriptor.h b/PrmPkg/Include/PrmExp= ortDescriptor.h new file mode 100644 index 000000000000..95198cef659c --- /dev/null +++ b/PrmPkg/Include/PrmExportDescriptor.h @@ -0,0 +1,87 @@ +/** @file + + Definitions for the Platform Runtime Mechanism (PRM) export descriptor= structures. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PRM_EXPORT_DESCRIPTOR_H_ +#define PRM_EXPORT_DESCRIPTOR_H_ + +#include <Prm.h> + +#define PRM_MODULE_EXPORT_DESCRIPTOR_NAME PrmModuleExportDescrip= tor +#define PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE SIGNATURE_64 ('P', 'R'= , 'M', '_', 'M', 'E', 'D', 'T') +#define PRM_MODULE_EXPORT_REVISION 0x0 + +// +// Platform Runtime Mechanism (PRM) Export Descriptor Structures +// +#pragma pack(push, 1) + +typedef struct { + GUID PrmHandlerGuid; + CHAR8 PrmHandlerName[PRM_HANDLER_NAME_= MAXIMUM_LENGTH]; +} PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT; + +typedef struct { + UINT64 Signature; + UINT16 Revision; + UINT16 NumberPrmHandlers; + GUID ModuleGuid; + PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT PrmHandlerExportDescriptors[3]; +} PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT; + +#pragma pack(pop) + +/** + A macro that declares a PRM Handler Export Descriptor for a PRM Handle= r. + + This macro is intended to be used once per PRM Handler to describe the= handler when the + module description is defined. It should be provided as an argument to= PRM_MODULE_EXPORT. + + @param Guid The GUID of the PRM Handler being exported. + + @param Name The name of the PRM Handler being exported. This strin= g should exactly + match the function name. + +**/ +#define PRM_HANDLER_EXPORT_ENTRY(Guid, Name) \ + { \ + Guid, \ + PRM_STRING_(Name) \ + } \ + +/** + A macro that returns the count of the number of variable-length argume= nts given. + + @param VariableArgumentList A variable argument list of elements tha= t will be included + in the return value of the list count. +**/ +#define VA_ARG_COUNT(...) (sizeof((PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT= []){__VA_ARGS__})/sizeof(PRM_HANDLER_EXPORT_DESCRIPTOR_STRUCT)) + +/** + A macro that declares the PRM Module Export Descriptor for a PRM Modul= e. + + This macro is intended to be used once in a PRM Module after all of th= e PRM Handler definitions + to describe the PRM Handlers being exported in the module. + + @param PrmHandlerExportEntries A variable argument list of PRM_HAND= LER_EXPORT_ENTRY values. + This list should include all PRM Han= dlers being exported by + this module. + +**/ +#define PRM_MODULE_EXPORT(...) = \ + PRM_EXPORT_API PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT PRM_MODULE_EXPORT_D= ESCRIPTOR_NAME =3D { \ + { = \ + PRM_MODULE_EXPORT_DESCRIPTOR_SIGNATURE, = \ + PRM_MODULE_EXPORT_REVISION, = \ + VA_ARG_COUNT(__VA_ARGS__), = \ + EFI_CALLER_ID_GUID = \ + }, = \ + { __VA_ARGS__ } = \ + } = \ + +#endif diff --git a/PrmPkg/Include/PrmMmio.h b/PrmPkg/Include/PrmMmio.h new file mode 100644 index 000000000000..fb216c27e8e3 --- /dev/null +++ b/PrmPkg/Include/PrmMmio.h @@ -0,0 +1,45 @@ +/** @file + + Definitions for the Platform Runtime Mechanism (PRM) MMIO elements. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PRM_MMIO_H_ +#define PRM_MMIO_H_ + +#include <Uefi.h> + +#pragma pack(push, 1) + +/// +/// Describes a memory range that needs to be made accessible at OS runt= ime. +/// +/// The memory range with the given base address and length will be mark= ed as EFI_MEMORY_RUNTIME. +/// +typedef struct { + EFI_PHYSICAL_ADDRESS PhysicalBaseAddress; + EFI_PHYSICAL_ADDRESS VirtualBaseAddress; + UINT32 Length; +} PRM_RUNTIME_MMIO_RANGE; + +/// +/// Describes a buffer with an array of PRM module +/// config runtime memory ranges. +/// +typedef struct { + /// + /// The number of runtime memory range elements in this buffer. + /// + UINT64 Count; + /// + /// The beginning of the runtime memory range data. + /// + PRM_RUNTIME_MMIO_RANGE Range[1]; +} PRM_RUNTIME_MMIO_RANGES; + +#pragma pack(pop) + +#endif diff --git a/PrmPkg/Include/PrmModule.h b/PrmPkg/Include/PrmModule.h new file mode 100644 index 000000000000..f40fb42a2b4f --- /dev/null +++ b/PrmPkg/Include/PrmModule.h @@ -0,0 +1,68 @@ +/** @file + + Common definitions needed for Platform Runtime Mechanism (PRM) modules= . + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PRM_MODULE_H_ +#define PRM_MODULE_H_ + +#include <Prm.h> +#include <PrmContextBuffer.h> +#include <PrmDataBuffer.h> +#include <PrmExportDescriptor.h> +#include <PrmMmio.h> +#include <PrmModuleUpdate.h> +#include <PrmOsServices.h> + +/** + Macro that provides a condensed form of a PRM Handler. + + This macro can be used to define a PRM Handler that uses the standard = PRM Handle + signature. It is simply provided for convenience. + +**/ +#define PRM_HANDLER_EXPORT(Name) = \ + STATIC_ASSERT (sizeof (PRM_STRING_(Name)) <=3D PRM_HANDLER_NAME_MAXIMU= M_LENGTH, "The PRM handler exceeds the maximum allowed size of 128."); \ + = \ +/** = \ + A Platform Runtime Mechanism (PRM) handler. = \ + = \ + @param[in] ParameterBuffer A pointer to the PRM handler parameter= buffer \ + @param[in] ContextBUffer A pointer to the PRM handler context b= uffer \ + = \ + @retval EFI_STATUS The PRM handler executed successfully.= \ + @retval Others An error occurred in the PRM handler. = \ + = \ +**/ = \ + EFI_STATUS \ + PRM_EXPORT_API \ + EFIAPI \ + Name ( \ + IN VOID *ParameterBuffer, \ + IN PRM_CONTEXT_BUFFER *ContextBuffer \ + ) \ + +/** + A macro that declares the PRM Module Update Lock Descriptor for a PRM = Module. + + This macro is intended to be used once in a PRM Module so the module u= pdate lock descriptor is + exported for the module. + +**/ +#define PRM_MODULE_UPDATE_LOCK_EXPORT = \ + PRM_EXPORT_API PRM_MODULE_UPDATE_LOCK_DESCRIPTOR PRM_MODULE_UPDATE_LOC= K_DESCRIPTOR_NAME =3D { \ + PRM_MODULE_UPDATE_LOCK_DESCRIPTOR_SIGNATURE, = \ + PRM_MODULE_UPDATE_LOCK_REVISION, = \ + { 0 } = \ + } = \ + +// +// A PRM module is required to export the PRM Module Update Lock +// +PRM_MODULE_UPDATE_LOCK_EXPORT; + +#endif diff --git a/PrmPkg/Include/PrmModuleUpdate.h b/PrmPkg/Include/PrmModuleU= pdate.h new file mode 100644 index 000000000000..fde97eff0462 --- /dev/null +++ b/PrmPkg/Include/PrmModuleUpdate.h @@ -0,0 +1,46 @@ +/** @file + + Definition for the Platform Runtime Mechanism (PRM) module update stru= ctures. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PRM_MODULE_UPDATE_H_ +#define PRM_MODULE_UPDATE_H_ + +#include <Uefi.h> + +#define PRM_MODULE_UPDATE_LOCK_DESCRIPTOR_NAME PrmModuleUpdateLoc= k +#define PRM_MODULE_UPDATE_LOCK_DESCRIPTOR_SIGNATURE SIGNATURE_64 ('P',= 'R', 'M', '_', 'M', 'U', 'L', '_') +#define PRM_MODULE_UPDATE_LOCK_REVISION 0x0 + +#pragma pack(push, 1) + +/// +/// Maintains the PRM Module Update Lock state +/// +typedef union { + /// + /// Individual bit fields + /// + struct { + UINT8 Acquired : 1; ///< [0] - If 1 lock is acquired. If 0= lock is released. + UINT8 Reserved : 7; ///< [7:1] - Reserved + } Bits; + /// + /// All bit fields as an 8-bit value + /// + UINT8 Uint8; +} PRM_MODULE_UPDATE_LOCK; + +typedef struct { + UINT64 Signature; + UINT16 Revision; + PRM_MODULE_UPDATE_LOCK Lock; +} PRM_MODULE_UPDATE_LOCK_DESCRIPTOR; + +#pragma pack(pop) + +#endif diff --git a/PrmPkg/Include/PrmOsServices.h b/PrmPkg/Include/PrmOsService= s.h new file mode 100644 index 000000000000..62dfa0018787 --- /dev/null +++ b/PrmPkg/Include/PrmOsServices.h @@ -0,0 +1,45 @@ +/** @file + + Definitions for the Platform Runtime Mechanism (PRM) OS Services. + + Note: OS Services have been removed from POR. This file has been reduc= ed to just debug print + OS Service for use during PRM enabling. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PRM_OS_SERVICES_H_ +#define PRM_OS_SERVICES_H_ + +#include <Uefi.h> + +typedef struct _PRM_OS_SERVICES PRM_OS_SERVICES; + +// +// PRM OS Services function signatures +// +typedef +VOID +(EFIAPI *PRM_OS_SERVICE_DEBUG_PRINT) ( + IN CONST CHAR8 *String + ); + +#pragma pack(push, 1) + +// +// PRM OS Services table +// +struct _PRM_OS_SERVICES { + // Structure information + UINT16 MajorVersion; + UINT16 MinorVersion; + + // OS Services + PRM_OS_SERVICE_DEBUG_PRINT DebugPrint; +}; + +#pragma pack(pop) + +#endif diff --git a/PrmPkg/PrmPkg.dec b/PrmPkg/PrmPkg.dec new file mode 100644 index 000000000000..ff681d423d30 --- /dev/null +++ b/PrmPkg/PrmPkg.dec @@ -0,0 +1,49 @@ +## @file PrmPkg.dec +# This package provides support for the Platform Runtime Mechanism (PRM)= . +# +# The following key elements of PRM are maintained in this package: +# +# 1. PRM interfaces - Comprised of interfaces shared with the operating = system such as ACPI table structures +# in addition to internal firmware interfaces such a= s protocols and library interfaces. +# +# 2. PRM generic drivers - EDK II drivers that implement generic functio= nality such that a platform can quickly +# and reliably adopt PRM. +# +# 3. PRM module - An independently updatable PE/COFF binary that conform= s to the unique requirements of a PRM module. +# PRM modules expose functions for operating system invo= cation referred to as PRM handlers. +# +# 4. PRM handler - A function in a PRM module. The function is identifie= d through PRM interfaces in the OS by a GUID. +# +# Copyright (c) Microsoft Corporation<BR> +## SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + DEC_SPECIFICATION =3D 0x00010005 + PACKAGE_NAME =3D PrmPkg + PACKAGE_UNI_FILE =3D PrmPkg.uni + PACKAGE_GUID =3D 3D22F66E-9090-46CE-B260-1836070AFA5= E + PACKAGE_VERSION =3D 0.1 + +[Includes] + Include + +[Guids] + gPrmPkgTokenSpaceGuid =3D { 0x46f56acc, 0x600b, 0x450f, { 0xa5, 0x9c, = 0x3a, 0x1a, 0x4a, 0xd4, 0x35, 0x3e }} + +[LibraryClasses] + ## @libraryclass Provides a general abstraction for PRM context buffer= management + # + PrmContextBufferLib|Include/Library/PrmContextBufferLib.h + +[Protocols] + ## PRM Configuration Protocol + # + gPrmConfigProtocolGuid =3D { 0x4e5b4fea, 0x936a, 0x45bc, { 0xac, 0x6a,= 0x2f, 0x8f, 0x14, 0xa6, 0xc2, 0x9e }} + +[PcdsFixedAtBuild] + ## Flash base address of a PRM firmware volume + gPrmPkgTokenSpaceGuid.PcdFlashFvPrmBase|0x00000000|UINT32|0x00000001 + + ## Size in bytes of a PRM firmware volume + gPrmPkgTokenSpaceGuid.PcdFlashFvPrmSize|0x00000000|UINT32|0x00000002 diff --git a/PrmPkg/PrmPkg.uni b/PrmPkg/PrmPkg.uni new file mode 100644 index 000000000000..3575b3505213 --- /dev/null +++ b/PrmPkg/PrmPkg.uni @@ -0,0 +1,10 @@ +// /** @file +// +// Copyright (c) Microsoft Corporation +// SPDX-License-Identifier: BSD-2-Clause-Patent +// **/ + + +#string STR_PACKAGE_ABSTRACT #language en-US "This package pr= ovides support for the Platform Runtime Mechanism (PRM)." + +#string STR_PACKAGE_DESCRIPTION #language en-US "Provides infras= tructure support code and sample PRM modules for PRM authors." --=20 2.28.0.windows.1 |
|
[PATCH v1 00/41] Add PrmPkg
Michael Kubacki
From: Michael Kubacki <michael.kubacki@...>
This patch series adds a new package called PrmPkg. An RFC was sent to the edk2 mailing list on January 28, 2022 detailing the proposal, see https://edk2.groups.io/g/devel/message/86181. Platform Runtime Mechanism (PRM) is a new firmware solution that has been developed in edk2-staging/PlatformRuntimeMechanism. This patch series has been organized to greatly condense the history from the edk2-staging branch but to preserve important decisions and changes in history that help establish context of changes and will serve as valuable references for future development. Interest in PRM has increased across various vendors and we believe it is beneficial to make the source code more widely available for the following reasons: 1. PRM specification adoption 2. Feature completeness 3. Overall validation coverage 4. Interest from the community and future collaboration The technical details of PRM are covered in the PRM Specification in addition to the Readme.md file located in the root of PrmPkg in this patch series. 1. PRM specification adoption Intel and Microsoft have worked together to standardize PRM in the ACPI Specification and the PRM Specification hosted on uefi.org. * ACPI 6.4 Specification: https://uefi.org/node/4149 * PRM Specification: https://uefi.org/sites/default/files/resources/Platform%20Runtime%20Mec= hanism%20-%20with%20legal%20notice.pdf 2. Feature completeness PrmPkg implements the full firmware functionality described in the PRM Specification and there are no significant changes to functionality planned at this time. Though we are very much interested in evolving PRM based on feedback. 3. Overall validation coverage PrmPkg has been integrated and tested on client and server systems in addition to virtual platforms (OvmfPkg/QEMU). Platform integration is simple and a demonstration of this integration for OvmfPkg is available in the following branch: https://github.com/makubacki/edk2/tree/ovmf_prmpkg_integration The code has been built with: * MSFT VS2015, VS2017, and VS2019 * GCC5 (see https://bugzilla.tianocore.org/show_bug.cgi?id=3D3802) * iASL compiler (20200528 - https://acpica.org/node/181) The Linux kernel currently includes the following PRM support: * _OSC PRM bit - allows FW to know determine the OS is PRM-capable and can redirect _DSM method from alternate triggers (such as SMI) to PRM. * PRM invocation via _DSM, includes PRM module and handler parsing from ACPI PRMT table, and also the PRM operation region handler for runtime PRM service invocation. * An OS configuration for PRM enabling, PRM support can be disabled during OS image build. Note that upstream Linux does not currently support the following: * Ability for the OS driver to call a PRM handler directly, it has to be via ACPI _DSM. * Run time update PRM module and handler via PE/COFF PRM image. This commit provides additional context of the changes in Linux: https://github.com/torvalds/linux/commit/cefc7ca46235f01d5233e3abd4b79452= af01d9e9 Windows 11 (https://www.microsoft.com/software-download/windows11) and Windows Server 2022 (https://docs.microsoft.com/en-us/windows-hardwar= e/drivers/download-the-wdk) include the PRM functionality noted above in addition to PRM direct call and PRM runtime updates. PRM has been tested on IA32, X64, and AARCH64 targets. 4. Interest from the community and future collaboration PRM has been presented at several industry conferences: * OSFC 2020 - "PRM: SMM Goes on a Diet" https://cfp.osfc.io/osfc2020/talk/MCJASB/ * OCP Summit 2019 - "Case Study Alternatives for SMM Usage in Intel Platforms" https://www.youtube.com/watch?v=3Dmu3DRLM1dPA =20 In addition, Microsoft plans to publish the Windows PRM driver interface and a WDF sample driver that uses the interface to the Windows Driver Samples GitHub repository (https://github.com/microsoft/Windows-driver-samples). We believe a PrmPkg in edk2 can increase accessibility to PRM and ease collaboration. PrmPkg ------ PrmPkg contains the common functionality needed to enable PRM on any system. It does not contain platform-specific code such as PRM modules (and by extension PRM handlers). Other than sample modules, PrmPkg will only contain code needed to provide PRM feature functionality as defined in the PRM Specification. PrmPkg is scoped to continue to only contain platform-agnostic functionality in the future. The proposed maintainers of PrmPkg are: * Michael Kubacki <mikuback@...> * Nate DeSimone <nathaniel.l.desimone@...> The proposed reviewers of PrmPkg are: * Ankit Sinha <ankit.sinha@...> Cc: Andrew Fish <afish@...> Cc: Kang Gao <kang.gao@...> Cc: Michael D Kinney <michael.d.kinney@...> Cc: Michael Kubacki <michael.kubacki@...> Cc: Leif Lindholm <leif@...> Cc: Benjamin You <benjamin.you@...> Cc: Liu Yun <yun.y.liu@...> Cc: Ankit Sinha <ankit.sinha@...> Cc: Nate DeSimone <nathaniel.l.desimone@...> Signed-off-by: Michael Kubacki <michael.kubacki@...> Liu (2): PrmPkg: Publish PRM operation region to support PRM ACPI _DSM invocation PrmPkg: Export major/minor version in PRM module PE COFF header Liu Yun Y (1): PrmPkg: Update PRM OpRegion Michael Kubacki (38): PrmPkg: Add package and include headers PrmPkg: Add PrmConfig protocol interface PrmPkg/PrmContextBufferLib: Add initial library instance PrmPkg/PrmConfigDxe: Add initial driver PrmPkg: Add initial PrmSamplePrintModule PrmPkg: Add initial PrmSampleMemoryAllocationModule PrmPkg: Add initial PrmSampleHardwareAccessModule PrmPkg: Add initial PrmSampleContextBufferModule PrmPkg: Add initial package DSC file Readme.md: Add initial content PrmPkg: Add ALLOCATE_CONTEXT_BUFFER_IN_FW build option PrmPkg: Enable variable growth for the PRM_MODULE_EXPORT macro PrmPkg: Add initial PrmSsdtInstallDxe module PrmPkg: Remove PRM Module Update Lock PrmPkg: Remove ALLOCATE_CONTEXT_BUFFER_IN_FW build flag PrmPkg/PrmContextBuffer.h: Add ACPI parameter support structures PrmPkg/PrmLoaderDxe: Add ACPI parameter buffer support PrmPkg/PrmSampleContextBufferModule: Remove OS debug print requirement PrmPkg/PrmSampleHardwareAccessModule: Add non-print PRM handlers PrmPkg/SampleAcpiParameterBufferModule: Add initial module PrmPkg/HardwareAccessModuleConfigLib: Add initial library PrmPkg/Samples/Readme.md: Add initial file PrmPkg: Refactor some PrmLoaderDxe functionality into libraries PrmPkg/Application/PrmInfo: Add initial application PrmPkg: Enforce stricter types PrmPkg/Test/PrmPkgHostTest.dsc: Add initial file PrmPkg/Test/UnitTest/Library: Add initial UEFI Boot Services test lib PrmPkg/Library/DxePrmContextBufferLib: Add host-based unit tests PrmPkg/DxePrmModuleDiscoveryLib: Add initial host-based unit tests PrmPkg: Add PlatformGuid Readme.md: Add iASL note and QEMU sample link PrmPkg: Replace PcdPrmPlatformGuid with EDKII_DSC_PLATFORM_GUID PrmPkg/Samples: Remove PrmSampleMemoryAllocationModule PrmPkg/Samples: Remove PrmSamplePrintModule PrmPkg: Remove the concept of OS services Readme.md: Add a link to PRM Specification PrmPkg: Changes for edk2 repo transition PrmPkg: Apply uncrustify changes PrmPkg/Application/PrmInfo/PrmInfo.c = | 732 = +++++++++ PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.c = | 199 = +++ PrmPkg/Library/DxePrmContextBufferLib/UnitTest/DxePrmContextBufferLibUni= tTest.c | 649 = ++++++++ PrmPkg/Library/DxePrmModuleDiscoveryLib/DxePrmModuleDiscoveryLib.c = | 386 = +++++ PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitTest/DxePrmModuleDiscoveryLi= bUnitTest.c | 210 = +++ PrmPkg/Library/DxePrmPeCoffLib/DxePrmPeCoffLib.c = | 417 = +++++ PrmPkg/PrmConfigDxe/PrmConfigDxe.c = | 512 = ++++++ PrmPkg/PrmLoaderDxe/PrmLoaderDxe.c = | 377 = +++++ PrmPkg/PrmSsdtInstallDxe/PrmSsdtInstallDxe.c = | 110 = ++ PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiParamet= erBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.c | 127 = ++ PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/PrmSampleAcpiParameter= BufferModule.c | 78 = + PrmPkg/Samples/PrmSampleContextBufferModule/Library/DxeContextBufferModu= leConfigLib/DxeContextBufferModuleConfigLib.c | 218 = +++ PrmPkg/Samples/PrmSampleContextBufferModule/PrmSampleContextBufferModule= .c | 84 = + PrmPkg/Samples/PrmSampleHardwareAccessModule/Library/DxeHardwareAccessMo= duleConfigLib/DxeHardwareAccessModuleConfigLib.c | 108 = ++ PrmPkg/Samples/PrmSampleHardwareAccessModule/PrmSampleHardwareAccessModu= le.c | 335 = ++++ PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootSe= rvicesTableLibUnitTest.c | 119 = ++ PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootSe= rvicesTableLibUnitTestEventTimer.c | 180 = +++ PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootSe= rvicesTableLibUnitTestImage.c | 163 = ++ PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootSe= rvicesTableLibUnitTestMemory.c | 145 = ++ PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootSe= rvicesTableLibUnitTestMisc.c | 198 = +++ PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootSe= rvicesTableLibUnitTestProtocol.c | 1650 = ++++++++++++++++++++ PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootSe= rvicesTableLibUnitTestTpl.c | 43 = + .azurepipelines/templates/pr-gate-build-job.yml = | 2 = +- .pytool/CISettings.py = | 1 = + Maintainers.txt = | 8 = + PrmPkg/Application/PrmInfo/PrmInfo.h = | 49 = + PrmPkg/Application/PrmInfo/PrmInfo.inf = | 66 = + PrmPkg/Application/PrmInfo/PrmInfo.uni = | 11 = + PrmPkg/Application/PrmInfo/PrmInfoExtra.uni = | 12 = + PrmPkg/Application/PrmInfo/PrmInfoStrings.uni = | 132 = ++ PrmPkg/Include/Library/PrmContextBufferLib.h = | 99 = ++ PrmPkg/Include/Library/PrmModuleDiscoveryLib.h = | 60 = + PrmPkg/Include/Library/PrmPeCoffLib.h = | 111 = ++ PrmPkg/Include/Prm.h = | 46 = + PrmPkg/Include/PrmContextBuffer.h = | 171 = ++ PrmPkg/Include/PrmDataBuffer.h = | 50 = + PrmPkg/Include/PrmExportDescriptor.h = | 109 = ++ PrmPkg/Include/PrmMmio.h = | 45 = + PrmPkg/Include/PrmModule.h = | 47 = + PrmPkg/Include/PrmModuleImageContext.h = | 28 = + PrmPkg/Include/Protocol/PrmConfig.h = | 31 = + PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBufferLib.inf = | 35 = + PrmPkg/Library/DxePrmContextBufferLib/UnitTest/DxePrmContextBufferLibUni= tTestHost.inf | 46 = + PrmPkg/Library/DxePrmModuleDiscoveryLib/DxePrmModuleDiscoveryLib.inf = | 41 = + PrmPkg/Library/DxePrmModuleDiscoveryLib/PrmModuleDiscovery.h = | 39 = + PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitTest/DxePrmModuleDiscoveryLi= bUnitTestHost.inf | 39 = + PrmPkg/Library/DxePrmPeCoffLib/DxePrmPeCoffLib.inf = | 32 = + PrmPkg/PrmConfigDxe/PrmConfigDxe.inf = | 48 = + PrmPkg/PrmLoaderDxe/PrmAcpiTable.h = | 96 = ++ PrmPkg/PrmLoaderDxe/PrmLoaderDxe.inf = | 61 = + PrmPkg/PrmPkg.ci.yaml = | 110 = ++ PrmPkg/PrmPkg.dec = | 67 = + PrmPkg/PrmPkg.dsc = | 142 = ++ PrmPkg/PrmPkg.uni = | 10 = + PrmPkg/PrmSsdtInstallDxe/Prm.asl = | 115 = ++ PrmPkg/PrmSsdtInstallDxe/PrmSsdtInstallDxe.inf = | 52 = + PrmPkg/Readme.md = | 264 = ++++ PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Library/DxeAcpiParamet= erBufferModuleConfigLib/DxeAcpiParameterBufferModuleConfigLib.inf | 39 = + PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/PrmSampleAcpiParameter= BufferModule.inf | 41 = + PrmPkg/Samples/PrmSampleContextBufferModule/Include/StaticData.h = | 24 = + PrmPkg/Samples/PrmSampleContextBufferModule/Library/DxeContextBufferModu= leConfigLib/DxeContextBufferModuleConfigLib.inf | 39 = + PrmPkg/Samples/PrmSampleContextBufferModule/PrmSampleContextBufferModule= .inf | 44 = + PrmPkg/Samples/PrmSampleHardwareAccessModule/Hpet.h = | 108 = ++ PrmPkg/Samples/PrmSampleHardwareAccessModule/Library/DxeHardwareAccessMo= duleConfigLib/DxeHardwareAccessModuleConfigLib.inf | 39 = + PrmPkg/Samples/PrmSampleHardwareAccessModule/PrmSampleHardwareAccessModu= le.inf | 43 = + PrmPkg/Samples/Readme.md = | 146 = ++ PrmPkg/Test/PrmPkgHostTest.dsc = | 39 = + PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootSe= rvicesTableLibTest.uni | 12 = + PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootSe= rvicesTableLibUnitTest.h | 1042 = ++++++++++++ PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootSe= rvicesTableLibUnitTest.inf | 46 = + PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLibUnitTest/UefiBootSe= rvicesTableLibUnitTestProtocol.h | 120 = ++ 71 files changed, 11096 insertions(+), 1 deletion(-) create mode 100644 PrmPkg/Application/PrmInfo/PrmInfo.c create mode 100644 PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBu= fferLib.c create mode 100644 PrmPkg/Library/DxePrmContextBufferLib/UnitTest/DxePrm= ContextBufferLibUnitTest.c create mode 100644 PrmPkg/Library/DxePrmModuleDiscoveryLib/DxePrmModuleD= iscoveryLib.c create mode 100644 PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitTest/DxeP= rmModuleDiscoveryLibUnitTest.c create mode 100644 PrmPkg/Library/DxePrmPeCoffLib/DxePrmPeCoffLib.c create mode 100644 PrmPkg/PrmConfigDxe/PrmConfigDxe.c create mode 100644 PrmPkg/PrmLoaderDxe/PrmLoaderDxe.c create mode 100644 PrmPkg/PrmSsdtInstallDxe/PrmSsdtInstallDxe.c create mode 100644 PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Lib= rary/DxeAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleCo= nfigLib.c create mode 100644 PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Prm= SampleAcpiParameterBufferModule.c create mode 100644 PrmPkg/Samples/PrmSampleContextBufferModule/Library/D= xeContextBufferModuleConfigLib/DxeContextBufferModuleConfigLib.c create mode 100644 PrmPkg/Samples/PrmSampleContextBufferModule/PrmSample= ContextBufferModule.c create mode 100644 PrmPkg/Samples/PrmSampleHardwareAccessModule/Library/= DxeHardwareAccessModuleConfigLib/DxeHardwareAccessModuleConfigLib.c create mode 100644 PrmPkg/Samples/PrmSampleHardwareAccessModule/PrmSampl= eHardwareAccessModule.c create mode 100644 PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLib= UnitTest/UefiBootServicesTableLibUnitTest.c create mode 100644 PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLib= UnitTest/UefiBootServicesTableLibUnitTestEventTimer.c create mode 100644 PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLib= UnitTest/UefiBootServicesTableLibUnitTestImage.c create mode 100644 PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLib= UnitTest/UefiBootServicesTableLibUnitTestMemory.c create mode 100644 PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLib= UnitTest/UefiBootServicesTableLibUnitTestMisc.c create mode 100644 PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLib= UnitTest/UefiBootServicesTableLibUnitTestProtocol.c create mode 100644 PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLib= UnitTest/UefiBootServicesTableLibUnitTestTpl.c create mode 100644 PrmPkg/Application/PrmInfo/PrmInfo.h create mode 100644 PrmPkg/Application/PrmInfo/PrmInfo.inf create mode 100644 PrmPkg/Application/PrmInfo/PrmInfo.uni create mode 100644 PrmPkg/Application/PrmInfo/PrmInfoExtra.uni create mode 100644 PrmPkg/Application/PrmInfo/PrmInfoStrings.uni create mode 100644 PrmPkg/Include/Library/PrmContextBufferLib.h create mode 100644 PrmPkg/Include/Library/PrmModuleDiscoveryLib.h create mode 100644 PrmPkg/Include/Library/PrmPeCoffLib.h create mode 100644 PrmPkg/Include/Prm.h create mode 100644 PrmPkg/Include/PrmContextBuffer.h create mode 100644 PrmPkg/Include/PrmDataBuffer.h create mode 100644 PrmPkg/Include/PrmExportDescriptor.h create mode 100644 PrmPkg/Include/PrmMmio.h create mode 100644 PrmPkg/Include/PrmModule.h create mode 100644 PrmPkg/Include/PrmModuleImageContext.h create mode 100644 PrmPkg/Include/Protocol/PrmConfig.h create mode 100644 PrmPkg/Library/DxePrmContextBufferLib/DxePrmContextBu= fferLib.inf create mode 100644 PrmPkg/Library/DxePrmContextBufferLib/UnitTest/DxePrm= ContextBufferLibUnitTestHost.inf create mode 100644 PrmPkg/Library/DxePrmModuleDiscoveryLib/DxePrmModuleD= iscoveryLib.inf create mode 100644 PrmPkg/Library/DxePrmModuleDiscoveryLib/PrmModuleDisc= overy.h create mode 100644 PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitTest/DxeP= rmModuleDiscoveryLibUnitTestHost.inf create mode 100644 PrmPkg/Library/DxePrmPeCoffLib/DxePrmPeCoffLib.inf create mode 100644 PrmPkg/PrmConfigDxe/PrmConfigDxe.inf create mode 100644 PrmPkg/PrmLoaderDxe/PrmAcpiTable.h create mode 100644 PrmPkg/PrmLoaderDxe/PrmLoaderDxe.inf create mode 100644 PrmPkg/PrmPkg.ci.yaml create mode 100644 PrmPkg/PrmPkg.dec create mode 100644 PrmPkg/PrmPkg.dsc create mode 100644 PrmPkg/PrmPkg.uni create mode 100644 PrmPkg/PrmSsdtInstallDxe/Prm.asl create mode 100644 PrmPkg/PrmSsdtInstallDxe/PrmSsdtInstallDxe.inf create mode 100644 PrmPkg/Readme.md create mode 100644 PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Lib= rary/DxeAcpiParameterBufferModuleConfigLib/DxeAcpiParameterBufferModuleCo= nfigLib.inf create mode 100644 PrmPkg/Samples/PrmSampleAcpiParameterBufferModule/Prm= SampleAcpiParameterBufferModule.inf create mode 100644 PrmPkg/Samples/PrmSampleContextBufferModule/Include/S= taticData.h create mode 100644 PrmPkg/Samples/PrmSampleContextBufferModule/Library/D= xeContextBufferModuleConfigLib/DxeContextBufferModuleConfigLib.inf create mode 100644 PrmPkg/Samples/PrmSampleContextBufferModule/PrmSample= ContextBufferModule.inf create mode 100644 PrmPkg/Samples/PrmSampleHardwareAccessModule/Hpet.h create mode 100644 PrmPkg/Samples/PrmSampleHardwareAccessModule/Library/= DxeHardwareAccessModuleConfigLib/DxeHardwareAccessModuleConfigLib.inf create mode 100644 PrmPkg/Samples/PrmSampleHardwareAccessModule/PrmSampl= eHardwareAccessModule.inf create mode 100644 PrmPkg/Samples/Readme.md create mode 100644 PrmPkg/Test/PrmPkgHostTest.dsc create mode 100644 PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLib= UnitTest/UefiBootServicesTableLibTest.uni create mode 100644 PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLib= UnitTest/UefiBootServicesTableLibUnitTest.h create mode 100644 PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLib= UnitTest/UefiBootServicesTableLibUnitTest.inf create mode 100644 PrmPkg/Test/UnitTest/Library/UefiBootServicesTableLib= UnitTest/UefiBootServicesTableLibUnitTestProtocol.h --=20 2.28.0.windows.1 |
|
Re: [PATCH v1 0/4] UncrustifyCheck Ignore Support
Michael D Kinney
Hi Michael,
toggle quoted message
Show quoted text
Should this be broken up into 2 series? One for pytool change and one for OvmfPkg? Mike -----Original Message----- |
|
Re: [PATCH v1 2/4] .pytool/Plugin/UncrustifyCheck: Add ignore file support
Michael D Kinney
Michael,
toggle quoted message
Show quoted text
One comment below. Mike -----Original Message-----What is the purpose of "nofile.txt" here? If this a param that is optional/ignored? If so, there are better python methods to do that. + |
|
Re: [PATCH v1 1/4] .pytool/Plugin/UncrustifyCheck: Update func to return absolute paths
Michael D Kinney
Hi Michael,
toggle quoted message
Show quoted text
I meant to ask. Is there a reason you are not normalizing the file paths os.path.normpath() before performing the path comparison? I am concerned that a mix of '/', '\' and '..' in YAML file may not detect what is supposed to be a matching path. Perhaps this is a topic that applies to IgnoreFiles feature for all plugins and can be addressed in a separate patch. Mike -----Original Message----- |
|
Re: [PATCH v1 1/4] .pytool/Plugin/UncrustifyCheck: Update func to return absolute paths
Michael D Kinney
Reviewed-by: Michael D Kinney <michael.d.kinney@...>
toggle quoted message
Show quoted text
Mike -----Original Message----- |
|
Re: [PATCH 1/2] MdeModulePkg: StackOffset must be aligned to a 16-byte boundary in X64
Kuo, Ted
Hi Marvin,
toggle quoted message
Show quoted text
Please find my inline comments with [Ted2]. Thanks, Ted -----Original Message-----
From: Marvin Häuser <mhaeuser@...> Sent: Tuesday, March 22, 2022 5:27 PM To: Kuo, Ted <ted.kuo@...> Cc: devel@edk2.groups.io; Kinney, Michael D <michael.d.kinney@...>; Bi, Dandan <dandan.bi@...>; Gao, Liming <gaoliming@...>; De, Debkumar <debkumar.de@...>; Han, Harry <harry.han@...>; West, Catharine <catharine.west@...>; Wang, Jian J <jian.j.wang@...> Subject: Re: [edk2-devel][PATCH 1/2] MdeModulePkg: StackOffset must be aligned to a 16-byte boundary in X64 Good day, Thanks for the updates! On 22. Mar 2022, at 08:23, Kuo, Ted <ted.kuo@...> wrote:Yes, I understood as much. I built a chain of reasoning for alignment in the response for the first revision, because a proper fix needs knowledge of which assumption is wrong in the first place. The question is, which *exact* value in the chain is not 16-Byte aligned, and should it be? Did you ever print all involved values, like PhysicalMemoryBegin (or whatever its name was, sorry, I’m responding from mobile)? [Ted2]: Yes, I confirmed that no issue with the current design in Dispatcher.c. The unaligned stack offset I observed was caused by the unaligned TopOfOldStack which is produced by sum of SecCoreData->StackBase and SecCoreData->StackSize. In my case, SecCoreData is provided by FspSecCore. Hence we need to ensure SecCoreData->StackBase and SecCoreData->StackSize provided by FspSecCore are 16-byte-aligned instead of making changes in Dispatcher.c in MdeModulePkg. The correct fix should be making the size of CONTEXT_STACK to be 16-byte-aligned for X64 so that FspSecCore can produce 16-byte-aligned stack base and save it in SecCoreData->StackBase. The fix will be included in the patch of enabling FspSecCore support for X64. Yes, I agreed above. But StackOffset is not the definition of where the new stack is located, but only a consequence from it. It is not the primary descriptor is what I’m trying to say. And the OldStack/NewStack in the fsp patch indicates the *current* old/new stack. The fsp patch just makes left shift 8-byte of whole used stack data when new stack not aligning with old stack. Hence I think no need to update TopOfNewStack.Yes, I understand what is happening, I don’t understand why it is happening. My comment here was separate from the FSP patch and only concerned the code here. If the top of the stack (as described by StackOffset) is aligned from its original value, why can TopOfNewStack remain unchanged, when it all points to the old, unaligned top, where no data should ever be stored? e.g.Is this the top or bottom? If it’s the top, why can it *not* be 16-Byte-aligned? If it’s the bottom, how is it relevant here? We are only dealing with the top addresses in this patch, no? [Ted2]: It's current stack before and after switching stack, not top or bottom. I just wanted to show why stack offset must be 16-byte-aligned in this patch which is no longer needed since the root cause is already identified in FspSecCore. We can drop the two patches. new stack: 0x49c8f3b8But StackOffset describes the offset from the top of the old stack to the top of the new stack. How does the top “remain unchanged”? Top alignment is the root for the transitive alignment chain, if it is aligned, and it must be, everything is aligned. [Ted2]: Totally agreed. We can drop the two patches as not required. Confused, sorry. Maybe explaining the rest will make this clearer. This is why I asked about 1). Things like this are fundamental and should not be changed without understanding both the full scope of the issue and the full scope of the changes. But how will StackOffset be in-sync with the changes in FSP SecCore then? If I’m not mistaken with my intro from last mail, both calculate the stack address separately from each other, and their calculations must be in-sync. If I’m mistaken, how does it work then? [Ted2]: Agreed. We can drop the two patches. Should be solved by 6). Thanks! Best regards, Marvin
|
|
[PATCH v3 3/5] NetworkPkg/HttpDxe: Add ConnectionClose flag fo HTTP_PROTOCOL
Oliver Steffen
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2720
Add ConnectionClose flag to HTTP_PROTOCOL. This boolean is FALSE by default. If set to TRUE, a reconfigure of the Http instance is forced on the next request. The flag is then reset. Signed-off-by: Oliver Steffen <osteffen@...> --- NetworkPkg/HttpDxe/HttpProto.h | 2 ++ NetworkPkg/HttpDxe/HttpImpl.c | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/NetworkPkg/HttpDxe/HttpProto.h b/NetworkPkg/HttpDxe/HttpProto.h index 8ed99c7a02d3..620eb3915843 100644 --- a/NetworkPkg/HttpDxe/HttpProto.h +++ b/NetworkPkg/HttpDxe/HttpProto.h @@ -194,6 +194,8 @@ typedef struct _HTTP_PROTOCOL { EFI_TCP6_IO_TOKEN Tcp6TlsRxToken; EFI_TCP6_RECEIVE_DATA Tcp6TlsRxData; BOOLEAN TlsIsRxDone; + + BOOLEAN ConnectionClose; } HTTP_PROTOCOL; typedef struct { diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c index d64cd9e965c0..d8b014c94f3a 100644 --- a/NetworkPkg/HttpDxe/HttpImpl.c +++ b/NetworkPkg/HttpDxe/HttpImpl.c @@ -161,6 +161,7 @@ EfiHttpConfigure ( HttpInstance->HttpVersion = HttpConfigData->HttpVersion; HttpInstance->TimeOutMillisec = HttpConfigData->TimeOutMillisec; HttpInstance->LocalAddressIsIPv6 = HttpConfigData->LocalAddressIsIPv6; + HttpInstance->ConnectionClose = FALSE; if (HttpConfigData->LocalAddressIsIPv6) { CopyMem ( @@ -440,7 +441,8 @@ EfiHttpRequest ( // ReConfigure = FALSE; } else { - if ((HttpInstance->RemotePort == RemotePort) && + if ((HttpInstance->ConnectionClose == FALSE) && + (HttpInstance->RemotePort == RemotePort) && (AsciiStrCmp (HttpInstance->RemoteHost, HostName) == 0) && (!HttpInstance->UseHttps || (HttpInstance->UseHttps && !TlsConfigure && @@ -649,6 +651,8 @@ EfiHttpRequest ( } } + HttpInstance->ConnectionClose = FALSE; + // // Transmit the request message. // -- 2.35.1 |
|
[PATCH v3 5/5] NetworkPkg/HttpDxe: Detect HTTP/1.0 servers
Oliver Steffen
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2720
Force connection close before the next request if the server identifies as version 1.0. Signed-off-by: Oliver Steffen <osteffen@...> --- NetworkPkg/HttpDxe/HttpImpl.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c index d40d55ac92ad..623e029c606e 100644 --- a/NetworkPkg/HttpDxe/HttpImpl.c +++ b/NetworkPkg/HttpDxe/HttpImpl.c @@ -1105,6 +1105,14 @@ HttpResponseWorker ( HttpInstance->CacheLen = BodyLen; } + // + // Check server's HTTP version. + // + if (AsciiStrnCmp (HttpHeaders, "HTTP/1.0", AsciiStrLen ("HTTP/1.0")) == 0) { + DEBUG ((DEBUG_VERBOSE, "HTTP: Server version is 1.0. Setting Connection close.\n")); + HttpInstance->ConnectionClose = TRUE; + } + // // Search for Status Code. // -- 2.35.1 |
|
[PATCH v3 4/5] NetworkPkg/HttpDxe: Detect 'Connection: close' header
Oliver Steffen
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2720
Force connection close before the next request if the server sends the 'Connection: close' header. Signed-off-by: Oliver Steffen <osteffen@...> --- NetworkPkg/HttpDxe/HttpImpl.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/NetworkPkg/HttpDxe/HttpImpl.c b/NetworkPkg/HttpDxe/HttpImpl.c index d8b014c94f3a..d40d55ac92ad 100644 --- a/NetworkPkg/HttpDxe/HttpImpl.c +++ b/NetworkPkg/HttpDxe/HttpImpl.c @@ -994,6 +994,7 @@ HttpResponseWorker ( UINTN HdrLen; NET_FRAGMENT Fragment; UINT32 TimeoutValue; + UINTN index; if ((Wrap == NULL) || (Wrap->HttpInstance == NULL)) { return EFI_INVALID_PARAMETER; @@ -1200,6 +1201,16 @@ HttpResponseWorker ( FreePool (HttpHeaders); HttpHeaders = NULL; + for (index = 0; index < HttpMsg->HeaderCount; ++index) { + if ((AsciiStriCmp ("Connection", HttpMsg->Headers[index].FieldName) == 0) && + (AsciiStriCmp ("close", HttpMsg->Headers[index].FieldValue) == 0)) + { + DEBUG ((DEBUG_VERBOSE, "Http: 'Connection: close' header received.\n")); + HttpInstance->ConnectionClose = TRUE; + break; + } + } + // // Init message-body parser by header information. // -- 2.35.1 |
|
[PATCH v3 0/5] Http Fixes (Take Two)
Oliver Steffen
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2720
This set of patches fixes booting from HTTP/1.0 servers. It also improves the interaction with HTTP/1.1 servers by recognizing the 'Connection: close' header field, which fixes a problem with servers that close the connection after a 404-error is encountered. It also prevents triggering the TCP issue described in https://bugzilla.tianocore.org/show_bug.cgi?id=3735 when booting from HTTP/1.0 servers. PR: https://github.com/tianocore/edk2/pull/2564 Oliver Steffen (5): NetworkPkg/HttpDxe: Decofigure Tcp4 before reconfiguring NetworkPkg/HttpDxe: Decofigure Tcp6 before reconfiguring NetworkPkg/HttpDxe: Add ConnectionClose flag fo HTTP_PROTOCOL NetworkPkg/HttpDxe: Detect 'Connection: close' header NetworkPkg/HttpDxe: Detect HTTP/1.0 servers NetworkPkg/HttpDxe/HttpProto.h | 2 ++ NetworkPkg/HttpDxe/HttpImpl.c | 25 ++++++++++++++++++++++++- NetworkPkg/HttpDxe/HttpProto.c | 24 ++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) -- 2.35.1 |
|
[PATCH v3 2/5] NetworkPkg/HttpDxe: Decofigure Tcp6 before reconfiguring
Oliver Steffen
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2720
Check if the state of the HTTP instance is HTTP_STATE_TCP_CONNECTED, or HTTP_STATE_TCP_CLOSED and de-configure the Tcp6 instance before configuring it again. Signed-off-by: Oliver Steffen <osteffen@...> --- NetworkPkg/HttpDxe/HttpProto.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c index cd54c574044b..33ae622c3f0b 100644 --- a/NetworkPkg/HttpDxe/HttpProto.c +++ b/NetworkPkg/HttpDxe/HttpProto.c @@ -1168,6 +1168,18 @@ HttpConfigureTcp6 ( Tcp6Option->KeepAliveInterval = HTTP_KEEP_ALIVE_INTERVAL; Tcp6Option->EnableNagle = TRUE; + if ((HttpInstance->State == HTTP_STATE_TCP_CONNECTED) || + (HttpInstance->State == HTTP_STATE_TCP_CLOSED)) + { + Status = HttpInstance->Tcp6->Configure (HttpInstance->Tcp6, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "HttpConfigureTcp6(NULL) - %r\n", Status)); + return Status; + } + + HttpInstance->State = HTTP_STATE_TCP_UNCONFIGED; + } + Status = HttpInstance->Tcp6->Configure (HttpInstance->Tcp6, Tcp6CfgData); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "HttpConfigureTcp6 - %r\n", Status)); -- 2.35.1 |
|
[PATCH v3 1/5] NetworkPkg/HttpDxe: Decofigure Tcp4 before reconfiguring
Oliver Steffen
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2720
Check if the state of the HTTP instance is HTTP_STATE_TCP_CONNECTED, or HTTP_STATE_TCP_CLOSED and de-configure the Tcp4 instance before configuring it again. Signed-off-by: Oliver Steffen <osteffen@...> --- NetworkPkg/HttpDxe/HttpProto.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/NetworkPkg/HttpDxe/HttpProto.c b/NetworkPkg/HttpDxe/HttpProto.c index 9457dd2623d3..cd54c574044b 100644 --- a/NetworkPkg/HttpDxe/HttpProto.c +++ b/NetworkPkg/HttpDxe/HttpProto.c @@ -1086,6 +1086,18 @@ HttpConfigureTcp4 ( Tcp4Option->EnableNagle = TRUE; Tcp4CfgData->ControlOption = Tcp4Option; + if ((HttpInstance->State == HTTP_STATE_TCP_CONNECTED) || + (HttpInstance->State == HTTP_STATE_TCP_CLOSED)) + { + Status = HttpInstance->Tcp4->Configure (HttpInstance->Tcp4, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "HttpConfigureTcp4(NULL) - %r\n", Status)); + return Status; + } + + HttpInstance->State = HTTP_STATE_TCP_UNCONFIGED; + } + Status = HttpInstance->Tcp4->Configure (HttpInstance->Tcp4, Tcp4CfgData); if (EFI_ERROR (Status)) { DEBUG ((DEBUG_ERROR, "HttpConfigureTcp4 - %r\n", Status)); -- 2.35.1 |
|
[PATCH 1/1] CryptoPkg: Add consumed library class by SMM to dsc file
Li, Yi
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3881
LibraryClass MmServicesTableLib SynchronizationLib in SmmCryptLib.inf should be listed in CryptoPkg.dsc. Cc: Jiewen Yao <jiewen.yao@...> Cc: Jian J Wang <jian.j.wang@...> Cc: Zhihao Li <zhihao.li@...> Signed-off-by: yi1 li <yi1.li@...> --- CryptoPkg/CryptoPkg.dsc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CryptoPkg/CryptoPkg.dsc b/CryptoPkg/CryptoPkg.dsc index 0aa72ed87846..e88da4fd7e46 100644 --- a/CryptoPkg/CryptoPkg.dsc +++ b/CryptoPkg/CryptoPkg.dsc @@ -127,6 +127,8 @@ TlsLib|CryptoPkg/Library/TlsLib/TlsLib.inf [LibraryClasses.common.DXE_SMM_DRIVER] + MmServicesTableLib|MdePkg/Library/MmServicesTableLib/MmServicesTableLib.inf + SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf ReportStatusCodeLib|MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf TlsLib|CryptoPkg/Library/TlsLibNull/TlsLibNull.inf -- 2.33.0.windows.2 |
|
Re: [PATCH 1/2] MdeModulePkg: StackOffset must be aligned to a 16-byte boundary in X64
Marvin Häuser
Good day,
Thanks for the updates! On 22. Mar 2022, at 08:23, Kuo, Ted <ted.kuo@...> wrote:Yes, I understood as much. I built a chain of reasoning for alignment in the response for the first revision, because a proper fix needs knowledge of which assumption is wrong in the first place. The question is, which *exact* value in the chain is not 16-Byte aligned, and should it be? Did you ever print all involved values, like PhysicalMemoryBegin (or whatever its name was, sorry, I’m responding from mobile)? Yes, I agreed above. But StackOffset is not the definition of where the new stack is located, but only a consequence from it. It is not the primary descriptor is what I’m trying to say. And the OldStack/NewStack in the fsp patch indicates the *current* old/new stack. The fsp patch just makes left shift 8-byte of whole used stack data when new stack not aligning with old stack. Hence I think no need to update TopOfNewStack.Yes, I understand what is happening, I don’t understand why it is happening. My comment here was separate from the FSP patch and only concerned the code here. If the top of the stack (as described by StackOffset) is aligned from its original value, why can TopOfNewStack remain unchanged, when it all points to the old, unaligned top, where no data should ever be stored? e.g.Is this the top or bottom? If it’s the top, why can it *not* be 16-Byte-aligned? If it’s the bottom, how is it relevant here? We are only dealing with the top addresses in this patch, no? new stack: 0x49c8f3b8But StackOffset describes the offset from the top of the old stack to the top of the new stack. How does the top “remain unchanged”? Top alignment is the root for the transitive alignment chain, if it is aligned, and it must be, everything is aligned. Confused, sorry. Maybe explaining the rest will make this clearer. This is why I asked about 1). Things like this are fundamental and should not be changed without understanding both the full scope of the issue and the full scope of the changes. But how will StackOffset be in-sync with the changes in FSP SecCore then? If I’m not mistaken with my intro from last mail, both calculate the stack address separately from each other, and their calculations must be in-sync. If I’m mistaken, how does it work then? Should be solved by 6). Thanks! Best regards, Marvin
|
|
Re: [PATCH v1 4/4] OvmfPkg: Do not check VbeShim.h formatting with Uncrustify
Gerd Hoffmann
On Mon, Mar 21, 2022 at 09:58:14PM -0400, Michael Kubacki wrote:
From: Michael Kubacki <michael.kubacki@...>Acked-by: Gerd Hoffmann <kraxel@...> |
|
Re: [PATCH v1 3/4] OvmfPkg: Revert Uncrustify formatting in VbeShim.h files
Gerd Hoffmann
On Mon, Mar 21, 2022 at 09:58:13PM -0400, Michael Kubacki wrote:
From: Michael Kubacki <michael.kubacki@...>Acked-by: Gerd Hoffmann <kraxel@...> |
|