]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/BaseMemEncryptSevLib/X64/MemEncryptSevLib.c
OvmfPkg/BaseMemcryptSevLib: Add SEV helper library
[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
8 are licensed and made available under the terms and conditions of the BSD
9 License which accompanies this distribution. The full text of the license may
10 be found at 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 current CR3)
32 @param[in] BaseAddress The physical address that is the start address
33 of a memory region.
34 @param[in] NumberOfPages The number of pages from start memory region.
35 @param[in] Flush Flush the caches before clearing the bit
36 (mostly TRUE except MMIO addresses)
37
38 @retval RETURN_SUCCESS The attributes were cleared for the memory
39 region.
40 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
41 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute is
42 not supported
43 **/
44 RETURN_STATUS
45 EFIAPI
46 MemEncryptSevClearPageEncMask (
47 IN PHYSICAL_ADDRESS Cr3BaseAddress,
48 IN PHYSICAL_ADDRESS BaseAddress,
49 IN UINTN NumPages,
50 IN BOOLEAN Flush
51 )
52 {
53 return InternalMemEncryptSevSetMemoryDecrypted (Cr3BaseAddress, BaseAddress, EFI_PAGES_TO_SIZE(NumPages), Flush);
54 }
55
56 /**
57
58 This function clears memory encryption bit for the memory region specified by
59 BaseAddress and Number of pages from the current page table context.
60
61 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use current CR3)
62 @param[in] BaseAddress The physical address that is the start address
63 of a memory region.
64 @param[in] NumberOfPages The number of pages from start memory region.
65 @param[in] Flush Flush the caches before clearing the bit
66 (mostly TRUE except MMIO addresses)
67
68 @retval RETURN_SUCCESS The attributes were cleared for the memory
69 region.
70 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
71 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute is
72 not supported
73 **/
74 RETURN_STATUS
75 EFIAPI
76 MemEncryptSevSetPageEncMask (
77 IN PHYSICAL_ADDRESS Cr3BaseAddress,
78 IN PHYSICAL_ADDRESS BaseAddress,
79 IN UINTN NumPages,
80 IN BOOLEAN Flush
81 )
82 {
83 return InternalMemEncryptSevSetMemoryEncrypted (Cr3BaseAddress, BaseAddress, EFI_PAGES_TO_SIZE(NumPages), Flush);
84 }