VirtualBox

source: vbox/trunk/include/VBox/pdmusb.h@ 5764

Last change on this file since 5764 was 5750, checked in by vboxsync, 17 years ago

refactored the URB part of the VUSB <-> Device interface.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 27.6 KB
Line 
1/** @file
2 * PDM - Pluggable Device Manager, USB Devices.
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
12 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
13 * distribution. VirtualBox OSE is distributed in the hope that it will
14 * be useful, but WITHOUT ANY WARRANTY of any kind.
15 */
16
17#ifndef ___VBox_pdmusb_h
18#define ___VBox_pdmusb_h
19
20#include <VBox/pdmqueue.h>
21#include <VBox/pdmcritsect.h>
22#include <VBox/pdmthread.h>
23#include <VBox/pdmifs.h>
24#include <VBox/tm.h>
25#include <VBox/ssm.h>
26#include <VBox/cfgm.h>
27#include <VBox/dbgf.h>
28#include <VBox/mm.h>
29#include <VBox/err.h>
30#include <VBox/vusb.h>
31#include <iprt/stdarg.h>
32
33__BEGIN_DECLS
34
35/** @defgroup grp_pdm_usbdev USB Devices
36 * @ingroup grp_pdm
37 * @{
38 */
39
40
41/** PDM USB Device Registration Structure,
42 *
43 * This structure is used when registering a device from VBoxUsbRegister() in HC Ring-3.
44 * The PDM will make use of this structure untill the VM is destroyed.
45 */
46typedef struct PDMUSBREG
47{
48 /** Structure version. PDM_DEVREG_VERSION defines the current version. */
49 uint32_t u32Version;
50 /** Device name. */
51 char szDeviceName[32];
52 /** The description of the device. The UTF-8 string pointed to shall, like this structure,
53 * remain unchanged from registration till VM destruction. */
54 const char *pszDescription;
55
56 /** Flags, combination of the PDM_USBREG_FLAGS_* \#defines. */
57 RTUINT fFlags;
58 /** Maximum number of instances (per VM). */
59 RTUINT cMaxInstances;
60 /** Size of the instance data. */
61 RTUINT cbInstance;
62
63
64 /**
65 * Construct an USB device instance for a VM.
66 *
67 * @returns VBox status.
68 * @param pUsbIns The USB device instance data.
69 * If the registration structure is needed, pUsbDev->pDevReg points to it.
70 * @param iInstance Instance number. Use this to figure out which registers and such to use.
71 * The instance number is also found in pUsbDev->iInstance, but since it's
72 * likely to be freqently used PDM passes it as parameter.
73 * @param pCfg Configuration node handle for the device. Use this to obtain the configuration
74 * of the device instance. It's also found in pUsbDev->pCfg, but since it's
75 * primary usage will in this function it's passed as a parameter.
76 * @param pCfgGlobal Handle to the global device configuration. Also found in pUsbDev->pCfgGlobal.
77 * @remarks This callback is required.
78 */
79 DECLR3CALLBACKMEMBER(int, pfnConstruct,(PPDMUSBINS pUsbIns, int iInstance, PCFGMNODE pCfg, PCFGMNODE pCfgGlobal));
80
81 /**
82 * Destruct an USB device instance.
83 *
84 * Most VM resources are freed by the VM. This callback is provided so that any non-VM
85 * resources can be freed correctly.
86 *
87 * This method will be called regardless of the pfnConstruc result to avoid
88 * complicated failure paths.
89 *
90 * @param pUsbIns The USB device instance data.
91 * @remarks Optional.
92 */
93 DECLR3CALLBACKMEMBER(void, pfnDestruct,(PPDMUSBINS pUsbIns));
94
95
96 /**
97 * Init complete notification.
98 *
99 * This can be done to do communication with other devices and other
100 * initialization which requires everything to be in place.
101 *
102 * @returns VBOX status code.
103 * @param pUsbIns The USB device instance data.
104 * @remarks Optional.
105 * @remarks Not called when hotplugged.
106 */
107 DECLR3CALLBACKMEMBER(int, pfnVMInitComplete,(PPDMUSBINS pUsbIns));
108
109 /**
110 * VM Power On notification.
111 *
112 * @returns VBox status.
113 * @param pUsbIns The USB device instance data.
114 * @remarks Optional.
115 */
116 DECLR3CALLBACKMEMBER(void, pfnVMPowerOn,(PPDMUSBINS pUsbIns));
117
118 /**
119 * VM Reset notification.
120 *
121 * @returns VBox status.
122 * @param pUsbIns The USB device instance data.
123 * @remarks Optional.
124 */
125 DECLR3CALLBACKMEMBER(void, pfnVMReset,(PPDMUSBINS pUsbIns));
126
127 /**
128 * VM Suspend notification.
129 *
130 * @returns VBox status.
131 * @param pUsbIns The USB device instance data.
132 * @remarks Optional.
133 */
134 DECLR3CALLBACKMEMBER(void, pfnVMSuspend,(PPDMUSBINS pUsbIns));
135
136 /**
137 * VM Resume notification.
138 *
139 * @returns VBox status.
140 * @param pUsbIns The USB device instance data.
141 * @remarks Optional.
142 */
143 DECLR3CALLBACKMEMBER(void, pfnVMResume,(PPDMUSBINS pUsbIns));
144
145 /**
146 * VM Power Off notification.
147 *
148 * @param pUsbIns The USB device instance data.
149 */
150 DECLR3CALLBACKMEMBER(void, pfnVMPowerOff,(PPDMUSBINS pUsbIns));
151
152 /**
153 * Called after the constructor when attaching a device at run time.
154 *
155 * This can be used to do tasks normally assigned to pfnInitComplete and/or pfnVMPowerOn.
156 *
157 * @returns VBox status.
158 * @param pUsbIns The USB device instance data.
159 * @remarks Optional.
160 */
161 DECLR3CALLBACKMEMBER(void, pfnHotPlugged,(PPDMUSBINS pUsbIns));
162
163 /**
164 * Called before the destructor when a device is unplugged at run time.
165 *
166 * This can be used to do tasks normally assigned to pfnVMSuspend and/or pfnVMPowerOff.
167 *
168 * @returns VBox status.
169 * @param pUsbIns The USB device instance data.
170 * @remarks Optional.
171 */
172 DECLR3CALLBACKMEMBER(void, pfnHotUnplugged,(PPDMUSBINS pUsbIns));
173 /**
174 * Driver Attach command.
175 *
176 * This is called to let the USB device attach to a driver for a specified LUN
177 * at runtime. This is not called during VM construction, the device constructor
178 * have to attach to all the available drivers.
179 *
180 * @returns VBox status code.
181 * @param pUsbIns The USB device instance data.
182 * @param iLUN The logical unit which is being detached.
183 * @remarks Optional.
184 */
185 DECLR3CALLBACKMEMBER(int, pfnDriverAttach,(PPDMUSBINS pUsbIns, unsigned iLUN));
186
187 /**
188 * Driver Detach notification.
189 *
190 * This is called when a driver is detaching itself from a LUN of the device.
191 * The device should adjust it's state to reflect this.
192 *
193 * @param pUsbIns The USB device instance data.
194 * @param iLUN The logical unit which is being detached.
195 * @remarks Optional.
196 */
197 DECLR3CALLBACKMEMBER(void, pfnDriverDetach,(PPDMUSBINS pUsbIns, unsigned iLUN));
198
199 /**
200 * Query the base interface of a logical unit.
201 *
202 * @returns VBOX status code.
203 * @param pUsbIns The USB device instance data.
204 * @param iLUN The logicial unit to query.
205 * @param ppBase Where to store the pointer to the base interface of the LUN.
206 * @remarks Optional.
207 */
208 DECLR3CALLBACKMEMBER(int, pfnQueryInterface,(PPDMUSBINS pUsbIns, unsigned iLUN, PPDMIBASE *ppBase));
209
210 /**
211 * Requests the USB device to reset.
212 *
213 * @returns VBox stauts code.
214 * @param pUsbIns The USB device instance.
215 * @param fResetOnLinux A hint to the usb proxy.
216 * Don't use this unless you're the linux proxy device.
217 * @thread Any thread.
218 * @remarks Optional.
219 */
220 DECLR3CALLBACKMEMBER(int, pfnUsbReset,(PPDMUSBINS pUsbIns, bool fResetOnLinux));
221
222 /**
223 * SET_CONFIGURATION request.
224 *
225 * @returns VBox stauts code.
226 * @param pUsbIns The USB device instance.
227 * @param bConfigurationValue The bConfigurationValue of the new configuration.
228 * @param pvOldCfgDesc Internal - for the device proxy.
229 * @param pvOldIfState Internal - for the device proxy.
230 * @param pvNewCfgDesc Internal - for the device proxy.
231 * @remarks Optional.
232 */
233 DECLR3CALLBACKMEMBER(int, pfnUsbSetConfiguration,(PPDMUSBINS pUsbIns, uint8_t bConfigurationValue,
234 const void *pvOldCfgDesc, const void *pvOldIfState, const void *pvNewCfgDesc));
235
236 /**
237 * SET_INTERFACE request.
238 *
239 * @returns VBox stauts code.
240 * @param pUsbIns The USB device instance.
241 * @param bInterfaceNumber The interface number.
242 * @param bAlternateSetting The alternate setting.
243 * @remarks Optional.
244 */
245 DECLR3CALLBACKMEMBER(int, pfnUsbSetInterface,(PPDMUSBINS pUsbIns, uint8_t bInterfaceNumber, uint8_t bAlternateSetting));
246
247 /**
248 * Clears the halted state of an endpoint. (Optional)
249 *
250 * This called when VUSB sees a CLEAR_FEATURE(ENDPOINT_HALT) on request
251 * on the zero pipe.
252 *
253 * @returns VBox stauts code.
254 * @param pUsbIns The USB device instance.
255 * @param uEndpoint The endpoint to clear.
256 * @remarks Optional.
257 */
258 DECLR3CALLBACKMEMBER(int, pfnUsbClearHaltedEndpoint,(PPDMUSBINS pUsbIns, unsigned uEndpoint));
259
260 /**
261 * Allocates an URB.
262 *
263 * This can be used to make use of shared user/kernel mode buffers.
264 *
265 * @returns VBox stauts code.
266 * @param pUsbIns The USB device instance.
267 * @param cbData The size of the data buffer.
268 * @param cTds The number of TDs.
269 * @param enmType The type of URB.
270 * @param ppUrb Where to store the allocated URB.
271 * @remarks Optional.
272 * @remarks Not implemented yet.
273 */
274 DECLR3CALLBACKMEMBER(int, pfnUrbNew,(PPDMUSBINS pUsbIns, size_t cbData, size_t cTds, VUSBXFERTYPE enmType, PVUSBURB *ppUrb));
275
276 /**
277 * Queues an URB for processing.
278 *
279 * @returns VBox stauts code.
280 * @param pUsbIns The USB device instance.
281 * @param pUrb The URB to process.
282 * @remarks Mandatory.
283 */
284 DECLR3CALLBACKMEMBER(int, pfnUrbQueue,(PPDMUSBINS pUsbIns, PVUSBURB pUrb));
285
286 /**
287 * Cancels an URB.
288 *
289 * @returns VBox stauts code.
290 * @param pUsbIns The USB device instance.
291 * @param pUrb The URB to cancel.
292 * @remarks Mandatory.
293 */
294 DECLR3CALLBACKMEMBER(int, pfnUrbCancel,(PPDMUSBINS pUsbIns, PVUSBURB pUrb));
295
296 /**
297 * Reaps an URB.
298 *
299 * @returns A ripe URB, NULL if none.
300 * @param pUsbIns The USB device instance.
301 * @param cMillies How log to wait for an URB to become ripe.
302 * @remarks Mandatory.
303 */
304 DECLR3CALLBACKMEMBER(PVUSBURB, pfnUrbReap,(PPDMUSBINS pUsbIns, unsigned cMillies));
305
306
307 /** Just some init precaution. Must be set to PDM_USBREG_VERSION. */
308 uint32_t u32TheEnd;
309} PDMUSBREG;
310/** Pointer to a PDM USB Device Structure. */
311typedef PDMUSBREG *PPDMUSBREG;
312/** Const pointer to a PDM USB Device Structure. */
313typedef PDMUSBREG const *PCPDMUSBREG;
314
315/** Current USBREG version number. */
316#define PDM_USBREG_VERSION 0xed010000
317
318/** PDM USB Device Flags.
319 * @{ */
320/* none yet */
321/** @} */
322
323#ifdef IN_RING3
324/**
325 * PDM USB Device API.
326 */
327typedef struct PDMUSBHLP
328{
329 /** Structure version. PDM_USBHLP_VERSION defines the current version. */
330 uint32_t u32Version;
331
332 /**
333 * Attaches a driver (chain) to the USB device.
334 *
335 * The first call for a LUN this will serve as a registartion of the LUN. The pBaseInterface and
336 * the pszDesc string will be registered with that LUN and kept around for PDMR3QueryUSBDeviceLun().
337 *
338 * @returns VBox status code.
339 * @param pUsbIns The USB device instance.
340 * @param iLun The logical unit to attach.
341 * @param pBaseInterface Pointer to the base interface for that LUN. (device side / down)
342 * @param ppBaseInterface Where to store the pointer to the base interface. (driver side / up)
343 * @param pszDesc Pointer to a string describing the LUN. This string must remain valid
344 * for the live of the device instance.
345 */
346 DECLR3CALLBACKMEMBER(int, pfnDriverAttach,(PPDMUSBINS pUsbIns, RTUINT iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc));
347
348 /**
349 * Assert that the current thread is the emulation thread.
350 *
351 * @returns True if correct.
352 * @returns False if wrong.
353 * @param pUsbIns The USB device instance.
354 * @param pszFile Filename of the assertion location.
355 * @param iLine Linenumber of the assertion location.
356 * @param pszFunction Function of the assertion location.
357 */
358 DECLR3CALLBACKMEMBER(bool, pfnAssertEMT,(PPDMUSBINS pUsbIns, const char *pszFile, unsigned iLine, const char *pszFunction));
359
360 /**
361 * Assert that the current thread is NOT the emulation thread.
362 *
363 * @returns True if correct.
364 * @returns False if wrong.
365 * @param pUsbIns The USB device instance.
366 * @param pszFile Filename of the assertion location.
367 * @param iLine Linenumber of the assertion location.
368 * @param pszFunction Function of the assertion location.
369 */
370 DECLR3CALLBACKMEMBER(bool, pfnAssertOther,(PPDMUSBINS pUsbIns, const char *pszFile, unsigned iLine, const char *pszFunction));
371
372 /**
373 * Stops the VM and enters the debugger to look at the guest state.
374 *
375 * Use the PDMUsbDBGFStop() inline function with the RT_SRC_POS macro instead of
376 * invoking this function directly.
377 *
378 * @returns VBox status code which must be passed up to the VMM.
379 * @param pUsbIns The USB device instance.
380 * @param pszFile Filename of the assertion location.
381 * @param iLine The linenumber of the assertion location.
382 * @param pszFunction Function of the assertion location.
383 * @param pszFormat Message. (optional)
384 * @param va Message parameters.
385 */
386 DECLR3CALLBACKMEMBER(int, pfnDBGFStopV,(PPDMUSBINS pUsbIns, const char *pszFile, unsigned iLine, const char *pszFunction, const char *pszFormat, va_list va));
387
388 /**
389 * Register a info handler with DBGF,
390 *
391 * @returns VBox status code.
392 * @param pUsbIns The USB device instance.
393 * @param pszName The identifier of the info.
394 * @param pszDesc The description of the info and any arguments the handler may take.
395 * @param pfnHandler The handler function to be called to display the info.
396 */
397/** @todo DECLR3CALLBACKMEMBER(int, pfnDBGFInfoRegister,(PPDMUSBINS pUsbIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERUSB pfnHandler)); */
398
399 /**
400 * Allocate memory which is associated with current VM instance
401 * and automatically freed on it's destruction.
402 *
403 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
404 * @param pUsbIns The USB device instance.
405 * @param cb Number of bytes to allocate.
406 */
407 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAlloc,(PPDMUSBINS pUsbIns, size_t cb));
408
409 /**
410 * Allocate memory which is associated with current VM instance
411 * and automatically freed on it's destruction. The memory is ZEROed.
412 *
413 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
414 * @param pUsbIns The USB device instance.
415 * @param cb Number of bytes to allocate.
416 */
417 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAllocZ,(PPDMUSBINS pUsbIns, size_t cb));
418
419 /**
420 * Create a queue.
421 *
422 * @returns VBox status code.
423 * @param pUsbIns The USB device instance.
424 * @param cbItem Size a queue item.
425 * @param cItems Number of items in the queue.
426 * @param cMilliesInterval Number of milliseconds between polling the queue.
427 * If 0 then the emulation thread will be notified whenever an item arrives.
428 * @param pfnCallback The consumer function.
429 * @param ppQueue Where to store the queue handle on success.
430 * @thread The emulation thread.
431 */
432/** @todo DECLR3CALLBACKMEMBER(int, pfnPDMQueueCreate,(PPDMUSBINS pUsbIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval, PFNPDMQUEUEUSB pfnCallback, PPDMQUEUE *ppQueue)); */
433
434 /**
435 * Register a save state data unit.
436 *
437 * @returns VBox status.
438 * @param pUsbIns The USB device instance.
439 * @param pszName Data unit name.
440 * @param u32Instance The instance identifier of the data unit.
441 * This must together with the name be unique.
442 * @param u32Version Data layout version number.
443 * @param cbGuess The approximate amount of data in the unit.
444 * Only for progress indicators.
445 * @param pfnSavePrep Prepare save callback, optional.
446 * @param pfnSaveExec Execute save callback, optional.
447 * @param pfnSaveDone Done save callback, optional.
448 * @param pfnLoadPrep Prepare load callback, optional.
449 * @param pfnLoadExec Execute load callback, optional.
450 * @param pfnLoadDone Done load callback, optional.
451 */
452/** @todo DECLR3CALLBACKMEMBER(int, pfnSSMRegister,(PPDMUSBINS pUsbIns, const char *pszName, uint32_t u32Instance, uint32_t u32Version, size_t cbGuess,
453 PFNSSMUSBSAVEPREP pfnSavePrep, PFNSSMUSBSAVEEXEC pfnSaveExec, PFNSSMUSBSAVEDONE pfnSaveDone,
454 PFNSSMUSBLOADPREP pfnLoadPrep, PFNSSMUSBLOADEXEC pfnLoadExec, PFNSSMUSBLOADDONE pfnLoadDone)); */
455
456 /**
457 * Register a STAM sample.
458 *
459 * Use the PDMUsbHlpSTAMRegister wrapper.
460 *
461 * @returns VBox status.
462 * @param pUsbIns The USB device instance.
463 * @param pvSample Pointer to the sample.
464 * @param enmType Sample type. This indicates what pvSample is pointing at.
465 * @param enmVisibility Visibility type specifying whether unused statistics should be visible or not.
466 * @param enmUnit Sample unit.
467 * @param pszDesc Sample description.
468 * @param pszName The sample name format string.
469 * @param va Arguments to the format string.
470 */
471 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterV,(PPDMUSBINS pUsbIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
472 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list va));
473
474 /**
475 * Creates a timer.
476 *
477 * @returns VBox status.
478 * @param pUsbIns The USB device instance.
479 * @param enmClock The clock to use on this timer.
480 * @param pfnCallback Callback function.
481 * @param pszDesc Pointer to description string which must stay around
482 * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
483 * @param ppTimer Where to store the timer on success.
484 */
485/** @todo DECLR3CALLBACKMEMBER(int, pfnTMTimerCreate,(PPDMUSBINS pUsbIns, TMCLOCK enmClock, PFNTMTIMERUSB pfnCallback, const char *pszDesc, PPTMTIMERHC ppTimer)); */
486
487 /**
488 * Set the VM error message
489 *
490 * @returns rc.
491 * @param pUsbIns The USB device instance.
492 * @param rc VBox status code.
493 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
494 * @param pszFormat Error message format string.
495 * @param va Error message arguments.
496 */
497 DECLR3CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMUSBINS pUsbIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
498
499 /**
500 * Set the VM runtime error message
501 *
502 * @returns VBox status code.
503 * @param pUsbIns The USB device instance.
504 * @param fFatal Whether it is a fatal error or not.
505 * @param pszErrorID Error ID string.
506 * @param pszFormat Error message format string.
507 * @param va Error message arguments.
508 */
509 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMUSBINS pUsbIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va));
510
511 /** Just a safety precaution. */
512 uint32_t u32TheEnd;
513} PDMUSBHLP;
514/** Pointer PDM USB Device API. */
515typedef PDMUSBHLP *PPDMUSBHLP;
516/** Pointer const PDM USB Device API. */
517typedef const PDMUSBHLP *PCPDMUSBHLP;
518
519/** Current USBHLP version number. */
520#define PDM_USBHLP_VERSION 0xec020000
521
522#endif /* IN_RING3 */
523
524/**
525 * PDM USB Device Instance.
526 */
527typedef struct PDMUSBINS
528{
529 /** Structure version. PDM_USBINS_VERSION defines the current version. */
530 uint32_t u32Version;
531 /** USB device instance number. */
532 RTUINT iInstance;
533 /** The base interface of the device.
534 * The device constructor initializes this if it has any device level
535 * interfaces to export. To obtain this interface call PDMR3QueryUSBDevice(). */
536 PDMIBASE IBase;
537#if HC_ARCH_BITS == 32
538 uint32_t u32Alignment; /**< Alignment padding. */
539#endif
540
541 /** Internal data. */
542 union
543 {
544#ifdef PDMUSBINSINT_DECLARED
545 PDMUSBINSINT s;
546#endif
547 uint8_t padding[HC_ARCH_BITS == 32 ? 64 : 96];
548 } Internal;
549
550 /** Pointer the PDM USB Device API. */
551 R3PTRTYPE(PCPDMUSBHLP) pUsbHlp;
552 /** Pointer to the USB device registration structure. */
553 R3PTRTYPE(PCPDMUSBREG) pUsbReg;
554 /** Configuration handle. */
555 R3PTRTYPE(PCFGMNODE) pCfg;
556 /** The (device) global configuration handle. */
557 R3PTRTYPE(PCFGMNODE) pCfgGlobal;
558 /** Pointer to device instance data. */
559 R3PTRTYPE(void *) pvInstanceDataR3;
560 /** Pointer to the VUSB Device structure.
561 * The constructor sets this.
562 * @todo Integrate VUSBDEV into this structure. */
563 R3PTRTYPE(void *) pvVUsbDev;
564 /** Device name for using when logging.
565 * The constructor sets this and the destructor frees it. */
566 R3PTRTYPE(char *) pszName;
567 /** Padding to make achInstanceData aligned at 32 byte boundrary. */
568 uint32_t au32Padding[HC_ARCH_BITS == 32 ? 5 : 2];
569 /** Device instance data. The size of this area is defined
570 * in the PDMUSBREG::cbInstanceData field. */
571 char achInstanceData[8];
572} PDMUSBINS;
573
574/** Current USBINS version number. */
575#define PDM_USBINS_VERSION 0xf3010000
576
577/** Converts a pointer to the PDMUSBINS::IBase to a pointer to PDMUSBINS. */
578#define PDMIBASE_2_PDMUSB(pInterface) ( (PPDMUSBINS)((char *)(pInterface) - RT_OFFSETOF(PDMUSBINS, IBase)) )
579
580
581/** @def PDMUSB_ASSERT_EMT
582 * Assert that the current thread is the emulation thread.
583 */
584#ifdef VBOX_STRICT
585# define PDMUSB_ASSERT_EMT(pUsbIns) pUsbIns->pUsbHlp->pfnAssertEMT(pUsbIns, __FILE__, __LINE__, __FUNCTION__)
586#else
587# define PDMUSB_ASSERT_EMT(pUsbIns) do { } while (0)
588#endif
589
590/** @def PDMUSB_ASSERT_OTHER
591 * Assert that the current thread is NOT the emulation thread.
592 */
593#ifdef VBOX_STRICT
594# define PDMUSB_ASSERT_OTHER(pUsbIns) pUsbIns->pUsbHlp->pfnAssertOther(pUsbIns, __FILE__, __LINE__, __FUNCTION__)
595#else
596# define PDMUSB_ASSERT_OTHER(pUsbIns) do { } while (0)
597#endif
598
599/** @def PDMUSB_SET_ERROR
600 * Set the VM error. See PDMDevHlpVMSetError() for printf like message formatting.
601 */
602#define PDMUSB_SET_ERROR(pUsbIns, rc, pszError) \
603 PDMDevHlpVMSetError(pUsbIns, rc, RT_SRC_POS, "%s", pszError)
604
605/** @def PDMUSB_SET_RUNTIME_ERROR
606 * Set the VM runtime error. See PDMDevHlpVMSetRuntimeError() for printf like message formatting.
607 */
608#define PDMUSB_SET_RUNTIME_ERROR(pUsbIns, fFatal, pszErrorID, pszError) \
609 PDMDevHlpVMSetRuntimeError(pUsbIns, fFatal, pszErrorID, "%s", pszError)
610
611
612#ifdef IN_RING3
613
614/**
615 * VBOX_STRICT wrapper for pUsbHlp->pfnDBGFStopV.
616 *
617 * @returns VBox status code which must be passed up to the VMM.
618 * @param pUsbIns Device instance.
619 * @param RT_SRC_POS_DECL Use RT_SRC_POS.
620 * @param pszFormat Message. (optional)
621 * @param ... Message parameters.
622 */
623DECLINLINE(int) PDMUsbDBGFStop(PPDMUSBINS pUsbIns, RT_SRC_POS_DECL, const char *pszFormat, ...)
624{
625#ifdef VBOX_STRICT
626 int rc;
627 va_list va;
628 va_start(va, pszFormat);
629 rc = pUsbIns->pUsbHlp->pfnDBGFStopV(pUsbIns, RT_SRC_POS_ARGS, pszFormat, va);
630 va_end(va);
631 return rc;
632#else
633 return VINF_SUCCESS;
634#endif
635}
636
637
638/* inline wrappers */
639
640#endif
641
642
643
644/** Pointer to callbacks provided to the VBoxUsbRegister() call. */
645typedef const struct PDMUSBREGCB *PCPDMUSBREGCB;
646
647/**
648 * Callbacks for VBoxUSBDeviceRegister().
649 */
650typedef struct PDMUSBREGCB
651{
652 /** Interface version.
653 * This is set to PDM_USBREG_CB_VERSION. */
654 uint32_t u32Version;
655
656 /**
657 * Registers a device with the current VM instance.
658 *
659 * @returns VBox status code.
660 * @param pCallbacks Pointer to the callback table.
661 * @param pDevReg Pointer to the device registration record.
662 * This data must be permanent and readonly.
663 */
664 DECLR3CALLBACKMEMBER(int, pfnRegister,(PCPDMUSBREGCB pCallbacks, PCPDMUSBREG pDevReg));
665
666 /**
667 * Allocate memory which is associated with current VM instance
668 * and automatically freed on it's destruction.
669 *
670 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
671 * @param pCallbacks Pointer to the callback table.
672 * @param cb Number of bytes to allocate.
673 */
674 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAlloc,(PCPDMUSBREGCB pCallbacks, size_t cb));
675} PDMUSBREGCB;
676
677/** Current version of the PDMUSBREGCB structure. */
678#define PDM_USBREG_CB_VERSION 0xee010000
679
680
681/**
682 * The VBoxUsbRegister callback function.
683 *
684 * PDM will invoke this function after loading a USB device module and letting
685 * the module decide which devices to register and how to handle conflicts.
686 *
687 * @returns VBox status code.
688 * @param pCallbacks Pointer to the callback table.
689 * @param u32Version VBox version number.
690 */
691typedef DECLCALLBACK(int) FNPDMVBOXUSBREGISTER(PCPDMUSBREGCB pCallbacks, uint32_t u32Version);
692
693
694/**
695 * Creates a USB proxy device instance.
696 *
697 * This will find an appropriate HUB for the USB device, create the necessary CFGM stuff
698 * and try instantiate the proxy device.
699 *
700 * @returns VBox status code.
701 * @param pVM The VM handle.
702 * @param pUuid The UUID thats to be associated with the device.
703 * @param fRemote Whether it's a remove or local device.
704 * @param pszAddress The address string.
705 * @param pvBackend Pointer to the backend.
706 * @param iUsbVersion The preferred USB version.
707 * @param fMaskedIfs The interfaces to hide from the guest.
708 */
709PDMR3DECL(int) PDMR3USBCreateProxyDevice(PVM pVM, PCRTUUID pUuid, bool fRemote, const char *pszAddress, void *pvBackend,
710 uint32_t iUsbVersion, uint32_t fMaskedIfs);
711
712/**
713 * Detaches and destroys a USB device.
714 *
715 * @returns VBox status code.
716 * @param pVM The VM handle.
717 * @param pUuid The UUID associated with the device to detach.
718 * @thread EMT
719 */
720PDMR3DECL(int) PDMR3USBDetachDevice(PVM pVM, PCRTUUID pUuid);
721
722/**
723 * Checks if there are any USB hubs attached.
724 *
725 * @returns true / false accordingly.
726 * @param pVM Pointer to the shared VM structure.
727 */
728PDMR3DECL(bool) PDMR3USBHasHub(PVM pVM);
729
730
731/** @} */
732
733__END_DECLS
734
735#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