Changeset 80928 in vbox for trunk/src/VBox/Devices/VirtIO
- Timestamp:
- Sep 21, 2019 5:29:54 AM (5 years ago)
- Location:
- trunk/src/VBox/Devices/VirtIO
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
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.