/** @file\r
Page table management header file.\r
\r
- Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
#define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_PSE BIT0\r
#define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_PAE BIT1\r
#define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_PAGE_1G_SUPPORT BIT2\r
+#define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_5_LEVEL BIT3\r
#define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_WP_ENABLE BIT30\r
#define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_XD_ACTIVATED BIT31\r
// Other bits are reserved for future use\r
typedef struct {\r
- UINT32 PageTableBase;\r
- UINT32 Reserved;\r
- UINT32 Attributes;\r
+ UINT32 PageTableBase;\r
+ UINT32 Reserved;\r
+ UINT32 Attributes;\r
} PAGE_TABLE_LIB_PAGING_CONTEXT_IA32;\r
\r
typedef struct {\r
- UINT64 PageTableBase;\r
- UINT32 Attributes;\r
+ UINT64 PageTableBase;\r
+ UINT32 Attributes;\r
} PAGE_TABLE_LIB_PAGING_CONTEXT_X64;\r
\r
typedef union {\r
- PAGE_TABLE_LIB_PAGING_CONTEXT_IA32 Ia32;\r
- PAGE_TABLE_LIB_PAGING_CONTEXT_X64 X64;\r
+ PAGE_TABLE_LIB_PAGING_CONTEXT_IA32 Ia32;\r
+ PAGE_TABLE_LIB_PAGING_CONTEXT_X64 X64;\r
} PAGE_TABLE_LIB_PAGING_CONTEXT_DATA;\r
\r
typedef struct {\r
// #define IMAGE_FILE_MACHINE_I386 0x014c\r
// #define IMAGE_FILE_MACHINE_X64 0x8664\r
//\r
- UINT16 MachineType;\r
- PAGE_TABLE_LIB_PAGING_CONTEXT_DATA ContextData;\r
+ UINT16 MachineType;\r
+ PAGE_TABLE_LIB_PAGING_CONTEXT_DATA ContextData;\r
} PAGE_TABLE_LIB_PAGING_CONTEXT;\r
\r
+#define PAGE_TABLE_POOL_ALIGNMENT BASE_2MB\r
+#define PAGE_TABLE_POOL_UNIT_SIZE SIZE_2MB\r
+#define PAGE_TABLE_POOL_UNIT_PAGES EFI_SIZE_TO_PAGES (PAGE_TABLE_POOL_UNIT_SIZE)\r
+#define PAGE_TABLE_POOL_ALIGN_MASK \\r
+ (~(EFI_PHYSICAL_ADDRESS)(PAGE_TABLE_POOL_ALIGNMENT - 1))\r
+\r
+typedef struct {\r
+ VOID *NextPool;\r
+ UINTN Offset;\r
+ UINTN FreePages;\r
+} PAGE_TABLE_POOL;\r
+\r
/**\r
Allocates one or more 4KB pages for page table.\r
\r
**/\r
typedef\r
VOID *\r
-(EFIAPI *PAGE_TABLE_LIB_ALLOCATE_PAGES) (\r
+(EFIAPI *PAGE_TABLE_LIB_ALLOCATE_PAGES)(\r
IN UINTN Pages\r
);\r
\r
\r
Caller should make sure BaseAddress and Length is at page boundary.\r
\r
- Caller need guarentee the TPL <= TPL_NOTIFY, if there is split page request.\r
+ Caller need guarantee the TPL <= TPL_NOTIFY, if there is split page request.\r
\r
@param PagingContext The paging context. NULL means get page table from current CPU context.\r
@param BaseAddress The physical address that is the start address of a memory region.\r
RETURN_STATUS\r
EFIAPI\r
AssignMemoryPageAttributes (\r
- IN PAGE_TABLE_LIB_PAGING_CONTEXT *PagingContext OPTIONAL,\r
- IN PHYSICAL_ADDRESS BaseAddress,\r
- IN UINT64 Length,\r
- IN UINT64 Attributes,\r
- IN PAGE_TABLE_LIB_ALLOCATE_PAGES AllocatePagesFunc OPTIONAL\r
+ IN PAGE_TABLE_LIB_PAGING_CONTEXT *PagingContext OPTIONAL,\r
+ IN PHYSICAL_ADDRESS BaseAddress,\r
+ IN UINT64 Length,\r
+ IN UINT64 Attributes,\r
+ IN PAGE_TABLE_LIB_ALLOCATE_PAGES AllocatePagesFunc OPTIONAL\r
);\r
\r
/**\r
VOID\r
);\r
\r
+/**\r
+ This API provides a way to allocate memory for page table.\r
+\r
+ This API can be called more once to allocate memory for page tables.\r
+\r
+ Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r
+ allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r
+ is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r
+ returned.\r
+\r
+ @param Pages The number of 4 KB pages to allocate.\r
+\r
+ @return A pointer to the allocated buffer or NULL if allocation fails.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+AllocatePageTableMemory (\r
+ IN UINTN Pages\r
+ );\r
+\r
+/**\r
+ Get paging details.\r
+\r
+ @param PagingContextData The paging context.\r
+ @param PageTableBase Return PageTableBase field.\r
+ @param Attributes Return Attributes field.\r
+\r
+**/\r
+VOID\r
+GetPagingDetails (\r
+ IN PAGE_TABLE_LIB_PAGING_CONTEXT_DATA *PagingContextData,\r
+ OUT UINTN **PageTableBase OPTIONAL,\r
+ OUT UINT32 **Attributes OPTIONAL\r
+ );\r
+\r
#endif\r