xref: /illumos-gate/usr/src/boot/efi/include/Protocol/DriverBinding.h (revision f334afcfaebea1b7dc3430015651d8d748fa8a3e)
1 /** @file
2   UEFI DriverBinding Protocol is defined in UEFI specification.
3 
4   This protocol is produced by every driver that follows the UEFI Driver Model,
5   and it is the central component that allows drivers and controllers to be managed.
6 
7 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
9 
10 **/
11 
12 #ifndef __EFI_DRIVER_BINDING_H__
13 #define __EFI_DRIVER_BINDING_H__
14 
15 ///
16 /// The global ID for the ControllerHandle Driver Protocol.
17 ///
18 #define EFI_DRIVER_BINDING_PROTOCOL_GUID \
19   { \
20     0x18a031ab, 0xb443, 0x4d1a, {0xa5, 0xc0, 0xc, 0x9, 0x26, 0x1e, 0x9f, 0x71 } \
21   }
22 
23 typedef struct _EFI_DRIVER_BINDING_PROTOCOL EFI_DRIVER_BINDING_PROTOCOL;
24 
25 /**
26   Tests to see if this driver supports a given controller. If a child device is provided,
27   it further tests to see if this driver supports creating a handle for the specified child device.
28 
29   This function checks to see if the driver specified by This supports the device specified by
30   ControllerHandle. Drivers will typically use the device path attached to
31   ControllerHandle and/or the services from the bus I/O abstraction attached to
32   ControllerHandle to determine if the driver supports ControllerHandle. This function
33   may be called many times during platform initialization. In order to reduce boot times, the tests
34   performed by this function must be very small, and take as little time as possible to execute. This
35   function must not change the state of any hardware devices, and this function must be aware that the
36   device specified by ControllerHandle may already be managed by the same driver or a
37   different driver. This function must match its calls to AllocatePages() with FreePages(),
38   AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
39   Because ControllerHandle may have been previously started by the same driver, if a protocol is
40   already in the opened state, then it must not be closed with CloseProtocol(). This is required
41   to guarantee the state of ControllerHandle is not modified by this function.
42 
43   @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
44   @param[in]  ControllerHandle     The handle of the controller to test. This handle
45                                    must support a protocol interface that supplies
46                                    an I/O abstraction to the driver.
47   @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This
48                                    parameter is ignored by device drivers, and is optional for bus
49                                    drivers. For bus drivers, if this parameter is not NULL, then
50                                    the bus driver must determine if the bus controller specified
51                                    by ControllerHandle and the child controller specified
52                                    by RemainingDevicePath are both supported by this
53                                    bus driver.
54 
55   @retval EFI_SUCCESS              The device specified by ControllerHandle and
56                                    RemainingDevicePath is supported by the driver specified by This.
57   @retval EFI_ALREADY_STARTED      The device specified by ControllerHandle and
58                                    RemainingDevicePath is already being managed by the driver
59                                    specified by This.
60   @retval EFI_ACCESS_DENIED        The device specified by ControllerHandle and
61                                    RemainingDevicePath is already being managed by a different
62                                    driver or an application that requires exclusive access.
63                                    Currently not implemented.
64   @retval EFI_UNSUPPORTED          The device specified by ControllerHandle and
65                                    RemainingDevicePath is not supported by the driver specified by This.
66 **/
67 typedef
68 EFI_STATUS
69 (EFIAPI *EFI_DRIVER_BINDING_SUPPORTED)(
70   IN EFI_DRIVER_BINDING_PROTOCOL            *This,
71   IN EFI_HANDLE                             ControllerHandle,
72   IN EFI_DEVICE_PATH_PROTOCOL               *RemainingDevicePath OPTIONAL
73   );
74 
75 /**
76   Starts a device controller or a bus controller.
77 
78   The Start() function is designed to be invoked from the EFI boot service ConnectController().
79   As a result, much of the error checking on the parameters to Start() has been moved into this
80   common boot service. It is legal to call Start() from other locations,
81   but the following calling restrictions must be followed, or the system behavior will not be deterministic.
82   1. ControllerHandle must be a valid EFI_HANDLE.
83   2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
84      EFI_DEVICE_PATH_PROTOCOL.
85   3. Prior to calling Start(), the Supported() function for the driver specified by This must
86      have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
87 
88   @param[in]  This                 A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
89   @param[in]  ControllerHandle     The handle of the controller to start. This handle
90                                    must support a protocol interface that supplies
91                                    an I/O abstraction to the driver.
92   @param[in]  RemainingDevicePath  A pointer to the remaining portion of a device path.  This
93                                    parameter is ignored by device drivers, and is optional for bus
94                                    drivers. For a bus driver, if this parameter is NULL, then handles
95                                    for all the children of Controller are created by this driver.
96                                    If this parameter is not NULL and the first Device Path Node is
97                                    not the End of Device Path Node, then only the handle for the
98                                    child device specified by the first Device Path Node of
99                                    RemainingDevicePath is created by this driver.
100                                    If the first Device Path Node of RemainingDevicePath is
101                                    the End of Device Path Node, no child handle is created by this
102                                    driver.
103 
104   @retval EFI_SUCCESS              The device was started.
105   @retval EFI_DEVICE_ERROR         The device could not be started due to a device error.Currently not implemented.
106   @retval EFI_OUT_OF_RESOURCES     The request could not be completed due to a lack of resources.
107   @retval Others                   The driver failded to start the device.
108 
109 **/
110 typedef
111 EFI_STATUS
112 (EFIAPI *EFI_DRIVER_BINDING_START)(
113   IN EFI_DRIVER_BINDING_PROTOCOL            *This,
114   IN EFI_HANDLE                             ControllerHandle,
115   IN EFI_DEVICE_PATH_PROTOCOL               *RemainingDevicePath OPTIONAL
116   );
117 
118 /**
119   Stops a device controller or a bus controller.
120 
121   The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
122   As a result, much of the error checking on the parameters to Stop() has been moved
123   into this common boot service. It is legal to call Stop() from other locations,
124   but the following calling restrictions must be followed, or the system behavior will not be deterministic.
125   1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
126      same driver's Start() function.
127   2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
128      EFI_HANDLE. In addition, all of these handles must have been created in this driver's
129      Start() function, and the Start() function must have called OpenProtocol() on
130      ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
131 
132   @param[in]  This              A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
133   @param[in]  ControllerHandle  A handle to the device being stopped. The handle must
134                                 support a bus specific I/O protocol for the driver
135                                 to use to stop the device.
136   @param[in]  NumberOfChildren  The number of child device handles in ChildHandleBuffer.
137   @param[in]  ChildHandleBuffer An array of child handles to be freed. May be NULL
138                                 if NumberOfChildren is 0.
139 
140   @retval EFI_SUCCESS           The device was stopped.
141   @retval EFI_DEVICE_ERROR      The device could not be stopped due to a device error.
142 
143 **/
144 typedef
145 EFI_STATUS
146 (EFIAPI *EFI_DRIVER_BINDING_STOP)(
147   IN EFI_DRIVER_BINDING_PROTOCOL            *This,
148   IN  EFI_HANDLE                            ControllerHandle,
149   IN  UINTN                                 NumberOfChildren,
150   IN  EFI_HANDLE                            *ChildHandleBuffer OPTIONAL
151   );
152 
153 ///
154 /// This protocol provides the services required to determine if a driver supports a given controller.
155 /// If a controller is supported, then it also provides routines to start and stop the controller.
156 ///
157 struct _EFI_DRIVER_BINDING_PROTOCOL {
158   EFI_DRIVER_BINDING_SUPPORTED    Supported;
159   EFI_DRIVER_BINDING_START        Start;
160   EFI_DRIVER_BINDING_STOP         Stop;
161 
162   ///
163   /// The version number of the UEFI driver that produced the
164   /// EFI_DRIVER_BINDING_PROTOCOL. This field is used by
165   /// the EFI boot service ConnectController() to determine
166   /// the order that driver's Supported() service will be used when
167   /// a controller needs to be started. EFI Driver Binding Protocol
168   /// instances with higher Version values will be used before ones
169   /// with lower Version values. The Version values of 0x0-
170   /// 0x0f and 0xfffffff0-0xffffffff are reserved for
171   /// platform/OEM specific drivers. The Version values of 0x10-
172   /// 0xffffffef are reserved for IHV-developed drivers.
173   ///
174   UINT32        Version;
175 
176   ///
177   /// The image handle of the UEFI driver that produced this instance
178   /// of the EFI_DRIVER_BINDING_PROTOCOL.
179   ///
180   EFI_HANDLE    ImageHandle;
181 
182   ///
183   /// The handle on which this instance of the
184   /// EFI_DRIVER_BINDING_PROTOCOL is installed. In most
185   /// cases, this is the same handle as ImageHandle. However, for
186   /// UEFI drivers that produce more than one instance of the
187   /// EFI_DRIVER_BINDING_PROTOCOL, this value may not be
188   /// the same as ImageHandle.
189   ///
190   EFI_HANDLE    DriverBindingHandle;
191 };
192 
193 extern EFI_GUID  gEfiDriverBindingProtocolGuid;
194 
195 #endif
196