83 EFI_PHYSICAL_ADDRESS BufferPtr;
85 AcpiTableOri = (VOID *)(UINTN)(*(UINT64 *)(*Table));
86 if (((UINTN)AcpiTableOri < 0x100000) && ((UINTN)AcpiTableOri > 0xE0000)) {
88 Status =
gBS->AllocatePages (
91 EFI_SIZE_TO_PAGES (TableLen),
94 ASSERT_EFI_ERROR (Status);
96 AcpiTableNew = (VOID *)(UINTN)BufferPtr;
97 CopyMem (AcpiTableNew, AcpiTableOri, TableLen);
99 AcpiTableNew = AcpiTableOri;
105 *Table = AcpiTableNew;
134 SMBIOS_TABLE_ENTRY_POINT *SmbiosTableNew;
135 SMBIOS_TABLE_ENTRY_POINT *SmbiosTableOri;
137 UINT32 SmbiosEntryLen;
139 EFI_PHYSICAL_ADDRESS BufferPtr;
141 SmbiosTableNew = NULL;
146 SmbiosTableOri = (SMBIOS_TABLE_ENTRY_POINT *)(UINTN)(*(UINT64 *)(*Table));
148 if ((SmbiosTableOri == NULL) ||
149 ((UINTN)SmbiosTableOri > 0x100000) ||
150 ((UINTN)SmbiosTableOri < 0xF0000))
159 if (SmbiosTableOri->SmbiosBcdRevision != 0x21) {
160 SmbiosEntryLen = SmbiosTableOri->EntryPointLength;
165 SmbiosEntryLen = 0x1F;
168 BufferLen = SmbiosEntryLen +
SYS_TABLE_PAD (SmbiosEntryLen) + SmbiosTableOri->TableLength;
169 Status =
gBS->AllocatePages (
172 EFI_SIZE_TO_PAGES (BufferLen),
175 ASSERT_EFI_ERROR (Status);
177 SmbiosTableNew = (SMBIOS_TABLE_ENTRY_POINT *)(UINTN)BufferPtr;
186 BufferPtr += SmbiosEntryLen +
SYS_TABLE_PAD (SmbiosEntryLen);
188 (VOID *)(UINTN)BufferPtr,
189 (VOID *)(UINTN)(SmbiosTableOri->TableAddress),
190 SmbiosTableOri->TableLength
192 SmbiosTableNew->TableAddress = (UINT32)BufferPtr;
193 SmbiosTableNew->SmbiosBcdRevision = 0x26;
194 SmbiosTableNew->IntermediateChecksum = 0;
195 SmbiosTableNew->IntermediateChecksum = CalculateCheckSum8 (
196 (UINT8 *)SmbiosTableNew + 0x10,
197 SmbiosEntryLen - 0x10
202 *Table = SmbiosTableNew;
332 UINTN NumberOfDescriptors;
333 EFI_GCD_MEMORY_SPACE_DESCRIPTOR *MemorySpaceMap;
335 EFI_PEI_HOB_POINTERS GuidHob;
339 EFI_PHYSICAL_ADDRESS Memory;
340 EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
341 EFI_PHYSICAL_ADDRESS FirstNonConventionalAddr;
346 Status = gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);
347 ASSERT_EFI_ERROR (Status);
349 for (Index = 0; Index < NumberOfDescriptors; ++Index) {
350 Capabilities = MemorySpaceMap[Index].Capabilities;
352 if ( (MemorySpaceMap[Index].GcdMemoryType == EfiGcdMemoryTypeReserved)
356 Status = gDS->RemoveMemorySpace (
357 MemorySpaceMap[Index].BaseAddress,
358 MemorySpaceMap[Index].
Length
360 if (EFI_ERROR (Status)) {
376 "UpdateMemoryMap: Remove %016lx %016lx - %r\n",
377 MemorySpaceMap[Index].BaseAddress,
378 MemorySpaceMap[Index].
Length,
384 Status = gDS->AddMemorySpace (
385 (Capabilities & EFI_MEMORY_MORE_RELIABLE) == EFI_MEMORY_MORE_RELIABLE
386 ? EfiGcdMemoryTypeMoreReliable : EfiGcdMemoryTypeSystemMemory,
387 MemorySpaceMap[Index].BaseAddress,
388 MemorySpaceMap[Index].
Length,
391 ASSERT_EFI_ERROR (Status);
394 "UpdateMemoryMap: Remap %016lx %016lx - %r\n",
395 MemorySpaceMap[Index].BaseAddress,
396 MemorySpaceMap[Index].
Length,
402 gBS->FreePool (MemorySpaceMap);
408 if (GuidHob.Raw == NULL) {
412 Table = GET_GUID_HOB_DATA (GuidHob.Guid);
418 MemoryDescHob.
MemDesc = *(EFI_MEMORY_DESCRIPTOR **)((UINTN)Table +
sizeof (UINTN));
420 FirstNonConventionalAddr = 0xFFFFFFFF;
421 for (Index = 0; Index < MemoryDescHob.
MemDescCount; Index++) {
422 if (MemoryDescHob.
MemDesc[Index].PhysicalStart < 0x100000) {
426 if (MemoryDescHob.
MemDesc[Index].PhysicalStart >= 0x100000000ULL) {
430 if ( (MemoryDescHob.
MemDesc[Index].Type == EfiReservedMemoryType)
431 || (MemoryDescHob.
MemDesc[Index].Type == EfiRuntimeServicesData)
432 || (MemoryDescHob.
MemDesc[Index].Type == EfiRuntimeServicesCode)
433 || (MemoryDescHob.
MemDesc[Index].Type == EfiACPIReclaimMemory)
434 || (MemoryDescHob.
MemDesc[Index].Type == EfiACPIMemoryNVS))
436 if (MemoryDescHob.
MemDesc[Index].PhysicalStart < FirstNonConventionalAddr) {
437 FirstNonConventionalAddr = MemoryDescHob.
MemDesc[Index].PhysicalStart;
440 if ( (MemoryDescHob.
MemDesc[Index].Type == EfiRuntimeServicesData)
441 || (MemoryDescHob.
MemDesc[Index].Type == EfiRuntimeServicesCode))
447 Status = gDS->GetMemorySpaceDescriptor (MemoryDescHob.
MemDesc[Index].PhysicalStart, &Descriptor);
448 if (EFI_ERROR (Status)) {
452 if (Descriptor.GcdMemoryType != EfiGcdMemoryTypeReserved) {
462 Status = gDS->FreeMemorySpace (
463 MemoryDescHob.
MemDesc[Index].PhysicalStart,
467 if (EFI_ERROR (Status)) {
471 Status = gDS->RemoveMemorySpace (
472 MemoryDescHob.
MemDesc[Index].PhysicalStart,
475 if (EFI_ERROR (Status)) {
482 if (MemoryDescHob.
MemDesc[Index].Type == EfiRuntimeServicesData) {
483 MemoryDescHob.
MemDesc[Index].Type = EfiBootServicesData;
485 MemoryDescHob.
MemDesc[Index].Type = EfiBootServicesCode;
496 Status = gDS->AddMemorySpace (
497 EfiGcdMemoryTypeSystemMemory,
498 MemoryDescHob.
MemDesc[Index].PhysicalStart,
500 MemoryDescHob.
MemDesc[Index].Attribute
502 if (EFI_ERROR (Status)) {
506 Memory = MemoryDescHob.
MemDesc[Index].PhysicalStart;
507 Status =
gBS->AllocatePages (
509 (EFI_MEMORY_TYPE)MemoryDescHob.
MemDesc[Index].Type,
510 (UINTN)MemoryDescHob.
MemDesc[Index].NumberOfPages,
513 if (EFI_ERROR (Status)) {
525 for (Index = 0; Index < MemoryDescHob.
MemDescCount; Index++) {
526 if (MemoryDescHob.
MemDesc[Index].PhysicalStart < 0x100000) {
530 if (MemoryDescHob.
MemDesc[Index].Type != EfiConventionalMemory) {
534 if (MemoryDescHob.
MemDesc[Index].PhysicalStart < FirstNonConventionalAddr) {
541 gDS->AddMemorySpace (
542 EfiGcdMemoryTypeSystemMemory,
543 MemoryDescHob.
MemDesc[Index].PhysicalStart,
545 MemoryDescHob.
MemDesc[Index].Attribute
650 IN EFI_DEVICE_PATH_PROTOCOL *PciDevicePath,
651 OUT EFI_DEVICE_PATH_PROTOCOL **GopDevicePath
656 EFI_HANDLE PciDeviceHandle;
657 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;
658 EFI_DEVICE_PATH_PROTOCOL *TempPciDevicePath;
659 UINTN GopHandleCount;
660 EFI_HANDLE *GopHandleBuffer;
662 if ((PciDevicePath == NULL) || (GopDevicePath == NULL)) {
663 return EFI_INVALID_PARAMETER;
669 *GopDevicePath = PciDevicePath;
670 TempPciDevicePath = PciDevicePath;
672 Status =
gBS->LocateDevicePath (
677 if (EFI_ERROR (Status)) {
687 gBS->ConnectController (PciDeviceHandle, NULL, NULL, FALSE);
689 Status =
gBS->LocateHandleBuffer (
696 if (!EFI_ERROR (Status)) {
700 for (Index = 0; Index < GopHandleCount; Index++) {
701 Status =
gBS->HandleProtocol (
702 GopHandleBuffer[Index],
704 (VOID *)&TempDevicePath
706 if (EFI_ERROR (Status)) {
713 GetDevicePathSize (PciDevicePath) - END_DEVICE_PATH_LENGTH
723 *GopDevicePath = TempDevicePath;
734 gBS->FreePool (GopHandleBuffer);