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
44 UINT32 LowerMemorySize
;
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 LowerMemorySize
= PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob
);
73 PlatformQemuUc32BaseInitialization (PlatformInfoHob
);
76 "Uc32Base = 0x%x, Uc32Size = 0x%x, LowerMemorySize = 0x%x\n",
77 PlatformInfoHob
->Uc32Base
,
78 PlatformInfoHob
->Uc32Size
,
83 PlatformTdxPublishRamRegions ();
85 PlatformQemuInitializeRam (PlatformInfoHob
);
86 PlatformQemuInitializeRamForS3 (PlatformInfoHob
);
90 // Create Memory Type Information HOB
93 &gEfiMemoryTypeInformationGuid
,
94 mDefaultMemoryTypeInformation
,
95 sizeof (mDefaultMemoryTypeInformation
)
98 PlatformMemMapInitialization (PlatformInfoHob
);
100 PlatformNoexecDxeInitialization (PlatformInfoHob
);
102 if (TdIsEnabled ()) {
103 PlatformInfoHob
->PcdConfidentialComputingGuestAttr
= CCAttrIntelTdx
;
104 PlatformInfoHob
->PcdTdxSharedBitMask
= TdSharedPageMask ();
105 PlatformInfoHob
->PcdSetNxForStack
= TRUE
;
108 PlatformMiscInitialization (PlatformInfoHob
);
114 * This function brings up the Tdx guest from SEC phase to DXE phase.
115 * PEI phase is skipped because most of the components in PEI phase
116 * is not needed for Tdx guest, for example, MP Services, TPM etc.
117 * In this way, the attack surfaces are reduced as much as possible.
119 * @param Context The pointer to the SecCoreData
120 * @return VOID This function never returns
128 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
129 EFI_FIRMWARE_VOLUME_HEADER
*BootFv
;
131 EFI_HOB_PLATFORM_INFO PlatformInfoHob
;
134 TD_RETURN_DATA TdReturnData
;
138 Status
= EFI_SUCCESS
;
141 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*)Context
;
142 CfvBase
= (UINT8
*)(UINTN
)FixedPcdGet32 (PcdCfvBase
);
144 ZeroMem (&PlatformInfoHob
, sizeof (PlatformInfoHob
));
146 if (TdIsEnabled ()) {
147 VmmHobList
= (VOID
*)(UINTN
)FixedPcdGet32 (PcdOvmfSecGhcbBase
);
148 Status
= TdCall (TDCALL_TDINFO
, 0, 0, 0, &TdReturnData
);
149 ASSERT (Status
== EFI_SUCCESS
);
153 "Tdx started with(Hob: 0x%x, Gpaw: 0x%x, Cpus: %d)\n",
154 (UINT32
)(UINTN
)VmmHobList
,
155 GET_GPAW_INIT_STATE (TdReturnData
.TdInfo
.Gpaw
),
156 TdReturnData
.TdInfo
.NumVcpus
159 Status
= ConstructFwHobList (VmmHobList
);
161 DEBUG ((DEBUG_INFO
, "Ovmf started\n"));
162 Status
= ConstructSecHobList ();
165 if (EFI_ERROR (Status
)) {
170 DEBUG ((DEBUG_INFO
, "HobList: %p\n", GetHobList ()));
172 if (TdIsEnabled ()) {
176 Status
= MeasureHobList (VmmHobList
);
177 if (EFI_ERROR (Status
)) {
185 if (!TdxValidateCfv (CfvBase
, FixedPcdGet32 (PcdCfvRawDataSize
))) {
193 Status
= MeasureFvImage ((EFI_PHYSICAL_ADDRESS
)(UINTN
)CfvBase
, FixedPcdGet32 (PcdCfvRawDataSize
), 1);
194 if (EFI_ERROR (Status
)) {
201 // Initialize the Platform
203 Status
= InitializePlatform (&PlatformInfoHob
);
204 if (EFI_ERROR (Status
)) {
209 BuildGuidDataHob (&gUefiOvmfPkgPlatformInfoGuid
, &PlatformInfoHob
, sizeof (EFI_HOB_PLATFORM_INFO
));
214 BootFv
= (EFI_FIRMWARE_VOLUME_HEADER
*)SecCoreData
->BootFirmwareVolumeBase
;
215 BuildFvHob ((UINTN
)BootFv
, BootFv
->FvLength
);
220 DxeCodeBase
= PcdGet32 (PcdBfvBase
);
221 DxeCodeSize
= PcdGet32 (PcdBfvRawDataSize
) - (UINT32
)BootFv
->FvLength
;
222 BuildFvHob (DxeCodeBase
, DxeCodeSize
);
224 DEBUG ((DEBUG_INFO
, "SecFv : %p, 0x%x\n", BootFv
, BootFv
->FvLength
));
225 DEBUG ((DEBUG_INFO
, "DxeFv : %x, 0x%x\n", DxeCodeBase
, DxeCodeSize
));
227 BuildStackHob ((UINTN
)SecCoreData
->StackBase
, SecCoreData
->StackSize
<<= 1);
229 BuildResourceDescriptorHob (
230 EFI_RESOURCE_SYSTEM_MEMORY
,
231 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
232 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
233 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
234 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
235 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
236 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
|
237 EFI_RESOURCE_ATTRIBUTE_TESTED
,
238 (UINT64
)SecCoreData
->TemporaryRamBase
,
239 (UINT64
)SecCoreData
->TemporaryRamSize
243 // Load the DXE Core and transfer control to it.
244 // Only DxeFV is in the compressed section.
246 Status
= DxeLoadCore (1);
249 // Never arrive here.