VirtualBox

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

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

Made VUSBDEV internal to VUSB.

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