VirtualBox

Changeset 93956 in vbox for trunk/src/VBox/Devices/USB


Ignore:
Timestamp:
Feb 25, 2022 4:21:22 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
150186
Message:

Devices/USB: Eliminiate some callback ping-pong and streamline the device attach/detach logic, bugref:10196 [fix, the saved state logic needs to use the new logic as well]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/USB/DrvVUSBRootHub.cpp

    r93955 r93956  
    400400
    401401
     402/**
     403 * Detaches the given device from the given roothub.
     404 *
     405 * @returns VBox status code.
     406 * @param   pThis       The roothub to detach the device from.
     407 * @param   pDev        The device to detach.
     408 */
     409static int vusbHubDetach(PVUSBROOTHUB pThis, PVUSBDEV pDev)
     410{
     411    PVUSBHUB pHub = &pThis->Hub;
     412
     413    Assert(pDev->i16Port != -1);
     414
     415    /* Cancel all in-flight URBs from this device. */
     416    vusbDevCancelAllUrbs(pDev, true);
     417
     418    /*
     419     * Detach the device and mark the port as available.
     420     */
     421    unsigned uPort = pDev->i16Port;
     422    pDev->i16Port = -1;
     423    pThis->pIRhPort->pfnDetach(pThis->pIRhPort, uPort);
     424    ASMBitSet(&pThis->Bitmap, uPort);
     425    pHub->cDevices--;
     426
     427    /* Check that it's attached and remove it. */
     428    RTCritSectEnter(&pThis->CritSectDevices);
     429    Assert(pThis->apDevByPort[uPort] == pDev);
     430    pThis->apDevByPort[uPort]  = NULL;
     431
     432    if (pDev->u8Address == VUSB_DEFAULT_ADDRESS)
     433    {
     434        AssertPtr(pThis->apDevByAddr[VUSB_DEFAULT_ADDRESS]);
     435
     436        if (pDev == pThis->apDevByAddr[VUSB_DEFAULT_ADDRESS])
     437            pThis->apDevByAddr[VUSB_DEFAULT_ADDRESS] = pDev->pNextDefAddr;
     438        else
     439        {
     440            /* Search the list for the device and remove it. */
     441            PVUSBDEV pDevPrev = pThis->apDevByAddr[VUSB_DEFAULT_ADDRESS];
     442
     443            while (   pDevPrev
     444                   && pDevPrev->pNextDefAddr != pDev)
     445                pDevPrev = pDevPrev->pNextDefAddr;
     446
     447            AssertPtr(pDevPrev);
     448            pDevPrev->pNextDefAddr = pDev->pNextDefAddr;
     449        }
     450
     451        pDev->pNextDefAddr = NULL;
     452    }
     453    else
     454    {
     455        Assert(pThis->apDevByAddr[pDev->u8Address] == pDev);
     456        pThis->apDevByAddr[pDev->u8Address] = NULL;
     457    }
     458    RTCritSectLeave(&pThis->CritSectDevices);
     459
     460    /* Free resources. */
     461    vusbDevDetach(pDev);
     462    return VINF_SUCCESS;
     463}
     464
     465
     466
    402467/* -=-=-=-=-=- PDMUSBHUBREG methods -=-=-=-=-=- */
    403468
     
    440505    Assert(pDev);
    441506
     507    LogRel(("VUSB: Detached '%s' from port %u on %s\n", pDev->pUsbIns->pszName, pDev->i16Port, pHub->pszName));
     508
    442509    /*
    443510     * Deal with pending async reset.
     
    445512     */
    446513    vusbDevSetStateCmp(pDev, VUSB_DEVICE_STATE_DEFAULT, VUSB_DEVICE_STATE_RESET);
    447     Assert(pDev->i16Port != -1);
    448 
    449     /* Cancel all in-flight URBs from this device. */
    450     vusbDevCancelAllUrbs(pDev, true);
    451 
    452     /*
    453      * Detach the device and mark the port as available.
    454      */
    455     unsigned uPort = pDev->i16Port;
    456     pDev->i16Port = -1;
    457     pThis->pIRhPort->pfnDetach(pThis->pIRhPort, uPort);
    458     ASMBitSet(&pThis->Bitmap, uPort);
    459     pHub->cDevices--;
    460 
    461     /* Check that it's attached and remove it. */
    462     RTCritSectEnter(&pThis->CritSectDevices);
    463     Assert(pThis->apDevByPort[uPort] == pDev);
    464     pThis->apDevByPort[uPort]  = NULL;
    465 
    466     if (pDev->u8Address == VUSB_DEFAULT_ADDRESS)
    467     {
    468         AssertPtr(pThis->apDevByAddr[VUSB_DEFAULT_ADDRESS]);
    469 
    470         if (pDev == pThis->apDevByAddr[VUSB_DEFAULT_ADDRESS])
    471             pThis->apDevByAddr[VUSB_DEFAULT_ADDRESS] = pDev->pNextDefAddr;
    472         else
    473         {
    474             /* Search the list for the device and remove it. */
    475             PVUSBDEV pDevPrev = pThis->apDevByAddr[VUSB_DEFAULT_ADDRESS];
    476 
    477             while (   pDevPrev
    478                    && pDevPrev->pNextDefAddr != pDev)
    479                 pDevPrev = pDevPrev->pNextDefAddr;
    480 
    481             AssertPtr(pDevPrev);
    482             pDevPrev->pNextDefAddr = pDev->pNextDefAddr;
    483         }
    484 
    485         pDev->pNextDefAddr = NULL;
    486     }
    487     else
    488     {
    489         Assert(pThis->apDevByAddr[pDev->u8Address] == pDev);
    490         pThis->apDevByAddr[pDev->u8Address] = NULL;
    491     }
    492     RTCritSectLeave(&pThis->CritSectDevices);
    493 
    494     /*
    495      * Detach and free resources.
    496      */
    497     vusbDevDetach(pDev);
    498 
    499     LogRel(("VUSB: Detached '%s' from port %u on %s\n", pDev->pUsbIns->pszName, uPort, pHub->pszName));
     514    vusbHubDetach(pThis, pDev);
    500515    vusbDevRelease(pDev);
    501516    return VINF_SUCCESS;
     
    13171332            if (!VUSBIDevIsSavedStateSupported(&pDev->IDevice))
    13181333            {
    1319                 int rc = vusbDevDetach(pDev);
     1334                int rc = vusbHubDetach(pThis, pDev);
    13201335                AssertRC(rc);
    13211336
     
    14131428            {
    14141429                Load.apDevs[Load.cDevs++] = pDev;
    1415                 vusbDevDetach(pDev);
     1430                vusbHubDetach(pThis, pDev);
    14161431                Assert(!pThis->apDevByPort[i]);
    14171432            }
Note: See TracChangeset for help on using the changeset viewer.

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