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