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