win-pvdrivers

view xenusb/xenusb.h @ 752:2ecb5104c33a

usb changes to support device hiding changes
author James Harper <james.harper@bendigoit.com.au>
date Sun Jan 10 10:14:07 2010 +1100 (2010-01-10)
parents 5bdb7251370c
children bbc6c94b9621
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 XENPCI_VECTORS vectors;
215 PXENPCI_DEVICE_STATE device_state;
217 } XENUSB_DEVICE_DATA, *PXENUSB_DEVICE_DATA;
219 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENUSB_DEVICE_DATA, GetXudd)
221 typedef struct {
222 WDFDEVICE wdf_device;
223 WDFDEVICE wdf_device_bus_fdo;
224 WDFQUEUE io_queue;
225 WDFQUEUE urb_queue;
226 ULONG device_number;
227 //ULONG port_number;
228 //ULONG port_type;
229 xenusb_device_t *usb_device;
230 PVOID BusCallbackContext;
231 PRH_INIT_CALLBACK BusCallbackFunction;
233 } XENUSB_PDO_DEVICE_DATA, *PXENUSB_PDO_DEVICE_DATA;
235 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENUSB_PDO_DEVICE_DATA, GetXupdd)
237 #if 0
238 typedef struct {
239 UCHAR usb_class;
240 UCHAR usb_subclass;
241 UCHAR usb_protocol;
242 } xenusb_compatible_id_details_t;
243 #endif
245 typedef struct {
246 WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER header;
247 ULONG device_number;
248 //ULONG port_number;
249 //ULONG port_type;
250 //USHORT vendor_id;
251 //USHORT product_id;
252 //xenusb_compatible_id_details_t xucid[1];
253 } XENUSB_PDO_IDENTIFICATION_DESCRIPTION, *PXENUSB_PDO_IDENTIFICATION_DESCRIPTION;
255 static usbif_shadow_t *
256 get_shadow_from_freelist(PXENUSB_DEVICE_DATA xudd)
257 {
258 if (xudd->shadow_free == 0)
259 {
260 KdPrint((__DRIVER_NAME " No more shadow entries\n"));
261 return NULL;
262 }
263 xudd->shadow_free--;
264 return &xudd->shadows[xudd->shadow_free_list[xudd->shadow_free]];
265 }
267 static VOID
268 put_shadow_on_freelist(PXENUSB_DEVICE_DATA xudd, usbif_shadow_t *shadow)
269 {
270 xudd->shadow_free_list[xudd->shadow_free] = (USHORT)shadow->id;
271 shadow->request = NULL;
272 xudd->shadow_free++;
273 }
275 static
276 ULONGLONG parse_numeric_string(PCHAR string)
277 {
278 ULONGLONG val = 0;
279 while (*string != 0)
280 {
281 val = val * 10 + (*string - '0');
282 string++;
283 }
284 return val;
285 }
287 #if 0
288 static VOID
289 XenUsb_PutRequest(PXENVBD_DEVICE_DATA xudd, usbif_request_t *req)
290 {
291 *RING_GET_REQUEST(&xudd->ring, xudd->ring.req_prod_pvt) = *req;
292 xudd->ring.req_prod_pvt++;
293 }
295 static usbif_request_t *
296 XenUsb_GetResponse(PXENVBD_DEVICE_DATA xudd, ULONG i)
297 {
298 return RING_GET_RESPONSE(&xvdd->ring, i);
299 }
300 #endif
303 /*
304 EVT_WDF_DEVICE_PREPARE_HARDWARE XenUsb_EvtDevicePrepareHardware;
305 EVT_WDF_DEVICE_RELEASE_HARDWARE XenUsb_EvtDeviceReleaseHardware;
306 EVT_WDF_DEVICE_D0_ENTRY XenUsb_EvtDeviceD0Entry;
307 EVT_WDF_DEVICE_D0_ENTRY_POST_INTERRUPTS_ENABLED XenUsb_EvtDeviceD0EntryPostInterruptsEnabled;
308 EVT_WDF_DEVICE_D0_EXIT XenUsb_EvtDeviceD0Exit;
309 EVT_WDF_DEVICE_D0_EXIT_PRE_INTERRUPTS_DISABLED XenUsb_EvtDeviceD0ExitPreInterruptsDisabled;
310 EVT_WDF_DEVICE_QUERY_REMOVE XenUsb_EvtDeviceQueryRemove;
311 */
313 EVT_WDF_DRIVER_DEVICE_ADD XenUsb_EvtDriverDeviceAdd;
315 EVT_WDF_CHILD_LIST_CREATE_DEVICE XenUsb_EvtChildListCreateDevice;
316 EVT_WDF_CHILD_LIST_SCAN_FOR_CHILDREN XenUsb_EvtChildListScanForChildren;
318 VOID
319 XenUsb_EnumeratePorts(WDFDEVICE device);
321 EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL XenUsb_EvtIoInternalDeviceControl_DEVICE_SUBMIT_URB;
322 EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL XenUsb_EvtIoInternalDeviceControl_ROOTHUB_SUBMIT_URB;
324 NTSTATUS
325 XenUsb_ExecuteRequest(
326 PXENUSB_DEVICE_DATA xudd,
327 usbif_shadow_t *shadow,
328 PVOID transfer_buffer,
329 PMDL transfer_buffer_mdl,
330 ULONG transfer_buffer_length);
332 #endif