2 This driver produces XenBus Protocol instances for each Xen PV devices.
4 This XenBus bus driver will first initialize differente services in order to
5 enumerate the ParaVirtualized devices available.
14 Copyright (C) 2014, Citrix Ltd.
16 This program and the accompanying materials
17 are licensed and made available under the terms and conditions of the BSD License
18 which accompanies this distribution. The full text of the license may be found at
19 http://opensource.org/licenses/bsd-license.php
21 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
22 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
26 #include <IndustryStandard/Pci.h>
27 #include <IndustryStandard/Acpi.h>
28 #include <Library/DebugLib.h>
30 #include "XenBusDxe.h"
34 /// Driver Binding Protocol instance
36 EFI_DRIVER_BINDING_PROTOCOL gXenBusDxeDriverBinding
= {
37 XenBusDxeDriverBindingSupported
,
38 XenBusDxeDriverBindingStart
,
39 XenBusDxeDriverBindingStop
,
49 @param ImageHandle Handle that identifies the image to be unloaded.
51 @retval EFI_SUCCESS The image has been unloaded.
52 @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle.
58 IN EFI_HANDLE ImageHandle
63 EFI_HANDLE
*HandleBuffer
;
68 // Retrieve array of all handles in the handle database
70 Status
= gBS
->LocateHandleBuffer (
77 if (EFI_ERROR (Status
)) {
82 // Disconnect the current driver from handles in the handle database
84 for (Index
= 0; Index
< HandleCount
; Index
++) {
85 gBS
->DisconnectController (HandleBuffer
[Index
], gImageHandle
, NULL
);
89 // Free the array of handles
91 FreePool (HandleBuffer
);
95 // Uninstall protocols installed in the driver entry point
97 Status
= gBS
->UninstallMultipleProtocolInterfaces (
99 &gEfiDriverBindingProtocolGuid
, &gXenBusDxeDriverBinding
,
100 &gEfiComponentNameProtocolGuid
, &gXenBusDxeComponentName
,
101 &gEfiComponentName2ProtocolGuid
, &gXenBusDxeComponentName2
,
104 if (EFI_ERROR (Status
)) {
112 This is the declaration of an EFI image entry point. This entry point is
113 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including
114 both device drivers and bus drivers.
116 @param ImageHandle The firmware allocated handle for the UEFI image.
117 @param SystemTable A pointer to the EFI System Table.
119 @retval EFI_SUCCESS The operation completed successfully.
120 @retval Others An unexpected error occurred.
124 XenBusDxeDriverEntryPoint (
125 IN EFI_HANDLE ImageHandle
,
126 IN EFI_SYSTEM_TABLE
*SystemTable
132 // Install UEFI Driver Model protocol(s).
134 Status
= EfiLibInstallDriverBindingComponentName2 (
137 &gXenBusDxeDriverBinding
,
139 &gXenBusDxeComponentName
,
140 &gXenBusDxeComponentName2
142 ASSERT_EFI_ERROR (Status
);
150 Tests to see if this driver supports a given controller. If a child device is provided,
151 it further tests to see if this driver supports creating a handle for the specified child device.
153 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
154 @param[in] ControllerHandle The handle of the controller to test. This handle
155 must support a protocol interface that supplies
156 an I/O abstraction to the driver.
157 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
158 parameter is ignored by device drivers, and is optional for bus
159 drivers. For bus drivers, if this parameter is not NULL, then
160 the bus driver must determine if the bus controller specified
161 by ControllerHandle and the child controller specified
162 by RemainingDevicePath are both supported by this
165 @retval EFI_SUCCESS The device specified by ControllerHandle and
166 RemainingDevicePath is supported by the driver specified by This.
167 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
168 RemainingDevicePath is already being managed by the driver
170 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
171 RemainingDevicePath is already being managed by a different
172 driver or an application that requires exclusive access.
173 Currently not implemented.
174 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
175 RemainingDevicePath is not supported by the driver specified by This.
179 XenBusDxeDriverBindingSupported (
180 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
181 IN EFI_HANDLE ControllerHandle
,
182 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
186 EFI_PCI_IO_PROTOCOL
*PciIo
;
189 Status
= gBS
->OpenProtocol (
191 &gEfiPciIoProtocolGuid
,
193 This
->DriverBindingHandle
,
195 EFI_OPEN_PROTOCOL_BY_DRIVER
197 if (EFI_ERROR (Status
)) {
201 Status
= PciIo
->Pci
.Read (PciIo
, EfiPciIoWidthUint32
, 0,
202 sizeof Pci
/ sizeof (UINT32
), &Pci
);
204 if (Status
== EFI_SUCCESS
) {
205 if (Pci
.Hdr
.VendorId
== PCI_VENDOR_ID_XEN
&&
206 Pci
.Hdr
.DeviceId
== PCI_DEVICE_ID_XEN_PLATFORM
) {
207 Status
= EFI_SUCCESS
;
209 Status
= EFI_UNSUPPORTED
;
213 gBS
->CloseProtocol (ControllerHandle
, &gEfiPciIoProtocolGuid
,
214 This
->DriverBindingHandle
, ControllerHandle
);
220 Starts a bus controller.
222 The Start() function is designed to be invoked from the EFI boot service ConnectController().
223 As a result, much of the error checking on the parameters to Start() has been moved into this
224 common boot service. It is legal to call Start() from other locations,
225 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
226 1. ControllerHandle must be a valid EFI_HANDLE.
227 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
228 EFI_DEVICE_PATH_PROTOCOL.
229 3. Prior to calling Start(), the Supported() function for the driver specified by This must
230 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
232 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
233 @param[in] ControllerHandle The handle of the controller to start. This handle
234 must support a protocol interface that supplies
235 an I/O abstraction to the driver.
236 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
237 parameter is ignored by device drivers, and is optional for bus
238 drivers. For a bus driver, if this parameter is NULL, then handles
239 for all the children of Controller are created by this driver.
240 If this parameter is not NULL and the first Device Path Node is
241 not the End of Device Path Node, then only the handle for the
242 child device specified by the first Device Path Node of
243 RemainingDevicePath is created by this driver.
244 If the first Device Path Node of RemainingDevicePath is
245 the End of Device Path Node, no child handle is created by this
248 @retval EFI_SUCCESS The device was started.
249 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
250 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
251 @retval Others The driver failded to start the device.
256 XenBusDxeDriverBindingStart (
257 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
258 IN EFI_HANDLE ControllerHandle
,
259 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath OPTIONAL
262 return EFI_UNSUPPORTED
;
266 Stops a bus controller.
268 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
269 As a result, much of the error checking on the parameters to Stop() has been moved
270 into this common boot service. It is legal to call Stop() from other locations,
271 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
272 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
273 same driver's Start() function.
274 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
275 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
276 Start() function, and the Start() function must have called OpenProtocol() on
277 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
279 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
280 @param[in] ControllerHandle A handle to the device being stopped. The handle must
281 support a bus specific I/O protocol for the driver
282 to use to stop the device.
283 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
284 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
285 if NumberOfChildren is 0.
287 @retval EFI_SUCCESS The device was stopped.
288 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
293 XenBusDxeDriverBindingStop (
294 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
295 IN EFI_HANDLE ControllerHandle
,
296 IN UINTN NumberOfChildren
,
297 IN EFI_HANDLE
*ChildHandleBuffer OPTIONAL
300 return EFI_UNSUPPORTED
;