OvmfPkg/MemEncryptSevLib: clean up MemEncryptSevIsEnabled() decl
[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
4bd6bf31
LE
7 This program and the accompanying materials are licensed and made available\r
8 under the terms and conditions of the BSD License which accompanies this\r
9 distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
a1f22614
BS
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
a1f22614
BS
70 Returns a boolean to indicate whether SEV is enabled\r
71\r
72 @retval TRUE SEV is enabled\r
73 @retval FALSE SEV is not enabled\r
d4dd22c7 74**/\r
a1f22614
BS
75BOOLEAN\r
76EFIAPI\r
77MemEncryptSevIsEnabled (\r
78 VOID\r
79 )\r
80{\r
81 if (mSevStatusChecked) {\r
82 return mSevStatus;\r
83 }\r
84\r
85 mSevStatus = InternalMemEncryptSevIsEnabled();\r
86 mSevStatusChecked = TRUE;\r
87\r
88 return mSevStatus;\r
89}\r