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