VirtualBox

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

Last change on this file since 99770 was 99739, checked in by vboxsync, 20 months ago

*: doxygen corrections (mostly about removing @returns from functions returning void).

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