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