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 - 2008, 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_PEIM_DRIVER
,
82 EFI_FV_FILETYPE_DXE_CORE
,
83 EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
87 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH File
;
88 EFI_DEVICE_PATH_PROTOCOL End
;
89 } FV_FILEPATH_DEVICE_PATH
;
91 FV_FILEPATH_DEVICE_PATH mFvDevicePath
;
95 // Function Prototypes
98 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
99 must add any driver with a before dependency on InsertedDriverEntry first.
100 You do this by recursively calling this routine. After all the Befores are
101 processed you can add InsertedDriverEntry to the mScheduledQueue.
102 Then you can add any driver with an After dependency on InsertedDriverEntry
103 by recursively calling this routine.
105 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
109 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
110 IN EFI_CORE_DRIVER_ENTRY
*InsertedDriverEntry
114 Event notification that is fired every time a FV dispatch protocol is added.
115 More than one protocol may have been added when this event is fired, so you
116 must loop on CoreLocateHandle () to see how many protocols were added and
117 do the following to each FV:
118 If the Fv has already been processed, skip it. If the Fv has not been
119 processed then mark it as being processed, as we are about to process it.
120 Read the Fv and add any driver in the Fv to the mDiscoveredList.The
121 mDiscoveredList is never free'ed and contains variables that define
122 the other states the DXE driver transitions to..
123 While you are at it read the A Priori file into memory.
124 Place drivers in the A Priori list onto the mScheduledQueue.
126 @param Event The Event that is being processed, not used.
127 @param Context Event Context, not used.
132 CoreFwVolEventProtocolNotify (
138 Convert FvHandle and DriverName into an EFI device path
140 @param Fv Fv protocol, needed to read Depex info out of
142 @param FvHandle Handle for Fv, needed in the
143 EFI_CORE_DRIVER_ENTRY so that the PE image can be
144 read out of the FV at a later time.
145 @param DriverName Name of driver to add to mDiscoveredList.
147 @return Pointer to device path constructed from FvHandle and DriverName
150 EFI_DEVICE_PATH_PROTOCOL
*
152 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
153 IN EFI_HANDLE FvHandle
,
154 IN EFI_GUID
*DriverName
158 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
159 and initilize any state variables. Read the Depex from the FV and store it
160 in DriverEntry. Pre-process the Depex to set the SOR, Before and After state.
161 The Discovered list is never free'ed and contains booleans that represent the
162 other possible DXE driver states.
164 @param Fv Fv protocol, needed to read Depex info out of
166 @param FvHandle Handle for Fv, needed in the
167 EFI_CORE_DRIVER_ENTRY so that the PE image can be
168 read out of the FV at a later time.
169 @param DriverName Name of driver to add to mDiscoveredList.
171 @retval EFI_SUCCESS If driver was added to the mDiscoveredList.
172 @retval EFI_ALREADY_STARTED The driver has already been started. Only one
173 DriverName may be active in the system at any one
178 CoreAddToDriverList (
179 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
180 IN EFI_HANDLE FvHandle
,
181 IN EFI_GUID
*DriverName
185 Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.
187 @param Fv The FIRMWARE_VOLUME protocol installed on the FV.
188 @param FvHandle The handle which FVB protocol installed on.
189 @param DriverName The driver guid specified.
191 @retval EFI_OUT_OF_RESOURCES No enough memory or other resource.
192 @retval EFI_VOLUME_CORRUPTED Corrupted volume.
193 @retval EFI_SUCCESS Function successfully returned.
197 CoreProcessFvImageFile (
198 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
199 IN EFI_HANDLE FvHandle
,
200 IN EFI_GUID
*DriverName
205 Enter critical section by gaining lock on mDispatcherLock.
209 CoreAcquireDispatcherLock (
213 CoreAcquireLock (&mDispatcherLock
);
218 Exit critical section by releasing lock on mDispatcherLock.
222 CoreReleaseDispatcherLock (
226 CoreReleaseLock (&mDispatcherLock
);
231 Read Depex and pre-process the Depex for Before and After. If Section Extraction
232 protocol returns an error via ReadSection defer the reading of the Depex.
234 @param DriverEntry Driver to work on.
236 @retval EFI_SUCCESS Depex read and preprossesed
237 @retval EFI_PROTOCOL_ERROR The section extraction protocol returned an error
238 and Depex reading needs to be retried.
239 @retval Error DEPEX not found.
243 CoreGetDepexSectionAndPreProccess (
244 IN EFI_CORE_DRIVER_ENTRY
*DriverEntry
248 EFI_SECTION_TYPE SectionType
;
249 UINT32 AuthenticationStatus
;
250 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
253 Fv
= DriverEntry
->Fv
;
256 // Grab Depex info, it will never be free'ed.
258 SectionType
= EFI_SECTION_DXE_DEPEX
;
259 Status
= Fv
->ReadSection (
261 &DriverEntry
->FileName
,
265 (UINTN
*)&DriverEntry
->DepexSize
,
266 &AuthenticationStatus
268 if (EFI_ERROR (Status
)) {
269 if (Status
== EFI_PROTOCOL_ERROR
) {
271 // The section extraction protocol failed so set protocol error flag
273 DriverEntry
->DepexProtocolError
= TRUE
;
276 // If no Depex assume UEFI 2.0 driver model
278 DriverEntry
->Depex
= NULL
;
279 DriverEntry
->Dependent
= TRUE
;
280 DriverEntry
->DepexProtocolError
= FALSE
;
284 // Set Before, After, and Unrequested state information based on Depex
285 // Driver will be put in Dependent or Unrequested state
287 CorePreProcessDepex (DriverEntry
);
288 DriverEntry
->DepexProtocolError
= FALSE
;
296 Check every driver and locate a matching one. If the driver is found, the Unrequested
297 state flag is cleared.
299 @param FirmwareVolumeHandle The handle of the Firmware Volume that contains
300 the firmware file specified by DriverName.
301 @param DriverName The Driver name to put in the Dependent state.
303 @retval EFI_SUCCESS The DriverName was found and it's SOR bit was
305 @retval EFI_NOT_FOUND The DriverName does not exist or it's SOR bit was
312 IN EFI_HANDLE FirmwareVolumeHandle
,
313 IN EFI_GUID
*DriverName
317 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
320 // Check every driver
322 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
323 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
324 if (DriverEntry
->FvHandle
== FirmwareVolumeHandle
&&
325 DriverEntry
->Unrequested
&&
326 CompareGuid (DriverName
, &DriverEntry
->FileName
)) {
328 // Move the driver from the Unrequested to the Dependent state
330 CoreAcquireDispatcherLock ();
331 DriverEntry
->Unrequested
= FALSE
;
332 DriverEntry
->Dependent
= TRUE
;
333 CoreReleaseDispatcherLock ();
338 return EFI_NOT_FOUND
;
344 Convert a driver from the Untrused back to the Scheduled state.
346 @param FirmwareVolumeHandle The handle of the Firmware Volume that contains
347 the firmware file specified by DriverName.
348 @param DriverName The Driver name to put in the Scheduled state
350 @retval EFI_SUCCESS The file was found in the untrusted state, and it
351 was promoted to the trusted state.
352 @retval EFI_NOT_FOUND The file was not found in the untrusted state.
358 IN EFI_HANDLE FirmwareVolumeHandle
,
359 IN EFI_GUID
*DriverName
363 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
366 // Check every driver
368 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
369 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
370 if (DriverEntry
->FvHandle
== FirmwareVolumeHandle
&&
371 DriverEntry
->Untrusted
&&
372 CompareGuid (DriverName
, &DriverEntry
->FileName
)) {
374 // Transition driver from Untrusted to Scheduled state.
376 CoreAcquireDispatcherLock ();
377 DriverEntry
->Untrusted
= FALSE
;
378 DriverEntry
->Scheduled
= TRUE
;
379 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
380 CoreReleaseDispatcherLock ();
385 return EFI_NOT_FOUND
;
391 This is the main Dispatcher for DXE and it exits when there are no more
392 drivers to run. Drain the mScheduledQueue and load and start a PE
393 image for each driver. Search the mDiscoveredList to see if any driver can
394 be placed on the mScheduledQueue. If no drivers are placed on the
395 mScheduledQueue exit the function. On exit it is assumed the Bds()
396 will be called, and when the Bds() exits the Dispatcher will be called
399 @retval EFI_ALREADY_STARTED The DXE Dispatcher is already running
400 @retval EFI_NOT_FOUND No DXE Drivers were dispatched
401 @retval EFI_SUCCESS One or more DXE Drivers were dispatched
411 EFI_STATUS ReturnStatus
;
413 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
416 if (gDispatcherRunning
) {
418 // If the dispatcher is running don't let it be restarted.
420 return EFI_ALREADY_STARTED
;
423 gDispatcherRunning
= TRUE
;
426 ReturnStatus
= EFI_NOT_FOUND
;
429 // Drain the Scheduled Queue
431 while (!IsListEmpty (&mScheduledQueue
)) {
433 mScheduledQueue
.ForwardLink
,
434 EFI_CORE_DRIVER_ENTRY
,
436 EFI_CORE_DRIVER_ENTRY_SIGNATURE
440 // Load the DXE Driver image into memory. If the Driver was transitioned from
441 // Untrused to Scheduled it would have already been loaded so we may need to
442 // skip the LoadImage
444 if (DriverEntry
->ImageHandle
== NULL
) {
445 Status
= CoreLoadImage (
448 DriverEntry
->FvFileDevicePath
,
451 &DriverEntry
->ImageHandle
455 // Update the driver state to reflect that it's been loaded
457 if (EFI_ERROR (Status
)) {
458 CoreAcquireDispatcherLock ();
460 if (Status
== EFI_SECURITY_VIOLATION
) {
462 // Take driver from Scheduled to Untrused state
464 DriverEntry
->Untrusted
= TRUE
;
467 // The DXE Driver could not be loaded, and do not attempt to load or start it again.
468 // Take driver from Scheduled to Initialized.
470 // This case include the Never Trusted state if EFI_ACCESS_DENIED is returned
472 DriverEntry
->Initialized
= TRUE
;
475 DriverEntry
->Scheduled
= FALSE
;
476 RemoveEntryList (&DriverEntry
->ScheduledLink
);
478 CoreReleaseDispatcherLock ();
481 // If it's an error don't try the StartImage
487 CoreAcquireDispatcherLock ();
489 DriverEntry
->Scheduled
= FALSE
;
490 DriverEntry
->Initialized
= TRUE
;
491 RemoveEntryList (&DriverEntry
->ScheduledLink
);
493 CoreReleaseDispatcherLock ();
496 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
498 FixedPcdGet32(PcdStatusCodeValueDxeDriverBegin
),
499 &DriverEntry
->ImageHandle
,
500 sizeof (DriverEntry
->ImageHandle
)
503 Status
= CoreStartImage (DriverEntry
->ImageHandle
, NULL
, NULL
);
505 REPORT_STATUS_CODE_WITH_EXTENDED_DATA (
507 FixedPcdGet32(PcdStatusCodeValueDxeDriverEnd
),
508 &DriverEntry
->ImageHandle
,
509 sizeof (DriverEntry
->ImageHandle
)
512 ReturnStatus
= EFI_SUCCESS
;
516 // Search DriverList for items to place on Scheduled Queue
519 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
520 DriverEntry
= CR (Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
522 if (DriverEntry
->DepexProtocolError
){
524 // If Section Extraction Protocol did not let the Depex be read before retry the read
526 Status
= CoreGetDepexSectionAndPreProccess (DriverEntry
);
529 if (DriverEntry
->Dependent
) {
530 if (CoreIsSchedulable (DriverEntry
)) {
531 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
536 } while (ReadyToRun
);
538 gDispatcherRunning
= FALSE
;
545 Insert InsertedDriverEntry onto the mScheduledQueue. To do this you
546 must add any driver with a before dependency on InsertedDriverEntry first.
547 You do this by recursively calling this routine. After all the Befores are
548 processed you can add InsertedDriverEntry to the mScheduledQueue.
549 Then you can add any driver with an After dependency on InsertedDriverEntry
550 by recursively calling this routine.
552 @param InsertedDriverEntry The driver to insert on the ScheduledLink Queue
556 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (
557 IN EFI_CORE_DRIVER_ENTRY
*InsertedDriverEntry
561 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
564 // Process Before Dependency
566 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
567 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
568 if (DriverEntry
->Before
&& DriverEntry
->Dependent
) {
569 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
571 // Recursively process BEFORE
573 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
579 // Convert driver from Dependent to Scheduled state
581 CoreAcquireDispatcherLock ();
583 InsertedDriverEntry
->Dependent
= FALSE
;
584 InsertedDriverEntry
->Scheduled
= TRUE
;
585 InsertTailList (&mScheduledQueue
, &InsertedDriverEntry
->ScheduledLink
);
587 CoreReleaseDispatcherLock ();
590 // Process After Dependency
592 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
593 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
594 if (DriverEntry
->After
&& DriverEntry
->Dependent
) {
595 if (CompareGuid (&InsertedDriverEntry
->FileName
, &DriverEntry
->BeforeAfterGuid
)) {
597 // Recursively process AFTER
599 CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (DriverEntry
);
607 Return TRUE if the Fv has been processed, FALSE if not.
609 @param FvHandle The handle of a FV that's being tested
611 @retval TRUE Fv protocol on FvHandle has been processed
612 @retval FALSE Fv protocol on FvHandle has not yet been processed
617 IN EFI_HANDLE FvHandle
621 KNOWN_HANDLE
*KnownHandle
;
623 for (Link
= mFvHandleList
.ForwardLink
; Link
!= &mFvHandleList
; Link
= Link
->ForwardLink
) {
624 KnownHandle
= CR(Link
, KNOWN_HANDLE
, Link
, KNOWN_HANDLE_SIGNATURE
);
625 if (KnownHandle
->Handle
== FvHandle
) {
634 Remember that Fv protocol on FvHandle has had it's drivers placed on the
635 mDiscoveredList. This fucntion adds entries on the mFvHandleList. Items are
636 never removed/freed from the mFvHandleList.
638 @param FvHandle The handle of a FV that has been processed
642 FvIsBeingProcesssed (
643 IN EFI_HANDLE FvHandle
646 KNOWN_HANDLE
*KnownHandle
;
648 KnownHandle
= AllocatePool (sizeof (KNOWN_HANDLE
));
649 ASSERT (KnownHandle
!= NULL
);
651 KnownHandle
->Signature
= KNOWN_HANDLE_SIGNATURE
;
652 KnownHandle
->Handle
= FvHandle
;
653 InsertTailList (&mFvHandleList
, &KnownHandle
->Link
);
660 Convert FvHandle and DriverName into an EFI device path
662 @param Fv Fv protocol, needed to read Depex info out of
664 @param FvHandle Handle for Fv, needed in the
665 EFI_CORE_DRIVER_ENTRY so that the PE image can be
666 read out of the FV at a later time.
667 @param DriverName Name of driver to add to mDiscoveredList.
669 @return Pointer to device path constructed from FvHandle and DriverName
672 EFI_DEVICE_PATH_PROTOCOL
*
674 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
675 IN EFI_HANDLE FvHandle
,
676 IN EFI_GUID
*DriverName
680 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
681 EFI_DEVICE_PATH_PROTOCOL
*FileNameDevicePath
;
684 // Remember the device path of the FV
686 Status
= CoreHandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
687 if (EFI_ERROR (Status
)) {
688 FileNameDevicePath
= NULL
;
691 // Build a device path to the file in the FV to pass into gBS->LoadImage
693 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, DriverName
);
694 mFvDevicePath
.End
.Type
= EFI_END_ENTIRE_DEVICE_PATH
;
695 mFvDevicePath
.End
.SubType
= END_ENTIRE_DEVICE_PATH_SUBTYPE
;
696 SetDevicePathNodeLength (&mFvDevicePath
.End
, sizeof (EFI_DEVICE_PATH_PROTOCOL
));
698 FileNameDevicePath
= AppendDevicePath (
700 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
704 return FileNameDevicePath
;
710 Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry,
711 and initilize any state variables. Read the Depex from the FV and store it
712 in DriverEntry. Pre-process the Depex to set the SOR, Before and After state.
713 The Discovered list is never free'ed and contains booleans that represent the
714 other possible DXE driver states.
716 @param Fv Fv protocol, needed to read Depex info out of
718 @param FvHandle Handle for Fv, needed in the
719 EFI_CORE_DRIVER_ENTRY so that the PE image can be
720 read out of the FV at a later time.
721 @param DriverName Name of driver to add to mDiscoveredList.
723 @retval EFI_SUCCESS If driver was added to the mDiscoveredList.
724 @retval EFI_ALREADY_STARTED The driver has already been started. Only one
725 DriverName may be active in the system at any one
730 CoreAddToDriverList (
731 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
732 IN EFI_HANDLE FvHandle
,
733 IN EFI_GUID
*DriverName
736 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
740 // Create the Driver Entry for the list. ZeroPool initializes lots of variables to
743 DriverEntry
= AllocateZeroPool (sizeof (EFI_CORE_DRIVER_ENTRY
));
744 ASSERT (DriverEntry
!= NULL
);
746 DriverEntry
->Signature
= EFI_CORE_DRIVER_ENTRY_SIGNATURE
;
747 CopyGuid (&DriverEntry
->FileName
, DriverName
);
748 DriverEntry
->FvHandle
= FvHandle
;
749 DriverEntry
->Fv
= Fv
;
750 DriverEntry
->FvFileDevicePath
= CoreFvToDevicePath (Fv
, FvHandle
, DriverName
);
752 CoreGetDepexSectionAndPreProccess (DriverEntry
);
754 CoreAcquireDispatcherLock ();
756 InsertTailList (&mDiscoveredList
, &DriverEntry
->Link
);
758 CoreReleaseDispatcherLock ();
765 Check if a FV Image type file (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) is
766 described by a EFI_HOB_FIRMWARE_VOLUME2 Hob.
768 @param FvHandle The handle which FVB protocol installed on.
769 @param DriverName The driver guid specified.
771 @retval TRUE This file is found in a EFI_HOB_FIRMWARE_VOLUME2
773 @retval FALSE Not found.
778 IN EFI_HANDLE FvHandle
,
779 IN CONST EFI_GUID
*DriverName
782 EFI_PEI_HOB_POINTERS HobFv2
;
784 HobFv2
.Raw
= GetHobList ();
786 while ((HobFv2
.Raw
= GetNextHob (EFI_HOB_TYPE_FV2
, HobFv2
.Raw
)) != NULL
) {
787 if (CompareGuid (DriverName
, &HobFv2
.FirmwareVolume2
->FileName
)) {
790 HobFv2
.Raw
= GET_NEXT_HOB (HobFv2
);
799 Get the driver from the FV through driver name, and produce a FVB protocol on FvHandle.
801 @param Fv The FIRMWARE_VOLUME protocol installed on the FV.
802 @param FvHandle The handle which FVB protocol installed on.
803 @param DriverName The driver guid specified.
805 @retval EFI_OUT_OF_RESOURCES No enough memory or other resource.
806 @retval EFI_VOLUME_CORRUPTED Corrupted volume.
807 @retval EFI_SUCCESS Function successfully returned.
811 CoreProcessFvImageFile (
812 IN EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
,
813 IN EFI_HANDLE FvHandle
,
814 IN EFI_GUID
*DriverName
818 EFI_SECTION_TYPE SectionType
;
819 UINT32 AuthenticationStatus
;
823 EFI_FIRMWARE_VOLUME_HEADER
*FvHeader
;
827 // Read the first (and only the first) firmware volume section
829 SectionType
= EFI_SECTION_FIRMWARE_VOLUME_IMAGE
;
834 AlignedBuffer
= NULL
;
835 Status
= Fv
->ReadSection (
842 &AuthenticationStatus
844 if (!EFI_ERROR (Status
)) {
846 // FvImage should be at its required alignment.
848 FvHeader
= (EFI_FIRMWARE_VOLUME_HEADER
*) Buffer
;
849 FvAlignment
= 1 << ((FvHeader
->Attributes
& EFI_FVB2_ALIGNMENT
) >> 16);
851 // FvAlignment must be more than 8 bytes required by FvHeader structure.
853 if (FvAlignment
< 8) {
857 // Allocate the aligned buffer for the FvImage.
859 AlignedBuffer
= AllocateAlignedPages (EFI_SIZE_TO_PAGES (BufferSize
), (UINTN
) FvAlignment
);
860 if (AlignedBuffer
== NULL
) {
861 Status
= EFI_OUT_OF_RESOURCES
;
864 // Move FvImage into the aligned buffer and release the original buffer.
866 CopyMem (AlignedBuffer
, Buffer
, BufferSize
);
867 CoreFreePool (Buffer
);
870 // Produce a FVB protocol for the file
872 Status
= ProduceFVBProtocolOnBuffer (
873 (EFI_PHYSICAL_ADDRESS
) (UINTN
) AlignedBuffer
,
881 if (EFI_ERROR (Status
)) {
883 // ReadSection or Produce FVB failed, Free data buffer
885 if (Buffer
!= NULL
) {
889 if (AlignedBuffer
!= NULL
) {
890 FreeAlignedPages (AlignedBuffer
, EFI_SIZE_TO_PAGES (BufferSize
));
899 Event notification that is fired every time a FV dispatch protocol is added.
900 More than one protocol may have been added when this event is fired, so you
901 must loop on CoreLocateHandle () to see how many protocols were added and
902 do the following to each FV:
903 If the Fv has already been processed, skip it. If the Fv has not been
904 processed then mark it as being processed, as we are about to process it.
905 Read the Fv and add any driver in the Fv to the mDiscoveredList.The
906 mDiscoveredList is never free'ed and contains variables that define
907 the other states the DXE driver transitions to..
908 While you are at it read the A Priori file into memory.
909 Place drivers in the A Priori list onto the mScheduledQueue.
911 @param Event The Event that is being processed, not used.
912 @param Context Event Context, not used.
917 CoreFwVolEventProtocolNotify (
923 EFI_STATUS GetNextFileStatus
;
924 EFI_STATUS SecurityStatus
;
925 EFI_FIRMWARE_VOLUME2_PROTOCOL
*Fv
;
926 EFI_DEVICE_PATH_PROTOCOL
*FvDevicePath
;
931 EFI_FV_FILETYPE Type
;
932 EFI_FV_FILE_ATTRIBUTES Attributes
;
934 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
935 EFI_GUID
*AprioriFile
;
936 UINTN AprioriEntryCount
;
939 UINT32 AuthenticationStatus
;
944 BufferSize
= sizeof (EFI_HANDLE
);
945 Status
= CoreLocateHandle (
948 mFwVolEventRegistration
,
952 if (EFI_ERROR (Status
)) {
954 // If no more notification events exit
959 if (FvHasBeenProcessed (FvHandle
)) {
961 // This Fv has already been processed so lets skip it!
966 Status
= CoreHandleProtocol (FvHandle
, &gEfiFirmwareVolumeDispatchProtocolGuid
, (VOID
**)&Fv
);
967 if (EFI_ERROR (Status
)) {
969 // If no dispatch protocol then skip, but do not marked as being processed as it
970 // may show up later.
976 // Since we are about to process this Fv mark it as processed.
978 FvIsBeingProcesssed (FvHandle
);
980 Status
= CoreHandleProtocol (FvHandle
, &gEfiFirmwareVolume2ProtocolGuid
, (VOID
**)&Fv
);
981 if (EFI_ERROR (Status
)) {
983 // The Handle has a FirmwareVolumeDispatch protocol and should also contiain
984 // a FirmwareVolume protocol thus we should never get here.
990 Status
= CoreHandleProtocol (FvHandle
, &gEfiDevicePathProtocolGuid
, (VOID
**)&FvDevicePath
);
991 if (EFI_ERROR (Status
)) {
993 // The Firmware volume doesn't have device path, can't be dispatched.
999 // Evaluate the authentication status of the Firmware Volume through
1000 // Security Architectural Protocol
1002 if (gSecurity
!= NULL
) {
1003 SecurityStatus
= gSecurity
->FileAuthenticationState (
1008 if (SecurityStatus
!= EFI_SUCCESS
) {
1010 // Security check failed. The firmware volume should not be used for any purpose.
1017 // Discover Drivers in FV and add them to the Discovered Driver List.
1018 // Process EFI_FV_FILETYPE_DRIVER type and then EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER
1019 // EFI_FV_FILETYPE_DXE_CORE is processed to produce a Loaded Image protocol for the core
1020 // EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE is processed to create a Fvb
1022 for (Index
= 0; Index
< sizeof (mDxeFileTypes
) / sizeof (EFI_FV_FILETYPE
); Index
++) {
1024 // Initialize the search key
1028 Type
= mDxeFileTypes
[Index
];
1029 GetNextFileStatus
= Fv
->GetNextFile (
1037 if (!EFI_ERROR (GetNextFileStatus
)) {
1038 if (Type
== EFI_FV_FILETYPE_DXE_CORE
) {
1040 // If this is the DXE core fill in it's DevicePath & DeviceHandle
1042 if (gDxeCoreLoadedImage
->FilePath
== NULL
) {
1043 if (CompareGuid (&NameGuid
, gDxeCoreFileName
)) {
1045 // Maybe One specail Fv cantains only one DXE_CORE module, so its device path must
1046 // be initialized completely.
1048 EfiInitializeFwVolDevicepathNode (&mFvDevicePath
.File
, &NameGuid
);
1049 mFvDevicePath
.End
.Type
= EFI_END_ENTIRE_DEVICE_PATH
;
1050 mFvDevicePath
.End
.SubType
= END_ENTIRE_DEVICE_PATH_SUBTYPE
;
1051 SetDevicePathNodeLength (&mFvDevicePath
.End
, sizeof (EFI_DEVICE_PATH_PROTOCOL
));
1053 gDxeCoreLoadedImage
->FilePath
= DuplicateDevicePath (
1054 (EFI_DEVICE_PATH_PROTOCOL
*)&mFvDevicePath
1056 gDxeCoreLoadedImage
->DeviceHandle
= FvHandle
;
1059 } else if (Type
== EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
) {
1061 // Check if this EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE file has already
1064 if (FvFoundInHobFv2 (FvHandle
, &NameGuid
)) {
1068 // Found a firmware volume image. Produce a firmware volume block
1069 // protocol for it so it gets dispatched from. This is usually a
1072 CoreProcessFvImageFile (Fv
, FvHandle
, &NameGuid
);
1075 // Transition driver from Undiscovered to Discovered state
1077 CoreAddToDriverList (Fv
, FvHandle
, &NameGuid
);
1080 } while (!EFI_ERROR (GetNextFileStatus
));
1084 // Read the array of GUIDs from the Apriori file if it is present in the firmware volume
1087 Status
= Fv
->ReadSection (
1092 (VOID
**)&AprioriFile
,
1094 &AuthenticationStatus
1096 if (!EFI_ERROR (Status
)) {
1097 AprioriEntryCount
= SizeOfBuffer
/ sizeof (EFI_GUID
);
1099 AprioriEntryCount
= 0;
1103 // Put drivers on Apriori List on the Scheduled queue. The Discovered List includes
1104 // drivers not in the current FV and these must be skipped since the a priori list
1105 // is only valid for the FV that it resided in.
1107 CoreAcquireDispatcherLock ();
1109 for (Index
= 0; Index
< AprioriEntryCount
; Index
++) {
1110 for (Link
= mDiscoveredList
.ForwardLink
; Link
!= &mDiscoveredList
; Link
= Link
->ForwardLink
) {
1111 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
1112 if (CompareGuid (&DriverEntry
->FileName
, &AprioriFile
[Index
]) &&
1113 (FvHandle
== DriverEntry
->FvHandle
)) {
1114 DriverEntry
->Dependent
= FALSE
;
1115 DriverEntry
->Scheduled
= TRUE
;
1116 InsertTailList (&mScheduledQueue
, &DriverEntry
->ScheduledLink
);
1122 CoreReleaseDispatcherLock ();
1125 // Free data allocated by Fv->ReadSection ()
1127 CoreFreePool (AprioriFile
);
1134 Initialize the dispatcher. Initialize the notification function that runs when
1135 an FV2 protocol is added to the system.
1139 CoreInitializeDispatcher (
1143 mFwVolEvent
= CoreCreateProtocolNotifyEvent (
1144 &gEfiFirmwareVolume2ProtocolGuid
,
1146 CoreFwVolEventProtocolNotify
,
1148 &mFwVolEventRegistration
,
1154 // Function only used in debug builds
1158 Traverse the discovered list for any drivers that were discovered but not loaded
1159 because the dependency experessions evaluated to false.
1163 CoreDisplayDiscoveredNotDispatched (
1168 EFI_CORE_DRIVER_ENTRY
*DriverEntry
;
1170 for (Link
= mDiscoveredList
.ForwardLink
;Link
!=&mDiscoveredList
; Link
= Link
->ForwardLink
) {
1171 DriverEntry
= CR(Link
, EFI_CORE_DRIVER_ENTRY
, Link
, EFI_CORE_DRIVER_ENTRY_SIGNATURE
);
1172 if (DriverEntry
->Dependent
) {
1173 DEBUG ((DEBUG_LOAD
, "Driver %g was discovered but not loaded!!\n", &DriverEntry
->FileName
));