24#define _DBGMSGID_ "[PRMMODULEDISCOVERYLIB]"
51 DEBUG ((DEBUG_INFO,
"%a %a - Entry.\n", _DBGMSGID_, __func__));
53 if (ModuleImageContext ==
NULL) {
54 return EFI_INVALID_PARAMETER;
57 if (*ModuleImageContext ==
NULL) {
60 CurrentListEntry =
NULL;
62 if ((CurrentListEntry ==
NULL) || (CurrentListEntry->Signature != PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY_SIGNATURE)) {
63 return EFI_INVALID_PARAMETER;
66 CurrentLink = &CurrentListEntry->Link;
67 ForwardLink =
GetNextNode (&mPrmModuleList, CurrentLink);
69 if (ForwardLink == &mPrmModuleList) {
75 if (ForwardListEntry->Signature == PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY_SIGNATURE) {
76 *ModuleImageContext = &ForwardListEntry->Context;
97 DEBUG ((DEBUG_INFO,
"%a %a - Entry.\n", _DBGMSGID_, __func__));
99 PrmModuleImageContextListEntry =
AllocateZeroPool (
sizeof (*PrmModuleImageContextListEntry));
100 if (PrmModuleImageContextListEntry ==
NULL) {
106 " %a %a: Allocated PrmModuleImageContextListEntry at 0x%x of size 0x%x bytes.\n",
109 (
UINTN)PrmModuleImageContextListEntry,
110 sizeof (*PrmModuleImageContextListEntry)
113 PrmModuleImageContextListEntry->Signature = PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY_SIGNATURE;
115 return PrmModuleImageContextListEntry;
138 for (Index = 0; Index < MmramRangeCount; Index++) {
139 if ((Address >= MmramRanges[Index].CpuStart) &&
140 (Address < (MmramRanges[Index].CpuStart + MmramRanges[Index].PhysicalSize)))
182 UINTN PrmHandlerCount;
183 UINTN PrmModuleCount;
187 UINTN MmramRangeCount;
189 DEBUG ((DEBUG_INFO,
"%a %a - Entry.\n", _DBGMSGID_, __func__));
195 return EFI_ALREADY_STARTED;
198 Status =
gBS->LocateHandleBuffer (
200 &gEfiLoadedImageProtocolGuid,
205 if (EFI_ERROR (Status) && (HandleCount == 0)) {
206 DEBUG ((DEBUG_ERROR,
"%a %a: No LoadedImageProtocol instances found!\n", _DBGMSGID_, __func__));
207 return EFI_NOT_FOUND;
212 Status =
gBS->LocateProtocol (
213 &gEfiMmAccessProtocolGuid,
222 Status = MmAccess->GetCapabilities (MmAccess, &Size,
NULL);
223 if ((Status == EFI_BUFFER_TOO_SMALL) && (Size != 0)) {
225 if (MmramRanges !=
NULL) {
226 Status = MmAccess->GetCapabilities (MmAccess, &Size, MmramRanges);
234 for (Index = 0; Index < HandleCount; Index++) {
235 Status =
gBS->HandleProtocol (
237 &gEfiLoadedImageProtocolGuid,
238 (VOID **)&LoadedImageProtocol
240 if (EFI_ERROR (Status)) {
248 ZeroMem (&TempPrmModuleImageContext,
sizeof (TempPrmModuleImageContext));
249 TempPrmModuleImageContext.PeCoffImageContext.
Handle = LoadedImageProtocol->
ImageBase;
253 if (EFI_ERROR (Status) || (TempPrmModuleImageContext.PeCoffImageContext.
ImageError != IMAGE_ERROR_SUCCESS)) {
256 "%a %a: ImageHandle 0x%016lx is not a valid PE/COFF image. It cannot be considered a PRM module.\n",
264 if (TempPrmModuleImageContext.PeCoffImageContext.
IsTeImage) {
272 &TempPrmModuleImageContext.PeCoffImageContext,
273 &TempPrmModuleImageContext.ExportDirectory
275 if (EFI_ERROR (Status)) {
281 TempPrmModuleImageContext.ExportDirectory,
282 &TempPrmModuleImageContext.PeCoffImageContext,
283 &TempPrmModuleImageContext.ExportDescriptor
285 if (EFI_ERROR (Status) || (TempPrmModuleImageContext.ExportDescriptor ==
NULL)) {
295 if (PrmModuleImageContextListEntry ==
NULL) {
296 return EFI_OUT_OF_RESOURCES;
300 &PrmModuleImageContextListEntry->Context,
301 &TempPrmModuleImageContext,
302 sizeof (PrmModuleImageContextListEntry->Context)
304 InsertTailList (&mPrmModuleList, &PrmModuleImageContextListEntry->Link);
305 PrmHandlerCount += TempPrmModuleImageContext.ExportDescriptor->Header.NumberPrmHandlers;
307 DEBUG ((DEBUG_INFO,
"%a %a: New PRM Module inserted into list to be processed.\n", _DBGMSGID_, __func__));
310 if (HandlerCount !=
NULL) {
311 *HandlerCount = PrmHandlerCount;
314 if (ModuleCount !=
NULL) {
315 *ModuleCount = PrmModuleCount;
318 if (MmramRanges !=
NULL) {
352 while (!
IsNull (&mPrmModuleList, Link)) {
BOOLEAN EFIAPI IsNull(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI GetNextPrmModuleEntry(IN OUT PRM_MODULE_IMAGE_CONTEXT **ModuleImageContext)
PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY * CreateNewPrmModuleImageContextListEntry(VOID)
BOOLEAN EFIAPI IsAddressInMmram(IN EFI_PHYSICAL_ADDRESS Address, IN EFI_MMRAM_DESCRIPTOR *MmramRanges, IN UINTN MmramRangeCount)
EFI_STATUS EFIAPI DiscoverPrmModules(OUT UINTN *ModuleCount OPTIONAL, OUT UINTN *HandlerCount OPTIONAL)
EFI_STATUS EFIAPI PrmModuleDiscoveryLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI PrmModuleDiscoveryLibDestructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define BASE_CR(Record, TYPE, Field)
#define DEBUG(Expression)
#define CR(Record, TYPE, Field, TestSignature)
RETURN_STATUS EFIAPI PeCoffLoaderGetImageInfo(IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext)
RETURN_STATUS EFIAPI PeCoffLoaderImageReadFromMemory(IN VOID *FileHandle, IN UINTN FileOffset, IN OUT UINTN *ReadSize, OUT VOID *Buffer)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_STATUS GetExportDirectoryInPeCoffImage(IN VOID *Image, IN PE_COFF_LOADER_IMAGE_CONTEXT *PeCoffLoaderImageContext, OUT EFI_IMAGE_EXPORT_DIRECTORY **ImageExportDirectory)
EFI_STATUS GetPrmModuleExportDescriptorTable(IN EFI_IMAGE_EXPORT_DIRECTORY *ImageExportDirectory, IN PE_COFF_LOADER_IMAGE_CONTEXT *PeCoffLoaderImageContext, OUT PRM_MODULE_EXPORT_DESCRIPTOR_STRUCT **ExportDescriptor)
UINT64 EFI_PHYSICAL_ADDRESS
VOID * ImageBase
The base address at which the image was loaded.
PE_COFF_LOADER_READ_FILE ImageRead