dispatcher.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 1,192 行 · 第 1/3 页
C
1,192 行
/*++
Copyright (c) 2004 - 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
Dispatcher.c
Abstract:
Tiano 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.
--*/
#include "Tiano.h"
#include "DxeCore.h"
#include "FwVolBlock.h"
#include EFI_GUID_DEFINITION (Apriori)
//
// The Driver List contains one copy of every driver that has been discovered.
// Items are never removed from the driver list. List of EFI_CORE_DRIVER_ENTRY
//
EFI_LIST_ENTRY mDiscoveredList = INITIALIZE_LIST_HEAD_VARIABLE (mDiscoveredList);
//
// Queue of drivers that are ready to dispatch. This queue is a subset of the
// mDiscoveredList.list of EFI_CORE_DRIVER_ENTRY.
//
EFI_LIST_ENTRY mScheduledQueue = INITIALIZE_LIST_HEAD_VARIABLE (mScheduledQueue);
//
// List of handles who's Fv's have been parsed and added to the mFwDriverList.
//
EFI_LIST_ENTRY mFvHandleList = INITIALIZE_LIST_HEAD_VARIABLE (mFvHandleList); // list of KNOWN_HANDLE
//
// Lock for mDiscoveredList, mScheduledQueue, mDispatcherRunning.
//
EFI_LOCK mDispatcherLock = EFI_INITIALIZE_LOCK_VARIABLE (EFI_TPL_HIGH_LEVEL);
//
// Flag for the DXE Dispacher. TRUE if dispatcher is execuing.
//
BOOLEAN mDispatcherRunning = FALSE;
//
// Module globals to manage the FwVol registration notification event
//
EFI_EVENT mFwVolEvent;
VOID *mFwVolEventRegistration;
//
// List of file types supported by dispatcher
//
static EFI_FV_FILETYPE mDxeFileTypes[] = {
EFI_FV_FILETYPE_DRIVER,
EFI_FV_FILETYPE_COMBINED_PEIM_DRIVER,
EFI_FV_FILETYPE_DXE_CORE,
EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
};
typedef struct {
MEDIA_FW_VOL_FILEPATH_DEVICE_PATH File;
EFI_DEVICE_PATH_PROTOCOL End;
} FV_FILEPATH_DEVICE_PATH;
FV_FILEPATH_DEVICE_PATH mFvDevicePath;
//
// Function Prototypes
//
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_VOLUME_PROTOCOL *Fv,
IN EFI_HANDLE FvHandle,
IN EFI_GUID *DriverName
);
STATIC
EFI_STATUS
CoreAddToDriverList (
IN EFI_FIRMWARE_VOLUME_PROTOCOL *Fv,
IN EFI_HANDLE FvHandle,
IN EFI_GUID *DriverName
);
STATIC
EFI_STATUS
CoreProcessFvImageFile (
IN EFI_FIRMWARE_VOLUME_PROTOCOL *Fv,
IN EFI_HANDLE FvHandle,
IN EFI_GUID *DriverName
);
VOID
CoreAcquireDispatcherLock (
VOID
)
/*++
Routine Description:
Enter critical section by gaining lock on mDispatcherLock
Arguments:
None
Returns:
None
--*/
{
CoreAcquireLock (&mDispatcherLock);
}
VOID
CoreReleaseDispatcherLock (
VOID
)
/*++
Routine Description:
Exit critical section by releasing lock on mDispatcherLock
Arguments:
None
Returns:
None
--*/
{
CoreReleaseLock (&mDispatcherLock);
}
EFI_STATUS
CoreGetDepexSectionAndPreProccess (
IN EFI_CORE_DRIVER_ENTRY *DriverEntry
)
/*++
Routine Description:
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.
Arguments:
DriverEntry - Driver to work on.
Returns:
EFI_SUCCESS - Depex read and preprossesed
EFI_PROTOCOL_ERROR - The section extraction protocol returned an error and
Depex reading needs to be retried.
Other Error - DEPEX not found.
--*/
{
EFI_STATUS Status;
EFI_SECTION_TYPE SectionType;
UINT32 AuthenticationStatus;
EFI_FIRMWARE_VOLUME_PROTOCOL *Fv;
Fv = DriverEntry->Fv;
//
// Grab Depex info, it will never be free'ed.
//
SectionType = EFI_SECTION_DXE_DEPEX;
Status = Fv->ReadSection (
DriverEntry->Fv,
&DriverEntry->FileName,
SectionType,
0,
&DriverEntry->Depex,
(UINTN *)&DriverEntry->DepexSize,
&AuthenticationStatus
);
if (EFI_ERROR (Status)) {
if (Status == EFI_PROTOCOL_ERROR) {
//
// The section extraction protocol failed so set protocol error flag
//
DriverEntry->DepexProtocolError = TRUE;
} else {
//
// If no Depex assume EFI 1.1 driver model
//
DriverEntry->Depex = NULL;
DriverEntry->Dependent = TRUE;
DriverEntry->DepexProtocolError = FALSE;
}
} else {
//
// Set Before, After, and Unrequested state information based on Depex
// Driver will be put in Dependent or Unrequested state
//
CorePreProcessDepex (DriverEntry);
DriverEntry->DepexProtocolError = FALSE;
}
return Status;
}
EFI_DXESERVICE
EFI_STATUS
EFIAPI
CoreSchedule (
IN EFI_HANDLE FirmwareVolumeHandle,
IN EFI_GUID *DriverName
)
/*++
Routine Description:
Check every driver and locate a matching one. If the driver is found, the Unrequested
state flag is cleared.
Arguments:
FirmwareVolumeHandle - The handle of the Firmware Volume that contains the firmware
file specified by DriverName.
DriverName - The Driver name to put in the Dependent state.
Returns:
EFI_SUCCESS - The DriverName was found and it's SOR bit was cleared
EFI_NOT_FOUND - The DriverName does not exist or it's SOR bit was not set.
--*/
{
EFI_LIST_ENTRY *Link;
EFI_CORE_DRIVER_ENTRY *DriverEntry;
//
// Check every driver
//
for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {
DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);
if (DriverEntry->FvHandle == FirmwareVolumeHandle &&
DriverEntry->Unrequested &&
EfiCompareGuid (DriverName, &DriverEntry->FileName)) {
//
// Move the driver from the Unrequested to the Dependent state
//
CoreAcquireDispatcherLock ();
DriverEntry->Unrequested = FALSE;
DriverEntry->Dependent = TRUE;
CoreReleaseDispatcherLock ();
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
EFI_DXESERVICE
EFI_STATUS
EFIAPI
CoreTrust (
IN EFI_HANDLE FirmwareVolumeHandle,
IN EFI_GUID *DriverName
)
/*++
Routine Description:
Convert a driver from the Untrused back to the Scheduled state
Arguments:
FirmwareVolumeHandle - The handle of the Firmware Volume that contains the firmware
file specified by DriverName.
DriverName - The Driver name to put in the Scheduled state
Returns:
EFI_SUCCESS - The file was found in the untrusted state, and it was promoted
to the trusted state.
EFI_NOT_FOUND - The file was not found in the untrusted state.
--*/
{
EFI_LIST_ENTRY *Link;
EFI_CORE_DRIVER_ENTRY *DriverEntry;
//
// Check every driver
//
for (Link = mDiscoveredList.ForwardLink; Link != &mDiscoveredList; Link = Link->ForwardLink) {
DriverEntry = CR(Link, EFI_CORE_DRIVER_ENTRY, Link, EFI_CORE_DRIVER_ENTRY_SIGNATURE);
if (DriverEntry->FvHandle == FirmwareVolumeHandle &&
DriverEntry->Untrusted &&
EfiCompareGuid (DriverName, &DriverEntry->FileName)) {
//
// Transition driver from Untrusted to Scheduled state.
//
CoreAcquireDispatcherLock ();
DriverEntry->Untrusted = FALSE;
DriverEntry->Scheduled = TRUE;
InsertTailList (&mScheduledQueue, &DriverEntry->ScheduledLink);
CoreReleaseDispatcherLock ();
return EFI_SUCCESS;
}
}
return EFI_NOT_FOUND;
}
EFI_DXESERVICE
EFI_STATUS
EFIAPI
CoreDispatcher (
VOID
)
/*++
Routine Description:
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.
Arguments:
NONE
Returns:
EFI_ALREADY_STARTED - The DXE Dispatcher is already running
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?