7.2.3 Adding Driver Health Protocol Feature

The Driver Health Protocol provides services allowing a UEFI Driver to express the health status of a controller, return status messages associated with the health status, perform repair operations and request configuration changes required to place the controller in a usable state. This protocol is required only for devices that may be in a bad state which can be recovered through a repair operation or a configuration change. If a device can never be in a bad state, or a device can be in a bad state for which there is no recovery possible, this protocol should not be installed.

There are no EDK II library functions to help install the Driver Health Protocol. Instead, the UEFI Driver that requires this feature must install the Driver Health Protocol using the UEFI Boot Service InstallMultipleProtocolInterfaces(). Example 92, below, expands Example 91, above, and adds a Driver Health Protocol instance to ImageHandle, the same handle on which the Driver Binding Protocol is installed.

Example 92-Driver Heath Protocol Feature
#include <Uefi.h>
#include <Protocol/DriverBinding.h>
#include <Protocol/ComponentName2.h>
#include <Protocol/ComponentName.h>
#include <Protocol/DriverHealth.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>

#define ABC_VERSION 0x10

EFI_DRIVER_BINDING_PROTOCOL gAbcDriverBinding = {
  AbcSupported,
  AbcStart,
  AbcStop,
  ABC_VERSION,
  NULL,
  NULL
};

GLOBAL_REMOVE_IF_UNREFERENCED
EFI_COMPONENT_NAME_PROTOCOL gAbcComponentName = {
  (EFI_COMPONENT_NAME_GET_DRIVER_NAME) AbcGetDriverName,
  (EFI_COMPONENT_NAME_GET_CONTROLLER_NAME) AbcGetControllerName,
  "eng"
};

GLOBAL_REMOVE_IF_UNREFERENCED
EFI_COMPONENT_NAME2_PROTOCOL gAbcComponentName2 = {
  AbcGetDriverName,
  AbcGetControllerName,
  "en"
};

GLOBAL_REMOVE_IF_UNREFERENCED
EFI_DRIVER_HEALTH_PROTOCOL gAbcDriverHealth = {
  AbcGetHealthStatus,
  AbcRepair
};

EFI_STATUS
EFIAPI
AbcDriverEntryPoint (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS  Status;

  //
  // Install driver model protocol(s) on ImageHandle
  //
  Status = EfiLibInstallDriverBindingComponentName2 (
             ImageHandle,                 // ImageHandle
             SystemTable,                 // SystemTable
             &gAbcDriverBinding,          // DriverBinding
             ImageHandle,                 // DriverBindingHandle
             &gAbcComponentName,          // ComponentName
             &gAbcComponentName2          // ComponentName2
             );
  ASSERT_EFI_ERROR (Status);

  //
  // Install Driver Health Protocol onto ImageHandle
  //
  Status = gBS->InstallMultipleProtocolInterfaces (
                  &ImageHandle,
                  &gEfiDriverHealthProtocolGuid,
                  &gAbcDriverHealth,
                  NULL
                  );
  ASSERT_EFI_ERROR (Status);

  return Status;
}