1 | /** @file
|
---|
2 | * PDM - Pluggable Device Manager, USB Devices.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License as published by the Free Software Foundation,
|
---|
12 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
13 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
14 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | */
|
---|
16 |
|
---|
17 | #ifndef ___VBox_pdmusb_h
|
---|
18 | #define ___VBox_pdmusb_h
|
---|
19 |
|
---|
20 | #include <VBox/pdmqueue.h>
|
---|
21 | #include <VBox/pdmcritsect.h>
|
---|
22 | #include <VBox/pdmthread.h>
|
---|
23 | #include <VBox/pdmifs.h>
|
---|
24 | #include <VBox/tm.h>
|
---|
25 | #include <VBox/ssm.h>
|
---|
26 | #include <VBox/cfgm.h>
|
---|
27 | #include <VBox/dbgf.h>
|
---|
28 | #include <VBox/mm.h>
|
---|
29 | #include <VBox/err.h>
|
---|
30 | #include <iprt/stdarg.h>
|
---|
31 |
|
---|
32 | __BEGIN_DECLS
|
---|
33 |
|
---|
34 | /** @defgroup grp_pdm_usbdev USB Devices
|
---|
35 | * @ingroup grp_pdm
|
---|
36 | * @{
|
---|
37 | */
|
---|
38 |
|
---|
39 |
|
---|
40 | /** PDM USB Device Registration Structure,
|
---|
41 | *
|
---|
42 | * This structure is used when registering a device from VBoxUsbRegister() in HC Ring-3.
|
---|
43 | * The PDM will make use of this structure untill the VM is destroyed.
|
---|
44 | */
|
---|
45 | typedef struct PDMUSBREG
|
---|
46 | {
|
---|
47 | /** Structure version. PDM_DEVREG_VERSION defines the current version. */
|
---|
48 | uint32_t u32Version;
|
---|
49 | /** Device name. */
|
---|
50 | char szDeviceName[32];
|
---|
51 | /** The description of the device. The UTF-8 string pointed to shall, like this structure,
|
---|
52 | * remain unchanged from registration till VM destruction. */
|
---|
53 | const char *pszDescription;
|
---|
54 |
|
---|
55 | /** Flags, combination of the PDM_USBREG_FLAGS_* \#defines. */
|
---|
56 | RTUINT fFlags;
|
---|
57 | /** Maximum number of instances (per VM). */
|
---|
58 | RTUINT cMaxInstances;
|
---|
59 | /** Size of the instance data. */
|
---|
60 | RTUINT cbInstance;
|
---|
61 |
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Construct an USB device instance for a VM.
|
---|
65 | *
|
---|
66 | * @returns VBox status.
|
---|
67 | * @param pUsbIns The USB device instance data.
|
---|
68 | * If the registration structure is needed, pUsbDev->pDevReg points to it.
|
---|
69 | * @param iInstance Instance number. Use this to figure out which registers and such to use.
|
---|
70 | * The instance number is also found in pUsbDev->iInstance, but since it's
|
---|
71 | * likely to be freqently used PDM passes it as parameter.
|
---|
72 | * @param pCfg Configuration node handle for the device. Use this to obtain the configuration
|
---|
73 | * of the device instance. It's also found in pUsbDev->pCfg, but since it's
|
---|
74 | * primary usage will in this function it's passed as a parameter.
|
---|
75 | * @param pCfgGlobal Handle to the global device configuration. Also found in pUsbDev->pCfgGlobal.
|
---|
76 | * @remarks This callback is required.
|
---|
77 | */
|
---|
78 | DECLR3CALLBACKMEMBER(int, pfnConstruct,(PPDMUSBINS pUsbIns, int iInstance, PCFGMNODE pCfg, PCFGMNODE pCfgGlobal));
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * Init complete notification.
|
---|
82 | *
|
---|
83 | * This can be done to do communication with other devices and other
|
---|
84 | * initialization which requires everything to be in place.
|
---|
85 | *
|
---|
86 | * @returns VBOX status code.
|
---|
87 | * @param pUsbIns The USB device instance data.
|
---|
88 | * @remarks Optional.
|
---|
89 | */
|
---|
90 | DECLR3CALLBACKMEMBER(int, pfnInitComplete,(PPDMUSBINS pUsbIns));
|
---|
91 |
|
---|
92 | /**
|
---|
93 | * Destruct an USB device instance.
|
---|
94 | *
|
---|
95 | * Most VM resources are freed by the VM. This callback is provided so that any non-VM
|
---|
96 | * resources can be freed correctly.
|
---|
97 | *
|
---|
98 | * This method will be called regardless of the pfnConstruc result to avoid
|
---|
99 | * complicated failure paths.
|
---|
100 | *
|
---|
101 | * @param pUsbIns The USB device instance data.
|
---|
102 | * @remarks Optional.
|
---|
103 | */
|
---|
104 | DECLR3CALLBACKMEMBER(void, pfnDestruct,(PPDMUSBINS pUsbIns));
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Power On notification.
|
---|
108 | *
|
---|
109 | * @returns VBox status.
|
---|
110 | * @param pUsbIns The USB device instance data.
|
---|
111 | * @remarks Optional.
|
---|
112 | */
|
---|
113 | DECLR3CALLBACKMEMBER(void, pfnPowerOn,(PPDMUSBINS pUsbIns));
|
---|
114 |
|
---|
115 | /**
|
---|
116 | * Reset notification.
|
---|
117 | *
|
---|
118 | * @returns VBox status.
|
---|
119 | * @param pUsbIns The USB device instance data.
|
---|
120 | * @remarks Optional.
|
---|
121 | */
|
---|
122 | DECLR3CALLBACKMEMBER(void, pfnReset,(PPDMUSBINS pUsbIns));
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * Suspend notification.
|
---|
126 | *
|
---|
127 | * @returns VBox status.
|
---|
128 | * @param pUsbIns The USB device instance data.
|
---|
129 | * @remarks Optional.
|
---|
130 | */
|
---|
131 | DECLR3CALLBACKMEMBER(void, pfnSuspend,(PPDMUSBINS pUsbIns));
|
---|
132 |
|
---|
133 | /**
|
---|
134 | * Resume notification.
|
---|
135 | *
|
---|
136 | * @returns VBox status.
|
---|
137 | * @param pUsbIns The USB device instance data.
|
---|
138 | * @remarks Optional.
|
---|
139 | */
|
---|
140 | DECLR3CALLBACKMEMBER(void, pfnResume,(PPDMUSBINS pUsbIns));
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Power Off notification.
|
---|
144 | *
|
---|
145 | * @param pUsbIns The USB device instance data.
|
---|
146 | */
|
---|
147 | DECLR3CALLBACKMEMBER(void, pfnPowerOff,(PPDMUSBINS pUsbIns));
|
---|
148 |
|
---|
149 | /**
|
---|
150 | * Attach command.
|
---|
151 | *
|
---|
152 | * This is called to let the USB device attach to a driver for a specified LUN
|
---|
153 | * at runtime. This is not called during VM construction, the device constructor
|
---|
154 | * have to attach to all the available drivers.
|
---|
155 | *
|
---|
156 | * @returns VBox status code.
|
---|
157 | * @param pUsbIns The USB device instance data.
|
---|
158 | * @param iLUN The logical unit which is being detached.
|
---|
159 | * @remarks Optional.
|
---|
160 | */
|
---|
161 | DECLR3CALLBACKMEMBER(int, pfnAttach,(PPDMUSBINS pUsbIns, unsigned iLUN));
|
---|
162 |
|
---|
163 | /**
|
---|
164 | * Detach notification.
|
---|
165 | *
|
---|
166 | * This is called when a driver is detaching itself from a LUN of the device.
|
---|
167 | * The device should adjust it's state to reflect this.
|
---|
168 | *
|
---|
169 | * @param pUsbIns The USB device instance data.
|
---|
170 | * @param iLUN The logical unit which is being detached.
|
---|
171 | * @remarks Optional.
|
---|
172 | */
|
---|
173 | DECLR3CALLBACKMEMBER(void, pfnDetach,(PPDMUSBINS pUsbIns, unsigned iLUN));
|
---|
174 |
|
---|
175 | /**
|
---|
176 | * Query the base interface of a logical unit.
|
---|
177 | *
|
---|
178 | * @returns VBOX status code.
|
---|
179 | * @param pUsbIns The USB device instance data.
|
---|
180 | * @param iLUN The logicial unit to query.
|
---|
181 | * @param ppBase Where to store the pointer to the base interface of the LUN.
|
---|
182 | * @remarks Optional.
|
---|
183 | */
|
---|
184 | DECLR3CALLBACKMEMBER(int, pfnQueryInterface,(PPDMUSBINS pUsbIns, unsigned iLUN, PPDMIBASE *ppBase));
|
---|
185 |
|
---|
186 | /** Just some init precaution. Must be set to PDM_USBREG_VERSION. */
|
---|
187 | uint32_t u32TheEnd;
|
---|
188 | } PDMUSBREG;
|
---|
189 | /** Pointer to a PDM USB Device Structure. */
|
---|
190 | typedef PDMUSBREG *PPDMUSBREG;
|
---|
191 | /** Const pointer to a PDM USB Device Structure. */
|
---|
192 | typedef PDMUSBREG const *PCPDMUSBREG;
|
---|
193 |
|
---|
194 | /** Current USBREG version number. */
|
---|
195 | #define PDM_USBREG_VERSION 0xed010000
|
---|
196 |
|
---|
197 | /** PDM USB Device Flags.
|
---|
198 | * @{ */
|
---|
199 | /* none yet */
|
---|
200 | /** @} */
|
---|
201 |
|
---|
202 | #ifdef IN_RING3
|
---|
203 | /**
|
---|
204 | * PDM USB Device API.
|
---|
205 | */
|
---|
206 | typedef struct PDMUSBHLP
|
---|
207 | {
|
---|
208 | /** Structure version. PDM_USBHLP_VERSION defines the current version. */
|
---|
209 | uint32_t u32Version;
|
---|
210 |
|
---|
211 | /**
|
---|
212 | * Attaches a driver (chain) to the USB device.
|
---|
213 | *
|
---|
214 | * The first call for a LUN this will serve as a registartion of the LUN. The pBaseInterface and
|
---|
215 | * the pszDesc string will be registered with that LUN and kept around for PDMR3QueryUSBDeviceLun().
|
---|
216 | *
|
---|
217 | * @returns VBox status code.
|
---|
218 | * @param pUsbIns The USB device instance.
|
---|
219 | * @param iLun The logical unit to attach.
|
---|
220 | * @param pBaseInterface Pointer to the base interface for that LUN. (device side / down)
|
---|
221 | * @param ppBaseInterface Where to store the pointer to the base interface. (driver side / up)
|
---|
222 | * @param pszDesc Pointer to a string describing the LUN. This string must remain valid
|
---|
223 | * for the live of the device instance.
|
---|
224 | */
|
---|
225 | DECLR3CALLBACKMEMBER(int, pfnDriverAttach,(PPDMUSBINS pUsbIns, RTUINT iLun, PPDMIBASE pBaseInterface, PPDMIBASE *ppBaseInterface, const char *pszDesc));
|
---|
226 |
|
---|
227 | /**
|
---|
228 | * Assert that the current thread is the emulation thread.
|
---|
229 | *
|
---|
230 | * @returns True if correct.
|
---|
231 | * @returns False if wrong.
|
---|
232 | * @param pUsbIns The USB device instance.
|
---|
233 | * @param pszFile Filename of the assertion location.
|
---|
234 | * @param iLine Linenumber of the assertion location.
|
---|
235 | * @param pszFunction Function of the assertion location.
|
---|
236 | */
|
---|
237 | DECLR3CALLBACKMEMBER(bool, pfnAssertEMT,(PPDMUSBINS pUsbIns, const char *pszFile, unsigned iLine, const char *pszFunction));
|
---|
238 |
|
---|
239 | /**
|
---|
240 | * Assert that the current thread is NOT the emulation thread.
|
---|
241 | *
|
---|
242 | * @returns True if correct.
|
---|
243 | * @returns False if wrong.
|
---|
244 | * @param pUsbIns The USB device instance.
|
---|
245 | * @param pszFile Filename of the assertion location.
|
---|
246 | * @param iLine Linenumber of the assertion location.
|
---|
247 | * @param pszFunction Function of the assertion location.
|
---|
248 | */
|
---|
249 | DECLR3CALLBACKMEMBER(bool, pfnAssertOther,(PPDMUSBINS pUsbIns, const char *pszFile, unsigned iLine, const char *pszFunction));
|
---|
250 |
|
---|
251 | /**
|
---|
252 | * Stops the VM and enters the debugger to look at the guest state.
|
---|
253 | *
|
---|
254 | * Use the PDMUsbDBGFStop() inline function with the RT_SRC_POS macro instead of
|
---|
255 | * invoking this function directly.
|
---|
256 | *
|
---|
257 | * @returns VBox status code which must be passed up to the VMM.
|
---|
258 | * @param pUsbIns The USB device instance.
|
---|
259 | * @param pszFile Filename of the assertion location.
|
---|
260 | * @param iLine The linenumber of the assertion location.
|
---|
261 | * @param pszFunction Function of the assertion location.
|
---|
262 | * @param pszFormat Message. (optional)
|
---|
263 | * @param va Message parameters.
|
---|
264 | */
|
---|
265 | DECLR3CALLBACKMEMBER(int, pfnDBGFStopV,(PPDMUSBINS pUsbIns, const char *pszFile, unsigned iLine, const char *pszFunction, const char *pszFormat, va_list va));
|
---|
266 |
|
---|
267 | /**
|
---|
268 | * Register a info handler with DBGF,
|
---|
269 | *
|
---|
270 | * @returns VBox status code.
|
---|
271 | * @param pUsbIns The USB device instance.
|
---|
272 | * @param pszName The identifier of the info.
|
---|
273 | * @param pszDesc The description of the info and any arguments the handler may take.
|
---|
274 | * @param pfnHandler The handler function to be called to display the info.
|
---|
275 | */
|
---|
276 | /** @todo DECLR3CALLBACKMEMBER(int, pfnDBGFInfoRegister,(PPDMUSBINS pUsbIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERUSB pfnHandler)); */
|
---|
277 |
|
---|
278 | /**
|
---|
279 | * Allocate memory which is associated with current VM instance
|
---|
280 | * and automatically freed on it's destruction.
|
---|
281 | *
|
---|
282 | * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
|
---|
283 | * @param pUsbIns The USB device instance.
|
---|
284 | * @param cb Number of bytes to allocate.
|
---|
285 | */
|
---|
286 | DECLR3CALLBACKMEMBER(void *, pfnMMHeapAlloc,(PPDMUSBINS pUsbIns, size_t cb));
|
---|
287 |
|
---|
288 | /**
|
---|
289 | * Allocate memory which is associated with current VM instance
|
---|
290 | * and automatically freed on it's destruction. The memory is ZEROed.
|
---|
291 | *
|
---|
292 | * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
|
---|
293 | * @param pUsbIns The USB device instance.
|
---|
294 | * @param cb Number of bytes to allocate.
|
---|
295 | */
|
---|
296 | DECLR3CALLBACKMEMBER(void *, pfnMMHeapAllocZ,(PPDMUSBINS pUsbIns, size_t cb));
|
---|
297 |
|
---|
298 | /**
|
---|
299 | * Create a queue.
|
---|
300 | *
|
---|
301 | * @returns VBox status code.
|
---|
302 | * @param pUsbIns The USB device instance.
|
---|
303 | * @param cbItem Size a queue item.
|
---|
304 | * @param cItems Number of items in the queue.
|
---|
305 | * @param cMilliesInterval Number of milliseconds between polling the queue.
|
---|
306 | * If 0 then the emulation thread will be notified whenever an item arrives.
|
---|
307 | * @param pfnCallback The consumer function.
|
---|
308 | * @param ppQueue Where to store the queue handle on success.
|
---|
309 | * @thread The emulation thread.
|
---|
310 | */
|
---|
311 | /** @todo DECLR3CALLBACKMEMBER(int, pfnPDMQueueCreate,(PPDMUSBINS pUsbIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval, PFNPDMQUEUEUSB pfnCallback, PPDMQUEUE *ppQueue)); */
|
---|
312 |
|
---|
313 | /**
|
---|
314 | * Register a save state data unit.
|
---|
315 | *
|
---|
316 | * @returns VBox status.
|
---|
317 | * @param pUsbIns The USB device instance.
|
---|
318 | * @param pszName Data unit name.
|
---|
319 | * @param u32Instance The instance identifier of the data unit.
|
---|
320 | * This must together with the name be unique.
|
---|
321 | * @param u32Version Data layout version number.
|
---|
322 | * @param cbGuess The approximate amount of data in the unit.
|
---|
323 | * Only for progress indicators.
|
---|
324 | * @param pfnSavePrep Prepare save callback, optional.
|
---|
325 | * @param pfnSaveExec Execute save callback, optional.
|
---|
326 | * @param pfnSaveDone Done save callback, optional.
|
---|
327 | * @param pfnLoadPrep Prepare load callback, optional.
|
---|
328 | * @param pfnLoadExec Execute load callback, optional.
|
---|
329 | * @param pfnLoadDone Done load callback, optional.
|
---|
330 | */
|
---|
331 | /** @todo DECLR3CALLBACKMEMBER(int, pfnSSMRegister,(PPDMUSBINS pUsbIns, const char *pszName, uint32_t u32Instance, uint32_t u32Version, size_t cbGuess,
|
---|
332 | PFNSSMUSBSAVEPREP pfnSavePrep, PFNSSMUSBSAVEEXEC pfnSaveExec, PFNSSMUSBSAVEDONE pfnSaveDone,
|
---|
333 | PFNSSMUSBLOADPREP pfnLoadPrep, PFNSSMUSBLOADEXEC pfnLoadExec, PFNSSMUSBLOADDONE pfnLoadDone)); */
|
---|
334 |
|
---|
335 | /**
|
---|
336 | * Register a STAM sample.
|
---|
337 | *
|
---|
338 | * Use the PDMUsbHlpSTAMRegister wrapper.
|
---|
339 | *
|
---|
340 | * @returns VBox status.
|
---|
341 | * @param pUsbIns The USB device instance.
|
---|
342 | * @param pvSample Pointer to the sample.
|
---|
343 | * @param enmType Sample type. This indicates what pvSample is pointing at.
|
---|
344 | * @param enmVisibility Visibility type specifying whether unused statistics should be visible or not.
|
---|
345 | * @param enmUnit Sample unit.
|
---|
346 | * @param pszDesc Sample description.
|
---|
347 | * @param pszName The sample name format string.
|
---|
348 | * @param va Arguments to the format string.
|
---|
349 | */
|
---|
350 | DECLR3CALLBACKMEMBER(void, pfnSTAMRegisterV,(PPDMUSBINS pUsbIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
|
---|
351 | STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list va));
|
---|
352 |
|
---|
353 | /**
|
---|
354 | * Creates a timer.
|
---|
355 | *
|
---|
356 | * @returns VBox status.
|
---|
357 | * @param pUsbIns The USB device instance.
|
---|
358 | * @param enmClock The clock to use on this timer.
|
---|
359 | * @param pfnCallback Callback function.
|
---|
360 | * @param pszDesc Pointer to description string which must stay around
|
---|
361 | * until the timer is fully destroyed (i.e. a bit after TMTimerDestroy()).
|
---|
362 | * @param ppTimer Where to store the timer on success.
|
---|
363 | */
|
---|
364 | /** @todo DECLR3CALLBACKMEMBER(int, pfnTMTimerCreate,(PPDMUSBINS pUsbIns, TMCLOCK enmClock, PFNTMTIMERUSB pfnCallback, const char *pszDesc, PPTMTIMERHC ppTimer)); */
|
---|
365 |
|
---|
366 | /**
|
---|
367 | * Set the VM error message
|
---|
368 | *
|
---|
369 | * @returns rc.
|
---|
370 | * @param pUsbIns The USB device instance.
|
---|
371 | * @param rc VBox status code.
|
---|
372 | * @param RT_SRC_POS_DECL Use RT_SRC_POS.
|
---|
373 | * @param pszFormat Error message format string.
|
---|
374 | * @param va Error message arguments.
|
---|
375 | */
|
---|
376 | DECLR3CALLBACKMEMBER(int, pfnVMSetErrorV,(PPDMUSBINS pUsbIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va));
|
---|
377 |
|
---|
378 | /**
|
---|
379 | * Set the VM runtime error message
|
---|
380 | *
|
---|
381 | * @returns VBox status code.
|
---|
382 | * @param pUsbIns The USB device instance.
|
---|
383 | * @param fFatal Whether it is a fatal error or not.
|
---|
384 | * @param pszErrorID Error ID string.
|
---|
385 | * @param pszFormat Error message format string.
|
---|
386 | * @param va Error message arguments.
|
---|
387 | */
|
---|
388 | DECLR3CALLBACKMEMBER(int, pfnVMSetRuntimeErrorV,(PPDMUSBINS pUsbIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va));
|
---|
389 |
|
---|
390 | /** Just a safety precaution. */
|
---|
391 | uint32_t u32TheEnd;
|
---|
392 | } PDMUSBHLP;
|
---|
393 | /** Pointer PDM USB Device API. */
|
---|
394 | typedef PDMUSBHLP *PPDMUSBHLP;
|
---|
395 | /** Pointer const PDM USB Device API. */
|
---|
396 | typedef const PDMUSBHLP *PCPDMUSBHLP;
|
---|
397 |
|
---|
398 | /** Current USBHLP version number. */
|
---|
399 | #define PDM_USBHLP_VERSION 0xec020000
|
---|
400 |
|
---|
401 | #endif /* IN_RING3 */
|
---|
402 |
|
---|
403 | /**
|
---|
404 | * PDM USB Device Instance.
|
---|
405 | */
|
---|
406 | typedef struct PDMUSBINS
|
---|
407 | {
|
---|
408 | /** Structure version. PDM_USBINS_VERSION defines the current version. */
|
---|
409 | uint32_t u32Version;
|
---|
410 | /** USB device instance number. */
|
---|
411 | RTUINT iInstance;
|
---|
412 | /** The base interface of the device.
|
---|
413 | * The device constructor initializes this if it has any device level
|
---|
414 | * interfaces to export. To obtain this interface call PDMR3QueryUSBDevice(). */
|
---|
415 | PDMIBASE IBase;
|
---|
416 | #if HC_ARCH_BITS == 32
|
---|
417 | uint32_t u32Alignment; /**< Alignment padding. */
|
---|
418 | #endif
|
---|
419 |
|
---|
420 | /** Internal data. */
|
---|
421 | union
|
---|
422 | {
|
---|
423 | #ifdef PDMUSBINSINT_DECLARED
|
---|
424 | PDMUSBINSINT s;
|
---|
425 | #endif
|
---|
426 | uint8_t padding[HC_ARCH_BITS == 32 ? 64 : 96];
|
---|
427 | } Internal;
|
---|
428 |
|
---|
429 | /** Pointer the PDM USB Device API. */
|
---|
430 | R3PTRTYPE(PCPDMUSBHLP) pUsbHlp;
|
---|
431 | /** Pointer to the USB device registration structure. */
|
---|
432 | R3PTRTYPE(PCPDMUSBREG) pUsbReg;
|
---|
433 | /** Configuration handle. */
|
---|
434 | R3PTRTYPE(PCFGMNODE) pCfg;
|
---|
435 | /** The (device) global configuration handle. */
|
---|
436 | R3PTRTYPE(PCFGMNODE) pCfgGlobal;
|
---|
437 | /** Pointer to device instance data. */
|
---|
438 | R3PTRTYPE(void *) pvInstanceDataR3;
|
---|
439 | /** Pointer to the VUSB Device structure.
|
---|
440 | * The constructor sets this.
|
---|
441 | * @todo Integrate VUSBDEV into this structure. */
|
---|
442 | R3PTRTYPE(void *) pvVUsbDev;
|
---|
443 | /** Padding to make achInstanceData aligned at 32 byte boundrary. */
|
---|
444 | uint32_t au32Padding[HC_ARCH_BITS == 32 ? 6 : 4];
|
---|
445 | /** Device instance data. The size of this area is defined
|
---|
446 | * in the PDMUSBREG::cbInstanceData field. */
|
---|
447 | char achInstanceData[8];
|
---|
448 | } PDMUSBINS;
|
---|
449 |
|
---|
450 | /** Current USBINS version number. */
|
---|
451 | #define PDM_USBINS_VERSION 0xf3010000
|
---|
452 |
|
---|
453 | /** Converts a pointer to the PDMUSBINS::IBase to a pointer to PDMUSBINS. */
|
---|
454 | #define PDMIBASE_2_PDMUSB(pInterface) ( (PPDMUSBINS)((char *)(pInterface) - RT_OFFSETOF(PDMUSBINS, IBase)) )
|
---|
455 |
|
---|
456 |
|
---|
457 | /** @def PDMUSB_ASSERT_EMT
|
---|
458 | * Assert that the current thread is the emulation thread.
|
---|
459 | */
|
---|
460 | #ifdef VBOX_STRICT
|
---|
461 | # define PDMUSB_ASSERT_EMT(pUsbIns) pUsbIns->pUsbHlp->pfnAssertEMT(pUsbIns, __FILE__, __LINE__, __FUNCTION__)
|
---|
462 | #else
|
---|
463 | # define PDMUSB_ASSERT_EMT(pUsbIns) do { } while (0)
|
---|
464 | #endif
|
---|
465 |
|
---|
466 | /** @def PDMUSB_ASSERT_OTHER
|
---|
467 | * Assert that the current thread is NOT the emulation thread.
|
---|
468 | */
|
---|
469 | #ifdef VBOX_STRICT
|
---|
470 | # define PDMUSB_ASSERT_OTHER(pUsbIns) pUsbIns->pUsbHlp->pfnAssertOther(pUsbIns, __FILE__, __LINE__, __FUNCTION__)
|
---|
471 | #else
|
---|
472 | # define PDMUSB_ASSERT_OTHER(pUsbIns) do { } while (0)
|
---|
473 | #endif
|
---|
474 |
|
---|
475 | /** @def PDMUSB_SET_ERROR
|
---|
476 | * Set the VM error. See PDMDevHlpVMSetError() for printf like message formatting.
|
---|
477 | */
|
---|
478 | #define PDMUSB_SET_ERROR(pUsbIns, rc, pszError) \
|
---|
479 | PDMDevHlpVMSetError(pUsbIns, rc, RT_SRC_POS, "%s", pszError)
|
---|
480 |
|
---|
481 | /** @def PDMUSB_SET_RUNTIME_ERROR
|
---|
482 | * Set the VM runtime error. See PDMDevHlpVMSetRuntimeError() for printf like message formatting.
|
---|
483 | */
|
---|
484 | #define PDMUSB_SET_RUNTIME_ERROR(pUsbIns, fFatal, pszErrorID, pszError) \
|
---|
485 | PDMDevHlpVMSetRuntimeError(pUsbIns, fFatal, pszErrorID, "%s", pszError)
|
---|
486 |
|
---|
487 |
|
---|
488 | #ifdef IN_RING3
|
---|
489 |
|
---|
490 | /**
|
---|
491 | * VBOX_STRICT wrapper for pUsbHlp->pfnDBGFStopV.
|
---|
492 | *
|
---|
493 | * @returns VBox status code which must be passed up to the VMM.
|
---|
494 | * @param pUsbIns Device instance.
|
---|
495 | * @param RT_SRC_POS_DECL Use RT_SRC_POS.
|
---|
496 | * @param pszFormat Message. (optional)
|
---|
497 | * @param ... Message parameters.
|
---|
498 | */
|
---|
499 | DECLINLINE(int) PDMUsbDBGFStop(PPDMUSBINS pUsbIns, RT_SRC_POS_DECL, const char *pszFormat, ...)
|
---|
500 | {
|
---|
501 | #ifdef VBOX_STRICT
|
---|
502 | int rc;
|
---|
503 | va_list va;
|
---|
504 | va_start(va, pszFormat);
|
---|
505 | rc = pUsbIns->pUsbHlp->pfnDBGFStopV(pUsbIns, RT_SRC_POS_ARGS, pszFormat, va);
|
---|
506 | va_end(va);
|
---|
507 | return rc;
|
---|
508 | #else
|
---|
509 | return VINF_SUCCESS;
|
---|
510 | #endif
|
---|
511 | }
|
---|
512 |
|
---|
513 |
|
---|
514 | /* inline wrappers */
|
---|
515 |
|
---|
516 | #endif
|
---|
517 |
|
---|
518 |
|
---|
519 |
|
---|
520 | /** Pointer to callbacks provided to the VBoxUsbRegister() call. */
|
---|
521 | typedef const struct PDMUSBREGCB *PCPDMUSBREGCB;
|
---|
522 |
|
---|
523 | /**
|
---|
524 | * Callbacks for VBoxUSBDeviceRegister().
|
---|
525 | */
|
---|
526 | typedef struct PDMUSBREGCB
|
---|
527 | {
|
---|
528 | /** Interface version.
|
---|
529 | * This is set to PDM_USBREG_CB_VERSION. */
|
---|
530 | uint32_t u32Version;
|
---|
531 |
|
---|
532 | /**
|
---|
533 | * Registers a device with the current VM instance.
|
---|
534 | *
|
---|
535 | * @returns VBox status code.
|
---|
536 | * @param pCallbacks Pointer to the callback table.
|
---|
537 | * @param pDevReg Pointer to the device registration record.
|
---|
538 | * This data must be permanent and readonly.
|
---|
539 | */
|
---|
540 | DECLR3CALLBACKMEMBER(int, pfnRegister,(PCPDMUSBREGCB pCallbacks, PCPDMUSBREG pDevReg));
|
---|
541 |
|
---|
542 | /**
|
---|
543 | * Allocate memory which is associated with current VM instance
|
---|
544 | * and automatically freed on it's destruction.
|
---|
545 | *
|
---|
546 | * @returns Pointer to allocated memory. The memory is *NOT* zero-ed.
|
---|
547 | * @param pCallbacks Pointer to the callback table.
|
---|
548 | * @param cb Number of bytes to allocate.
|
---|
549 | */
|
---|
550 | DECLR3CALLBACKMEMBER(void *, pfnMMHeapAlloc,(PCPDMUSBREGCB pCallbacks, size_t cb));
|
---|
551 | } PDMUSBREGCB;
|
---|
552 |
|
---|
553 | /** Current version of the PDMUSBREGCB structure. */
|
---|
554 | #define PDM_USBREG_CB_VERSION 0xee010000
|
---|
555 |
|
---|
556 |
|
---|
557 | /**
|
---|
558 | * The VBoxUsbRegister callback function.
|
---|
559 | *
|
---|
560 | * PDM will invoke this function after loading a USB device module and letting
|
---|
561 | * the module decide which devices to register and how to handle conflicts.
|
---|
562 | *
|
---|
563 | * @returns VBox status code.
|
---|
564 | * @param pCallbacks Pointer to the callback table.
|
---|
565 | * @param u32Version VBox version number.
|
---|
566 | */
|
---|
567 | typedef DECLCALLBACK(int) FNPDMVBOXUSBREGISTER(PCPDMUSBREGCB pCallbacks, uint32_t u32Version);
|
---|
568 |
|
---|
569 |
|
---|
570 | /**
|
---|
571 | * Creates a USB proxy device instance.
|
---|
572 | *
|
---|
573 | * This will find an appropriate HUB for the USB device, create the necessary CFGM stuff
|
---|
574 | * and try instantiate the proxy device.
|
---|
575 | *
|
---|
576 | * @returns VBox status code.
|
---|
577 | * @param pVM The VM handle.
|
---|
578 | * @param pUuid The UUID thats to be associated with the device.
|
---|
579 | * @param fRemote Whether it's a remove or local device.
|
---|
580 | * @param pszAddress The address string.
|
---|
581 | * @param pvBackend Pointer to the backend.
|
---|
582 | * @param iUsbVersion The preferred USB version.
|
---|
583 | */
|
---|
584 | PDMR3DECL(int) PDMR3USBCreateProxyDevice(PVM pVM, PCRTUUID pUuid, bool fRemote, const char *pszAddress, void *pvBackend, uint32_t iUsbVersion);
|
---|
585 |
|
---|
586 | /**
|
---|
587 | * Detaches and destroys a USB device.
|
---|
588 | *
|
---|
589 | * @returns VBox status code.
|
---|
590 | * @param pVM The VM handle.
|
---|
591 | * @param pUuid The UUID associated with the device to detach.
|
---|
592 | * @thread EMT
|
---|
593 | */
|
---|
594 | PDMR3DECL(int) PDMR3USBDetachDevice(PVM pVM, PCRTUUID pUuid);
|
---|
595 |
|
---|
596 | /**
|
---|
597 | * Checks if there are any USB hubs attached.
|
---|
598 | *
|
---|
599 | * @returns true / false accordingly.
|
---|
600 | * @param pVM Pointer to the shared VM structure.
|
---|
601 | */
|
---|
602 | PDMR3DECL(bool) PDMR3USBHasHub(PVM pVM);
|
---|
603 |
|
---|
604 |
|
---|
605 | /** @} */
|
---|
606 |
|
---|
607 | __END_DECLS
|
---|
608 |
|
---|
609 | #endif
|
---|