VirtualBox

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

Last change on this file since 26471 was 26471, checked in by vboxsync, 15 years ago

VUSB: Provide a way to store and pass along vendor/class-specific descriptors embedded in device or endpoint descriptors.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 33.0 KB
Line 
1/** @file
2 * VUSB - VirtualBox USB. (DEV,VMM)
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___VBox_vusb_h
31#define ___VBox_vusb_h
32
33#include <VBox/cdefs.h>
34#include <VBox/types.h>
35
36RT_C_DECLS_BEGIN
37
38/** @defgroup grp_vusb VBox USB API
39 * @{
40 */
41
42/** @defgroup grp_vusb_std Standard Stuff
43 * @{ */
44
45/** Frequency of USB bus (from spec). */
46#define VUSB_BUS_HZ 12000000
47
48
49/** @name USB Descriptor types (from spec)
50 * @{ */
51#define VUSB_DT_DEVICE 0x01
52#define VUSB_DT_CONFIG 0x02
53#define VUSB_DT_STRING 0x03
54#define VUSB_DT_INTERFACE 0x04
55#define VUSB_DT_ENDPOINT 0x05
56#define VUSB_DT_DEVICE_QUALIFIER 0x06
57#define VUSB_DT_OTHER_SPEED_CFG 0x07
58#define VUSB_DT_INTERFACE_POWER 0x08
59/** @} */
60
61/** @name USB Descriptor minimum sizes (from spec)
62 * @{ */
63#define VUSB_DT_DEVICE_MIN_LEN 18
64#define VUSB_DT_CONFIG_MIN_LEN 9
65#define VUSB_DT_CONFIG_STRING_MIN_LEN 2
66#define VUSB_DT_INTERFACE_MIN_LEN 9
67#define VUSB_DT_ENDPOINT_MIN_LEN 7
68/** @} */
69
70
71#pragma pack(1) /* ensure byte packing of the descriptors. */
72
73/**
74 * USB language id descriptor (from specs).
75 */
76typedef struct VUSBDESCLANGID
77{
78 uint8_t bLength;
79 uint8_t bDescriptorType;
80} VUSBDESCLANGID;
81/** Pointer to a USB language id descriptor. */
82typedef VUSBDESCLANGID *PVUSBDESCLANGID;
83/** Pointer to a const USB language id descriptor. */
84typedef const VUSBDESCLANGID *PCVUSBDESCLANGID;
85
86
87/**
88 * USB string descriptor (from specs).
89 */
90typedef struct VUSBDESCSTRING
91{
92 uint8_t bLength;
93 uint8_t bDescriptorType;
94} VUSBDESCSTRING;
95/** Pointer to a USB string descriptor. */
96typedef VUSBDESCSTRING *PVUSBDESCSTRING;
97/** Pointer to a const USB string descriptor. */
98typedef const VUSBDESCSTRING *PCVUSBDESCSTRING;
99
100
101/**
102 * USB device descriptor (from spec)
103 */
104typedef struct VUSBDESCDEVICE
105{
106 uint8_t bLength;
107 uint8_t bDescriptorType;
108 uint16_t bcdUSB;
109 uint8_t bDeviceClass;
110 uint8_t bDeviceSubClass;
111 uint8_t bDeviceProtocol;
112 uint8_t bMaxPacketSize0;
113 uint16_t idVendor;
114 uint16_t idProduct;
115 uint16_t bcdDevice;
116 uint8_t iManufacturer;
117 uint8_t iProduct;
118 uint8_t iSerialNumber;
119 uint8_t bNumConfigurations;
120} VUSBDESCDEVICE;
121/** Pointer to a USB device descriptor. */
122typedef VUSBDESCDEVICE *PVUSBDESCDEVICE;
123/** Pointer to a const USB device descriptor. */
124typedef const VUSBDESCDEVICE *PCVUSBDESCDEVICE;
125
126
127/**
128 * USB configuration descriptor (from spec).
129 */
130typedef struct VUSBDESCCONFIG
131{
132 uint8_t bLength;
133 uint8_t bDescriptorType;
134 uint16_t wTotalLength; /**< recalculated by VUSB when involved in URB. */
135 uint8_t bNumInterfaces;
136 uint8_t bConfigurationValue;
137 uint8_t iConfiguration;
138 uint8_t bmAttributes;
139 uint8_t MaxPower;
140} VUSBDESCCONFIG;
141/** Pointer to a USB configuration descriptor. */
142typedef VUSBDESCCONFIG *PVUSBDESCCONFIG;
143/** Pointer to a readonly USB configuration descriptor. */
144typedef const VUSBDESCCONFIG *PCVUSBDESCCONFIG;
145
146
147/**
148 * USB interface descriptor (from spec)
149 */
150typedef struct VUSBDESCINTERFACE
151{
152 uint8_t bLength;
153 uint8_t bDescriptorType;
154 uint8_t bInterfaceNumber;
155 uint8_t bAlternateSetting;
156 uint8_t bNumEndpoints;
157 uint8_t bInterfaceClass;
158 uint8_t bInterfaceSubClass;
159 uint8_t bInterfaceProtocol;
160 uint8_t iInterface;
161} VUSBDESCINTERFACE;
162/** Pointer to an USB interface descriptor. */
163typedef VUSBDESCINTERFACE *PVUSBDESCINTERFACE;
164/** Pointer to a const USB interface descriptor. */
165typedef const VUSBDESCINTERFACE *PCVUSBDESCINTERFACE;
166
167
168/**
169 * USB endpoint descriptor (from spec)
170 */
171typedef struct VUSBDESCENDPOINT
172{
173 uint8_t bLength;
174 uint8_t bDescriptorType;
175 uint8_t bEndpointAddress;
176 uint8_t bmAttributes;
177 uint16_t wMaxPacketSize;
178 uint8_t bInterval;
179} VUSBDESCENDPOINT;
180/** Pointer to an USB endpoint descriptor. */
181typedef VUSBDESCENDPOINT *PVUSBDESCENDPOINT;
182/** Pointer to a const USB endpoint descriptor. */
183typedef const VUSBDESCENDPOINT *PCVUSBDESCENDPOINT;
184
185#pragma pack() /* end of the byte packing. */
186
187
188/**
189 * USB configuration descriptor, the parsed variant used by VUSB.
190 */
191typedef struct VUSBDESCCONFIGEX
192{
193 /** The USB descriptor data.
194 * @remark The wTotalLength member is recalculated before the data is passed to the guest. */
195 VUSBDESCCONFIG Core;
196 /** Pointer to additional descriptor bytes following what's covered by VUSBDESCCONFIG. */
197 void *pvMore;
198 /** Pointer to an array of the interfaces referenced in the configuration.
199 * Core.bNumInterfaces in size. */
200 const struct VUSBINTERFACE *paIfs;
201} VUSBDESCCONFIGEX;
202/** Pointer to a parsed USB configuration descriptor. */
203typedef VUSBDESCCONFIGEX *PVUSBDESCCONFIGEX;
204/** Pointer to a const parsed USB configuration descriptor. */
205typedef const VUSBDESCCONFIGEX *PCVUSBDESCCONFIGEX;
206
207
208/**
209 * For tracking the alternate interface settings of a configuration.
210 */
211typedef struct VUSBINTERFACE
212{
213 /** Pointer to an array of interfaces. */
214 const struct VUSBDESCINTERFACEEX *paSettings;
215 /** The number of entries in the array. */
216 uint32_t cSettings;
217} VUSBINTERFACE;
218/** Pointer to a VUSBINTERFACE. */
219typedef VUSBINTERFACE *PVUSBINTERFACE;
220/** Pointer to a const VUSBINTERFACE. */
221typedef const VUSBINTERFACE *PCVUSBINTERFACE;
222
223
224/**
225 * USB interface descriptor, the parsed variant used by VUSB.
226 */
227typedef struct VUSBDESCINTERFACEEX
228{
229 /** The USB descriptor data. */
230 VUSBDESCINTERFACE Core;
231 /** Pointer to additional descriptor bytes following what's covered by VUSBDESCINTERFACE. */
232 const void *pvMore;
233 /** Pointer to additional class- or vendor-specific interface descriptors. */
234 const void *pvClass;
235 /** Size of class- or vendor-specific descriptors. */
236 uint16_t cbClass;
237 /** Pointer to an array of the endpoints referenced by the interface.
238 * Core.bNumEndpoints in size. */
239 const struct VUSBDESCENDPOINTEX *paEndpoints;
240} VUSBDESCINTERFACEEX;
241/** Pointer to an prased USB interface descriptor. */
242typedef VUSBDESCINTERFACEEX *PVUSBDESCINTERFACEEX;
243/** Pointer to a const parsed USB interface descriptor. */
244typedef const VUSBDESCINTERFACEEX *PCVUSBDESCINTERFACEEX;
245
246
247/**
248 * USB endpoint descriptor, the parsed variant used by VUSB.
249 */
250typedef struct VUSBDESCENDPOINTEX
251{
252 /** The USB descriptor data.
253 * @remark The wMaxPacketSize member is converted to native endian. */
254 VUSBDESCENDPOINT Core;
255 /** Pointer to additional descriptor bytes following what's covered by VUSBDESCENDPOINT. */
256 const void *pvMore;
257 /** Pointer to additional class- or vendor-specific interface descriptors. */
258 const void *pvClass;
259 /** Size of class- or vendor-specific descriptors. */
260 uint16_t cbClass;
261} VUSBDESCENDPOINTEX;
262/** Pointer to a parsed USB endpoint descriptor. */
263typedef VUSBDESCENDPOINTEX *PVUSBDESCENDPOINTEX;
264/** Pointer to a const parsed USB endpoint descriptor. */
265typedef const VUSBDESCENDPOINTEX *PCVUSBDESCENDPOINTEX;
266
267
268/** @name USB Control message recipient codes (from spec)
269 * @{ */
270#define VUSB_TO_DEVICE 0x0
271#define VUSB_TO_INTERFACE 0x1
272#define VUSB_TO_ENDPOINT 0x2
273#define VUSB_TO_OTHER 0x3
274#define VUSB_RECIP_MASK 0x1f
275/** @} */
276
277/** @name USB control pipe setup packet structure (from spec)
278 * @{ */
279#define VUSB_REQ_SHIFT (5)
280#define VUSB_REQ_STANDARD (0x0 << VUSB_REQ_SHIFT)
281#define VUSB_REQ_CLASS (0x1 << VUSB_REQ_SHIFT)
282#define VUSB_REQ_VENDOR (0x2 << VUSB_REQ_SHIFT)
283#define VUSB_REQ_RESERVED (0x3 << VUSB_REQ_SHIFT)
284#define VUSB_REQ_MASK (0x3 << VUSB_REQ_SHIFT)
285/** @} */
286
287#define VUSB_DIR_TO_DEVICE 0x00
288#define VUSB_DIR_TO_HOST 0x80
289#define VUSB_DIR_MASK 0x80
290
291/**
292 * USB Setup request (from spec)
293 */
294typedef struct vusb_setup
295{
296 uint8_t bmRequestType;
297 uint8_t bRequest;
298 uint16_t wValue;
299 uint16_t wIndex;
300 uint16_t wLength;
301} VUSBSETUP;
302/** Pointer to a setup request. */
303typedef VUSBSETUP *PVUSBSETUP;
304/** Pointer to a const setup request. */
305typedef const VUSBSETUP *PCVUSBSETUP;
306
307/** @name USB Standard device requests (from spec)
308 * @{ */
309#define VUSB_REQ_GET_STATUS 0x00
310#define VUSB_REQ_CLEAR_FEATURE 0x01
311#define VUSB_REQ_SET_FEATURE 0x03
312#define VUSB_REQ_SET_ADDRESS 0x05
313#define VUSB_REQ_GET_DESCRIPTOR 0x06
314#define VUSB_REQ_SET_DESCRIPTOR 0x07
315#define VUSB_REQ_GET_CONFIGURATION 0x08
316#define VUSB_REQ_SET_CONFIGURATION 0x09
317#define VUSB_REQ_GET_INTERFACE 0x0a
318#define VUSB_REQ_SET_INTERFACE 0x0b
319#define VUSB_REQ_SYNCH_FRAME 0x0c
320#define VUSB_REQ_MAX 0x0d
321/** @} */
322
323/** @} */ /* end of grp_vusb_std */
324
325
326
327/** @name USB Standard version flags.
328 * @{ */
329/** Indicates USB 1.1 support. */
330#define VUSB_STDVER_11 RT_BIT(1)
331/** Indicates USB 2.0 support. */
332#define VUSB_STDVER_20 RT_BIT(2)
333/** @} */
334
335
336/** Pointer to a VBox USB device interface. */
337typedef struct VUSBIDEVICE *PVUSBIDEVICE;
338
339/** Pointer to a VUSB RootHub port interface. */
340typedef struct VUSBIROOTHUBPORT *PVUSBIROOTHUBPORT;
341
342/** Pointer to an USB request descriptor. */
343typedef struct VUSBURB *PVUSBURB;
344
345
346
347/**
348 * VBox USB port bitmap.
349 *
350 * Bit 0 == Port 0, ... , Bit 127 == Port 127.
351 */
352typedef struct VUSBPORTBITMAP
353{
354 /** 128 bits */
355 char ach[16];
356} VUSBPORTBITMAP;
357/** Pointer to a VBox USB port bitmap. */
358typedef VUSBPORTBITMAP *PVUSBPORTBITMAP;
359
360
361/**
362 * The VUSB RootHub port interface provided by the HCI (down).
363 * Pair with VUSBIROOTCONNECTOR
364 */
365typedef struct VUSBIROOTHUBPORT
366{
367 /**
368 * Get the number of avilable ports in the hub.
369 *
370 * @returns The number of ports available.
371 * @param pInterface Pointer to this structure.
372 * @param pAvailable Bitmap indicating the available ports. Set bit == available port.
373 */
374 DECLR3CALLBACKMEMBER(unsigned, pfnGetAvailablePorts,(PVUSBIROOTHUBPORT pInterface, PVUSBPORTBITMAP pAvailable));
375
376 /**
377 * Gets the supported USB versions.
378 *
379 * @returns The mask of supported USB versions.
380 * @param pInterface Pointer to this structure.
381 */
382 DECLR3CALLBACKMEMBER(uint32_t, pfnGetUSBVersions,(PVUSBIROOTHUBPORT pInterface));
383
384 /**
385 * A device is being attached to a port in the roothub.
386 *
387 * @param pInterface Pointer to this structure.
388 * @param pDev Pointer to the device being attached.
389 * @param uPort The port number assigned to the device.
390 */
391 DECLR3CALLBACKMEMBER(int, pfnAttach,(PVUSBIROOTHUBPORT pInterface, PVUSBIDEVICE pDev, unsigned uPort));
392
393 /**
394 * A device is being detached from a port in the roothub.
395 *
396 * @param pInterface Pointer to this structure.
397 * @param pDev Pointer to the device being detached.
398 * @param uPort The port number assigned to the device.
399 */
400 DECLR3CALLBACKMEMBER(void, pfnDetach,(PVUSBIROOTHUBPORT pInterface, PVUSBIDEVICE pDev, unsigned uPort));
401
402 /**
403 * Reset the root hub.
404 *
405 * @returns VBox status code.
406 * @param pInterface Pointer to this structure.
407 * @param pResetOnLinux Whether or not to do real reset on linux.
408 */
409 DECLR3CALLBACKMEMBER(int, pfnReset,(PVUSBIROOTHUBPORT pInterface, bool fResetOnLinux));
410
411 /**
412 * Transfer completion callback routine.
413 *
414 * VUSB will call this when a transfer have been completed
415 * in a one or another way.
416 *
417 * @param pInterface Pointer to this structure.
418 * @param pUrb Pointer to the URB in question.
419 */
420 DECLR3CALLBACKMEMBER(void, pfnXferCompletion,(PVUSBIROOTHUBPORT pInterface, PVUSBURB urb));
421
422 /**
423 * Handle transfer errors.
424 *
425 * VUSB calls this when a transfer attempt failed. This function will respond
426 * indicating wheter to retry or complete the URB with failure.
427 *
428 * @returns Retry indicator.
429 * @param pInterface Pointer to this structure.
430 * @param pUrb Pointer to the URB in question.
431 */
432 DECLR3CALLBACKMEMBER(bool, pfnXferError,(PVUSBIROOTHUBPORT pInterface, PVUSBURB pUrb));
433
434 /** Alignment dummy. */
435 RTR3PTR Alignment;
436
437} VUSBIROOTHUBPORT;
438/** VUSBIROOTHUBPORT interface ID. */
439#define VUSBIROOTHUBPORT_IID "e38e2978-7aa2-4860-94b6-9ef4a066d8a0"
440
441
442/** Pointer to a VUSB RootHub connector interface. */
443typedef struct VUSBIROOTHUBCONNECTOR *PVUSBIROOTHUBCONNECTOR;
444/**
445 * The VUSB RootHub connector interface provided by the VBox USB RootHub driver
446 * (up).
447 * Pair with VUSBIROOTHUBPORT.
448 */
449typedef struct VUSBIROOTHUBCONNECTOR
450{
451 /**
452 * Allocates a new URB for a transfer.
453 *
454 * Either submit using pfnSubmitUrb or free using VUSBUrbFree().
455 *
456 * @returns Pointer to a new URB.
457 * @returns NULL on failure - try again later.
458 * This will not fail if the device wasn't found. We'll fail it
459 * at submit time, since that makes the usage of this api simpler.
460 * @param pInterface Pointer to this struct.
461 * @param DstAddress The destination address of the URB.
462 * @param cbData The amount of data space required.
463 * @param cTds The amount of TD space.
464 */
465 DECLR3CALLBACKMEMBER(PVUSBURB, pfnNewUrb,(PVUSBIROOTHUBCONNECTOR pInterface, uint8_t DstAddress, uint32_t cbData, uint32_t cTds));
466
467 /**
468 * Submits a URB for transfer.
469 * The transfer will do asynchronously if possible.
470 *
471 * @returns VBox status code.
472 * @param pInterface Pointer to this struct.
473 * @param pUrb Pointer to the URB returned by pfnNewUrb.
474 * The URB will be freed in case of failure.
475 * @param pLed Pointer to USB Status LED
476 */
477 DECLR3CALLBACKMEMBER(int, pfnSubmitUrb,(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb, struct PDMLED *pLed));
478
479 /**
480 * Call to service asynchronous URB completions in a polling fashion.
481 *
482 * Reaped URBs will be finished by calling the completion callback,
483 * thus there is no return code or input or anything from this function
484 * except for potential state changes elsewhere.
485 *
486 * @returns VINF_SUCCESS if no URBs are pending upon return.
487 * @returns VERR_TIMEOUT if one or more URBs are still in flight upon returning.
488 * @returns Other VBox status code.
489 *
490 * @param pInterface Pointer to this struct.
491 * @param cMillies Number of milliseconds to poll for completion.
492 */
493 DECLR3CALLBACKMEMBER(void, pfnReapAsyncUrbs,(PVUSBIROOTHUBCONNECTOR pInterface, RTMSINTERVAL cMillies));
494
495 /**
496 * Cancels and completes - with CRC failure - all in-flight async URBs.
497 * This is typically done before saving a state.
498 *
499 * @param pInterface Pointer to this struct.
500 */
501 DECLR3CALLBACKMEMBER(void, pfnCancelAllUrbs,(PVUSBIROOTHUBCONNECTOR pInterface));
502
503 /**
504 * Attach the device to the root hub.
505 * The device must not be attached to any hub for this call to succeed.
506 *
507 * @returns VBox status code.
508 * @param pInterface Pointer to this struct.
509 * @param pDevice Pointer to the device (interface) attach.
510 */
511 DECLR3CALLBACKMEMBER(int, pfnAttachDevice,(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice));
512
513 /**
514 * Detach the device from the root hub.
515 * The device must already be attached for this call to succeed.
516 *
517 * @returns VBox status code.
518 * @param pInterface Pointer to this struct.
519 * @param pDevice Pointer to the device (interface) to detach.
520 */
521 DECLR3CALLBACKMEMBER(int, pfnDetachDevice,(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice));
522
523} VUSBIROOTHUBCONNECTOR;
524/** VUSBIROOTHUBCONNECTOR interface ID. */
525#define VUSBIROOTHUBCONNECTOR_IID "d9a90c59-e3ff-4dff-9754-844557c3f7a0"
526
527
528#ifdef IN_RING3
529/** @copydoc VUSBIROOTHUBCONNECTOR::pfnNewUrb */
530DECLINLINE(PVUSBURB) VUSBIRhNewUrb(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t DstAddress, uint32_t cbData, uint32_t cTds)
531{
532 return pInterface->pfnNewUrb(pInterface, DstAddress, cbData, cTds);
533}
534
535/** @copydoc VUSBIROOTHUBCONNECTOR::pfnSubmitUrb */
536DECLINLINE(int) VUSBIRhSubmitUrb(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb, struct PDMLED *pLed)
537{
538 return pInterface->pfnSubmitUrb(pInterface, pUrb, pLed);
539}
540
541/** @copydoc VUSBIROOTHUBCONNECTOR::pfnReapAsyncUrbs */
542DECLINLINE(void) VUSBIRhReapAsyncUrbs(PVUSBIROOTHUBCONNECTOR pInterface, RTMSINTERVAL cMillies)
543{
544 pInterface->pfnReapAsyncUrbs(pInterface, cMillies);
545}
546
547/** @copydoc VUSBIROOTHUBCONNECTOR::pfnCancelAllUrbs */
548DECLINLINE(void) VUSBIRhCancelAllUrbs(PVUSBIROOTHUBCONNECTOR pInterface)
549{
550 pInterface->pfnCancelAllUrbs(pInterface);
551}
552
553/** @copydoc VUSBIROOTHUBCONNECTOR::pfnAttachDevice */
554DECLINLINE(int) VUSBIRhAttachDevice(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice)
555{
556 return pInterface->pfnAttachDevice(pInterface, pDevice);
557}
558
559/** @copydoc VUSBIROOTHUBCONNECTOR::pfnDetachDevice */
560DECLINLINE(int) VUSBIRhDetachDevice(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice)
561{
562 return pInterface->pfnDetachDevice(pInterface, pDevice);
563}
564#endif /* IN_RING3 */
565
566
567
568/** Pointer to a Root Hub Configuration Interface. */
569typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
570/**
571 * Root Hub Configuration Interface (intended for MAIN).
572 * No interface pair.
573 */
574typedef struct VUSBIRHCONFIG
575{
576 /**
577 * Creates a USB proxy device and attaches it to the root hub.
578 *
579 * @returns VBox status code.
580 * @param pInterface Pointer to the root hub configuration interface structure.
581 * @param pUuid Pointer to the UUID for the new device.
582 * @param fRemote Whether the device must use the VRDP backend.
583 * @param pszAddress OS specific device address.
584 * @param pvBackend An opaque pointer for the backend. Only used by
585 * the VRDP backend so far.
586 */
587 DECLR3CALLBACKMEMBER(int, pfnCreateProxyDevice,(PVUSBIRHCONFIG pInterface, PCRTUUID pUuid, bool fRemote, const char *pszAddress, void *pvBackend));
588
589 /**
590 * Removes a USB proxy device from the root hub and destroys it.
591 *
592 * @returns VBox status code.
593 * @param pInterface Pointer to the root hub configuration interface structure.
594 * @param pUuid Pointer to the UUID for the device.
595 */
596 DECLR3CALLBACKMEMBER(int, pfnDestroyProxyDevice,(PVUSBIRHCONFIG pInterface, PCRTUUID pUuid));
597
598} VUSBIRHCONFIG;
599/** VUSBIRHCONFIG interface ID. */
600#define VUSBIRHCONFIG_IID "c354cd97-e85f-465e-bc12-b58798465f52"
601
602
603#ifdef IN_RING3
604/** @copydoc VUSBIRHCONFIG::pfnCreateProxyDevice */
605DECLINLINE(int) VUSBIRhCreateProxyDevice(PVUSBIRHCONFIG pInterface, PCRTUUID pUuid, bool fRemote, const char *pszAddress, void *pvBackend)
606{
607 return pInterface->pfnCreateProxyDevice(pInterface, pUuid, fRemote, pszAddress, pvBackend);
608}
609
610/** @copydoc VUSBIRHCONFIG::pfnDestroyProxyDevice */
611DECLINLINE(int) VUSBIRhDestroyProxyDevice(PVUSBIRHCONFIG pInterface, PCRTUUID pUuid)
612{
613 return pInterface->pfnDestroyProxyDevice(pInterface, pUuid);
614}
615#endif /* IN_RING3 */
616
617
618
619/**
620 * VUSB device reset completion callback function.
621 * This is called by the reset thread when the reset has been completed.
622 *
623 * @param pDev Pointer to the virtual USB device core.
624 * @param rc The VBox status code of the reset operation.
625 * @param pvUser User specific argument.
626 *
627 * @thread The reset thread or EMT.
628 */
629typedef DECLCALLBACK(void) FNVUSBRESETDONE(PVUSBIDEVICE pDevice, int rc, void *pvUser);
630/** Pointer to a device reset completion callback function (FNUSBRESETDONE). */
631typedef FNVUSBRESETDONE *PFNVUSBRESETDONE;
632
633/**
634 * The state of a VUSB Device.
635 *
636 * @remark The order of these states is vital.
637 */
638typedef enum VUSBDEVICESTATE
639{
640 VUSB_DEVICE_STATE_INVALID = 0,
641 VUSB_DEVICE_STATE_DETACHED,
642 VUSB_DEVICE_STATE_ATTACHED,
643 VUSB_DEVICE_STATE_POWERED,
644 VUSB_DEVICE_STATE_DEFAULT,
645 VUSB_DEVICE_STATE_ADDRESS,
646 VUSB_DEVICE_STATE_CONFIGURED,
647 VUSB_DEVICE_STATE_SUSPENDED,
648 /** The device is being reset. Don't mess with it.
649 * Next states: VUSB_DEVICE_STATE_DEFAULT, VUSB_DEVICE_STATE_DESTROYED
650 */
651 VUSB_DEVICE_STATE_RESET,
652 /** The device has been destroy. */
653 VUSB_DEVICE_STATE_DESTROYED,
654 /** The usual 32-bit hack. */
655 VUSB_DEVICE_STATE_32BIT_HACK = 0x7fffffff
656} VUSBDEVICESTATE;
657
658
659/**
660 * USB Device Interface (up).
661 * No interface pair.
662 */
663typedef struct VUSBIDEVICE
664{
665 /**
666 * Resets the device.
667 *
668 * Since a device reset shall take at least 10ms from the guest point of view,
669 * it must be performed asynchronously. We create a thread which performs this
670 * operation and ensures it will take at least 10ms.
671 *
672 * At times - like init - a synchronous reset is required, this can be done
673 * by passing NULL for pfnDone.
674 *
675 * -- internal stuff, move it --
676 * While the device is being reset it is in the VUSB_DEVICE_STATE_RESET state.
677 * On completion it will be in the VUSB_DEVICE_STATE_DEFAULT state if successful,
678 * or in the VUSB_DEVICE_STATE_DETACHED state if the rest failed.
679 * -- internal stuff, move it --
680 *
681 * @returns VBox status code.
682 * @param pInterface Pointer to this structure.
683 * @param fResetOnLinux Set if we can permit a real reset and a potential logical
684 * device reconnect on linux hosts.
685 * @param pfnDone Pointer to the completion routine. If NULL a synchronous
686 * reset is preformed not respecting the 10ms.
687 * @param pvUser User argument to the completion routine.
688 * @param pVM Pointer to the VM handle if callback in EMT is required. (optional)
689 */
690 DECLR3CALLBACKMEMBER(int, pfnReset,(PVUSBIDEVICE pInterface, bool fResetOnLinux,
691 PFNVUSBRESETDONE pfnDone, void *pvUser, PVM pVM));
692
693 /**
694 * Powers on the device.
695 *
696 * @returns VBox status code.
697 * @param pInterface Pointer to the device interface structure.
698 */
699 DECLR3CALLBACKMEMBER(int, pfnPowerOn,(PVUSBIDEVICE pInterface));
700
701 /**
702 * Powers off the device.
703 *
704 * @returns VBox status code.
705 * @param pInterface Pointer to the device interface structure.
706 */
707 DECLR3CALLBACKMEMBER(int, pfnPowerOff,(PVUSBIDEVICE pInterface));
708
709 /**
710 * Get the state of the device.
711 *
712 * @returns Device state.
713 * @param pInterface Pointer to the device interface structure.
714 */
715 DECLR3CALLBACKMEMBER(VUSBDEVICESTATE, pfnGetState,(PVUSBIDEVICE pInterface));
716
717} VUSBIDEVICE;
718/** VUSBIDEVICE interface ID. */
719#define VUSBIDEVICE_IID "88732dd3-0ccd-4625-b040-48804ac7a217"
720
721
722#ifdef IN_RING3
723/**
724 * Resets the device.
725 *
726 * Since a device reset shall take at least 10ms from the guest point of view,
727 * it must be performed asynchronously. We create a thread which performs this
728 * operation and ensures it will take at least 10ms.
729 *
730 * At times - like init - a synchronous reset is required, this can be done
731 * by passing NULL for pfnDone.
732 *
733 * -- internal stuff, move it --
734 * While the device is being reset it is in the VUSB_DEVICE_STATE_RESET state.
735 * On completion it will be in the VUSB_DEVICE_STATE_DEFAULT state if successful,
736 * or in the VUSB_DEVICE_STATE_DETACHED state if the rest failed.
737 * -- internal stuff, move it --
738 *
739 * @returns VBox status code.
740 * @param pInterface Pointer to the device interface structure.
741 * @param fResetOnLinux Set if we can permit a real reset and a potential logical
742 * device reconnect on linux hosts.
743 * @param pfnDone Pointer to the completion routine. If NULL a synchronous
744 * reset is preformed not respecting the 10ms.
745 * @param pvUser User argument to the completion routine.
746 * @param pVM Pointer to the VM handle if callback in EMT is required. (optional)
747 */
748DECLINLINE(int) VUSBIDevReset(PVUSBIDEVICE pInterface, bool fResetOnLinux, PFNVUSBRESETDONE pfnDone, void *pvUser, PVM pVM)
749{
750 return pInterface->pfnReset(pInterface, fResetOnLinux, pfnDone, pvUser, pVM);
751}
752
753/**
754 * Powers on the device.
755 *
756 * @returns VBox status code.
757 * @param pInterface Pointer to the device interface structure.
758 */
759DECLINLINE(int) VUSBIDevPowerOn(PVUSBIDEVICE pInterface)
760{
761 return pInterface->pfnPowerOn(pInterface);
762}
763
764/**
765 * Powers off the device.
766 *
767 * @returns VBox status code.
768 * @param pInterface Pointer to the device interface structure.
769 */
770DECLINLINE(int) VUSBIDevPowerOff(PVUSBIDEVICE pInterface)
771{
772 return pInterface->pfnPowerOff(pInterface);
773}
774
775/**
776 * Get the state of the device.
777 *
778 * @returns Device state.
779 * @param pInterface Pointer to the device interface structure.
780 */
781DECLINLINE(VUSBDEVICESTATE) VUSBIDevGetState(PVUSBIDEVICE pInterface)
782{
783 return pInterface->pfnGetState(pInterface);
784}
785#endif /* IN_RING3 */
786
787
788/** @name URB
789 * @{ */
790
791/**
792 * VUSB Transfer status codes.
793 */
794typedef enum VUSBSTATUS
795{
796 /** Transer was ok. */
797 VUSBSTATUS_OK = 0,
798 /** Transfer stalled, endpoint halted. */
799 VUSBSTATUS_STALL,
800 /** Device not responding. */
801 VUSBSTATUS_DNR,
802 /** CRC error. */
803 VUSBSTATUS_CRC,
804 /** Data overrun error. */
805 VUSBSTATUS_DATA_UNDERRUN,
806 /** Data overrun error. */
807 VUSBSTATUS_DATA_OVERRUN,
808 /** The isochronous buffer hasn't been touched. */
809 VUSBSTATUS_NOT_ACCESSED,
810 /** Invalid status. */
811 VUSBSTATUS_INVALID = 0x7f
812} VUSBSTATUS;
813
814
815/**
816 * VUSB Transfer types.
817 */
818typedef enum VUSBXFERTYPE
819{
820 /** Control message. Used to represent a single control transfer. */
821 VUSBXFERTYPE_CTRL = 0,
822 /* Isochronous transfer. */
823 VUSBXFERTYPE_ISOC,
824 /** Bulk transfer. */
825 VUSBXFERTYPE_BULK,
826 /** Interrupt transfer. */
827 VUSBXFERTYPE_INTR,
828 /** Complete control message. Used to represent an entire control message. */
829 VUSBXFERTYPE_MSG,
830 /** Invalid transfer type. */
831 VUSBXFERTYPE_INVALID = 0x7f
832} VUSBXFERTYPE;
833
834
835/**
836 * VUSB transfer direction.
837 */
838typedef enum VUSBDIRECTION
839{
840 /** Setup */
841 VUSBDIRECTION_SETUP = 0,
842#define VUSB_DIRECTION_SETUP VUSBDIRECTION_SETUP
843 /** In - Device to host. */
844 VUSBDIRECTION_IN = 1,
845#define VUSB_DIRECTION_IN VUSBDIRECTION_IN
846 /** Out - Host to device. */
847 VUSBDIRECTION_OUT = 2,
848#define VUSB_DIRECTION_OUT VUSBDIRECTION_OUT
849 /** Invalid direction */
850 VUSBDIRECTION_INVALID = 0x7f
851} VUSBDIRECTION;
852
853/**
854 * The URB states
855 */
856typedef enum VUSBURBSTATE
857{
858 /** The usual invalid state. */
859 VUSBURBSTATE_INVALID = 0,
860 /** The URB is free, i.e. not in use.
861 * Next state: ALLOCATED */
862 VUSBURBSTATE_FREE,
863 /** The URB is allocated, i.e. being prepared for submission.
864 * Next state: FREE, IN_FLIGHT */
865 VUSBURBSTATE_ALLOCATED,
866 /** The URB is in flight.
867 * Next state: REAPED, CANCELLED */
868 VUSBURBSTATE_IN_FLIGHT,
869 /** The URB has been reaped and is being completed.
870 * Next state: FREE */
871 VUSBURBSTATE_REAPED,
872 /** The URB has been cancelled and is awaiting reaping and immediate freeing.
873 * Next state: FREE */
874 VUSBURBSTATE_CANCELLED,
875 /** The end of the valid states (exclusive). */
876 VUSBURBSTATE_END,
877 /** The usual 32-bit blow up. */
878 VUSBURBSTATE_32BIT_HACK = 0x7fffffff
879} VUSBURBSTATE;
880
881
882/**
883 * Information about a isochronous packet.
884 */
885typedef struct VUSBURBISOCPKT
886{
887 /** The size of the packet.
888 * IN: The packet size. I.e. the number of bytes to the next packet or end of buffer.
889 * OUT: The actual size transfered. */
890 uint16_t cb;
891 /** The offset of the packet. (Relative to VUSBURB::abData[0].)
892 * OUT: This can be changed by the USB device if it does some kind of buffer squeezing. */
893 uint16_t off;
894 /** The status of the transfer.
895 * IN: VUSBSTATUS_INVALID
896 * OUT: VUSBSTATUS_INVALID if nothing was done, otherwise the correct status. */
897 VUSBSTATUS enmStatus;
898} VUSBURBISOCPKT;
899/** Pointer to a isochronous packet. */
900typedef VUSBURBISOCPKT *PVUSBURBISOCPTK;
901/** Pointer to a const isochronous packet. */
902typedef const VUSBURBISOCPKT *PCVUSBURBISOCPKT;
903
904/**
905 * Asynchronous USB request descriptor
906 */
907typedef struct VUSBURB
908{
909 /** URB magic value. */
910 uint32_t u32Magic;
911 /** The USR state. */
912 VUSBURBSTATE enmState;
913 /** URB description, can be null. intended for logging. */
914 char *pszDesc;
915
916 /** The VUSB data. */
917 struct VUSBURBVUSB
918 {
919 /** URB chain pointer. */
920 PVUSBURB pNext;
921 /** URB chain pointer. */
922 PVUSBURB *ppPrev;
923 /** Pointer to the original for control messages. */
924 PVUSBURB pCtrlUrb;
925 /** Pointer to the VUSB device.
926 * This may be NULL if the destination address is invalid. */
927 struct VUSBDEV *pDev;
928 /** Sepcific to the pfnFree function. */
929 void *pvFreeCtx;
930 /**
931 * Callback which will free the URB once it's reaped and completed.
932 * @param pUrb The URB.
933 */
934 DECLCALLBACKMEMBER(void, pfnFree)(PVUSBURB pUrb);
935 /** Submit timestamp. (logging only) */
936 uint64_t u64SubmitTS;
937 /** The allocated data length. */
938 uint32_t cbDataAllocated;
939 /** The allocated TD length. */
940 uint32_t cTdsAllocated;
941 } VUsb;
942
943 /** The host controller data. */
944 struct VUSBURBHCI
945 {
946 /** The endpoint descriptor address. */
947 RTGCPHYS32 EdAddr;
948 /** Number of Tds in the array. */
949 uint32_t cTds;
950 /** Pointer to an array of TD info items.*/
951 struct VUSBURBHCITD
952 {
953 /** Type of TD (private) */
954 uint32_t TdType;
955 /** The address of the */
956 RTGCPHYS32 TdAddr;
957 /** A copy of the TD. */
958 uint32_t TdCopy[16];
959 } *paTds;
960 /** URB chain pointer. */
961 PVUSBURB pNext;
962 /** When this URB was created.
963 * (Used for isochronous frames and for logging.) */
964 uint32_t u32FrameNo;
965 /** Flag indicating that the TDs have been unlinked. */
966 bool fUnlinked;
967 } Hci;
968
969 /** The device data. */
970 struct VUSBURBDEV
971 {
972 /** Pointer to private device specific data. */
973 void *pvPrivate;
974 /** Used by the device when linking the URB in some list of its own. */
975 PVUSBURB pNext;
976 } Dev;
977
978 /** The USB device instance this belongs to.
979 * This is NULL if the device address is invalid, in which case this belongs to the hub. */
980 PPDMUSBINS pUsbIns;
981 /** The device address.
982 * This is set at allocation time. */
983 uint8_t DstAddress;
984
985 /** The endpoint.
986 * IN: Must be set before submitting the URB.
987 * @remark This does not have the high bit (direction) set! */
988 uint8_t EndPt;
989 /** The transfer type.
990 * IN: Must be set before submitting the URB. */
991 VUSBXFERTYPE enmType;
992 /** The transfer direction.
993 * IN: Must be set before submitting the URB. */
994 VUSBDIRECTION enmDir;
995 /** Indicates whether it is OK to receive/send less data than requested.
996 * IN: Must be initialized before submitting the URB. */
997 bool fShortNotOk;
998 /** The transfer status.
999 * OUT: This is set when reaping the URB. */
1000 VUSBSTATUS enmStatus;
1001
1002 /** The number of isochronous packets describe in aIsocPkts.
1003 * This is ignored when enmType isn't VUSBXFERTYPE_ISOC. */
1004 uint32_t cIsocPkts;
1005 /** The iso packets within abData.
1006 * This is ignored when enmType isn't VUSBXFERTYPE_ISOC. */
1007 VUSBURBISOCPKT aIsocPkts[8];
1008
1009 /** The message length.
1010 * IN: The amount of data to send / receive - set at allocation time.
1011 * OUT: The amount of data sent / received. */
1012 uint32_t cbData;
1013 /** The message data.
1014 * IN: On host to device transfers, the data to send.
1015 * OUT: On device to host transfers, the data to received. */
1016 uint8_t abData[8*_1K];
1017} VUSBURB;
1018
1019/** The magic value of a valid VUSBURB. (Murakami Haruki) */
1020#define VUSBURB_MAGIC UINT32_C(0x19490112)
1021
1022/** @} */
1023
1024
1025/** @} */
1026
1027RT_C_DECLS_END
1028
1029#endif
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