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 are licensed and made available
8 under the terms and conditions of the BSD License which accompanies this
9 distribution. The full text of the license may be found at
10 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 <Library/MemEncryptSevLib.h>
20 #include <Register/Amd/Cpuid.h>
21 #include <Register/Amd/Msr.h>
22 #include <Register/Cpuid.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
) {
70 Returns a boolean to indicate whether SEV is enabled
72 @retval TRUE SEV is enabled
73 @retval FALSE SEV is not enabled
77 MemEncryptSevIsEnabled (
81 if (mSevStatusChecked
) {
85 mSevStatus
= InternalMemEncryptSevIsEnabled();
86 mSevStatusChecked
= TRUE
;