26#define _DBGMSGID_ "[PRMCONFIG]"
45 if ((RuntimeMmioRanges ==
NULL) || (RuntimeMmioRanges->Count == 0)) {
49 for (Index = 0; Index < (
UINTN)RuntimeMmioRanges->Count; Index++) {
50 RuntimeMmioRanges->Range[Index].VirtualBaseAddress = RuntimeMmioRanges->Range[Index].PhysicalBaseAddress;
51 gRT->ConvertPointer (0x0, (VOID **)&(RuntimeMmioRanges->Range[Index].VirtualBaseAddress));
74 DEBUG ((DEBUG_INFO,
"%a %a - Entry.\n", _DBGMSGID_, __func__));
76 if ((RuntimeMmioRanges ==
NULL) || (RuntimeMmioRanges->Count == 0)) {
80 for (Index = 0; Index < (
UINTN)RuntimeMmioRanges->Count; Index++) {
83 " %a %a: Runtime MMIO Range [%d].\n",
90 " %a %a: Physical address = 0x%016x. Length = 0x%x.\n",
93 RuntimeMmioRanges->Range[Index].PhysicalBaseAddress,
94 RuntimeMmioRanges->Range[Index].Length
98 ASSERT ((RuntimeMmioRanges->Range[Index].PhysicalBaseAddress & EFI_PAGE_MASK) == 0);
99 ASSERT ((RuntimeMmioRanges->Range[Index].Length & EFI_PAGE_MASK) == 0);
101 Status2 = EFI_NOT_FOUND;
102 Status =
gDS->GetMemorySpaceDescriptor (RuntimeMmioRanges->Range[Index].PhysicalBaseAddress, &Descriptor);
103 if (!EFI_ERROR (Status) &&
106 ((Descriptor.
Length & EFI_PAGE_MASK) != 0)
110 Status2 =
gDS->RemoveMemorySpace (
111 RuntimeMmioRanges->Range[Index].PhysicalBaseAddress,
116 if ((Status == EFI_NOT_FOUND) || !EFI_ERROR (Status2)) {
117 Status =
gDS->AddMemorySpace (
119 RuntimeMmioRanges->Range[Index].PhysicalBaseAddress,
120 (UINT64)RuntimeMmioRanges->Range[Index].Length,
121 EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
125 Status =
gDS->AllocateMemorySpace (
129 (UINT64)RuntimeMmioRanges->Range[Index].Length,
130 &RuntimeMmioRanges->Range[Index].PhysicalBaseAddress,
137 Status =
gDS->GetMemorySpaceDescriptor (RuntimeMmioRanges->Range[Index].PhysicalBaseAddress, &Descriptor);
139 if (EFI_ERROR (Status)) {
142 " %a %a: Error [%r] finding descriptor for runtime memory range 0x%016x.\n",
146 RuntimeMmioRanges->Range[Index].PhysicalBaseAddress
151 if ((Descriptor.
Attributes & EFI_MEMORY_RUNTIME) != 0) {
160 Status =
gDS->SetMemorySpaceAttributes (
161 RuntimeMmioRanges->Range[Index].PhysicalBaseAddress,
162 (UINT64)RuntimeMmioRanges->Range[Index].Length,
166 if (EFI_ERROR (Status)) {
169 " %a %a: Error [%r] setting descriptor for runtime memory range 0x%016x.\n",
173 RuntimeMmioRanges->Range[Index].PhysicalBaseAddress
176 DEBUG ((DEBUG_INFO,
" %a %a: Successfully set runtime attribute for the MMIO range.\n", _DBGMSGID_, __func__));
197 DEBUG ((DEBUG_INFO,
"%a %a - Entry.\n", _DBGMSGID_, __func__));
202 if ((mRuntimeMmioRanges ==
NULL) && (mMaxRuntimeMmioRangeCount > 0)) {
205 " %a %a: Memory allocation for runtime MMIO pointer array failed.\n",
214 Status =
gBS->LocateHandleBuffer (
216 &gPrmConfigProtocolGuid,
221 if (!EFI_ERROR (Status)) {
222 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
223 Status =
gBS->HandleProtocol (
224 HandleBuffer[HandleIndex],
225 &gPrmConfigProtocolGuid,
226 (VOID **)&PrmConfigProtocol
229 if (EFI_ERROR (Status) || (PrmConfigProtocol ==
NULL)) {
233 if (PrmConfigProtocol->ModuleContextBuffers.RuntimeMmioRanges !=
NULL) {
234 if (RangeIndex >= mMaxRuntimeMmioRangeCount) {
235 Status = EFI_BUFFER_TOO_SMALL;
238 " %a %a: Index out of bounds - Actual count (%d) of runtime MMIO ranges exceeds maximum count (%d).\n",
242 mMaxRuntimeMmioRangeCount
248 mRuntimeMmioRanges[RangeIndex++] = PrmConfigProtocol->ModuleContextBuffers.RuntimeMmioRanges;
254 " %a %a: %d MMIO ranges buffers saved for future virtual memory conversion.\n",
280 if (PrmDataBuffer ==
NULL) {
281 return EFI_INVALID_PARAMETER;
284 if (PrmDataBuffer->Header.Signature != PRM_DATA_BUFFER_HEADER_SIGNATURE) {
285 DEBUG ((DEBUG_ERROR,
" %a %a: The PRM data buffer signature is invalid. PRM module.\n", _DBGMSGID_, __func__));
286 return EFI_NOT_FOUND;
290 DEBUG ((DEBUG_ERROR,
" %a %a: The PRM data buffer length is invalid.\n", _DBGMSGID_, __func__));
291 return EFI_BUFFER_TOO_SMALL;
314 if (PrmContextBuffer ==
NULL) {
315 return EFI_INVALID_PARAMETER;
318 if (PrmContextBuffer->Signature != PRM_CONTEXT_BUFFER_SIGNATURE) {
319 DEBUG ((DEBUG_ERROR,
" %a %a: The PRM context buffer signature is invalid.\n", _DBGMSGID_, __func__));
320 return EFI_NOT_FOUND;
323 if (
IsZeroGuid (&PrmContextBuffer->HandlerGuid)) {
324 DEBUG ((DEBUG_ERROR,
" %a %a: The PRM context buffer GUID is zero.\n", _DBGMSGID_, __func__));
325 return EFI_NOT_FOUND;
328 if ((PrmContextBuffer->StaticDataBuffer !=
NULL) && EFI_ERROR (
ValidatePrmDataBuffer (PrmContextBuffer->StaticDataBuffer))) {
331 " %a %a: Error in static buffer for PRM handler %g.\n",
334 &PrmContextBuffer->HandlerGuid
336 return EFI_NOT_FOUND;
364 for (Index = 0; Index < mMaxRuntimeMmioRangeCount; Index++) {
395 DEBUG ((DEBUG_INFO,
"%a %a - Entry.\n", _DBGMSGID_, __func__));
398 Status =
gBS->LocateHandleBuffer (
400 &gPrmConfigProtocolGuid,
405 if (!EFI_ERROR (Status)) {
406 for (HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
407 Status =
gBS->HandleProtocol (
408 HandleBuffer[HandleIndex],
409 &gPrmConfigProtocolGuid,
410 (VOID **)&PrmConfigProtocol
413 if (EFI_ERROR (Status) || (PrmConfigProtocol ==
NULL)) {
419 " %a %a: Found PRM configuration protocol for PRM module %g.\n",
422 &PrmConfigProtocol->ModuleContextBuffers.ModuleGuid
425 DEBUG ((DEBUG_INFO,
" %a %a: Validating module context buffers...\n", _DBGMSGID_, __func__));
426 for (BufferIndex = 0; BufferIndex < PrmConfigProtocol->ModuleContextBuffers.BufferCount; BufferIndex++) {
427 CurrentContextBuffer = &(PrmConfigProtocol->ModuleContextBuffers.Buffer[BufferIndex]);
430 if (EFI_ERROR (Status)) {
433 " %a %a: Context buffer validation failed for PRM handler %g.\n",
441 DEBUG ((DEBUG_INFO,
" %a %a: Module context buffer validation complete.\n", _DBGMSGID_, __func__));
443 if (PrmConfigProtocol->ModuleContextBuffers.RuntimeMmioRanges !=
NULL) {
446 " %a %a: Found %d PRM runtime MMIO ranges.\n",
449 PrmConfigProtocol->ModuleContextBuffers.RuntimeMmioRanges->Count
452 mMaxRuntimeMmioRangeCount++;
459 if (HandleBuffer !=
NULL) {
460 gBS->FreePool (HandleBuffer);
463 gBS->CloseEvent (Event);
486 DEBUG ((DEBUG_INFO,
"%a %a - Entry.\n", _DBGMSGID_, __func__));
492 Status =
gBS->CreateEventEx (
497 &gEfiEndOfDxeEventGroupGuid,
506 Status =
gBS->CreateEventEx (
511 &gEfiEventVirtualAddressChangeGuid,
BOOLEAN EFIAPI IsZeroGuid(IN CONST GUID *Guid)
VOID *EFIAPI AllocateRuntimeZeroPool(IN UINTN AllocationSize)
EFI_RUNTIME_SERVICES * gRT
#define GLOBAL_REMOVE_IF_UNREFERENCED
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
@ EfiGcdMemoryTypeReserved
@ EfiGcdMemoryTypeMemoryMappedIo
EFI_STATUS ValidatePrmContextBuffer(IN CONST PRM_CONTEXT_BUFFER *PrmContextBuffer)
VOID EFIAPI PrmConfigVirtualAddressChangeEvent(IN EFI_EVENT Event, IN VOID *Context)
VOID StoreVirtualMemoryAddressChangePointers(VOID)
VOID ConvertRuntimeMemoryRangeAddresses(IN PRM_RUNTIME_MMIO_RANGES *RuntimeMmioRanges)
VOID EFIAPI PrmConfigEndOfDxeNotification(IN EFI_EVENT Event, IN VOID *Context)
VOID SetRuntimeMemoryRangeAttributes(IN PRM_RUNTIME_MMIO_RANGES *RuntimeMmioRanges)
EFI_STATUS EFIAPI PrmConfigEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS ValidatePrmDataBuffer(IN CONST PRM_DATA_BUFFER *PrmDataBuffer)
EFI_GCD_MEMORY_TYPE GcdMemoryType