TianoCore EDK2 master
Loading...
Searching...
No Matches
Dispatcher.c File Reference
#include "DxeMain.h"

Go to the source code of this file.

Data Structures

struct  FV_FILEPATH_DEVICE_PATH
 

Functions

VOID CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter (IN EFI_CORE_DRIVER_ENTRY *InsertedDriverEntry)
 
VOID EFIAPI CoreFwVolEventProtocolNotify (IN EFI_EVENT Event, IN VOID *Context)
 
EFI_DEVICE_PATH_PROTOCOL * CoreFvToDevicePath (IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv, IN EFI_HANDLE FvHandle, IN EFI_GUID *DriverName)
 
EFI_STATUS CoreAddToDriverList (IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv, IN EFI_HANDLE FvHandle, IN EFI_GUID *DriverName, IN EFI_FV_FILETYPE Type)
 
EFI_STATUS CoreProcessFvImageFile (IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv, IN EFI_HANDLE FvHandle, IN EFI_GUID *FileName)
 
VOID CoreAcquireDispatcherLock (VOID)
 
VOID CoreReleaseDispatcherLock (VOID)
 
EFI_STATUS CoreGetDepexSectionAndPreProccess (IN EFI_CORE_DRIVER_ENTRY *DriverEntry)
 
EFI_STATUS EFIAPI CoreSchedule (IN EFI_HANDLE FirmwareVolumeHandle, IN EFI_GUID *DriverName)
 
EFI_STATUS EFIAPI CoreTrust (IN EFI_HANDLE FirmwareVolumeHandle, IN EFI_GUID *DriverName)
 
EFI_STATUS EFIAPI CoreDispatcher (VOID)
 
BOOLEAN FvHasBeenProcessed (IN EFI_HANDLE FvHandle)
 
KNOWN_HANDLE * FvIsBeingProcessed (IN EFI_HANDLE FvHandle)
 
BOOLEAN FvFoundInHobFv2 (IN CONST EFI_GUID *FvNameGuid, IN CONST EFI_GUID *DriverName)
 
BOOLEAN GetFvUsedSize (IN EFI_FIRMWARE_VOLUME_HEADER *FvHeader, OUT UINT32 *FvUsedSize, OUT UINT8 *EraseByte)
 
VOID CoreInitializeDispatcher (VOID)
 
VOID CoreDisplayDiscoveredNotDispatched (VOID)
 

Variables

LIST_ENTRY mDiscoveredList = INITIALIZE_LIST_HEAD_VARIABLE (mDiscoveredList)
 
LIST_ENTRY mScheduledQueue = INITIALIZE_LIST_HEAD_VARIABLE (mScheduledQueue)
 
LIST_ENTRY mFvHandleList = INITIALIZE_LIST_HEAD_VARIABLE (mFvHandleList)
 
EFI_LOCK mDispatcherLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL)
 
BOOLEAN gDispatcherRunning = FALSE
 
EFI_EVENT mFwVolEvent
 
VOID * mFwVolEventRegistration
 
EFI_FV_FILETYPE mDxeFileTypes []
 
FV_FILEPATH_DEVICE_PATH mFvDevicePath
 

Detailed Description

DXE Dispatcher.

Step #1 - When a FV protocol is added to the system every driver in the FV is added to the mDiscoveredList. The SOR, Before, and After Depex are pre-processed as drivers are added to the mDiscoveredList. If an Apriori file exists in the FV those drivers are addeded to the mScheduledQueue. The mFvHandleList is used to make sure a FV is only processed once.

Step #2 - Dispatch. Remove driver from the mScheduledQueue and load and start it. After mScheduledQueue is drained check the mDiscoveredList to see if any item has a Depex that is ready to be placed on the mScheduledQueue.

Step #3 - Adding to the mScheduledQueue requires that you process Before and After dependencies. This is done recursively as the call to add to the mScheduledQueue checks for Before and recursively adds all Befores. It then addes the item that was passed in and then processess the After dependecies by recursively calling the routine.

Dispatcher Rules: The rules for the dispatcher are in chapter 10 of the DXE CIS. Figure 10-3 is the state diagram for the DXE dispatcher

Depex - Dependency Expresion. SOR - Schedule On Request - Don't schedule if this bit is set.

Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file Dispatcher.c.

Function Documentation

◆ CoreAcquireDispatcherLock()

