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