]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / Library / BaseMemEncryptSevLib / X64 / VirtualMemory.h
CommitLineData
a1f22614
BS
1/** @file\r
2\r
3 Virtual Memory Management Services to set or clear the memory encryption bit\r
4\r
4bd6bf31 5 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>\r
c330af02 6 Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.<BR>\r
a1f22614 7\r
b26f0cf9 8 SPDX-License-Identifier: BSD-2-Clause-Patent\r
a1f22614 9\r
4bd6bf31 10 Code is derived from MdeModulePkg/Core/DxeIplPeim/X64/VirtualMemory.h\r
a1f22614
BS
11\r
12**/\r
13\r
14#ifndef __VIRTUAL_MEMORY__\r
15#define __VIRTUAL_MEMORY__\r
16\r
9d686149 17#include <IndustryStandard/PageTable.h>\r
a1f22614
BS
18#include <Library/BaseLib.h>\r
19#include <Library/BaseMemoryLib.h>\r
bd13ecf3 20#include <Library/CacheMaintenanceLib.h>\r
a1f22614
BS
21#include <Library/DebugLib.h>\r
22#include <Library/MemoryAllocationLib.h>\r
bd13ecf3 23#include <Uefi.h>\r
a1f22614 24\r
ac0a286f 25#define SYS_CODE64_SEL 0x38\r
a1f22614 26\r
ac0a286f
MK
27#define PAGE_TABLE_POOL_ALIGNMENT BASE_2MB\r
28#define PAGE_TABLE_POOL_UNIT_SIZE SIZE_2MB\r
4bd6bf31
LE
29#define PAGE_TABLE_POOL_UNIT_PAGES \\r
30 EFI_SIZE_TO_PAGES (PAGE_TABLE_POOL_UNIT_SIZE)\r
b721aa74
BS
31#define PAGE_TABLE_POOL_ALIGN_MASK \\r
32 (~(EFI_PHYSICAL_ADDRESS)(PAGE_TABLE_POOL_ALIGNMENT - 1))\r
33\r
34typedef struct {\r
ac0a286f
MK
35 VOID *NextPool;\r
36 UINTN Offset;\r
37 UINTN FreePages;\r
b721aa74
BS
38} PAGE_TABLE_POOL;\r
39\r
c330af02
TL
40/**\r
41 Return the pagetable memory encryption mask.\r
b721aa74 42\r
c330af02
TL
43 @return The pagetable memory encryption mask.\r
44\r
45**/\r
46UINT64\r
47EFIAPI\r
48InternalGetMemEncryptionAddressMask (\r
49 VOID\r
50 );\r
b721aa74 51\r
a1f22614 52/**\r
4bd6bf31 53 This function clears memory encryption bit for the memory region specified by\r
1532e5d5 54 PhysicalAddress and Length from the current page table context.\r
a1f22614 55\r
1532e5d5
LE
56 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r
57 current CR3)\r
4bd6bf31
LE
58 @param[in] PhysicalAddress The physical address that is the start\r
59 address of a memory region.\r
a1f22614 60 @param[in] Length The length of memory region\r
a1f22614 61\r
4bd6bf31
LE
62 @retval RETURN_SUCCESS The attributes were cleared for the\r
63 memory region.\r
a1f22614 64 @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r
1532e5d5 65 @retval RETURN_UNSUPPORTED Clearing the memory encyrption attribute\r
4bd6bf31 66 is not supported\r
a1f22614
BS
67**/\r
68RETURN_STATUS\r
69EFIAPI\r
70InternalMemEncryptSevSetMemoryDecrypted (\r
ac0a286f
MK
71 IN PHYSICAL_ADDRESS Cr3BaseAddress,\r
72 IN PHYSICAL_ADDRESS PhysicalAddress,\r
73 IN UINTN Length\r
a1f22614
BS
74 );\r
75\r
76/**\r
77 This function sets memory encryption bit for the memory region specified by\r
68e60a38 78 PhysicalAddress and Length from the current page table context.\r
a1f22614 79\r
68e60a38
LE
80 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r
81 current CR3)\r
4bd6bf31
LE
82 @param[in] PhysicalAddress The physical address that is the start\r
83 address of a memory region.\r
a1f22614 84 @param[in] Length The length of memory region\r
a1f22614 85\r
68e60a38
LE
86 @retval RETURN_SUCCESS The attributes were set for the memory\r
87 region.\r
a1f22614 88 @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r
4bd6bf31
LE
89 @retval RETURN_UNSUPPORTED Setting the memory encyrption attribute\r
90 is not supported\r
a1f22614
BS
91**/\r
92RETURN_STATUS\r
93EFIAPI\r
94InternalMemEncryptSevSetMemoryEncrypted (\r
ac0a286f
MK
95 IN PHYSICAL_ADDRESS Cr3BaseAddress,\r
96 IN PHYSICAL_ADDRESS PhysicalAddress,\r
97 IN UINTN Length\r
a1f22614
BS
98 );\r
99\r
c330af02
TL
100/**\r
101 Returns the encryption state of the specified virtual address range.\r
102\r
103 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r
104 current CR3)\r
105 @param[in] BaseAddress Base address to check\r
106 @param[in] Length Length of virtual address range\r
107\r
108 @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped\r
109 unencrypted\r
110 @retval MemEncryptSevAddressRangeEncrypted Address range is mapped\r
111 encrypted\r
112 @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed\r
113 @retval MemEncryptSevAddressRangeError Address range is not mapped\r
114**/\r
115MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE\r
116EFIAPI\r
117InternalMemEncryptSevGetAddressRangeState (\r
ac0a286f
MK
118 IN PHYSICAL_ADDRESS Cr3BaseAddress,\r
119 IN PHYSICAL_ADDRESS BaseAddress,\r
120 IN UINTN Length\r
c330af02
TL
121 );\r
122\r
901a9bfc
BS
123/**\r
124 This function clears memory encryption bit for the MMIO region specified by\r
125 PhysicalAddress and Length.\r
126\r
127 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r
128 current CR3)\r
129 @param[in] PhysicalAddress The physical address that is the start\r
130 address of a MMIO region.\r
131 @param[in] Length The length of memory region\r
132\r
133 @retval RETURN_SUCCESS The attributes were cleared for the\r
134 memory region.\r
135 @retval RETURN_INVALID_PARAMETER Length is zero.\r
136 @retval RETURN_UNSUPPORTED Clearing the memory encyrption attribute\r
137 is not supported\r
138**/\r
139RETURN_STATUS\r
140EFIAPI\r
141InternalMemEncryptSevClearMmioPageEncMask (\r
ac0a286f
MK
142 IN PHYSICAL_ADDRESS Cr3BaseAddress,\r
143 IN PHYSICAL_ADDRESS PhysicalAddress,\r
144 IN UINTN Length\r
901a9bfc 145 );\r
ac0a286f 146\r
a1f22614 147#endif\r