4 Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 EFI_PEI_TEMPORARY_RAM_DONE_PPI gSecTemporaryRamDonePpi
= {
15 EFI_SEC_PLATFORM_INFORMATION_PPI mSecPlatformInformationPpi
= { SecPlatformInformation
};
17 EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformationPpi
[] = {
20 // SecPerformance PPI notify descriptor.
22 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
23 &gPeiSecPerformancePpiGuid
,
24 (VOID
*) (UINTN
) SecPerformancePpiCallBack
27 EFI_PEI_PPI_DESCRIPTOR_PPI
,
28 &gEfiTemporaryRamDonePpiGuid
,
29 &gSecTemporaryRamDonePpi
32 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
33 &gEfiSecPlatformInformationPpiGuid
,
34 &mSecPlatformInformationPpi
39 // These are IDT entries pointing to 10:FFFFFFE4h.
41 UINT64 mIdtEntryTemplate
= 0xffff8e000010ffe4ULL
;
44 Caller provided function to be invoked at the end of InitializeDebugAgent().
46 Entry point to the C language phase of SEC. After the SEC assembly
47 code has initialized some temporary memory and set up the stack,
48 the control is transferred to this function.
50 @param[in] Context The first input parameter of InitializeDebugAgent().
61 Entry point of the notification callback function itself within the PEIM.
62 It is to get SEC performance data and build HOB to convey the SEC performance
65 @param PeiServices Indirect reference to the PEI Services Table.
66 @param NotifyDescriptor Address of the notification descriptor data structure.
67 @param Ppi Address of the PPI that was installed.
69 @return Status of the notification.
70 The status code returned from this function is ignored.
74 SecPerformancePpiCallBack (
75 IN EFI_PEI_SERVICES
**PeiServices
,
76 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
81 PEI_SEC_PERFORMANCE_PPI
*SecPerf
;
82 FIRMWARE_SEC_PERFORMANCE Performance
;
84 SecPerf
= (PEI_SEC_PERFORMANCE_PPI
*) Ppi
;
85 Status
= SecPerf
->GetPerformance ((CONST EFI_PEI_SERVICES
**) PeiServices
, SecPerf
, &Performance
);
86 if (!EFI_ERROR (Status
)) {
88 &gEfiFirmwarePerformanceGuid
,
90 sizeof (FIRMWARE_SEC_PERFORMANCE
)
92 DEBUG ((DEBUG_INFO
, "FPDT: SEC Performance Hob ResetEnd = %ld\n", Performance
.ResetEnd
));
100 Entry point to the C language phase of SEC. After the SEC assembly
101 code has initialized some temporary memory and set up the stack,
102 the control is transferred to this function.
105 @param SizeOfRam Size of the temporary memory available for use.
106 @param TempRamBase Base address of temporary ram
107 @param BootFirmwareVolume Base address of the Boot Firmware Volume.
114 IN UINT32 TempRamBase
,
115 IN VOID
*BootFirmwareVolume
118 EFI_SEC_PEI_HAND_OFF SecCoreData
;
119 IA32_DESCRIPTOR IdtDescriptor
;
120 SEC_IDT_TABLE IdtTableInStack
;
126 // Report Status Code to indicate entering SEC core
130 EFI_SOFTWARE_SEC
| EFI_SW_SEC_PC_ENTRY_POINT
133 PeiStackSize
= PcdGet32 (PcdPeiTemporaryRamStackSize
);
134 if (PeiStackSize
== 0) {
135 PeiStackSize
= (SizeOfRam
>> 1);
138 ASSERT (PeiStackSize
< SizeOfRam
);
141 // Process all libraries constructor function linked to SecCore.
143 ProcessLibraryConstructorList ();
146 // Initialize floating point operating environment
147 // to be compliant with UEFI spec.
149 InitializeFloatingPointUnits ();
151 // |-------------------|---->
153 // |-------------------|
154 // |PeiService Pointer | PeiStackSize
155 // |-------------------|
158 // |-------------------|---->
161 // | Heap | PeiTemporayRamSize
164 // |-------------------|----> TempRamBase
166 IdtTableInStack
.PeiService
= 0;
167 for (Index
= 0; Index
< SEC_IDT_ENTRY_COUNT
; Index
++) {
168 CopyMem ((VOID
*)&IdtTableInStack
.IdtTable
[Index
], (VOID
*)&mIdtEntryTemplate
, sizeof (UINT64
));
171 IdtDescriptor
.Base
= (UINTN
) &IdtTableInStack
.IdtTable
;
172 IdtDescriptor
.Limit
= (UINT16
)(sizeof (IdtTableInStack
.IdtTable
) - 1);
174 AsmWriteIdtr (&IdtDescriptor
);
177 // Setup the default exception handlers
179 Status
= InitializeCpuExceptionHandlers (NULL
);
180 ASSERT_EFI_ERROR (Status
);
183 // Update the base address and length of Pei temporary memory
185 SecCoreData
.DataSize
= (UINT16
) sizeof (EFI_SEC_PEI_HAND_OFF
);
186 SecCoreData
.BootFirmwareVolumeBase
= BootFirmwareVolume
;
187 SecCoreData
.BootFirmwareVolumeSize
= (UINTN
)((EFI_FIRMWARE_VOLUME_HEADER
*) BootFirmwareVolume
)->FvLength
;
188 SecCoreData
.TemporaryRamBase
= (VOID
*)(UINTN
) TempRamBase
;
189 SecCoreData
.TemporaryRamSize
= SizeOfRam
;
190 SecCoreData
.PeiTemporaryRamBase
= SecCoreData
.TemporaryRamBase
;
191 SecCoreData
.PeiTemporaryRamSize
= SizeOfRam
- PeiStackSize
;
192 SecCoreData
.StackBase
= (VOID
*)(UINTN
)(TempRamBase
+ SecCoreData
.PeiTemporaryRamSize
);
193 SecCoreData
.StackSize
= PeiStackSize
;
196 // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.
198 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC
, &SecCoreData
, SecStartupPhase2
);
201 // Should not come here.
207 Caller provided function to be invoked at the end of InitializeDebugAgent().
209 Entry point to the C language phase of SEC. After the SEC assembly
210 code has initialized some temporary memory and set up the stack,
211 the control is transferred to this function.
213 @param[in] Context The first input parameter of InitializeDebugAgent().
223 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
224 EFI_PEI_PPI_DESCRIPTOR
*PpiList
;
226 EFI_PEI_PPI_DESCRIPTOR
*AllSecPpiList
;
227 EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
;
229 PeiCoreEntryPoint
= NULL
;
230 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*) Context
;
231 AllSecPpiList
= (EFI_PEI_PPI_DESCRIPTOR
*) SecCoreData
->PeiTemporaryRamBase
;
234 // Perform platform specific initialization before entering PeiCore.
236 PpiList
= SecPlatformMain (SecCoreData
);
238 // Find Pei Core entry point. It will report SEC and Pei Core debug information if remote debug
241 if (PpiList
!= NULL
) {
243 (PpiList
[Index
].Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
;
245 if (CompareGuid (PpiList
[Index
].Guid
, &gEfiPeiCoreFvLocationPpiGuid
) &&
246 (((EFI_PEI_CORE_FV_LOCATION_PPI
*) PpiList
[Index
].Ppi
)->PeiCoreFvLocation
!= 0)
249 // In this case, SecCore is in BFV but PeiCore is in another FV reported by PPI.
251 FindAndReportEntryPoints (
252 (EFI_FIRMWARE_VOLUME_HEADER
*) SecCoreData
->BootFirmwareVolumeBase
,
253 (EFI_FIRMWARE_VOLUME_HEADER
*) ((EFI_PEI_CORE_FV_LOCATION_PPI
*) PpiList
[Index
].Ppi
)->PeiCoreFvLocation
,
256 if (PeiCoreEntryPoint
!= NULL
) {
268 // If EFI_PEI_CORE_FV_LOCATION_PPI not found, try to locate PeiCore from BFV.
270 if (PeiCoreEntryPoint
== NULL
) {
272 // Both SecCore and PeiCore are in BFV.
274 FindAndReportEntryPoints (
275 (EFI_FIRMWARE_VOLUME_HEADER
*) SecCoreData
->BootFirmwareVolumeBase
,
276 (EFI_FIRMWARE_VOLUME_HEADER
*) SecCoreData
->BootFirmwareVolumeBase
,
279 if (PeiCoreEntryPoint
== NULL
) {
284 if (PpiList
!= NULL
) {
286 // Remove the terminal flag from the terminal PPI
288 CopyMem (AllSecPpiList
, mPeiSecPlatformInformationPpi
, sizeof (mPeiSecPlatformInformationPpi
));
289 Index
= sizeof (mPeiSecPlatformInformationPpi
) / sizeof (EFI_PEI_PPI_DESCRIPTOR
) - 1;
290 AllSecPpiList
[Index
].Flags
= AllSecPpiList
[Index
].Flags
& (~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
293 // Append the platform additional PPI list
296 while (((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
)) {
297 CopyMem (&AllSecPpiList
[Index
], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
303 // Add the terminal PPI
305 CopyMem (&AllSecPpiList
[Index
++], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
308 // Set PpiList to the total PPI
310 PpiList
= AllSecPpiList
;
313 // Adjust PEI TEMP RAM Range.
315 ASSERT (SecCoreData
->PeiTemporaryRamSize
> Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
));
316 SecCoreData
->PeiTemporaryRamBase
= (VOID
*)((UINTN
) SecCoreData
->PeiTemporaryRamBase
+ Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
));
317 SecCoreData
->PeiTemporaryRamSize
= SecCoreData
->PeiTemporaryRamSize
- Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
);
319 // Adjust the Base and Size to be 8-byte aligned as HOB which has 8byte aligned requirement
320 // will be built based on them in PEI phase.
322 SecCoreData
->PeiTemporaryRamBase
= (VOID
*)(((UINTN
)SecCoreData
->PeiTemporaryRamBase
+ 7) & ~0x07);
323 SecCoreData
->PeiTemporaryRamSize
&= ~(UINTN
)0x07;
326 // No addition PPI, PpiList directly point to the common PPI list.
328 PpiList
= &mPeiSecPlatformInformationPpi
[0];
333 "%a() Stack Base: 0x%p, Stack Size: 0x%x\n",
335 SecCoreData
->StackBase
,
336 (UINT32
) SecCoreData
->StackSize
340 // Report Status Code to indicate transferring to PEI core
344 EFI_SOFTWARE_SEC
| EFI_SW_SEC_PC_HANDOFF_TO_NEXT
348 // Transfer the control to the PEI core
350 ASSERT (PeiCoreEntryPoint
!= NULL
);
351 (*PeiCoreEntryPoint
) (SecCoreData
, PpiList
);
354 // Should not come here.
360 TemporaryRamDone() disables the use of Temporary RAM. If present, this service is invoked
361 by the PEI Foundation after the EFI_PEI_PERMANANT_MEMORY_INSTALLED_PPI is installed.
363 @retval EFI_SUCCESS Use of Temporary RAM was disabled.
364 @retval EFI_INVALID_PARAMETER Temporary RAM could not be disabled.
369 SecTemporaryRamDone (
376 // Republish Sec Platform Information(2) PPI
378 RepublishSecPlatformInformationPpi ();
381 // Migrate DebugAgentContext.
383 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, NULL
, NULL
);
386 // Disable interrupts and save current interrupt state
388 State
= SaveAndDisableInterrupts();
391 // Disable Temporary RAM after Stack and Heap have been migrated at this point.
393 SecPlatformDisableTemporaryMemory ();
396 // Restore original interrupt state
398 SetInterruptState (State
);