VOID CoreAcquireDispatcherLock ( VOID  )

Enter critical section by gaining lock on mDispatcherLock.

Definition at line 203 of file Dispatcher.c.

◆ CoreAddToDriverList()

EFI_STATUS CoreAddToDriverList ( IN EFI_FIRMWARE_VOLUME2_PROTOCOL *  Fv,
IN EFI_HANDLE  FvHandle,
IN EFI_GUID *  DriverName,
IN EFI_FV_FILETYPE  Type 
)

Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry, and initilize any state variables. Read the Depex from the FV and store it in DriverEntry. Pre-process the Depex to set the SOR, Before and After state. The Discovered list is never free'ed and contains booleans that represent the other possible DXE driver states.

Parameters
FvFv protocol, needed to read Depex info out of FLASH.
FvHandleHandle for Fv, needed in the EFI_CORE_DRIVER_ENTRY so that the PE image can be read out of the FV at a later time.
DriverNameName of driver to add to mDiscoveredList.
TypeFv File Type of file to add to mDiscoveredList.
Return values
EFI_SUCCESSIf driver was added to the mDiscoveredList.
EFI_ALREADY_STARTEDThe driver has already been started. Only one DriverName may be active in the system at any one time.

Add an entry to the mDiscoveredList. Allocate memory to store the DriverEntry, and initilize any state variables. Read the Depex from the FV and store it in DriverEntry. Pre-process the Depex to set the SOR, Before and After state. The Discovered list is never free'ed and contains booleans that represent the other possible DXE driver states.

Parameters
FvFv protocol, needed to read Depex info out of FLASH.
FvHandleHandle for Fv, needed in the EFI_CORE_DRIVER_ENTRY so that the PE image can be read out of the FV at a later time.
DriverNameName of driver to add to mDiscoveredList.
TypeFv File Type of file to add to mDiscoveredList.
Return values
EFI_SUCCESSIf driver was added to the mDiscoveredList.
EFI_ALREADY_STARTEDThe driver has already been started. Only one DriverName may be active in the system at any one time.
EFI_OUT_OF_RESOURCESIf memory could not be allocated for the DriverEntry.

Definition at line 860 of file Dispatcher.c.

◆ CoreDispatcher()

EFI_STATUS EFIAPI CoreDispatcher ( VOID  )

This is the main Dispatcher for DXE and it exits when there are no more drivers to run. Drain the mScheduledQueue and load and start a PE image for each driver. Search the mDiscoveredList to see if any driver can be placed on the mScheduledQueue. If no drivers are placed on the mScheduledQueue exit the function. On exit it is assumed the Bds() will be called, and when the Bds() exits the Dispatcher will be called again.

Return values
EFI_ALREADY_STARTEDThe DXE Dispatcher is already running
EFI_NOT_FOUNDNo DXE Drivers were dispatched
EFI_SUCCESSOne or more DXE Drivers were dispatched

Definition at line 400 of file Dispatcher.c.

◆ CoreDisplayDiscoveredNotDispatched()

VOID CoreDisplayDiscoveredNotDispatched ( VOID  )

Traverse the discovered list for any drivers that were discovered but not loaded because the dependency experessions evaluated to false.

Definition at line 1481 of file Dispatcher.c.

◆ CoreFvToDevicePath()

EFI_DEVICE_PATH_PROTOCOL * CoreFvToDevicePath ( IN EFI_FIRMWARE_VOLUME2_PROTOCOL *  Fv,
IN EFI_HANDLE  FvHandle,
IN EFI_GUID *  DriverName 
)

Convert FvHandle and DriverName into an EFI device path

Parameters
FvFv protocol, needed to read Depex info out of FLASH.
FvHandleHandle for Fv, needed in the EFI_CORE_DRIVER_ENTRY so that the PE image can be read out of the FV at a later time.
DriverNameName of driver to add to mDiscoveredList.
Returns
Pointer to device path constructed from FvHandle and DriverName

Definition at line 805 of file Dispatcher.c.

◆ CoreFwVolEventProtocolNotify()

VOID EFIAPI CoreFwVolEventProtocolNotify ( IN EFI_EVENT  Event,
IN VOID *  Context 
)

