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