3 Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/BaseLib.h>
11 #include <Library/BaseMemoryLib.h>
12 #include <Library/MemoryAllocationLib.h>
13 #include <Library/DebugLib.h>
14 #include <Protocol/DebugSupport.h>
15 #include <Library/TdxLib.h>
16 #include <IndustryStandard/Tdx.h>
17 #include <Library/PrePiLib.h>
18 #include <Library/PeilessStartupLib.h>
19 #include <Library/PlatformInitLib.h>
20 #include <ConfidentialComputingGuestAttr.h>
21 #include <Guid/MemoryTypeInformation.h>
22 #include <OvmfPlatforms.h>
23 #include "PeilessStartupInternal.h"
25 #define GET_GPAW_INIT_STATE(INFO) ((UINT8) ((INFO) & 0x3f))
27 EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation
[] = {
28 { EfiACPIMemoryNVS
, 0x004 },
29 { EfiACPIReclaimMemory
, 0x008 },
30 { EfiReservedMemoryType
, 0x004 },
31 { EfiRuntimeServicesData
, 0x024 },
32 { EfiRuntimeServicesCode
, 0x030 },
33 { EfiBootServicesCode
, 0x180 },
34 { EfiBootServicesData
, 0xF00 },
35 { EfiMaxMemoryType
, 0x000 }
41 EFI_HOB_PLATFORM_INFO
*PlatformInfoHob
46 DEBUG ((DEBUG_INFO
, "InitializePlatform in Pei-less boot\n"));
47 PlatformDebugDumpCmos ();
49 PlatformInfoHob
->DefaultMaxCpuNumber
= 64;
50 PlatformInfoHob
->PcdPciMmio64Size
= 0x800000000;
52 PlatformInfoHob
->HostBridgeDevId
= PciRead16 (OVMF_HOSTBRIDGE_DID
);
53 DEBUG ((DEBUG_INFO
, "HostBridgeDeviceId = 0x%x\n", PlatformInfoHob
->HostBridgeDevId
));
55 PlatformAddressWidthInitialization (PlatformInfoHob
);
58 "PhysMemAddressWidth=0x%x, Pci64Base=0x%llx, Pci64Size=0x%llx\n",
59 PlatformInfoHob
->PhysMemAddressWidth
,
60 PlatformInfoHob
->PcdPciMmio64Base
,
61 PlatformInfoHob
->PcdPciMmio64Size
64 PlatformMaxCpuCountInitialization (PlatformInfoHob
);
67 "MaxCpuCount=%d, BootCpuCount=%d\n",
68 PlatformInfoHob
->PcdCpuMaxLogicalProcessorNumber
,
69 PlatformInfoHob
->PcdCpuBootLogicalProcessorNumber
72 PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob
);
73 PlatformQemuUc32BaseInitialization (PlatformInfoHob
);
76 "Uc32Base = 0x%x, Uc32Size = 0x%x, LowerMemorySize = 0x%x\n",
77 PlatformInfoHob
->Uc32Base
,
78 PlatformInfoHob
->Uc32Size
,
79 PlatformInfoHob
->LowMemory
82 VariableStore
= PlatformReserveEmuVariableNvStore ();
83 PlatformInfoHob
->PcdEmuVariableNvStoreReserved
= (UINT64
)(UINTN
)VariableStore
;
84 #ifdef SECURE_BOOT_FEATURE_ENABLED
85 PlatformInitEmuVariableNvStore (VariableStore
);
89 PlatformTdxPublishRamRegions ();
91 PlatformQemuInitializeRam (PlatformInfoHob
);
92 PlatformQemuInitializeRamForS3 (PlatformInfoHob
);
96 // Create Memory Type Information HOB
99 &gEfiMemoryTypeInformationGuid
,
100 mDefaultMemoryTypeInformation
,
101 sizeof (mDefaultMemoryTypeInformation
)
104 PlatformMemMapInitialization (PlatformInfoHob
);
106 PlatformNoexecDxeInitialization (PlatformInfoHob
);
108 if (TdIsEnabled ()) {
109 PlatformInfoHob
->PcdConfidentialComputingGuestAttr
= CCAttrIntelTdx
;
110 PlatformInfoHob
->PcdTdxSharedBitMask
= TdSharedPageMask ();
111 PlatformInfoHob
->PcdSetNxForStack
= TRUE
;
114 PlatformMiscInitialization (PlatformInfoHob
);
120 * This function brings up the Tdx guest from SEC phase to DXE phase.
121 * PEI phase is skipped because most of the components in PEI phase
122 * is not needed for Tdx guest, for example, MP Services, TPM etc.
123 * In this way, the attack surfaces are reduced as much as possible.
125 * @param Context The pointer to the SecCoreData
126 * @return VOID This function never returns
134 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
135 EFI_FIRMWARE_VOLUME_HEADER
*BootFv
;
137 EFI_HOB_PLATFORM_INFO PlatformInfoHob
;
140 TD_RETURN_DATA TdReturnData
;
144 Status
= EFI_SUCCESS
;
147 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*)Context
;
148 CfvBase
= (UINT8
*)(UINTN
)FixedPcdGet32 (PcdCfvBase
);
150 ZeroMem (&PlatformInfoHob
, sizeof (PlatformInfoHob
));
152 if (TdIsEnabled ()) {
153 VmmHobList
= (VOID
*)(UINTN
)FixedPcdGet32 (PcdOvmfSecGhcbBase
);
154 Status
= TdCall (TDCALL_TDINFO
, 0, 0, 0, &TdReturnData
);
155 ASSERT (Status
== EFI_SUCCESS
);
159 "Tdx started with(Hob: 0x%x, Gpaw: 0x%x, Cpus: %d)\n",
160 (UINT32
)(UINTN
)VmmHobList
,
161 GET_GPAW_INIT_STATE (TdReturnData
.TdInfo
.Gpaw
),
162 TdReturnData
.TdInfo
.NumVcpus
165 Status
= ConstructFwHobList (VmmHobList
);
167 DEBUG ((DEBUG_INFO
, "Ovmf started\n"));
168 Status
= ConstructSecHobList ();
171 if (EFI_ERROR (Status
)) {
176 DEBUG ((DEBUG_INFO
, "HobList: %p\n", GetHobList ()));
178 if (TdIsEnabled ()) {
182 Status
= MeasureHobList (VmmHobList
);
183 if (EFI_ERROR (Status
)) {
191 Status
= MeasureFvImage ((EFI_PHYSICAL_ADDRESS
)(UINTN
)CfvBase
, FixedPcdGet32 (PcdCfvRawDataSize
), 1);
192 if (EFI_ERROR (Status
)) {
199 // Initialize the Platform
201 Status
= InitializePlatform (&PlatformInfoHob
);
202 if (EFI_ERROR (Status
)) {
207 BuildGuidDataHob (&gUefiOvmfPkgPlatformInfoGuid
, &PlatformInfoHob
, sizeof (EFI_HOB_PLATFORM_INFO
));
212 BootFv
= (EFI_FIRMWARE_VOLUME_HEADER
*)SecCoreData
->BootFirmwareVolumeBase
;
213 BuildFvHob ((UINTN
)BootFv
, BootFv
->FvLength
);
218 DxeCodeBase
= PcdGet32 (PcdBfvBase
);
219 DxeCodeSize
= PcdGet32 (PcdBfvRawDataSize
) - (UINT32
)BootFv
->FvLength
;
220 BuildFvHob (DxeCodeBase
, DxeCodeSize
);
222 DEBUG ((DEBUG_INFO
, "SecFv : %p, 0x%x\n", BootFv
, BootFv
->FvLength
));
223 DEBUG ((DEBUG_INFO
, "DxeFv : %x, 0x%x\n", DxeCodeBase
, DxeCodeSize
));
225 BuildStackHob ((UINTN
)SecCoreData
->StackBase
, SecCoreData
->StackSize
<<= 1);
227 BuildResourceDescriptorHob (
228 EFI_RESOURCE_SYSTEM_MEMORY
,
229 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
230 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
231 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
232 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
233 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
234 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
|
235 EFI_RESOURCE_ATTRIBUTE_TESTED
,
236 (UINT64
)SecCoreData
->TemporaryRamBase
,
237 (UINT64
)SecCoreData
->TemporaryRamSize
241 // Load the DXE Core and transfer control to it.
242 // Only DxeFV is in the compressed section.
244 Status
= DxeLoadCore (1);
247 // Never arrive here.