VirtualBox

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

Last change on this file since 17251 was 13005, checked in by vboxsync, 16 years ago

VMM/doxygen: More links.

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