4 * Copyright IBM, Corp. 2007
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
19 /* The alignment to use between consumer and producer parts of vring.
20 * x86 pagesize again. */
21 #define VIRTIO_PCI_VRING_ALIGN 4096
23 /* QEMU doesn't strictly need write barriers since everything runs in
24 * lock-step. We'll leave the calls to wmb() in though to make it obvious for
25 * KVM or if kqemu gets SMP support.
26 * In any case, we must prevent the compiler from reordering the code.
27 * TODO: we likely need some rmb()/mb() as well.
30 #define wmb() __asm__ __volatile__("": : :"memory")
32 typedef struct VRingDesc
40 typedef struct VRingAvail
47 typedef struct VRingUsedElem
53 typedef struct VRingUsed
57 VRingUsedElem ring
[0];
63 target_phys_addr_t desc
;
64 target_phys_addr_t avail
;
65 target_phys_addr_t used
;
71 target_phys_addr_t pa
;
72 uint16_t last_avail_idx
;
75 void (*handle_output
)(VirtIODevice
*vdev
, VirtQueue
*vq
);
77 EventNotifier guest_notifier
;
78 EventNotifier host_notifier
;
81 /* virt queue functions */
82 static void virtqueue_init(VirtQueue
*vq
)
84 target_phys_addr_t pa
= vq
->pa
;
87 vq
->vring
.avail
= pa
+ vq
->vring
.num
* sizeof(VRingDesc
);
88 vq
->vring
.used
= vring_align(vq
->vring
.avail
+
89 offsetof(VRingAvail
, ring
[vq
->vring
.num
]),
90 VIRTIO_PCI_VRING_ALIGN
);
93 static inline uint64_t vring_desc_addr(target_phys_addr_t desc_pa
, int i
)
95 target_phys_addr_t pa
;
96 pa
= desc_pa
+ sizeof(VRingDesc
) * i
+ offsetof(VRingDesc
, addr
);
100 static inline uint32_t vring_desc_len(target_phys_addr_t desc_pa
, int i
)
102 target_phys_addr_t pa
;
103 pa
= desc_pa
+ sizeof(VRingDesc
) * i
+ offsetof(VRingDesc
, len
);
107 static inline uint16_t vring_desc_flags(target_phys_addr_t desc_pa
, int i
)
109 target_phys_addr_t pa
;
110 pa
= desc_pa
+ sizeof(VRingDesc
) * i
+ offsetof(VRingDesc
, flags
);
111 return lduw_phys(pa
);
114 static inline uint16_t vring_desc_next(target_phys_addr_t desc_pa
, int i
)
116 target_phys_addr_t pa
;
117 pa
= desc_pa
+ sizeof(VRingDesc
) * i
+ offsetof(VRingDesc
, next
);
118 return lduw_phys(pa
);
121 static inline uint16_t vring_avail_flags(VirtQueue
*vq
)
123 target_phys_addr_t pa
;
124 pa
= vq
->vring
.avail
+ offsetof(VRingAvail
, flags
);
125 return lduw_phys(pa
);
128 static inline uint16_t vring_avail_idx(VirtQueue
*vq
)
130 target_phys_addr_t pa
;
131 pa
= vq
->vring
.avail
+ offsetof(VRingAvail
, idx
);
132 return lduw_phys(pa
);
135 static inline uint16_t vring_avail_ring(VirtQueue
*vq
, int i
)
137 target_phys_addr_t pa
;
138 pa
= vq
->vring
.avail
+ offsetof(VRingAvail
, ring
[i
]);
139 return lduw_phys(pa
);
142 static inline void vring_used_ring_id(VirtQueue
*vq
, int i
, uint32_t val
)
144 target_phys_addr_t pa
;
145 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, ring
[i
].id
);
149 static inline void vring_used_ring_len(VirtQueue
*vq
, int i
, uint32_t val
)
151 target_phys_addr_t pa
;
152 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, ring
[i
].len
);
156 static uint16_t vring_used_idx(VirtQueue
*vq
)
158 target_phys_addr_t pa
;
159 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, idx
);
160 return lduw_phys(pa
);
163 static inline void vring_used_idx_increment(VirtQueue
*vq
, uint16_t val
)
165 target_phys_addr_t pa
;
167 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, idx
);
169 stw_phys(pa
, vring_used_idx(vq
) + val
);
172 static inline void vring_used_flags_set_bit(VirtQueue
*vq
, int mask
)
174 target_phys_addr_t pa
;
175 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, flags
);
176 stw_phys(pa
, lduw_phys(pa
) | mask
);
179 static inline void vring_used_flags_unset_bit(VirtQueue
*vq
, int mask
)
181 target_phys_addr_t pa
;
182 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, flags
);
183 stw_phys(pa
, lduw_phys(pa
) & ~mask
);
186 void virtio_queue_set_notification(VirtQueue
*vq
, int enable
)
189 vring_used_flags_unset_bit(vq
, VRING_USED_F_NO_NOTIFY
);
191 vring_used_flags_set_bit(vq
, VRING_USED_F_NO_NOTIFY
);
194 int virtio_queue_ready(VirtQueue
*vq
)
196 return vq
->vring
.avail
!= 0;
199 int virtio_queue_empty(VirtQueue
*vq
)
201 return vring_avail_idx(vq
) == vq
->last_avail_idx
;
204 void virtqueue_fill(VirtQueue
*vq
, const VirtQueueElement
*elem
,
205 unsigned int len
, unsigned int idx
)
211 for (i
= 0; i
< elem
->in_num
; i
++) {
212 size_t size
= MIN(len
- offset
, elem
->in_sg
[i
].iov_len
);
214 cpu_physical_memory_unmap(elem
->in_sg
[i
].iov_base
,
215 elem
->in_sg
[i
].iov_len
,
218 offset
+= elem
->in_sg
[i
].iov_len
;
221 for (i
= 0; i
< elem
->out_num
; i
++)
222 cpu_physical_memory_unmap(elem
->out_sg
[i
].iov_base
,
223 elem
->out_sg
[i
].iov_len
,
224 0, elem
->out_sg
[i
].iov_len
);
226 idx
= (idx
+ vring_used_idx(vq
)) % vq
->vring
.num
;
228 /* Get a pointer to the next entry in the used ring. */
229 vring_used_ring_id(vq
, idx
, elem
->index
);
230 vring_used_ring_len(vq
, idx
, len
);
233 void virtqueue_flush(VirtQueue
*vq
, unsigned int count
)
235 /* Make sure buffer is written before we update index. */
237 vring_used_idx_increment(vq
, count
);
241 void virtqueue_push(VirtQueue
*vq
, const VirtQueueElement
*elem
,
244 virtqueue_fill(vq
, elem
, len
, 0);
245 virtqueue_flush(vq
, 1);
248 static int virtqueue_num_heads(VirtQueue
*vq
, unsigned int idx
)
250 uint16_t num_heads
= vring_avail_idx(vq
) - idx
;
252 /* Check it isn't doing very strange things with descriptor numbers. */
253 if (num_heads
> vq
->vring
.num
) {
254 fprintf(stderr
, "Guest moved used index from %u to %u",
255 idx
, vring_avail_idx(vq
));
262 static unsigned int virtqueue_get_head(VirtQueue
*vq
, unsigned int idx
)
266 /* Grab the next descriptor number they're advertising, and increment
267 * the index we've seen. */
268 head
= vring_avail_ring(vq
, idx
% vq
->vring
.num
);
270 /* If their number is silly, that's a fatal mistake. */
271 if (head
>= vq
->vring
.num
) {
272 fprintf(stderr
, "Guest says index %u is available", head
);
279 static unsigned virtqueue_next_desc(target_phys_addr_t desc_pa
,
280 unsigned int i
, unsigned int max
)
284 /* If this descriptor says it doesn't chain, we're done. */
285 if (!(vring_desc_flags(desc_pa
, i
) & VRING_DESC_F_NEXT
))
288 /* Check they're not leading us off end of descriptors. */
289 next
= vring_desc_next(desc_pa
, i
);
290 /* Make sure compiler knows to grab that: we don't want it changing! */
294 fprintf(stderr
, "Desc next is %u", next
);
301 int virtqueue_avail_bytes(VirtQueue
*vq
, int in_bytes
, int out_bytes
)
304 int total_bufs
, in_total
, out_total
;
306 idx
= vq
->last_avail_idx
;
308 total_bufs
= in_total
= out_total
= 0;
309 while (virtqueue_num_heads(vq
, idx
)) {
310 unsigned int max
, num_bufs
, indirect
= 0;
311 target_phys_addr_t desc_pa
;
315 num_bufs
= total_bufs
;
316 i
= virtqueue_get_head(vq
, idx
++);
317 desc_pa
= vq
->vring
.desc
;
319 if (vring_desc_flags(desc_pa
, i
) & VRING_DESC_F_INDIRECT
) {
320 if (vring_desc_len(desc_pa
, i
) % sizeof(VRingDesc
)) {
321 fprintf(stderr
, "Invalid size for indirect buffer table\n");
325 /* If we've got too many, that implies a descriptor loop. */
326 if (num_bufs
>= max
) {
327 fprintf(stderr
, "Looped descriptor");
331 /* loop over the indirect descriptor table */
333 max
= vring_desc_len(desc_pa
, i
) / sizeof(VRingDesc
);
335 desc_pa
= vring_desc_addr(desc_pa
, i
);
339 /* If we've got too many, that implies a descriptor loop. */
340 if (++num_bufs
> max
) {
341 fprintf(stderr
, "Looped descriptor");
345 if (vring_desc_flags(desc_pa
, i
) & VRING_DESC_F_WRITE
) {
347 (in_total
+= vring_desc_len(desc_pa
, i
)) >= in_bytes
)
351 (out_total
+= vring_desc_len(desc_pa
, i
)) >= out_bytes
)
354 } while ((i
= virtqueue_next_desc(desc_pa
, i
, max
)) != max
);
357 total_bufs
= num_bufs
;
365 void virtqueue_map_sg(struct iovec
*sg
, target_phys_addr_t
*addr
,
366 size_t num_sg
, int is_write
)
369 target_phys_addr_t len
;
371 for (i
= 0; i
< num_sg
; i
++) {
373 sg
[i
].iov_base
= cpu_physical_memory_map(addr
[i
], &len
, is_write
);
374 if (sg
[i
].iov_base
== NULL
|| len
!= sg
[i
].iov_len
) {
375 fprintf(stderr
, "virtio: trying to map MMIO memory\n");
381 int virtqueue_pop(VirtQueue
*vq
, VirtQueueElement
*elem
)
383 unsigned int i
, head
, max
;
384 target_phys_addr_t desc_pa
= vq
->vring
.desc
;
386 if (!virtqueue_num_heads(vq
, vq
->last_avail_idx
))
389 /* When we start there are none of either input nor output. */
390 elem
->out_num
= elem
->in_num
= 0;
394 i
= head
= virtqueue_get_head(vq
, vq
->last_avail_idx
++);
396 if (vring_desc_flags(desc_pa
, i
) & VRING_DESC_F_INDIRECT
) {
397 if (vring_desc_len(desc_pa
, i
) % sizeof(VRingDesc
)) {
398 fprintf(stderr
, "Invalid size for indirect buffer table\n");
402 /* loop over the indirect descriptor table */
403 max
= vring_desc_len(desc_pa
, i
) / sizeof(VRingDesc
);
404 desc_pa
= vring_desc_addr(desc_pa
, i
);
408 /* Collect all the descriptors */
412 if (vring_desc_flags(desc_pa
, i
) & VRING_DESC_F_WRITE
) {
413 elem
->in_addr
[elem
->in_num
] = vring_desc_addr(desc_pa
, i
);
414 sg
= &elem
->in_sg
[elem
->in_num
++];
416 elem
->out_addr
[elem
->out_num
] = vring_desc_addr(desc_pa
, i
);
417 sg
= &elem
->out_sg
[elem
->out_num
++];
420 sg
->iov_len
= vring_desc_len(desc_pa
, i
);
422 /* If we've got too many, that implies a descriptor loop. */
423 if ((elem
->in_num
+ elem
->out_num
) > max
) {
424 fprintf(stderr
, "Looped descriptor");
427 } while ((i
= virtqueue_next_desc(desc_pa
, i
, max
)) != max
);
429 /* Now map what we have collected */
430 virtqueue_map_sg(elem
->in_sg
, elem
->in_addr
, elem
->in_num
, 1);
431 virtqueue_map_sg(elem
->out_sg
, elem
->out_addr
, elem
->out_num
, 0);
437 return elem
->in_num
+ elem
->out_num
;
441 static void virtio_notify_vector(VirtIODevice
*vdev
, uint16_t vector
)
443 if (vdev
->binding
->notify
) {
444 vdev
->binding
->notify(vdev
->binding_opaque
, vector
);
448 void virtio_update_irq(VirtIODevice
*vdev
)
450 virtio_notify_vector(vdev
, VIRTIO_NO_VECTOR
);
453 void virtio_reset(void *opaque
)
455 VirtIODevice
*vdev
= opaque
;
458 virtio_set_status(vdev
, 0);
463 vdev
->guest_features
= 0;
467 vdev
->config_vector
= VIRTIO_NO_VECTOR
;
468 virtio_notify_vector(vdev
, vdev
->config_vector
);
470 for(i
= 0; i
< VIRTIO_PCI_QUEUE_MAX
; i
++) {
471 vdev
->vq
[i
].vring
.desc
= 0;
472 vdev
->vq
[i
].vring
.avail
= 0;
473 vdev
->vq
[i
].vring
.used
= 0;
474 vdev
->vq
[i
].last_avail_idx
= 0;
476 vdev
->vq
[i
].vector
= VIRTIO_NO_VECTOR
;
480 uint32_t virtio_config_readb(VirtIODevice
*vdev
, uint32_t addr
)
484 vdev
->get_config(vdev
, vdev
->config
);
486 if (addr
> (vdev
->config_len
- sizeof(val
)))
489 memcpy(&val
, vdev
->config
+ addr
, sizeof(val
));
493 uint32_t virtio_config_readw(VirtIODevice
*vdev
, uint32_t addr
)
497 vdev
->get_config(vdev
, vdev
->config
);
499 if (addr
> (vdev
->config_len
- sizeof(val
)))
502 memcpy(&val
, vdev
->config
+ addr
, sizeof(val
));
506 uint32_t virtio_config_readl(VirtIODevice
*vdev
, uint32_t addr
)
510 vdev
->get_config(vdev
, vdev
->config
);
512 if (addr
> (vdev
->config_len
- sizeof(val
)))
515 memcpy(&val
, vdev
->config
+ addr
, sizeof(val
));
519 void virtio_config_writeb(VirtIODevice
*vdev
, uint32_t addr
, uint32_t data
)
523 if (addr
> (vdev
->config_len
- sizeof(val
)))
526 memcpy(vdev
->config
+ addr
, &val
, sizeof(val
));
528 if (vdev
->set_config
)
529 vdev
->set_config(vdev
, vdev
->config
);
532 void virtio_config_writew(VirtIODevice
*vdev
, uint32_t addr
, uint32_t data
)
536 if (addr
> (vdev
->config_len
- sizeof(val
)))
539 memcpy(vdev
->config
+ addr
, &val
, sizeof(val
));
541 if (vdev
->set_config
)
542 vdev
->set_config(vdev
, vdev
->config
);
545 void virtio_config_writel(VirtIODevice
*vdev
, uint32_t addr
, uint32_t data
)
549 if (addr
> (vdev
->config_len
- sizeof(val
)))
552 memcpy(vdev
->config
+ addr
, &val
, sizeof(val
));
554 if (vdev
->set_config
)
555 vdev
->set_config(vdev
, vdev
->config
);
558 void virtio_queue_set_addr(VirtIODevice
*vdev
, int n
, target_phys_addr_t addr
)
560 vdev
->vq
[n
].pa
= addr
;
561 virtqueue_init(&vdev
->vq
[n
]);
564 target_phys_addr_t
virtio_queue_get_addr(VirtIODevice
*vdev
, int n
)
566 return vdev
->vq
[n
].pa
;
569 int virtio_queue_get_num(VirtIODevice
*vdev
, int n
)
571 return vdev
->vq
[n
].vring
.num
;
574 void virtio_queue_notify(VirtIODevice
*vdev
, int n
)
576 if (n
< VIRTIO_PCI_QUEUE_MAX
&& vdev
->vq
[n
].vring
.desc
) {
577 vdev
->vq
[n
].handle_output(vdev
, &vdev
->vq
[n
]);
581 uint16_t virtio_queue_vector(VirtIODevice
*vdev
, int n
)
583 return n
< VIRTIO_PCI_QUEUE_MAX
? vdev
->vq
[n
].vector
:
587 void virtio_queue_set_vector(VirtIODevice
*vdev
, int n
, uint16_t vector
)
589 if (n
< VIRTIO_PCI_QUEUE_MAX
)
590 vdev
->vq
[n
].vector
= vector
;
593 VirtQueue
*virtio_add_queue(VirtIODevice
*vdev
, int queue_size
,
594 void (*handle_output
)(VirtIODevice
*, VirtQueue
*))
598 for (i
= 0; i
< VIRTIO_PCI_QUEUE_MAX
; i
++) {
599 if (vdev
->vq
[i
].vring
.num
== 0)
603 if (i
== VIRTIO_PCI_QUEUE_MAX
|| queue_size
> VIRTQUEUE_MAX_SIZE
)
606 vdev
->vq
[i
].vring
.num
= queue_size
;
607 vdev
->vq
[i
].handle_output
= handle_output
;
612 void virtio_irq(VirtQueue
*vq
)
614 vq
->vdev
->isr
|= 0x01;
615 virtio_notify_vector(vq
->vdev
, vq
->vector
);
618 void virtio_notify(VirtIODevice
*vdev
, VirtQueue
*vq
)
620 /* Always notify when queue is empty (when feature acknowledge) */
621 if ((vring_avail_flags(vq
) & VRING_AVAIL_F_NO_INTERRUPT
) &&
622 (!(vdev
->guest_features
& (1 << VIRTIO_F_NOTIFY_ON_EMPTY
)) ||
623 (vq
->inuse
|| vring_avail_idx(vq
) != vq
->last_avail_idx
)))
627 virtio_notify_vector(vdev
, vq
->vector
);
630 void virtio_notify_config(VirtIODevice
*vdev
)
632 if (!(vdev
->status
& VIRTIO_CONFIG_S_DRIVER_OK
))
636 virtio_notify_vector(vdev
, vdev
->config_vector
);
639 void virtio_save(VirtIODevice
*vdev
, QEMUFile
*f
)
643 if (vdev
->binding
->save_config
)
644 vdev
->binding
->save_config(vdev
->binding_opaque
, f
);
646 qemu_put_8s(f
, &vdev
->status
);
647 qemu_put_8s(f
, &vdev
->isr
);
648 qemu_put_be16s(f
, &vdev
->queue_sel
);
649 qemu_put_be32s(f
, &vdev
->guest_features
);
650 qemu_put_be32(f
, vdev
->config_len
);
651 qemu_put_buffer(f
, vdev
->config
, vdev
->config_len
);
653 for (i
= 0; i
< VIRTIO_PCI_QUEUE_MAX
; i
++) {
654 if (vdev
->vq
[i
].vring
.num
== 0)
660 for (i
= 0; i
< VIRTIO_PCI_QUEUE_MAX
; i
++) {
661 if (vdev
->vq
[i
].vring
.num
== 0)
664 qemu_put_be32(f
, vdev
->vq
[i
].vring
.num
);
665 qemu_put_be64(f
, vdev
->vq
[i
].pa
);
666 qemu_put_be16s(f
, &vdev
->vq
[i
].last_avail_idx
);
667 if (vdev
->binding
->save_queue
)
668 vdev
->binding
->save_queue(vdev
->binding_opaque
, i
, f
);
672 int virtio_load(VirtIODevice
*vdev
, QEMUFile
*f
)
676 uint32_t supported_features
=
677 vdev
->binding
->get_features(vdev
->binding_opaque
);
679 if (vdev
->binding
->load_config
) {
680 ret
= vdev
->binding
->load_config(vdev
->binding_opaque
, f
);
685 qemu_get_8s(f
, &vdev
->status
);
686 qemu_get_8s(f
, &vdev
->isr
);
687 qemu_get_be16s(f
, &vdev
->queue_sel
);
688 qemu_get_be32s(f
, &features
);
689 if (features
& ~supported_features
) {
690 fprintf(stderr
, "Features 0x%x unsupported. Allowed features: 0x%x\n",
691 features
, supported_features
);
694 if (vdev
->set_features
)
695 vdev
->set_features(vdev
, features
);
696 vdev
->guest_features
= features
;
697 vdev
->config_len
= qemu_get_be32(f
);
698 qemu_get_buffer(f
, vdev
->config
, vdev
->config_len
);
700 num
= qemu_get_be32(f
);
702 for (i
= 0; i
< num
; i
++) {
703 vdev
->vq
[i
].vring
.num
= qemu_get_be32(f
);
704 vdev
->vq
[i
].pa
= qemu_get_be64(f
);
705 qemu_get_be16s(f
, &vdev
->vq
[i
].last_avail_idx
);
707 if (vdev
->vq
[i
].pa
) {
708 virtqueue_init(&vdev
->vq
[i
]);
710 if (vdev
->binding
->load_queue
) {
711 ret
= vdev
->binding
->load_queue(vdev
->binding_opaque
, i
, f
);
717 virtio_notify_vector(vdev
, VIRTIO_NO_VECTOR
);
721 void virtio_cleanup(VirtIODevice
*vdev
)
724 qemu_free(vdev
->config
);
728 VirtIODevice
*virtio_common_init(const char *name
, uint16_t device_id
,
729 size_t config_size
, size_t struct_size
)
734 vdev
= qemu_mallocz(struct_size
);
736 vdev
->device_id
= device_id
;
740 vdev
->config_vector
= VIRTIO_NO_VECTOR
;
741 vdev
->vq
= qemu_mallocz(sizeof(VirtQueue
) * VIRTIO_PCI_QUEUE_MAX
);
742 for(i
= 0; i
< VIRTIO_PCI_QUEUE_MAX
; i
++) {
743 vdev
->vq
[i
].vector
= VIRTIO_NO_VECTOR
;
744 vdev
->vq
[i
].vdev
= vdev
;
748 vdev
->config_len
= config_size
;
749 if (vdev
->config_len
)
750 vdev
->config
= qemu_mallocz(config_size
);
757 void virtio_bind_device(VirtIODevice
*vdev
, const VirtIOBindings
*binding
,
760 vdev
->binding
= binding
;
761 vdev
->binding_opaque
= opaque
;
764 target_phys_addr_t
virtio_queue_get_desc_addr(VirtIODevice
*vdev
, int n
)
766 return vdev
->vq
[n
].vring
.desc
;
769 target_phys_addr_t
virtio_queue_get_avail_addr(VirtIODevice
*vdev
, int n
)
771 return vdev
->vq
[n
].vring
.avail
;
774 target_phys_addr_t
virtio_queue_get_used_addr(VirtIODevice
*vdev
, int n
)
776 return vdev
->vq
[n
].vring
.used
;
779 target_phys_addr_t
virtio_queue_get_ring_addr(VirtIODevice
*vdev
, int n
)
781 return vdev
->vq
[n
].vring
.desc
;
784 target_phys_addr_t
virtio_queue_get_desc_size(VirtIODevice
*vdev
, int n
)
786 return sizeof(VRingDesc
) * vdev
->vq
[n
].vring
.num
;
789 target_phys_addr_t
virtio_queue_get_avail_size(VirtIODevice
*vdev
, int n
)
791 return offsetof(VRingAvail
, ring
) +
792 sizeof(uint64_t) * vdev
->vq
[n
].vring
.num
;
795 target_phys_addr_t
virtio_queue_get_used_size(VirtIODevice
*vdev
, int n
)
797 return offsetof(VRingUsed
, ring
) +
798 sizeof(VRingUsedElem
) * vdev
->vq
[n
].vring
.num
;
801 target_phys_addr_t
virtio_queue_get_ring_size(VirtIODevice
*vdev
, int n
)
803 return vdev
->vq
[n
].vring
.used
- vdev
->vq
[n
].vring
.desc
+
804 virtio_queue_get_used_size(vdev
, n
);
807 uint16_t virtio_queue_get_last_avail_idx(VirtIODevice
*vdev
, int n
)
809 return vdev
->vq
[n
].last_avail_idx
;
812 void virtio_queue_set_last_avail_idx(VirtIODevice
*vdev
, int n
, uint16_t idx
)
814 vdev
->vq
[n
].last_avail_idx
= idx
;
817 VirtQueue
*virtio_get_queue(VirtIODevice
*vdev
, int n
)
822 EventNotifier
*virtio_queue_get_guest_notifier(VirtQueue
*vq
)
824 return &vq
->guest_notifier
;
826 EventNotifier
*virtio_queue_get_host_notifier(VirtQueue
*vq
)
828 return &vq
->host_notifier
;