VirtualBox

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

Last change on this file since 28197 was 27935, checked in by vboxsync, 15 years ago

PDM: Document the pfnPowerOff behavior.

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