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