]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/BaseMemEncryptSevLib/MemEncryptSevLibInternal.c
MdeModulePkg/Terminal: ReadKeyStrokeEx always return key state
[mirror_edk2.git] / OvmfPkg / Library / BaseMemEncryptSevLib / MemEncryptSevLibInternal.c
CommitLineData
a1f22614
BS
1/** @file\r
2\r
3 Secure Encrypted Virtualization (SEV) library helper function\r
4\r
5 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>\r
6\r
7 This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD\r
9 License which accompanies this distribution. The full text of the license may\r
10 be found at http://opensource.org/licenses/bsd-license.php\r
11\r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#include <Library/BaseLib.h>\r
18#include <Library/DebugLib.h>\r
19#include <Register/Cpuid.h>\r
20#include <Register/Amd/Cpuid.h>\r
21#include <Register/Amd/Msr.h>\r
22#include <Library/MemEncryptSevLib.h>\r
23\r
24STATIC BOOLEAN mSevStatus = FALSE;\r
25STATIC BOOLEAN mSevStatusChecked = FALSE;\r
26\r
27/**\r
28\r
29 Returns a boolean to indicate whether SEV is enabled\r
30\r
31 @retval TRUE SEV is enabled\r
32 @retval FALSE SEV is not enabled\r
33 **/\r
34STATIC\r
35BOOLEAN\r
36EFIAPI\r
37InternalMemEncryptSevIsEnabled (\r
38 VOID\r
39 )\r
40{\r
41 UINT32 RegEax;\r
42 MSR_SEV_STATUS_REGISTER Msr;\r
43 CPUID_MEMORY_ENCRYPTION_INFO_EAX Eax;\r
44\r
45 //\r
46 // Check if memory encryption leaf exist\r
47 //\r
48 AsmCpuid (CPUID_EXTENDED_FUNCTION, &RegEax, NULL, NULL, NULL);\r
49 if (RegEax >= CPUID_MEMORY_ENCRYPTION_INFO) {\r
50 //\r
51 // CPUID Fn8000_001F[EAX] Bit 1 (Sev supported)\r
52 //\r
53 AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, &Eax.Uint32, NULL, NULL, NULL);\r
54\r
55 if (Eax.Bits.SevBit) {\r
56 //\r
57 // Check MSR_0xC0010131 Bit 0 (Sev Enabled)\r
58 //\r
59 Msr.Uint32 = AsmReadMsr32 (MSR_SEV_STATUS);\r
60 if (Msr.Bits.SevBit) {\r
61 return TRUE;\r
62 }\r
63 }\r
64 }\r
65\r
66 return FALSE;\r
67}\r
68\r
69/**\r
70\r
71 Returns a boolean to indicate whether SEV is enabled\r
72\r
73 @retval TRUE SEV is enabled\r
74 @retval FALSE SEV is not enabled\r
75 **/\r
76BOOLEAN\r
77EFIAPI\r
78MemEncryptSevIsEnabled (\r
79 VOID\r
80 )\r
81{\r
82 if (mSevStatusChecked) {\r
83 return mSevStatus;\r
84 }\r
85\r
86 mSevStatus = InternalMemEncryptSevIsEnabled();\r
87 mSevStatusChecked = TRUE;\r
88\r
89 return mSevStatus;\r
90}\r