VirtualBox

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

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

include/VBox/*.h: Mark which components the header files relate to.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 31.9 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 *iface;
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 *setting;
215 /** The number of entries in the array. */
216 unsigned int num_settings;
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 void *pvMore;
233 /** Pointer to an array of the endpoints referenced by the interface.
234 * Core.bNumEndpoints in size. */
235 const struct VUSBDESCENDPOINTEX *endpoint;
236} VUSBDESCINTERFACEEX;
237/** Pointer to an prased USB interface descriptor. */
238typedef VUSBDESCINTERFACEEX *PVUSBDESCINTERFACEEX;
239/** Pointer to a const parsed USB interface descriptor. */
240typedef const VUSBDESCINTERFACEEX *PCVUSBDESCINTERFACEEX;
241
242
243/**
244 * USB endpoint descriptor, the parsed variant used by VUSB.
245 */
246typedef struct VUSBDESCENDPOINTEX
247{
248 /** The USB descriptor data.
249 * @remark The wMaxPacketSize member is converted to native endian. */
250 VUSBDESCENDPOINT Core;
251 /** Pointer to additional descriptor bytes following what's covered by VUSBDESCENDPOINT. */
252 void *pvMore;
253} VUSBDESCENDPOINTEX;
254/** Pointer to a parsed USB endpoint descriptor. */
255typedef VUSBDESCENDPOINTEX *PVUSBDESCENDPOINTEX;
256/** Pointer to a const parsed USB endpoint descriptor. */
257typedef const VUSBDESCENDPOINTEX *PCVUSBDESCENDPOINTEX;
258
259
260/** @name USB Control message recipient codes (from spec)
261 * @{ */
262#define VUSB_TO_DEVICE 0x0
263#define VUSB_TO_INTERFACE 0x1
264#define VUSB_TO_ENDPOINT 0x2
265#define VUSB_TO_OTHER 0x3
266#define VUSB_RECIP_MASK 0x1f
267/** @} */
268
269/** @name USB control pipe setup packet structure (from spec)
270 * @{ */
271#define VUSB_REQ_SHIFT (5)
272#define VUSB_REQ_STANDARD (0x0 << VUSB_REQ_SHIFT)
273#define VUSB_REQ_CLASS (0x1 << VUSB_REQ_SHIFT)
274#define VUSB_REQ_VENDOR (0x2 << VUSB_REQ_SHIFT)
275#define VUSB_REQ_RESERVED (0x3 << VUSB_REQ_SHIFT)
276#define VUSB_REQ_MASK (0x3 << VUSB_REQ_SHIFT)
277/** @} */
278
279#define VUSB_DIR_TO_DEVICE 0x00
280#define VUSB_DIR_TO_HOST 0x80
281#define VUSB_DIR_MASK 0x80
282
283/**
284 * USB Setup request (from spec)
285 */
286typedef struct vusb_setup
287{
288 uint8_t bmRequestType;
289 uint8_t bRequest;
290 uint16_t wValue;
291 uint16_t wIndex;
292 uint16_t wLength;
293} VUSBSETUP;
294/** Pointer to a setup request. */
295typedef VUSBSETUP *PVUSBSETUP;
296/** Pointer to a const setup request. */
297typedef const VUSBSETUP *PCVUSBSETUP;
298
299/** @name USB Standard device requests (from spec)
300 * @{ */
301#define VUSB_REQ_GET_STATUS 0x00
302#define VUSB_REQ_CLEAR_FEATURE 0x01
303#define VUSB_REQ_SET_FEATURE 0x03
304#define VUSB_REQ_SET_ADDRESS 0x05
305#define VUSB_REQ_GET_DESCRIPTOR 0x06
306#define VUSB_REQ_SET_DESCRIPTOR 0x07
307#define VUSB_REQ_GET_CONFIGURATION 0x08
308#define VUSB_REQ_SET_CONFIGURATION 0x09
309#define VUSB_REQ_GET_INTERFACE 0x0a
310#define VUSB_REQ_SET_INTERFACE 0x0b
311#define VUSB_REQ_SYNCH_FRAME 0x0c
312#define VUSB_REQ_MAX 0x0d
313/** @} */
314
315/** @} */ /* end of grp_vusb_std */
316
317
318
319/** @name USB Standard version flags.
320 * @{ */
321/** Indicates USB 1.1 support. */
322#define VUSB_STDVER_11 RT_BIT(1)
323/** Indicates USB 2.0 support. */
324#define VUSB_STDVER_20 RT_BIT(2)
325/** @} */
326
327
328/** Pointer to a VBox USB device interface. */
329typedef struct VUSBIDEVICE *PVUSBIDEVICE;
330
331/** Pointer to a VUSB RootHub port interface. */
332typedef struct VUSBIROOTHUBPORT *PVUSBIROOTHUBPORT;
333
334/** Pointer to an USB request descriptor. */
335typedef struct VUSBURB *PVUSBURB;
336
337
338
339/**
340 * VBox USB port bitmap.
341 *
342 * Bit 0 == Port 0, ... , Bit 127 == Port 127.
343 */
344typedef struct VUSBPORTBITMAP
345{
346 /** 128 bits */
347 char ach[16];
348} VUSBPORTBITMAP;
349/** Pointer to a VBox USB port bitmap. */
350typedef VUSBPORTBITMAP *PVUSBPORTBITMAP;
351
352
353/**
354 * The VUSB RootHub port interface provided by the HCI.
355 */
356typedef struct VUSBIROOTHUBPORT
357{
358 /**
359 * Get the number of avilable ports in the hub.
360 *
361 * @returns The number of ports available.
362 * @param pInterface Pointer to this structure.
363 * @param pAvailable Bitmap indicating the available ports. Set bit == available port.
364 */
365 DECLR3CALLBACKMEMBER(unsigned, pfnGetAvailablePorts,(PVUSBIROOTHUBPORT pInterface, PVUSBPORTBITMAP pAvailable));
366
367 /**
368 * Gets the supported USB versions.
369 *
370 * @returns The mask of supported USB versions.
371 * @param pInterface Pointer to this structure.
372 */
373 DECLR3CALLBACKMEMBER(uint32_t, pfnGetUSBVersions,(PVUSBIROOTHUBPORT pInterface));
374
375 /**
376 * A device is being attached to a port in the roothub.
377 *
378 * @param pInterface Pointer to this structure.
379 * @param pDev Pointer to the device being attached.
380 * @param uPort The port number assigned to the device.
381 */
382 DECLR3CALLBACKMEMBER(int, pfnAttach,(PVUSBIROOTHUBPORT pInterface, PVUSBIDEVICE pDev, unsigned uPort));
383
384 /**
385 * A device is being detached from a port in the roothub.
386 *
387 * @param pInterface Pointer to this structure.
388 * @param pDev Pointer to the device being detached.
389 * @param uPort The port number assigned to the device.
390 */
391 DECLR3CALLBACKMEMBER(void, pfnDetach,(PVUSBIROOTHUBPORT pInterface, PVUSBIDEVICE pDev, unsigned uPort));
392
393 /**
394 * Reset the root hub.
395 *
396 * @returns VBox status code.
397 * @param pInterface Pointer to this structure.
398 * @param pResetOnLinux Whether or not to do real reset on linux.
399 */
400 DECLR3CALLBACKMEMBER(int, pfnReset,(PVUSBIROOTHUBPORT pInterface, bool fResetOnLinux));
401
402 /**
403 * Transfer completion callback routine.
404 *
405 * VUSB will call this when a transfer have been completed
406 * in a one or another way.
407 *
408 * @param pInterface Pointer to this structure.
409 * @param pUrb Pointer to the URB in question.
410 */
411 DECLR3CALLBACKMEMBER(void, pfnXferCompletion,(PVUSBIROOTHUBPORT pInterface, PVUSBURB urb));
412
413 /**
414 * Handle transfer errors.
415 *
416 * VUSB calls this when a transfer attempt failed. This function will respond
417 * indicating wheter to retry or complete the URB with failure.
418 *
419 * @returns Retry indicator.
420 * @param pInterface Pointer to this structure.
421 * @param pUrb Pointer to the URB in question.
422 */
423 DECLR3CALLBACKMEMBER(bool, pfnXferError,(PVUSBIROOTHUBPORT pInterface, PVUSBURB pUrb));
424
425 /** Alignment dummy. */
426 RTR3PTR Alignment;
427
428} VUSBIROOTHUBPORT;
429
430
431/** Pointer to a VUSB RootHub connector interface. */
432typedef struct VUSBIROOTHUBCONNECTOR *PVUSBIROOTHUBCONNECTOR;
433
434/**
435 * The VUSB RootHub connector interface provided by the VBox USB RootHub driver.
436 */
437typedef struct VUSBIROOTHUBCONNECTOR
438{
439 /**
440 * Allocates a new URB for a transfer.
441 *
442 * Either submit using pfnSubmitUrb or free using VUSBUrbFree().
443 *
444 * @returns Pointer to a new URB.
445 * @returns NULL on failure - try again later.
446 * This will not fail if the device wasn't found. We'll fail it
447 * at submit time, since that makes the usage of this api simpler.
448 * @param pInterface Pointer to this struct.
449 * @param DstAddress The destination address of the URB.
450 * @param cbData The amount of data space required.
451 * @param cTds The amount of TD space.
452 */
453 DECLR3CALLBACKMEMBER(PVUSBURB, pfnNewUrb,(PVUSBIROOTHUBCONNECTOR pInterface, uint8_t DstAddress, uint32_t cbData, uint32_t cTds));
454
455 /**
456 * Submits a URB for transfer.
457 * The transfer will do asynchronously if possible.
458 *
459 * @returns VBox status code.
460 * @param pInterface Pointer to this struct.
461 * @param pUrb Pointer to the URB returned by pfnNewUrb.
462 * The URB will be freed in case of failure.
463 * @param pLed Pointer to USB Status LED
464 */
465 DECLR3CALLBACKMEMBER(int, pfnSubmitUrb,(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb, struct PDMLED *pLed));
466
467 /**
468 * Call to service asynchronous URB completions in a polling fashion.
469 *
470 * Reaped URBs will be finished by calling the completion callback,
471 * thus there is no return code or input or anything from this function
472 * except for potential state changes elsewhere.
473 *
474 * @returns VINF_SUCCESS if no URBs are pending upon return.
475 * @returns VERR_TIMEOUT if one or more URBs are still in flight upon returning.
476 * @returns Other VBox status code.
477 *
478 * @param pInterface Pointer to this struct.
479 * @param cMillies Number of milliseconds to poll for completion.
480 */
481 DECLR3CALLBACKMEMBER(void, pfnReapAsyncUrbs,(PVUSBIROOTHUBCONNECTOR pInterface, unsigned cMillies));
482
483 /**
484 * Cancels and completes - with CRC failure - all in-flight async URBs.
485 * This is typically done before saving a state.
486 *
487 * @param pInterface Pointer to this struct.
488 */
489 DECLR3CALLBACKMEMBER(void, pfnCancelAllUrbs,(PVUSBIROOTHUBCONNECTOR pInterface));
490
491 /**
492 * Attach the device to the root hub.
493 * The device must not be attached to any hub for this call to succeed.
494 *
495 * @returns VBox status code.
496 * @param pInterface Pointer to this struct.
497 * @param pDevice Pointer to the device (interface) attach.
498 */
499 DECLR3CALLBACKMEMBER(int, pfnAttachDevice,(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice));
500
501 /**
502 * Detach the device from the root hub.
503 * The device must already be attached for this call to succeed.
504 *
505 * @returns VBox status code.
506 * @param pInterface Pointer to this struct.
507 * @param pDevice Pointer to the device (interface) to detach.
508 */
509 DECLR3CALLBACKMEMBER(int, pfnDetachDevice,(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice));
510
511} VUSBIROOTHUBCONNECTOR;
512
513
514#ifdef IN_RING3
515/** @copydoc VUSBIROOTHUBCONNECTOR::pfnNewUrb */
516DECLINLINE(PVUSBURB) VUSBIRhNewUrb(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t DstAddress, uint32_t cbData, uint32_t cTds)
517{
518 return pInterface->pfnNewUrb(pInterface, DstAddress, cbData, cTds);
519}
520
521/** @copydoc VUSBIROOTHUBCONNECTOR::pfnSubmitUrb */
522DECLINLINE(int) VUSBIRhSubmitUrb(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb, struct PDMLED *pLed)
523{
524 return pInterface->pfnSubmitUrb(pInterface, pUrb, pLed);
525}
526
527/** @copydoc VUSBIROOTHUBCONNECTOR::pfnReapAsyncUrbs */
528DECLINLINE(void) VUSBIRhReapAsyncUrbs(PVUSBIROOTHUBCONNECTOR pInterface, unsigned cMillies)
529{
530 pInterface->pfnReapAsyncUrbs(pInterface, cMillies);
531}
532
533/** @copydoc VUSBIROOTHUBCONNECTOR::pfnCancelAllUrbs */
534DECLINLINE(void) VUSBIRhCancelAllUrbs(PVUSBIROOTHUBCONNECTOR pInterface)
535{
536 pInterface->pfnCancelAllUrbs(pInterface);
537}
538
539/** @copydoc VUSBIROOTHUBCONNECTOR::pfnAttachDevice */
540DECLINLINE(int) VUSBIRhAttachDevice(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice)
541{
542 return pInterface->pfnAttachDevice(pInterface, pDevice);
543}
544
545/** @copydoc VUSBIROOTHUBCONNECTOR::pfnDetachDevice */
546DECLINLINE(int) VUSBIRhDetachDevice(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBIDEVICE pDevice)
547{
548 return pInterface->pfnDetachDevice(pInterface, pDevice);
549}
550#endif /* IN_RING3 */
551
552
553
554/** Pointer to a Root Hub Configuration Interface. */
555typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
556
557/**
558 * Root Hub Configuration Interface (intended for MAIN).
559 */
560typedef struct VUSBIRHCONFIG
561{
562 /**
563 * Creates a USB proxy device and attaches it to the root hub.
564 *
565 * @returns VBox status code.
566 * @param pInterface Pointer to the root hub configuration interface structure.
567 * @param pUuid Pointer to the UUID for the new device.
568 * @param fRemote Whether the device must use the VRDP backend.
569 * @param pszAddress OS specific device address.
570 * @param pvBackend An opaque pointer for the backend. Only used by
571 * the VRDP backend so far.
572 */
573 DECLR3CALLBACKMEMBER(int, pfnCreateProxyDevice,(PVUSBIRHCONFIG pInterface, PCRTUUID pUuid, bool fRemote, const char *pszAddress, void *pvBackend));
574
575 /**
576 * Removes a USB proxy device from the root hub and destroys it.
577 *
578 * @returns VBox status code.
579 * @param pInterface Pointer to the root hub configuration interface structure.
580 * @param pUuid Pointer to the UUID for the device.
581 */
582 DECLR3CALLBACKMEMBER(int, pfnDestroyProxyDevice,(PVUSBIRHCONFIG pInterface, PCRTUUID pUuid));
583
584} VUSBIRHCONFIG;
585
586#ifdef IN_RING3
587/** @copydoc VUSBIRHCONFIG::pfnCreateProxyDevice */
588DECLINLINE(int) VUSBIRhCreateProxyDevice(PVUSBIRHCONFIG pInterface, PCRTUUID pUuid, bool fRemote, const char *pszAddress, void *pvBackend)
589{
590 return pInterface->pfnCreateProxyDevice(pInterface, pUuid, fRemote, pszAddress, pvBackend);
591}
592
593/** @copydoc VUSBIRHCONFIG::pfnDestroyProxyDevice */
594DECLINLINE(int) VUSBIRhDestroyProxyDevice(PVUSBIRHCONFIG pInterface, PCRTUUID pUuid)
595{
596 return pInterface->pfnDestroyProxyDevice(pInterface, pUuid);
597}
598#endif /* IN_RING3 */
599
600
601
602/**
603 * VUSB device reset completion callback function.
604 * This is called by the reset thread when the reset has been completed.
605 *
606 * @param pDev Pointer to the virtual USB device core.
607 * @param rc The VBox status code of the reset operation.
608 * @param pvUser User specific argument.
609 *
610 * @thread The reset thread or EMT.
611 */
612typedef DECLCALLBACK(void) FNVUSBRESETDONE(PVUSBIDEVICE pDevice, int rc, void *pvUser);
613/** Pointer to a device reset completion callback function (FNUSBRESETDONE). */
614typedef FNVUSBRESETDONE *PFNVUSBRESETDONE;
615
616/**
617 * The state of a VUSB Device.
618 *
619 * @remark The order of these states is vital.
620 */
621typedef enum VUSBDEVICESTATE
622{
623 VUSB_DEVICE_STATE_INVALID = 0,
624 VUSB_DEVICE_STATE_DETACHED,
625 VUSB_DEVICE_STATE_ATTACHED,
626 VUSB_DEVICE_STATE_POWERED,
627 VUSB_DEVICE_STATE_DEFAULT,
628 VUSB_DEVICE_STATE_ADDRESS,
629 VUSB_DEVICE_STATE_CONFIGURED,
630 VUSB_DEVICE_STATE_SUSPENDED,
631 /** The device is being reset. Don't mess with it.
632 * Next states: VUSB_DEVICE_STATE_DEFAULT, VUSB_DEVICE_STATE_DESTROYED
633 */
634 VUSB_DEVICE_STATE_RESET,
635 /** The device has been destroy. */
636 VUSB_DEVICE_STATE_DESTROYED,
637 /** The usual 32-bit hack. */
638 VUSB_DEVICE_STATE_32BIT_HACK = 0x7fffffff
639} VUSBDEVICESTATE;
640
641
642/**
643 * USB Device Interface.
644 */
645typedef struct VUSBIDEVICE
646{
647 /**
648 * Resets the device.
649 *
650 * Since a device reset shall take at least 10ms from the guest point of view,
651 * it must be performed asynchronously. We create a thread which performs this
652 * operation and ensures it will take at least 10ms.
653 *
654 * At times - like init - a synchronous reset is required, this can be done
655 * by passing NULL for pfnDone.
656 *
657 * -- internal stuff, move it --
658 * While the device is being reset it is in the VUSB_DEVICE_STATE_RESET state.
659 * On completion it will be in the VUSB_DEVICE_STATE_DEFAULT state if successful,
660 * or in the VUSB_DEVICE_STATE_DETACHED state if the rest failed.
661 * -- internal stuff, move it --
662 *
663 * @returns VBox status code.
664 * @param pInterface Pointer to this structure.
665 * @param fResetOnLinux Set if we can permit a real reset and a potential logical
666 * device reconnect on linux hosts.
667 * @param pfnDone Pointer to the completion routine. If NULL a synchronous
668 * reset is preformed not respecting the 10ms.
669 * @param pvUser User argument to the completion routine.
670 * @param pVM Pointer to the VM handle if callback in EMT is required. (optional)
671 */
672 DECLR3CALLBACKMEMBER(int, pfnReset,(PVUSBIDEVICE pInterface, bool fResetOnLinux,
673 PFNVUSBRESETDONE pfnDone, void *pvUser, PVM pVM));
674
675 /**
676 * Powers on the device.
677 *
678 * @returns VBox status code.
679 * @param pInterface Pointer to the device interface structure.
680 */
681 DECLR3CALLBACKMEMBER(int, pfnPowerOn,(PVUSBIDEVICE pInterface));
682
683 /**
684 * Powers off the device.
685 *
686 * @returns VBox status code.
687 * @param pInterface Pointer to the device interface structure.
688 */
689 DECLR3CALLBACKMEMBER(int, pfnPowerOff,(PVUSBIDEVICE pInterface));
690
691 /**
692 * Get the state of the device.
693 *
694 * @returns Device state.
695 * @param pInterface Pointer to the device interface structure.
696 */
697 DECLR3CALLBACKMEMBER(VUSBDEVICESTATE, pfnGetState,(PVUSBIDEVICE pInterface));
698
699} VUSBIDEVICE;
700
701
702#ifdef IN_RING3
703/**
704 * Resets the device.
705 *
706 * Since a device reset shall take at least 10ms from the guest point of view,
707 * it must be performed asynchronously. We create a thread which performs this
708 * operation and ensures it will take at least 10ms.
709 *
710 * At times - like init - a synchronous reset is required, this can be done
711 * by passing NULL for pfnDone.
712 *
713 * -- internal stuff, move it --
714 * While the device is being reset it is in the VUSB_DEVICE_STATE_RESET state.
715 * On completion it will be in the VUSB_DEVICE_STATE_DEFAULT state if successful,
716 * or in the VUSB_DEVICE_STATE_DETACHED state if the rest failed.
717 * -- internal stuff, move it --
718 *
719 * @returns VBox status code.
720 * @param pInterface Pointer to the device interface structure.
721 * @param fResetOnLinux Set if we can permit a real reset and a potential logical
722 * device reconnect on linux hosts.
723 * @param pfnDone Pointer to the completion routine. If NULL a synchronous
724 * reset is preformed not respecting the 10ms.
725 * @param pvUser User argument to the completion routine.
726 * @param pVM Pointer to the VM handle if callback in EMT is required. (optional)
727 */
728DECLINLINE(int) VUSBIDevReset(PVUSBIDEVICE pInterface, bool fResetOnLinux, PFNVUSBRESETDONE pfnDone, void *pvUser, PVM pVM)
729{
730 return pInterface->pfnReset(pInterface, fResetOnLinux, pfnDone, pvUser, pVM);
731}
732
733/**
734 * Powers on the device.
735 *
736 * @returns VBox status code.
737 * @param pInterface Pointer to the device interface structure.
738 */
739DECLINLINE(int) VUSBIDevPowerOn(PVUSBIDEVICE pInterface)
740{
741 return pInterface->pfnPowerOn(pInterface);
742}
743
744/**
745 * Powers off the device.
746 *
747 * @returns VBox status code.
748 * @param pInterface Pointer to the device interface structure.
749 */
750DECLINLINE(int) VUSBIDevPowerOff(PVUSBIDEVICE pInterface)
751{
752 return pInterface->pfnPowerOff(pInterface);
753}
754
755/**
756 * Get the state of the device.
757 *
758 * @returns Device state.
759 * @param pInterface Pointer to the device interface structure.
760 */
761DECLINLINE(VUSBDEVICESTATE) VUSBIDevGetState(PVUSBIDEVICE pInterface)
762{
763 return pInterface->pfnGetState(pInterface);
764}
765#endif /* IN_RING3 */
766
767
768/** @name URB
769 * @{ */
770
771/**
772 * VUSB Transfer status codes.
773 */
774typedef enum VUSBSTATUS
775{
776 /** Transer was ok. */
777 VUSBSTATUS_OK = 0,
778 /** Transfer stalled, endpoint halted. */
779 VUSBSTATUS_STALL,
780 /** Device not responding. */
781 VUSBSTATUS_DNR,
782 /** CRC error. */
783 VUSBSTATUS_CRC,
784 /** Data overrun error. */
785 VUSBSTATUS_DATA_UNDERRUN,
786 /** Data overrun error. */
787 VUSBSTATUS_DATA_OVERRUN,
788 /** The isochronous buffer hasn't been touched. */
789 VUSBSTATUS_NOT_ACCESSED,
790 /** Invalid status. */
791 VUSBSTATUS_INVALID = 0x7f
792} VUSBSTATUS;
793
794
795/**
796 * VUSB Transfer types.
797 */
798typedef enum VUSBXFERTYPE
799{
800 /** Control message. Used to represent a single control transfer. */
801 VUSBXFERTYPE_CTRL = 0,
802 /* Isochronous transfer. */
803 VUSBXFERTYPE_ISOC,
804 /** Bulk transfer. */
805 VUSBXFERTYPE_BULK,
806 /** Interrupt transfer. */
807 VUSBXFERTYPE_INTR,
808 /** Complete control message. Used to represent an entire control message. */
809 VUSBXFERTYPE_MSG,
810 /** Invalid transfer type. */
811 VUSBXFERTYPE_INVALID = 0x7f
812} VUSBXFERTYPE;
813
814
815/**
816 * VUSB transfer direction.
817 */
818typedef enum VUSBDIRECTION
819{
820 /** Setup */
821 VUSBDIRECTION_SETUP = 0,
822#define VUSB_DIRECTION_SETUP VUSBDIRECTION_SETUP
823 /** In - Device to host. */
824 VUSBDIRECTION_IN = 1,
825#define VUSB_DIRECTION_IN VUSBDIRECTION_IN
826 /** Out - Host to device. */
827 VUSBDIRECTION_OUT = 2,
828#define VUSB_DIRECTION_OUT VUSBDIRECTION_OUT
829 /** Invalid direction */
830 VUSBDIRECTION_INVALID = 0x7f
831} VUSBDIRECTION;
832
833/**
834 * The URB states
835 */
836typedef enum VUSBURBSTATE
837{
838 /** The usual invalid state. */
839 VUSBURBSTATE_INVALID = 0,
840 /** The URB is free, i.e. not in use.
841 * Next state: ALLOCATED */
842 VUSBURBSTATE_FREE,
843 /** The URB is allocated, i.e. being prepared for submission.
844 * Next state: FREE, IN_FLIGHT */
845 VUSBURBSTATE_ALLOCATED,
846 /** The URB is in flight.
847 * Next state: REAPED, CANCELLED */
848 VUSBURBSTATE_IN_FLIGHT,
849 /** The URB has been reaped and is being completed.
850 * Next state: FREE */
851 VUSBURBSTATE_REAPED,
852 /** The URB has been cancelled and is awaiting reaping and immediate freeing.
853 * Next state: FREE */
854 VUSBURBSTATE_CANCELLED,
855 /** The end of the valid states (exclusive). */
856 VUSBURBSTATE_END,
857 /** The usual 32-bit blow up. */
858 VUSBURBSTATE_32BIT_HACK = 0x7fffffff
859} VUSBURBSTATE;
860
861
862/**
863 * Information about a isochronous packet.
864 */
865typedef struct VUSBURBISOCPKT
866{
867 /** The size of the packet.
868 * IN: The packet size. I.e. the number of bytes to the next packet or end of buffer.
869 * OUT: The actual size transfered. */
870 uint16_t cb;
871 /** The offset of the packet. (Relative to VUSBURB::abData[0].)
872 * OUT: This can be changed by the USB device if it does some kind of buffer squeezing. */
873 uint16_t off;
874 /** The status of the transfer.
875 * IN: VUSBSTATUS_INVALID
876 * OUT: VUSBSTATUS_INVALID if nothing was done, otherwise the correct status. */
877 VUSBSTATUS enmStatus;
878} VUSBURBISOCPKT;
879/** Pointer to a isochronous packet. */
880typedef VUSBURBISOCPKT *PVUSBURBISOCPTK;
881/** Pointer to a const isochronous packet. */
882typedef const VUSBURBISOCPKT *PCVUSBURBISOCPKT;
883
884/**
885 * Asynchronous USB request descriptor
886 */
887typedef struct VUSBURB
888{
889 /** URB magic value. */
890 uint32_t u32Magic;
891 /** The USR state. */
892 VUSBURBSTATE enmState;
893 /** URB description, can be null. intended for logging. */
894 char *pszDesc;
895
896 /** The VUSB data. */
897 struct VUSBURBVUSB
898 {
899 /** URB chain pointer. */
900 PVUSBURB pNext;
901 /** URB chain pointer. */
902 PVUSBURB *ppPrev;
903 /** Pointer to the original for control messages. */
904 PVUSBURB pCtrlUrb;
905 /** Pointer to the VUSB device.
906 * This may be NULL if the destination address is invalid. */
907 struct VUSBDEV *pDev;
908 /** Sepcific to the pfnFree function. */
909 void *pvFreeCtx;
910 /**
911 * Callback which will free the URB once it's reaped and completed.
912 * @param pUrb The URB.
913 */
914 DECLCALLBACKMEMBER(void, pfnFree)(PVUSBURB pUrb);
915 /** Submit timestamp. (logging only) */
916 uint64_t u64SubmitTS;
917 /** The allocated data length. */
918 uint32_t cbDataAllocated;
919 /** The allocated TD length. */
920 uint32_t cTdsAllocated;
921 } VUsb;
922
923 /** The host controller data. */
924 struct VUSBURBHCI
925 {
926 /** The endpoint descriptor address. */
927 RTGCPHYS32 EdAddr;
928 /** Number of Tds in the array. */
929 uint32_t cTds;
930 /** Pointer to an array of TD info items.*/
931 struct VUSBURBHCITD
932 {
933 /** Type of TD (private) */
934 uint32_t TdType;
935 /** The address of the */
936 RTGCPHYS32 TdAddr;
937 /** A copy of the TD. */
938 uint32_t TdCopy[16];
939 } *paTds;
940 /** URB chain pointer. */
941 PVUSBURB pNext;
942 /** When this URB was created.
943 * (Used for isochronous frames and for logging.) */
944 uint32_t u32FrameNo;
945 /** Flag indicating that the TDs have been unlinked. */
946 bool fUnlinked;
947 } Hci;
948
949 /** The device data. */
950 struct VUSBURBDEV
951 {
952 /** Pointer to the proxy URB. */
953 void *pvProxyUrb;
954 } Dev;
955
956 /** The USB device instance this belongs to.
957 * This is NULL if the device address is invalid, in which case this belongs to the hub. */
958 PPDMUSBINS pUsbIns;
959 /** The device address.
960 * This is set at allocation time. */
961 uint8_t DstAddress;
962
963 /** The endpoint.
964 * IN: Must be set before submitting the URB.
965 * @remark This does not have the high bit (direction) set! */
966 uint8_t EndPt;
967 /** The transfer type.
968 * IN: Must be set before submitting the URB. */
969 VUSBXFERTYPE enmType;
970 /** The transfer direction.
971 * IN: Must be set before submitting the URB. */
972 VUSBDIRECTION enmDir;
973 /** Indicates whether it is OK to receive/send less data than requested.
974 * IN: Must be initialized before submitting the URB. */
975 bool fShortNotOk;
976 /** The transfer status.
977 * OUT: This is set when reaping the URB. */
978 VUSBSTATUS enmStatus;
979
980 /** The number of isochronous packets describe in aIsocPkts.
981 * This is ignored when enmType isn't VUSBXFERTYPE_ISOC. */
982 uint32_t cIsocPkts;
983 /** The iso packets within abData.
984 * This is ignored when enmType isn't VUSBXFERTYPE_ISOC. */
985 VUSBURBISOCPKT aIsocPkts[8];
986
987 /** The message length.
988 * IN: The amount of data to send / receive - set at allocation time.
989 * OUT: The amount of data sent / received. */
990 uint32_t cbData;
991 /** The message data.
992 * IN: On host to device transfers, the data to send.
993 * OUT: On device to host transfers, the data to received. */
994 uint8_t abData[8*_1K];
995} VUSBURB;
996
997/** The magic value of a valid VUSBURB. (Murakami Haruki) */
998#define VUSBURB_MAGIC 0x19490112
999
1000/** @} */
1001
1002
1003/** @} */
1004
1005RT_C_DECLS_END
1006
1007#endif
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use