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 Migrates the Global Descriptor Table (GDT) to permanent memory.
41 @retval EFI_SUCCESS The GDT was migrated successfully.
42 @retval EFI_OUT_OF_RESOURCES The GDT could not be migrated due to lack of available memory.
55 AsmReadGdtr ((IA32_DESCRIPTOR
*) &Gdtr
);
56 GdtBufferSize
= sizeof (IA32_SEGMENT_DESCRIPTOR
) -1 + Gdtr
.Limit
+ 1;
58 Status
= PeiServicesAllocatePool (
62 ASSERT (GdtBuffer
!= NULL
);
63 if (EFI_ERROR (Status
)) {
64 return EFI_OUT_OF_RESOURCES
;
67 GdtBuffer
= ALIGN_POINTER (GdtBuffer
, sizeof (IA32_SEGMENT_DESCRIPTOR
));
68 CopyMem (GdtBuffer
, (VOID
*) Gdtr
.Base
, Gdtr
.Limit
+ 1);
69 Gdtr
.Base
= (UINTN
) GdtBuffer
;
76 // These are IDT entries pointing to 10:FFFFFFE4h.
78 UINT64 mIdtEntryTemplate
= 0xffff8e000010ffe4ULL
;
81 Caller provided function to be invoked at the end of InitializeDebugAgent().
83 Entry point to the C language phase of SEC. After the SEC assembly
84 code has initialized some temporary memory and set up the stack,
85 the control is transferred to this function.
87 @param[in] Context The first input parameter of InitializeDebugAgent().
98 Entry point of the notification callback function itself within the PEIM.
99 It is to get SEC performance data and build HOB to convey the SEC performance
102 @param PeiServices Indirect reference to the PEI Services Table.
103 @param NotifyDescriptor Address of the notification descriptor data structure.
104 @param Ppi Address of the PPI that was installed.
106 @return Status of the notification.
107 The status code returned from this function is ignored.
111 SecPerformancePpiCallBack (
112 IN EFI_PEI_SERVICES
**PeiServices
,
113 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
118 PEI_SEC_PERFORMANCE_PPI
*SecPerf
;
119 FIRMWARE_SEC_PERFORMANCE Performance
;
121 SecPerf
= (PEI_SEC_PERFORMANCE_PPI
*) Ppi
;
122 Status
= SecPerf
->GetPerformance ((CONST EFI_PEI_SERVICES
**) PeiServices
, SecPerf
, &Performance
);
123 if (!EFI_ERROR (Status
)) {
125 &gEfiFirmwarePerformanceGuid
,
127 sizeof (FIRMWARE_SEC_PERFORMANCE
)
129 DEBUG ((DEBUG_INFO
, "FPDT: SEC Performance Hob ResetEnd = %ld\n", Performance
.ResetEnd
));
137 Entry point to the C language phase of SEC. After the SEC assembly
138 code has initialized some temporary memory and set up the stack,
139 the control is transferred to this function.
142 @param SizeOfRam Size of the temporary memory available for use.
143 @param TempRamBase Base address of temporary ram
144 @param BootFirmwareVolume Base address of the Boot Firmware Volume.
151 IN UINT32 TempRamBase
,
152 IN VOID
*BootFirmwareVolume
155 EFI_SEC_PEI_HAND_OFF SecCoreData
;
156 IA32_DESCRIPTOR IdtDescriptor
;
157 SEC_IDT_TABLE IdtTableInStack
;
163 // Report Status Code to indicate entering SEC core
167 EFI_SOFTWARE_SEC
| EFI_SW_SEC_PC_ENTRY_POINT
170 PeiStackSize
= PcdGet32 (PcdPeiTemporaryRamStackSize
);
171 if (PeiStackSize
== 0) {
172 PeiStackSize
= (SizeOfRam
>> 1);
175 ASSERT (PeiStackSize
< SizeOfRam
);
178 // Process all libraries constructor function linked to SecCore.
180 ProcessLibraryConstructorList ();
183 // Initialize floating point operating environment
184 // to be compliant with UEFI spec.
186 InitializeFloatingPointUnits ();
188 // |-------------------|---->
190 // |-------------------|
191 // |PeiService Pointer | PeiStackSize
192 // |-------------------|
195 // |-------------------|---->
198 // | Heap | PeiTemporayRamSize
201 // |-------------------|----> TempRamBase
203 IdtTableInStack
.PeiService
= 0;
204 for (Index
= 0; Index
< SEC_IDT_ENTRY_COUNT
; Index
++) {
205 CopyMem ((VOID
*)&IdtTableInStack
.IdtTable
[Index
], (VOID
*)&mIdtEntryTemplate
, sizeof (UINT64
));
208 IdtDescriptor
.Base
= (UINTN
) &IdtTableInStack
.IdtTable
;
209 IdtDescriptor
.Limit
= (UINT16
)(sizeof (IdtTableInStack
.IdtTable
) - 1);
211 AsmWriteIdtr (&IdtDescriptor
);
214 // Setup the default exception handlers
216 Status
= InitializeCpuExceptionHandlers (NULL
);
217 ASSERT_EFI_ERROR (Status
);
220 // Update the base address and length of Pei temporary memory
222 SecCoreData
.DataSize
= (UINT16
) sizeof (EFI_SEC_PEI_HAND_OFF
);
223 SecCoreData
.BootFirmwareVolumeBase
= BootFirmwareVolume
;
224 SecCoreData
.BootFirmwareVolumeSize
= (UINTN
)((EFI_FIRMWARE_VOLUME_HEADER
*) BootFirmwareVolume
)->FvLength
;
225 SecCoreData
.TemporaryRamBase
= (VOID
*)(UINTN
) TempRamBase
;
226 SecCoreData
.TemporaryRamSize
= SizeOfRam
;
227 SecCoreData
.PeiTemporaryRamBase
= SecCoreData
.TemporaryRamBase
;
228 SecCoreData
.PeiTemporaryRamSize
= SizeOfRam
- PeiStackSize
;
229 SecCoreData
.StackBase
= (VOID
*)(UINTN
)(TempRamBase
+ SecCoreData
.PeiTemporaryRamSize
);
230 SecCoreData
.StackSize
= PeiStackSize
;
233 // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.
235 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC
, &SecCoreData
, SecStartupPhase2
);
238 // Should not come here.
244 Caller provided function to be invoked at the end of InitializeDebugAgent().
246 Entry point to the C language phase of SEC. After the SEC assembly
247 code has initialized some temporary memory and set up the stack,
248 the control is transferred to this function.
250 @param[in] Context The first input parameter of InitializeDebugAgent().
260 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
261 EFI_PEI_PPI_DESCRIPTOR
*PpiList
;
263 EFI_PEI_PPI_DESCRIPTOR
*AllSecPpiList
;
264 EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
;
266 PeiCoreEntryPoint
= NULL
;
267 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*) Context
;
270 // Perform platform specific initialization before entering PeiCore.
272 PpiList
= SecPlatformMain (SecCoreData
);
274 // Find Pei Core entry point. It will report SEC and Pei Core debug information if remote debug
277 if (PpiList
!= NULL
) {
280 if (CompareGuid (PpiList
[Index
].Guid
, &gEfiPeiCoreFvLocationPpiGuid
) &&
281 (((EFI_PEI_CORE_FV_LOCATION_PPI
*) PpiList
[Index
].Ppi
)->PeiCoreFvLocation
!= 0)
284 // In this case, SecCore is in BFV but PeiCore is in another FV reported by PPI.
286 FindAndReportEntryPoints (
287 (EFI_FIRMWARE_VOLUME_HEADER
*) SecCoreData
->BootFirmwareVolumeBase
,
288 (EFI_FIRMWARE_VOLUME_HEADER
*) ((EFI_PEI_CORE_FV_LOCATION_PPI
*) PpiList
[Index
].Ppi
)->PeiCoreFvLocation
,
291 if (PeiCoreEntryPoint
!= NULL
) {
295 // Invalid PeiCore FV provided by platform
300 } while ((PpiList
[Index
++].Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
303 // If EFI_PEI_CORE_FV_LOCATION_PPI not found, try to locate PeiCore from BFV.
305 if (PeiCoreEntryPoint
== NULL
) {
307 // Both SecCore and PeiCore are in BFV.
309 FindAndReportEntryPoints (
310 (EFI_FIRMWARE_VOLUME_HEADER
*) SecCoreData
->BootFirmwareVolumeBase
,
311 (EFI_FIRMWARE_VOLUME_HEADER
*) SecCoreData
->BootFirmwareVolumeBase
,
314 if (PeiCoreEntryPoint
== NULL
) {
319 if (PpiList
!= NULL
) {
320 AllSecPpiList
= (EFI_PEI_PPI_DESCRIPTOR
*) SecCoreData
->PeiTemporaryRamBase
;
323 // Remove the terminal flag from the terminal PPI
325 CopyMem (AllSecPpiList
, mPeiSecPlatformInformationPpi
, sizeof (mPeiSecPlatformInformationPpi
));
326 Index
= sizeof (mPeiSecPlatformInformationPpi
) / sizeof (EFI_PEI_PPI_DESCRIPTOR
) - 1;
327 AllSecPpiList
[Index
].Flags
= AllSecPpiList
[Index
].Flags
& (~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
330 // Append the platform additional PPI list
333 while (((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
)) {
334 CopyMem (&AllSecPpiList
[Index
], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
340 // Add the terminal PPI
342 CopyMem (&AllSecPpiList
[Index
++], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
345 // Set PpiList to the total PPI
347 PpiList
= AllSecPpiList
;
350 // Adjust PEI TEMP RAM Range.
352 ASSERT (SecCoreData
->PeiTemporaryRamSize
> Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
));
353 SecCoreData
->PeiTemporaryRamBase
= (VOID
*)((UINTN
) SecCoreData
->PeiTemporaryRamBase
+ Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
));
354 SecCoreData
->PeiTemporaryRamSize
= SecCoreData
->PeiTemporaryRamSize
- Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
);
356 // Adjust the Base and Size to be 8-byte aligned as HOB which has 8byte aligned requirement
357 // will be built based on them in PEI phase.
359 SecCoreData
->PeiTemporaryRamBase
= (VOID
*)(((UINTN
)SecCoreData
->PeiTemporaryRamBase
+ 7) & ~0x07);
360 SecCoreData
->PeiTemporaryRamSize
&= ~(UINTN
)0x07;
363 // No addition PPI, PpiList directly point to the common PPI list.
365 PpiList
= &mPeiSecPlatformInformationPpi
[0];
370 "%a() Stack Base: 0x%p, Stack Size: 0x%x\n",
372 SecCoreData
->StackBase
,
373 (UINT32
) SecCoreData
->StackSize
377 // Report Status Code to indicate transferring to PEI core
381 EFI_SOFTWARE_SEC
| EFI_SW_SEC_PC_HANDOFF_TO_NEXT
385 // Transfer the control to the PEI core
387 ASSERT (PeiCoreEntryPoint
!= NULL
);
388 (*PeiCoreEntryPoint
) (SecCoreData
, PpiList
);
391 // Should not come here.
397 TemporaryRamDone() disables the use of Temporary RAM. If present, this service is invoked
398 by the PEI Foundation after the EFI_PEI_PERMANANT_MEMORY_INSTALLED_PPI is installed.
400 @retval EFI_SUCCESS Use of Temporary RAM was disabled.
401 @retval EFI_INVALID_PARAMETER Temporary RAM could not be disabled.
406 SecTemporaryRamDone (
414 EFI_PEI_PPI_DESCRIPTOR
*PeiPpiDescriptor
;
415 REPUBLISH_SEC_PPI_PPI
*RepublishSecPpiPpi
;
418 // Republish Sec Platform Information(2) PPI
420 RepublishSecPlatformInformationPpi ();
423 // Re-install SEC PPIs using a PEIM produced service if published
425 for (Index
= 0, Status
= EFI_SUCCESS
; Status
== EFI_SUCCESS
; Index
++) {
426 Status
= PeiServicesLocatePpi (
427 &gRepublishSecPpiPpiGuid
,
430 (VOID
**) &RepublishSecPpiPpi
432 if (!EFI_ERROR (Status
)) {
433 DEBUG ((DEBUG_INFO
, "Calling RepublishSecPpi instance %d.\n", Index
));
434 Status2
= RepublishSecPpiPpi
->RepublishSecPpis ();
435 ASSERT_EFI_ERROR (Status2
);
440 // Migrate DebugAgentContext.
442 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, NULL
, NULL
);
445 // Disable interrupts and save current interrupt state
447 State
= SaveAndDisableInterrupts ();
450 // Migrate GDT before NEM near down
452 if (PcdGetBool (PcdMigrateTemporaryRamFirmwareVolumes
)) {
453 Status
= MigrateGdt ();
454 ASSERT_EFI_ERROR (Status
);
458 // Disable Temporary RAM after Stack and Heap have been migrated at this point.
460 SecPlatformDisableTemporaryMemory ();
463 // Restore original interrupt state
465 SetInterruptState (State
);