Event notification that is fired every time a FV dispatch protocol is added. More than one protocol may have been added when this event is fired, so you must loop on CoreLocateHandle () to see how many protocols were added and do the following to each FV: If the Fv has already been processed, skip it. If the Fv has not been processed then mark it as being processed, as we are about to process it. Read the Fv and add any driver in the Fv to the mDiscoveredList.The mDiscoveredList is never free'ed and contains variables that define the other states the DXE driver transitions to.. While you are at it read the A Priori file into memory. Place drivers in the A Priori list onto the mScheduledQueue.

Parameters
EventThe Event that is being processed, not used.
ContextEvent Context, not used.

Definition at line 1209 of file Dispatcher.c.

◆ CoreGetDepexSectionAndPreProccess()

EFI_STATUS CoreGetDepexSectionAndPreProccess ( IN EFI_CORE_DRIVER_ENTRY *  DriverEntry)

Read Depex and pre-process the Depex for Before and After. If Section Extraction protocol returns an error via ReadSection defer the reading of the Depex.

Parameters
DriverEntryDriver to work on.
Return values
EFI_SUCCESSDepex read and preprossesed
EFI_PROTOCOL_ERRORThe section extraction protocol returned an error and Depex reading needs to be retried.
ErrorDEPEX not found.

Definition at line 235 of file Dispatcher.c.

◆ CoreInitializeDispatcher()

VOID CoreInitializeDispatcher ( VOID  )

Initialize the dispatcher. Initialize the notification function that runs when an FV2 protocol is added to the system.

Definition at line 1454 of file Dispatcher.c.

◆ CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter()

VOID CoreInsertOnScheduledQueueWhileProcessingBeforeAndAfter ( IN EFI_CORE_DRIVER_ENTRY *  InsertedDriverEntry)

Insert InsertedDriverEntry onto the mScheduledQueue. To do this you must add any driver with a before dependency on InsertedDriverEntry first. You do this by recursively calling this routine. After all the Befores are processed you can add InsertedDriverEntry to the mScheduledQueue. Then you can add any driver with an After dependency on InsertedDriverEntry by recursively calling this routine.

Parameters
InsertedDriverEntryThe driver to insert on the ScheduledLink Queue

Definition at line 593 of file Dispatcher.c.

◆ CoreProcessFvImageFile()

EFI_STATUS CoreProcessFvImageFile ( IN EFI_FIRMWARE_VOLUME2_PROTOCOL *  Fv,
IN EFI_HANDLE  FvHandle,
IN EFI_GUID *  FileName 
)

Get Fv image(s) from the FV through file name, and produce FVB protocol for every Fv image(s).

Parameters
FvThe FIRMWARE_VOLUME protocol installed on the FV.
FvHandleThe handle which FVB protocol installed on.
FileNameThe file name guid specified.
Return values
EFI_OUT_OF_RESOURCESNo enough memory or other resource.
EFI_SUCCESSFunction successfully returned.

Definition at line 1014 of file Dispatcher.c.

◆ CoreReleaseDispatcherLock()

VOID CoreReleaseDispatcherLock ( VOID  )

Exit critical section by releasing lock on mDispatcherLock.

Definition at line 215 of file Dispatcher.c.

◆ CoreSchedule()

EFI_STATUS EFIAPI CoreSchedule ( IN EFI_HANDLE  FirmwareVolumeHandle,
IN EFI_GUID *  DriverName 
)

Check every driver and locate a matching one. If the driver is found, the Unrequested state flag is cleared.

Parameters
FirmwareVolumeHandleThe handle of the Firmware Volume that contains the firmware file specified by DriverName.
DriverNameThe Driver name to put in the Dependent state.
Return values
EFI_SUCCESSThe DriverName was found and it's SOR bit was cleared
EFI_NOT_FOUNDThe DriverName does not exist or it's SOR bit was not set.

Definition at line 301 of file Dispatcher.c.

◆ CoreTrust()

EFI_STATUS EFIAPI CoreTrust ( IN EFI_HANDLE  FirmwareVolumeHandle,
IN EFI_GUID *  DriverName 
)

Convert a driver from the Untrused back to the Scheduled state.

Parameters
FirmwareVolumeHandleThe handle of the Firmware Volume that contains the firmware file specified by DriverName.
DriverNameThe Driver name to put in the Scheduled state
Return values
EFI_SUCCESSThe file was found in the untrusted state, and it was promoted to the trusted state.
EFI_NOT_FOUNDThe file was not found in the untrusted state.

Definition at line 351 of file Dispatcher.c.

