VirtualBox

Changeset 81662 in vbox for trunk/src/VBox/Devices/Storage


Ignore:
Timestamp:
Nov 5, 2019 12:09:57 AM (5 years ago)
Author:
vboxsync
Message:

Virtio_1_0,DevVirtioScsi: Started converting to new PDM model. (untested) bugref:9218

File:
1 edited

Legend:

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

    r81660 r81662  
    8282#define VIRTIOSCSI_REQ_QUEUE_CNT                    1           /**< T.B.D. Consider increasing                      */
    8383#define VIRTIOSCSI_QUEUE_CNT                        (VIRTIOSCSI_REQ_QUEUE_CNT + 2)
     84#define VIRTIOSCSI_MAX_TARGETS                      256         /**< @todo r=bird: I just picked a number at random.  Please put something sensible here. */
    8485#define VIRTIOSCSI_MAX_LUN                          256         /**< VirtIO specification, section 5.6.4             */
    8586#define VIRTIOSCSI_MAX_COMMANDS_PER_LUN             128         /**< T.B.D. What is a good value for this?           */
     
    8788#define VIRTIOSCSI_MAX_SECTORS_HINT                 0x10000     /**< VirtIO specification, section 5.6.4             */
    8889#define VIRTIOSCSI_MAX_CHANNEL_HINT                 0           /**< VirtIO specification, section 5.6.4 should be 0 */
    89 #define VIRTIOSCSI_SAVED_STATE_MINOR_VERSION        0x01        /**< SSM version #                                   */
    9090
    9191#define PCI_DEVICE_ID_VIRTIOSCSI_HOST               0x1048      /**< Informs guest driver of type of VirtIO device   */
     
    416416    VIRTIOSTATE                     Virtio;
    417417
    418     /** Number of targets detected */
    419     uint64_t                        cTargets;
    420 
     418    bool                            fBootable;
     419    bool                            afPadding[3];
     420
     421    /** Number of targets in paTargetInstances. */
     422    uint32_t                        cTargets;
     423    /** Array of per-target data. */
    421424    R3PTRTYPE(PVIRTIOSCSITARGET)    paTargetInstances;
    422425#if HC_ARCH_BITS == 32
     
    427430    VIRTIOSCSIWORKER                aWorkers[VIRTIOSCSI_QUEUE_CNT];
    428431
    429     bool                            fBootable;
    430     bool                            fRCEnabled;
    431     bool                            fR0Enabled;
    432432    /** Instance name */
    433433    char                            szInstance[16];
     
    531531typedef VIRTIOSCSIREQ *PVIRTIOSCSIREQ;
    532532
     533
     534#ifdef IN_RING3 /* spans most of the file, at the moment. */
    533535
    534536#ifdef LOG_ENABLED
     
    21962198    RTMemFree(pThis->paTargetInstances);
    21972199    pThis->paTargetInstances = NULL;
     2200
    21982201    for (unsigned qIdx = 0; qIdx < VIRTIOSCSI_QUEUE_CNT; qIdx++)
    21992202    {
     
    22162219{
    22172220    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    2218 
    2219     PVIRTIOSCSI  pThis = PDMDEVINS_2_DATA(pDevIns, PVIRTIOSCSI);
    2220     int  rc = VINF_SUCCESS;
    2221 
     2221    PVIRTIOSCSI   pThis = PDMDEVINS_2_DATA(pDevIns, PVIRTIOSCSI);
     2222    PCPDMDEVHLPR3 pHlp  = pDevIns->pHlpR3;
     2223
     2224    /*
     2225     * Quick initialization of the state data, making sure that the destructor always works.
     2226     */
    22222227    pThis->pDevInsR3 = pDevIns;
    22232228    pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
     
    22262231
    22272232    LogFunc(("PDM device instance: %d\n", iInstance));
    2228     RTStrPrintf((char *)pThis->szInstance, sizeof(pThis->szInstance), "VIRTIOSCSI%d", iInstance);
    2229 
    2230     /* Usable defaults */
    2231     pThis->cTargets = 1;
     2233    RTStrPrintf(pThis->szInstance, sizeof(pThis->szInstance), "VIRTIOSCSI%d", iInstance);
     2234
     2235    pThis->IBase.pfnQueryInterface = virtioScsiR3DeviceQueryInterface;
    22322236
    22332237    /*
    22342238     * Validate and read configuration.
    22352239     */
    2236     if (!CFGMR3AreValuesValid(pCfg,"NumTargets\0"
    2237                                    "Bootable\0"
    2238                                 /* "GCEnabled\0"    TBD */
    2239                                 /* "R0Enabled\0"    TBD */
    2240     ))
    2241     return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
    2242                                 N_("virtio-scsi configuration error: unknown option specified"));
    2243 
    2244     rc = CFGMR3QueryIntegerDef(pCfg, "NumTargets", &pThis->cTargets, true);
     2240    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "NumTargets|Bootable", "");
     2241
     2242    int rc = pHlp->pfnCFGMQueryU32Def(pCfg, "NumTargets", &pThis->cTargets, 1);
    22452243    if (RT_FAILURE(rc))
    2246         return PDMDEV_SET_ERROR(pDevIns, rc,
    2247                                 N_("virtio-scsi configuration error: failed to read NumTargets as integer"));
    2248     LogFunc(("NumTargets=%d\n", pThis->cTargets));
    2249 
    2250     rc = CFGMR3QueryBoolDef(pCfg, "Bootable", &pThis->fBootable, true);
     2244        return PDMDEV_SET_ERROR(pDevIns, rc, N_("virtio-scsi configuration error: failed to read NumTargets as integer"));
     2245    if (pThis->cTargets < 1 || pThis->cTargets > VIRTIOSCSI_MAX_TARGETS)
     2246        return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
     2247                                   N_("virtio-scsi configuration error: NumTargets=%u is out of range (1..%u)"),
     2248                                   pThis->cTargets, VIRTIOSCSI_MAX_TARGETS);
     2249
     2250    rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "Bootable", &pThis->fBootable, true);
    22512251    if (RT_FAILURE(rc))
    2252          return PDMDEV_SET_ERROR(pDevIns, rc,
    2253                                 N_("virtio-scsi configuration error: failed to read Bootable as boolean"));
    2254     LogFunc(("Bootable=%RTbool (unimplemented)\n", pThis->fBootable));
    2255 
    2256     rc = CFGMR3QueryBoolDef(pCfg, "R0Enabled", &pThis->fR0Enabled, false);
    2257     if (RT_FAILURE(rc))
    2258          return PDMDEV_SET_ERROR(pDevIns, rc,
    2259                                 N_("virtio-scsi configuration error: failed to read R0Enabled as boolean"));
    2260 
    2261     rc = CFGMR3QueryBoolDef(pCfg, "RCEnabled", &pThis->fRCEnabled, false);
    2262     if (RT_FAILURE(rc))
    2263          return PDMDEV_SET_ERROR(pDevIns, rc,
    2264                                 N_("virtio-scsi configuration error: failed to read RCEnabled as boolean"));
    2265 
    2266     VIRTIOPCIPARAMS virtioPciParams, *pVirtioPciParams = &virtioPciParams;
    2267     pVirtioPciParams->uDeviceId      = PCI_DEVICE_ID_VIRTIOSCSI_HOST;
    2268     pVirtioPciParams->uClassBase     = PCI_CLASS_BASE_MASS_STORAGE;
    2269     pVirtioPciParams->uClassSub      = PCI_CLASS_SUB_SCSI_STORAGE_CONTROLLER;
    2270     pVirtioPciParams->uClassProg     = PCI_CLASS_PROG_UNSPECIFIED;
    2271     pVirtioPciParams->uSubsystemId   = PCI_DEVICE_ID_VIRTIOSCSI_HOST;  /* Virtio 1.0 spec allows PCI Device ID here */
    2272     pVirtioPciParams->uInterruptLine = 0x00;
    2273     pVirtioPciParams->uInterruptPin  = 0x01;
    2274 
    2275     pThis->IBase.pfnQueryInterface = virtioScsiR3DeviceQueryInterface;
     2252         return PDMDEV_SET_ERROR(pDevIns, rc, N_("virtio-scsi configuration error: failed to read Bootable as boolean"));
     2253
     2254    LogRel(("%s: Targets=%u Bootable=%RTbool (unimplemented) R0Enabled=%RTbool RCEnabled=%RTbool\n",
     2255            pThis->szInstance, pThis->cTargets, pThis->fBootable, pDevIns->fR0Enabled, pDevIns->fRCEnabled));
     2256
     2257
     2258    /*
     2259     * Do core virtio initialization.
     2260     */
    22762261
    22772262    /* Configure virtio_scsi_config that transacts via VirtIO implementation's Dev. Specific Cap callbacks */
     
    22932278    pThis->Virtio.Callbacks.pfnDevCapWrite    = virtioScsiR3DevCapWrite;
    22942279
    2295     rc = virtioR3Init(&pThis->Virtio, pDevIns, pVirtioPciParams, pThis->szInstance, VIRTIOSCSI_HOST_SCSI_FEATURES_OFFERED,
     2280    VIRTIOPCIPARAMS VirtioPciParams;
     2281    VirtioPciParams.uDeviceId           = PCI_DEVICE_ID_VIRTIOSCSI_HOST;
     2282    VirtioPciParams.uClassBase          = PCI_CLASS_BASE_MASS_STORAGE;
     2283    VirtioPciParams.uClassSub           = PCI_CLASS_SUB_SCSI_STORAGE_CONTROLLER;
     2284    VirtioPciParams.uClassProg          = PCI_CLASS_PROG_UNSPECIFIED;
     2285    VirtioPciParams.uSubsystemId        = PCI_DEVICE_ID_VIRTIOSCSI_HOST;  /* Virtio 1.0 spec allows PCI Device ID here */
     2286    VirtioPciParams.uSubsystemVendorId  = DEVICE_PCI_VENDOR_ID_VIRTIO;   /** @todo r=bird: was uninitialized, but not used by core virtio code. so, drop it from the struct? */
     2287    VirtioPciParams.uRevisionId         = DEVICE_PCI_REVISION_ID_VIRTIO; /** @todo r=bird: was uninitialized, but not used by core virtio code. so, drop it from the struct? */
     2288    VirtioPciParams.uInterruptLine      = 0x00;
     2289    VirtioPciParams.uInterruptPin       = 0x01;
     2290
     2291    rc = virtioR3Init(&pThis->Virtio, pDevIns, &VirtioPciParams, pThis->szInstance, VIRTIOSCSI_HOST_SCSI_FEATURES_OFFERED,
    22962292                      &pThis->virtioScsiConfig /*pvDevSpecificCap*/, sizeof(pThis->virtioScsiConfig));
    22972293
    22982294    if (RT_FAILURE(rc))
    22992295        return PDMDEV_SET_ERROR(pDevIns, rc, N_("virtio-scsi: failed to initialize VirtIO"));
     2296
     2297    /*
     2298     * Initialize queues.
     2299     */
    23002300
    23012301    /* Name the queues: */
     
    23302330    }
    23312331
    2332     /* Initialize per device instance. */
    2333 
    2334     Log2Func(("Found %d targets attached to controller\n", pThis->cTargets));
     2332    /*
     2333     * Initialize per device instances (targets).
     2334     */
     2335
     2336    Log2Func(("Probing %d targets ...\n", pThis->cTargets));
    23352337
    23362338    pThis->paTargetInstances = (PVIRTIOSCSITARGET)RTMemAllocZ(sizeof(VIRTIOSCSITARGET) * pThis->cTargets);
     
    24132415    }
    24142416
    2415     /* Status driver */
     2417    /*
     2418     * Status driver (optional).
     2419     */
    24162420    PPDMIBASE pUpBase;
     2421    AssertCompile(PDM_STATUS_LUN >= VIRTIOSCSI_MAX_TARGETS);
    24172422    rc = PDMDevHlpDriverAttach(pDevIns, PDM_STATUS_LUN, &pThis->IBase, &pUpBase, "Status Port");
    2418     if (RT_FAILURE(rc))
     2423    if (RT_FAILURE(rc) && rc != VERR_PDM_NO_ATTACHED_DRIVER)
    24192424        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to attach the status LUN"));
    24202425
     
    24312436     */
    24322437    char szTmp[128];
    2433     RTStrPrintf(szTmp, sizeof(szTmp), "%s%d", pDevIns->pReg->szName, pDevIns->iInstance);
     2438    RTStrPrintf(szTmp, sizeof(szTmp), "%s%u", pDevIns->pReg->szName, pDevIns->iInstance);
    24342439    PDMDevHlpDBGFInfoRegister(pDevIns, szTmp, "virtio-scsi info", virtioScsiR3Info);
    24352440
    24362441    return rc;
    24372442}
     2443
     2444#else  /* !IN_RING3 */
     2445
     2446/**
     2447 * @callback_method_impl{PDMDEVREGR0,pfnConstruct}
     2448 */
     2449static DECLCALLBACK(int) virtioScsiRZConstruct(PPDMDEVINS pDevIns)
     2450{
     2451    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
     2452    PVIRTIOSCSI pThis = PDMDEVINS_2_DATA(pDevIns, PVIRTIOSCSI);
     2453
     2454    return virtioRZInit(&pThis->virtio, pDevIns);
     2455}
     2456
     2457#endif /* !IN_RING3 */
     2458
    24382459
    24392460/**
     
    24452466    /* .uReserved0 = */             0,
    24462467    /* .szName = */                 "virtio-scsi",
    2447 
    2448 #ifdef VIRTIOSCSI_GC_SUPPORT
    2449     /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ
     2468    /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS /** @todo | PDM_DEVREG_FLAGS_RZ */
    24502469                                    | PDM_DEVREG_FLAGS_FIRST_SUSPEND_NOTIFICATION
    24512470                                    | PDM_DEVREG_FLAGS_FIRST_POWEROFF_NOTIFICATION,
    2452 #else
    2453     /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS
    2454                                     | PDM_DEVREG_FLAGS_FIRST_SUSPEND_NOTIFICATION
    2455                                     | PDM_DEVREG_FLAGS_FIRST_POWEROFF_NOTIFICATION,
    2456 #endif
    24572471    /* .fClass = */                 PDM_DEVREG_CLASS_MISC,
    24582472    /* .cMaxInstances = */          ~0U,
     
    24912505#elif defined(IN_RING0)
    24922506    /* .pfnEarlyConstruct = */      NULL,
    2493     /* .pfnConstruct = */           NULL,
     2507    /* .pfnConstruct = */           virtioScsiRZConstruct,
    24942508    /* .pfnDestruct = */            NULL,
    24952509    /* .pfnFinalDestruct = */       NULL,
     
    25042518    /* .pfnReserved7 = */           NULL,
    25052519#elif defined(IN_RC)
    2506     /* .pfnConstruct = */           NULL,
     2520    /* .pfnConstruct = */           virtioScsiRZConstruct,
    25072521    /* .pfnReserved0 = */           NULL,
    25082522    /* .pfnReserved1 = */           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