]> git.proxmox.com Git - mirror_edk2.git/blame - UefiCpuPkg/SecCore/SecMain.c
UefiCpuPkg/SecCore: Abstract worker function GetBistFromHob()
[mirror_edk2.git] / UefiCpuPkg / SecCore / SecMain.c
CommitLineData
1921695e
MK
1/** @file\r
2 C functions in SEC\r
3\r
4 Copyright (c) 2008 - 2015, Intel Corporation. All rights reserved.<BR>\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "SecMain.h"\r
16\r
17EFI_PEI_TEMPORARY_RAM_DONE_PPI gSecTemporaryRamDonePpi = {\r
18 SecTemporaryRamDone\r
19};\r
20\r
21EFI_SEC_PLATFORM_INFORMATION_PPI mSecPlatformInformationPpi = { SecPlatformInformation };\r
22\r
23EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformationPpi[] = {\r
24 {\r
25 EFI_PEI_PPI_DESCRIPTOR_PPI,\r
26 &gEfiTemporaryRamDonePpiGuid,\r
27 &gSecTemporaryRamDonePpi\r
28 },\r
29 {\r
30 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
31 &gEfiSecPlatformInformationPpiGuid,\r
32 &mSecPlatformInformationPpi\r
33 }\r
34};\r
35\r
36//\r
37// These are IDT entries pointing to 10:FFFFFFE4h.\r
38//\r
39UINT64 mIdtEntryTemplate = 0xffff8e000010ffe4ULL;\r
40\r
41/**\r
42 Caller provided function to be invoked at the end of InitializeDebugAgent().\r
43\r
44 Entry point to the C language phase of SEC. After the SEC assembly\r
45 code has initialized some temporary memory and set up the stack,\r
46 the control is transferred to this function.\r
47\r
48 @param[in] Context The first input parameter of InitializeDebugAgent().\r
49\r
50**/\r
51VOID\r
61257251 52NORETURN\r
1921695e
MK
53EFIAPI\r
54SecStartupPhase2(\r
55 IN VOID *Context\r
56 );\r
57\r
58/**\r
59\r
60 Entry point to the C language phase of SEC. After the SEC assembly\r
61 code has initialized some temporary memory and set up the stack,\r
62 the control is transferred to this function.\r
63\r
64\r
65 @param SizeOfRam Size of the temporary memory available for use.\r
66 @param TempRamBase Base address of temporary ram\r
67 @param BootFirmwareVolume Base address of the Boot Firmware Volume.\r
68**/\r
69VOID\r
70EFIAPI\r
71SecStartup (\r
72 IN UINT32 SizeOfRam,\r
73 IN UINT32 TempRamBase,\r
74 IN VOID *BootFirmwareVolume\r
75 )\r
76{\r
77 EFI_SEC_PEI_HAND_OFF SecCoreData;\r
78 IA32_DESCRIPTOR IdtDescriptor;\r
79 SEC_IDT_TABLE IdtTableInStack;\r
80 UINT32 Index;\r
81 UINT32 PeiStackSize;\r
82 EFI_STATUS Status;\r
83\r
84 //\r
85 // Report Status Code to indicate entering SEC core\r
86 //\r
87 REPORT_STATUS_CODE (\r
88 EFI_PROGRESS_CODE,\r
89 EFI_SOFTWARE_SEC | EFI_SW_SEC_PC_ENTRY_POINT\r
90 );\r
91\r
92 PeiStackSize = PcdGet32 (PcdPeiTemporaryRamStackSize);\r
93 if (PeiStackSize == 0) {\r
94 PeiStackSize = (SizeOfRam >> 1);\r
95 }\r
96\r
97 ASSERT (PeiStackSize < SizeOfRam);\r
98\r
99 //\r
100 // Process all libraries constructor function linked to SecCore.\r
101 //\r
102 ProcessLibraryConstructorList ();\r
103\r
104 //\r
105 // Initialize floating point operating environment\r
106 // to be compliant with UEFI spec.\r
107 //\r
108 InitializeFloatingPointUnits ();\r
109\r
110 // |-------------------|---->\r
111 // |IDT Table |\r
112 // |-------------------|\r
113 // |PeiService Pointer | PeiStackSize\r
114 // |-------------------|\r
115 // | |\r
116 // | Stack |\r
117 // |-------------------|---->\r
118 // | |\r
119 // | |\r
120 // | Heap | PeiTemporayRamSize\r
121 // | |\r
122 // | |\r
123 // |-------------------|----> TempRamBase\r
124\r
125 IdtTableInStack.PeiService = 0;\r
126 for (Index = 0; Index < SEC_IDT_ENTRY_COUNT; Index ++) {\r
127 CopyMem ((VOID*)&IdtTableInStack.IdtTable[Index], (VOID*)&mIdtEntryTemplate, sizeof (UINT64));\r
128 }\r
129\r
130 IdtDescriptor.Base = (UINTN) &IdtTableInStack.IdtTable;\r
131 IdtDescriptor.Limit = (UINT16)(sizeof (IdtTableInStack.IdtTable) - 1);\r
132\r
133 AsmWriteIdtr (&IdtDescriptor);\r
134\r
135 //\r
136 // Setup the default exception handlers\r
137 //\r
138 Status = InitializeCpuExceptionHandlers (NULL);\r
139 ASSERT_EFI_ERROR (Status);\r
140\r
141 //\r
142 // Update the base address and length of Pei temporary memory\r
143 //\r
144 SecCoreData.DataSize = (UINT16) sizeof (EFI_SEC_PEI_HAND_OFF);\r
145 SecCoreData.BootFirmwareVolumeBase = BootFirmwareVolume;\r
146 SecCoreData.BootFirmwareVolumeSize = (UINTN)(0x100000000ULL - (UINTN) BootFirmwareVolume);\r
147 SecCoreData.TemporaryRamBase = (VOID*)(UINTN) TempRamBase;\r
148 SecCoreData.TemporaryRamSize = SizeOfRam;\r
149 SecCoreData.PeiTemporaryRamBase = SecCoreData.TemporaryRamBase;\r
150 SecCoreData.PeiTemporaryRamSize = SizeOfRam - PeiStackSize;\r
151 SecCoreData.StackBase = (VOID*)(UINTN)(TempRamBase + SecCoreData.PeiTemporaryRamSize);\r
152 SecCoreData.StackSize = PeiStackSize;\r
153\r
154 //\r
155 // Initialize Debug Agent to support source level debug in SEC/PEI phases before memory ready.\r
156 //\r
157 InitializeDebugAgent (DEBUG_AGENT_INIT_PREMEM_SEC, &SecCoreData, SecStartupPhase2);\r
158}\r
159\r
160/**\r
161 Caller provided function to be invoked at the end of InitializeDebugAgent().\r
162\r
163 Entry point to the C language phase of SEC. After the SEC assembly\r
164 code has initialized some temporary memory and set up the stack,\r
165 the control is transferred to this function.\r
166\r
167 @param[in] Context The first input parameter of InitializeDebugAgent().\r
168\r
169**/\r
170VOID\r
61257251 171NORETURN\r
1921695e
MK
172EFIAPI\r
173SecStartupPhase2(\r
174 IN VOID *Context\r
175 )\r
176{\r
177 EFI_SEC_PEI_HAND_OFF *SecCoreData;\r
178 EFI_PEI_PPI_DESCRIPTOR *PpiList;\r
179 UINT32 Index;\r
180 EFI_PEI_PPI_DESCRIPTOR *AllSecPpiList;\r
181 EFI_PEI_CORE_ENTRY_POINT PeiCoreEntryPoint;\r
182\r
183 SecCoreData = (EFI_SEC_PEI_HAND_OFF *) Context;\r
184 AllSecPpiList = (EFI_PEI_PPI_DESCRIPTOR *) SecCoreData->PeiTemporaryRamBase;\r
185 //\r
186 // Find Pei Core entry point. It will report SEC and Pei Core debug information if remote debug\r
187 // is enabled.\r
188 //\r
189 FindAndReportEntryPoints ((EFI_FIRMWARE_VOLUME_HEADER *) SecCoreData->BootFirmwareVolumeBase, &PeiCoreEntryPoint);\r
190 if (PeiCoreEntryPoint == NULL)\r
191 {\r
192 CpuDeadLoop ();\r
193 }\r
194\r
195 //\r
196 // Perform platform specific initialization before entering PeiCore.\r
197 //\r
198 PpiList = SecPlatformMain (SecCoreData);\r
199 if (PpiList != NULL) {\r
200 //\r
201 // Remove the terminal flag from the terminal PPI\r
202 //\r
203 CopyMem (AllSecPpiList, mPeiSecPlatformInformationPpi, sizeof (mPeiSecPlatformInformationPpi));\r
204 Index = sizeof (mPeiSecPlatformInformationPpi) / sizeof (EFI_PEI_PPI_DESCRIPTOR) - 1;\r
205 AllSecPpiList[Index].Flags = AllSecPpiList[Index].Flags & (~EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);\r
206\r
207 //\r
208 // Append the platform additional PPI list\r
209 //\r
210 Index += 1;\r
211 while (((PpiList->Flags & EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST) != EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST)) {\r
212 CopyMem (&AllSecPpiList[Index], PpiList, sizeof (EFI_PEI_PPI_DESCRIPTOR));\r
213 Index++;\r
214 PpiList++;\r
215 }\r
216\r
217 //\r
218 // Add the terminal PPI\r
219 //\r
220 CopyMem (&AllSecPpiList[Index ++], PpiList, sizeof (EFI_PEI_PPI_DESCRIPTOR));\r
221\r
222 //\r
223 // Set PpiList to the total PPI\r
224 //\r
225 PpiList = AllSecPpiList;\r
226\r
227 //\r
228 // Adjust PEI TEMP RAM Range.\r
229 //\r
230 ASSERT (SecCoreData->PeiTemporaryRamSize > Index * sizeof (EFI_PEI_PPI_DESCRIPTOR));\r
231 SecCoreData->PeiTemporaryRamBase = (VOID *)((UINTN) SecCoreData->PeiTemporaryRamBase + Index * sizeof (EFI_PEI_PPI_DESCRIPTOR));\r
232 SecCoreData->PeiTemporaryRamSize = SecCoreData->PeiTemporaryRamSize - Index * sizeof (EFI_PEI_PPI_DESCRIPTOR);\r
233 } else {\r
234 //\r
235 // No addition PPI, PpiList directly point to the common PPI list.\r
236 //\r
237 PpiList = &mPeiSecPlatformInformationPpi[0];\r
238 }\r
239\r
240 //\r
241 // Report Status Code to indicate transferring to PEI core\r
242 //\r
243 REPORT_STATUS_CODE (\r
244 EFI_PROGRESS_CODE,\r
245 EFI_SOFTWARE_SEC | EFI_SW_SEC_PC_HANDOFF_TO_NEXT\r
246 );\r
247\r
248 //\r
249 // Transfer the control to the PEI core\r
250 //\r
251 ASSERT (PeiCoreEntryPoint != NULL);\r
252 (*PeiCoreEntryPoint) (SecCoreData, PpiList);\r
253\r
254 //\r
255 // Should not come here.\r
256 //\r
61257251 257 UNREACHABLE ();\r
1921695e
MK
258}\r
259\r
260/**\r
261 TemporaryRamDone() disables the use of Temporary RAM. If present, this service is invoked\r
262 by the PEI Foundation after the EFI_PEI_PERMANANT_MEMORY_INSTALLED_PPI is installed.\r
263\r
264 @retval EFI_SUCCESS Use of Temporary RAM was disabled.\r
265 @retval EFI_INVALID_PARAMETER Temporary RAM could not be disabled.\r
266\r
267**/\r
268EFI_STATUS\r
269EFIAPI\r
270SecTemporaryRamDone (\r
271 VOID\r
272 )\r
273{\r
274 BOOLEAN State;\r
275\r
276 //\r
277 // Migrate DebugAgentContext.\r
278 //\r
279 InitializeDebugAgent (DEBUG_AGENT_INIT_POSTMEM_SEC, NULL, NULL);\r
280\r
281 //\r
282 // Disable interrupts and save current interrupt state\r
283 //\r
284 State = SaveAndDisableInterrupts();\r
285\r
286 //\r
287 // Disable Temporary RAM after Stack and Heap have been migrated at this point.\r
288 //\r
289 SecPlatformDisableTemporaryMemory ();\r
290\r
291 //\r
292 // Restore original interrupt state\r
293 //\r
294 SetInterruptState (State);\r
295\r
296 return EFI_SUCCESS;\r
297}\r