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.
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.
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.
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
26 Depex - Dependency Expresion.
27 SOR - Schedule On Request - Don't schedule if this bit is set.
29 Copyright (c) 2006 - 2010, 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
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.
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
46 LIST_ENTRY mDiscoveredList
= INITIALIZE_LIST_HEAD_VARIABLE (mDiscoveredList
);
49 // Queue of drivers that are ready to dispatch. This queue is a subset of the
50 // mDiscoveredList.list of EFI_CORE_DRIVER_ENTRY.
52 LIST_ENTRY mScheduledQueue
= INITIALIZE_LIST_HEAD_VARIABLE (mScheduledQueue
);
55 // List of handles who's Fv's have been parsed and added to the mFwDriverList.
57 LIST_ENTRY mFvHandleList
= INITIALIZE_LIST_HEAD_VARIABLE (mFvHandleList
); // list of KNOWN_HANDLE
60 // Lock for mDiscoveredList, mScheduledQueue, gDispatcherRunning.
62 EFI_LOCK mDispatcherLock
= EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL
);
66 // Flag for the DXE Dispacher. TRUE if dispatcher is execuing.
68 BOOLEAN gDispatcherRunning
= FALSE
;
71 // Module globals to manage the FwVol registration notification event
73 EFI_EVENT mFwVolEvent
;
74 VOID
*mFwVolEventRegistration
;
77 // List of file types supported by dispatcher
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
88 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH File
;
89 EFI_DEVICE_PATH_PROTOCOL End
;
90 } FV_FILEPATH_DEVICE_PATH
;
92 FV_FILEPATH_DEVICE_PATH mFvDevicePath
;
96 // Function Prototypes
99 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
100 must add any driver with a before dependency on InsertedDriverEntry first.
101 You do this by recursively calling this routine. After all the Befores are
102 processed you can add InsertedDriverEntry to the mScheduledQueue.
103 Then you can add any driver with an After dependency on InsertedDriverEntry
104 by recursively calling this routine.
106 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
110 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
111 IN EFI_CORE_DRIVER_ENTRY
*InsertedDriverEntry
115 Event notification that is fired every time a FV dispatch protocol is added.
116 More than one protocol may have been added when this event is fired, so you
117 must loop on CoreLocateHandle () to see how many protocols were added and
118 do the following to each FV:
119 If the Fv has already been processed, skip it. If the Fv has not been
120 processed then mark it as being processed, as we are about to process it.
121 Read the Fv and add any driver in the Fv to the mDiscoveredList.The
122 mDiscoveredList is never free'ed and contains variables that define
123 the other states the DXE driver transitions to..
124 While you are at it read the A Priori file into memory.
125 Place drivers in the A Priori list onto the mScheduledQueue.
127 @param Event The Event that is being processed, not used.
128 @param Context Event Context, not used.
133 CoreFwVolEventProtocolNotify (
139 Convert FvHandle and DriverName into an EFI device path
141 @param Fv Fv protocol, needed to read Depex info out of
143 @param FvHandle Handle for Fv, needed in the
144 EFI_CORE_DRIVER_ENTRY so that the PE image can be
145 read out of the FV at a later time.
146 @param DriverName Name of driver to add to mDiscoveredList.
148 @return Pointer to device path constructed from FvHandle and DriverName
151 EFI_DEVICE_PATH_PROTOCOL
*
153 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
154 IN EFI_HANDLE FvHandle
,
155 IN EFI_GUID
*DriverName
159 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
160 and initilize any state variables. Read the Depex from the FV and store it
161 in DriverEntry. Pre-process the Depex to set the SOR, Before and After state.
162 The Discovered list is never free'ed and contains booleans that represent the
163 other possible DXE driver states.
165 @param Fv Fv protocol, needed to read Depex info out of
167 @param FvHandle Handle for Fv, needed in the
168 EFI_CORE_DRIVER_ENTRY so that the PE image can be
169 read out of the FV at a later time.
170 @param DriverName Name of driver to add to mDiscoveredList.
172 @retval EFI_SUCCESS If driver was added to the mDiscoveredList.
173 @retval EFI_ALREADY_STARTED The driver has already been started. Only one
174 DriverName may be active in the system at any one
179 CoreAddToDriverList (
180 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
181 IN EFI_HANDLE FvHandle
,
182 IN EFI_GUID
*DriverName
186 Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.
188 @param Fv The FIRMWARE_VOLUME protocol installed on the FV.
189 @param FvHandle The handle which FVB protocol installed on.
190 @param DriverName The driver guid specified.
192 @retval EFI_OUT_OF_RESOURCES No enough memory or other resource.
193 @retval EFI_VOLUME_CORRUPTED Corrupted volume.
194 @retval EFI_SUCCESS Function successfully returned.
198 CoreProcessFvImageFile (
199 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
200 IN EFI_HANDLE FvHandle
,
201 IN EFI_GUID
*DriverName
206 Enter critical section by gaining lock on mDispatcherLock.
210 CoreAcquireDispatcherLock (
214 CoreAcquireLock (&mDispatcherLock
);
219 Exit critical section by releasing lock on mDispatcherLock.
223 CoreReleaseDispatcherLock (
227 CoreReleaseLock (&mDispatcherLock
);
232 Read Depex and pre-process the Depex for Before and After. If Section Extraction
233 protocol returns an error via ReadSection defer the reading of the Depex.
235 @param DriverEntry Driver to work on.
237 @retval EFI_SUCCESS Depex read and preprossesed
238 @retval EFI_PROTOCOL_ERROR The section extraction protocol returned an error
239 and Depex reading needs to be retried.
240 @retval Error DEPEX not found.
244 CoreGetDepexSectionAndPreProccess (
245 IN EFI_CORE_DRIVER_ENTRY
*DriverEntry
249 EFI_SECTION_TYPE SectionType
;
250 UINT32 AuthenticationStatus
;
251 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
254 Fv
= DriverEntry
->Fv
;
257 // Grab Depex info, it will never be free'ed.
259 SectionType
= EFI_SECTION_DXE_DEPEX
;
260 Status
= Fv
->ReadSection (
262 &DriverEntry
->FileName
,
266 (UINTN
*)&DriverEntry
->DepexSize
,
267 &AuthenticationStatus
269 if (EFI_ERROR (Status
)) {
270 if (Status
== EFI_PROTOCOL_ERROR
) {
272 // The section extraction protocol failed so set protocol error flag
274 DriverEntry
->DepexProtocolError
= TRUE
;
277 // If no Depex assume UEFI 2.0 driver model
279 DriverEntry
->Depex
= NULL
;
280 DriverEntry
->Dependent
= TRUE
;
281 DriverEntry
->DepexProtocolError
= FALSE
;
285 // Set Before, After, and Unrequested state information based on Depex
286 // Driver will be put in Dependent or Unrequested state
288 CorePreProcessDepex (DriverEntry
);
289 DriverEntry
->DepexProtocolError
= FALSE
;
297 Check every driver and locate a matching one. If the driver is found, the Unrequested
298 state flag is cleared.
300 @param FirmwareVolumeHandle The handle of the Firmware Volume that contains
301 the firmware file specified by DriverName.
302 @param DriverName The Driver name to put in the Dependent state.
304 @retval EFI_SUCCESS The DriverName was found and it's SOR bit was
306 @retval EFI_NOT_FOUND The DriverName does not exist or it's SOR bit was
313 IN EFI_HANDLE FirmwareVolumeHandle
,
314 IN EFI_GUID
*DriverName
318 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
321 // Check every driver
323 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
324 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
325 if (DriverEntry
->FvHandle
== FirmwareVolumeHandle
&&
326 DriverEntry
->Unrequested
&&
327 CompareGuid (DriverName
, &DriverEntry
->FileName
)) {
329 // Move the driver from the Unrequested to the Dependent state
331 CoreAcquireDispatcherLock ();
332 DriverEntry
->Unrequested
= FALSE
;
333 DriverEntry
->Dependent
= TRUE
;
334 CoreReleaseDispatcherLock ();
336 DEBUG ((DEBUG_DISPATCH
, "Schedule FFS(%g) - EFI_SUCCESS\n", DriverName
));
342 DEBUG ((DEBUG_DISPATCH
, "Schedule FFS(%g) - EFI_NOT_FOUND\n", DriverName
));
344 return EFI_NOT_FOUND
;
350 Convert a driver from the Untrused back to the Scheduled state.
352 @param FirmwareVolumeHandle The handle of the Firmware Volume that contains
353 the firmware file specified by DriverName.
354 @param DriverName The Driver name to put in the Scheduled state
356 @retval EFI_SUCCESS The file was found in the untrusted state, and it
357 was promoted to the trusted state.
358 @retval EFI_NOT_FOUND The file was not found in the untrusted state.
364 IN EFI_HANDLE FirmwareVolumeHandle
,
365 IN EFI_GUID
*DriverName
369 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
372 // Check every driver
374 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
375 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
376 if (DriverEntry
->FvHandle
== FirmwareVolumeHandle
&&
377 DriverEntry
->Untrusted
&&
378 CompareGuid (DriverName
, &DriverEntry
->FileName
)) {
380 // Transition driver from Untrusted to Scheduled state.
382 CoreAcquireDispatcherLock ();
383 DriverEntry
->Untrusted
= FALSE
;
384 DriverEntry
->Scheduled
= TRUE
;
385 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
386 CoreReleaseDispatcherLock ();
391 return EFI_NOT_FOUND
;
396 An empty function to pass error checking of CreateEventEx ().
398 @param Event Event whose notification function is being invoked.
399 @param Context Pointer to the notification function's context,
400 which is implementation-dependent.
414 This is the main Dispatcher for DXE and it exits when there are no more
415 drivers to run. Drain the mScheduledQueue and load and start a PE
416 image for each driver. Search the mDiscoveredList to see if any driver can
417 be placed on the mScheduledQueue. If no drivers are placed on the
418 mScheduledQueue exit the function. On exit it is assumed the Bds()
419 will be called, and when the Bds() exits the Dispatcher will be called
422 @retval EFI_ALREADY_STARTED The DXE Dispatcher is already running
423 @retval EFI_NOT_FOUND No DXE Drivers were dispatched
424 @retval EFI_SUCCESS One or more DXE Drivers were dispatched
434 EFI_STATUS ReturnStatus
;
436 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
438 EFI_EVENT DxeDispatchEvent
;
441 if (gDispatcherRunning
) {
443 // If the dispatcher is running don't let it be restarted.
445 return EFI_ALREADY_STARTED
;
448 gDispatcherRunning
= TRUE
;
450 Status
= CoreCreateEventEx (
455 &gEfiEventDxeDispatchGuid
,
458 if (EFI_ERROR (Status
)) {
462 ReturnStatus
= EFI_NOT_FOUND
;
465 // Drain the Scheduled Queue
467 while (!IsListEmpty (&mScheduledQueue
)) {
469 mScheduledQueue
.ForwardLink
,
470 EFI_CORE_DRIVER_ENTRY
,
472 EFI_CORE_DRIVER_ENTRY_SIGNATURE
476 // Load the DXE Driver image into memory. If the Driver was transitioned from
477 // Untrused to Scheduled it would have already been loaded so we may need to
478 // skip the LoadImage
480 if (DriverEntry
->ImageHandle
== NULL
) {
481 DEBUG ((DEBUG_INFO
, "Loading driver %g\n", &DriverEntry
->FileName
));
482 Status
= CoreLoadImage (
485 DriverEntry
->FvFileDevicePath
,
488 &DriverEntry
->ImageHandle
492 // Update the driver state to reflect that it's been loaded
494 if (EFI_ERROR (Status
)) {
495 CoreAcquireDispatcherLock ();
497 if (Status
== EFI_SECURITY_VIOLATION
) {
499 // Take driver from Scheduled to Untrused state
501 DriverEntry
->Untrusted
= TRUE
;
504 // The DXE Driver could not be loaded, and do not attempt to load or start it again.
505 // Take driver from Scheduled to Initialized.
507 // This case include the Never Trusted state if EFI_ACCESS_DENIED is returned
509 DriverEntry
->Initialized
= TRUE
;
512 DriverEntry
->Scheduled
= FALSE
;
513 RemoveEntryList (&DriverEntry
->ScheduledLink
);
515 CoreReleaseDispatcherLock ();
518 // If it's an error don't try the StartImage
524 CoreAcquireDispatcherLock ();
526 DriverEntry
->Scheduled
= FALSE
;
527 DriverEntry
->Initialized
= TRUE
;
528 RemoveEntryList (&DriverEntry
->ScheduledLink
);
530 CoreReleaseDispatcherLock ();
533 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
535 (EFI_SOFTWARE_DXE_CORE
| EFI_SW_PC_INIT_BEGIN
),
536 &DriverEntry
->ImageHandle
,
537 sizeof (DriverEntry
->ImageHandle
)
540 Status
= CoreStartImage (DriverEntry
->ImageHandle
, NULL
, NULL
);
542 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
544 (EFI_SOFTWARE_DXE_CORE
| EFI_SW_PC_INIT_END
),
545 &DriverEntry
->ImageHandle
,
546 sizeof (DriverEntry
->ImageHandle
)
549 ReturnStatus
= EFI_SUCCESS
;
553 // Now DXE Dispatcher finished one round of dispatch, signal an event group
554 // so that SMM Dispatcher get chance to dispatch SMM Drivers which depend
557 if (!EFI_ERROR (ReturnStatus
)) {
558 CoreSignalEvent (DxeDispatchEvent
);
562 // Search DriverList for items to place on Scheduled Queue
565 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
566 DriverEntry
= CR (Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
568 if (DriverEntry
->DepexProtocolError
){
570 // If Section Extraction Protocol did not let the Depex be read before retry the read
572 Status
= CoreGetDepexSectionAndPreProccess (DriverEntry
);
575 if (DriverEntry
->Dependent
) {
576 if (CoreIsSchedulable (DriverEntry
)) {
577 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
581 if (DriverEntry
->Unrequested
) {
582 DEBUG ((DEBUG_DISPATCH
, "Evaluate DXE DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
583 DEBUG ((DEBUG_DISPATCH
, " SOR = Not Requested\n"));
584 DEBUG ((DEBUG_DISPATCH
, " RESULT = FALSE\n"));
588 } while (ReadyToRun
);
591 // Close DXE dispatch Event
593 CoreCloseEvent (DxeDispatchEvent
);
595 gDispatcherRunning
= FALSE
;
602 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
603 must add any driver with a before dependency on InsertedDriverEntry first.
604 You do this by recursively calling this routine. After all the Befores are
605 processed you can add InsertedDriverEntry to the mScheduledQueue.
606 Then you can add any driver with an After dependency on InsertedDriverEntry
607 by recursively calling this routine.
609 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
613 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
614 IN EFI_CORE_DRIVER_ENTRY
*InsertedDriverEntry
618 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
621 // Process Before Dependency
623 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
624 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
625 if (DriverEntry
->Before
&& DriverEntry
->Dependent
&& DriverEntry
!= InsertedDriverEntry
) {
626 DEBUG ((DEBUG_DISPATCH
, "Evaluate DXE DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
627 DEBUG ((DEBUG_DISPATCH
, " BEFORE FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
628 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
630 // Recursively process BEFORE
632 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
633 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
635 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
641 // Convert driver from Dependent to Scheduled state
643 CoreAcquireDispatcherLock ();
645 InsertedDriverEntry
->Dependent
= FALSE
;
646 InsertedDriverEntry
->Scheduled
= TRUE
;
647 InsertTailList (&mScheduledQueue
, &InsertedDriverEntry
->ScheduledLink
);
649 CoreReleaseDispatcherLock ();
652 // Process After Dependency
654 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
655 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
656 if (DriverEntry
->After
&& DriverEntry
->Dependent
&& DriverEntry
!= InsertedDriverEntry
) {
657 DEBUG ((DEBUG_DISPATCH
, "Evaluate DXE DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
658 DEBUG ((DEBUG_DISPATCH
, " AFTER FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
659 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
661 // Recursively process AFTER
663 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
664 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
666 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
674 Return TRUE if the Fv has been processed, FALSE if not.
676 @param FvHandle The handle of a FV that's being tested
678 @retval TRUE Fv protocol on FvHandle has been processed
679 @retval FALSE Fv protocol on FvHandle has not yet been processed
684 IN EFI_HANDLE FvHandle
688 KNOWN_HANDLE
*KnownHandle
;
690 for (Link
= mFvHandleList
.ForwardLink
; Link
!= &mFvHandleList
; Link
= Link
->ForwardLink
) {
691 KnownHandle
= CR(Link
, KNOWN_HANDLE
, Link
, KNOWN_HANDLE_SIGNATURE
);
692 if (KnownHandle
->Handle
== FvHandle
) {
701 Remember that Fv protocol on FvHandle has had it's drivers placed on the
702 mDiscoveredList. This fucntion adds entries on the mFvHandleList. Items are
703 never removed/freed from the mFvHandleList.
705 @param FvHandle The handle of a FV that has been processed
709 FvIsBeingProcesssed (
710 IN EFI_HANDLE FvHandle
713 KNOWN_HANDLE
*KnownHandle
;
715 KnownHandle
= AllocatePool (sizeof (KNOWN_HANDLE
));
716 ASSERT (KnownHandle
!= NULL
);
718 KnownHandle
->Signature
= KNOWN_HANDLE_SIGNATURE
;
719 KnownHandle
->Handle
= FvHandle
;
720 InsertTailList (&mFvHandleList
, &KnownHandle
->Link
);
727 Convert FvHandle and DriverName into an EFI device path
729 @param Fv Fv protocol, needed to read Depex info out of
731 @param FvHandle Handle for Fv, needed in the
732 EFI_CORE_DRIVER_ENTRY so that the PE image can be
733 read out of the FV at a later time.
734 @param DriverName Name of driver to add to mDiscoveredList.
736 @return Pointer to device path constructed from FvHandle and DriverName
739 EFI_DEVICE_PATH_PROTOCOL
*
741 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
742 IN EFI_HANDLE FvHandle
,
743 IN EFI_GUID
*DriverName
747 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
748 EFI_DEVICE_PATH_PROTOCOL
*FileNameDevicePath
;
751 // Remember the device path of the FV
753 Status
= CoreHandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
754 if (EFI_ERROR (Status
)) {
755 FileNameDevicePath
= NULL
;
758 // Build a device path to the file in the FV to pass into gBS->LoadImage
760 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, DriverName
);
761 SetDevicePathEndNode (&mFvDevicePath
.End
);
763 FileNameDevicePath
= AppendDevicePath (
765 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
769 return FileNameDevicePath
;
775 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
776 and initilize any state variables. Read the Depex from the FV and store it
777 in DriverEntry. Pre-process the Depex to set the SOR, Before and After state.
778 The Discovered list is never free'ed and contains booleans that represent the
779 other possible DXE driver states.
781 @param Fv Fv protocol, needed to read Depex info out of
783 @param FvHandle Handle for Fv, needed in the
784 EFI_CORE_DRIVER_ENTRY so that the PE image can be
785 read out of the FV at a later time.
786 @param DriverName Name of driver to add to mDiscoveredList.
788 @retval EFI_SUCCESS If driver was added to the mDiscoveredList.
789 @retval EFI_ALREADY_STARTED The driver has already been started. Only one
790 DriverName may be active in the system at any one
795 CoreAddToDriverList (
796 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
797 IN EFI_HANDLE FvHandle
,
798 IN EFI_GUID
*DriverName
801 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
805 // Create the Driver Entry for the list. ZeroPool initializes lots of variables to
808 DriverEntry
= AllocateZeroPool (sizeof (EFI_CORE_DRIVER_ENTRY
));
809 ASSERT (DriverEntry
!= NULL
);
811 DriverEntry
->Signature
= EFI_CORE_DRIVER_ENTRY_SIGNATURE
;
812 CopyGuid (&DriverEntry
->FileName
, DriverName
);
813 DriverEntry
->FvHandle
= FvHandle
;
814 DriverEntry
->Fv
= Fv
;
815 DriverEntry
->FvFileDevicePath
= CoreFvToDevicePath (Fv
, FvHandle
, DriverName
);
817 CoreGetDepexSectionAndPreProccess (DriverEntry
);
819 CoreAcquireDispatcherLock ();
821 InsertTailList (&mDiscoveredList
, &DriverEntry
->Link
);
823 CoreReleaseDispatcherLock ();
830 Check if a FV Image type file (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) is
831 described by a EFI_HOB_FIRMWARE_VOLUME2 Hob.
833 @param FvHandle The handle which FVB protocol installed on.
834 @param DriverName The driver guid specified.
836 @retval TRUE This file is found in a EFI_HOB_FIRMWARE_VOLUME2
838 @retval FALSE Not found.
843 IN EFI_HANDLE FvHandle
,
844 IN CONST EFI_GUID
*DriverName
847 EFI_PEI_HOB_POINTERS HobFv2
;
849 HobFv2
.Raw
= GetHobList ();
851 while ((HobFv2
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobFv2
.Raw
)) != NULL
) {
852 if (CompareGuid (DriverName
, &HobFv2
.FirmwareVolume2
->FileName
)) {
855 HobFv2
.Raw
= GET_NEXT_HOB (HobFv2
);
864 Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.
866 @param Fv The FIRMWARE_VOLUME protocol installed on the FV.
867 @param FvHandle The handle which FVB protocol installed on.
868 @param DriverName The driver guid specified.
870 @retval EFI_OUT_OF_RESOURCES No enough memory or other resource.
871 @retval EFI_VOLUME_CORRUPTED Corrupted volume.
872 @retval EFI_SUCCESS Function successfully returned.
876 CoreProcessFvImageFile (
877 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
878 IN EFI_HANDLE FvHandle
,
879 IN EFI_GUID
*DriverName
883 EFI_SECTION_TYPE SectionType
;
884 UINT32 AuthenticationStatus
;
888 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
892 // Read the first (and only the first) firmware volume section
894 SectionType
= EFI_SECTION_FIRMWARE_VOLUME_IMAGE
;
899 AlignedBuffer
= NULL
;
900 Status
= Fv
->ReadSection (
907 &AuthenticationStatus
909 if (!EFI_ERROR (Status
)) {
911 // FvImage should be at its required alignment.
913 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) Buffer
;
915 // Get FvHeader alignment
917 FvAlignment
= 1 << ((FvHeader
->Attributes
& EFI_FVB2_ALIGNMENT
) >> 16);
919 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
921 if (FvAlignment
< 8) {
925 // Allocate the aligned buffer for the FvImage.
927 AlignedBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize
), (UINTN
) FvAlignment
);
928 if (AlignedBuffer
== NULL
) {
929 Status
= EFI_OUT_OF_RESOURCES
;
932 // Move FvImage into the aligned buffer and release the original buffer.
934 CopyMem (AlignedBuffer
, Buffer
, BufferSize
);
935 CoreFreePool (Buffer
);
938 // Produce a FVB protocol for the file
940 Status
= ProduceFVBProtocolOnBuffer (
941 (EFI_PHYSICAL_ADDRESS
) (UINTN
) AlignedBuffer
,
949 if (EFI_ERROR (Status
)) {
951 // ReadSection or Produce FVB failed, Free data buffer
953 if (Buffer
!= NULL
) {
957 if (AlignedBuffer
!= NULL
) {
958 FreeAlignedPages (AlignedBuffer
, EFI_SIZE_TO_PAGES (BufferSize
));
967 Event notification that is fired every time a FV dispatch protocol is added.
968 More than one protocol may have been added when this event is fired, so you
969 must loop on CoreLocateHandle () to see how many protocols were added and
970 do the following to each FV:
971 If the Fv has already been processed, skip it. If the Fv has not been
972 processed then mark it as being processed, as we are about to process it.
973 Read the Fv and add any driver in the Fv to the mDiscoveredList.The
974 mDiscoveredList is never free'ed and contains variables that define
975 the other states the DXE driver transitions to..
976 While you are at it read the A Priori file into memory.
977 Place drivers in the A Priori list onto the mScheduledQueue.
979 @param Event The Event that is being processed, not used.
980 @param Context Event Context, not used.
985 CoreFwVolEventProtocolNotify (
991 EFI_STATUS GetNextFileStatus
;
992 EFI_STATUS SecurityStatus
;
993 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
994 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
999 EFI_FV_FILETYPE Type
;
1000 EFI_FV_FILE_ATTRIBUTES Attributes
;
1002 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
1003 EFI_GUID
*AprioriFile
;
1004 UINTN AprioriEntryCount
;
1007 UINT32 AuthenticationStatus
;
1012 BufferSize
= sizeof (EFI_HANDLE
);
1013 Status
= CoreLocateHandle (
1016 mFwVolEventRegistration
,
1020 if (EFI_ERROR (Status
)) {
1022 // If no more notification events exit
1027 if (FvHasBeenProcessed (FvHandle
)) {
1029 // This Fv has already been processed so lets skip it!
1035 // Since we are about to process this Fv mark it as processed.
1037 FvIsBeingProcesssed (FvHandle
);
1039 Status
= CoreHandleProtocol (FvHandle
, &gEfiFirmwareVolume2ProtocolGuid
, (VOID
**)&Fv
);
1040 if (EFI_ERROR (Status
) || Fv
== NULL
) {
1042 // FvHandle must have Firmware Volume2 protocol thus we should never get here.
1048 Status
= CoreHandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
1049 if (EFI_ERROR (Status
)) {
1051 // The Firmware volume doesn't have device path, can't be dispatched.
1057 // Evaluate the authentication status of the Firmware Volume through
1058 // Security Architectural Protocol
1060 if (gSecurity
!= NULL
) {
1061 SecurityStatus
= gSecurity
->FileAuthenticationState (
1066 if (SecurityStatus
!= EFI_SUCCESS
) {
1068 // Security check failed. The firmware volume should not be used for any purpose.
1075 // Discover Drivers in FV and add them to the Discovered Driver List.
1076 // Process EFI_FV_FILETYPE_DRIVER type and then EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
1077 // EFI_FV_FILETYPE_DXE_CORE is processed to produce a Loaded Image protocol for the core
1078 // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE is processed to create a Fvb
1080 for (Index
= 0; Index
< sizeof (mDxeFileTypes
) / sizeof (EFI_FV_FILETYPE
); Index
++) {
1082 // Initialize the search key
1086 Type
= mDxeFileTypes
[Index
];
1087 GetNextFileStatus
= Fv
->GetNextFile (
1095 if (!EFI_ERROR (GetNextFileStatus
)) {
1096 if (Type
== EFI_FV_FILETYPE_DXE_CORE
) {
1098 // If this is the DXE core fill in it's DevicePath & DeviceHandle
1100 if (gDxeCoreLoadedImage
->FilePath
== NULL
) {
1101 if (CompareGuid (&NameGuid
, gDxeCoreFileName
)) {
1103 // Maybe One specail Fv cantains only one DXE_CORE module, so its device path must
1104 // be initialized completely.
1106 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, &NameGuid
);
1107 SetDevicePathEndNode (&mFvDevicePath
.End
);
1109 gDxeCoreLoadedImage
->FilePath
= DuplicateDevicePath (
1110 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
1112 gDxeCoreLoadedImage
->DeviceHandle
= FvHandle
;
1115 } else if (Type
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
1117 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
1120 if (FvFoundInHobFv2 (FvHandle
, &NameGuid
)) {
1124 // Found a firmware volume image. Produce a firmware volume block
1125 // protocol for it so it gets dispatched from. This is usually a
1128 CoreProcessFvImageFile (Fv
, FvHandle
, &NameGuid
);
1131 // Transition driver from Undiscovered to Discovered state
1133 CoreAddToDriverList (Fv
, FvHandle
, &NameGuid
);
1136 } while (!EFI_ERROR (GetNextFileStatus
));
1140 // Read the array of GUIDs from the Apriori file if it is present in the firmware volume
1143 Status
= Fv
->ReadSection (
1148 (VOID
**)&AprioriFile
,
1150 &AuthenticationStatus
1152 if (!EFI_ERROR (Status
)) {
1153 AprioriEntryCount
= SizeOfBuffer
/ sizeof (EFI_GUID
);
1155 AprioriEntryCount
= 0;
1159 // Put drivers on Apriori List on the Scheduled queue. The Discovered List includes
1160 // drivers not in the current FV and these must be skipped since the a priori list
1161 // is only valid for the FV that it resided in.
1164 for (Index
= 0; Index
< AprioriEntryCount
; Index
++) {
1165 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
1166 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
1167 if (CompareGuid (&DriverEntry
->FileName
, &AprioriFile
[Index
]) &&
1168 (FvHandle
== DriverEntry
->FvHandle
)) {
1169 CoreAcquireDispatcherLock ();
1170 DriverEntry
->Dependent
= FALSE
;
1171 DriverEntry
->Scheduled
= TRUE
;
1172 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
1173 CoreReleaseDispatcherLock ();
1174 DEBUG ((DEBUG_DISPATCH
, "Evaluate DXE DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
1175 DEBUG ((DEBUG_DISPATCH
, " RESULT = TRUE (Apriori)\n"));
1182 // Free data allocated by Fv->ReadSection ()
1184 CoreFreePool (AprioriFile
);
1191 Initialize the dispatcher. Initialize the notification function that runs when
1192 an FV2 protocol is added to the system.
1196 CoreInitializeDispatcher (
1200 mFwVolEvent
= EfiCreateProtocolNotifyEvent (
1201 &gEfiFirmwareVolume2ProtocolGuid
,
1203 CoreFwVolEventProtocolNotify
,
1205 &mFwVolEventRegistration
1210 // Function only used in debug builds
1214 Traverse the discovered list for any drivers that were discovered but not loaded
1215 because the dependency experessions evaluated to false.
1219 CoreDisplayDiscoveredNotDispatched (
1224 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
1226 for (Link
= mDiscoveredList
.ForwardLink
;Link
!=&mDiscoveredList
; Link
= Link
->ForwardLink
) {
1227 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
1228 if (DriverEntry
->Dependent
) {
1229 DEBUG ((DEBUG_LOAD
, "Driver %g was discovered but not loaded!!\n", &DriverEntry
->FileName
));