◆ FvFoundInHobFv2()

BOOLEAN FvFoundInHobFv2 ( IN CONST EFI_GUID *  FvNameGuid,
IN CONST EFI_GUID *  DriverName 
)

Check if a FV Image type file (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE) is described by a EFI_HOB_FIRMWARE_VOLUME2 Hob.

Parameters
FvNameGuidThe FV image guid specified.
DriverNameThe driver guid specified.
Return values
TRUEThis file is found in a EFI_HOB_FIRMWARE_VOLUME2 Hob.
FALSENot found.

Definition at line 913 of file Dispatcher.c.

◆ FvHasBeenProcessed()

BOOLEAN FvHasBeenProcessed ( IN EFI_HANDLE  FvHandle)

Return TRUE if the Fv has been processed, FALSE if not.

Parameters
FvHandleThe handle of a FV that's being tested
Return values
TRUEFv protocol on FvHandle has been processed
FALSEFv protocol on FvHandle has not yet been processed

Definition at line 662 of file Dispatcher.c.

◆ FvIsBeingProcessed()

KNOWN_HANDLE * FvIsBeingProcessed ( IN EFI_HANDLE  FvHandle)

Remember that Fv protocol on FvHandle has had it's drivers placed on the mDiscoveredList. This fucntion adds entries on the mFvHandleList if new entry is different from one in mFvHandleList by checking FvImage Guid. Items are never removed/freed from the mFvHandleList.

Parameters
FvHandleThe handle of a FV that has been processed
Returns
A point to new added FvHandle entry. If FvHandle with the same FvImage guid has been added, NULL will return.

Definition at line 692 of file Dispatcher.c.

◆ GetFvUsedSize()

BOOLEAN GetFvUsedSize ( IN EFI_FIRMWARE_VOLUME_HEADER *  FvHeader,
OUT UINT32 *  FvUsedSize,
OUT UINT8 *  EraseByte 
)

Find USED_SIZE FV_EXT_TYPE entry in FV extension header and get the FV used size.

Parameters
[in]FvHeaderPointer to FV header.
[out]FvUsedSizePointer to FV used size returned, only valid if USED_SIZE FV_EXT_TYPE entry is found.
[out]EraseBytePointer to erase byte returned, only valid if USED_SIZE FV_EXT_TYPE entry is found.
Return values
TRUEUSED_SIZE FV_EXT_TYPE entry is found, FV used size and erase byte are returned.
FALSENo USED_SIZE FV_EXT_TYPE entry found.

Definition at line 953 of file Dispatcher.c.

Variable Documentation

◆ gDispatcherRunning

BOOLEAN gDispatcherRunning = FALSE

Definition at line 61 of file Dispatcher.c.

◆ mDiscoveredList

LIST_ENTRY mDiscoveredList = INITIALIZE_LIST_HEAD_VARIABLE (mDiscoveredList)

Definition at line 40 of file Dispatcher.c.

◆ mDispatcherLock

EFI_LOCK mDispatcherLock = EFI_INITIALIZE_LOCK_VARIABLE (TPL_HIGH_LEVEL)

Definition at line 56 of file Dispatcher.c.

◆ mDxeFileTypes

EFI_FV_FILETYPE mDxeFileTypes[]
Initial value:
= {
EFI_FV_FILETYPE_DRIVER,
EFI_FV_FILETYPE_COMBINED_SMM_DXE,
EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER,
EFI_FV_FILETYPE_DXE_CORE,
EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
}

Definition at line 72 of file Dispatcher.c.

◆ mFvDevicePath

FV_FILEPATH_DEVICE_PATH mFvDevicePath

Definition at line 85 of file Dispatcher.c.

◆ mFvHandleList

LIST_ENTRY mFvHandleList = INITIALIZE_LIST_HEAD_VARIABLE (mFvHandleList)

Definition at line 51 of file Dispatcher.c.

◆ mFwVolEvent

EFI_EVENT mFwVolEvent

Definition at line 66 of file Dispatcher.c.

◆ mFwVolEventRegistration

VOID* mFwVolEventRegistration

Definition at line 67 of file Dispatcher.c.

◆ mScheduledQueue

LIST_ENTRY mScheduledQueue = INITIALIZE_LIST_HEAD_VARIABLE (mScheduledQueue)

Definition at line 46 of file Dispatcher.c.