3 Secure Encrypted Virtualization (SEV) library helper function
5 Copyright (c) 2017, AMD Incorporated. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD
9 License which accompanies this distribution. The full text of the license may
10 be found at http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Library/BaseLib.h>
18 #include <Library/DebugLib.h>
19 #include <Register/Cpuid.h>
20 #include <Register/Amd/Cpuid.h>
21 #include <Register/Amd/Msr.h>
22 #include <Library/MemEncryptSevLib.h>
24 STATIC BOOLEAN mSevStatus
= FALSE
;
25 STATIC BOOLEAN mSevStatusChecked
= FALSE
;
29 Returns a boolean to indicate whether SEV is enabled
31 @retval TRUE SEV is enabled
32 @retval FALSE SEV is not enabled
37 InternalMemEncryptSevIsEnabled (
42 MSR_SEV_STATUS_REGISTER Msr
;
43 CPUID_MEMORY_ENCRYPTION_INFO_EAX Eax
;
46 // Check if memory encryption leaf exist
48 AsmCpuid (CPUID_EXTENDED_FUNCTION
, &RegEax
, NULL
, NULL
, NULL
);
49 if (RegEax
>= CPUID_MEMORY_ENCRYPTION_INFO
) {
51 // CPUID Fn8000_001F[EAX] Bit 1 (Sev supported)
53 AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO
, &Eax
.Uint32
, NULL
, NULL
, NULL
);
55 if (Eax
.Bits
.SevBit
) {
57 // Check MSR_0xC0010131 Bit 0 (Sev Enabled)
59 Msr
.Uint32
= AsmReadMsr32 (MSR_SEV_STATUS
);
60 if (Msr
.Bits
.SevBit
) {
71 Returns a boolean to indicate whether SEV is enabled
73 @retval TRUE SEV is enabled
74 @retval FALSE SEV is not enabled
78 MemEncryptSevIsEnabled (
82 if (mSevStatusChecked
) {
86 mSevStatus
= InternalMemEncryptSevIsEnabled();
87 mSevStatusChecked
= TRUE
;