]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/BaseMemEncryptSevLib/X64/VirtualMemory.h
OvmfPkg/BaseMemEncryptSevLib: introduce MemEncryptSevClearMmioPageEncMask()
[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 @param[in] Flush Flush the caches before applying the
62 encryption mask
63
64 @retval RETURN_SUCCESS The attributes were cleared for the
65 memory region.
66 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
67 @retval RETURN_UNSUPPORTED Clearing the memory encyrption attribute
68 is not supported
69 **/
70 RETURN_STATUS
71 EFIAPI
72 InternalMemEncryptSevSetMemoryDecrypted (
73 IN PHYSICAL_ADDRESS Cr3BaseAddress,
74 IN PHYSICAL_ADDRESS PhysicalAddress,
75 IN UINTN Length,
76 IN BOOLEAN Flush
77 );
78
79 /**
80 This function sets memory encryption bit for the memory region specified by
81 PhysicalAddress and Length from the current page table context.
82
83 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
84 current CR3)
85 @param[in] PhysicalAddress The physical address that is the start
86 address of a memory region.
87 @param[in] Length The length of memory region
88 @param[in] Flush Flush the caches before applying the
89 encryption mask
90
91 @retval RETURN_SUCCESS The attributes were set for the memory
92 region.
93 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
94 @retval RETURN_UNSUPPORTED Setting the memory encyrption attribute
95 is not supported
96 **/
97 RETURN_STATUS
98 EFIAPI
99 InternalMemEncryptSevSetMemoryEncrypted (
100 IN PHYSICAL_ADDRESS Cr3BaseAddress,
101 IN PHYSICAL_ADDRESS PhysicalAddress,
102 IN UINTN Length,
103 IN BOOLEAN Flush
104 );
105
106 /**
107 Returns the encryption state of the specified virtual address range.
108
109 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
110 current CR3)
111 @param[in] BaseAddress Base address to check
112 @param[in] Length Length of virtual address range
113
114 @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped
115 unencrypted
116 @retval MemEncryptSevAddressRangeEncrypted Address range is mapped
117 encrypted
118 @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed
119 @retval MemEncryptSevAddressRangeError Address range is not mapped
120 **/
121 MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE
122 EFIAPI
123 InternalMemEncryptSevGetAddressRangeState (
124 IN PHYSICAL_ADDRESS Cr3BaseAddress,
125 IN PHYSICAL_ADDRESS BaseAddress,
126 IN UINTN Length
127 );
128
129 /**
130 This function clears memory encryption bit for the MMIO region specified by
131 PhysicalAddress and Length.
132
133 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
134 current CR3)
135 @param[in] PhysicalAddress The physical address that is the start
136 address of a MMIO region.
137 @param[in] Length The length of memory region
138
139 @retval RETURN_SUCCESS The attributes were cleared for the
140 memory region.
141 @retval RETURN_INVALID_PARAMETER Length is zero.
142 @retval RETURN_UNSUPPORTED Clearing the memory encyrption attribute
143 is not supported
144 **/
145 RETURN_STATUS
146 EFIAPI
147 InternalMemEncryptSevClearMmioPageEncMask (
148 IN PHYSICAL_ADDRESS Cr3BaseAddress,
149 IN PHYSICAL_ADDRESS PhysicalAddress,
150 IN UINTN Length
151 );
152 #endif