7.9 Service Driver entry point

A service driver produces one or more protocol interfaces on the driver's image handle or on newly created handles. The example below, shows the Decompress Protocol being installed onto the driver's image handle. A service driver may produce an Unload() service, and that service would be required to uninstall the protocols that were installed in the driver's entry point.


Caution: The Unload() service for a service driver may be a dangerous operation because there is no way for the service driver to know if the protocols that it installed are being used by other UEFI components. If the service driver is unloaded and other UEFI components are still using the protocols that were produced by the unloaded driver, then the system is likely to fail.


Example 104-Service driver entry point using image handle
#include <Uefi.h>
#include <Protocol/Decompress.h>
#include <Library/UefiBootServicesTableLib.h>

//
// Decompress Protocol instance
//
EFI_DECOMPRESS_PROTOCOL gAbcDecompress = {
  AbcGetInfo,
  AbcDecompress
};

EFI_STATUS
EFIAPI
AbcDriverEntryPoint (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  //
  // Install Decompress Protocol onto UEFI Driver's ImageHandle
  //
  return gBS->InstallMultipleProtocolInterfaces (
                &ImageHandle,
                &gEfiDecompressProtocolGuid,
                &gAbcDecompress,
                NULL
                );
}

A service driver may also install its protocol interfaces onto one or more new handles in the Handle Database. The following example shows a template for a service driver called Abc that produces the Decompress Protocol on a new handle.

Example 105-Service driver entry point creating new handle
#include <Uefi.h>
#include <Protocol/Decompress.h>
#include <Library/UefiBootServicesTableLib.h>

//
// Handle for the Decompress Protocol
//
EFI_HANDLE gAbcDecompressHandle = NULL;

//
// Decompress Protocol instance
//
EFI_DECOMPRESS_PROTOCOL gAbcDecompress = {
  AbcGetInfo,
  AbcDecompress
};

EFI_STATUS
EFIAPI
AbcDriverEntryPoint (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  //
  // Install Decompress Protocol onto a new handle
  //
  return gBS->InstallMultipleProtocolInterfaces (
                &gAbcDecompressHandle,
                &gEfiDecompressProtocolGuid,
                &gAbcDecompress,
                NULL
                );
}