VirtualBox

Changeset 79535 in vbox


Ignore:
Timestamp:
Jul 5, 2019 6:05:14 AM (6 years ago)
Author:
vboxsync
Message:

Added some code to support status driver attach. That call still fails, so #ifdef'd it out for now

File:
1 edited

Legend:

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

    r79494 r79535  
    7171    bool                          fPresent;
    7272
     73    /** Media port interface. */
     74    PDMIMEDIAPORT                 IMediaPort;
     75    /** Extended media port interface. */
     76    PDMIMEDIAEXPORT               IMediaExPort;
    7377    /** Led interface. */
    7478    PDMILEDPORTS                  ILed;
     
    7680    /** The status LED state for this device. */
    7781    PDMLED                        Led;
     82
     83    /** Number of outstanding tasks on the port. */
     84    volatile uint32_t             cOutstandingRequests;
    7885
    7986} VIRTIOSCSITARGET;
     
    132139    RTGCPHYS                        MMIOBase;
    133140
     141    /** Status LUN: Media Notifys. */
     142    R3PTRTYPE(PPDMIMEDIANOTIFY)     pMediaNotify;
     143
    134144    /** Partner of ILeds. */
    135145    R3PTRTYPE(PPDMILEDCONNECTORS)   pLedsConnector;
     146
     147    /** Indicates that PDMDevHlpAsyncNotificationCompleted should be called when
     148     * a port is entering the idle state. */
     149    bool volatile                   fSignalIdle;
    136150
    137151} VIRTIOSCSI, *PVIRTIOSCSI;
     
    293307    Assert(cb == 1);
    294308
    295 //    return buslogicRegisterRead(pBusLogic, iRegister, pu32);
     309//    return buslogicRegisterRead(pVirtioScsi, iRegister, pu32);
    296310    return 0;
    297311}
     
    321335    Assert(cb == 1);
    322336
    323 //    int rc = buslogicRegisterWrite(pBusLogic, iRegister, (uint8_t)uVal);
     337//    int rc = buslogicRegisterWrite(pVirtioScsi, iRegister, (uint8_t)uVal);
    324338    int rc = 0;
    325339    Log2(("#%d %s: pvUser=%#p cb=%d u32=%#x uPort=%#x rc=%Rrc\n",
     
    332346 * @callback_method_impl{FNPCIIOREGIONMAP}
    333347 */
    334 static DECLCALLBACK(int) devVirtioScsiR3MmioMap(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
     348static DECLCALLBACK(int) virtioScsiR3MmioMap(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
    335349                                           RTGCPHYS GCPhysAddress, RTGCPHYS cb, PCIADDRESSSPACE enmType)
    336350{
     
    416430        PVIRTIOSCSITARGET pTarget = &pThis->aTargetInstances[i];
    417431        pTarget->pVirtioScsiR3 = pThis;;
    418 
    419   }
    420 
    421 }
     432    }
     433
     434}
     435
     436static DECLCALLBACK(int) virtioScsiR3QueryDeviceLocation(PPDMIMEDIAPORT pInterface, const char **ppcszController,
     437                                                       uint32_t *piInstance, uint32_t *piLUN)
     438{
     439    PVIRTIOSCSITARGET pVirtioScsiTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, IMediaPort);
     440    PPDMDEVINS pDevIns = pVirtioScsiTarget->CTX_SUFF(pVirtioScsi)->CTX_SUFF(pDevIns);
     441
     442    AssertPtrReturn(ppcszController, VERR_INVALID_POINTER);
     443    AssertPtrReturn(piInstance, VERR_INVALID_POINTER);
     444    AssertPtrReturn(piLUN, VERR_INVALID_POINTER);
     445
     446    *ppcszController = pDevIns->pReg->szName;
     447    *piInstance = pDevIns->iInstance;
     448    *piLUN = pVirtioScsiTarget->iLUN;
     449
     450    return VINF_SUCCESS;
     451}
     452
     453/**
     454 * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqCopyFromBuf}
     455 */
     456static DECLCALLBACK(int) virtioScsiR3IoReqCopyFromBuf(PPDMIMEDIAEXPORT pInterface, PDMMEDIAEXIOREQ hIoReq,
     457                                                    void *pvIoReqAlloc, uint32_t offDst, PRTSGBUF pSgBuf,
     458                                                    size_t cbCopy)
     459{
     460NOREF(pInterface);
     461NOREF(pvIoReqAlloc);
     462NOREF(offDst);
     463NOREF(pSgBuf);
     464
     465    RT_NOREF1(hIoReq);
     466//    PVIRTIOSCSITARGET pTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, IMediaExPort);
     467//    PVIRTIOSCSIREQ pReq = (PVIRTIOSCSIREQ)pvIoReqAlloc;
     468
     469    size_t cbCopied = 0;
     470/*
     471    if (RT_UNLIKELY(pReq->fBIOS))
     472        cbCopied = vboxscsiCopyToBuf(&pTarget->CTX_SUFF(pVirtioScsi)->VBoxSCSI, pSgBuf, offDst, cbCopy);
     473    else
     474        cbCopied = virtioScsiR3CopySgBufToGuest(pTarget->CTX_SUFF(pVirtioScsi), pReq, pSgBuf, offDst, cbCopy);
     475*/
     476    return cbCopied == cbCopy ? VINF_SUCCESS : VERR_PDM_MEDIAEX_IOBUF_OVERFLOW;
     477}
     478
     479/**
     480 * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqCopyToBuf}
     481 */
     482static DECLCALLBACK(int) virtioScsiR3IoReqCopyToBuf(PPDMIMEDIAEXPORT pInterface, PDMMEDIAEXIOREQ hIoReq,
     483                                                  void *pvIoReqAlloc, uint32_t offSrc, PRTSGBUF pSgBuf,
     484                                                  size_t cbCopy)
     485{
     486NOREF(pInterface);
     487NOREF(pvIoReqAlloc);
     488NOREF(offSrc);
     489NOREF(pSgBuf);
     490
     491    RT_NOREF1(hIoReq);
     492//    PVIRTIOSCSITARGET pTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, IMediaExPort);
     493//    PVIRTIOSCSIREQ pReq = (PVIRTIOSCSIREQ)pvIoReqAlloc;
     494
     495    size_t cbCopied = 0;
     496/*
     497    if (RT_UNLIKELY(pReq->fBIOS))
     498        cbCopied = vboxscsiCopyFromBuf(&pTarget->CTX_SUFF(pVirtioScsi)->VBoxSCSI, pSgBuf, offSrc, cbCopy);
     499    else
     500        cbCopied = vboxscsiR3CopySgBufFromGuest(pTarget->CTX_SUFF(pVirtioScsi), pReq, pSgBuf, offSrc, cbCopy);
     501*/
     502    return cbCopied == cbCopy ? VINF_SUCCESS : VERR_PDM_MEDIAEX_IOBUF_UNDERRUN;
     503}
     504
     505/**
     506 * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqCompleteNotify}
     507 */
     508static DECLCALLBACK(int) virtioScsiR3IoReqCompleteNotify(PPDMIMEDIAEXPORT pInterface, PDMMEDIAEXIOREQ hIoReq,
     509                                                       void *pvIoReqAlloc, int rcReq)
     510{
     511NOREF(pInterface);
     512NOREF(pvIoReqAlloc);
     513NOREF(rcReq);
     514    RT_NOREF(hIoReq);
     515//    PVIRTIOSCSITARGET pTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, IMediaExPort);
     516//    virtioScsiR3ReqComplete(pTarget->CTX_SUFF(pVirtioScsi), (VIRTIOSCSIREQ)pvIoReqAlloc, rcReq);
     517    return VINF_SUCCESS;
     518}
     519
     520/**
     521 * @interface_method_impl{PDMIMEDIAEXPORT,pfnIoReqStateChanged}
     522 */
     523static DECLCALLBACK(void) virtioScsiR3IoReqStateChanged(PPDMIMEDIAEXPORT pInterface, PDMMEDIAEXIOREQ hIoReq,
     524                                                      void *pvIoReqAlloc, PDMMEDIAEXIOREQSTATE enmState)
     525{
     526
     527NOREF(pInterface);
     528NOREF(hIoReq);
     529NOREF(enmState);
     530    RT_NOREF3(hIoReq, pvIoReqAlloc, enmState);
     531    PVIRTIOSCSITARGET pTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, IMediaExPort);
     532
     533    switch (enmState)
     534    {
     535        case PDMMEDIAEXIOREQSTATE_SUSPENDED:
     536        {
     537            /* Make sure the request is not accounted for so the VM can suspend successfully. */
     538            uint32_t cTasksActive = ASMAtomicDecU32(&pTarget->cOutstandingRequests);
     539            if (!cTasksActive && pTarget->CTX_SUFF(pVirtioScsi)->fSignalIdle)
     540                PDMDevHlpAsyncNotificationCompleted(pTarget->CTX_SUFF(pVirtioScsi)->pDevInsR3);
     541            break;
     542        }
     543        case PDMMEDIAEXIOREQSTATE_ACTIVE:
     544            /* Make sure the request is accounted for so the VM suspends only when the request is complete. */
     545            ASMAtomicIncU32(&pTarget->cOutstandingRequests);
     546            break;
     547        default:
     548            AssertMsgFailed(("Invalid request state given %u\n", enmState));
     549    }
     550}
     551
     552/**
     553 * Gets the pointer to the status LED of a device - called from the SCSI driver.
     554 *
     555 * @returns VBox status code.
     556 * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     557 * @param   iLUN            The unit which status LED we desire. Always 0 here as the driver
     558 *                          doesn't know about other LUN's.
     559 * @param   ppLed           Where to store the LED pointer.
     560 */
     561static DECLCALLBACK(int) virtioScsiR3DeviceQueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
     562{
     563    PVIRTIOSCSITARGET pTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, ILed);
     564    if (iLUN == 0)
     565    {
     566        *ppLed = &pTarget->Led;
     567        Assert((*ppLed)->u32Magic == PDMLED_MAGIC);
     568        return VINF_SUCCESS;
     569    }
     570    return VERR_PDM_LUN_NOT_FOUND;
     571}
     572
     573/**
     574 * @interface_method_impl{PDMIMEDIAEXPORT,pfnMediumEjected}
     575 */
     576static DECLCALLBACK(void) virtioScsiR3MediumEjected(PPDMIMEDIAEXPORT pInterface)
     577{
     578    PVIRTIOSCSITARGET pTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, IMediaExPort);
     579    PVIRTIOSCSI pThis = pTarget->CTX_SUFF(pVirtioScsi);
     580
     581    if (pThis->pMediaNotify)
     582    {
     583        int rc = VMR3ReqCallNoWait(PDMDevHlpGetVM(pThis->CTX_SUFF(pDevIns)), VMCPUID_ANY,
     584                                   (PFNRT)pThis->pMediaNotify->pfnEjected, 2,
     585                                   pThis->pMediaNotify, pTarget->iLUN);
     586        AssertRC(rc);
     587    }
     588}
     589
    422590
    423591/**
     
    428596    PVIRTIOSCSITARGET pTarget = RT_FROM_MEMBER(pInterface, VIRTIOSCSITARGET, IBase);
    429597    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pTarget->IBase);
    430 //    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAPORT, &pTarget->IMediaPort);
    431 //    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAEXPORT, &pTarget->IMediaExPort);
     598    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAPORT, &pTarget->IMediaPort);
     599    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMEDIAEXPORT, &pTarget->IMediaExPort);
    432600    PDMIBASE_RETURN_INTERFACE(pszIID, PDMILEDPORTS, &pTarget->ILed);
    433601    return NULL;
     
    454622}
    455623
    456 static DECLCALLBACK(int) devVirtIoScsiDestruct(PPDMDEVINS pDevIns)
     624static DECLCALLBACK(int) virtioScsiDestruct(PPDMDEVINS pDevIns)
    457625{
    458626    /*
     
    464632}
    465633
    466 static DECLCALLBACK(int) devVirtioScsiConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
     634static DECLCALLBACK(int) virtioScsiConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
    467635{
    468636
     
    531699
    532700LogFunc(("Register io region\n"));
    533     rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 32, PCI_ADDRESS_SPACE_IO, devVirtioScsiR3MmioMap);
     701    rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 32, PCI_ADDRESS_SPACE_IO, virtioScsiR3MmioMap);
    534702    if (RT_FAILURE(rc))
    535703        return PDMDEV_SET_ERROR(pDevIns, rc, N_("virtio-scsi cannot register PCI I/O address space"));
    536704LogFunc(("Register mmio region\n"));
    537     rc = PDMDevHlpPCIIORegionRegister(pDevIns, 1, 32, PCI_ADDRESS_SPACE_MEM, devVirtioScsiR3MmioMap);
     705    rc = PDMDevHlpPCIIORegionRegister(pDevIns, 1, 32, PCI_ADDRESS_SPACE_MEM, virtioScsiR3MmioMap);
    538706    if (RT_FAILURE(rc))
    539707        return PDMDEV_SET_ERROR(pDevIns, rc, N_("virtio-scsi cannot register PCI mmio address space"));
    540 
    541708#if 0
    542709    if (fBootable)
     
    551718    }
    552719#endif
    553 
    554720    /* Initialize task queue. */
    555721    rc = PDMDevHlpQueueCreate(pDevIns, sizeof(PDMQUEUEITEMCORE), 5, 0,
     
    576742        pTarget->Led.u32Magic = PDMLED_MAGIC;
    577743        pTarget->IBase.pfnQueryInterface                 = virtioScsiR3DeviceQueryInterface;
    578 /*      pTarget->IMediaPort.pfnQueryDeviceLocation       = virtioScsiR3QueryDeviceLocation;
     744        pTarget->IMediaPort.pfnQueryDeviceLocation       = virtioScsiR3QueryDeviceLocation;
    579745        pTarget->IMediaExPort.pfnIoReqCompleteNotify     = virtioScsiR3IoReqCompleteNotify;
    580746        pTarget->IMediaExPort.pfnIoReqCopyFromBuf        = virtioScsiR3IoReqCopyFromBuf;
     
    585751        pTarget->IMediaExPort.pfnMediumEjected           = virtioScsiR3MediumEjected;
    586752        pTarget->ILed.pfnQueryStatusLed                  = virtioScsiR3DeviceQueryStatusLed;
    587 */
     753
    588754        LogFunc(("Attaching: Lun=%d, pszName=%s\n",  pTarget->iLUN, pszName));
    589755        /* Attach SCSI driver. */
     
    606772    }
    607773
    608 #if 0
    609774    /*
    610775     * Attach status driver (optional).
    611776     */
    612 
     777/*
    613778    PPDMIBASE pBase;
    614779    rc = PDMDevHlpDriverAttach(pDevIns, PDM_STATUS_LUN, &pThis->IBase, &pBase, "Status Port");
     
    620785        return PDMDEV_SET_ERROR(pDevIns, rc, N_("virtio-scsi cannot attach to status driver"));
    621786    }
    622 #endif
    623 
     787*/
    624788    rc = PDMDevHlpSSMRegisterEx(pDevIns, VIRTIOSCSI_SAVED_STATE_MINOR_VERSION, sizeof(*pThis), NULL,
    625789                                NULL, virtioScsiR3LiveExec, NULL,
     
    649813 * @param   fFlags      Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
    650814 */
    651 static DECLCALLBACK(void) devVirtioScsiR3Detach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
     815static DECLCALLBACK(void) virtioScsiR3Detach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
    652816{
    653817    RT_NOREF(fFlags);
     
    678842 * @param   fFlags      Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
    679843 */
    680 static DECLCALLBACK(int)  devVirtioScsiR3Attach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
     844static DECLCALLBACK(int)  virtioScsiR3Attach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
    681845{
    682846    PVIRTIOSCSI       pThis   = PDMINS_2_DATA(pDevIns, PVIRTIOSCSI);
     
    737901    sizeof(VIRTIOSCSI),
    738902    /* pfnConstruct */
    739     devVirtioScsiConstruct,
     903    virtioScsiConstruct,
    740904    /* pfnDestruct */
    741     devVirtIoScsiDestruct,
     905    virtioScsiDestruct,
    742906    /* pfnRelocate */
    743907    virtioScsiR3Relocate,
     
    753917    NULL,
    754918    /* pfnAttach */
    755     devVirtioScsiR3Attach,
     919    virtioScsiR3Attach,
    756920    /* pfnDetach */
    757     devVirtioScsiR3Detach,
     921    virtioScsiR3Detach,
    758922    /* pfnQueryInterface */
    759923    NULL,
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