]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/CpuDxe/CpuPageTable.h
UefiCpuPkg/CpuDxe: Add memory attribute setting.
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuPageTable.h
CommitLineData
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
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#ifndef _PAGE_TABLE_LIB_H_\r
16#define _PAGE_TABLE_LIB_H_\r
17\r
18#include <IndustryStandard/PeImage.h>\r
19\r
20#define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_PSE BIT0\r
21#define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_PAE BIT1\r
22#define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_PAGE_1G_SUPPORT BIT2\r
23#define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_WP_ENABLE BIT30\r
24#define PAGE_TABLE_LIB_PAGING_CONTEXT_IA32_X64_ATTRIBUTES_XD_ACTIVATED BIT31\r
25// Other bits are reserved for future use\r
26typedef struct {\r
27 UINT32 PageTableBase;\r
28 UINT32 Reserved;\r
29 UINT32 Attributes;\r
30} PAGE_TABLE_LIB_PAGING_CONTEXT_IA32;\r
31\r
32typedef struct {\r
33 UINT64 PageTableBase;\r
34 UINT32 Attributes;\r
35} PAGE_TABLE_LIB_PAGING_CONTEXT_X64;\r
36\r
37typedef union {\r
38 PAGE_TABLE_LIB_PAGING_CONTEXT_IA32 Ia32;\r
39 PAGE_TABLE_LIB_PAGING_CONTEXT_X64 X64;\r
40} PAGE_TABLE_LIB_PAGING_CONTEXT_DATA;\r
41\r
42typedef struct {\r
43 //\r
44 // PE32+ Machine type for EFI images\r
45 //\r
46 // #define IMAGE_FILE_MACHINE_I386 0x014c\r
47 // #define IMAGE_FILE_MACHINE_X64 0x8664\r
48 //\r
49 UINT16 MachineType;\r
50 PAGE_TABLE_LIB_PAGING_CONTEXT_DATA ContextData;\r
51} PAGE_TABLE_LIB_PAGING_CONTEXT;\r
52\r
53/**\r
54 Allocates one or more 4KB pages for page table.\r
55\r
56 @param Pages The number of 4 KB pages to allocate.\r
57\r
58 @return A pointer to the allocated buffer or NULL if allocation fails.\r
59\r
60**/\r
61typedef\r
62VOID *\r
63(EFIAPI *PAGE_TABLE_LIB_ALLOCATE_PAGES) (\r
64 IN UINTN Pages\r
65 );\r
66\r
67/**\r
68 This function assigns the page attributes for the memory region specified by BaseAddress and\r
69 Length from their current attributes to the attributes specified by Attributes.\r
70\r
71 Caller should make sure BaseAddress and Length is at page boundary.\r
72\r
73 Caller need guarentee the TPL <= TPL_NOTIFY, if there is split page request.\r
74\r
75 @param PagingContext The paging context. NULL means get page table from current CPU context.\r
76 @param BaseAddress The physical address that is the start address of a memory region.\r
77 @param Length The size in bytes of the memory region.\r
78 @param Attributes The bit mask of attributes to set for the memory region.\r
79 @param AllocatePagesFunc If page split is needed, this function is used to allocate more pages.\r
80 NULL mean page split is unsupported.\r
81\r
82 @retval RETURN_SUCCESS The attributes were cleared for the memory region.\r
83 @retval RETURN_ACCESS_DENIED The attributes for the memory resource range specified by\r
84 BaseAddress and Length cannot be modified.\r
85 @retval RETURN_INVALID_PARAMETER Length is zero.\r
86 Attributes specified an illegal combination of attributes that\r
87 cannot be set together.\r
88 @retval RETURN_OUT_OF_RESOURCES There are not enough system resources to modify the attributes of\r
89 the memory resource range.\r
90 @retval RETURN_UNSUPPORTED The processor does not support one or more bytes of the memory\r
91 resource range specified by BaseAddress and Length.\r
92 The bit mask of attributes is not support for the memory resource\r
93 range specified by BaseAddress and Length.\r
94**/\r
95RETURN_STATUS\r
96EFIAPI\r
97AssignMemoryPageAttributes (\r
98 IN PAGE_TABLE_LIB_PAGING_CONTEXT *PagingContext OPTIONAL,\r
99 IN PHYSICAL_ADDRESS BaseAddress,\r
100 IN UINT64 Length,\r
101 IN UINT64 Attributes,\r
102 IN PAGE_TABLE_LIB_ALLOCATE_PAGES AllocatePagesFunc OPTIONAL\r
103 );\r
104\r
105/**\r
106 Initialize the Page Table lib.\r
107**/\r
108VOID\r
109InitializePageTableLib (\r
110 VOID\r
111 );\r
112\r
113#endif\r