5.2 Write the UEFI Driver entry point

The following table lists the most common protocols used in UEFI driver entry point.

Table 9 Protocols Used to Separate the Loading and Starting/Stopping of Drivers
Protocol Description
Driver Binding Protocol Provides functions for starting and stopping the driver, as well as a function for determining if the driver can manage a particular controller. The UEFI Driver Model requires this protocol.
Component Name Protocol Provides functions for retrieving a human-readable name of a driver and the controllers that a driver is managing. While the UEFI Specification lists this protocol as optional, the Developer's Interface Guide for 64-bit Intel Architecturebased Servers (hereafter referred to as "DIG64 specification" or "DIG64") lists this protocol as required for Itanium-based platforms.
Driver Diagnostics Protocol Provides functions for executing diagnostic functions on the devices that a driver is managing. While the UEFI
Specification lists this protocol as optional, DIG64 lists this protocol as required for Itanium-based platforms.

The UefiLib library class is provided to simplify the driver entry point of a UEFI driver.

5.2.1 Example: APIs in UefiLib

The two APIs in UefiLib are shown below:

EFI_STATUS
EfiLibInstallDriverBinding (
    IN CONST EFI_HANDLE ImageHandle ,
    IN CONST EFI_SYSTEM_TABLE * SystemTable ,
    IN EFI_DRIVER_BINDING_PROTOCOL * DriverBinding ,
    IN EFI_HANDLE DriverBindingHandle
);

EFI_STATUS
EfiLibInstallAllDriverProtocols2 (
    IN CONST EFI_HANDLE ImageHandle ,
    IN CONST EFI_SYSTEM_TABLE * SystemTable ,
    IN EFI_DRIVER_BINDING_PROTOCOL * DriverBinding ,
    IN EFI_HANDLE DriverBindingHandle ,
    IN CONST EFI_COMPONENT_NAME_PROTOCOL * ComponentName , OPTIONAL
    IN CONST EFI_COMPONENT_NAME2_PROTOCOL * ComponentName2 , OPTIONAL 
    IN CONST EFI_DRIVER_CONFIGURATION_PROTOCOL * DriverConfiguration ,OPTIONAL 
    IN CONST EFI_DRIVER_CONFIGURATION2_PROTOCOL * DriverConfiguration2 ,OPTIONAL
    IN CONST EFI_DRIVER_DIAGNOSTICS_PROTOCOL * DriverDiagnostics ,OPTIONAL
    IN CONST EFI_DRIVER_DIAGNOSTICS2_PROTOCOL * DriverDiagnostics2 OPTIONAL
);

5.2.2 Example: Entry point to the Abc driver

The following shows an example of the entry point to the Abc driver that installs the Driver Binding Protocol gAbcDriverBindingProtocol, the Component Name Protocol gAbcComponentName, the Component Name2 Protocol gAbcComponentName2, the

Diagnostic Protocol gAbcDriverDiagnostics and the Diagnostic2 Protocol

gAbcDriverDiagnostics2 onto the Abc driver's image handle. This driver simply returns the status from the UefiLib function EfiLibInstallAllDriverProtocols2()

EFI_DRIVER_BINDING_PROTOCOL gAbcDriverBinding = {
  AbcDriverBindingSupported,
  AbcDriverBindingStart,
  AbcDriverBindingStop,
  0xa,
  NULL,
  NULL
};
EFI_COMPONENT_NAME_PROTOCOL gAbcComponentName = {
  AbcComponentNameGetDriverName,
  AbcComponentNameGetControllerName,
  "eng"
};
EFI_COMPONENT_NAME2_PROTOCOL gAbcComponentName2 = {
  (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) AbcComponentNameGetDriverName,
  (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)
  AbcComponentNameGetControllerName,
  "en"
};
EFI_DRIVER_DIAGNOSTICS_PROTOCOL gAbcDriverDiagnostics = {
  AbcDriverDiagnosticsRunDiagnostics,
  "eng"
};
EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gAbcDriverDiagnostics2 = {
  (EFI_DRIVER_DIAGNOSTICS2_RUN_DIAGNOSTICS) gAbcDriverDiagnosticsRunDiagnostics,
  "en"
};
EFI_STATUS
EFIAPI
AbcDriverEntryPoint (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  //
  // Initialize a simple EFI driver that follows the EFI Driver Model
  //
  return EfiLibInstallAllDriverProtocols (
           ImageHandle, // Driver's image handle
           SystemTable, // EFI System Table Pointer
           &gAbcDriverBinding, // Required parameters
           ImageHandle,
           // Handle for driver-related protocols &gAbcComponentName,
           // Component Name Procol. May be NULL.
           &gAbcComponentName2, // Component Name2 Procol. May be NULL.
           NULL, // Configuration Protocol. May be NULL.
           NULL // Configuration Protocol2 May be NULL.
           &gAbcDriverDiagnostics, // Diagnostics Protocol. May be NULL.
           &gAbcDriverDiagnostics2,// Diagnostics Protocol2 May be NULL.
           );
}

results matching ""

    No results matching ""