]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c
OvmfPkg/MemEncryptSevLib: add support to validate system RAM
[mirror_edk2.git] / OvmfPkg / Library / BaseMemEncryptSevLib / Ia32 / MemEncryptSevLib.c
1 /** @file
2
3 Secure Encrypted Virtualization (SEV) library helper function
4
5 Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include <Library/BaseLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/MemEncryptSevLib.h>
14 #include <Register/Amd/Cpuid.h>
15 #include <Register/Amd/Msr.h>
16 #include <Register/Cpuid.h>
17
18 /**
19 This function clears memory encryption bit for the memory region specified by
20 BaseAddress and NumPages from the current page table context.
21
22 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
23 current CR3)
24 @param[in] BaseAddress The physical address that is the start
25 address of a memory region.
26 @param[in] NumPages The number of pages from start memory
27 region.
28
29 @retval RETURN_SUCCESS The attributes were cleared for the
30 memory region.
31 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
32 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute
33 is not supported
34 **/
35 RETURN_STATUS
36 EFIAPI
37 MemEncryptSevClearPageEncMask (
38 IN PHYSICAL_ADDRESS Cr3BaseAddress,
39 IN PHYSICAL_ADDRESS BaseAddress,
40 IN UINTN NumPages
41 )
42 {
43 //
44 // Memory encryption bit is not accessible in 32-bit mode
45 //
46 return RETURN_UNSUPPORTED;
47 }
48
49 /**
50 This function sets memory encryption bit for the memory region specified by
51 BaseAddress and NumPages from the current page table context.
52
53 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
54 current CR3)
55 @param[in] BaseAddress The physical address that is the start
56 address of a memory region.
57 @param[in] NumPages The number of pages from start memory
58 region.
59
60 @retval RETURN_SUCCESS The attributes were set for the memory
61 region.
62 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
63 @retval RETURN_UNSUPPORTED Setting the memory encryption attribute
64 is not supported
65 **/
66 RETURN_STATUS
67 EFIAPI
68 MemEncryptSevSetPageEncMask (
69 IN PHYSICAL_ADDRESS Cr3BaseAddress,
70 IN PHYSICAL_ADDRESS BaseAddress,
71 IN UINTN NumPages
72 )
73 {
74 //
75 // Memory encryption bit is not accessible in 32-bit mode
76 //
77 return RETURN_UNSUPPORTED;
78 }
79
80 /**
81 Returns the encryption state of the specified virtual address range.
82
83 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
84 current CR3)
85 @param[in] BaseAddress Base address to check
86 @param[in] Length Length of virtual address range
87
88 @retval MemEncryptSevAddressRangeUnencrypted Address range is mapped
89 unencrypted
90 @retval MemEncryptSevAddressRangeEncrypted Address range is mapped
91 encrypted
92 @retval MemEncryptSevAddressRangeMixed Address range is mapped mixed
93 @retval MemEncryptSevAddressRangeError Address range is not mapped
94 **/
95 MEM_ENCRYPT_SEV_ADDRESS_RANGE_STATE
96 EFIAPI
97 MemEncryptSevGetAddressRangeState (
98 IN PHYSICAL_ADDRESS Cr3BaseAddress,
99 IN PHYSICAL_ADDRESS BaseAddress,
100 IN UINTN Length
101 )
102 {
103 //
104 // Memory is always encrypted in 32-bit mode
105 //
106 return MemEncryptSevAddressRangeEncrypted;
107 }
108
109 /**
110 This function clears memory encryption bit for the MMIO region specified by
111 BaseAddress and NumPages.
112
113 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
114 current CR3)
115 @param[in] BaseAddress The physical address that is the start
116 address of a MMIO region.
117 @param[in] NumPages The number of pages from start memory
118 region.
119
120 @retval RETURN_SUCCESS The attributes were cleared for the
121 memory region.
122 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
123 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute
124 is not supported
125 **/
126 RETURN_STATUS
127 EFIAPI
128 MemEncryptSevClearMmioPageEncMask (
129 IN PHYSICAL_ADDRESS Cr3BaseAddress,
130 IN PHYSICAL_ADDRESS BaseAddress,
131 IN UINTN NumPages
132 )
133 {
134 //
135 // Memory encryption bit is not accessible in 32-bit mode
136 //
137 return RETURN_UNSUPPORTED;
138 }
139
140 /**
141 Pre-validate the system RAM when SEV-SNP is enabled in the guest VM.
142
143 @param[in] BaseAddress Base address
144 @param[in] NumPages Number of pages starting from the base address
145
146 **/
147 VOID
148 EFIAPI
149 MemEncryptSevSnpPreValidateSystemRam (
150 IN PHYSICAL_ADDRESS BaseAddress,
151 IN UINTN NumPages
152 )
153 {
154 ASSERT (FALSE);
155 }