]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c
OvmfPkg/BaseMemcryptSevLib: Add SEV helper library
[mirror_edk2.git] / OvmfPkg / Library / BaseMemEncryptSevLib / X64 / MemEncryptSevLib.c
CommitLineData
a1f22614
BS
1/** @file\r
2\r
3 Secure Encrypted Virtualization (SEV) library helper function\r
4\r
5 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>\r
6\r
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD\r
9 License which accompanies this distribution. The full text of the license may\r
10 be found at http://opensource.org/licenses/bsd-license.php\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include <Library/BaseLib.h>\r
18#include <Library/DebugLib.h>\r
19#include <Register/Cpuid.h>\r
20#include <Register/Amd/Cpuid.h>\r
21#include <Register/Amd/Msr.h>\r
22#include <Library/MemEncryptSevLib.h>\r
23\r
24#include "VirtualMemory.h"\r
25\r
26/**\r
27\r
28 This function clears memory encryption bit for the memory region specified by\r
29 BaseAddress and Number of pages from the current page table context.\r
30\r
31 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use current CR3)\r
32 @param[in] BaseAddress The physical address that is the start address\r
33 of a memory region.\r
34 @param[in] NumberOfPages The number of pages from start memory region.\r
35 @param[in] Flush Flush the caches before clearing the bit\r
36 (mostly TRUE except MMIO addresses)\r
37\r
38 @retval RETURN_SUCCESS The attributes were cleared for the memory\r
39 region.\r
40 @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r
41 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute is\r
42 not supported\r
43 **/\r
44RETURN_STATUS\r
45EFIAPI\r
46MemEncryptSevClearPageEncMask (\r
47 IN PHYSICAL_ADDRESS Cr3BaseAddress,\r
48 IN PHYSICAL_ADDRESS BaseAddress,\r
49 IN UINTN NumPages,\r
50 IN BOOLEAN Flush\r
51 )\r
52{\r
53 return InternalMemEncryptSevSetMemoryDecrypted (Cr3BaseAddress, BaseAddress, EFI_PAGES_TO_SIZE(NumPages), Flush);\r
54}\r
55\r
56/**\r
57\r
58 This function clears memory encryption bit for the memory region specified by\r
59 BaseAddress and Number of pages from the current page table context.\r
60\r
61 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use current CR3)\r
62 @param[in] BaseAddress The physical address that is the start address\r
63 of a memory region.\r
64 @param[in] NumberOfPages The number of pages from start memory region.\r
65 @param[in] Flush Flush the caches before clearing the bit\r
66 (mostly TRUE except MMIO addresses)\r
67\r
68 @retval RETURN_SUCCESS The attributes were cleared for the memory\r
69 region.\r
70 @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r
71 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute is\r
72 not supported\r
73 **/\r
74RETURN_STATUS\r
75EFIAPI\r
76MemEncryptSevSetPageEncMask (\r
77 IN PHYSICAL_ADDRESS Cr3BaseAddress,\r
78 IN PHYSICAL_ADDRESS BaseAddress,\r
79 IN UINTN NumPages,\r
80 IN BOOLEAN Flush\r
81 )\r
82{\r
83 return InternalMemEncryptSevSetMemoryEncrypted (Cr3BaseAddress, BaseAddress, EFI_PAGES_TO_SIZE(NumPages), Flush);\r
84}\r