2 Initialize Secure Encrypted Virtualization (SEV) support
4 Copyright (c) 2017, Advanced Micro Devices. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD
8 License which accompanies this distribution. The full text of the license
9 may be found at http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 // The package level header files this module uses
20 #include <Library/DebugLib.h>
21 #include <Library/PcdLib.h>
22 #include <Register/Cpuid.h>
23 #include <Register/Amd/Cpuid.h>
24 #include <Library/MemEncryptSevLib.h>
28 Function checks if SEV support is available, if present then it sets
29 the dynamic PcdPteMemoryEncryptionAddressOrMask with memory encryption mask.
38 CPUID_MEMORY_ENCRYPTION_INFO_EBX Ebx
;
39 UINT64 EncryptionMask
;
40 RETURN_STATUS PcdStatus
;
43 // Check if SEV is enabled
45 if (!MemEncryptSevIsEnabled ()) {
50 // CPUID Fn8000_001F[EBX] Bit 0:5 (memory encryption bit position)
52 AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO
, NULL
, &Ebx
.Uint32
, NULL
, NULL
);
53 EncryptionMask
= LShiftU64 (1, Ebx
.Bits
.PtePosBits
);
56 // Set Memory Encryption Mask PCD
58 PcdStatus
= PcdSet64S (PcdPteMemoryEncryptionAddressOrMask
, EncryptionMask
);
59 ASSERT_RETURN_ERROR (PcdStatus
);
61 DEBUG ((DEBUG_INFO
, "SEV is enabled (mask 0x%lx)\n", EncryptionMask
));
64 // Set Pcd to Deny the execution of option ROM when security
67 PcdStatus
= PcdSet32S (PcdOptionRomImageVerificationPolicy
, 0x4);
68 ASSERT_RETURN_ERROR (PcdStatus
);