]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Core/Dxe/Dispatcher/Dispatcher.c
Add the missing supported module type in MdePkg DxeServicesTableLib instance.
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Dispatcher / Dispatcher.c
CommitLineData
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
54cd17e9 29Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
cd5ebaa0 30This program and the accompanying materials\r
23c98c94 31are licensed and made available under the terms and conditions of the BSD License\r
32which accompanies this distribution. The full text of the license may be found at\r
33http://opensource.org/licenses/bsd-license.php\r
34\r
35THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
36WITHOUT 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 46LIST_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
52LIST_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
57LIST_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
62EFI_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
68BOOLEAN gDispatcherRunning = FALSE;\r
69\r
70//\r
71// Module globals to manage the FwVol registration notification event\r
72//\r
73EFI_EVENT mFwVolEvent;\r
74VOID *mFwVolEventRegistration;\r
75\r
76//\r
77// List of file types supported by dispatcher\r
78//\r
022c6d45 79EFI_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
87typedef 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
92FV_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 109VOID\r
110CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (\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 131VOID\r
132EFIAPI\r
133CoreFwVolEventProtocolNotify (\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 151EFI_DEVICE_PATH_PROTOCOL *\r
152CoreFvToDevicePath (\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 178EFI_STATUS\r
179CoreAddToDriverList (\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 197EFI_STATUS\r
28a00297 198CoreProcessFvImageFile (\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 209VOID\r
210CoreAcquireDispatcherLock (\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 222VOID\r
223CoreReleaseDispatcherLock (\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 243EFI_STATUS\r
244CoreGetDepexSectionAndPreProccess (\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 310EFI_STATUS\r
311EFIAPI\r
312CoreSchedule (\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
6a55eea3 336 DEBUG ((DEBUG_DISPATCH, "Schedule FFS(%g) - EFI_SUCCESS\n", DriverName));\r
337 \r
28a00297 338 return EFI_SUCCESS;\r
339 }\r
340 }\r
6a55eea3 341 \r
342 DEBUG ((DEBUG_DISPATCH, "Schedule FFS(%g) - EFI_NOT_FOUND\n", DriverName));\r
343 \r
022c6d45 344 return EFI_NOT_FOUND;\r
28a00297 345}\r
346\r
347\r
162ed594 348\r
349/**\r
e94a9ff7 350 Convert a driver from the Untrused back to the Scheduled state.\r
162ed594 351\r
022c6d45 352 @param FirmwareVolumeHandle The handle of the Firmware Volume that contains\r
353 the firmware file specified by DriverName.\r
354 @param DriverName The Driver name to put in the Scheduled state\r
162ed594 355\r
022c6d45 356 @retval EFI_SUCCESS The file was found in the untrusted state, and it\r
357 was promoted to the trusted state.\r
358 @retval EFI_NOT_FOUND The file was not found in the untrusted state.\r
162ed594 359\r
360**/\r
28a00297 361EFI_STATUS\r
362EFIAPI\r
363CoreTrust (\r
364 IN EFI_HANDLE FirmwareVolumeHandle,\r
365 IN EFI_GUID *DriverName\r
366 )\r
28a00297 367{\r
368 LIST_ENTRY *Link;\r
369 EFI_CORE_DRIVER_ENTRY *DriverEntry;\r
370\r
371 //\r
372 // Check every driver\r
373 //\r
374 for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r
375 DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r
376 if (DriverEntry->FvHandle == FirmwareVolumeHandle &&\r
022c6d45 377 DriverEntry->Untrusted &&\r
28a00297 378 CompareGuid (DriverName, &DriverEntry->FileName)) {\r
379 //\r
380 // Transition driver from Untrusted to Scheduled state.\r
381 //\r
382 CoreAcquireDispatcherLock ();\r
383 DriverEntry->Untrusted = FALSE;\r
384 DriverEntry->Scheduled = TRUE;\r
385 InsertTailList (&mScheduledQueue, &DriverEntry->ScheduledLink);\r
386 CoreReleaseDispatcherLock ();\r
022c6d45 387\r
28a00297 388 return EFI_SUCCESS;\r
389 }\r
390 }\r
022c6d45 391 return EFI_NOT_FOUND;\r
28a00297 392}\r
393\r
394\r
202c3279 395/**\r
396 An empty function to pass error checking of CreateEventEx ().\r
397\r
398 @param Event Event whose notification function is being invoked.\r
399 @param Context Pointer to the notification function's context,\r
400 which is implementation-dependent.\r
401\r
402**/\r
403VOID\r
404EFIAPI\r
54cd17e9 405CoreEmptyCallbackFunction (\r
202c3279 406 IN EFI_EVENT Event,\r
407 IN VOID *Context\r
408 )\r
409{\r
410 return;\r
411}\r
28a00297 412\r
162ed594 413/**\r
414 This is the main Dispatcher for DXE and it exits when there are no more\r
28a00297 415 drivers to run. Drain the mScheduledQueue and load and start a PE\r
162ed594 416 image for each driver. Search the mDiscoveredList to see if any driver can\r
28a00297 417 be placed on the mScheduledQueue. If no drivers are placed on the\r
418 mScheduledQueue exit the function. On exit it is assumed the Bds()\r
162ed594 419 will be called, and when the Bds() exits the Dispatcher will be called\r
28a00297 420 again.\r
421\r
022c6d45 422 @retval EFI_ALREADY_STARTED The DXE Dispatcher is already running\r
423 @retval EFI_NOT_FOUND No DXE Drivers were dispatched\r
424 @retval EFI_SUCCESS One or more DXE Drivers were dispatched\r
28a00297 425\r
162ed594 426**/\r
162ed594 427EFI_STATUS\r
428EFIAPI\r
429CoreDispatcher (\r
430 VOID\r
431 )\r
28a00297 432{\r
433 EFI_STATUS Status;\r
434 EFI_STATUS ReturnStatus;\r
435 LIST_ENTRY *Link;\r
436 EFI_CORE_DRIVER_ENTRY *DriverEntry;\r
437 BOOLEAN ReadyToRun;\r
202c3279 438 EFI_EVENT DxeDispatchEvent;\r
439 \r
28a00297 440\r
441 if (gDispatcherRunning) {\r
442 //\r
443 // If the dispatcher is running don't let it be restarted.\r
444 //\r
445 return EFI_ALREADY_STARTED;\r
446 }\r
447\r
448 gDispatcherRunning = TRUE;\r
449\r
202c3279 450 Status = CoreCreateEventEx (\r
451 EVT_NOTIFY_SIGNAL,\r
452 TPL_NOTIFY,\r
54cd17e9 453 CoreEmptyCallbackFunction,\r
202c3279 454 NULL,\r
455 &gEfiEventDxeDispatchGuid,\r
456 &DxeDispatchEvent\r
457 );\r
458 if (EFI_ERROR (Status)) {\r
459 return Status;\r
460 }\r
28a00297 461\r
462 ReturnStatus = EFI_NOT_FOUND;\r
463 do {\r
464 //\r
465 // Drain the Scheduled Queue\r
466 //\r
467 while (!IsListEmpty (&mScheduledQueue)) {\r
468 DriverEntry = CR (\r
469 mScheduledQueue.ForwardLink,\r
470 EFI_CORE_DRIVER_ENTRY,\r
471 ScheduledLink,\r
472 EFI_CORE_DRIVER_ENTRY_SIGNATURE\r
473 );\r
474\r
475 //\r
476 // Load the DXE Driver image into memory. If the Driver was transitioned from\r
477 // Untrused to Scheduled it would have already been loaded so we may need to\r
478 // skip the LoadImage\r
479 //\r
480 if (DriverEntry->ImageHandle == NULL) {\r
94903510 481 DEBUG ((DEBUG_INFO, "Loading driver %g\n", &DriverEntry->FileName));\r
28a00297 482 Status = CoreLoadImage (\r
022c6d45 483 FALSE,\r
484 gDxeCoreImageHandle,\r
28a00297 485 DriverEntry->FvFileDevicePath,\r
022c6d45 486 NULL,\r
487 0,\r
28a00297 488 &DriverEntry->ImageHandle\r
489 );\r
490\r
491 //\r
492 // Update the driver state to reflect that it's been loaded\r
493 //\r
494 if (EFI_ERROR (Status)) {\r
495 CoreAcquireDispatcherLock ();\r
496\r
497 if (Status == EFI_SECURITY_VIOLATION) {\r
498 //\r
499 // Take driver from Scheduled to Untrused state\r
500 //\r
501 DriverEntry->Untrusted = TRUE;\r
502 } else {\r
503 //\r
504 // The DXE Driver could not be loaded, and do not attempt to load or start it again.\r
022c6d45 505 // Take driver from Scheduled to Initialized.\r
28a00297 506 //\r
507 // This case include the Never Trusted state if EFI_ACCESS_DENIED is returned\r
508 //\r
509 DriverEntry->Initialized = TRUE;\r
510 }\r
511\r
512 DriverEntry->Scheduled = FALSE;\r
513 RemoveEntryList (&DriverEntry->ScheduledLink);\r
022c6d45 514\r
28a00297 515 CoreReleaseDispatcherLock ();\r
022c6d45 516\r
28a00297 517 //\r
518 // If it's an error don't try the StartImage\r
519 //\r
520 continue;\r
521 }\r
522 }\r
523\r
524 CoreAcquireDispatcherLock ();\r
525\r
526 DriverEntry->Scheduled = FALSE;\r
527 DriverEntry->Initialized = TRUE;\r
528 RemoveEntryList (&DriverEntry->ScheduledLink);\r
022c6d45 529\r
28a00297 530 CoreReleaseDispatcherLock ();\r
531\r
2680a308 532 \r
533 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
534 EFI_PROGRESS_CODE,\r
f9876ecf 535 (EFI_SOFTWARE_DXE_CORE | EFI_SW_PC_INIT_BEGIN),\r
2680a308 536 &DriverEntry->ImageHandle,\r
537 sizeof (DriverEntry->ImageHandle)\r
797a9d67 538 );\r
2680a308 539\r
28a00297 540 Status = CoreStartImage (DriverEntry->ImageHandle, NULL, NULL);\r
2680a308 541\r
542 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (\r
543 EFI_PROGRESS_CODE,\r
f9876ecf 544 (EFI_SOFTWARE_DXE_CORE | EFI_SW_PC_INIT_END),\r
2680a308 545 &DriverEntry->ImageHandle,\r
546 sizeof (DriverEntry->ImageHandle)\r
797a9d67 547 );\r
28a00297 548\r
549 ReturnStatus = EFI_SUCCESS;\r
550 }\r
551\r
0e4483bc
LG
552 //\r
553 // Now DXE Dispatcher finished one round of dispatch, signal an event group\r
554 // so that SMM Dispatcher get chance to dispatch SMM Drivers which depend\r
555 // on UEFI protocols\r
556 //\r
557 if (!EFI_ERROR (ReturnStatus)) {\r
558 CoreSignalEvent (DxeDispatchEvent);\r
559 }\r
560\r
28a00297 561 //\r
562 // Search DriverList for items to place on Scheduled Queue\r
563 //\r
564 ReadyToRun = FALSE;\r
565 for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r
566 DriverEntry = CR (Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r
567\r
568 if (DriverEntry->DepexProtocolError){\r
569 //\r
570 // If Section Extraction Protocol did not let the Depex be read before retry the read\r
571 //\r
572 Status = CoreGetDepexSectionAndPreProccess (DriverEntry);\r
022c6d45 573 }\r
28a00297 574\r
575 if (DriverEntry->Dependent) {\r
576 if (CoreIsSchedulable (DriverEntry)) {\r
022c6d45 577 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry);\r
28a00297 578 ReadyToRun = TRUE;\r
022c6d45 579 }\r
6a55eea3 580 } else {\r
581 if (DriverEntry->Unrequested) {\r
582 DEBUG ((DEBUG_DISPATCH, "Evaluate DXE DEPEX for FFS(%g)\n", &DriverEntry->FileName));\r
583 DEBUG ((DEBUG_DISPATCH, " SOR = Not Requested\n"));\r
584 DEBUG ((DEBUG_DISPATCH, " RESULT = FALSE\n"));\r
585 }\r
28a00297 586 }\r
587 }\r
588 } while (ReadyToRun);\r
589\r
202c3279 590 //\r
591 // Close DXE dispatch Event\r
592 //\r
593 CoreCloseEvent (DxeDispatchEvent);\r
594\r
28a00297 595 gDispatcherRunning = FALSE;\r
596\r
597 return ReturnStatus;\r
598}\r
599\r
28a00297 600\r
162ed594 601/**\r
602 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you\r
28a00297 603 must add any driver with a before dependency on InsertedDriverEntry first.\r
604 You do this by recursively calling this routine. After all the Befores are\r
162ed594 605 processed you can add InsertedDriverEntry to the mScheduledQueue.\r
606 Then you can add any driver with an After dependency on InsertedDriverEntry\r
28a00297 607 by recursively calling this routine.\r
608\r
162ed594 609 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue\r
28a00297 610\r
162ed594 611**/\r
162ed594 612VOID\r
613CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (\r
614 IN EFI_CORE_DRIVER_ENTRY *InsertedDriverEntry\r
615 )\r
28a00297 616{\r
617 LIST_ENTRY *Link;\r
618 EFI_CORE_DRIVER_ENTRY *DriverEntry;\r
619\r
620 //\r
621 // Process Before Dependency\r
622 //\r
623 for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r
624 DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r
6a55eea3 625 if (DriverEntry->Before && DriverEntry->Dependent && DriverEntry != InsertedDriverEntry) {\r
626 DEBUG ((DEBUG_DISPATCH, "Evaluate DXE DEPEX for FFS(%g)\n", &DriverEntry->FileName));\r
627 DEBUG ((DEBUG_DISPATCH, " BEFORE FFS(%g) = ", &DriverEntry->BeforeAfterGuid));\r
28a00297 628 if (CompareGuid (&InsertedDriverEntry->FileName, &DriverEntry->BeforeAfterGuid)) {\r
629 //\r
630 // Recursively process BEFORE\r
631 //\r
6a55eea3 632 DEBUG ((DEBUG_DISPATCH, "TRUE\n END\n RESULT = TRUE\n"));\r
28a00297 633 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry);\r
6a55eea3 634 } else {\r
635 DEBUG ((DEBUG_DISPATCH, "FALSE\n END\n RESULT = FALSE\n"));\r
28a00297 636 }\r
637 }\r
638 }\r
639\r
640 //\r
641 // Convert driver from Dependent to Scheduled state\r
642 //\r
643 CoreAcquireDispatcherLock ();\r
644\r
645 InsertedDriverEntry->Dependent = FALSE;\r
646 InsertedDriverEntry->Scheduled = TRUE;\r
647 InsertTailList (&mScheduledQueue, &InsertedDriverEntry->ScheduledLink);\r
022c6d45 648\r
28a00297 649 CoreReleaseDispatcherLock ();\r
650\r
651 //\r
652 // Process After Dependency\r
653 //\r
654 for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r
655 DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r
6a55eea3 656 if (DriverEntry->After && DriverEntry->Dependent && DriverEntry != InsertedDriverEntry) {\r
657 DEBUG ((DEBUG_DISPATCH, "Evaluate DXE DEPEX for FFS(%g)\n", &DriverEntry->FileName));\r
658 DEBUG ((DEBUG_DISPATCH, " AFTER FFS(%g) = ", &DriverEntry->BeforeAfterGuid));\r
28a00297 659 if (CompareGuid (&InsertedDriverEntry->FileName, &DriverEntry->BeforeAfterGuid)) {\r
660 //\r
661 // Recursively process AFTER\r
662 //\r
6a55eea3 663 DEBUG ((DEBUG_DISPATCH, "TRUE\n END\n RESULT = TRUE\n"));\r
28a00297 664 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry);\r
6a55eea3 665 } else {\r
666 DEBUG ((DEBUG_DISPATCH, "FALSE\n END\n RESULT = FALSE\n"));\r
28a00297 667 }\r
668 }\r
669 }\r
670}\r
671\r
28a00297 672\r
162ed594 673/**\r
28a00297 674 Return TRUE if the Fv has been processed, FALSE if not.\r
675\r
022c6d45 676 @param FvHandle The handle of a FV that's being tested\r
28a00297 677\r
022c6d45 678 @retval TRUE Fv protocol on FvHandle has been processed\r
e94a9ff7 679 @retval FALSE Fv protocol on FvHandle has not yet been processed\r
28a00297 680\r
162ed594 681**/\r
162ed594 682BOOLEAN\r
683FvHasBeenProcessed (\r
684 IN EFI_HANDLE FvHandle\r
685 )\r
28a00297 686{\r
687 LIST_ENTRY *Link;\r
688 KNOWN_HANDLE *KnownHandle;\r
689\r
690 for (Link = mFvHandleList.ForwardLink; Link != &mFvHandleList; Link = Link->ForwardLink) {\r
691 KnownHandle = CR(Link, KNOWN_HANDLE, Link, KNOWN_HANDLE_SIGNATURE);\r
692 if (KnownHandle->Handle == FvHandle) {\r
693 return TRUE;\r
694 }\r
695 }\r
696 return FALSE;\r
697}\r
698\r
28a00297 699\r
162ed594 700/**\r
28a00297 701 Remember that Fv protocol on FvHandle has had it's drivers placed on the\r
702 mDiscoveredList. This fucntion adds entries on the mFvHandleList. Items are\r
703 never removed/freed from the mFvHandleList.\r
704\r
162ed594 705 @param FvHandle The handle of a FV that has been processed\r
28a00297 706\r
162ed594 707**/\r
162ed594 708VOID\r
709FvIsBeingProcesssed (\r
710 IN EFI_HANDLE FvHandle\r
711 )\r
28a00297 712{\r
713 KNOWN_HANDLE *KnownHandle;\r
714\r
9c4ac31c 715 KnownHandle = AllocatePool (sizeof (KNOWN_HANDLE));\r
28a00297 716 ASSERT (KnownHandle != NULL);\r
717\r
718 KnownHandle->Signature = KNOWN_HANDLE_SIGNATURE;\r
719 KnownHandle->Handle = FvHandle;\r
720 InsertTailList (&mFvHandleList, &KnownHandle->Link);\r
721}\r
722\r
723\r
724\r
162ed594 725\r
726/**\r
727 Convert FvHandle and DriverName into an EFI device path\r
728\r
022c6d45 729 @param Fv Fv protocol, needed to read Depex info out of\r
730 FLASH.\r
731 @param FvHandle Handle for Fv, needed in the\r
732 EFI_CORE_DRIVER_ENTRY so that the PE image can be\r
733 read out of the FV at a later time.\r
734 @param DriverName Name of driver to add to mDiscoveredList.\r
162ed594 735\r
736 @return Pointer to device path constructed from FvHandle and DriverName\r
737\r
738**/\r
28a00297 739EFI_DEVICE_PATH_PROTOCOL *\r
740CoreFvToDevicePath (\r
0c2b5da8 741 IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r
28a00297 742 IN EFI_HANDLE FvHandle,\r
743 IN EFI_GUID *DriverName\r
744 )\r
28a00297 745{\r
746 EFI_STATUS Status;\r
747 EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;\r
748 EFI_DEVICE_PATH_PROTOCOL *FileNameDevicePath;\r
749\r
750 //\r
751 // Remember the device path of the FV\r
752 //\r
753 Status = CoreHandleProtocol (FvHandle, &gEfiDevicePathProtocolGuid, (VOID **)&FvDevicePath);\r
754 if (EFI_ERROR (Status)) {\r
755 FileNameDevicePath = NULL;\r
756 } else {\r
757 //\r
758 // Build a device path to the file in the FV to pass into gBS->LoadImage\r
759 //\r
760 EfiInitializeFwVolDevicepathNode (&mFvDevicePath.File, DriverName);\r
1232b214 761 SetDevicePathEndNode (&mFvDevicePath.End);\r
28a00297 762\r
9c4ac31c 763 FileNameDevicePath = AppendDevicePath (\r
022c6d45 764 FvDevicePath,\r
28a00297 765 (EFI_DEVICE_PATH_PROTOCOL *)&mFvDevicePath\r
766 );\r
767 }\r
768\r
769 return FileNameDevicePath;\r
770}\r
771\r
772\r
773\r
162ed594 774/**\r
775 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,\r
28a00297 776 and initilize any state variables. Read the Depex from the FV and store it\r
777 in DriverEntry. Pre-process the Depex to set the SOR, Before and After state.\r
778 The Discovered list is never free'ed and contains booleans that represent the\r
779 other possible DXE driver states.\r
780\r
022c6d45 781 @param Fv Fv protocol, needed to read Depex info out of\r
782 FLASH.\r
783 @param FvHandle Handle for Fv, needed in the\r
784 EFI_CORE_DRIVER_ENTRY so that the PE image can be\r
785 read out of the FV at a later time.\r
786 @param DriverName Name of driver to add to mDiscoveredList.\r
28a00297 787\r
022c6d45 788 @retval EFI_SUCCESS If driver was added to the mDiscoveredList.\r
789 @retval EFI_ALREADY_STARTED The driver has already been started. Only one\r
790 DriverName may be active in the system at any one\r
162ed594 791 time.\r
28a00297 792\r
162ed594 793**/\r
794EFI_STATUS\r
795CoreAddToDriverList (\r
796 IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r
797 IN EFI_HANDLE FvHandle,\r
798 IN EFI_GUID *DriverName\r
799 )\r
28a00297 800{\r
801 EFI_CORE_DRIVER_ENTRY *DriverEntry;\r
802\r
022c6d45 803\r
28a00297 804 //\r
022c6d45 805 // Create the Driver Entry for the list. ZeroPool initializes lots of variables to\r
28a00297 806 // NULL or FALSE.\r
807 //\r
9c4ac31c 808 DriverEntry = AllocateZeroPool (sizeof (EFI_CORE_DRIVER_ENTRY));\r
28a00297 809 ASSERT (DriverEntry != NULL);\r
810\r
811 DriverEntry->Signature = EFI_CORE_DRIVER_ENTRY_SIGNATURE;\r
e94a9ff7 812 CopyGuid (&DriverEntry->FileName, DriverName);\r
28a00297 813 DriverEntry->FvHandle = FvHandle;\r
814 DriverEntry->Fv = Fv;\r
815 DriverEntry->FvFileDevicePath = CoreFvToDevicePath (Fv, FvHandle, DriverName);\r
816\r
817 CoreGetDepexSectionAndPreProccess (DriverEntry);\r
022c6d45 818\r
28a00297 819 CoreAcquireDispatcherLock ();\r
022c6d45 820\r
28a00297 821 InsertTailList (&mDiscoveredList, &DriverEntry->Link);\r
822\r
823 CoreReleaseDispatcherLock ();\r
824\r
825 return EFI_SUCCESS;\r
826}\r
827\r
bbc0f1bb 828\r
162ed594 829/**\r
bbc0f1bb 830 Check if a FV Image type file (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) is\r
831 described by a EFI_HOB_FIRMWARE_VOLUME2 Hob.\r
832\r
022c6d45 833 @param FvHandle The handle which FVB protocol installed on.\r
834 @param DriverName The driver guid specified.\r
bbc0f1bb 835\r
022c6d45 836 @retval TRUE This file is found in a EFI_HOB_FIRMWARE_VOLUME2\r
837 Hob.\r
162ed594 838 @retval FALSE Not found.\r
bbc0f1bb 839\r
162ed594 840**/\r
162ed594 841BOOLEAN\r
842FvFoundInHobFv2 (\r
843 IN EFI_HANDLE FvHandle,\r
844 IN CONST EFI_GUID *DriverName\r
845 )\r
bbc0f1bb 846{\r
847 EFI_PEI_HOB_POINTERS HobFv2;\r
022c6d45 848\r
bbc0f1bb 849 HobFv2.Raw = GetHobList ();\r
022c6d45 850\r
bbc0f1bb 851 while ((HobFv2.Raw = GetNextHob (EFI_HOB_TYPE_FV2, HobFv2.Raw)) != NULL) {\r
852 if (CompareGuid (DriverName, &HobFv2.FirmwareVolume2->FileName)) {\r
b0d803fe 853 return TRUE;\r
bbc0f1bb 854 }\r
855 HobFv2.Raw = GET_NEXT_HOB (HobFv2);\r
856 }\r
857\r
858 return FALSE;\r
859}\r
28a00297 860\r
861\r
162ed594 862\r
863/**\r
864 Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.\r
865\r
022c6d45 866 @param Fv The FIRMWARE_VOLUME protocol installed on the FV.\r
867 @param FvHandle The handle which FVB protocol installed on.\r
868 @param DriverName The driver guid specified.\r
162ed594 869\r
022c6d45 870 @retval EFI_OUT_OF_RESOURCES No enough memory or other resource.\r
871 @retval EFI_VOLUME_CORRUPTED Corrupted volume.\r
162ed594 872 @retval EFI_SUCCESS Function successfully returned.\r
873\r
874**/\r
022c6d45 875EFI_STATUS\r
28a00297 876CoreProcessFvImageFile (\r
0c2b5da8 877 IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r
28a00297 878 IN EFI_HANDLE FvHandle,\r
879 IN EFI_GUID *DriverName\r
880 )\r
28a00297 881{\r
882 EFI_STATUS Status;\r
883 EFI_SECTION_TYPE SectionType;\r
884 UINT32 AuthenticationStatus;\r
885 VOID *Buffer;\r
38837959 886 VOID *AlignedBuffer;\r
28a00297 887 UINTN BufferSize;\r
38837959 888 EFI_FIRMWARE_VOLUME_HEADER *FvHeader;\r
022c6d45 889 UINT32 FvAlignment;\r
28a00297 890\r
891 //\r
892 // Read the first (and only the first) firmware volume section\r
893 //\r
e94a9ff7 894 SectionType = EFI_SECTION_FIRMWARE_VOLUME_IMAGE;\r
895 FvHeader = NULL;\r
896 FvAlignment = 0;\r
897 Buffer = NULL;\r
898 BufferSize = 0;\r
38837959 899 AlignedBuffer = NULL;\r
28a00297 900 Status = Fv->ReadSection (\r
022c6d45 901 Fv,\r
902 DriverName,\r
903 SectionType,\r
904 0,\r
905 &Buffer,\r
e94a9ff7 906 &BufferSize,\r
907 &AuthenticationStatus\r
908 );\r
28a00297 909 if (!EFI_ERROR (Status)) {\r
910 //\r
38837959 911 // FvImage should be at its required alignment.\r
28a00297 912 //\r
38837959 913 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) Buffer;\r
6d9a0f28
LG
914 //\r
915 // Get FvHeader alignment\r
916 //\r
38837959
LG
917 FvAlignment = 1 << ((FvHeader->Attributes & EFI_FVB2_ALIGNMENT) >> 16);\r
918 //\r
6d9a0f28 919 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value. \r
022c6d45 920 //\r
38837959
LG
921 if (FvAlignment < 8) {\r
922 FvAlignment = 8;\r
923 }\r
e94a9ff7 924 //\r
925 // Allocate the aligned buffer for the FvImage.\r
926 //\r
b2c5e194 927 AlignedBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize), (UINTN) FvAlignment);\r
38837959
LG
928 if (AlignedBuffer == NULL) {\r
929 Status = EFI_OUT_OF_RESOURCES;\r
930 } else {\r
931 //\r
932 // Move FvImage into the aligned buffer and release the original buffer.\r
933 //\r
934 CopyMem (AlignedBuffer, Buffer, BufferSize);\r
935 CoreFreePool (Buffer);\r
936 Buffer = NULL;\r
937 //\r
938 // Produce a FVB protocol for the file\r
939 //\r
940 Status = ProduceFVBProtocolOnBuffer (\r
941 (EFI_PHYSICAL_ADDRESS) (UINTN) AlignedBuffer,\r
942 (UINT64)BufferSize,\r
943 FvHandle,\r
944 NULL\r
945 );\r
946 }\r
28a00297 947 }\r
948\r
022c6d45 949 if (EFI_ERROR (Status)) {\r
38837959
LG
950 //\r
951 // ReadSection or Produce FVB failed, Free data buffer\r
952 //\r
953 if (Buffer != NULL) {\r
9c4ac31c 954 FreePool (Buffer);\r
38837959 955 }\r
022c6d45 956\r
38837959 957 if (AlignedBuffer != NULL) {\r
b2c5e194 958 FreeAlignedPages (AlignedBuffer, EFI_SIZE_TO_PAGES (BufferSize));\r
38837959 959 }\r
28a00297 960 }\r
961\r
962 return Status;\r
963}\r
964\r
28a00297 965\r
162ed594 966/**\r
967 Event notification that is fired every time a FV dispatch protocol is added.\r
28a00297 968 More than one protocol may have been added when this event is fired, so you\r
969 must loop on CoreLocateHandle () to see how many protocols were added and\r
970 do the following to each FV:\r
162ed594 971 If the Fv has already been processed, skip it. If the Fv has not been\r
28a00297 972 processed then mark it as being processed, as we are about to process it.\r
162ed594 973 Read the Fv and add any driver in the Fv to the mDiscoveredList.The\r
28a00297 974 mDiscoveredList is never free'ed and contains variables that define\r
162ed594 975 the other states the DXE driver transitions to..\r
28a00297 976 While you are at it read the A Priori file into memory.\r
977 Place drivers in the A Priori list onto the mScheduledQueue.\r
978\r
022c6d45 979 @param Event The Event that is being processed, not used.\r
162ed594 980 @param Context Event Context, not used.\r
28a00297 981\r
162ed594 982**/\r
162ed594 983VOID\r
984EFIAPI\r
985CoreFwVolEventProtocolNotify (\r
986 IN EFI_EVENT Event,\r
987 IN VOID *Context\r
988 )\r
28a00297 989{\r
990 EFI_STATUS Status;\r
991 EFI_STATUS GetNextFileStatus;\r
992 EFI_STATUS SecurityStatus;\r
0c2b5da8 993 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
28a00297 994 EFI_DEVICE_PATH_PROTOCOL *FvDevicePath;\r
995 EFI_HANDLE FvHandle;\r
996 UINTN BufferSize;\r
997 EFI_GUID NameGuid;\r
998 UINTN Key;\r
999 EFI_FV_FILETYPE Type;\r
1000 EFI_FV_FILE_ATTRIBUTES Attributes;\r
1001 UINTN Size;\r
1002 EFI_CORE_DRIVER_ENTRY *DriverEntry;\r
1003 EFI_GUID *AprioriFile;\r
1004 UINTN AprioriEntryCount;\r
1005 UINTN Index;\r
1006 LIST_ENTRY *Link;\r
1007 UINT32 AuthenticationStatus;\r
1008 UINTN SizeOfBuffer;\r
1009\r
1010\r
1011 while (TRUE) {\r
1012 BufferSize = sizeof (EFI_HANDLE);\r
1013 Status = CoreLocateHandle (\r
e94a9ff7 1014 ByRegisterNotify,\r
1015 NULL,\r
1016 mFwVolEventRegistration,\r
1017 &BufferSize,\r
1018 &FvHandle\r
1019 );\r
28a00297 1020 if (EFI_ERROR (Status)) {\r
1021 //\r
1022 // If no more notification events exit\r
1023 //\r
1024 return;\r
1025 }\r
1026\r
1027 if (FvHasBeenProcessed (FvHandle)) {\r
1028 //\r
1029 // This Fv has already been processed so lets skip it!\r
1030 //\r
1031 continue;\r
1032 }\r
1033\r
28a00297 1034 //\r
1035 // Since we are about to process this Fv mark it as processed.\r
1036 //\r
1037 FvIsBeingProcesssed (FvHandle);\r
1038\r
0c2b5da8 1039 Status = CoreHandleProtocol (FvHandle, &gEfiFirmwareVolume2ProtocolGuid, (VOID **)&Fv);\r
d2fbaaab 1040 if (EFI_ERROR (Status) || Fv == NULL) {\r
28a00297 1041 //\r
cd539d48 1042 // FvHandle must have Firmware Volume2 protocol thus we should never get here.\r
28a00297 1043 //\r
1044 ASSERT (FALSE);\r
1045 continue;\r
1046 }\r
022c6d45 1047\r
28a00297 1048 Status = CoreHandleProtocol (FvHandle, &gEfiDevicePathProtocolGuid, (VOID **)&FvDevicePath);\r
1049 if (EFI_ERROR (Status)) {\r
1050 //\r
1051 // The Firmware volume doesn't have device path, can't be dispatched.\r
1052 //\r
1053 continue;\r
1054 }\r
022c6d45 1055\r
28a00297 1056 //\r
022c6d45 1057 // Evaluate the authentication status of the Firmware Volume through\r
28a00297 1058 // Security Architectural Protocol\r
1059 //\r
1060 if (gSecurity != NULL) {\r
1061 SecurityStatus = gSecurity->FileAuthenticationState (\r
022c6d45 1062 gSecurity,\r
1063 0,\r
28a00297 1064 FvDevicePath\r
1065 );\r
1066 if (SecurityStatus != EFI_SUCCESS) {\r
1067 //\r
1068 // Security check failed. The firmware volume should not be used for any purpose.\r
1069 //\r
1070 continue;\r
1071 }\r
022c6d45 1072 }\r
1073\r
28a00297 1074 //\r
022c6d45 1075 // Discover Drivers in FV and add them to the Discovered Driver List.\r
1076 // Process EFI_FV_FILETYPE_DRIVER type and then EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER\r
28a00297 1077 // EFI_FV_FILETYPE_DXE_CORE is processed to produce a Loaded Image protocol for the core\r
1078 // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE is processed to create a Fvb\r
1079 //\r
e94a9ff7 1080 for (Index = 0; Index < sizeof (mDxeFileTypes) / sizeof (EFI_FV_FILETYPE); Index++) {\r
28a00297 1081 //\r
1082 // Initialize the search key\r
1083 //\r
1084 Key = 0;\r
1085 do {\r
1086 Type = mDxeFileTypes[Index];\r
1087 GetNextFileStatus = Fv->GetNextFile (\r
022c6d45 1088 Fv,\r
28a00297 1089 &Key,\r
022c6d45 1090 &Type,\r
1091 &NameGuid,\r
1092 &Attributes,\r
28a00297 1093 &Size\r
1094 );\r
1095 if (!EFI_ERROR (GetNextFileStatus)) {\r
1096 if (Type == EFI_FV_FILETYPE_DXE_CORE) {\r
1097 //\r
1098 // If this is the DXE core fill in it's DevicePath & DeviceHandle\r
1099 //\r
1100 if (gDxeCoreLoadedImage->FilePath == NULL) {\r
1101 if (CompareGuid (&NameGuid, gDxeCoreFileName)) {\r
1102 //\r
1103 // Maybe One specail Fv cantains only one DXE_CORE module, so its device path must\r
1104 // be initialized completely.\r
1105 //\r
1106 EfiInitializeFwVolDevicepathNode (&mFvDevicePath.File, &NameGuid);\r
1232b214 1107 SetDevicePathEndNode (&mFvDevicePath.End);\r
28a00297 1108\r
9c4ac31c 1109 gDxeCoreLoadedImage->FilePath = DuplicateDevicePath (\r
28a00297 1110 (EFI_DEVICE_PATH_PROTOCOL *)&mFvDevicePath\r
1111 );\r
1112 gDxeCoreLoadedImage->DeviceHandle = FvHandle;\r
1113 }\r
1114 }\r
1115 } else if (Type == EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) {\r
bbc0f1bb 1116 //\r
022c6d45 1117 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already\r
bbc0f1bb 1118 // been extracted.\r
1119 //\r
1120 if (FvFoundInHobFv2 (FvHandle, &NameGuid)) {\r
1121 continue;\r
1122 }\r
28a00297 1123 //\r
1124 // Found a firmware volume image. Produce a firmware volume block\r
022c6d45 1125 // protocol for it so it gets dispatched from. This is usually a\r
28a00297 1126 // capsule.\r
1127 //\r
1128 CoreProcessFvImageFile (Fv, FvHandle, &NameGuid);\r
1129 } else {\r
1130 //\r
1131 // Transition driver from Undiscovered to Discovered state\r
1132 //\r
1133 CoreAddToDriverList (Fv, FvHandle, &NameGuid);\r
1134 }\r
1135 }\r
1136 } while (!EFI_ERROR (GetNextFileStatus));\r
1137 }\r
022c6d45 1138\r
28a00297 1139 //\r
1140 // Read the array of GUIDs from the Apriori file if it is present in the firmware volume\r
1141 //\r
1142 AprioriFile = NULL;\r
1143 Status = Fv->ReadSection (\r
1144 Fv,\r
1145 &gAprioriGuid,\r
1146 EFI_SECTION_RAW,\r
1147 0,\r
1148 (VOID **)&AprioriFile,\r
1149 &SizeOfBuffer,\r
1150 &AuthenticationStatus\r
1151 );\r
1152 if (!EFI_ERROR (Status)) {\r
1153 AprioriEntryCount = SizeOfBuffer / sizeof (EFI_GUID);\r
1154 } else {\r
1155 AprioriEntryCount = 0;\r
1156 }\r
1157\r
1158 //\r
1159 // Put drivers on Apriori List on the Scheduled queue. The Discovered List includes\r
1160 // drivers not in the current FV and these must be skipped since the a priori list\r
1161 // is only valid for the FV that it resided in.\r
1162 //\r
022c6d45 1163\r
28a00297 1164 for (Index = 0; Index < AprioriEntryCount; Index++) {\r
1165 for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {\r
1166 DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r
1167 if (CompareGuid (&DriverEntry->FileName, &AprioriFile[Index]) &&\r
1168 (FvHandle == DriverEntry->FvHandle)) {\r
6a55eea3 1169 CoreAcquireDispatcherLock ();\r
28a00297 1170 DriverEntry->Dependent = FALSE;\r
1171 DriverEntry->Scheduled = TRUE;\r
1172 InsertTailList (&mScheduledQueue, &DriverEntry->ScheduledLink);\r
6a55eea3 1173 CoreReleaseDispatcherLock ();\r
1174 DEBUG ((DEBUG_DISPATCH, "Evaluate DXE DEPEX for FFS(%g)\n", &DriverEntry->FileName));\r
1175 DEBUG ((DEBUG_DISPATCH, " RESULT = TRUE (Apriori)\n"));\r
28a00297 1176 break;\r
1177 }\r
1178 }\r
1179 }\r
1180\r
28a00297 1181 //\r
022c6d45 1182 // Free data allocated by Fv->ReadSection ()\r
28a00297 1183 //\r
022c6d45 1184 CoreFreePool (AprioriFile);\r
28a00297 1185 }\r
1186}\r
1187\r
1188\r
28a00297 1189\r
162ed594 1190/**\r
28a00297 1191 Initialize the dispatcher. Initialize the notification function that runs when\r
e94a9ff7 1192 an FV2 protocol is added to the system.\r
28a00297 1193\r
162ed594 1194**/\r
1195VOID\r
1196CoreInitializeDispatcher (\r
1197 VOID\r
1198 )\r
28a00297 1199{\r
7899b797 1200 mFwVolEvent = EfiCreateProtocolNotifyEvent (\r
022c6d45 1201 &gEfiFirmwareVolume2ProtocolGuid,\r
28a00297 1202 TPL_CALLBACK,\r
1203 CoreFwVolEventProtocolNotify,\r
1204 NULL,\r
7899b797 1205 &mFwVolEventRegistration\r
28a00297 1206 );\r
1207}\r
1208\r
1209//\r
1210// Function only used in debug builds\r
1211//\r
162ed594 1212\r
1213/**\r
1214 Traverse the discovered list for any drivers that were discovered but not loaded\r
1215 because the dependency experessions evaluated to false.\r
1216\r
1217**/\r
28a00297 1218VOID\r
1219CoreDisplayDiscoveredNotDispatched (\r
1220 VOID\r
1221 )\r
28a00297 1222{\r
1223 LIST_ENTRY *Link;\r
1224 EFI_CORE_DRIVER_ENTRY *DriverEntry;\r
1225\r
1226 for (Link = mDiscoveredList.ForwardLink;Link !=&mDiscoveredList; Link = Link->ForwardLink) {\r
1227 DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);\r
1228 if (DriverEntry->Dependent) {\r
162ed594 1229 DEBUG ((DEBUG_LOAD, "Driver %g was discovered but not loaded!!\n", &DriverEntry->FileName));\r
28a00297 1230 }\r
1231 }\r
1232}\r