VirtualBox

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

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

PDM,UsbMsd,++: Resumed hacking the MSD code.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette