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 <Library/SecMeasurementLib.h>
24 #include "PeilessStartupInternal.h"
26 #define GET_GPAW_INIT_STATE(INFO) ((UINT8) ((INFO) & 0x3f))
28 EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation
[] = {
29 { EfiACPIMemoryNVS
, 0x004 },
30 { EfiACPIReclaimMemory
, 0x008 },
31 { EfiReservedMemoryType
, 0x004 },
32 { EfiRuntimeServicesData
, 0x024 },
33 { EfiRuntimeServicesCode
, 0x030 },
34 { EfiBootServicesCode
, 0x180 },
35 { EfiBootServicesData
, 0xF00 },
36 { EfiMaxMemoryType
, 0x000 }
42 EFI_HOB_PLATFORM_INFO
*PlatformInfoHob
45 UINT32 LowerMemorySize
;
47 DEBUG ((DEBUG_INFO
, "InitializePlatform in Pei-less boot\n"));
48 PlatformDebugDumpCmos ();
50 PlatformInfoHob
->DefaultMaxCpuNumber
= 64;
51 PlatformInfoHob
->PcdPciMmio64Size
= 0x800000000;
53 PlatformInfoHob
->HostBridgeDevId
= PciRead16 (OVMF_HOSTBRIDGE_DID
);
54 DEBUG ((DEBUG_INFO
, "HostBridgeDeviceId = 0x%x\n", PlatformInfoHob
->HostBridgeDevId
));
56 PlatformAddressWidthInitialization (PlatformInfoHob
);
59 "PhysMemAddressWidth=0x%x, Pci64Base=0x%llx, Pci64Size=0x%llx\n",
60 PlatformInfoHob
->PhysMemAddressWidth
,
61 PlatformInfoHob
->PcdPciMmio64Base
,
62 PlatformInfoHob
->PcdPciMmio64Size
65 PlatformMaxCpuCountInitialization (PlatformInfoHob
);
68 "MaxCpuCount=%d, BootCpuCount=%d\n",
69 PlatformInfoHob
->PcdCpuMaxLogicalProcessorNumber
,
70 PlatformInfoHob
->PcdCpuBootLogicalProcessorNumber
73 LowerMemorySize
= PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob
);
74 PlatformQemuUc32BaseInitialization (PlatformInfoHob
);
77 "Uc32Base = 0x%x, Uc32Size = 0x%x, LowerMemorySize = 0x%x\n",
78 PlatformInfoHob
->Uc32Base
,
79 PlatformInfoHob
->Uc32Size
,
84 PlatformTdxPublishRamRegions ();
86 PlatformQemuInitializeRam (PlatformInfoHob
);
87 PlatformQemuInitializeRamForS3 (PlatformInfoHob
);
91 // Create Memory Type Information HOB
94 &gEfiMemoryTypeInformationGuid
,
95 mDefaultMemoryTypeInformation
,
96 sizeof (mDefaultMemoryTypeInformation
)
99 PlatformMemMapInitialization (PlatformInfoHob
);
101 PlatformNoexecDxeInitialization (PlatformInfoHob
);
103 if (TdIsEnabled ()) {
104 PlatformInfoHob
->PcdConfidentialComputingGuestAttr
= CCAttrIntelTdx
;
105 PlatformInfoHob
->PcdTdxSharedBitMask
= TdSharedPageMask ();
106 PlatformInfoHob
->PcdSetNxForStack
= TRUE
;
109 PlatformMiscInitialization (PlatformInfoHob
);
115 * This function brings up the Tdx guest from SEC phase to DXE phase.
116 * PEI phase is skipped because most of the components in PEI phase
117 * is not needed for Tdx guest, for example, MP Services, TPM etc.
118 * In this way, the attack surfaces are reduced as much as possible.
120 * @param Context The pointer to the SecCoreData
121 * @return VOID This function never returns
129 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
130 EFI_FIRMWARE_VOLUME_HEADER
*BootFv
;
132 EFI_HOB_PLATFORM_INFO PlatformInfoHob
;
135 TD_RETURN_DATA TdReturnData
;
139 Status
= EFI_SUCCESS
;
142 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*)Context
;
143 CfvBase
= (UINT8
*)(UINTN
)FixedPcdGet32 (PcdCfvBase
);
145 ZeroMem (&PlatformInfoHob
, sizeof (PlatformInfoHob
));
147 if (TdIsEnabled ()) {
148 VmmHobList
= (VOID
*)(UINTN
)FixedPcdGet32 (PcdOvmfSecGhcbBase
);
149 Status
= TdCall (TDCALL_TDINFO
, 0, 0, 0, &TdReturnData
);
150 ASSERT (Status
== EFI_SUCCESS
);
154 "Tdx started with(Hob: 0x%x, Gpaw: 0x%x, Cpus: %d)\n",
155 (UINT32
)(UINTN
)VmmHobList
,
156 GET_GPAW_INIT_STATE (TdReturnData
.TdInfo
.Gpaw
),
157 TdReturnData
.TdInfo
.NumVcpus
160 Status
= ConstructFwHobList (VmmHobList
);
162 DEBUG ((DEBUG_INFO
, "Ovmf started\n"));
163 Status
= ConstructSecHobList ();
166 if (EFI_ERROR (Status
)) {
171 DEBUG ((DEBUG_INFO
, "HobList: %p\n", GetHobList ()));
173 if (TdIsEnabled ()) {
177 Status
= MeasureHobList (VmmHobList
);
178 if (EFI_ERROR (Status
)) {
186 if (!TdxValidateCfv (CfvBase
, FixedPcdGet32 (PcdCfvRawDataSize
))) {
194 Status
= MeasureFvImage ((EFI_PHYSICAL_ADDRESS
)(UINTN
)CfvBase
, FixedPcdGet32 (PcdCfvRawDataSize
), 1);
195 if (EFI_ERROR (Status
)) {
202 // Initialize the Platform
204 Status
= InitializePlatform (&PlatformInfoHob
);
205 if (EFI_ERROR (Status
)) {
210 BuildGuidDataHob (&gUefiOvmfPkgPlatformInfoGuid
, &PlatformInfoHob
, sizeof (EFI_HOB_PLATFORM_INFO
));
215 BootFv
= (EFI_FIRMWARE_VOLUME_HEADER
*)SecCoreData
->BootFirmwareVolumeBase
;
216 BuildFvHob ((UINTN
)BootFv
, BootFv
->FvLength
);
221 DxeCodeBase
= PcdGet32 (PcdBfvBase
);
222 DxeCodeSize
= PcdGet32 (PcdBfvRawDataSize
) - (UINT32
)BootFv
->FvLength
;
223 BuildFvHob (DxeCodeBase
, DxeCodeSize
);
225 DEBUG ((DEBUG_INFO
, "SecFv : %p, 0x%x\n", BootFv
, BootFv
->FvLength
));
226 DEBUG ((DEBUG_INFO
, "DxeFv : %x, 0x%x\n", DxeCodeBase
, DxeCodeSize
));
228 BuildStackHob ((UINTN
)SecCoreData
->StackBase
, SecCoreData
->StackSize
<<= 1);
230 BuildResourceDescriptorHob (
231 EFI_RESOURCE_SYSTEM_MEMORY
,
232 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
233 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
234 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
235 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
236 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
237 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
|
238 EFI_RESOURCE_ATTRIBUTE_TESTED
,
239 (UINT64
)SecCoreData
->TemporaryRamBase
,
240 (UINT64
)SecCoreData
->TemporaryRamSize
244 // Load the DXE Core and transfer control to it.
245 // Only DxeFV is in the compressed section.
247 Status
= DxeLoadCore (1);
250 // Never arrive here.