VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR3/PDMUsb.cpp@ 45301

Last change on this file since 45301 was 44386, checked in by vboxsync, 12 years ago

CFGM: Some smaller PVM/PUVM adjustments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 52.9 KB
Line 
1/* $Id: PDMUsb.cpp 44386 2013-01-25 18:18:12Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device and Driver Manager, USB part.
4 */
5
6/*
7 * Copyright (C) 2006-2013 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#define LOG_GROUP LOG_GROUP_PDM_DRIVER
23#include "PDMInternal.h"
24#include <VBox/vmm/pdm.h>
25#include <VBox/vusb.h>
26#include <VBox/vmm/mm.h>
27#include <VBox/vmm/cfgm.h>
28#include <VBox/vmm/vmm.h>
29#include <VBox/sup.h>
30#include <VBox/vmm/vm.h>
31#include <VBox/vmm/uvm.h>
32#include <VBox/version.h>
33#include <VBox/err.h>
34
35#include <VBox/log.h>
36#include <iprt/assert.h>
37#include <iprt/thread.h>
38#include <iprt/string.h>
39#include <iprt/asm.h>
40#include <iprt/alloc.h>
41#include <iprt/alloca.h>
42#include <iprt/path.h>
43#include <iprt/uuid.h>
44
45
46/*******************************************************************************
47* Structures and Typedefs *
48*******************************************************************************/
49/**
50 * Internal callback structure pointer.
51 *
52 * The main purpose is to define the extra data we associate
53 * with PDMUSBREGCB so we can find the VM instance and so on.
54 */
55typedef struct PDMUSBREGCBINT
56{
57 /** The callback structure. */
58 PDMUSBREGCB Core;
59 /** A bit of padding. */
60 uint32_t u32[4];
61 /** VM Handle. */
62 PVM pVM;
63} PDMUSBREGCBINT, *PPDMUSBREGCBINT;
64typedef const PDMUSBREGCBINT *PCPDMUSBREGCBINT;
65
66
67/*******************************************************************************
68* Defined Constants And Macros *
69*******************************************************************************/
70/** @def PDMUSB_ASSERT_USBINS
71 * Asserts the validity of the USB device instance.
72 */
73#ifdef VBOX_STRICT
74# define PDMUSB_ASSERT_USBINS(pUsbIns) \
75 do { \
76 AssertPtr(pUsbIns); \
77 Assert(pUsbIns->u32Version == PDM_USBINS_VERSION); \
78 Assert(pUsbIns->pvInstanceDataR3 == (void *)&pUsbIns->achInstanceData[0]); \
79 } while (0)
80#else
81# define PDMUSB_ASSERT_USBINS(pUsbIns) do { } while (0)
82#endif
83
84
85/*******************************************************************************
86* Internal Functions *
87*******************************************************************************/
88static void pdmR3UsbDestroyDevice(PVM pVM, PPDMUSBINS pUsbIns);
89
90
91/*******************************************************************************
92* Global Variables *
93*******************************************************************************/
94extern const PDMUSBHLP g_pdmR3UsbHlp;
95
96
97AssertCompile(sizeof(PDMUSBINSINT) <= RT_SIZEOFMEMB(PDMUSBINS, Internal.padding));
98
99
100/**
101 * Registers a USB hub driver.
102 *
103 * @returns VBox status code.
104 * @param pVM Pointer to the VM.
105 * @param pDrvIns The driver instance of the hub.
106 * @param fVersions Indicates the kinds of USB devices that can be attached to this HUB.
107 * @param cPorts The number of ports.
108 * @param pUsbHubReg The hub callback structure that PDMUsb uses to interact with it.
109 * @param ppUsbHubHlp The helper callback structure that the hub uses to talk to PDMUsb.
110 * @thread EMT
111 */
112int pdmR3UsbRegisterHub(PVM pVM, PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp)
113{
114 /*
115 * Validate input.
116 */
117 /* The driver must be in the USB class. */
118 if (!(pDrvIns->pReg->fClass & PDM_DRVREG_CLASS_USB))
119 {
120 LogRel(("pdmR3UsbRegisterHub: fClass=%#x expected %#x to be set\n", pDrvIns->pReg->fClass, PDM_DRVREG_CLASS_USB));
121 return VERR_INVALID_PARAMETER;
122 }
123 AssertMsgReturn(!(fVersions & ~(VUSB_STDVER_11 | VUSB_STDVER_20)), ("%#x\n", fVersions), VERR_INVALID_PARAMETER);
124 AssertPtrReturn(ppUsbHubHlp, VERR_INVALID_POINTER);
125 AssertPtrReturn(pUsbHubReg, VERR_INVALID_POINTER);
126 AssertReturn(pUsbHubReg->u32Version == PDM_USBHUBREG_VERSION, VERR_INVALID_MAGIC);
127 AssertReturn(pUsbHubReg->u32TheEnd == PDM_USBHUBREG_VERSION, VERR_INVALID_MAGIC);
128 AssertPtrReturn(pUsbHubReg->pfnAttachDevice, VERR_INVALID_PARAMETER);
129 AssertPtrReturn(pUsbHubReg->pfnDetachDevice, VERR_INVALID_PARAMETER);
130
131 /*
132 * Check for duplicate registration and find the last hub for FIFO registration.
133 */
134 PPDMUSBHUB pPrev = NULL;
135 for (PPDMUSBHUB pCur = pVM->pdm.s.pUsbHubs; pCur; pCur = pCur->pNext)
136 {
137 if (pCur->pDrvIns == pDrvIns)
138 return VERR_PDM_USB_HUB_EXISTS;
139 pPrev = pCur;
140 }
141
142 /*
143 * Create an internal USB hub structure.
144 */
145 PPDMUSBHUB pHub = (PPDMUSBHUB)MMR3HeapAlloc(pVM, MM_TAG_PDM_DRIVER, sizeof(*pHub));
146 if (!pHub)
147 return VERR_NO_MEMORY;
148
149 pHub->fVersions = fVersions;
150 pHub->cPorts = cPorts;
151 pHub->cAvailablePorts = cPorts;
152 pHub->pDrvIns = pDrvIns;
153 pHub->Reg = *pUsbHubReg;
154 pHub->pNext = NULL;
155
156 /* link it */
157 if (pPrev)
158 pPrev->pNext = pHub;
159 else
160 pVM->pdm.s.pUsbHubs = pHub;
161
162 Log(("PDM: Registered USB hub %p/%s\n", pDrvIns, pDrvIns->pReg->szName));
163 return VINF_SUCCESS;
164}
165
166
167/**
168 * Loads one device module and call the registration entry point.
169 *
170 * @returns VBox status code.
171 * @param pVM Pointer to the VM.
172 * @param pRegCB The registration callback stuff.
173 * @param pszFilename Module filename.
174 * @param pszName Module name.
175 */
176static int pdmR3UsbLoad(PVM pVM, PCPDMUSBREGCBINT pRegCB, const char *pszFilename, const char *pszName)
177{
178 /*
179 * Load it.
180 */
181 int rc = pdmR3LoadR3U(pVM->pUVM, pszFilename, pszName);
182 if (RT_SUCCESS(rc))
183 {
184 /*
185 * Get the registration export and call it.
186 */
187 FNPDMVBOXUSBREGISTER *pfnVBoxUsbRegister;
188 rc = PDMR3LdrGetSymbolR3(pVM, pszName, "VBoxUsbRegister", (void **)&pfnVBoxUsbRegister);
189 if (RT_SUCCESS(rc))
190 {
191 Log(("PDM: Calling VBoxUsbRegister (%p) of %s (%s)\n", pfnVBoxUsbRegister, pszName, pszFilename));
192 rc = pfnVBoxUsbRegister(&pRegCB->Core, VBOX_VERSION);
193 if (RT_SUCCESS(rc))
194 Log(("PDM: Successfully loaded device module %s (%s).\n", pszName, pszFilename));
195 else
196 AssertMsgFailed(("VBoxDevicesRegister failed with rc=%Rrc for module %s (%s)\n", rc, pszName, pszFilename));
197 }
198 else
199 {
200 AssertMsgFailed(("Failed to locate 'VBoxUsbRegister' in %s (%s) rc=%Rrc\n", pszName, pszFilename, rc));
201 if (rc == VERR_SYMBOL_NOT_FOUND)
202 rc = VERR_PDM_NO_REGISTRATION_EXPORT;
203 }
204 }
205 else
206 AssertMsgFailed(("Failed to load VBoxDD!\n"));
207 return rc;
208}
209
210
211
212/**
213 * @interface_method_impl{PDMUSBREGCB,pfnRegister}
214 */
215static DECLCALLBACK(int) pdmR3UsbReg_Register(PCPDMUSBREGCB pCallbacks, PCPDMUSBREG pReg)
216{
217 /*
218 * Validate the registration structure.
219 */
220 Assert(pReg);
221 AssertMsgReturn(pReg->u32Version == PDM_USBREG_VERSION,
222 ("Unknown struct version %#x!\n", pReg->u32Version),
223 VERR_PDM_UNKNOWN_USBREG_VERSION);
224 AssertMsgReturn( pReg->szName[0]
225 && strlen(pReg->szName) < sizeof(pReg->szName)
226 && pdmR3IsValidName(pReg->szName),
227 ("Invalid name '%.s'\n", sizeof(pReg->szName), pReg->szName),
228 VERR_PDM_INVALID_USB_REGISTRATION);
229 AssertMsgReturn((pReg->fFlags & ~(PDM_USBREG_HIGHSPEED_CAPABLE)) == 0,
230 ("fFlags=%#x\n", pReg->fFlags), VERR_PDM_INVALID_USB_REGISTRATION);
231 AssertMsgReturn(pReg->cMaxInstances > 0,
232 ("Max instances %u! (USB Device %s)\n", pReg->cMaxInstances, pReg->szName),
233 VERR_PDM_INVALID_USB_REGISTRATION);
234 AssertMsgReturn(pReg->cbInstance <= _1M,
235 ("Instance size %d bytes! (USB Device %s)\n", pReg->cbInstance, pReg->szName),
236 VERR_PDM_INVALID_USB_REGISTRATION);
237 AssertMsgReturn(pReg->pfnConstruct, ("No constructor! (USB Device %s)\n", pReg->szName),
238 VERR_PDM_INVALID_USB_REGISTRATION);
239
240 /*
241 * Check for duplicate and find FIFO entry at the same time.
242 */
243 PCPDMUSBREGCBINT pRegCB = (PCPDMUSBREGCBINT)pCallbacks;
244 PPDMUSB pUsbPrev = NULL;
245 PPDMUSB pUsb = pRegCB->pVM->pdm.s.pUsbDevs;
246 for (; pUsb; pUsbPrev = pUsb, pUsb = pUsb->pNext)
247 AssertMsgReturn(strcmp(pUsb->pReg->szName, pReg->szName),
248 ("USB Device '%s' already exists\n", pReg->szName),
249 VERR_PDM_USB_NAME_CLASH);
250
251 /*
252 * Allocate new device structure and insert it into the list.
253 */
254 pUsb = (PPDMUSB)MMR3HeapAlloc(pRegCB->pVM, MM_TAG_PDM_DEVICE, sizeof(*pUsb));
255 if (pUsb)
256 {
257 pUsb->pNext = NULL;
258 pUsb->iNextInstance = 0;
259 pUsb->pInstances = NULL;
260 pUsb->pReg = pReg;
261 pUsb->cchName = (RTUINT)strlen(pReg->szName);
262
263 if (pUsbPrev)
264 pUsbPrev->pNext = pUsb;
265 else
266 pRegCB->pVM->pdm.s.pUsbDevs = pUsb;
267 Log(("PDM: Registered USB device '%s'\n", pReg->szName));
268 return VINF_SUCCESS;
269 }
270 return VERR_NO_MEMORY;
271}
272
273
274/**
275 * Load USB Device modules.
276 *
277 * This is called by pdmR3DevInit() after it has loaded it's device modules.
278 *
279 * @returns VBox status code.
280 * @param pVM Pointer to the VM.
281 */
282int pdmR3UsbLoadModules(PVM pVM)
283{
284 LogFlow(("pdmR3UsbLoadModules:\n"));
285
286 AssertRelease(!(RT_OFFSETOF(PDMUSBINS, achInstanceData) & 15));
287 AssertRelease(sizeof(pVM->pdm.s.pUsbInstances->Internal.s) <= sizeof(pVM->pdm.s.pUsbInstances->Internal.padding));
288
289 /*
290 * Initialize the callback structure.
291 */
292 PDMUSBREGCBINT RegCB;
293 RegCB.Core.u32Version = PDM_USBREG_CB_VERSION;
294 RegCB.Core.pfnRegister = pdmR3UsbReg_Register;
295 RegCB.pVM = pVM;
296
297 /*
298 * Load the builtin module
299 */
300 PCFGMNODE pUsbNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "PDM/USB/");
301 bool fLoadBuiltin;
302 int rc = CFGMR3QueryBool(pUsbNode, "LoadBuiltin", &fLoadBuiltin);
303 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
304 fLoadBuiltin = true;
305 else if (RT_FAILURE(rc))
306 {
307 AssertMsgFailed(("Configuration error: Querying boolean \"LoadBuiltin\" failed with %Rrc\n", rc));
308 return rc;
309 }
310 if (fLoadBuiltin)
311 {
312 /* make filename */
313 char *pszFilename = pdmR3FileR3("VBoxDD", true /*fShared*/);
314 if (!pszFilename)
315 return VERR_NO_TMP_MEMORY;
316 rc = pdmR3UsbLoad(pVM, &RegCB, pszFilename, "VBoxDD");
317 RTMemTmpFree(pszFilename);
318 if (RT_FAILURE(rc))
319 return rc;
320 }
321
322 /*
323 * Load additional device modules.
324 */
325 PCFGMNODE pCur;
326 for (pCur = CFGMR3GetFirstChild(pUsbNode); pCur; pCur = CFGMR3GetNextChild(pCur))
327 {
328 /*
329 * Get the name and path.
330 */
331 char szName[PDMMOD_NAME_LEN];
332 rc = CFGMR3GetName(pCur, &szName[0], sizeof(szName));
333 if (rc == VERR_CFGM_NOT_ENOUGH_SPACE)
334 {
335 AssertMsgFailed(("configuration error: The module name is too long, cchName=%zu.\n", CFGMR3GetNameLen(pCur)));
336 return VERR_PDM_MODULE_NAME_TOO_LONG;
337 }
338 else if (RT_FAILURE(rc))
339 {
340 AssertMsgFailed(("CFGMR3GetName -> %Rrc.\n", rc));
341 return rc;
342 }
343
344 /* the path is optional, if no path the module name + path is used. */
345 char szFilename[RTPATH_MAX];
346 rc = CFGMR3QueryString(pCur, "Path", &szFilename[0], sizeof(szFilename));
347 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
348 strcpy(szFilename, szName);
349 else if (RT_FAILURE(rc))
350 {
351 AssertMsgFailed(("configuration error: Failure to query the module path, rc=%Rrc.\n", rc));
352 return rc;
353 }
354
355 /* prepend path? */
356 if (!RTPathHavePath(szFilename))
357 {
358 char *psz = pdmR3FileR3(szFilename, false /*fShared*/);
359 if (!psz)
360 return VERR_NO_TMP_MEMORY;
361 size_t cch = strlen(psz) + 1;
362 if (cch > sizeof(szFilename))
363 {
364 RTMemTmpFree(psz);
365 AssertMsgFailed(("Filename too long! cch=%d '%s'\n", cch, psz));
366 return VERR_FILENAME_TOO_LONG;
367 }
368 memcpy(szFilename, psz, cch);
369 RTMemTmpFree(psz);
370 }
371
372 /*
373 * Load the module and register it's devices.
374 */
375 rc = pdmR3UsbLoad(pVM, &RegCB, szFilename, szName);
376 if (RT_FAILURE(rc))
377 return rc;
378 }
379
380 return VINF_SUCCESS;
381}
382
383
384/**
385 * Send the init-complete notification to all the USB devices.
386 *
387 * This is called from pdmR3DevInit() after it has do its notification round.
388 *
389 * @returns VBox status code.
390 * @param pVM Pointer to the VM.
391 */
392int pdmR3UsbVMInitComplete(PVM pVM)
393{
394 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
395 {
396 if (pUsbIns->pReg->pfnVMInitComplete)
397 {
398 int rc = pUsbIns->pReg->pfnVMInitComplete(pUsbIns);
399 if (RT_FAILURE(rc))
400 {
401 AssertMsgFailed(("InitComplete on USB device '%s'/%d failed with rc=%Rrc\n",
402 pUsbIns->pReg->szName, pUsbIns->iInstance, rc));
403 return rc;
404 }
405 }
406 }
407 return VINF_SUCCESS;
408}
409
410
411/**
412 * Lookups a device structure by name.
413 * @internal
414 */
415PPDMUSB pdmR3UsbLookup(PVM pVM, const char *pszName)
416{
417 size_t cchName = strlen(pszName);
418 for (PPDMUSB pUsb = pVM->pdm.s.pUsbDevs; pUsb; pUsb = pUsb->pNext)
419 if ( pUsb->cchName == cchName
420 && !strcmp(pUsb->pReg->szName, pszName))
421 return pUsb;
422 return NULL;
423}
424
425
426/**
427 * Locates a suitable hub for the specified kind of device.
428 *
429 * @returns VINF_SUCCESS and *ppHub on success.
430 * VERR_PDM_NO_USB_HUBS or VERR_PDM_NO_USB_PORTS on failure.
431 * @param pVM Pointer to the VM.
432 * @param iUsbVersion The USB device version.
433 * @param ppHub Where to store the pointer to the USB hub.
434 */
435static int pdmR3UsbFindHub(PVM pVM, uint32_t iUsbVersion, PPDMUSBHUB *ppHub)
436{
437 *ppHub = NULL;
438 if (!pVM->pdm.s.pUsbHubs)
439 return VERR_PDM_NO_USB_HUBS;
440
441 for (PPDMUSBHUB pCur = pVM->pdm.s.pUsbHubs; pCur; pCur = pCur->pNext)
442 if ( pCur->cAvailablePorts > 0
443 && ( (pCur->fVersions & iUsbVersion)
444 || pCur->fVersions == VUSB_STDVER_11))
445 {
446 *ppHub = pCur;
447 if (pCur->fVersions & iUsbVersion)
448 break;
449 }
450 if (*ppHub)
451 return VINF_SUCCESS;
452 return VERR_PDM_NO_USB_PORTS;
453}
454
455
456/**
457 * Creates the device.
458 *
459 * @returns VBox status code.
460 * @param pVM Pointer to the VM.
461 * @param pUsbDev The USB device emulation.
462 * @param iInstance -1 if not called by pdmR3UsbInstantiateDevices().
463 * @param pUuid The UUID for this device.
464 * @param pInstanceNode The instance CFGM node. NULL if not called by pdmR3UsbInstantiateDevices().
465 * @param ppConfig Pointer to the device configuration pointer. This is set to NULL if inserted
466 * into the tree or cleaned up.
467 *
468 * In the pdmR3UsbInstantiateDevices() case (pInstanceNode != NULL) this is
469 * the actual config node and will not be cleaned up.
470 *
471 * @parma iUsbVersion The USB version preferred by the device.
472 */
473static int pdmR3UsbCreateDevice(PVM pVM, PPDMUSBHUB pHub, PPDMUSB pUsbDev, int iInstance, PCRTUUID pUuid,
474 PCFGMNODE pInstanceNode, PCFGMNODE *ppConfig, uint32_t iUsbVersion)
475{
476 const bool fAtRuntime = pInstanceNode == NULL;
477 int rc;
478 NOREF(iUsbVersion);
479
480 /*
481 * If not called by pdmR3UsbInstantiateDevices(), we'll have to fix
482 * the configuration now.
483 */
484 /* USB device node. */
485 PCFGMNODE pDevNode = CFGMR3GetChildF(CFGMR3GetRoot(pVM), "USB/%s/", pUsbDev->pReg->szName);
486 if (!pDevNode)
487 {
488 rc = CFGMR3InsertNodeF(CFGMR3GetRoot(pVM), &pDevNode, "USB/%s/", pUsbDev->pReg->szName);
489 AssertRCReturn(rc, rc);
490 }
491
492 /* The instance node and number. */
493 if (!pInstanceNode)
494 {
495 for (unsigned c = 0; c < _2M; c++)
496 {
497 iInstance = pUsbDev->iNextInstance++;
498 rc = CFGMR3InsertNodeF(pDevNode, &pInstanceNode, "%d/", iInstance);
499 if (rc != VERR_CFGM_NODE_EXISTS)
500 break;
501 }
502 AssertRCReturn(rc, rc);
503 }
504 else
505 {
506 Assert(iInstance >= 0);
507 if (iInstance >= (int)pUsbDev->iNextInstance)
508 pUsbDev->iNextInstance = iInstance + 1;
509 }
510
511 /* The instance config node. */
512 PCFGMNODE pConfigToDelete = NULL;
513 PCFGMNODE pConfig = NULL;
514 if (!ppConfig || !*ppConfig)
515 {
516 rc = CFGMR3InsertNode(pInstanceNode, "Config", &pConfig);
517 AssertRCReturn(rc, rc);
518 }
519 else if (fAtRuntime)
520 {
521 rc = CFGMR3InsertSubTree(pInstanceNode, "Config", *ppConfig, &pConfig);
522 AssertRCReturn(rc, rc);
523 *ppConfig = NULL;
524 pConfigToDelete = pConfig;
525 }
526 else
527 pConfig = *ppConfig;
528 Assert(CFGMR3GetChild(pInstanceNode, "Config") == pConfig);
529
530 /* The global device config node. */
531 PCFGMNODE pGlobalConfig = CFGMR3GetChild(pDevNode, "GlobalConfig");
532 if (!pGlobalConfig)
533 {
534 rc = CFGMR3InsertNode(pDevNode, "GlobalConfig", &pGlobalConfig);
535 if (RT_FAILURE(rc))
536 {
537 CFGMR3RemoveNode(pConfigToDelete);
538 AssertRCReturn(rc, rc);
539 }
540 }
541
542 /*
543 * Allocate the device instance.
544 */
545 size_t cb = RT_OFFSETOF(PDMUSBINS, achInstanceData[pUsbDev->pReg->cbInstance]);
546 cb = RT_ALIGN_Z(cb, 16);
547 PPDMUSBINS pUsbIns;
548 rc = MMR3HeapAllocZEx(pVM, MM_TAG_PDM_USB, cb, (void **)&pUsbIns);
549 if (RT_FAILURE(rc))
550 {
551 AssertMsgFailed(("Failed to allocate %d bytes of instance data for USB device '%s'. rc=%Rrc\n",
552 cb, pUsbDev->pReg->szName, rc));
553 CFGMR3RemoveNode(pConfigToDelete);
554 return rc;
555 }
556
557 /*
558 * Initialize it.
559 */
560 pUsbIns->u32Version = PDM_USBINS_VERSION;
561 //pUsbIns->Internal.s.pNext = NULL;
562 //pUsbIns->Internal.s.pPerDeviceNext = NULL;
563 pUsbIns->Internal.s.pUsbDev = pUsbDev;
564 pUsbIns->Internal.s.pVM = pVM;
565 //pUsbIns->Internal.s.pLuns = NULL;
566 pUsbIns->Internal.s.pCfg = pInstanceNode;
567 pUsbIns->Internal.s.pCfgDelete = pConfigToDelete;
568 pUsbIns->Internal.s.pCfgGlobal = pGlobalConfig;
569 pUsbIns->Internal.s.Uuid = *pUuid;
570 //pUsbIns->Internal.s.pHub = NULL;
571 pUsbIns->Internal.s.iPort = UINT32_MAX; /* to be determined. */
572 pUsbIns->Internal.s.fVMSuspended = true;
573 //pUsbIns->Internal.s.pfnAsyncNotify = NULL;
574 pUsbIns->pHlpR3 = &g_pdmR3UsbHlp;
575 pUsbIns->pReg = pUsbDev->pReg;
576 pUsbIns->pCfg = pConfig;
577 pUsbIns->pCfgGlobal = pGlobalConfig;
578 pUsbIns->iInstance = iInstance;
579 pUsbIns->pvInstanceDataR3 = &pUsbIns->achInstanceData[0];
580 pUsbIns->pszName = RTStrDup(pUsbDev->pReg->szName);
581 //pUsbIns->fTracing = 0;
582 pUsbIns->idTracing = ++pVM->pdm.s.idTracingOther;
583 pUsbIns->iUsbHubVersion = iUsbVersion;
584
585 /*
586 * Link it into all the lists.
587 */
588 /* The global instance FIFO. */
589 PPDMUSBINS pPrev1 = pVM->pdm.s.pUsbInstances;
590 if (!pPrev1)
591 pVM->pdm.s.pUsbInstances = pUsbIns;
592 else
593 {
594 while (pPrev1->Internal.s.pNext)
595 {
596 Assert(pPrev1->u32Version == PDM_USBINS_VERSION);
597 pPrev1 = pPrev1->Internal.s.pNext;
598 }
599 pPrev1->Internal.s.pNext = pUsbIns;
600 }
601
602 /* The per device instance FIFO. */
603 PPDMUSBINS pPrev2 = pUsbDev->pInstances;
604 if (!pPrev2)
605 pUsbDev->pInstances = pUsbIns;
606 else
607 {
608 while (pPrev2->Internal.s.pPerDeviceNext)
609 {
610 Assert(pPrev2->u32Version == PDM_USBINS_VERSION);
611 pPrev2 = pPrev2->Internal.s.pPerDeviceNext;
612 }
613 pPrev2->Internal.s.pPerDeviceNext = pUsbIns;
614 }
615
616 /*
617 * Call the constructor.
618 */
619 Log(("PDM: Constructing USB device '%s' instance %d...\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
620 rc = pUsbIns->pReg->pfnConstruct(pUsbIns, pUsbIns->iInstance, pUsbIns->pCfg, pUsbIns->pCfgGlobal);
621 if (RT_SUCCESS(rc))
622 {
623 /*
624 * Attach it to the hub.
625 */
626 Log(("PDM: Attaching it...\n"));
627 rc = pHub->Reg.pfnAttachDevice(pHub->pDrvIns, pUsbIns, &pUsbIns->Internal.s.iPort);
628 if (RT_SUCCESS(rc))
629 {
630 pHub->cAvailablePorts--;
631 Assert((int32_t)pHub->cAvailablePorts >= 0 && pHub->cAvailablePorts < pHub->cPorts);
632 pUsbIns->Internal.s.pHub = pHub;
633
634 /* Send the hot-plugged notification if applicable. */
635 if (fAtRuntime && pUsbIns->pReg->pfnHotPlugged)
636 pUsbIns->pReg->pfnHotPlugged(pUsbIns);
637
638 Log(("PDM: Successfully attached USB device '%s' instance %d to hub %p\n",
639 pUsbIns->pReg->szName, pUsbIns->iInstance, pHub));
640 return VINF_SUCCESS;
641 }
642
643 LogRel(("PDM: Failed to attach USB device '%s' instance %d to hub %p: %Rrc\n",
644 pUsbIns->pReg->szName, pUsbIns->iInstance, pHub, rc));
645 }
646 else
647 {
648 AssertMsgFailed(("Failed to construct '%s'/%d! %Rra\n", pUsbIns->pReg->szName, pUsbIns->iInstance, rc));
649 if (rc == VERR_VERSION_MISMATCH)
650 rc = VERR_PDM_DRIVER_VERSION_MISMATCH;
651 }
652 if (fAtRuntime)
653 pdmR3UsbDestroyDevice(pVM, pUsbIns);
654 /* else: destructors are invoked later. */
655 return rc;
656}
657
658
659/**
660 * Instantiate USB devices.
661 *
662 * This is called by pdmR3DevInit() after it has instantiated the
663 * other devices and their drivers. If there aren't any hubs
664 * around, we'll silently skip the USB devices.
665 *
666 * @returns VBox status code.
667 * @param pVM
668 */
669int pdmR3UsbInstantiateDevices(PVM pVM)
670{
671 /*
672 * Any hubs?
673 */
674 if (!pVM->pdm.s.pUsbHubs)
675 {
676 Log(("PDM: No USB hubs, skipping USB device instantiation.\n"));
677 return VINF_SUCCESS;
678 }
679
680 /*
681 * Count the device instances.
682 */
683 PCFGMNODE pCur;
684 PCFGMNODE pUsbNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "USB/");
685 PCFGMNODE pInstanceNode;
686 unsigned cUsbDevs = 0;
687 for (pCur = CFGMR3GetFirstChild(pUsbNode); pCur; pCur = CFGMR3GetNextChild(pCur))
688 {
689 PCFGMNODE pGlobal = CFGMR3GetChild(pCur, "GlobalConfig/");
690 for (pInstanceNode = CFGMR3GetFirstChild(pCur); pInstanceNode; pInstanceNode = CFGMR3GetNextChild(pInstanceNode))
691 if (pInstanceNode != pGlobal)
692 cUsbDevs++;
693 }
694 if (!cUsbDevs)
695 {
696 Log(("PDM: No USB devices were configured!\n"));
697 return VINF_SUCCESS;
698 }
699 Log2(("PDM: cUsbDevs=%d!\n", cUsbDevs));
700
701 /*
702 * Collect info on each USB device instance.
703 */
704 struct USBDEVORDER
705 {
706 /** Configuration node. */
707 PCFGMNODE pNode;
708 /** Pointer to the USB device. */
709 PPDMUSB pUsbDev;
710 /** Init order. */
711 uint32_t u32Order;
712 /** VBox instance number. */
713 uint32_t iInstance;
714 } *paUsbDevs = (struct USBDEVORDER *)alloca(sizeof(paUsbDevs[0]) * (cUsbDevs + 1)); /* (One extra for swapping) */
715 Assert(paUsbDevs);
716 int rc;
717 unsigned i = 0;
718 for (pCur = CFGMR3GetFirstChild(pUsbNode); pCur; pCur = CFGMR3GetNextChild(pCur))
719 {
720 /* Get the device name. */
721 char szName[sizeof(paUsbDevs[0].pUsbDev->pReg->szName)];
722 rc = CFGMR3GetName(pCur, szName, sizeof(szName));
723 AssertMsgRCReturn(rc, ("Configuration error: device name is too long (or something)! rc=%Rrc\n", rc), rc);
724
725 /* Find the device. */
726 PPDMUSB pUsbDev = pdmR3UsbLookup(pVM, szName);
727 AssertMsgReturn(pUsbDev, ("Configuration error: device '%s' not found!\n", szName), VERR_PDM_DEVICE_NOT_FOUND);
728
729 /* Configured priority or use default? */
730 uint32_t u32Order;
731 rc = CFGMR3QueryU32(pCur, "Priority", &u32Order);
732 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
733 u32Order = i << 4;
734 else
735 AssertMsgRCReturn(rc, ("Configuration error: reading \"Priority\" for the '%s' USB device failed rc=%Rrc!\n", szName, rc), rc);
736
737 /* Global config. */
738 PCFGMNODE pGlobal = CFGMR3GetChild(pCur, "GlobalConfig/");
739 if (!pGlobal)
740 {
741 rc = CFGMR3InsertNode(pCur, "GlobalConfig/", &pGlobal);
742 AssertMsgRCReturn(rc, ("Failed to create GlobalConfig node! rc=%Rrc\n", rc), rc);
743 CFGMR3SetRestrictedRoot(pGlobal);
744 }
745
746 /* Enumerate the device instances. */
747 for (pInstanceNode = CFGMR3GetFirstChild(pCur); pInstanceNode; pInstanceNode = CFGMR3GetNextChild(pInstanceNode))
748 {
749 if (pInstanceNode == pGlobal)
750 continue;
751
752 paUsbDevs[i].pNode = pInstanceNode;
753 paUsbDevs[i].pUsbDev = pUsbDev;
754 paUsbDevs[i].u32Order = u32Order;
755
756 /* Get the instance number. */
757 char szInstance[32];
758 rc = CFGMR3GetName(pInstanceNode, szInstance, sizeof(szInstance));
759 AssertMsgRCReturn(rc, ("Configuration error: instance name is too long (or something)! rc=%Rrc\n", rc), rc);
760 char *pszNext = NULL;
761 rc = RTStrToUInt32Ex(szInstance, &pszNext, 0, &paUsbDevs[i].iInstance);
762 AssertMsgRCReturn(rc, ("Configuration error: RTStrToInt32Ex failed on the instance name '%s'! rc=%Rrc\n", szInstance, rc), rc);
763 AssertMsgReturn(!*pszNext, ("Configuration error: the instance name '%s' isn't all digits. (%s)\n", szInstance, pszNext), VERR_INVALID_PARAMETER);
764
765 /* next instance */
766 i++;
767 }
768 } /* devices */
769 Assert(i == cUsbDevs);
770
771 /*
772 * Sort the device array ascending on u32Order. (bubble)
773 */
774 unsigned c = cUsbDevs - 1;
775 while (c)
776 {
777 unsigned j = 0;
778 for (i = 0; i < c; i++)
779 if (paUsbDevs[i].u32Order > paUsbDevs[i + 1].u32Order)
780 {
781 paUsbDevs[cUsbDevs] = paUsbDevs[i + 1];
782 paUsbDevs[i + 1] = paUsbDevs[i];
783 paUsbDevs[i] = paUsbDevs[cUsbDevs];
784 j = i;
785 }
786 c = j;
787 }
788
789 /*
790 * Instantiate the devices.
791 */
792 for (i = 0; i < cUsbDevs; i++)
793 {
794 /*
795 * Make sure there is a config node and mark it as restricted.
796 */
797 PCFGMNODE pConfigNode = CFGMR3GetChild(paUsbDevs[i].pNode, "Config/");
798 if (!pConfigNode)
799 {
800 rc = CFGMR3InsertNode(paUsbDevs[i].pNode, "Config", &pConfigNode);
801 AssertMsgRCReturn(rc, ("Failed to create Config node! rc=%Rrc\n", rc), rc);
802 }
803 CFGMR3SetRestrictedRoot(pConfigNode);
804
805 /*
806 * Every device must support USB 1.x hubs; optionally, high-speed USB 2.0 hubs
807 * might be also supported. This determines where to attach the device.
808 */
809 uint32_t iUsbVersion = VUSB_STDVER_11;
810
811 if (paUsbDevs[i].pUsbDev->pReg->fFlags & PDM_USBREG_HIGHSPEED_CAPABLE)
812 iUsbVersion |= VUSB_STDVER_20;
813
814 /*
815 * Find a suitable hub with free ports.
816 */
817 PPDMUSBHUB pHub;
818 rc = pdmR3UsbFindHub(pVM, iUsbVersion, &pHub);
819 if (RT_FAILURE(rc))
820 {
821 Log(("pdmR3UsbFindHub failed %Rrc\n", rc));
822 return rc;
823 }
824
825 /*
826 * This is how we inform the device what speed it's communicating at, and hence
827 * which descriptors it should present to the guest.
828 */
829 iUsbVersion &= pHub->fVersions;
830
831 /*
832 * Create and attach the device.
833 */
834 RTUUID Uuid;
835 rc = RTUuidCreate(&Uuid);
836 AssertRCReturn(rc, rc);
837 rc = pdmR3UsbCreateDevice(pVM, pHub, paUsbDevs[i].pUsbDev, paUsbDevs[i].iInstance, &Uuid, paUsbDevs[i].pNode, &pConfigNode, iUsbVersion);
838 if (RT_FAILURE(rc))
839 return rc;
840 } /* for device instances */
841
842 return VINF_SUCCESS;
843}
844
845
846/**
847 * Creates a USB proxy device instance.
848 *
849 * This will find an appropriate HUB for the USB device, create the necessary CFGM stuff
850 * and try instantiate the proxy device.
851 *
852 * @returns VBox status code.
853 * @param pUVM The user mode VM handle.
854 * @param pUuid The UUID to be associated with the device.
855 * @param fRemote Whether it's a remove or local device.
856 * @param pszAddress The address string.
857 * @param pvBackend Pointer to the backend.
858 * @param iUsbVersion The preferred USB version.
859 * @param fMaskedIfs The interfaces to hide from the guest.
860 */
861VMMR3DECL(int) PDMR3UsbCreateProxyDevice(PUVM pUVM, PCRTUUID pUuid, bool fRemote, const char *pszAddress, void *pvBackend,
862 uint32_t iUsbVersion, uint32_t fMaskedIfs)
863{
864 /*
865 * Validate input.
866 */
867 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
868 PVM pVM = pUVM->pVM;
869 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
870 VM_ASSERT_EMT(pVM);
871 AssertPtrReturn(pUuid, VERR_INVALID_POINTER);
872 AssertPtrReturn(pszAddress, VERR_INVALID_POINTER);
873 AssertReturn( iUsbVersion == VUSB_STDVER_20
874 || iUsbVersion == VUSB_STDVER_11, VERR_INVALID_PARAMETER);
875
876 /*
877 * Find the USBProxy driver.
878 */
879 PPDMUSB pUsbDev = pdmR3UsbLookup(pVM, "USBProxy");
880 if (!pUsbDev)
881 {
882 LogRel(("PDMR3UsbCreateProxyDevice: The USBProxy device class wasn't found\n"));
883 return VERR_PDM_NO_USBPROXY;
884 }
885
886 /*
887 * Find a suitable hub with free ports.
888 */
889 PPDMUSBHUB pHub;
890 int rc = pdmR3UsbFindHub(pVM, iUsbVersion, &pHub);
891 if (RT_FAILURE(rc))
892 {
893 Log(("pdmR3UsbFindHub: failed %Rrc\n", rc));
894 return rc;
895 }
896
897 /*
898 * Create the CFGM configuration node.
899 */
900 PCFGMNODE pConfig = CFGMR3CreateTree(pUVM);
901 AssertReturn(pConfig, VERR_NO_MEMORY);
902 do /* break loop */
903 {
904 rc = CFGMR3InsertString(pConfig, "Address", pszAddress); AssertRCBreak(rc);
905 char szUuid[RTUUID_STR_LENGTH];
906 rc = RTUuidToStr(pUuid, &szUuid[0], sizeof(szUuid)); AssertRCBreak(rc);
907 rc = CFGMR3InsertString(pConfig, "UUID", szUuid); AssertRCBreak(rc);
908 rc = CFGMR3InsertInteger(pConfig, "Remote", fRemote); AssertRCBreak(rc);
909 rc = CFGMR3InsertInteger(pConfig, "USBVersion", iUsbVersion); AssertRCBreak(rc);
910 rc = CFGMR3InsertInteger(pConfig, "pvBackend", (uintptr_t)pvBackend); AssertRCBreak(rc);
911 rc = CFGMR3InsertInteger(pConfig, "MaskedIfs", fMaskedIfs); AssertRCBreak(rc);
912 rc = CFGMR3InsertInteger(pConfig, "Force11Device", !(pHub->fVersions & iUsbVersion)); AssertRCBreak(rc);
913 } while (0); /* break loop */
914 if (RT_FAILURE(rc))
915 {
916 CFGMR3RemoveNode(pConfig);
917 LogRel(("PDMR3UsbCreateProxyDevice: failed to setup CFGM config, rc=%Rrc\n", rc));
918 return rc;
919 }
920
921 /*
922 * Finally, try to create it.
923 */
924 rc = pdmR3UsbCreateDevice(pVM, pHub, pUsbDev, -1, pUuid, NULL, &pConfig, iUsbVersion);
925 if (RT_FAILURE(rc) && pConfig)
926 CFGMR3RemoveNode(pConfig);
927 return rc;
928}
929
930
931/**
932 * Destroys a hot-plugged USB device.
933 *
934 * The device must be detached from the HUB at this point.
935 *
936 * @param pVM Pointer to the VM.
937 * @param pUsbIns The USB device instance to destroy.
938 * @thread EMT
939 */
940static void pdmR3UsbDestroyDevice(PVM pVM, PPDMUSBINS pUsbIns)
941{
942 Assert(!pUsbIns->Internal.s.pHub);
943
944 /*
945 * Do the unplug notification.
946 */
947 /** @todo what about the drivers? */
948 if (pUsbIns->pReg->pfnHotUnplugged)
949 pUsbIns->pReg->pfnHotUnplugged(pUsbIns);
950
951 /*
952 * Destroy the luns with their driver chains and call the device destructor.
953 */
954 while (pUsbIns->Internal.s.pLuns)
955 {
956 PPDMLUN pLun = pUsbIns->Internal.s.pLuns;
957 pUsbIns->Internal.s.pLuns = pLun->pNext;
958 if (pLun->pTop)
959 pdmR3DrvDestroyChain(pLun->pTop, PDM_TACH_FLAGS_NOT_HOT_PLUG); /* Hotplugging is handled differently here atm. */
960 MMR3HeapFree(pLun);
961 }
962
963 /* finally, the device. */
964 if (pUsbIns->pReg->pfnDestruct)
965 {
966 Log(("PDM: Destructing USB device '%s' instance %d...\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
967 pUsbIns->pReg->pfnDestruct(pUsbIns);
968 }
969 TMR3TimerDestroyUsb(pVM, pUsbIns);
970 //SSMR3DeregisterUsb(pVM, pUsbIns, NULL, 0);
971 pdmR3ThreadDestroyUsb(pVM, pUsbIns);
972#ifdef VBOX_WITH_PDM_ASYNC_COMPLETION
973 pdmR3AsyncCompletionTemplateDestroyUsb(pVM, pUsbIns);
974#endif
975
976 /*
977 * Unlink it.
978 */
979 /* The global instance FIFO. */
980 if (pVM->pdm.s.pUsbInstances == pUsbIns)
981 pVM->pdm.s.pUsbInstances = pUsbIns->Internal.s.pNext;
982 else
983 {
984 PPDMUSBINS pPrev = pVM->pdm.s.pUsbInstances;
985 while (pPrev && pPrev->Internal.s.pNext != pUsbIns)
986 {
987 Assert(pPrev->u32Version == PDM_USBINS_VERSION);
988 pPrev = pPrev->Internal.s.pNext;
989 }
990 Assert(pPrev); Assert(pPrev != pUsbIns);
991 if (pPrev)
992 pPrev->Internal.s.pNext = pUsbIns->Internal.s.pNext;
993 }
994
995 /* The per device instance FIFO. */
996 PPDMUSB pUsbDev = pUsbIns->Internal.s.pUsbDev;
997 if (pUsbDev->pInstances == pUsbIns)
998 pUsbDev->pInstances = pUsbIns->Internal.s.pPerDeviceNext;
999 else
1000 {
1001 PPDMUSBINS pPrev = pUsbDev->pInstances;
1002 while (pPrev && pPrev->Internal.s.pPerDeviceNext != pUsbIns)
1003 {
1004 Assert(pPrev->u32Version == PDM_USBINS_VERSION);
1005 pPrev = pPrev->Internal.s.pPerDeviceNext;
1006 }
1007 Assert(pPrev); Assert(pPrev != pUsbIns);
1008 if (pPrev)
1009 pPrev->Internal.s.pPerDeviceNext = pUsbIns->Internal.s.pPerDeviceNext;
1010 }
1011
1012 /*
1013 * Trash it.
1014 */
1015 pUsbIns->u32Version = 0;
1016 pUsbIns->pReg = NULL;
1017 if (pUsbIns->pszName)
1018 {
1019 RTStrFree(pUsbIns->pszName);
1020 pUsbIns->pszName = NULL;
1021 }
1022 CFGMR3RemoveNode(pUsbIns->Internal.s.pCfgDelete);
1023 MMR3HeapFree(pUsbIns);
1024}
1025
1026
1027/**
1028 * Detaches and destroys a USB device.
1029 *
1030 * @returns VBox status code.
1031 * @param pUVM The user mode VM handle.
1032 * @param pUuid The UUID associated with the device to detach.
1033 * @thread EMT
1034 */
1035VMMR3DECL(int) PDMR3UsbDetachDevice(PUVM pUVM, PCRTUUID pUuid)
1036{
1037 /*
1038 * Validate input.
1039 */
1040 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
1041 PVM pVM = pUVM->pVM;
1042 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
1043 VM_ASSERT_EMT(pVM);
1044 AssertPtrReturn(pUuid, VERR_INVALID_POINTER);
1045
1046 /*
1047 * Search the global list for it.
1048 */
1049 PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances;
1050 for ( ; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext)
1051 if (!RTUuidCompare(&pUsbIns->Internal.s.Uuid, pUuid))
1052 break;
1053 if (!pUsbIns)
1054 return VERR_PDM_DEVICE_INSTANCE_NOT_FOUND; /** @todo VERR_PDM_USB_INSTANCE_NOT_FOUND */
1055
1056 /*
1057 * Detach it from the HUB (if it's actually attached to one).
1058 */
1059 PPDMUSBHUB pHub = pUsbIns->Internal.s.pHub;
1060 if (pHub)
1061 {
1062 int rc = pHub->Reg.pfnDetachDevice(pHub->pDrvIns, pUsbIns, pUsbIns->Internal.s.iPort);
1063 if (RT_FAILURE(rc))
1064 {
1065 LogRel(("PDM: Failed to detach USB device '%s' instance %d from %p: %Rrc\n",
1066 pUsbIns->pReg->szName, pUsbIns->iInstance, pHub, rc));
1067 return rc;
1068 }
1069
1070 pHub->cAvailablePorts++;
1071 Assert(pHub->cAvailablePorts > 0 && pHub->cAvailablePorts <= pHub->cPorts);
1072 pUsbIns->Internal.s.pHub = NULL;
1073 }
1074
1075 /*
1076 * Notify about unplugging and destroy the device with it's drivers.
1077 */
1078 pdmR3UsbDestroyDevice(pVM, pUsbIns);
1079
1080 return VINF_SUCCESS;
1081}
1082
1083
1084/**
1085 * Checks if there are any USB hubs attached.
1086 *
1087 * @returns true / false accordingly.
1088 * @param pUVM The user mode VM handle.
1089 */
1090VMMR3DECL(bool) PDMR3UsbHasHub(PUVM pUVM)
1091{
1092 UVM_ASSERT_VALID_EXT_RETURN(pUVM, false);
1093 PVM pVM = pUVM->pVM;
1094 VM_ASSERT_VALID_EXT_RETURN(pVM, false);
1095 return pVM->pdm.s.pUsbHubs != NULL;
1096}
1097
1098
1099/** @name USB Device Helpers
1100 * @{
1101 */
1102
1103/** @interface_method_impl{PDMUSBHLPR3,pfnDriverAttach} */
1104static DECLCALLBACK(int) pdmR3UsbHlp_DriverAttach(PPDMUSBINS pUsbIns, RTUINT iLun, PPDMIBASE pBaseInterface,
1105 PPDMIBASE *ppBaseInterface, const char *pszDesc)
1106{
1107 PDMUSB_ASSERT_USBINS(pUsbIns);
1108 PVM pVM = pUsbIns->Internal.s.pVM;
1109 VM_ASSERT_EMT(pVM);
1110 LogFlow(("pdmR3UsbHlp_DriverAttach: caller='%s'/%d: iLun=%d pBaseInterface=%p ppBaseInterface=%p pszDesc=%p:{%s}\n",
1111 pUsbIns->pReg->szName, pUsbIns->iInstance, iLun, pBaseInterface, ppBaseInterface, pszDesc, pszDesc));
1112
1113 /*
1114 * Lookup the LUN, it might already be registered.
1115 */
1116 PPDMLUN pLunPrev = NULL;
1117 PPDMLUN pLun = pUsbIns->Internal.s.pLuns;
1118 for (; pLun; pLunPrev = pLun, pLun = pLun->pNext)
1119 if (pLun->iLun == iLun)
1120 break;
1121
1122 /*
1123 * Create the LUN if if wasn't found, else check if driver is already attached to it.
1124 */
1125 if (!pLun)
1126 {
1127 if ( !pBaseInterface
1128 || !pszDesc
1129 || !*pszDesc)
1130 {
1131 Assert(pBaseInterface);
1132 Assert(pszDesc || *pszDesc);
1133 return VERR_INVALID_PARAMETER;
1134 }
1135
1136 pLun = (PPDMLUN)MMR3HeapAlloc(pVM, MM_TAG_PDM_LUN, sizeof(*pLun));
1137 if (!pLun)
1138 return VERR_NO_MEMORY;
1139
1140 pLun->iLun = iLun;
1141 pLun->pNext = pLunPrev ? pLunPrev->pNext : NULL;
1142 pLun->pTop = NULL;
1143 pLun->pBottom = NULL;
1144 pLun->pDevIns = NULL;
1145 pLun->pUsbIns = pUsbIns;
1146 pLun->pszDesc = pszDesc;
1147 pLun->pBase = pBaseInterface;
1148 if (!pLunPrev)
1149 pUsbIns->Internal.s.pLuns = pLun;
1150 else
1151 pLunPrev->pNext = pLun;
1152 Log(("pdmR3UsbHlp_DriverAttach: Registered LUN#%d '%s' with device '%s'/%d.\n",
1153 iLun, pszDesc, pUsbIns->pReg->szName, pUsbIns->iInstance));
1154 }
1155 else if (pLun->pTop)
1156 {
1157 AssertMsgFailed(("Already attached! The device should keep track of such things!\n"));
1158 LogFlow(("pdmR3UsbHlp_DriverAttach: caller='%s'/%d: returns %Rrc\n", pUsbIns->pReg->szName, pUsbIns->iInstance, VERR_PDM_DRIVER_ALREADY_ATTACHED));
1159 return VERR_PDM_DRIVER_ALREADY_ATTACHED;
1160 }
1161 Assert(pLun->pBase == pBaseInterface);
1162
1163
1164 /*
1165 * Get the attached driver configuration.
1166 */
1167 int rc;
1168 PCFGMNODE pNode = CFGMR3GetChildF(pUsbIns->Internal.s.pCfg, "LUN#%u", iLun);
1169 if (pNode)
1170 rc = pdmR3DrvInstantiate(pVM, pNode, pBaseInterface, NULL /*pDrvAbove*/, pLun, ppBaseInterface);
1171 else
1172 rc = VERR_PDM_NO_ATTACHED_DRIVER;
1173
1174
1175 LogFlow(("pdmR3UsbHlp_DriverAttach: caller='%s'/%d: returns %Rrc\n", pUsbIns->pReg->szName, pUsbIns->iInstance, rc));
1176 return rc;
1177}
1178
1179
1180/** @interface_method_impl{PDMUSBHLP,pfnAssertEMT} */
1181static DECLCALLBACK(bool) pdmR3UsbHlp_AssertEMT(PPDMUSBINS pUsbIns, const char *pszFile, unsigned iLine, const char *pszFunction)
1182{
1183 PDMUSB_ASSERT_USBINS(pUsbIns);
1184 if (VM_IS_EMT(pUsbIns->Internal.s.pVM))
1185 return true;
1186
1187 char szMsg[100];
1188 RTStrPrintf(szMsg, sizeof(szMsg), "AssertEMT '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance);
1189 RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
1190 AssertBreakpoint();
1191 return false;
1192}
1193
1194
1195/** @interface_method_impl{PDMUSBHLP,pfnAssertOther} */
1196static DECLCALLBACK(bool) pdmR3UsbHlp_AssertOther(PPDMUSBINS pUsbIns, const char *pszFile, unsigned iLine, const char *pszFunction)
1197{
1198 PDMUSB_ASSERT_USBINS(pUsbIns);
1199 if (!VM_IS_EMT(pUsbIns->Internal.s.pVM))
1200 return true;
1201
1202 char szMsg[100];
1203 RTStrPrintf(szMsg, sizeof(szMsg), "AssertOther '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance);
1204 RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
1205 AssertBreakpoint();
1206 return false;
1207}
1208
1209
1210/** @interface_method_impl{PDMUSBHLP,pfnDBGFStopV} */
1211static DECLCALLBACK(int) pdmR3UsbHlp_DBGFStopV(PPDMUSBINS pUsbIns, const char *pszFile, unsigned iLine, const char *pszFunction, const char *pszFormat, va_list args)
1212{
1213 PDMUSB_ASSERT_USBINS(pUsbIns);
1214#ifdef LOG_ENABLED
1215 va_list va2;
1216 va_copy(va2, args);
1217 LogFlow(("pdmR3UsbHlp_DBGFStopV: caller='%s'/%d: pszFile=%p:{%s} iLine=%d pszFunction=%p:{%s} pszFormat=%p:{%s} (%N)\n",
1218 pUsbIns->pReg->szName, pUsbIns->iInstance, pszFile, pszFile, iLine, pszFunction, pszFunction, pszFormat, pszFormat, pszFormat, &va2));
1219 va_end(va2);
1220#endif
1221
1222 PVM pVM = pUsbIns->Internal.s.pVM;
1223 VM_ASSERT_EMT(pVM);
1224 int rc = DBGFR3EventSrcV(pVM, DBGFEVENT_DEV_STOP, pszFile, iLine, pszFunction, pszFormat, args);
1225 if (rc == VERR_DBGF_NOT_ATTACHED)
1226 rc = VINF_SUCCESS;
1227
1228 LogFlow(("pdmR3UsbHlp_DBGFStopV: caller='%s'/%d: returns %Rrc\n", pUsbIns->pReg->szName, pUsbIns->iInstance, rc));
1229 return rc;
1230}
1231
1232
1233/** @interface_method_impl{PDMUSBHLP,pfnDBGFInfoRegister} */
1234static DECLCALLBACK(int) pdmR3UsbHlp_DBGFInfoRegister(PPDMUSBINS pUsbIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERUSB pfnHandler)
1235{
1236 PDMUSB_ASSERT_USBINS(pUsbIns);
1237 LogFlow(("pdmR3UsbHlp_DBGFInfoRegister: caller='%s'/%d: pszName=%p:{%s} pszDesc=%p:{%s} pfnHandler=%p\n",
1238 pUsbIns->pReg->szName, pUsbIns->iInstance, pszName, pszName, pszDesc, pszDesc, pfnHandler));
1239
1240 PVM pVM = pUsbIns->Internal.s.pVM;
1241 VM_ASSERT_EMT(pVM);
1242 NOREF(pVM); /** @todo int rc = DBGFR3InfoRegisterUsb(pVM, pszName, pszDesc, pfnHandler, pUsbIns); */
1243 int rc = VERR_NOT_IMPLEMENTED; AssertFailed();
1244
1245 LogFlow(("pdmR3UsbHlp_DBGFInfoRegister: caller='%s'/%d: returns %Rrc\n", pUsbIns->pReg->szName, pUsbIns->iInstance, rc));
1246 return rc;
1247}
1248
1249
1250/** @interface_method_impl{PDMUSBHLP,pfnMMHeapAlloc} */
1251static DECLCALLBACK(void *) pdmR3UsbHlp_MMHeapAlloc(PPDMUSBINS pUsbIns, size_t cb)
1252{
1253 PDMUSB_ASSERT_USBINS(pUsbIns);
1254 LogFlow(("pdmR3UsbHlp_MMHeapAlloc: caller='%s'/%d: cb=%#x\n", pUsbIns->pReg->szName, pUsbIns->iInstance, cb));
1255
1256 void *pv = MMR3HeapAlloc(pUsbIns->Internal.s.pVM, MM_TAG_PDM_USB_USER, cb);
1257
1258 LogFlow(("pdmR3UsbHlp_MMHeapAlloc: caller='%s'/%d: returns %p\n", pUsbIns->pReg->szName, pUsbIns->iInstance, pv));
1259 return pv;
1260}
1261
1262
1263/** @interface_method_impl{PDMUSBHLP,pfnMMHeapAllocZ} */
1264static DECLCALLBACK(void *) pdmR3UsbHlp_MMHeapAllocZ(PPDMUSBINS pUsbIns, size_t cb)
1265{
1266 PDMUSB_ASSERT_USBINS(pUsbIns);
1267 LogFlow(("pdmR3UsbHlp_MMHeapAllocZ: caller='%s'/%d: cb=%#x\n", pUsbIns->pReg->szName, pUsbIns->iInstance, cb));
1268
1269 void *pv = MMR3HeapAllocZ(pUsbIns->Internal.s.pVM, MM_TAG_PDM_USB_USER, cb);
1270
1271 LogFlow(("pdmR3UsbHlp_MMHeapAllocZ: caller='%s'/%d: returns %p\n", pUsbIns->pReg->szName, pUsbIns->iInstance, pv));
1272 return pv;
1273}
1274
1275
1276/** @interface_method_impl{PDMUSBHLP,pfnPDMQueueCreate} */
1277static DECLCALLBACK(int) pdmR3UsbHlp_PDMQueueCreate(PPDMUSBINS pUsbIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval,
1278 PFNPDMQUEUEUSB pfnCallback, const char *pszName, PPDMQUEUE *ppQueue)
1279{
1280 PDMUSB_ASSERT_USBINS(pUsbIns);
1281 LogFlow(("pdmR3UsbHlp_PDMQueueCreate: caller='%s'/%d: cbItem=%#x cItems=%#x cMilliesInterval=%u pfnCallback=%p pszName=%p:{%s} ppQueue=%p\n",
1282 pUsbIns->pReg->szName, pUsbIns->iInstance, cbItem, cItems, cMilliesInterval, pfnCallback, pszName, pszName, ppQueue));
1283
1284 PVM pVM = pUsbIns->Internal.s.pVM;
1285 VM_ASSERT_EMT(pVM);
1286
1287 if (pUsbIns->iInstance > 0)
1288 {
1289 pszName = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DEVICE_DESC, "%s_%u", pszName, pUsbIns->iInstance);
1290 AssertLogRelReturn(pszName, VERR_NO_MEMORY);
1291 }
1292
1293 /** @todo int rc = PDMR3QueueCreateUsb(pVM, pUsbIns, cbItem, cItems, cMilliesInterval, pfnCallback, fGCEnabled, pszName, ppQueue); */
1294 int rc = VERR_NOT_IMPLEMENTED; AssertFailed();
1295
1296 LogFlow(("pdmR3UsbHlp_PDMQueueCreate: caller='%s'/%d: returns %Rrc *ppQueue=%p\n", pUsbIns->pReg->szName, pUsbIns->iInstance, rc, *ppQueue));
1297 return rc;
1298}
1299
1300
1301/** @interface_method_impl{PDMUSBHLP,pfnSSMRegister} */
1302static DECLCALLBACK(int) pdmR3UsbHlp_SSMRegister(PPDMUSBINS pUsbIns, uint32_t uVersion, size_t cbGuess,
1303 PFNSSMUSBLIVEPREP pfnLivePrep, PFNSSMUSBLIVEEXEC pfnLiveExec, PFNSSMUSBLIVEVOTE pfnLiveVote,
1304 PFNSSMUSBSAVEPREP pfnSavePrep, PFNSSMUSBSAVEEXEC pfnSaveExec, PFNSSMUSBSAVEDONE pfnSaveDone,
1305 PFNSSMUSBLOADPREP pfnLoadPrep, PFNSSMUSBLOADEXEC pfnLoadExec, PFNSSMUSBLOADDONE pfnLoadDone)
1306{
1307 PDMUSB_ASSERT_USBINS(pUsbIns);
1308 VM_ASSERT_EMT(pUsbIns->Internal.s.pVM);
1309 LogFlow(("pdmR3UsbHlp_SSMRegister: caller='%s'/%d: uVersion=#x cbGuess=%#x\n"
1310 " pfnLivePrep=%p pfnLiveExec=%p pfnLiveVote=%p pfnSavePrep=%p pfnSaveExec=%p pfnSaveDone=%p pszLoadPrep=%p pfnLoadExec=%p pfnLoadDone=%p\n",
1311 pUsbIns->pReg->szName, pUsbIns->iInstance, uVersion, cbGuess,
1312 pfnLivePrep, pfnLiveExec, pfnLiveVote,
1313 pfnSavePrep, pfnSaveExec, pfnSaveDone,
1314 pfnLoadPrep, pfnLoadExec, pfnLoadDone));
1315
1316 /** @todo
1317 int rc = SSMR3RegisterUsb(pUsbIns->Internal.s.pVM, pUsbIns, pUsbIns->pReg->szName, pUsbIns->iInstance,
1318 uVersion, cbGuess,
1319 pfnLivePrep, pfnLiveExec, pfnLiveVote,
1320 pfnSavePrep, pfnSaveExec, pfnSaveDone,
1321 pfnLoadPrep, pfnLoadExec, pfnLoadDone); */
1322 int rc = VERR_NOT_IMPLEMENTED; AssertFailed();
1323
1324 LogFlow(("pdmR3UsbHlp_SSMRegister: caller='%s'/%d: returns %Rrc\n", pUsbIns->pReg->szName, pUsbIns->iInstance, rc));
1325 return rc;
1326}
1327
1328
1329/** @interface_method_impl{PDMUSBHLP,pfnSTAMRegisterV} */
1330static DECLCALLBACK(void) pdmR3UsbHlp_STAMRegisterV(PPDMUSBINS pUsbIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
1331 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args)
1332{
1333 PDMUSB_ASSERT_USBINS(pUsbIns);
1334 PVM pVM = pUsbIns->Internal.s.pVM;
1335 VM_ASSERT_EMT(pVM);
1336
1337 int rc = STAMR3RegisterV(pVM, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
1338 AssertRC(rc);
1339
1340 NOREF(pVM);
1341}
1342
1343
1344/** @interface_method_impl{PDMUSBHLP,pfnTMTimerCreate} */
1345static DECLCALLBACK(int) pdmR3UsbHlp_TMTimerCreate(PPDMUSBINS pUsbIns, TMCLOCK enmClock, PFNTMTIMERUSB pfnCallback, void *pvUser,
1346 uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer)
1347{
1348 PDMUSB_ASSERT_USBINS(pUsbIns);
1349 PVM pVM = pUsbIns->Internal.s.pVM;
1350 VM_ASSERT_EMT(pVM);
1351 LogFlow(("pdmR3UsbHlp_TMTimerCreate: caller='%s'/%d: enmClock=%d pfnCallback=%p pvUser=%p fFlags=%#x pszDesc=%p:{%s} ppTimer=%p\n",
1352 pUsbIns->pReg->szName, pUsbIns->iInstance, enmClock, pfnCallback, pvUser, fFlags, pszDesc, pszDesc, ppTimer));
1353
1354 if (pUsbIns->iInstance > 0) /** @todo use a string cache here later. */
1355 {
1356 char *pszDesc2 = MMR3HeapAPrintf(pVM, MM_TAG_PDM_USB_DESC, "%s [%u]", pszDesc, pUsbIns->iInstance);
1357 if (pszDesc2)
1358 pszDesc = pszDesc2;
1359 }
1360
1361 int rc = TMR3TimerCreateUsb(pVM, pUsbIns, enmClock, pfnCallback, pvUser, fFlags, pszDesc, ppTimer);
1362
1363 LogFlow(("pdmR3UsbHlp_TMTimerCreate: caller='%s'/%d: returns %Rrc\n", pUsbIns->pReg->szName, pUsbIns->iInstance, rc));
1364 return rc;
1365}
1366
1367
1368/** @interface_method_impl{PDMUSBHLP,pfnVMSetErrorV} */
1369static DECLCALLBACK(int) pdmR3UsbHlp_VMSetErrorV(PPDMUSBINS pUsbIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
1370{
1371 PDMUSB_ASSERT_USBINS(pUsbIns);
1372 int rc2 = VMSetErrorV(pUsbIns->Internal.s.pVM, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
1373 return rc;
1374}
1375
1376
1377/** @interface_method_impl{PDMUSBHLP,pfnVMSetRuntimeErrorV} */
1378static DECLCALLBACK(int) pdmR3UsbHlp_VMSetRuntimeErrorV(PPDMUSBINS pUsbIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va)
1379{
1380 PDMUSB_ASSERT_USBINS(pUsbIns);
1381 int rc = VMSetRuntimeErrorV(pUsbIns->Internal.s.pVM, fFlags, pszErrorId, pszFormat, va);
1382 return rc;
1383}
1384
1385
1386/** @interface_method_impl{PDMUSBHLP,pfnVMState} */
1387static DECLCALLBACK(VMSTATE) pdmR3UsbHlp_VMState(PPDMUSBINS pUsbIns)
1388{
1389 PDMUSB_ASSERT_USBINS(pUsbIns);
1390
1391 VMSTATE enmVMState = VMR3GetState(pUsbIns->Internal.s.pVM);
1392
1393 LogFlow(("pdmR3UsbHlp_VMState: caller='%s'/%d: returns %d (%s)\n", pUsbIns->pReg->szName, pUsbIns->iInstance,
1394 enmVMState, VMR3GetStateName(enmVMState)));
1395 return enmVMState;
1396}
1397
1398/** @interface_method_impl{PDMUSBHLP,pfnThreadCreate} */
1399static DECLCALLBACK(int) pdmR3UsbHlp_ThreadCreate(PPDMUSBINS pUsbIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADUSB pfnThread,
1400 PFNPDMTHREADWAKEUPUSB pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
1401{
1402 PDMUSB_ASSERT_USBINS(pUsbIns);
1403 VM_ASSERT_EMT(pUsbIns->Internal.s.pVM);
1404 LogFlow(("pdmR3UsbHlp_ThreadCreate: caller='%s'/%d: ppThread=%p pvUser=%p pfnThread=%p pfnWakeup=%p cbStack=%#zx enmType=%d pszName=%p:{%s}\n",
1405 pUsbIns->pReg->szName, pUsbIns->iInstance, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName, pszName));
1406
1407 int rc = pdmR3ThreadCreateUsb(pUsbIns->Internal.s.pVM, pUsbIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
1408
1409 LogFlow(("pdmR3UsbHlp_ThreadCreate: caller='%s'/%d: returns %Rrc *ppThread=%RTthrd\n", pUsbIns->pReg->szName, pUsbIns->iInstance,
1410 rc, *ppThread));
1411 return rc;
1412}
1413
1414
1415/** @interface_method_impl{PDMUSBHLP,pfnSetAsyncNotification} */
1416static DECLCALLBACK(int) pdmR3UsbHlp_SetAsyncNotification(PPDMUSBINS pUsbIns, PFNPDMUSBASYNCNOTIFY pfnAsyncNotify)
1417{
1418 PDMUSB_ASSERT_USBINS(pUsbIns);
1419 VM_ASSERT_EMT0(pUsbIns->Internal.s.pVM);
1420 LogFlow(("pdmR3UsbHlp_SetAsyncNotification: caller='%s'/%d: pfnAsyncNotify=%p\n", pUsbIns->pReg->szName, pUsbIns->iInstance, pfnAsyncNotify));
1421
1422 int rc = VINF_SUCCESS;
1423 AssertStmt(pfnAsyncNotify, rc = VERR_INVALID_PARAMETER);
1424 AssertStmt(!pUsbIns->Internal.s.pfnAsyncNotify, rc = VERR_WRONG_ORDER);
1425 AssertStmt(pUsbIns->Internal.s.fVMSuspended || pUsbIns->Internal.s.fVMReset, rc = VERR_WRONG_ORDER);
1426 VMSTATE enmVMState = VMR3GetState(pUsbIns->Internal.s.pVM);
1427 AssertStmt( enmVMState == VMSTATE_SUSPENDING
1428 || enmVMState == VMSTATE_SUSPENDING_EXT_LS
1429 || enmVMState == VMSTATE_SUSPENDING_LS
1430 || enmVMState == VMSTATE_RESETTING
1431 || enmVMState == VMSTATE_RESETTING_LS
1432 || enmVMState == VMSTATE_POWERING_OFF
1433 || enmVMState == VMSTATE_POWERING_OFF_LS,
1434 rc = VERR_INVALID_STATE);
1435
1436 if (RT_SUCCESS(rc))
1437 pUsbIns->Internal.s.pfnAsyncNotify = pfnAsyncNotify;
1438
1439 LogFlow(("pdmR3UsbHlp_SetAsyncNotification: caller='%s'/%d: returns %Rrc\n", pUsbIns->pReg->szName, pUsbIns->iInstance, rc));
1440 return rc;
1441}
1442
1443
1444/** @interface_method_impl{PDMUSBHLP,pfnAsyncNotificationCompleted} */
1445static DECLCALLBACK(void) pdmR3UsbHlp_AsyncNotificationCompleted(PPDMUSBINS pUsbIns)
1446{
1447 PDMUSB_ASSERT_USBINS(pUsbIns);
1448 PVM pVM = pUsbIns->Internal.s.pVM;
1449
1450 VMSTATE enmVMState = VMR3GetState(pVM);
1451 if ( enmVMState == VMSTATE_SUSPENDING
1452 || enmVMState == VMSTATE_SUSPENDING_EXT_LS
1453 || enmVMState == VMSTATE_SUSPENDING_LS
1454 || enmVMState == VMSTATE_RESETTING
1455 || enmVMState == VMSTATE_RESETTING_LS
1456 || enmVMState == VMSTATE_POWERING_OFF
1457 || enmVMState == VMSTATE_POWERING_OFF_LS)
1458 {
1459 LogFlow(("pdmR3UsbHlp_AsyncNotificationCompleted: caller='%s'/%d:\n", pUsbIns->pReg->szName, pUsbIns->iInstance));
1460 VMR3AsyncPdmNotificationWakeupU(pVM->pUVM);
1461 }
1462 else
1463 LogFlow(("pdmR3UsbHlp_AsyncNotificationCompleted: caller='%s'/%d: enmVMState=%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance, enmVMState));
1464}
1465
1466
1467/**
1468 * The USB device helper structure.
1469 */
1470const PDMUSBHLP g_pdmR3UsbHlp =
1471{
1472 PDM_USBHLP_VERSION,
1473 pdmR3UsbHlp_DriverAttach,
1474 pdmR3UsbHlp_AssertEMT,
1475 pdmR3UsbHlp_AssertOther,
1476 pdmR3UsbHlp_DBGFStopV,
1477 pdmR3UsbHlp_DBGFInfoRegister,
1478 pdmR3UsbHlp_MMHeapAlloc,
1479 pdmR3UsbHlp_MMHeapAllocZ,
1480 pdmR3UsbHlp_PDMQueueCreate,
1481 pdmR3UsbHlp_SSMRegister,
1482 pdmR3UsbHlp_STAMRegisterV,
1483 pdmR3UsbHlp_TMTimerCreate,
1484 pdmR3UsbHlp_VMSetErrorV,
1485 pdmR3UsbHlp_VMSetRuntimeErrorV,
1486 pdmR3UsbHlp_VMState,
1487 pdmR3UsbHlp_ThreadCreate,
1488 pdmR3UsbHlp_SetAsyncNotification,
1489 pdmR3UsbHlp_AsyncNotificationCompleted,
1490 PDM_USBHLP_VERSION
1491};
1492
1493/** @} */
Note: See TracBrowser for help on using the repository browser.

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