4 Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 EFI_PEI_PPI_DESCRIPTOR mPeiSecMainPpi
[] = {
14 EFI_PEI_PPI_DESCRIPTOR_PPI
,
15 &gTopOfTemporaryRamPpiGuid
,
16 NULL
// To be patched later.
19 EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
,
25 FSP_INIT_DONE_PPI gFspInitDonePpi
= {
26 FspInitDoneGetFspHobList
30 // These are IDT entries pointing to 10:FFFFFFE4h.
32 UINT64 mIdtEntryTemplate
= 0xffff8e000010ffe4ULL
;
35 Caller provided function to be invoked at the end of InitializeDebugAgent().
37 Entry point to the C language phase of SEC. After the SEC assembly
38 code has initialized some temporary memory and set up the stack,
39 the control is transferred to this function.
41 @param[in] Context The first input parameter of InitializeDebugAgent().
53 Entry point to the C language phase of SEC. After the SEC assembly
54 code has initialized some temporary memory and set up the stack,
55 the control is transferred to this function.
57 @param[in] SizeOfRam Size of the temporary memory available for use.
58 @param[in] TempRamBase Base address of temporary ram
59 @param[in] BootFirmwareVolume Base address of the Boot Firmware Volume.
65 IN UINT32 TempRamBase
,
66 IN VOID
*BootFirmwareVolume
69 EFI_SEC_PEI_HAND_OFF SecCoreData
;
70 IA32_DESCRIPTOR IdtDescriptor
;
71 SEC_IDT_TABLE IdtTableInStack
;
75 PeiStackSize
= PcdGet32 (PcdPeiTemporaryRamStackSize
);
76 if (PeiStackSize
== 0) {
77 PeiStackSize
= (SizeOfRam
>> 1);
80 ASSERT (PeiStackSize
< SizeOfRam
);
83 // Process all libraries constructor function linked to SecCore.
85 ProcessLibraryConstructorList ();
87 DEBUG ((DEBUG_INFO
, "FspPei - SecStartup\n"));
90 // Initialize floating point operating environment
91 // to be compliant with UEFI spec.
93 InitializeFloatingPointUnits ();
96 // |-------------------|---->
98 // |-------------------|
99 // |PeiService Pointer | PeiStackSize
100 // |-------------------|
103 // |-------------------|---->
106 // | Heap | PeiTemporayRamSize
109 // |-------------------|----> TempRamBase
111 IdtTableInStack
.PeiService
= 0;
112 for (Index
= 0; Index
< SEC_IDT_ENTRY_COUNT
; Index
++) {
113 CopyMem ((VOID
*)&IdtTableInStack
.IdtTable
[Index
], (VOID
*)&mIdtEntryTemplate
, sizeof (UINT64
));
116 IdtDescriptor
.Base
= (UINTN
) &IdtTableInStack
.IdtTable
;
117 IdtDescriptor
.Limit
= (UINT16
)(sizeof (IdtTableInStack
.IdtTable
) - 1);
119 AsmWriteIdtr (&IdtDescriptor
);
122 // Update the base address and length of Pei temporary memory
124 SecCoreData
.DataSize
= (UINT16
) sizeof (EFI_SEC_PEI_HAND_OFF
);
125 SecCoreData
.BootFirmwareVolumeBase
= BootFirmwareVolume
;
126 SecCoreData
.BootFirmwareVolumeSize
= (UINTN
)(SIZE_4GB
- (UINTN
) BootFirmwareVolume
);
127 SecCoreData
.TemporaryRamBase
= (VOID
*)(UINTN
) TempRamBase
;
128 SecCoreData
.TemporaryRamSize
= SizeOfRam
;
129 SecCoreData
.PeiTemporaryRamBase
= SecCoreData
.TemporaryRamBase
;
130 SecCoreData
.PeiTemporaryRamSize
= SizeOfRam
- PeiStackSize
;
131 SecCoreData
.StackBase
= (VOID
*)(UINTN
)(TempRamBase
+ SecCoreData
.PeiTemporaryRamSize
);
132 SecCoreData
.StackSize
= PeiStackSize
;
134 DEBUG ((DEBUG_INFO
, "BootFirmwareVolumeBase - 0x%x\n", SecCoreData
.BootFirmwareVolumeBase
));
135 DEBUG ((DEBUG_INFO
, "BootFirmwareVolumeSize - 0x%x\n", SecCoreData
.BootFirmwareVolumeSize
));
136 DEBUG ((DEBUG_INFO
, "TemporaryRamBase - 0x%x\n", SecCoreData
.TemporaryRamBase
));
137 DEBUG ((DEBUG_INFO
, "TemporaryRamSize - 0x%x\n", SecCoreData
.TemporaryRamSize
));
138 DEBUG ((DEBUG_INFO
, "PeiTemporaryRamBase - 0x%x\n", SecCoreData
.PeiTemporaryRamBase
));
139 DEBUG ((DEBUG_INFO
, "PeiTemporaryRamSize - 0x%x\n", SecCoreData
.PeiTemporaryRamSize
));
140 DEBUG ((DEBUG_INFO
, "StackBase - 0x%x\n", SecCoreData
.StackBase
));
141 DEBUG ((DEBUG_INFO
, "StackSize - 0x%x\n", SecCoreData
.StackSize
));
144 // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.
146 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC
, &SecCoreData
, SecStartupPhase2
);
151 This API patch the TopOfTemporaryRam value in SecPpiList.
153 @param[in,out] SecPpiList PPI list to be patched.
154 @param[in] TopOfTemporaryRam The top of Temporary Ram.
158 PatchTopOfTemporaryRamPpi (
159 IN OUT EFI_PEI_PPI_DESCRIPTOR
*SecPpiList
,
160 IN VOID
*TopOfTemporaryRam
163 SecPpiList
[0].Ppi
= TopOfTemporaryRam
;
167 Caller provided function to be invoked at the end of InitializeDebugAgent().
169 Entry point to the C language phase of SEC. After the SEC assembly
170 code has initialized some temporary memory and set up the stack,
171 the control is transferred to this function.
173 @param[in] Context The first input parameter of InitializeDebugAgent().
182 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
183 EFI_PEI_PPI_DESCRIPTOR
*PpiList
;
185 EFI_PEI_PPI_DESCRIPTOR LocalSecPpiList
[sizeof(mPeiSecMainPpi
)/sizeof(mPeiSecMainPpi
[0])];
186 EFI_PEI_PPI_DESCRIPTOR AllSecPpiList
[FixedPcdGet32(PcdSecCoreMaxPpiSupported
)];
187 EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
;
189 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*) Context
;
191 // Find Pei Core entry point. It will report SEC and Pei Core debug information if remote debug
194 FindAndReportEntryPoints ((EFI_FIRMWARE_VOLUME_HEADER
*) SecCoreData
->BootFirmwareVolumeBase
, &PeiCoreEntryPoint
);
195 if (PeiCoreEntryPoint
== NULL
)
200 CopyMem (LocalSecPpiList
, mPeiSecMainPpi
, sizeof(mPeiSecMainPpi
));
201 PatchTopOfTemporaryRamPpi (LocalSecPpiList
, (VOID
*)((UINTN
)SecCoreData
->TemporaryRamBase
+ SecCoreData
->TemporaryRamSize
));
204 // Perform platform specific initialization before entering PeiCore.
206 PpiList
= SecPlatformMain (SecCoreData
);
207 if (PpiList
!= NULL
) {
209 // Remove the terminal flag from the terminal Ppi
211 CopyMem (AllSecPpiList
, LocalSecPpiList
, sizeof (LocalSecPpiList
));
212 for (Index
= 0; Index
< PcdGet32 (PcdSecCoreMaxPpiSupported
); Index
++) {
213 if ((AllSecPpiList
[Index
].Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) == EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) {
217 AllSecPpiList
[Index
].Flags
= AllSecPpiList
[Index
].Flags
& (~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
220 // Append the platform additional Ppi list
223 while (Index
< PcdGet32 (PcdSecCoreMaxPpiSupported
) &&
224 ((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
)) {
225 CopyMem (&AllSecPpiList
[Index
], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
231 // Check whether the total Ppis exceeds the max supported Ppi.
233 if (Index
>= PcdGet32 (PcdSecCoreMaxPpiSupported
)) {
235 // the total Ppi is larger than the supported Max
236 // PcdSecCoreMaxPpiSupported can be enlarged to solve it.
241 // Add the terminal Ppi
243 CopyMem (&AllSecPpiList
[Index
], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
247 // Set PpiList to the total Ppi
249 PpiList
= &AllSecPpiList
[0];
252 // No addition Ppi, PpiList directly point to the common Ppi list.
254 PpiList
= &LocalSecPpiList
[0];
258 // Transfer the control to the PEI core
260 ASSERT (PeiCoreEntryPoint
!= NULL
);
261 (*PeiCoreEntryPoint
) (SecCoreData
, PpiList
);
264 // Should not come here.
270 Return Hob list produced by FSP.
272 @param[in] PeiServices The pointer to the PEI Services Table.
273 @param[in] This The pointer to this instance of this PPI.
274 @param[out] FspHobList The pointer to Hob list produced by FSP.
276 @return EFI_SUCCESS FReturn Hob list produced by FSP successfully.
280 FspInitDoneGetFspHobList (
281 IN CONST EFI_PEI_SERVICES
**PeiServices
,
282 IN FSP_INIT_DONE_PPI
*This
,
283 OUT VOID
**FspHobList
286 VOID
*TopOfTemporaryRamPpi
;
289 Status
= (*PeiServices
)->LocatePpi (
291 &gTopOfTemporaryRamPpiGuid
,
294 (VOID
**) &TopOfTemporaryRamPpi
296 if (EFI_ERROR (Status
)) {
297 return EFI_NOT_FOUND
;
300 *FspHobList
= (VOID
*)(UINTN
)(*(UINT32
*)((UINTN
)TopOfTemporaryRamPpi
- sizeof(UINT32
)));