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