]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Include/Library/MemEncryptSevLib.h
OvmfPkg/ResetVector: Validate the encryption bit position for SEV/SEV-ES
[mirror_edk2.git] / OvmfPkg / Include / Library / MemEncryptSevLib.h
1 /** @file
2
3 Define Secure Encrypted Virtualization (SEV) base library helper function
4
5 Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #ifndef _MEM_ENCRYPT_SEV_LIB_H_
12 #define _MEM_ENCRYPT_SEV_LIB_H_
13
14 #include <Base.h>
15
16 //
17 // Internal structure for holding SEV-ES information needed during SEC phase
18 // and valid only during SEC phase and early PEI during platform
19 // initialization.
20 //
21 // This structure is also used by assembler files:
22 // OvmfPkg/ResetVector/ResetVector.nasmb
23 // OvmfPkg/ResetVector/Ia32/PageTables64.asm
24 // OvmfPkg/ResetVector/Ia32/Flat32ToFlat64.asm
25 // any changes must stay in sync with its usage.
26 //
27 typedef struct _SEC_SEV_ES_WORK_AREA {
28 UINT8 SevEsEnabled;
29 UINT8 Reserved1[7];
30
31 UINT64 RandomData;
32 } SEC_SEV_ES_WORK_AREA;
33
34 /**
35 Returns a boolean to indicate whether SEV-ES is enabled.
36
37 @retval TRUE SEV-ES is enabled
38 @retval FALSE SEV-ES is not enabled
39 **/
40 BOOLEAN
41 EFIAPI
42 MemEncryptSevEsIsEnabled (
43 VOID
44 );
45
46 /**
47 Returns a boolean to indicate whether SEV is enabled
48
49 @retval TRUE SEV is enabled
50 @retval FALSE SEV is not enabled
51 **/
52 BOOLEAN
53 EFIAPI
54 MemEncryptSevIsEnabled (
55 VOID
56 );
57
58 /**
59 This function clears memory encryption bit for the memory region specified by
60 BaseAddress and NumPages from the current page table context.
61
62 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
63 current CR3)
64 @param[in] BaseAddress The physical address that is the start
65 address of a memory region.
66 @param[in] NumPages The number of pages from start memory
67 region.
68 @param[in] Flush Flush the caches before clearing the bit
69 (mostly TRUE except MMIO addresses)
70
71 @retval RETURN_SUCCESS The attributes were cleared for the
72 memory region.
73 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
74 @retval RETURN_UNSUPPORTED Clearing the memory encryption attribute
75 is not supported
76 **/
77 RETURN_STATUS
78 EFIAPI
79 MemEncryptSevClearPageEncMask (
80 IN PHYSICAL_ADDRESS Cr3BaseAddress,
81 IN PHYSICAL_ADDRESS BaseAddress,
82 IN UINTN NumPages,
83 IN BOOLEAN Flush
84 );
85
86 /**
87 This function sets memory encryption bit for the memory region specified by
88 BaseAddress and NumPages from the current page table context.
89
90 @param[in] Cr3BaseAddress Cr3 Base Address (if zero then use
91 current CR3)
92 @param[in] BaseAddress The physical address that is the start
93 address of a memory region.
94 @param[in] NumPages The number of pages from start memory
95 region.
96 @param[in] Flush Flush the caches before setting the bit
97 (mostly TRUE except MMIO addresses)
98
99 @retval RETURN_SUCCESS The attributes were set for the memory
100 region.
101 @retval RETURN_INVALID_PARAMETER Number of pages is zero.
102 @retval RETURN_UNSUPPORTED Setting the memory encryption attribute
103 is not supported
104 **/
105 RETURN_STATUS
106 EFIAPI
107 MemEncryptSevSetPageEncMask (
108 IN PHYSICAL_ADDRESS Cr3BaseAddress,
109 IN PHYSICAL_ADDRESS BaseAddress,
110 IN UINTN NumPages,
111 IN BOOLEAN Flush
112 );
113
114
115 /**
116 Locate the page range that covers the initial (pre-SMBASE-relocation) SMRAM
117 Save State Map.
118
119 @param[out] BaseAddress The base address of the lowest-address page that
120 covers the initial SMRAM Save State Map.
121
122 @param[out] NumberOfPages The number of pages in the page range that covers
123 the initial SMRAM Save State Map.
124
125 @retval RETURN_SUCCESS BaseAddress and NumberOfPages have been set on
126 output.
127
128 @retval RETURN_UNSUPPORTED SMM is unavailable.
129 **/
130 RETURN_STATUS
131 EFIAPI
132 MemEncryptSevLocateInitialSmramSaveStateMapPages (
133 OUT UINTN *BaseAddress,
134 OUT UINTN *NumberOfPages
135 );
136 #endif // _MEM_ENCRYPT_SEV_LIB_H_