- Timestamp:
- Sep 21, 2019 5:29:54 AM (5 years ago)
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/DevVirtioSCSI.cpp
r80762 r80928 47 47 #include "VBoxDD.h" 48 48 49 50 /* 51 * RT log-levels used: 52 * 53 * Level 1: The most important (but usually rare) things to note 54 * Level 2: SCSI command logging 55 * Level 3: Vector and I/O transfer summary (shows what client sent an expects and fulfillment) 56 * Level 6: Device ⟷ Guest Driver negotation, traffic, notifications and state handling 57 * Level 12: Brief formatted hex dumps of I/O data 58 */ 59 49 60 #define LUN0 0 50 61 /** … … 69 80 * TEMPORARY NOTE: following parameter is set to 1 for early development. Will be increased later 70 81 */ 71 #define VIRTIOSCSI_REQ_QUEUE_CNT 1/**< Number of req queues exposed by dev. */82 #define VIRTIOSCSI_REQ_QUEUE_CNT 2 /**< Number of req queues exposed by dev. */ 72 83 #define VIRTIOSCSI_QUEUE_CNT VIRTIOSCSI_REQ_QUEUE_CNT + 2 73 #define VIRTIOSCSI_MAX_TARGETS 256 /**< Default value */74 84 #define VIRTIOSCSI_MAX_LUN 256 /* < VirtIO specification, section 5.6.4 */ 75 85 #define VIRTIOSCSI_MAX_COMMANDS_PER_LUN 1 /* < T.B.D. What is a good value for this? */ … … 110 120 111 121 /** 112 * This macro resolves to boolean true if uOffset matches a field offset and size exactly,113 * (or if it is a64-bit field, if it accesses either 32-bit part as a 32-bit access)114 * ASSUMED this critereon is mandated by section 4.1.3.1 of the VirtIO 1.0 specification)115 * This MACROcan be re-written to allow unaligned access to a field (within bounds).122 * Resolves to boolean true if uOffset matches a field offset and size exactly, 123 * (or if 64-bit field, if it accesses either 32-bit part as a 32-bit access) 124 * It is *assumed* this critereon is mandated by section 4.1.3.1 of the VirtIO 1.0 spec) 125 * This macro can be re-written to allow unaligned access to a field (within bounds). 116 126 * 117 127 * @param member - Member of VIRTIO_PCI_COMMON_CFG_T … … 160 170 pMediaExTxDirEnumValue == PDMMEDIAEXIOREQSCSITXDIR_TO_DEVICE 161 171 /** 162 * The following struct is the VirtIO SCSI Host Devicedevice-specific configuration described in section 5.6.4163 * of the VirtIO 1.0 spec ification. This layout maps an MMIO area shared VirtIO guest driver. The VBox VirtIO164 * this virtual controller device implementation is a client of. The frame work calls back whenever the guest driver165 * accesses any part of field in this struct172 * Following struct is the VirtIO SCSI Host Device device-specific configuration described in section 5.6.4 173 * of the VirtIO 1.0 spec. Layout maps an MMIO area shared VirtIO guest driver. The VBox VirtIO 174 * this virtual controller device implementation is a client of. Framework does a callback whenever 175 * guest driver accesses any part of field in this struct 166 176 */ 167 177 typedef struct virtio_scsi_config … … 312 322 uint32_t uType; /** type */ 313 323 uint32_t uSubtype; /** subtype */ 314 uint8_t uScsiLun[8]; /** lun */324 uint8_t uScsiLun[8]; /** lun */ 315 325 uint64_t uId; /** id */ 316 326 // Device-writable part … … 335 345 // Device-readable part 336 346 uint32_t uType; /** type */ 337 uint8_t uScsiLun[8]; /** lun */347 uint8_t uScsiLun[8]; /** lun */ 338 348 uint32_t uEventsRequested; /** event_requested */ 339 349 // Device-writable part … … 429 439 VIRTIOHANDLE hVirtio; 430 440 431 /** SCSI target instances data */ 432 VIRTIOSCSITARGET aTargetInstances[VIRTIOSCSI_MAX_TARGETS]; 441 /** Number of targets detected */ 442 uint64_t cTargets; 443 444 R3PTRTYPE(PVIRTIOSCSITARGET) paTargetInstances; 445 #if HC_ARCH_BITS == 32 446 RTR3PTR R3PtrPadding0; 447 #endif 433 448 434 449 /** Per device-bound virtq worker-thread contexts (eventq slot unused) */ … … 482 497 /** The event semaphore the processing thread waits on. */ 483 498 484 /** Number of targets detected */485 uint64_t cTargets;486 499 487 500 /** Total number of requests active across all targets */ … … 532 545 PVIRTIOSCSITARGET pTarget; /**< Target */ 533 546 uint16_t qIdx; /**< Index of queue this request arrived on */ 534 size_tcbPiOut; /**< Size of T10 pi in buffer */547 uint32_t cbPiOut; /**< Size of T10 pi in buffer */ 535 548 uint8_t *pbPiOut; /**< Address of pi out buffer */ 536 549 uint8_t *pbDataOut; /**< dataout */ 537 size_tcbDataOut; /**< size of dataout buffer */538 size_tcbPiIn; /**< Size of T10 pi buffer */550 uint32_t cbDataOut; /**< size of dataout buffer */ 551 uint32_t cbPiIn; /**< Size of T10 pi buffer */ 539 552 uint8_t *pbPiIn; /**< Address of pi in buffer */ 540 size_tcbDataIn; /**< Size of datain buffer */553 uint32_t cbDataIn; /**< Size of datain buffer */ 541 554 uint8_t *pbDataIn; /**< datain */ 542 size_tcbSense; /**< Size of sense buffer */555 uint32_t cbSense; /**< Size of sense buffer */ 543 556 size_t uSenseLen; /**< Receives # bytes written into sense buffer */ 544 557 uint8_t *pbSense; /**< Pointer to R3 sense buffer */ … … 548 561 } VIRTIOSCSIREQ; 549 562 550 DECLINLINE(bool) isBufZero(uint8_t *pv, size_t cb)563 DECLINLINE(bool) isBufZero(uint8_t *pv, uint32_t cb) 551 564 { 552 565 for (uint32_t i = 0; i < cb; i++) … … 619 632 } 620 633 621 DECLINLINE(void) virtioGetControlAsyncMaskText(char *pszOutput, size_t cbOutput, uint32_t uAsyncTypesMask)634 DECLINLINE(void) virtioGetControlAsyncMaskText(char *pszOutput, uint32_t cbOutput, uint32_t uAsyncTypesMask) 622 635 { 623 636 RTStrPrintf(pszOutput, cbOutput, "%s%s%s%s%s%s", … … 713 726 case VIRTIOSCSI_T_NO_EVENT: 714 727 if (uEventType & VIRTIOSCSI_T_EVENTS_MISSED) 715 Log Func(("(target=%d, LUN=%d) Warning driver that events were missed\n", uTarget, LUN0));728 Log6Func(("(target=%d, LUN=%d) Warning driver that events were missed\n", uTarget, LUN0)); 716 729 else 717 Log Func(("(target=%d, LUN=%d): Warning event info guest queued is shorter than configured\n",730 Log6Func(("(target=%d, LUN=%d): Warning event info guest queued is shorter than configured\n", 718 731 uTarget, LUN0)); 719 732 break; … … 722 735 { 723 736 case VIRTIOSCSI_EVT_RESET_REMOVED: 724 Log Func(("(target=%d, LUN=%d): Target or LUN removed\n", uTarget, LUN0));737 Log6Func(("(target=%d, LUN=%d): Target or LUN removed\n", uTarget, LUN0)); 725 738 break; 726 739 case VIRTIOSCSI_EVT_RESET_RESCAN: 727 Log Func(("(target=%d, LUN=%d): Target or LUN added\n", uTarget, LUN0));740 Log6Func(("(target=%d, LUN=%d): Target or LUN added\n", uTarget, LUN0)); 728 741 break; 729 742 case VIRTIOSCSI_EVT_RESET_HARD: 730 Log Func(("(target=%d, LUN=%d): Target was reset\n", uTarget, LUN0));743 Log6Func(("(target=%d, LUN=%d): Target was reset\n", uTarget, LUN0)); 731 744 break; 732 745 } … … 735 748 char szTypeText[128]; 736 749 virtioGetControlAsyncMaskText(szTypeText, sizeof(szTypeText), uReason); 737 Log Func(("(target=%d, LUN=%d): Delivering subscribed async notification %s\n", uTarget, LUN0));750 Log6Func(("(target=%d, LUN=%d): Delivering subscribed async notification %s\n", uTarget, LUN0)); 738 751 break; 739 752 case VIRTIOSCSI_T_PARAM_CHANGE: … … 742 755 break; 743 756 default: 744 Log Func(("(target=%d, LUN=%d): Unknown event type: %d, ignoring\n", uTarget, LUN0));757 Log6Func(("(target=%d, LUN=%d): Unknown event type: %d, ignoring\n", uTarget, LUN0)); 745 758 return VINF_SUCCESS; 746 759 } … … 837 850 PPDMIMEDIAEX pIMediaEx = pTarget->pDrvMediaEx; 838 851 839 size_t cbResidual = 0, cbXfer = 0; 852 size_t cbResidual = 0; 853 size_t cbXfer = 0; 840 854 int rc = pIMediaEx->pfnIoReqQueryResidual(pIMediaEx, hIoReq, &cbResidual); 841 855 AssertRC(rc); … … 845 859 846 860 struct REQ_RESP_HDR respHdr = { 0 }; 847 respHdr.uSenseLen = pReq->pbSense[2] == SCSI_SENSE_NONE ? 0 : pReq->uSenseLen; 848 respHdr.uResidual = cbResidual; 861 respHdr.uSenseLen = pReq->pbSense[2] == SCSI_SENSE_NONE ? 0 : (uint32_t)pReq->uSenseLen; 862 AssertMsg(!(cbResidual & 0xffffffff00000000), 863 ("WARNING: Residual size larger than uint32_t holds, truncating")); 864 respHdr.uResidual = (uint32_t)(cbResidual & 0xffffffff); 849 865 respHdr.uStatus = pReq->uStatus; 850 866 … … 909 925 LogFunc(("cbDataIn = %u, cbDataOut = %u (cbIn = %u, cbOut = %u)\n", 910 926 pReq->cbDataIn, pReq->cbDataOut, pReq->pDescChain->cbPhysDst, pReq->pDescChain->cbVirtSrc)); 911 LogFunc(("xfer = % d, residual = %u\n", cbXfer, cbResidual));927 LogFunc(("xfer = %lu, residual = %u\n", cbXfer, cbResidual)); 912 928 LogFunc(("xfer direction: %s, sense written = %d, sense size = %d\n", 913 929 virtioGetTxDirText(pReq->enmTxDir), respHdr.uSenseLen, pThis->virtioScsiConfig.uSenseSize)); … … 920 936 } 921 937 922 if (LogIs ItEnabled(RTLOGGRPFLAGS_LEVEL_12, LOG_GROUP))923 { 924 size_t cb = RT_MIN(cbXfer, 256);938 if (LogIs12Enabled()) 939 { 940 uint32_t cb = RT_MIN(cbXfer, 256); 925 941 if (VIRTIO_IN_DIRECTION(pReq->enmTxDir)) 926 942 { 927 Log(("datain[ 256 of %d total bytes xferred]:\n", cbXfer));943 Log(("datain[%d of %d total bytes xferred]:\n", cb, cbXfer)); 928 944 if (!isBufZero(pReq->pbDataIn, cb)) 929 945 VIRTIO_HEX_DUMP(RTLOGGRPFLAGS_LEVEL_12, pReq->pbDataIn, cb, 0, 0); … … 934 950 if (VIRTIO_OUT_DIRECTION(pReq->enmTxDir)) 935 951 { 936 Log(("dataout[ 256 of %d total bytes xferred]:\n", cbXfer));952 Log(("dataout[%d of %d total bytes xferred]:\n", cb, cbXfer)); 937 953 if (!isBufZero(pReq->pbDataOut, cb)) 938 954 VIRTIO_HEX_DUMP(RTLOGGRPFLAGS_LEVEL_12, pReq->pbDataOut, cb, 0, 0); … … 987 1003 * (phys. memory) with the Req response data in virtual memory. 988 1004 */ 989 size_t cbReqSgBuf = RTSgBufCalcTotalLength(&reqSegBuf);1005 uint32_t cbReqSgBuf = RTSgBufCalcTotalLength(&reqSegBuf); 990 1006 AssertMsgReturn(cbReqSgBuf <= pReq->pDescChain->cbPhysDst, 991 1007 ("Guest expected less req data (space needed: %d, avail: %d)\n", … … 1016 1032 uint8_t uTarget = pVirtqReq->cmdHdr.uVirtioLun[1]; 1017 1033 uint32_t uScsiLun = (pVirtqReq->cmdHdr.uVirtioLun[2] << 8 | pVirtqReq->cmdHdr.uVirtioLun[3]) & 0x3fff; 1018 PVIRTIOSCSITARGET pTarget = &pThis-> aTargetInstances[uTarget];1034 PVIRTIOSCSITARGET pTarget = &pThis->paTargetInstances[uTarget]; 1019 1035 1020 1036 LogFunc(("[%s] (Target: %d LUN: %d) CDB: %.*Rhxs\n", … … 1029 1045 * Calculate request offsets 1030 1046 */ 1031 size_t cbPiIn = 0, cbPiOut = 0, cbPiHdr = 0;1047 uint32_t cbPiIn = 0, cbPiOut = 0, cbPiHdr = 0; 1032 1048 off_t piOutOff = 0; 1033 1049 … … 1043 1059 off_t uDataInOff = sizeof(REQ_RESP_HDR) + pThis->virtioScsiConfig.uSenseSize + cbPiIn; 1044 1060 uint8_t *pbDataOut = (uint8_t *)((uint64_t)pVirtqReq + uDataOutOff); 1045 size_t cbDataOut = pDescChain->cbVirtSrc - uDataOutOff;1046 size_t cbDataIn = pDescChain->cbPhysDst - uDataInOff;1061 uint32_t cbDataOut = pDescChain->cbVirtSrc - uDataOutOff; 1062 uint32_t cbDataIn = pDescChain->cbPhysDst - uDataInOff; 1047 1063 1048 1064 /** … … 1132 1148 1133 1149 rc = pIMediaEx->pfnIoReqSendScsiCmd(pIMediaEx, pReq->hIoReq, uScsiLun, 1134 pVirtqReq->uCdb, pThis->virtioScsiConfig.uCdbSize,1150 pVirtqReq->uCdb, (size_t)pThis->virtioScsiConfig.uCdbSize, 1135 1151 PDMMEDIAEXIOREQSCSITXDIR_UNKNOWN, &pReq->enmTxDir, 1136 RT_MAX(cbDataIn, cbDataOut),1137 pReq->pbSense, pReq->cbSense, &pReq->uSenseLen,1152 (size_t)RT_MAX(cbDataIn, cbDataOut), 1153 pReq->pbSense, (size_t)pReq->cbSense, &pReq->uSenseLen, 1138 1154 &pReq->uStatus, 30 * RT_MS_1SEC); 1139 1155 … … 1145 1161 */ 1146 1162 Log2Func(("Request submission error from lower-level driver\n")); 1147 size_t cbResidual;1148 pIMediaEx->pfnIoReqQueryResidual(pIMediaEx, pReq->hIoReq, &cbResidual);1149 1163 uint8_t uASC, uASCQ = 0; 1150 1164 switch (rc) … … 1343 1357 if (virtioQueueIsEmpty(pThis->hVirtio, qIdx)) 1344 1358 { 1345 /* Interlocks avoid missing alarm while going to sleep & notifier doesn't wakethe awoken */1359 /* Atomic interlocks avoid missing alarm while going to sleep & notifier waking the awoken */ 1346 1360 ASMAtomicWriteBool(&pWorker->fSleeping, true); 1347 1361 bool fNotificationSent = ASMAtomicXchgBool(&pWorker->fNotified, false); … … 1371 1385 if (qIdx == CONTROLQ_IDX) 1372 1386 virtioScsiCtrl(pThis, qIdx, pDescChain); 1373 else 1387 else /* request queue index */ 1374 1388 { 1375 1389 rc = virtioScsiReqSubmit(pThis, qIdx, pDescChain); … … 1472 1486 PVIRTIOSCSI pThis = (PVIRTIOSCSI)pClient; 1473 1487 PWORKER pWorker = &pThis->aWorker[qIdx]; 1474 1475 1488 1476 1489 RTLogFlush(RTLogDefaultInstanceEx(RT_MAKE_U32(0, UINT16_MAX))); … … 1736 1749 for (uint32_t i = 0; i < pThis->cTargets; i++) 1737 1750 { 1738 PVIRTIOSCSITARGET pTarget = &pThis-> aTargetInstances[i];1751 PVIRTIOSCSITARGET pTarget = &pThis->paTargetInstances[i]; 1739 1752 if (pTarget->pDrvBase) 1740 1753 if (pTarget->pDrvMediaEx) … … 1778 1791 * @returns VBox status code. 1779 1792 * @param pInterface Pointer to the interface structure containing the called function pointer. 1780 * @param iTarget 1793 * @param iTarget The unit which status LED we desire. 1781 1794 * @param ppLed Where to store the LED pointer. 1782 1795 */ … … 1798 1811 * @returns VBox status code. 1799 1812 * @param pInterface Pointer to the interface structure containing the called function pointer. 1800 * @param iTarget 1813 * @param iTarget The unit which status LED we desire. 1801 1814 * @param ppLed Where to store the LED pointer. 1802 1815 */ … … 1806 1819 if (iTarget < pThis->cTargets) 1807 1820 { 1808 *ppLed = &pThis-> aTargetInstances[iTarget].led;1821 *ppLed = &pThis->paTargetInstances[iTarget].led; 1809 1822 Assert((*ppLed)->u32Magic == PDMLED_MAGIC); 1810 1823 return VINF_SUCCESS; … … 1814 1827 1815 1828 static int virtioScsiCfgAccessed(PVIRTIOSCSI pThis, uint32_t uOffset, 1816 const void *pv, size_t cb, uint8_t fWrite)1829 const void *pv, uint32_t cb, uint8_t fWrite) 1817 1830 { 1818 1831 int rc = VINF_SUCCESS; … … 1863 1876 * @param cb Number of bytes to read 1864 1877 */ 1865 static DECLCALLBACK(int) virtioScsiDevCapRead(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pv, size_t cb)1878 static DECLCALLBACK(int) virtioScsiDevCapRead(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pv, uint32_t cb) 1866 1879 { 1867 1880 int rc = VINF_SUCCESS; … … 1882 1895 * @param cb Number of bytes to write 1883 1896 */ 1884 static DECLCALLBACK(int) virtioScsiDevCapWrite(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pv, size_t cb)1897 static DECLCALLBACK(int) virtioScsiDevCapWrite(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pv, uint32_t cb) 1885 1898 { 1886 1899 int rc = VINF_SUCCESS; … … 1916 1929 pThis->pDevInsR3 = pDevIns; 1917 1930 1918 for (uint32_t i = 0; i < VIRTIOSCSI_MAX_TARGETS; i++)1919 { 1920 PVIRTIOSCSITARGET pTarget = &pThis-> aTargetInstances[i];1931 for (uint32_t i = 0; i < pThis->cTargets; i++) 1932 { 1933 PVIRTIOSCSITARGET pTarget = &pThis->paTargetInstances[i]; 1921 1934 pTarget->pVirtioScsi = pThis; 1922 1935 } … … 1986 1999 RT_NOREF(fFlags); 1987 2000 PVIRTIOSCSI pThis = PDMINS_2_DATA(pDevIns, PVIRTIOSCSI); 1988 PVIRTIOSCSITARGET pTarget = &pThis-> aTargetInstances[iTarget];2001 PVIRTIOSCSITARGET pTarget = &pThis->paTargetInstances[iTarget]; 1989 2002 1990 2003 LogFunc(("")); … … 2013 2026 { 2014 2027 PVIRTIOSCSI pThis = PDMINS_2_DATA(pDevIns, PVIRTIOSCSI); 2015 PVIRTIOSCSITARGET pTarget = &pThis-> aTargetInstances[iTarget];2028 PVIRTIOSCSITARGET pTarget = &pThis->paTargetInstances[iTarget]; 2016 2029 int rc; 2017 2030 … … 2057 2070 PVIRTIOSCSI pThis = PDMINS_2_DATA(pDevIns, PVIRTIOSCSI); 2058 2071 2072 RTMemFree(pThis->paTargetInstances); 2073 pThis->paTargetInstances = NULL; 2059 2074 for (int qIdx = 0; qIdx < VIRTIOSCSI_QUEUE_CNT; qIdx++) 2060 2075 { … … 2085 2100 2086 2101 /* Usable defaults */ 2087 pThis->cTargets = VIRTIOSCSI_MAX_TARGETS;2102 pThis->cTargets = 1; 2088 2103 2089 2104 /* … … 2206 2221 Log2Func(("Found %d targets attached to controller\n", pThis->cTargets)); 2207 2222 2223 pThis->paTargetInstances = (PVIRTIOSCSITARGET)RTMemAllocZ(sizeof(VIRTIOSCSITARGET) * pThis->cTargets); 2224 if (!pThis->paTargetInstances) 2225 return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to allocate memory for target states")); 2226 2208 2227 for (RTUINT iTarget = 0; iTarget < pThis->cTargets; iTarget++) 2209 2228 { 2210 PVIRTIOSCSITARGET pTarget = &pThis-> aTargetInstances[iTarget];2229 PVIRTIOSCSITARGET pTarget = &pThis->paTargetInstances[iTarget]; 2211 2230 2212 2231 if (RTStrAPrintf(&pTarget->pszTargetName, "VSCSI%u", iTarget) < 0) … … 2238 2257 LogFunc(("Attaching LUN: %s\n", pTarget->pszTargetName)); 2239 2258 2240 AssertReturn(iTarget < RT_ELEMENTS(pThis->aTargetInstances), VERR_PDM_NO_SUCH_LUN);2241 rc = PDMDevHlpDriverAttach(pDevIns, iTarget, &pTarget->IBase, &pTarget->pDrvBase, (const char *)&pTarget->pszTargetName);2259 AssertReturn(iTarget < pThis->cTargets, VERR_PDM_NO_SUCH_LUN); 2260 rc = PDMDevHlpDriverAttach(pDevIns, iTarget, &pTarget->IBase, &pTarget->pDrvBase, pTarget->pszTargetName); 2242 2261 if (RT_SUCCESS(rc)) 2243 2262 { … … 2246 2265 pTarget->pDrvMedia = PDMIBASE_QUERY_INTERFACE(pTarget->pDrvBase, PDMIMEDIA); 2247 2266 AssertMsgReturn(VALID_PTR(pTarget->pDrvMedia), 2248 ("virtio-scsi configuration error: LUN#%d missing basic media interface!\n", pTarget->iTarget),2267 ("virtio-scsi configuration error: LUN#%d missing basic media interface!\n", iTarget), 2249 2268 VERR_PDM_MISSING_INTERFACE); 2250 2269 … … 2252 2271 pTarget->pDrvMediaEx = PDMIBASE_QUERY_INTERFACE(pTarget->pDrvBase, PDMIMEDIAEX); 2253 2272 AssertMsgReturn(VALID_PTR(pTarget->pDrvMediaEx), 2254 ("virtio-scsi configuration error: LUN#%d missing extended media interface!\n", pTarget->iTarget),2273 ("virtio-scsi configuration error: LUN#%d missing extended media interface!\n", iTarget), 2255 2274 VERR_PDM_MISSING_INTERFACE); 2256 2275 2257 2276 rc = pTarget->pDrvMediaEx->pfnIoReqAllocSizeSet(pTarget->pDrvMediaEx, sizeof(VIRTIOSCSIREQ)); 2258 2277 AssertMsgReturn(VALID_PTR(pTarget->pDrvMediaEx), 2259 ("virtio-scsi configuration error: LUN#%u: Failed to set I/O request size!\n", pTarget->iTarget),2278 ("virtio-scsi configuration error: LUN#%u: Failed to set I/O request size!\n", iTarget), 2260 2279 rc); 2261 2280 … … 2263 2282 AssertMsgReturn(VALID_PTR(pTarget->pDrvMediaEx), 2264 2283 ("virtio-scsi configuration error: LUN#%u: Failed to get set Media notify obj!\n", 2265 pTarget->iTarget), rc);2284 iTarget), rc); 2266 2285 2267 2286 } … … 2275 2294 else 2276 2295 { 2277 AssertLogRelMsgFailed(("virtio-scsi: Failed to attach %s: %Rrc\n", pTarget->pszTargetName ));2296 AssertLogRelMsgFailed(("virtio-scsi: Failed to attach %s: %Rrc\n", pTarget->pszTargetName, rc)); 2278 2297 return rc; 2279 2298 } -
trunk/src/VBox/Devices/VirtIO/Virtio_1_0.cpp
r80762 r80928 39 39 * See API comments in header file for description 40 40 */ 41 void virtioVirtToSgPhys(VIRTIOHANDLE hVirtio, PRTSGBUF pSgDst, void *pvSrc, size_t cb)42 {43 while (cb)44 {45 size_t cbSeg = cb;46 RTGCPHYS GCPhys = (RTGCPHYS)RTSgBufGetNextSegment(pSgDst, &cbSeg);47 PDMDevHlpPhysWrite(((PVIRTIOSTATE)hVirtio)->CTX_SUFF(pDevIns), GCPhys, pvSrc, cbSeg);48 pvSrc = ((uint8_t *)pvSrc) + cbSeg;49 cb -= cbSeg;50 }51 }52 53 /**54 * See API comments in header file for description55 */56 void virtioSgPhysToVirt(VIRTIOHANDLE hVirtio, PRTSGBUF pSgSrc, void *pvDst, size_t cb)57 {58 while (cb)59 {60 size_t cbSeg = cb;61 RTGCPHYS GCPhys = (RTGCPHYS)RTSgBufGetNextSegment(pSgSrc, &cbSeg);62 PDMDevHlpPhysRead(((PVIRTIOSTATE)hVirtio)->CTX_SUFF(pDevIns), GCPhys, pvDst, cbSeg);63 pvDst = ((uint8_t *)pvDst) + cbSeg;64 cb -= cbSeg;65 }66 }67 68 /**69 * See API comments in header file for description70 */71 41 int virtioQueueAttach(VIRTIOHANDLE hVirtio, uint16_t qIdx, const char *pcszName) 72 42 { … … 79 49 RTStrCopy((char *)pVirtq->szVirtqName, sizeof(pVirtq->szVirtqName), pcszName); 80 50 return VINF_SUCCESS; 81 82 51 } 83 52 … … 157 126 uint16_t uDescIdx = uHeadIdx; 158 127 159 Log 6Func(("%s DESC CHAIN: (head) desc_idx=%u [avail_idx=%u]\n",128 Log3Func(("%s DESC CHAIN: (head) desc_idx=%u [avail_idx=%u]\n", 160 129 pVirtq->szVirtqName, uHeadIdx, pVirtq->uAvailIdx)); 161 130 … … 198 167 if (desc.fFlags & VIRTQ_DESC_F_WRITE) 199 168 { 200 Log 6Func(("%s IN desc_idx=%u seg=%u addr=%RGp cb=%u\n",169 Log3Func(("%s IN desc_idx=%u seg=%u addr=%RGp cb=%u\n", 201 170 QUEUENAME(qIdx), uDescIdx, cSegsIn, desc.pGcPhysBuf, desc.cb)); 202 171 cbIn += desc.cb; … … 205 174 else 206 175 { 207 Log 6Func(("%s OUT desc_idx=%u seg=%u addr=%RGp cb=%u\n",176 Log3Func(("%s OUT desc_idx=%u seg=%u addr=%RGp cb=%u\n", 208 177 QUEUENAME(qIdx), uDescIdx, cSegsOut, desc.pGcPhysBuf, desc.cb)); 209 178 cbOut += desc.cb; … … 223 192 RTSgBufInit(pSgPhysIn, (PCRTSGSEG)paSegsIn, cSegsIn); 224 193 225 void *pSgVirtOut = RTMemAlloc(cbOut); 226 AssertReturn(pSgVirtOut, VERR_NO_MEMORY); 194 void *pVirtOut = RTMemAlloc(cbOut); 195 AssertReturn(pVirtOut, VERR_NO_MEMORY); 196 197 /* If there's any guest → device data in phys. memory pulled 198 * from queue, copy it into virtual memory to return to caller */ 227 199 228 200 if (cSegsOut) 229 201 { 202 uint8_t *outSgVirt = (uint8_t *)pVirtOut; 230 203 RTSGBUF outSgPhys; 231 204 RTSgBufInit(&outSgPhys, (PCRTSGSEG)paSegsOut, cSegsOut); 232 virtioSgPhysToVirt((PVIRTIOSTATE)hVirtio, &outSgPhys, pSgVirtOut, cbOut); 205 for (size_t cb = cbOut; cb;) 206 { 207 size_t cbSeg = cb; 208 RTGCPHYS GCPhys = (RTGCPHYS)RTSgBufGetNextSegment(&outSgPhys, &cbSeg); 209 PDMDevHlpPhysRead(((PVIRTIOSTATE)hVirtio)->CTX_SUFF(pDevIns), GCPhys, outSgVirt, cbSeg); 210 outSgVirt = ((uint8_t *)outSgVirt) + cbSeg; 211 cb -= cbSeg; 212 } 233 213 RTMemFree(paSegsOut); 234 214 } … … 239 219 pDescChain->uHeadIdx = uHeadIdx; 240 220 pDescChain->cbVirtSrc = cbOut; 241 pDescChain->pVirtSrc = p SgVirtOut;221 pDescChain->pVirtSrc = pVirtOut; 242 222 pDescChain->cbPhysDst = cbIn; 243 223 pDescChain->pSgPhysDst = pSgPhysIn; 244 224 *ppDescChain = pDescChain; 245 225 246 Log 6Func(("%s -- segs OUT: %u (%u bytes) IN: %u (%u bytes) --\n",226 Log3Func(("%s -- segs OUT: %u (%u bytes) IN: %u (%u bytes) --\n", 247 227 pVirtq->szVirtqName, cSegsOut, cbOut, cSegsIn, cbIn)); 248 228 … … 264 244 265 245 uint16_t uUsedIdx = virtioReadUsedRingIdx(pVirtio, qIdx); 266 Log 6Func(("Copying client data to %s, desc chain (head desc_idx %d)\n",246 Log3Func(("Copying client data to %s, desc chain (head desc_idx %d)\n", 267 247 QUEUENAME(qIdx), uUsedIdx)); 268 248 … … 270 250 * Copy virtual memory s/g buffer containing data to return to the guest 271 251 * to phys. memory described by (IN direction ) s/g buffer of the descriptor chain 272 * original pulled from the queue, to 'send back'to the guest driver.252 * (pulled from avail ring of queue), essentially giving result back to the guest driver. 273 253 */ 274 size_t cbRemain = RTSgBufCalcTotalLength(pSgVirtReturn);275 size_t cbCopy = 0;254 uint32_t cbRemain = RTSgBufCalcTotalLength(pSgVirtReturn); 255 uint32_t cbCopy = 0; 276 256 while (cbRemain) 277 257 { … … 288 268 } 289 269 290 291 270 if (fFence) 292 271 RT_UNTRUSTED_NONVOLATILE_COPY_FENCE(); … … 302 281 virtioWriteUsedElem(pVirtio, qIdx, pVirtq->uUsedIdx++, pDescChain->uHeadIdx, cbCopy); 303 282 304 305 if (LogIs2Enabled()) 306 { 307 Log2Func((".... Copied %u bytes to %u byte buffer, residual=%d\n", 308 cbCopy, pDescChain->cbPhysDst, pDescChain->cbPhysDst - cbCopy)); 309 } 283 Log2Func((".... Copied %u bytes to %u byte buffer, residual=%d\n", 284 cbCopy, pDescChain->cbPhysDst, pDescChain->cbPhysDst - cbCopy)); 285 310 286 Log6Func(("Write ahead used_idx=%d, %s used_idx=%d\n", 311 287 pVirtq->uUsedIdx, QUEUENAME(qIdx), uUsedIdx)); … … 1477 1453 * 1478 1454 */ 1479 void virtioHexDump(uint8_t *pv, size_t cb, uint32_t uBase, const char *pszTitle)1455 void virtioHexDump(uint8_t *pv, uint32_t cb, uint32_t uBase, const char *pszTitle) 1480 1456 { 1481 1457 if (pszTitle) … … 1512 1488 * @param idx - The index, if fHasIndex is true 1513 1489 */ 1514 void virtioLogMappedIoValue(const char *pszFunc, const char *pszMember, size_t uMemberSize,1490 void virtioLogMappedIoValue(const char *pszFunc, const char *pszMember, uint32_t uMemberSize, 1515 1491 const void *pv, uint32_t cb, uint32_t uOffset, bool fWrite, 1516 1492 bool fHasIndex, uint32_t idx) -
trunk/src/VBox/Devices/VirtIO/Virtio_1_0.h
r80762 r80928 65 65 { 66 66 uint32_t uHeadIdx; /**< Head idx of associated desc chain */ 67 size_t cbVirtSrc; /**< Size of virt source buffer */67 uint32_t cbVirtSrc; /**< Size of virt source buffer */ 68 68 void *pVirtSrc; /**< Virt mem buf holding out data from guest */ 69 size_t cbPhysDst; /**< Total size of dst buffer */69 uint32_t cbPhysDst; /**< Total size of dst buffer */ 70 70 PRTSGBUF pSgPhysDst; /**< Phys S/G buf to store result for guest */ 71 71 } VIRTIO_DESC_CHAIN_T, *PVIRTIO_DESC_CHAIN_T, **PPVIRTIO_DESC_CHAIN_T; … … 119 119 * @param cbWrite Number of bytes to write 120 120 */ 121 typedef DECLCALLBACK(int) FNVIRTIODEVCAPWRITE(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, size_t cbWrite);121 typedef DECLCALLBACK(int) FNVIRTIODEVCAPWRITE(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, uint32_t cbWrite); 122 122 typedef FNVIRTIODEVCAPWRITE *PFNVIRTIODEVCAPWRITE; 123 123 … … 131 131 * @param cbRead Number of bytes to read 132 132 */ 133 typedef DECLCALLBACK(int) FNVIRTIODEVCAPREAD(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, size_t cbRead);133 typedef DECLCALLBACK(int) FNVIRTIODEVCAPREAD(PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, uint32_t cbRead); 134 134 typedef FNVIRTIODEVCAPREAD *PFNVIRTIODEVCAPREAD; 135 135 … … 144 144 (VIRTIOHANDLE hVirtio, void *pClient, uint16_t qIdx); 145 145 DECLCALLBACKMEMBER(int, pfnVirtioDevCapRead) 146 (PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, size_t cbRead);146 (PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, uint32_t cbRead); 147 147 DECLCALLBACKMEMBER(int, pfnVirtioDevCapWrite) 148 (PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, size_t cbWrite);148 (PPDMDEVINS pDevIns, uint32_t uOffset, const void *pvBuf, uint32_t cbWrite); 149 149 DECLCALLBACKMEMBER(int, pfnSSMDevLiveExec) 150 150 (PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass); … … 381 381 * @param idx - The index if fHasIndex 382 382 */ 383 void virtioLogMappedIoValue(const char *pszFunc, const char *pszMember, size_t uMemberSize,383 void virtioLogMappedIoValue(const char *pszFunc, const char *pszMember, uint32_t uMemberSize, 384 384 const void *pv, uint32_t cb, uint32_t uOffset, 385 385 bool fWrite, bool fHasIndex, uint32_t idx); … … 395 395 * provided text with value of cb to indicate size next to it. 396 396 */ 397 void virtioHexDump(uint8_t *pv, size_t cb, uint32_t uBase, const char *pszTitle);397 void virtioHexDump(uint8_t *pv, uint32_t cb, uint32_t uBase, const char *pszTitle); 398 398 399 399 #endif /* !VBOX_INCLUDED_SRC_VirtIO_Virtio_1_0_h */ -
trunk/src/VBox/Devices/VirtIO/Virtio_1_0_impl.h
r80762 r80928 517 517 if (status & VIRTIO_STATUS_DEVICE_NEEDS_RESET) 518 518 Log6(("%sNEEDS_RESET", primed++ ? " | " : "")); 519 (void)primed; 519 520 } 520 521 }
Note:
See TracChangeset
for help on using the changeset viewer.