VirtualBox

source: vbox/trunk/include/VBox/vmm/pdmusb.h@ 90828

Last change on this file since 90828 was 87762, checked in by vboxsync, 4 years ago

VMM/UsbHlp: Changed the timer interface to TMTIMERHANDLE, adding the same set of methods as DevHlp has. bugref:9943

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 50.4 KB
Line 
1/** @file
2 * PDM - Pluggable Device Manager, USB Devices.
3 */
4
5/*
6 * Copyright (C) 2006-2020 Oracle Corporation
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
26#ifndef VBOX_INCLUDED_vmm_pdmusb_h
27#define VBOX_INCLUDED_vmm_pdmusb_h
28#ifndef RT_WITHOUT_PRAGMA_ONCE
29# pragma once
30#endif
31
32#include <VBox/vmm/pdmqueue.h>
33#include <VBox/vmm/pdmcritsect.h>
34#include <VBox/vmm/pdmthread.h>
35#include <VBox/vmm/pdmifs.h>
36#include <VBox/vmm/pdmins.h>
37#include <VBox/vmm/pdmcommon.h>
38#include <VBox/vmm/tm.h>
39#include <VBox/vmm/ssm.h>
40#include <VBox/vmm/cfgm.h>
41#include <VBox/vmm/dbgf.h>
42#include <VBox/vmm/mm.h>
43#include <VBox/vusb.h>
44#include <iprt/errcore.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/** PDM Device Flags.
121 * @{ */
122/** A high-speed capable USB 2.0 device (also required to support full-speed). */
123#define PDM_USBREG_HIGHSPEED_CAPABLE RT_BIT(0)
124/** Indicates that the device implements the saved state handlers. */
125#define PDM_USBREG_SAVED_STATE_SUPPORTED RT_BIT(1)
126/** A SuperSpeed USB 3.0 device. */
127#define PDM_USBREG_SUPERSPEED_CAPABLE RT_BIT(2)
128/** @} */
129
130/** PDM USB Device Registration Structure,
131 *
132 * This structure is used when registering a device from VBoxUsbRegister() in HC Ring-3.
133 * The PDM will make use of this structure until the VM is destroyed.
134 */
135typedef struct PDMUSBREG
136{
137 /** Structure version. PDM_DEVREG_VERSION defines the current version. */
138 uint32_t u32Version;
139 /** Device name. */
140 char szName[32];
141 /** The description of the device. The UTF-8 string pointed to shall, like this structure,
142 * remain unchanged from registration till VM destruction. */
143 const char *pszDescription;
144
145 /** Flags, combination of the PDM_USBREG_FLAGS_* \#defines. */
146 RTUINT fFlags;
147 /** Maximum number of instances (per VM). */
148 RTUINT cMaxInstances;
149 /** Size of the instance data. */
150 RTUINT cbInstance;
151
152
153 /**
154 * Construct an USB device instance for a VM.
155 *
156 * @returns VBox status.
157 * @param pUsbIns The USB device instance data.
158 * If the registration structure is needed, it will be
159 * accessible thru pUsbDev->pReg.
160 * @param iInstance Instance number. Use this to figure out which registers
161 * and such to use. The instance number is also found in
162 * pUsbDev->iInstance, but since it's likely to be
163 * frequently used PDM passes it as parameter.
164 * @param pCfg Configuration node handle for the device. Use this to
165 * obtain the configuration of the device instance. It is
166 * also found in pUsbDev->pCfg, but since it is primary
167 * usage will in this function it is passed as a parameter.
168 * @param pCfgGlobal Handle to the global device configuration. Also found
169 * in pUsbDev->pCfgGlobal.
170 * @remarks This callback is required.
171 */
172 DECLR3CALLBACKMEMBER(int, pfnConstruct,(PPDMUSBINS pUsbIns, int iInstance, PCFGMNODE pCfg, PCFGMNODE pCfgGlobal));
173
174 /**
175 * Destruct an USB device instance.
176 *
177 * Most VM resources are freed by the VM. This callback is provided so that any non-VM
178 * resources can be freed correctly.
179 *
180 * This method will be called regardless of the pfnConstruct result to avoid
181 * complicated failure paths.
182 *
183 * @param pUsbIns The USB device instance data.
184 * @remarks Optional.
185 */
186 DECLR3CALLBACKMEMBER(void, pfnDestruct,(PPDMUSBINS pUsbIns));
187
188
189 /**
190 * Init complete notification.
191 *
192 * This can be done to do communication with other devices and other
193 * initialization which requires everything to be in place.
194 *
195 * @returns VBOX status code.
196 * @param pUsbIns The USB device instance data.
197 * @remarks Optional.
198 * @remarks Not called when hotplugged.
199 */
200 DECLR3CALLBACKMEMBER(int, pfnVMInitComplete,(PPDMUSBINS pUsbIns));
201
202 /**
203 * VM Power On notification.
204 *
205 * @returns VBox status.
206 * @param pUsbIns The USB device instance data.
207 * @remarks Optional.
208 */
209 DECLR3CALLBACKMEMBER(void, pfnVMPowerOn,(PPDMUSBINS pUsbIns));
210
211 /**
212 * VM Reset notification.
213 *
214 * @returns VBox status.
215 * @param pUsbIns The USB device instance data.
216 * @remarks Optional.
217 */
218 DECLR3CALLBACKMEMBER(void, pfnVMReset,(PPDMUSBINS pUsbIns));
219
220 /**
221 * VM Suspend notification.
222 *
223 * @returns VBox status.
224 * @param pUsbIns The USB device instance data.
225 * @remarks Optional.
226 */
227 DECLR3CALLBACKMEMBER(void, pfnVMSuspend,(PPDMUSBINS pUsbIns));
228
229 /**
230 * VM Resume notification.
231 *
232 * @returns VBox status.
233 * @param pUsbIns The USB device instance data.
234 * @remarks Optional.
235 */
236 DECLR3CALLBACKMEMBER(void, pfnVMResume,(PPDMUSBINS pUsbIns));
237
238 /**
239 * VM Power Off notification.
240 *
241 * This is only called when the VMR3PowerOff call is made on a running VM. This
242 * means that there is no notification if the VM was suspended before being
243 * powered of. There will also be no callback when hot plugging devices.
244 *
245 * @param pUsbIns The USB device instance data.
246 */
247 DECLR3CALLBACKMEMBER(void, pfnVMPowerOff,(PPDMUSBINS pUsbIns));
248
249 /**
250 * Called after the constructor when attaching a device at run time.
251 *
252 * This can be used to do tasks normally assigned to pfnInitComplete and/or pfnVMPowerOn.
253 *
254 * @returns VBox status.
255 * @param pUsbIns The USB device instance data.
256 * @remarks Optional.
257 */
258 DECLR3CALLBACKMEMBER(void, pfnHotPlugged,(PPDMUSBINS pUsbIns));
259
260 /**
261 * Called before the destructor when a device is unplugged at run time.
262 *
263 * This can be used to do tasks normally assigned to pfnVMSuspend and/or pfnVMPowerOff.
264 *
265 * @returns VBox status.
266 * @param pUsbIns The USB device instance data.
267 * @remarks Optional.
268 */
269 DECLR3CALLBACKMEMBER(void, pfnHotUnplugged,(PPDMUSBINS pUsbIns));
270 /**
271 * Driver Attach command.
272 *
273 * This is called to let the USB device attach to a driver for a specified LUN
274 * at runtime. This is not called during VM construction, the device constructor
275 * have to attach to all the available drivers.
276 *
277 * @returns VBox status code.
278 * @param pUsbIns The USB device instance data.
279 * @param iLUN The logical unit which is being detached.
280 * @param fFlags Flags, combination of the PDM_TACH_FLAGS_* \#defines.
281 * @remarks Optional.
282 */
283 DECLR3CALLBACKMEMBER(int, pfnDriverAttach,(PPDMUSBINS pUsbIns, unsigned iLUN, uint32_t fFlags));
284
285 /**
286 * Driver Detach notification.
287 *
288 * This is called when a driver is detaching itself from a LUN of the device.
289 * The device should adjust it's state to reflect this.
290 *
291 * @param pUsbIns The USB device instance data.
292 * @param iLUN The logical unit which is being detached.
293 * @param fFlags Flags, combination of the PDM_TACH_FLAGS_* \#defines.
294 * @remarks Optional.
295 */
296 DECLR3CALLBACKMEMBER(void, pfnDriverDetach,(PPDMUSBINS pUsbIns, unsigned iLUN, uint32_t fFlags));
297
298 /**
299 * Query the base interface of a logical unit.
300 *
301 * @returns VBOX status code.
302 * @param pUsbIns The USB device instance data.
303 * @param iLUN The logicial unit to query.
304 * @param ppBase Where to store the pointer to the base interface of the LUN.
305 * @remarks Optional.
306 */
307 DECLR3CALLBACKMEMBER(int, pfnQueryInterface,(PPDMUSBINS pUsbIns, unsigned iLUN, PPDMIBASE *ppBase));
308
309 /**
310 * Requests the USB device to reset.
311 *
312 * @returns VBox status code.
313 * @param pUsbIns The USB device instance.
314 * @param fResetOnLinux A hint to the usb proxy.
315 * Don't use this unless you're the linux proxy device.
316 * @thread Any thread.
317 * @remarks Optional.
318 */
319 DECLR3CALLBACKMEMBER(int, pfnUsbReset,(PPDMUSBINS pUsbIns, bool fResetOnLinux));
320
321 /**
322 * Query device and configuration descriptors for the caching and servicing
323 * relevant GET_DESCRIPTOR requests.
324 *
325 * @returns Pointer to the descriptor cache (read-only).
326 * @param pUsbIns The USB device instance.
327 * @remarks Mandatory.
328 */
329 DECLR3CALLBACKMEMBER(PCPDMUSBDESCCACHE, pfnUsbGetDescriptorCache,(PPDMUSBINS pUsbIns));
330
331 /**
332 * SET_CONFIGURATION request.
333 *
334 * @returns VBox status code.
335 * @param pUsbIns The USB device instance.
336 * @param bConfigurationValue The bConfigurationValue of the new configuration.
337 * @param pvOldCfgDesc Internal - for the device proxy.
338 * @param pvOldIfState Internal - for the device proxy.
339 * @param pvNewCfgDesc Internal - for the device proxy.
340 * @remarks Optional.
341 */
342 DECLR3CALLBACKMEMBER(int, pfnUsbSetConfiguration,(PPDMUSBINS pUsbIns, uint8_t bConfigurationValue,
343 const void *pvOldCfgDesc, const void *pvOldIfState, const void *pvNewCfgDesc));
344
345 /**
346 * SET_INTERFACE request.
347 *
348 * @returns VBox status code.
349 * @param pUsbIns The USB device instance.
350 * @param bInterfaceNumber The interface number.
351 * @param bAlternateSetting The alternate setting.
352 * @remarks Optional.
353 */
354 DECLR3CALLBACKMEMBER(int, pfnUsbSetInterface,(PPDMUSBINS pUsbIns, uint8_t bInterfaceNumber, uint8_t bAlternateSetting));
355
356 /**
357 * Clears the halted state of an endpoint. (Optional)
358 *
359 * This called when VUSB sees a CLEAR_FEATURE(ENDPOINT_HALT) on request
360 * on the zero pipe.
361 *
362 * @returns VBox status code.
363 * @param pUsbIns The USB device instance.
364 * @param uEndpoint The endpoint to clear.
365 * @remarks Optional.
366 */
367 DECLR3CALLBACKMEMBER(int, pfnUsbClearHaltedEndpoint,(PPDMUSBINS pUsbIns, unsigned uEndpoint));
368
369 /**
370 * Allocates an URB.
371 *
372 * This can be used to make use of shared user/kernel mode buffers.
373 *
374 * @returns VBox status code.
375 * @param pUsbIns The USB device instance.
376 * @param cbData The size of the data buffer.
377 * @param cTds The number of TDs.
378 * @param enmType The type of URB.
379 * @param ppUrb Where to store the allocated URB.
380 * @remarks Optional.
381 * @remarks Not implemented yet.
382 */
383 DECLR3CALLBACKMEMBER(int, pfnUrbNew,(PPDMUSBINS pUsbIns, size_t cbData, size_t cTds, VUSBXFERTYPE enmType, PVUSBURB *ppUrb));
384
385 /**
386 * Queues an URB for processing.
387 *
388 * @returns VBox status code.
389 * @retval VINF_SUCCESS on success.
390 * @retval VERR_VUSB_DEVICE_NOT_ATTACHED if the device has been disconnected.
391 * @retval VERR_VUSB_FAILED_TO_QUEUE_URB as a general failure kind of thing.
392 * @retval TBD - document new stuff!
393 *
394 * @param pUsbIns The USB device instance.
395 * @param pUrb The URB to process.
396 * @remarks Mandatory.
397 */
398 DECLR3CALLBACKMEMBER(int, pfnUrbQueue,(PPDMUSBINS pUsbIns, PVUSBURB pUrb));
399
400 /**
401 * Cancels an URB.
402 *
403 * @returns VBox status code.
404 * @param pUsbIns The USB device instance.
405 * @param pUrb The URB to cancel.
406 * @remarks Mandatory.
407 */
408 DECLR3CALLBACKMEMBER(int, pfnUrbCancel,(PPDMUSBINS pUsbIns, PVUSBURB pUrb));
409
410 /**
411 * Reaps an URB.
412 *
413 * @returns A ripe URB, NULL if none.
414 * @param pUsbIns The USB device instance.
415 * @param cMillies How log to wait for an URB to become ripe.
416 * @remarks Mandatory.
417 */
418 DECLR3CALLBACKMEMBER(PVUSBURB, pfnUrbReap,(PPDMUSBINS pUsbIns, RTMSINTERVAL cMillies));
419
420 /**
421 * Wakes a thread waiting in pfnUrbReap.
422 *
423 * @returns VBox status code.
424 * @param pUsbIns The USB device instance.
425 */
426 DECLR3CALLBACKMEMBER(int, pfnWakeup,(PPDMUSBINS pUsbIns));
427
428 /** Just some init precaution. Must be set to PDM_USBREG_VERSION. */
429 uint32_t u32TheEnd;
430} PDMUSBREG;
431/** Pointer to a PDM USB Device Structure. */
432typedef PDMUSBREG *PPDMUSBREG;
433/** Const pointer to a PDM USB Device Structure. */
434typedef PDMUSBREG const *PCPDMUSBREG;
435
436/** Current USBREG version number. */
437#define PDM_USBREG_VERSION PDM_VERSION_MAKE(0xeeff, 1, 0)
438
439/** PDM USB Device Flags.
440 * @{ */
441/* none yet */
442/** @} */
443
444
445#ifdef IN_RING3
446
447/**
448 * PDM USB Device API.
449 */
450typedef struct PDMUSBHLP
451{
452 /** Structure version. PDM_USBHLP_VERSION defines the current version. */
453 uint32_t u32Version;
454
455 /**
456 * Attaches a driver (chain) to the USB device.
457 *
458 * The first call for a LUN this will serve as a registration of the LUN. The pBaseInterface and
459 * the pszDesc string will be registered with that LUN and kept around for PDMR3QueryUSBDeviceLun().
460 *
461 * @returns VBox status code.
462 * @param pUsbIns The USB device instance.
463 * @param iLun The logical unit to attach.
464 * @param pBaseInterface Pointer to the base interface for that LUN. (device side / down)
465 * @param ppBaseInterface Where to store the pointer to the base interface. (driver side / up)
466 * @param pszDesc Pointer to a string describing the LUN. This string must remain valid
467 * for the live of the device instance.
468 */
469 DECLR3CALLBACKMEMBER(int, pfnDriverAttach,(PPDMUSBINS pUsbIns, RTUINT iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc));
470
471 /**
472 * Assert that the current thread is the emulation thread.
473 *
474 * @returns True if correct.
475 * @returns False if wrong.
476 * @param pUsbIns The USB device instance.
477 * @param pszFile Filename of the assertion location.
478 * @param iLine Linenumber of the assertion location.
479 * @param pszFunction Function of the assertion location.
480 */
481 DECLR3CALLBACKMEMBER(bool, pfnAssertEMT,(PPDMUSBINS pUsbIns, const char *pszFile, unsigned iLine, const char *pszFunction));
482
483 /**
484 * Assert that the current thread is NOT the emulation thread.
485 *
486 * @returns True if correct.
487 * @returns False if wrong.
488 * @param pUsbIns The USB device instance.
489 * @param pszFile Filename of the assertion location.
490 * @param iLine Linenumber of the assertion location.
491 * @param pszFunction Function of the assertion location.
492 */
493 DECLR3CALLBACKMEMBER(bool, pfnAssertOther,(PPDMUSBINS pUsbIns, const char *pszFile, unsigned iLine, const char *pszFunction));
494
495 /**
496 * Stops the VM and enters the debugger to look at the guest state.
497 *
498 * Use the PDMUsbDBGFStop() inline function with the RT_SRC_POS macro instead of
499 * invoking this function directly.
500 *
501 * @returns VBox status code which must be passed up to the VMM.
502 * @param pUsbIns The USB device instance.
503 * @param pszFile Filename of the assertion location.
504 * @param iLine The linenumber of the assertion location.
505 * @param pszFunction Function of the assertion location.
506 * @param pszFormat Message. (optional)
507 * @param va Message parameters.
508 */
509 DECLR3CALLBACKMEMBER(int, pfnDBGFStopV,(PPDMUSBINS pUsbIns, const char *pszFile, unsigned iLine, const char *pszFunction,
510 const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(5, 0));
511
512 /**
513 * Register a info handler with DBGF, argv style.
514 *
515 * @returns VBox status code.
516 * @param pUsbIns The USB device instance.
517 * @param pszName The identifier of the info.
518 * @param pszDesc The description of the info and any arguments the handler may take.
519 * @param pfnHandler The handler function to be called to display the info.
520 */
521 DECLR3CALLBACKMEMBER(int, pfnDBGFInfoRegisterArgv,(PPDMUSBINS pUsbIns, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVUSB pfnHandler));
522
523 /**
524 * Allocate memory which is associated with current VM instance
525 * and automatically freed on it's destruction.
526 *
527 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
528 * @param pUsbIns The USB device instance.
529 * @param cb Number of bytes to allocate.
530 */
531 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAlloc,(PPDMUSBINS pUsbIns, size_t cb));
532
533 /**
534 * Allocate memory which is associated with current VM instance
535 * and automatically freed on it's destruction. The memory is ZEROed.
536 *
537 * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
538 * @param pUsbIns The USB device instance.
539 * @param cb Number of bytes to allocate.
540 */
541 DECLR3CALLBACKMEMBER(void *, pfnMMHeapAllocZ,(PPDMUSBINS pUsbIns, size_t cb));
542
543 /**
544 * Create a queue.
545 *
546 * @returns VBox status code.
547 * @param pUsbIns The USB device instance.
548 * @param cbItem Size a queue item.
549 * @param cItems Number of items in the queue.
550 * @param cMilliesInterval Number of milliseconds between polling the queue.
551 * If 0 then the emulation thread will be notified whenever an item arrives.
552 * @param pfnCallback The consumer function.
553 * @param pszName The queue base name. The instance number will be
554 * appended automatically.
555 * @param ppQueue Where to store the queue handle on success.
556 * @thread The emulation thread.
557 */
558 DECLR3CALLBACKMEMBER(int, pfnPDMQueueCreate,(PPDMUSBINS pUsbIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
559 PFNPDMQUEUEUSB pfnCallback, const char *pszName, PPDMQUEUE *ppQueue));
560
561 /**
562 * Register a save state data unit.
563 *
564 * @returns VBox status.
565 * @param pUsbIns The USB device instance.
566 * @param uVersion Data layout version number.
567 * @param cbGuess The approximate amount of data in the unit.
568 * Only for progress indicators.
569 *
570 * @param pfnLivePrep Prepare live save callback, optional.
571 * @param pfnLiveExec Execute live save callback, optional.
572 * @param pfnLiveVote Vote live save callback, optional.
573 *
574 * @param pfnSavePrep Prepare save callback, optional.
575 * @param pfnSaveExec Execute save callback, optional.
576 * @param pfnSaveDone Done save callback, optional.
577 *
578 * @param pfnLoadPrep Prepare load callback, optional.
579 * @param pfnLoadExec Execute load callback, optional.
580 * @param pfnLoadDone Done load callback, optional.
581 */
582 DECLR3CALLBACKMEMBER(int, pfnSSMRegister,(PPDMUSBINS pUsbIns, uint32_t uVersion, size_t cbGuess,
583 PFNSSMUSBLIVEPREP pfnLivePrep, PFNSSMUSBLIVEEXEC pfnLiveExec, PFNSSMUSBLIVEVOTE pfnLiveVote,
584 PFNSSMUSBSAVEPREP pfnSavePrep, PFNSSMUSBSAVEEXEC pfnSaveExec, PFNSSMUSBSAVEDONE pfnSaveDone,
585 PFNSSMUSBLOADPREP pfnLoadPrep, PFNSSMUSBLOADEXEC pfnLoadExec, PFNSSMUSBLOADDONE pfnLoadDone));
586
587 /**
588 * Register a STAM sample.
589 *
590 * Use the PDMUsbHlpSTAMRegister wrapper.
591 *
592 * @returns VBox status.
593 * @param pUsbIns The USB device instance.
594 * @param pvSample Pointer to the sample.
595 * @param enmType Sample type. This indicates what pvSample is pointing at.
596 * @param enmVisibility Visibility type specifying whether unused statistics should be visible or not.
597 * @param enmUnit Sample unit.
598 * @param pszDesc Sample description.
599 * @param pszName The sample name format string.
600 * @param va Arguments to the format string.
601 */
602 DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterV,(PPDMUSBINS pUsbIns, void *pvSample, STAMTYPE enmType,
603 STAMVISIBILITY enmVisibility, STAMUNIT enmUnit, const char *pszDesc,
604 const char *pszName, va_list va) RT_IPRT_FORMAT_ATTR(7, 0));
605
606 /**
607 * Creates a timer.
608 *
609 * @returns VBox status.
610 * @param pUsbIns The USB device instance.
611 * @param enmClock The clock to use on this timer.
612 * @param pfnCallback Callback function.
613 * @param pvUser User argument for the callback.
614 * @param fFlags Flags, see TMTIMER_FLAGS_*.
615 * @param pszDesc Pointer to description string which must stay around
616 * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
617 * @param phTimer Where to store the timer handle on success.
618 */
619 DECLR3CALLBACKMEMBER(int, pfnTimerCreate,(PPDMUSBINS pUsbIns, TMCLOCK enmClock, PFNTMTIMERUSB pfnCallback, void *pvUser,
620 uint32_t fFlags, const char *pszDesc, PTMTIMERHANDLE phTimer));
621
622 /** @name Timer handle method wrappers
623 * @{ */
624 DECLR3CALLBACKMEMBER(uint64_t, pfnTimerFromMicro,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t cMicroSecs));
625 DECLR3CALLBACKMEMBER(uint64_t, pfnTimerFromMilli,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t cMilliSecs));
626 DECLR3CALLBACKMEMBER(uint64_t, pfnTimerFromNano,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t cNanoSecs));
627 DECLR3CALLBACKMEMBER(uint64_t, pfnTimerGet,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer));
628 DECLR3CALLBACKMEMBER(uint64_t, pfnTimerGetFreq,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer));
629 DECLR3CALLBACKMEMBER(uint64_t, pfnTimerGetNano,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer));
630 DECLR3CALLBACKMEMBER(bool, pfnTimerIsActive,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer));
631 DECLR3CALLBACKMEMBER(bool, pfnTimerIsLockOwner,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer));
632 DECLR3CALLBACKMEMBER(int, pfnTimerLockClock,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer));
633 /** Takes the clock lock then enters the specified critical section. */
634 DECLR3CALLBACKMEMBER(int, pfnTimerLockClock2,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, PPDMCRITSECT pCritSect));
635 DECLR3CALLBACKMEMBER(int, pfnTimerSet,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t uExpire));
636 DECLR3CALLBACKMEMBER(int, pfnTimerSetFrequencyHint,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint32_t uHz));
637 DECLR3CALLBACKMEMBER(int, pfnTimerSetMicro,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t cMicrosToNext));
638 DECLR3CALLBACKMEMBER(int, pfnTimerSetMillies,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t cMilliesToNext));
639 DECLR3CALLBACKMEMBER(int, pfnTimerSetNano,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t cNanosToNext));
640 DECLR3CALLBACKMEMBER(int, pfnTimerSetRelative,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t cTicksToNext, uint64_t *pu64Now));
641 DECLR3CALLBACKMEMBER(int, pfnTimerStop,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer));
642 DECLR3CALLBACKMEMBER(void, pfnTimerUnlockClock,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer));
643 DECLR3CALLBACKMEMBER(void, pfnTimerUnlockClock2,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, PPDMCRITSECT pCritSect));
644 DECLR3CALLBACKMEMBER(int, pfnTimerSetCritSect,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, PPDMCRITSECT pCritSect));
645 DECLR3CALLBACKMEMBER(int, pfnTimerSave,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, PSSMHANDLE pSSM));
646 DECLR3CALLBACKMEMBER(int, pfnTimerLoad,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, PSSMHANDLE pSSM));
647 DECLR3CALLBACKMEMBER(int, pfnTimerDestroy,(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer));
648 /** @sa TMR3TimerSkip */
649 DECLR3CALLBACKMEMBER(int, pfnTimerSkipLoad,(PSSMHANDLE pSSM, bool *pfActive));
650 /** @} */
651
652 /**
653 * Set the VM error message
654 *
655 * @returns rc.
656 * @param pUsbIns The USB device instance.
657 * @param rc VBox status code.
658 * @param SRC_POS Use RT_SRC_POS.
659 * @param pszFormat Error message format string.
660 * @param va Error message arguments.
661 */
662 DECLR3CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMUSBINS pUsbIns, int rc, RT_SRC_POS_DECL,
663 const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(6, 0));
664
665 /**
666 * Set the VM runtime error message
667 *
668 * @returns VBox status code.
669 * @param pUsbIns The USB device instance.
670 * @param fFlags The action flags. See VMSETRTERR_FLAGS_*.
671 * @param pszErrorId Error ID string.
672 * @param pszFormat Error message format string.
673 * @param va Error message arguments.
674 */
675 DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMUSBINS pUsbIns, uint32_t fFlags, const char *pszErrorId,
676 const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(4, 0));
677
678 /**
679 * Gets the VM state.
680 *
681 * @returns VM state.
682 * @param pUsbIns The USB device instance.
683 * @thread Any thread (just keep in mind that it's volatile info).
684 */
685 DECLR3CALLBACKMEMBER(VMSTATE, pfnVMState, (PPDMUSBINS pUsbIns));
686
687 /**
688 * Creates a PDM thread.
689 *
690 * This differs from the RTThreadCreate() API in that PDM takes care of suspending,
691 * resuming, and destroying the thread as the VM state changes.
692 *
693 * @returns VBox status code.
694 * @param pUsbIns The USB device instance.
695 * @param ppThread Where to store the thread 'handle'.
696 * @param pvUser The user argument to the thread function.
697 * @param pfnThread The thread function.
698 * @param pfnWakeup The wakup callback. This is called on the EMT
699 * thread when a state change is pending.
700 * @param cbStack See RTThreadCreate.
701 * @param enmType See RTThreadCreate.
702 * @param pszName See RTThreadCreate.
703 */
704 DECLR3CALLBACKMEMBER(int, pfnThreadCreate,(PPDMUSBINS pUsbIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADUSB pfnThread,
705 PFNPDMTHREADWAKEUPUSB pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName));
706
707 /**
708 * Set up asynchronous handling of a suspend, reset or power off notification.
709 *
710 * This shall only be called when getting the notification. It must be called
711 * for each one.
712 *
713 * @returns VBox status code.
714 * @param pUsbIns The USB device instance.
715 * @param pfnAsyncNotify The callback.
716 * @thread EMT(0)
717 */
718 DECLR3CALLBACKMEMBER(int, pfnSetAsyncNotification, (PPDMUSBINS pUSbIns, PFNPDMUSBASYNCNOTIFY pfnAsyncNotify));
719
720 /**
721 * Notify EMT(0) that the device has completed the asynchronous notification
722 * handling.
723 *
724 * This can be called at any time, spurious calls will simply be ignored.
725 *
726 * @param pUsbIns The USB device instance.
727 * @thread Any
728 */
729 DECLR3CALLBACKMEMBER(void, pfnAsyncNotificationCompleted, (PPDMUSBINS pUsbIns));
730
731 /**
732 * Gets the reason for the most recent VM suspend.
733 *
734 * @returns The suspend reason. VMSUSPENDREASON_INVALID is returned if no
735 * suspend has been made or if the pUsbIns is invalid.
736 * @param pUsbIns The driver instance.
737 */
738 DECLR3CALLBACKMEMBER(VMSUSPENDREASON, pfnVMGetSuspendReason,(PPDMUSBINS pUsbIns));
739
740 /**
741 * Gets the reason for the most recent VM resume.
742 *
743 * @returns The resume reason. VMRESUMEREASON_INVALID is returned if no
744 * resume has been made or if the pUsbIns is invalid.
745 * @param pUsbIns The driver instance.
746 */
747 DECLR3CALLBACKMEMBER(VMRESUMEREASON, pfnVMGetResumeReason,(PPDMUSBINS pUsbIns));
748
749 /** @name Space reserved for minor interface changes.
750 * @{ */
751 DECLR3CALLBACKMEMBER(void, pfnReserved0,(PPDMUSBINS pUsbIns));
752 DECLR3CALLBACKMEMBER(void, pfnReserved1,(PPDMUSBINS pUsbIns));
753 DECLR3CALLBACKMEMBER(void, pfnReserved2,(PPDMUSBINS pUsbIns));
754 DECLR3CALLBACKMEMBER(void, pfnReserved3,(PPDMUSBINS pUsbIns));
755 DECLR3CALLBACKMEMBER(void, pfnReserved4,(PPDMUSBINS pUsbIns));
756 DECLR3CALLBACKMEMBER(void, pfnReserved5,(PPDMUSBINS pUsbIns));
757 DECLR3CALLBACKMEMBER(void, pfnReserved6,(PPDMUSBINS pUsbIns));
758 DECLR3CALLBACKMEMBER(void, pfnReserved7,(PPDMUSBINS pUsbIns));
759 DECLR3CALLBACKMEMBER(void, pfnReserved8,(PPDMUSBINS pUsbIns));
760 DECLR3CALLBACKMEMBER(void, pfnReserved9,(PPDMUSBINS pUsbIns));
761 /** @} */
762
763 /** Just a safety precaution. */
764 uint32_t u32TheEnd;
765} PDMUSBHLP;
766/** Pointer PDM USB Device API. */
767typedef PDMUSBHLP *PPDMUSBHLP;
768/** Pointer const PDM USB Device API. */
769typedef const PDMUSBHLP *PCPDMUSBHLP;
770
771/** Current USBHLP version number. */
772#define PDM_USBHLP_VERSION PDM_VERSION_MAKE(0xeefe, 4, 0)
773
774#endif /* IN_RING3 */
775
776/**
777 * PDM USB Device Instance.
778 */
779typedef struct PDMUSBINS
780{
781 /** Structure version. PDM_USBINS_VERSION defines the current version. */
782 uint32_t u32Version;
783 /** USB device instance number. */
784 uint32_t iInstance;
785 /** The base interface of the device.
786 * The device constructor initializes this if it has any device level
787 * interfaces to export. To obtain this interface call PDMR3QueryUSBDevice(). */
788 PDMIBASE IBase;
789#if HC_ARCH_BITS == 32
790 uint32_t u32Alignment; /**< Alignment padding. */
791#endif
792
793 /** Internal data. */
794 union
795 {
796#ifdef PDMUSBINSINT_DECLARED
797 PDMUSBINSINT s;
798#endif
799 uint8_t padding[HC_ARCH_BITS == 32 ? 96 : 128];
800 } Internal;
801
802 /** Pointer the PDM USB Device API. */
803 R3PTRTYPE(PCPDMUSBHLP) pHlpR3;
804 /** Pointer to the USB device registration structure. */
805 R3PTRTYPE(PCPDMUSBREG) pReg;
806 /** Configuration handle. */
807 R3PTRTYPE(PCFGMNODE) pCfg;
808 /** The (device) global configuration handle. */
809 R3PTRTYPE(PCFGMNODE) pCfgGlobal;
810 /** Pointer to device instance data. */
811 R3PTRTYPE(void *) pvInstanceDataR3;
812 /** Pointer to the VUSB Device structure.
813 * Internal to VUSB, don't touch.
814 * @todo Moved this to PDMUSBINSINT. */
815 R3PTRTYPE(void *) pvVUsbDev2;
816 /** Device name for using when logging.
817 * The constructor sets this and the destructor frees it. */
818 R3PTRTYPE(char *) pszName;
819 /** Tracing indicator. */
820 uint32_t fTracing;
821 /** The tracing ID of this device. */
822 uint32_t idTracing;
823 /** The port/device speed. HCs and emulated devices need to know. */
824 VUSBSPEED enmSpeed;
825
826 /** Padding to make achInstanceData aligned at 32 byte boundary. */
827 uint32_t au32Padding[HC_ARCH_BITS == 32 ? 2 : 3];
828
829 /** Device instance data. The size of this area is defined
830 * in the PDMUSBREG::cbInstanceData field. */
831 char achInstanceData[8];
832} PDMUSBINS;
833
834/** Current USBINS version number. */
835#define PDM_USBINS_VERSION PDM_VERSION_MAKE(0xeefd, 3, 0)
836
837/**
838 * Checks the structure versions of the USB device instance and USB device
839 * helpers, returning if they are incompatible.
840 *
841 * This shall be the first statement of the constructor!
842 *
843 * @param pUsbIns The USB device instance pointer.
844 */
845#define PDMUSB_CHECK_VERSIONS_RETURN(pUsbIns) \
846 do \
847 { \
848 PPDMUSBINS pUsbInsTypeCheck = (pUsbIns); NOREF(pUsbInsTypeCheck); \
849 AssertLogRelMsgReturn(PDM_VERSION_ARE_COMPATIBLE((pUsbIns)->u32Version, PDM_USBINS_VERSION), \
850 ("DevIns=%#x mine=%#x\n", (pUsbIns)->u32Version, PDM_USBINS_VERSION), \
851 VERR_PDM_USBINS_VERSION_MISMATCH); \
852 AssertLogRelMsgReturn(PDM_VERSION_ARE_COMPATIBLE((pUsbIns)->pHlpR3->u32Version, PDM_USBHLP_VERSION), \
853 ("DevHlp=%#x mine=%#x\n", (pUsbIns)->pHlpR3->u32Version, PDM_USBHLP_VERSION), \
854 VERR_PDM_USBHLPR3_VERSION_MISMATCH); \
855 } while (0)
856
857/**
858 * Quietly checks the structure versions of the USB device instance and
859 * USB device helpers, returning if they are incompatible.
860 *
861 * This shall be invoked as the first statement in the destructor!
862 *
863 * @param pUsbIns The USB device instance pointer.
864 */
865#define PDMUSB_CHECK_VERSIONS_RETURN_VOID(pUsbIns) \
866 do \
867 { \
868 PPDMUSBINS pUsbInsTypeCheck = (pUsbIns); NOREF(pUsbInsTypeCheck); \
869 if (RT_LIKELY(PDM_VERSION_ARE_COMPATIBLE((pUsbIns)->u32Version, PDM_USBINS_VERSION) )) \
870 { /* likely */ } else return; \
871 if (RT_LIKELY(PDM_VERSION_ARE_COMPATIBLE((pUsbIns)->pHlpR3->u32Version, PDM_USBHLP_VERSION) )) \
872 { /* likely */ } else return; \
873 } while (0)
874
875
876/** Converts a pointer to the PDMUSBINS::IBase to a pointer to PDMUSBINS. */
877#define PDMIBASE_2_PDMUSB(pInterface) ( (PPDMUSBINS)((char *)(pInterface) - RT_UOFFSETOF(PDMUSBINS, IBase)) )
878
879
880/** @def PDMUSB_ASSERT_EMT
881 * Assert that the current thread is the emulation thread.
882 */
883#ifdef VBOX_STRICT
884# define PDMUSB_ASSERT_EMT(pUsbIns) pUsbIns->pHlpR3->pfnAssertEMT(pUsbIns, __FILE__, __LINE__, __FUNCTION__)
885#else
886# define PDMUSB_ASSERT_EMT(pUsbIns) do { } while (0)
887#endif
888
889/** @def PDMUSB_ASSERT_OTHER
890 * Assert that the current thread is NOT the emulation thread.
891 */
892#ifdef VBOX_STRICT
893# define PDMUSB_ASSERT_OTHER(pUsbIns) pUsbIns->pHlpR3->pfnAssertOther(pUsbIns, __FILE__, __LINE__, __FUNCTION__)
894#else
895# define PDMUSB_ASSERT_OTHER(pUsbIns) do { } while (0)
896#endif
897
898/** @def PDMUSB_SET_ERROR
899 * Set the VM error. See PDMUsbHlpVMSetError() for printf like message
900 * formatting.
901 */
902#define PDMUSB_SET_ERROR(pUsbIns, rc, pszError) \
903 PDMUsbHlpVMSetError(pUsbIns, rc, RT_SRC_POS, "%s", pszError)
904
905/** @def PDMUSB_SET_RUNTIME_ERROR
906 * Set the VM runtime error. See PDMUsbHlpVMSetRuntimeError() for printf like
907 * message formatting.
908 */
909#define PDMUSB_SET_RUNTIME_ERROR(pUsbIns, fFlags, pszErrorId, pszError) \
910 PDMUsbHlpVMSetRuntimeError(pUsbIns, fFlags, pszErrorId, "%s", pszError)
911
912
913#ifdef IN_RING3
914
915/**
916 * @copydoc PDMUSBHLP::pfnDriverAttach
917 */
918DECLINLINE(int) PDMUsbHlpDriverAttach(PPDMUSBINS pUsbIns, RTUINT iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc)
919{
920 return pUsbIns->pHlpR3->pfnDriverAttach(pUsbIns, iLun, pBaseInterface, ppBaseInterface, pszDesc);
921}
922
923/**
924 * VBOX_STRICT wrapper for pHlpR3->pfnDBGFStopV.
925 *
926 * @returns VBox status code which must be passed up to the VMM.
927 * @param pUsbIns Device instance.
928 * @param SRC_POS Use RT_SRC_POS.
929 * @param pszFormat Message. (optional)
930 * @param ... Message parameters.
931 */
932DECLINLINE(int) RT_IPRT_FORMAT_ATTR(5, 6) PDMUsbDBGFStop(PPDMUSBINS pUsbIns, RT_SRC_POS_DECL, const char *pszFormat, ...)
933{
934#ifdef VBOX_STRICT
935 int rc;
936 va_list va;
937 va_start(va, pszFormat);
938 rc = pUsbIns->pHlpR3->pfnDBGFStopV(pUsbIns, RT_SRC_POS_ARGS, pszFormat, va);
939 va_end(va);
940 return rc;
941#else
942 NOREF(pUsbIns);
943 NOREF(pszFile);
944 NOREF(iLine);
945 NOREF(pszFunction);
946 NOREF(pszFormat);
947 return VINF_SUCCESS;
948#endif
949}
950
951/**
952 * @copydoc PDMUSBHLP::pfnVMState
953 */
954DECLINLINE(VMSTATE) PDMUsbHlpVMState(PPDMUSBINS pUsbIns)
955{
956 return pUsbIns->pHlpR3->pfnVMState(pUsbIns);
957}
958
959/**
960 * @copydoc PDMUSBHLP::pfnThreadCreate
961 */
962DECLINLINE(int) PDMUsbHlpThreadCreate(PPDMUSBINS pUsbIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADUSB pfnThread,
963 PFNPDMTHREADWAKEUPUSB pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
964{
965 return pUsbIns->pHlpR3->pfnThreadCreate(pUsbIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
966}
967
968
969/**
970 * @copydoc PDMUSBHLP::pfnSetAsyncNotification
971 */
972DECLINLINE(int) PDMUsbHlpSetAsyncNotification(PPDMUSBINS pUsbIns, PFNPDMUSBASYNCNOTIFY pfnAsyncNotify)
973{
974 return pUsbIns->pHlpR3->pfnSetAsyncNotification(pUsbIns, pfnAsyncNotify);
975}
976
977/**
978 * @copydoc PDMUSBHLP::pfnAsyncNotificationCompleted
979 */
980DECLINLINE(void) PDMUsbHlpAsyncNotificationCompleted(PPDMUSBINS pUsbIns)
981{
982 pUsbIns->pHlpR3->pfnAsyncNotificationCompleted(pUsbIns);
983}
984
985/**
986 * Set the VM error message
987 *
988 * @returns rc.
989 * @param pUsbIns The USB device instance.
990 * @param rc VBox status code.
991 * @param SRC_POS Use RT_SRC_POS.
992 * @param pszFormat Error message format string.
993 * @param ... Error message arguments.
994 */
995DECLINLINE(int) RT_IPRT_FORMAT_ATTR(6, 7) PDMUsbHlpVMSetError(PPDMUSBINS pUsbIns, int rc, RT_SRC_POS_DECL,
996 const char *pszFormat, ...)
997{
998 va_list va;
999 va_start(va, pszFormat);
1000 rc = pUsbIns->pHlpR3->pfnVMSetErrorV(pUsbIns, rc, RT_SRC_POS_ARGS, pszFormat, va);
1001 va_end(va);
1002 return rc;
1003}
1004
1005/**
1006 * @copydoc PDMUSBHLP::pfnMMHeapAlloc
1007 */
1008DECLINLINE(void *) PDMUsbHlpMMHeapAlloc(PPDMUSBINS pUsbIns, size_t cb)
1009{
1010 return pUsbIns->pHlpR3->pfnMMHeapAlloc(pUsbIns, cb);
1011}
1012
1013/**
1014 * @copydoc PDMUSBHLP::pfnMMHeapAllocZ
1015 */
1016DECLINLINE(void *) PDMUsbHlpMMHeapAllocZ(PPDMUSBINS pUsbIns, size_t cb)
1017{
1018 return pUsbIns->pHlpR3->pfnMMHeapAllocZ(pUsbIns, cb);
1019}
1020
1021/**
1022 * Frees memory allocated by PDMUsbHlpMMHeapAlloc or PDMUsbHlpMMHeapAllocZ.
1023 *
1024 * @param pUsbIns The USB device instance.
1025 * @param pv The memory to free. NULL is fine.
1026 */
1027DECLINLINE(void) PDMUsbHlpMMHeapFree(PPDMUSBINS pUsbIns, void *pv)
1028{
1029 NOREF(pUsbIns);
1030 MMR3HeapFree(pv);
1031}
1032
1033/**
1034 * @copydoc PDMUSBHLP::pfnDBGFInfoRegisterArgv
1035 */
1036DECLINLINE(int) PDMUsbHlpDBGFInfoRegisterArgv(PPDMUSBINS pUsbIns, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVUSB pfnHandler)
1037{
1038 return pUsbIns->pHlpR3->pfnDBGFInfoRegisterArgv(pUsbIns, pszName, pszDesc, pfnHandler);
1039}
1040
1041/**
1042 * @copydoc PDMUSBHLP::pfnTimerCreate
1043 */
1044DECLINLINE(int) PDMUsbHlpTimerCreate(PPDMUSBINS pUsbIns, TMCLOCK enmClock, PFNTMTIMERUSB pfnCallback, void *pvUser,
1045 uint32_t fFlags, const char *pszDesc, PTMTIMERHANDLE phTimer)
1046{
1047 return pUsbIns->pHlpR3->pfnTimerCreate(pUsbIns, enmClock, pfnCallback, pvUser, fFlags, pszDesc, phTimer);
1048}
1049
1050/**
1051 * @copydoc PDMUSBHLP::pfnTimerFromMicro
1052 */
1053DECLINLINE(uint64_t) PDMUsbHlpTimerFromMicro(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t cMicroSecs)
1054{
1055 return pUsbIns->pHlpR3->pfnTimerFromMicro(pUsbIns, hTimer, cMicroSecs);
1056}
1057
1058/**
1059 * @copydoc PDMUSBHLP::pfnTimerFromMilli
1060 */
1061DECLINLINE(uint64_t) PDMUsbHlpTimerFromMilli(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t cMilliSecs)
1062{
1063 return pUsbIns->pHlpR3->pfnTimerFromMilli(pUsbIns, hTimer, cMilliSecs);
1064}
1065
1066/**
1067 * @copydoc PDMUSBHLP::pfnTimerFromNano
1068 */
1069DECLINLINE(uint64_t) PDMUsbHlpTimerFromNano(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t cNanoSecs)
1070{
1071 return pUsbIns->pHlpR3->pfnTimerFromNano(pUsbIns, hTimer, cNanoSecs);
1072}
1073
1074/**
1075 * @copydoc PDMUSBHLP::pfnTimerGet
1076 */
1077DECLINLINE(uint64_t) PDMUsbHlpTimerGet(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer)
1078{
1079 return pUsbIns->pHlpR3->pfnTimerGet(pUsbIns, hTimer);
1080}
1081
1082/**
1083 * @copydoc PDMUSBHLP::pfnTimerGetFreq
1084 */
1085DECLINLINE(uint64_t) PDMUsbHlpTimerGetFreq(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer)
1086{
1087 return pUsbIns->pHlpR3->pfnTimerGetFreq(pUsbIns, hTimer);
1088}
1089
1090/**
1091 * @copydoc PDMUSBHLP::pfnTimerGetNano
1092 */
1093DECLINLINE(uint64_t) PDMUsbHlpTimerGetNano(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer)
1094{
1095 return pUsbIns->pHlpR3->pfnTimerGetNano(pUsbIns, hTimer);
1096}
1097
1098/**
1099 * @copydoc PDMUSBHLP::pfnTimerIsActive
1100 */
1101DECLINLINE(bool) PDMUsbHlpTimerIsActive(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer)
1102{
1103 return pUsbIns->pHlpR3->pfnTimerIsActive(pUsbIns, hTimer);
1104}
1105
1106/**
1107 * @copydoc PDMUSBHLP::pfnTimerIsLockOwner
1108 */
1109DECLINLINE(bool) PDMUsbHlpTimerIsLockOwner(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer)
1110{
1111 return pUsbIns->pHlpR3->pfnTimerIsLockOwner(pUsbIns, hTimer);
1112}
1113
1114/**
1115 * @copydoc PDMUSBHLP::pfnTimerLockClock
1116 */
1117DECLINLINE(int) PDMUsbHlpTimerLockClock(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer)
1118{
1119 return pUsbIns->pHlpR3->pfnTimerLockClock(pUsbIns, hTimer);
1120}
1121
1122/**
1123 * @copydoc PDMUSBHLP::pfnTimerLockClock2
1124 */
1125DECLINLINE(int) PDMUsbHlpTimerLockClock2(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, PPDMCRITSECT pCritSect)
1126{
1127 return pUsbIns->pHlpR3->pfnTimerLockClock2(pUsbIns, hTimer, pCritSect);
1128}
1129
1130/**
1131 * @copydoc PDMUSBHLP::pfnTimerSet
1132 */
1133DECLINLINE(int) PDMUsbHlpTimerSet(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t uExpire)
1134{
1135 return pUsbIns->pHlpR3->pfnTimerSet(pUsbIns, hTimer, uExpire);
1136}
1137
1138/**
1139 * @copydoc PDMUSBHLP::pfnTimerSetFrequencyHint
1140 */
1141DECLINLINE(int) PDMUsbHlpTimerSetFrequencyHint(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint32_t uHz)
1142{
1143 return pUsbIns->pHlpR3->pfnTimerSetFrequencyHint(pUsbIns, hTimer, uHz);
1144}
1145
1146/**
1147 * @copydoc PDMUSBHLP::pfnTimerSetMicro
1148 */
1149DECLINLINE(int) PDMUsbHlpTimerSetMicro(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t cMicrosToNext)
1150{
1151 return pUsbIns->pHlpR3->pfnTimerSetMicro(pUsbIns, hTimer, cMicrosToNext);
1152}
1153
1154/**
1155 * @copydoc PDMUSBHLP::pfnTimerSetMillies
1156 */
1157DECLINLINE(int) PDMUsbHlpTimerSetMillies(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t cMilliesToNext)
1158{
1159 return pUsbIns->pHlpR3->pfnTimerSetMillies(pUsbIns, hTimer, cMilliesToNext);
1160}
1161
1162/**
1163 * @copydoc PDMUSBHLP::pfnTimerSetNano
1164 */
1165DECLINLINE(int) PDMUsbHlpTimerSetNano(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t cNanosToNext)
1166{
1167 return pUsbIns->pHlpR3->pfnTimerSetNano(pUsbIns, hTimer, cNanosToNext);
1168}
1169
1170/**
1171 * @copydoc PDMUSBHLP::pfnTimerSetRelative
1172 */
1173DECLINLINE(int) PDMUsbHlpTimerSetRelative(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, uint64_t cTicksToNext, uint64_t *pu64Now)
1174{
1175 return pUsbIns->pHlpR3->pfnTimerSetRelative(pUsbIns, hTimer, cTicksToNext, pu64Now);
1176}
1177
1178/**
1179 * @copydoc PDMUSBHLP::pfnTimerStop
1180 */
1181DECLINLINE(int) PDMUsbHlpTimerStop(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer)
1182{
1183 return pUsbIns->pHlpR3->pfnTimerStop(pUsbIns, hTimer);
1184}
1185
1186/**
1187 * @copydoc PDMUSBHLP::pfnTimerUnlockClock
1188 */
1189DECLINLINE(void) PDMUsbHlpTimerUnlockClock(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer)
1190{
1191 pUsbIns->pHlpR3->pfnTimerUnlockClock(pUsbIns, hTimer);
1192}
1193
1194/**
1195 * @copydoc PDMUSBHLP::pfnTimerUnlockClock2
1196 */
1197DECLINLINE(void) PDMUsbHlpTimerUnlockClock2(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, PPDMCRITSECT pCritSect)
1198{
1199 pUsbIns->pHlpR3->pfnTimerUnlockClock2(pUsbIns, hTimer, pCritSect);
1200}
1201
1202/**
1203 * @copydoc PDMUSBHLP::pfnTimerSetCritSect
1204 */
1205DECLINLINE(int) PDMUsbHlpTimerSetCritSect(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, PPDMCRITSECT pCritSect)
1206{
1207 return pUsbIns->pHlpR3->pfnTimerSetCritSect(pUsbIns, hTimer, pCritSect);
1208}
1209
1210/**
1211 * @copydoc PDMUSBHLP::pfnTimerSave
1212 */
1213DECLINLINE(int) PDMUsbHlpTimerSave(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, PSSMHANDLE pSSM)
1214{
1215 return pUsbIns->pHlpR3->pfnTimerSave(pUsbIns, hTimer, pSSM);
1216}
1217
1218/**
1219 * @copydoc PDMUSBHLP::pfnTimerLoad
1220 */
1221DECLINLINE(int) PDMUsbHlpTimerLoad(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer, PSSMHANDLE pSSM)
1222{
1223 return pUsbIns->pHlpR3->pfnTimerLoad(pUsbIns, hTimer, pSSM);
1224}
1225
1226/**
1227 * @copydoc PDMUSBHLP::pfnTimerDestroy
1228 */
1229DECLINLINE(int) PDMUsbHlpTimerDestroy(PPDMUSBINS pUsbIns, TMTIMERHANDLE hTimer)
1230{
1231 return pUsbIns->pHlpR3->pfnTimerDestroy(pUsbIns, hTimer);
1232}
1233
1234/**
1235 * @copydoc PDMUSBHLP::pfnSSMRegister
1236 */
1237DECLINLINE(int) PDMUsbHlpSSMRegister(PPDMUSBINS pUsbIns, uint32_t uVersion, size_t cbGuess,
1238 PFNSSMUSBLIVEPREP pfnLivePrep, PFNSSMUSBLIVEEXEC pfnLiveExec, PFNSSMUSBLIVEVOTE pfnLiveVote,
1239 PFNSSMUSBSAVEPREP pfnSavePrep, PFNSSMUSBSAVEEXEC pfnSaveExec, PFNSSMUSBSAVEDONE pfnSaveDone,
1240 PFNSSMUSBLOADPREP pfnLoadPrep, PFNSSMUSBLOADEXEC pfnLoadExec, PFNSSMUSBLOADDONE pfnLoadDone)
1241{
1242 return pUsbIns->pHlpR3->pfnSSMRegister(pUsbIns, uVersion, cbGuess,
1243 pfnLivePrep, pfnLiveExec, pfnLiveVote,
1244 pfnSavePrep, pfnSaveExec, pfnSaveDone,
1245 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
1246}
1247
1248#endif /* IN_RING3 */
1249
1250
1251
1252/** Pointer to callbacks provided to the VBoxUsbRegister() call. */
1253typedef const struct PDMUSBREGCB *PCPDMUSBREGCB;
1254
1255/**
1256 * Callbacks for VBoxUSBDeviceRegister().
1257 */
1258typedef struct PDMUSBREGCB
1259{
1260 /** Interface version.
1261 * This is set to PDM_USBREG_CB_VERSION. */
1262 uint32_t u32Version;
1263
1264 /**
1265 * Registers a device with the current VM instance.
1266 *
1267 * @returns VBox status code.
1268 * @param pCallbacks Pointer to the callback table.
1269 * @param pReg Pointer to the USB device registration record.
1270 * This data must be permanent and readonly.
1271 */
1272 DECLR3CALLBACKMEMBER(int, pfnRegister,(PCPDMUSBREGCB pCallbacks, PCPDMUSBREG pReg));
1273} PDMUSBREGCB;
1274
1275/** Current version of the PDMUSBREGCB structure. */
1276#define PDM_USBREG_CB_VERSION PDM_VERSION_MAKE(0xeefc, 1, 0)
1277
1278
1279/**
1280 * The VBoxUsbRegister callback function.
1281 *
1282 * PDM will invoke this function after loading a USB device module and letting
1283 * the module decide which devices to register and how to handle conflicts.
1284 *
1285 * @returns VBox status code.
1286 * @param pCallbacks Pointer to the callback table.
1287 * @param u32Version VBox version number.
1288 */
1289typedef DECLCALLBACKTYPE(int, FNPDMVBOXUSBREGISTER,(PCPDMUSBREGCB pCallbacks, uint32_t u32Version));
1290
1291VMMR3DECL(int) PDMR3UsbCreateEmulatedDevice(PUVM pUVM, const char *pszDeviceName, PCFGMNODE pDeviceNode, PCRTUUID pUuid,
1292 const char *pszCaptureFilename);
1293VMMR3DECL(int) PDMR3UsbCreateProxyDevice(PUVM pUVM, PCRTUUID pUuid, const char *pszBackend, const char *pszAddress, void *pvBackend,
1294 VUSBSPEED enmSpeed, uint32_t fMaskedIfs, const char *pszCaptureFilename);
1295VMMR3DECL(int) PDMR3UsbDetachDevice(PUVM pUVM, PCRTUUID pUuid);
1296VMMR3DECL(bool) PDMR3UsbHasHub(PUVM pUVM);
1297VMMR3DECL(int) PDMR3UsbDriverAttach(PUVM pUVM, const char *pszDevice, unsigned iDevIns, unsigned iLun, uint32_t fFlags,
1298 PPPDMIBASE ppBase);
1299VMMR3DECL(int) PDMR3UsbDriverDetach(PUVM pUVM, const char *pszDevice, unsigned iDevIns, unsigned iLun,
1300 const char *pszDriver, unsigned iOccurrence, uint32_t fFlags);
1301VMMR3DECL(int) PDMR3UsbQueryLun(PUVM pUVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase);
1302VMMR3DECL(int) PDMR3UsbQueryDriverOnLun(PUVM pUVM, const char *pszDevice, unsigned iInstance, unsigned iLun,
1303 const char *pszDriver, PPPDMIBASE ppBase);
1304
1305/** @} */
1306
1307RT_C_DECLS_END
1308
1309#endif /* !VBOX_INCLUDED_vmm_pdmusb_h */
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