VirtualBox

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

最後變更 在這個檔案從26248是 26248,由 vboxsync 提交於 15 年 前

USB: Descriptor member name cleanup. (#2603)

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

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