Changeset 81678 in vbox for trunk/src/VBox/Devices/VirtIO
- Timestamp:
- Nov 5, 2019 4:58:45 PM (5 years ago)
- Location:
- trunk/src/VBox/Devices/VirtIO
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/VirtIO/Virtio_1_0.cpp
r81677 r81678 108 108 * Internal Functions * 109 109 *********************************************************************************************************************************/ 110 static void virtioNotifyGuestDriver(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint16_t idxQueue, bool fForce);111 static int virtioKick(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint8_t uCause, uint16_t uVec, bool fForce);110 static void virtioNotifyGuestDriver(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue, bool fForce); 111 static int virtioKick(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint8_t uCause, uint16_t uVec, bool fForce); 112 112 113 113 /** @name Internal queue operations … … 124 124 * Accessor for virtq descriptor 125 125 */ 126 DECLINLINE(void) virtioReadDesc(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint16_t idxQueue,126 DECLINLINE(void) virtioReadDesc(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue, 127 127 uint32_t idxDesc, PVIRTQ_DESC_T pDesc) 128 128 { … … 138 138 * Accessors for virtq avail ring 139 139 */ 140 DECLINLINE(uint16_t) virtioReadAvailDescIdx(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint16_t idxQueue, uint32_t availIdx)140 DECLINLINE(uint16_t) virtioReadAvailDescIdx(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue, uint32_t availIdx) 141 141 { 142 142 uint16_t uDescIdx; … … 150 150 } 151 151 152 DECLINLINE(uint16_t) virtioReadAvailRingIdx(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint16_t idxQueue)152 DECLINLINE(uint16_t) virtioReadAvailRingIdx(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue) 153 153 { 154 154 uint16_t uIdx = 0; … … 160 160 } 161 161 162 DECLINLINE(bool) virtqIsEmpty(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint16_t idxQueue)162 DECLINLINE(bool) virtqIsEmpty(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue) 163 163 { 164 164 return virtioReadAvailRingIdx(pDevIns, pVirtio, idxQueue) == pVirtio->virtqState[idxQueue].uAvailIdx; … … 166 166 167 167 #if 0 /* unused */ 168 DECLINLINE(uint16_t) virtioReadAvailFlags(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint16_t idxQueue)168 DECLINLINE(uint16_t) virtioReadAvailFlags(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue) 169 169 { 170 170 uint16_t fFlags; … … 177 177 #endif 178 178 179 DECLINLINE(uint16_t) virtioReadAvailUsedEvent(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint16_t idxQueue)179 DECLINLINE(uint16_t) virtioReadAvailUsedEvent(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue) 180 180 { 181 181 uint16_t uUsedEventIdx; … … 192 192 * @{ 193 193 */ 194 DECLINLINE(void) virtioWriteUsedElem(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint16_t idxQueue,194 DECLINLINE(void) virtioWriteUsedElem(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue, 195 195 uint32_t usedIdx, uint32_t uDescIdx, uint32_t uLen) 196 196 { … … 203 203 } 204 204 205 DECLINLINE(void) virtioWriteUsedRingIdx(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint16_t idxQueue, uint16_t uIdx)205 DECLINLINE(void) virtioWriteUsedRingIdx(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue, uint16_t uIdx) 206 206 { 207 207 AssertMsg(pVirtio->uDeviceStatus & VIRTIO_STATUS_DRIVER_OK, ("Called with guest driver not ready\n")); … … 212 212 213 213 #ifdef LOG_ENABLED 214 DECLINLINE(uint16_t) virtioReadUsedRingIdx(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint16_t idxQueue)214 DECLINLINE(uint16_t) virtioReadUsedRingIdx(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue) 215 215 { 216 216 uint16_t uIdx = 0; … … 223 223 #endif 224 224 225 DECLINLINE(uint16_t) virtioReadUsedFlags(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint16_t idxQueue)225 DECLINLINE(uint16_t) virtioReadUsedFlags(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue) 226 226 { 227 227 uint16_t fFlags = 0; … … 234 234 235 235 #if 0 /* unused */ 236 DECLINLINE(void) virtioWriteUsedFlags(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint16_t idxQueue, uint32_t fFlags)236 DECLINLINE(void) virtioWriteUsedFlags(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue, uint32_t fFlags) 237 237 { 238 238 AssertMsg(pVirtio->uDeviceStatus & VIRTIO_STATUS_DRIVER_OK, ("Called with guest driver not ready\n")); … … 245 245 246 246 #if 0 /* unused */ 247 DECLINLINE(uint16_t) virtioReadUsedAvailEvent(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint16_t idxQueue)247 DECLINLINE(uint16_t) virtioReadUsedAvailEvent(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue) 248 248 { 249 249 uint16_t uAvailEventIdx; … … 259 259 260 260 #if 0 /* unused */ 261 DECLINLINE(void) virtioWriteUsedAvailEvent(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint16_t idxQueue, uint32_t uAvailEventIdx)261 DECLINLINE(void) virtioWriteUsedAvailEvent(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue, uint32_t uAvailEventIdx) 262 262 { 263 263 /** VirtIO 1.0 uAvailEventIdx (avail_event) immediately follows ring */ … … 283 283 * provided text with value of cb to indicate size next to it. 284 284 */ 285 void virtio HexDump(uint8_t *pv, uint32_t cb, uint32_t uBase, const char *pszTitle)285 void virtioCoreHexDump(uint8_t *pv, uint32_t cb, uint32_t uBase, const char *pszTitle) 286 286 { 287 287 if (pszTitle) … … 326 326 * @param idx The index if fHasIndex 327 327 */ 328 void virtio LogMappedIoValue(const char *pszFunc, const char *pszMember, uint32_t uMemberSize,328 void virtioCoreLogMappedIoValue(const char *pszFunc, const char *pszMember, uint32_t uMemberSize, 329 329 const void *pv, uint32_t cb, uint32_t uOffset, int fWrite, 330 330 int fHasIndex, uint32_t idx) … … 408 408 * @returns VBox status code. 409 409 */ 410 int virtio R3QueueAttach(PVIRTIOSTATE pVirtio, uint16_t idxQueue, const char *pcszName)410 int virtioCoreR3QueueAttach(PVIRTIOCORE pVirtio, uint16_t idxQueue, const char *pcszName) 411 411 { 412 412 LogFunc(("%s\n", pcszName)); … … 424 424 * See API comments in header file for description 425 425 */ 426 int virtioQueueSkip(PVIRTIO STATE pVirtio, uint16_t idxQueue)426 int virtioQueueSkip(PVIRTIOCORE pVirtio, uint16_t idxQueue) 427 427 { 428 428 Assert(idxQueue < RT_ELEMENTS(pVirtio->virtqState)); … … 432 432 ("Guest driver not in ready state.\n"), VERR_INVALID_STATE); 433 433 434 if (virtio QueueIsEmpty(pVirtio, idxQueue))434 if (virtioCoreQueueIsEmpty(pVirtio, idxQueue)) 435 435 return VERR_NOT_AVAILABLE; 436 436 … … 452 452 * @retval false Queue is available and has entries 453 453 */ 454 bool virtio QueueIsEmpty(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio, uint16_t idxQueue)454 bool virtioCoreQueueIsEmpty(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue) 455 455 { 456 456 if (pVirtio->uDeviceStatus & VIRTIO_STATUS_DRIVER_OK) … … 467 467 * Additionally it converts the OUT desc chain data to a contiguous virtual 468 468 * memory buffer for easy consumption by the caller. The caller must return the 469 * descriptor chain pointer via virtio R3QueuePut() and then call virtioQueueSync()469 * descriptor chain pointer via virtioCoreR3QueuePut() and then call virtioCoreQueueSync() 470 470 * at some point to return the data to the guest and complete the transaction. 471 471 * … … 482 482 * @retval VERR_NOT_AVAILABLE If the queue is empty. 483 483 */ 484 int virtio R3QueueGet(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio, uint16_t idxQueue,485 PPVIRTIO_DESC_CHAIN_T ppDescChain, bool fRemove)484 int virtioCoreR3QueueGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue, 485 PPVIRTIO_DESC_CHAIN_T ppDescChain, bool fRemove) 486 486 { 487 487 AssertReturn(ppDescChain, VERR_INVALID_PARAMETER); … … 595 595 * 596 596 * @note This does a write-ahead to the used ring of the guest's queue. The data 597 * written won't be seen by the guest until the next call to virtio QueueSync()597 * written won't be seen by the guest until the next call to virtioCoreQueueSync() 598 598 * 599 599 * … … 616 616 * @retval VERR_NOT_AVAILABLE Queue is empty 617 617 */ 618 int virtio R3QueuePut(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio, uint16_t idxQueue, PRTSGBUF pSgVirtReturn,619 PVIRTIO_DESC_CHAIN_T pDescChain, bool fFence)618 int virtioCoreR3QueuePut(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue, PRTSGBUF pSgVirtReturn, 619 PVIRTIO_DESC_CHAIN_T pDescChain, bool fFence) 620 620 { 621 621 Assert(idxQueue < RT_ELEMENTS(pVirtio->virtqState)); … … 663 663 /* 664 664 * Place used buffer's descriptor in used ring but don't update used ring's slot index. 665 * That will be done with a subsequent client call to virtio QueueSync() */665 * That will be done with a subsequent client call to virtioCoreQueueSync() */ 666 666 virtioWriteUsedElem(pDevIns, pVirtio, idxQueue, pVirtq->uUsedIdx++, pDescChain->uHeadIdx, (uint32_t)cbCopy); 667 667 … … 686 686 * Updates the indicated virtq's "used ring" descriptor index to match the 687 687 * current write-head index, thus exposing the data added to the used ring by all 688 * virtio R3QueuePut() calls since the last sync. This should be called after one or688 * virtioCoreR3QueuePut() calls since the last sync. This should be called after one or 689 689 * more virtQueuePut() calls to inform the guest driver there is data in the queue. 690 690 * Explicit notifications (e.g. interrupt or MSI-X) will be sent to the guest, … … 701 701 * @retval VERR_INVALID_STATE VirtIO not in ready state 702 702 */ 703 int virtio QueueSync(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio, uint16_t idxQueue)703 int virtioCoreQueueSync(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue) 704 704 { 705 705 Assert(idxQueue < RT_ELEMENTS(pVirtio->virtqState)); … … 721 721 /** 722 722 */ 723 static void virtioR3QueueNotified(PVIRTIO STATE pVirtio, PVIRTIOSTATECC pVirtioCC, uint16_t idxQueue, uint16_t uNotifyIdx)723 static void virtioR3QueueNotified(PVIRTIOCORE pVirtio, PVIRTIOCORECC pVirtioCC, uint16_t idxQueue, uint16_t uNotifyIdx) 724 724 { 725 725 /* See VirtIO 1.0, section 4.1.5.2 It implies that idxQueue and uNotifyIdx should match. … … 740 740 741 741 /* Inform client */ 742 pVirtioCC-> Callbacks.pfnQueueNotified(pVirtio, pVirtioCC, idxQueue);742 pVirtioCC->pfnQueueNotified(pVirtio, pVirtioCC, idxQueue); 743 743 } 744 744 #endif /* IN_RING3 */ … … 760 760 * as they only cause the guest driver to [re]scan queues for work to do. 761 761 */ 762 static void virtioNotifyGuestDriver(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint16_t idxQueue, bool fForce)762 static void virtioNotifyGuestDriver(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue, bool fForce) 763 763 { 764 764 Assert(idxQueue < RT_ELEMENTS(pVirtio->virtqState)); … … 797 797 * @param uForce True of out-of-band 798 798 */ 799 static int virtioKick(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, uint8_t uCause, uint16_t uMsixVector, bool fForce)799 static int virtioKick(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint8_t uCause, uint16_t uMsixVector, bool fForce) 800 800 { 801 801 if (fForce) … … 832 832 } 833 833 834 static void virtioResetQueue(PVIRTIO STATE pVirtio, uint16_t idxQueue)834 static void virtioResetQueue(PVIRTIOCORE pVirtio, uint16_t idxQueue) 835 835 { 836 836 Assert(idxQueue < RT_ELEMENTS(pVirtio->virtqState)); … … 847 847 } 848 848 849 static void virtioResetDevice(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio)849 static void virtioResetDevice(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio) 850 850 { 851 851 Log2Func(("\n")); … … 874 874 * @param fEnabled Flag indicating whether to enable queue or not 875 875 */ 876 void virtio QueueEnable(PVIRTIOSTATE pVirtio, uint16_t idxQueue, bool fEnabled)876 void virtioCoreQueueEnable(PVIRTIOCORE pVirtio, uint16_t idxQueue, bool fEnabled) 877 877 { 878 878 if (fEnabled) … … 888 888 * Invoked by client to reset the device and driver (see VirtIO 1.0 section 2.1.1/2.1.2) 889 889 */ 890 void virtio ResetAll(PVIRTIOSTATE pVirtio)890 void virtioCoreResetAll(PVIRTIOCORE pVirtio) 891 891 { 892 892 LogFunc(("VIRTIO RESET REQUESTED!!!\n")); … … 905 905 * The driver itself will not until the device has read the status change. 906 906 */ 907 static void virtioGuestR3WasReset(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, PVIRTIOSTATECC pVirtioCC)907 static void virtioGuestR3WasReset(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, PVIRTIOCORECC pVirtioCC) 908 908 { 909 909 LogFunc(("Guest reset the device\n")); 910 910 911 911 /* Let the client know */ 912 pVirtioCC-> Callbacks.pfnStatusChanged(pVirtio, pVirtioCC, 0);912 pVirtioCC->pfnStatusChanged(pVirtio, pVirtioCC, 0); 913 913 virtioResetDevice(pDevIns, pVirtio); 914 914 } … … 928 928 * @param pv Pointer to location to write to or read from 929 929 */ 930 static int virtioCommonCfgAccessed(PPDMDEVINS pDevIns, PVIRTIO STATE pVirtio, PVIRTIOSTATECC pVirtioCC,930 static int virtioCommonCfgAccessed(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, PVIRTIOCORECC pVirtioCC, 931 931 int fWrite, uint32_t offCfg, unsigned cb, void *pv) 932 932 { … … 952 952 #ifdef LOG_ENABLED 953 953 # define LOG_COMMON_CFG_ACCESS(member, a_offIntra) \ 954 virtio LogMappedIoValue(__FUNCTION__, #member, RT_SIZEOFMEMB(VIRTIO_PCI_COMMON_CFG_T, member), \954 virtioCoreLogMappedIoValue(__FUNCTION__, #member, RT_SIZEOFMEMB(VIRTIO_PCI_COMMON_CFG_T, member), \ 955 955 pv, cb, a_offIntra, fWrite, false, 0); 956 956 # define LOG_COMMON_CFG_ACCESS_INDEXED(member, idx, a_offIntra) \ 957 virtio LogMappedIoValue(__FUNCTION__, #member, RT_SIZEOFMEMB(VIRTIO_PCI_COMMON_CFG_T, member), \957 virtioCoreLogMappedIoValue(__FUNCTION__, #member, RT_SIZEOFMEMB(VIRTIO_PCI_COMMON_CFG_T, member), \ 958 958 pv, cb, a_offIntra, fWrite, true, idx); 959 959 #else … … 1125 1125 virtioGuestR3WasReset(pDevIns, pVirtio, pVirtioCC); 1126 1126 if (fStatusChanged) 1127 pVirtioCC-> Callbacks.pfnStatusChanged(pVirtio, pVirtioCC, fNewStatus & VIRTIO_STATUS_DRIVER_OK);1127 pVirtioCC->pfnStatusChanged(pVirtio, pVirtioCC, fNewStatus & VIRTIO_STATUS_DRIVER_OK); 1128 1128 #endif 1129 1129 /* … … 1202 1202 static DECLCALLBACK(VBOXSTRICTRC) virtioMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb) 1203 1203 { 1204 PVIRTIO STATE pVirtio = PDMINS_2_DATA(pDevIns, PVIRTIOSTATE);1205 PVIRTIO STATECC pVirtioCC = PDMINS_2_DATA_CC(pDevIns, PVIRTIOSTATECC);1206 Assert(pVirtio == (PVIRTIO STATE)pvUser); RT_NOREF(pvUser);1204 PVIRTIOCORE pVirtio = PDMINS_2_DATA(pDevIns, PVIRTIOCORE); 1205 PVIRTIOCORECC pVirtioCC = PDMINS_2_DATA_CC(pDevIns, PVIRTIOCORECC); 1206 Assert(pVirtio == (PVIRTIOCORE)pvUser); RT_NOREF(pvUser); 1207 1207 1208 1208 /** @todo r=bird: This code does not handle reads spanning more than one … … 1221 1221 * Callback to client to manage device-specific configuration. 1222 1222 */ 1223 VBOXSTRICTRC rcStrict = pVirtioCC-> Callbacks.pfnDevCapRead(pDevIns, offIntra, pv, cb);1223 VBOXSTRICTRC rcStrict = pVirtioCC->pfnDevCapRead(pDevIns, offIntra, pv, cb); 1224 1224 1225 1225 /* … … 1271 1271 static DECLCALLBACK(VBOXSTRICTRC) virtioMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb) 1272 1272 { 1273 PVIRTIO STATE pVirtio = PDMINS_2_DATA(pDevIns, PVIRTIOSTATE);1274 PVIRTIO STATECC pVirtioCC = PDMINS_2_DATA_CC(pDevIns, PVIRTIOSTATECC);1275 Assert(pVirtio == (PVIRTIO STATE)pvUser); RT_NOREF(pvUser);1273 PVIRTIOCORE pVirtio = PDMINS_2_DATA(pDevIns, PVIRTIOCORE); 1274 PVIRTIOCORECC pVirtioCC = PDMINS_2_DATA_CC(pDevIns, PVIRTIOCORECC); 1275 Assert(pVirtio == (PVIRTIOCORE)pvUser); RT_NOREF(pvUser); 1276 1276 1277 1277 /** @todo r=bird: This code does not handle writes spanning more than one … … 1290 1290 * Pass this MMIO write access back to the client to handle 1291 1291 */ 1292 return pVirtioCC-> Callbacks.pfnDevCapWrite(pDevIns, offIntra, pv, cb);1292 return pVirtioCC->pfnDevCapWrite(pDevIns, offIntra, pv, cb); 1293 1293 #else 1294 1294 return VINF_IOM_R3_MMIO_WRITE; … … 1331 1331 uint32_t uAddress, unsigned cb, uint32_t *pu32Value) 1332 1332 { 1333 PVIRTIO STATE pVirtio = PDMINS_2_DATA(pDevIns, PVIRTIOSTATE);1334 PVIRTIO STATECC pVirtioCC = PDMINS_2_DATA_CC(pDevIns, PVIRTIOSTATECC);1333 PVIRTIOCORE pVirtio = PDMINS_2_DATA(pDevIns, PVIRTIOCORE); 1334 PVIRTIOCORECC pVirtioCC = PDMINS_2_DATA_CC(pDevIns, PVIRTIOCORECC); 1335 1335 RT_NOREF(pPciDev); 1336 1336 … … 1371 1371 uint32_t uAddress, unsigned cb, uint32_t u32Value) 1372 1372 { 1373 PVIRTIO STATE pVirtio = PDMINS_2_DATA(pDevIns, PVIRTIOSTATE);1374 PVIRTIO STATECC pVirtioCC = PDMINS_2_DATA_CC(pDevIns, PVIRTIOSTATECC);1373 PVIRTIOCORE pVirtio = PDMINS_2_DATA(pDevIns, PVIRTIOCORE); 1374 PVIRTIOCORECC pVirtioCC = PDMINS_2_DATA_CC(pDevIns, PVIRTIOCORECC); 1375 1375 RT_NOREF(pPciDev); 1376 1376 … … 1415 1415 * @returns VBox status code. 1416 1416 */ 1417 int virtio R3SaveExec(PVIRTIOSTATE pVirtio, PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM)1417 int virtioCoreR3SaveExec(PVIRTIOCORE pVirtio, PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM) 1418 1418 { 1419 1419 pHlp->pfnSSMPutU64(pSSM, VIRTIO_SAVEDSTATE_MARKER); … … 1429 1429 pHlp->pfnSSMPutU32(pSSM, pVirtio->uDriverFeaturesSelect); 1430 1430 pHlp->pfnSSMPutU64(pSSM, pVirtio->uDriverFeatures); 1431 Assert(pVirtio->uNumQueues == VIRTQ_MAX_CNT); /** @todo r=bird: See todo in struct & virtio R3LoadExec. */1431 Assert(pVirtio->uNumQueues == VIRTQ_MAX_CNT); /** @todo r=bird: See todo in struct & virtioCoreR3LoadExec. */ 1432 1432 pHlp->pfnSSMPutU32(pSSM, pVirtio->uNumQueues); 1433 1433 … … 1458 1458 * @returns VBox status code. 1459 1459 */ 1460 int virtio R3LoadExec(PVIRTIOSTATE pVirtio, PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM)1460 int virtioCoreR3LoadExec(PVIRTIOCORE pVirtio, PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM) 1461 1461 { 1462 1462 /* … … 1530 1530 * @param pVirtio Pointer to the shared virtio state. 1531 1531 */ 1532 void virtio R3PropagateResetNotification(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio)1532 void virtioCoreR3PropagateResetNotification(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio) 1533 1533 { 1534 1534 /** @todo r=bird: You probably need to do something here. See … … 1546 1546 * from stalling after suspend. 1547 1547 */ 1548 void virtio R3PropagateResumeNotification(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio)1548 void virtioCoreR3PropagateResumeNotification(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio) 1549 1549 { 1550 1550 virtioNotifyGuestDriver(pDevIns, pVirtio, 0 /* idxQueue */, true /* fForce */); … … 1559 1559 * @param pVirtioCC Pointer to the ring-3 virtio state. 1560 1560 */ 1561 void virtio R3Term(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio, PVIRTIOSTATECC pVirtioCC)1561 void virtioCoreR3Term(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, PVIRTIOCORECC pVirtioCC) 1562 1562 { 1563 1563 if (pVirtioCC->pbPrevDevSpecificCfg) … … 1590 1590 * configuration struct. 1591 1591 */ 1592 int virtio R3Init(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio, PVIRTIOSTATECC pVirtioCC, PVIRTIOPCIPARAMS pPciParams,1593 const char *pcszInstance, uint64_t fDevSpecificFeatures, void *pvDevSpecificCfg, uint16_t cbDevSpecificCfg)1592 int virtioCoreR3Init(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, PVIRTIOCORECC pVirtioCC, PVIRTIOPCIPARAMS pPciParams, 1593 const char *pcszInstance, uint64_t fDevSpecificFeatures, void *pvDevSpecificCfg, uint16_t cbDevSpecificCfg) 1594 1594 { 1595 1595 /* … … 1597 1597 * data, otherwise we cannot get our bearings in the PCI configuration callbacks. 1598 1598 */ 1599 AssertLogRelReturn(pVirtio == PDMINS_2_DATA(pDevIns, PVIRTIOSTATE), VERR_STATE_CHANGED); 1600 AssertLogRelReturn(pVirtioCC == PDMINS_2_DATA_CC(pDevIns, PVIRTIOSTATECC), VERR_STATE_CHANGED); 1601 1599 AssertLogRelReturn(pVirtio == PDMINS_2_DATA(pDevIns, PVIRTIOCORE), VERR_STATE_CHANGED); 1600 AssertLogRelReturn(pVirtioCC == PDMINS_2_DATA_CC(pDevIns, PVIRTIOCORECC), VERR_STATE_CHANGED); 1601 1602 /* 1603 * Caller must initialize these. 1604 */ 1605 AssertReturn(pVirtioCC->pfnStatusChanged, VERR_INVALID_POINTER); 1606 AssertReturn(pVirtioCC->pfnQueueNotified, VERR_INVALID_POINTER); 1607 AssertReturn(pVirtioCC->pfnDevCapRead, VERR_INVALID_POINTER); 1608 AssertReturn(pVirtioCC->pfnDevCapWrite, VERR_INVALID_POINTER); 1602 1609 1603 1610 #if 0 /* Until pdmR3DvHlp_PCISetIrq() impl is fixed and Assert that limits vec to 0 is removed */ … … 1809 1816 * first member in the currenct context's device instance data! 1810 1817 */ 1811 int virtio RZInit(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio, PVIRTIOSTATECC pVirtioCC)1812 { 1813 AssertLogRelReturn(pVirtio == PDMINS_2_DATA(pDevIns, PVIRTIO STATE), VERR_STATE_CHANGED);1814 AssertLogRelReturn(pVirtioCC == PDMINS_2_DATA_CC(pDevIns, PVIRTIO STATECC), VERR_STATE_CHANGED);1818 int virtioCoreRZInit(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, PVIRTIOCORECC pVirtioCC) 1819 { 1820 AssertLogRelReturn(pVirtio == PDMINS_2_DATA(pDevIns, PVIRTIOCORE), VERR_STATE_CHANGED); 1821 AssertLogRelReturn(pVirtioCC == PDMINS_2_DATA_CC(pDevIns, PVIRTIOCORECC), VERR_STATE_CHANGED); 1815 1822 1816 1823 int rc = PDMDevHlpMmioSetUpContext(pDevIns, pVirtio->hMmioPciCap, virtioMmioWrite, virtioMmioRead, pVirtio); -
trunk/src/VBox/Devices/VirtIO/Virtio_1_0.h
r81677 r81678 26 26 27 27 /** Pointer to the shared VirtIO state. */ 28 typedef struct VIRTIO STATE *PVIRTIOSTATE;28 typedef struct VIRTIOCORE *PVIRTIOCORE; 29 29 /** Pointer to the ring-3 VirtIO state. */ 30 typedef struct VIRTIO STATER3 *PVIRTIOSTATER3;30 typedef struct VIRTIOCORER3 *PVIRTIOCORER3; 31 31 /** Pointer to the ring-0 VirtIO state. */ 32 typedef struct VIRTIO STATER0 *PVIRTIOSTATER0;32 typedef struct VIRTIOCORER0 *PVIRTIOCORER0; 33 33 /** Pointer to the raw-mode VirtIO state. */ 34 typedef struct VIRTIO STATERC *PVIRTIOSTATERC;34 typedef struct VIRTIOCORERC *PVIRTIOCORERC; 35 35 /** Pointer to the instance data for the current context. */ 36 typedef CTX_SUFF(PVIRTIO STATE) PVIRTIOSTATECC;36 typedef CTX_SUFF(PVIRTIOCORE) PVIRTIOCORECC; 37 37 38 38 … … 54 54 do { \ 55 55 if (LogIsItEnabled(logLevel, LOG_GROUP)) \ 56 virtio HexDump((pv), (cb), (base), (title)); \56 virtioCoreHexDump((pv), (cb), (base), (title)); \ 57 57 } while (0) 58 58 #else … … 72 72 * 73 73 * Typical use is, When the client (worker thread) detects available data on the queue, it pulls the 74 * next one of these descriptor chain structs off the queue using virtio R3QueueGet(), processes the74 * next one of these descriptor chain structs off the queue using virtioCoreR3QueueGet(), processes the 75 75 * virtual memory buffer pVirtSrc, produces result data to pass back to the guest driver and calls 76 * virtio R3QueuePut() to return the result data to the client.76 * virtioCoreR3QueuePut() to return the result data to the client. 77 77 */ 78 78 typedef struct VIRTIO_DESC_CHAIN … … 102 102 } VIRTIOPCIPARAMS, *PVIRTIOPCIPARAMS; 103 103 104 /** @name VirtIO port I/O callbacks.105 * @{ */106 typedef struct VIRTIOCALLBACKS107 {108 /**109 * Implementation-specific client callback to notify client of significant device status110 * changes.111 *112 * @param pVirtio Pointer to the shared virtio state.113 * @param pVirtioCC Pointer to the ring-3 virtio state.114 * @param fDriverOk True if guest driver is okay (thus queues, etc... are115 * valid)116 */117 DECLCALLBACKMEMBER(void, pfnStatusChanged)(PVIRTIOSTATE pVirtio, PVIRTIOSTATECC pVirtioCC, uint32_t fDriverOk);118 119 /**120 * When guest-to-host queue notifications are enabled, the guest driver notifies the host121 * that the avail queue has buffers, and this callback informs the client.122 *123 * @param pVirtio Pointer to the shared virtio state.124 * @param pVirtioCC Pointer to the ring-3 virtio state.125 * @param idxQueue Index of the notified queue126 */127 DECLCALLBACKMEMBER(void, pfnQueueNotified)(PVIRTIOSTATE pVirtio, PVIRTIOSTATECC pVirtioCC, uint16_t idxQueue);128 129 /**130 * Implementation-specific client callback to access VirtIO Device-specific capabilities131 * (other VirtIO capabilities and features are handled in VirtIO implementation)132 *133 * @param pDevIns The device instance.134 * @param offCap Offset within device specific capabilities struct.135 * @param pvBuf Buffer in which to save read data.136 * @param cbToRead Number of bytes to read.137 */138 DECLCALLBACKMEMBER(int, pfnDevCapRead)(PPDMDEVINS pDevIns, uint32_t offCap, void *pvBuf, uint32_t cbToRead);139 140 /**141 * Implementation-specific client ballback to access VirtIO Device-specific capabilities142 * (other VirtIO capabilities and features are handled in VirtIO implementation)143 *144 * @param pDevIns The device instance.145 * @param offCap Offset within device specific capabilities struct.146 * @param pvBuf Buffer with the bytes to write.147 * @param cbToWrite Number of bytes to write.148 */149 DECLCALLBACKMEMBER(int, pfnDevCapWrite)(PPDMDEVINS pDevIns, uint32_t offCap, const void *pvBuf, uint32_t cbWrite);150 } VIRTIOCALLBACKS;151 /** @} */152 104 153 105 #define VIRTIO_F_VERSION_1 RT_BIT_64(32) /**< Required feature bit for 1.0 devices */ … … 267 219 * The core/common state of the VirtIO PCI devices, shared edition. 268 220 */ 269 typedef struct VIRTIO STATE221 typedef struct VIRTIOCORE 270 222 { 271 223 char szInstance[16]; /**< Instance name, e.g. "VIRTIOSCSI0" */ … … 313 265 /** The MMIO handle for the PCI capability region (\#2). */ 314 266 IOMMMIOHANDLE hMmioPciCap; 315 } VIRTIO STATE;267 } VIRTIOCORE; 316 268 317 269 … … 319 271 * The core/common state of the VirtIO PCI devices, ring-3 edition. 320 272 */ 321 typedef struct VIRTIOSTATER3 322 { 323 VIRTIOCALLBACKS Callbacks; /**< Callback vectors to client */ 273 typedef struct VIRTIOCORER3 274 { 275 /** @name Callbacks filled by the device before calling virtioCoreR3Init. 276 * @{ */ 277 /** 278 * Implementation-specific client callback to notify client of significant device status 279 * changes. 280 * 281 * @param pVirtio Pointer to the shared virtio state. 282 * @param pVirtioCC Pointer to the ring-3 virtio state. 283 * @param fDriverOk True if guest driver is okay (thus queues, etc... are 284 * valid) 285 */ 286 DECLCALLBACKMEMBER(void, pfnStatusChanged)(PVIRTIOCORE pVirtio, PVIRTIOCORECC pVirtioCC, uint32_t fDriverOk); 287 288 /** 289 * When guest-to-host queue notifications are enabled, the guest driver notifies the host 290 * that the avail queue has buffers, and this callback informs the client. 291 * 292 * @param pVirtio Pointer to the shared virtio state. 293 * @param pVirtioCC Pointer to the ring-3 virtio state. 294 * @param idxQueue Index of the notified queue 295 */ 296 DECLCALLBACKMEMBER(void, pfnQueueNotified)(PVIRTIOCORE pVirtio, PVIRTIOCORECC pVirtioCC, uint16_t idxQueue); 297 298 /** 299 * Implementation-specific client callback to access VirtIO Device-specific capabilities 300 * (other VirtIO capabilities and features are handled in VirtIO implementation) 301 * 302 * @param pDevIns The device instance. 303 * @param offCap Offset within device specific capabilities struct. 304 * @param pvBuf Buffer in which to save read data. 305 * @param cbToRead Number of bytes to read. 306 */ 307 DECLCALLBACKMEMBER(int, pfnDevCapRead)(PPDMDEVINS pDevIns, uint32_t offCap, void *pvBuf, uint32_t cbToRead); 308 309 /** 310 * Implementation-specific client ballback to access VirtIO Device-specific capabilities 311 * (other VirtIO capabilities and features are handled in VirtIO implementation) 312 * 313 * @param pDevIns The device instance. 314 * @param offCap Offset within device specific capabilities struct. 315 * @param pvBuf Buffer with the bytes to write. 316 * @param cbToWrite Number of bytes to write. 317 */ 318 DECLCALLBACKMEMBER(int, pfnDevCapWrite)(PPDMDEVINS pDevIns, uint32_t offCap, const void *pvBuf, uint32_t cbWrite); 319 /** @} */ 324 320 325 321 R3PTRTYPE(PVIRTIO_PCI_CFG_CAP_T) pPciCfgCap; /**< Pointer to struct in the PCI configuration area. */ … … 333 329 R3PTRTYPE(uint8_t *) pbPrevDevSpecificCfg; /**< Previous read dev-specific cfg of client */ 334 330 bool fGenUpdatePending; /**< If set, update cfg gen after driver reads */ 335 } VIRTIO STATER3;331 } VIRTIOCORER3; 336 332 337 333 … … 339 335 * The core/common state of the VirtIO PCI devices, ring-0 edition. 340 336 */ 341 typedef struct VIRTIO STATER0337 typedef struct VIRTIOCORER0 342 338 { 343 339 uint64_t uUnusedAtTheMoment; 344 } VIRTIO STATER0;340 } VIRTIOCORER0; 345 341 346 342 … … 348 344 * The core/common state of the VirtIO PCI devices, raw-mode edition. 349 345 */ 350 typedef struct VIRTIO STATERC346 typedef struct VIRTIOCORERC 351 347 { 352 348 uint64_t uUnusedAtTheMoment; 353 } VIRTIO STATERC;354 355 356 /** @typedef VIRTIO STATECC349 } VIRTIOCORERC; 350 351 352 /** @typedef VIRTIOCORECC 357 353 * The instance data for the current context. */ 358 typedef CTX_SUFF(VIRTIOSTATE) VIRTIOSTATECC; 359 360 361 /** virtq related flags */ 354 typedef CTX_SUFF(VIRTIOCORE) VIRTIOCORECC; 355 356 357 /** @name virtq related flags 358 * @{ */ 362 359 #define VIRTQ_DESC_F_NEXT 1 /**< Indicates this descriptor chains to next */ 363 360 #define VIRTQ_DESC_F_WRITE 2 /**< Marks buffer as write-only (default ro) */ … … 366 363 #define VIRTQ_USED_F_NO_NOTIFY 1 /**< Dev to Drv: Don't notify when buf added */ 367 364 #define VIRTQ_AVAIL_F_NO_INTERRUPT 1 /**< Drv to Dev: Don't notify when buf eaten */ 368 369 370 /** @name API for VirtIO client 365 /** @} */ 366 367 368 /** @name API for VirtIO parent device 371 369 * @{ */ 372 370 373 int virtio R3QueueAttach(PVIRTIOSTATE pVirtio, uint16_t idxQueue, const char *pcszName);371 int virtioCoreR3QueueAttach(PVIRTIOCORE pVirtio, uint16_t idxQueue, const char *pcszName); 374 372 #if 0 /* no such function */ 375 373 /** … … 379 377 * @param idxQueue Queue number 380 378 */ 381 int virtio QueueDetach(PVIRTIOSTATE pVirtio, uint16_t idxQueue);379 int virtioCoreR3QueueDetach(PVIRTIOCORE pVirtio, uint16_t idxQueue); 382 380 #endif 383 int virtioR3QueueGet(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio, uint16_t idxQueue, 384 PPVIRTIO_DESC_CHAIN_T ppDescChain, bool fRemove); 385 int virtioR3QueuePut(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio, uint16_t idxQueue, PRTSGBUF pSgVirtReturn, 386 PVIRTIO_DESC_CHAIN_T pDescChain, bool fFence); 387 int virtioQueueSync(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio, uint16_t idxQueue); 388 bool virtioQueueIsEmpty(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio, uint16_t idxQueue); 389 void virtioQueueEnable(PVIRTIOSTATE pVirtio, uint16_t idxQueue, bool fEnabled); 390 391 #if 0 /** @todo unused */ 392 void virtioResetAll(PVIRTIOSTATE pVirtio); 393 #endif 381 int virtioCoreR3QueueGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue, 382 PPVIRTIO_DESC_CHAIN_T ppDescChain, bool fRemove); 383 int virtioCoreR3QueuePut(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue, PRTSGBUF pSgVirtReturn, 384 PVIRTIO_DESC_CHAIN_T pDescChain, bool fFence); 385 int virtioCoreQueueSync(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue); 386 bool virtioCoreQueueIsEmpty(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t idxQueue); 387 void virtioCoreQueueEnable(PVIRTIOCORE pVirtio, uint16_t idxQueue, bool fEnabled); 394 388 395 389 /** … … 400 394 * @param fEnabled Flag indicating whether to enable queue or not 401 395 */ 402 DECLINLINE(bool) virtio IsQueueEnabled(PVIRTIOSTATE pVirtio, uint16_t idxQueue)396 DECLINLINE(bool) virtioCoreIsQueueEnabled(PVIRTIOCORE pVirtio, uint16_t idxQueue) 403 397 { 404 398 Assert(idxQueue < RT_ELEMENTS(pVirtio->virtqState)); … … 408 402 409 403 /** 410 * Get name of queue, by idxQueue, assigned at virtio R3QueueAttach()404 * Get name of queue, by idxQueue, assigned at virtioCoreR3QueueAttach() 411 405 * 412 406 * @param pVirtio Pointer to the virtio state. … … 415 409 * @returns Pointer to read-only queue name. 416 410 */ 417 DECLINLINE(const char *) virtio QueueGetName(PVIRTIOSTATE pVirtio, uint16_t idxQueue)411 DECLINLINE(const char *) virtioCoreQueueGetName(PVIRTIOCORE pVirtio, uint16_t idxQueue) 418 412 { 419 413 Assert((size_t)idxQueue < RT_ELEMENTS(pVirtio->virtqState)); … … 426 420 * @returns Features the guest driver has accepted, finalizing the operational features 427 421 */ 428 DECLINLINE(uint64_t) virtio GetNegotiatedFeatures(PVIRTIOSTATE pVirtio)422 DECLINLINE(uint64_t) virtioCoreGetNegotiatedFeatures(PVIRTIOCORE pVirtio) 429 423 { 430 424 return pVirtio->uDriverFeatures; … … 438 432 * @param pState Virtio state 439 433 */ 440 DECLINLINE(uint64_t) virtio GetAcceptedFeatures(PVIRTIOSTATE pVirtio)434 DECLINLINE(uint64_t) virtioCoreGetAcceptedFeatures(PVIRTIOCORE pVirtio) 441 435 { 442 436 return pVirtio->uDriverFeatures; … … 444 438 445 439 446 int virtioR3SaveExec(PVIRTIOSTATE pVirtio, PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM); 447 int virtioR3LoadExec(PVIRTIOSTATE pVirtio, PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM); 448 void virtioR3PropagateResetNotification(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio); 449 void virtioR3PropagateResumeNotification(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio); 450 void virtioR3Term(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio, PVIRTIOSTATECC pVirtioCC); 451 int virtioR3Init(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio, PVIRTIOSTATECC pVirtioCC, PVIRTIOPCIPARAMS pPciParams, 452 const char *pcszInstance, uint64_t fDevSpecificFeatures, void *pvDevSpecificCfg, uint16_t cbDevSpecificCfg); 453 int virtioRZInit(PPDMDEVINS pDevIns, PVIRTIOSTATE pVirtio, PVIRTIOSTATECC pVirtioCC); 454 455 void virtioLogMappedIoValue(const char *pszFunc, const char *pszMember, uint32_t uMemberSize, 456 const void *pv, uint32_t cb, uint32_t uOffset, 457 int fWrite, int fHasIndex, uint32_t idx); 458 void virtioHexDump(uint8_t *pv, uint32_t cb, uint32_t uBase, const char *pszTitle); 440 void virtioCoreLogMappedIoValue(const char *pszFunc, const char *pszMember, uint32_t uMemberSize, 441 const void *pv, uint32_t cb, uint32_t uOffset, 442 int fWrite, int fHasIndex, uint32_t idx); 443 void virtioCoreHexDump(uint8_t *pv, uint32_t cb, uint32_t uBase, const char *pszTitle); 444 445 446 int virtioCoreR3SaveExec(PVIRTIOCORE pVirtio, PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM); 447 int virtioCoreR3LoadExec(PVIRTIOCORE pVirtio, PCPDMDEVHLPR3 pHlp, PSSMHANDLE pSSM); 448 #if 0 /** @todo unused */ 449 void virtioCoreResetAll(PVIRTIOCORE pVirtio); 450 #endif 451 void virtioCoreR3PropagateResetNotification(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio); 452 void virtioCoreR3PropagateResumeNotification(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio); 453 void virtioCoreR3Term(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, PVIRTIOCORECC pVirtioCC); 454 int virtioCoreR3Init(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, PVIRTIOCORECC pVirtioCC, PVIRTIOPCIPARAMS pPciParams, 455 const char *pcszInstance, uint64_t fDevSpecificFeatures, void *pvDevSpecificCfg, uint16_t cbDevSpecificCfg); 456 int virtioCoreRZInit(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, PVIRTIOCORECC pVirtioCC); 459 457 /** @} */ 460 458
Note:
See TracChangeset
for help on using the changeset viewer.