Changeset 100371 in vbox for trunk/src/VBox/Devices/VirtIO
- Timestamp:
- Jul 5, 2023 7:47:33 AM (22 months ago)
- svn:sync-xref-src-repo-rev:
- 158108
- Location:
- trunk/src/VBox/Devices/VirtIO
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/VirtIO/VirtioCore.cpp
r99775 r100371 635 635 uint16_t uUsedIdxShadow = pVirtq->uUsedIdxShadow; 636 636 637 #ifdef VIRTIO_VBUF_ON_STACK638 637 VIRTQBUF_T VirtqBuf; 639 638 PVIRTQBUF pVirtqBuf = &VirtqBuf; 640 #else /* !VIRTIO_VBUF_ON_STACK */641 PVIRTQBUF pVirtqBuf = NULL;642 #endif /* !VIRTIO_VBUF_ON_STACK */643 644 639 bool fEmpty = IS_VIRTQ_EMPTY(pDevIns, pVirtio, pVirtq); 645 640 … … 649 644 if (!fEmpty) 650 645 { 651 #ifdef VIRTIO_VBUF_ON_STACK652 646 virtioCoreR3VirtqAvailBufPeek(pDevIns, pVirtio, uVirtq, pVirtqBuf); 653 #else /* !VIRTIO_VBUF_ON_STACK */654 virtioCoreR3VirtqAvailBufPeek(pDevIns, pVirtio, uVirtq, &pVirtqBuf);655 #endif /* !VIRTIO_VBUF_ON_STACK */656 647 cSendSegs = pVirtqBuf->pSgPhysSend ? pVirtqBuf->pSgPhysSend->cSegs : 0; 657 648 cReturnSegs = pVirtqBuf->pSgPhysReturn ? pVirtqBuf->pSgPhysReturn->cSegs : 0; … … 704 695 } 705 696 706 #ifdef VIRTIO_VBUF_ON_STACK 697 707 698 /** API Function: See header file */ 708 699 PVIRTQBUF virtioCoreR3VirtqBufAlloc(void) … … 714 705 return pVirtqBuf; 715 706 } 716 #endif /* VIRTIO_VBUF_ON_STACK */ 707 717 708 718 709 /** API Function: See header file */ … … 788 779 789 780 /** API function: See Header file */ 790 #ifdef VIRTIO_VBUF_ON_STACK791 781 int virtioCoreR3VirtqAvailBufPeek(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtq, PVIRTQBUF pVirtqBuf) 792 782 { 793 783 return virtioCoreR3VirtqAvailBufGet(pDevIns, pVirtio, uVirtq, pVirtqBuf, false); 794 784 } 795 #else /* !VIRTIO_VBUF_ON_STACK */ 796 int virtioCoreR3VirtqAvailBufPeek(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtq, 797 PPVIRTQBUF ppVirtqBuf) 798 { 799 return virtioCoreR3VirtqAvailBufGet(pDevIns, pVirtio, uVirtq, ppVirtqBuf, false); 800 } 801 #endif /* !VIRTIO_VBUF_ON_STACK */ 785 802 786 803 787 /** API function: See Header file */ … … 821 805 822 806 /** API Function: See header file */ 823 #ifdef VIRTIO_VBUF_ON_STACK824 807 int virtioCoreR3VirtqAvailBufGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtq, 825 808 uint16_t uHeadIdx, PVIRTQBUF pVirtqBuf) 826 #else /* !VIRTIO_VBUF_ON_STACK */ 827 int virtioCoreR3VirtqAvailBufGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtq, 828 uint16_t uHeadIdx, PPVIRTQBUF ppVirtqBuf) 829 #endif /* !VIRTIO_VBUF_ON_STACK */ 830 { 831 #ifndef VIRTIO_VBUF_ON_STACK 832 AssertReturn(ppVirtqBuf, VERR_INVALID_POINTER); 833 *ppVirtqBuf = NULL; 834 #endif /* !VIRTIO_VBUF_ON_STACK */ 835 809 { 836 810 AssertMsgReturn(uVirtq < RT_ELEMENTS(pVirtio->aVirtqueues), 837 811 ("uVirtq out of range"), VERR_INVALID_PARAMETER); … … 850 824 * Allocate and initialize the descriptor chain structure. 851 825 */ 852 #ifndef VIRTIO_VBUF_ON_STACK853 PVIRTQBUF pVirtqBuf = (PVIRTQBUF)RTMemAllocZ(sizeof(VIRTQBUF_T));854 AssertReturn(pVirtqBuf, VERR_NO_MEMORY);855 #endif /* !VIRTIO_VBUF_ON_STACK */856 826 pVirtqBuf->u32Magic = VIRTQBUF_MAGIC; 857 827 pVirtqBuf->cRefs = 1; 858 828 pVirtqBuf->uHeadIdx = uHeadIdx; 859 829 pVirtqBuf->uVirtq = uVirtq; 860 #ifndef VIRTIO_VBUF_ON_STACK861 *ppVirtqBuf = pVirtqBuf;862 #endif /* !VIRTIO_VBUF_ON_STACK */863 830 864 831 /* … … 958 925 959 926 /** API function: See Header file */ 960 #ifdef VIRTIO_VBUF_ON_STACK961 927 int virtioCoreR3VirtqAvailBufGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtq, 962 928 PVIRTQBUF pVirtqBuf, bool fRemove) 963 #else /* !VIRTIO_VBUF_ON_STACK */964 int virtioCoreR3VirtqAvailBufGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtq,965 PPVIRTQBUF ppVirtqBuf, bool fRemove)966 #endif /* !VIRTIO_VBUF_ON_STACK */967 929 { 968 930 Assert(uVirtq < RT_ELEMENTS(pVirtio->aVirtqueues)); … … 980 942 pVirtq->uAvailIdxShadow++; 981 943 982 #ifdef VIRTIO_VBUF_ON_STACK 983 int rc = virtioCoreR3VirtqAvailBufGet(pDevIns, pVirtio, uVirtq, uHeadIdx, pVirtqBuf); 984 #else /* !VIRTIO_VBUF_ON_STACK */ 985 int rc = virtioCoreR3VirtqAvailBufGet(pDevIns, pVirtio, uVirtq, uHeadIdx, ppVirtqBuf); 986 #endif /* !VIRTIO_VBUF_ON_STACK */ 987 return rc; 944 return virtioCoreR3VirtqAvailBufGet(pDevIns, pVirtio, uVirtq, uHeadIdx, pVirtqBuf); 988 945 } 989 946 -
trunk/src/VBox/Devices/VirtIO/VirtioCore.h
r99739 r100371 32 32 # pragma once 33 33 #endif 34 35 /* Do not allocate VIRTQBUF from the heap when possible */36 #define VIRTIO_VBUF_ON_STACK 137 34 38 35 #include <iprt/ctype.h> … … 698 695 uint16_t virtioCoreVirtqAvailBufCount(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtqNbr); 699 696 700 #ifdef VIRTIO_VBUF_ON_STACK701 697 /** 702 698 * This function is identical to virtioCoreR3VirtqAvailBufGet(), *except* it doesn't consume … … 767 763 int virtioCoreR3VirtqAvailBufGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtqNbr, 768 764 uint16_t uHeadIdx, PVIRTQBUF pVirtqBuf); 769 #else /* !VIRTIO_VBUF_ON_STACK */770 /**771 * This function is identical to virtioCoreR3VirtqAvailBufGet(), *except* it doesn't consume772 * peeked buffer from avail ring of the virtq. The function *becomes* identical to the773 * virtioCoreR3VirtqAvailBufGet() only if virtioCoreR3VirtqAvailRingNext() is invoked to774 * consume buf from the queue's avail ring, followed by invocation of virtioCoreR3VirtqUsedBufPut(),775 * to hand host-processed buffer back to guest, which completes guest-initiated virtq buffer circuit.776 *777 * @param pDevIns The device instance.778 * @param pVirtio Pointer to the shared virtio state.779 * @param uVirtqNbr Virtq number780 * @param ppVirtqBuf Address to store pointer to descriptor chain that contains the781 * pre-processed transaction information pulled from the virtq.782 *783 * @returns VBox status code:784 * @retval VINF_SUCCESS Success785 * @retval VERR_INVALID_STATE VirtIO not in ready state (asserted).786 * @retval VERR_NOT_AVAILABLE If the queue is empty.787 */788 int virtioCoreR3VirtqAvailBufPeek(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtqNbr,789 PPVIRTQBUF ppVirtqBuf);790 791 /**792 * This function fetches the next buffer (descriptor chain) from the VirtIO "avail" ring of793 * indicated queue, separating the buf's s/g vectors into OUT (e.g. guest-to-host)794 * components and and IN (host-to-guest) components.795 *796 * Caller is responsible for GCPhys to host virtual memory conversions. If the797 * virtq buffer being peeked at is "consumed", virtioCoreR3VirtqAvailRingNext() must798 * be called, and after that virtioCoreR3VirtqUsedBufPut() must be called to799 * complete the buffer transfer cycle with the guest.800 *801 * @param pDevIns The device instance.802 * @param pVirtio Pointer to the shared virtio state.803 * @param uVirtqNbr Virtq number804 * @param ppVirtqBuf Address to store pointer to descriptor chain that contains the805 * pre-processed transaction information pulled from the virtq.806 * Returned reference must be released by calling807 * virtioCoreR3VirtqBufRelease().808 * @param fRemove flags whether to remove desc chain from queue (false = peek)809 *810 * @returns VBox status code:811 * @retval VINF_SUCCESS Success812 * @retval VERR_INVALID_STATE VirtIO not in ready state (asserted).813 * @retval VERR_NOT_AVAILABLE If the queue is empty.814 */815 int virtioCoreR3VirtqAvailBufGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtqNbr,816 PPVIRTQBUF ppVirtqBuf, bool fRemove);817 818 /**819 * Fetches a specific descriptor chain using avail ring of indicated queue and converts the820 * descriptor chain into its OUT (to device) and IN (to guest) components.821 *822 * The caller is responsible for GCPhys to host virtual memory conversions and *must*823 * return the virtq buffer using virtioCoreR3VirtqUsedBufPut() to complete the roundtrip824 * virtq transaction.825 * *826 * @param pDevIns The device instance.827 * @param pVirtio Pointer to the shared virtio state.828 * @param uVirtqNbr Virtq number829 * @param ppVirtqBuf Address to store pointer to descriptor chain that contains the830 * pre-processed transaction information pulled from the virtq.831 * Returned reference must be released by calling832 * virtioCoreR3VirtqBufRelease().833 * @param fRemove flags whether to remove desc chain from queue (false = peek)834 *835 * @returns VBox status code:836 * @retval VINF_SUCCESS Success837 * @retval VERR_INVALID_STATE VirtIO not in ready state (asserted).838 * @retval VERR_NOT_AVAILABLE If the queue is empty.839 */840 int virtioCoreR3VirtqAvailBufGet(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtqNbr,841 uint16_t uHeadIdx, PPVIRTQBUF ppVirtqBuf);842 #endif /* !VIRTIO_VBUF_ON_STACK */843 765 844 766 /** … … 1185 1107 int virtioCoreVirtqUsedRingSync(PPDMDEVINS pDevIns, PVIRTIOCORE pVirtio, uint16_t uVirtqNbr); 1186 1108 1187 #ifdef VIRTIO_VBUF_ON_STACK1188 1109 /** 1189 1110 * Allocates a descriptor chain object with the reference count of one. Copying the reference … … 1200 1121 */ 1201 1122 PVIRTQBUF virtioCoreR3VirtqBufAlloc(void); 1202 #endif /* VIRTIO_VBUF_ON_STACK */1203 1123 1204 1124 /**
Note:
See TracChangeset
for help on using the changeset viewer.