]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c
OvmfPkg: Replace BSD License with BSD+Patent License
[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
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#include "VirtualMemory.h"\r
19\r
20/**\r
a1f22614 21 This function clears memory encryption bit for the memory region specified by\r
5b5028e6 22 BaseAddress and NumPages from the current page table context.\r
a1f22614 23\r
4bd6bf31
LE
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
5b5028e6 28 @param[in] NumPages The number of pages from start memory\r
4bd6bf31 29 region.\r
a1f22614
BS
30 @param[in] Flush Flush the caches before clearing the bit\r
31 (mostly TRUE except MMIO addresses)\r
32\r
4bd6bf31
LE
33 @retval RETURN_SUCCESS The attributes were cleared for the\r
34 memory region.\r
a1f22614 35 @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r
4bd6bf31
LE
36 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute\r
37 is not supported\r
5b5028e6 38**/\r
a1f22614
BS
39RETURN_STATUS\r
40EFIAPI\r
41MemEncryptSevClearPageEncMask (\r
42 IN PHYSICAL_ADDRESS Cr3BaseAddress,\r
43 IN PHYSICAL_ADDRESS BaseAddress,\r
44 IN UINTN NumPages,\r
45 IN BOOLEAN Flush\r
46 )\r
47{\r
4bd6bf31
LE
48 return InternalMemEncryptSevSetMemoryDecrypted (\r
49 Cr3BaseAddress,\r
50 BaseAddress,\r
51 EFI_PAGES_TO_SIZE (NumPages),\r
52 Flush\r
53 );\r
a1f22614
BS
54}\r
55\r
56/**\r
154dcd6c
LE
57 This function sets memory encryption bit for the memory region specified by\r
58 BaseAddress and NumPages from the current page table context.\r
a1f22614 59\r
4bd6bf31
LE
60 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r
61 current CR3)\r
62 @param[in] BaseAddress The physical address that is the start\r
63 address of a memory region.\r
154dcd6c 64 @param[in] NumPages The number of pages from start memory\r
4bd6bf31 65 region.\r
154dcd6c 66 @param[in] Flush Flush the caches before setting the bit\r
a1f22614
BS
67 (mostly TRUE except MMIO addresses)\r
68\r
154dcd6c
LE
69 @retval RETURN_SUCCESS The attributes were set for the memory\r
70 region.\r
a1f22614 71 @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r
154dcd6c 72 @retval RETURN_UNSUPPORTED Setting the memory encryption attribute\r
4bd6bf31 73 is not supported\r
154dcd6c 74**/\r
a1f22614
BS
75RETURN_STATUS\r
76EFIAPI\r
77MemEncryptSevSetPageEncMask (\r
78 IN PHYSICAL_ADDRESS Cr3BaseAddress,\r
79 IN PHYSICAL_ADDRESS BaseAddress,\r
80 IN UINTN NumPages,\r
81 IN BOOLEAN Flush\r
82 )\r
83{\r
4bd6bf31
LE
84 return InternalMemEncryptSevSetMemoryEncrypted (\r
85 Cr3BaseAddress,\r
86 BaseAddress,\r
87 EFI_PAGES_TO_SIZE (NumPages),\r
88 Flush\r
89 );\r
a1f22614 90}\r