TianoCore EDK2 master
Loading...
Searching...
No Matches
PeilessStartup.c
Go to the documentation of this file.
1
9#include <PiPei.h>
10#include <Library/BaseLib.h>
13#include <Library/DebugLib.h>
15#include <Library/TdxLib.h>
17#include <Library/PrePiLib.h>
23#include <OvmfPlatforms.h>
25
26#define GET_GPAW_INIT_STATE(INFO) ((UINT8) ((INFO) & 0x3f))
27
28EFI_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 }
37};
38
40EFIAPI
42 EFI_HOB_PLATFORM_INFO *PlatformInfoHob
43 )
44{
45 VOID *VariableStore;
46
47 DEBUG ((DEBUG_INFO, "InitializePlatform in Pei-less boot\n"));
49
50 PlatformInfoHob->DefaultMaxCpuNumber = 64;
51 PlatformInfoHob->PcdPciMmio64Size = 0x800000000;
52
53 PlatformInfoHob->HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
54 DEBUG ((DEBUG_INFO, "HostBridgeDeviceId = 0x%x\n", PlatformInfoHob->HostBridgeDevId));
55
56 PlatformAddressWidthInitialization (PlatformInfoHob);
57 DEBUG ((
58 DEBUG_INFO,
59 "PhysMemAddressWidth=0x%x, Pci64Base=0x%llx, Pci64Size=0x%llx\n",
60 PlatformInfoHob->PhysMemAddressWidth,
61 PlatformInfoHob->PcdPciMmio64Base,
62 PlatformInfoHob->PcdPciMmio64Size
63 ));
64
65 PlatformMaxCpuCountInitialization (PlatformInfoHob);
66 DEBUG ((
67 DEBUG_INFO,
68 "MaxCpuCount=%d, BootCpuCount=%d\n",
69 PlatformInfoHob->PcdCpuMaxLogicalProcessorNumber,
70 PlatformInfoHob->PcdCpuBootLogicalProcessorNumber
71 ));
72
73 PlatformGetSystemMemorySizeBelow4gb (PlatformInfoHob);
74 PlatformQemuUc32BaseInitialization (PlatformInfoHob);
75 DEBUG ((
76 DEBUG_INFO,
77 "Uc32Base = 0x%x, Uc32Size = 0x%x, LowerMemorySize = 0x%x\n",
78 PlatformInfoHob->Uc32Base,
79 PlatformInfoHob->Uc32Size,
80 PlatformInfoHob->LowMemory
81 ));
82
83 VariableStore = PlatformReserveEmuVariableNvStore ();
84 PlatformInfoHob->PcdEmuVariableNvStoreReserved = (UINT64)(UINTN)VariableStore;
85 if (FeaturePcdGet (PcdSecureBootSupported)) {
86 PlatformInitEmuVariableNvStore (VariableStore);
87 }
88
89 if (TdIsEnabled ()) {
91 } else {
92 PlatformQemuInitializeRam (PlatformInfoHob);
93 PlatformQemuInitializeRamForS3 (PlatformInfoHob);
94 }
95
96 //
97 // Create Memory Type Information HOB
98 //
100 &gEfiMemoryTypeInformationGuid,
101 mDefaultMemoryTypeInformation,
102 sizeof (mDefaultMemoryTypeInformation)
103 );
104
105 PlatformMemMapInitialization (PlatformInfoHob);
106
107 PlatformNoexecDxeInitialization (PlatformInfoHob);
108
109 if (TdIsEnabled ()) {
110 PlatformInfoHob->PcdConfidentialComputingGuestAttr = CCAttrIntelTdx;
111 PlatformInfoHob->PcdTdxSharedBitMask = TdSharedPageMask ();
112 }
113
114 PlatformMiscInitialization (PlatformInfoHob);
115
116 return EFI_SUCCESS;
117}
118
128VOID
129EFIAPI
131 IN VOID *Context
132 )
133{
134 EFI_SEC_PEI_HAND_OFF *SecCoreData;
136 EFI_STATUS Status;
137 EFI_HOB_PLATFORM_INFO PlatformInfoHob;
138 UINT32 DxeCodeBase;
139 UINT32 DxeCodeSize;
140 TD_RETURN_DATA TdReturnData;
141 VOID *VmmHobList;
142
143 Status = EFI_SUCCESS;
144 BootFv = NULL;
145 VmmHobList = NULL;
146 SecCoreData = (EFI_SEC_PEI_HAND_OFF *)Context;
147
148 ZeroMem (&PlatformInfoHob, sizeof (PlatformInfoHob));
149
150 if (TdIsEnabled ()) {
151 VmmHobList = (VOID *)(UINTN)FixedPcdGet32 (PcdOvmfSecGhcbBase);
152 Status = TdCall (TDCALL_TDINFO, 0, 0, 0, &TdReturnData);
153 ASSERT (Status == EFI_SUCCESS);
154
155 DEBUG ((
156 DEBUG_INFO,
157 "Tdx started with(Hob: 0x%x, Gpaw: 0x%x, Cpus: %d)\n",
158 (UINT32)(UINTN)VmmHobList,
159 GET_GPAW_INIT_STATE (TdReturnData.TdInfo.Gpaw),
160 TdReturnData.TdInfo.NumVcpus
161 ));
162
163 Status = ConstructFwHobList (VmmHobList);
164 } else {
165 DEBUG ((DEBUG_INFO, "Ovmf started\n"));
166 Status = ConstructSecHobList ();
167 }
168
169 if (EFI_ERROR (Status)) {
170 ASSERT (FALSE);
171 CpuDeadLoop ();
172 }
173
174 DEBUG ((DEBUG_INFO, "HobList: %p\n", GetHobList ()));
175
176 if (TdIsEnabled ()) {
177 //
178 // Build GuidHob for the tdx measurements which were done in SEC phase.
179 //
181 if (EFI_ERROR (Status)) {
182 ASSERT (FALSE);
183 CpuDeadLoop ();
184 }
185 }
186
187 //
188 // Initialize the Platform
189 //
190 Status = InitializePlatform (&PlatformInfoHob);
191 if (EFI_ERROR (Status)) {
192 ASSERT (FALSE);
193 CpuDeadLoop ();
194 }
195
196 BuildGuidDataHob (&gUefiOvmfPkgPlatformInfoGuid, &PlatformInfoHob, sizeof (EFI_HOB_PLATFORM_INFO));
197
198 //
199 // SecFV
200 //
201 BootFv = (EFI_FIRMWARE_VOLUME_HEADER *)SecCoreData->BootFirmwareVolumeBase;
202 BuildFvHob ((UINTN)BootFv, BootFv->FvLength);
203
204 //
205 // DxeFV
206 //
207 DxeCodeBase = PcdGet32 (PcdBfvBase);
208 DxeCodeSize = PcdGet32 (PcdBfvRawDataSize) - (UINT32)BootFv->FvLength;
209 BuildFvHob (DxeCodeBase, DxeCodeSize);
210
211 DEBUG ((DEBUG_INFO, "SecFv : %p, 0x%x\n", BootFv, BootFv->FvLength));
212 DEBUG ((DEBUG_INFO, "DxeFv : %x, 0x%x\n", DxeCodeBase, DxeCodeSize));
213
214 BuildStackHob ((UINTN)SecCoreData->StackBase, SecCoreData->StackSize <<= 1);
215
217 EFI_RESOURCE_SYSTEM_MEMORY,
218 EFI_RESOURCE_ATTRIBUTE_PRESENT |
219 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
220 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
221 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
222 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
223 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE |
224 EFI_RESOURCE_ATTRIBUTE_TESTED,
225 (UINT64)SecCoreData->TemporaryRamBase,
226 (UINT64)SecCoreData->TemporaryRamSize
227 );
228
229 //
230 // Load the DXE Core and transfer control to it.
231 // Only DxeFV is in the compressed section.
232 //
233 Status = DxeLoadCore (1);
234
235 //
236 // Never arrive here.
237 //
238 ASSERT (FALSE);
239 CpuDeadLoop ();
240}
UINT64 UINTN
VOID *EFIAPI BuildGuidDataHob(IN CONST EFI_GUID *Guid, IN VOID *Data, IN UINTN DataLength)
Definition: HobLib.c:375
VOID EFIAPI BuildResourceDescriptorHob(IN EFI_RESOURCE_TYPE ResourceType, IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute, IN EFI_PHYSICAL_ADDRESS PhysicalStart, IN UINT64 NumberOfBytes)
Definition: HobLib.c:299
VOID EFIAPI BuildFvHob(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
Definition: HobLib.c:404
VOID *EFIAPI GetHobList(VOID)
Definition: HobLib.c:76
VOID EFIAPI BuildStackHob(IN EFI_PHYSICAL_ADDRESS BaseAddress, IN UINT64 Length)
Definition: HobLib.c:546
UINTN EFIAPI TdCall(IN UINT64 Leaf, IN UINT64 Arg1, IN UINT64 Arg2, IN UINT64 Arg3, IN OUT VOID *Results)
Definition: IntelTdxNull.c:31
VOID EFIAPI CpuDeadLoop(VOID)
Definition: CpuDeadLoop.c:25
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI DxeLoadCore(IN CONST EFI_DXE_IPL_PPI *This, IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_HOB_POINTERS HobList)
Definition: DxeLoad.c:247
#define NULL
Definition: Base.h:319
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
UINT16 EFIAPI PciRead16(IN UINTN Address)
Definition: PciLib.c:396
BOOLEAN EFIAPI TdIsEnabled()
Definition: IntelTdxNull.c:79
EFI_STATUS EFIAPI InitializePlatform(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
Definition: Platform.c:568
EFI_STATUS EFIAPI ConstructSecHobList()
Definition: Hob.c:34
EFI_STATUS EFIAPI ConstructFwHobList(IN CONST VOID *VmmHobList)
Definition: Hob.c:73
#define FixedPcdGet32(TokenName)
Definition: PcdLib.h:92
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
#define FeaturePcdGet(TokenName)
Definition: PcdLib.h:50
VOID EFIAPI PeilessStartup(IN VOID *Context)
VOID EFIAPI PlatformMaxCpuCountInitialization(IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob)
Definition: Platform.c:560
VOID EFIAPI PlatformAddressWidthInitialization(IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob)
Definition: MemDetect.c:1045
VOID EFIAPI PlatformDebugDumpCmos(VOID)
Definition: Cmos.c:63
EFI_STATUS EFIAPI PlatformNoexecDxeInitialization(IN OUT EFI_HOB_PLATFORM_INFO *PlatformInfoHob)
Definition: Platform.c:261
VOID EFIAPI PlatformTdxPublishRamRegions(VOID)
Definition: IntelTdx.c:146
VOID EFIAPI PlatformQemuInitializeRam(IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob)
Definition: MemDetect.c:1231
VOID *EFIAPI PlatformReserveEmuVariableNvStore(VOID)
Definition: Platform.c:890
EFI_STATUS EFIAPI PlatformInitEmuVariableNvStore(IN VOID *EmuVariableNvStore)
Definition: Platform.c:933
EFI_STATUS EFIAPI TdxHelperBuildGuidHobForTdxMeasurement(VOID)
Definition: PeiTdxHelper.c:86
UINT64 EFIAPI TdSharedPageMask(VOID)
Definition: TdInfo.c:68
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
@ EfiBootServicesData
@ EfiReservedMemoryType
@ EfiBootServicesCode
@ EfiACPIMemoryNVS
@ EfiACPIReclaimMemory
@ EfiRuntimeServicesCode
@ EfiRuntimeServicesData
VOID * BootFirmwareVolumeBase
Definition: PiPeiCis.h:965