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