win-pvdrivers

view xenusb/xenusb.h @ 874:f5a973a8a10b

Handle shadow entries in dump mode that were created in normal mode when crashing
author James Harper <james.harper@bendigoit.com.au>
date Fri Mar 11 12:38:07 2011 +1100 (2011-03-11)
parents bbc6c94b9621
children 3aa213de2a31
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 <io/xenbus.h>
48 #include <usb.h>
49 #include <usbioctl.h>
50 #include <usbdlib.h>
51 #include <hubbusif.h>
52 #include <usbbusif.h>
54 #define C_HUB_LOCAL_POWER 0
55 #define C_HUB_OVER_CURRENT 1
56 #define PORT_CONNECTION 0
57 #define PORT_ENABLE 1
58 #define PORT_SUSPEND 2
59 #define PORT_OVER_CURRENT 3
60 #define PORT_RESET 4
61 #define PORT_POWER 8
62 #define PORT_LOW_SPEED 9
63 #define PORT_HIGH_SPEED 9
64 #define C_PORT_CONNECTION 16
65 #define C_PORT_ENABLE 17
66 #define C_PORT_SUSPEND 18
67 #define C_PORT_OVER_CURRENT 19
68 #define C_PORT_RESET 20
69 #define PORT_TEST 21
70 #define PORT_INDICATOR 22
72 #define XENUSB_POOL_TAG (ULONG)'XenU'
74 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
76 #define CHILD_STATE_EMPTY 0
77 #define CHILD_STATE_DELETED 1
78 #define CHILD_STATE_ADDED 2
80 #define LINUX_PIPE_DIRECTION_OUT 0x00000000
81 #define LINUX_PIPE_DIRECTION_IN 0x00000080
83 /* these are linux definitions - different to usb standard */
84 #define LINUX_PIPE_TYPE_ISOC 0x00000000
85 #define LINUX_PIPE_TYPE_INTR 0x40000000
86 #define LINUX_PIPE_TYPE_CTRL 0x80000000
87 #define LINUX_PIPE_TYPE_BULK 0xC0000000
89 /*
90 * urb->transfer_flags:
91 */
92 #define LINUX_URB_SHORT_NOT_OK 0x0001 /* report short reads as errors */
93 #define LINUX_URB_ISO_ASAP 0x0002 /* iso-only, urb->start_frame ignored */
94 #define LINUX_URB_NO_TRANSFER_DMA_MAP 0x0004 /* urb->transfer_dma valid on submit */
95 #define LINUX_URB_NO_SETUP_DMA_MAP 0x0008 /* urb->setup_dma valid on submit */
96 #define LINUX_URB_NO_FSBR 0x0020 /* UHCI-specific */
97 #define LINUX_URB_ZERO_PACKET 0x0040 /* Finish bulk OUT with short packet */
98 #define LINUX_URB_NO_INTERRUPT 0x0080 /* HINT: no non-error interrupt needed */
102 struct _usbif_shadow;
103 typedef struct _usbif_shadow usbif_shadow_t;
105 struct _usbif_shadow {
106 uint16_t id;
107 union
108 {
109 struct {
110 WDFREQUEST request;
111 PURB urb;
112 };
113 KEVENT event;
114 };
115 WDFDMATRANSACTION dma_transaction;
116 PMDL mdl;
117 ULONG total_length;
118 /* called at DISPATCH_LEVEL */
119 VOID (*callback)(usbif_shadow_t *);
120 usbif_urb_request_t req;
121 usbif_urb_response_t rsp;
122 usbif_shadow_t *next; /* for gathering shadows from the ring for callback */
123 };
125 #define MAX_SHADOW_ENTRIES 64
126 #define SHADOW_ENTRIES min(MAX_SHADOW_ENTRIES, USB_URB_RING_SIZE)
128 struct _xenusb_endpoint_t;
129 struct _xenusb_interface_t;
130 struct _xenusb_config_t;
131 struct _xenusb_device_t;
132 typedef struct _xenusb_endpoint_t xenusb_endpoint_t, *pxenusb_endpoint_t;
133 typedef struct _xenusb_interface_t xenusb_interface_t;
134 typedef struct _xenusb_config_t xenusb_config_t;
135 typedef struct _xenusb_device_t xenusb_device_t;
137 typedef struct _xenusb_endpoint_t {
138 xenusb_interface_t *interface;
139 ULONG pipe_value;
140 WDFTIMER interrupt_timer;
141 WDFQUEUE interrupt_queue;
142 WDFSPINLOCK interrupt_lock;
143 USB_ENDPOINT_DESCRIPTOR endpoint_descriptor;
144 };
145 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(pxenusb_endpoint_t, GetEndpoint)
147 typedef struct _xenusb_interface_t {
148 //ULONG pipe_value;
149 xenusb_config_t *config;
150 USB_INTERFACE_DESCRIPTOR interface_descriptor;
151 xenusb_endpoint_t *endpoints[0];
152 } xenusb_interface_t;
154 typedef struct _xenusb_config_t {
155 xenusb_device_t *device;
156 USB_CONFIGURATION_DESCRIPTOR config_descriptor;
157 xenusb_interface_t *interfaces[0];
158 } xenusb_config_t;
160 typedef struct _xenusb_device_t {
161 WDFDEVICE pdo_device;
162 UCHAR address;
163 USB_DEVICE_DESCRIPTOR device_descriptor;
164 ULONG port_number;
165 WDFQUEUE urb_queue;
166 USB_DEVICE_SPEED device_speed;
167 USB_DEVICE_TYPE device_type;
168 xenusb_config_t *active_config;
169 xenusb_interface_t *active_interface;
170 xenusb_config_t **configs; /* pointer to an array of configs */
171 } xenusb_device_t;
173 #define USB_PORT_TYPE_NOT_CONNECTED 0
174 #define USB_PORT_TYPE_LOW_SPEED 1
175 #define USB_PORT_TYPE_FULL_SPEED 2
176 #define USB_PORT_TYPE_HIGH_SPEED 3
178 typedef struct
179 {
180 ULONG port_number;
181 ULONG port_type;
182 USHORT port_status;
183 USHORT port_change;
184 } xenusb_port_t;
186 typedef struct {
187 BOOLEAN XenBus_ShuttingDown;
188 WDFQUEUE io_queue;
189 WDFDMAENABLER dma_enabler;
191 WDFCHILDLIST child_list;
193 WDFDEVICE root_hub_device;
195 usbif_shadow_t shadows[MAX_SHADOW_ENTRIES];
196 USHORT shadow_free_list[MAX_SHADOW_ENTRIES];
197 USHORT shadow_free;
199 PUCHAR config_page;
201 /* protected by conn_ring_lock */
202 ULONG num_ports;
203 xenusb_port_t ports[32];
205 KSPIN_LOCK urb_ring_lock;
206 usbif_urb_sring_t *urb_sring;
207 usbif_urb_front_ring_t urb_ring;
209 KSPIN_LOCK conn_ring_lock;
210 usbif_conn_sring_t *conn_sring;
211 usbif_conn_front_ring_t conn_ring;
213 evtchn_port_t event_channel;
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 EVT_WDF_DRIVER_DEVICE_ADD XenUsb_EvtDriverDeviceAdd;
316 EVT_WDF_CHILD_LIST_CREATE_DEVICE XenUsb_EvtChildListCreateDevice;
317 EVT_WDF_CHILD_LIST_SCAN_FOR_CHILDREN XenUsb_EvtChildListScanForChildren;
319 VOID
320 XenUsb_EnumeratePorts(WDFDEVICE device);
322 EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL XenUsb_EvtIoInternalDeviceControl_DEVICE_SUBMIT_URB;
323 EVT_WDF_IO_QUEUE_IO_INTERNAL_DEVICE_CONTROL XenUsb_EvtIoInternalDeviceControl_ROOTHUB_SUBMIT_URB;
325 NTSTATUS
326 XenUsb_ExecuteRequest(
327 PXENUSB_DEVICE_DATA xudd,
328 usbif_shadow_t *shadow,
329 PVOID transfer_buffer,
330 PMDL transfer_buffer_mdl,
331 ULONG transfer_buffer_length);
333 #endif