]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/CpuDxe/CpuPageTable.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuPageTable.h
CommitLineData
22292ed3
JY
1/** @file\r
2 Page table management header file.\r
3\r
e58aa474 4 Copyright (c) 2017 - 2019, 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
e58aa474 17#define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_5_LEVEL BIT3\r
22292ed3
JY
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
21typedef struct {\r
053e878b
MK
22 UINT32 PageTableBase;\r
23 UINT32 Reserved;\r
24 UINT32 Attributes;\r
22292ed3
JY
25} PAGE_TABLE_LIB_PAGING_CONTEXT_IA32;\r
26\r
27typedef struct {\r
053e878b
MK
28 UINT64 PageTableBase;\r
29 UINT32 Attributes;\r
22292ed3
JY
30} PAGE_TABLE_LIB_PAGING_CONTEXT_X64;\r
31\r
32typedef union {\r
053e878b
MK
33 PAGE_TABLE_LIB_PAGING_CONTEXT_IA32 Ia32;\r
34 PAGE_TABLE_LIB_PAGING_CONTEXT_X64 X64;\r
22292ed3
JY
35} PAGE_TABLE_LIB_PAGING_CONTEXT_DATA;\r
36\r
37typedef 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
053e878b
MK
44 UINT16 MachineType;\r
45 PAGE_TABLE_LIB_PAGING_CONTEXT_DATA ContextData;\r
22292ed3
JY
46} PAGE_TABLE_LIB_PAGING_CONTEXT;\r
47\r
147fd35c
JW
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
54typedef struct {\r
053e878b
MK
55 VOID *NextPool;\r
56 UINTN Offset;\r
57 UINTN FreePages;\r
147fd35c
JW
58} PAGE_TABLE_POOL;\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
68typedef\r
69VOID *\r
053e878b 70(EFIAPI *PAGE_TABLE_LIB_ALLOCATE_PAGES)(\r
22292ed3
JY
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
f60f4cfe 80 Caller need guarantee the TPL <= TPL_NOTIFY, if there is split page request.\r
22292ed3
JY
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
102RETURN_STATUS\r
103EFIAPI\r
104AssignMemoryPageAttributes (\r
053e878b
MK
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
22292ed3
JY
110 );\r
111\r
112/**\r
113 Initialize the Page Table lib.\r
114**/\r
115VOID\r
116InitializePageTableLib (\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
135VOID *\r
136EFIAPI\r
137AllocatePageTableMemory (\r
053e878b 138 IN UINTN Pages\r
147fd35c
JW
139 );\r
140\r
c70fef96
ED
141/**\r
142 Get paging details.\r
143\r
144 @param PagingContextData The paging context.\r
145 @param PageTableBase Return PageTableBase field.\r
146 @param Attributes Return Attributes field.\r
147\r
148**/\r
149VOID\r
150GetPagingDetails (\r
053e878b
MK
151 IN PAGE_TABLE_LIB_PAGING_CONTEXT_DATA *PagingContextData,\r
152 OUT UINTN **PageTableBase OPTIONAL,\r
153 OUT UINT32 **Attributes OPTIONAL\r
c70fef96
ED
154 );\r
155\r
22292ed3 156#endif\r