-/** @file\r
- Function to create page talbe.\r
- Only create page table for x64, and leave the CreatePageTable empty for Ia32.\r
-\r
- Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r
- SPDX-License-Identifier: BSD-2-Clause-Patent\r
-\r
-**/\r
-#include <Library/CpuPageTableLib.h>\r
-#include <Library/MemoryAllocationLib.h>\r
-#include <Base.h>\r
-#include <Library/BaseMemoryLib.h>\r
-#include <Library/DebugLib.h>\r
-\r
-/**\r
- Create 1:1 mapping page table in reserved memory to map the specified address range.\r
-\r
- @param[in] LinearAddress The start of the linear address range.\r
- @param[in] Length The length of the linear address range.\r
-\r
- @return The page table to be created.\r
-**/\r
-UINTN\r
-CreatePageTable (\r
- IN UINTN Address,\r
- IN UINTN Length\r
- )\r
-{\r
- EFI_STATUS Status;\r
- VOID *PageTableBuffer;\r
- UINTN PageTableBufferSize;\r
- UINTN PageTable;\r
-\r
- IA32_MAP_ATTRIBUTE MapAttribute;\r
- IA32_MAP_ATTRIBUTE MapMask;\r
-\r
- MapAttribute.Uint64 = Address;\r
- MapAttribute.Bits.Present = 1;\r
- MapAttribute.Bits.ReadWrite = 1;\r
-\r
- MapMask.Bits.PageTableBaseAddress = 1;\r
- MapMask.Bits.Present = 1;\r
- MapMask.Bits.ReadWrite = 1;\r
-\r
- PageTable = 0;\r
- PageTableBufferSize = 0;\r
-\r
- Status = PageTableMap (\r
- &PageTable,\r
- Paging4Level,\r
- NULL,\r
- &PageTableBufferSize,\r
- Address,\r
- Length,\r
- &MapAttribute,\r
- &MapMask\r
- );\r
- ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
- DEBUG ((DEBUG_INFO, "AP Page Table Buffer Size = %x\n", PageTableBufferSize));\r
-\r
- PageTableBuffer = AllocateReservedPages (EFI_SIZE_TO_PAGES (PageTableBufferSize));\r
- ASSERT (PageTableBuffer != NULL);\r
- Status = PageTableMap (\r
- &PageTable,\r
- Paging4Level,\r
- PageTableBuffer,\r
- &PageTableBufferSize,\r
- Address,\r
- Length,\r
- &MapAttribute,\r
- &MapMask\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
- return PageTable;\r
-}\r