win-pvdrivers

view xenusb/xenusb.h @ 670:b59c7dfdee9b

Updates to support latest pre-release version of pvusb. No longer compatible with current version.
author James Harper <james.harper@bendigoit.com.au>
date Wed Sep 23 17:06:30 2009 +1000 (2009-09-23)
parents 21e041d3e07d
children 5bdb7251370c
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_urb_request_t req;
120 usbif_urb_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_URB_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 /* protected by conn_ring_lock */
201 ULONG num_ports;
202 xenusb_port_t ports[32];
204 KSPIN_LOCK urb_ring_lock;
205 usbif_urb_sring_t *urb_sring;
206 usbif_urb_front_ring_t urb_ring;
208 KSPIN_LOCK conn_ring_lock;
209 usbif_conn_sring_t *conn_sring;
210 usbif_conn_front_ring_t conn_ring;
212 evtchn_port_t event_channel;
214 BOOLEAN inactive;
215 XENPCI_VECTORS vectors;
216 PXENPCI_DEVICE_STATE device_state;
218 } XENUSB_DEVICE_DATA, *PXENUSB_DEVICE_DATA;
220 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENUSB_DEVICE_DATA, GetXudd)
222 typedef struct {
223 WDFDEVICE wdf_device;
224 WDFDEVICE wdf_device_bus_fdo;
225 WDFQUEUE io_queue;
226 WDFQUEUE urb_queue;
227 ULONG device_number;
228 //ULONG port_number;
229 //ULONG port_type;
230 xenusb_device_t *usb_device;
231 PVOID BusCallbackContext;
232 PRH_INIT_CALLBACK BusCallbackFunction;
234 } XENUSB_PDO_DEVICE_DATA, *PXENUSB_PDO_DEVICE_DATA;
236 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENUSB_PDO_DEVICE_DATA, GetXupdd)
238 #if 0
239 typedef struct {
240 UCHAR usb_class;
241 UCHAR usb_subclass;
242 UCHAR usb_protocol;
243 } xenusb_compatible_id_details_t;
244 #endif
246 typedef struct {
247 WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER header;
248 ULONG device_number;
249 //ULONG port_number;
250 //ULONG port_type;
251 //USHORT vendor_id;
252 //USHORT product_id;
253 //xenusb_compatible_id_details_t xucid[1];
254 } XENUSB_PDO_IDENTIFICATION_DESCRIPTION, *PXENUSB_PDO_IDENTIFICATION_DESCRIPTION;
256 static usbif_shadow_t *
257 get_shadow_from_freelist(PXENUSB_DEVICE_DATA xudd)
258 {
259 if (xudd->shadow_free == 0)
260 {
261 KdPrint((__DRIVER_NAME " No more shadow entries\n"));
262 return NULL;
263 }
264 xudd->shadow_free--;
265 return &xudd->shadows[xudd->shadow_free_list[xudd->shadow_free]];
266 }
268 static VOID
269 put_shadow_on_freelist(PXENUSB_DEVICE_DATA xudd, usbif_shadow_t *shadow)
270 {
271 xudd->shadow_free_list[xudd->shadow_free] = (USHORT)shadow->id;
272 shadow->request = NULL;
273 xudd->shadow_free++;
274 }
276 static
277 ULONGLONG parse_numeric_string(PCHAR string)
278 {
279 ULONGLONG val = 0;
280 while (*string != 0)
281 {
282 val = val * 10 + (*string - '0');
283 string++;
284 }
285 return val;
286 }
288 #if 0
289 static VOID
290 XenUsb_PutRequest(PXENVBD_DEVICE_DATA xudd, usbif_request_t *req)
291 {
292 *RING_GET_REQUEST(&xudd->ring, xudd->ring.req_prod_pvt) = *req;
293 xudd->ring.req_prod_pvt++;
294 }
296 static usbif_request_t *
297 XenUsb_GetResponse(PXENVBD_DEVICE_DATA xudd, ULONG i)
298 {
299 return RING_GET_RESPONSE(&xvdd->ring, i);
300 }
301 #endif
304 /*
305 EVT_WDF_DEVICE_PREPARE_HARDWARE XenUsb_EvtDevicePrepareHardware;
306 EVT_WDF_DEVICE_RELEASE_HARDWARE XenUsb_EvtDeviceReleaseHardware;
307 EVT_WDF_DEVICE_D0_ENTRY XenUsb_EvtDeviceD0Entry;
308 EVT_WDF_DEVICE_D0_ENTRY_POST_INTERRUPTS_ENABLED XenUsb_EvtDeviceD0EntryPostInterruptsEnabled;
309 EVT_WDF_DEVICE_D0_EXIT XenUsb_EvtDeviceD0Exit;
310 EVT_WDF_DEVICE_D0_EXIT_PRE_INTERRUPTS_DISABLED XenUsb_EvtDeviceD0ExitPreInterruptsDisabled;
311 EVT_WDF_DEVICE_QUERY_REMOVE XenUsb_EvtDeviceQueryRemove;
312 */
314 //PFN_WDF_DRIVER_DEVICE_ADD XenUsb_EvtDriverDeviceAdd;
315 NTSTATUS
316 XenUsb_EvtDriverDeviceAdd(WDFDRIVER driver, PWDFDEVICE_INIT device_init);
318 NTSTATUS
319 XenUsb_EvtChildListCreateDevice(WDFCHILDLIST child_list, PWDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER description_header, PWDFDEVICE_INIT child_init);
320 VOID
321 XenUsb_EvtChildListScanForChildren(WDFCHILDLIST child_list);
323 VOID
324 XenUsb_EnumeratePorts(WDFDEVICE device);
326 VOID
327 XenUsb_EvtIoInternalDeviceControl_ROOTHUB_SUBMIT_URB(
328 WDFQUEUE queue,
329 WDFREQUEST request,
330 size_t output_buffer_length,
331 size_t input_buffer_length,
332 ULONG io_control_code);
334 VOID
335 XenUsb_EvtIoInternalDeviceControl_DEVICE_SUBMIT_URB(
336 WDFQUEUE queue,
337 WDFREQUEST request,
338 size_t output_buffer_length,
339 size_t input_buffer_length,
340 ULONG io_control_code);
342 NTSTATUS
343 XenUsb_ExecuteRequest(
344 PXENUSB_DEVICE_DATA xudd,
345 usbif_shadow_t *shadow,
346 PVOID transfer_buffer,
347 PMDL transfer_buffer_mdl,
348 ULONG transfer_buffer_length);
350 #endif