]>
Commit | Line | Data |
---|---|---|
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 | |
24 | STATIC BOOLEAN mSevStatus = FALSE;\r | |
25 | STATIC 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 | |
34 | STATIC\r | |
35 | BOOLEAN\r | |
36 | EFIAPI\r | |
37 | InternalMemEncryptSevIsEnabled (\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 | |
76 | BOOLEAN\r | |
77 | EFIAPI\r | |
78 | MemEncryptSevIsEnabled (\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 |