09_UEFI Service Binding Protocol - manojkumarpaladugu/UEFI-BIOS-Development GitHub Wiki

Introduction:
The Service Binding Protocol is not associated with a single GUID value. Instead, each Service Binding Protocol GUID value is paired with another protocol providing a specific set of service.

The protocol interfaces for all Service Binding Protocols are identical and contain the services CreateChild() and DestroyChild(). When CreateChild() is called, a new handle is created with the associated protocol installed. When DestroyChild() is called, the associated protocol is uninstalled and handle is freed.

struct _EFI_SERVICE_BINDING_PROTOCOL {
  EFI_SERVICE_BINDING_CREATE_CHILD         CreateChild;
  EFI_SERVICE_BINDING_DESTROY_CHILD        DestroyChild;
};

When to use?
For a new protocol, decision must be made to determine if the new protocol requires a Service Binding Protocol. Driver Binding Protocol is usually enough for managing devices on a common bus topology and for the simple layering of protocols on a single device. When more complex tree or graph topologies are required and, with the expectation that the services of the new protocol be required by multiple consumers, a Service Binding Protocol should be considered.


Sample Code:

#include 
#include 
#include 

typedef struct {
  UINT32 AbcField;
} ABC_PROTOCOL;

EFI_HANDLE gAbcServiceBindingHandle = NULL;

EFI_SERVICE_BINDING_PROTOCOL gAbcServiceBinding = {
  AbcCreateChild,
  AbcDestroyChild
};

ABC_PROTOCOL gAbc = {
  0
};

EFI_STATUS
EFIAPI
AbcCreateChild(
  IN     EFI_SERVICE_BINDING_PROTOCOL* This,
  IN OUT EFI_HANDLE* ChildHandle
)
{
  EFI_HANDLE  NewHandle;
  NewHandle = NULL;
  return gBS->InstallMultipleProtocolInterfaces(
    &NewHandle,
    &gAbcProtocolGuid,
    &gAbc,
    NULL
  );
}

EFI_STATUS
EFIAPI
AbcDestroyChild(
  IN EFI_SERVICE_BINDING_PROTOCOL* This,
  IN EFI_HANDLE                    ChildHandle
)
{
  return gBS->UninstallMultipleProtocolInterfaces(
    ChildHandle,
    &gAbcProtocolGuid,
    &gAbc,
    NULL
  );
}

EFI_STATUS
EFIAPI
AbcDriverEntryPoint(
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE* SystemTable
)
{
  //
  // Install Service Binding Protocol for ABC onto a new handle
  //
  return gBS->InstallMultipleProtocolInterfaces(
    &gAbcServiceBindingHandle,
    &gAbcServiceBindingProtocolGuid,
    &gAbcServiceBinding,
    NULL
  );
}
⚠️ **GitHub.com Fallback** ⚠️