3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 Step #1 - When a FV protocol is added to the system every driver in the FV
21 is added to the mDiscoveredList. The SOR, Before, and After Depex are
22 pre-processed as drivers are added to the mDiscoveredList. If an Apriori
23 file exists in the FV those drivers are addeded to the
24 mScheduledQueue. The mFvHandleList is used to make sure a
25 FV is only processed once.
27 Step #2 - Dispatch. Remove driver from the mScheduledQueue and load and
28 start it. After mScheduledQueue is drained check the
29 mDiscoveredList to see if any item has a Depex that is ready to
30 be placed on the mScheduledQueue.
32 Step #3 - Adding to the mScheduledQueue requires that you process Before
33 and After dependencies. This is done recursively as the call to add
34 to the mScheduledQueue checks for Before and recursively adds
35 all Befores. It then addes the item that was passed in and then
36 processess the After dependecies by recursively calling the routine.
39 The rules for the dispatcher are in chapter 10 of the DXE CIS. Figure 10-3
40 is the state diagram for the DXE dispatcher
42 Depex - Dependency Expresion.
43 SOR - Schedule On Request - Don't schedule if this bit is set.
50 // The Driver List contains one copy of every driver that has been discovered.
51 // Items are never removed from the driver list. List of EFI_CORE_DRIVER_ENTRY
53 LIST_ENTRY mDiscoveredList
= INITIALIZE_LIST_HEAD_VARIABLE (mDiscoveredList
);
56 // Queue of drivers that are ready to dispatch. This queue is a subset of the
57 // mDiscoveredList.list of EFI_CORE_DRIVER_ENTRY.
59 LIST_ENTRY mScheduledQueue
= INITIALIZE_LIST_HEAD_VARIABLE (mScheduledQueue
);
62 // List of handles who's Fv's have been parsed and added to the mFwDriverList.
64 LIST_ENTRY mFvHandleList
= INITIALIZE_LIST_HEAD_VARIABLE (mFvHandleList
); // list of KNOWN_HANDLE
67 // Lock for mDiscoveredList, mScheduledQueue, gDispatcherRunning.
69 EFI_LOCK mDispatcherLock
= EFI_INITIALIZE_LOCK_VARIABLE (EFI_TPL_HIGH_LEVEL
);
73 // Flag for the DXE Dispacher. TRUE if dispatcher is execuing.
75 BOOLEAN gDispatcherRunning
= FALSE
;
78 // Module globals to manage the FwVol registration notification event
80 EFI_EVENT mFwVolEvent
;
81 VOID
*mFwVolEventRegistration
;
84 // List of file types supported by dispatcher
86 static EFI_FV_FILETYPE mDxeFileTypes
[] = {
87 EFI_FV_FILETYPE_DRIVER
,
88 EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
,
89 EFI_FV_FILETYPE_DXE_CORE
,
90 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
94 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH File
;
95 EFI_DEVICE_PATH_PROTOCOL End
;
96 } FV_FILEPATH_DEVICE_PATH
;
98 FV_FILEPATH_DEVICE_PATH mFvDevicePath
;
102 // Function Prototypes
105 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
106 IN EFI_CORE_DRIVER_ENTRY
*InsertedDriverEntry
111 CoreFwVolEventProtocolNotify (
116 EFI_DEVICE_PATH_PROTOCOL
*
118 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
,
119 IN EFI_HANDLE FvHandle
,
120 IN EFI_GUID
*DriverName
125 CoreAddToDriverList (
126 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
,
127 IN EFI_HANDLE FvHandle
,
128 IN EFI_GUID
*DriverName
133 CoreProcessFvImageFile (
134 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
,
135 IN EFI_HANDLE FvHandle
,
136 IN EFI_GUID
*DriverName
141 CoreAcquireDispatcherLock (
148 Enter critical section by gaining lock on mDispatcherLock
161 CoreAcquireLock (&mDispatcherLock
);
166 CoreReleaseDispatcherLock (
173 Exit critical section by releasing lock on mDispatcherLock
185 CoreReleaseLock (&mDispatcherLock
);
190 CoreGetDepexSectionAndPreProccess (
191 IN EFI_CORE_DRIVER_ENTRY
*DriverEntry
197 Read Depex and pre-process the Depex for Before and After. If Section Extraction
198 protocol returns an error via ReadSection defer the reading of the Depex.
202 DriverEntry - Driver to work on.
206 EFI_SUCCESS - Depex read and preprossesed
208 EFI_PROTOCOL_ERROR - The section extraction protocol returned an error and
209 Depex reading needs to be retried.
211 Other Error - DEPEX not found.
216 EFI_SECTION_TYPE SectionType
;
217 UINT32 AuthenticationStatus
;
218 EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
;
221 Fv
= DriverEntry
->Fv
;
224 // Grab Depex info, it will never be free'ed.
226 SectionType
= EFI_SECTION_DXE_DEPEX
;
227 Status
= Fv
->ReadSection (
229 &DriverEntry
->FileName
,
233 (UINTN
*)&DriverEntry
->DepexSize
,
234 &AuthenticationStatus
236 if (EFI_ERROR (Status
)) {
237 if (Status
== EFI_PROTOCOL_ERROR
) {
239 // The section extraction protocol failed so set protocol error flag
241 DriverEntry
->DepexProtocolError
= TRUE
;
244 // If no Depex assume EFI 1.1 driver model
246 DriverEntry
->Depex
= NULL
;
247 DriverEntry
->Dependent
= TRUE
;
248 DriverEntry
->DepexProtocolError
= FALSE
;
252 // Set Before, After, and Unrequested state information based on Depex
253 // Driver will be put in Dependent or Unrequested state
255 CorePreProcessDepex (DriverEntry
);
256 DriverEntry
->DepexProtocolError
= FALSE
;
266 IN EFI_HANDLE FirmwareVolumeHandle
,
267 IN EFI_GUID
*DriverName
273 Check every driver and locate a matching one. If the driver is found, the Unrequested
274 state flag is cleared.
278 FirmwareVolumeHandle - The handle of the Firmware Volume that contains the firmware
279 file specified by DriverName.
281 DriverName - The Driver name to put in the Dependent state.
285 EFI_SUCCESS - The DriverName was found and it's SOR bit was cleared
287 EFI_NOT_FOUND - The DriverName does not exist or it's SOR bit was not set.
292 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
295 // Check every driver
297 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
298 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
299 if (DriverEntry
->FvHandle
== FirmwareVolumeHandle
&&
300 DriverEntry
->Unrequested
&&
301 CompareGuid (DriverName
, &DriverEntry
->FileName
)) {
303 // Move the driver from the Unrequested to the Dependent state
305 CoreAcquireDispatcherLock ();
306 DriverEntry
->Unrequested
= FALSE
;
307 DriverEntry
->Dependent
= TRUE
;
308 CoreReleaseDispatcherLock ();
313 return EFI_NOT_FOUND
;
321 IN EFI_HANDLE FirmwareVolumeHandle
,
322 IN EFI_GUID
*DriverName
328 Convert a driver from the Untrused back to the Scheduled state
332 FirmwareVolumeHandle - The handle of the Firmware Volume that contains the firmware
333 file specified by DriverName.
335 DriverName - The Driver name to put in the Scheduled state
339 EFI_SUCCESS - The file was found in the untrusted state, and it was promoted
340 to the trusted state.
342 EFI_NOT_FOUND - The file was not found in the untrusted state.
347 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
350 // Check every driver
352 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
353 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
354 if (DriverEntry
->FvHandle
== FirmwareVolumeHandle
&&
355 DriverEntry
->Untrusted
&&
356 CompareGuid (DriverName
, &DriverEntry
->FileName
)) {
358 // Transition driver from Untrusted to Scheduled state.
360 CoreAcquireDispatcherLock ();
361 DriverEntry
->Untrusted
= FALSE
;
362 DriverEntry
->Scheduled
= TRUE
;
363 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
364 CoreReleaseDispatcherLock ();
369 return EFI_NOT_FOUND
;
383 This is the main Dispatcher for DXE and it exits when there are no more
384 drivers to run. Drain the mScheduledQueue and load and start a PE
385 image for each driver. Search the mDiscoveredList to see if any driver can
386 be placed on the mScheduledQueue. If no drivers are placed on the
387 mScheduledQueue exit the function. On exit it is assumed the Bds()
388 will be called, and when the Bds() exits the Dispatcher will be called
397 EFI_ALREADY_STARTED - The DXE Dispatcher is already running
399 EFI_NOT_FOUND - No DXE Drivers were dispatched
401 EFI_SUCCESS - One or more DXE Drivers were dispatched
406 EFI_STATUS ReturnStatus
;
408 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
411 if (gDispatcherRunning
) {
413 // If the dispatcher is running don't let it be restarted.
415 return EFI_ALREADY_STARTED
;
418 gDispatcherRunning
= TRUE
;
421 ReturnStatus
= EFI_NOT_FOUND
;
424 // Drain the Scheduled Queue
426 while (!IsListEmpty (&mScheduledQueue
)) {
428 mScheduledQueue
.ForwardLink
,
429 EFI_CORE_DRIVER_ENTRY
,
431 EFI_CORE_DRIVER_ENTRY_SIGNATURE
435 // Load the DXE Driver image into memory. If the Driver was transitioned from
436 // Untrused to Scheduled it would have already been loaded so we may need to
437 // skip the LoadImage
439 if (DriverEntry
->ImageHandle
== NULL
) {
440 Status
= CoreLoadImage (
443 DriverEntry
->FvFileDevicePath
,
446 &DriverEntry
->ImageHandle
450 // Update the driver state to reflect that it's been loaded
452 if (EFI_ERROR (Status
)) {
453 CoreAcquireDispatcherLock ();
455 if (Status
== EFI_SECURITY_VIOLATION
) {
457 // Take driver from Scheduled to Untrused state
459 DriverEntry
->Untrusted
= TRUE
;
462 // The DXE Driver could not be loaded, and do not attempt to load or start it again.
463 // Take driver from Scheduled to Initialized.
465 // This case include the Never Trusted state if EFI_ACCESS_DENIED is returned
467 DriverEntry
->Initialized
= TRUE
;
470 DriverEntry
->Scheduled
= FALSE
;
471 RemoveEntryList (&DriverEntry
->ScheduledLink
);
473 CoreReleaseDispatcherLock ();
476 // If it's an error don't try the StartImage
482 CoreAcquireDispatcherLock ();
484 DriverEntry
->Scheduled
= FALSE
;
485 DriverEntry
->Initialized
= TRUE
;
486 RemoveEntryList (&DriverEntry
->ScheduledLink
);
488 CoreReleaseDispatcherLock ();
491 CoreReportProgressCodeSpecific (EFI_SOFTWARE_DXE_CORE
| EFI_SW_PC_INIT_BEGIN
, DriverEntry
->ImageHandle
);
492 Status
= CoreStartImage (DriverEntry
->ImageHandle
, NULL
, NULL
);
493 CoreReportProgressCodeSpecific (EFI_SOFTWARE_DXE_CORE
| EFI_SW_PC_INIT_END
, DriverEntry
->ImageHandle
);
495 ReturnStatus
= EFI_SUCCESS
;
499 // Search DriverList for items to place on Scheduled Queue
502 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
503 DriverEntry
= CR (Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
505 if (DriverEntry
->DepexProtocolError
){
507 // If Section Extraction Protocol did not let the Depex be read before retry the read
509 Status
= CoreGetDepexSectionAndPreProccess (DriverEntry
);
512 if (DriverEntry
->Dependent
) {
513 if (CoreIsSchedulable (DriverEntry
)) {
514 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
519 } while (ReadyToRun
);
521 gDispatcherRunning
= FALSE
;
528 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
529 IN EFI_CORE_DRIVER_ENTRY
*InsertedDriverEntry
535 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
536 must add any driver with a before dependency on InsertedDriverEntry first.
537 You do this by recursively calling this routine. After all the Befores are
538 processed you can add InsertedDriverEntry to the mScheduledQueue.
539 Then you can add any driver with an After dependency on InsertedDriverEntry
540 by recursively calling this routine.
544 InsertedDriverEntry - The driver to insert on the ScheduledLink Queue
553 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
556 // Process Before Dependency
558 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
559 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
560 if (DriverEntry
->Before
&& DriverEntry
->Dependent
) {
561 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
563 // Recursively process BEFORE
565 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
571 // Convert driver from Dependent to Scheduled state
573 CoreAcquireDispatcherLock ();
575 InsertedDriverEntry
->Dependent
= FALSE
;
576 InsertedDriverEntry
->Scheduled
= TRUE
;
577 InsertTailList (&mScheduledQueue
, &InsertedDriverEntry
->ScheduledLink
);
579 CoreReleaseDispatcherLock ();
582 // Process After Dependency
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 if (DriverEntry
->After
&& DriverEntry
->Dependent
) {
587 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
589 // Recursively process AFTER
591 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
600 IN EFI_HANDLE FvHandle
606 Return TRUE if the Fv has been processed, FALSE if not.
610 FvHandle - The handle of a FV that's being tested
614 TRUE - Fv protocol on FvHandle has been processed
616 FALSE - Fv protocol on FvHandle has not yet been processed
621 KNOWN_HANDLE
*KnownHandle
;
623 for (Link
= mFvHandleList
.ForwardLink
; Link
!= &mFvHandleList
; Link
= Link
->ForwardLink
) {
624 KnownHandle
= CR(Link
, KNOWN_HANDLE
, Link
, KNOWN_HANDLE_SIGNATURE
);
625 if (KnownHandle
->Handle
== FvHandle
) {
634 FvIsBeingProcesssed (
635 IN EFI_HANDLE FvHandle
641 Remember that Fv protocol on FvHandle has had it's drivers placed on the
642 mDiscoveredList. This fucntion adds entries on the mFvHandleList. Items are
643 never removed/freed from the mFvHandleList.
647 FvHandle - The handle of a FV that has been processed
655 KNOWN_HANDLE
*KnownHandle
;
657 KnownHandle
= CoreAllocateBootServicesPool (sizeof (KNOWN_HANDLE
));
658 ASSERT (KnownHandle
!= NULL
);
660 KnownHandle
->Signature
= KNOWN_HANDLE_SIGNATURE
;
661 KnownHandle
->Handle
= FvHandle
;
662 InsertTailList (&mFvHandleList
, &KnownHandle
->Link
);
668 EFI_DEVICE_PATH_PROTOCOL
*
670 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
,
671 IN EFI_HANDLE FvHandle
,
672 IN EFI_GUID
*DriverName
678 Convert FvHandle and DriverName into an EFI device path
682 Fv - Fv protocol, needed to read Depex info out of FLASH.
684 FvHandle - Handle for Fv, needed in the EFI_CORE_DRIVER_ENTRY so that the
685 PE image can be read out of the FV at a later time.
687 DriverName - Name of driver to add to mDiscoveredList.
691 Pointer to device path constructed from FvHandle and DriverName
696 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
697 EFI_DEVICE_PATH_PROTOCOL
*FileNameDevicePath
;
700 // Remember the device path of the FV
702 Status
= CoreHandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
703 if (EFI_ERROR (Status
)) {
704 FileNameDevicePath
= NULL
;
707 // Build a device path to the file in the FV to pass into gBS->LoadImage
709 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, DriverName
);
710 mFvDevicePath
.End
.Type
= EFI_END_ENTIRE_DEVICE_PATH
;
711 mFvDevicePath
.End
.SubType
= END_ENTIRE_DEVICE_PATH_SUBTYPE
;
712 SetDevicePathNodeLength (&mFvDevicePath
.End
, sizeof (EFI_DEVICE_PATH_PROTOCOL
));
714 FileNameDevicePath
= CoreAppendDevicePath (
716 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
720 return FileNameDevicePath
;
726 CoreAddToDriverList (
727 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
,
728 IN EFI_HANDLE FvHandle
,
729 IN EFI_GUID
*DriverName
735 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
736 and initilize any state variables. Read the Depex from the FV and store it
737 in DriverEntry. Pre-process the Depex to set the SOR, Before and After state.
738 The Discovered list is never free'ed and contains booleans that represent the
739 other possible DXE driver states.
743 Fv - Fv protocol, needed to read Depex info out of FLASH.
745 FvHandle - Handle for Fv, needed in the EFI_CORE_DRIVER_ENTRY so that the
746 PE image can be read out of the FV at a later time.
748 DriverName - Name of driver to add to mDiscoveredList.
752 EFI_SUCCESS - If driver was added to the mDiscoveredList.
754 EFI_ALREADY_STARTED - The driver has already been started. Only one DriverName
755 may be active in the system at any one time.
759 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
763 // Create the Driver Entry for the list. ZeroPool initializes lots of variables to
766 DriverEntry
= CoreAllocateZeroBootServicesPool (sizeof (EFI_CORE_DRIVER_ENTRY
));
767 ASSERT (DriverEntry
!= NULL
);
769 DriverEntry
->Signature
= EFI_CORE_DRIVER_ENTRY_SIGNATURE
;
770 CopyMem (&DriverEntry
->FileName
, DriverName
, sizeof (EFI_GUID
));
771 DriverEntry
->FvHandle
= FvHandle
;
772 DriverEntry
->Fv
= Fv
;
773 DriverEntry
->FvFileDevicePath
= CoreFvToDevicePath (Fv
, FvHandle
, DriverName
);
775 CoreGetDepexSectionAndPreProccess (DriverEntry
);
777 CoreAcquireDispatcherLock ();
779 InsertTailList (&mDiscoveredList
, &DriverEntry
->Link
);
781 CoreReleaseDispatcherLock ();
789 CoreProcessFvImageFile (
790 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
,
791 IN EFI_HANDLE FvHandle
,
792 IN EFI_GUID
*DriverName
798 Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.
802 Fv - The FIRMWARE_VOLUME protocol installed on the FV.
803 FvHandle - The handle which FVB protocol installed on.
804 DriverName - The driver guid specified.
808 EFI_OUT_OF_RESOURCES - No enough memory or other resource.
810 EFI_VOLUME_CORRUPTED - Corrupted volume.
812 EFI_SUCCESS - Function successfully returned.
818 EFI_SECTION_TYPE SectionType
;
819 UINT32 AuthenticationStatus
;
824 // Read the first (and only the first) firmware volume section
826 SectionType
= EFI_SECTION_FIRMWARE_VOLUME_IMAGE
;
829 Status
= Fv
->ReadSection (
836 &AuthenticationStatus
838 if (!EFI_ERROR (Status
)) {
840 // Produce a FVB protocol for the file
842 Status
= ProduceFVBProtocolOnBuffer (
843 (EFI_PHYSICAL_ADDRESS
) (UINTN
) Buffer
,
850 if (EFI_ERROR (Status
) && (Buffer
!= NULL
)) {
852 // ReadSection or Produce FVB failed, Free data buffer
854 CoreFreePool (Buffer
);
864 CoreFwVolEventProtocolNotify (
872 Event notification that is fired every time a FV dispatch protocol is added.
873 More than one protocol may have been added when this event is fired, so you
874 must loop on CoreLocateHandle () to see how many protocols were added and
875 do the following to each FV:
877 If the Fv has already been processed, skip it. If the Fv has not been
878 processed then mark it as being processed, as we are about to process it.
880 Read the Fv and add any driver in the Fv to the mDiscoveredList.The
881 mDiscoveredList is never free'ed and contains variables that define
882 the other states the DXE driver transitions to..
884 While you are at it read the A Priori file into memory.
885 Place drivers in the A Priori list onto the mScheduledQueue.
889 Event - The Event that is being processed, not used.
891 Context - Event Context, not used.
900 EFI_STATUS GetNextFileStatus
;
901 EFI_STATUS SecurityStatus
;
902 EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
;
903 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
908 EFI_FV_FILETYPE Type
;
909 EFI_FV_FILE_ATTRIBUTES Attributes
;
911 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
912 EFI_GUID
*AprioriFile
;
913 UINTN AprioriEntryCount
;
916 UINT32 AuthenticationStatus
;
921 BufferSize
= sizeof (EFI_HANDLE
);
922 Status
= CoreLocateHandle (
925 mFwVolEventRegistration
,
929 if (EFI_ERROR (Status
)) {
931 // If no more notification events exit
936 if (FvHasBeenProcessed (FvHandle
)) {
938 // This Fv has already been processed so lets skip it!
943 Status
= CoreHandleProtocol (FvHandle
, &gEfiFirmwareVolumeDispatchProtocolGuid
, (VOID
**)&Fv
);
944 if (EFI_ERROR (Status
)) {
946 // If no dispatch protocol then skip, but do not marked as being processed as it
947 // may show up later.
953 // Since we are about to process this Fv mark it as processed.
955 FvIsBeingProcesssed (FvHandle
);
958 Status
= CoreHandleProtocol (FvHandle
, &gEfiFirmwareVolumeProtocolGuid
, (VOID
**)&Fv
);
959 if (EFI_ERROR (Status
)) {
961 // The Handle has a FirmwareVolumeDispatch protocol and should also contiain
962 // a FirmwareVolume protocol thus we should never get here.
968 Status
= CoreHandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
969 if (EFI_ERROR (Status
)) {
971 // The Firmware volume doesn't have device path, can't be dispatched.
977 // Evaluate the authentication status of the Firmware Volume through
978 // Security Architectural Protocol
980 if (gSecurity
!= NULL
) {
981 SecurityStatus
= gSecurity
->FileAuthenticationState (
986 if (SecurityStatus
!= EFI_SUCCESS
) {
988 // Security check failed. The firmware volume should not be used for any purpose.
995 // Discover Drivers in FV and add them to the Discovered Driver List.
996 // Process EFI_FV_FILETYPE_DRIVER type and then EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
997 // EFI_FV_FILETYPE_DXE_CORE is processed to produce a Loaded Image protocol for the core
998 // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE is processed to create a Fvb
1000 for (Index
= 0; Index
< sizeof (mDxeFileTypes
)/sizeof (EFI_FV_FILETYPE
); Index
++) {
1002 // Initialize the search key
1006 Type
= mDxeFileTypes
[Index
];
1007 GetNextFileStatus
= Fv
->GetNextFile (
1015 if (!EFI_ERROR (GetNextFileStatus
)) {
1016 if (Type
== EFI_FV_FILETYPE_DXE_CORE
) {
1018 // If this is the DXE core fill in it's DevicePath & DeviceHandle
1020 if (gDxeCoreLoadedImage
->FilePath
== NULL
) {
1021 if (CompareGuid (&NameGuid
, gDxeCoreFileName
)) {
1023 // Maybe One specail Fv cantains only one DXE_CORE module, so its device path must
1024 // be initialized completely.
1026 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, &NameGuid
);
1027 mFvDevicePath
.End
.Type
= EFI_END_ENTIRE_DEVICE_PATH
;
1028 mFvDevicePath
.End
.SubType
= END_ENTIRE_DEVICE_PATH_SUBTYPE
;
1029 SetDevicePathNodeLength (&mFvDevicePath
.End
, sizeof (EFI_DEVICE_PATH_PROTOCOL
));
1031 gDxeCoreLoadedImage
->FilePath
= CoreDuplicateDevicePath (
1032 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
1034 gDxeCoreLoadedImage
->DeviceHandle
= FvHandle
;
1037 } else if (Type
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
1039 // Found a firmware volume image. Produce a firmware volume block
1040 // protocol for it so it gets dispatched from. This is usually a
1043 CoreProcessFvImageFile (Fv
, FvHandle
, &NameGuid
);
1046 // Transition driver from Undiscovered to Discovered state
1048 CoreAddToDriverList (Fv
, FvHandle
, &NameGuid
);
1051 } while (!EFI_ERROR (GetNextFileStatus
));
1055 // Read the array of GUIDs from the Apriori file if it is present in the firmware volume
1058 Status
= Fv
->ReadSection (
1063 (VOID
**)&AprioriFile
,
1065 &AuthenticationStatus
1067 if (!EFI_ERROR (Status
)) {
1068 AprioriEntryCount
= SizeOfBuffer
/ sizeof (EFI_GUID
);
1070 AprioriEntryCount
= 0;
1074 // Put drivers on Apriori List on the Scheduled queue. The Discovered List includes
1075 // drivers not in the current FV and these must be skipped since the a priori list
1076 // is only valid for the FV that it resided in.
1078 CoreAcquireDispatcherLock ();
1080 for (Index
= 0; Index
< AprioriEntryCount
; Index
++) {
1081 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
1082 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
1083 if (CompareGuid (&DriverEntry
->FileName
, &AprioriFile
[Index
]) &&
1084 (FvHandle
== DriverEntry
->FvHandle
)) {
1085 DriverEntry
->Dependent
= FALSE
;
1086 DriverEntry
->Scheduled
= TRUE
;
1087 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
1093 CoreReleaseDispatcherLock ();
1096 // Free data allocated by Fv->ReadSection ()
1098 CoreFreePool (AprioriFile
);
1104 CoreInitializeDispatcher (
1109 Routine Description:
1111 Initialize the dispatcher. Initialize the notification function that runs when
1112 a FV protocol is added to the system.
1124 mFwVolEvent
= CoreCreateProtocolNotifyEvent (
1125 &gEfiFirmwareVolumeProtocolGuid
,
1127 CoreFwVolEventProtocolNotify
,
1129 &mFwVolEventRegistration
,
1135 // Function only used in debug buils
1138 CoreDisplayDiscoveredNotDispatched (
1143 Routine Description:
1145 Traverse the discovered list for any drivers that were discovered but not loaded
1146 because the dependency experessions evaluated to false
1159 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
1161 for (Link
= mDiscoveredList
.ForwardLink
;Link
!=&mDiscoveredList
; Link
= Link
->ForwardLink
) {
1162 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
1163 if (DriverEntry
->Dependent
) {
1164 DEBUG ((EFI_D_LOAD
, "Driver %g was discovered but not loaded!!\n", &DriverEntry
->FileName
));