]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/XenBusDxe/XenBusDxe.c
OvmfPkg: Add basic skeleton for the XenBus bus driver.
[mirror_edk2.git] / OvmfPkg / XenBusDxe / XenBusDxe.c
CommitLineData
e65e8802
AP
1/** @file\r
2 This driver produces XenBus Protocol instances for each Xen PV devices.\r
3\r
4 This XenBus bus driver will first initialize differente services in order to\r
5 enumerate the ParaVirtualized devices available.\r
6\r
7 Those services are:\r
8 - HyperCall\r
9 - Event Channel\r
10 - Grant Table\r
11 - XenStore\r
12 - XenBus\r
13\r
14 Copyright (C) 2014, Citrix Ltd.\r
15\r
16 This program and the accompanying materials\r
17 are licensed and made available under the terms and conditions of the BSD License\r
18 which accompanies this distribution. The full text of the license may be found at\r
19 http://opensource.org/licenses/bsd-license.php\r
20\r
21 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
22 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
23\r
24**/\r
25\r
26#include <IndustryStandard/Pci.h>\r
27#include <IndustryStandard/Acpi.h>\r
28#include <Library/DebugLib.h>\r
29\r
30#include "XenBusDxe.h"\r
31\r
32\r
33///\r
34/// Driver Binding Protocol instance\r
35///\r
36EFI_DRIVER_BINDING_PROTOCOL gXenBusDxeDriverBinding = {\r
37 XenBusDxeDriverBindingSupported,\r
38 XenBusDxeDriverBindingStart,\r
39 XenBusDxeDriverBindingStop,\r
40 XENBUS_DXE_VERSION,\r
41 NULL,\r
42 NULL\r
43};\r
44\r
45\r
46/**\r
47 Unloads an image.\r
48\r
49 @param ImageHandle Handle that identifies the image to be unloaded.\r
50\r
51 @retval EFI_SUCCESS The image has been unloaded.\r
52 @retval EFI_INVALID_PARAMETER ImageHandle is not a valid image handle.\r
53\r
54**/\r
55EFI_STATUS\r
56EFIAPI\r
57XenBusDxeUnload (\r
58 IN EFI_HANDLE ImageHandle\r
59 )\r
60{\r
61 EFI_STATUS Status;\r
62\r
63 EFI_HANDLE *HandleBuffer;\r
64 UINTN HandleCount;\r
65 UINTN Index;\r
66\r
67 //\r
68 // Retrieve array of all handles in the handle database\r
69 //\r
70 Status = gBS->LocateHandleBuffer (\r
71 AllHandles,\r
72 NULL,\r
73 NULL,\r
74 &HandleCount,\r
75 &HandleBuffer\r
76 );\r
77 if (EFI_ERROR (Status)) {\r
78 return Status;\r
79 }\r
80\r
81 //\r
82 // Disconnect the current driver from handles in the handle database\r
83 //\r
84 for (Index = 0; Index < HandleCount; Index++) {\r
85 gBS->DisconnectController (HandleBuffer[Index], gImageHandle, NULL);\r
86 }\r
87\r
88 //\r
89 // Free the array of handles\r
90 //\r
91 FreePool (HandleBuffer);\r
92\r
93\r
94 //\r
95 // Uninstall protocols installed in the driver entry point\r
96 //\r
97 Status = gBS->UninstallMultipleProtocolInterfaces (\r
98 ImageHandle,\r
99 &gEfiDriverBindingProtocolGuid, &gXenBusDxeDriverBinding,\r
100 &gEfiComponentNameProtocolGuid, &gXenBusDxeComponentName,\r
101 &gEfiComponentName2ProtocolGuid, &gXenBusDxeComponentName2,\r
102 NULL\r
103 );\r
104 if (EFI_ERROR (Status)) {\r
105 return Status;\r
106 }\r
107\r
108 return EFI_SUCCESS;\r
109}\r
110\r
111/**\r
112 This is the declaration of an EFI image entry point. This entry point is\r
113 the same for UEFI Applications, UEFI OS Loaders, and UEFI Drivers including\r
114 both device drivers and bus drivers.\r
115\r
116 @param ImageHandle The firmware allocated handle for the UEFI image.\r
117 @param SystemTable A pointer to the EFI System Table.\r
118\r
119 @retval EFI_SUCCESS The operation completed successfully.\r
120 @retval Others An unexpected error occurred.\r
121**/\r
122EFI_STATUS\r
123EFIAPI\r
124XenBusDxeDriverEntryPoint (\r
125 IN EFI_HANDLE ImageHandle,\r
126 IN EFI_SYSTEM_TABLE *SystemTable\r
127 )\r
128{\r
129 EFI_STATUS Status;\r
130\r
131 //\r
132 // Install UEFI Driver Model protocol(s).\r
133 //\r
134 Status = EfiLibInstallDriverBindingComponentName2 (\r
135 ImageHandle,\r
136 SystemTable,\r
137 &gXenBusDxeDriverBinding,\r
138 ImageHandle,\r
139 &gXenBusDxeComponentName,\r
140 &gXenBusDxeComponentName2\r
141 );\r
142 ASSERT_EFI_ERROR (Status);\r
143\r
144\r
145 return Status;\r
146}\r
147\r
148\r
149/**\r
150 Tests to see if this driver supports a given controller. If a child device is provided,\r
151 it further tests to see if this driver supports creating a handle for the specified child device.\r
152\r
153 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
154 @param[in] ControllerHandle The handle of the controller to test. This handle\r
155 must support a protocol interface that supplies\r
156 an I/O abstraction to the driver.\r
157 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
158 parameter is ignored by device drivers, and is optional for bus\r
159 drivers. For bus drivers, if this parameter is not NULL, then\r
160 the bus driver must determine if the bus controller specified\r
161 by ControllerHandle and the child controller specified\r
162 by RemainingDevicePath are both supported by this\r
163 bus driver.\r
164\r
165 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
166 RemainingDevicePath is supported by the driver specified by This.\r
167 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
168 RemainingDevicePath is already being managed by the driver\r
169 specified by This.\r
170 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
171 RemainingDevicePath is already being managed by a different\r
172 driver or an application that requires exclusive access.\r
173 Currently not implemented.\r
174 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
175 RemainingDevicePath is not supported by the driver specified by This.\r
176**/\r
177EFI_STATUS\r
178EFIAPI\r
179XenBusDxeDriverBindingSupported (\r
180 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
181 IN EFI_HANDLE ControllerHandle,\r
182 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
183 )\r
184{\r
185 EFI_STATUS Status;\r
186 EFI_PCI_IO_PROTOCOL *PciIo;\r
187 PCI_TYPE00 Pci;\r
188\r
189 Status = gBS->OpenProtocol (\r
190 ControllerHandle,\r
191 &gEfiPciIoProtocolGuid,\r
192 (VOID **)&PciIo,\r
193 This->DriverBindingHandle,\r
194 ControllerHandle,\r
195 EFI_OPEN_PROTOCOL_BY_DRIVER\r
196 );\r
197 if (EFI_ERROR (Status)) {\r
198 return Status;\r
199 }\r
200\r
201 Status = PciIo->Pci.Read (PciIo, EfiPciIoWidthUint32, 0,\r
202 sizeof Pci / sizeof (UINT32), &Pci);\r
203\r
204 if (Status == EFI_SUCCESS) {\r
205 if (Pci.Hdr.VendorId == PCI_VENDOR_ID_XEN &&\r
206 Pci.Hdr.DeviceId == PCI_DEVICE_ID_XEN_PLATFORM) {\r
207 Status = EFI_SUCCESS;\r
208 } else {\r
209 Status = EFI_UNSUPPORTED;\r
210 }\r
211 }\r
212\r
213 gBS->CloseProtocol (ControllerHandle, &gEfiPciIoProtocolGuid,\r
214 This->DriverBindingHandle, ControllerHandle);\r
215\r
216 return Status;\r
217}\r
218\r
219/**\r
220 Starts a bus controller.\r
221\r
222 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
223 As a result, much of the error checking on the parameters to Start() has been moved into this\r
224 common boot service. It is legal to call Start() from other locations,\r
225 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
226 1. ControllerHandle must be a valid EFI_HANDLE.\r
227 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
228 EFI_DEVICE_PATH_PROTOCOL.\r
229 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
230 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
231\r
232 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
233 @param[in] ControllerHandle The handle of the controller to start. This handle\r
234 must support a protocol interface that supplies\r
235 an I/O abstraction to the driver.\r
236 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
237 parameter is ignored by device drivers, and is optional for bus\r
238 drivers. For a bus driver, if this parameter is NULL, then handles\r
239 for all the children of Controller are created by this driver.\r
240 If this parameter is not NULL and the first Device Path Node is\r
241 not the End of Device Path Node, then only the handle for the\r
242 child device specified by the first Device Path Node of\r
243 RemainingDevicePath is created by this driver.\r
244 If the first Device Path Node of RemainingDevicePath is\r
245 the End of Device Path Node, no child handle is created by this\r
246 driver.\r
247\r
248 @retval EFI_SUCCESS The device was started.\r
249 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
250 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
251 @retval Others The driver failded to start the device.\r
252\r
253**/\r
254EFI_STATUS\r
255EFIAPI\r
256XenBusDxeDriverBindingStart (\r
257 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
258 IN EFI_HANDLE ControllerHandle,\r
259 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL\r
260 )\r
261{\r
262 return EFI_UNSUPPORTED;\r
263}\r
264\r
265/**\r
266 Stops a bus controller.\r
267\r
268 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
269 As a result, much of the error checking on the parameters to Stop() has been moved\r
270 into this common boot service. It is legal to call Stop() from other locations,\r
271 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
272 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
273 same driver's Start() function.\r
274 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
275 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
276 Start() function, and the Start() function must have called OpenProtocol() on\r
277 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
278\r
279 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
280 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
281 support a bus specific I/O protocol for the driver\r
282 to use to stop the device.\r
283 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
284 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
285 if NumberOfChildren is 0.\r
286\r
287 @retval EFI_SUCCESS The device was stopped.\r
288 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
289\r
290**/\r
291EFI_STATUS\r
292EFIAPI\r
293XenBusDxeDriverBindingStop (\r
294 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
295 IN EFI_HANDLE ControllerHandle,\r
296 IN UINTN NumberOfChildren,\r
297 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL\r
298 )\r
299{\r
300 return EFI_UNSUPPORTED;\r
301}\r