VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/UefiCpuPkg/Include/Library/CpuPageTableLib.h@ 105681

Last change on this file since 105681 was 105670, checked in by vboxsync, 9 months ago

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

  • Property svn:eol-style set to native
File size: 6.8 KB
Line 
1/** @file
2 Public include file for PageTableLib library.
3
4 Copyright (c) 2022 - 2023, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7**/
8
9#ifndef PAGE_TABLE_LIB_H_
10#define PAGE_TABLE_LIB_H_
11
12typedef union {
13 struct {
14 UINT32 Present : 1; // 0 = Not present in memory, 1 = Present in memory
15 UINT32 ReadWrite : 1; // 0 = Read-Only, 1= Read/Write
16 UINT32 UserSupervisor : 1; // 0 = Supervisor, 1=User
17 UINT32 WriteThrough : 1; // 0 = Write-Back caching, 1=Write-Through caching
18 UINT32 CacheDisabled : 1; // 0 = Cached, 1=Non-Cached
19 UINT32 Accessed : 1; // 0 = Not accessed, 1 = Accessed (set by CPU)
20 UINT32 Dirty : 1; // 0 = Not dirty, 1 = Dirty (set by CPU)
21 UINT32 Pat : 1; // PAT
22 UINT32 Global : 1; // 0 = Not global, 1 = Global (if CR4.PGE = 1)
23 UINT32 Reserved1 : 3; // Ignored
24 UINT32 PageTableBaseAddressLow : 20; // Page Table Base Address Low
25
26 UINT32 PageTableBaseAddressHigh : 20; // Page Table Base Address High
27 UINT32 Reserved2 : 7; // Ignored
28 UINT32 ProtectionKey : 4; // Protection key
29 UINT32 Nx : 1; // No Execute bit
30 } Bits;
31 UINT64 Uint64;
32} IA32_MAP_ATTRIBUTE;
33
34#define IA32_MAP_ATTRIBUTE_PAGE_TABLE_BASE_ADDRESS_MASK 0xFFFFFFFFFF000ull
35#define IA32_MAP_ATTRIBUTE_PAGE_TABLE_BASE_ADDRESS(pa) ((pa)->Uint64 & IA32_MAP_ATTRIBUTE_PAGE_TABLE_BASE_ADDRESS_MASK)
36#define IA32_MAP_ATTRIBUTE_ATTRIBUTES(pa) ((pa)->Uint64 & ~IA32_MAP_ATTRIBUTE_PAGE_TABLE_BASE_ADDRESS_MASK)
37
38//
39// Below enum follows "4.1.1 Four Paging Modes" in Chapter 4 Paging of SDM Volume 3.
40// Page1GB is only supported in 4-level and 5-level.
41//
42typedef enum {
43 Paging32bit,
44
45 //
46 // High byte in paging mode indicates the max levels of the page table.
47 // Low byte in paging mode indicates the max level that can be a leaf entry.
48 //
49 PagingPae4KB = 0x0301,
50 PagingPae2MB = 0x0302,
51 PagingPae = 0x0302,
52
53 Paging4Level4KB = 0x0401,
54 Paging4Level2MB = 0x0402,
55 Paging4Level = 0x0402,
56 Paging4Level1GB = 0x0403,
57
58 Paging5Level4KB = 0x0501,
59 Paging5Level2MB = 0x0502,
60 Paging5Level = 0x0502,
61 Paging5Level1GB = 0x0503,
62
63 PagingModeMax
64} PAGING_MODE;
65
66/**
67 Create or update page table to map [LinearAddress, LinearAddress + Length) with specified attribute.
68
69 @param[in, out] PageTable The pointer to the page table to update, or pointer to NULL if a new page table is to be created.
70 If not pointer to NULL, the value it points to won't be changed in this function.
71 @param[in] PagingMode The paging mode.
72 @param[in] Buffer The free buffer to be used for page table creation/updating.
73 @param[in, out] BufferSize The buffer size.
74 On return, the remaining buffer size.
75 The free buffer is used from the end so caller can supply the same Buffer pointer with an updated
76 BufferSize in the second call to this API.
77 @param[in] LinearAddress The start of the linear address range.
78 @param[in] Length The length of the linear address range.
79 @param[in] Attribute The attribute of the linear address range.
80 All non-reserved fields in IA32_MAP_ATTRIBUTE are supported to set in the page table.
81 Page table entries that map the linear address range are reset to 0 before set to the new attribute
82 when a new physical base address is set.
83 @param[in] Mask The mask used for attribute. The corresponding field in Attribute is ignored if that in Mask is 0.
84 @param[out] IsModified TRUE means page table is modified by software or hardware. FALSE means page table is not modified by software.
85 If the output IsModified is FALSE, there is possibility that the page table is changed by hardware. It is ok
86 because page table can be changed by hardware anytime, and caller don't need to Flush TLB.
87
88 @retval RETURN_UNSUPPORTED PagingMode is not supported.
89 @retval RETURN_INVALID_PARAMETER PageTable, BufferSize, Attribute or Mask is NULL.
90 @retval RETURN_INVALID_PARAMETER For non-present range, Mask->Bits.Present is 0 but some other attributes are provided.
91 @retval RETURN_INVALID_PARAMETER For non-present range, Mask->Bits.Present is 1, Attribute->Bits.Present is 1 but some other attributes are not provided.
92 @retval RETURN_INVALID_PARAMETER For non-present range, Mask->Bits.Present is 1, Attribute->Bits.Present is 0 but some other attributes are provided.
93 @retval RETURN_INVALID_PARAMETER For present range, Mask->Bits.Present is 1, Attribute->Bits.Present is 0 but some other attributes are provided.
94 @retval RETURN_INVALID_PARAMETER *BufferSize is not multiple of 4KB.
95 @retval RETURN_BUFFER_TOO_SMALL The buffer is too small for page table creation/updating.
96 BufferSize is updated to indicate the expected buffer size.
97 Caller may still get RETURN_BUFFER_TOO_SMALL with the new BufferSize.
98 @retval RETURN_SUCCESS PageTable is created/updated successfully or the input Length is 0.
99**/
100RETURN_STATUS
101EFIAPI
102PageTableMap (
103 IN OUT UINTN *PageTable OPTIONAL,
104 IN PAGING_MODE PagingMode,
105 IN VOID *Buffer,
106 IN OUT UINTN *BufferSize,
107 IN UINT64 LinearAddress,
108 IN UINT64 Length,
109 IN IA32_MAP_ATTRIBUTE *Attribute,
110 IN IA32_MAP_ATTRIBUTE *Mask,
111 OUT BOOLEAN *IsModified OPTIONAL
112 );
113
114typedef struct {
115 UINT64 LinearAddress;
116 UINT64 Length;
117 IA32_MAP_ATTRIBUTE Attribute;
118} IA32_MAP_ENTRY;
119
120/**
121 Parse page table.
122
123 @param[in] PageTable Pointer to the page table.
124 @param[in] PagingMode The paging mode.
125 @param[out] Map Return an array that describes multiple linear address ranges.
126 @param[in, out] MapCount On input, the maximum number of entries that Map can hold.
127 On output, the number of entries in Map.
128
129 @retval RETURN_UNSUPPORTED PageLevel is not 5 or 4.
130 @retval RETURN_INVALID_PARAMETER MapCount is NULL.
131 @retval RETURN_INVALID_PARAMETER *MapCount is not 0 but Map is NULL.
132 @retval RETURN_BUFFER_TOO_SMALL *MapCount is too small.
133 @retval RETURN_SUCCESS Page table is parsed successfully.
134**/
135RETURN_STATUS
136EFIAPI
137PageTableParse (
138 IN UINTN PageTable,
139 IN PAGING_MODE PagingMode,
140 IN IA32_MAP_ENTRY *Map,
141 IN OUT UINTN *MapCount
142 );
143
144#endif
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette