Changeset 81662 in vbox for trunk/src/VBox/Devices/Storage
- Timestamp:
- Nov 5, 2019 12:09:57 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/DevVirtioSCSI.cpp
r81660 r81662 82 82 #define VIRTIOSCSI_REQ_QUEUE_CNT 1 /**< T.B.D. Consider increasing */ 83 83 #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. */ 84 85 #define VIRTIOSCSI_MAX_LUN 256 /**< VirtIO specification, section 5.6.4 */ 85 86 #define VIRTIOSCSI_MAX_COMMANDS_PER_LUN 128 /**< T.B.D. What is a good value for this? */ … … 87 88 #define VIRTIOSCSI_MAX_SECTORS_HINT 0x10000 /**< VirtIO specification, section 5.6.4 */ 88 89 #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 # */90 90 91 91 #define PCI_DEVICE_ID_VIRTIOSCSI_HOST 0x1048 /**< Informs guest driver of type of VirtIO device */ … … 416 416 VIRTIOSTATE Virtio; 417 417 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. */ 421 424 R3PTRTYPE(PVIRTIOSCSITARGET) paTargetInstances; 422 425 #if HC_ARCH_BITS == 32 … … 427 430 VIRTIOSCSIWORKER aWorkers[VIRTIOSCSI_QUEUE_CNT]; 428 431 429 bool fBootable;430 bool fRCEnabled;431 bool fR0Enabled;432 432 /** Instance name */ 433 433 char szInstance[16]; … … 531 531 typedef VIRTIOSCSIREQ *PVIRTIOSCSIREQ; 532 532 533 534 #ifdef IN_RING3 /* spans most of the file, at the moment. */ 533 535 534 536 #ifdef LOG_ENABLED … … 2196 2198 RTMemFree(pThis->paTargetInstances); 2197 2199 pThis->paTargetInstances = NULL; 2200 2198 2201 for (unsigned qIdx = 0; qIdx < VIRTIOSCSI_QUEUE_CNT; qIdx++) 2199 2202 { … … 2216 2219 { 2217 2220 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 */ 2222 2227 pThis->pDevInsR3 = pDevIns; 2223 2228 pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns); … … 2226 2231 2227 2232 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; 2232 2236 2233 2237 /* 2234 2238 * Validate and read configuration. 2235 2239 */ 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); 2245 2243 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); 2251 2251 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 */ 2276 2261 2277 2262 /* Configure virtio_scsi_config that transacts via VirtIO implementation's Dev. Specific Cap callbacks */ … … 2293 2278 pThis->Virtio.Callbacks.pfnDevCapWrite = virtioScsiR3DevCapWrite; 2294 2279 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, 2296 2292 &pThis->virtioScsiConfig /*pvDevSpecificCap*/, sizeof(pThis->virtioScsiConfig)); 2297 2293 2298 2294 if (RT_FAILURE(rc)) 2299 2295 return PDMDEV_SET_ERROR(pDevIns, rc, N_("virtio-scsi: failed to initialize VirtIO")); 2296 2297 /* 2298 * Initialize queues. 2299 */ 2300 2300 2301 2301 /* Name the queues: */ … … 2330 2330 } 2331 2331 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)); 2335 2337 2336 2338 pThis->paTargetInstances = (PVIRTIOSCSITARGET)RTMemAllocZ(sizeof(VIRTIOSCSITARGET) * pThis->cTargets); … … 2413 2415 } 2414 2416 2415 /* Status driver */ 2417 /* 2418 * Status driver (optional). 2419 */ 2416 2420 PPDMIBASE pUpBase; 2421 AssertCompile(PDM_STATUS_LUN >= VIRTIOSCSI_MAX_TARGETS); 2417 2422 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) 2419 2424 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to attach the status LUN")); 2420 2425 … … 2431 2436 */ 2432 2437 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); 2434 2439 PDMDevHlpDBGFInfoRegister(pDevIns, szTmp, "virtio-scsi info", virtioScsiR3Info); 2435 2440 2436 2441 return rc; 2437 2442 } 2443 2444 #else /* !IN_RING3 */ 2445 2446 /** 2447 * @callback_method_impl{PDMDEVREGR0,pfnConstruct} 2448 */ 2449 static 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 2438 2459 2439 2460 /** … … 2445 2466 /* .uReserved0 = */ 0, 2446 2467 /* .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 */ 2450 2469 | PDM_DEVREG_FLAGS_FIRST_SUSPEND_NOTIFICATION 2451 2470 | PDM_DEVREG_FLAGS_FIRST_POWEROFF_NOTIFICATION, 2452 #else2453 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS2454 | PDM_DEVREG_FLAGS_FIRST_SUSPEND_NOTIFICATION2455 | PDM_DEVREG_FLAGS_FIRST_POWEROFF_NOTIFICATION,2456 #endif2457 2471 /* .fClass = */ PDM_DEVREG_CLASS_MISC, 2458 2472 /* .cMaxInstances = */ ~0U, … … 2491 2505 #elif defined(IN_RING0) 2492 2506 /* .pfnEarlyConstruct = */ NULL, 2493 /* .pfnConstruct = */ NULL,2507 /* .pfnConstruct = */ virtioScsiRZConstruct, 2494 2508 /* .pfnDestruct = */ NULL, 2495 2509 /* .pfnFinalDestruct = */ NULL, … … 2504 2518 /* .pfnReserved7 = */ NULL, 2505 2519 #elif defined(IN_RC) 2506 /* .pfnConstruct = */ NULL,2520 /* .pfnConstruct = */ virtioScsiRZConstruct, 2507 2521 /* .pfnReserved0 = */ NULL, 2508 2522 /* .pfnReserved1 = */ NULL,
Note:
See TracChangeset
for help on using the changeset viewer.