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. <BR>
30 All rights reserved. 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 ();
339 return EFI_NOT_FOUND
;
345 Convert a driver from the Untrused back to the Scheduled state.
347 @param FirmwareVolumeHandle The handle of the Firmware Volume that contains
348 the firmware file specified by DriverName.
349 @param DriverName The Driver name to put in the Scheduled state
351 @retval EFI_SUCCESS The file was found in the untrusted state, and it
352 was promoted to the trusted state.
353 @retval EFI_NOT_FOUND The file was not found in the untrusted state.
359 IN EFI_HANDLE FirmwareVolumeHandle
,
360 IN EFI_GUID
*DriverName
364 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
367 // Check every driver
369 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
370 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
371 if (DriverEntry
->FvHandle
== FirmwareVolumeHandle
&&
372 DriverEntry
->Untrusted
&&
373 CompareGuid (DriverName
, &DriverEntry
->FileName
)) {
375 // Transition driver from Untrusted to Scheduled state.
377 CoreAcquireDispatcherLock ();
378 DriverEntry
->Untrusted
= FALSE
;
379 DriverEntry
->Scheduled
= TRUE
;
380 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
381 CoreReleaseDispatcherLock ();
386 return EFI_NOT_FOUND
;
391 An empty function to pass error checking of CreateEventEx ().
393 @param Event Event whose notification function is being invoked.
394 @param Context Pointer to the notification function's context,
395 which is implementation-dependent.
409 This is the main Dispatcher for DXE and it exits when there are no more
410 drivers to run. Drain the mScheduledQueue and load and start a PE
411 image for each driver. Search the mDiscoveredList to see if any driver can
412 be placed on the mScheduledQueue. If no drivers are placed on the
413 mScheduledQueue exit the function. On exit it is assumed the Bds()
414 will be called, and when the Bds() exits the Dispatcher will be called
417 @retval EFI_ALREADY_STARTED The DXE Dispatcher is already running
418 @retval EFI_NOT_FOUND No DXE Drivers were dispatched
419 @retval EFI_SUCCESS One or more DXE Drivers were dispatched
429 EFI_STATUS ReturnStatus
;
431 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
433 EFI_EVENT DxeDispatchEvent
;
436 if (gDispatcherRunning
) {
438 // If the dispatcher is running don't let it be restarted.
440 return EFI_ALREADY_STARTED
;
443 gDispatcherRunning
= TRUE
;
445 Status
= CoreCreateEventEx (
450 &gEfiEventDxeDispatchGuid
,
453 if (EFI_ERROR (Status
)) {
457 ReturnStatus
= EFI_NOT_FOUND
;
460 // Drain the Scheduled Queue
462 while (!IsListEmpty (&mScheduledQueue
)) {
464 mScheduledQueue
.ForwardLink
,
465 EFI_CORE_DRIVER_ENTRY
,
467 EFI_CORE_DRIVER_ENTRY_SIGNATURE
471 // Load the DXE Driver image into memory. If the Driver was transitioned from
472 // Untrused to Scheduled it would have already been loaded so we may need to
473 // skip the LoadImage
475 if (DriverEntry
->ImageHandle
== NULL
) {
476 DEBUG ((DEBUG_INFO
, "Loading driver %g\n", &DriverEntry
->FileName
));
477 Status
= CoreLoadImage (
480 DriverEntry
->FvFileDevicePath
,
483 &DriverEntry
->ImageHandle
487 // Update the driver state to reflect that it's been loaded
489 if (EFI_ERROR (Status
)) {
490 CoreAcquireDispatcherLock ();
492 if (Status
== EFI_SECURITY_VIOLATION
) {
494 // Take driver from Scheduled to Untrused state
496 DriverEntry
->Untrusted
= TRUE
;
499 // The DXE Driver could not be loaded, and do not attempt to load or start it again.
500 // Take driver from Scheduled to Initialized.
502 // This case include the Never Trusted state if EFI_ACCESS_DENIED is returned
504 DriverEntry
->Initialized
= TRUE
;
507 DriverEntry
->Scheduled
= FALSE
;
508 RemoveEntryList (&DriverEntry
->ScheduledLink
);
510 CoreReleaseDispatcherLock ();
513 // If it's an error don't try the StartImage
519 CoreAcquireDispatcherLock ();
521 DriverEntry
->Scheduled
= FALSE
;
522 DriverEntry
->Initialized
= TRUE
;
523 RemoveEntryList (&DriverEntry
->ScheduledLink
);
525 CoreReleaseDispatcherLock ();
528 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
530 (EFI_SOFTWARE_DXE_CORE
| EFI_SW_PC_INIT_BEGIN
),
531 &DriverEntry
->ImageHandle
,
532 sizeof (DriverEntry
->ImageHandle
)
535 Status
= CoreStartImage (DriverEntry
->ImageHandle
, NULL
, NULL
);
537 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
539 (EFI_SOFTWARE_DXE_CORE
| EFI_SW_PC_INIT_END
),
540 &DriverEntry
->ImageHandle
,
541 sizeof (DriverEntry
->ImageHandle
)
544 ReturnStatus
= EFI_SUCCESS
;
548 // Search DriverList for items to place on Scheduled Queue
551 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
552 DriverEntry
= CR (Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
554 if (DriverEntry
->DepexProtocolError
){
556 // If Section Extraction Protocol did not let the Depex be read before retry the read
558 Status
= CoreGetDepexSectionAndPreProccess (DriverEntry
);
561 if (DriverEntry
->Dependent
) {
562 if (CoreIsSchedulable (DriverEntry
)) {
563 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
570 // Now DXE Dispatcher finished one round of dispatch, signal an event group
571 // so that SMM Dispatcher get chance to dispatch SMM Drivers which depend
574 if (!EFI_ERROR (ReturnStatus
)) {
575 CoreSignalEvent (DxeDispatchEvent
);
577 } while (ReadyToRun
);
580 // Close DXE dispatch Event
582 CoreCloseEvent (DxeDispatchEvent
);
584 gDispatcherRunning
= FALSE
;
591 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
592 must add any driver with a before dependency on InsertedDriverEntry first.
593 You do this by recursively calling this routine. After all the Befores are
594 processed you can add InsertedDriverEntry to the mScheduledQueue.
595 Then you can add any driver with an After dependency on InsertedDriverEntry
596 by recursively calling this routine.
598 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
602 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
603 IN EFI_CORE_DRIVER_ENTRY
*InsertedDriverEntry
607 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
610 // Process Before Dependency
612 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
613 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
614 if (DriverEntry
->Before
&& DriverEntry
->Dependent
) {
615 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
617 // Recursively process BEFORE
619 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
625 // Convert driver from Dependent to Scheduled state
627 CoreAcquireDispatcherLock ();
629 InsertedDriverEntry
->Dependent
= FALSE
;
630 InsertedDriverEntry
->Scheduled
= TRUE
;
631 InsertTailList (&mScheduledQueue
, &InsertedDriverEntry
->ScheduledLink
);
633 CoreReleaseDispatcherLock ();
636 // Process After Dependency
638 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
639 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
640 if (DriverEntry
->After
&& DriverEntry
->Dependent
) {
641 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
643 // Recursively process AFTER
645 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
653 Return TRUE if the Fv has been processed, FALSE if not.
655 @param FvHandle The handle of a FV that's being tested
657 @retval TRUE Fv protocol on FvHandle has been processed
658 @retval FALSE Fv protocol on FvHandle has not yet been processed
663 IN EFI_HANDLE FvHandle
667 KNOWN_HANDLE
*KnownHandle
;
669 for (Link
= mFvHandleList
.ForwardLink
; Link
!= &mFvHandleList
; Link
= Link
->ForwardLink
) {
670 KnownHandle
= CR(Link
, KNOWN_HANDLE
, Link
, KNOWN_HANDLE_SIGNATURE
);
671 if (KnownHandle
->Handle
== FvHandle
) {
680 Remember that Fv protocol on FvHandle has had it's drivers placed on the
681 mDiscoveredList. This fucntion adds entries on the mFvHandleList. Items are
682 never removed/freed from the mFvHandleList.
684 @param FvHandle The handle of a FV that has been processed
688 FvIsBeingProcesssed (
689 IN EFI_HANDLE FvHandle
692 KNOWN_HANDLE
*KnownHandle
;
694 KnownHandle
= AllocatePool (sizeof (KNOWN_HANDLE
));
695 ASSERT (KnownHandle
!= NULL
);
697 KnownHandle
->Signature
= KNOWN_HANDLE_SIGNATURE
;
698 KnownHandle
->Handle
= FvHandle
;
699 InsertTailList (&mFvHandleList
, &KnownHandle
->Link
);
706 Convert FvHandle and DriverName into an EFI device path
708 @param Fv Fv protocol, needed to read Depex info out of
710 @param FvHandle Handle for Fv, needed in the
711 EFI_CORE_DRIVER_ENTRY so that the PE image can be
712 read out of the FV at a later time.
713 @param DriverName Name of driver to add to mDiscoveredList.
715 @return Pointer to device path constructed from FvHandle and DriverName
718 EFI_DEVICE_PATH_PROTOCOL
*
720 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
721 IN EFI_HANDLE FvHandle
,
722 IN EFI_GUID
*DriverName
726 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
727 EFI_DEVICE_PATH_PROTOCOL
*FileNameDevicePath
;
730 // Remember the device path of the FV
732 Status
= CoreHandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
733 if (EFI_ERROR (Status
)) {
734 FileNameDevicePath
= NULL
;
737 // Build a device path to the file in the FV to pass into gBS->LoadImage
739 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, DriverName
);
740 SetDevicePathEndNode (&mFvDevicePath
.End
);
742 FileNameDevicePath
= AppendDevicePath (
744 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
748 return FileNameDevicePath
;
754 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
755 and initilize any state variables. Read the Depex from the FV and store it
756 in DriverEntry. Pre-process the Depex to set the SOR, Before and After state.
757 The Discovered list is never free'ed and contains booleans that represent the
758 other possible DXE driver states.
760 @param Fv Fv protocol, needed to read Depex info out of
762 @param FvHandle Handle for Fv, needed in the
763 EFI_CORE_DRIVER_ENTRY so that the PE image can be
764 read out of the FV at a later time.
765 @param DriverName Name of driver to add to mDiscoveredList.
767 @retval EFI_SUCCESS If driver was added to the mDiscoveredList.
768 @retval EFI_ALREADY_STARTED The driver has already been started. Only one
769 DriverName may be active in the system at any one
774 CoreAddToDriverList (
775 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
776 IN EFI_HANDLE FvHandle
,
777 IN EFI_GUID
*DriverName
780 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
784 // Create the Driver Entry for the list. ZeroPool initializes lots of variables to
787 DriverEntry
= AllocateZeroPool (sizeof (EFI_CORE_DRIVER_ENTRY
));
788 ASSERT (DriverEntry
!= NULL
);
790 DriverEntry
->Signature
= EFI_CORE_DRIVER_ENTRY_SIGNATURE
;
791 CopyGuid (&DriverEntry
->FileName
, DriverName
);
792 DriverEntry
->FvHandle
= FvHandle
;
793 DriverEntry
->Fv
= Fv
;
794 DriverEntry
->FvFileDevicePath
= CoreFvToDevicePath (Fv
, FvHandle
, DriverName
);
796 CoreGetDepexSectionAndPreProccess (DriverEntry
);
798 CoreAcquireDispatcherLock ();
800 InsertTailList (&mDiscoveredList
, &DriverEntry
->Link
);
802 CoreReleaseDispatcherLock ();
809 Check if a FV Image type file (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) is
810 described by a EFI_HOB_FIRMWARE_VOLUME2 Hob.
812 @param FvHandle The handle which FVB protocol installed on.
813 @param DriverName The driver guid specified.
815 @retval TRUE This file is found in a EFI_HOB_FIRMWARE_VOLUME2
817 @retval FALSE Not found.
822 IN EFI_HANDLE FvHandle
,
823 IN CONST EFI_GUID
*DriverName
826 EFI_PEI_HOB_POINTERS HobFv2
;
828 HobFv2
.Raw
= GetHobList ();
830 while ((HobFv2
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobFv2
.Raw
)) != NULL
) {
831 if (CompareGuid (DriverName
, &HobFv2
.FirmwareVolume2
->FileName
)) {
834 HobFv2
.Raw
= GET_NEXT_HOB (HobFv2
);
843 Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.
845 @param Fv The FIRMWARE_VOLUME protocol installed on the FV.
846 @param FvHandle The handle which FVB protocol installed on.
847 @param DriverName The driver guid specified.
849 @retval EFI_OUT_OF_RESOURCES No enough memory or other resource.
850 @retval EFI_VOLUME_CORRUPTED Corrupted volume.
851 @retval EFI_SUCCESS Function successfully returned.
855 CoreProcessFvImageFile (
856 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
857 IN EFI_HANDLE FvHandle
,
858 IN EFI_GUID
*DriverName
862 EFI_SECTION_TYPE SectionType
;
863 UINT32 AuthenticationStatus
;
867 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
871 // Read the first (and only the first) firmware volume section
873 SectionType
= EFI_SECTION_FIRMWARE_VOLUME_IMAGE
;
878 AlignedBuffer
= NULL
;
879 Status
= Fv
->ReadSection (
886 &AuthenticationStatus
888 if (!EFI_ERROR (Status
)) {
890 // FvImage should be at its required alignment.
892 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) Buffer
;
894 // Get FvHeader alignment
896 FvAlignment
= 1 << ((FvHeader
->Attributes
& EFI_FVB2_ALIGNMENT
) >> 16);
898 // FvAlignment must be greater than or equal to 8 bytes of the minimum FFS alignment value.
900 if (FvAlignment
< 8) {
904 // Allocate the aligned buffer for the FvImage.
906 AlignedBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize
), (UINTN
) FvAlignment
);
907 if (AlignedBuffer
== NULL
) {
908 Status
= EFI_OUT_OF_RESOURCES
;
911 // Move FvImage into the aligned buffer and release the original buffer.
913 CopyMem (AlignedBuffer
, Buffer
, BufferSize
);
914 CoreFreePool (Buffer
);
917 // Produce a FVB protocol for the file
919 Status
= ProduceFVBProtocolOnBuffer (
920 (EFI_PHYSICAL_ADDRESS
) (UINTN
) AlignedBuffer
,
928 if (EFI_ERROR (Status
)) {
930 // ReadSection or Produce FVB failed, Free data buffer
932 if (Buffer
!= NULL
) {
936 if (AlignedBuffer
!= NULL
) {
937 FreeAlignedPages (AlignedBuffer
, EFI_SIZE_TO_PAGES (BufferSize
));
946 Event notification that is fired every time a FV dispatch protocol is added.
947 More than one protocol may have been added when this event is fired, so you
948 must loop on CoreLocateHandle () to see how many protocols were added and
949 do the following to each FV:
950 If the Fv has already been processed, skip it. If the Fv has not been
951 processed then mark it as being processed, as we are about to process it.
952 Read the Fv and add any driver in the Fv to the mDiscoveredList.The
953 mDiscoveredList is never free'ed and contains variables that define
954 the other states the DXE driver transitions to..
955 While you are at it read the A Priori file into memory.
956 Place drivers in the A Priori list onto the mScheduledQueue.
958 @param Event The Event that is being processed, not used.
959 @param Context Event Context, not used.
964 CoreFwVolEventProtocolNotify (
970 EFI_STATUS GetNextFileStatus
;
971 EFI_STATUS SecurityStatus
;
972 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
973 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
978 EFI_FV_FILETYPE Type
;
979 EFI_FV_FILE_ATTRIBUTES Attributes
;
981 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
982 EFI_GUID
*AprioriFile
;
983 UINTN AprioriEntryCount
;
986 UINT32 AuthenticationStatus
;
991 BufferSize
= sizeof (EFI_HANDLE
);
992 Status
= CoreLocateHandle (
995 mFwVolEventRegistration
,
999 if (EFI_ERROR (Status
)) {
1001 // If no more notification events exit
1006 if (FvHasBeenProcessed (FvHandle
)) {
1008 // This Fv has already been processed so lets skip it!
1014 // Since we are about to process this Fv mark it as processed.
1016 FvIsBeingProcesssed (FvHandle
);
1018 Status
= CoreHandleProtocol (FvHandle
, &gEfiFirmwareVolume2ProtocolGuid
, (VOID
**)&Fv
);
1019 if (EFI_ERROR (Status
)) {
1021 // FvHandle must have Firmware Volume2 protocol thus we should never get here.
1027 Status
= CoreHandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
1028 if (EFI_ERROR (Status
)) {
1030 // The Firmware volume doesn't have device path, can't be dispatched.
1036 // Evaluate the authentication status of the Firmware Volume through
1037 // Security Architectural Protocol
1039 if (gSecurity
!= NULL
) {
1040 SecurityStatus
= gSecurity
->FileAuthenticationState (
1045 if (SecurityStatus
!= EFI_SUCCESS
) {
1047 // Security check failed. The firmware volume should not be used for any purpose.
1054 // Discover Drivers in FV and add them to the Discovered Driver List.
1055 // Process EFI_FV_FILETYPE_DRIVER type and then EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
1056 // EFI_FV_FILETYPE_DXE_CORE is processed to produce a Loaded Image protocol for the core
1057 // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE is processed to create a Fvb
1059 for (Index
= 0; Index
< sizeof (mDxeFileTypes
) / sizeof (EFI_FV_FILETYPE
); Index
++) {
1061 // Initialize the search key
1065 Type
= mDxeFileTypes
[Index
];
1066 GetNextFileStatus
= Fv
->GetNextFile (
1074 if (!EFI_ERROR (GetNextFileStatus
)) {
1075 if (Type
== EFI_FV_FILETYPE_DXE_CORE
) {
1077 // If this is the DXE core fill in it's DevicePath & DeviceHandle
1079 if (gDxeCoreLoadedImage
->FilePath
== NULL
) {
1080 if (CompareGuid (&NameGuid
, gDxeCoreFileName
)) {
1082 // Maybe One specail Fv cantains only one DXE_CORE module, so its device path must
1083 // be initialized completely.
1085 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, &NameGuid
);
1086 SetDevicePathEndNode (&mFvDevicePath
.End
);
1088 gDxeCoreLoadedImage
->FilePath
= DuplicateDevicePath (
1089 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
1091 gDxeCoreLoadedImage
->DeviceHandle
= FvHandle
;
1094 } else if (Type
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
1096 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
1099 if (FvFoundInHobFv2 (FvHandle
, &NameGuid
)) {
1103 // Found a firmware volume image. Produce a firmware volume block
1104 // protocol for it so it gets dispatched from. This is usually a
1107 CoreProcessFvImageFile (Fv
, FvHandle
, &NameGuid
);
1110 // Transition driver from Undiscovered to Discovered state
1112 CoreAddToDriverList (Fv
, FvHandle
, &NameGuid
);
1115 } while (!EFI_ERROR (GetNextFileStatus
));
1119 // Read the array of GUIDs from the Apriori file if it is present in the firmware volume
1122 Status
= Fv
->ReadSection (
1127 (VOID
**)&AprioriFile
,
1129 &AuthenticationStatus
1131 if (!EFI_ERROR (Status
)) {
1132 AprioriEntryCount
= SizeOfBuffer
/ sizeof (EFI_GUID
);
1134 AprioriEntryCount
= 0;
1138 // Put drivers on Apriori List on the Scheduled queue. The Discovered List includes
1139 // drivers not in the current FV and these must be skipped since the a priori list
1140 // is only valid for the FV that it resided in.
1142 CoreAcquireDispatcherLock ();
1144 for (Index
= 0; Index
< AprioriEntryCount
; Index
++) {
1145 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
1146 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
1147 if (CompareGuid (&DriverEntry
->FileName
, &AprioriFile
[Index
]) &&
1148 (FvHandle
== DriverEntry
->FvHandle
)) {
1149 DriverEntry
->Dependent
= FALSE
;
1150 DriverEntry
->Scheduled
= TRUE
;
1151 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
1157 CoreReleaseDispatcherLock ();
1160 // Free data allocated by Fv->ReadSection ()
1162 CoreFreePool (AprioriFile
);
1169 Initialize the dispatcher. Initialize the notification function that runs when
1170 an FV2 protocol is added to the system.
1174 CoreInitializeDispatcher (
1178 mFwVolEvent
= EfiCreateProtocolNotifyEvent (
1179 &gEfiFirmwareVolume2ProtocolGuid
,
1181 CoreFwVolEventProtocolNotify
,
1183 &mFwVolEventRegistration
1188 // Function only used in debug builds
1192 Traverse the discovered list for any drivers that were discovered but not loaded
1193 because the dependency experessions evaluated to false.
1197 CoreDisplayDiscoveredNotDispatched (
1202 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
1204 for (Link
= mDiscoveredList
.ForwardLink
;Link
!=&mDiscoveredList
; Link
= Link
->ForwardLink
) {
1205 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
1206 if (DriverEntry
->Dependent
) {
1207 DEBUG ((DEBUG_LOAD
, "Driver %g was discovered but not loaded!!\n", &DriverEntry
->FileName
));