2 This driver produce a BlockIo protocol instance for a Xen PV block device.
4 This driver support XenBus protocol of type 'vbd'. Every function that
5 comsume XenBus protocol are in BlockFront, which the implementation to access
6 a Xen PV device. The BlockIo implementation is in it's one file and will call
9 Copyright (C) 2014, Citrix Ltd.
11 This program and the accompanying materials
12 are licensed and made available under the terms and conditions of the BSD License
13 which accompanies this distribution. The full text of the license may be found at
14 http://opensource.org/licenses/bsd-license.php
16 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
17 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include "XenPvBlkDxe.h"
25 /// Driver Binding Protocol instance
27 EFI_DRIVER_BINDING_PROTOCOL gXenPvBlkDxeDriverBinding
= {
28 XenPvBlkDxeDriverBindingSupported
,
29 XenPvBlkDxeDriverBindingStart
,
30 XenPvBlkDxeDriverBindingStop
,
31 XEN_PV_BLK_DXE_VERSION
,
40 @param ImageHandle Handle that identifies the image to be unloaded.
42 @retval EFI_SUCCESS The image has been unloaded.
43 @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle.
49 IN EFI_HANDLE ImageHandle
54 EFI_HANDLE
*HandleBuffer
;
60 // Retrieve array of all handles in the handle database
62 Status
= gBS
->LocateHandleBuffer (
69 if (EFI_ERROR (Status
)) {
74 // Disconnect the current driver from handles in the handle database
76 for (Index
= 0; Index
< HandleCount
; Index
++) {
77 gBS
->DisconnectController (HandleBuffer
[Index
], gImageHandle
, NULL
);
81 // Free the array of handles
83 FreePool (HandleBuffer
);
87 // Uninstall protocols installed in the driver entry point
89 Status
= gBS
->UninstallMultipleProtocolInterfaces (
91 &gEfiDriverBindingProtocolGuid
, &gXenPvBlkDxeDriverBinding
,
92 &gEfiComponentNameProtocolGuid
, &gXenPvBlkDxeComponentName
,
93 &gEfiComponentName2ProtocolGuid
, &gXenPvBlkDxeComponentName2
,
96 if (EFI_ERROR (Status
)) {
104 This is the declaration of an EFI image entry point. This entry point is
105 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
106 both device drivers and bus drivers.
108 @param ImageHandle The firmware allocated handle for the UEFI image.
109 @param SystemTable A pointer to the EFI System Table.
111 @retval EFI_SUCCESS The operation completed successfully.
112 @retval Others An unexpected error occurred.
116 XenPvBlkDxeDriverEntryPoint (
117 IN EFI_HANDLE ImageHandle
,
118 IN EFI_SYSTEM_TABLE
*SystemTable
124 // Install UEFI Driver Model protocol(s).
126 Status
= EfiLibInstallDriverBindingComponentName2 (
129 &gXenPvBlkDxeDriverBinding
,
131 &gXenPvBlkDxeComponentName
,
132 &gXenPvBlkDxeComponentName2
134 ASSERT_EFI_ERROR (Status
);
141 Tests to see if this driver supports a given controller. If a child device is provided,
142 it further tests to see if this driver supports creating a handle for the specified child device.
144 This function checks to see if the driver specified by This supports the device specified by
145 ControllerHandle. Drivers will typically use the device path attached to
146 ControllerHandle and/or the services from the bus I/O abstraction attached to
147 ControllerHandle to determine if the driver supports ControllerHandle. This function
148 may be called many times during platform initialization. In order to reduce boot times, the tests
149 performed by this function must be very small, and take as little time as possible to execute. This
150 function must not change the state of any hardware devices, and this function must be aware that the
151 device specified by ControllerHandle may already be managed by the same driver or a
152 different driver. This function must match its calls to AllocatePages() with FreePages(),
153 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
154 Because ControllerHandle may have been previously started by the same driver, if a protocol is
155 already in the opened state, then it must not be closed with CloseProtocol(). This is required
156 to guarantee the state of ControllerHandle is not modified by this function.
158 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
159 @param[in] ControllerHandle The handle of the controller to test. This handle
160 must support a protocol interface that supplies
161 an I/O abstraction to the driver.
162 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
163 parameter is ignored by device drivers, and is optional for bus
164 drivers. For bus drivers, if this parameter is not NULL, then
165 the bus driver must determine if the bus controller specified
166 by ControllerHandle and the child controller specified
167 by RemainingDevicePath are both supported by this
170 @retval EFI_SUCCESS The device specified by ControllerHandle and
171 RemainingDevicePath is supported by the driver specified by This.
172 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
173 RemainingDevicePath is already being managed by the driver
175 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
176 RemainingDevicePath is already being managed by a different
177 driver or an application that requires exclusive access.
178 Currently not implemented.
179 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
180 RemainingDevicePath is not supported by the driver specified by This.
184 XenPvBlkDxeDriverBindingSupported (
185 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
186 IN EFI_HANDLE ControllerHandle
,
187 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
191 XENBUS_PROTOCOL
*XenBusIo
;
193 Status
= gBS
->OpenProtocol (
195 &gXenBusProtocolGuid
,
197 This
->DriverBindingHandle
,
199 EFI_OPEN_PROTOCOL_BY_DRIVER
201 if (EFI_ERROR (Status
)) {
204 if (AsciiStrCmp (XenBusIo
->Type
, "vbd") == 0) {
205 Status
= EFI_SUCCESS
;
207 Status
= EFI_UNSUPPORTED
;
210 gBS
->CloseProtocol (ControllerHandle
, &gXenBusProtocolGuid
,
211 This
->DriverBindingHandle
, ControllerHandle
);
217 Starts a device controller.
219 The Start() function is designed to be invoked from the EFI boot service ConnectController().
220 As a result, much of the error checking on the parameters to Start() has been moved into this
221 common boot service. It is legal to call Start() from other locations,
222 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
223 1. ControllerHandle must be a valid EFI_HANDLE.
224 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
225 EFI_DEVICE_PATH_PROTOCOL.
226 3. Prior to calling Start(), the Supported() function for the driver specified by This must
227 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
229 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
230 @param[in] ControllerHandle The handle of the controller to start. This handle
231 must support a protocol interface that supplies
232 an I/O abstraction to the driver.
233 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
234 parameter is ignored by device drivers, and is optional for bus
235 drivers. For a bus driver, if this parameter is NULL, then handles
236 for all the children of Controller are created by this driver.
237 If this parameter is not NULL and the first Device Path Node is
238 not the End of Device Path Node, then only the handle for the
239 child device specified by the first Device Path Node of
240 RemainingDevicePath is created by this driver.
241 If the first Device Path Node of RemainingDevicePath is
242 the End of Device Path Node, no child handle is created by this
245 @retval EFI_SUCCESS The device was started.
246 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
247 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
248 @retval Others The driver failded to start the device.
253 XenPvBlkDxeDriverBindingStart (
254 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
255 IN EFI_HANDLE ControllerHandle
,
256 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
260 XENBUS_PROTOCOL
*XenBusIo
;
262 Status
= gBS
->OpenProtocol (
264 &gXenBusProtocolGuid
,
266 This
->DriverBindingHandle
,
268 EFI_OPEN_PROTOCOL_BY_DRIVER
270 if (EFI_ERROR (Status
)) {
278 Stops a device controller.
280 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
281 As a result, much of the error checking on the parameters to Stop() has been moved
282 into this common boot service. It is legal to call Stop() from other locations,
283 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
284 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
285 same driver's Start() function.
286 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
287 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
288 Start() function, and the Start() function must have called OpenProtocol() on
289 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
291 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
292 @param[in] ControllerHandle A handle to the device being stopped. The handle must
293 support a bus specific I/O protocol for the driver
294 to use to stop the device.
295 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
296 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
297 if NumberOfChildren is 0.
299 @retval EFI_SUCCESS The device was stopped.
300 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
305 XenPvBlkDxeDriverBindingStop (
306 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
307 IN EFI_HANDLE ControllerHandle
,
308 IN UINTN NumberOfChildren
,
309 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
312 gBS
->CloseProtocol (ControllerHandle
, &gXenBusProtocolGuid
,
313 This
->DriverBindingHandle
, ControllerHandle
);