4 Copyright (c) 2008 - 2019, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 EFI_PEI_TEMPORARY_RAM_DONE_PPI gSecTemporaryRamDonePpi
= {
21 EFI_SEC_PLATFORM_INFORMATION_PPI mSecPlatformInformationPpi
= { SecPlatformInformation
};
23 EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformationPpi
[] = {
26 // SecPerformance PPI notify descriptor.
28 EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK
,
29 &gPeiSecPerformancePpiGuid
,
30 (VOID
*) (UINTN
) SecPerformancePpiCallBack
33 EFI_PEI_PPI_DESCRIPTOR_PPI
,
34 &gEfiTemporaryRamDonePpiGuid
,
35 &gSecTemporaryRamDonePpi
38 (EFI_PEI_PPI_DESCRIPTOR_PPI
| EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
),
39 &gEfiSecPlatformInformationPpiGuid
,
40 &mSecPlatformInformationPpi
45 // These are IDT entries pointing to 10:FFFFFFE4h.
47 UINT64 mIdtEntryTemplate
= 0xffff8e000010ffe4ULL
;
50 Caller provided function to be invoked at the end of InitializeDebugAgent().
52 Entry point to the C language phase of SEC. After the SEC assembly
53 code has initialized some temporary memory and set up the stack,
54 the control is transferred to this function.
56 @param[in] Context The first input parameter of InitializeDebugAgent().
67 Entry point of the notification callback function itself within the PEIM.
68 It is to get SEC performance data and build HOB to convey the SEC performance
71 @param PeiServices Indirect reference to the PEI Services Table.
72 @param NotifyDescriptor Address of the notification descriptor data structure.
73 @param Ppi Address of the PPI that was installed.
75 @return Status of the notification.
76 The status code returned from this function is ignored.
80 SecPerformancePpiCallBack (
81 IN EFI_PEI_SERVICES
**PeiServices
,
82 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDescriptor
,
87 PEI_SEC_PERFORMANCE_PPI
*SecPerf
;
88 FIRMWARE_SEC_PERFORMANCE Performance
;
90 SecPerf
= (PEI_SEC_PERFORMANCE_PPI
*) Ppi
;
91 Status
= SecPerf
->GetPerformance ((CONST EFI_PEI_SERVICES
**) PeiServices
, SecPerf
, &Performance
);
92 if (!EFI_ERROR (Status
)) {
94 &gEfiFirmwarePerformanceGuid
,
96 sizeof (FIRMWARE_SEC_PERFORMANCE
)
98 DEBUG ((DEBUG_INFO
, "FPDT: SEC Performance Hob ResetEnd = %ld\n", Performance
.ResetEnd
));
106 Entry point to the C language phase of SEC. After the SEC assembly
107 code has initialized some temporary memory and set up the stack,
108 the control is transferred to this function.
111 @param SizeOfRam Size of the temporary memory available for use.
112 @param TempRamBase Base address of temporary ram
113 @param BootFirmwareVolume Base address of the Boot Firmware Volume.
120 IN UINT32 TempRamBase
,
121 IN VOID
*BootFirmwareVolume
124 EFI_SEC_PEI_HAND_OFF SecCoreData
;
125 IA32_DESCRIPTOR IdtDescriptor
;
126 SEC_IDT_TABLE IdtTableInStack
;
132 // Report Status Code to indicate entering SEC core
136 EFI_SOFTWARE_SEC
| EFI_SW_SEC_PC_ENTRY_POINT
139 PeiStackSize
= PcdGet32 (PcdPeiTemporaryRamStackSize
);
140 if (PeiStackSize
== 0) {
141 PeiStackSize
= (SizeOfRam
>> 1);
144 ASSERT (PeiStackSize
< SizeOfRam
);
147 // Process all libraries constructor function linked to SecCore.
149 ProcessLibraryConstructorList ();
152 // Initialize floating point operating environment
153 // to be compliant with UEFI spec.
155 InitializeFloatingPointUnits ();
157 // |-------------------|---->
159 // |-------------------|
160 // |PeiService Pointer | PeiStackSize
161 // |-------------------|
164 // |-------------------|---->
167 // | Heap | PeiTemporayRamSize
170 // |-------------------|----> TempRamBase
172 IdtTableInStack
.PeiService
= 0;
173 for (Index
= 0; Index
< SEC_IDT_ENTRY_COUNT
; Index
++) {
174 CopyMem ((VOID
*)&IdtTableInStack
.IdtTable
[Index
], (VOID
*)&mIdtEntryTemplate
, sizeof (UINT64
));
177 IdtDescriptor
.Base
= (UINTN
) &IdtTableInStack
.IdtTable
;
178 IdtDescriptor
.Limit
= (UINT16
)(sizeof (IdtTableInStack
.IdtTable
) - 1);
180 AsmWriteIdtr (&IdtDescriptor
);
183 // Setup the default exception handlers
185 Status
= InitializeCpuExceptionHandlers (NULL
);
186 ASSERT_EFI_ERROR (Status
);
189 // Update the base address and length of Pei temporary memory
191 SecCoreData
.DataSize
= (UINT16
) sizeof (EFI_SEC_PEI_HAND_OFF
);
192 SecCoreData
.BootFirmwareVolumeBase
= BootFirmwareVolume
;
193 SecCoreData
.BootFirmwareVolumeSize
= (UINTN
)((EFI_FIRMWARE_VOLUME_HEADER
*) BootFirmwareVolume
)->FvLength
;
194 SecCoreData
.TemporaryRamBase
= (VOID
*)(UINTN
) TempRamBase
;
195 SecCoreData
.TemporaryRamSize
= SizeOfRam
;
196 SecCoreData
.PeiTemporaryRamBase
= SecCoreData
.TemporaryRamBase
;
197 SecCoreData
.PeiTemporaryRamSize
= SizeOfRam
- PeiStackSize
;
198 SecCoreData
.StackBase
= (VOID
*)(UINTN
)(TempRamBase
+ SecCoreData
.PeiTemporaryRamSize
);
199 SecCoreData
.StackSize
= PeiStackSize
;
202 // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.
204 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC
, &SecCoreData
, SecStartupPhase2
);
207 // Should not come here.
213 Caller provided function to be invoked at the end of InitializeDebugAgent().
215 Entry point to the C language phase of SEC. After the SEC assembly
216 code has initialized some temporary memory and set up the stack,
217 the control is transferred to this function.
219 @param[in] Context The first input parameter of InitializeDebugAgent().
229 EFI_SEC_PEI_HAND_OFF
*SecCoreData
;
230 EFI_PEI_PPI_DESCRIPTOR
*PpiList
;
232 EFI_PEI_PPI_DESCRIPTOR
*AllSecPpiList
;
233 EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint
;
235 PeiCoreEntryPoint
= NULL
;
236 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*) Context
;
237 AllSecPpiList
= (EFI_PEI_PPI_DESCRIPTOR
*) SecCoreData
->PeiTemporaryRamBase
;
240 // Perform platform specific initialization before entering PeiCore.
242 PpiList
= SecPlatformMain (SecCoreData
);
244 // Find Pei Core entry point. It will report SEC and Pei Core debug information if remote debug
247 if (PpiList
!= NULL
) {
249 (PpiList
[Index
].Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
;
251 if (CompareGuid (PpiList
[Index
].Guid
, &gEfiPeiCoreFvLocationPpiGuid
) && (((EFI_PEI_CORE_FV_LOCATION_PPI
*) PpiList
[Index
].Ppi
)->PeiCoreFvLocation
!= 0)) {
252 FindAndReportEntryPoints ((EFI_FIRMWARE_VOLUME_HEADER
*) ((EFI_PEI_CORE_FV_LOCATION_PPI
*) PpiList
[Index
].Ppi
)->PeiCoreFvLocation
, &PeiCoreEntryPoint
);
253 if (PeiCoreEntryPoint
!= NULL
) {
265 // If EFI_PEI_CORE_FV_LOCATION_PPI not found, try to locate PeiCore from BFV.
267 if (PeiCoreEntryPoint
== NULL
) {
268 FindAndReportEntryPoints ((EFI_FIRMWARE_VOLUME_HEADER
*) SecCoreData
->BootFirmwareVolumeBase
, &PeiCoreEntryPoint
);
269 if (PeiCoreEntryPoint
== NULL
) {
274 if (PpiList
!= NULL
) {
276 // Remove the terminal flag from the terminal PPI
278 CopyMem (AllSecPpiList
, mPeiSecPlatformInformationPpi
, sizeof (mPeiSecPlatformInformationPpi
));
279 Index
= sizeof (mPeiSecPlatformInformationPpi
) / sizeof (EFI_PEI_PPI_DESCRIPTOR
) - 1;
280 AllSecPpiList
[Index
].Flags
= AllSecPpiList
[Index
].Flags
& (~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
283 // Append the platform additional PPI list
286 while (((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
)) {
287 CopyMem (&AllSecPpiList
[Index
], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
293 // Add the terminal PPI
295 CopyMem (&AllSecPpiList
[Index
++], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
298 // Set PpiList to the total PPI
300 PpiList
= AllSecPpiList
;
303 // Adjust PEI TEMP RAM Range.
305 ASSERT (SecCoreData
->PeiTemporaryRamSize
> Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
));
306 SecCoreData
->PeiTemporaryRamBase
= (VOID
*)((UINTN
) SecCoreData
->PeiTemporaryRamBase
+ Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
));
307 SecCoreData
->PeiTemporaryRamSize
= SecCoreData
->PeiTemporaryRamSize
- Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
);
309 // Adjust the Base and Size to be 8-byte aligned as HOB which has 8byte aligned requirement
310 // will be built based on them in PEI phase.
312 SecCoreData
->PeiTemporaryRamBase
= (VOID
*)(((UINTN
)SecCoreData
->PeiTemporaryRamBase
+ 7) & ~0x07);
313 SecCoreData
->PeiTemporaryRamSize
&= ~(UINTN
)0x07;
316 // No addition PPI, PpiList directly point to the common PPI list.
318 PpiList
= &mPeiSecPlatformInformationPpi
[0];
323 "%a() Stack Base: 0x%p, Stack Size: 0x%x\n",
325 SecCoreData
->StackBase
,
326 (UINT32
) SecCoreData
->StackSize
330 // Report Status Code to indicate transferring to PEI core
334 EFI_SOFTWARE_SEC
| EFI_SW_SEC_PC_HANDOFF_TO_NEXT
338 // Transfer the control to the PEI core
340 ASSERT (PeiCoreEntryPoint
!= NULL
);
341 (*PeiCoreEntryPoint
) (SecCoreData
, PpiList
);
344 // Should not come here.
350 TemporaryRamDone() disables the use of Temporary RAM. If present, this service is invoked
351 by the PEI Foundation after the EFI_PEI_PERMANANT_MEMORY_INSTALLED_PPI is installed.
353 @retval EFI_SUCCESS Use of Temporary RAM was disabled.
354 @retval EFI_INVALID_PARAMETER Temporary RAM could not be disabled.
359 SecTemporaryRamDone (
366 // Republish Sec Platform Information(2) PPI
368 RepublishSecPlatformInformationPpi ();
371 // Migrate DebugAgentContext.
373 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, NULL
, NULL
);
376 // Disable interrupts and save current interrupt state
378 State
= SaveAndDisableInterrupts();
381 // Disable Temporary RAM after Stack and Heap have been migrated at this point.
383 SecPlatformDisableTemporaryMemory ();
386 // Restore original interrupt state
388 SetInterruptState (State
);