VirtualBox

source: vbox/trunk/include/VBox/vusb.h@ 93914

Last change on this file since 93914 was 93914, checked in by vboxsync, 3 years ago

Devices/USB: Convert the HCI emulations to call into the roothub using the devices port instead of using the VUSBIDEVICE interface directly. This will avoid races when devices will get detached unexpectedly while being in use. Also move the device re-attach logic after a saved state operation down to the roothub in order to avoid code duplication, bugref:10196

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 49.2 KB
Line 
1/** @file
2 * VUSB - VirtualBox USB. (DEV,VMM)
3 */
4
5/*
6 * Copyright (C) 2006-2022 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef VBOX_INCLUDED_vusb_h
27#define VBOX_INCLUDED_vusb_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <VBox/cdefs.h>
33#include <VBox/types.h>
34#include <iprt/assert.h>
35
36struct PDMLED;
37
38RT_C_DECLS_BEGIN
39
40/** @defgroup grp_vusb VBox USB API
41 * @{
42 */
43
44/** @defgroup grp_vusb_std Standard Stuff
45 * @{ */
46
47/** Frequency of USB bus (from spec). */
48#define VUSB_BUS_HZ 12000000
49
50
51/** @name USB Descriptor types (from spec)
52 * @{ */
53#define VUSB_DT_DEVICE 0x01
54#define VUSB_DT_CONFIG 0x02
55#define VUSB_DT_STRING 0x03
56#define VUSB_DT_INTERFACE 0x04
57#define VUSB_DT_ENDPOINT 0x05
58#define VUSB_DT_DEVICE_QUALIFIER 0x06
59#define VUSB_DT_OTHER_SPEED_CFG 0x07
60#define VUSB_DT_INTERFACE_POWER 0x08
61#define VUSB_DT_INTERFACE_ASSOCIATION 0x0B
62#define VUSB_DT_BOS 0x0F
63#define VUSB_DT_DEVICE_CAPABILITY 0x10
64#define VUSB_DT_SS_ENDPOINT_COMPANION 0x30
65/** @} */
66
67/** @name USB Descriptor minimum sizes (from spec)
68 * @{ */
69#define VUSB_DT_DEVICE_MIN_LEN 18
70#define VUSB_DT_CONFIG_MIN_LEN 9
71#define VUSB_DT_CONFIG_STRING_MIN_LEN 2
72#define VUSB_DT_INTERFACE_MIN_LEN 9
73#define VUSB_DT_ENDPOINT_MIN_LEN 7
74#define VUSB_DT_SSEP_COMPANION_MIN_LEN 6
75/** @} */
76
77/** @name USB Device Capability Type Codes (from spec)
78 * @{ */
79#define VUSB_DCT_WIRELESS_USB 0x01
80#define VUSB_DCT_USB_20_EXTENSION 0x02
81#define VUSB_DCT_SUPERSPEED_USB 0x03
82#define VUSB_DCT_CONTAINER_ID 0x04
83/** @} */
84
85
86#pragma pack(1) /* ensure byte packing of the descriptors. */
87
88/**
89 * USB language id descriptor (from specs).
90 */
91typedef struct VUSBDESCLANGID
92{
93 uint8_t bLength;
94 uint8_t bDescriptorType;
95} VUSBDESCLANGID;
96/** Pointer to a USB language id descriptor. */
97typedef VUSBDESCLANGID *PVUSBDESCLANGID;
98/** Pointer to a const USB language id descriptor. */
99typedef const VUSBDESCLANGID *PCVUSBDESCLANGID;
100
101
102/**
103 * USB string descriptor (from specs).
104 */
105typedef struct VUSBDESCSTRING
106{
107 uint8_t bLength;
108 uint8_t bDescriptorType;
109} VUSBDESCSTRING;
110/** Pointer to a USB string descriptor. */
111typedef VUSBDESCSTRING *PVUSBDESCSTRING;
112/** Pointer to a const USB string descriptor. */
113typedef const VUSBDESCSTRING *PCVUSBDESCSTRING;
114
115
116/**
117 * USB device descriptor (from spec)
118 */
119typedef struct VUSBDESCDEVICE
120{
121 uint8_t bLength;
122 uint8_t bDescriptorType;
123 uint16_t bcdUSB;
124 uint8_t bDeviceClass;
125 uint8_t bDeviceSubClass;
126 uint8_t bDeviceProtocol;
127 uint8_t bMaxPacketSize0;
128 uint16_t idVendor;
129 uint16_t idProduct;
130 uint16_t bcdDevice;
131 uint8_t iManufacturer;
132 uint8_t iProduct;
133 uint8_t iSerialNumber;
134 uint8_t bNumConfigurations;
135} VUSBDESCDEVICE;
136/** Pointer to a USB device descriptor. */
137typedef VUSBDESCDEVICE *PVUSBDESCDEVICE;
138/** Pointer to a const USB device descriptor. */
139typedef const VUSBDESCDEVICE *PCVUSBDESCDEVICE;
140
141/**
142 * USB device qualifier (from spec 9.6.2)
143 */
144struct VUSBDEVICEQUALIFIER
145{
146 uint8_t bLength;
147 uint8_t bDescriptorType;
148 uint16_t bcdUsb;
149 uint8_t bDeviceClass;
150 uint8_t bDeviceSubClass;
151 uint8_t bDeviceProtocol;
152 uint8_t bMaxPacketSize0;
153 uint8_t bNumConfigurations;
154 uint8_t bReserved;
155};
156
157typedef struct VUSBDEVICEQUALIFIER VUSBDEVICEQUALIFIER;
158typedef VUSBDEVICEQUALIFIER *PVUSBDEVICEQUALIFIER;
159
160
161/**
162 * USB configuration descriptor (from spec).
163 */
164typedef struct VUSBDESCCONFIG
165{
166 uint8_t bLength;
167 uint8_t bDescriptorType;
168 uint16_t wTotalLength; /**< recalculated by VUSB when involved in URB. */
169 uint8_t bNumInterfaces;
170 uint8_t bConfigurationValue;
171 uint8_t iConfiguration;
172 uint8_t bmAttributes;
173 uint8_t MaxPower;
174} VUSBDESCCONFIG;
175/** Pointer to a USB configuration descriptor. */
176typedef VUSBDESCCONFIG *PVUSBDESCCONFIG;
177/** Pointer to a readonly USB configuration descriptor. */
178typedef const VUSBDESCCONFIG *PCVUSBDESCCONFIG;
179
180
181/**
182 * USB interface association descriptor (from USB ECN Interface Association Descriptors)
183 */
184typedef struct VUSBDESCIAD
185{
186 uint8_t bLength;
187 uint8_t bDescriptorType;
188 uint8_t bFirstInterface;
189 uint8_t bInterfaceCount;
190 uint8_t bFunctionClass;
191 uint8_t bFunctionSubClass;
192 uint8_t bFunctionProtocol;
193 uint8_t iFunction;
194} VUSBDESCIAD;
195/** Pointer to a USB interface association descriptor. */
196typedef VUSBDESCIAD *PVUSBDESCIAD;
197/** Pointer to a readonly USB interface association descriptor. */
198typedef const VUSBDESCIAD *PCVUSBDESCIAD;
199
200
201/**
202 * USB interface descriptor (from spec)
203 */
204typedef struct VUSBDESCINTERFACE
205{
206 uint8_t bLength;
207 uint8_t bDescriptorType;
208 uint8_t bInterfaceNumber;
209 uint8_t bAlternateSetting;
210 uint8_t bNumEndpoints;
211 uint8_t bInterfaceClass;
212 uint8_t bInterfaceSubClass;
213 uint8_t bInterfaceProtocol;
214 uint8_t iInterface;
215} VUSBDESCINTERFACE;
216/** Pointer to a USB interface descriptor. */
217typedef VUSBDESCINTERFACE *PVUSBDESCINTERFACE;
218/** Pointer to a const USB interface descriptor. */
219typedef const VUSBDESCINTERFACE *PCVUSBDESCINTERFACE;
220
221
222/**
223 * USB endpoint descriptor (from spec)
224 */
225typedef struct VUSBDESCENDPOINT
226{
227 uint8_t bLength;
228 uint8_t bDescriptorType;
229 uint8_t bEndpointAddress;
230 uint8_t bmAttributes;
231 uint16_t wMaxPacketSize;
232 uint8_t bInterval;
233} VUSBDESCENDPOINT;
234/** Pointer to a USB endpoint descriptor. */
235typedef VUSBDESCENDPOINT *PVUSBDESCENDPOINT;
236/** Pointer to a const USB endpoint descriptor. */
237typedef const VUSBDESCENDPOINT *PCVUSBDESCENDPOINT;
238
239
240/**
241 * USB SuperSpeed endpoint companion descriptor (from USB3 spec)
242 */
243typedef struct VUSBDESCSSEPCOMPANION
244{
245 uint8_t bLength;
246 uint8_t bDescriptorType;
247 uint8_t bMaxBurst;
248 uint8_t bmAttributes;
249 uint16_t wBytesPerInterval;
250} VUSBDESCSSEPCOMPANION;
251/** Pointer to a USB endpoint companion descriptor. */
252typedef VUSBDESCSSEPCOMPANION *PVUSBDESCSSEPCOMPANION;
253/** Pointer to a const USB endpoint companion descriptor. */
254typedef const VUSBDESCSSEPCOMPANION *PCVUSBDESCSSEPCOMPANION;
255
256
257/**
258 * USB Binary Device Object Store, aka BOS (from USB3 spec)
259 */
260typedef struct VUSBDESCBOS
261{
262 uint8_t bLength;
263 uint8_t bDescriptorType;
264 uint16_t wTotalLength;
265 uint8_t bNumDeviceCaps;
266} VUSBDESCBOS;
267/** Pointer to a USB BOS descriptor. */
268typedef VUSBDESCBOS *PVUSBDESCBOS;
269/** Pointer to a const USB BOS descriptor. */
270typedef const VUSBDESCBOS *PCVUSBDESCBOS;
271
272
273/**
274 * Generic USB Device Capability Descriptor within BOS (from USB3 spec)
275 */
276typedef struct VUSBDESCDEVICECAP
277{
278 uint8_t bLength;
279 uint8_t bDescriptorType;
280 uint8_t bDevCapabilityType;
281 uint8_t aCapSpecific[1];
282} VUSBDESCDEVICECAP;
283/** Pointer to a USB device capability descriptor. */
284typedef VUSBDESCDEVICECAP *PVUSBDESCDEVICECAP;
285/** Pointer to a const USB device capability descriptor. */
286typedef const VUSBDESCDEVICECAP *PCVUSBDESCDEVICECAP;
287
288
289/**
290 * SuperSpeed USB Device Capability Descriptor within BOS
291 */
292typedef struct VUSBDESCSSDEVCAP
293{
294 uint8_t bLength;
295 uint8_t bDescriptorType; /* DEVICE CAPABILITY */
296 uint8_t bDevCapabilityType; /* SUPERSPEED_USB */
297 uint8_t bmAttributes;
298 uint16_t wSpeedsSupported;
299 uint8_t bFunctionalitySupport;
300 uint8_t bU1DevExitLat;
301 uint16_t wU2DevExitLat;
302} VUSBDESCSSDEVCAP;
303/** Pointer to an SS USB device capability descriptor. */
304typedef VUSBDESCSSDEVCAP *PVUSBDESCSSDEVCAP;
305/** Pointer to a const SS USB device capability descriptor. */
306typedef const VUSBDESCSSDEVCAP *PCVUSBDESCSSDEVCAP;
307
308
309/**
310 * USB 2.0 Extension Descriptor within BOS
311 */
312typedef struct VUSBDESCUSB2EXT
313{
314 uint8_t bLength;
315 uint8_t bDescriptorType; /* DEVICE CAPABILITY */
316 uint8_t bDevCapabilityType; /* USB 2.0 EXTENSION */
317 uint8_t bmAttributes;
318} VUSBDESCUSB2EXT;
319/** Pointer to a USB 2.0 extension capability descriptor. */
320typedef VUSBDESCUSB2EXT *PVUSBDESCUSB2EXT;
321/** Pointer to a const USB 2.0 extension capability descriptor. */
322typedef const VUSBDESCUSB2EXT *PCVUSBDESCUSB2EXT;
323
324
325#pragma pack() /* end of the byte packing. */
326
327
328/**
329 * USB configuration descriptor, the parsed variant used by VUSB.
330 */
331typedef struct VUSBDESCCONFIGEX
332{
333 /** The USB descriptor data.
334 * @remark The wTotalLength member is recalculated before the data is passed to the guest. */
335 VUSBDESCCONFIG Core;
336 /** Pointer to additional descriptor bytes following what's covered by VUSBDESCCONFIG. */
337 void *pvMore;
338 /** Pointer to additional class- or vendor-specific interface descriptors. */
339 const void *pvClass;
340 /** Size of class- or vendor-specific descriptors. */
341 uint16_t cbClass;
342 /** Pointer to an array of the interfaces referenced in the configuration.
343 * Core.bNumInterfaces in size. */
344 const struct VUSBINTERFACE *paIfs;
345 /** Pointer to the original descriptor data read from the device. */
346 const void *pvOriginal;
347} VUSBDESCCONFIGEX;
348/** Pointer to a parsed USB configuration descriptor. */
349typedef VUSBDESCCONFIGEX *PVUSBDESCCONFIGEX;
350/** Pointer to a const parsed USB configuration descriptor. */
351typedef const VUSBDESCCONFIGEX *PCVUSBDESCCONFIGEX;
352
353
354/**
355 * For tracking the alternate interface settings of a configuration.
356 */
357typedef struct VUSBINTERFACE
358{
359 /** Pointer to an array of interfaces. */
360 const struct VUSBDESCINTERFACEEX *paSettings;
361 /** The number of entries in the array. */
362 uint32_t cSettings;
363} VUSBINTERFACE;
364/** Pointer to a VUSBINTERFACE. */
365typedef VUSBINTERFACE *PVUSBINTERFACE;
366/** Pointer to a const VUSBINTERFACE. */
367typedef const VUSBINTERFACE *PCVUSBINTERFACE;
368
369
370/**
371 * USB interface descriptor, the parsed variant used by VUSB.
372 */
373typedef struct VUSBDESCINTERFACEEX
374{
375 /** The USB descriptor data. */
376 VUSBDESCINTERFACE Core;
377 /** Pointer to additional descriptor bytes following what's covered by VUSBDESCINTERFACE. */
378 const void *pvMore;
379 /** Pointer to additional class- or vendor-specific interface descriptors. */
380 const void *pvClass;
381 /** Size of class- or vendor-specific descriptors. */
382 uint16_t cbClass;
383 /** Pointer to an array of the endpoints referenced by the interface.
384 * Core.bNumEndpoints in size. */
385 const struct VUSBDESCENDPOINTEX *paEndpoints;
386 /** Interface association descriptor, which prepends a group of interfaces,
387 * starting with this interface. */
388 PCVUSBDESCIAD pIAD;
389 /** Size of interface association descriptor. */
390 uint16_t cbIAD;
391} VUSBDESCINTERFACEEX;
392/** Pointer to an prased USB interface descriptor. */
393typedef VUSBDESCINTERFACEEX *PVUSBDESCINTERFACEEX;
394/** Pointer to a const parsed USB interface descriptor. */
395typedef const VUSBDESCINTERFACEEX *PCVUSBDESCINTERFACEEX;
396
397
398/**
399 * USB endpoint descriptor, the parsed variant used by VUSB.
400 */
401typedef struct VUSBDESCENDPOINTEX
402{
403 /** The USB descriptor data.
404 * @remark The wMaxPacketSize member is converted to native endian. */
405 VUSBDESCENDPOINT Core;
406 /** Pointer to additional descriptor bytes following what's covered by VUSBDESCENDPOINT. */
407 const void *pvMore;
408 /** Pointer to additional class- or vendor-specific endpoint descriptors. */
409 const void *pvClass;
410 /** Size of class- or vendor-specific descriptors. */
411 uint16_t cbClass;
412 /** Pointer to SuperSpeed endpoint companion descriptor (SS endpoints only). */
413 const void *pvSsepc;
414 /** Size of SuperSpeed endpoint companion descriptor.
415 * @remark Must be non-zero for SuperSpeed endpoints. */
416 uint16_t cbSsepc;
417} VUSBDESCENDPOINTEX;
418/** Pointer to a parsed USB endpoint descriptor. */
419typedef VUSBDESCENDPOINTEX *PVUSBDESCENDPOINTEX;
420/** Pointer to a const parsed USB endpoint descriptor. */
421typedef const VUSBDESCENDPOINTEX *PCVUSBDESCENDPOINTEX;
422
423
424/** @name USB Control message recipient codes (from spec)
425 * @{ */
426#define VUSB_TO_DEVICE 0x0
427#define VUSB_TO_INTERFACE 0x1
428#define VUSB_TO_ENDPOINT 0x2
429#define VUSB_TO_OTHER 0x3
430#define VUSB_RECIP_MASK 0x1f
431/** @} */
432
433/** @name USB control pipe setup packet structure (from spec)
434 * @{ */
435#define VUSB_REQ_SHIFT (5)
436#define VUSB_REQ_STANDARD (0x0 << VUSB_REQ_SHIFT)
437#define VUSB_REQ_CLASS (0x1 << VUSB_REQ_SHIFT)
438#define VUSB_REQ_VENDOR (0x2 << VUSB_REQ_SHIFT)
439#define VUSB_REQ_RESERVED (0x3 << VUSB_REQ_SHIFT)
440#define VUSB_REQ_MASK (0x3 << VUSB_REQ_SHIFT)
441/** @} */
442
443#define VUSB_DIR_TO_DEVICE 0x00
444#define VUSB_DIR_TO_HOST 0x80
445#define VUSB_DIR_MASK 0x80
446
447/**
448 * USB Setup request (from spec)
449 */
450typedef struct vusb_setup
451{
452 uint8_t bmRequestType;
453 uint8_t bRequest;
454 uint16_t wValue;
455 uint16_t wIndex;
456 uint16_t wLength;
457} VUSBSETUP;
458/** Pointer to a setup request. */
459typedef VUSBSETUP *PVUSBSETUP;
460/** Pointer to a const setup request. */
461typedef const VUSBSETUP *PCVUSBSETUP;
462
463/** @name USB Standard device requests (from spec)
464 * @{ */
465#define VUSB_REQ_GET_STATUS 0x00
466#define VUSB_REQ_CLEAR_FEATURE 0x01
467#define VUSB_REQ_SET_FEATURE 0x03
468#define VUSB_REQ_SET_ADDRESS 0x05
469#define VUSB_REQ_GET_DESCRIPTOR 0x06
470#define VUSB_REQ_SET_DESCRIPTOR 0x07
471#define VUSB_REQ_GET_CONFIGURATION 0x08
472#define VUSB_REQ_SET_CONFIGURATION 0x09
473#define VUSB_REQ_GET_INTERFACE 0x0a
474#define VUSB_REQ_SET_INTERFACE 0x0b
475#define VUSB_REQ_SYNCH_FRAME 0x0c
476#define VUSB_REQ_MAX 0x0d
477/** @} */
478
479/** @} */ /* end of grp_vusb_std */
480
481
482
483/** @name USB Standard version flags.
484 * @{ */
485/** Indicates USB 1.1 support. */
486#define VUSB_STDVER_11 RT_BIT(1)
487/** Indicates USB 2.0 support. */
488#define VUSB_STDVER_20 RT_BIT(2)
489/** Indicates USB 3.0 support. */
490#define VUSB_STDVER_30 RT_BIT(3)
491/** @} */
492
493/**
494 * USB port/device speeds.
495 */
496typedef enum VUSBSPEED
497{
498 /** Undetermined/unknown speed. */
499 VUSB_SPEED_UNKNOWN = 0,
500 /** Low-speed (LS), 1.5 Mbit/s, USB 1.0. */
501 VUSB_SPEED_LOW,
502 /** Full-speed (FS), 12 Mbit/s, USB 1.1. */
503 VUSB_SPEED_FULL,
504 /** High-speed (HS), 480 Mbit/s, USB 2.0. */
505 VUSB_SPEED_HIGH,
506 /** Variable speed, wireless USB 2.5. */
507 VUSB_SPEED_VARIABLE,
508 /** SuperSpeed (SS), 5.0 Gbit/s, USB 3.0. */
509 VUSB_SPEED_SUPER,
510 /** SuperSpeed+ (SS+), 10.0 Gbit/s, USB 3.1. */
511 VUSB_SPEED_SUPERPLUS,
512 /** The usual 32-bit hack. */
513 VUSB_SPEED_32BIT_HACK = 0x7fffffff
514} VUSBSPEED;
515
516/**
517 * VUSB transfer direction.
518 */
519typedef enum VUSBDIRECTION
520{
521 /** Setup */
522 VUSBDIRECTION_SETUP = 0,
523#define VUSB_DIRECTION_SETUP VUSBDIRECTION_SETUP
524 /** In - Device to host. */
525 VUSBDIRECTION_IN = 1,
526#define VUSB_DIRECTION_IN VUSBDIRECTION_IN
527 /** Out - Host to device. */
528 VUSBDIRECTION_OUT = 2,
529#define VUSB_DIRECTION_OUT VUSBDIRECTION_OUT
530 /** Invalid direction */
531 VUSBDIRECTION_INVALID = 0x7f
532} VUSBDIRECTION;
533
534/**
535 * VUSB Transfer types.
536 */
537typedef enum VUSBXFERTYPE
538{
539 /** Control message. Used to represent a single control transfer. */
540 VUSBXFERTYPE_CTRL = 0,
541 /* Isochronous transfer. */
542 VUSBXFERTYPE_ISOC,
543 /** Bulk transfer. */
544 VUSBXFERTYPE_BULK,
545 /** Interrupt transfer. */
546 VUSBXFERTYPE_INTR,
547 /** Complete control message. Used to represent an entire control message. */
548 VUSBXFERTYPE_MSG,
549 /** Invalid transfer type. */
550 VUSBXFERTYPE_INVALID = 0x7f
551} VUSBXFERTYPE;
552
553/** Number of valid USB transfer types - KEEP in sync with VUSBXFERTYPE!. */
554#define VUSBXFERTYPE_ELEMENTS (5)
555
556/** Pointer to a VBox USB device interface. */
557typedef struct VUSBIDEVICE *PVUSBIDEVICE;
558
559/** Pointer to a VUSB RootHub port interface. */
560typedef struct VUSBIROOTHUBPORT *PVUSBIROOTHUBPORT;
561
562/** Pointer to an USB request descriptor. */
563typedef struct VUSBURB *PVUSBURB;
564
565
566/**
567 * VUSB device reset completion callback function.
568 * This is called by the reset thread when the reset has been completed.
569 *
570 * @param pDevice Pointer to the virtual USB device core.
571 * @param uPort The port of the device which completed the reset.
572 * @param rc The VBox status code of the reset operation.
573 * @param pvUser User specific argument.
574 *
575 * @thread The reset thread or EMT.
576 */
577typedef DECLCALLBACKTYPE(void, FNVUSBRESETDONE,(PVUSBIDEVICE pDevice, uint32_t uPort, int rc, void *pvUser));
578/** Pointer to a device reset completion callback function (FNUSBRESETDONE). */
579typedef FNVUSBRESETDONE *PFNVUSBRESETDONE;
580
581
582/**
583 * The state of a VUSB Device.
584 *
585 * @remark The order of these states is vital.
586 */
587typedef enum VUSBDEVICESTATE
588{
589 VUSB_DEVICE_STATE_INVALID = 0,
590 VUSB_DEVICE_STATE_DETACHED,
591 VUSB_DEVICE_STATE_ATTACHED,
592 VUSB_DEVICE_STATE_POWERED,
593 VUSB_DEVICE_STATE_DEFAULT,
594 VUSB_DEVICE_STATE_ADDRESS,
595 VUSB_DEVICE_STATE_CONFIGURED,
596 VUSB_DEVICE_STATE_SUSPENDED,
597 /** The device is being reset. Don't mess with it.
598 * Next states: VUSB_DEVICE_STATE_DEFAULT, VUSB_DEVICE_STATE_DESTROYED
599 */
600 VUSB_DEVICE_STATE_RESET,
601 /** The device has been destroyed. */
602 VUSB_DEVICE_STATE_DESTROYED,
603 /** The usual 32-bit hack. */
604 VUSB_DEVICE_STATE_32BIT_HACK = 0x7fffffff
605} VUSBDEVICESTATE;
606
607
608/** Maximum number of USB devices supported. */
609#define VUSB_DEVICES_MAX 128
610/** An invalid device port. */
611#define VUSB_DEVICE_PORT_INVALID UINT32_MAX
612
613/**
614 * VBox USB port bitmap.
615 *
616 * Bit 0 == Port 0, ... , Bit 127 == Port 127.
617 */
618typedef struct VUSBPORTBITMAP
619{
620 /** 128 bits */
621 char ach[VUSB_DEVICES_MAX / 8];
622} VUSBPORTBITMAP;
623/** Pointer to a VBox USB port bitmap. */
624typedef VUSBPORTBITMAP *PVUSBPORTBITMAP;
625AssertCompile(sizeof(VUSBPORTBITMAP) * 8 >= VUSB_DEVICES_MAX);
626
627#ifndef RDESKTOP
628
629/**
630 * The VUSB RootHub port interface provided by the HCI (down).
631 * Pair with VUSBIROOTCONNECTOR
632 */
633typedef struct VUSBIROOTHUBPORT
634{
635 /**
636 * Get the number of available ports in the hub.
637 *
638 * @returns The number of ports available.
639 * @param pInterface Pointer to this structure.
640 * @param pAvailable Bitmap indicating the available ports. Set bit == available port.
641 */
642 DECLR3CALLBACKMEMBER(unsigned, pfnGetAvailablePorts,(PVUSBIROOTHUBPORT pInterface, PVUSBPORTBITMAP pAvailable));
643
644 /**
645 * Gets the supported USB versions.
646 *
647 * @returns The mask of supported USB versions.
648 * @param pInterface Pointer to this structure.
649 */
650 DECLR3CALLBACKMEMBER(uint32_t, pfnGetUSBVersions,(PVUSBIROOTHUBPORT pInterface));
651
652 /**
653 * A device is being attached to a port in the roothub.
654 *
655 * @param pInterface Pointer to this structure.
656 * @param uPort The port number assigned to the device.
657 * @param enmSpeed The speed of the device being attached.
658 */
659 DECLR3CALLBACKMEMBER(int, pfnAttach,(PVUSBIROOTHUBPORT pInterface, uint32_t uPort, VUSBSPEED enmSpeed));
660
661 /**
662 * A device is being detached from a port in the roothub.
663 *
664 * @param pInterface Pointer to this structure.
665 * @param uPort The port number assigned to the device.
666 */
667 DECLR3CALLBACKMEMBER(void, pfnDetach,(PVUSBIROOTHUBPORT pInterface, uint32_t uPort));
668
669 /**
670 * Reset the root hub.
671 *
672 * @returns VBox status code.
673 * @param pInterface Pointer to this structure.
674 * @param fResetOnLinux Whether or not to do real reset on linux.
675 */
676 DECLR3CALLBACKMEMBER(int, pfnReset,(PVUSBIROOTHUBPORT pInterface, bool fResetOnLinux));
677
678 /**
679 * Transfer completion callback routine.
680 *
681 * VUSB will call this when a transfer have been completed
682 * in a one or another way.
683 *
684 * @param pInterface Pointer to this structure.
685 * @param pUrb Pointer to the URB in question.
686 */
687 DECLR3CALLBACKMEMBER(void, pfnXferCompletion,(PVUSBIROOTHUBPORT pInterface, PVUSBURB pUrb));
688
689 /**
690 * Handle transfer errors.
691 *
692 * VUSB calls this when a transfer attempt failed. This function will respond
693 * indicating whether to retry or complete the URB with failure.
694 *
695 * @returns Retry indicator.
696 * @param pInterface Pointer to this structure.
697 * @param pUrb Pointer to the URB in question.
698 */
699 DECLR3CALLBACKMEMBER(bool, pfnXferError,(PVUSBIROOTHUBPORT pInterface, PVUSBURB pUrb));
700
701 /**
702 * Processes a new frame if periodic frame processing is enabled.
703 *
704 * @returns Flag whether there was activity which influences the frame rate.
705 * @param pInterface Pointer to this structure.
706 * @param u32FrameNo The frame number.
707 */
708 DECLR3CALLBACKMEMBER(bool, pfnStartFrame, (PVUSBIROOTHUBPORT pInterface, uint32_t u32FrameNo));
709
710 /**
711 * Informs the callee about a change in the frame rate due to too many idle cycles or
712 * when seeing activity after some idle time.
713 *
714 * @returns nothing.
715 * @param pInterface Pointer to this structure.
716 * @param u32FrameRate The new frame rate.
717 */
718 DECLR3CALLBACKMEMBER(void, pfnFrameRateChanged, (PVUSBIROOTHUBPORT pInterface, uint32_t u32FrameRate));
719
720 /** Alignment dummy. */
721 RTR3PTR Alignment;
722
723} VUSBIROOTHUBPORT;
724/** VUSBIROOTHUBPORT interface ID. */
725# define VUSBIROOTHUBPORT_IID "2ece01c2-4dbf-4bd5-96ca-09fc14164cd4"
726
727/** Pointer to a VUSB RootHub connector interface. */
728typedef struct VUSBIROOTHUBCONNECTOR *PVUSBIROOTHUBCONNECTOR;
729/**
730 * The VUSB RootHub connector interface provided by the VBox USB RootHub driver
731 * (up).
732 * Pair with VUSBIROOTHUBPORT.
733 */
734typedef struct VUSBIROOTHUBCONNECTOR
735{
736 /**
737 * Sets the URB parameters for the caller.
738 *
739 * @returns VBox status code.
740 * @param pInterface Pointer to this struct.
741 * @param cbHci Size of the data private to the HCI for each URB when allocated.
742 * @param cbHciTd Size of one transfer descriptor. The number of transfer descriptors
743 * is given VUSBIROOTHUBCONNECTOR::pfnNewUrb for each URB to calculate the
744 * final amount of memory required for the TDs.
745 *
746 * @note This must be called before starting to allocate any URB or otherwise there will be no
747 * data available for the HCI.
748 */
749 DECLR3CALLBACKMEMBER(int, pfnSetUrbParams, (PVUSBIROOTHUBCONNECTOR pInterface, size_t cbHci, size_t cbHciTd));
750
751 /**
752 * Resets the roothub.
753 *
754 * @returns VBox status code.
755 * @param pInterface Pointer to this struct.
756 * @param fResetOnLinux Whether or not to do real reset on linux.
757 */
758 DECLR3CALLBACKMEMBER(int, pfnReset, (PVUSBIROOTHUBCONNECTOR pInterface, bool fResetOnLinux));
759
760 /**
761 * Powers on the roothub.
762 *
763 * @returns VBox status code.
764 * @param pInterface Pointer to this struct.
765 */
766 DECLR3CALLBACKMEMBER(int, pfnPowerOn, (PVUSBIROOTHUBCONNECTOR pInterface));
767
768 /**
769 * Power off the roothub.
770 *
771 * @returns VBox status code.
772 * @param pInterface Pointer to this struct.
773 */
774 DECLR3CALLBACKMEMBER(int, pfnPowerOff, (PVUSBIROOTHUBCONNECTOR pInterface));
775
776 /**
777 * Allocates a new URB for a transfer.
778 *
779 * Either submit using pfnSubmitUrb or free using VUSBUrbFree().
780 *
781 * @returns Pointer to a new URB.
782 * @returns NULL on failure - try again later.
783 * This will not fail if the device wasn't found. We'll fail it
784 * at submit time, since that makes the usage of this api simpler.
785 * @param pInterface Pointer to this struct.
786 * @param DstAddress The destination address of the URB.
787 * @param uPort Optional port of the device the URB is for, use VUSB_DEVICE_PORT_INVALID to indicate to use the destination address.
788 * @param enmType Type of the URB.
789 * @param enmDir Data transfer direction.
790 * @param cbData The amount of data space required.
791 * @param cTds The amount of TD space.
792 * @param pszTag Custom URB tag assigned by the caller, only for
793 * logged builds and optional.
794 *
795 * @note pDev should be NULL in most cases. The only useful case is for USB3 where
796 * it is required for the SET_ADDRESS request because USB3 uses unicast traffic.
797 */
798 DECLR3CALLBACKMEMBER(PVUSBURB, pfnNewUrb,(PVUSBIROOTHUBCONNECTOR pInterface, uint8_t DstAddress, uint32_t uPort,
799 VUSBXFERTYPE enmType, VUSBDIRECTION enmDir, uint32_t cbData, uint32_t cTds, const char *pszTag));
800
801 /**
802 * Free an URB not submitted yet.
803 *
804 * @returns VBox status code.
805 * @param pInterface Pointer to this struct.
806 * @param pUrb Pointer to the URB to free returned by VUSBIROOTHUBCONNECTOR::pfnNewUrb.
807 */
808 DECLR3CALLBACKMEMBER(int, pfnFreeUrb, (PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb));
809
810 /**
811 * Submits a URB for transfer.
812 * The transfer will do asynchronously if possible.
813 *
814 * @returns VBox status code.
815 * @param pInterface Pointer to this struct.
816 * @param pUrb Pointer to the URB returned by pfnNewUrb.
817 * The URB will be freed in case of failure.
818 * @param pLed Pointer to USB Status LED
819 */
820 DECLR3CALLBACKMEMBER(int, pfnSubmitUrb,(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb, struct PDMLED *pLed));
821
822 /**
823 * Call to service asynchronous URB completions in a polling fashion.
824 *
825 * Reaped URBs will be finished by calling the completion callback,
826 * thus there is no return code or input or anything from this function
827 * except for potential state changes elsewhere.
828 *
829 * @returns VINF_SUCCESS if no URBs are pending upon return.
830 * @returns VERR_TIMEOUT if one or more URBs are still in flight upon returning.
831 * @returns Other VBox status code.
832 *
833 * @param pInterface Pointer to this struct.
834 * @param uPort Port of the device to reap URBs on.
835 * @param cMillies Number of milliseconds to poll for completion.
836 */
837 DECLR3CALLBACKMEMBER(void, pfnReapAsyncUrbs,(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort, RTMSINTERVAL cMillies));
838
839 /**
840 * Cancels and completes - with CRC failure - all URBs queued on an endpoint.
841 * This is done in response to guest URB cancellation.
842 *
843 * @returns VBox status code.
844 * @param pInterface Pointer to this struct.
845 * @param pUrb Pointer to a previously submitted URB.
846 */
847 DECLR3CALLBACKMEMBER(int, pfnCancelUrbsEp,(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb));
848
849 /**
850 * Cancels and completes - with CRC failure - all in-flight async URBs.
851 * This is typically done before saving a state.
852 *
853 * @param pInterface Pointer to this struct.
854 */
855 DECLR3CALLBACKMEMBER(void, pfnCancelAllUrbs,(PVUSBIROOTHUBCONNECTOR pInterface));
856
857 /**
858 * Cancels and completes - with CRC failure - all URBs queued on an endpoint.
859 * This is done in response to a guest endpoint/pipe abort.
860 *
861 * @returns VBox status code.
862 * @param pInterface Pointer to this struct.
863 * @param uPort Port of the device.
864 * @param EndPt Endpoint number.
865 * @param enmDir Endpoint direction.
866 */
867 DECLR3CALLBACKMEMBER(int, pfnAbortEp,(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort, int EndPt, VUSBDIRECTION enmDir));
868
869 /**
870 * Attach the device to the root hub.
871 * The device must not be attached to any hub for this call to succeed.
872 *
873 * @returns VBox status code.
874 * @param pInterface Pointer to this struct.
875 * @param uPort Port of the device to attach.
876 */
877 DECLR3CALLBACKMEMBER(int, pfnAttachDevice,(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort));
878
879 /**
880 * Detach the device from the root hub.
881 * The device must already be attached for this call to succeed.
882 *
883 * @returns VBox status code.
884 * @param pInterface Pointer to this struct.
885 * @param uPort Port of the device to detach.
886 */
887 DECLR3CALLBACKMEMBER(int, pfnDetachDevice,(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort));
888
889 /**
890 * Sets periodic frame processing.
891 *
892 * @returns VBox status code.
893 * @param pInterface Pointer to this struct.
894 * @param uFrameRate The target frame rate in Hertz, 0 disables periodic frame processing.
895 * The real frame rate might be lower if there is no activity for a certain period or
896 * higher if there is a need for catching up with where the guest expects the device to be.
897 */
898 DECLR3CALLBACKMEMBER(int, pfnSetPeriodicFrameProcessing, (PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uFrameRate));
899
900 /**
901 * Returns the current frame rate for the periodic frame processing.
902 *
903 * @returns Frame rate for periodic frame processing.
904 * @retval 0 if disabled.
905 * @param pInterface Pointer to this struct.
906 */
907 DECLR3CALLBACKMEMBER(uint32_t, pfnGetPeriodicFrameRate, (PVUSBIROOTHUBCONNECTOR pInterface));
908
909 /**
910 * Updates the internally stored isochronous scheduling frame for a given
911 * endpoint and returns the delta between the current and previous frame.
912 *
913 * @returns Delta between currently and previously scheduled frame.
914 * @retval 0 if no previous frame was set.
915 * @param pInterface Pointer to this struct.
916 * @param uPort Port of the device.
917 * @param EndPt Endpoint number.
918 * @param enmDir Endpoint direction.
919 * @param uNewFrameID The frame ID of a new transfer.
920 * @param uBits The number of significant bits in frame ID.
921 */
922 DECLR3CALLBACKMEMBER(uint32_t, pfnUpdateIsocFrameDelta, (PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort,
923 int EndPt, VUSBDIRECTION enmDir, uint16_t uNewFrameID, uint8_t uBits));
924
925 /**
926 * Resets the device.
927 *
928 * Since a device reset shall take at least 10ms from the guest point of view,
929 * it must be performed asynchronously. We create a thread which performs this
930 * operation and ensures it will take at least 10ms.
931 *
932 * At times - like init - a synchronous reset is required, this can be done
933 * by passing NULL for pfnDone.
934 *
935 * -- internal stuff, move it --
936 * While the device is being reset it is in the VUSB_DEVICE_STATE_RESET state.
937 * On completion it will be in the VUSB_DEVICE_STATE_DEFAULT state if successful,
938 * or in the VUSB_DEVICE_STATE_DETACHED state if the rest failed.
939 * -- internal stuff, move it --
940 *
941 * @returns VBox status code.
942 * @param pInterface Pointer to this struct.
943 * @param uPort Port of the device to reset.
944 * @param fResetOnLinux Set if we can permit a real reset and a potential logical
945 * device reconnect on linux hosts.
946 * @param pfnDone Pointer to the completion routine. If NULL a synchronous
947 * reset is performed not respecting the 10ms.
948 * @param pvUser User argument to the completion routine.
949 * @param pVM The cross context VM structure. Required if pfnDone
950 * is not NULL.
951 */
952 DECLR3CALLBACKMEMBER(int, pfnDevReset,(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort, bool fResetOnLinux,
953 PFNVUSBRESETDONE pfnDone, void *pvUser, PVM pVM));
954
955 /**
956 * Powers on the device.
957 *
958 * @returns VBox status code.
959 * @param pInterface Pointer to this struct.
960 * @param uPort Port of the device to power on.
961 */
962 DECLR3CALLBACKMEMBER(int, pfnDevPowerOn,(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort));
963
964 /**
965 * Powers off the device.
966 *
967 * @returns VBox status code.
968 * @param pInterface Pointer to this struct.
969 * @param uPort Port of the device to power off.
970 */
971 DECLR3CALLBACKMEMBER(int, pfnDevPowerOff,(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort));
972
973 /**
974 * Get the state of the device.
975 *
976 * @returns Device state.
977 * @param pInterface Pointer to this struct.
978 * @param uPort Port of the device to get the state for.
979 */
980 DECLR3CALLBACKMEMBER(VUSBDEVICESTATE, pfnDevGetState,(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort));
981
982 /**
983 * Returns whether the device implements the saved state handlers
984 * and doesn't need to get detached.
985 *
986 * @returns true if the device supports saving the state, false otherwise.
987 * @param pInterface Pointer to this struct.
988 * @param uPort Port of the device to query saved state support for.
989 */
990 DECLR3CALLBACKMEMBER(bool, pfnDevIsSavedStateSupported,(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort));
991
992 /**
993 * Get the speed the device is operating at.
994 *
995 * @returns Device state.
996 * @param pInterface Pointer to this struct.
997 * @param uPort Port of the device to query the speed for.
998 */
999 DECLR3CALLBACKMEMBER(VUSBSPEED, pfnDevGetSpeed,(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort));
1000
1001} VUSBIROOTHUBCONNECTOR;
1002AssertCompileSizeAlignment(VUSBIROOTHUBCONNECTOR, 8);
1003/** VUSBIROOTHUBCONNECTOR interface ID. */
1004# define VUSBIROOTHUBCONNECTOR_IID "662d7822-b9c6-43b5-88b6-5d59f0106e46"
1005
1006
1007# ifdef IN_RING3
1008/** @copydoc VUSBIROOTHUBCONNECTOR::pfnSetUrbParams */
1009DECLINLINE(int) VUSBIRhSetUrbParams(PVUSBIROOTHUBCONNECTOR pInterface, size_t cbHci, size_t cbHciTd)
1010{
1011 return pInterface->pfnSetUrbParams(pInterface, cbHci, cbHciTd);
1012}
1013
1014/** @copydoc VUSBIROOTHUBCONNECTOR::pfnNewUrb */
1015DECLINLINE(PVUSBURB) VUSBIRhNewUrb(PVUSBIROOTHUBCONNECTOR pInterface, uint8_t DstAddress, uint32_t uPort,
1016 VUSBXFERTYPE enmType, VUSBDIRECTION enmDir, uint32_t cbData, uint32_t cTds, const char *pszTag)
1017{
1018 return pInterface->pfnNewUrb(pInterface, DstAddress, uPort, enmType, enmDir, cbData, cTds, pszTag);
1019}
1020
1021/** @copydoc VUSBIROOTHUBCONNECTOR::pfnFreeUrb */
1022DECLINLINE(int) VUSBIRhFreeUrb(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb)
1023{
1024 return pInterface->pfnFreeUrb(pInterface, pUrb);
1025}
1026
1027/** @copydoc VUSBIROOTHUBCONNECTOR::pfnSubmitUrb */
1028DECLINLINE(int) VUSBIRhSubmitUrb(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb, struct PDMLED *pLed)
1029{
1030 return pInterface->pfnSubmitUrb(pInterface, pUrb, pLed);
1031}
1032
1033/** @copydoc VUSBIROOTHUBCONNECTOR::pfnReapAsyncUrbs */
1034DECLINLINE(void) VUSBIRhReapAsyncUrbs(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort, RTMSINTERVAL cMillies)
1035{
1036 pInterface->pfnReapAsyncUrbs(pInterface, uPort, cMillies);
1037}
1038
1039/** @copydoc VUSBIROOTHUBCONNECTOR::pfnCancelAllUrbs */
1040DECLINLINE(void) VUSBIRhCancelAllUrbs(PVUSBIROOTHUBCONNECTOR pInterface)
1041{
1042 pInterface->pfnCancelAllUrbs(pInterface);
1043}
1044
1045/** @copydoc VUSBIROOTHUBCONNECTOR::pfnAttachDevice */
1046DECLINLINE(int) VUSBIRhAttachDevice(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort)
1047{
1048 return pInterface->pfnAttachDevice(pInterface, uPort);
1049}
1050
1051/** @copydoc VUSBIROOTHUBCONNECTOR::pfnDetachDevice */
1052DECLINLINE(int) VUSBIRhDetachDevice(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort)
1053{
1054 return pInterface->pfnDetachDevice(pInterface, uPort);
1055}
1056
1057/** @copydoc VUSBIROOTHUBCONNECTOR::pfnSetPeriodicFrameProcessing */
1058DECLINLINE(int) VUSBIRhSetPeriodicFrameProcessing(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uFrameRate)
1059{
1060 return pInterface->pfnSetPeriodicFrameProcessing(pInterface, uFrameRate);
1061}
1062
1063/** @copydoc VUSBIROOTHUBCONNECTOR::pfnGetPeriodicFrameRate */
1064DECLINLINE(uint32_t) VUSBIRhGetPeriodicFrameRate(PVUSBIROOTHUBCONNECTOR pInterface)
1065{
1066 return pInterface->pfnGetPeriodicFrameRate(pInterface);
1067}
1068
1069/** @copydoc VUSBIROOTHUBCONNECTOR::pfnDevReset */
1070DECLINLINE(int) VUSBIRhDevReset(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort, bool fResetOnLinux,
1071 PFNVUSBRESETDONE pfnDone, void *pvUser, PVM pVM)
1072{
1073 return pInterface->pfnDevReset(pInterface, uPort, fResetOnLinux, pfnDone, pvUser, pVM);
1074}
1075
1076/** @copydoc VUSBIROOTHUBCONNECTOR::pfnDevPowerOn */
1077DECLINLINE(int) VUSBIRhDevPowerOn(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort)
1078{
1079 return pInterface->pfnDevPowerOn(pInterface, uPort);
1080}
1081
1082/** @copydoc VUSBIROOTHUBCONNECTOR::pfnDevPowerOff */
1083DECLINLINE(int) VUSBIRhDevPowerOff(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort)
1084{
1085 return pInterface->pfnDevPowerOff(pInterface, uPort);
1086}
1087
1088/** @copydoc VUSBIROOTHUBCONNECTOR::pfnDevGetState */
1089DECLINLINE(VUSBDEVICESTATE) VUSBIRhDevGetState(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort)
1090{
1091 return pInterface->pfnDevGetState(pInterface, uPort);
1092}
1093
1094/** @copydoc VUSBIROOTHUBCONNECTOR::pfnDevGetState */
1095DECLINLINE(bool) VUSBIRhDevIsSavedStateSupported(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort)
1096{
1097 return pInterface->pfnDevIsSavedStateSupported(pInterface, uPort);
1098}
1099
1100/** @copydoc VUSBIROOTHUBCONNECTOR::pfnDevGetSpeed */
1101DECLINLINE(VUSBSPEED) VUSBIRhDevGetSpeed(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort)
1102{
1103 return pInterface->pfnDevGetSpeed(pInterface, uPort);
1104}
1105# endif /* IN_RING3 */
1106
1107#endif /* ! RDESKTOP */
1108
1109
1110#ifndef RDESKTOP
1111
1112/**
1113 * USB Device Interface (up).
1114 * No interface pair.
1115 */
1116typedef struct VUSBIDEVICE
1117{
1118 /**
1119 * Resets the device.
1120 *
1121 * Since a device reset shall take at least 10ms from the guest point of view,
1122 * it must be performed asynchronously. We create a thread which performs this
1123 * operation and ensures it will take at least 10ms.
1124 *
1125 * At times - like init - a synchronous reset is required, this can be done
1126 * by passing NULL for pfnDone.
1127 *
1128 * -- internal stuff, move it --
1129 * While the device is being reset it is in the VUSB_DEVICE_STATE_RESET state.
1130 * On completion it will be in the VUSB_DEVICE_STATE_DEFAULT state if successful,
1131 * or in the VUSB_DEVICE_STATE_DETACHED state if the rest failed.
1132 * -- internal stuff, move it --
1133 *
1134 * @returns VBox status code.
1135 * @param pInterface Pointer to this structure.
1136 * @param fResetOnLinux Set if we can permit a real reset and a potential logical
1137 * device reconnect on linux hosts.
1138 * @param pfnDone Pointer to the completion routine. If NULL a synchronous
1139 * reset is performed not respecting the 10ms.
1140 * @param pvUser User argument to the completion routine.
1141 * @param pVM The cross context VM structure. Required if pfnDone
1142 * is not NULL.
1143 */
1144 DECLR3CALLBACKMEMBER(int, pfnReset,(PVUSBIDEVICE pInterface, bool fResetOnLinux,
1145 PFNVUSBRESETDONE pfnDone, void *pvUser, PVM pVM));
1146
1147 /**
1148 * Powers on the device.
1149 *
1150 * @returns VBox status code.
1151 * @param pInterface Pointer to the device interface structure.
1152 */
1153 DECLR3CALLBACKMEMBER(int, pfnPowerOn,(PVUSBIDEVICE pInterface));
1154
1155 /**
1156 * Powers off the device.
1157 *
1158 * @returns VBox status code.
1159 * @param pInterface Pointer to the device interface structure.
1160 */
1161 DECLR3CALLBACKMEMBER(int, pfnPowerOff,(PVUSBIDEVICE pInterface));
1162
1163 /**
1164 * Get the state of the device.
1165 *
1166 * @returns Device state.
1167 * @param pInterface Pointer to the device interface structure.
1168 */
1169 DECLR3CALLBACKMEMBER(VUSBDEVICESTATE, pfnGetState,(PVUSBIDEVICE pInterface));
1170
1171 /**
1172 * Returns whether the device implements the saved state handlers
1173 * and doesn't need to get detached.
1174 *
1175 * @returns true if the device supports saving the state, false otherwise.
1176 * @param pInterface Pointer to the device interface structure.
1177 */
1178 DECLR3CALLBACKMEMBER(bool, pfnIsSavedStateSupported,(PVUSBIDEVICE pInterface));
1179
1180 /**
1181 * Get the speed the device is operating at.
1182 *
1183 * @returns Device state.
1184 * @param pInterface Pointer to the device interface structure.
1185 */
1186 DECLR3CALLBACKMEMBER(VUSBSPEED, pfnGetSpeed,(PVUSBIDEVICE pInterface));
1187
1188} VUSBIDEVICE;
1189/** VUSBIDEVICE interface ID. */
1190# define VUSBIDEVICE_IID "af576b38-e8ca-4db7-810a-2596d8d57ca0"
1191
1192
1193# ifdef IN_RING3
1194/**
1195 * Resets the device.
1196 *
1197 * Since a device reset shall take at least 10ms from the guest point of view,
1198 * it must be performed asynchronously. We create a thread which performs this
1199 * operation and ensures it will take at least 10ms.
1200 *
1201 * At times - like init - a synchronous reset is required, this can be done
1202 * by passing NULL for pfnDone.
1203 *
1204 * -- internal stuff, move it --
1205 * While the device is being reset it is in the VUSB_DEVICE_STATE_RESET state.
1206 * On completion it will be in the VUSB_DEVICE_STATE_DEFAULT state if successful,
1207 * or in the VUSB_DEVICE_STATE_DETACHED state if the rest failed.
1208 * -- internal stuff, move it --
1209 *
1210 * @returns VBox status code.
1211 * @param pInterface Pointer to the device interface structure.
1212 * @param fResetOnLinux Set if we can permit a real reset and a potential logical
1213 * device reconnect on linux hosts.
1214 * @param pfnDone Pointer to the completion routine. If NULL a
1215 * synchronous reset is performed not respecting the
1216 * 10ms.
1217 * @param pvUser User argument to the completion routine.
1218 * @param pVM The cross context VM structure. Required if pfnDone
1219 * is not NULL.
1220 *
1221 * NULL is acceptable Required if callback in EMT is desired, NULL is otherwise
1222 * acceptable.
1223 */
1224DECLINLINE(int) VUSBIDevReset(PVUSBIDEVICE pInterface, bool fResetOnLinux, PFNVUSBRESETDONE pfnDone, void *pvUser, PVM pVM)
1225{
1226 return pInterface->pfnReset(pInterface, fResetOnLinux, pfnDone, pvUser, pVM);
1227}
1228
1229/**
1230 * Powers on the device.
1231 *
1232 * @returns VBox status code.
1233 * @param pInterface Pointer to the device interface structure.
1234 */
1235DECLINLINE(int) VUSBIDevPowerOn(PVUSBIDEVICE pInterface)
1236{
1237 return pInterface->pfnPowerOn(pInterface);
1238}
1239
1240/**
1241 * Powers off the device.
1242 *
1243 * @returns VBox status code.
1244 * @param pInterface Pointer to the device interface structure.
1245 */
1246DECLINLINE(int) VUSBIDevPowerOff(PVUSBIDEVICE pInterface)
1247{
1248 return pInterface->pfnPowerOff(pInterface);
1249}
1250
1251/**
1252 * Get the state of the device.
1253 *
1254 * @returns Device state.
1255 * @param pInterface Pointer to the device interface structure.
1256 */
1257DECLINLINE(VUSBDEVICESTATE) VUSBIDevGetState(PVUSBIDEVICE pInterface)
1258{
1259 return pInterface->pfnGetState(pInterface);
1260}
1261
1262/**
1263 * @copydoc VUSBIDEVICE::pfnIsSavedStateSupported
1264 */
1265DECLINLINE(bool) VUSBIDevIsSavedStateSupported(PVUSBIDEVICE pInterface)
1266{
1267 return pInterface->pfnIsSavedStateSupported(pInterface);
1268}
1269# endif /* IN_RING3 */
1270
1271#endif /* ! RDESKTOP */
1272
1273/** @name URB
1274 * @{ */
1275
1276/**
1277 * VUSB Transfer status codes.
1278 */
1279typedef enum VUSBSTATUS
1280{
1281 /** Transer was ok. */
1282 VUSBSTATUS_OK = 0,
1283 /** Transfer stalled, endpoint halted. */
1284 VUSBSTATUS_STALL,
1285 /** Device not responding. */
1286 VUSBSTATUS_DNR,
1287 /** CRC error. */
1288 VUSBSTATUS_CRC,
1289 /** Data underrun error. */
1290 VUSBSTATUS_DATA_UNDERRUN,
1291 /** Data overrun error. */
1292 VUSBSTATUS_DATA_OVERRUN,
1293 /** The isochronous buffer hasn't been touched. */
1294 VUSBSTATUS_NOT_ACCESSED,
1295 /** Canceled/undone URB (VUSB internal). */
1296 VUSBSTATUS_UNDO,
1297 /** Canceled URB. */
1298 VUSBSTATUS_CANCELED,
1299 /** Invalid status. */
1300 VUSBSTATUS_INVALID = 0x7f
1301} VUSBSTATUS;
1302
1303
1304/**
1305 * The URB states
1306 */
1307typedef enum VUSBURBSTATE
1308{
1309 /** The usual invalid state. */
1310 VUSBURBSTATE_INVALID = 0,
1311 /** The URB is free, i.e. not in use.
1312 * Next state: ALLOCATED */
1313 VUSBURBSTATE_FREE,
1314 /** The URB is allocated, i.e. being prepared for submission.
1315 * Next state: FREE, IN_FLIGHT */
1316 VUSBURBSTATE_ALLOCATED,
1317 /** The URB is in flight.
1318 * Next state: REAPED, CANCELLED */
1319 VUSBURBSTATE_IN_FLIGHT,
1320 /** The URB has been reaped and is being completed.
1321 * Next state: FREE */
1322 VUSBURBSTATE_REAPED,
1323 /** The URB has been cancelled and is awaiting reaping and immediate freeing.
1324 * Next state: FREE */
1325 VUSBURBSTATE_CANCELLED,
1326 /** The end of the valid states (exclusive). */
1327 VUSBURBSTATE_END,
1328 /** The usual 32-bit blow up. */
1329 VUSBURBSTATE_32BIT_HACK = 0x7fffffff
1330} VUSBURBSTATE;
1331
1332
1333/**
1334 * Information about a isochronous packet.
1335 */
1336typedef struct VUSBURBISOCPKT
1337{
1338 /** The size of the packet.
1339 * IN: The packet size. I.e. the number of bytes to the next packet or end of buffer.
1340 * OUT: The actual size transferred. */
1341 uint32_t cb;
1342 /** The offset of the packet. (Relative to VUSBURB::abData[0].)
1343 * OUT: This can be changed by the USB device if it does some kind of buffer squeezing. */
1344 uint32_t off;
1345 /** The status of the transfer.
1346 * IN: VUSBSTATUS_INVALID
1347 * OUT: VUSBSTATUS_INVALID if nothing was done, otherwise the correct status. */
1348 VUSBSTATUS enmStatus;
1349} VUSBURBISOCPKT;
1350/** Pointer to a isochronous packet. */
1351typedef VUSBURBISOCPKT *PVUSBURBISOCPTK;
1352/** Pointer to a const isochronous packet. */
1353typedef const VUSBURBISOCPKT *PCVUSBURBISOCPKT;
1354
1355/** Private controller emulation specific data for the associated USB request descriptor. */
1356typedef struct VUSBURBHCIINT *PVUSBURBHCI;
1357/** Private controller emulation specific TD data. */
1358typedef struct VUSBURBHCITDINT *PVUSBURBHCITD;
1359/** Private VUSB/roothub related state for the associated URB. */
1360typedef struct VUSBURBVUSBINT *PVUSBURBVUSB;
1361
1362/**
1363 * Asynchronous USB request descriptor
1364 */
1365typedef struct VUSBURB
1366{
1367 /** URB magic value. */
1368 uint32_t u32Magic;
1369 /** The USR state. */
1370 VUSBURBSTATE enmState;
1371 /** Flag whether the URB is about to be completed,
1372 * either by the I/O thread or the cancellation worker.
1373 */
1374 volatile bool fCompleting;
1375 /** URB description, can be null. intended for logging. */
1376 char *pszDesc;
1377
1378#ifdef RDESKTOP
1379 /** The next URB in rdesktop-vrdp's linked list */
1380 PVUSBURB pNext;
1381 /** The previous URB in rdesktop-vrdp's linked list */
1382 PVUSBURB pPrev;
1383 /** The vrdp handle for the URB */
1384 uint32_t handle;
1385 /** Pointer used to find the usb proxy device */
1386 struct VUSBDEV *pDev;
1387#endif
1388
1389 /** The VUSB stack private data. */
1390 PVUSBURBVUSB pVUsb;
1391 /** Private host controller data associated with this URB. */
1392 PVUSBURBHCI pHci;
1393 /** Pointer to the host controller transfer descriptor array. */
1394 PVUSBURBHCITD paTds;
1395
1396 /** The device data. */
1397 struct VUSBURBDEV
1398 {
1399 /** Pointer to private device specific data. */
1400 void *pvPrivate;
1401 /** Used by the device when linking the URB in some list of its own. */
1402 PVUSBURB pNext;
1403 } Dev;
1404
1405 /** The device address.
1406 * This is set at allocation time. */
1407 uint8_t DstAddress;
1408
1409 /** The endpoint.
1410 * IN: Must be set before submitting the URB.
1411 * @remark This does not have the high bit (direction) set! */
1412 uint8_t EndPt;
1413 /** The transfer type.
1414 * IN: Set at allocation time. */
1415 VUSBXFERTYPE enmType;
1416 /** The transfer direction.
1417 * IN: Set at allocation time. */
1418 VUSBDIRECTION enmDir;
1419 /** Indicates whether it is OK to receive/send less data than requested.
1420 * IN: Must be initialized before submitting the URB. */
1421 bool fShortNotOk;
1422 /** The transfer status.
1423 * OUT: This is set when reaping the URB. */
1424 VUSBSTATUS enmStatus;
1425
1426 /** The relative starting frame for isochronous transfers.
1427 * Zero indicates "transfer ASAP".
1428 * This is ignored when enmType isn't VUSBXFERTYPE_ISOC. */
1429 uint16_t uStartFrameDelta;
1430 /** Flag indicating whether the start frame delta is relative
1431 * to the previous transfer (false) or now (true).
1432 * This is ignored when enmType isn't VUSBXFERTYPE_ISOC. */
1433 bool fStartRelToNow;
1434 /** The number of isochronous packets describe in aIsocPkts.
1435 * This is ignored when enmType isn't VUSBXFERTYPE_ISOC. */
1436 uint8_t cIsocPkts;
1437 /** The iso packets within abData.
1438 * This is ignored when enmType isn't VUSBXFERTYPE_ISOC. */
1439 VUSBURBISOCPKT aIsocPkts[8];
1440
1441 /** The message length.
1442 * IN: The amount of data to send / receive - set at allocation time.
1443 * OUT: The amount of data sent / received. */
1444 uint32_t cbData;
1445 /** The message data.
1446 * IN: On host to device transfers, the data to send.
1447 * OUT: On device to host transfers, the data to received.
1448 * This array has actually a size of VUsb.cbDataAllocated, not 8KB! */
1449 uint8_t abData[8*_1K];
1450} VUSBURB;
1451
1452/** The magic value of a valid VUSBURB. (Murakami Haruki) */
1453#define VUSBURB_MAGIC UINT32_C(0x19490112)
1454
1455/** @} */
1456
1457
1458/** @} */
1459
1460RT_C_DECLS_END
1461
1462#endif /* !VBOX_INCLUDED_vusb_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette