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