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