]>
Commit | Line | Data |
---|---|---|
192f6d4c | 1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | PeiMain.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Pei Core Main Entry Point\r | |
19 | \r | |
20 | Revision History\r | |
21 | \r | |
22 | --*/\r | |
23 | \r | |
192f6d4c | 24 | #include <PeiMain.h>\r |
25 | \r | |
26 | //\r | |
27 | //CAR is filled with this initial value during SEC phase\r | |
28 | //\r | |
29 | #define INIT_CAR_VALUE 0x5AA55AA5\r | |
30 | \r | |
31 | static EFI_PEI_PPI_DESCRIPTOR mMemoryDiscoveredPpi = {\r | |
32 | (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r | |
33 | &gEfiPeiMemoryDiscoveredPpiGuid,\r | |
34 | NULL\r | |
35 | };\r | |
36 | \r | |
37 | //\r | |
38 | // Pei Core Module Variables\r | |
39 | //\r | |
40 | //\r | |
41 | static EFI_PEI_SERVICES mPS = {\r | |
42 | {\r | |
43 | PEI_SERVICES_SIGNATURE,\r | |
44 | PEI_SERVICES_REVISION,\r | |
45 | sizeof (EFI_PEI_SERVICES),\r | |
46 | 0,\r | |
47 | 0\r | |
48 | },\r | |
49 | PeiInstallPpi,\r | |
50 | PeiReInstallPpi,\r | |
51 | PeiLocatePpi,\r | |
52 | PeiNotifyPpi,\r | |
53 | \r | |
54 | PeiGetBootMode,\r | |
55 | PeiSetBootMode,\r | |
56 | \r | |
57 | PeiGetHobList,\r | |
58 | PeiCreateHob,\r | |
59 | \r | |
60 | PeiFvFindNextVolume,\r | |
61 | PeiFfsFindNextFile,\r | |
62 | PeiFfsFindSectionData,\r | |
63 | \r | |
b0d803fe | 64 | PeiInstallPeiMemory, \r |
192f6d4c | 65 | PeiAllocatePages,\r |
66 | PeiAllocatePool,\r | |
67 | (EFI_PEI_COPY_MEM)CopyMem,\r | |
68 | (EFI_PEI_SET_MEM)SetMem,\r | |
69 | \r | |
70 | PeiReportStatusCode,\r | |
14e8823a | 71 | PeiResetSystem,\r |
b0d803fe | 72 | \r |
14e8823a | 73 | NULL,\r |
74 | NULL,\r | |
b0d803fe | 75 | \r |
76 | PeiFfsFindFileByName,\r | |
77 | PeiFfsGetFileInfo,\r | |
78 | PeiFfsGetVolumeInfo,\r | |
14e8823a | 79 | PeiRegisterForShadow\r |
192f6d4c | 80 | };\r |
81 | \r | |
82 | EFI_STATUS\r | |
83 | EFIAPI\r | |
84 | PeiCore (\r | |
5aae0aa7 | 85 | IN CONST EFI_SEC_PEI_HAND_OFF *SecCoreData,\r |
5088e385 | 86 | IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList,\r |
5aae0aa7 | 87 | IN VOID *Data\r |
192f6d4c | 88 | )\r |
89 | /*++\r | |
90 | \r | |
91 | Routine Description:\r | |
92 | \r | |
93 | The entry routine to Pei Core, invoked by PeiMain during transition\r | |
94 | from SEC to PEI. After switching stack in the PEI core, it will restart\r | |
95 | with the old core data.\r | |
96 | \r | |
97 | Arguments:\r | |
98 | \r | |
5aae0aa7 | 99 | SecCoreData - Points to a data structure containing information about the PEI core's operating\r |
100 | environment, such as the size and location of temporary RAM, the stack location and\r | |
101 | the BFV location.\r | |
102 | PpiList - Points to a list of one or more PPI descriptors to be installed initially by the PEI core.\r | |
103 | An empty PPI list consists of a single descriptor with the end-tag\r | |
104 | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST. As part of its initialization\r | |
105 | phase, the PEI Foundation will add these SEC-hosted PPIs to its PPI database such\r | |
106 | that both the PEI Foundation and any modules can leverage the associated service\r | |
107 | calls and/or code in these early PPIs\r | |
108 | Data - Pointer to old core data that is used to initialize the\r | |
192f6d4c | 109 | core's data areas.\r |
110 | \r | |
111 | Returns:\r | |
112 | \r | |
113 | This function never returns\r | |
114 | EFI_NOT_FOUND - Never reach\r | |
115 | \r | |
116 | --*/\r | |
117 | {\r | |
118 | PEI_CORE_INSTANCE PrivateData;\r | |
119 | EFI_STATUS Status;\r | |
120 | PEI_CORE_TEMP_POINTERS TempPtr;\r | |
192f6d4c | 121 | UINT64 mTick;\r |
122 | PEI_CORE_INSTANCE *OldCoreData;\r | |
b0d803fe | 123 | EFI_PEI_CPU_IO_PPI *CpuIo;\r |
124 | EFI_PEI_PCI_CFG2_PPI *PciCfg;\r | |
192f6d4c | 125 | \r |
126 | mTick = 0;\r | |
127 | OldCoreData = (PEI_CORE_INSTANCE *) Data;\r | |
128 | \r | |
129 | if (PerformanceMeasurementEnabled()) {\r | |
130 | if (OldCoreData == NULL) {\r | |
131 | mTick = GetPerformanceCounter ();\r | |
132 | }\r | |
133 | }\r | |
134 | \r | |
192f6d4c | 135 | if (OldCoreData != NULL) {\r |
136 | CopyMem (&PrivateData, OldCoreData, sizeof (PEI_CORE_INSTANCE));\r | |
b0d803fe | 137 | \r |
138 | CpuIo = (VOID*)PrivateData.ServiceTableShadow.CpuIo;\r | |
139 | PciCfg = (VOID*)PrivateData.ServiceTableShadow.PciCfg;\r | |
140 | \r | |
141 | CopyMem (&PrivateData.ServiceTableShadow, &mPS, sizeof (mPS));\r | |
142 | \r | |
143 | PrivateData.ServiceTableShadow.CpuIo = CpuIo;\r | |
144 | PrivateData.ServiceTableShadow.PciCfg = PciCfg;\r | |
192f6d4c | 145 | } else {\r |
146 | ZeroMem (&PrivateData, sizeof (PEI_CORE_INSTANCE));\r | |
b0d803fe | 147 | PrivateData.Signature = PEI_CORE_HANDLE_SIGNATURE;\r |
148 | CopyMem (&PrivateData.ServiceTableShadow, &mPS, sizeof (mPS));\r | |
192f6d4c | 149 | }\r |
150 | \r | |
b0d803fe | 151 | PrivateData.PS = &PrivateData.ServiceTableShadow;\r |
192f6d4c | 152 | \r |
153 | //\r | |
154 | // Initialize libraries that the PeiCore is linked against\r | |
b0d803fe | 155 | // BUGBUG: The FileHandle is passed in as NULL. Do we look it up or remove it from the lib init?\r |
192f6d4c | 156 | //\r |
157 | ProcessLibraryConstructorList (NULL, &PrivateData.PS);\r | |
158 | \r | |
b0d803fe | 159 | InitializeMemoryServices (&PrivateData, SecCoreData, OldCoreData);\r |
192f6d4c | 160 | \r |
b0d803fe | 161 | InitializePpiServices (&PrivateData, OldCoreData);\r |
192f6d4c | 162 | \r |
81c7803c | 163 | //\r |
164 | // Save PeiServicePointer so that it can be retrieved anywhere.\r | |
165 | //\r | |
166 | SetPeiServicesTablePointer(&PrivateData.PS);\r | |
167 | \r | |
192f6d4c | 168 | if (OldCoreData != NULL) {\r |
169 | \r | |
170 | PERF_END (NULL,"PreMem", NULL, 0);\r | |
171 | PERF_START (NULL,"PostMem", NULL, 0);\r | |
172 | \r | |
173 | //\r | |
174 | // The following code dumps out interesting cache as RAM usage information\r | |
175 | // so we can keep tabs on how the cache as RAM is being utilized. The\r | |
176 | // DEBUG_CODE_BEGIN macro is used to prevent this code from being compiled\r | |
177 | // on a debug build.\r | |
178 | //\r | |
179 | DEBUG_CODE_BEGIN ();\r | |
180 | UINTN *StackPointer;\r | |
181 | UINTN StackValue;\r | |
182 | \r | |
183 | StackValue = INIT_CAR_VALUE;\r | |
6797657e | 184 | for (StackPointer = (UINTN *) OldCoreData->TopOfCarHeap;\r |
185 | ((UINTN) StackPointer < ((UINTN) OldCoreData->MaxTopOfCarHeap))\r | |
192f6d4c | 186 | && StackValue == INIT_CAR_VALUE;\r |
187 | StackPointer++) {\r | |
188 | StackValue = *StackPointer;\r | |
189 | }\r | |
6797657e | 190 | \r |
192f6d4c | 191 | DEBUG ((EFI_D_INFO, "Total Cache as RAM: %d bytes.\n", OldCoreData->SizeOfCacheAsRam));\r |
192 | DEBUG ((EFI_D_INFO, " CAR stack ever used: %d bytes.\n",\r | |
61f21f40 | 193 | ((UINTN) OldCoreData->MaxTopOfCarHeap - (UINTN) StackPointer)\r |
192f6d4c | 194 | ));\r |
195 | DEBUG ((EFI_D_INFO, " CAR heap used: %d bytes.\n",\r | |
196 | ((UINTN) OldCoreData->HobList.HandoffInformationTable->EfiFreeMemoryBottom -\r | |
197 | (UINTN) OldCoreData->HobList.Raw)\r | |
198 | ));\r | |
199 | DEBUG_CODE_END ();\r | |
200 | \r | |
201 | //\r | |
202 | // Alert any listeners that there is permanent memory available\r | |
203 | //\r | |
204 | \r | |
205 | PERF_START (NULL,"DisMem", NULL, 0);\r | |
206 | Status = PeiServicesInstallPpi (&mMemoryDiscoveredPpi);\r | |
207 | PERF_END (NULL,"DisMem", NULL, 0);\r | |
208 | \r | |
209 | } else {\r | |
210 | \r | |
211 | //\r | |
212 | // Report Status Code EFI_SW_PC_INIT\r | |
213 | //\r | |
214 | REPORT_STATUS_CODE (\r | |
215 | EFI_PROGRESS_CODE,\r | |
797a9d67 | 216 | FixedPcdGet32 (PcdStatusCodeValuePeiCoreEntry)\r |
192f6d4c | 217 | );\r |
218 | \r | |
219 | PERF_START (NULL,"PEI", NULL, mTick);\r | |
220 | //\r | |
221 | // If first pass, start performance measurement.\r | |
222 | //\r | |
223 | PERF_START (NULL,"PreMem", NULL, mTick);\r | |
224 | \r | |
225 | //\r | |
226 | // If SEC provided any PPI services to PEI, install them.\r | |
227 | //\r | |
5088e385 | 228 | if (PpiList != NULL) {\r |
229 | Status = PeiServicesInstallPpi (PpiList);\r | |
192f6d4c | 230 | ASSERT_EFI_ERROR (Status);\r |
231 | }\r | |
232 | }\r | |
233 | \r | |
b0d803fe | 234 | InitializeSecurityServices (&PrivateData.PS, OldCoreData);\r |
235 | \r | |
236 | InitializeDispatcherData (&PrivateData, OldCoreData, SecCoreData);\r | |
237 | \r | |
238 | //\r | |
239 | // Install Pei Load File PPI. \r | |
240 | //\r | |
241 | InitializeImageServices (&PrivateData, OldCoreData);\r | |
192f6d4c | 242 | \r |
243 | //\r | |
244 | // Call PEIM dispatcher\r | |
245 | //\r | |
b0d803fe | 246 | PeiDispatcher (SecCoreData, &PrivateData);\r |
192f6d4c | 247 | \r |
248 | //\r | |
249 | // Check if InstallPeiMemory service was called.\r | |
250 | //\r | |
251 | ASSERT(PrivateData.PeiMemoryInstalled == TRUE);\r | |
252 | \r | |
253 | PERF_END (NULL, "PostMem", NULL, 0);\r | |
254 | \r | |
255 | Status = PeiServicesLocatePpi (\r | |
256 | &gEfiDxeIplPpiGuid,\r | |
257 | 0,\r | |
258 | NULL,\r | |
259 | (VOID **)&TempPtr.DxeIpl\r | |
260 | );\r | |
261 | ASSERT_EFI_ERROR (Status);\r | |
262 | \r | |
263 | DEBUG ((EFI_D_INFO, "DXE IPL Entry\n"));\r | |
264 | Status = TempPtr.DxeIpl->Entry (\r | |
265 | TempPtr.DxeIpl,\r | |
266 | &PrivateData.PS,\r | |
267 | PrivateData.HobList\r | |
268 | );\r | |
269 | \r | |
270 | ASSERT_EFI_ERROR (Status);\r | |
271 | \r | |
272 | return EFI_NOT_FOUND;\r | |
273 | }\r | |
274 | \r | |
a3a15d21 | 275 | \r |