2
* PDM - Pluggable Device Manager, USB Devices. (VMM)
6
* Copyright (C) 2006-2010 Oracle Corporation
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.
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.
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.
26
#ifndef ___VBox_pdmusb_h
27
#define ___VBox_pdmusb_h
29
#include <VBox/pdmqueue.h>
30
#include <VBox/pdmcritsect.h>
31
#include <VBox/pdmthread.h>
32
#include <VBox/pdmifs.h>
33
#include <VBox/pdmcommon.h>
36
#include <VBox/cfgm.h>
37
#include <VBox/dbgf.h>
40
#include <VBox/vusb.h>
41
#include <iprt/stdarg.h>
45
/** @defgroup grp_pdm_usbdev The USB Devices API
52
* A string entry for the USB descriptor cache.
54
typedef struct PDMUSBDESCCACHESTRING
56
/** The string index. */
58
/** The UTF-8 representation of the string. */
60
} PDMUSBDESCCACHESTRING;
61
/** Pointer to a const string entry. */
62
typedef PDMUSBDESCCACHESTRING const *PCPDMUSBDESCCACHESTRING;
66
* A language entry for the USB descriptor cache.
68
typedef struct PDMUSBDESCCACHELANG
70
/** The language ID for the strings in this block. */
72
/** The number of strings in the array. */
74
/** Pointer to an array of associated strings.
75
* This must be sorted in ascending order by string index as a binary lookup
76
* will be performed. */
77
PCPDMUSBDESCCACHESTRING paStrings;
78
} PDMUSBDESCCACHELANG;
79
/** Pointer to a const language entry. */
80
typedef PDMUSBDESCCACHELANG const *PCPDMUSBDESCCACHELANG;
84
* USB descriptor cache.
86
* This structure is owned by the USB device but provided to the PDM/VUSB layer
87
* thru the PDMUSBREG::pfnGetDescriptorCache method. PDM/VUSB will use the
88
* information here to map addresses to endpoints, perform SET_CONFIGURATION
89
* requests, and optionally perform GET_DESCRIPTOR requests (see flag).
91
* Currently, only device and configuration descriptors are cached.
93
typedef struct PDMUSBDESCCACHE
95
/** USB device descriptor */
96
PCVUSBDESCDEVICE pDevice;
97
/** USB Descriptor arrays (pDev->bNumConfigurations) */
98
PCVUSBDESCCONFIGEX paConfigs;
99
/** Language IDs and their associated strings.
100
* This must be sorted in ascending order by language ID as a binary lookup
102
PCPDMUSBDESCCACHELANG paLanguages;
103
/** The number of entries in the array pointed to by paLanguages. */
105
/** Use the cached descriptors for GET_DESCRIPTOR requests. */
106
bool fUseCachedDescriptors;
107
/** Use the cached string descriptors. */
108
bool fUseCachedStringsDescriptors;
110
/** Pointer to an USB descriptor cache. */
111
typedef PDMUSBDESCCACHE *PPDMUSBDESCCACHE;
112
/** Pointer to a const USB descriptor cache. */
113
typedef const PDMUSBDESCCACHE *PCPDMUSBDESCCACHE;
117
/** PDM USB Device Registration Structure,
119
* This structure is used when registering a device from VBoxUsbRegister() in HC Ring-3.
120
* The PDM will make use of this structure untill the VM is destroyed.
122
typedef struct PDMUSBREG
124
/** Structure version. PDM_DEVREG_VERSION defines the current version. */
128
/** The description of the device. The UTF-8 string pointed to shall, like this structure,
129
* remain unchanged from registration till VM destruction. */
130
const char *pszDescription;
132
/** Flags, combination of the PDM_USBREG_FLAGS_* \#defines. */
134
/** Maximum number of instances (per VM). */
135
RTUINT cMaxInstances;
136
/** Size of the instance data. */
141
* Construct an USB device instance for a VM.
143
* @returns VBox status.
144
* @param pUsbIns The USB device instance data.
145
* If the registration structure is needed, it will be
146
* accessible thru pUsbDev->pReg.
147
* @param iInstance Instance number. Use this to figure out which registers
148
* and such to use. The instance number is also found in
149
* pUsbDev->iInstance, but since it's likely to be
150
* freqently used PDM passes it as parameter.
151
* @param pCfg Configuration node handle for the device. Use this to
152
* obtain the configuration of the device instance. It is
153
* also found in pUsbDev->pCfg, but since it is primary
154
* usage will in this function it is passed as a parameter.
155
* @param pCfgGlobal Handle to the global device configuration. Also found
156
* in pUsbDev->pCfgGlobal.
157
* @remarks This callback is required.
159
DECLR3CALLBACKMEMBER(int, pfnConstruct,(PPDMUSBINS pUsbIns, int iInstance, PCFGMNODE pCfg, PCFGMNODE pCfgGlobal));
162
* Destruct an USB device instance.
164
* Most VM resources are freed by the VM. This callback is provided so that any non-VM
165
* resources can be freed correctly.
167
* This method will be called regardless of the pfnConstruc result to avoid
168
* complicated failure paths.
170
* @param pUsbIns The USB device instance data.
173
DECLR3CALLBACKMEMBER(void, pfnDestruct,(PPDMUSBINS pUsbIns));
177
* Init complete notification.
179
* This can be done to do communication with other devices and other
180
* initialization which requires everything to be in place.
182
* @returns VBOX status code.
183
* @param pUsbIns The USB device instance data.
185
* @remarks Not called when hotplugged.
187
DECLR3CALLBACKMEMBER(int, pfnVMInitComplete,(PPDMUSBINS pUsbIns));
190
* VM Power On notification.
192
* @returns VBox status.
193
* @param pUsbIns The USB device instance data.
196
DECLR3CALLBACKMEMBER(void, pfnVMPowerOn,(PPDMUSBINS pUsbIns));
199
* VM Reset notification.
201
* @returns VBox status.
202
* @param pUsbIns The USB device instance data.
205
DECLR3CALLBACKMEMBER(void, pfnVMReset,(PPDMUSBINS pUsbIns));
208
* VM Suspend notification.
210
* @returns VBox status.
211
* @param pUsbIns The USB device instance data.
214
DECLR3CALLBACKMEMBER(void, pfnVMSuspend,(PPDMUSBINS pUsbIns));
217
* VM Resume notification.
219
* @returns VBox status.
220
* @param pUsbIns The USB device instance data.
223
DECLR3CALLBACKMEMBER(void, pfnVMResume,(PPDMUSBINS pUsbIns));
226
* VM Power Off notification.
228
* This is only called when the VMR3PowerOff call is made on a running VM. This
229
* means that there is no notification if the VM was suspended before being
230
* powered of. There will also be no callback when hot plugging devices.
232
* @param pUsbIns The USB device instance data.
234
DECLR3CALLBACKMEMBER(void, pfnVMPowerOff,(PPDMUSBINS pUsbIns));
237
* Called after the constructor when attaching a device at run time.
239
* This can be used to do tasks normally assigned to pfnInitComplete and/or pfnVMPowerOn.
241
* @returns VBox status.
242
* @param pUsbIns The USB device instance data.
245
DECLR3CALLBACKMEMBER(void, pfnHotPlugged,(PPDMUSBINS pUsbIns));
248
* Called before the destructor when a device is unplugged at run time.
250
* This can be used to do tasks normally assigned to pfnVMSuspend and/or pfnVMPowerOff.
252
* @returns VBox status.
253
* @param pUsbIns The USB device instance data.
256
DECLR3CALLBACKMEMBER(void, pfnHotUnplugged,(PPDMUSBINS pUsbIns));
258
* Driver Attach command.
260
* This is called to let the USB device attach to a driver for a specified LUN
261
* at runtime. This is not called during VM construction, the device constructor
262
* have to attach to all the available drivers.
264
* @returns VBox status code.
265
* @param pUsbIns The USB device instance data.
266
* @param iLUN The logical unit which is being detached.
269
DECLR3CALLBACKMEMBER(int, pfnDriverAttach,(PPDMUSBINS pUsbIns, unsigned iLUN));
272
* Driver Detach notification.
274
* This is called when a driver is detaching itself from a LUN of the device.
275
* The device should adjust it's state to reflect this.
277
* @param pUsbIns The USB device instance data.
278
* @param iLUN The logical unit which is being detached.
281
DECLR3CALLBACKMEMBER(void, pfnDriverDetach,(PPDMUSBINS pUsbIns, unsigned iLUN));
284
* Query the base interface of a logical unit.
286
* @returns VBOX status code.
287
* @param pUsbIns The USB device instance data.
288
* @param iLUN The logicial unit to query.
289
* @param ppBase Where to store the pointer to the base interface of the LUN.
292
DECLR3CALLBACKMEMBER(int, pfnQueryInterface,(PPDMUSBINS pUsbIns, unsigned iLUN, PPDMIBASE *ppBase));
295
* Requests the USB device to reset.
297
* @returns VBox status code.
298
* @param pUsbIns The USB device instance.
299
* @param fResetOnLinux A hint to the usb proxy.
300
* Don't use this unless you're the linux proxy device.
301
* @thread Any thread.
304
DECLR3CALLBACKMEMBER(int, pfnUsbReset,(PPDMUSBINS pUsbIns, bool fResetOnLinux));
307
* Query device and configuration descriptors for the caching and servicing
308
* relevant GET_DESCRIPTOR requests.
310
* @returns Pointer to the descriptor cache (read-only).
311
* @param pUsbIns The USB device instance.
312
* @remarks Mandatory.
314
DECLR3CALLBACKMEMBER(PCPDMUSBDESCCACHE, pfnUsbGetDescriptorCache,(PPDMUSBINS pUsbIns));
317
* SET_CONFIGURATION request.
319
* @returns VBox status code.
320
* @param pUsbIns The USB device instance.
321
* @param bConfigurationValue The bConfigurationValue of the new configuration.
322
* @param pvOldCfgDesc Internal - for the device proxy.
323
* @param pvOldIfState Internal - for the device proxy.
324
* @param pvNewCfgDesc Internal - for the device proxy.
327
DECLR3CALLBACKMEMBER(int, pfnUsbSetConfiguration,(PPDMUSBINS pUsbIns, uint8_t bConfigurationValue,
328
const void *pvOldCfgDesc, const void *pvOldIfState, const void *pvNewCfgDesc));
331
* SET_INTERFACE request.
333
* @returns VBox status code.
334
* @param pUsbIns The USB device instance.
335
* @param bInterfaceNumber The interface number.
336
* @param bAlternateSetting The alternate setting.
339
DECLR3CALLBACKMEMBER(int, pfnUsbSetInterface,(PPDMUSBINS pUsbIns, uint8_t bInterfaceNumber, uint8_t bAlternateSetting));
342
* Clears the halted state of an endpoint. (Optional)
344
* This called when VUSB sees a CLEAR_FEATURE(ENDPOINT_HALT) on request
347
* @returns VBox status code.
348
* @param pUsbIns The USB device instance.
349
* @param uEndpoint The endpoint to clear.
352
DECLR3CALLBACKMEMBER(int, pfnUsbClearHaltedEndpoint,(PPDMUSBINS pUsbIns, unsigned uEndpoint));
357
* This can be used to make use of shared user/kernel mode buffers.
359
* @returns VBox status code.
360
* @param pUsbIns The USB device instance.
361
* @param cbData The size of the data buffer.
362
* @param cTds The number of TDs.
363
* @param enmType The type of URB.
364
* @param ppUrb Where to store the allocated URB.
366
* @remarks Not implemented yet.
368
DECLR3CALLBACKMEMBER(int, pfnUrbNew,(PPDMUSBINS pUsbIns, size_t cbData, size_t cTds, VUSBXFERTYPE enmType, PVUSBURB *ppUrb));
371
* Queues an URB for processing.
373
* @returns VBox status code.
374
* @retval VINF_SUCCESS on success.
375
* @retval VERR_VUSB_DEVICE_NOT_ATTACHED if the device has been disconnected.
376
* @retval VERR_VUSB_FAILED_TO_QUEUE_URB as a general failure kind of thing.
377
* @retval TBD - document new stuff!
379
* @param pUsbIns The USB device instance.
380
* @param pUrb The URB to process.
381
* @remarks Mandatory.
383
DECLR3CALLBACKMEMBER(int, pfnUrbQueue,(PPDMUSBINS pUsbIns, PVUSBURB pUrb));
388
* @returns VBox status code.
389
* @param pUsbIns The USB device instance.
390
* @param pUrb The URB to cancel.
391
* @remarks Mandatory.
393
DECLR3CALLBACKMEMBER(int, pfnUrbCancel,(PPDMUSBINS pUsbIns, PVUSBURB pUrb));
398
* @returns A ripe URB, NULL if none.
399
* @param pUsbIns The USB device instance.
400
* @param cMillies How log to wait for an URB to become ripe.
401
* @remarks Mandatory.
403
DECLR3CALLBACKMEMBER(PVUSBURB, pfnUrbReap,(PPDMUSBINS pUsbIns, RTMSINTERVAL cMillies));
406
/** Just some init precaution. Must be set to PDM_USBREG_VERSION. */
409
/** Pointer to a PDM USB Device Structure. */
410
typedef PDMUSBREG *PPDMUSBREG;
411
/** Const pointer to a PDM USB Device Structure. */
412
typedef PDMUSBREG const *PCPDMUSBREG;
414
/** Current USBREG version number. */
415
#define PDM_USBREG_VERSION PDM_VERSION_MAKE(0xeeff, 1, 0)
417
/** PDM USB Device Flags.
426
* PDM USB Device API.
428
typedef struct PDMUSBHLP
430
/** Structure version. PDM_USBHLP_VERSION defines the current version. */
434
* Attaches a driver (chain) to the USB device.
436
* The first call for a LUN this will serve as a registartion of the LUN. The pBaseInterface and
437
* the pszDesc string will be registered with that LUN and kept around for PDMR3QueryUSBDeviceLun().
439
* @returns VBox status code.
440
* @param pUsbIns The USB device instance.
441
* @param iLun The logical unit to attach.
442
* @param pBaseInterface Pointer to the base interface for that LUN. (device side / down)
443
* @param ppBaseInterface Where to store the pointer to the base interface. (driver side / up)
444
* @param pszDesc Pointer to a string describing the LUN. This string must remain valid
445
* for the live of the device instance.
447
DECLR3CALLBACKMEMBER(int, pfnDriverAttach,(PPDMUSBINS pUsbIns, RTUINT iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc));
450
* Assert that the current thread is the emulation thread.
452
* @returns True if correct.
453
* @returns False if wrong.
454
* @param pUsbIns The USB device instance.
455
* @param pszFile Filename of the assertion location.
456
* @param iLine Linenumber of the assertion location.
457
* @param pszFunction Function of the assertion location.
459
DECLR3CALLBACKMEMBER(bool, pfnAssertEMT,(PPDMUSBINS pUsbIns, const char *pszFile, unsigned iLine, const char *pszFunction));
462
* Assert that the current thread is NOT the emulation thread.
464
* @returns True if correct.
465
* @returns False if wrong.
466
* @param pUsbIns The USB device instance.
467
* @param pszFile Filename of the assertion location.
468
* @param iLine Linenumber of the assertion location.
469
* @param pszFunction Function of the assertion location.
471
DECLR3CALLBACKMEMBER(bool, pfnAssertOther,(PPDMUSBINS pUsbIns, const char *pszFile, unsigned iLine, const char *pszFunction));
474
* Stops the VM and enters the debugger to look at the guest state.
476
* Use the PDMUsbDBGFStop() inline function with the RT_SRC_POS macro instead of
477
* invoking this function directly.
479
* @returns VBox status code which must be passed up to the VMM.
480
* @param pUsbIns The USB device instance.
481
* @param pszFile Filename of the assertion location.
482
* @param iLine The linenumber of the assertion location.
483
* @param pszFunction Function of the assertion location.
484
* @param pszFormat Message. (optional)
485
* @param va Message parameters.
487
DECLR3CALLBACKMEMBER(int, pfnDBGFStopV,(PPDMUSBINS pUsbIns, const char *pszFile, unsigned iLine, const char *pszFunction, const char *pszFormat, va_list va));
490
* Register a info handler with DBGF,
492
* @returns VBox status code.
493
* @param pUsbIns The USB device instance.
494
* @param pszName The identifier of the info.
495
* @param pszDesc The description of the info and any arguments the handler may take.
496
* @param pfnHandler The handler function to be called to display the info.
498
DECLR3CALLBACKMEMBER(int, pfnDBGFInfoRegister,(PPDMUSBINS pUsbIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERUSB pfnHandler));
501
* Allocate memory which is associated with current VM instance
502
* and automatically freed on it's destruction.
504
* @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
505
* @param pUsbIns The USB device instance.
506
* @param cb Number of bytes to allocate.
508
DECLR3CALLBACKMEMBER(void *, pfnMMHeapAlloc,(PPDMUSBINS pUsbIns, size_t cb));
511
* Allocate memory which is associated with current VM instance
512
* and automatically freed on it's destruction. The memory is ZEROed.
514
* @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
515
* @param pUsbIns The USB device instance.
516
* @param cb Number of bytes to allocate.
518
DECLR3CALLBACKMEMBER(void *, pfnMMHeapAllocZ,(PPDMUSBINS pUsbIns, size_t cb));
523
* @returns VBox status code.
524
* @param pUsbIns The USB device instance.
525
* @param cbItem Size a queue item.
526
* @param cItems Number of items in the queue.
527
* @param cMilliesInterval Number of milliseconds between polling the queue.
528
* If 0 then the emulation thread will be notified whenever an item arrives.
529
* @param pfnCallback The consumer function.
530
* @param pszName The queue base name. The instance number will be
531
* appended automatically.
532
* @param ppQueue Where to store the queue handle on success.
533
* @thread The emulation thread.
535
DECLR3CALLBACKMEMBER(int, pfnPDMQueueCreate,(PPDMUSBINS pUsbIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
536
PFNPDMQUEUEUSB pfnCallback, const char *pszName, PPDMQUEUE *ppQueue));
539
* Register a save state data unit.
541
* @returns VBox status.
542
* @param pUsbIns The USB device instance.
543
* @param uVersion Data layout version number.
544
* @param cbGuess The approximate amount of data in the unit.
545
* Only for progress indicators.
547
* @param pfnLivePrep Prepare live save callback, optional.
548
* @param pfnLiveExec Execute live save callback, optional.
549
* @param pfnLiveVote Vote live save callback, optional.
551
* @param pfnSavePrep Prepare save callback, optional.
552
* @param pfnSaveExec Execute save callback, optional.
553
* @param pfnSaveDone Done save callback, optional.
555
* @param pfnLoadPrep Prepare load callback, optional.
556
* @param pfnLoadExec Execute load callback, optional.
557
* @param pfnLoadDone Done load callback, optional.
559
DECLR3CALLBACKMEMBER(int, pfnSSMRegister,(PPDMUSBINS pUsbIns, uint32_t uVersion, size_t cbGuess,
560
PFNSSMUSBLIVEPREP pfnLivePrep, PFNSSMUSBLIVEEXEC pfnLiveExec, PFNSSMUSBLIVEVOTE pfnLiveVote,
561
PFNSSMUSBSAVEPREP pfnSavePrep, PFNSSMUSBSAVEEXEC pfnSaveExec, PFNSSMUSBSAVEDONE pfnSaveDone,
562
PFNSSMUSBLOADPREP pfnLoadPrep, PFNSSMUSBLOADEXEC pfnLoadExec, PFNSSMUSBLOADDONE pfnLoadDone));
565
* Register a STAM sample.
567
* Use the PDMUsbHlpSTAMRegister wrapper.
569
* @returns VBox status.
570
* @param pUsbIns The USB device instance.
571
* @param pvSample Pointer to the sample.
572
* @param enmType Sample type. This indicates what pvSample is pointing at.
573
* @param enmVisibility Visibility type specifying whether unused statistics should be visible or not.
574
* @param enmUnit Sample unit.
575
* @param pszDesc Sample description.
576
* @param pszName The sample name format string.
577
* @param va Arguments to the format string.
579
DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterV,(PPDMUSBINS pUsbIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
580
STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list va));
585
* @returns VBox status.
586
* @param pUsbIns The USB device instance.
587
* @param enmClock The clock to use on this timer.
588
* @param pfnCallback Callback function.
589
* @param pvUser User argument for the callback.
590
* @param fFlags Flags, see TMTIMER_FLAGS_*.
591
* @param pszDesc Pointer to description string which must stay around
592
* until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
593
* @param ppTimer Where to store the timer on success.
595
DECLR3CALLBACKMEMBER(int, pfnTMTimerCreate,(PPDMUSBINS pUsbIns, TMCLOCK enmClock, PFNTMTIMERUSB pfnCallback, void *pvUser,
596
uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer));
599
* Set the VM error message
602
* @param pUsbIns The USB device instance.
603
* @param rc VBox status code.
604
* @param RT_SRC_POS_DECL Use RT_SRC_POS.
605
* @param pszFormat Error message format string.
606
* @param va Error message arguments.
608
DECLR3CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMUSBINS pUsbIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
611
* Set the VM runtime error message
613
* @returns VBox status code.
614
* @param pUsbIns The USB device instance.
615
* @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
616
* @param pszErrorId Error ID string.
617
* @param pszFormat Error message format string.
618
* @param va Error message arguments.
620
DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMUSBINS pUsbIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va));
626
* @param pUsbIns The USB device instance.
627
* @thread Any thread (just keep in mind that it's volatile info).
629
DECLR3CALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMUSBINS pUsbIns));
632
* Set up asynchronous handling of a suspend, reset or power off notification.
634
* This shall only be called when getting the notification. It must be called
637
* @returns VBox status code.
638
* @param pUSBIns The USB device instance.
639
* @param pfnAsyncNotify The callback.
642
DECLR3CALLBACKMEMBER(int, pfnSetAsyncNotification, (PPDMUSBINS pUSbIns, PFNPDMUSBASYNCNOTIFY pfnAsyncNotify));
645
* Notify EMT(0) that the device has completed the asynchronous notification
648
* This can be called at any time, spurious calls will simply be ignored.
650
* @param pUSBIns The USB device instance.
653
DECLR3CALLBACKMEMBER(void, pfnAsyncNotificationCompleted, (PPDMUSBINS pUsbIns));
655
/** Just a safety precaution. */
658
/** Pointer PDM USB Device API. */
659
typedef PDMUSBHLP *PPDMUSBHLP;
660
/** Pointer const PDM USB Device API. */
661
typedef const PDMUSBHLP *PCPDMUSBHLP;
663
/** Current USBHLP version number. */
664
#define PDM_USBHLP_VERSION PDM_VERSION_MAKE(0xeefe, 1, 0)
666
#endif /* IN_RING3 */
669
* PDM USB Device Instance.
671
typedef struct PDMUSBINS
673
/** Structure version. PDM_USBINS_VERSION defines the current version. */
675
/** USB device instance number. */
677
/** The base interface of the device.
678
* The device constructor initializes this if it has any device level
679
* interfaces to export. To obtain this interface call PDMR3QueryUSBDevice(). */
681
#if HC_ARCH_BITS == 32
682
uint32_t u32Alignment; /**< Alignment padding. */
685
/** Internal data. */
688
#ifdef PDMUSBINSINT_DECLARED
691
uint8_t padding[HC_ARCH_BITS == 32 ? 96 : 128];
694
/** Pointer the PDM USB Device API. */
695
R3PTRTYPE(PCPDMUSBHLP) pHlpR3;
696
/** Pointer to the USB device registration structure. */
697
R3PTRTYPE(PCPDMUSBREG) pReg;
698
/** Configuration handle. */
699
R3PTRTYPE(PCFGMNODE) pCfg;
700
/** The (device) global configuration handle. */
701
R3PTRTYPE(PCFGMNODE) pCfgGlobal;
702
/** Pointer to device instance data. */
703
R3PTRTYPE(void *) pvInstanceDataR3;
704
/** Pointer to the VUSB Device structure.
705
* Internal to VUSB, don't touch.
706
* @todo Moved this to PDMUSBINSINT. */
707
R3PTRTYPE(void *) pvVUsbDev2;
708
/** Device name for using when logging.
709
* The constructor sets this and the destructor frees it. */
710
R3PTRTYPE(char *) pszName;
711
/** Padding to make achInstanceData aligned at 32 byte boundrary. */
712
uint32_t au32Padding[HC_ARCH_BITS == 32 ? 5 : 2];
713
/** Device instance data. The size of this area is defined
714
* in the PDMUSBREG::cbInstanceData field. */
715
char achInstanceData[8];
718
/** Current USBINS version number. */
719
#define PDM_USBINS_VERSION PDM_VERSION_MAKE(0xeefd, 1, 0)
722
* Checks the structure versions of the USB device instance and USB device
723
* helpers, returning if they are incompatible.
725
* This is for use in the constructor.
727
* @param pUsbIns The USB device instance pointer.
729
#define PDMUSB_CHECK_VERSIONS_RETURN(pUsbIns) \
732
PPDMUSBINS pUsbInsTypeCheck = (pUsbIns); NOREF(pUsbInsTypeCheck); \
733
AssertLogRelMsgReturn(PDM_VERSION_ARE_COMPATIBLE((pUsbIns)->u32Version, PDM_USBINS_VERSION), \
734
("DevIns=%#x mine=%#x\n", (pUsbIns)->u32Version, PDM_USBINS_VERSION), \
735
VERR_VERSION_MISMATCH); \
736
AssertLogRelMsgReturn(PDM_VERSION_ARE_COMPATIBLE((pUsbIns)->pHlpR3->u32Version, PDM_USBHLP_VERSION), \
737
("DevHlp=%#x mine=%#x\n", (pUsbIns)->pHlpR3->u32Version, PDM_USBHLP_VERSION), \
738
VERR_VERSION_MISMATCH); \
742
* Quietly checks the structure versions of the USB device instance and
743
* USB device helpers, returning if they are incompatible.
745
* This is for use in the destructor.
747
* @param pUsbIns The USB device instance pointer.
749
#define PDMUSB_CHECK_VERSIONS_RETURN_QUIET(pUsbIns) \
752
PPDMUSBINS pUsbInsTypeCheck = (pUsbIns); NOREF(pUsbInsTypeCheck); \
753
if (RT_UNLIKELY( !PDM_VERSION_ARE_COMPATIBLE((pUsbIns)->u32Version, PDM_USBINS_VERSION) \
754
|| !PDM_VERSION_ARE_COMPATIBLE((pUsbIns)->pHlpR3->u32Version, PDM_USBHLPR3_VERSION) )) \
755
return VERR_VERSION_MISMATCH; \
759
/** Converts a pointer to the PDMUSBINS::IBase to a pointer to PDMUSBINS. */
760
#define PDMIBASE_2_PDMUSB(pInterface) ( (PPDMUSBINS)((char *)(pInterface) - RT_OFFSETOF(PDMUSBINS, IBase)) )
763
/** @def PDMUSB_ASSERT_EMT
764
* Assert that the current thread is the emulation thread.
767
# define PDMUSB_ASSERT_EMT(pUsbIns) pUsbIns->pHlpR3->pfnAssertEMT(pUsbIns, __FILE__, __LINE__, __FUNCTION__)
769
# define PDMUSB_ASSERT_EMT(pUsbIns) do { } while (0)
772
/** @def PDMUSB_ASSERT_OTHER
773
* Assert that the current thread is NOT the emulation thread.
776
# define PDMUSB_ASSERT_OTHER(pUsbIns) pUsbIns->pHlpR3->pfnAssertOther(pUsbIns, __FILE__, __LINE__, __FUNCTION__)
778
# define PDMUSB_ASSERT_OTHER(pUsbIns) do { } while (0)
781
/** @def PDMUSB_SET_ERROR
782
* Set the VM error. See PDMUsbHlpVMSetError() for printf like message
785
#define PDMUSB_SET_ERROR(pUsbIns, rc, pszError) \
786
PDMUsbHlpVMSetError(pUsbIns, rc, RT_SRC_POS, "%s", pszError)
788
/** @def PDMUSB_SET_RUNTIME_ERROR
789
* Set the VM runtime error. See PDMUsbHlpVMSetRuntimeError() for printf like
790
* message formatting.
792
#define PDMUSB_SET_RUNTIME_ERROR(pUsbIns, fFlags, pszErrorId, pszError) \
793
PDMUsbHlpVMSetRuntimeError(pUsbIns, fFlags, pszErrorId, "%s", pszError)
799
* @copydoc PDMUSBHLP::pfnDriverAttach
801
DECLINLINE(int) PDMUsbHlpDriverAttach(PPDMUSBINS pUsbIns, RTUINT iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc)
803
return pUsbIns->pHlpR3->pfnDriverAttach(pUsbIns, iLun, pBaseInterface, ppBaseInterface, pszDesc);
807
* VBOX_STRICT wrapper for pHlpR3->pfnDBGFStopV.
809
* @returns VBox status code which must be passed up to the VMM.
810
* @param pUsbIns Device instance.
811
* @param RT_SRC_POS_DECL Use RT_SRC_POS.
812
* @param pszFormat Message. (optional)
813
* @param ... Message parameters.
815
DECLINLINE(int) PDMUsbDBGFStop(PPDMUSBINS pUsbIns, RT_SRC_POS_DECL, const char *pszFormat, ...)
820
va_start(va, pszFormat);
821
rc = pUsbIns->pHlpR3->pfnDBGFStopV(pUsbIns, RT_SRC_POS_ARGS, pszFormat, va);
835
* @copydoc PDMUSBHLP::pfnVMState
837
DECLINLINE(VMSTATE) PDMUsbHlpVMState(PPDMUSBINS pUsbIns)
839
return pUsbIns->pHlpR3->pfnVMState(pUsbIns);
843
* @copydoc PDMUSBHLP::pfnSetAsyncNotification
845
DECLINLINE(int) PDMUsbHlpSetAsyncNotification(PPDMUSBINS pUsbIns, PFNPDMUSBASYNCNOTIFY pfnAsyncNotify)
847
return pUsbIns->pHlpR3->pfnSetAsyncNotification(pUsbIns, pfnAsyncNotify);
851
* @copydoc PDMUSBHLP::pfnAsyncNotificationCompleted
853
DECLINLINE(void) PDMUsbHlpAsyncNotificationCompleted(PPDMUSBINS pUsbIns)
855
pUsbIns->pHlpR3->pfnAsyncNotificationCompleted(pUsbIns);
859
* Set the VM error message
862
* @param pUsbIns The USB device instance.
863
* @param rc VBox status code.
864
* @param RT_SRC_POS_DECL Use RT_SRC_POS.
865
* @param pszFormat Error message format string.
866
* @param ... Error message arguments.
868
DECLINLINE(int) PDMUsbHlpVMSetError(PPDMUSBINS pUsbIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
871
va_start(va, pszFormat);
872
rc = pUsbIns->pHlpR3->pfnVMSetErrorV(pUsbIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
878
* @copydoc PDMUSBHLP::pfnMMHeapAlloc
880
DECLINLINE(void *) PDMUsbHlpMMHeapAlloc(PPDMUSBINS pUsbIns, size_t cb)
882
return pUsbIns->pHlpR3->pfnMMHeapAlloc(pUsbIns, cb);
886
* @copydoc PDMUSBHLP::pfnMMHeapAllocZ
888
DECLINLINE(void *) PDMUsbHlpMMHeapAllocZ(PPDMUSBINS pUsbIns, size_t cb)
890
return pUsbIns->pHlpR3->pfnMMHeapAllocZ(pUsbIns, cb);
894
* Frees memory allocated by PDMUsbHlpMMHeapAlloc or PDMUsbHlpMMHeapAllocZ.
896
* @param pUsbIns The USB device instance.
897
* @param pv The memory to free. NULL is fine.
899
DECLINLINE(void) PDMUsbHlpMMHeapFree(PPDMUSBINS pUsbIns, void *pv)
905
#endif /* IN_RING3 */
909
/** Pointer to callbacks provided to the VBoxUsbRegister() call. */
910
typedef const struct PDMUSBREGCB *PCPDMUSBREGCB;
913
* Callbacks for VBoxUSBDeviceRegister().
915
typedef struct PDMUSBREGCB
917
/** Interface version.
918
* This is set to PDM_USBREG_CB_VERSION. */
922
* Registers a device with the current VM instance.
924
* @returns VBox status code.
925
* @param pCallbacks Pointer to the callback table.
926
* @param pReg Pointer to the USB device registration record.
927
* This data must be permanent and readonly.
929
DECLR3CALLBACKMEMBER(int, pfnRegister,(PCPDMUSBREGCB pCallbacks, PCPDMUSBREG pReg));
932
/** Current version of the PDMUSBREGCB structure. */
933
#define PDM_USBREG_CB_VERSION PDM_VERSION_MAKE(0xeefc, 1, 0)
937
* The VBoxUsbRegister callback function.
939
* PDM will invoke this function after loading a USB device module and letting
940
* the module decide which devices to register and how to handle conflicts.
942
* @returns VBox status code.
943
* @param pCallbacks Pointer to the callback table.
944
* @param u32Version VBox version number.
946
typedef DECLCALLBACK(int) FNPDMVBOXUSBREGISTER(PCPDMUSBREGCB pCallbacks, uint32_t u32Version);
948
VMMR3DECL(int) PDMR3USBCreateProxyDevice(PVM pVM, PCRTUUID pUuid, bool fRemote, const char *pszAddress, void *pvBackend,
949
uint32_t iUsbVersion, uint32_t fMaskedIfs);
950
VMMR3DECL(int) PDMR3USBDetachDevice(PVM pVM, PCRTUUID pUuid);
951
VMMR3DECL(bool) PDMR3USBHasHub(PVM pVM);