]>
Commit | Line | Data |
---|---|---|
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 | \r | |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD\r | |
8 | License which accompanies this distribution. The full text of the license\r | |
9 | may be found at http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | //\r | |
16 | // The package level header files this module uses\r | |
17 | //\r | |
18 | #include <Library/DebugLib.h>\r | |
19 | #include <Library/HobLib.h>\r | |
20 | #include <Library/MemEncryptSevLib.h>\r | |
21 | #include <Library/PcdLib.h>\r | |
22 | #include <PiPei.h>\r | |
23 | #include <Register/Amd/Cpuid.h>\r | |
24 | #include <Register/Cpuid.h>\r | |
25 | \r | |
26 | #include "Platform.h"\r | |
27 | \r | |
28 | /**\r | |
29 | \r | |
30 | Function checks if SEV support is available, if present then it sets\r | |
31 | the dynamic PcdPteMemoryEncryptionAddressOrMask with memory encryption mask.\r | |
32 | \r | |
33 | **/\r | |
34 | VOID\r | |
35 | AmdSevInitialize (\r | |
36 | VOID\r | |
37 | )\r | |
38 | {\r | |
39 | CPUID_MEMORY_ENCRYPTION_INFO_EBX Ebx;\r | |
40 | UINT64 EncryptionMask;\r | |
41 | RETURN_STATUS PcdStatus;\r | |
42 | \r | |
43 | //\r | |
44 | // Check if SEV is enabled\r | |
45 | //\r | |
46 | if (!MemEncryptSevIsEnabled ()) {\r | |
47 | return;\r | |
48 | }\r | |
49 | \r | |
50 | //\r | |
51 | // CPUID Fn8000_001F[EBX] Bit 0:5 (memory encryption bit position)\r | |
52 | //\r | |
53 | AsmCpuid (CPUID_MEMORY_ENCRYPTION_INFO, NULL, &Ebx.Uint32, NULL, NULL);\r | |
54 | EncryptionMask = LShiftU64 (1, Ebx.Bits.PtePosBits);\r | |
55 | \r | |
56 | //\r | |
57 | // Set Memory Encryption Mask PCD\r | |
58 | //\r | |
59 | PcdStatus = PcdSet64S (PcdPteMemoryEncryptionAddressOrMask, EncryptionMask);\r | |
60 | ASSERT_RETURN_ERROR (PcdStatus);\r | |
61 | \r | |
62 | DEBUG ((DEBUG_INFO, "SEV is enabled (mask 0x%lx)\n", EncryptionMask));\r | |
63 | \r | |
64 | //\r | |
65 | // Set Pcd to Deny the execution of option ROM when security\r | |
66 | // violation.\r | |
67 | //\r | |
68 | PcdStatus = PcdSet32S (PcdOptionRomImageVerificationPolicy, 0x4);\r | |
69 | ASSERT_RETURN_ERROR (PcdStatus);\r | |
70 | \r | |
71 | //\r | |
72 | // When SMM is required, cover the pages containing the initial SMRAM Save\r | |
73 | // State Map with a memory allocation HOB:\r | |
74 | //\r | |
75 | // There's going to be a time interval between our decrypting those pages for\r | |
76 | // SMBASE relocation and re-encrypting the same pages after SMBASE\r | |
77 | // relocation. We shall ensure that the DXE phase stay away from those pages\r | |
78 | // until after re-encryption, in order to prevent an information leak to the\r | |
79 | // hypervisor.\r | |
80 | //\r | |
81 | if (FeaturePcdGet (PcdSmmSmramRequire) && (mBootMode != BOOT_ON_S3_RESUME)) {\r | |
82 | RETURN_STATUS LocateMapStatus;\r | |
83 | UINTN MapPagesBase;\r | |
84 | UINTN MapPagesCount;\r | |
85 | \r | |
86 | LocateMapStatus = MemEncryptSevLocateInitialSmramSaveStateMapPages (\r | |
87 | &MapPagesBase,\r | |
88 | &MapPagesCount\r | |
89 | );\r | |
90 | ASSERT_RETURN_ERROR (LocateMapStatus);\r | |
91 | \r | |
92 | BuildMemoryAllocationHob (\r | |
93 | MapPagesBase, // BaseAddress\r | |
94 | EFI_PAGES_TO_SIZE (MapPagesCount), // Length\r | |
95 | EfiBootServicesData // MemoryType\r | |
96 | );\r | |
97 | }\r | |
98 | }\r |