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 (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
106 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
107 IN EFI_CORE_DRIVER_ENTRY
*InsertedDriverEntry
113 CoreFwVolEventProtocolNotify (
119 EFI_DEVICE_PATH_PROTOCOL
*
121 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
122 IN EFI_HANDLE FvHandle
,
123 IN EFI_GUID
*DriverName
128 CoreAddToDriverList (
129 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
130 IN EFI_HANDLE FvHandle
,
131 IN EFI_GUID
*DriverName
136 CoreProcessFvImageFile (
137 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
138 IN EFI_HANDLE FvHandle
,
139 IN EFI_GUID
*DriverName
144 CoreAcquireDispatcherLock (
151 Enter critical section by gaining lock on mDispatcherLock
164 CoreAcquireLock (&mDispatcherLock
);
169 CoreReleaseDispatcherLock (
176 Exit critical section by releasing lock on mDispatcherLock
188 CoreReleaseLock (&mDispatcherLock
);
193 CoreGetDepexSectionAndPreProccess (
194 IN EFI_CORE_DRIVER_ENTRY
*DriverEntry
200 Read Depex and pre-process the Depex for Before and After. If Section Extraction
201 protocol returns an error via ReadSection defer the reading of the Depex.
205 DriverEntry - Driver to work on.
209 EFI_SUCCESS - Depex read and preprossesed
211 EFI_PROTOCOL_ERROR - The section extraction protocol returned an error and
212 Depex reading needs to be retried.
214 Other Error - DEPEX not found.
219 EFI_SECTION_TYPE SectionType
;
220 UINT32 AuthenticationStatus
;
221 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
224 Fv
= DriverEntry
->Fv
;
227 // Grab Depex info, it will never be free'ed.
229 SectionType
= EFI_SECTION_DXE_DEPEX
;
230 Status
= Fv
->ReadSection (
232 &DriverEntry
->FileName
,
236 (UINTN
*)&DriverEntry
->DepexSize
,
237 &AuthenticationStatus
239 if (EFI_ERROR (Status
)) {
240 if (Status
== EFI_PROTOCOL_ERROR
) {
242 // The section extraction protocol failed so set protocol error flag
244 DriverEntry
->DepexProtocolError
= TRUE
;
247 // If no Depex assume UEFI 2.0 driver model
249 DriverEntry
->Depex
= NULL
;
250 DriverEntry
->Dependent
= TRUE
;
251 DriverEntry
->DepexProtocolError
= FALSE
;
255 // Set Before, After, and Unrequested state information based on Depex
256 // Driver will be put in Dependent or Unrequested state
258 CorePreProcessDepex (DriverEntry
);
259 DriverEntry
->DepexProtocolError
= FALSE
;
269 IN EFI_HANDLE FirmwareVolumeHandle
,
270 IN EFI_GUID
*DriverName
276 Check every driver and locate a matching one. If the driver is found, the Unrequested
277 state flag is cleared.
281 FirmwareVolumeHandle - The handle of the Firmware Volume that contains the firmware
282 file specified by DriverName.
284 DriverName - The Driver name to put in the Dependent state.
288 EFI_SUCCESS - The DriverName was found and it's SOR bit was cleared
290 EFI_NOT_FOUND - The DriverName does not exist or it's SOR bit was not set.
295 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
298 // Check every driver
300 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
301 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
302 if (DriverEntry
->FvHandle
== FirmwareVolumeHandle
&&
303 DriverEntry
->Unrequested
&&
304 CompareGuid (DriverName
, &DriverEntry
->FileName
)) {
306 // Move the driver from the Unrequested to the Dependent state
308 CoreAcquireDispatcherLock ();
309 DriverEntry
->Unrequested
= FALSE
;
310 DriverEntry
->Dependent
= TRUE
;
311 CoreReleaseDispatcherLock ();
316 return EFI_NOT_FOUND
;
324 IN EFI_HANDLE FirmwareVolumeHandle
,
325 IN EFI_GUID
*DriverName
331 Convert a driver from the Untrused back to the Scheduled state
335 FirmwareVolumeHandle - The handle of the Firmware Volume that contains the firmware
336 file specified by DriverName.
338 DriverName - The Driver name to put in the Scheduled state
342 EFI_SUCCESS - The file was found in the untrusted state, and it was promoted
343 to the trusted state.
345 EFI_NOT_FOUND - The file was not found in the untrusted state.
350 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
353 // Check every driver
355 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
356 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
357 if (DriverEntry
->FvHandle
== FirmwareVolumeHandle
&&
358 DriverEntry
->Untrusted
&&
359 CompareGuid (DriverName
, &DriverEntry
->FileName
)) {
361 // Transition driver from Untrusted to Scheduled state.
363 CoreAcquireDispatcherLock ();
364 DriverEntry
->Untrusted
= FALSE
;
365 DriverEntry
->Scheduled
= TRUE
;
366 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
367 CoreReleaseDispatcherLock ();
372 return EFI_NOT_FOUND
;
386 This is the main Dispatcher for DXE and it exits when there are no more
387 drivers to run. Drain the mScheduledQueue and load and start a PE
388 image for each driver. Search the mDiscoveredList to see if any driver can
389 be placed on the mScheduledQueue. If no drivers are placed on the
390 mScheduledQueue exit the function. On exit it is assumed the Bds()
391 will be called, and when the Bds() exits the Dispatcher will be called
400 EFI_ALREADY_STARTED - The DXE Dispatcher is already running
402 EFI_NOT_FOUND - No DXE Drivers were dispatched
404 EFI_SUCCESS - One or more DXE Drivers were dispatched
409 EFI_STATUS ReturnStatus
;
411 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
414 if (gDispatcherRunning
) {
416 // If the dispatcher is running don't let it be restarted.
418 return EFI_ALREADY_STARTED
;
421 gDispatcherRunning
= TRUE
;
424 ReturnStatus
= EFI_NOT_FOUND
;
427 // Drain the Scheduled Queue
429 while (!IsListEmpty (&mScheduledQueue
)) {
431 mScheduledQueue
.ForwardLink
,
432 EFI_CORE_DRIVER_ENTRY
,
434 EFI_CORE_DRIVER_ENTRY_SIGNATURE
438 // Load the DXE Driver image into memory. If the Driver was transitioned from
439 // Untrused to Scheduled it would have already been loaded so we may need to
440 // skip the LoadImage
442 if (DriverEntry
->ImageHandle
== NULL
) {
443 Status
= CoreLoadImage (
446 DriverEntry
->FvFileDevicePath
,
449 &DriverEntry
->ImageHandle
453 // Update the driver state to reflect that it's been loaded
455 if (EFI_ERROR (Status
)) {
456 CoreAcquireDispatcherLock ();
458 if (Status
== EFI_SECURITY_VIOLATION
) {
460 // Take driver from Scheduled to Untrused state
462 DriverEntry
->Untrusted
= TRUE
;
465 // The DXE Driver could not be loaded, and do not attempt to load or start it again.
466 // Take driver from Scheduled to Initialized.
468 // This case include the Never Trusted state if EFI_ACCESS_DENIED is returned
470 DriverEntry
->Initialized
= TRUE
;
473 DriverEntry
->Scheduled
= FALSE
;
474 RemoveEntryList (&DriverEntry
->ScheduledLink
);
476 CoreReleaseDispatcherLock ();
479 // If it's an error don't try the StartImage
485 CoreAcquireDispatcherLock ();
487 DriverEntry
->Scheduled
= FALSE
;
488 DriverEntry
->Initialized
= TRUE
;
489 RemoveEntryList (&DriverEntry
->ScheduledLink
);
491 CoreReleaseDispatcherLock ();
493 CoreReportProgressCodeSpecific (EFI_SOFTWARE_DXE_CORE
| EFI_SW_PC_INIT_BEGIN
, DriverEntry
->ImageHandle
);
494 Status
= CoreStartImage (DriverEntry
->ImageHandle
, NULL
, NULL
);
495 CoreReportProgressCodeSpecific (EFI_SOFTWARE_DXE_CORE
| EFI_SW_PC_INIT_END
, DriverEntry
->ImageHandle
);
497 ReturnStatus
= EFI_SUCCESS
;
501 // Search DriverList for items to place on Scheduled Queue
504 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
505 DriverEntry
= CR (Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
507 if (DriverEntry
->DepexProtocolError
){
509 // If Section Extraction Protocol did not let the Depex be read before retry the read
511 Status
= CoreGetDepexSectionAndPreProccess (DriverEntry
);
514 if (DriverEntry
->Dependent
) {
515 if (CoreIsSchedulable (DriverEntry
)) {
516 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
521 } while (ReadyToRun
);
523 gDispatcherRunning
= FALSE
;
530 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
531 IN EFI_CORE_DRIVER_ENTRY
*InsertedDriverEntry
537 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
538 must add any driver with a before dependency on InsertedDriverEntry first.
539 You do this by recursively calling this routine. After all the Befores are
540 processed you can add InsertedDriverEntry to the mScheduledQueue.
541 Then you can add any driver with an After dependency on InsertedDriverEntry
542 by recursively calling this routine.
546 InsertedDriverEntry - The driver to insert on the ScheduledLink Queue
555 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
558 // Process Before Dependency
560 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
561 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
562 if (DriverEntry
->Before
&& DriverEntry
->Dependent
) {
563 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
565 // Recursively process BEFORE
567 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
573 // Convert driver from Dependent to Scheduled state
575 CoreAcquireDispatcherLock ();
577 InsertedDriverEntry
->Dependent
= FALSE
;
578 InsertedDriverEntry
->Scheduled
= TRUE
;
579 InsertTailList (&mScheduledQueue
, &InsertedDriverEntry
->ScheduledLink
);
581 CoreReleaseDispatcherLock ();
584 // Process After Dependency
586 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
587 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
588 if (DriverEntry
->After
&& DriverEntry
->Dependent
) {
589 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
591 // Recursively process AFTER
593 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
602 IN EFI_HANDLE FvHandle
608 Return TRUE if the Fv has been processed, FALSE if not.
612 FvHandle - The handle of a FV that's being tested
616 TRUE - Fv protocol on FvHandle has been processed
618 FALSE - Fv protocol on FvHandle has not yet been processed
623 KNOWN_HANDLE
*KnownHandle
;
625 for (Link
= mFvHandleList
.ForwardLink
; Link
!= &mFvHandleList
; Link
= Link
->ForwardLink
) {
626 KnownHandle
= CR(Link
, KNOWN_HANDLE
, Link
, KNOWN_HANDLE_SIGNATURE
);
627 if (KnownHandle
->Handle
== FvHandle
) {
636 FvIsBeingProcesssed (
637 IN EFI_HANDLE FvHandle
643 Remember that Fv protocol on FvHandle has had it's drivers placed on the
644 mDiscoveredList. This fucntion adds entries on the mFvHandleList. Items are
645 never removed/freed from the mFvHandleList.
649 FvHandle - The handle of a FV that has been processed
657 KNOWN_HANDLE
*KnownHandle
;
659 KnownHandle
= CoreAllocateBootServicesPool (sizeof (KNOWN_HANDLE
));
660 ASSERT (KnownHandle
!= NULL
);
662 KnownHandle
->Signature
= KNOWN_HANDLE_SIGNATURE
;
663 KnownHandle
->Handle
= FvHandle
;
664 InsertTailList (&mFvHandleList
, &KnownHandle
->Link
);
670 EFI_DEVICE_PATH_PROTOCOL
*
672 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
673 IN EFI_HANDLE FvHandle
,
674 IN EFI_GUID
*DriverName
680 Convert FvHandle and DriverName into an EFI device path
684 Fv - Fv protocol, needed to read Depex info out of FLASH.
686 FvHandle - Handle for Fv, needed in the EFI_CORE_DRIVER_ENTRY so that the
687 PE image can be read out of the FV at a later time.
689 DriverName - Name of driver to add to mDiscoveredList.
693 Pointer to device path constructed from FvHandle and DriverName
698 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
699 EFI_DEVICE_PATH_PROTOCOL
*FileNameDevicePath
;
702 // Remember the device path of the FV
704 Status
= CoreHandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
705 if (EFI_ERROR (Status
)) {
706 FileNameDevicePath
= NULL
;
709 // Build a device path to the file in the FV to pass into gBS->LoadImage
711 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, DriverName
);
712 mFvDevicePath
.End
.Type
= EFI_END_ENTIRE_DEVICE_PATH
;
713 mFvDevicePath
.End
.SubType
= END_ENTIRE_DEVICE_PATH_SUBTYPE
;
714 SetDevicePathNodeLength (&mFvDevicePath
.End
, sizeof (EFI_DEVICE_PATH_PROTOCOL
));
716 FileNameDevicePath
= CoreAppendDevicePath (
718 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
722 return FileNameDevicePath
;
728 CoreAddToDriverList (
729 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
730 IN EFI_HANDLE FvHandle
,
731 IN EFI_GUID
*DriverName
737 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
738 and initilize any state variables. Read the Depex from the FV and store it
739 in DriverEntry. Pre-process the Depex to set the SOR, Before and After state.
740 The Discovered list is never free'ed and contains booleans that represent the
741 other possible DXE driver states.
745 Fv - Fv protocol, needed to read Depex info out of FLASH.
747 FvHandle - Handle for Fv, needed in the EFI_CORE_DRIVER_ENTRY so that the
748 PE image can be read out of the FV at a later time.
750 DriverName - Name of driver to add to mDiscoveredList.
754 EFI_SUCCESS - If driver was added to the mDiscoveredList.
756 EFI_ALREADY_STARTED - The driver has already been started. Only one DriverName
757 may be active in the system at any one time.
761 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
765 // Create the Driver Entry for the list. ZeroPool initializes lots of variables to
768 DriverEntry
= CoreAllocateZeroBootServicesPool (sizeof (EFI_CORE_DRIVER_ENTRY
));
769 ASSERT (DriverEntry
!= NULL
);
771 DriverEntry
->Signature
= EFI_CORE_DRIVER_ENTRY_SIGNATURE
;
772 CopyMem (&DriverEntry
->FileName
, DriverName
, sizeof (EFI_GUID
));
773 DriverEntry
->FvHandle
= FvHandle
;
774 DriverEntry
->Fv
= Fv
;
775 DriverEntry
->FvFileDevicePath
= CoreFvToDevicePath (Fv
, FvHandle
, DriverName
);
777 CoreGetDepexSectionAndPreProccess (DriverEntry
);
779 CoreAcquireDispatcherLock ();
781 InsertTailList (&mDiscoveredList
, &DriverEntry
->Link
);
783 CoreReleaseDispatcherLock ();
791 IN EFI_HANDLE FvHandle
,
792 IN CONST EFI_GUID
*DriverName
798 Check if a FV Image type file (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) is
799 described by a EFI_HOB_FIRMWARE_VOLUME2 Hob.
803 FvHandle - The handle which FVB protocol installed on.
804 DriverName - The driver guid specified.
808 TRUE - This file is found in a EFI_HOB_FIRMWARE_VOLUME2 Hob.
815 EFI_PEI_HOB_POINTERS HobFv2
;
817 HobFv2
.Raw
= GetHobList ();
819 while ((HobFv2
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobFv2
.Raw
)) != NULL
) {
820 if (CompareGuid (DriverName
, &HobFv2
.FirmwareVolume2
->FileName
)) {
823 HobFv2
.Raw
= GET_NEXT_HOB (HobFv2
);
831 CoreProcessFvImageFile (
832 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
833 IN EFI_HANDLE FvHandle
,
834 IN EFI_GUID
*DriverName
840 Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.
844 Fv - The FIRMWARE_VOLUME protocol installed on the FV.
845 FvHandle - The handle which FVB protocol installed on.
846 DriverName - The driver guid specified.
850 EFI_OUT_OF_RESOURCES - No enough memory or other resource.
852 EFI_VOLUME_CORRUPTED - Corrupted volume.
854 EFI_SUCCESS - Function successfully returned.
860 EFI_SECTION_TYPE SectionType
;
861 UINT32 AuthenticationStatus
;
866 // Read the first (and only the first) firmware volume section
868 SectionType
= EFI_SECTION_FIRMWARE_VOLUME_IMAGE
;
871 Status
= Fv
->ReadSection (
878 &AuthenticationStatus
880 if (!EFI_ERROR (Status
)) {
882 // Produce a FVB protocol for the file
884 Status
= ProduceFVBProtocolOnBuffer (
885 (EFI_PHYSICAL_ADDRESS
) (UINTN
) Buffer
,
892 if (EFI_ERROR (Status
) && (Buffer
!= NULL
)) {
894 // ReadSection or Produce FVB failed, Free data buffer
896 CoreFreePool (Buffer
);
906 CoreFwVolEventProtocolNotify (
914 Event notification that is fired every time a FV dispatch protocol is added.
915 More than one protocol may have been added when this event is fired, so you
916 must loop on CoreLocateHandle () to see how many protocols were added and
917 do the following to each FV:
919 If the Fv has already been processed, skip it. If the Fv has not been
920 processed then mark it as being processed, as we are about to process it.
922 Read the Fv and add any driver in the Fv to the mDiscoveredList.The
923 mDiscoveredList is never free'ed and contains variables that define
924 the other states the DXE driver transitions to..
926 While you are at it read the A Priori file into memory.
927 Place drivers in the A Priori list onto the mScheduledQueue.
931 Event - The Event that is being processed, not used.
933 Context - Event Context, not used.
942 EFI_STATUS GetNextFileStatus
;
943 EFI_STATUS SecurityStatus
;
944 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
945 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
950 EFI_FV_FILETYPE Type
;
951 EFI_FV_FILE_ATTRIBUTES Attributes
;
953 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
954 EFI_GUID
*AprioriFile
;
955 UINTN AprioriEntryCount
;
958 UINT32 AuthenticationStatus
;
963 BufferSize
= sizeof (EFI_HANDLE
);
964 Status
= CoreLocateHandle (
967 mFwVolEventRegistration
,
971 if (EFI_ERROR (Status
)) {
973 // If no more notification events exit
978 if (FvHasBeenProcessed (FvHandle
)) {
980 // This Fv has already been processed so lets skip it!
985 Status
= CoreHandleProtocol (FvHandle
, &gEfiFirmwareVolumeDispatchProtocolGuid
, (VOID
**)&Fv
);
986 if (EFI_ERROR (Status
)) {
988 // If no dispatch protocol then skip, but do not marked as being processed as it
989 // may show up later.
995 // Since we are about to process this Fv mark it as processed.
997 FvIsBeingProcesssed (FvHandle
);
1000 Status
= CoreHandleProtocol (FvHandle
, &gEfiFirmwareVolume2ProtocolGuid
, (VOID
**)&Fv
);
1001 if (EFI_ERROR (Status
)) {
1003 // The Handle has a FirmwareVolumeDispatch protocol and should also contiain
1004 // a FirmwareVolume protocol thus we should never get here.
1010 Status
= CoreHandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
1011 if (EFI_ERROR (Status
)) {
1013 // The Firmware volume doesn't have device path, can't be dispatched.
1019 // Evaluate the authentication status of the Firmware Volume through
1020 // Security Architectural Protocol
1022 if (gSecurity
!= NULL
) {
1023 SecurityStatus
= gSecurity
->FileAuthenticationState (
1028 if (SecurityStatus
!= EFI_SUCCESS
) {
1030 // Security check failed. The firmware volume should not be used for any purpose.
1037 // Discover Drivers in FV and add them to the Discovered Driver List.
1038 // Process EFI_FV_FILETYPE_DRIVER type and then EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
1039 // EFI_FV_FILETYPE_DXE_CORE is processed to produce a Loaded Image protocol for the core
1040 // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE is processed to create a Fvb
1042 for (Index
= 0; Index
< sizeof (mDxeFileTypes
)/sizeof (EFI_FV_FILETYPE
); Index
++) {
1044 // Initialize the search key
1048 Type
= mDxeFileTypes
[Index
];
1049 GetNextFileStatus
= Fv
->GetNextFile (
1057 if (!EFI_ERROR (GetNextFileStatus
)) {
1058 if (Type
== EFI_FV_FILETYPE_DXE_CORE
) {
1060 // If this is the DXE core fill in it's DevicePath & DeviceHandle
1062 if (gDxeCoreLoadedImage
->FilePath
== NULL
) {
1063 if (CompareGuid (&NameGuid
, gDxeCoreFileName
)) {
1065 // Maybe One specail Fv cantains only one DXE_CORE module, so its device path must
1066 // be initialized completely.
1068 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, &NameGuid
);
1069 mFvDevicePath
.End
.Type
= EFI_END_ENTIRE_DEVICE_PATH
;
1070 mFvDevicePath
.End
.SubType
= END_ENTIRE_DEVICE_PATH_SUBTYPE
;
1071 SetDevicePathNodeLength (&mFvDevicePath
.End
, sizeof (EFI_DEVICE_PATH_PROTOCOL
));
1073 gDxeCoreLoadedImage
->FilePath
= CoreDuplicateDevicePath (
1074 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
1076 gDxeCoreLoadedImage
->DeviceHandle
= FvHandle
;
1079 } else if (Type
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
1081 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
1084 if (FvFoundInHobFv2 (FvHandle
, &NameGuid
)) {
1089 // Found a firmware volume image. Produce a firmware volume block
1090 // protocol for it so it gets dispatched from. This is usually a
1093 CoreProcessFvImageFile (Fv
, FvHandle
, &NameGuid
);
1096 // Transition driver from Undiscovered to Discovered state
1098 CoreAddToDriverList (Fv
, FvHandle
, &NameGuid
);
1101 } while (!EFI_ERROR (GetNextFileStatus
));
1105 // Read the array of GUIDs from the Apriori file if it is present in the firmware volume
1108 Status
= Fv
->ReadSection (
1113 (VOID
**)&AprioriFile
,
1115 &AuthenticationStatus
1117 if (!EFI_ERROR (Status
)) {
1118 AprioriEntryCount
= SizeOfBuffer
/ sizeof (EFI_GUID
);
1120 AprioriEntryCount
= 0;
1124 // Put drivers on Apriori List on the Scheduled queue. The Discovered List includes
1125 // drivers not in the current FV and these must be skipped since the a priori list
1126 // is only valid for the FV that it resided in.
1128 CoreAcquireDispatcherLock ();
1130 for (Index
= 0; Index
< AprioriEntryCount
; Index
++) {
1131 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
1132 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
1133 if (CompareGuid (&DriverEntry
->FileName
, &AprioriFile
[Index
]) &&
1134 (FvHandle
== DriverEntry
->FvHandle
)) {
1135 DriverEntry
->Dependent
= FALSE
;
1136 DriverEntry
->Scheduled
= TRUE
;
1137 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
1143 CoreReleaseDispatcherLock ();
1146 // Free data allocated by Fv->ReadSection ()
1148 CoreFreePool (AprioriFile
);
1154 CoreInitializeDispatcher (
1159 Routine Description:
1161 Initialize the dispatcher. Initialize the notification function that runs when
1162 a FV protocol is added to the system.
1174 mFwVolEvent
= CoreCreateProtocolNotifyEvent (
1175 &gEfiFirmwareVolume2ProtocolGuid
,
1177 CoreFwVolEventProtocolNotify
,
1179 &mFwVolEventRegistration
,
1185 // Function only used in debug builds
1188 CoreDisplayDiscoveredNotDispatched (
1193 Routine Description:
1195 Traverse the discovered list for any drivers that were discovered but not loaded
1196 because the dependency experessions evaluated to false
1209 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
1211 for (Link
= mDiscoveredList
.ForwardLink
;Link
!=&mDiscoveredList
; Link
= Link
->ForwardLink
) {
1212 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
1213 if (DriverEntry
->Dependent
) {
1214 DEBUG ((EFI_D_LOAD
, "Driver %g was discovered but not loaded!!\n", &DriverEntry
->FileName
));