VirtualBox

Changeset 29758 in vbox


Ignore:
Timestamp:
May 24, 2010 8:38:48 AM (14 years ago)
Author:
vboxsync
Message:

AHCI: Fix crash on reset after a snapshot was taken. The Driver needs to be updated in the ATA emulation

Location:
trunk/src/VBox/Devices/Storage
Files:
3 edited

Legend:

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

    r28800 r29758  
    49654965}
    49664966
    4967 #if 0
    49684967/**
    49694968 * Detach notification.
     
    49724971 *
    49734972 * @param   pDevIns     The device instance.
    4974  * @param   iLUN        The logical unit which is being detached.
     4973 * @param   fMaster     True if the master is detached
     4974 *                      false for the slave
    49754975 */
    4976 static DECLCALLBACK(void) ataDetach(PPDMDEVINS pDevIns, unsigned iLUN)
    4977 {
    4978     PCIATAState    *pThis = PDMINS_2_DATA(pDevIns, PCIATAState *);
    4979     PAHCIATACONTROLLER  pCtl;
     4976void ataControllerDetach(PAHCIATACONTROLLER pCtl, bool fMaster)
     4977{
    49804978    AHCIATADevState    *pIf;
    4981     unsigned        iController;
    4982     unsigned        iInterface;
    49834979
    49844980    /*
    49854981     * Locate the controller and stuff.
    49864982     */
    4987     iController = iLUN / RT_ELEMENTS(pThis->aCts[0].aIfs);
    4988     AssertReleaseMsg(iController < RT_ELEMENTS(pThis->aCts), ("iController=%d iLUN=%d\n", iController, iLUN));
    4989     pCtl = &pThis->aCts[iController];
    4990 
    4991     iInterface  = iLUN % RT_ELEMENTS(pThis->aCts[0].aIfs);
    4992     pIf = &pCtl->aIfs[iInterface];
     4983    pIf = &pCtl->aIfs[fMaster ? 0 : 1];
    49934984
    49944985    /*
     
    49994990    pIf->pDrvBlockBios = NULL;
    50004991    pIf->pDrvMount = NULL;
    5001 
    5002     /*
    5003      * Just in case there was a medium inserted. Only required when attached to a physical drive
    5004      * in passthrough mode as in virtual ATAPI mode we've got an unmount notification.
    5005      */
    5006     if (pIf->fATAPIPassthrough)
    5007         ataMediumRemoved(pIf);
    5008 
    5009 }
    5010 #endif
     4992}
    50114993
    50124994/**
     
    51395121}
    51405122
    5141 #if 0
    51425123/**
    51435124 * Attach command.
     
    51495130 * @param   iLUN        The logical unit which is being detached.
    51505131 */
    5151 static DECLCALLBACK(int)  ataAttach(PPDMDEVINS pDevIns, unsigned iLUN)
    5152 {
    5153     PCIATAState    *pThis = PDMINS_2_DATA(pDevIns, PCIATAState *);
    5154     PAHCIATACONTROLLER  pCtl;
     5132int  ataControllerAttach(PAHCIATACONTROLLER pCtl, PPDMIBASE pDrvBase, bool fMaster)
     5133{
    51555134    AHCIATADevState    *pIf;
    51565135    int             rc;
    5157     unsigned        iController;
    5158     unsigned        iInterface;
    51595136
    51605137    /*
    51615138     * Locate the controller and stuff.
    51625139     */
    5163     iController = iLUN / RT_ELEMENTS(pThis->aCts[0].aIfs);
    5164     AssertReleaseMsg(iController < RT_ELEMENTS(pThis->aCts), ("iController=%d iLUN=%d\n", iController, iLUN));
    5165     pCtl = &pThis->aCts[iController];
    5166 
    5167     iInterface  = iLUN % RT_ELEMENTS(pThis->aCts[0].aIfs);
    5168     pIf = &pCtl->aIfs[iInterface];
     5140    pIf = &pCtl->aIfs[fMaster ? 0 : 1];
    51695141
    51705142    /* the usual paranoia */
     
    51725144    AssertRelease(!pIf->pDrvBlock);
    51735145    Assert(ATADEVSTATE_2_CONTROLLER(pIf) == pCtl);
    5174     Assert(pIf->iLUN == iLUN);
    51755146
    51765147    /*
     
    51785149     * required as well as optional.
    51795150     */
    5180     rc = PDMDevHlpDriverAttach(pDevIns, pIf->iLUN, &pIf->IBase, &pIf->pDrvBase, NULL);
    5181     if (RT_SUCCESS(rc))
    5182     {
    5183         rc = ataConfigLun(pDevIns, pIf);
    5184         /*
    5185          * In case there is a new medium inserted. In virtual ATAPI mode we get an mount
    5186          * notification.
    5187          */
    5188         if (pIf->fATAPIPassthrough)
    5189             ataMediumInserted(pIf);
     5151   
     5152    pIf->pDrvBase = pDrvBase;
     5153    if (pDrvBase)
     5154    {
     5155        rc = ataConfigLun(pCtl->pDevInsR3, pIf);
    51905156    }
    51915157    else
     
    51995165    return rc;
    52005166}
    5201 #endif
    52025167
    52035168
     
    54665431}
    54675432
    5468 DECLCALLBACK(int) ataControllerInit(PPDMDEVINS pDevIns, PAHCIATACONTROLLER pCtl, PPDMIBASE pDrvBaseMaster, PPDMIBASE pDrvBaseSlave,
     5433DECLCALLBACK(int) ataControllerInit(PPDMDEVINS pDevIns, PAHCIATACONTROLLER pCtl,
     5434                                    unsigned iLUNMaster, PPDMIBASE pDrvBaseMaster,
     5435                                    unsigned iLUNSlave, PPDMIBASE pDrvBaseSlave,
    54695436                                    uint32_t *pcbSSMState, const char *szName, PPDMLED pLed,
    54705437                                    PSTAMCOUNTER pStatBytesRead, PSTAMCOUNTER pStatBytesWritten)
     
    54845451    for (uint32_t j = 0; j < RT_ELEMENTS(pCtl->aIfs); j++)
    54855452    {
    5486         pCtl->aIfs[j].iLUN              = j;
     5453        pCtl->aIfs[j].iLUN              = j == 0 ? iLUNMaster : iLUNSlave;
    54875454        pCtl->aIfs[j].pDevInsR3         = pDevIns;
    54885455        pCtl->aIfs[j].pDevInsR0         = PDMDEVINS_2_R0PTR(pDevIns);
  • trunk/src/VBox/Devices/Storage/ATAController.h

    r28800 r29758  
    420420 * @param   szName         Name of the controller (Used to initialize the critical section).
    421421 */
    422 int ataControllerInit(PPDMDEVINS pDevIns, PAHCIATACONTROLLER pCtl, PPDMIBASE pDrvBaseMaster, PPDMIBASE pDrvBaseSlave,
     422int ataControllerInit(PPDMDEVINS pDevIns, PAHCIATACONTROLLER pCtl,
     423                      unsigned iLUNMaster, PPDMIBASE pDrvBaseMaster,
     424                      unsigned iLUNSlave, PPDMIBASE pDrvBaseSlave,
    423425                      uint32_t *pcbSSMState, const char *szName, PPDMLED pLed, PSTAMCOUNTER pStatBytesRead, PSTAMCOUNTER pStatBytesWritten);
    424426
     
    483485int ataControllerLoadExec(PAHCIATACONTROLLER pCtl, PSSMHANDLE pSSM);
    484486
     487/**
     488 * Attach command.
     489 *
     490 * This is called when we change block driver for the DVD drive.
     491 *
     492 * @returns VBox status code.
     493 * @param   pDevIns     The device instance.
     494 * @param   iLUN        The logical unit which is being detached.
     495 */
     496int  ataControllerAttach(PAHCIATACONTROLLER pCtl, PPDMIBASE pDrvBase, bool fMaster);
     497
     498/**
     499 * Detach notification.
     500 *
     501 * The DVD drive has been unplugged.
     502 *
     503 * @param   pDevIns     The device instance.
     504 * @param   fMaster     True if the master is detached
     505 *                      false for the slave
     506 */
     507void ataControllerDetach(PAHCIATACONTROLLER pCtl, bool fMaster);
     508
    485509#endif /* IN_RING3 */
    486510
  • trunk/src/VBox/Devices/Storage/DevAHCI.cpp

    r29672 r29758  
    65456545    }
    65466546
     6547    /* Check if the changed port uses IDE emulation. */
     6548    bool fMaster = false;
     6549    PAHCIATACONTROLLER pCtl = NULL;
     6550
     6551    for (unsigned i = 0; i < RT_ELEMENTS(pAhci->aCts); i++)
     6552        for (unsigned j = 0; j < RT_ELEMENTS(pAhci->aCts[0].aIfs); j++)
     6553        {
     6554            PAHCIATACONTROLLER pTmp = &pAhci->aCts[i];
     6555            if (pTmp->aIfs[j].iLUN == iLUN)
     6556            {
     6557                pCtl = pTmp;
     6558                fMaster = j == 0 ? true : false;
     6559            }
     6560        }
     6561
     6562    if (pCtl)
     6563        ataControllerDetach(pCtl, fMaster);
     6564
    65476565    /*
    65486566     * Zero some important members.
     
    65976615    else
    65986616    {
    6599         char szName[24];
    6600         RTStrPrintf(szName, sizeof(szName), "Port%d", iLUN);
    6601 
    6602         if (pAhciPort->pDrvBlockAsync)
    6603         {
    6604             pAhciPort->fAsyncInterface = true;
    6605         }
    6606         else
    6607         {
    6608             pAhciPort->fAsyncInterface = false;
    6609 
    6610             /* Create event semaphore. */
    6611             rc = RTSemEventCreate(&pAhciPort->AsyncIORequestSem);
    6612             if (RT_FAILURE(rc))
     6617        /* Check if the changed port uses IDE emulation. */
     6618        bool fMaster = false;
     6619        PAHCIATACONTROLLER pCtl = NULL;
     6620
     6621        for (unsigned i = 0; i < RT_ELEMENTS(pAhci->aCts); i++)
     6622            for (unsigned j = 0; j < RT_ELEMENTS(pAhci->aCts[0].aIfs); j++)
    66136623            {
    6614                 Log(("%s: Failed to create event semaphore for %s.\n", __FUNCTION__, szName));
    6615                 return rc;
     6624                PAHCIATACONTROLLER pTmp = &pAhci->aCts[i];
     6625                if (pTmp->aIfs[j].iLUN == iLUN)
     6626                {
     6627                    pCtl = pTmp;
     6628                    fMaster = j == 0 ? true : false;
     6629                }
    66166630            }
    66176631
    6618             /* Create the async IO thread. */
    6619             rc = PDMDevHlpThreadCreate(pDevIns, &pAhciPort->pAsyncIOThread, pAhciPort, ahciAsyncIOLoop, ahciAsyncIOLoopWakeUp, 0,
    6620                                        RTTHREADTYPE_IO, szName);
    6621             if (RT_FAILURE(rc))
     6632        /* Attach to the controller if available */
     6633        if (pCtl)
     6634            rc = ataControllerAttach(pCtl, pAhciPort->pDrvBase, fMaster);
     6635
     6636        if (RT_SUCCESS(rc))
     6637        {
     6638            if (pAhciPort->pDrvBlockAsync)
    66226639            {
    6623                 AssertMsgFailed(("%s: Async IO Thread creation for %s failed rc=%d\n", __FUNCTION__, szName, rc));
    6624                 return rc;
     6640                pAhciPort->fAsyncInterface = true;
     6641            }
     6642            else
     6643            {
     6644                char szName[24];
     6645                RTStrPrintf(szName, sizeof(szName), "Port%d", iLUN);
     6646
     6647                pAhciPort->fAsyncInterface = false;
     6648
     6649                /* Create event semaphore. */
     6650                rc = RTSemEventCreate(&pAhciPort->AsyncIORequestSem);
     6651                if (RT_FAILURE(rc))
     6652                {
     6653                    Log(("%s: Failed to create event semaphore for %s.\n", __FUNCTION__, szName));
     6654                    return rc;
     6655                }
     6656
     6657                /* Create the async IO thread. */
     6658                rc = PDMDevHlpThreadCreate(pDevIns, &pAhciPort->pAsyncIOThread, pAhciPort, ahciAsyncIOLoop, ahciAsyncIOLoopWakeUp, 0,
     6659                                           RTTHREADTYPE_IO, szName);
     6660                if (RT_FAILURE(rc))
     6661                {
     6662                    AssertMsgFailed(("%s: Async IO Thread creation for %s failed rc=%d\n", __FUNCTION__, szName, rc));
     6663                    return rc;
     6664                }
    66256665            }
    66266666        }
     
    71387178        char szName[24];
    71397179        RTStrPrintf(szName, sizeof(szName), "EmulatedATA%d", i);
    7140         rc = ataControllerInit(pDevIns, pCtl, pThis->ahciPort[iPortMaster].pDrvBase, pThis->ahciPort[iPortSlave].pDrvBase,
    7141                                &cbSSMState, szName, &pThis->ahciPort[iPortMaster].Led, &pThis->ahciPort[iPortMaster].StatBytesRead,
     7180        rc = ataControllerInit(pDevIns, pCtl,
     7181                               iPortMaster, pThis->ahciPort[iPortMaster].pDrvBase,
     7182                               iPortSlave, pThis->ahciPort[iPortSlave].pDrvBase,
     7183                               &cbSSMState, szName, &pThis->ahciPort[iPortMaster].Led,
     7184                               &pThis->ahciPort[iPortMaster].StatBytesRead,
    71427185                               &pThis->ahciPort[iPortMaster].StatBytesWritten);
    71437186        if (RT_FAILURE(rc))
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