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
);
165 CoreReleaseDispatcherLock (
172 Exit critical section by releasing lock on mDispatcherLock
184 CoreReleaseLock (&mDispatcherLock
);
189 CoreGetDepexSectionAndPreProccess (
190 IN EFI_CORE_DRIVER_ENTRY
*DriverEntry
196 Read Depex and pre-process the Depex for Before and After. If Section Extraction
197 protocol returns an error via ReadSection defer the reading of the Depex.
201 DriverEntry - Driver to work on.
205 EFI_SUCCESS - Depex read and preprossesed
207 EFI_PROTOCOL_ERROR - The section extraction protocol returned an error and
208 Depex reading needs to be retried.
210 Other Error - DEPEX not found.
215 EFI_SECTION_TYPE SectionType
;
216 UINT32 AuthenticationStatus
;
217 EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
;
220 Fv
= DriverEntry
->Fv
;
223 // Grab Depex info, it will never be free'ed.
225 SectionType
= EFI_SECTION_DXE_DEPEX
;
226 Status
= Fv
->ReadSection (
228 &DriverEntry
->FileName
,
232 (UINTN
*)&DriverEntry
->DepexSize
,
233 &AuthenticationStatus
235 if (EFI_ERROR (Status
)) {
236 if (Status
== EFI_PROTOCOL_ERROR
) {
238 // The section extraction protocol failed so set protocol error flag
240 DriverEntry
->DepexProtocolError
= TRUE
;
243 // If no Depex assume EFI 1.1 driver model
245 DriverEntry
->Depex
= NULL
;
246 DriverEntry
->Dependent
= TRUE
;
247 DriverEntry
->DepexProtocolError
= FALSE
;
251 // Set Before, After, and Unrequested state information based on Depex
252 // Driver will be put in Dependent or Unrequested state
254 CorePreProcessDepex (DriverEntry
);
255 DriverEntry
->DepexProtocolError
= FALSE
;
265 IN EFI_HANDLE FirmwareVolumeHandle
,
266 IN EFI_GUID
*DriverName
272 Check every driver and locate a matching one. If the driver is found, the Unrequested
273 state flag is cleared.
277 FirmwareVolumeHandle - The handle of the Firmware Volume that contains the firmware
278 file specified by DriverName.
280 DriverName - The Driver name to put in the Dependent state.
284 EFI_SUCCESS - The DriverName was found and it's SOR bit was cleared
286 EFI_NOT_FOUND - The DriverName does not exist or it's SOR bit was not set.
291 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
294 // Check every driver
296 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
297 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
298 if (DriverEntry
->FvHandle
== FirmwareVolumeHandle
&&
299 DriverEntry
->Unrequested
&&
300 CompareGuid (DriverName
, &DriverEntry
->FileName
)) {
302 // Move the driver from the Unrequested to the Dependent state
304 CoreAcquireDispatcherLock ();
305 DriverEntry
->Unrequested
= FALSE
;
306 DriverEntry
->Dependent
= TRUE
;
307 CoreReleaseDispatcherLock ();
312 return EFI_NOT_FOUND
;
320 IN EFI_HANDLE FirmwareVolumeHandle
,
321 IN EFI_GUID
*DriverName
327 Convert a driver from the Untrused back to the Scheduled state
331 FirmwareVolumeHandle - The handle of the Firmware Volume that contains the firmware
332 file specified by DriverName.
334 DriverName - The Driver name to put in the Scheduled state
338 EFI_SUCCESS - The file was found in the untrusted state, and it was promoted
339 to the trusted state.
341 EFI_NOT_FOUND - The file was not found in the untrusted state.
346 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
349 // Check every driver
351 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
352 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
353 if (DriverEntry
->FvHandle
== FirmwareVolumeHandle
&&
354 DriverEntry
->Untrusted
&&
355 CompareGuid (DriverName
, &DriverEntry
->FileName
)) {
357 // Transition driver from Untrusted to Scheduled state.
359 CoreAcquireDispatcherLock ();
360 DriverEntry
->Untrusted
= FALSE
;
361 DriverEntry
->Scheduled
= TRUE
;
362 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
363 CoreReleaseDispatcherLock ();
368 return EFI_NOT_FOUND
;
382 This is the main Dispatcher for DXE and it exits when there are no more
383 drivers to run. Drain the mScheduledQueue and load and start a PE
384 image for each driver. Search the mDiscoveredList to see if any driver can
385 be placed on the mScheduledQueue. If no drivers are placed on the
386 mScheduledQueue exit the function. On exit it is assumed the Bds()
387 will be called, and when the Bds() exits the Dispatcher will be called
396 EFI_ALREADY_STARTED - The DXE Dispatcher is already running
398 EFI_NOT_FOUND - No DXE Drivers were dispatched
400 EFI_SUCCESS - One or more DXE Drivers were dispatched
405 EFI_STATUS ReturnStatus
;
407 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
410 if (gDispatcherRunning
) {
412 // If the dispatcher is running don't let it be restarted.
414 return EFI_ALREADY_STARTED
;
417 gDispatcherRunning
= TRUE
;
420 ReturnStatus
= EFI_NOT_FOUND
;
423 // Drain the Scheduled Queue
425 while (!IsListEmpty (&mScheduledQueue
)) {
427 mScheduledQueue
.ForwardLink
,
428 EFI_CORE_DRIVER_ENTRY
,
430 EFI_CORE_DRIVER_ENTRY_SIGNATURE
434 // Load the DXE Driver image into memory. If the Driver was transitioned from
435 // Untrused to Scheduled it would have already been loaded so we may need to
436 // skip the LoadImage
438 if (DriverEntry
->ImageHandle
== NULL
) {
439 Status
= CoreLoadImage (
442 DriverEntry
->FvFileDevicePath
,
445 &DriverEntry
->ImageHandle
449 // Update the driver state to reflect that it's been loaded
451 if (EFI_ERROR (Status
)) {
452 CoreAcquireDispatcherLock ();
454 if (Status
== EFI_SECURITY_VIOLATION
) {
456 // Take driver from Scheduled to Untrused state
458 DriverEntry
->Untrusted
= TRUE
;
461 // The DXE Driver could not be loaded, and do not attempt to load or start it again.
462 // Take driver from Scheduled to Initialized.
464 // This case include the Never Trusted state if EFI_ACCESS_DENIED is returned
466 DriverEntry
->Initialized
= TRUE
;
469 DriverEntry
->Scheduled
= FALSE
;
470 RemoveEntryList (&DriverEntry
->ScheduledLink
);
472 CoreReleaseDispatcherLock ();
475 // If it's an error don't try the StartImage
481 CoreAcquireDispatcherLock ();
483 DriverEntry
->Scheduled
= FALSE
;
484 DriverEntry
->Initialized
= TRUE
;
485 RemoveEntryList (&DriverEntry
->ScheduledLink
);
487 CoreReleaseDispatcherLock ();
490 CoreReportProgressCodeSpecific (EFI_SOFTWARE_DXE_CORE
| EFI_SW_PC_INIT_BEGIN
, DriverEntry
->ImageHandle
);
491 Status
= CoreStartImage (DriverEntry
->ImageHandle
, NULL
, NULL
);
492 CoreReportProgressCodeSpecific (EFI_SOFTWARE_DXE_CORE
| EFI_SW_PC_INIT_END
, DriverEntry
->ImageHandle
);
494 ReturnStatus
= EFI_SUCCESS
;
498 // Search DriverList for items to place on Scheduled Queue
501 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
502 DriverEntry
= CR (Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
504 if (DriverEntry
->DepexProtocolError
){
506 // If Section Extraction Protocol did not let the Depex be read before retry the read
508 Status
= CoreGetDepexSectionAndPreProccess (DriverEntry
);
511 if (DriverEntry
->Dependent
) {
512 if (CoreIsSchedulable (DriverEntry
)) {
513 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
518 } while (ReadyToRun
);
520 gDispatcherRunning
= FALSE
;
527 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
528 IN EFI_CORE_DRIVER_ENTRY
*InsertedDriverEntry
534 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
535 must add any driver with a before dependency on InsertedDriverEntry first.
536 You do this by recursively calling this routine. After all the Befores are
537 processed you can add InsertedDriverEntry to the mScheduledQueue.
538 Then you can add any driver with an After dependency on InsertedDriverEntry
539 by recursively calling this routine.
543 InsertedDriverEntry - The driver to insert on the ScheduledLink Queue
552 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
555 // Process Before Dependency
557 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
558 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
559 if (DriverEntry
->Before
&& DriverEntry
->Dependent
) {
560 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
562 // Recursively process BEFORE
564 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
570 // Convert driver from Dependent to Scheduled state
572 CoreAcquireDispatcherLock ();
574 InsertedDriverEntry
->Dependent
= FALSE
;
575 InsertedDriverEntry
->Scheduled
= TRUE
;
576 InsertTailList (&mScheduledQueue
, &InsertedDriverEntry
->ScheduledLink
);
578 CoreReleaseDispatcherLock ();
581 // Process After Dependency
583 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
584 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
585 if (DriverEntry
->After
&& DriverEntry
->Dependent
) {
586 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
588 // Recursively process AFTER
590 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
599 IN EFI_HANDLE FvHandle
605 Return TRUE if the Fv has been processed, FALSE if not.
609 FvHandle - The handle of a FV that's being tested
613 TRUE - Fv protocol on FvHandle has been processed
615 FALSE - Fv protocol on FvHandle has not yet been processed
620 KNOWN_HANDLE
*KnownHandle
;
622 for (Link
= mFvHandleList
.ForwardLink
; Link
!= &mFvHandleList
; Link
= Link
->ForwardLink
) {
623 KnownHandle
= CR(Link
, KNOWN_HANDLE
, Link
, KNOWN_HANDLE_SIGNATURE
);
624 if (KnownHandle
->Handle
== FvHandle
) {
633 FvIsBeingProcesssed (
634 IN EFI_HANDLE FvHandle
640 Remember that Fv protocol on FvHandle has had it's drivers placed on the
641 mDiscoveredList. This fucntion adds entries on the mFvHandleList. Items are
642 never removed/freed from the mFvHandleList.
646 FvHandle - The handle of a FV that has been processed
654 KNOWN_HANDLE
*KnownHandle
;
656 KnownHandle
= CoreAllocateBootServicesPool (sizeof (KNOWN_HANDLE
));
657 ASSERT (KnownHandle
!= NULL
);
659 KnownHandle
->Signature
= KNOWN_HANDLE_SIGNATURE
;
660 KnownHandle
->Handle
= FvHandle
;
661 InsertTailList (&mFvHandleList
, &KnownHandle
->Link
);
667 EFI_DEVICE_PATH_PROTOCOL
*
669 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
,
670 IN EFI_HANDLE FvHandle
,
671 IN EFI_GUID
*DriverName
677 Convert FvHandle and DriverName into an EFI device path
681 Fv - Fv protocol, needed to read Depex info out of FLASH.
683 FvHandle - Handle for Fv, needed in the EFI_CORE_DRIVER_ENTRY so that the
684 PE image can be read out of the FV at a later time.
686 DriverName - Name of driver to add to mDiscoveredList.
690 Pointer to device path constructed from FvHandle and DriverName
695 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
696 EFI_DEVICE_PATH_PROTOCOL
*FileNameDevicePath
;
699 // Remember the device path of the FV
701 Status
= CoreHandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
702 if (EFI_ERROR (Status
)) {
703 FileNameDevicePath
= NULL
;
706 // Build a device path to the file in the FV to pass into gBS->LoadImage
708 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, DriverName
);
709 mFvDevicePath
.End
.Type
= EFI_END_ENTIRE_DEVICE_PATH
;
710 mFvDevicePath
.End
.SubType
= END_ENTIRE_DEVICE_PATH_SUBTYPE
;
711 SetDevicePathNodeLength (&mFvDevicePath
.End
, sizeof (EFI_DEVICE_PATH_PROTOCOL
));
713 FileNameDevicePath
= CoreAppendDevicePath (
715 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
719 return FileNameDevicePath
;
725 CoreAddToDriverList (
726 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
,
727 IN EFI_HANDLE FvHandle
,
728 IN EFI_GUID
*DriverName
734 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
735 and initilize any state variables. Read the Depex from the FV and store it
736 in DriverEntry. Pre-process the Depex to set the SOR, Before and After state.
737 The Discovered list is never free'ed and contains booleans that represent the
738 other possible DXE driver states.
742 Fv - Fv protocol, needed to read Depex info out of FLASH.
744 FvHandle - Handle for Fv, needed in the EFI_CORE_DRIVER_ENTRY so that the
745 PE image can be read out of the FV at a later time.
747 DriverName - Name of driver to add to mDiscoveredList.
751 EFI_SUCCESS - If driver was added to the mDiscoveredList.
753 EFI_ALREADY_STARTED - The driver has already been started. Only one DriverName
754 may be active in the system at any one time.
758 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
762 // Create the Driver Entry for the list. ZeroPool initializes lots of variables to
765 DriverEntry
= CoreAllocateZeroBootServicesPool (sizeof (EFI_CORE_DRIVER_ENTRY
));
766 ASSERT (DriverEntry
!= NULL
);
768 DriverEntry
->Signature
= EFI_CORE_DRIVER_ENTRY_SIGNATURE
;
769 CopyMem (&DriverEntry
->FileName
, DriverName
, sizeof (EFI_GUID
));
770 DriverEntry
->FvHandle
= FvHandle
;
771 DriverEntry
->Fv
= Fv
;
772 DriverEntry
->FvFileDevicePath
= CoreFvToDevicePath (Fv
, FvHandle
, DriverName
);
774 CoreGetDepexSectionAndPreProccess (DriverEntry
);
776 CoreAcquireDispatcherLock ();
778 InsertTailList (&mDiscoveredList
, &DriverEntry
->Link
);
780 CoreReleaseDispatcherLock ();
788 CoreProcessFvImageFile (
789 IN EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
,
790 IN EFI_HANDLE FvHandle
,
791 IN EFI_GUID
*DriverName
797 Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.
801 Fv - The FIRMWARE_VOLUME protocol installed on the FV.
802 FvHandle - The handle which FVB protocol installed on.
803 DriverName - The driver guid specified.
807 EFI_OUT_OF_RESOURCES - No enough memory or other resource.
809 EFI_VOLUME_CORRUPTED - Corrupted volume.
811 EFI_SUCCESS - Function successfully returned.
817 EFI_SECTION_TYPE SectionType
;
818 UINT32 AuthenticationStatus
;
823 // Read the first (and only the first) firmware volume section
825 SectionType
= EFI_SECTION_FIRMWARE_VOLUME_IMAGE
;
828 Status
= Fv
->ReadSection (
835 &AuthenticationStatus
837 if (!EFI_ERROR (Status
)) {
839 // Produce a FVB protocol for the file
841 Status
= ProduceFVBProtocolOnBuffer (
842 (EFI_PHYSICAL_ADDRESS
) (UINTN
) Buffer
,
849 if (EFI_ERROR (Status
) && (Buffer
!= NULL
)) {
851 // ReadSection or Produce FVB failed, Free data buffer
853 CoreFreePool (Buffer
);
863 CoreFwVolEventProtocolNotify (
871 Event notification that is fired every time a FV dispatch protocol is added.
872 More than one protocol may have been added when this event is fired, so you
873 must loop on CoreLocateHandle () to see how many protocols were added and
874 do the following to each FV:
876 If the Fv has already been processed, skip it. If the Fv has not been
877 processed then mark it as being processed, as we are about to process it.
879 Read the Fv and add any driver in the Fv to the mDiscoveredList.The
880 mDiscoveredList is never free'ed and contains variables that define
881 the other states the DXE driver transitions to..
883 While you are at it read the A Priori file into memory.
884 Place drivers in the A Priori list onto the mScheduledQueue.
888 Event - The Event that is being processed, not used.
890 Context - Event Context, not used.
899 EFI_STATUS GetNextFileStatus
;
900 EFI_STATUS SecurityStatus
;
901 EFI_FIRMWARE_VOLUME_PROTOCOL
*Fv
;
902 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
907 EFI_FV_FILETYPE Type
;
908 EFI_FV_FILE_ATTRIBUTES Attributes
;
910 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
911 EFI_GUID
*AprioriFile
;
912 UINTN AprioriEntryCount
;
915 UINT32 AuthenticationStatus
;
920 BufferSize
= sizeof (EFI_HANDLE
);
921 Status
= CoreLocateHandle (
924 mFwVolEventRegistration
,
928 if (EFI_ERROR (Status
)) {
930 // If no more notification events exit
935 if (FvHasBeenProcessed (FvHandle
)) {
937 // This Fv has already been processed so lets skip it!
942 Status
= CoreHandleProtocol (FvHandle
, &gEfiFirmwareVolumeDispatchProtocolGuid
, (VOID
**)&Fv
);
943 if (EFI_ERROR (Status
)) {
945 // If no dispatch protocol then skip, but do not marked as being processed as it
946 // may show up later.
952 // Since we are about to process this Fv mark it as processed.
954 FvIsBeingProcesssed (FvHandle
);
957 Status
= CoreHandleProtocol (FvHandle
, &gEfiFirmwareVolumeProtocolGuid
, (VOID
**)&Fv
);
958 if (EFI_ERROR (Status
)) {
960 // The Handle has a FirmwareVolumeDispatch protocol and should also contiain
961 // a FirmwareVolume protocol thus we should never get here.
967 Status
= CoreHandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
968 if (EFI_ERROR (Status
)) {
970 // The Firmware volume doesn't have device path, can't be dispatched.
976 // Evaluate the authentication status of the Firmware Volume through
977 // Security Architectural Protocol
979 if (gSecurity
!= NULL
) {
980 SecurityStatus
= gSecurity
->FileAuthenticationState (
985 if (SecurityStatus
!= EFI_SUCCESS
) {
987 // Security check failed. The firmware volume should not be used for any purpose.
994 // Discover Drivers in FV and add them to the Discovered Driver List.
995 // Process EFI_FV_FILETYPE_DRIVER type and then EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
996 // EFI_FV_FILETYPE_DXE_CORE is processed to produce a Loaded Image protocol for the core
997 // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE is processed to create a Fvb
999 for (Index
= 0; Index
< sizeof (mDxeFileTypes
)/sizeof (EFI_FV_FILETYPE
); Index
++) {
1001 // Initialize the search key
1005 Type
= mDxeFileTypes
[Index
];
1006 GetNextFileStatus
= Fv
->GetNextFile (
1014 if (!EFI_ERROR (GetNextFileStatus
)) {
1015 if (Type
== EFI_FV_FILETYPE_DXE_CORE
) {
1017 // If this is the DXE core fill in it's DevicePath & DeviceHandle
1019 if (gDxeCoreLoadedImage
->FilePath
== NULL
) {
1020 if (CompareGuid (&NameGuid
, gDxeCoreFileName
)) {
1021 CopyGuid (&mFvDevicePath
.File
.NameGuid
, &NameGuid
);
1023 gDxeCoreLoadedImage
->FilePath
= CoreDuplicateDevicePath (
1024 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
1026 gDxeCoreLoadedImage
->DeviceHandle
= FvHandle
;
1029 } else if (Type
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
1031 // Found a firmware volume image. Produce a firmware volume block
1032 // protocol for it so it gets dispatched from. This is usually a
1035 CoreProcessFvImageFile (Fv
, FvHandle
, &NameGuid
);
1038 // Transition driver from Undiscovered to Discovered state
1040 CoreAddToDriverList (Fv
, FvHandle
, &NameGuid
);
1043 } while (!EFI_ERROR (GetNextFileStatus
));
1047 // Read the array of GUIDs from the Apriori file if it is present in the firmware volume
1050 Status
= Fv
->ReadSection (
1055 (VOID
**)&AprioriFile
,
1057 &AuthenticationStatus
1059 if (!EFI_ERROR (Status
)) {
1060 AprioriEntryCount
= SizeOfBuffer
/ sizeof (EFI_GUID
);
1062 AprioriEntryCount
= 0;
1066 // Put drivers on Apriori List on the Scheduled queue. The Discovered List includes
1067 // drivers not in the current FV and these must be skipped since the a priori list
1068 // is only valid for the FV that it resided in.
1070 CoreAcquireDispatcherLock ();
1072 for (Index
= 0; Index
< AprioriEntryCount
; Index
++) {
1073 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
1074 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
1075 if (CompareGuid (&DriverEntry
->FileName
, &AprioriFile
[Index
]) &&
1076 (FvHandle
== DriverEntry
->FvHandle
)) {
1077 DriverEntry
->Dependent
= FALSE
;
1078 DriverEntry
->Scheduled
= TRUE
;
1079 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
1085 CoreReleaseDispatcherLock ();
1088 // Free data allocated by Fv->ReadSection ()
1090 CoreFreePool (AprioriFile
);
1096 CoreInitializeDispatcher (
1101 Routine Description:
1103 Initialize the dispatcher. Initialize the notification function that runs when
1104 a FV protocol is added to the system.
1116 mFwVolEvent
= CoreCreateProtocolNotifyEvent (
1117 &gEfiFirmwareVolumeProtocolGuid
,
1119 CoreFwVolEventProtocolNotify
,
1121 &mFwVolEventRegistration
,
1127 // Function only used in debug buils
1130 CoreDisplayDiscoveredNotDispatched (
1135 Routine Description:
1137 Traverse the discovered list for any drivers that were discovered but not loaded
1138 because the dependency experessions evaluated to false
1151 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
1153 for (Link
= mDiscoveredList
.ForwardLink
;Link
!=&mDiscoveredList
; Link
= Link
->ForwardLink
) {
1154 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
1155 if (DriverEntry
->Dependent
) {
1156 DEBUG ((EFI_D_LOAD
, "Driver %g was discovered but not loaded!!\n", &DriverEntry
->FileName
));