--- /dev/null
+/** @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
+\r
+**/\r
+\r
+#ifndef _PAGE_TABLE_LIB_H_\r
+#define _PAGE_TABLE_LIB_H_\r
+\r
+#include <IndustryStandard/PeImage.h>\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_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
+} PAGE_TABLE_LIB_PAGING_CONTEXT_IA32;\r
+\r
+typedef struct {\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_DATA;\r
+\r
+typedef struct {\r
+ //\r
+ // PE32+ Machine type for EFI images\r
+ //\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
+} PAGE_TABLE_LIB_PAGING_CONTEXT;\r
+\r
+/**\r
+ Allocates one or more 4KB pages for page table.\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
+typedef\r
+VOID *\r
+(EFIAPI *PAGE_TABLE_LIB_ALLOCATE_PAGES) (\r
+ IN UINTN Pages\r
+ );\r
+\r
+/**\r
+ This function assigns the page attributes for the memory region specified by BaseAddress and\r
+ Length from their current attributes to the attributes specified by Attributes.\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
+\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
+ @param Length The size in bytes of the memory region.\r
+ @param Attributes The bit mask of attributes to set for the memory region.\r
+ @param AllocatePagesFunc If page split is needed, this function is used to allocate more pages.\r
+ NULL mean page split is unsupported.\r
+\r
+ @retval RETURN_SUCCESS The attributes were cleared for the memory region.\r
+ @retval RETURN_ACCESS_DENIED The attributes for the memory resource range specified by\r
+ BaseAddress and Length cannot be modified.\r
+ @retval RETURN_INVALID_PARAMETER Length is zero.\r
+ Attributes specified an illegal combination of attributes that\r
+ cannot be set together.\r
+ @retval RETURN_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r
+ the memory resource range.\r
+ @retval RETURN_UNSUPPORTED The processor does not support one or more bytes of the memory\r
+ resource range specified by BaseAddress and Length.\r
+ The bit mask of attributes is not support for the memory resource\r
+ range specified by BaseAddress and Length.\r
+**/\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
+ );\r
+\r
+/**\r
+ Initialize the Page Table lib.\r
+**/\r
+VOID\r
+InitializePageTableLib (\r
+ VOID\r
+ );\r
+\r
+#endif\r