VirtualBox

Changeset 48983 in vbox for trunk/src/VBox/Main/src-client


Ignore:
Timestamp:
Oct 8, 2013 9:57:15 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
89700
Message:

Main,Frontends: Support for the USB storage controller

Location:
trunk/src/VBox/Main/src-client
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r48528 r48983  
    34623462        case StorageControllerType_I82078:
    34633463            return "i82078";
     3464        case StorageControllerType_USB:
     3465            return "Msd";
    34643466        default:
    34653467            return NULL;
     
    34843486        {
    34853487            uLun = port;
     3488            return S_OK;
     3489        }
     3490        case StorageBus_USB:
     3491        {
     3492             /*
     3493              * It is always the first lun, the port denotes the device instance
     3494              * for the Msd device.
     3495              */
     3496            uLun = 0;
    34863497            return S_OK;
    34873498        }
     
    39403951    }
    39413952
    3942     /* Determine the base path for the device instance. */
     3953    /*
     3954     * Determine the base path for the device instance. USB Msd devices are handled different
     3955     * because the PDM USB API requires a differnet CFGM tree when attaching a new USB device.
     3956     */
    39433957    PCFGMNODE pCtlInst;
    3944     pCtlInst = CFGMR3GetChildF(CFGMR3GetRootU(pUVM), "Devices/%s/%u/", pcszDevice, uInstance);
     3958
     3959    if (enmBus == StorageBus_USB)
     3960        pCtlInst = CFGMR3CreateTree(pUVM);
     3961    else
     3962        pCtlInst = CFGMR3GetChildF(CFGMR3GetRootU(pUVM), "Devices/%s/%u/", pcszDevice, uInstance);
     3963
    39453964    AssertReturn(pCtlInst, VERR_INTERNAL_ERROR);
    39463965
     
    39673986    /** @todo this dumps everything attached to this device instance, which
    39683987     * is more than necessary. Dumping the changed LUN would be enough. */
    3969     CFGMR3Dump(pCtlInst);
     3988    if (enmBus != StorageBus_USB)
     3989        CFGMR3Dump(pCtlInst);
    39703990
    39713991    /*
     
    41864206    PCFGMNODE pCtlInst;
    41874207    pCtlInst = CFGMR3GetChildF(CFGMR3GetRootU(pUVM), "Devices/%s/%u/", pcszDevice, uInstance);
    4188     AssertReturn(pCtlInst, VERR_INTERNAL_ERROR);
     4208    AssertReturn(pCtlInst || enmBus == StorageBus_USB, VERR_INTERNAL_ERROR);
    41894209
    41904210#define H()         AssertMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_GENERAL_FAILURE)
     
    42074227#undef H
    42084228
    4209     /* First check if the LUN really exists. */
    4210     pLunL0 = CFGMR3GetChildF(pCtlInst, "LUN#%u", uLUN);
    4211     if (pLunL0)
    4212     {
    4213         uint32_t fFlags = 0;
    4214 
    4215         if (fSilent)
    4216             fFlags |= PDM_TACH_FLAGS_NOT_HOT_PLUG;
    4217 
    4218         rc = PDMR3DeviceDetach(pUVM, pcszDevice, uInstance, uLUN, fFlags);
    4219         if (rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
    4220             rc = VINF_SUCCESS;
     4229    if (enmBus != StorageBus_USB)
     4230    {
     4231        /* First check if the LUN really exists. */
     4232        pLunL0 = CFGMR3GetChildF(pCtlInst, "LUN#%u", uLUN);
     4233        if (pLunL0)
     4234        {
     4235            uint32_t fFlags = 0;
     4236
     4237            if (fSilent)
     4238                fFlags |= PDM_TACH_FLAGS_NOT_HOT_PLUG;
     4239
     4240            rc = PDMR3DeviceDetach(pUVM, pcszDevice, uInstance, uLUN, fFlags);
     4241            if (rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
     4242                rc = VINF_SUCCESS;
     4243            AssertRCReturn(rc, rc);
     4244            CFGMR3RemoveNode(pLunL0);
     4245
     4246            Utf8Str devicePath = Utf8StrFmt("%s/%u/LUN#%u", pcszDevice, uInstance, uLUN);
     4247            pConsole->mapMediumAttachments.erase(devicePath);
     4248
     4249        }
     4250        else
     4251            AssertFailedReturn(VERR_INTERNAL_ERROR);
     4252
     4253        CFGMR3Dump(pCtlInst);
     4254    }
     4255    else
     4256    {
     4257        /* Find the correct USB device in the list. */
     4258        USBStorageDeviceList::iterator it;
     4259        for (it = pConsole->mUSBStorageDevices.begin(); it != pConsole->mUSBStorageDevices.end(); it++)
     4260        {
     4261            if (it->iPort == lPort)
     4262                break;
     4263        }
     4264
     4265        AssertReturn(it != pConsole->mUSBStorageDevices.end(), VERR_INTERNAL_ERROR);
     4266        rc = PDMR3UsbDetachDevice(pUVM, &it->mUuid);
    42214267        AssertRCReturn(rc, rc);
    4222         CFGMR3RemoveNode(pLunL0);
    4223 
    4224         Utf8Str devicePath = Utf8StrFmt("%s/%u/LUN#%u", pcszDevice, uInstance, uLUN);
    4225         pConsole->mapMediumAttachments.erase(devicePath);
    4226 
    4227     }
    4228     else
    4229         AssertFailedReturn(VERR_INTERNAL_ERROR);
    4230 
    4231     CFGMR3Dump(pCtlInst);
     4268        pConsole->mUSBStorageDevices.erase(it);
     4269    }
    42324270
    42334271    /*
     
    94529490    /* Determine the base path for the device instance. */
    94539491    PCFGMNODE pCtlInst;
    9454     pCtlInst = CFGMR3GetChildF(CFGMR3GetRootU(pUVM), "Devices/%s/%u/", pcszDevice, uInstance);
     9492
     9493    if (enmBus == StorageBus_USB)
     9494        pCtlInst = CFGMR3GetChildF(CFGMR3GetRootU(pUVM), "USB/%s/", pcszDevice);
     9495    else
     9496        pCtlInst = CFGMR3GetChildF(CFGMR3GetRootU(pUVM), "Devices/%s/%u/", pcszDevice, uInstance);
     9497
    94559498    AssertReturn(pCtlInst, VERR_INTERNAL_ERROR);
    94569499
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r48915 r48983  
    6666#include <VBox/param.h>
    6767#include <VBox/vmm/pdmapi.h> /* For PDMR3DriverAttach/PDMR3DriverDetach */
     68#include <VBox/vmm/pdmusb.h> /* For PDMR3UsbCreateEmulatedDevice */
    6869#include <VBox/version.h>
    6970#include <VBox/HostServices/VBoxClipboardSvc.h>
     
    10851086
    10861087
     1088
    10871089        /*
    10881090         * MM values.
     
    15761578
    15771579        /*
     1580         * The USB Controllers.
     1581         */
     1582        com::SafeIfaceArray<IUSBController> usbCtrls;
     1583        hrc = pMachine->COMGETTER(USBControllers)(ComSafeArrayAsOutParam(usbCtrls));        H();
     1584        bool fOhciPresent = false; /**< Flag whether at least one OHCI controller is present. */
     1585
     1586        for (size_t i = 0; i < usbCtrls.size(); ++i)
     1587        {
     1588            USBControllerType_T enmCtrlType;
     1589            rc = usbCtrls[i]->COMGETTER(Type)(&enmCtrlType);                                   H();
     1590            if (enmCtrlType == USBControllerType_OHCI)
     1591            {
     1592                fOhciPresent = true;
     1593                break;
     1594            }
     1595        }
     1596
     1597        /*
     1598         * Currently EHCI is only enabled when a OHCI controller is present too.
     1599         * This might change when XHCI is supported.
     1600         */
     1601        if (fOhciPresent)
     1602            mfVMHasUsbController = true;
     1603
     1604        PCFGMNODE pUsbDevices = NULL; /**< Required for USB storage controller later. */
     1605        if (mfVMHasUsbController)
     1606        {
     1607            for (size_t i = 0; i < usbCtrls.size(); ++i)
     1608            {
     1609                USBControllerType_T enmCtrlType;
     1610                rc = usbCtrls[i]->COMGETTER(Type)(&enmCtrlType);                                   H();
     1611
     1612                if (enmCtrlType == USBControllerType_OHCI)
     1613                {
     1614                    InsertConfigNode(pDevices, "usb-ohci", &pDev);
     1615                    InsertConfigNode(pDev,     "0", &pInst);
     1616                    InsertConfigNode(pInst,    "Config", &pCfg);
     1617                    InsertConfigInteger(pInst, "Trusted",              1); /* boolean */
     1618                    hrc = pBusMgr->assignPCIDevice("usb-ohci", pInst);                          H();
     1619                    InsertConfigNode(pInst,    "LUN#0", &pLunL0);
     1620                    InsertConfigString(pLunL0, "Driver",               "VUSBRootHub");
     1621                    InsertConfigNode(pLunL0,   "Config", &pCfg);
     1622
     1623                    /*
     1624                     * Attach the status driver.
     1625                     */
     1626                    attachStatusDriver(pInst, &mapUSBLed[0], 0, 0, NULL, NULL, 0);
     1627                }
     1628#ifdef VBOX_WITH_EHCI
     1629                else if (enmCtrlType == USBControllerType_EHCI)
     1630                {
     1631                    /*
     1632                     * USB 2.0 is only available if the proper ExtPack is installed.
     1633                     *
     1634                     * Note. Configuring EHCI here and providing messages about
     1635                     * the missing extpack isn't exactly clean, but it is a
     1636                     * necessary evil to patch over legacy compatability issues
     1637                     * introduced by the new distribution model.
     1638                     */
     1639                    static const char *s_pszUsbExtPackName = "Oracle VM VirtualBox Extension Pack";
     1640# ifdef VBOX_WITH_EXTPACK
     1641                    if (mptrExtPackManager->isExtPackUsable(s_pszUsbExtPackName))
     1642# endif
     1643                    {
     1644                        InsertConfigNode(pDevices, "usb-ehci", &pDev);
     1645                        InsertConfigNode(pDev,     "0", &pInst);
     1646                        InsertConfigNode(pInst,    "Config", &pCfg);
     1647                        InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
     1648                        hrc = pBusMgr->assignPCIDevice("usb-ehci", pInst);                  H();
     1649
     1650                        InsertConfigNode(pInst,    "LUN#0", &pLunL0);
     1651                        InsertConfigString(pLunL0, "Driver",               "VUSBRootHub");
     1652                        InsertConfigNode(pLunL0,   "Config", &pCfg);
     1653
     1654                        /*
     1655                         * Attach the status driver.
     1656                         */
     1657                        attachStatusDriver(pInst, &mapUSBLed[1], 0, 0, NULL, NULL, 0);
     1658                    }
     1659# ifdef VBOX_WITH_EXTPACK
     1660                    else
     1661                    {
     1662                        /* Always fatal! Up to VBox 4.0.4 we allowed to start the VM anyway
     1663                         * but this induced problems when the user saved + restored the VM! */
     1664                        return VMR3SetError(pUVM, VERR_NOT_FOUND, RT_SRC_POS,
     1665                                N_("Implementation of the USB 2.0 controller not found!\n"
     1666                                   "Because the USB 2.0 controller state is part of the saved "
     1667                                   "VM state, the VM cannot be started. To fix "
     1668                                   "this problem, either install the '%s' or disable USB 2.0 "
     1669                                   "support in the VM settings"),
     1670                                s_pszUsbExtPackName);
     1671                    }
     1672# endif
     1673                }
     1674#endif
     1675            } /* for every USB controller. */
     1676
     1677
     1678            /*
     1679             * Virtual USB Devices.
     1680             */
     1681            InsertConfigNode(pRoot, "USB", &pUsbDevices);
     1682
     1683#ifdef VBOX_WITH_USB
     1684            {
     1685                /*
     1686                 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
     1687                 * on a per device level now.
     1688                 */
     1689                InsertConfigNode(pUsbDevices, "USBProxy", &pCfg);
     1690                InsertConfigNode(pCfg, "GlobalConfig", &pCfg);
     1691                // This globally enables the 2.0 -> 1.1 device morphing of proxied devices to keep windows quiet.
     1692                //InsertConfigInteger(pCfg, "Force11Device", true);
     1693                // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
     1694                // that it's documented somewhere.) Users needing it can use:
     1695                //      VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
     1696                //InsertConfigInteger(pCfg, "Force11PacketSize", true);
     1697            }
     1698#endif
     1699
     1700#ifdef VBOX_WITH_USB_CARDREADER
     1701            BOOL aEmulatedUSBCardReaderEnabled = FALSE;
     1702            hrc = pMachine->COMGETTER(EmulatedUSBCardReaderEnabled)(&aEmulatedUSBCardReaderEnabled);    H();
     1703            if (aEmulatedUSBCardReaderEnabled)
     1704            {
     1705                InsertConfigNode(pUsbDevices, "CardReader", &pDev);
     1706                InsertConfigNode(pDev,     "0", &pInst);
     1707                InsertConfigNode(pInst,    "Config", &pCfg);
     1708
     1709                InsertConfigNode(pInst,    "LUN#0", &pLunL0);
     1710# ifdef VBOX_WITH_USB_CARDREADER_TEST
     1711                InsertConfigString(pLunL0, "Driver", "DrvDirectCardReader");
     1712                InsertConfigNode(pLunL0,   "Config", &pCfg);
     1713# else
     1714                InsertConfigString(pLunL0, "Driver", "UsbCardReader");
     1715                InsertConfigNode(pLunL0,   "Config", &pCfg);
     1716                InsertConfigInteger(pCfg,  "Object", (uintptr_t)mUsbCardReader);
     1717# endif
     1718             }
     1719#endif
     1720
     1721            /* Virtual USB Mouse/Tablet */
     1722            if (   aPointingHID == PointingHIDType_USBMouse
     1723                || aPointingHID == PointingHIDType_ComboMouse
     1724                || aPointingHID == PointingHIDType_USBTablet
     1725                || aPointingHID == PointingHIDType_USBMultiTouch)
     1726                InsertConfigNode(pUsbDevices, "HidMouse", &pDev);
     1727            if (aPointingHID == PointingHIDType_USBMouse)
     1728            {
     1729                InsertConfigNode(pDev,     "0", &pInst);
     1730                InsertConfigNode(pInst,    "Config", &pCfg);
     1731
     1732                InsertConfigString(pCfg,   "Mode", "relative");
     1733                InsertConfigNode(pInst,    "LUN#0", &pLunL0);
     1734                InsertConfigString(pLunL0, "Driver",        "MouseQueue");
     1735                InsertConfigNode(pLunL0,   "Config", &pCfg);
     1736                InsertConfigInteger(pCfg,  "QueueSize",            128);
     1737
     1738                InsertConfigNode(pLunL0,   "AttachedDriver", &pLunL1);
     1739                InsertConfigString(pLunL1, "Driver",        "MainMouse");
     1740                InsertConfigNode(pLunL1,   "Config", &pCfg);
     1741                InsertConfigInteger(pCfg,  "Object",     (uintptr_t)pMouse);
     1742            }
     1743            if (   aPointingHID == PointingHIDType_USBTablet
     1744                || aPointingHID == PointingHIDType_USBMultiTouch)
     1745            {
     1746                InsertConfigNode(pDev,     "1", &pInst);
     1747                InsertConfigNode(pInst,    "Config", &pCfg);
     1748
     1749                InsertConfigString(pCfg,   "Mode", "absolute");
     1750                InsertConfigNode(pInst,    "LUN#0", &pLunL0);
     1751                InsertConfigString(pLunL0, "Driver",        "MouseQueue");
     1752                InsertConfigNode(pLunL0,   "Config", &pCfg);
     1753                InsertConfigInteger(pCfg,  "QueueSize",            128);
     1754
     1755                InsertConfigNode(pLunL0,   "AttachedDriver", &pLunL1);
     1756                InsertConfigString(pLunL1, "Driver",        "MainMouse");
     1757                InsertConfigNode(pLunL1,   "Config", &pCfg);
     1758                InsertConfigInteger(pCfg,  "Object",     (uintptr_t)pMouse);
     1759            }
     1760            if (aPointingHID == PointingHIDType_USBMultiTouch)
     1761            {
     1762                InsertConfigNode(pDev,     "2", &pInst);
     1763                InsertConfigNode(pInst,    "Config", &pCfg);
     1764
     1765                InsertConfigString(pCfg,   "Mode", "multitouch");
     1766                InsertConfigNode(pInst,    "LUN#0", &pLunL0);
     1767                InsertConfigString(pLunL0, "Driver",        "MouseQueue");
     1768                InsertConfigNode(pLunL0,   "Config", &pCfg);
     1769                InsertConfigInteger(pCfg,  "QueueSize",            128);
     1770
     1771                InsertConfigNode(pLunL0,   "AttachedDriver", &pLunL1);
     1772                InsertConfigString(pLunL1, "Driver",        "MainMouse");
     1773                InsertConfigNode(pLunL1,   "Config", &pCfg);
     1774                InsertConfigInteger(pCfg,  "Object",     (uintptr_t)pMouse);
     1775            }
     1776
     1777            /* Virtual USB Keyboard */
     1778            KeyboardHIDType_T aKbdHID;
     1779            hrc = pMachine->COMGETTER(KeyboardHIDType)(&aKbdHID);                       H();
     1780            if (aKbdHID == KeyboardHIDType_USBKeyboard)
     1781            {
     1782                InsertConfigNode(pUsbDevices, "HidKeyboard", &pDev);
     1783                InsertConfigNode(pDev,     "0", &pInst);
     1784                InsertConfigNode(pInst,    "Config", &pCfg);
     1785
     1786                InsertConfigNode(pInst,    "LUN#0", &pLunL0);
     1787                InsertConfigString(pLunL0, "Driver",               "KeyboardQueue");
     1788                InsertConfigNode(pLunL0,   "Config", &pCfg);
     1789                InsertConfigInteger(pCfg,  "QueueSize",            64);
     1790
     1791                InsertConfigNode(pLunL0,   "AttachedDriver", &pLunL1);
     1792                InsertConfigString(pLunL1, "Driver",               "MainKeyboard");
     1793                InsertConfigNode(pLunL1,   "Config", &pCfg);
     1794                pKeyboard = mKeyboard;
     1795                InsertConfigInteger(pCfg,  "Object",     (uintptr_t)pKeyboard);
     1796            }
     1797        }
     1798
     1799        /*
    15781800         * Storage controllers.
    15791801         */
     
    15891811            StorageControllerType_T enmCtrlType;
    15901812            rc = ctrls[i]->COMGETTER(ControllerType)(&enmCtrlType);                         H();
    1591             AssertRelease((unsigned)enmCtrlType < RT_ELEMENTS(aCtrlNodes));
     1813            AssertRelease((unsigned)enmCtrlType < RT_ELEMENTS(aCtrlNodes)
     1814                          || enmCtrlType == StorageControllerType_USB);
    15921815
    15931816            StorageBus_T enmBus;
     
    16061829            rc = ctrls[i]->COMGETTER(Bootable)(&fBootable);                                 H();
    16071830
    1608             /* /Devices/<ctrldev>/ */
     1831            PCFGMNODE pCtlInst = NULL;
    16091832            const char *pszCtrlDev = convertControllerTypeToDev(enmCtrlType);
    1610             pDev = aCtrlNodes[enmCtrlType];
    1611             if (!pDev)
    1612             {
    1613                 InsertConfigNode(pDevices, pszCtrlDev, &pDev);
    1614                 aCtrlNodes[enmCtrlType] = pDev; /* IDE variants are handled in the switch */
    1615             }
    1616 
    1617             /* /Devices/<ctrldev>/<instance>/ */
    1618             PCFGMNODE pCtlInst = NULL;
    1619             InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pCtlInst);
    1620 
    1621             /* Device config: /Devices/<ctrldev>/<instance>/<values> & /ditto/Config/<values> */
    1622             InsertConfigInteger(pCtlInst, "Trusted",   1);
    1623             InsertConfigNode(pCtlInst,    "Config",    &pCfg);
     1833            if (enmCtrlType != StorageControllerType_USB)
     1834            {
     1835                /* /Devices/<ctrldev>/ */
     1836                pDev = aCtrlNodes[enmCtrlType];
     1837                if (!pDev)
     1838                {
     1839                    InsertConfigNode(pDevices, pszCtrlDev, &pDev);
     1840                    aCtrlNodes[enmCtrlType] = pDev; /* IDE variants are handled in the switch */
     1841                }
     1842
     1843                /* /Devices/<ctrldev>/<instance>/ */
     1844                InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pCtlInst);
     1845
     1846                /* Device config: /Devices/<ctrldev>/<instance>/<values> & /ditto/Config/<values> */
     1847                InsertConfigInteger(pCtlInst, "Trusted",   1);
     1848                InsertConfigNode(pCtlInst,    "Config",    &pCfg);
     1849            }
    16241850
    16251851            switch (enmCtrlType)
     
    17982024                                       &mapMediumAttachments, pszCtrlDev, ulInstance);
    17992025                    paLedDevType = &maStorageDevType[iLedSas];
     2026                    break;
     2027                }
     2028
     2029                case StorageControllerType_USB:
     2030                {
     2031                    if (pUsbDevices)
     2032                    {
     2033                        /*
     2034                         * USB MSDs are handled a bit different as the device instance
     2035                         * doesn't match the storage controller instance but the port.
     2036                         */
     2037                        InsertConfigNode(pUsbDevices, "Msd", &pDev);
     2038                        pCtlInst = pDev;
     2039                    }
     2040                    else
     2041                        return VMR3SetError(pUVM, VERR_NOT_FOUND, RT_SRC_POS,
     2042                                N_("There is no USB controller enabled but there\n"
     2043                                   "is at least one USB storage device configured for this VM.\n"
     2044                                   "To fix this problem either enable the USB controller or remove\n"
     2045                                   "the storage device from the VM"));
    18002046                    break;
    18012047                }
     
    23332579            hrc = pMachine->COMGETTER(Name)(bstr.asOutParam());                             H();
    23342580            InsertConfigString(pCfg, "StreamName", bstr);
    2335         }
    2336 
    2337         /*
    2338          * The USB Controllers.
    2339          */
    2340         com::SafeIfaceArray<IUSBController> usbCtrls;
    2341         hrc = pMachine->COMGETTER(USBControllers)(ComSafeArrayAsOutParam(usbCtrls));        H();
    2342         bool fOhciPresent = false; /**< Flag whether at least one OHCI controller is presnet. */
    2343 
    2344         for (size_t i = 0; i < usbCtrls.size(); ++i)
    2345         {
    2346             USBControllerType_T enmCtrlType;
    2347             rc = usbCtrls[i]->COMGETTER(Type)(&enmCtrlType);                                   H();
    2348             if (enmCtrlType == USBControllerType_OHCI)
    2349             {
    2350                 fOhciPresent = true;
    2351                 break;
    2352             }
    2353         }
    2354 
    2355         /*
    2356          * Currently EHCI is only enabled when a OHCI controller is present too.
    2357          * This might change when XHCI is supported.
    2358          */
    2359         if (fOhciPresent)
    2360             mfVMHasUsbController = true;
    2361 
    2362         if (mfVMHasUsbController)
    2363         {
    2364             for (size_t i = 0; i < usbCtrls.size(); ++i)
    2365             {
    2366                 USBControllerType_T enmCtrlType;
    2367                 rc = usbCtrls[i]->COMGETTER(Type)(&enmCtrlType);                                   H();
    2368 
    2369                 if (enmCtrlType == USBControllerType_OHCI)
    2370                 {
    2371                     InsertConfigNode(pDevices, "usb-ohci", &pDev);
    2372                     InsertConfigNode(pDev,     "0", &pInst);
    2373                     InsertConfigNode(pInst,    "Config", &pCfg);
    2374                     InsertConfigInteger(pInst, "Trusted",              1); /* boolean */
    2375                     hrc = pBusMgr->assignPCIDevice("usb-ohci", pInst);                          H();
    2376                     InsertConfigNode(pInst,    "LUN#0", &pLunL0);
    2377                     InsertConfigString(pLunL0, "Driver",               "VUSBRootHub");
    2378                     InsertConfigNode(pLunL0,   "Config", &pCfg);
    2379 
    2380                     /*
    2381                      * Attach the status driver.
    2382                      */
    2383                     attachStatusDriver(pInst, &mapUSBLed[0], 0, 0, NULL, NULL, 0);
    2384                 }
    2385 #ifdef VBOX_WITH_EHCI
    2386                 else if (enmCtrlType == USBControllerType_EHCI)
    2387                 {
    2388                     /*
    2389                      * USB 2.0 is only available if the proper ExtPack is installed.
    2390                      *
    2391                      * Note. Configuring EHCI here and providing messages about
    2392                      * the missing extpack isn't exactly clean, but it is a
    2393                      * necessary evil to patch over legacy compatability issues
    2394                      * introduced by the new distribution model.
    2395                      */
    2396                     static const char *s_pszUsbExtPackName = "Oracle VM VirtualBox Extension Pack";
    2397 # ifdef VBOX_WITH_EXTPACK
    2398                     if (mptrExtPackManager->isExtPackUsable(s_pszUsbExtPackName))
    2399 # endif
    2400                     {
    2401                         InsertConfigNode(pDevices, "usb-ehci", &pDev);
    2402                         InsertConfigNode(pDev,     "0", &pInst);
    2403                         InsertConfigNode(pInst,    "Config", &pCfg);
    2404                         InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
    2405                         hrc = pBusMgr->assignPCIDevice("usb-ehci", pInst);                  H();
    2406 
    2407                         InsertConfigNode(pInst,    "LUN#0", &pLunL0);
    2408                         InsertConfigString(pLunL0, "Driver",               "VUSBRootHub");
    2409                         InsertConfigNode(pLunL0,   "Config", &pCfg);
    2410 
    2411                         /*
    2412                          * Attach the status driver.
    2413                          */
    2414                         attachStatusDriver(pInst, &mapUSBLed[1], 0, 0, NULL, NULL, 0);
    2415                     }
    2416 # ifdef VBOX_WITH_EXTPACK
    2417                     else
    2418                     {
    2419                         /* Always fatal! Up to VBox 4.0.4 we allowed to start the VM anyway
    2420                          * but this induced problems when the user saved + restored the VM! */
    2421                         return VMR3SetError(pUVM, VERR_NOT_FOUND, RT_SRC_POS,
    2422                                 N_("Implementation of the USB 2.0 controller not found!\n"
    2423                                    "Because the USB 2.0 controller state is part of the saved "
    2424                                    "VM state, the VM cannot be started. To fix "
    2425                                    "this problem, either install the '%s' or disable USB 2.0 "
    2426                                    "support in the VM settings"),
    2427                                 s_pszUsbExtPackName);
    2428                     }
    2429 # endif
    2430                 }
    2431 #endif
    2432             } /* for every USB controller. */
    2433 
    2434 
    2435             /*
    2436              * Virtual USB Devices.
    2437              */
    2438             PCFGMNODE pUsbDevices = NULL;
    2439             InsertConfigNode(pRoot, "USB", &pUsbDevices);
    2440 
    2441 #ifdef VBOX_WITH_USB
    2442             {
    2443                 /*
    2444                  * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
    2445                  * on a per device level now.
    2446                  */
    2447                 InsertConfigNode(pUsbDevices, "USBProxy", &pCfg);
    2448                 InsertConfigNode(pCfg, "GlobalConfig", &pCfg);
    2449                 // This globally enables the 2.0 -> 1.1 device morphing of proxied devices to keep windows quiet.
    2450                 //InsertConfigInteger(pCfg, "Force11Device", true);
    2451                 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
    2452                 // that it's documented somewhere.) Users needing it can use:
    2453                 //      VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
    2454                 //InsertConfigInteger(pCfg, "Force11PacketSize", true);
    2455             }
    2456 #endif
    2457 
    2458 #ifdef VBOX_WITH_USB_CARDREADER
    2459             BOOL aEmulatedUSBCardReaderEnabled = FALSE;
    2460             hrc = pMachine->COMGETTER(EmulatedUSBCardReaderEnabled)(&aEmulatedUSBCardReaderEnabled);    H();
    2461             if (aEmulatedUSBCardReaderEnabled)
    2462             {
    2463                 InsertConfigNode(pUsbDevices, "CardReader", &pDev);
    2464                 InsertConfigNode(pDev,     "0", &pInst);
    2465                 InsertConfigNode(pInst,    "Config", &pCfg);
    2466 
    2467                 InsertConfigNode(pInst,    "LUN#0", &pLunL0);
    2468 # ifdef VBOX_WITH_USB_CARDREADER_TEST
    2469                 InsertConfigString(pLunL0, "Driver", "DrvDirectCardReader");
    2470                 InsertConfigNode(pLunL0,   "Config", &pCfg);
    2471 # else
    2472                 InsertConfigString(pLunL0, "Driver", "UsbCardReader");
    2473                 InsertConfigNode(pLunL0,   "Config", &pCfg);
    2474                 InsertConfigInteger(pCfg,  "Object", (uintptr_t)mUsbCardReader);
    2475 # endif
    2476              }
    2477 #endif
    2478 
    2479 # if 0  /* Virtual MSD*/
    2480             InsertConfigNode(pUsbDevices, "Msd", &pDev);
    2481             InsertConfigNode(pDev,     "0", &pInst);
    2482             InsertConfigNode(pInst,    "Config", &pCfg);
    2483             InsertConfigNode(pInst,    "LUN#0", &pLunL0);
    2484 
    2485             InsertConfigString(pLunL0, "Driver", "SCSI");
    2486             InsertConfigNode(pLunL0,   "Config", &pCfg);
    2487 
    2488             InsertConfigNode(pLunL0,   "AttachedDriver", &pLunL1);
    2489             InsertConfigString(pLunL1, "Driver", "Block");
    2490             InsertConfigNode(pLunL1,   "Config", &pCfg);
    2491             InsertConfigString(pCfg,   "Type", "HardDisk");
    2492             InsertConfigInteger(pCfg,  "Mountable", 0);
    2493 
    2494             InsertConfigNode(pLunL1,   "AttachedDriver", &pLunL2);
    2495             InsertConfigString(pLunL2, "Driver", "VD");
    2496             InsertConfigNode(pLunL2,   "Config", &pCfg);
    2497             InsertConfigString(pCfg,   "Path", "/Volumes/DataHFS/bird/VDIs/linux.vdi");
    2498             InsertConfigString(pCfg,   "Format", "VDI");
    2499 # endif
    2500 
    2501             /* Virtual USB Mouse/Tablet */
    2502             if (   aPointingHID == PointingHIDType_USBMouse
    2503                 || aPointingHID == PointingHIDType_ComboMouse
    2504                 || aPointingHID == PointingHIDType_USBTablet
    2505                 || aPointingHID == PointingHIDType_USBMultiTouch)
    2506                 InsertConfigNode(pUsbDevices, "HidMouse", &pDev);
    2507             if (aPointingHID == PointingHIDType_USBMouse)
    2508             {
    2509                 InsertConfigNode(pDev,     "0", &pInst);
    2510                 InsertConfigNode(pInst,    "Config", &pCfg);
    2511 
    2512                 InsertConfigString(pCfg,   "Mode", "relative");
    2513                 InsertConfigNode(pInst,    "LUN#0", &pLunL0);
    2514                 InsertConfigString(pLunL0, "Driver",        "MouseQueue");
    2515                 InsertConfigNode(pLunL0,   "Config", &pCfg);
    2516                 InsertConfigInteger(pCfg,  "QueueSize",            128);
    2517 
    2518                 InsertConfigNode(pLunL0,   "AttachedDriver", &pLunL1);
    2519                 InsertConfigString(pLunL1, "Driver",        "MainMouse");
    2520                 InsertConfigNode(pLunL1,   "Config", &pCfg);
    2521                 InsertConfigInteger(pCfg,  "Object",     (uintptr_t)pMouse);
    2522             }
    2523             if (   aPointingHID == PointingHIDType_USBTablet
    2524                 || aPointingHID == PointingHIDType_USBMultiTouch)
    2525             {
    2526                 InsertConfigNode(pDev,     "1", &pInst);
    2527                 InsertConfigNode(pInst,    "Config", &pCfg);
    2528 
    2529                 InsertConfigString(pCfg,   "Mode", "absolute");
    2530                 InsertConfigNode(pInst,    "LUN#0", &pLunL0);
    2531                 InsertConfigString(pLunL0, "Driver",        "MouseQueue");
    2532                 InsertConfigNode(pLunL0,   "Config", &pCfg);
    2533                 InsertConfigInteger(pCfg,  "QueueSize",            128);
    2534 
    2535                 InsertConfigNode(pLunL0,   "AttachedDriver", &pLunL1);
    2536                 InsertConfigString(pLunL1, "Driver",        "MainMouse");
    2537                 InsertConfigNode(pLunL1,   "Config", &pCfg);
    2538                 InsertConfigInteger(pCfg,  "Object",     (uintptr_t)pMouse);
    2539             }
    2540             if (aPointingHID == PointingHIDType_USBMultiTouch)
    2541             {
    2542                 InsertConfigNode(pDev,     "2", &pInst);
    2543                 InsertConfigNode(pInst,    "Config", &pCfg);
    2544 
    2545                 InsertConfigString(pCfg,   "Mode", "multitouch");
    2546                 InsertConfigNode(pInst,    "LUN#0", &pLunL0);
    2547                 InsertConfigString(pLunL0, "Driver",        "MouseQueue");
    2548                 InsertConfigNode(pLunL0,   "Config", &pCfg);
    2549                 InsertConfigInteger(pCfg,  "QueueSize",            128);
    2550 
    2551                 InsertConfigNode(pLunL0,   "AttachedDriver", &pLunL1);
    2552                 InsertConfigString(pLunL1, "Driver",        "MainMouse");
    2553                 InsertConfigNode(pLunL1,   "Config", &pCfg);
    2554                 InsertConfigInteger(pCfg,  "Object",     (uintptr_t)pMouse);
    2555             }
    2556 
    2557             /* Virtual USB Keyboard */
    2558             KeyboardHIDType_T aKbdHID;
    2559             hrc = pMachine->COMGETTER(KeyboardHIDType)(&aKbdHID);                       H();
    2560             if (aKbdHID == KeyboardHIDType_USBKeyboard)
    2561             {
    2562                 InsertConfigNode(pUsbDevices, "HidKeyboard", &pDev);
    2563                 InsertConfigNode(pDev,     "0", &pInst);
    2564                 InsertConfigNode(pInst,    "Config", &pCfg);
    2565 
    2566                 InsertConfigNode(pInst,    "LUN#0", &pLunL0);
    2567                 InsertConfigString(pLunL0, "Driver",               "KeyboardQueue");
    2568                 InsertConfigNode(pLunL0,   "Config", &pCfg);
    2569                 InsertConfigInteger(pCfg,  "QueueSize",            64);
    2570 
    2571                 InsertConfigNode(pLunL0,   "AttachedDriver", &pLunL1);
    2572                 InsertConfigString(pLunL1, "Driver",               "MainKeyboard");
    2573                 InsertConfigNode(pLunL1,   "Config", &pCfg);
    2574                 pKeyboard = mKeyboard;
    2575                 InsertConfigInteger(pCfg,  "Object",     (uintptr_t)pKeyboard);
    2576             }
    25772581        }
    25782582
     
    33453349        hrc = Console::convertBusPortDeviceToLun(enmBus, lPort, lDev, uLUN);                H();
    33463350
     3351        if (enmBus == StorageBus_USB)
     3352        {
     3353            PCFGMNODE pCfg = NULL;
     3354
     3355            /* Create correct instance. */
     3356            if (!fHotplug && !fAttachDetach)
     3357                InsertConfigNode(pCtlInst, Utf8StrFmt("%d", lPort).c_str(), &pCtlInst);
     3358            else if (fAttachDetach)
     3359                pCtlInst = CFGMR3GetChildF(pCtlInst, "%d/", lPort);
     3360
     3361            if (!fAttachDetach)
     3362                InsertConfigNode(pCtlInst, "Config", &pCfg);
     3363
     3364            uInstance = lPort; /* Overwrite uInstance with the correct one. */
     3365
     3366            if (!fHotplug && !fAttachDetach)
     3367            {
     3368                char aszUuid[RTUUID_STR_LENGTH + 1];
     3369                USBStorageDevice UsbMsd = USBStorageDevice();
     3370
     3371                memset(aszUuid, 0, sizeof(aszUuid));
     3372                rc = RTUuidCreate(&UsbMsd.mUuid);
     3373                AssertRCReturn(rc, rc);
     3374                rc = RTUuidToStr(&UsbMsd.mUuid, aszUuid, sizeof(aszUuid));
     3375                AssertRCReturn(rc, rc);
     3376
     3377                UsbMsd.iPort = uInstance;
     3378
     3379                InsertConfigString(pCtlInst, "UUID", aszUuid);
     3380                mUSBStorageDevices.push_back(UsbMsd);
     3381
     3382                /** @todo: No LED after hotplugging. */
     3383                /* Attach the status driver */
     3384                Assert(cLedUsb >= 8);
     3385                attachStatusDriver(pCtlInst, &mapStorageLeds[iLedUsb], 0, 7,
     3386                                   &mapMediumAttachments, pcszDevice, 0);
     3387                paLedDevType = &maStorageDevType[iLedUsb];
     3388            }
     3389        }
     3390
    33473391        /* First check if the LUN already exists. */
    33483392        pLunL0 = CFGMR3GetChildF(pCtlInst, "LUN#%u", uLUN);
     
    33773421                }
    33783422
    3379                 rc = PDMR3DeviceDetach(pUVM, pcszDevice, uInstance, uLUN, fHotplug ? 0 : PDM_TACH_FLAGS_NOT_HOT_PLUG);
     3423                if (enmBus == StorageBus_USB)
     3424                    rc = PDMR3UsbDriverDetach(pUVM, pcszDevice, uInstance, uLUN, NULL, 0, fHotplug ? 0 : PDM_TACH_FLAGS_NOT_HOT_PLUG);
     3425                else
     3426                    rc = PDMR3DeviceDetach(pUVM, pcszDevice, uInstance, uLUN, fHotplug ? 0 : PDM_TACH_FLAGS_NOT_HOT_PLUG);
    33803427                if (rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
    33813428                    rc = VINF_SUCCESS;
     
    34203467
    34213468        /* SCSI has a another driver between device and block. */
    3422         if (enmBus == StorageBus_SCSI || enmBus == StorageBus_SAS)
     3469        if (enmBus == StorageBus_SCSI || enmBus == StorageBus_SAS || enmBus == StorageBus_USB)
    34233470        {
    34243471            InsertConfigString(pLunL0, "Driver", "SCSI");
     
    36703717        {
    36713718            /* Attach the new driver. */
    3672             rc = PDMR3DeviceAttach(pUVM, pcszDevice, uInstance, uLUN,
    3673                                    fHotplug ? 0 : PDM_TACH_FLAGS_NOT_HOT_PLUG, NULL /*ppBase*/);
     3719            if (enmBus == StorageBus_USB)
     3720            {
     3721                if (fHotplug)
     3722                {
     3723                    USBStorageDevice UsbMsd = USBStorageDevice();
     3724                    RTUuidCreate(&UsbMsd.mUuid);
     3725                    UsbMsd.iPort = uInstance;
     3726                    rc = PDMR3UsbCreateEmulatedDevice(pUVM, pcszDevice, pCtlInst, &UsbMsd.mUuid);
     3727                    if (RT_SUCCESS(rc))
     3728                        mUSBStorageDevices.push_back(UsbMsd);
     3729                }
     3730                else
     3731                    rc = PDMR3UsbDriverAttach(pUVM, pcszDevice, uInstance, uLUN,
     3732                                              fHotplug ? 0 : PDM_TACH_FLAGS_NOT_HOT_PLUG, NULL /*ppBase*/);
     3733            }
     3734            else
     3735                rc = PDMR3DeviceAttach(pUVM, pcszDevice, uInstance, uLUN,
     3736                                       fHotplug ? 0 : PDM_TACH_FLAGS_NOT_HOT_PLUG, NULL /*ppBase*/);
    36743737            AssertRCReturn(rc, rc);
    36753738
Note: See TracChangeset for help on using the changeset viewer.

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