4 Copyright (c) 2008 - 2017, 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.
119 IN UINT32 TempRamBase
,
120 IN VOID
*BootFirmwareVolume
123 EFI_SEC_PEI_HAND_OFF SecCoreData
;
124 IA32_DESCRIPTOR IdtDescriptor
;
125 SEC_IDT_TABLE IdtTableInStack
;
131 // Report Status Code to indicate entering SEC core
135 EFI_SOFTWARE_SEC
| EFI_SW_SEC_PC_ENTRY_POINT
138 PeiStackSize
= PcdGet32 (PcdPeiTemporaryRamStackSize
);
139 if (PeiStackSize
== 0) {
140 PeiStackSize
= (SizeOfRam
>> 1);
143 ASSERT (PeiStackSize
< SizeOfRam
);
146 // Process all libraries constructor function linked to SecCore.
148 ProcessLibraryConstructorList ();
151 // Initialize floating point operating environment
152 // to be compliant with UEFI spec.
154 InitializeFloatingPointUnits ();
156 // |-------------------|---->
158 // |-------------------|
159 // |PeiService Pointer | PeiStackSize
160 // |-------------------|
163 // |-------------------|---->
166 // | Heap | PeiTemporayRamSize
169 // |-------------------|----> TempRamBase
171 IdtTableInStack
.PeiService
= 0;
172 for (Index
= 0; Index
< SEC_IDT_ENTRY_COUNT
; Index
++) {
173 CopyMem ((VOID
*)&IdtTableInStack
.IdtTable
[Index
], (VOID
*)&mIdtEntryTemplate
, sizeof (UINT64
));
176 IdtDescriptor
.Base
= (UINTN
) &IdtTableInStack
.IdtTable
;
177 IdtDescriptor
.Limit
= (UINT16
)(sizeof (IdtTableInStack
.IdtTable
) - 1);
179 AsmWriteIdtr (&IdtDescriptor
);
182 // Setup the default exception handlers
184 Status
= InitializeCpuExceptionHandlers (NULL
);
185 ASSERT_EFI_ERROR (Status
);
188 // Update the base address and length of Pei temporary memory
190 SecCoreData
.DataSize
= (UINT16
) sizeof (EFI_SEC_PEI_HAND_OFF
);
191 SecCoreData
.BootFirmwareVolumeBase
= BootFirmwareVolume
;
192 SecCoreData
.BootFirmwareVolumeSize
= (UINTN
)((EFI_FIRMWARE_VOLUME_HEADER
*) BootFirmwareVolume
)->FvLength
;
193 SecCoreData
.TemporaryRamBase
= (VOID
*)(UINTN
) TempRamBase
;
194 SecCoreData
.TemporaryRamSize
= SizeOfRam
;
195 SecCoreData
.PeiTemporaryRamBase
= SecCoreData
.TemporaryRamBase
;
196 SecCoreData
.PeiTemporaryRamSize
= SizeOfRam
- PeiStackSize
;
197 SecCoreData
.StackBase
= (VOID
*)(UINTN
)(TempRamBase
+ SecCoreData
.PeiTemporaryRamSize
);
198 SecCoreData
.StackSize
= PeiStackSize
;
201 // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.
203 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC
, &SecCoreData
, SecStartupPhase2
);
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 SecCoreData
= (EFI_SEC_PEI_HAND_OFF
*) Context
;
230 AllSecPpiList
= (EFI_PEI_PPI_DESCRIPTOR
*) SecCoreData
->PeiTemporaryRamBase
;
232 // Find Pei Core entry point. It will report SEC and Pei Core debug information if remote debug
235 FindAndReportEntryPoints ((EFI_FIRMWARE_VOLUME_HEADER
*) SecCoreData
->BootFirmwareVolumeBase
, &PeiCoreEntryPoint
);
236 if (PeiCoreEntryPoint
== NULL
)
242 // Perform platform specific initialization before entering PeiCore.
244 PpiList
= SecPlatformMain (SecCoreData
);
245 if (PpiList
!= NULL
) {
247 // Remove the terminal flag from the terminal PPI
249 CopyMem (AllSecPpiList
, mPeiSecPlatformInformationPpi
, sizeof (mPeiSecPlatformInformationPpi
));
250 Index
= sizeof (mPeiSecPlatformInformationPpi
) / sizeof (EFI_PEI_PPI_DESCRIPTOR
) - 1;
251 AllSecPpiList
[Index
].Flags
= AllSecPpiList
[Index
].Flags
& (~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
254 // Append the platform additional PPI list
257 while (((PpiList
->Flags
& EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
)) {
258 CopyMem (&AllSecPpiList
[Index
], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
264 // Add the terminal PPI
266 CopyMem (&AllSecPpiList
[Index
++], PpiList
, sizeof (EFI_PEI_PPI_DESCRIPTOR
));
269 // Set PpiList to the total PPI
271 PpiList
= AllSecPpiList
;
274 // Adjust PEI TEMP RAM Range.
276 ASSERT (SecCoreData
->PeiTemporaryRamSize
> Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
));
277 SecCoreData
->PeiTemporaryRamBase
= (VOID
*)((UINTN
) SecCoreData
->PeiTemporaryRamBase
+ Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
));
278 SecCoreData
->PeiTemporaryRamSize
= SecCoreData
->PeiTemporaryRamSize
- Index
* sizeof (EFI_PEI_PPI_DESCRIPTOR
);
280 // Adjust the Base and Size to be 8-byte aligned as HOB which has 8byte aligned requirement
281 // will be built based on them in PEI phase.
283 SecCoreData
->PeiTemporaryRamBase
= (VOID
*)(((UINTN
)SecCoreData
->PeiTemporaryRamBase
+ 7) & ~0x07);
284 SecCoreData
->PeiTemporaryRamSize
&= ~(UINTN
)0x07;
287 // No addition PPI, PpiList directly point to the common PPI list.
289 PpiList
= &mPeiSecPlatformInformationPpi
[0];
294 "%a() Stack Base: 0x%p, Stack Size: 0x%x\n",
296 SecCoreData
->StackBase
,
297 (UINT32
) SecCoreData
->StackSize
301 // Report Status Code to indicate transferring to PEI core
305 EFI_SOFTWARE_SEC
| EFI_SW_SEC_PC_HANDOFF_TO_NEXT
309 // Transfer the control to the PEI core
311 ASSERT (PeiCoreEntryPoint
!= NULL
);
312 (*PeiCoreEntryPoint
) (SecCoreData
, PpiList
);
315 // Should not come here.
321 TemporaryRamDone() disables the use of Temporary RAM. If present, this service is invoked
322 by the PEI Foundation after the EFI_PEI_PERMANANT_MEMORY_INSTALLED_PPI is installed.
324 @retval EFI_SUCCESS Use of Temporary RAM was disabled.
325 @retval EFI_INVALID_PARAMETER Temporary RAM could not be disabled.
330 SecTemporaryRamDone (
337 // Republish Sec Platform Information(2) PPI
339 RepublishSecPlatformInformationPpi ();
342 // Migrate DebugAgentContext.
344 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC
, NULL
, NULL
);
347 // Disable interrupts and save current interrupt state
349 State
= SaveAndDisableInterrupts();
352 // Disable Temporary RAM after Stack and Heap have been migrated at this point.
354 SecPlatformDisableTemporaryMemory ();
357 // Restore original interrupt state
359 SetInterruptState (State
);