X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=EdkModulePkg%2FCore%2FDxeIplPeim%2FIa32%2FVirtualMemory.c;h=89b18c36f8cf9e9d09b0fdcfa466501433a778b3;hb=7689c0808e654d53f28c7993cb97a5dd9ecc9627;hp=78134564e5b49917f7834c4afa215c91331e4a54;hpb=f40793becf28ffb9b58e29c8501410247df9dedd;p=mirror_edk2.git diff --git a/EdkModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.c b/EdkModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.c index 78134564e5..89b18c36f8 100644 --- a/EdkModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.c +++ b/EdkModulePkg/Core/DxeIplPeim/Ia32/VirtualMemory.c @@ -57,7 +57,6 @@ Returns: --*/ { - UINT32 RegEax; UINT8 PhysicalAddressBits; EFI_PHYSICAL_ADDRESS PageAddress; UINTN IndexOfPml4Entries; @@ -69,22 +68,18 @@ Returns: PAGE_MAP_AND_DIRECTORY_POINTER *PageMap; PAGE_MAP_AND_DIRECTORY_POINTER *PageDirectoryPointerEntry; PAGE_TABLE_ENTRY *PageDirectoryEntry; + UINTN TotalPagesNum; + UINTN BigPageAddress; + VOID *Hob; // - // By architecture only one PageMapLevel4 exists - so lets allocate storage for it. - // - PageMap = AllocatePages (1); - ASSERT (PageMap != NULL); - - // - // Get physical address bits supported. + // Get physical address bits supported from CPU HOB. // - AsmCpuid (0x80000000, &RegEax, NULL, NULL, NULL); - if (RegEax >= 0x80000008) { - AsmCpuid (0x80000008, &RegEax, NULL, NULL, NULL); - PhysicalAddressBits = (UINT8) RegEax; - } else { - PhysicalAddressBits = 36; + PhysicalAddressBits = 36; + + Hob = GetFirstHob (EFI_HOB_TYPE_CPU); + if (Hob != NULL) { + PhysicalAddressBits = ((EFI_HOB_CPU *) Hob)->SizeOfMemorySpace; } // @@ -98,6 +93,19 @@ Returns: NumberOfPdpEntriesNeeded = 512; } + // + // Pre-allocate big pages to avoid later allocations. + // + TotalPagesNum = (NumberOfPdpEntriesNeeded + 1) * NumberOfPml4EntriesNeeded + 1; + BigPageAddress = (UINTN) AllocatePages (TotalPagesNum); + ASSERT (BigPageAddress != 0); + + // + // By architecture only one PageMapLevel4 exists - so lets allocate storage for it. + // + PageMap = (VOID *) BigPageAddress; + BigPageAddress += EFI_PAGE_SIZE; + PageMapLevel4Entry = PageMap; PageAddress = 0; for (IndexOfPml4Entries = 0; IndexOfPml4Entries < NumberOfPml4EntriesNeeded; IndexOfPml4Entries++, PageMapLevel4Entry++) { @@ -105,8 +113,8 @@ Returns: // Each PML4 entry points to a page of Page Directory Pointer entires. // So lets allocate space for them and fill them in in the IndexOfPdpEntries loop. // - PageDirectoryPointerEntry = AllocatePages (1); - ASSERT (PageDirectoryPointerEntry != NULL); + PageDirectoryPointerEntry = (VOID *) BigPageAddress; + BigPageAddress += EFI_PAGE_SIZE; // // Make a PML4 Entry @@ -120,8 +128,8 @@ Returns: // Each Directory Pointer entries points to a page of Page Directory entires. // So allocate space for them and fill them in in the IndexOfPageDirectoryEntries loop. // - PageDirectoryEntry = AllocatePages (1); - ASSERT (PageDirectoryEntry != NULL); + PageDirectoryEntry = (VOID *) BigPageAddress; + BigPageAddress += EFI_PAGE_SIZE; // // Fill in a Page Directory Pointer Entries