]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/BaseMemEncryptSevLib/Ia32/MemEncryptSevLib.c
OvmfPkg/BaseMemcryptSevLib: Add SEV helper library
[mirror_edk2.git] / OvmfPkg / Library / BaseMemEncryptSevLib / Ia32 / 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 /**
25 This function clears memory encryption bit for the memory region specified
26 by BaseAddress and Number of pages from the current page table context.
27
28 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use current CR3)
29 @param[in] BaseAddress The physical address that is the start address
30 of a memory region.
31 @param[in] NumberOfPages The number of pages from start memory region.
32 @param[in] Flush Flush the caches before clearing the bit
33 (mostly TRUE except MMIO addresses)
34
35 @retval RETURN_SUCCESS The attributes were cleared for the memory region.
36 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
37 @retval RETURN_UNSUPPORTED Clearing memory encryption attribute is not
38 supported
39 **/
40 RETURN_STATUS
41 EFIAPI
42 MemEncryptSevClearPageEncMask (
43 IN PHYSICAL_ADDRESS Cr3BaseAddress,
44 IN PHYSICAL_ADDRESS BaseAddress,
45 IN UINTN NumberOfPages,
46 IN BOOLEAN Flush
47 )
48 {
49 //
50 // Memory encryption bit is not accessible in 32-bit mode
51 //
52 return RETURN_UNSUPPORTED;
53 }
54
55 /**
56 This function sets memory encryption bit for the memory region specified by
57 BaseAddress and Number of pages from the current page table context.
58
59 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use current CR3)
60 @param[in] BaseAddress The physical address that is the start address
61 of a memory region.
62 @param[in] NumberOfPages The number of pages from start memory region.
63 @param[in] Flush Flush the caches before clearing the bit
64 (mostly TRUE except MMIO addresses)
65
66 @retval RETURN_SUCCESS The attributes were set for the memory region.
67 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
68 @retval RETURN_UNSUPPORTED Clearing memory encryption attribute is not
69 supported
70 **/
71 RETURN_STATUS
72 EFIAPI
73 MemEncryptSevSetPageEncMask (
74 IN PHYSICAL_ADDRESS Cr3BaseAddress,
75 IN PHYSICAL_ADDRESS BaseAddress,
76 IN UINTN NumberOfPages,
77 IN BOOLEAN Flush
78 )
79 {
80 //
81 // Memory encryption bit is not accessible in 32-bit mode
82 //
83 return RETURN_UNSUPPORTED;
84 }