Commit | Line | Data |
---|---|---|
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 | |
4bd6bf31 LE |
7 | This program and the accompanying materials are licensed and made available\r |
8 | under the terms and conditions of the BSD License which accompanies this\r | |
9 | distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
a1f22614 BS |
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 | |
4bd6bf31 LE |
31 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r |
32 | current CR3)\r | |
33 | @param[in] BaseAddress The physical address that is the start\r | |
34 | address of a memory region.\r | |
35 | @param[in] NumberOfPages The number of pages from start memory\r | |
36 | region.\r | |
a1f22614 BS |
37 | @param[in] Flush Flush the caches before clearing the bit\r |
38 | (mostly TRUE except MMIO addresses)\r | |
39 | \r | |
4bd6bf31 LE |
40 | @retval RETURN_SUCCESS The attributes were cleared for the\r |
41 | memory region.\r | |
a1f22614 | 42 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r |
4bd6bf31 LE |
43 | @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute\r |
44 | is not supported\r | |
a1f22614 BS |
45 | **/\r |
46 | RETURN_STATUS\r | |
47 | EFIAPI\r | |
48 | MemEncryptSevClearPageEncMask (\r | |
49 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r | |
50 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
51 | IN UINTN NumPages,\r | |
52 | IN BOOLEAN Flush\r | |
53 | )\r | |
54 | {\r | |
4bd6bf31 LE |
55 | return InternalMemEncryptSevSetMemoryDecrypted (\r |
56 | Cr3BaseAddress,\r | |
57 | BaseAddress,\r | |
58 | EFI_PAGES_TO_SIZE (NumPages),\r | |
59 | Flush\r | |
60 | );\r | |
a1f22614 BS |
61 | }\r |
62 | \r | |
63 | /**\r | |
64 | \r | |
65 | This function clears memory encryption bit for the memory region specified by\r | |
66 | BaseAddress and Number of pages from the current page table context.\r | |
67 | \r | |
4bd6bf31 LE |
68 | @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use\r |
69 | current CR3)\r | |
70 | @param[in] BaseAddress The physical address that is the start\r | |
71 | address of a memory region.\r | |
72 | @param[in] NumberOfPages The number of pages from start memory\r | |
73 | region.\r | |
a1f22614 BS |
74 | @param[in] Flush Flush the caches before clearing the bit\r |
75 | (mostly TRUE except MMIO addresses)\r | |
76 | \r | |
4bd6bf31 LE |
77 | @retval RETURN_SUCCESS The attributes were cleared for the\r |
78 | memory region.\r | |
a1f22614 | 79 | @retval RETURN_INVALID_PARAMETER Number of pages is zero.\r |
4bd6bf31 LE |
80 | @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute\r |
81 | is not supported\r | |
a1f22614 BS |
82 | **/\r |
83 | RETURN_STATUS\r | |
84 | EFIAPI\r | |
85 | MemEncryptSevSetPageEncMask (\r | |
86 | IN PHYSICAL_ADDRESS Cr3BaseAddress,\r | |
87 | IN PHYSICAL_ADDRESS BaseAddress,\r | |
88 | IN UINTN NumPages,\r | |
89 | IN BOOLEAN Flush\r | |
90 | )\r | |
91 | {\r | |
4bd6bf31 LE |
92 | return InternalMemEncryptSevSetMemoryEncrypted (\r |
93 | Cr3BaseAddress,\r | |
94 | BaseAddress,\r | |
95 | EFI_PAGES_TO_SIZE (NumPages),\r | |
96 | Flush\r | |
97 | );\r | |
a1f22614 | 98 | }\r |