1 | /* $Id: DrvVUSBRootHub.cpp 93979 2022-02-28 13:16:30Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Virtual USB - Root Hub Driver.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2005-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /** @page pg_dev_vusb VUSB - Virtual USB
|
---|
20 | *
|
---|
21 | * @todo read thru this and correct typos. Merge with old docs.
|
---|
22 | *
|
---|
23 | *
|
---|
24 | * The Virtual USB component glues USB devices and host controllers together.
|
---|
25 | * The VUSB takes the form of a PDM driver which is attached to the HCI. USB
|
---|
26 | * devices are created by, attached to, and managed by the VUSB roothub. The
|
---|
27 | * VUSB also exposes an interface which is used by Main to attach and detach
|
---|
28 | * proxied USB devices.
|
---|
29 | *
|
---|
30 | *
|
---|
31 | * @section sec_dev_vusb_urb The Life of an URB
|
---|
32 | *
|
---|
33 | * The URB is created when the HCI calls the roothub (VUSB) method pfnNewUrb.
|
---|
34 | * VUSB has a pool of URBs, if no free URBs are available a new one is
|
---|
35 | * allocated. The returned URB starts life in the ALLOCATED state and all
|
---|
36 | * fields are initialized with sensible defaults.
|
---|
37 | *
|
---|
38 | * The HCI then copies any request data into the URB if it's an host2dev
|
---|
39 | * transfer. It then submits the URB by calling the pfnSubmitUrb roothub
|
---|
40 | * method.
|
---|
41 | *
|
---|
42 | * pfnSubmitUrb will start by checking if it knows the device address, and if
|
---|
43 | * it doesn't the URB is completed with a device-not-ready error. When the
|
---|
44 | * device address is known to it, action is taken based on the kind of
|
---|
45 | * transfer it is. There are four kinds of transfers: 1. control, 2. bulk,
|
---|
46 | * 3. interrupt, and 4. isochronous. In either case something eventually ends
|
---|
47 | * up being submitted to the device.
|
---|
48 | *
|
---|
49 | *
|
---|
50 | * If an URB fails submitting, may or may not be completed. This depends on
|
---|
51 | * heuristics in some cases and on the kind of failure in others. If
|
---|
52 | * pfnSubmitUrb returns a failure, the HCI should retry submitting it at a
|
---|
53 | * later time. If pfnSubmitUrb returns success the URB is submitted, and it
|
---|
54 | * can even been completed.
|
---|
55 | *
|
---|
56 | * The URB is in the IN_FLIGHT state from the time it's successfully submitted
|
---|
57 | * and till it's reaped or cancelled.
|
---|
58 | *
|
---|
59 | * When an URB transfer or in some case submit failure occurs, the pfnXferError
|
---|
60 | * callback of the HCI is consulted about what to do. If pfnXferError indicates
|
---|
61 | * that the URB should be retried, pfnSubmitUrb will fail. If it indicates that
|
---|
62 | * it should fail, the URB will be completed.
|
---|
63 | *
|
---|
64 | * Completing an URB means that the URB status is set and the HCI
|
---|
65 | * pfnXferCompletion callback is invoked with the URB. The HCI is the supposed
|
---|
66 | * to report the transfer status to the guest OS. After completion the URB
|
---|
67 | * is freed and returned to the pool, unless it was cancelled. If it was
|
---|
68 | * cancelled it will have to await reaping before it's actually freed.
|
---|
69 | *
|
---|
70 | *
|
---|
71 | * @subsection subsec_dev_vusb_urb_ctrl Control
|
---|
72 | *
|
---|
73 | * The control transfer is the most complex one, from VUSB's point of view,
|
---|
74 | * with its three stages and being bi-directional. A control transfer starts
|
---|
75 | * with a SETUP packet containing the request description and two basic
|
---|
76 | * parameters. It is followed by zero or more DATA packets which either picks
|
---|
77 | * up incoming data (dev2host) or supplies the request data (host2dev). This
|
---|
78 | * can then be followed by a STATUS packet which gets the status of the whole
|
---|
79 | * transfer.
|
---|
80 | *
|
---|
81 | * What makes the control transfer complicated is that for a host2dev request
|
---|
82 | * the URB is assembled from the SETUP and DATA stage, and for a dev2host
|
---|
83 | * request the returned data must be kept around for the DATA stage. For both
|
---|
84 | * transfer directions the status of the transfer has to be kept around for
|
---|
85 | * the STATUS stage.
|
---|
86 | *
|
---|
87 | * To complicate matters further, VUSB must intercept and in some cases emulate
|
---|
88 | * some of the standard requests in order to keep the virtual device state
|
---|
89 | * correct and provide the correct virtualization of a device.
|
---|
90 | *
|
---|
91 | * @subsection subsec_dev_vusb_urb_bulk Bulk and Interrupt
|
---|
92 | *
|
---|
93 | * The bulk and interrupt transfer types are relativly simple compared to the
|
---|
94 | * control transfer. VUSB is not inspecting the request content or anything,
|
---|
95 | * but passes it down the device.
|
---|
96 | *
|
---|
97 | * @subsection subsec_dev_vusb_urb_isoc Isochronous
|
---|
98 | *
|
---|
99 | * This kind of transfers hasn't yet been implemented.
|
---|
100 | *
|
---|
101 | */
|
---|
102 |
|
---|
103 |
|
---|
104 | /** @page pg_dev_vusb_old VUSB - Virtual USB Core
|
---|
105 | *
|
---|
106 | * The virtual USB core is controlled by the roothub and the underlying HCI
|
---|
107 | * emulator, it is responsible for device addressing, managing configurations,
|
---|
108 | * interfaces and endpoints, assembling and splitting multi-part control
|
---|
109 | * messages and in general acts as a middle layer between the USB device
|
---|
110 | * emulation code and USB HCI emulation code.
|
---|
111 | *
|
---|
112 | * All USB devices are represented by a struct vusb_dev. This structure
|
---|
113 | * contains things like the device state, device address, all the configuration
|
---|
114 | * descriptors, the currently selected configuration and a mapping between
|
---|
115 | * endpoint addresses and endpoint descriptors.
|
---|
116 | *
|
---|
117 | * Each vusb_dev also has a pointer to a vusb_dev_ops structure which serves as
|
---|
118 | * the virtual method table and includes a virtual constructor and destructor.
|
---|
119 | * After a vusb_dev is created it may be attached to a hub device such as a
|
---|
120 | * roothub (using vusbHubAttach). Although each hub structure has cPorts
|
---|
121 | * and cDevices fields, it is the responsibility of the hub device to allocate
|
---|
122 | * a free port for the new device.
|
---|
123 | *
|
---|
124 | * Devices can chose one of two interfaces for dealing with requests, the
|
---|
125 | * synchronous interface or the asynchronous interface. The synchronous
|
---|
126 | * interface is much simpler and ought to be used for devices which are
|
---|
127 | * unlikely to sleep for long periods in order to serve requests. The
|
---|
128 | * asynchronous interface on the other hand is more difficult to use but is
|
---|
129 | * useful for the USB proxy or if one were to write a mass storage device
|
---|
130 | * emulator. Currently the synchronous interface only supports control and bulk
|
---|
131 | * endpoints and is no longer used by anything.
|
---|
132 | *
|
---|
133 | * In order to use the asynchronous interface, the queue_urb, cancel_urb and
|
---|
134 | * pfnUrbReap fields must be set in the devices vusb_dev_ops structure. The
|
---|
135 | * queue_urb method is used to submit a request to a device without blocking,
|
---|
136 | * it returns 1 if successful and 0 on any kind of failure. A successfully
|
---|
137 | * queued URB is completed when the pfnUrbReap method returns it. Each function
|
---|
138 | * address is reference counted so that pfnUrbReap will only be called if there
|
---|
139 | * are URBs outstanding. For a roothub to reap an URB from any one of it's
|
---|
140 | * devices, the vusbRhReapAsyncUrbs() function is used.
|
---|
141 | *
|
---|
142 | * There are four types of messages an URB may contain:
|
---|
143 | * -# Control - represents a single packet of a multi-packet control
|
---|
144 | * transfer, these are only really used by the host controller to
|
---|
145 | * submit the parts to the usb core.
|
---|
146 | * -# Message - the usb core assembles multiple control transfers in
|
---|
147 | * to single message transfers. In this case the data buffer
|
---|
148 | * contains the setup packet in little endian followed by the full
|
---|
149 | * buffer. In the case of an host-to-device control message, the
|
---|
150 | * message packet is created when the STATUS transfer is seen. In
|
---|
151 | * the case of device-to-host messages, the message packet is
|
---|
152 | * created after the SETUP transfer is seen. Also, certain control
|
---|
153 | * requests never go the real device and get handled synchronously.
|
---|
154 | * -# Bulk - Currently the only endpoint type that does error checking
|
---|
155 | * and endpoint halting.
|
---|
156 | * -# Interrupt - The only non-periodic type supported.
|
---|
157 | *
|
---|
158 | * Hubs are special cases of devices, they have a number of downstream ports
|
---|
159 | * that other devices can be attached to and removed from.
|
---|
160 | *
|
---|
161 | * After a device has been attached (vusbHubAttach):
|
---|
162 | * -# The hub attach method is called, which sends a hub status
|
---|
163 | * change message to the OS.
|
---|
164 | * -# The OS resets the device, and it appears on the default
|
---|
165 | * address with it's config 0 selected (a pseudo-config that
|
---|
166 | * contains only 1 interface with 1 endpoint - the default
|
---|
167 | * message pipe).
|
---|
168 | * -# The OS assigns the device a new address and selects an
|
---|
169 | * appropriate config.
|
---|
170 | * -# The device is ready.
|
---|
171 | *
|
---|
172 | * After a device has been detached (vusbDevDetach):
|
---|
173 | * -# All pending URBs are cancelled.
|
---|
174 | * -# The devices address is unassigned.
|
---|
175 | * -# The hub detach method is called which signals the OS
|
---|
176 | * of the status change.
|
---|
177 | * -# The OS unlinks the ED's for that device.
|
---|
178 | *
|
---|
179 | * A device can also request detachment from within its own methods by
|
---|
180 | * calling vusbDevUnplugged().
|
---|
181 | *
|
---|
182 | * Roothubs are responsible for driving the whole system, they are special
|
---|
183 | * cases of hubs and as such implement attach and detach methods, each one
|
---|
184 | * is described by a struct vusb_roothub. Once a roothub has submitted an
|
---|
185 | * URB to the USB core, a number of callbacks to the roothub are required
|
---|
186 | * for when the URB completes, since the roothub typically wants to inform
|
---|
187 | * the OS when transfers are completed.
|
---|
188 | *
|
---|
189 | * There are four callbacks to be concerned with:
|
---|
190 | * -# prepare - This is called after the URB is successfully queued.
|
---|
191 | * -# completion - This is called after the URB completed.
|
---|
192 | * -# error - This is called if the URB errored, some systems have
|
---|
193 | * automatic resubmission of failed requests, so this callback
|
---|
194 | * should keep track of the error count and return 1 if the count
|
---|
195 | * is above the number of allowed resubmissions.
|
---|
196 | * -# halt_ep - This is called after errors on bulk pipes in order
|
---|
197 | * to halt the pipe.
|
---|
198 | *
|
---|
199 | */
|
---|
200 |
|
---|
201 |
|
---|
202 | /*********************************************************************************************************************************
|
---|
203 | * Header Files *
|
---|
204 | *********************************************************************************************************************************/
|
---|
205 | #define LOG_GROUP LOG_GROUP_DRV_VUSB
|
---|
206 | #include <VBox/vmm/pdm.h>
|
---|
207 | #include <VBox/vmm/vmapi.h>
|
---|
208 | #include <VBox/err.h>
|
---|
209 | #include <iprt/alloc.h>
|
---|
210 | #include <VBox/log.h>
|
---|
211 | #include <iprt/time.h>
|
---|
212 | #include <iprt/thread.h>
|
---|
213 | #include <iprt/semaphore.h>
|
---|
214 | #include <iprt/string.h>
|
---|
215 | #include <iprt/assert.h>
|
---|
216 | #include <iprt/asm.h>
|
---|
217 | #include <iprt/uuid.h>
|
---|
218 | #include "VUSBInternal.h"
|
---|
219 | #include "VBoxDD.h"
|
---|
220 |
|
---|
221 |
|
---|
222 | #define VUSB_ROOTHUB_SAVED_STATE_VERSION 1
|
---|
223 |
|
---|
224 |
|
---|
225 | /**
|
---|
226 | * Data used for reattaching devices on a state load.
|
---|
227 | */
|
---|
228 | typedef struct VUSBROOTHUBLOAD
|
---|
229 | {
|
---|
230 | /** Timer used once after state load to inform the guest about new devices.
|
---|
231 | * We do this to be sure the guest get any disconnect / reconnect on the
|
---|
232 | * same port. */
|
---|
233 | TMTIMERHANDLE hTimer;
|
---|
234 | /** Number of detached devices. */
|
---|
235 | unsigned cDevs;
|
---|
236 | /** Array of devices which were detached. */
|
---|
237 | PVUSBDEV apDevs[VUSB_DEVICES_MAX];
|
---|
238 | } VUSBROOTHUBLOAD;
|
---|
239 |
|
---|
240 |
|
---|
241 | /**
|
---|
242 | * Returns the attached VUSB device for the given port or NULL if none is attached.
|
---|
243 | *
|
---|
244 | * @returns Pointer to the VUSB device or NULL if not found.
|
---|
245 | * @param pThis The VUSB roothub device instance.
|
---|
246 | * @param uPort The port to get the device for.
|
---|
247 | *
|
---|
248 | * @note The reference count of the VUSB device structure is retained to prevent it from going away.
|
---|
249 | */
|
---|
250 | static PVUSBDEV vusbR3RhGetVUsbDevByPortRetain(PVUSBROOTHUB pThis, uint32_t uPort)
|
---|
251 | {
|
---|
252 | PVUSBDEV pDev = NULL;
|
---|
253 |
|
---|
254 | AssertReturn(uPort < RT_ELEMENTS(pThis->apDevByPort), NULL);
|
---|
255 |
|
---|
256 | RTCritSectEnter(&pThis->CritSectDevices);
|
---|
257 |
|
---|
258 | pDev = pThis->apDevByPort[uPort];
|
---|
259 | if (RT_LIKELY(pDev))
|
---|
260 | vusbDevRetain(pDev);
|
---|
261 |
|
---|
262 | RTCritSectLeave(&pThis->CritSectDevices);
|
---|
263 |
|
---|
264 | return pDev;
|
---|
265 | }
|
---|
266 |
|
---|
267 |
|
---|
268 | /**
|
---|
269 | * Returns the attached VUSB device for the given port or NULL if none is attached.
|
---|
270 | *
|
---|
271 | * @returns Pointer to the VUSB device or NULL if not found.
|
---|
272 | * @param pThis The VUSB roothub device instance.
|
---|
273 | * @param u8Address The address to get the device for.
|
---|
274 | *
|
---|
275 | * @note The reference count of the VUSB device structure is retained to prevent it from going away.
|
---|
276 | */
|
---|
277 | static PVUSBDEV vusbR3RhGetVUsbDevByAddrRetain(PVUSBROOTHUB pThis, uint8_t u8Address)
|
---|
278 | {
|
---|
279 | PVUSBDEV pDev = NULL;
|
---|
280 |
|
---|
281 | AssertReturn(u8Address < RT_ELEMENTS(pThis->apDevByAddr), NULL);
|
---|
282 |
|
---|
283 | RTCritSectEnter(&pThis->CritSectDevices);
|
---|
284 |
|
---|
285 | pDev = pThis->apDevByAddr[u8Address];
|
---|
286 | if (RT_LIKELY(pDev))
|
---|
287 | vusbDevRetain(pDev);
|
---|
288 |
|
---|
289 | RTCritSectLeave(&pThis->CritSectDevices);
|
---|
290 |
|
---|
291 | return pDev;
|
---|
292 | }
|
---|
293 |
|
---|
294 |
|
---|
295 | /**
|
---|
296 | * Returns a human readable string fromthe given USB speed enum.
|
---|
297 | *
|
---|
298 | * @returns Human readable string.
|
---|
299 | * @param enmSpeed The speed to stringify.
|
---|
300 | */
|
---|
301 | static const char *vusbGetSpeedString(VUSBSPEED enmSpeed)
|
---|
302 | {
|
---|
303 | const char *pszSpeed = NULL;
|
---|
304 |
|
---|
305 | switch (enmSpeed)
|
---|
306 | {
|
---|
307 | case VUSB_SPEED_LOW:
|
---|
308 | pszSpeed = "Low";
|
---|
309 | break;
|
---|
310 | case VUSB_SPEED_FULL:
|
---|
311 | pszSpeed = "Full";
|
---|
312 | break;
|
---|
313 | case VUSB_SPEED_HIGH:
|
---|
314 | pszSpeed = "High";
|
---|
315 | break;
|
---|
316 | case VUSB_SPEED_VARIABLE:
|
---|
317 | pszSpeed = "Variable";
|
---|
318 | break;
|
---|
319 | case VUSB_SPEED_SUPER:
|
---|
320 | pszSpeed = "Super";
|
---|
321 | break;
|
---|
322 | case VUSB_SPEED_SUPERPLUS:
|
---|
323 | pszSpeed = "SuperPlus";
|
---|
324 | break;
|
---|
325 | default:
|
---|
326 | pszSpeed = "Unknown";
|
---|
327 | break;
|
---|
328 | }
|
---|
329 | return pszSpeed;
|
---|
330 | }
|
---|
331 |
|
---|
332 |
|
---|
333 | /**
|
---|
334 | * Attaches a device to a specific hub.
|
---|
335 | *
|
---|
336 | * This function is called by the vusb_add_device() and vusbRhAttachDevice().
|
---|
337 | *
|
---|
338 | * @returns VBox status code.
|
---|
339 | * @param pThis The roothub to attach it to.
|
---|
340 | * @param pDev The device to attach.
|
---|
341 | * @thread EMT
|
---|
342 | */
|
---|
343 | static int vusbHubAttach(PVUSBROOTHUB pThis, PVUSBDEV pDev)
|
---|
344 | {
|
---|
345 | LogFlow(("vusbHubAttach: pThis=%p[%s] pDev=%p[%s]\n", pThis, pThis->pszName, pDev, pDev->pUsbIns->pszName));
|
---|
346 |
|
---|
347 | /*
|
---|
348 | * Assign a port.
|
---|
349 | */
|
---|
350 | int iPort = ASMBitFirstSet(&pThis->Bitmap, sizeof(pThis->Bitmap) * 8);
|
---|
351 | if (iPort < 0)
|
---|
352 | {
|
---|
353 | LogRel(("VUSB: No ports available!\n"));
|
---|
354 | return VERR_VUSB_NO_PORTS;
|
---|
355 | }
|
---|
356 | ASMBitClear(&pThis->Bitmap, iPort);
|
---|
357 | pThis->cDevices++;
|
---|
358 | pDev->i16Port = iPort;
|
---|
359 |
|
---|
360 | /* Call the device attach helper, so it can initialize its state. */
|
---|
361 | int rc = vusbDevAttach(pDev, pThis);
|
---|
362 | if (RT_SUCCESS(rc))
|
---|
363 | {
|
---|
364 | RTCritSectEnter(&pThis->CritSectDevices);
|
---|
365 | Assert(!pThis->apDevByPort[iPort]);
|
---|
366 | pThis->apDevByPort[iPort] = pDev;
|
---|
367 | RTCritSectLeave(&pThis->CritSectDevices);
|
---|
368 |
|
---|
369 | /*
|
---|
370 | * Call the HCI attach routine and let it have its say before the device is
|
---|
371 | * linked into the device list of this hub.
|
---|
372 | */
|
---|
373 | VUSBSPEED enmSpeed = pDev->IDevice.pfnGetSpeed(&pDev->IDevice);
|
---|
374 | rc = pThis->pIRhPort->pfnAttach(pThis->pIRhPort, iPort, enmSpeed);
|
---|
375 | if (RT_SUCCESS(rc))
|
---|
376 | {
|
---|
377 | LogRel(("VUSB: Attached '%s' to port %d on %s (%sSpeed)\n", pDev->pUsbIns->pszName,
|
---|
378 | iPort, pThis->pszName, vusbGetSpeedString(pDev->pUsbIns->enmSpeed)));
|
---|
379 | return VINF_SUCCESS;
|
---|
380 | }
|
---|
381 |
|
---|
382 | /* Remove from the port in case of failure. */
|
---|
383 | RTCritSectEnter(&pThis->CritSectDevices);
|
---|
384 | Assert(!pThis->apDevByPort[iPort]);
|
---|
385 | pThis->apDevByPort[iPort] = NULL;
|
---|
386 | RTCritSectLeave(&pThis->CritSectDevices);
|
---|
387 |
|
---|
388 | vusbDevDetach(pDev);
|
---|
389 | }
|
---|
390 |
|
---|
391 | ASMBitSet(&pThis->Bitmap, iPort);
|
---|
392 | pThis->cDevices--;
|
---|
393 | pDev->i16Port = -1;
|
---|
394 | LogRel(("VUSB: Failed to attach '%s' to port %d, rc=%Rrc\n", pDev->pUsbIns->pszName, iPort, rc));
|
---|
395 |
|
---|
396 | return rc;
|
---|
397 | }
|
---|
398 |
|
---|
399 |
|
---|
400 | /**
|
---|
401 | * Detaches the given device from the given roothub.
|
---|
402 | *
|
---|
403 | * @returns VBox status code.
|
---|
404 | * @param pThis The roothub to detach the device from.
|
---|
405 | * @param pDev The device to detach.
|
---|
406 | */
|
---|
407 | static int vusbHubDetach(PVUSBROOTHUB pThis, PVUSBDEV pDev)
|
---|
408 | {
|
---|
409 | Assert(pDev->i16Port != -1);
|
---|
410 |
|
---|
411 | /* Cancel all in-flight URBs from this device. */
|
---|
412 | vusbDevCancelAllUrbs(pDev, true);
|
---|
413 |
|
---|
414 | /*
|
---|
415 | * Detach the device and mark the port as available.
|
---|
416 | */
|
---|
417 | unsigned uPort = pDev->i16Port;
|
---|
418 | pDev->i16Port = -1;
|
---|
419 | pThis->pIRhPort->pfnDetach(pThis->pIRhPort, uPort);
|
---|
420 | ASMBitSet(&pThis->Bitmap, uPort);
|
---|
421 | pThis->cDevices--;
|
---|
422 |
|
---|
423 | /* Check that it's attached and remove it. */
|
---|
424 | RTCritSectEnter(&pThis->CritSectDevices);
|
---|
425 | Assert(pThis->apDevByPort[uPort] == pDev);
|
---|
426 | pThis->apDevByPort[uPort] = NULL;
|
---|
427 |
|
---|
428 | if (pDev->u8Address != VUSB_INVALID_ADDRESS)
|
---|
429 | {
|
---|
430 | Assert(pThis->apDevByAddr[pDev->u8Address] == pDev);
|
---|
431 | pThis->apDevByAddr[pDev->u8Address] = NULL;
|
---|
432 | }
|
---|
433 | RTCritSectLeave(&pThis->CritSectDevices);
|
---|
434 |
|
---|
435 | /* Free resources. */
|
---|
436 | vusbDevDetach(pDev);
|
---|
437 | return VINF_SUCCESS;
|
---|
438 | }
|
---|
439 |
|
---|
440 |
|
---|
441 |
|
---|
442 | /* -=-=-=-=-=- PDMUSBHUBREG methods -=-=-=-=-=- */
|
---|
443 |
|
---|
444 | /** @interface_method_impl{PDMUSBHUBREG,pfnAttachDevice} */
|
---|
445 | static DECLCALLBACK(int) vusbPDMHubAttachDevice(PPDMDRVINS pDrvIns, PPDMUSBINS pUsbIns, const char *pszCaptureFilename, uint32_t *piPort)
|
---|
446 | {
|
---|
447 | PVUSBROOTHUB pThis = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
|
---|
448 |
|
---|
449 | /*
|
---|
450 | * Allocate a new VUSB device and initialize it.
|
---|
451 | */
|
---|
452 | PVUSBDEV pDev = (PVUSBDEV)RTMemAllocZ(sizeof(*pDev));
|
---|
453 | AssertReturn(pDev, VERR_NO_MEMORY);
|
---|
454 | int rc = vusbDevInit(pDev, pUsbIns, pszCaptureFilename);
|
---|
455 | if (RT_SUCCESS(rc))
|
---|
456 | {
|
---|
457 | pUsbIns->pvVUsbDev2 = pDev;
|
---|
458 | rc = vusbHubAttach(pThis, pDev);
|
---|
459 | if (RT_SUCCESS(rc))
|
---|
460 | {
|
---|
461 | *piPort = UINT32_MAX; /// @todo implement piPort
|
---|
462 | return rc;
|
---|
463 | }
|
---|
464 |
|
---|
465 | RTMemFree(pDev->paIfStates);
|
---|
466 | pUsbIns->pvVUsbDev2 = NULL;
|
---|
467 | }
|
---|
468 | vusbDevRelease(pDev);
|
---|
469 | return rc;
|
---|
470 | }
|
---|
471 |
|
---|
472 |
|
---|
473 | /** @interface_method_impl{PDMUSBHUBREG,pfnDetachDevice} */
|
---|
474 | static DECLCALLBACK(int) vusbPDMHubDetachDevice(PPDMDRVINS pDrvIns, PPDMUSBINS pUsbIns, uint32_t iPort)
|
---|
475 | {
|
---|
476 | RT_NOREF(iPort);
|
---|
477 | PVUSBROOTHUB pThis = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
|
---|
478 | PVUSBDEV pDev = (PVUSBDEV)pUsbIns->pvVUsbDev2;
|
---|
479 | Assert(pDev);
|
---|
480 |
|
---|
481 | LogRel(("VUSB: Detached '%s' from port %u on %s\n", pDev->pUsbIns->pszName, pDev->i16Port, pThis->pszName));
|
---|
482 |
|
---|
483 | /*
|
---|
484 | * Deal with pending async reset.
|
---|
485 | * (anything but reset)
|
---|
486 | */
|
---|
487 | vusbDevSetStateCmp(pDev, VUSB_DEVICE_STATE_DEFAULT, VUSB_DEVICE_STATE_RESET);
|
---|
488 | vusbHubDetach(pThis, pDev);
|
---|
489 | vusbDevRelease(pDev);
|
---|
490 | return VINF_SUCCESS;
|
---|
491 | }
|
---|
492 |
|
---|
493 | /**
|
---|
494 | * The hub registration structure.
|
---|
495 | */
|
---|
496 | static const PDMUSBHUBREG g_vusbHubReg =
|
---|
497 | {
|
---|
498 | PDM_USBHUBREG_VERSION,
|
---|
499 | vusbPDMHubAttachDevice,
|
---|
500 | vusbPDMHubDetachDevice,
|
---|
501 | PDM_USBHUBREG_VERSION
|
---|
502 | };
|
---|
503 |
|
---|
504 |
|
---|
505 | /* -=-=-=-=-=- VUSBIROOTHUBCONNECTOR methods -=-=-=-=-=- */
|
---|
506 |
|
---|
507 |
|
---|
508 | /**
|
---|
509 | * Callback for freeing an URB.
|
---|
510 | * @param pUrb The URB to free.
|
---|
511 | */
|
---|
512 | static DECLCALLBACK(void) vusbRhFreeUrb(PVUSBURB pUrb)
|
---|
513 | {
|
---|
514 | /*
|
---|
515 | * Assert sanity.
|
---|
516 | */
|
---|
517 | vusbUrbAssert(pUrb);
|
---|
518 | PVUSBROOTHUB pRh = (PVUSBROOTHUB)pUrb->pVUsb->pvFreeCtx;
|
---|
519 | Assert(pRh);
|
---|
520 |
|
---|
521 | Assert(pUrb->enmState != VUSBURBSTATE_FREE);
|
---|
522 |
|
---|
523 | /*
|
---|
524 | * Free the URB description (logging builds only).
|
---|
525 | */
|
---|
526 | if (pUrb->pszDesc)
|
---|
527 | {
|
---|
528 | RTStrFree(pUrb->pszDesc);
|
---|
529 | pUrb->pszDesc = NULL;
|
---|
530 | }
|
---|
531 |
|
---|
532 | /* The URB comes from the roothub if there is no device (invalid address). */
|
---|
533 | if (pUrb->pVUsb->pDev)
|
---|
534 | {
|
---|
535 | PVUSBDEV pDev = pUrb->pVUsb->pDev;
|
---|
536 |
|
---|
537 | vusbUrbPoolFree(&pUrb->pVUsb->pDev->UrbPool, pUrb);
|
---|
538 | vusbDevRelease(pDev);
|
---|
539 | }
|
---|
540 | else
|
---|
541 | vusbUrbPoolFree(&pRh->Dev.UrbPool, pUrb);
|
---|
542 | }
|
---|
543 |
|
---|
544 |
|
---|
545 | /**
|
---|
546 | * Worker routine for vusbRhConnNewUrb().
|
---|
547 | */
|
---|
548 | static PVUSBURB vusbRhNewUrb(PVUSBROOTHUB pRh, uint8_t DstAddress, uint32_t uPort, VUSBXFERTYPE enmType,
|
---|
549 | VUSBDIRECTION enmDir, uint32_t cbData, uint32_t cTds, const char *pszTag)
|
---|
550 | {
|
---|
551 | RT_NOREF(pszTag);
|
---|
552 | PVUSBURBPOOL pUrbPool = &pRh->Dev.UrbPool;
|
---|
553 |
|
---|
554 | if (RT_UNLIKELY(cbData > (32 * _1M)))
|
---|
555 | {
|
---|
556 | LogFunc(("Bad URB size (%u)!\n", cbData));
|
---|
557 | return NULL;
|
---|
558 | }
|
---|
559 |
|
---|
560 | PVUSBDEV pDev;
|
---|
561 | if (uPort == VUSB_DEVICE_PORT_INVALID)
|
---|
562 | pDev = vusbR3RhGetVUsbDevByAddrRetain(pRh, DstAddress);
|
---|
563 | else
|
---|
564 | pDev = vusbR3RhGetVUsbDevByPortRetain(pRh, uPort);
|
---|
565 |
|
---|
566 | if (pDev)
|
---|
567 | pUrbPool = &pDev->UrbPool;
|
---|
568 |
|
---|
569 | PVUSBURB pUrb = vusbUrbPoolAlloc(pUrbPool, enmType, enmDir, cbData,
|
---|
570 | pRh->cbHci, pRh->cbHciTd, cTds);
|
---|
571 | if (RT_LIKELY(pUrb))
|
---|
572 | {
|
---|
573 | pUrb->pVUsb->pvFreeCtx = pRh;
|
---|
574 | pUrb->pVUsb->pfnFree = vusbRhFreeUrb;
|
---|
575 | pUrb->DstAddress = DstAddress;
|
---|
576 | pUrb->pVUsb->pDev = pDev;
|
---|
577 |
|
---|
578 | #ifdef LOG_ENABLED
|
---|
579 | const char *pszType = NULL;
|
---|
580 |
|
---|
581 | switch(pUrb->enmType)
|
---|
582 | {
|
---|
583 | case VUSBXFERTYPE_CTRL:
|
---|
584 | pszType = "ctrl";
|
---|
585 | break;
|
---|
586 | case VUSBXFERTYPE_INTR:
|
---|
587 | pszType = "intr";
|
---|
588 | break;
|
---|
589 | case VUSBXFERTYPE_BULK:
|
---|
590 | pszType = "bulk";
|
---|
591 | break;
|
---|
592 | case VUSBXFERTYPE_ISOC:
|
---|
593 | pszType = "isoc";
|
---|
594 | break;
|
---|
595 | default:
|
---|
596 | pszType = "invld";
|
---|
597 | break;
|
---|
598 | }
|
---|
599 |
|
---|
600 | pRh->iSerial = (pRh->iSerial + 1) % 10000;
|
---|
601 | RTStrAPrintf(&pUrb->pszDesc, "URB %p %s%c%04d (%s)", pUrb, pszType,
|
---|
602 | (pUrb->enmDir == VUSBDIRECTION_IN) ? '<' : ((pUrb->enmDir == VUSBDIRECTION_SETUP) ? 's' : '>'),
|
---|
603 | pRh->iSerial, pszTag ? pszTag : "<none>");
|
---|
604 | #endif
|
---|
605 | }
|
---|
606 |
|
---|
607 | return pUrb;
|
---|
608 | }
|
---|
609 |
|
---|
610 |
|
---|
611 | /**
|
---|
612 | * Calculate frame timer variables given a frame rate.
|
---|
613 | */
|
---|
614 | static void vusbRhR3CalcTimerIntervals(PVUSBROOTHUB pThis, uint32_t u32FrameRate)
|
---|
615 | {
|
---|
616 | pThis->nsWait = RT_NS_1SEC / u32FrameRate;
|
---|
617 | pThis->uFrameRate = u32FrameRate;
|
---|
618 | /* Inform the HCD about the new frame rate. */
|
---|
619 | pThis->pIRhPort->pfnFrameRateChanged(pThis->pIRhPort, u32FrameRate);
|
---|
620 | }
|
---|
621 |
|
---|
622 |
|
---|
623 | /**
|
---|
624 | * Calculates the new frame rate based on the idle detection and number of idle
|
---|
625 | * cycles.
|
---|
626 | *
|
---|
627 | * @returns nothing.
|
---|
628 | * @param pThis The roothub instance data.
|
---|
629 | * @param fIdle Flag whether the last frame didn't produce any activity.
|
---|
630 | */
|
---|
631 | static void vusbRhR3FrameRateCalcNew(PVUSBROOTHUB pThis, bool fIdle)
|
---|
632 | {
|
---|
633 | uint32_t uNewFrameRate = pThis->uFrameRate;
|
---|
634 |
|
---|
635 | /*
|
---|
636 | * Adjust the frame timer interval based on idle detection.
|
---|
637 | */
|
---|
638 | if (fIdle)
|
---|
639 | {
|
---|
640 | pThis->cIdleCycles++;
|
---|
641 | /* Set the new frame rate based on how long we've been idle. Tunable. */
|
---|
642 | switch (pThis->cIdleCycles)
|
---|
643 | {
|
---|
644 | case 4: uNewFrameRate = 500; break; /* 2ms interval */
|
---|
645 | case 16:uNewFrameRate = 125; break; /* 8ms interval */
|
---|
646 | case 24:uNewFrameRate = 50; break; /* 20ms interval */
|
---|
647 | default: break;
|
---|
648 | }
|
---|
649 | /* Avoid overflow. */
|
---|
650 | if (pThis->cIdleCycles > 60000)
|
---|
651 | pThis->cIdleCycles = 20000;
|
---|
652 | }
|
---|
653 | else
|
---|
654 | {
|
---|
655 | if (pThis->cIdleCycles)
|
---|
656 | {
|
---|
657 | pThis->cIdleCycles = 0;
|
---|
658 | uNewFrameRate = pThis->uFrameRateDefault;
|
---|
659 | }
|
---|
660 | }
|
---|
661 |
|
---|
662 | if ( uNewFrameRate != pThis->uFrameRate
|
---|
663 | && uNewFrameRate)
|
---|
664 | {
|
---|
665 | LogFlow(("Frame rate changed from %u to %u\n", pThis->uFrameRate, uNewFrameRate));
|
---|
666 | vusbRhR3CalcTimerIntervals(pThis, uNewFrameRate);
|
---|
667 | }
|
---|
668 | }
|
---|
669 |
|
---|
670 |
|
---|
671 | /**
|
---|
672 | * The core frame processing routine keeping track of the elapsed time and calling into
|
---|
673 | * the device emulation above us to do the work.
|
---|
674 | *
|
---|
675 | * @returns Relative timespan when to process the next frame.
|
---|
676 | * @param pThis The roothub instance data.
|
---|
677 | * @param fCallback Flag whether this method is called from the URB completion callback or
|
---|
678 | * from the worker thread (only used for statistics).
|
---|
679 | */
|
---|
680 | DECLHIDDEN(uint64_t) vusbRhR3ProcessFrame(PVUSBROOTHUB pThis, bool fCallback)
|
---|
681 | {
|
---|
682 | uint64_t tsNext = 0;
|
---|
683 | uint64_t tsNanoStart = RTTimeNanoTS();
|
---|
684 |
|
---|
685 | /* Don't do anything if we are not supposed to process anything (EHCI and XHCI). */
|
---|
686 | if (!pThis->uFrameRateDefault)
|
---|
687 | return 0;
|
---|
688 |
|
---|
689 | if (ASMAtomicXchgBool(&pThis->fFrameProcessing, true))
|
---|
690 | return pThis->nsWait;
|
---|
691 |
|
---|
692 | if ( tsNanoStart > pThis->tsFrameProcessed
|
---|
693 | && tsNanoStart - pThis->tsFrameProcessed >= 750 * RT_NS_1US)
|
---|
694 | {
|
---|
695 | LogFlowFunc(("Starting new frame at ts %llu\n", tsNanoStart));
|
---|
696 |
|
---|
697 | bool fIdle = pThis->pIRhPort->pfnStartFrame(pThis->pIRhPort, 0 /* u32FrameNo */);
|
---|
698 | vusbRhR3FrameRateCalcNew(pThis, fIdle);
|
---|
699 |
|
---|
700 | uint64_t tsNow = RTTimeNanoTS();
|
---|
701 | tsNext = (tsNanoStart + pThis->nsWait) > tsNow ? (tsNanoStart + pThis->nsWait) - tsNow : 0;
|
---|
702 | pThis->tsFrameProcessed = tsNanoStart;
|
---|
703 | LogFlowFunc(("Current frame took %llu nano seconds to process, next frame in %llu ns\n", tsNow - tsNanoStart, tsNext));
|
---|
704 | if (fCallback)
|
---|
705 | STAM_COUNTER_INC(&pThis->StatFramesProcessedClbk);
|
---|
706 | else
|
---|
707 | STAM_COUNTER_INC(&pThis->StatFramesProcessedThread);
|
---|
708 | }
|
---|
709 | else
|
---|
710 | {
|
---|
711 | tsNext = (pThis->tsFrameProcessed + pThis->nsWait) > tsNanoStart ? (pThis->tsFrameProcessed + pThis->nsWait) - tsNanoStart : 0;
|
---|
712 | LogFlowFunc(("Next frame is too far away in the future, waiting... (tsNanoStart=%llu tsFrameProcessed=%llu)\n",
|
---|
713 | tsNanoStart, pThis->tsFrameProcessed));
|
---|
714 | }
|
---|
715 |
|
---|
716 | ASMAtomicXchgBool(&pThis->fFrameProcessing, false);
|
---|
717 | LogFlowFunc(("returns %llu\n", tsNext));
|
---|
718 | return tsNext;
|
---|
719 | }
|
---|
720 |
|
---|
721 |
|
---|
722 | /**
|
---|
723 | * Worker for processing frames periodically.
|
---|
724 | *
|
---|
725 | * @returns VBox status code.
|
---|
726 | * @param pDrvIns The driver instance.
|
---|
727 | * @param pThread The PDM thread structure for the thread this worker runs on.
|
---|
728 | */
|
---|
729 | static DECLCALLBACK(int) vusbRhR3PeriodFrameWorker(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
|
---|
730 | {
|
---|
731 | RT_NOREF(pDrvIns);
|
---|
732 | int rc = VINF_SUCCESS;
|
---|
733 | PVUSBROOTHUB pThis = (PVUSBROOTHUB)pThread->pvUser;
|
---|
734 |
|
---|
735 | if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
|
---|
736 | return VINF_SUCCESS;
|
---|
737 |
|
---|
738 | while (pThread->enmState == PDMTHREADSTATE_RUNNING)
|
---|
739 | {
|
---|
740 | while ( !ASMAtomicReadU32(&pThis->uFrameRateDefault)
|
---|
741 | && pThread->enmState == PDMTHREADSTATE_RUNNING)
|
---|
742 | {
|
---|
743 | /* Signal the waiter that we are stopped now. */
|
---|
744 | rc = RTSemEventMultiSignal(pThis->hSemEventPeriodFrameStopped);
|
---|
745 | AssertRC(rc);
|
---|
746 |
|
---|
747 | rc = RTSemEventMultiWait(pThis->hSemEventPeriodFrame, RT_INDEFINITE_WAIT);
|
---|
748 | RTSemEventMultiReset(pThis->hSemEventPeriodFrame);
|
---|
749 |
|
---|
750 | /*
|
---|
751 | * Notify the device above about the frame rate changed if we are supposed to
|
---|
752 | * process frames.
|
---|
753 | */
|
---|
754 | uint32_t uFrameRate = ASMAtomicReadU32(&pThis->uFrameRateDefault);
|
---|
755 | if (uFrameRate)
|
---|
756 | vusbRhR3CalcTimerIntervals(pThis, uFrameRate);
|
---|
757 | }
|
---|
758 |
|
---|
759 | AssertLogRelMsgReturn(RT_SUCCESS(rc) || rc == VERR_TIMEOUT, ("%Rrc\n", rc), rc);
|
---|
760 | if (RT_UNLIKELY(pThread->enmState != PDMTHREADSTATE_RUNNING))
|
---|
761 | break;
|
---|
762 |
|
---|
763 | uint64_t tsNext = vusbRhR3ProcessFrame(pThis, false /* fCallback */);
|
---|
764 |
|
---|
765 | if (tsNext >= 250 * RT_NS_1US)
|
---|
766 | {
|
---|
767 | rc = RTSemEventMultiWaitEx(pThis->hSemEventPeriodFrame, RTSEMWAIT_FLAGS_RELATIVE | RTSEMWAIT_FLAGS_NANOSECS | RTSEMWAIT_FLAGS_UNINTERRUPTIBLE,
|
---|
768 | tsNext);
|
---|
769 | AssertLogRelMsg(RT_SUCCESS(rc) || rc == VERR_TIMEOUT, ("%Rrc\n", rc));
|
---|
770 | RTSemEventMultiReset(pThis->hSemEventPeriodFrame);
|
---|
771 | }
|
---|
772 | }
|
---|
773 |
|
---|
774 | return VINF_SUCCESS;
|
---|
775 | }
|
---|
776 |
|
---|
777 |
|
---|
778 | /**
|
---|
779 | * Unblock the periodic frame thread so it can respond to a state change.
|
---|
780 | *
|
---|
781 | * @returns VBox status code.
|
---|
782 | * @param pDrvIns The driver instance.
|
---|
783 | * @param pThread The send thread.
|
---|
784 | */
|
---|
785 | static DECLCALLBACK(int) vusbRhR3PeriodFrameWorkerWakeup(PPDMDRVINS pDrvIns, PPDMTHREAD pThread)
|
---|
786 | {
|
---|
787 | RT_NOREF(pThread);
|
---|
788 | PVUSBROOTHUB pThis = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
|
---|
789 | return RTSemEventMultiSignal(pThis->hSemEventPeriodFrame);
|
---|
790 | }
|
---|
791 |
|
---|
792 |
|
---|
793 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnSetUrbParams} */
|
---|
794 | static DECLCALLBACK(int) vusbRhSetUrbParams(PVUSBIROOTHUBCONNECTOR pInterface, size_t cbHci, size_t cbHciTd)
|
---|
795 | {
|
---|
796 | PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
797 |
|
---|
798 | pRh->cbHci = cbHci;
|
---|
799 | pRh->cbHciTd = cbHciTd;
|
---|
800 |
|
---|
801 | return VINF_SUCCESS;
|
---|
802 | }
|
---|
803 |
|
---|
804 |
|
---|
805 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnReset} */
|
---|
806 | static DECLCALLBACK(int) vusbR3RhReset(PVUSBIROOTHUBCONNECTOR pInterface, bool fResetOnLinux)
|
---|
807 | {
|
---|
808 | PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
809 | return pRh->pIRhPort->pfnReset(pRh->pIRhPort, fResetOnLinux);
|
---|
810 | }
|
---|
811 |
|
---|
812 |
|
---|
813 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnPowerOn} */
|
---|
814 | static DECLCALLBACK(int) vusbR3RhPowerOn(PVUSBIROOTHUBCONNECTOR pInterface)
|
---|
815 | {
|
---|
816 | PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
817 | LogFlow(("vusR3bRhPowerOn: pRh=%p\n", pRh));
|
---|
818 |
|
---|
819 | Assert( pRh->Dev.enmState != VUSB_DEVICE_STATE_DETACHED
|
---|
820 | && pRh->Dev.enmState != VUSB_DEVICE_STATE_RESET);
|
---|
821 |
|
---|
822 | if (pRh->Dev.enmState == VUSB_DEVICE_STATE_ATTACHED)
|
---|
823 | pRh->Dev.enmState = VUSB_DEVICE_STATE_POWERED;
|
---|
824 |
|
---|
825 | return VINF_SUCCESS;
|
---|
826 | }
|
---|
827 |
|
---|
828 |
|
---|
829 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnPowerOff} */
|
---|
830 | static DECLCALLBACK(int) vusbR3RhPowerOff(PVUSBIROOTHUBCONNECTOR pInterface)
|
---|
831 | {
|
---|
832 | PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
833 | LogFlow(("vusbR3RhDevPowerOff: pThis=%p\n", pThis));
|
---|
834 |
|
---|
835 | Assert( pThis->Dev.enmState != VUSB_DEVICE_STATE_DETACHED
|
---|
836 | && pThis->Dev.enmState != VUSB_DEVICE_STATE_RESET);
|
---|
837 |
|
---|
838 | /*
|
---|
839 | * Cancel all URBs and reap them.
|
---|
840 | */
|
---|
841 | VUSBIRhCancelAllUrbs(&pThis->IRhConnector);
|
---|
842 | for (uint32_t uPort = 0; uPort < RT_ELEMENTS(pThis->apDevByPort); uPort++)
|
---|
843 | VUSBIRhReapAsyncUrbs(&pThis->IRhConnector, uPort, 0);
|
---|
844 |
|
---|
845 | pThis->Dev.enmState = VUSB_DEVICE_STATE_ATTACHED;
|
---|
846 | return VINF_SUCCESS;
|
---|
847 | }
|
---|
848 |
|
---|
849 |
|
---|
850 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnNewUrb} */
|
---|
851 | static DECLCALLBACK(PVUSBURB) vusbRhConnNewUrb(PVUSBIROOTHUBCONNECTOR pInterface, uint8_t DstAddress, uint32_t uPort, VUSBXFERTYPE enmType,
|
---|
852 | VUSBDIRECTION enmDir, uint32_t cbData, uint32_t cTds, const char *pszTag)
|
---|
853 | {
|
---|
854 | PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
855 | return vusbRhNewUrb(pRh, DstAddress, uPort, enmType, enmDir, cbData, cTds, pszTag);
|
---|
856 | }
|
---|
857 |
|
---|
858 |
|
---|
859 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnFreeUrb} */
|
---|
860 | static DECLCALLBACK(int) vusbRhConnFreeUrb(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb)
|
---|
861 | {
|
---|
862 | RT_NOREF(pInterface);
|
---|
863 | pUrb->pVUsb->pfnFree(pUrb);
|
---|
864 | return VINF_SUCCESS;
|
---|
865 | }
|
---|
866 |
|
---|
867 |
|
---|
868 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnSubmitUrb} */
|
---|
869 | static DECLCALLBACK(int) vusbRhSubmitUrb(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb, PPDMLED pLed)
|
---|
870 | {
|
---|
871 | PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
872 | STAM_PROFILE_START(&pRh->StatSubmitUrb, a);
|
---|
873 |
|
---|
874 | #ifdef VBOX_WITH_STATISTICS
|
---|
875 | /*
|
---|
876 | * Total and per-type submit statistics.
|
---|
877 | */
|
---|
878 | Assert(pUrb->enmType >= 0 && pUrb->enmType < (int)RT_ELEMENTS(pRh->aTypes));
|
---|
879 | STAM_COUNTER_INC(&pRh->Total.StatUrbsSubmitted);
|
---|
880 | STAM_COUNTER_INC(&pRh->aTypes[pUrb->enmType].StatUrbsSubmitted);
|
---|
881 |
|
---|
882 | STAM_COUNTER_ADD(&pRh->Total.StatReqBytes, pUrb->cbData);
|
---|
883 | STAM_COUNTER_ADD(&pRh->aTypes[pUrb->enmType].StatReqBytes, pUrb->cbData);
|
---|
884 | if (pUrb->enmDir == VUSBDIRECTION_IN)
|
---|
885 | {
|
---|
886 | STAM_COUNTER_ADD(&pRh->Total.StatReqReadBytes, pUrb->cbData);
|
---|
887 | STAM_COUNTER_ADD(&pRh->aTypes[pUrb->enmType].StatReqReadBytes, pUrb->cbData);
|
---|
888 | }
|
---|
889 | else
|
---|
890 | {
|
---|
891 | STAM_COUNTER_ADD(&pRh->Total.StatReqWriteBytes, pUrb->cbData);
|
---|
892 | STAM_COUNTER_ADD(&pRh->aTypes[pUrb->enmType].StatReqWriteBytes, pUrb->cbData);
|
---|
893 | }
|
---|
894 |
|
---|
895 | if (pUrb->enmType == VUSBXFERTYPE_ISOC)
|
---|
896 | {
|
---|
897 | STAM_COUNTER_ADD(&pRh->StatIsocReqPkts, pUrb->cIsocPkts);
|
---|
898 | if (pUrb->enmDir == VUSBDIRECTION_IN)
|
---|
899 | STAM_COUNTER_ADD(&pRh->StatIsocReqReadPkts, pUrb->cIsocPkts);
|
---|
900 | else
|
---|
901 | STAM_COUNTER_ADD(&pRh->StatIsocReqWritePkts, pUrb->cIsocPkts);
|
---|
902 | }
|
---|
903 | #endif
|
---|
904 |
|
---|
905 | /* If there is a sniffer on the roothub record the URB there. */
|
---|
906 | if (pRh->hSniffer != VUSBSNIFFER_NIL)
|
---|
907 | {
|
---|
908 | int rc = VUSBSnifferRecordEvent(pRh->hSniffer, pUrb, VUSBSNIFFEREVENT_SUBMIT);
|
---|
909 | if (RT_FAILURE(rc))
|
---|
910 | LogRel(("VUSB: Capturing URB submit event on the root hub failed with %Rrc\n", rc));
|
---|
911 | }
|
---|
912 |
|
---|
913 | /*
|
---|
914 | * The device was resolved when we allocated the URB.
|
---|
915 | * Submit it to the device if we found it, if not fail with device-not-ready.
|
---|
916 | */
|
---|
917 | int rc;
|
---|
918 | if ( pUrb->pVUsb->pDev
|
---|
919 | && pUrb->pVUsb->pDev->pUsbIns)
|
---|
920 | {
|
---|
921 | switch (pUrb->enmDir)
|
---|
922 | {
|
---|
923 | case VUSBDIRECTION_IN:
|
---|
924 | pLed->Asserted.s.fReading = pLed->Actual.s.fReading = 1;
|
---|
925 | rc = vusbUrbSubmit(pUrb);
|
---|
926 | pLed->Actual.s.fReading = 0;
|
---|
927 | break;
|
---|
928 | case VUSBDIRECTION_OUT:
|
---|
929 | pLed->Asserted.s.fWriting = pLed->Actual.s.fWriting = 1;
|
---|
930 | rc = vusbUrbSubmit(pUrb);
|
---|
931 | pLed->Actual.s.fWriting = 0;
|
---|
932 | break;
|
---|
933 | default:
|
---|
934 | rc = vusbUrbSubmit(pUrb);
|
---|
935 | break;
|
---|
936 | }
|
---|
937 |
|
---|
938 | if (RT_FAILURE(rc))
|
---|
939 | {
|
---|
940 | LogFlow(("vusbRhSubmitUrb: freeing pUrb=%p\n", pUrb));
|
---|
941 | pUrb->pVUsb->pfnFree(pUrb);
|
---|
942 | }
|
---|
943 | }
|
---|
944 | else
|
---|
945 | {
|
---|
946 | vusbDevRetain(&pRh->Dev);
|
---|
947 | pUrb->pVUsb->pDev = &pRh->Dev;
|
---|
948 | Log(("vusb: pRh=%p: SUBMIT: Address %i not found!!!\n", pRh, pUrb->DstAddress));
|
---|
949 |
|
---|
950 | pUrb->enmState = VUSBURBSTATE_REAPED;
|
---|
951 | pUrb->enmStatus = VUSBSTATUS_DNR;
|
---|
952 | vusbUrbCompletionRh(pUrb);
|
---|
953 | rc = VINF_SUCCESS;
|
---|
954 | }
|
---|
955 |
|
---|
956 | STAM_PROFILE_STOP(&pRh->StatSubmitUrb, a);
|
---|
957 | return rc;
|
---|
958 | }
|
---|
959 |
|
---|
960 |
|
---|
961 | static DECLCALLBACK(int) vusbRhReapAsyncUrbsWorker(PVUSBDEV pDev, RTMSINTERVAL cMillies)
|
---|
962 | {
|
---|
963 | if (!cMillies)
|
---|
964 | vusbUrbDoReapAsync(&pDev->LstAsyncUrbs, 0);
|
---|
965 | else
|
---|
966 | {
|
---|
967 | uint64_t u64Start = RTTimeMilliTS();
|
---|
968 | do
|
---|
969 | {
|
---|
970 | vusbUrbDoReapAsync(&pDev->LstAsyncUrbs, RT_MIN(cMillies >> 8, 10));
|
---|
971 | } while ( !RTListIsEmpty(&pDev->LstAsyncUrbs)
|
---|
972 | && RTTimeMilliTS() - u64Start < cMillies);
|
---|
973 | }
|
---|
974 |
|
---|
975 | return VINF_SUCCESS;
|
---|
976 | }
|
---|
977 |
|
---|
978 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnReapAsyncUrbs} */
|
---|
979 | static DECLCALLBACK(void) vusbRhReapAsyncUrbs(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort, RTMSINTERVAL cMillies)
|
---|
980 | {
|
---|
981 | PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface); NOREF(pRh);
|
---|
982 | PVUSBDEV pDev = vusbR3RhGetVUsbDevByPortRetain(pRh, uPort);
|
---|
983 |
|
---|
984 | if ( !pDev
|
---|
985 | || RTListIsEmpty(&pDev->LstAsyncUrbs))
|
---|
986 | return;
|
---|
987 |
|
---|
988 | STAM_PROFILE_START(&pRh->StatReapAsyncUrbs, a);
|
---|
989 | int rc = vusbDevIoThreadExecSync(pDev, (PFNRT)vusbRhReapAsyncUrbsWorker, 2, pDev, cMillies);
|
---|
990 | AssertRC(rc);
|
---|
991 | STAM_PROFILE_STOP(&pRh->StatReapAsyncUrbs, a);
|
---|
992 |
|
---|
993 | vusbDevRelease(pDev);
|
---|
994 | }
|
---|
995 |
|
---|
996 |
|
---|
997 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnCancelUrbsEp} */
|
---|
998 | static DECLCALLBACK(int) vusbRhCancelUrbsEp(PVUSBIROOTHUBCONNECTOR pInterface, PVUSBURB pUrb)
|
---|
999 | {
|
---|
1000 | PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
1001 | AssertReturn(pRh, VERR_INVALID_PARAMETER);
|
---|
1002 | AssertReturn(pUrb, VERR_INVALID_PARAMETER);
|
---|
1003 |
|
---|
1004 | /// @todo This method of URB canceling may not work on non-Linux hosts.
|
---|
1005 | /*
|
---|
1006 | * Cancel and reap the URB(s) on an endpoint.
|
---|
1007 | */
|
---|
1008 | LogFlow(("vusbRhCancelUrbsEp: pRh=%p pUrb=%p\n", pRh, pUrb));
|
---|
1009 |
|
---|
1010 | vusbUrbCancelAsync(pUrb, CANCELMODE_UNDO);
|
---|
1011 |
|
---|
1012 | /* The reaper thread will take care of completing the URB. */
|
---|
1013 |
|
---|
1014 | return VINF_SUCCESS;
|
---|
1015 | }
|
---|
1016 |
|
---|
1017 | /**
|
---|
1018 | * Worker doing the actual cancelling of all outstanding URBs on the device I/O thread.
|
---|
1019 | *
|
---|
1020 | * @returns VBox status code.
|
---|
1021 | * @param pDev USB device instance data.
|
---|
1022 | */
|
---|
1023 | static DECLCALLBACK(int) vusbRhCancelAllUrbsWorker(PVUSBDEV pDev)
|
---|
1024 | {
|
---|
1025 | /*
|
---|
1026 | * Cancel the URBS.
|
---|
1027 | *
|
---|
1028 | * Not using th CritAsyncUrbs critical section here is safe
|
---|
1029 | * as the I/O thread is the only thread accessing this struture at the
|
---|
1030 | * moment.
|
---|
1031 | */
|
---|
1032 | PVUSBURBVUSB pVUsbUrb, pVUsbUrbNext;
|
---|
1033 | RTListForEachSafe(&pDev->LstAsyncUrbs, pVUsbUrb, pVUsbUrbNext, VUSBURBVUSBINT, NdLst)
|
---|
1034 | {
|
---|
1035 | PVUSBURB pUrb = pVUsbUrb->pUrb;
|
---|
1036 | /* Call the worker directly. */
|
---|
1037 | vusbUrbCancelWorker(pUrb, CANCELMODE_FAIL);
|
---|
1038 | }
|
---|
1039 |
|
---|
1040 | return VINF_SUCCESS;
|
---|
1041 | }
|
---|
1042 |
|
---|
1043 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnCancelAllUrbs} */
|
---|
1044 | static DECLCALLBACK(void) vusbRhCancelAllUrbs(PVUSBIROOTHUBCONNECTOR pInterface)
|
---|
1045 | {
|
---|
1046 | PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
1047 |
|
---|
1048 | RTCritSectEnter(&pThis->CritSectDevices);
|
---|
1049 | for (unsigned i = 0; i < RT_ELEMENTS(pThis->apDevByPort); i++)
|
---|
1050 | {
|
---|
1051 | PVUSBDEV pDev = pThis->apDevByPort[i];
|
---|
1052 | if (pDev)
|
---|
1053 | vusbDevIoThreadExecSync(pDev, (PFNRT)vusbRhCancelAllUrbsWorker, 1, pDev);
|
---|
1054 | }
|
---|
1055 | RTCritSectLeave(&pThis->CritSectDevices);
|
---|
1056 | }
|
---|
1057 |
|
---|
1058 | /**
|
---|
1059 | * Worker doing the actual cancelling of all outstanding per-EP URBs on the
|
---|
1060 | * device I/O thread.
|
---|
1061 | *
|
---|
1062 | * @returns VBox status code.
|
---|
1063 | * @param pDev USB device instance data.
|
---|
1064 | * @param EndPt Endpoint number.
|
---|
1065 | * @param enmDir Endpoint direction.
|
---|
1066 | */
|
---|
1067 | static DECLCALLBACK(int) vusbRhAbortEpWorker(PVUSBDEV pDev, int EndPt, VUSBDIRECTION enmDir)
|
---|
1068 | {
|
---|
1069 | /*
|
---|
1070 | * Iterate the URBs, find ones corresponding to given EP, and cancel them.
|
---|
1071 | */
|
---|
1072 | PVUSBURBVUSB pVUsbUrb, pVUsbUrbNext;
|
---|
1073 | RTListForEachSafe(&pDev->LstAsyncUrbs, pVUsbUrb, pVUsbUrbNext, VUSBURBVUSBINT, NdLst)
|
---|
1074 | {
|
---|
1075 | PVUSBURB pUrb = pVUsbUrb->pUrb;
|
---|
1076 |
|
---|
1077 | Assert(pUrb->pVUsb->pDev == pDev);
|
---|
1078 |
|
---|
1079 | /* For the default control EP, direction does not matter. */
|
---|
1080 | if (pUrb->EndPt == EndPt && (pUrb->enmDir == enmDir || !EndPt))
|
---|
1081 | {
|
---|
1082 | LogFlow(("%s: vusbRhAbortEpWorker: CANCELING URB\n", pUrb->pszDesc));
|
---|
1083 | int rc = vusbUrbCancelWorker(pUrb, CANCELMODE_UNDO);
|
---|
1084 | AssertRC(rc);
|
---|
1085 | }
|
---|
1086 | }
|
---|
1087 |
|
---|
1088 | return VINF_SUCCESS;
|
---|
1089 | }
|
---|
1090 |
|
---|
1091 |
|
---|
1092 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnAbortEp} */
|
---|
1093 | static DECLCALLBACK(int) vusbRhAbortEp(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort, int EndPt, VUSBDIRECTION enmDir)
|
---|
1094 | {
|
---|
1095 | PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
1096 | PVUSBDEV pDev = vusbR3RhGetVUsbDevByPortRetain(pRh, uPort);
|
---|
1097 |
|
---|
1098 | if (pDev->pHub != pRh)
|
---|
1099 | AssertFailedReturn(VERR_INVALID_PARAMETER);
|
---|
1100 |
|
---|
1101 | vusbDevIoThreadExecSync(pDev, (PFNRT)vusbRhAbortEpWorker, 3, pDev, EndPt, enmDir);
|
---|
1102 | vusbDevRelease(pDev);
|
---|
1103 |
|
---|
1104 | /* The reaper thread will take care of completing the URB. */
|
---|
1105 |
|
---|
1106 | return VINF_SUCCESS;
|
---|
1107 | }
|
---|
1108 |
|
---|
1109 |
|
---|
1110 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnSetPeriodicFrameProcessing} */
|
---|
1111 | static DECLCALLBACK(int) vusbRhSetFrameProcessing(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uFrameRate)
|
---|
1112 | {
|
---|
1113 | int rc = VINF_SUCCESS;
|
---|
1114 | PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
1115 |
|
---|
1116 | /* Create the frame thread lazily. */
|
---|
1117 | if ( !pThis->hThreadPeriodFrame
|
---|
1118 | && uFrameRate)
|
---|
1119 | {
|
---|
1120 | ASMAtomicXchgU32(&pThis->uFrameRateDefault, uFrameRate);
|
---|
1121 | pThis->uFrameRate = uFrameRate;
|
---|
1122 | vusbRhR3CalcTimerIntervals(pThis, uFrameRate);
|
---|
1123 |
|
---|
1124 | rc = RTSemEventMultiCreate(&pThis->hSemEventPeriodFrame);
|
---|
1125 | AssertRCReturn(rc, rc);
|
---|
1126 |
|
---|
1127 | rc = RTSemEventMultiCreate(&pThis->hSemEventPeriodFrameStopped);
|
---|
1128 | AssertRCReturn(rc, rc);
|
---|
1129 |
|
---|
1130 | rc = PDMDrvHlpThreadCreate(pThis->pDrvIns, &pThis->hThreadPeriodFrame, pThis, vusbRhR3PeriodFrameWorker,
|
---|
1131 | vusbRhR3PeriodFrameWorkerWakeup, 0, RTTHREADTYPE_IO, "VUsbPeriodFrm");
|
---|
1132 | AssertRCReturn(rc, rc);
|
---|
1133 |
|
---|
1134 | VMSTATE enmState = PDMDrvHlpVMState(pThis->pDrvIns);
|
---|
1135 | if ( enmState == VMSTATE_RUNNING
|
---|
1136 | || enmState == VMSTATE_RUNNING_LS)
|
---|
1137 | {
|
---|
1138 | rc = PDMDrvHlpThreadResume(pThis->pDrvIns, pThis->hThreadPeriodFrame);
|
---|
1139 | AssertRCReturn(rc, rc);
|
---|
1140 | }
|
---|
1141 | }
|
---|
1142 | else if ( pThis->hThreadPeriodFrame
|
---|
1143 | && !uFrameRate)
|
---|
1144 | {
|
---|
1145 | /* Stop processing. */
|
---|
1146 | uint32_t uFrameRateOld = ASMAtomicXchgU32(&pThis->uFrameRateDefault, uFrameRate);
|
---|
1147 | if (uFrameRateOld)
|
---|
1148 | {
|
---|
1149 | rc = RTSemEventMultiReset(pThis->hSemEventPeriodFrameStopped);
|
---|
1150 | AssertRC(rc);
|
---|
1151 |
|
---|
1152 | /* Signal the frame thread to stop. */
|
---|
1153 | RTSemEventMultiSignal(pThis->hSemEventPeriodFrame);
|
---|
1154 |
|
---|
1155 | /* Wait for signal from the thread that it stopped. */
|
---|
1156 | rc = RTSemEventMultiWait(pThis->hSemEventPeriodFrameStopped, RT_INDEFINITE_WAIT);
|
---|
1157 | AssertRC(rc);
|
---|
1158 | }
|
---|
1159 | }
|
---|
1160 | else if ( pThis->hThreadPeriodFrame
|
---|
1161 | && uFrameRate)
|
---|
1162 | {
|
---|
1163 | /* Just switch to the new frame rate and let the periodic frame thread pick it up. */
|
---|
1164 | uint32_t uFrameRateOld = ASMAtomicXchgU32(&pThis->uFrameRateDefault, uFrameRate);
|
---|
1165 |
|
---|
1166 | /* Signal the frame thread to continue if it was stopped. */
|
---|
1167 | if (!uFrameRateOld)
|
---|
1168 | RTSemEventMultiSignal(pThis->hSemEventPeriodFrame);
|
---|
1169 | }
|
---|
1170 |
|
---|
1171 | return rc;
|
---|
1172 | }
|
---|
1173 |
|
---|
1174 |
|
---|
1175 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnGetPeriodicFrameRate} */
|
---|
1176 | static DECLCALLBACK(uint32_t) vusbRhGetPeriodicFrameRate(PVUSBIROOTHUBCONNECTOR pInterface)
|
---|
1177 | {
|
---|
1178 | PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
1179 |
|
---|
1180 | return pThis->uFrameRate;
|
---|
1181 | }
|
---|
1182 |
|
---|
1183 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnUpdateIsocFrameDelta} */
|
---|
1184 | static DECLCALLBACK(uint32_t) vusbRhUpdateIsocFrameDelta(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort,
|
---|
1185 | int EndPt, VUSBDIRECTION enmDir, uint16_t uNewFrameID, uint8_t uBits)
|
---|
1186 | {
|
---|
1187 | PVUSBROOTHUB pRh = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
1188 | AssertReturn(pRh, 0);
|
---|
1189 | PVUSBDEV pDev = vusbR3RhGetVUsbDevByPortRetain(pRh, uPort); AssertPtr(pDev);
|
---|
1190 | PVUSBPIPE pPipe = &pDev->aPipes[EndPt];
|
---|
1191 | uint32_t *puLastFrame;
|
---|
1192 | int32_t uFrameDelta;
|
---|
1193 | uint32_t uMaxVal = 1 << uBits;
|
---|
1194 |
|
---|
1195 | puLastFrame = enmDir == VUSBDIRECTION_IN ? &pPipe->uLastFrameIn : &pPipe->uLastFrameOut;
|
---|
1196 | uFrameDelta = uNewFrameID - *puLastFrame;
|
---|
1197 | *puLastFrame = uNewFrameID;
|
---|
1198 | /* Take care of wrap-around. */
|
---|
1199 | if (uFrameDelta < 0)
|
---|
1200 | uFrameDelta += uMaxVal;
|
---|
1201 |
|
---|
1202 | vusbDevRelease(pDev);
|
---|
1203 | return (uint16_t)uFrameDelta;
|
---|
1204 | }
|
---|
1205 |
|
---|
1206 |
|
---|
1207 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnDevReset} */
|
---|
1208 | static DECLCALLBACK(int) vusbR3RhDevReset(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort, bool fResetOnLinux,
|
---|
1209 | PFNVUSBRESETDONE pfnDone, void *pvUser, PVM pVM)
|
---|
1210 | {
|
---|
1211 | PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
1212 | PVUSBDEV pDev = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort);
|
---|
1213 | AssertPtr(pDev);
|
---|
1214 |
|
---|
1215 | int rc = VUSBIDevReset(&pDev->IDevice, fResetOnLinux, pfnDone, pvUser, pVM);
|
---|
1216 | vusbDevRelease(pDev);
|
---|
1217 | return rc;
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 |
|
---|
1221 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnDevPowerOn} */
|
---|
1222 | static DECLCALLBACK(int) vusbR3RhDevPowerOn(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort)
|
---|
1223 | {
|
---|
1224 | PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
1225 | PVUSBDEV pDev = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort);
|
---|
1226 | AssertPtr(pDev);
|
---|
1227 |
|
---|
1228 | int rc = VUSBIDevPowerOn(&pDev->IDevice);
|
---|
1229 | vusbDevRelease(pDev);
|
---|
1230 | return rc;
|
---|
1231 | }
|
---|
1232 |
|
---|
1233 |
|
---|
1234 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnDevPowerOff} */
|
---|
1235 | static DECLCALLBACK(int) vusbR3RhDevPowerOff(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort)
|
---|
1236 | {
|
---|
1237 | PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
1238 | PVUSBDEV pDev = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort);
|
---|
1239 | AssertPtr(pDev);
|
---|
1240 |
|
---|
1241 | int rc = VUSBIDevPowerOff(&pDev->IDevice);
|
---|
1242 | vusbDevRelease(pDev);
|
---|
1243 | return rc;
|
---|
1244 | }
|
---|
1245 |
|
---|
1246 |
|
---|
1247 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnDevGetState} */
|
---|
1248 | static DECLCALLBACK(VUSBDEVICESTATE) vusbR3RhDevGetState(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort)
|
---|
1249 | {
|
---|
1250 | PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
1251 | PVUSBDEV pDev = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort);
|
---|
1252 | AssertPtr(pDev);
|
---|
1253 |
|
---|
1254 | VUSBDEVICESTATE enmState = VUSBIDevGetState(&pDev->IDevice);
|
---|
1255 | vusbDevRelease(pDev);
|
---|
1256 | return enmState;
|
---|
1257 | }
|
---|
1258 |
|
---|
1259 |
|
---|
1260 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnDevIsSavedStateSupported} */
|
---|
1261 | static DECLCALLBACK(bool) vusbR3RhDevIsSavedStateSupported(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort)
|
---|
1262 | {
|
---|
1263 | PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
1264 | PVUSBDEV pDev = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort);
|
---|
1265 | AssertPtr(pDev);
|
---|
1266 |
|
---|
1267 | bool fSavedStateSupported = VUSBIDevIsSavedStateSupported(&pDev->IDevice);
|
---|
1268 | vusbDevRelease(pDev);
|
---|
1269 | return fSavedStateSupported;
|
---|
1270 | }
|
---|
1271 |
|
---|
1272 |
|
---|
1273 | /** @interface_method_impl{VUSBIROOTHUBCONNECTOR,pfnDevGetSpeed} */
|
---|
1274 | static DECLCALLBACK(VUSBSPEED) vusbR3RhDevGetSpeed(PVUSBIROOTHUBCONNECTOR pInterface, uint32_t uPort)
|
---|
1275 | {
|
---|
1276 | PVUSBROOTHUB pThis = VUSBIROOTHUBCONNECTOR_2_VUSBROOTHUB(pInterface);
|
---|
1277 | PVUSBDEV pDev = vusbR3RhGetVUsbDevByPortRetain(pThis, uPort);
|
---|
1278 | AssertPtr(pDev);
|
---|
1279 |
|
---|
1280 | VUSBSPEED enmSpeed = pDev->IDevice.pfnGetSpeed(&pDev->IDevice);
|
---|
1281 | vusbDevRelease(pDev);
|
---|
1282 | return enmSpeed;
|
---|
1283 | }
|
---|
1284 |
|
---|
1285 |
|
---|
1286 | /**
|
---|
1287 | * @callback_method_impl{FNSSMDRVSAVEPREP, All URBs needs to be canceled.}
|
---|
1288 | */
|
---|
1289 | static DECLCALLBACK(int) vusbR3RhSavePrep(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
|
---|
1290 | {
|
---|
1291 | PVUSBROOTHUB pThis = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
|
---|
1292 | LogFlow(("vusbR3RhSavePrep:\n"));
|
---|
1293 | RT_NOREF(pSSM);
|
---|
1294 |
|
---|
1295 | /*
|
---|
1296 | * Detach all proxied devices.
|
---|
1297 | */
|
---|
1298 | RTCritSectEnter(&pThis->CritSectDevices);
|
---|
1299 |
|
---|
1300 | /** @todo we a) can't tell which are proxied, and b) this won't work well when continuing after saving! */
|
---|
1301 | for (unsigned i = 0; i < RT_ELEMENTS(pThis->apDevByPort); i++)
|
---|
1302 | {
|
---|
1303 | PVUSBDEV pDev = pThis->apDevByPort[i];
|
---|
1304 | if (pDev)
|
---|
1305 | {
|
---|
1306 | if (!VUSBIDevIsSavedStateSupported(&pDev->IDevice))
|
---|
1307 | {
|
---|
1308 | int rc = vusbHubDetach(pThis, pDev);
|
---|
1309 | AssertRC(rc);
|
---|
1310 |
|
---|
1311 | /*
|
---|
1312 | * Save the device pointers here so we can reattach them afterwards.
|
---|
1313 | * This will work fine even if the save fails since the Done handler is
|
---|
1314 | * called unconditionally if the Prep handler was called.
|
---|
1315 | */
|
---|
1316 | pThis->apDevByPort[i] = pDev;
|
---|
1317 | }
|
---|
1318 | }
|
---|
1319 | }
|
---|
1320 |
|
---|
1321 | RTCritSectLeave(&pThis->CritSectDevices);
|
---|
1322 |
|
---|
1323 | /*
|
---|
1324 | * Kill old load data which might be hanging around.
|
---|
1325 | */
|
---|
1326 | if (pThis->pLoad)
|
---|
1327 | {
|
---|
1328 | PDMDrvHlpTimerDestroy(pDrvIns, pThis->pLoad->hTimer);
|
---|
1329 | pThis->pLoad->hTimer = NIL_TMTIMERHANDLE;
|
---|
1330 | PDMDrvHlpMMHeapFree(pDrvIns, pThis->pLoad);
|
---|
1331 | pThis->pLoad = NULL;
|
---|
1332 | }
|
---|
1333 |
|
---|
1334 | return VINF_SUCCESS;
|
---|
1335 | }
|
---|
1336 |
|
---|
1337 |
|
---|
1338 | /**
|
---|
1339 | * @callback_method_impl{FNSSMDRVSAVEDONE}
|
---|
1340 | */
|
---|
1341 | static DECLCALLBACK(int) vusbR3RhSaveDone(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
|
---|
1342 | {
|
---|
1343 | PVUSBROOTHUB pThis = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
|
---|
1344 | PVUSBDEV aPortsOld[VUSB_DEVICES_MAX];
|
---|
1345 | unsigned i;
|
---|
1346 | LogFlow(("vusbR3RhSaveDone:\n"));
|
---|
1347 | RT_NOREF(pSSM);
|
---|
1348 |
|
---|
1349 | /* Save the current data. */
|
---|
1350 | memcpy(aPortsOld, pThis->apDevByPort, sizeof(aPortsOld));
|
---|
1351 | AssertCompile(sizeof(aPortsOld) == sizeof(pThis->apDevByPort));
|
---|
1352 |
|
---|
1353 | /*
|
---|
1354 | * NULL the dev pointers.
|
---|
1355 | */
|
---|
1356 | for (i = 0; i < RT_ELEMENTS(pThis->apDevByPort); i++)
|
---|
1357 | if (pThis->apDevByPort[i] && !VUSBIDevIsSavedStateSupported(&pThis->apDevByPort[i]->IDevice))
|
---|
1358 | pThis->apDevByPort[i] = NULL;
|
---|
1359 |
|
---|
1360 | /*
|
---|
1361 | * Attach the devices.
|
---|
1362 | */
|
---|
1363 | for (i = 0; i < RT_ELEMENTS(pThis->apDevByPort); i++)
|
---|
1364 | {
|
---|
1365 | PVUSBDEV pDev = aPortsOld[i];
|
---|
1366 | if (pDev && !VUSBIDevIsSavedStateSupported(&pDev->IDevice))
|
---|
1367 | vusbHubAttach(pThis, pDev);
|
---|
1368 | }
|
---|
1369 |
|
---|
1370 | return VINF_SUCCESS;
|
---|
1371 | }
|
---|
1372 |
|
---|
1373 |
|
---|
1374 | /**
|
---|
1375 | * @callback_method_impl{FNSSMDRVLOADPREP, This must detach the devices
|
---|
1376 | * currently attached and save them for reconnect after the state load has been
|
---|
1377 | * completed.}
|
---|
1378 | */
|
---|
1379 | static DECLCALLBACK(int) vusbR3RhLoadPrep(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
|
---|
1380 | {
|
---|
1381 | PVUSBROOTHUB pThis = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
|
---|
1382 | int rc = VINF_SUCCESS;
|
---|
1383 | LogFlow(("vusbR3RhLoadPrep:\n"));
|
---|
1384 | RT_NOREF(pSSM);
|
---|
1385 |
|
---|
1386 | if (!pThis->pLoad)
|
---|
1387 | {
|
---|
1388 | VUSBROOTHUBLOAD Load;
|
---|
1389 | unsigned i;
|
---|
1390 |
|
---|
1391 | /// @todo This is all bogus.
|
---|
1392 | /*
|
---|
1393 | * Detach all devices which are present in this session. Save them in the load
|
---|
1394 | * structure so we can reattach them after restoring the guest.
|
---|
1395 | */
|
---|
1396 | Load.hTimer = NIL_TMTIMERHANDLE;
|
---|
1397 | Load.cDevs = 0;
|
---|
1398 | for (i = 0; i < RT_ELEMENTS(pThis->apDevByPort); i++)
|
---|
1399 | {
|
---|
1400 | PVUSBDEV pDev = pThis->apDevByPort[i];
|
---|
1401 | if (pDev && !VUSBIDevIsSavedStateSupported(&pDev->IDevice))
|
---|
1402 | {
|
---|
1403 | Load.apDevs[Load.cDevs++] = pDev;
|
---|
1404 | vusbHubDetach(pThis, pDev);
|
---|
1405 | Assert(!pThis->apDevByPort[i]);
|
---|
1406 | }
|
---|
1407 | }
|
---|
1408 |
|
---|
1409 | /*
|
---|
1410 | * Any devices to reattach? If so, duplicate the Load struct.
|
---|
1411 | */
|
---|
1412 | if (Load.cDevs)
|
---|
1413 | {
|
---|
1414 | pThis->pLoad = (PVUSBROOTHUBLOAD)RTMemAllocZ(sizeof(Load));
|
---|
1415 | if (!pThis->pLoad)
|
---|
1416 | return VERR_NO_MEMORY;
|
---|
1417 | *pThis->pLoad = Load;
|
---|
1418 | }
|
---|
1419 | }
|
---|
1420 | /* else: we ASSUME no device can be attached or detached in the time
|
---|
1421 | * between a state load and the pLoad stuff processing. */
|
---|
1422 | return rc;
|
---|
1423 | }
|
---|
1424 |
|
---|
1425 |
|
---|
1426 | /**
|
---|
1427 | * Reattaches devices after a saved state load.
|
---|
1428 | */
|
---|
1429 | static DECLCALLBACK(void) vusbR3RhLoadReattachDevices(PPDMDRVINS pDrvIns, TMTIMERHANDLE hTimer, void *pvUser)
|
---|
1430 | {
|
---|
1431 | PVUSBROOTHUB pThis = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
|
---|
1432 | PVUSBROOTHUBLOAD pLoad = pThis->pLoad;
|
---|
1433 | LogFlow(("vusbR3RhLoadReattachDevices:\n"));
|
---|
1434 | Assert(hTimer == pLoad->hTimer); RT_NOREF(pvUser);
|
---|
1435 |
|
---|
1436 | /*
|
---|
1437 | * Reattach devices.
|
---|
1438 | */
|
---|
1439 | for (unsigned i = 0; i < pLoad->cDevs; i++)
|
---|
1440 | vusbHubAttach(pThis, pLoad->apDevs[i]);
|
---|
1441 |
|
---|
1442 | /*
|
---|
1443 | * Cleanup.
|
---|
1444 | */
|
---|
1445 | PDMDrvHlpTimerDestroy(pDrvIns, hTimer);
|
---|
1446 | pLoad->hTimer = NIL_TMTIMERHANDLE;
|
---|
1447 | RTMemFree(pLoad);
|
---|
1448 | pThis->pLoad = NULL;
|
---|
1449 | }
|
---|
1450 |
|
---|
1451 |
|
---|
1452 | /**
|
---|
1453 | * @callback_method_impl{FNSSMDRVLOADDONE}
|
---|
1454 | */
|
---|
1455 | static DECLCALLBACK(int) vusbR3RhLoadDone(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
|
---|
1456 | {
|
---|
1457 | PVUSBROOTHUB pThis = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
|
---|
1458 | LogFlow(("vusbR3RhLoadDone:\n"));
|
---|
1459 | RT_NOREF(pSSM);
|
---|
1460 |
|
---|
1461 | /*
|
---|
1462 | * Start a timer if we've got devices to reattach
|
---|
1463 | */
|
---|
1464 | if (pThis->pLoad)
|
---|
1465 | {
|
---|
1466 | int rc = PDMDrvHlpTMTimerCreate(pDrvIns, TMCLOCK_VIRTUAL, vusbR3RhLoadReattachDevices, NULL,
|
---|
1467 | TMTIMER_FLAGS_NO_CRIT_SECT | TMTIMER_FLAGS_NO_RING0,
|
---|
1468 | "VUSB reattach on load", &pThis->pLoad->hTimer);
|
---|
1469 | if (RT_SUCCESS(rc))
|
---|
1470 | rc = PDMDrvHlpTimerSetMillies(pDrvIns, pThis->pLoad->hTimer, 250);
|
---|
1471 | return rc;
|
---|
1472 | }
|
---|
1473 |
|
---|
1474 | return VINF_SUCCESS;
|
---|
1475 | }
|
---|
1476 |
|
---|
1477 |
|
---|
1478 | /* -=-=-=-=-=- PDM Base interface methods -=-=-=-=-=- */
|
---|
1479 |
|
---|
1480 |
|
---|
1481 | /**
|
---|
1482 | * @interface_method_impl{PDMIBASE,pfnQueryInterface}
|
---|
1483 | */
|
---|
1484 | static DECLCALLBACK(void *) vusbRhQueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
1485 | {
|
---|
1486 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
1487 | PVUSBROOTHUB pRh = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
|
---|
1488 |
|
---|
1489 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
1490 | PDMIBASE_RETURN_INTERFACE(pszIID, VUSBIROOTHUBCONNECTOR, &pRh->IRhConnector);
|
---|
1491 | return NULL;
|
---|
1492 | }
|
---|
1493 |
|
---|
1494 |
|
---|
1495 | /* -=-=-=-=-=- PDM Driver methods -=-=-=-=-=- */
|
---|
1496 |
|
---|
1497 |
|
---|
1498 | /**
|
---|
1499 | * Destruct a driver instance.
|
---|
1500 | *
|
---|
1501 | * Most VM resources are freed by the VM. This callback is provided so that any non-VM
|
---|
1502 | * resources can be freed correctly.
|
---|
1503 | *
|
---|
1504 | * @param pDrvIns The driver instance data.
|
---|
1505 | */
|
---|
1506 | static DECLCALLBACK(void) vusbRhDestruct(PPDMDRVINS pDrvIns)
|
---|
1507 | {
|
---|
1508 | PVUSBROOTHUB pRh = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
|
---|
1509 | PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
|
---|
1510 |
|
---|
1511 | vusbUrbPoolDestroy(&pRh->Dev.UrbPool);
|
---|
1512 | if (pRh->pszName)
|
---|
1513 | {
|
---|
1514 | RTStrFree(pRh->pszName);
|
---|
1515 | pRh->pszName = NULL;
|
---|
1516 | }
|
---|
1517 | if (pRh->hSniffer != VUSBSNIFFER_NIL)
|
---|
1518 | VUSBSnifferDestroy(pRh->hSniffer);
|
---|
1519 |
|
---|
1520 | if (pRh->hSemEventPeriodFrame)
|
---|
1521 | RTSemEventMultiDestroy(pRh->hSemEventPeriodFrame);
|
---|
1522 |
|
---|
1523 | if (pRh->hSemEventPeriodFrameStopped)
|
---|
1524 | RTSemEventMultiDestroy(pRh->hSemEventPeriodFrameStopped);
|
---|
1525 |
|
---|
1526 | RTCritSectDelete(&pRh->CritSectDevices);
|
---|
1527 | }
|
---|
1528 |
|
---|
1529 |
|
---|
1530 | /**
|
---|
1531 | * Construct a root hub driver instance.
|
---|
1532 | *
|
---|
1533 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
1534 | */
|
---|
1535 | static DECLCALLBACK(int) vusbRhConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
1536 | {
|
---|
1537 | RT_NOREF(fFlags);
|
---|
1538 | PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
|
---|
1539 | PVUSBROOTHUB pThis = PDMINS_2_DATA(pDrvIns, PVUSBROOTHUB);
|
---|
1540 | PCPDMDRVHLPR3 pHlp = pDrvIns->pHlpR3;
|
---|
1541 |
|
---|
1542 | LogFlow(("vusbRhConstruct: Instance %d\n", pDrvIns->iInstance));
|
---|
1543 |
|
---|
1544 | /*
|
---|
1545 | * Validate configuration.
|
---|
1546 | */
|
---|
1547 | PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "CaptureFilename", "");
|
---|
1548 |
|
---|
1549 | /*
|
---|
1550 | * Check that there are no drivers below us.
|
---|
1551 | */
|
---|
1552 | AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
|
---|
1553 | ("Configuration error: Not possible to attach anything to this driver!\n"),
|
---|
1554 | VERR_PDM_DRVINS_NO_ATTACH);
|
---|
1555 |
|
---|
1556 | /*
|
---|
1557 | * Initialize the critical sections.
|
---|
1558 | */
|
---|
1559 | int rc = RTCritSectInit(&pThis->CritSectDevices);
|
---|
1560 | if (RT_FAILURE(rc))
|
---|
1561 | return rc;
|
---|
1562 |
|
---|
1563 | char *pszCaptureFilename = NULL;
|
---|
1564 | rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "CaptureFilename", &pszCaptureFilename);
|
---|
1565 | if ( RT_FAILURE(rc)
|
---|
1566 | && rc != VERR_CFGM_VALUE_NOT_FOUND)
|
---|
1567 | return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
|
---|
1568 | N_("Configuration error: Failed to query value of \"CaptureFilename\""));
|
---|
1569 |
|
---|
1570 | /*
|
---|
1571 | * Initialize the data members.
|
---|
1572 | */
|
---|
1573 | pDrvIns->IBase.pfnQueryInterface = vusbRhQueryInterface;
|
---|
1574 | /* the usb device */
|
---|
1575 | pThis->Dev.enmState = VUSB_DEVICE_STATE_ATTACHED;
|
---|
1576 | pThis->Dev.cRefs = 1;
|
---|
1577 | //pThis->hub.cPorts - later
|
---|
1578 | pThis->cDevices = 0;
|
---|
1579 | pThis->Dev.pHub = pThis;
|
---|
1580 | RTStrAPrintf(&pThis->pszName, "RootHub#%d", pDrvIns->iInstance);
|
---|
1581 | /* misc */
|
---|
1582 | pThis->pDrvIns = pDrvIns;
|
---|
1583 | /* the connector */
|
---|
1584 | pThis->IRhConnector.pfnSetUrbParams = vusbRhSetUrbParams;
|
---|
1585 | pThis->IRhConnector.pfnReset = vusbR3RhReset;
|
---|
1586 | pThis->IRhConnector.pfnPowerOn = vusbR3RhPowerOn;
|
---|
1587 | pThis->IRhConnector.pfnPowerOff = vusbR3RhPowerOff;
|
---|
1588 | pThis->IRhConnector.pfnNewUrb = vusbRhConnNewUrb;
|
---|
1589 | pThis->IRhConnector.pfnFreeUrb = vusbRhConnFreeUrb;
|
---|
1590 | pThis->IRhConnector.pfnSubmitUrb = vusbRhSubmitUrb;
|
---|
1591 | pThis->IRhConnector.pfnReapAsyncUrbs = vusbRhReapAsyncUrbs;
|
---|
1592 | pThis->IRhConnector.pfnCancelUrbsEp = vusbRhCancelUrbsEp;
|
---|
1593 | pThis->IRhConnector.pfnCancelAllUrbs = vusbRhCancelAllUrbs;
|
---|
1594 | pThis->IRhConnector.pfnAbortEp = vusbRhAbortEp;
|
---|
1595 | pThis->IRhConnector.pfnSetPeriodicFrameProcessing = vusbRhSetFrameProcessing;
|
---|
1596 | pThis->IRhConnector.pfnGetPeriodicFrameRate = vusbRhGetPeriodicFrameRate;
|
---|
1597 | pThis->IRhConnector.pfnUpdateIsocFrameDelta = vusbRhUpdateIsocFrameDelta;
|
---|
1598 | pThis->IRhConnector.pfnDevReset = vusbR3RhDevReset;
|
---|
1599 | pThis->IRhConnector.pfnDevPowerOn = vusbR3RhDevPowerOn;
|
---|
1600 | pThis->IRhConnector.pfnDevPowerOff = vusbR3RhDevPowerOff;
|
---|
1601 | pThis->IRhConnector.pfnDevGetState = vusbR3RhDevGetState;
|
---|
1602 | pThis->IRhConnector.pfnDevIsSavedStateSupported = vusbR3RhDevIsSavedStateSupported;
|
---|
1603 | pThis->IRhConnector.pfnDevGetSpeed = vusbR3RhDevGetSpeed;
|
---|
1604 | pThis->hSniffer = VUSBSNIFFER_NIL;
|
---|
1605 | pThis->cbHci = 0;
|
---|
1606 | pThis->cbHciTd = 0;
|
---|
1607 | pThis->fFrameProcessing = false;
|
---|
1608 | #ifdef LOG_ENABLED
|
---|
1609 | pThis->iSerial = 0;
|
---|
1610 | #endif
|
---|
1611 | /*
|
---|
1612 | * Resolve interface(s).
|
---|
1613 | */
|
---|
1614 | pThis->pIRhPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, VUSBIROOTHUBPORT);
|
---|
1615 | AssertMsgReturn(pThis->pIRhPort, ("Configuration error: the device/driver above us doesn't expose any VUSBIROOTHUBPORT interface!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
|
---|
1616 |
|
---|
1617 | /*
|
---|
1618 | * Get number of ports and the availability bitmap.
|
---|
1619 | * ASSUME that the number of ports reported now at creation time is the max number.
|
---|
1620 | */
|
---|
1621 | pThis->cPorts = pThis->pIRhPort->pfnGetAvailablePorts(pThis->pIRhPort, &pThis->Bitmap);
|
---|
1622 | Log(("vusbRhConstruct: cPorts=%d\n", pThis->cPorts));
|
---|
1623 |
|
---|
1624 | /*
|
---|
1625 | * Get the USB version of the attached HC.
|
---|
1626 | * ASSUME that version 2.0 implies high-speed.
|
---|
1627 | */
|
---|
1628 | pThis->fHcVersions = pThis->pIRhPort->pfnGetUSBVersions(pThis->pIRhPort);
|
---|
1629 | Log(("vusbRhConstruct: fHcVersions=%u\n", pThis->fHcVersions));
|
---|
1630 |
|
---|
1631 | rc = vusbUrbPoolInit(&pThis->Dev.UrbPool);
|
---|
1632 | if (RT_FAILURE(rc))
|
---|
1633 | return rc;
|
---|
1634 |
|
---|
1635 | if (pszCaptureFilename)
|
---|
1636 | {
|
---|
1637 | rc = VUSBSnifferCreate(&pThis->hSniffer, 0, pszCaptureFilename, NULL, NULL);
|
---|
1638 | if (RT_FAILURE(rc))
|
---|
1639 | return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS,
|
---|
1640 | N_("VUSBSniffer cannot open '%s' for writing. The directory must exist and it must be writable for the current user"),
|
---|
1641 | pszCaptureFilename);
|
---|
1642 |
|
---|
1643 | PDMDrvHlpMMHeapFree(pDrvIns, pszCaptureFilename);
|
---|
1644 | }
|
---|
1645 |
|
---|
1646 | /*
|
---|
1647 | * Register ourselves as a USB hub.
|
---|
1648 | * The current implementation uses the VUSBIRHCONFIG interface for communication.
|
---|
1649 | */
|
---|
1650 | PCPDMUSBHUBHLP pHlpUsb; /* not used currently */
|
---|
1651 | rc = PDMDrvHlpUSBRegisterHub(pDrvIns, pThis->fHcVersions, pThis->cPorts, &g_vusbHubReg, &pHlpUsb);
|
---|
1652 | if (RT_FAILURE(rc))
|
---|
1653 | return rc;
|
---|
1654 |
|
---|
1655 | /*
|
---|
1656 | * Register the saved state data unit for attaching devices.
|
---|
1657 | */
|
---|
1658 | rc = PDMDrvHlpSSMRegisterEx(pDrvIns, VUSB_ROOTHUB_SAVED_STATE_VERSION, 0,
|
---|
1659 | NULL, NULL, NULL,
|
---|
1660 | vusbR3RhSavePrep, NULL, vusbR3RhSaveDone,
|
---|
1661 | vusbR3RhLoadPrep, NULL, vusbR3RhLoadDone);
|
---|
1662 | AssertRCReturn(rc, rc);
|
---|
1663 |
|
---|
1664 | /*
|
---|
1665 | * Statistics. (It requires a 30" monitor or extremely tiny fonts to edit this "table".)
|
---|
1666 | */
|
---|
1667 | #ifdef VBOX_WITH_STATISTICS
|
---|
1668 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "The number of URBs submitted.", "/VUSB/%d/UrbsSubmitted", pDrvIns->iInstance);
|
---|
1669 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Bulk transfer.", "/VUSB/%d/UrbsSubmitted/Bulk", pDrvIns->iInstance);
|
---|
1670 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Control transfer.", "/VUSB/%d/UrbsSubmitted/Ctrl", pDrvIns->iInstance);
|
---|
1671 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Interrupt transfer.", "/VUSB/%d/UrbsSubmitted/Intr", pDrvIns->iInstance);
|
---|
1672 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Isochronous transfer.", "/VUSB/%d/UrbsSubmitted/Isoc", pDrvIns->iInstance);
|
---|
1673 |
|
---|
1674 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "The number of URBs cancelled. (included in failed)", "/VUSB/%d/UrbsCancelled", pDrvIns->iInstance);
|
---|
1675 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Bulk transfer.", "/VUSB/%d/UrbsCancelled/Bulk", pDrvIns->iInstance);
|
---|
1676 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Control transfer.", "/VUSB/%d/UrbsCancelled/Ctrl", pDrvIns->iInstance);
|
---|
1677 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Interrupt transfer.", "/VUSB/%d/UrbsCancelled/Intr", pDrvIns->iInstance);
|
---|
1678 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Isochronous transfer.", "/VUSB/%d/UrbsCancelled/Isoc", pDrvIns->iInstance);
|
---|
1679 |
|
---|
1680 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "The number of URBs failing.", "/VUSB/%d/UrbsFailed", pDrvIns->iInstance);
|
---|
1681 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Bulk transfer.", "/VUSB/%d/UrbsFailed/Bulk", pDrvIns->iInstance);
|
---|
1682 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Control transfer.", "/VUSB/%d/UrbsFailed/Ctrl", pDrvIns->iInstance);
|
---|
1683 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Interrupt transfer.", "/VUSB/%d/UrbsFailed/Intr", pDrvIns->iInstance);
|
---|
1684 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Isochronous transfer.", "/VUSB/%d/UrbsFailed/Isoc", pDrvIns->iInstance);
|
---|
1685 |
|
---|
1686 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Total requested transfer.", "/VUSB/%d/ReqBytes", pDrvIns->iInstance);
|
---|
1687 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ReqBytes/Bulk", pDrvIns->iInstance);
|
---|
1688 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ReqBytes/Ctrl", pDrvIns->iInstance);
|
---|
1689 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ReqBytes/Intr", pDrvIns->iInstance);
|
---|
1690 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ReqBytes/Isoc", pDrvIns->iInstance);
|
---|
1691 |
|
---|
1692 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Total requested read transfer.", "/VUSB/%d/ReqReadBytes", pDrvIns->iInstance);
|
---|
1693 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ReqReadBytes/Bulk", pDrvIns->iInstance);
|
---|
1694 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ReqReadBytes/Ctrl", pDrvIns->iInstance);
|
---|
1695 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ReqReadBytes/Intr", pDrvIns->iInstance);
|
---|
1696 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ReqReadBytes/Isoc", pDrvIns->iInstance);
|
---|
1697 |
|
---|
1698 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Total requested write transfer.", "/VUSB/%d/ReqWriteBytes", pDrvIns->iInstance);
|
---|
1699 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ReqWriteBytes/Bulk", pDrvIns->iInstance);
|
---|
1700 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ReqWriteBytes/Ctrl", pDrvIns->iInstance);
|
---|
1701 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ReqWriteBytes/Intr", pDrvIns->iInstance);
|
---|
1702 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ReqWriteBytes/Isoc", pDrvIns->iInstance);
|
---|
1703 |
|
---|
1704 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Actual total transfer.", "/VUSB/%d/ActBytes", pDrvIns->iInstance);
|
---|
1705 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ActBytes/Bulk", pDrvIns->iInstance);
|
---|
1706 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ActBytes/Ctrl", pDrvIns->iInstance);
|
---|
1707 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ActBytes/Intr", pDrvIns->iInstance);
|
---|
1708 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ActBytes/Isoc", pDrvIns->iInstance);
|
---|
1709 |
|
---|
1710 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Actual total read transfer.", "/VUSB/%d/ActReadBytes", pDrvIns->iInstance);
|
---|
1711 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ActReadBytes/Bulk", pDrvIns->iInstance);
|
---|
1712 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ActReadBytes/Ctrl", pDrvIns->iInstance);
|
---|
1713 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ActReadBytes/Intr", pDrvIns->iInstance);
|
---|
1714 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ActReadBytes/Isoc", pDrvIns->iInstance);
|
---|
1715 |
|
---|
1716 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->Total.StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Actual total write transfer.", "/VUSB/%d/ActWriteBytes", pDrvIns->iInstance);
|
---|
1717 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Bulk transfer.", "/VUSB/%d/ActWriteBytes/Bulk", pDrvIns->iInstance);
|
---|
1718 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Control transfer.", "/VUSB/%d/ActWriteBytes/Ctrl", pDrvIns->iInstance);
|
---|
1719 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Interrupt transfer.", "/VUSB/%d/ActWriteBytes/Intr", pDrvIns->iInstance);
|
---|
1720 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Isochronous transfer.", "/VUSB/%d/ActWriteBytes/Isoc", pDrvIns->iInstance);
|
---|
1721 |
|
---|
1722 | /* bulk */
|
---|
1723 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of submitted URBs.", "/VUSB/%d/Bulk/Urbs", pDrvIns->iInstance);
|
---|
1724 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of failed URBs.", "/VUSB/%d/Bulk/UrbsFailed", pDrvIns->iInstance);
|
---|
1725 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of cancelled URBs.", "/VUSB/%d/Bulk/UrbsFailed/Cancelled", pDrvIns->iInstance);
|
---|
1726 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of bytes transferred.", "/VUSB/%d/Bulk/ActBytes", pDrvIns->iInstance);
|
---|
1727 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Bulk/ActBytes/Read", pDrvIns->iInstance);
|
---|
1728 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Bulk/ActBytes/Write", pDrvIns->iInstance);
|
---|
1729 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Requested number of bytes.", "/VUSB/%d/Bulk/ReqBytes", pDrvIns->iInstance);
|
---|
1730 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Bulk/ReqBytes/Read", pDrvIns->iInstance);
|
---|
1731 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_BULK].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Bulk/ReqBytes/Write", pDrvIns->iInstance);
|
---|
1732 |
|
---|
1733 | /* control */
|
---|
1734 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of submitted URBs.", "/VUSB/%d/Ctrl/Urbs", pDrvIns->iInstance);
|
---|
1735 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of failed URBs.", "/VUSB/%d/Ctrl/UrbsFailed", pDrvIns->iInstance);
|
---|
1736 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of cancelled URBs.", "/VUSB/%d/Ctrl/UrbsFailed/Cancelled", pDrvIns->iInstance);
|
---|
1737 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of bytes transferred.", "/VUSB/%d/Ctrl/ActBytes", pDrvIns->iInstance);
|
---|
1738 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Ctrl/ActBytes/Read", pDrvIns->iInstance);
|
---|
1739 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Ctrl/ActBytes/Write", pDrvIns->iInstance);
|
---|
1740 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Requested number of bytes.", "/VUSB/%d/Ctrl/ReqBytes", pDrvIns->iInstance);
|
---|
1741 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Ctrl/ReqBytes/Read", pDrvIns->iInstance);
|
---|
1742 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_CTRL].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Ctrl/ReqBytes/Write", pDrvIns->iInstance);
|
---|
1743 |
|
---|
1744 | /* interrupt */
|
---|
1745 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of submitted URBs.", "/VUSB/%d/Intr/Urbs", pDrvIns->iInstance);
|
---|
1746 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of failed URBs.", "/VUSB/%d/Intr/UrbsFailed", pDrvIns->iInstance);
|
---|
1747 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of cancelled URBs.", "/VUSB/%d/Intr/UrbsFailed/Cancelled", pDrvIns->iInstance);
|
---|
1748 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of bytes transferred.", "/VUSB/%d/Intr/ActBytes", pDrvIns->iInstance);
|
---|
1749 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Intr/ActBytes/Read", pDrvIns->iInstance);
|
---|
1750 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Intr/ActBytes/Write", pDrvIns->iInstance);
|
---|
1751 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Requested number of bytes.", "/VUSB/%d/Intr/ReqBytes", pDrvIns->iInstance);
|
---|
1752 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Intr/ReqBytes/Read", pDrvIns->iInstance);
|
---|
1753 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_INTR].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Intr/ReqBytes/Write", pDrvIns->iInstance);
|
---|
1754 |
|
---|
1755 | /* isochronous */
|
---|
1756 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsSubmitted, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of submitted URBs.", "/VUSB/%d/Isoc/Urbs", pDrvIns->iInstance);
|
---|
1757 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsFailed, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of failed URBs.", "/VUSB/%d/Isoc/UrbsFailed", pDrvIns->iInstance);
|
---|
1758 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatUrbsCancelled, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of cancelled URBs.", "/VUSB/%d/Isoc/UrbsFailed/Cancelled", pDrvIns->iInstance);
|
---|
1759 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Number of bytes transferred.", "/VUSB/%d/Isoc/ActBytes", pDrvIns->iInstance);
|
---|
1760 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Isoc/ActBytes/Read", pDrvIns->iInstance);
|
---|
1761 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatActWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Isoc/ActBytes/Write", pDrvIns->iInstance);
|
---|
1762 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Requested number of bytes.", "/VUSB/%d/Isoc/ReqBytes", pDrvIns->iInstance);
|
---|
1763 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqReadBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Read.", "/VUSB/%d/Isoc/ReqBytes/Read", pDrvIns->iInstance);
|
---|
1764 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aTypes[VUSBXFERTYPE_ISOC].StatReqWriteBytes, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Write.", "/VUSB/%d/Isoc/ReqBytes/Write", pDrvIns->iInstance);
|
---|
1765 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocActPkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Number of isochronous packets returning data.", "/VUSB/%d/Isoc/ActPkts", pDrvIns->iInstance);
|
---|
1766 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocActReadPkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Read.", "/VUSB/%d/Isoc/ActPkts/Read", pDrvIns->iInstance);
|
---|
1767 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocActWritePkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Write.", "/VUSB/%d/Isoc/ActPkts/Write", pDrvIns->iInstance);
|
---|
1768 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocReqPkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Requested number of isochronous packets.", "/VUSB/%d/Isoc/ReqPkts", pDrvIns->iInstance);
|
---|
1769 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocReqReadPkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Read.", "/VUSB/%d/Isoc/ReqPkts/Read", pDrvIns->iInstance);
|
---|
1770 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatIsocReqWritePkts, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Write.", "/VUSB/%d/Isoc/ReqPkts/Write", pDrvIns->iInstance);
|
---|
1771 |
|
---|
1772 | for (unsigned i = 0; i < RT_ELEMENTS(pThis->aStatIsocDetails); i++)
|
---|
1773 | {
|
---|
1774 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].Pkts, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d", pDrvIns->iInstance, i);
|
---|
1775 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].Ok, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/Ok", pDrvIns->iInstance, i);
|
---|
1776 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].Ok0, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/Ok0", pDrvIns->iInstance, i);
|
---|
1777 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].DataUnderrun, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/DataUnderrun", pDrvIns->iInstance, i);
|
---|
1778 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].DataUnderrun0, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/DataUnderrun0", pDrvIns->iInstance, i);
|
---|
1779 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].DataOverrun, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/DataOverrun", pDrvIns->iInstance, i);
|
---|
1780 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].NotAccessed, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/NotAccessed", pDrvIns->iInstance, i);
|
---|
1781 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].Misc, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_COUNT, ".", "/VUSB/%d/Isoc/%d/Misc", pDrvIns->iInstance, i);
|
---|
1782 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->aStatIsocDetails[i].Bytes, STAMTYPE_COUNTER, STAMVISIBILITY_USED, STAMUNIT_BYTES, ".", "/VUSB/%d/Isoc/%d/Bytes", pDrvIns->iInstance, i);
|
---|
1783 | }
|
---|
1784 |
|
---|
1785 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatReapAsyncUrbs, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling the vusbRhReapAsyncUrbs body (omitting calls when nothing is in-flight).",
|
---|
1786 | "/VUSB/%d/ReapAsyncUrbs", pDrvIns->iInstance);
|
---|
1787 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatSubmitUrb, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling the vusbRhSubmitUrb body.",
|
---|
1788 | "/VUSB/%d/SubmitUrb", pDrvIns->iInstance);
|
---|
1789 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatFramesProcessedThread, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Processed frames in the dedicated thread",
|
---|
1790 | "/VUSB/%d/FramesProcessedThread", pDrvIns->iInstance);
|
---|
1791 | PDMDrvHlpSTAMRegisterF(pDrvIns, &pThis->StatFramesProcessedClbk, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Processed frames in the URB completion callback",
|
---|
1792 | "/VUSB/%d/FramesProcessedClbk", pDrvIns->iInstance);
|
---|
1793 | #endif
|
---|
1794 | PDMDrvHlpSTAMRegisterF(pDrvIns, (void *)&pThis->Dev.UrbPool.cUrbsInPool, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "The number of URBs in the pool.",
|
---|
1795 | "/VUSB/%d/cUrbsInPool", pDrvIns->iInstance);
|
---|
1796 |
|
---|
1797 | return VINF_SUCCESS;
|
---|
1798 | }
|
---|
1799 |
|
---|
1800 |
|
---|
1801 | /**
|
---|
1802 | * VUSB Root Hub driver registration record.
|
---|
1803 | */
|
---|
1804 | const PDMDRVREG g_DrvVUSBRootHub =
|
---|
1805 | {
|
---|
1806 | /* u32Version */
|
---|
1807 | PDM_DRVREG_VERSION,
|
---|
1808 | /* szName */
|
---|
1809 | "VUSBRootHub",
|
---|
1810 | /* szRCMod */
|
---|
1811 | "",
|
---|
1812 | /* szR0Mod */
|
---|
1813 | "",
|
---|
1814 | /* pszDescription */
|
---|
1815 | "VUSB Root Hub Driver.",
|
---|
1816 | /* fFlags */
|
---|
1817 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
1818 | /* fClass. */
|
---|
1819 | PDM_DRVREG_CLASS_USB,
|
---|
1820 | /* cMaxInstances */
|
---|
1821 | ~0U,
|
---|
1822 | /* cbInstance */
|
---|
1823 | sizeof(VUSBROOTHUB),
|
---|
1824 | /* pfnConstruct */
|
---|
1825 | vusbRhConstruct,
|
---|
1826 | /* pfnDestruct */
|
---|
1827 | vusbRhDestruct,
|
---|
1828 | /* pfnRelocate */
|
---|
1829 | NULL,
|
---|
1830 | /* pfnIOCtl */
|
---|
1831 | NULL,
|
---|
1832 | /* pfnPowerOn */
|
---|
1833 | NULL,
|
---|
1834 | /* pfnReset */
|
---|
1835 | NULL,
|
---|
1836 | /* pfnSuspend */
|
---|
1837 | NULL,
|
---|
1838 | /* pfnResume */
|
---|
1839 | NULL,
|
---|
1840 | /* pfnAttach */
|
---|
1841 | NULL,
|
---|
1842 | /* pfnDetach */
|
---|
1843 | NULL,
|
---|
1844 | /* pfnPowerOff */
|
---|
1845 | NULL,
|
---|
1846 | /* pfnSoftReset */
|
---|
1847 | NULL,
|
---|
1848 | /* u32EndVersion */
|
---|
1849 | PDM_DRVREG_VERSION
|
---|
1850 | };
|
---|
1851 |
|
---|
1852 | /*
|
---|
1853 | * Local Variables:
|
---|
1854 | * mode: c
|
---|
1855 | * c-file-style: "bsd"
|
---|
1856 | * c-basic-offset: 4
|
---|
1857 | * tab-width: 4
|
---|
1858 | * indent-tabs-mode: s
|
---|
1859 | * End:
|
---|
1860 | */
|
---|
1861 |
|
---|