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 - 2011, 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.
171 @param Type Fv File Type of file to add to mDiscoveredList.
173 @retval EFI_SUCCESS If driver was added to the mDiscoveredList.
174 @retval EFI_ALREADY_STARTED The driver has already been started. Only one
175 DriverName may be active in the system at any one
180 CoreAddToDriverList (
181 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
182 IN EFI_HANDLE FvHandle
,
183 IN EFI_GUID
*DriverName
,
184 IN EFI_FV_FILETYPE Type
188 Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.
190 @param Fv The FIRMWARE_VOLUME protocol installed on the FV.
191 @param FvHandle The handle which FVB protocol installed on.
192 @param DriverName The driver guid specified.
194 @retval EFI_OUT_OF_RESOURCES No enough memory or other resource.
195 @retval EFI_VOLUME_CORRUPTED Corrupted volume.
196 @retval EFI_SUCCESS Function successfully returned.
200 CoreProcessFvImageFile (
201 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
202 IN EFI_HANDLE FvHandle
,
203 IN EFI_GUID
*DriverName
208 Enter critical section by gaining lock on mDispatcherLock.
212 CoreAcquireDispatcherLock (
216 CoreAcquireLock (&mDispatcherLock
);
221 Exit critical section by releasing lock on mDispatcherLock.
225 CoreReleaseDispatcherLock (
229 CoreReleaseLock (&mDispatcherLock
);
234 Read Depex and pre-process the Depex for Before and After. If Section Extraction
235 protocol returns an error via ReadSection defer the reading of the Depex.
237 @param DriverEntry Driver to work on.
239 @retval EFI_SUCCESS Depex read and preprossesed
240 @retval EFI_PROTOCOL_ERROR The section extraction protocol returned an error
241 and Depex reading needs to be retried.
242 @retval Error DEPEX not found.
246 CoreGetDepexSectionAndPreProccess (
247 IN EFI_CORE_DRIVER_ENTRY
*DriverEntry
251 EFI_SECTION_TYPE SectionType
;
252 UINT32 AuthenticationStatus
;
253 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
256 Fv
= DriverEntry
->Fv
;
259 // Grab Depex info, it will never be free'ed.
261 SectionType
= EFI_SECTION_DXE_DEPEX
;
262 Status
= Fv
->ReadSection (
264 &DriverEntry
->FileName
,
268 (UINTN
*)&DriverEntry
->DepexSize
,
269 &AuthenticationStatus
271 if (EFI_ERROR (Status
)) {
272 if (Status
== EFI_PROTOCOL_ERROR
) {
274 // The section extraction protocol failed so set protocol error flag
276 DriverEntry
->DepexProtocolError
= TRUE
;
279 // If no Depex assume UEFI 2.0 driver model
281 DriverEntry
->Depex
= NULL
;
282 DriverEntry
->Dependent
= TRUE
;
283 DriverEntry
->DepexProtocolError
= FALSE
;
287 // Set Before, After, and Unrequested state information based on Depex
288 // Driver will be put in Dependent or Unrequested state
290 CorePreProcessDepex (DriverEntry
);
291 DriverEntry
->DepexProtocolError
= FALSE
;
299 Check every driver and locate a matching one. If the driver is found, the Unrequested
300 state flag is cleared.
302 @param FirmwareVolumeHandle The handle of the Firmware Volume that contains
303 the firmware file specified by DriverName.
304 @param DriverName The Driver name to put in the Dependent state.
306 @retval EFI_SUCCESS The DriverName was found and it's SOR bit was
308 @retval EFI_NOT_FOUND The DriverName does not exist or it's SOR bit was
315 IN EFI_HANDLE FirmwareVolumeHandle
,
316 IN EFI_GUID
*DriverName
320 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
323 // Check every driver
325 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
326 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
327 if (DriverEntry
->FvHandle
== FirmwareVolumeHandle
&&
328 DriverEntry
->Unrequested
&&
329 CompareGuid (DriverName
, &DriverEntry
->FileName
)) {
331 // Move the driver from the Unrequested to the Dependent state
333 CoreAcquireDispatcherLock ();
334 DriverEntry
->Unrequested
= FALSE
;
335 DriverEntry
->Dependent
= TRUE
;
336 CoreReleaseDispatcherLock ();
338 DEBUG ((DEBUG_DISPATCH
, "Schedule FFS(%g) - EFI_SUCCESS\n", DriverName
));
344 DEBUG ((DEBUG_DISPATCH
, "Schedule FFS(%g) - EFI_NOT_FOUND\n", DriverName
));
346 return EFI_NOT_FOUND
;
352 Convert a driver from the Untrused back to the Scheduled state.
354 @param FirmwareVolumeHandle The handle of the Firmware Volume that contains
355 the firmware file specified by DriverName.
356 @param DriverName The Driver name to put in the Scheduled state
358 @retval EFI_SUCCESS The file was found in the untrusted state, and it
359 was promoted to the trusted state.
360 @retval EFI_NOT_FOUND The file was not found in the untrusted state.
366 IN EFI_HANDLE FirmwareVolumeHandle
,
367 IN EFI_GUID
*DriverName
371 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
374 // Check every driver
376 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
377 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
378 if (DriverEntry
->FvHandle
== FirmwareVolumeHandle
&&
379 DriverEntry
->Untrusted
&&
380 CompareGuid (DriverName
, &DriverEntry
->FileName
)) {
382 // Transition driver from Untrusted to Scheduled state.
384 CoreAcquireDispatcherLock ();
385 DriverEntry
->Untrusted
= FALSE
;
386 DriverEntry
->Scheduled
= TRUE
;
387 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
388 CoreReleaseDispatcherLock ();
393 return EFI_NOT_FOUND
;
398 An empty function to pass error checking of CreateEventEx ().
400 @param Event Event whose notification function is being invoked.
401 @param Context Pointer to the notification function's context,
402 which is implementation-dependent.
407 CoreEmptyCallbackFunction (
416 This is the main Dispatcher for DXE and it exits when there are no more
417 drivers to run. Drain the mScheduledQueue and load and start a PE
418 image for each driver. Search the mDiscoveredList to see if any driver can
419 be placed on the mScheduledQueue. If no drivers are placed on the
420 mScheduledQueue exit the function. On exit it is assumed the Bds()
421 will be called, and when the Bds() exits the Dispatcher will be called
424 @retval EFI_ALREADY_STARTED The DXE Dispatcher is already running
425 @retval EFI_NOT_FOUND No DXE Drivers were dispatched
426 @retval EFI_SUCCESS One or more DXE Drivers were dispatched
436 EFI_STATUS ReturnStatus
;
438 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
440 EFI_EVENT DxeDispatchEvent
;
443 if (gDispatcherRunning
) {
445 // If the dispatcher is running don't let it be restarted.
447 return EFI_ALREADY_STARTED
;
450 gDispatcherRunning
= TRUE
;
452 Status
= CoreCreateEventEx (
455 CoreEmptyCallbackFunction
,
457 &gEfiEventDxeDispatchGuid
,
460 if (EFI_ERROR (Status
)) {
464 ReturnStatus
= EFI_NOT_FOUND
;
467 // Drain the Scheduled Queue
469 while (!IsListEmpty (&mScheduledQueue
)) {
471 mScheduledQueue
.ForwardLink
,
472 EFI_CORE_DRIVER_ENTRY
,
474 EFI_CORE_DRIVER_ENTRY_SIGNATURE
478 // Load the DXE Driver image into memory. If the Driver was transitioned from
479 // Untrused to Scheduled it would have already been loaded so we may need to
480 // skip the LoadImage
482 if (DriverEntry
->ImageHandle
== NULL
&& !DriverEntry
->IsFvImage
) {
483 DEBUG ((DEBUG_INFO
, "Loading driver %g\n", &DriverEntry
->FileName
));
484 Status
= CoreLoadImage (
487 DriverEntry
->FvFileDevicePath
,
490 &DriverEntry
->ImageHandle
494 // Update the driver state to reflect that it's been loaded
496 if (EFI_ERROR (Status
)) {
497 CoreAcquireDispatcherLock ();
499 if (Status
== EFI_SECURITY_VIOLATION
) {
501 // Take driver from Scheduled to Untrused state
503 DriverEntry
->Untrusted
= TRUE
;
506 // The DXE Driver could not be loaded, and do not attempt to load or start it again.
507 // Take driver from Scheduled to Initialized.
509 // This case include the Never Trusted state if EFI_ACCESS_DENIED is returned
511 DriverEntry
->Initialized
= TRUE
;
514 DriverEntry
->Scheduled
= FALSE
;
515 RemoveEntryList (&DriverEntry
->ScheduledLink
);
517 CoreReleaseDispatcherLock ();
520 // If it's an error don't try the StartImage
526 CoreAcquireDispatcherLock ();
528 DriverEntry
->Scheduled
= FALSE
;
529 DriverEntry
->Initialized
= TRUE
;
530 RemoveEntryList (&DriverEntry
->ScheduledLink
);
532 CoreReleaseDispatcherLock ();
535 if (DriverEntry
->IsFvImage
) {
537 // Produce a firmware volume block protocol for FvImage so it gets dispatched from.
539 Status
= CoreProcessFvImageFile (DriverEntry
->Fv
, DriverEntry
->FvHandle
, &DriverEntry
->FileName
);
541 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
543 (EFI_SOFTWARE_DXE_CORE
| EFI_SW_PC_INIT_BEGIN
),
544 &DriverEntry
->ImageHandle
,
545 sizeof (DriverEntry
->ImageHandle
)
548 Status
= CoreStartImage (DriverEntry
->ImageHandle
, NULL
, NULL
);
550 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
552 (EFI_SOFTWARE_DXE_CORE
| EFI_SW_PC_INIT_END
),
553 &DriverEntry
->ImageHandle
,
554 sizeof (DriverEntry
->ImageHandle
)
558 ReturnStatus
= EFI_SUCCESS
;
562 // Now DXE Dispatcher finished one round of dispatch, signal an event group
563 // so that SMM Dispatcher get chance to dispatch SMM Drivers which depend
566 if (!EFI_ERROR (ReturnStatus
)) {
567 CoreSignalEvent (DxeDispatchEvent
);
571 // Search DriverList for items to place on Scheduled Queue
574 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
575 DriverEntry
= CR (Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
577 if (DriverEntry
->DepexProtocolError
){
579 // If Section Extraction Protocol did not let the Depex be read before retry the read
581 Status
= CoreGetDepexSectionAndPreProccess (DriverEntry
);
584 if (DriverEntry
->Dependent
) {
585 if (CoreIsSchedulable (DriverEntry
)) {
586 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
590 if (DriverEntry
->Unrequested
) {
591 DEBUG ((DEBUG_DISPATCH
, "Evaluate DXE DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
592 DEBUG ((DEBUG_DISPATCH
, " SOR = Not Requested\n"));
593 DEBUG ((DEBUG_DISPATCH
, " RESULT = FALSE\n"));
597 } while (ReadyToRun
);
600 // Close DXE dispatch Event
602 CoreCloseEvent (DxeDispatchEvent
);
604 gDispatcherRunning
= FALSE
;
611 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
612 must add any driver with a before dependency on InsertedDriverEntry first.
613 You do this by recursively calling this routine. After all the Befores are
614 processed you can add InsertedDriverEntry to the mScheduledQueue.
615 Then you can add any driver with an After dependency on InsertedDriverEntry
616 by recursively calling this routine.
618 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
622 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
623 IN EFI_CORE_DRIVER_ENTRY
*InsertedDriverEntry
627 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
630 // Process Before Dependency
632 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
633 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
634 if (DriverEntry
->Before
&& DriverEntry
->Dependent
&& DriverEntry
!= InsertedDriverEntry
) {
635 DEBUG ((DEBUG_DISPATCH
, "Evaluate DXE DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
636 DEBUG ((DEBUG_DISPATCH
, " BEFORE FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
637 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
639 // Recursively process BEFORE
641 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
642 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
644 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
650 // Convert driver from Dependent to Scheduled state
652 CoreAcquireDispatcherLock ();
654 InsertedDriverEntry
->Dependent
= FALSE
;
655 InsertedDriverEntry
->Scheduled
= TRUE
;
656 InsertTailList (&mScheduledQueue
, &InsertedDriverEntry
->ScheduledLink
);
658 CoreReleaseDispatcherLock ();
661 // Process After Dependency
663 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
664 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
665 if (DriverEntry
->After
&& DriverEntry
->Dependent
&& DriverEntry
!= InsertedDriverEntry
) {
666 DEBUG ((DEBUG_DISPATCH
, "Evaluate DXE DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
667 DEBUG ((DEBUG_DISPATCH
, " AFTER FFS(%g) = ", &DriverEntry
->BeforeAfterGuid
));
668 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
670 // Recursively process AFTER
672 DEBUG ((DEBUG_DISPATCH
, "TRUE\n END\n RESULT = TRUE\n"));
673 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
675 DEBUG ((DEBUG_DISPATCH
, "FALSE\n END\n RESULT = FALSE\n"));
683 Return TRUE if the Fv has been processed, FALSE if not.
685 @param FvHandle The handle of a FV that's being tested
687 @retval TRUE Fv protocol on FvHandle has been processed
688 @retval FALSE Fv protocol on FvHandle has not yet been processed
693 IN EFI_HANDLE FvHandle
697 KNOWN_HANDLE
*KnownHandle
;
699 for (Link
= mFvHandleList
.ForwardLink
; Link
!= &mFvHandleList
; Link
= Link
->ForwardLink
) {
700 KnownHandle
= CR(Link
, KNOWN_HANDLE
, Link
, KNOWN_HANDLE_SIGNATURE
);
701 if (KnownHandle
->Handle
== FvHandle
) {
710 Remember that Fv protocol on FvHandle has had it's drivers placed on the
711 mDiscoveredList. This fucntion adds entries on the mFvHandleList. Items are
712 never removed/freed from the mFvHandleList.
714 @param FvHandle The handle of a FV that has been processed
718 FvIsBeingProcesssed (
719 IN EFI_HANDLE FvHandle
722 KNOWN_HANDLE
*KnownHandle
;
724 KnownHandle
= AllocatePool (sizeof (KNOWN_HANDLE
));
725 ASSERT (KnownHandle
!= NULL
);
727 KnownHandle
->Signature
= KNOWN_HANDLE_SIGNATURE
;
728 KnownHandle
->Handle
= FvHandle
;
729 InsertTailList (&mFvHandleList
, &KnownHandle
->Link
);
736 Convert FvHandle and DriverName into an EFI device path
738 @param Fv Fv protocol, needed to read Depex info out of
740 @param FvHandle Handle for Fv, needed in the
741 EFI_CORE_DRIVER_ENTRY so that the PE image can be
742 read out of the FV at a later time.
743 @param DriverName Name of driver to add to mDiscoveredList.
745 @return Pointer to device path constructed from FvHandle and DriverName
748 EFI_DEVICE_PATH_PROTOCOL
*
750 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
751 IN EFI_HANDLE FvHandle
,
752 IN EFI_GUID
*DriverName
756 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
757 EFI_DEVICE_PATH_PROTOCOL
*FileNameDevicePath
;
760 // Remember the device path of the FV
762 Status
= CoreHandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
763 if (EFI_ERROR (Status
)) {
764 FileNameDevicePath
= NULL
;
767 // Build a device path to the file in the FV to pass into gBS->LoadImage
769 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, DriverName
);
770 SetDevicePathEndNode (&mFvDevicePath
.End
);
772 FileNameDevicePath
= AppendDevicePath (
774 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
778 return FileNameDevicePath
;
784 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
785 and initilize any state variables. Read the Depex from the FV and store it
786 in DriverEntry. Pre-process the Depex to set the SOR, Before and After state.
787 The Discovered list is never free'ed and contains booleans that represent the
788 other possible DXE driver states.
790 @param Fv Fv protocol, needed to read Depex info out of
792 @param FvHandle Handle for Fv, needed in the
793 EFI_CORE_DRIVER_ENTRY so that the PE image can be
794 read out of the FV at a later time.
795 @param DriverName Name of driver to add to mDiscoveredList.
796 @param Type Fv File Type of file to add to mDiscoveredList.
798 @retval EFI_SUCCESS If driver was added to the mDiscoveredList.
799 @retval EFI_ALREADY_STARTED The driver has already been started. Only one
800 DriverName may be active in the system at any one
805 CoreAddToDriverList (
806 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
807 IN EFI_HANDLE FvHandle
,
808 IN EFI_GUID
*DriverName
,
809 IN EFI_FV_FILETYPE Type
812 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
816 // Create the Driver Entry for the list. ZeroPool initializes lots of variables to
819 DriverEntry
= AllocateZeroPool (sizeof (EFI_CORE_DRIVER_ENTRY
));
820 ASSERT (DriverEntry
!= NULL
);
821 if (Type
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
822 DriverEntry
->IsFvImage
= TRUE
;
825 DriverEntry
->Signature
= EFI_CORE_DRIVER_ENTRY_SIGNATURE
;
826 CopyGuid (&DriverEntry
->FileName
, DriverName
);
827 DriverEntry
->FvHandle
= FvHandle
;
828 DriverEntry
->Fv
= Fv
;
829 DriverEntry
->FvFileDevicePath
= CoreFvToDevicePath (Fv
, FvHandle
, DriverName
);
831 CoreGetDepexSectionAndPreProccess (DriverEntry
);
833 CoreAcquireDispatcherLock ();
835 InsertTailList (&mDiscoveredList
, &DriverEntry
->Link
);
837 CoreReleaseDispatcherLock ();
844 Check if a FV Image type file (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) is
845 described by a EFI_HOB_FIRMWARE_VOLUME2 Hob.
847 @param FvHandle The handle which FVB protocol installed on.
848 @param DriverName The driver guid specified.
850 @retval TRUE This file is found in a EFI_HOB_FIRMWARE_VOLUME2
852 @retval FALSE Not found.
857 IN EFI_HANDLE FvHandle
,
858 IN CONST EFI_GUID
*DriverName
861 EFI_PEI_HOB_POINTERS HobFv2
;
863 HobFv2
.Raw
= GetHobList ();
865 while ((HobFv2
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobFv2
.Raw
)) != NULL
) {
866 if (CompareGuid (DriverName
, &HobFv2
.FirmwareVolume2
->FileName
)) {
869 HobFv2
.Raw
= GET_NEXT_HOB (HobFv2
);
878 Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.
880 @param Fv The FIRMWARE_VOLUME protocol installed on the FV.
881 @param FvHandle The handle which FVB protocol installed on.
882 @param DriverName The driver guid specified.
884 @retval EFI_OUT_OF_RESOURCES No enough memory or other resource.
885 @retval EFI_VOLUME_CORRUPTED Corrupted volume.
886 @retval EFI_SUCCESS Function successfully returned.
890 CoreProcessFvImageFile (
891 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
892 IN EFI_HANDLE FvHandle
,
893 IN EFI_GUID
*DriverName
897 EFI_SECTION_TYPE SectionType
;
898 UINT32 AuthenticationStatus
;
902 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
906 // Read the first (and only the first) firmware volume section
908 SectionType
= EFI_SECTION_FIRMWARE_VOLUME_IMAGE
;
913 AlignedBuffer
= NULL
;
914 Status
= Fv
->ReadSection (
921 &AuthenticationStatus
923 if (!EFI_ERROR (Status
)) {
925 // FvImage should be at its required alignment.
927 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) Buffer
;
929 // Get FvHeader alignment
931 FvAlignment
= 1 << ((FvHeader
->Attributes
& EFI_FVB2_ALIGNMENT
) >> 16);
933 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
935 if (FvAlignment
< 8) {
939 // Allocate the aligned buffer for the FvImage.
941 AlignedBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize
), (UINTN
) FvAlignment
);
942 if (AlignedBuffer
== NULL
) {
943 Status
= EFI_OUT_OF_RESOURCES
;
946 // Move FvImage into the aligned buffer and release the original buffer.
948 CopyMem (AlignedBuffer
, Buffer
, BufferSize
);
949 CoreFreePool (Buffer
);
952 // Produce a FVB protocol for the file
954 Status
= ProduceFVBProtocolOnBuffer (
955 (EFI_PHYSICAL_ADDRESS
) (UINTN
) AlignedBuffer
,
963 if (EFI_ERROR (Status
)) {
965 // ReadSection or Produce FVB failed, Free data buffer
967 if (Buffer
!= NULL
) {
971 if (AlignedBuffer
!= NULL
) {
972 FreeAlignedPages (AlignedBuffer
, EFI_SIZE_TO_PAGES (BufferSize
));
981 Event notification that is fired every time a FV dispatch protocol is added.
982 More than one protocol may have been added when this event is fired, so you
983 must loop on CoreLocateHandle () to see how many protocols were added and
984 do the following to each FV:
985 If the Fv has already been processed, skip it. If the Fv has not been
986 processed then mark it as being processed, as we are about to process it.
987 Read the Fv and add any driver in the Fv to the mDiscoveredList.The
988 mDiscoveredList is never free'ed and contains variables that define
989 the other states the DXE driver transitions to..
990 While you are at it read the A Priori file into memory.
991 Place drivers in the A Priori list onto the mScheduledQueue.
993 @param Event The Event that is being processed, not used.
994 @param Context Event Context, not used.
999 CoreFwVolEventProtocolNotify (
1005 EFI_STATUS GetNextFileStatus
;
1006 EFI_STATUS SecurityStatus
;
1007 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
1008 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
1009 EFI_HANDLE FvHandle
;
1013 EFI_FV_FILETYPE Type
;
1014 EFI_FV_FILE_ATTRIBUTES Attributes
;
1016 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
1017 EFI_GUID
*AprioriFile
;
1018 UINTN AprioriEntryCount
;
1021 UINT32 AuthenticationStatus
;
1026 BufferSize
= sizeof (EFI_HANDLE
);
1027 Status
= CoreLocateHandle (
1030 mFwVolEventRegistration
,
1034 if (EFI_ERROR (Status
)) {
1036 // If no more notification events exit
1041 if (FvHasBeenProcessed (FvHandle
)) {
1043 // This Fv has already been processed so lets skip it!
1049 // Since we are about to process this Fv mark it as processed.
1051 FvIsBeingProcesssed (FvHandle
);
1053 Status
= CoreHandleProtocol (FvHandle
, &gEfiFirmwareVolume2ProtocolGuid
, (VOID
**)&Fv
);
1054 if (EFI_ERROR (Status
) || Fv
== NULL
) {
1056 // FvHandle must have Firmware Volume2 protocol thus we should never get here.
1062 Status
= CoreHandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
1063 if (EFI_ERROR (Status
)) {
1065 // The Firmware volume doesn't have device path, can't be dispatched.
1071 // Evaluate the authentication status of the Firmware Volume through
1072 // Security Architectural Protocol
1074 if (gSecurity
!= NULL
) {
1075 SecurityStatus
= gSecurity
->FileAuthenticationState (
1080 if (SecurityStatus
!= EFI_SUCCESS
) {
1082 // Security check failed. The firmware volume should not be used for any purpose.
1089 // Discover Drivers in FV and add them to the Discovered Driver List.
1090 // Process EFI_FV_FILETYPE_DRIVER type and then EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
1091 // EFI_FV_FILETYPE_DXE_CORE is processed to produce a Loaded Image protocol for the core
1092 // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE is processed to create a Fvb
1094 for (Index
= 0; Index
< sizeof (mDxeFileTypes
) / sizeof (EFI_FV_FILETYPE
); Index
++) {
1096 // Initialize the search key
1100 Type
= mDxeFileTypes
[Index
];
1101 GetNextFileStatus
= Fv
->GetNextFile (
1109 if (!EFI_ERROR (GetNextFileStatus
)) {
1110 if (Type
== EFI_FV_FILETYPE_DXE_CORE
) {
1112 // If this is the DXE core fill in it's DevicePath & DeviceHandle
1114 if (gDxeCoreLoadedImage
->FilePath
== NULL
) {
1115 if (CompareGuid (&NameGuid
, gDxeCoreFileName
)) {
1117 // Maybe One specail Fv cantains only one DXE_CORE module, so its device path must
1118 // be initialized completely.
1120 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, &NameGuid
);
1121 SetDevicePathEndNode (&mFvDevicePath
.End
);
1123 gDxeCoreLoadedImage
->FilePath
= DuplicateDevicePath (
1124 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
1126 gDxeCoreLoadedImage
->DeviceHandle
= FvHandle
;
1129 } else if (Type
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
1131 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
1134 if (FvFoundInHobFv2 (FvHandle
, &NameGuid
)) {
1139 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has PEI depex section.
1143 Status
= Fv
->ReadSection (
1146 EFI_SECTION_PEI_DEPEX
,
1150 &AuthenticationStatus
1152 if (!EFI_ERROR (Status
)) {
1154 // If PEI depex section is found, this FV image will be ignored in DXE phase.
1155 // Now, DxeCore doesn't support FV image with more one type DEPEX section.
1157 FreePool (DepexBuffer
);
1162 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has SMM depex section.
1166 Status
= Fv
->ReadSection (
1169 EFI_SECTION_SMM_DEPEX
,
1173 &AuthenticationStatus
1175 if (!EFI_ERROR (Status
)) {
1177 // If SMM depex section is found, this FV image will be ignored in DXE phase.
1178 // Now, DxeCore doesn't support FV image with more one type DEPEX section.
1180 FreePool (DepexBuffer
);
1185 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has DXE depex section.
1189 Status
= Fv
->ReadSection (
1192 EFI_SECTION_DXE_DEPEX
,
1196 &AuthenticationStatus
1198 if (EFI_ERROR (Status
)) {
1200 // If no depex section, produce a firmware volume block protocol for it so it gets dispatched from.
1202 CoreProcessFvImageFile (Fv
, FvHandle
, &NameGuid
);
1205 // If depex section is found, this FV image will be dispatched until its depex is evaluated to TRUE.
1207 FreePool (DepexBuffer
);
1208 CoreAddToDriverList (Fv
, FvHandle
, &NameGuid
, Type
);
1212 // Transition driver from Undiscovered to Discovered state
1214 CoreAddToDriverList (Fv
, FvHandle
, &NameGuid
, Type
);
1217 } while (!EFI_ERROR (GetNextFileStatus
));
1221 // Read the array of GUIDs from the Apriori file if it is present in the firmware volume
1224 Status
= Fv
->ReadSection (
1229 (VOID
**)&AprioriFile
,
1231 &AuthenticationStatus
1233 if (!EFI_ERROR (Status
)) {
1234 AprioriEntryCount
= SizeOfBuffer
/ sizeof (EFI_GUID
);
1236 AprioriEntryCount
= 0;
1240 // Put drivers on Apriori List on the Scheduled queue. The Discovered List includes
1241 // drivers not in the current FV and these must be skipped since the a priori list
1242 // is only valid for the FV that it resided in.
1245 for (Index
= 0; Index
< AprioriEntryCount
; Index
++) {
1246 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
1247 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
1248 if (CompareGuid (&DriverEntry
->FileName
, &AprioriFile
[Index
]) &&
1249 (FvHandle
== DriverEntry
->FvHandle
)) {
1250 CoreAcquireDispatcherLock ();
1251 DriverEntry
->Dependent
= FALSE
;
1252 DriverEntry
->Scheduled
= TRUE
;
1253 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
1254 CoreReleaseDispatcherLock ();
1255 DEBUG ((DEBUG_DISPATCH
, "Evaluate DXE DEPEX for FFS(%g)\n", &DriverEntry
->FileName
));
1256 DEBUG ((DEBUG_DISPATCH
, " RESULT = TRUE (Apriori)\n"));
1263 // Free data allocated by Fv->ReadSection ()
1265 CoreFreePool (AprioriFile
);
1272 Initialize the dispatcher. Initialize the notification function that runs when
1273 an FV2 protocol is added to the system.
1277 CoreInitializeDispatcher (
1281 mFwVolEvent
= EfiCreateProtocolNotifyEvent (
1282 &gEfiFirmwareVolume2ProtocolGuid
,
1284 CoreFwVolEventProtocolNotify
,
1286 &mFwVolEventRegistration
1291 // Function only used in debug builds
1295 Traverse the discovered list for any drivers that were discovered but not loaded
1296 because the dependency experessions evaluated to false.
1300 CoreDisplayDiscoveredNotDispatched (
1305 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
1307 for (Link
= mDiscoveredList
.ForwardLink
;Link
!=&mDiscoveredList
; Link
= Link
->ForwardLink
) {
1308 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
1309 if (DriverEntry
->Dependent
) {
1310 DEBUG ((DEBUG_LOAD
, "Driver %g was discovered but not loaded!!\n", &DriverEntry
->FileName
));