]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/XenPlatformPei/AmdSev.c
UefiCpuPkg: Remove FIT based microcode shadow logic from MpInitLib.
[mirror_edk2.git] / OvmfPkg / XenPlatformPei / AmdSev.c
CommitLineData
3b96221f
AP
1/**@file\r
2 Initialize Secure Encrypted Virtualization (SEV) support\r
3\r
4 Copyright (c) 2017, Advanced Micro Devices. All rights reserved.<BR>\r
5 Copyright (c) 2019, Citrix Systems, Inc.\r
6\r
7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
8\r
9**/\r
10//\r
11// The package level header files this module uses\r
12//\r
13#include <Library/DebugLib.h>\r
14#include <Library/MemEncryptSevLib.h>\r
15#include <Library/PcdLib.h>\r
16#include <PiPei.h>\r
17#include <Register/Amd/Cpuid.h>\r
18#include <Register/Cpuid.h>\r
19\r
20#include "Platform.h"\r
21\r
22/**\r
23\r
24 Function checks if SEV support is available, if present then it sets\r
25 the dynamic PcdPteMemoryEncryptionAddressOrMask with memory encryption mask.\r
26\r
27 **/\r
28VOID\r
29AmdSevInitialize (\r
30 VOID\r
31 )\r
32{\r
33 CPUID_MEMORY_ENCRYPTION_INFO_EBX Ebx;\r
34 UINT64 EncryptionMask;\r
35 RETURN_STATUS PcdStatus;\r
36\r
37 //\r
38 // Check if SEV is enabled\r
39 //\r
40 if (!MemEncryptSevIsEnabled ()) {\r
41 return;\r
42 }\r
43\r
44 //\r
45 // CPUID Fn8000_001F[EBX] Bit 0:5 (memory encryption bit position)\r
46 //\r
47 AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, NULL, &Ebx.Uint32, NULL, NULL);\r
48 EncryptionMask = LShiftU64 (1, Ebx.Bits.PtePosBits);\r
49\r
50 //\r
51 // Set Memory Encryption Mask PCD\r
52 //\r
53 PcdStatus = PcdSet64S (PcdPteMemoryEncryptionAddressOrMask, EncryptionMask);\r
54 ASSERT_RETURN_ERROR (PcdStatus);\r
55\r
56 DEBUG ((DEBUG_INFO, "SEV is enabled (mask 0x%lx)\n", EncryptionMask));\r
57\r
58 //\r
59 // Set Pcd to Deny the execution of option ROM when security\r
60 // violation.\r
61 //\r
62 PcdStatus = PcdSet32S (PcdOptionRomImageVerificationPolicy, 0x4);\r
63 ASSERT_RETURN_ERROR (PcdStatus);\r
64}\r