win-pvdrivers

view xenusb/xenusb.h @ 662:21e041d3e07d

Lots of little fixes.
usbview now works.
Advanced properties of HCD in device manager still crashes.
author James Harper <james.harper@bendigoit.com.au>
date Tue Sep 15 20:17:23 2009 +1000 (2009-09-15)
parents 43a106f19847
children b59c7dfdee9b
line source
1 /*
2 PV Drivers for Windows Xen HVM Domains
3 Copyright (C) 2007 James Harper
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
20 #pragma warning(disable: 4127)
22 #pragma warning(disable : 4200) // zero-sized array
24 #if !defined(_XENUSB_H_)
25 #define _XENUSB_H_
27 #define __attribute__(arg) /* empty */
28 #define EISCONN 127
30 #include <ntifs.h>
31 #include <ntddk.h>
33 #define DDKAPI
34 //#include <wdm.h>
35 #include <wdf.h>
36 #include <initguid.h>
37 #include <wdmguid.h>
38 #include <errno.h>
39 #define NTSTRSAFE_LIB
40 #include <ntstrsafe.h>
42 #define __DRIVER_NAME "XenUSB"
44 #include <xen_windows.h>
45 #include <io/ring.h>
46 #include <io/usbif.h>
47 #include <usb.h>
48 #include <usbioctl.h>
49 #include <usbdlib.h>
50 #include <hubbusif.h>
51 #include <usbbusif.h>
53 #define C_HUB_LOCAL_POWER 0
54 #define C_HUB_OVER_CURRENT 1
55 #define PORT_CONNECTION 0
56 #define PORT_ENABLE 1
57 #define PORT_SUSPEND 2
58 #define PORT_OVER_CURRENT 3
59 #define PORT_RESET 4
60 #define PORT_POWER 8
61 #define PORT_LOW_SPEED 9
62 #define PORT_HIGH_SPEED 9
63 #define C_PORT_CONNECTION 16
64 #define C_PORT_ENABLE 17
65 #define C_PORT_SUSPEND 18
66 #define C_PORT_OVER_CURRENT 19
67 #define C_PORT_RESET 20
68 #define PORT_TEST 21
69 #define PORT_INDICATOR 22
71 #define XENUSB_POOL_TAG (ULONG)'XenU'
73 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
75 #define CHILD_STATE_EMPTY 0
76 #define CHILD_STATE_DELETED 1
77 #define CHILD_STATE_ADDED 2
79 #define LINUX_PIPE_DIRECTION_OUT 0x00000000
80 #define LINUX_PIPE_DIRECTION_IN 0x00000080
82 /* these are linux definitions - different to usb standard */
83 #define LINUX_PIPE_TYPE_ISOC 0x00000000
84 #define LINUX_PIPE_TYPE_INTR 0x40000000
85 #define LINUX_PIPE_TYPE_CTRL 0x80000000
86 #define LINUX_PIPE_TYPE_BULK 0xC0000000
88 /*
89 * urb->transfer_flags:
90 */
91 #define LINUX_URB_SHORT_NOT_OK 0x0001 /* report short reads as errors */
92 #define LINUX_URB_ISO_ASAP 0x0002 /* iso-only, urb->start_frame ignored */
93 #define LINUX_URB_NO_TRANSFER_DMA_MAP 0x0004 /* urb->transfer_dma valid on submit */
94 #define LINUX_URB_NO_SETUP_DMA_MAP 0x0008 /* urb->setup_dma valid on submit */
95 #define LINUX_URB_NO_FSBR 0x0020 /* UHCI-specific */
96 #define LINUX_URB_ZERO_PACKET 0x0040 /* Finish bulk OUT with short packet */
97 #define LINUX_URB_NO_INTERRUPT 0x0080 /* HINT: no non-error interrupt needed */
101 struct _usbif_shadow;
102 typedef struct _usbif_shadow usbif_shadow_t;
104 struct _usbif_shadow {
105 uint16_t id;
106 union
107 {
108 struct {
109 WDFREQUEST request;
110 PURB urb;
111 };
112 KEVENT event;
113 };
114 WDFDMATRANSACTION dma_transaction;
115 PMDL mdl;
116 ULONG total_length;
117 /* called at DISPATCH_LEVEL */
118 VOID (*callback)(usbif_shadow_t *);
119 usbif_request_t req;
120 usbif_response_t rsp;
121 usbif_shadow_t *next; /* for gathering shadows from the ring for callback */
122 };
124 #define MAX_SHADOW_ENTRIES 64
125 #define SHADOW_ENTRIES min(MAX_SHADOW_ENTRIES, USB_RING_SIZE)
127 struct _xenusb_endpoint_t;
128 struct _xenusb_interface_t;
129 struct _xenusb_config_t;
130 struct _xenusb_device_t;
131 typedef struct _xenusb_endpoint_t xenusb_endpoint_t, *pxenusb_endpoint_t;
132 typedef struct _xenusb_interface_t xenusb_interface_t;
133 typedef struct _xenusb_config_t xenusb_config_t;
134 typedef struct _xenusb_device_t xenusb_device_t;
136 typedef struct _xenusb_endpoint_t {
137 xenusb_interface_t *interface;
138 ULONG pipe_value;
139 WDFTIMER interrupt_timer;
140 WDFQUEUE interrupt_queue;
141 WDFSPINLOCK interrupt_lock;
142 USB_ENDPOINT_DESCRIPTOR endpoint_descriptor;
143 };
144 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(pxenusb_endpoint_t, GetEndpoint)
146 typedef struct _xenusb_interface_t {
147 //ULONG pipe_value;
148 xenusb_config_t *config;
149 USB_INTERFACE_DESCRIPTOR interface_descriptor;
150 xenusb_endpoint_t *endpoints[0];
151 } xenusb_interface_t;
153 typedef struct _xenusb_config_t {
154 xenusb_device_t *device;
155 USB_CONFIGURATION_DESCRIPTOR config_descriptor;
156 xenusb_interface_t *interfaces[0];
157 } xenusb_config_t;
159 typedef struct _xenusb_device_t {
160 WDFDEVICE pdo_device;
161 UCHAR address;
162 USB_DEVICE_DESCRIPTOR device_descriptor;
163 ULONG port_number;
164 WDFQUEUE urb_queue;
165 USB_DEVICE_SPEED device_speed;
166 USB_DEVICE_TYPE device_type;
167 xenusb_config_t *active_config;
168 xenusb_interface_t *active_interface;
169 xenusb_config_t **configs; /* pointer to an array of configs */
170 } xenusb_device_t;
172 #define USB_PORT_TYPE_NOT_CONNECTED 0
173 #define USB_PORT_TYPE_LOW_SPEED 1
174 #define USB_PORT_TYPE_FULL_SPEED 2
175 #define USB_PORT_TYPE_HIGH_SPEED 3
177 typedef struct
178 {
179 ULONG port_number;
180 ULONG port_type;
181 USHORT port_status;
182 USHORT port_change;
183 } xenusb_port_t;
185 typedef struct {
186 BOOLEAN XenBus_ShuttingDown;
187 WDFQUEUE io_queue;
188 WDFDMAENABLER dma_enabler;
190 WDFCHILDLIST child_list;
192 WDFDEVICE root_hub_device;
194 usbif_shadow_t shadows[MAX_SHADOW_ENTRIES];
195 USHORT shadow_free_list[MAX_SHADOW_ENTRIES];
196 USHORT shadow_free;
198 PUCHAR config_page;
200 KSPIN_LOCK port_lock;
201 ULONG num_ports;
202 xenusb_port_t ports[32];
204 KSPIN_LOCK ring_lock;
205 usbif_sring_t *sring;
206 usbif_front_ring_t ring;
207 evtchn_port_t event_channel;
209 BOOLEAN inactive;
210 XENPCI_VECTORS vectors;
211 PXENPCI_DEVICE_STATE device_state;
213 } XENUSB_DEVICE_DATA, *PXENUSB_DEVICE_DATA;
215 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENUSB_DEVICE_DATA, GetXudd)
217 typedef struct {
218 WDFDEVICE wdf_device;
219 WDFDEVICE wdf_device_bus_fdo;
220 WDFQUEUE io_queue;
221 WDFQUEUE urb_queue;
222 ULONG device_number;
223 //ULONG port_number;
224 //ULONG port_type;
225 xenusb_device_t *usb_device;
226 PVOID BusCallbackContext;
227 PRH_INIT_CALLBACK BusCallbackFunction;
229 } XENUSB_PDO_DEVICE_DATA, *PXENUSB_PDO_DEVICE_DATA;
231 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENUSB_PDO_DEVICE_DATA, GetXupdd)
233 #if 0
234 typedef struct {
235 UCHAR usb_class;
236 UCHAR usb_subclass;
237 UCHAR usb_protocol;
238 } xenusb_compatible_id_details_t;
239 #endif
241 typedef struct {
242 WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER header;
243 ULONG device_number;
244 //ULONG port_number;
245 //ULONG port_type;
246 //USHORT vendor_id;
247 //USHORT product_id;
248 //xenusb_compatible_id_details_t xucid[1];
249 } XENUSB_PDO_IDENTIFICATION_DESCRIPTION, *PXENUSB_PDO_IDENTIFICATION_DESCRIPTION;
251 static usbif_shadow_t *
252 get_shadow_from_freelist(PXENUSB_DEVICE_DATA xudd)
253 {
254 if (xudd->shadow_free == 0)
255 {
256 KdPrint((__DRIVER_NAME " No more shadow entries\n"));
257 return NULL;
258 }
259 xudd->shadow_free--;
260 return &xudd->shadows[xudd->shadow_free_list[xudd->shadow_free]];
261 }
263 static VOID
264 put_shadow_on_freelist(PXENUSB_DEVICE_DATA xudd, usbif_shadow_t *shadow)
265 {
266 xudd->shadow_free_list[xudd->shadow_free] = (USHORT)shadow->id;
267 shadow->request = NULL;
268 xudd->shadow_free++;
269 }
271 static
272 ULONGLONG parse_numeric_string(PCHAR string)
273 {
274 ULONGLONG val = 0;
275 while (*string != 0)
276 {
277 val = val * 10 + (*string - '0');
278 string++;
279 }
280 return val;
281 }
283 #if 0
284 static VOID
285 XenUsb_PutRequest(PXENVBD_DEVICE_DATA xudd, usbif_request_t *req)
286 {
287 *RING_GET_REQUEST(&xudd->ring, xudd->ring.req_prod_pvt) = *req;
288 xudd->ring.req_prod_pvt++;
289 }
291 static usbif_request_t *
292 XenUsb_GetResponse(PXENVBD_DEVICE_DATA xudd, ULONG i)
293 {
294 return RING_GET_RESPONSE(&xvdd->ring, i);
295 }
296 #endif
299 /*
300 EVT_WDF_DEVICE_PREPARE_HARDWARE XenUsb_EvtDevicePrepareHardware;
301 EVT_WDF_DEVICE_RELEASE_HARDWARE XenUsb_EvtDeviceReleaseHardware;
302 EVT_WDF_DEVICE_D0_ENTRY XenUsb_EvtDeviceD0Entry;
303 EVT_WDF_DEVICE_D0_ENTRY_POST_INTERRUPTS_ENABLED XenUsb_EvtDeviceD0EntryPostInterruptsEnabled;
304 EVT_WDF_DEVICE_D0_EXIT XenUsb_EvtDeviceD0Exit;
305 EVT_WDF_DEVICE_D0_EXIT_PRE_INTERRUPTS_DISABLED XenUsb_EvtDeviceD0ExitPreInterruptsDisabled;
306 EVT_WDF_DEVICE_QUERY_REMOVE XenUsb_EvtDeviceQueryRemove;
307 */
309 //PFN_WDF_DRIVER_DEVICE_ADD XenUsb_EvtDriverDeviceAdd;
310 NTSTATUS
311 XenUsb_EvtDriverDeviceAdd(WDFDRIVER driver, PWDFDEVICE_INIT device_init);
313 NTSTATUS
314 XenUsb_EvtChildListCreateDevice(WDFCHILDLIST child_list, PWDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER description_header, PWDFDEVICE_INIT child_init);
315 VOID
316 XenUsb_EvtChildListScanForChildren(WDFCHILDLIST child_list);
318 VOID
319 XenUsb_EnumeratePorts(WDFDEVICE device);
321 VOID
322 XenUsb_EvtIoInternalDeviceControl_ROOTHUB_SUBMIT_URB(
323 WDFQUEUE queue,
324 WDFREQUEST request,
325 size_t output_buffer_length,
326 size_t input_buffer_length,
327 ULONG io_control_code);
329 VOID
330 XenUsb_EvtIoInternalDeviceControl_DEVICE_SUBMIT_URB(
331 WDFQUEUE queue,
332 WDFREQUEST request,
333 size_t output_buffer_length,
334 size_t input_buffer_length,
335 ULONG io_control_code);
337 NTSTATUS
338 XenUsb_ExecuteRequest(
339 PXENUSB_DEVICE_DATA xudd,
340 usbif_shadow_t *shadow,
341 PVOID transfer_buffer,
342 PMDL transfer_buffer_mdl,
343 ULONG transfer_buffer_length);
345 #endif