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