VirtualBox

Changeset 48981 in vbox


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

Devices/UsbMsd: Updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/UsbMsd.cpp

    r48947 r48981  
    237237     * This is waiting for SCSI request completion before finishing the reset. */
    238238    PVUSBURB            pResetUrb;
     239    /** Indicates that PDMUsbHlpAsyncNotificationCompleted should be called when
     240     * the MSD is entering the idle state. */
     241    volatile bool       fSignalIdle;
    239242
    240243    /**
     
    914917
    915918    RTCritSectLeave(&pThis->CritSect);
     919    return VINF_SUCCESS;
     920}
     921
     922
     923/**
     924 * @interface_method_impl{PDMISCSIPORT,pfnQueryDeviceLocation}
     925 */
     926static DECLCALLBACK(int) usbMsdLun0QueryDeviceLocation(PPDMISCSIPORT pInterface, const char **ppcszController,
     927                                                       uint32_t *piInstance, uint32_t *piLUN)
     928{
     929    PUSBMSD    pThis = RT_FROM_MEMBER(pInterface, USBMSD, Lun0.IScsiPort);
     930    PPDMUSBINS pUsbIns = pThis->pUsbIns;
     931
     932    AssertPtrReturn(ppcszController, VERR_INVALID_POINTER);
     933    AssertPtrReturn(piInstance, VERR_INVALID_POINTER);
     934    AssertPtrReturn(piLUN, VERR_INVALID_POINTER);
     935
     936    *ppcszController = pUsbIns->pReg->szName;
     937    *piInstance = pUsbIns->iInstance;
     938    *piLUN = 0;
     939
    916940    return VINF_SUCCESS;
    917941}
     
    12581282                }
    12591283            }
    1260 LogRel(("DATA_FROM_HOST: %d bytes\n", cbData));
    12611284            return usbMsdCompleteOk(pThis, pUrb, cbData);
    12621285        }
     
    13191342                pReq->enmState = USBMSDREQSTATE_STATUS;
    13201343            }
    1321 LogRel(("DATA_TO_HOST: %d bytes\n", cbCopy));
    13221344            return usbMsdCompleteOk(pThis, pUrb, cbCopy);
    13231345        }
     
    16301652
    16311653/**
     1654 * Checks if all asynchronous I/O is finished.
     1655 *
     1656 * Used by usbMsdVMReset, usbMsdVMSuspend and usbMsdVMPowerOff.
     1657 *
     1658 * @returns true if quiesced, false if busy.
     1659 * @param   pUsbIns         The USB device instance.
     1660 */
     1661static bool usbMsdAllAsyncIOIsFinished(PPDMUSBINS pUsbIns)
     1662{
     1663    PUSBMSD pThis = PDMINS_2_DATA(pUsbIns, PUSBMSD);
     1664
     1665    if (   VALID_PTR(pThis->pReq)
     1666        && pThis->pReq->enmState == USBMSDREQSTATE_EXECUTING)
     1667        return false;
     1668
     1669    return true;
     1670}
     1671
     1672/**
     1673 * @callback_method_impl{FNPDMDEVASYNCNOTIFY,
     1674 * Callback employed by usbMsdVMSuspend and usbMsdVMPowerOff.}
     1675 */
     1676static DECLCALLBACK(bool) usbMsdIsAsyncSuspendOrPowerOffDone(PPDMUSBINS pUsbIns)
     1677{
     1678    if (!usbMsdAllAsyncIOIsFinished(pUsbIns))
     1679        return false;
     1680
     1681    PUSBMSD pThis = PDMINS_2_DATA(pUsbIns, PUSBMSD);
     1682    ASMAtomicWriteBool(&pThis->fSignalIdle, false);
     1683    return true;
     1684}
     1685
     1686/**
     1687 * Common worker for usbMsdVMSuspend and usbMsdVMPowerOff.
     1688 */
     1689static void usbMsdSuspendOrPowerOff(PPDMUSBINS pUsbIns)
     1690{
     1691    PUSBMSD pThis = PDMINS_2_DATA(pUsbIns, PUSBMSD);
     1692
     1693    ASMAtomicWriteBool(&pThis->fSignalIdle, true);
     1694    if (!usbMsdAllAsyncIOIsFinished(pUsbIns))
     1695        PDMUsbHlpSetAsyncNotification(pUsbIns, usbMsdIsAsyncSuspendOrPowerOffDone);
     1696    else
     1697        ASMAtomicWriteBool(&pThis->fSignalIdle, false);
     1698}
     1699
     1700
     1701/**
     1702 * @copydoc PDMUSBREG::pfnVMSuspend
     1703 */
     1704static DECLCALLBACK(void) usbMsdVMSuspend(PPDMUSBINS pUsbIns)
     1705{
     1706    LogFlow(("usbMsdVMSuspend/#%u:\n", pUsbIns->iInstance));
     1707    usbMsdSuspendOrPowerOff(pUsbIns);
     1708}
     1709
     1710
     1711/**
     1712 * @copydoc PDMUSBREG::pfnVMSuspend
     1713 */
     1714static DECLCALLBACK(void) usbMsdVMPowerOff(PPDMUSBINS pUsbIns)
     1715{
     1716    LogFlow(("usbMsdVMPowerOff/#%u:\n", pUsbIns->iInstance));
     1717    usbMsdSuspendOrPowerOff(pUsbIns);
     1718}
     1719
     1720
     1721/**
     1722 * @copydoc PDMUSBREG::pfnDriverAttach
     1723 */
     1724static DECLCALLBACK(int) usbMsdDriverAttach(PPDMUSBINS pUsbIns, unsigned iLUN, uint32_t fFlags)
     1725{
     1726    PUSBMSD pThis = PDMINS_2_DATA(pUsbIns, PUSBMSD);
     1727    int rc;
     1728
     1729    LogFlow(("usbMsdDetach/#%u:\n", pUsbIns->iInstance));
     1730
     1731    AssertMsg(iLUN == 0, ("UsbMsd: No other LUN than 0 is supported\n"));
     1732    AssertMsg(fFlags & PDM_TACH_FLAGS_NOT_HOT_PLUG,
     1733              ("UsbMsd: Device does not support hotplugging\n"));
     1734
     1735    /* the usual paranoia */
     1736    AssertRelease(!pThis->Lun0.pIBase);
     1737    AssertRelease(!pThis->Lun0.pIScsiConnector);
     1738
     1739    /*
     1740     * Try attach the block device and get the interfaces,
     1741     * required as well as optional.
     1742     */
     1743    rc = PDMUsbHlpDriverAttach(pUsbIns, iLUN, &pThis->Lun0.IBase, &pThis->Lun0.pIBase, NULL);
     1744    if (RT_SUCCESS(rc))
     1745    {
     1746        /* Get SCSI connector interface. */
     1747        pThis->Lun0.pIScsiConnector = PDMIBASE_QUERY_INTERFACE(pThis->Lun0.pIBase, PDMISCSICONNECTOR);
     1748        AssertMsgReturn(pThis->Lun0.pIScsiConnector, ("Missing SCSI interface below\n"), VERR_PDM_MISSING_INTERFACE);
     1749    }
     1750    else
     1751        AssertMsgFailed(("Failed to attach LUN#%d. rc=%Rrc\n", iLUN, rc));
     1752
     1753    if (RT_FAILURE(rc))
     1754    {
     1755        pThis->Lun0.pIBase = NULL;
     1756        pThis->Lun0.pIScsiConnector = NULL;
     1757    }
     1758    return rc;
     1759}
     1760
     1761
     1762/**
     1763 * @copydoc PDMUSBREG::pfnDriverDetach
     1764 */
     1765static DECLCALLBACK(void) usbMsdDriverDetach(PPDMUSBINS pUsbIns, unsigned iLUN, uint32_t fFlags)
     1766{
     1767    PUSBMSD pThis = PDMINS_2_DATA(pUsbIns, PUSBMSD);
     1768
     1769    LogFlow(("usbMsdDetach/#%u:\n", pUsbIns->iInstance));
     1770
     1771    AssertMsg(iLUN == 0, ("UsbMsd: No other LUN than 0 is supported\n"));
     1772    AssertMsg(fFlags & PDM_TACH_FLAGS_NOT_HOT_PLUG,
     1773              ("UsbMsd: Device does not support hotplugging\n"));
     1774
     1775    /*
     1776     * Zero some important members.
     1777     */
     1778    pThis->Lun0.pIBase = NULL;
     1779    pThis->Lun0.pIScsiConnector = NULL;
     1780}
     1781
     1782
     1783/**
     1784 * @callback_method_impl{FNPDMDEVASYNCNOTIFY,
     1785 * Callback employed by usbMsdVMReset.}
     1786 */
     1787static DECLCALLBACK(bool) usbMsdIsAsyncResetDone(PPDMUSBINS pUsbIns)
     1788{
     1789    PUSBMSD pThis = PDMINS_2_DATA(pUsbIns, PUSBMSD);
     1790
     1791    if (!usbMsdAllAsyncIOIsFinished(pUsbIns))
     1792        return false;
     1793    ASMAtomicWriteBool(&pThis->fSignalIdle, false);
     1794
     1795    int rc = usbMsdResetWorker(pThis, NULL, false /*fSetConfig*/);
     1796    AssertRC(rc);
     1797    return true;
     1798}
     1799
     1800/**
     1801 * @interface_method_impl{PDMDEVREG,pfnReset}
     1802 */
     1803static DECLCALLBACK(void) usbMsdVMReset(PPDMUSBINS pUsbIns)
     1804{
     1805    PUSBMSD pThis = PDMINS_2_DATA(pUsbIns, PUSBMSD);
     1806
     1807    ASMAtomicWriteBool(&pThis->fSignalIdle, true);
     1808    if (!usbMsdAllAsyncIOIsFinished(pUsbIns))
     1809        PDMUsbHlpSetAsyncNotification(pUsbIns, usbMsdIsAsyncResetDone);
     1810    else
     1811    {
     1812        ASMAtomicWriteBool(&pThis->fSignalIdle, false);
     1813        int rc = usbMsdResetWorker(pThis, NULL, false /*fSetConfig*/);
     1814        AssertRC(rc);
     1815    }
     1816}
     1817
     1818
     1819/**
    16321820 * @copydoc PDMUSBREG::pfnDestruct
    16331821 */
     
    16811869    pThis->Lun0.IBase.pfnQueryInterface             = usbMsdLun0QueryInterface;
    16821870    pThis->Lun0.IScsiPort.pfnSCSIRequestCompleted   = usbMsdLun0ScsiRequestCompleted;
     1871    pThis->Lun0.IScsiPort.pfnQueryDeviceLocation    = usbMsdLun0QueryDeviceLocation;
    16831872    usbMsdQueueInit(&pThis->ToHostQueue);
    16841873    usbMsdQueueInit(&pThis->DoneQueue);
     
    17411930    NULL,
    17421931    /* pfnVMReset */
    1743     NULL,
     1932    usbMsdVMReset,
    17441933    /* pfnVMSuspend */
    1745     NULL,
     1934    usbMsdVMSuspend,
    17461935    /* pfnVMResume */
    17471936    NULL,
    17481937    /* pfnVMPowerOff */
    1749     NULL,
     1938    usbMsdVMPowerOff,
    17501939    /* pfnHotPlugged */
    17511940    NULL,
     
    17531942    NULL,
    17541943    /* pfnDriverAttach */
    1755     NULL,
     1944    usbMsdDriverAttach,
    17561945    /* pfnDriverDetach */
    1757     NULL,
     1946    usbMsdDriverDetach,
    17581947    /* pfnQueryInterface */
    17591948    NULL,
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