]>
Commit | Line | Data |
---|---|---|
162ed594 | 1 | /** @file\r |
797a9d67 | 2 | DXE Dispatcher.\r |
28a00297 | 3 | \r |
4 | Step #1 - When a FV protocol is added to the system every driver in the FV\r | |
022c6d45 | 5 | is added to the mDiscoveredList. The SOR, Before, and After Depex are\r |
6 | pre-processed as drivers are added to the mDiscoveredList. If an Apriori\r | |
7 | file exists in the FV those drivers are addeded to the\r | |
8 | mScheduledQueue. The mFvHandleList is used to make sure a\r | |
28a00297 | 9 | FV is only processed once.\r |
10 | \r | |
11 | Step #2 - Dispatch. Remove driver from the mScheduledQueue and load and\r | |
022c6d45 | 12 | start it. After mScheduledQueue is drained check the\r |
13 | mDiscoveredList to see if any item has a Depex that is ready to\r | |
28a00297 | 14 | be placed on the mScheduledQueue.\r |
15 | \r | |
022c6d45 | 16 | Step #3 - Adding to the mScheduledQueue requires that you process Before\r |
28a00297 | 17 | and After dependencies. This is done recursively as the call to add\r |
022c6d45 | 18 | to the mScheduledQueue checks for Before and recursively adds\r |
19 | all Befores. It then addes the item that was passed in and then\r | |
28a00297 | 20 | processess the After dependecies by recursively calling the routine.\r |
21 | \r | |
22 | Dispatcher Rules:\r | |
022c6d45 | 23 | The rules for the dispatcher are in chapter 10 of the DXE CIS. Figure 10-3\r |
28a00297 | 24 | is the state diagram for the DXE dispatcher\r |
25 | \r | |
26 | Depex - Dependency Expresion.\r | |
27 | SOR - Schedule On Request - Don't schedule if this bit is set.\r | |
28 | \r | |
cd5ebaa0 HT |
29 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r |
30 | This program and the accompanying materials\r | |
23c98c94 | 31 | are licensed and made available under the terms and conditions of the BSD License\r |
32 | which accompanies this distribution. The full text of the license may be found at\r | |
33 | http://opensource.org/licenses/bsd-license.php\r | |
34 | \r | |
35 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
36 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
797a9d67 | 37 | \r |
38 | **/\r | |
28a00297 | 39 | \r |
9c4ac31c | 40 | #include "DxeMain.h"\r |
28a00297 | 41 | \r |
42 | //\r | |
43 | // The Driver List contains one copy of every driver that has been discovered.\r | |
44 | // Items are never removed from the driver list. List of EFI_CORE_DRIVER_ENTRY\r | |
45 | //\r | |
022c6d45 | 46 | LIST_ENTRY mDiscoveredList = INITIALIZE_LIST_HEAD_VARIABLE (mDiscoveredList);\r |
28a00297 | 47 | \r |
48 | //\r | |
49 | // Queue of drivers that are ready to dispatch. This queue is a subset of the\r | |
50 | // mDiscoveredList.list of EFI_CORE_DRIVER_ENTRY.\r | |
51 | //\r | |
52 | LIST_ENTRY mScheduledQueue = INITIALIZE_LIST_HEAD_VARIABLE (mScheduledQueue);\r | |
53 | \r | |
54 | //\r | |
55 | // List of handles who's Fv's have been parsed and added to the mFwDriverList.\r | |
56 | //\r | |
57 | LIST_ENTRY mFvHandleList = INITIALIZE_LIST_HEAD_VARIABLE (mFvHandleList); // list of KNOWN_HANDLE\r | |
58 | \r | |
59 | //\r | |
60 | // Lock for mDiscoveredList, mScheduledQueue, gDispatcherRunning.\r | |
61 | //\r | |
62 | EFI_LOCK mDispatcherLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL);\r | |
63 | \r | |
64 | \r | |
65 | //\r | |
66 | // Flag for the DXE Dispacher. TRUE if dispatcher is execuing.\r | |
67 | //\r | |
68 | BOOLEAN gDispatcherRunning = FALSE;\r | |
69 | \r | |
70 | //\r | |
71 | // Module globals to manage the FwVol registration notification event\r | |
72 | //\r | |
73 | EFI_EVENT mFwVolEvent;\r | |
74 | VOID *mFwVolEventRegistration;\r | |
75 | \r | |
76 | //\r | |
77 | // List of file types supported by dispatcher\r | |
78 | //\r | |
022c6d45 | 79 | EFI_FV_FILETYPE mDxeFileTypes[] = {\r |
80 | EFI_FV_FILETYPE_DRIVER,\r | |
202c3279 | 81 | EFI_FV_FILETYPE_COMBINED_SMM_DXE,\r |
022c6d45 | 82 | EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER,\r |
28a00297 | 83 | EFI_FV_FILETYPE_DXE_CORE,\r |
84 | EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE\r | |
85 | };\r | |
86 | \r | |
87 | typedef struct {\r | |
88 | MEDIA_FW_VOL_FILEPATH_DEVICE_PATH File;\r | |
89 | EFI_DEVICE_PATH_PROTOCOL End;\r | |
90 | } FV_FILEPATH_DEVICE_PATH;\r | |
91 | \r | |
92 | FV_FILEPATH_DEVICE_PATH mFvDevicePath;\r | |
93 | \r | |
94 | \r | |
95 | //\r | |
96 | // Function Prototypes\r | |
97 | //\r | |
162ed594 | 98 | /**\r |
99 | Insert InsertedDriverEntry onto the mScheduledQueue. To do this you\r | |
100 | must add any driver with a before dependency on InsertedDriverEntry first.\r | |
101 | You do this by recursively calling this routine. After all the Befores are\r | |
102 | processed you can add InsertedDriverEntry to the mScheduledQueue.\r | |
103 | Then you can add any driver with an After dependency on InsertedDriverEntry\r | |
104 | by recursively calling this routine.\r | |
105 | \r | |
106 | @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue\r | |
107 | \r | |
108 | **/\r | |
28a00297 | 109 | VOID\r |
110 | CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (\r | |
111 | IN EFI_CORE_DRIVER_ENTRY *InsertedDriverEntry\r | |
112 | );\r | |
022c6d45 | 113 | \r |
162ed594 | 114 | /**\r |
115 | Event notification that is fired every time a FV dispatch protocol is added.\r | |
116 | More than one protocol may have been added when this event is fired, so you\r | |
117 | must loop on CoreLocateHandle () to see how many protocols were added and\r | |
118 | do the following to each FV:\r | |
119 | If the Fv has already been processed, skip it. If the Fv has not been\r | |
120 | processed then mark it as being processed, as we are about to process it.\r | |
121 | Read the Fv and add any driver in the Fv to the mDiscoveredList.The\r | |
122 | mDiscoveredList is never free'ed and contains variables that define\r | |
123 | the other states the DXE driver transitions to..\r | |
124 | While you are at it read the A Priori file into memory.\r | |
125 | Place drivers in the A Priori list onto the mScheduledQueue.\r | |
126 | \r | |
022c6d45 | 127 | @param Event The Event that is being processed, not used.\r |
162ed594 | 128 | @param Context Event Context, not used.\r |
129 | \r | |
130 | **/\r | |
28a00297 | 131 | VOID\r |
132 | EFIAPI\r | |
133 | CoreFwVolEventProtocolNotify (\r | |
134 | IN EFI_EVENT Event,\r | |
135 | IN VOID *Context\r | |
136 | );\r | |
137 | \r | |
162ed594 | 138 | /**\r |
022c6d45 | 139 | Convert FvHandle and DriverName into an EFI device path\r |
162ed594 | 140 | \r |
022c6d45 | 141 | @param Fv Fv protocol, needed to read Depex info out of\r |
142 | FLASH.\r | |
143 | @param FvHandle Handle for Fv, needed in the\r | |
144 | EFI_CORE_DRIVER_ENTRY so that the PE image can be\r | |
145 | read out of the FV at a later time.\r | |
146 | @param DriverName Name of driver to add to mDiscoveredList.\r | |
162ed594 | 147 | \r |
148 | @return Pointer to device path constructed from FvHandle and DriverName\r | |
149 | \r | |
150 | **/\r | |
28a00297 | 151 | EFI_DEVICE_PATH_PROTOCOL *\r |
152 | CoreFvToDevicePath (\r | |
0c2b5da8 | 153 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r |
28a00297 | 154 | IN EFI_HANDLE FvHandle,\r |
155 | IN EFI_GUID *DriverName\r | |
156 | );\r | |
157 | \r | |
162ed594 | 158 | /**\r |
159 | Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,\r | |
160 | and initilize any state variables. Read the Depex from the FV and store it\r | |
161 | in DriverEntry. Pre-process the Depex to set the SOR, Before and After state.\r | |
162 | The Discovered list is never free'ed and contains booleans that represent the\r | |
163 | other possible DXE driver states.\r | |
164 | \r | |
022c6d45 | 165 | @param Fv Fv protocol, needed to read Depex info out of\r |
166 | FLASH.\r | |
167 | @param FvHandle Handle for Fv, needed in the\r | |
168 | EFI_CORE_DRIVER_ENTRY so that the PE image can be\r | |
169 | read out of the FV at a later time.\r | |
170 | @param DriverName Name of driver to add to mDiscoveredList.\r | |
162ed594 | 171 | \r |
022c6d45 | 172 | @retval EFI_SUCCESS If driver was added to the mDiscoveredList.\r |
173 | @retval EFI_ALREADY_STARTED The driver has already been started. Only one\r | |
174 | DriverName may be active in the system at any one\r | |
162ed594 | 175 | time.\r |
176 | \r | |
177 | **/\r | |
28a00297 | 178 | EFI_STATUS\r |
179 | CoreAddToDriverList (\r | |
23c98c94 | 180 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r |
181 | IN EFI_HANDLE FvHandle,\r | |
182 | IN EFI_GUID *DriverName\r | |
28a00297 | 183 | );\r |
184 | \r | |
162ed594 | 185 | /**\r |
186 | Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.\r | |
187 | \r | |
022c6d45 | 188 | @param Fv The FIRMWARE_VOLUME protocol installed on the FV.\r |
189 | @param FvHandle The handle which FVB protocol installed on.\r | |
190 | @param DriverName The driver guid specified.\r | |
162ed594 | 191 | \r |
022c6d45 | 192 | @retval EFI_OUT_OF_RESOURCES No enough memory or other resource.\r |
193 | @retval EFI_VOLUME_CORRUPTED Corrupted volume.\r | |
162ed594 | 194 | @retval EFI_SUCCESS Function successfully returned.\r |
195 | \r | |
196 | **/\r | |
022c6d45 | 197 | EFI_STATUS\r |
28a00297 | 198 | CoreProcessFvImageFile (\r |
0c2b5da8 | 199 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r |
28a00297 | 200 | IN EFI_HANDLE FvHandle,\r |
201 | IN EFI_GUID *DriverName\r | |
202 | );\r | |
203 | \r | |
162ed594 | 204 | \r |
205 | /**\r | |
206 | Enter critical section by gaining lock on mDispatcherLock.\r | |
207 | \r | |
208 | **/\r | |
28a00297 | 209 | VOID\r |
210 | CoreAcquireDispatcherLock (\r | |
211 | VOID\r | |
212 | )\r | |
28a00297 | 213 | {\r |
214 | CoreAcquireLock (&mDispatcherLock);\r | |
215 | }\r | |
216 | \r | |
162ed594 | 217 | \r |
218 | /**\r | |
219 | Exit critical section by releasing lock on mDispatcherLock.\r | |
220 | \r | |
221 | **/\r | |
28a00297 | 222 | VOID\r |
223 | CoreReleaseDispatcherLock (\r | |
224 | VOID\r | |
225 | )\r | |
28a00297 | 226 | {\r |
227 | CoreReleaseLock (&mDispatcherLock);\r | |
228 | }\r | |
229 | \r | |
28a00297 | 230 | \r |
162ed594 | 231 | /**\r |
28a00297 | 232 | Read Depex and pre-process the Depex for Before and After. If Section Extraction\r |
233 | protocol returns an error via ReadSection defer the reading of the Depex.\r | |
234 | \r | |
022c6d45 | 235 | @param DriverEntry Driver to work on.\r |
28a00297 | 236 | \r |
022c6d45 | 237 | @retval EFI_SUCCESS Depex read and preprossesed\r |
238 | @retval EFI_PROTOCOL_ERROR The section extraction protocol returned an error\r | |
239 | and Depex reading needs to be retried.\r | |
162ed594 | 240 | @retval Error DEPEX not found.\r |
28a00297 | 241 | \r |
162ed594 | 242 | **/\r |
162ed594 | 243 | EFI_STATUS\r |
244 | CoreGetDepexSectionAndPreProccess (\r | |
245 | IN EFI_CORE_DRIVER_ENTRY *DriverEntry\r | |
246 | )\r | |
28a00297 | 247 | {\r |
248 | EFI_STATUS Status;\r | |
249 | EFI_SECTION_TYPE SectionType;\r | |
250 | UINT32 AuthenticationStatus;\r | |
0c2b5da8 | 251 | EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r |
28a00297 | 252 | \r |
022c6d45 | 253 | \r |
28a00297 | 254 | Fv = DriverEntry->Fv;\r |
255 | \r | |
256 | //\r | |
257 | // Grab Depex info, it will never be free'ed.\r | |
258 | //\r | |
259 | SectionType = EFI_SECTION_DXE_DEPEX;\r | |
260 | Status = Fv->ReadSection (\r | |
022c6d45 | 261 | DriverEntry->Fv,\r |
28a00297 | 262 | &DriverEntry->FileName,\r |
022c6d45 | 263 | SectionType,\r |
264 | 0,\r | |
265 | &DriverEntry->Depex,\r | |
28a00297 | 266 | (UINTN *)&DriverEntry->DepexSize,\r |
267 | &AuthenticationStatus\r | |
268 | );\r | |
269 | if (EFI_ERROR (Status)) {\r | |
270 | if (Status == EFI_PROTOCOL_ERROR) {\r | |
271 | //\r | |
272 | // The section extraction protocol failed so set protocol error flag\r | |
273 | //\r | |
274 | DriverEntry->DepexProtocolError = TRUE;\r | |
275 | } else {\r | |
276 | //\r | |
8a7d75b0 | 277 | // If no Depex assume UEFI 2.0 driver model\r |
28a00297 | 278 | //\r |
279 | DriverEntry->Depex = NULL;\r | |
280 | DriverEntry->Dependent = TRUE;\r | |
281 | DriverEntry->DepexProtocolError = FALSE;\r | |
282 | }\r | |
283 | } else {\r | |
284 | //\r | |
285 | // Set Before, After, and Unrequested state information based on Depex\r | |
286 | // Driver will be put in Dependent or Unrequested state\r | |
287 | //\r | |
288 | CorePreProcessDepex (DriverEntry);\r | |
289 | DriverEntry->DepexProtocolError = FALSE;\r | |
022c6d45 | 290 | }\r |
28a00297 | 291 | \r |
292 | return Status;\r | |
293 | }\r | |
294 | \r | |
162ed594 | 295 | \r |
296 | /**\r | |
297 | Check every driver and locate a matching one. If the driver is found, the Unrequested\r | |
298 | state flag is cleared.\r | |
299 | \r | |
022c6d45 | 300 | @param FirmwareVolumeHandle The handle of the Firmware Volume that contains\r |
301 | the firmware file specified by DriverName.\r | |
302 | @param DriverName The Driver name to put in the Dependent state.\r | |
162ed594 | 303 | \r |
022c6d45 | 304 | @retval EFI_SUCCESS The DriverName was found and it's SOR bit was\r |
305 | cleared\r | |
306 | @retval EFI_NOT_FOUND The DriverName does not exist or it's SOR bit was\r | |
307 | not set.\r | |
162ed594 | 308 | \r |
309 | **/\r | |
28a00297 | 310 | EFI_STATUS\r |
311 | EFIAPI\r | |
312 | CoreSchedule (\r | |
313 | IN EFI_HANDLE FirmwareVolumeHandle,\r | |
314 | IN EFI_GUID *DriverName\r | |
315 | )\r | |
28a00297 | 316 | {\r |
317 | LIST_ENTRY *Link;\r | |
318 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
319 | \r | |
320 | //\r | |
321 | // Check every driver\r | |
322 | //\r | |
323 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
324 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
325 | if (DriverEntry->FvHandle == FirmwareVolumeHandle &&\r | |
022c6d45 | 326 | DriverEntry->Unrequested &&\r |
28a00297 | 327 | CompareGuid (DriverName, &DriverEntry->FileName)) {\r |
328 | //\r | |
329 | // Move the driver from the Unrequested to the Dependent state\r | |
330 | //\r | |
331 | CoreAcquireDispatcherLock ();\r | |
332 | DriverEntry->Unrequested = FALSE;\r | |
333 | DriverEntry->Dependent = TRUE;\r | |
334 | CoreReleaseDispatcherLock ();\r | |
022c6d45 | 335 | \r |
28a00297 | 336 | return EFI_SUCCESS;\r |
337 | }\r | |
338 | }\r | |
022c6d45 | 339 | return EFI_NOT_FOUND;\r |
28a00297 | 340 | }\r |
341 | \r | |
342 | \r | |
162ed594 | 343 | \r |
344 | /**\r | |
e94a9ff7 | 345 | Convert a driver from the Untrused back to the Scheduled state.\r |
162ed594 | 346 | \r |
022c6d45 | 347 | @param FirmwareVolumeHandle The handle of the Firmware Volume that contains\r |
348 | the firmware file specified by DriverName.\r | |
349 | @param DriverName The Driver name to put in the Scheduled state\r | |
162ed594 | 350 | \r |
022c6d45 | 351 | @retval EFI_SUCCESS The file was found in the untrusted state, and it\r |
352 | was promoted to the trusted state.\r | |
353 | @retval EFI_NOT_FOUND The file was not found in the untrusted state.\r | |
162ed594 | 354 | \r |
355 | **/\r | |
28a00297 | 356 | EFI_STATUS\r |
357 | EFIAPI\r | |
358 | CoreTrust (\r | |
359 | IN EFI_HANDLE FirmwareVolumeHandle,\r | |
360 | IN EFI_GUID *DriverName\r | |
361 | )\r | |
28a00297 | 362 | {\r |
363 | LIST_ENTRY *Link;\r | |
364 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
365 | \r | |
366 | //\r | |
367 | // Check every driver\r | |
368 | //\r | |
369 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
370 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
371 | if (DriverEntry->FvHandle == FirmwareVolumeHandle &&\r | |
022c6d45 | 372 | DriverEntry->Untrusted &&\r |
28a00297 | 373 | CompareGuid (DriverName, &DriverEntry->FileName)) {\r |
374 | //\r | |
375 | // Transition driver from Untrusted to Scheduled state.\r | |
376 | //\r | |
377 | CoreAcquireDispatcherLock ();\r | |
378 | DriverEntry->Untrusted = FALSE;\r | |
379 | DriverEntry->Scheduled = TRUE;\r | |
380 | InsertTailList (&mScheduledQueue, &DriverEntry->ScheduledLink);\r | |
381 | CoreReleaseDispatcherLock ();\r | |
022c6d45 | 382 | \r |
28a00297 | 383 | return EFI_SUCCESS;\r |
384 | }\r | |
385 | }\r | |
022c6d45 | 386 | return EFI_NOT_FOUND;\r |
28a00297 | 387 | }\r |
388 | \r | |
389 | \r | |
202c3279 | 390 | /**\r |
391 | An empty function to pass error checking of CreateEventEx ().\r | |
392 | \r | |
393 | @param Event Event whose notification function is being invoked.\r | |
394 | @param Context Pointer to the notification function's context,\r | |
395 | which is implementation-dependent.\r | |
396 | \r | |
397 | **/\r | |
398 | VOID\r | |
399 | EFIAPI\r | |
400 | EmptyFuntion (\r | |
401 | IN EFI_EVENT Event,\r | |
402 | IN VOID *Context\r | |
403 | )\r | |
404 | {\r | |
405 | return;\r | |
406 | }\r | |
28a00297 | 407 | \r |
162ed594 | 408 | /**\r |
409 | This is the main Dispatcher for DXE and it exits when there are no more\r | |
28a00297 | 410 | drivers to run. Drain the mScheduledQueue and load and start a PE\r |
162ed594 | 411 | image for each driver. Search the mDiscoveredList to see if any driver can\r |
28a00297 | 412 | be placed on the mScheduledQueue. If no drivers are placed on the\r |
413 | mScheduledQueue exit the function. On exit it is assumed the Bds()\r | |
162ed594 | 414 | will be called, and when the Bds() exits the Dispatcher will be called\r |
28a00297 | 415 | again.\r |
416 | \r | |
022c6d45 | 417 | @retval EFI_ALREADY_STARTED The DXE Dispatcher is already running\r |
418 | @retval EFI_NOT_FOUND No DXE Drivers were dispatched\r | |
419 | @retval EFI_SUCCESS One or more DXE Drivers were dispatched\r | |
28a00297 | 420 | \r |
162ed594 | 421 | **/\r |
162ed594 | 422 | EFI_STATUS\r |
423 | EFIAPI\r | |
424 | CoreDispatcher (\r | |
425 | VOID\r | |
426 | )\r | |
28a00297 | 427 | {\r |
428 | EFI_STATUS Status;\r | |
429 | EFI_STATUS ReturnStatus;\r | |
430 | LIST_ENTRY *Link;\r | |
431 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
432 | BOOLEAN ReadyToRun;\r | |
202c3279 | 433 | EFI_EVENT DxeDispatchEvent;\r |
434 | \r | |
28a00297 | 435 | \r |
436 | if (gDispatcherRunning) {\r | |
437 | //\r | |
438 | // If the dispatcher is running don't let it be restarted.\r | |
439 | //\r | |
440 | return EFI_ALREADY_STARTED;\r | |
441 | }\r | |
442 | \r | |
443 | gDispatcherRunning = TRUE;\r | |
444 | \r | |
202c3279 | 445 | Status = CoreCreateEventEx (\r |
446 | EVT_NOTIFY_SIGNAL,\r | |
447 | TPL_NOTIFY,\r | |
448 | EmptyFuntion,\r | |
449 | NULL,\r | |
450 | &gEfiEventDxeDispatchGuid,\r | |
451 | &DxeDispatchEvent\r | |
452 | );\r | |
453 | if (EFI_ERROR (Status)) {\r | |
454 | return Status;\r | |
455 | }\r | |
28a00297 | 456 | \r |
457 | ReturnStatus = EFI_NOT_FOUND;\r | |
458 | do {\r | |
459 | //\r | |
460 | // Drain the Scheduled Queue\r | |
461 | //\r | |
462 | while (!IsListEmpty (&mScheduledQueue)) {\r | |
463 | DriverEntry = CR (\r | |
464 | mScheduledQueue.ForwardLink,\r | |
465 | EFI_CORE_DRIVER_ENTRY,\r | |
466 | ScheduledLink,\r | |
467 | EFI_CORE_DRIVER_ENTRY_SIGNATURE\r | |
468 | );\r | |
469 | \r | |
470 | //\r | |
471 | // Load the DXE Driver image into memory. If the Driver was transitioned from\r | |
472 | // Untrused to Scheduled it would have already been loaded so we may need to\r | |
473 | // skip the LoadImage\r | |
474 | //\r | |
475 | if (DriverEntry->ImageHandle == NULL) {\r | |
94903510 | 476 | DEBUG ((DEBUG_INFO, "Loading driver %g\n", &DriverEntry->FileName));\r |
28a00297 | 477 | Status = CoreLoadImage (\r |
022c6d45 | 478 | FALSE,\r |
479 | gDxeCoreImageHandle,\r | |
28a00297 | 480 | DriverEntry->FvFileDevicePath,\r |
022c6d45 | 481 | NULL,\r |
482 | 0,\r | |
28a00297 | 483 | &DriverEntry->ImageHandle\r |
484 | );\r | |
485 | \r | |
486 | //\r | |
487 | // Update the driver state to reflect that it's been loaded\r | |
488 | //\r | |
489 | if (EFI_ERROR (Status)) {\r | |
490 | CoreAcquireDispatcherLock ();\r | |
491 | \r | |
492 | if (Status == EFI_SECURITY_VIOLATION) {\r | |
493 | //\r | |
494 | // Take driver from Scheduled to Untrused state\r | |
495 | //\r | |
496 | DriverEntry->Untrusted = TRUE;\r | |
497 | } else {\r | |
498 | //\r | |
499 | // The DXE Driver could not be loaded, and do not attempt to load or start it again.\r | |
022c6d45 | 500 | // Take driver from Scheduled to Initialized.\r |
28a00297 | 501 | //\r |
502 | // This case include the Never Trusted state if EFI_ACCESS_DENIED is returned\r | |
503 | //\r | |
504 | DriverEntry->Initialized = TRUE;\r | |
505 | }\r | |
506 | \r | |
507 | DriverEntry->Scheduled = FALSE;\r | |
508 | RemoveEntryList (&DriverEntry->ScheduledLink);\r | |
022c6d45 | 509 | \r |
28a00297 | 510 | CoreReleaseDispatcherLock ();\r |
022c6d45 | 511 | \r |
28a00297 | 512 | //\r |
513 | // If it's an error don't try the StartImage\r | |
514 | //\r | |
515 | continue;\r | |
516 | }\r | |
517 | }\r | |
518 | \r | |
519 | CoreAcquireDispatcherLock ();\r | |
520 | \r | |
521 | DriverEntry->Scheduled = FALSE;\r | |
522 | DriverEntry->Initialized = TRUE;\r | |
523 | RemoveEntryList (&DriverEntry->ScheduledLink);\r | |
022c6d45 | 524 | \r |
28a00297 | 525 | CoreReleaseDispatcherLock ();\r |
526 | \r | |
2680a308 | 527 | \r |
528 | REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r | |
529 | EFI_PROGRESS_CODE,\r | |
f9876ecf | 530 | (EFI_SOFTWARE_DXE_CORE | EFI_SW_PC_INIT_BEGIN),\r |
2680a308 | 531 | &DriverEntry->ImageHandle,\r |
532 | sizeof (DriverEntry->ImageHandle)\r | |
797a9d67 | 533 | );\r |
2680a308 | 534 | \r |
28a00297 | 535 | Status = CoreStartImage (DriverEntry->ImageHandle, NULL, NULL);\r |
2680a308 | 536 | \r |
537 | REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r | |
538 | EFI_PROGRESS_CODE,\r | |
f9876ecf | 539 | (EFI_SOFTWARE_DXE_CORE | EFI_SW_PC_INIT_END),\r |
2680a308 | 540 | &DriverEntry->ImageHandle,\r |
541 | sizeof (DriverEntry->ImageHandle)\r | |
797a9d67 | 542 | );\r |
28a00297 | 543 | \r |
544 | ReturnStatus = EFI_SUCCESS;\r | |
545 | }\r | |
546 | \r | |
0e4483bc LG |
547 | //\r |
548 | // Now DXE Dispatcher finished one round of dispatch, signal an event group\r | |
549 | // so that SMM Dispatcher get chance to dispatch SMM Drivers which depend\r | |
550 | // on UEFI protocols\r | |
551 | //\r | |
552 | if (!EFI_ERROR (ReturnStatus)) {\r | |
553 | CoreSignalEvent (DxeDispatchEvent);\r | |
554 | }\r | |
555 | \r | |
28a00297 | 556 | //\r |
557 | // Search DriverList for items to place on Scheduled Queue\r | |
558 | //\r | |
559 | ReadyToRun = FALSE;\r | |
560 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
561 | DriverEntry = CR (Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
562 | \r | |
563 | if (DriverEntry->DepexProtocolError){\r | |
564 | //\r | |
565 | // If Section Extraction Protocol did not let the Depex be read before retry the read\r | |
566 | //\r | |
567 | Status = CoreGetDepexSectionAndPreProccess (DriverEntry);\r | |
022c6d45 | 568 | }\r |
28a00297 | 569 | \r |
570 | if (DriverEntry->Dependent) {\r | |
571 | if (CoreIsSchedulable (DriverEntry)) {\r | |
022c6d45 | 572 | CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry);\r |
28a00297 | 573 | ReadyToRun = TRUE;\r |
022c6d45 | 574 | }\r |
28a00297 | 575 | }\r |
576 | }\r | |
577 | } while (ReadyToRun);\r | |
578 | \r | |
202c3279 | 579 | //\r |
580 | // Close DXE dispatch Event\r | |
581 | //\r | |
582 | CoreCloseEvent (DxeDispatchEvent);\r | |
583 | \r | |
28a00297 | 584 | gDispatcherRunning = FALSE;\r |
585 | \r | |
586 | return ReturnStatus;\r | |
587 | }\r | |
588 | \r | |
28a00297 | 589 | \r |
162ed594 | 590 | /**\r |
591 | Insert InsertedDriverEntry onto the mScheduledQueue. To do this you\r | |
28a00297 | 592 | must add any driver with a before dependency on InsertedDriverEntry first.\r |
593 | You do this by recursively calling this routine. After all the Befores are\r | |
162ed594 | 594 | processed you can add InsertedDriverEntry to the mScheduledQueue.\r |
595 | Then you can add any driver with an After dependency on InsertedDriverEntry\r | |
28a00297 | 596 | by recursively calling this routine.\r |
597 | \r | |
162ed594 | 598 | @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue\r |
28a00297 | 599 | \r |
162ed594 | 600 | **/\r |
162ed594 | 601 | VOID\r |
602 | CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (\r | |
603 | IN EFI_CORE_DRIVER_ENTRY *InsertedDriverEntry\r | |
604 | )\r | |
28a00297 | 605 | {\r |
606 | LIST_ENTRY *Link;\r | |
607 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
608 | \r | |
609 | //\r | |
610 | // Process Before Dependency\r | |
611 | //\r | |
612 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
613 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
614 | if (DriverEntry->Before && DriverEntry->Dependent) {\r | |
615 | if (CompareGuid (&InsertedDriverEntry->FileName, &DriverEntry->BeforeAfterGuid)) {\r | |
616 | //\r | |
617 | // Recursively process BEFORE\r | |
618 | //\r | |
619 | CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry);\r | |
620 | }\r | |
621 | }\r | |
622 | }\r | |
623 | \r | |
624 | //\r | |
625 | // Convert driver from Dependent to Scheduled state\r | |
626 | //\r | |
627 | CoreAcquireDispatcherLock ();\r | |
628 | \r | |
629 | InsertedDriverEntry->Dependent = FALSE;\r | |
630 | InsertedDriverEntry->Scheduled = TRUE;\r | |
631 | InsertTailList (&mScheduledQueue, &InsertedDriverEntry->ScheduledLink);\r | |
022c6d45 | 632 | \r |
28a00297 | 633 | CoreReleaseDispatcherLock ();\r |
634 | \r | |
635 | //\r | |
636 | // Process After Dependency\r | |
637 | //\r | |
638 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
639 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
640 | if (DriverEntry->After && DriverEntry->Dependent) {\r | |
641 | if (CompareGuid (&InsertedDriverEntry->FileName, &DriverEntry->BeforeAfterGuid)) {\r | |
642 | //\r | |
643 | // Recursively process AFTER\r | |
644 | //\r | |
645 | CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry);\r | |
646 | }\r | |
647 | }\r | |
648 | }\r | |
649 | }\r | |
650 | \r | |
28a00297 | 651 | \r |
162ed594 | 652 | /**\r |
28a00297 | 653 | Return TRUE if the Fv has been processed, FALSE if not.\r |
654 | \r | |
022c6d45 | 655 | @param FvHandle The handle of a FV that's being tested\r |
28a00297 | 656 | \r |
022c6d45 | 657 | @retval TRUE Fv protocol on FvHandle has been processed\r |
e94a9ff7 | 658 | @retval FALSE Fv protocol on FvHandle has not yet been processed\r |
28a00297 | 659 | \r |
162ed594 | 660 | **/\r |
162ed594 | 661 | BOOLEAN\r |
662 | FvHasBeenProcessed (\r | |
663 | IN EFI_HANDLE FvHandle\r | |
664 | )\r | |
28a00297 | 665 | {\r |
666 | LIST_ENTRY *Link;\r | |
667 | KNOWN_HANDLE *KnownHandle;\r | |
668 | \r | |
669 | for (Link = mFvHandleList.ForwardLink; Link != &mFvHandleList; Link = Link->ForwardLink) {\r | |
670 | KnownHandle = CR(Link, KNOWN_HANDLE, Link, KNOWN_HANDLE_SIGNATURE);\r | |
671 | if (KnownHandle->Handle == FvHandle) {\r | |
672 | return TRUE;\r | |
673 | }\r | |
674 | }\r | |
675 | return FALSE;\r | |
676 | }\r | |
677 | \r | |
28a00297 | 678 | \r |
162ed594 | 679 | /**\r |
28a00297 | 680 | Remember that Fv protocol on FvHandle has had it's drivers placed on the\r |
681 | mDiscoveredList. This fucntion adds entries on the mFvHandleList. Items are\r | |
682 | never removed/freed from the mFvHandleList.\r | |
683 | \r | |
162ed594 | 684 | @param FvHandle The handle of a FV that has been processed\r |
28a00297 | 685 | \r |
162ed594 | 686 | **/\r |
162ed594 | 687 | VOID\r |
688 | FvIsBeingProcesssed (\r | |
689 | IN EFI_HANDLE FvHandle\r | |
690 | )\r | |
28a00297 | 691 | {\r |
692 | KNOWN_HANDLE *KnownHandle;\r | |
693 | \r | |
9c4ac31c | 694 | KnownHandle = AllocatePool (sizeof (KNOWN_HANDLE));\r |
28a00297 | 695 | ASSERT (KnownHandle != NULL);\r |
696 | \r | |
697 | KnownHandle->Signature = KNOWN_HANDLE_SIGNATURE;\r | |
698 | KnownHandle->Handle = FvHandle;\r | |
699 | InsertTailList (&mFvHandleList, &KnownHandle->Link);\r | |
700 | }\r | |
701 | \r | |
702 | \r | |
703 | \r | |
162ed594 | 704 | \r |
705 | /**\r | |
706 | Convert FvHandle and DriverName into an EFI device path\r | |
707 | \r | |
022c6d45 | 708 | @param Fv Fv protocol, needed to read Depex info out of\r |
709 | FLASH.\r | |
710 | @param FvHandle Handle for Fv, needed in the\r | |
711 | EFI_CORE_DRIVER_ENTRY so that the PE image can be\r | |
712 | read out of the FV at a later time.\r | |
713 | @param DriverName Name of driver to add to mDiscoveredList.\r | |
162ed594 | 714 | \r |
715 | @return Pointer to device path constructed from FvHandle and DriverName\r | |
716 | \r | |
717 | **/\r | |
28a00297 | 718 | EFI_DEVICE_PATH_PROTOCOL *\r |
719 | CoreFvToDevicePath (\r | |
0c2b5da8 | 720 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r |
28a00297 | 721 | IN EFI_HANDLE FvHandle,\r |
722 | IN EFI_GUID *DriverName\r | |
723 | )\r | |
28a00297 | 724 | {\r |
725 | EFI_STATUS Status;\r | |
726 | EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;\r | |
727 | EFI_DEVICE_PATH_PROTOCOL *FileNameDevicePath;\r | |
728 | \r | |
729 | //\r | |
730 | // Remember the device path of the FV\r | |
731 | //\r | |
732 | Status = CoreHandleProtocol (FvHandle, &gEfiDevicePathProtocolGuid, (VOID **)&FvDevicePath);\r | |
733 | if (EFI_ERROR (Status)) {\r | |
734 | FileNameDevicePath = NULL;\r | |
735 | } else {\r | |
736 | //\r | |
737 | // Build a device path to the file in the FV to pass into gBS->LoadImage\r | |
738 | //\r | |
739 | EfiInitializeFwVolDevicepathNode (&mFvDevicePath.File, DriverName);\r | |
1232b214 | 740 | SetDevicePathEndNode (&mFvDevicePath.End);\r |
28a00297 | 741 | \r |
9c4ac31c | 742 | FileNameDevicePath = AppendDevicePath (\r |
022c6d45 | 743 | FvDevicePath,\r |
28a00297 | 744 | (EFI_DEVICE_PATH_PROTOCOL *)&mFvDevicePath\r |
745 | );\r | |
746 | }\r | |
747 | \r | |
748 | return FileNameDevicePath;\r | |
749 | }\r | |
750 | \r | |
751 | \r | |
752 | \r | |
162ed594 | 753 | /**\r |
754 | Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,\r | |
28a00297 | 755 | and initilize any state variables. Read the Depex from the FV and store it\r |
756 | in DriverEntry. Pre-process the Depex to set the SOR, Before and After state.\r | |
757 | The Discovered list is never free'ed and contains booleans that represent the\r | |
758 | other possible DXE driver states.\r | |
759 | \r | |
022c6d45 | 760 | @param Fv Fv protocol, needed to read Depex info out of\r |
761 | FLASH.\r | |
762 | @param FvHandle Handle for Fv, needed in the\r | |
763 | EFI_CORE_DRIVER_ENTRY so that the PE image can be\r | |
764 | read out of the FV at a later time.\r | |
765 | @param DriverName Name of driver to add to mDiscoveredList.\r | |
28a00297 | 766 | \r |
022c6d45 | 767 | @retval EFI_SUCCESS If driver was added to the mDiscoveredList.\r |
768 | @retval EFI_ALREADY_STARTED The driver has already been started. Only one\r | |
769 | DriverName may be active in the system at any one\r | |
162ed594 | 770 | time.\r |
28a00297 | 771 | \r |
162ed594 | 772 | **/\r |
773 | EFI_STATUS\r | |
774 | CoreAddToDriverList (\r | |
775 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r | |
776 | IN EFI_HANDLE FvHandle,\r | |
777 | IN EFI_GUID *DriverName\r | |
778 | )\r | |
28a00297 | 779 | {\r |
780 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
781 | \r | |
022c6d45 | 782 | \r |
28a00297 | 783 | //\r |
022c6d45 | 784 | // Create the Driver Entry for the list. ZeroPool initializes lots of variables to\r |
28a00297 | 785 | // NULL or FALSE.\r |
786 | //\r | |
9c4ac31c | 787 | DriverEntry = AllocateZeroPool (sizeof (EFI_CORE_DRIVER_ENTRY));\r |
28a00297 | 788 | ASSERT (DriverEntry != NULL);\r |
789 | \r | |
790 | DriverEntry->Signature = EFI_CORE_DRIVER_ENTRY_SIGNATURE;\r | |
e94a9ff7 | 791 | CopyGuid (&DriverEntry->FileName, DriverName);\r |
28a00297 | 792 | DriverEntry->FvHandle = FvHandle;\r |
793 | DriverEntry->Fv = Fv;\r | |
794 | DriverEntry->FvFileDevicePath = CoreFvToDevicePath (Fv, FvHandle, DriverName);\r | |
795 | \r | |
796 | CoreGetDepexSectionAndPreProccess (DriverEntry);\r | |
022c6d45 | 797 | \r |
28a00297 | 798 | CoreAcquireDispatcherLock ();\r |
022c6d45 | 799 | \r |
28a00297 | 800 | InsertTailList (&mDiscoveredList, &DriverEntry->Link);\r |
801 | \r | |
802 | CoreReleaseDispatcherLock ();\r | |
803 | \r | |
804 | return EFI_SUCCESS;\r | |
805 | }\r | |
806 | \r | |
bbc0f1bb | 807 | \r |
162ed594 | 808 | /**\r |
bbc0f1bb | 809 | Check if a FV Image type file (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) is\r |
810 | described by a EFI_HOB_FIRMWARE_VOLUME2 Hob.\r | |
811 | \r | |
022c6d45 | 812 | @param FvHandle The handle which FVB protocol installed on.\r |
813 | @param DriverName The driver guid specified.\r | |
bbc0f1bb | 814 | \r |
022c6d45 | 815 | @retval TRUE This file is found in a EFI_HOB_FIRMWARE_VOLUME2\r |
816 | Hob.\r | |
162ed594 | 817 | @retval FALSE Not found.\r |
bbc0f1bb | 818 | \r |
162ed594 | 819 | **/\r |
162ed594 | 820 | BOOLEAN\r |
821 | FvFoundInHobFv2 (\r | |
822 | IN EFI_HANDLE FvHandle,\r | |
823 | IN CONST EFI_GUID *DriverName\r | |
824 | )\r | |
bbc0f1bb | 825 | {\r |
826 | EFI_PEI_HOB_POINTERS HobFv2;\r | |
022c6d45 | 827 | \r |
bbc0f1bb | 828 | HobFv2.Raw = GetHobList ();\r |
022c6d45 | 829 | \r |
bbc0f1bb | 830 | while ((HobFv2.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobFv2.Raw)) != NULL) {\r |
831 | if (CompareGuid (DriverName, &HobFv2.FirmwareVolume2->FileName)) {\r | |
b0d803fe | 832 | return TRUE;\r |
bbc0f1bb | 833 | }\r |
834 | HobFv2.Raw = GET_NEXT_HOB (HobFv2);\r | |
835 | }\r | |
836 | \r | |
837 | return FALSE;\r | |
838 | }\r | |
28a00297 | 839 | \r |
840 | \r | |
162ed594 | 841 | \r |
842 | /**\r | |
843 | Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.\r | |
844 | \r | |
022c6d45 | 845 | @param Fv The FIRMWARE_VOLUME protocol installed on the FV.\r |
846 | @param FvHandle The handle which FVB protocol installed on.\r | |
847 | @param DriverName The driver guid specified.\r | |
162ed594 | 848 | \r |
022c6d45 | 849 | @retval EFI_OUT_OF_RESOURCES No enough memory or other resource.\r |
850 | @retval EFI_VOLUME_CORRUPTED Corrupted volume.\r | |
162ed594 | 851 | @retval EFI_SUCCESS Function successfully returned.\r |
852 | \r | |
853 | **/\r | |
022c6d45 | 854 | EFI_STATUS\r |
28a00297 | 855 | CoreProcessFvImageFile (\r |
0c2b5da8 | 856 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r |
28a00297 | 857 | IN EFI_HANDLE FvHandle,\r |
858 | IN EFI_GUID *DriverName\r | |
859 | )\r | |
28a00297 | 860 | {\r |
861 | EFI_STATUS Status;\r | |
862 | EFI_SECTION_TYPE SectionType;\r | |
863 | UINT32 AuthenticationStatus;\r | |
864 | VOID *Buffer;\r | |
38837959 | 865 | VOID *AlignedBuffer;\r |
28a00297 | 866 | UINTN BufferSize;\r |
38837959 | 867 | EFI_FIRMWARE_VOLUME_HEADER *FvHeader;\r |
022c6d45 | 868 | UINT32 FvAlignment;\r |
28a00297 | 869 | \r |
870 | //\r | |
871 | // Read the first (and only the first) firmware volume section\r | |
872 | //\r | |
e94a9ff7 | 873 | SectionType = EFI_SECTION_FIRMWARE_VOLUME_IMAGE;\r |
874 | FvHeader = NULL;\r | |
875 | FvAlignment = 0;\r | |
876 | Buffer = NULL;\r | |
877 | BufferSize = 0;\r | |
38837959 | 878 | AlignedBuffer = NULL;\r |
28a00297 | 879 | Status = Fv->ReadSection (\r |
022c6d45 | 880 | Fv,\r |
881 | DriverName,\r | |
882 | SectionType,\r | |
883 | 0,\r | |
884 | &Buffer,\r | |
e94a9ff7 | 885 | &BufferSize,\r |
886 | &AuthenticationStatus\r | |
887 | );\r | |
28a00297 | 888 | if (!EFI_ERROR (Status)) {\r |
889 | //\r | |
38837959 | 890 | // FvImage should be at its required alignment.\r |
28a00297 | 891 | //\r |
38837959 | 892 | FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Buffer;\r |
6d9a0f28 LG |
893 | //\r |
894 | // Get FvHeader alignment\r | |
895 | //\r | |
38837959 LG |
896 | FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r |
897 | //\r | |
6d9a0f28 | 898 | // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value. \r |
022c6d45 | 899 | //\r |
38837959 LG |
900 | if (FvAlignment < 8) {\r |
901 | FvAlignment = 8;\r | |
902 | }\r | |
e94a9ff7 | 903 | //\r |
904 | // Allocate the aligned buffer for the FvImage.\r | |
905 | //\r | |
b2c5e194 | 906 | AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN) FvAlignment);\r |
38837959 LG |
907 | if (AlignedBuffer == NULL) {\r |
908 | Status = EFI_OUT_OF_RESOURCES;\r | |
909 | } else {\r | |
910 | //\r | |
911 | // Move FvImage into the aligned buffer and release the original buffer.\r | |
912 | //\r | |
913 | CopyMem (AlignedBuffer, Buffer, BufferSize);\r | |
914 | CoreFreePool (Buffer);\r | |
915 | Buffer = NULL;\r | |
916 | //\r | |
917 | // Produce a FVB protocol for the file\r | |
918 | //\r | |
919 | Status = ProduceFVBProtocolOnBuffer (\r | |
920 | (EFI_PHYSICAL_ADDRESS) (UINTN) AlignedBuffer,\r | |
921 | (UINT64)BufferSize,\r | |
922 | FvHandle,\r | |
923 | NULL\r | |
924 | );\r | |
925 | }\r | |
28a00297 | 926 | }\r |
927 | \r | |
022c6d45 | 928 | if (EFI_ERROR (Status)) {\r |
38837959 LG |
929 | //\r |
930 | // ReadSection or Produce FVB failed, Free data buffer\r | |
931 | //\r | |
932 | if (Buffer != NULL) {\r | |
9c4ac31c | 933 | FreePool (Buffer);\r |
38837959 | 934 | }\r |
022c6d45 | 935 | \r |
38837959 | 936 | if (AlignedBuffer != NULL) {\r |
b2c5e194 | 937 | FreeAlignedPages (AlignedBuffer, EFI_SIZE_TO_PAGES (BufferSize));\r |
38837959 | 938 | }\r |
28a00297 | 939 | }\r |
940 | \r | |
941 | return Status;\r | |
942 | }\r | |
943 | \r | |
28a00297 | 944 | \r |
162ed594 | 945 | /**\r |
946 | Event notification that is fired every time a FV dispatch protocol is added.\r | |
28a00297 | 947 | More than one protocol may have been added when this event is fired, so you\r |
948 | must loop on CoreLocateHandle () to see how many protocols were added and\r | |
949 | do the following to each FV:\r | |
162ed594 | 950 | If the Fv has already been processed, skip it. If the Fv has not been\r |
28a00297 | 951 | processed then mark it as being processed, as we are about to process it.\r |
162ed594 | 952 | Read the Fv and add any driver in the Fv to the mDiscoveredList.The\r |
28a00297 | 953 | mDiscoveredList is never free'ed and contains variables that define\r |
162ed594 | 954 | the other states the DXE driver transitions to..\r |
28a00297 | 955 | While you are at it read the A Priori file into memory.\r |
956 | Place drivers in the A Priori list onto the mScheduledQueue.\r | |
957 | \r | |
022c6d45 | 958 | @param Event The Event that is being processed, not used.\r |
162ed594 | 959 | @param Context Event Context, not used.\r |
28a00297 | 960 | \r |
162ed594 | 961 | **/\r |
162ed594 | 962 | VOID\r |
963 | EFIAPI\r | |
964 | CoreFwVolEventProtocolNotify (\r | |
965 | IN EFI_EVENT Event,\r | |
966 | IN VOID *Context\r | |
967 | )\r | |
28a00297 | 968 | {\r |
969 | EFI_STATUS Status;\r | |
970 | EFI_STATUS GetNextFileStatus;\r | |
971 | EFI_STATUS SecurityStatus;\r | |
0c2b5da8 | 972 | EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r |
28a00297 | 973 | EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;\r |
974 | EFI_HANDLE FvHandle;\r | |
975 | UINTN BufferSize;\r | |
976 | EFI_GUID NameGuid;\r | |
977 | UINTN Key;\r | |
978 | EFI_FV_FILETYPE Type;\r | |
979 | EFI_FV_FILE_ATTRIBUTES Attributes;\r | |
980 | UINTN Size;\r | |
981 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
982 | EFI_GUID *AprioriFile;\r | |
983 | UINTN AprioriEntryCount;\r | |
984 | UINTN Index;\r | |
985 | LIST_ENTRY *Link;\r | |
986 | UINT32 AuthenticationStatus;\r | |
987 | UINTN SizeOfBuffer;\r | |
988 | \r | |
989 | \r | |
990 | while (TRUE) {\r | |
991 | BufferSize = sizeof (EFI_HANDLE);\r | |
992 | Status = CoreLocateHandle (\r | |
e94a9ff7 | 993 | ByRegisterNotify,\r |
994 | NULL,\r | |
995 | mFwVolEventRegistration,\r | |
996 | &BufferSize,\r | |
997 | &FvHandle\r | |
998 | );\r | |
28a00297 | 999 | if (EFI_ERROR (Status)) {\r |
1000 | //\r | |
1001 | // If no more notification events exit\r | |
1002 | //\r | |
1003 | return;\r | |
1004 | }\r | |
1005 | \r | |
1006 | if (FvHasBeenProcessed (FvHandle)) {\r | |
1007 | //\r | |
1008 | // This Fv has already been processed so lets skip it!\r | |
1009 | //\r | |
1010 | continue;\r | |
1011 | }\r | |
1012 | \r | |
28a00297 | 1013 | //\r |
1014 | // Since we are about to process this Fv mark it as processed.\r | |
1015 | //\r | |
1016 | FvIsBeingProcesssed (FvHandle);\r | |
1017 | \r | |
0c2b5da8 | 1018 | Status = CoreHandleProtocol (FvHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&Fv);\r |
d2fbaaab | 1019 | if (EFI_ERROR (Status) || Fv == NULL) {\r |
28a00297 | 1020 | //\r |
cd539d48 | 1021 | // FvHandle must have Firmware Volume2 protocol thus we should never get here.\r |
28a00297 | 1022 | //\r |
1023 | ASSERT (FALSE);\r | |
1024 | continue;\r | |
1025 | }\r | |
022c6d45 | 1026 | \r |
28a00297 | 1027 | Status = CoreHandleProtocol (FvHandle, &gEfiDevicePathProtocolGuid, (VOID **)&FvDevicePath);\r |
1028 | if (EFI_ERROR (Status)) {\r | |
1029 | //\r | |
1030 | // The Firmware volume doesn't have device path, can't be dispatched.\r | |
1031 | //\r | |
1032 | continue;\r | |
1033 | }\r | |
022c6d45 | 1034 | \r |
28a00297 | 1035 | //\r |
022c6d45 | 1036 | // Evaluate the authentication status of the Firmware Volume through\r |
28a00297 | 1037 | // Security Architectural Protocol\r |
1038 | //\r | |
1039 | if (gSecurity != NULL) {\r | |
1040 | SecurityStatus = gSecurity->FileAuthenticationState (\r | |
022c6d45 | 1041 | gSecurity,\r |
1042 | 0,\r | |
28a00297 | 1043 | FvDevicePath\r |
1044 | );\r | |
1045 | if (SecurityStatus != EFI_SUCCESS) {\r | |
1046 | //\r | |
1047 | // Security check failed. The firmware volume should not be used for any purpose.\r | |
1048 | //\r | |
1049 | continue;\r | |
1050 | }\r | |
022c6d45 | 1051 | }\r |
1052 | \r | |
28a00297 | 1053 | //\r |
022c6d45 | 1054 | // Discover Drivers in FV and add them to the Discovered Driver List.\r |
1055 | // Process EFI_FV_FILETYPE_DRIVER type and then EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER\r | |
28a00297 | 1056 | // EFI_FV_FILETYPE_DXE_CORE is processed to produce a Loaded Image protocol for the core\r |
1057 | // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE is processed to create a Fvb\r | |
1058 | //\r | |
e94a9ff7 | 1059 | for (Index = 0; Index < sizeof (mDxeFileTypes) / sizeof (EFI_FV_FILETYPE); Index++) {\r |
28a00297 | 1060 | //\r |
1061 | // Initialize the search key\r | |
1062 | //\r | |
1063 | Key = 0;\r | |
1064 | do {\r | |
1065 | Type = mDxeFileTypes[Index];\r | |
1066 | GetNextFileStatus = Fv->GetNextFile (\r | |
022c6d45 | 1067 | Fv,\r |
28a00297 | 1068 | &Key,\r |
022c6d45 | 1069 | &Type,\r |
1070 | &NameGuid,\r | |
1071 | &Attributes,\r | |
28a00297 | 1072 | &Size\r |
1073 | );\r | |
1074 | if (!EFI_ERROR (GetNextFileStatus)) {\r | |
1075 | if (Type == EFI_FV_FILETYPE_DXE_CORE) {\r | |
1076 | //\r | |
1077 | // If this is the DXE core fill in it's DevicePath & DeviceHandle\r | |
1078 | //\r | |
1079 | if (gDxeCoreLoadedImage->FilePath == NULL) {\r | |
1080 | if (CompareGuid (&NameGuid, gDxeCoreFileName)) {\r | |
1081 | //\r | |
1082 | // Maybe One specail Fv cantains only one DXE_CORE module, so its device path must\r | |
1083 | // be initialized completely.\r | |
1084 | //\r | |
1085 | EfiInitializeFwVolDevicepathNode (&mFvDevicePath.File, &NameGuid);\r | |
1232b214 | 1086 | SetDevicePathEndNode (&mFvDevicePath.End);\r |
28a00297 | 1087 | \r |
9c4ac31c | 1088 | gDxeCoreLoadedImage->FilePath = DuplicateDevicePath (\r |
28a00297 | 1089 | (EFI_DEVICE_PATH_PROTOCOL *)&mFvDevicePath\r |
1090 | );\r | |
1091 | gDxeCoreLoadedImage->DeviceHandle = FvHandle;\r | |
1092 | }\r | |
1093 | }\r | |
1094 | } else if (Type == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) {\r | |
bbc0f1bb | 1095 | //\r |
022c6d45 | 1096 | // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r |
bbc0f1bb | 1097 | // been extracted.\r |
1098 | //\r | |
1099 | if (FvFoundInHobFv2 (FvHandle, &NameGuid)) {\r | |
1100 | continue;\r | |
1101 | }\r | |
28a00297 | 1102 | //\r |
1103 | // Found a firmware volume image. Produce a firmware volume block\r | |
022c6d45 | 1104 | // protocol for it so it gets dispatched from. This is usually a\r |
28a00297 | 1105 | // capsule.\r |
1106 | //\r | |
1107 | CoreProcessFvImageFile (Fv, FvHandle, &NameGuid);\r | |
1108 | } else {\r | |
1109 | //\r | |
1110 | // Transition driver from Undiscovered to Discovered state\r | |
1111 | //\r | |
1112 | CoreAddToDriverList (Fv, FvHandle, &NameGuid);\r | |
1113 | }\r | |
1114 | }\r | |
1115 | } while (!EFI_ERROR (GetNextFileStatus));\r | |
1116 | }\r | |
022c6d45 | 1117 | \r |
28a00297 | 1118 | //\r |
1119 | // Read the array of GUIDs from the Apriori file if it is present in the firmware volume\r | |
1120 | //\r | |
1121 | AprioriFile = NULL;\r | |
1122 | Status = Fv->ReadSection (\r | |
1123 | Fv,\r | |
1124 | &gAprioriGuid,\r | |
1125 | EFI_SECTION_RAW,\r | |
1126 | 0,\r | |
1127 | (VOID **)&AprioriFile,\r | |
1128 | &SizeOfBuffer,\r | |
1129 | &AuthenticationStatus\r | |
1130 | );\r | |
1131 | if (!EFI_ERROR (Status)) {\r | |
1132 | AprioriEntryCount = SizeOfBuffer / sizeof (EFI_GUID);\r | |
1133 | } else {\r | |
1134 | AprioriEntryCount = 0;\r | |
1135 | }\r | |
1136 | \r | |
1137 | //\r | |
1138 | // Put drivers on Apriori List on the Scheduled queue. The Discovered List includes\r | |
1139 | // drivers not in the current FV and these must be skipped since the a priori list\r | |
1140 | // is only valid for the FV that it resided in.\r | |
1141 | //\r | |
1142 | CoreAcquireDispatcherLock ();\r | |
022c6d45 | 1143 | \r |
28a00297 | 1144 | for (Index = 0; Index < AprioriEntryCount; Index++) {\r |
1145 | for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r | |
1146 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
1147 | if (CompareGuid (&DriverEntry->FileName, &AprioriFile[Index]) &&\r | |
1148 | (FvHandle == DriverEntry->FvHandle)) {\r | |
1149 | DriverEntry->Dependent = FALSE;\r | |
1150 | DriverEntry->Scheduled = TRUE;\r | |
1151 | InsertTailList (&mScheduledQueue, &DriverEntry->ScheduledLink);\r | |
1152 | break;\r | |
1153 | }\r | |
1154 | }\r | |
1155 | }\r | |
1156 | \r | |
1157 | CoreReleaseDispatcherLock ();\r | |
1158 | \r | |
1159 | //\r | |
022c6d45 | 1160 | // Free data allocated by Fv->ReadSection ()\r |
28a00297 | 1161 | //\r |
022c6d45 | 1162 | CoreFreePool (AprioriFile);\r |
28a00297 | 1163 | }\r |
1164 | }\r | |
1165 | \r | |
1166 | \r | |
28a00297 | 1167 | \r |
162ed594 | 1168 | /**\r |
28a00297 | 1169 | Initialize the dispatcher. Initialize the notification function that runs when\r |
e94a9ff7 | 1170 | an FV2 protocol is added to the system.\r |
28a00297 | 1171 | \r |
162ed594 | 1172 | **/\r |
1173 | VOID\r | |
1174 | CoreInitializeDispatcher (\r | |
1175 | VOID\r | |
1176 | )\r | |
28a00297 | 1177 | {\r |
7899b797 | 1178 | mFwVolEvent = EfiCreateProtocolNotifyEvent (\r |
022c6d45 | 1179 | &gEfiFirmwareVolume2ProtocolGuid,\r |
28a00297 | 1180 | TPL_CALLBACK,\r |
1181 | CoreFwVolEventProtocolNotify,\r | |
1182 | NULL,\r | |
7899b797 | 1183 | &mFwVolEventRegistration\r |
28a00297 | 1184 | );\r |
1185 | }\r | |
1186 | \r | |
1187 | //\r | |
1188 | // Function only used in debug builds\r | |
1189 | //\r | |
162ed594 | 1190 | \r |
1191 | /**\r | |
1192 | Traverse the discovered list for any drivers that were discovered but not loaded\r | |
1193 | because the dependency experessions evaluated to false.\r | |
1194 | \r | |
1195 | **/\r | |
28a00297 | 1196 | VOID\r |
1197 | CoreDisplayDiscoveredNotDispatched (\r | |
1198 | VOID\r | |
1199 | )\r | |
28a00297 | 1200 | {\r |
1201 | LIST_ENTRY *Link;\r | |
1202 | EFI_CORE_DRIVER_ENTRY *DriverEntry;\r | |
1203 | \r | |
1204 | for (Link = mDiscoveredList.ForwardLink;Link !=&mDiscoveredList; Link = Link->ForwardLink) {\r | |
1205 | DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r | |
1206 | if (DriverEntry->Dependent) {\r | |
162ed594 | 1207 | DEBUG ((DEBUG_LOAD, "Driver %g was discovered but not loaded!!\n", &DriverEntry->FileName));\r |
28a00297 | 1208 | }\r |
1209 | }\r | |
1210 | }\r |