]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Page table management header file.\r | |
3 | \r | |
4 | Copyright (c) 2017 - 2019, Intel Corporation. All rights reserved.<BR>\r | |
5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | \r | |
7 | **/\r | |
8 | \r | |
9 | #ifndef _PAGE_TABLE_LIB_H_\r | |
10 | #define _PAGE_TABLE_LIB_H_\r | |
11 | \r | |
12 | #include <IndustryStandard/PeImage.h>\r | |
13 | \r | |
14 | #define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_PSE BIT0\r | |
15 | #define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_PAE BIT1\r | |
16 | #define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_PAGE_1G_SUPPORT BIT2\r | |
17 | #define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_5_LEVEL BIT3\r | |
18 | #define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_WP_ENABLE BIT30\r | |
19 | #define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_XD_ACTIVATED BIT31\r | |
20 | // Other bits are reserved for future use\r | |
21 | typedef struct {\r | |
22 | UINT32 PageTableBase;\r | |
23 | UINT32 Reserved;\r | |
24 | UINT32 Attributes;\r | |
25 | } PAGE_TABLE_LIB_PAGING_CONTEXT_IA32;\r | |
26 | \r | |
27 | typedef struct {\r | |
28 | UINT64 PageTableBase;\r | |
29 | UINT32 Attributes;\r | |
30 | } PAGE_TABLE_LIB_PAGING_CONTEXT_X64;\r | |
31 | \r | |
32 | typedef union {\r | |
33 | PAGE_TABLE_LIB_PAGING_CONTEXT_IA32 Ia32;\r | |
34 | PAGE_TABLE_LIB_PAGING_CONTEXT_X64 X64;\r | |
35 | } PAGE_TABLE_LIB_PAGING_CONTEXT_DATA;\r | |
36 | \r | |
37 | typedef struct {\r | |
38 | //\r | |
39 | // PE32+ Machine type for EFI images\r | |
40 | //\r | |
41 | // #define IMAGE_FILE_MACHINE_I386 0x014c\r | |
42 | // #define IMAGE_FILE_MACHINE_X64 0x8664\r | |
43 | //\r | |
44 | UINT16 MachineType;\r | |
45 | PAGE_TABLE_LIB_PAGING_CONTEXT_DATA ContextData;\r | |
46 | } PAGE_TABLE_LIB_PAGING_CONTEXT;\r | |
47 | \r | |
48 | #define PAGE_TABLE_POOL_ALIGNMENT BASE_2MB\r | |
49 | #define PAGE_TABLE_POOL_UNIT_SIZE SIZE_2MB\r | |
50 | #define PAGE_TABLE_POOL_UNIT_PAGES EFI_SIZE_TO_PAGES (PAGE_TABLE_POOL_UNIT_SIZE)\r | |
51 | #define PAGE_TABLE_POOL_ALIGN_MASK \\r | |
52 | (~(EFI_PHYSICAL_ADDRESS)(PAGE_TABLE_POOL_ALIGNMENT - 1))\r | |
53 | \r | |
54 | typedef struct {\r | |
55 | VOID *NextPool;\r | |
56 | UINTN Offset;\r | |
57 | UINTN FreePages;\r | |
58 | } PAGE_TABLE_POOL;\r | |
59 | \r | |
60 | \r | |
61 | /**\r | |
62 | Allocates one or more 4KB pages for page table.\r | |
63 | \r | |
64 | @param Pages The number of 4 KB pages to allocate.\r | |
65 | \r | |
66 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
67 | \r | |
68 | **/\r | |
69 | typedef\r | |
70 | VOID *\r | |
71 | (EFIAPI *PAGE_TABLE_LIB_ALLOCATE_PAGES) (\r | |
72 | IN UINTN Pages\r | |
73 | );\r | |
74 | \r | |
75 | /**\r | |
76 | This function assigns the page attributes for the memory region specified by BaseAddress and\r | |
77 | Length from their current attributes to the attributes specified by Attributes.\r | |
78 | \r | |
79 | Caller should make sure BaseAddress and Length is at page boundary.\r | |
80 | \r | |
81 | Caller need guarentee the TPL <= TPL_NOTIFY, if there is split page request.\r | |
82 | \r | |
83 | @param PagingContext The paging context. NULL means get page table from current CPU context.\r | |
84 | @param BaseAddress The physical address that is the start address of a memory region.\r | |
85 | @param Length The size in bytes of the memory region.\r | |
86 | @param Attributes The bit mask of attributes to set for the memory region.\r | |
87 | @param AllocatePagesFunc If page split is needed, this function is used to allocate more pages.\r | |
88 | NULL mean page split is unsupported.\r | |
89 | \r | |
90 | @retval RETURN_SUCCESS The attributes were cleared for the memory region.\r | |
91 | @retval RETURN_ACCESS_DENIED The attributes for the memory resource range specified by\r | |
92 | BaseAddress and Length cannot be modified.\r | |
93 | @retval RETURN_INVALID_PARAMETER Length is zero.\r | |
94 | Attributes specified an illegal combination of attributes that\r | |
95 | cannot be set together.\r | |
96 | @retval RETURN_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r | |
97 | the memory resource range.\r | |
98 | @retval RETURN_UNSUPPORTED The processor does not support one or more bytes of the memory\r | |
99 | resource range specified by BaseAddress and Length.\r | |
100 | The bit mask of attributes is not support for the memory resource\r | |
101 | range specified by BaseAddress and Length.\r | |
102 | **/\r | |
103 | RETURN_STATUS\r | |
104 | EFIAPI\r | |
105 | AssignMemoryPageAttributes (\r | |
106 | IN PAGE_TABLE_LIB_PAGING_CONTEXT *PagingContext OPTIONAL,\r | |
107 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
108 | IN UINT64 Length,\r | |
109 | IN UINT64 Attributes,\r | |
110 | IN PAGE_TABLE_LIB_ALLOCATE_PAGES AllocatePagesFunc OPTIONAL\r | |
111 | );\r | |
112 | \r | |
113 | /**\r | |
114 | Initialize the Page Table lib.\r | |
115 | **/\r | |
116 | VOID\r | |
117 | InitializePageTableLib (\r | |
118 | VOID\r | |
119 | );\r | |
120 | \r | |
121 | /**\r | |
122 | This API provides a way to allocate memory for page table.\r | |
123 | \r | |
124 | This API can be called more once to allocate memory for page tables.\r | |
125 | \r | |
126 | Allocates the number of 4KB pages of type EfiRuntimeServicesData and returns a pointer to the\r | |
127 | allocated buffer. The buffer returned is aligned on a 4KB boundary. If Pages is 0, then NULL\r | |
128 | is returned. If there is not enough memory remaining to satisfy the request, then NULL is\r | |
129 | returned.\r | |
130 | \r | |
131 | @param Pages The number of 4 KB pages to allocate.\r | |
132 | \r | |
133 | @return A pointer to the allocated buffer or NULL if allocation fails.\r | |
134 | \r | |
135 | **/\r | |
136 | VOID *\r | |
137 | EFIAPI\r | |
138 | AllocatePageTableMemory (\r | |
139 | IN UINTN Pages\r | |
140 | );\r | |
141 | \r | |
142 | #endif\r |