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.
17 #include "exec/address-spaces.h"
18 #include "qemu/error-report.h"
19 #include "hw/virtio/virtio.h"
20 #include "qemu/atomic.h"
21 #include "hw/virtio/virtio-bus.h"
22 #include "migration/migration.h"
23 #include "hw/virtio/virtio-access.h"
26 * The alignment to use between consumer and producer parts of vring.
27 * x86 pagesize again. This is the default, used by transports like PCI
28 * which don't provide a means for the guest to tell the host the alignment.
30 #define VIRTIO_PCI_VRING_ALIGN 4096
32 typedef struct VRingDesc
40 typedef struct VRingAvail
47 typedef struct VRingUsedElem
53 typedef struct VRingUsed
57 VRingUsedElem ring
[0];
72 uint16_t last_avail_idx
;
73 /* Last used index value we have signalled on */
74 uint16_t signalled_used
;
76 /* Last used index value we have signalled on */
77 bool signalled_used_valid
;
79 /* Notification enabled? */
87 void (*handle_output
)(VirtIODevice
*vdev
, VirtQueue
*vq
);
89 EventNotifier guest_notifier
;
90 EventNotifier host_notifier
;
91 QLIST_ENTRY(VirtQueue
) node
;
94 /* virt queue functions */
95 void virtio_queue_update_rings(VirtIODevice
*vdev
, int n
)
97 VRing
*vring
= &vdev
->vq
[n
].vring
;
100 /* not yet setup -> nothing to do */
103 vring
->avail
= vring
->desc
+ vring
->num
* sizeof(VRingDesc
);
104 vring
->used
= vring_align(vring
->avail
+
105 offsetof(VRingAvail
, ring
[vring
->num
]),
109 static inline uint64_t vring_desc_addr(VirtIODevice
*vdev
, hwaddr desc_pa
,
113 pa
= desc_pa
+ sizeof(VRingDesc
) * i
+ offsetof(VRingDesc
, addr
);
114 return virtio_ldq_phys(vdev
, pa
);
117 static inline uint32_t vring_desc_len(VirtIODevice
*vdev
, hwaddr desc_pa
, int i
)
120 pa
= desc_pa
+ sizeof(VRingDesc
) * i
+ offsetof(VRingDesc
, len
);
121 return virtio_ldl_phys(vdev
, pa
);
124 static inline uint16_t vring_desc_flags(VirtIODevice
*vdev
, hwaddr desc_pa
,
128 pa
= desc_pa
+ sizeof(VRingDesc
) * i
+ offsetof(VRingDesc
, flags
);
129 return virtio_lduw_phys(vdev
, pa
);
132 static inline uint16_t vring_desc_next(VirtIODevice
*vdev
, hwaddr desc_pa
,
136 pa
= desc_pa
+ sizeof(VRingDesc
) * i
+ offsetof(VRingDesc
, next
);
137 return virtio_lduw_phys(vdev
, pa
);
140 static inline uint16_t vring_avail_flags(VirtQueue
*vq
)
143 pa
= vq
->vring
.avail
+ offsetof(VRingAvail
, flags
);
144 return virtio_lduw_phys(vq
->vdev
, pa
);
147 static inline uint16_t vring_avail_idx(VirtQueue
*vq
)
150 pa
= vq
->vring
.avail
+ offsetof(VRingAvail
, idx
);
151 return virtio_lduw_phys(vq
->vdev
, pa
);
154 static inline uint16_t vring_avail_ring(VirtQueue
*vq
, int i
)
157 pa
= vq
->vring
.avail
+ offsetof(VRingAvail
, ring
[i
]);
158 return virtio_lduw_phys(vq
->vdev
, pa
);
161 static inline uint16_t vring_get_used_event(VirtQueue
*vq
)
163 return vring_avail_ring(vq
, vq
->vring
.num
);
166 static inline void vring_used_ring_id(VirtQueue
*vq
, int i
, uint32_t val
)
169 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, ring
[i
].id
);
170 virtio_stl_phys(vq
->vdev
, pa
, val
);
173 static inline void vring_used_ring_len(VirtQueue
*vq
, int i
, uint32_t val
)
176 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, ring
[i
].len
);
177 virtio_stl_phys(vq
->vdev
, pa
, val
);
180 static uint16_t vring_used_idx(VirtQueue
*vq
)
183 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, idx
);
184 return virtio_lduw_phys(vq
->vdev
, pa
);
187 static inline void vring_used_idx_set(VirtQueue
*vq
, uint16_t val
)
190 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, idx
);
191 virtio_stw_phys(vq
->vdev
, pa
, val
);
194 static inline void vring_used_flags_set_bit(VirtQueue
*vq
, int mask
)
196 VirtIODevice
*vdev
= vq
->vdev
;
198 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, flags
);
199 virtio_stw_phys(vdev
, pa
, virtio_lduw_phys(vdev
, pa
) | mask
);
202 static inline void vring_used_flags_unset_bit(VirtQueue
*vq
, int mask
)
204 VirtIODevice
*vdev
= vq
->vdev
;
206 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, flags
);
207 virtio_stw_phys(vdev
, pa
, virtio_lduw_phys(vdev
, pa
) & ~mask
);
210 static inline void vring_set_avail_event(VirtQueue
*vq
, uint16_t val
)
213 if (!vq
->notification
) {
216 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, ring
[vq
->vring
.num
]);
217 virtio_stw_phys(vq
->vdev
, pa
, val
);
220 void virtio_queue_set_notification(VirtQueue
*vq
, int enable
)
222 vq
->notification
= enable
;
223 if (virtio_has_feature(vq
->vdev
, VIRTIO_RING_F_EVENT_IDX
)) {
224 vring_set_avail_event(vq
, vring_avail_idx(vq
));
226 vring_used_flags_unset_bit(vq
, VRING_USED_F_NO_NOTIFY
);
228 vring_used_flags_set_bit(vq
, VRING_USED_F_NO_NOTIFY
);
231 /* Expose avail event/used flags before caller checks the avail idx. */
236 int virtio_queue_ready(VirtQueue
*vq
)
238 return vq
->vring
.avail
!= 0;
241 int virtio_queue_empty(VirtQueue
*vq
)
243 return vring_avail_idx(vq
) == vq
->last_avail_idx
;
246 void virtqueue_fill(VirtQueue
*vq
, const VirtQueueElement
*elem
,
247 unsigned int len
, unsigned int idx
)
252 trace_virtqueue_fill(vq
, elem
, len
, idx
);
255 for (i
= 0; i
< elem
->in_num
; i
++) {
256 size_t size
= MIN(len
- offset
, elem
->in_sg
[i
].iov_len
);
258 cpu_physical_memory_unmap(elem
->in_sg
[i
].iov_base
,
259 elem
->in_sg
[i
].iov_len
,
265 for (i
= 0; i
< elem
->out_num
; i
++)
266 cpu_physical_memory_unmap(elem
->out_sg
[i
].iov_base
,
267 elem
->out_sg
[i
].iov_len
,
268 0, elem
->out_sg
[i
].iov_len
);
270 idx
= (idx
+ vring_used_idx(vq
)) % vq
->vring
.num
;
272 /* Get a pointer to the next entry in the used ring. */
273 vring_used_ring_id(vq
, idx
, elem
->index
);
274 vring_used_ring_len(vq
, idx
, len
);
277 void virtqueue_flush(VirtQueue
*vq
, unsigned int count
)
280 /* Make sure buffer is written before we update index. */
282 trace_virtqueue_flush(vq
, count
);
283 old
= vring_used_idx(vq
);
285 vring_used_idx_set(vq
, new);
287 if (unlikely((int16_t)(new - vq
->signalled_used
) < (uint16_t)(new - old
)))
288 vq
->signalled_used_valid
= false;
291 void virtqueue_push(VirtQueue
*vq
, const VirtQueueElement
*elem
,
294 virtqueue_fill(vq
, elem
, len
, 0);
295 virtqueue_flush(vq
, 1);
298 static int virtqueue_num_heads(VirtQueue
*vq
, unsigned int idx
)
300 uint16_t num_heads
= vring_avail_idx(vq
) - idx
;
302 /* Check it isn't doing very strange things with descriptor numbers. */
303 if (num_heads
> vq
->vring
.num
) {
304 error_report("Guest moved used index from %u to %u",
305 idx
, vring_avail_idx(vq
));
308 /* On success, callers read a descriptor at vq->last_avail_idx.
309 * Make sure descriptor read does not bypass avail index read. */
317 static unsigned int virtqueue_get_head(VirtQueue
*vq
, unsigned int idx
)
321 /* Grab the next descriptor number they're advertising, and increment
322 * the index we've seen. */
323 head
= vring_avail_ring(vq
, idx
% vq
->vring
.num
);
325 /* If their number is silly, that's a fatal mistake. */
326 if (head
>= vq
->vring
.num
) {
327 error_report("Guest says index %u is available", head
);
334 static unsigned virtqueue_next_desc(VirtIODevice
*vdev
, hwaddr desc_pa
,
335 unsigned int i
, unsigned int max
)
339 /* If this descriptor says it doesn't chain, we're done. */
340 if (!(vring_desc_flags(vdev
, desc_pa
, i
) & VRING_DESC_F_NEXT
)) {
344 /* Check they're not leading us off end of descriptors. */
345 next
= vring_desc_next(vdev
, desc_pa
, i
);
346 /* Make sure compiler knows to grab that: we don't want it changing! */
350 error_report("Desc next is %u", next
);
357 void virtqueue_get_avail_bytes(VirtQueue
*vq
, unsigned int *in_bytes
,
358 unsigned int *out_bytes
,
359 unsigned max_in_bytes
, unsigned max_out_bytes
)
362 unsigned int total_bufs
, in_total
, out_total
;
364 idx
= vq
->last_avail_idx
;
366 total_bufs
= in_total
= out_total
= 0;
367 while (virtqueue_num_heads(vq
, idx
)) {
368 VirtIODevice
*vdev
= vq
->vdev
;
369 unsigned int max
, num_bufs
, indirect
= 0;
374 num_bufs
= total_bufs
;
375 i
= virtqueue_get_head(vq
, idx
++);
376 desc_pa
= vq
->vring
.desc
;
378 if (vring_desc_flags(vdev
, desc_pa
, i
) & VRING_DESC_F_INDIRECT
) {
379 if (vring_desc_len(vdev
, desc_pa
, i
) % sizeof(VRingDesc
)) {
380 error_report("Invalid size for indirect buffer table");
384 /* If we've got too many, that implies a descriptor loop. */
385 if (num_bufs
>= max
) {
386 error_report("Looped descriptor");
390 /* loop over the indirect descriptor table */
392 max
= vring_desc_len(vdev
, desc_pa
, i
) / sizeof(VRingDesc
);
393 desc_pa
= vring_desc_addr(vdev
, desc_pa
, i
);
398 /* If we've got too many, that implies a descriptor loop. */
399 if (++num_bufs
> max
) {
400 error_report("Looped descriptor");
404 if (vring_desc_flags(vdev
, desc_pa
, i
) & VRING_DESC_F_WRITE
) {
405 in_total
+= vring_desc_len(vdev
, desc_pa
, i
);
407 out_total
+= vring_desc_len(vdev
, desc_pa
, i
);
409 if (in_total
>= max_in_bytes
&& out_total
>= max_out_bytes
) {
412 } while ((i
= virtqueue_next_desc(vdev
, desc_pa
, i
, max
)) != max
);
415 total_bufs
= num_bufs
;
421 *in_bytes
= in_total
;
424 *out_bytes
= out_total
;
428 int virtqueue_avail_bytes(VirtQueue
*vq
, unsigned int in_bytes
,
429 unsigned int out_bytes
)
431 unsigned int in_total
, out_total
;
433 virtqueue_get_avail_bytes(vq
, &in_total
, &out_total
, in_bytes
, out_bytes
);
434 return in_bytes
<= in_total
&& out_bytes
<= out_total
;
437 void virtqueue_map_sg(struct iovec
*sg
, hwaddr
*addr
,
438 size_t num_sg
, int is_write
)
443 if (num_sg
> VIRTQUEUE_MAX_SIZE
) {
444 error_report("virtio: map attempt out of bounds: %zd > %d",
445 num_sg
, VIRTQUEUE_MAX_SIZE
);
449 for (i
= 0; i
< num_sg
; i
++) {
451 sg
[i
].iov_base
= cpu_physical_memory_map(addr
[i
], &len
, is_write
);
452 if (sg
[i
].iov_base
== NULL
|| len
!= sg
[i
].iov_len
) {
453 error_report("virtio: error trying to map MMIO memory");
459 int virtqueue_pop(VirtQueue
*vq
, VirtQueueElement
*elem
)
461 unsigned int i
, head
, max
;
462 hwaddr desc_pa
= vq
->vring
.desc
;
463 VirtIODevice
*vdev
= vq
->vdev
;
465 if (!virtqueue_num_heads(vq
, vq
->last_avail_idx
))
468 /* When we start there are none of either input nor output. */
469 elem
->out_num
= elem
->in_num
= 0;
473 i
= head
= virtqueue_get_head(vq
, vq
->last_avail_idx
++);
474 if (virtio_has_feature(vdev
, VIRTIO_RING_F_EVENT_IDX
)) {
475 vring_set_avail_event(vq
, vq
->last_avail_idx
);
478 if (vring_desc_flags(vdev
, desc_pa
, i
) & VRING_DESC_F_INDIRECT
) {
479 if (vring_desc_len(vdev
, desc_pa
, i
) % sizeof(VRingDesc
)) {
480 error_report("Invalid size for indirect buffer table");
484 /* loop over the indirect descriptor table */
485 max
= vring_desc_len(vdev
, desc_pa
, i
) / sizeof(VRingDesc
);
486 desc_pa
= vring_desc_addr(vdev
, desc_pa
, i
);
490 /* Collect all the descriptors */
494 if (vring_desc_flags(vdev
, desc_pa
, i
) & VRING_DESC_F_WRITE
) {
495 if (elem
->in_num
>= ARRAY_SIZE(elem
->in_sg
)) {
496 error_report("Too many write descriptors in indirect table");
499 elem
->in_addr
[elem
->in_num
] = vring_desc_addr(vdev
, desc_pa
, i
);
500 sg
= &elem
->in_sg
[elem
->in_num
++];
502 if (elem
->out_num
>= ARRAY_SIZE(elem
->out_sg
)) {
503 error_report("Too many read descriptors in indirect table");
506 elem
->out_addr
[elem
->out_num
] = vring_desc_addr(vdev
, desc_pa
, i
);
507 sg
= &elem
->out_sg
[elem
->out_num
++];
510 sg
->iov_len
= vring_desc_len(vdev
, desc_pa
, i
);
512 /* If we've got too many, that implies a descriptor loop. */
513 if ((elem
->in_num
+ elem
->out_num
) > max
) {
514 error_report("Looped descriptor");
517 } while ((i
= virtqueue_next_desc(vdev
, desc_pa
, i
, max
)) != max
);
519 /* Now map what we have collected */
520 virtqueue_map_sg(elem
->in_sg
, elem
->in_addr
, elem
->in_num
, 1);
521 virtqueue_map_sg(elem
->out_sg
, elem
->out_addr
, elem
->out_num
, 0);
527 trace_virtqueue_pop(vq
, elem
, elem
->in_num
, elem
->out_num
);
528 return elem
->in_num
+ elem
->out_num
;
532 static void virtio_notify_vector(VirtIODevice
*vdev
, uint16_t vector
)
534 BusState
*qbus
= qdev_get_parent_bus(DEVICE(vdev
));
535 VirtioBusClass
*k
= VIRTIO_BUS_GET_CLASS(qbus
);
538 k
->notify(qbus
->parent
, vector
);
542 void virtio_update_irq(VirtIODevice
*vdev
)
544 virtio_notify_vector(vdev
, VIRTIO_NO_VECTOR
);
547 static int virtio_validate_features(VirtIODevice
*vdev
)
549 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
551 if (k
->validate_features
) {
552 return k
->validate_features(vdev
);
558 int virtio_set_status(VirtIODevice
*vdev
, uint8_t val
)
560 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
561 trace_virtio_set_status(vdev
, val
);
563 if (virtio_has_feature(vdev
, VIRTIO_F_VERSION_1
)) {
564 if (!(vdev
->status
& VIRTIO_CONFIG_S_FEATURES_OK
) &&
565 val
& VIRTIO_CONFIG_S_FEATURES_OK
) {
566 int ret
= virtio_validate_features(vdev
);
574 k
->set_status(vdev
, val
);
580 bool target_words_bigendian(void);
581 static enum virtio_device_endian
virtio_default_endian(void)
583 if (target_words_bigendian()) {
584 return VIRTIO_DEVICE_ENDIAN_BIG
;
586 return VIRTIO_DEVICE_ENDIAN_LITTLE
;
590 static enum virtio_device_endian
virtio_current_cpu_endian(void)
592 CPUClass
*cc
= CPU_GET_CLASS(current_cpu
);
594 if (cc
->virtio_is_big_endian(current_cpu
)) {
595 return VIRTIO_DEVICE_ENDIAN_BIG
;
597 return VIRTIO_DEVICE_ENDIAN_LITTLE
;
601 void virtio_reset(void *opaque
)
603 VirtIODevice
*vdev
= opaque
;
604 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
607 virtio_set_status(vdev
, 0);
609 /* Guest initiated reset */
610 vdev
->device_endian
= virtio_current_cpu_endian();
613 vdev
->device_endian
= virtio_default_endian();
620 vdev
->guest_features
= 0;
624 vdev
->config_vector
= VIRTIO_NO_VECTOR
;
625 virtio_notify_vector(vdev
, vdev
->config_vector
);
627 for(i
= 0; i
< VIRTIO_QUEUE_MAX
; i
++) {
628 vdev
->vq
[i
].vring
.desc
= 0;
629 vdev
->vq
[i
].vring
.avail
= 0;
630 vdev
->vq
[i
].vring
.used
= 0;
631 vdev
->vq
[i
].last_avail_idx
= 0;
632 virtio_queue_set_vector(vdev
, i
, VIRTIO_NO_VECTOR
);
633 vdev
->vq
[i
].signalled_used
= 0;
634 vdev
->vq
[i
].signalled_used_valid
= false;
635 vdev
->vq
[i
].notification
= true;
639 uint32_t virtio_config_readb(VirtIODevice
*vdev
, uint32_t addr
)
641 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
644 if (addr
+ sizeof(val
) > vdev
->config_len
) {
648 k
->get_config(vdev
, vdev
->config
);
650 val
= ldub_p(vdev
->config
+ addr
);
654 uint32_t virtio_config_readw(VirtIODevice
*vdev
, uint32_t addr
)
656 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
659 if (addr
+ sizeof(val
) > vdev
->config_len
) {
663 k
->get_config(vdev
, vdev
->config
);
665 val
= lduw_p(vdev
->config
+ addr
);
669 uint32_t virtio_config_readl(VirtIODevice
*vdev
, uint32_t addr
)
671 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
674 if (addr
+ sizeof(val
) > vdev
->config_len
) {
678 k
->get_config(vdev
, vdev
->config
);
680 val
= ldl_p(vdev
->config
+ addr
);
684 void virtio_config_writeb(VirtIODevice
*vdev
, uint32_t addr
, uint32_t data
)
686 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
689 if (addr
+ sizeof(val
) > vdev
->config_len
) {
693 stb_p(vdev
->config
+ addr
, val
);
696 k
->set_config(vdev
, vdev
->config
);
700 void virtio_config_writew(VirtIODevice
*vdev
, uint32_t addr
, uint32_t data
)
702 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
705 if (addr
+ sizeof(val
) > vdev
->config_len
) {
709 stw_p(vdev
->config
+ addr
, val
);
712 k
->set_config(vdev
, vdev
->config
);
716 void virtio_config_writel(VirtIODevice
*vdev
, uint32_t addr
, uint32_t data
)
718 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
721 if (addr
+ sizeof(val
) > vdev
->config_len
) {
725 stl_p(vdev
->config
+ addr
, val
);
728 k
->set_config(vdev
, vdev
->config
);
732 uint32_t virtio_config_modern_readb(VirtIODevice
*vdev
, uint32_t addr
)
734 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
737 if (addr
+ sizeof(val
) > vdev
->config_len
) {
741 k
->get_config(vdev
, vdev
->config
);
743 val
= ldub_p(vdev
->config
+ addr
);
747 uint32_t virtio_config_modern_readw(VirtIODevice
*vdev
, uint32_t addr
)
749 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
752 if (addr
+ sizeof(val
) > vdev
->config_len
) {
756 k
->get_config(vdev
, vdev
->config
);
758 val
= lduw_le_p(vdev
->config
+ addr
);
762 uint32_t virtio_config_modern_readl(VirtIODevice
*vdev
, uint32_t addr
)
764 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
767 if (addr
+ sizeof(val
) > vdev
->config_len
) {
771 k
->get_config(vdev
, vdev
->config
);
773 val
= ldl_le_p(vdev
->config
+ addr
);
777 void virtio_config_modern_writeb(VirtIODevice
*vdev
,
778 uint32_t addr
, uint32_t data
)
780 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
783 if (addr
+ sizeof(val
) > vdev
->config_len
) {
787 stb_p(vdev
->config
+ addr
, val
);
790 k
->set_config(vdev
, vdev
->config
);
794 void virtio_config_modern_writew(VirtIODevice
*vdev
,
795 uint32_t addr
, uint32_t data
)
797 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
800 if (addr
+ sizeof(val
) > vdev
->config_len
) {
804 stw_le_p(vdev
->config
+ addr
, val
);
807 k
->set_config(vdev
, vdev
->config
);
811 void virtio_config_modern_writel(VirtIODevice
*vdev
,
812 uint32_t addr
, uint32_t data
)
814 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
817 if (addr
+ sizeof(val
) > vdev
->config_len
) {
821 stl_le_p(vdev
->config
+ addr
, val
);
824 k
->set_config(vdev
, vdev
->config
);
828 void virtio_queue_set_addr(VirtIODevice
*vdev
, int n
, hwaddr addr
)
830 vdev
->vq
[n
].vring
.desc
= addr
;
831 virtio_queue_update_rings(vdev
, n
);
834 hwaddr
virtio_queue_get_addr(VirtIODevice
*vdev
, int n
)
836 return vdev
->vq
[n
].vring
.desc
;
839 void virtio_queue_set_rings(VirtIODevice
*vdev
, int n
, hwaddr desc
,
840 hwaddr avail
, hwaddr used
)
842 vdev
->vq
[n
].vring
.desc
= desc
;
843 vdev
->vq
[n
].vring
.avail
= avail
;
844 vdev
->vq
[n
].vring
.used
= used
;
847 void virtio_queue_set_num(VirtIODevice
*vdev
, int n
, int num
)
849 /* Don't allow guest to flip queue between existent and
850 * nonexistent states, or to set it to an invalid size.
852 if (!!num
!= !!vdev
->vq
[n
].vring
.num
||
853 num
> VIRTQUEUE_MAX_SIZE
||
857 vdev
->vq
[n
].vring
.num
= num
;
860 VirtQueue
*virtio_vector_first_queue(VirtIODevice
*vdev
, uint16_t vector
)
862 return QLIST_FIRST(&vdev
->vector_queues
[vector
]);
865 VirtQueue
*virtio_vector_next_queue(VirtQueue
*vq
)
867 return QLIST_NEXT(vq
, node
);
870 int virtio_queue_get_num(VirtIODevice
*vdev
, int n
)
872 return vdev
->vq
[n
].vring
.num
;
875 int virtio_get_num_queues(VirtIODevice
*vdev
)
879 for (i
= 0; i
< VIRTIO_QUEUE_MAX
; i
++) {
880 if (!virtio_queue_get_num(vdev
, i
)) {
888 int virtio_queue_get_id(VirtQueue
*vq
)
890 VirtIODevice
*vdev
= vq
->vdev
;
891 assert(vq
>= &vdev
->vq
[0] && vq
< &vdev
->vq
[VIRTIO_QUEUE_MAX
]);
892 return vq
- &vdev
->vq
[0];
895 void virtio_queue_set_align(VirtIODevice
*vdev
, int n
, int align
)
897 BusState
*qbus
= qdev_get_parent_bus(DEVICE(vdev
));
898 VirtioBusClass
*k
= VIRTIO_BUS_GET_CLASS(qbus
);
900 /* virtio-1 compliant devices cannot change the alignment */
901 if (virtio_has_feature(vdev
, VIRTIO_F_VERSION_1
)) {
902 error_report("tried to modify queue alignment for virtio-1 device");
905 /* Check that the transport told us it was going to do this
906 * (so a buggy transport will immediately assert rather than
907 * silently failing to migrate this state)
909 assert(k
->has_variable_vring_alignment
);
911 vdev
->vq
[n
].vring
.align
= align
;
912 virtio_queue_update_rings(vdev
, n
);
915 void virtio_queue_notify_vq(VirtQueue
*vq
)
917 if (vq
->vring
.desc
&& vq
->handle_output
) {
918 VirtIODevice
*vdev
= vq
->vdev
;
920 trace_virtio_queue_notify(vdev
, vq
- vdev
->vq
, vq
);
921 vq
->handle_output(vdev
, vq
);
925 void virtio_queue_notify(VirtIODevice
*vdev
, int n
)
927 virtio_queue_notify_vq(&vdev
->vq
[n
]);
930 uint16_t virtio_queue_vector(VirtIODevice
*vdev
, int n
)
932 return n
< VIRTIO_QUEUE_MAX
? vdev
->vq
[n
].vector
:
936 void virtio_queue_set_vector(VirtIODevice
*vdev
, int n
, uint16_t vector
)
938 VirtQueue
*vq
= &vdev
->vq
[n
];
940 if (n
< VIRTIO_QUEUE_MAX
) {
941 if (vdev
->vector_queues
&&
942 vdev
->vq
[n
].vector
!= VIRTIO_NO_VECTOR
) {
943 QLIST_REMOVE(vq
, node
);
945 vdev
->vq
[n
].vector
= vector
;
946 if (vdev
->vector_queues
&&
947 vector
!= VIRTIO_NO_VECTOR
) {
948 QLIST_INSERT_HEAD(&vdev
->vector_queues
[vector
], vq
, node
);
953 VirtQueue
*virtio_add_queue(VirtIODevice
*vdev
, int queue_size
,
954 void (*handle_output
)(VirtIODevice
*, VirtQueue
*))
958 for (i
= 0; i
< VIRTIO_QUEUE_MAX
; i
++) {
959 if (vdev
->vq
[i
].vring
.num
== 0)
963 if (i
== VIRTIO_QUEUE_MAX
|| queue_size
> VIRTQUEUE_MAX_SIZE
)
966 vdev
->vq
[i
].vring
.num
= queue_size
;
967 vdev
->vq
[i
].vring
.align
= VIRTIO_PCI_VRING_ALIGN
;
968 vdev
->vq
[i
].handle_output
= handle_output
;
973 void virtio_del_queue(VirtIODevice
*vdev
, int n
)
975 if (n
< 0 || n
>= VIRTIO_QUEUE_MAX
) {
979 vdev
->vq
[n
].vring
.num
= 0;
982 void virtio_irq(VirtQueue
*vq
)
984 trace_virtio_irq(vq
);
985 vq
->vdev
->isr
|= 0x01;
986 virtio_notify_vector(vq
->vdev
, vq
->vector
);
989 static bool vring_notify(VirtIODevice
*vdev
, VirtQueue
*vq
)
993 /* We need to expose used array entries before checking used event. */
995 /* Always notify when queue is empty (when feature acknowledge) */
996 if (virtio_has_feature(vdev
, VIRTIO_F_NOTIFY_ON_EMPTY
) &&
997 !vq
->inuse
&& vring_avail_idx(vq
) == vq
->last_avail_idx
) {
1001 if (!virtio_has_feature(vdev
, VIRTIO_RING_F_EVENT_IDX
)) {
1002 return !(vring_avail_flags(vq
) & VRING_AVAIL_F_NO_INTERRUPT
);
1005 v
= vq
->signalled_used_valid
;
1006 vq
->signalled_used_valid
= true;
1007 old
= vq
->signalled_used
;
1008 new = vq
->signalled_used
= vring_used_idx(vq
);
1009 return !v
|| vring_need_event(vring_get_used_event(vq
), new, old
);
1012 void virtio_notify(VirtIODevice
*vdev
, VirtQueue
*vq
)
1014 if (!vring_notify(vdev
, vq
)) {
1018 trace_virtio_notify(vdev
, vq
);
1020 virtio_notify_vector(vdev
, vq
->vector
);
1023 void virtio_notify_config(VirtIODevice
*vdev
)
1025 if (!(vdev
->status
& VIRTIO_CONFIG_S_DRIVER_OK
))
1030 virtio_notify_vector(vdev
, vdev
->config_vector
);
1033 static bool virtio_device_endian_needed(void *opaque
)
1035 VirtIODevice
*vdev
= opaque
;
1037 assert(vdev
->device_endian
!= VIRTIO_DEVICE_ENDIAN_UNKNOWN
);
1038 if (!virtio_has_feature(vdev
, VIRTIO_F_VERSION_1
)) {
1039 return vdev
->device_endian
!= virtio_default_endian();
1041 /* Devices conforming to VIRTIO 1.0 or later are always LE. */
1042 return vdev
->device_endian
!= VIRTIO_DEVICE_ENDIAN_LITTLE
;
1045 static bool virtio_64bit_features_needed(void *opaque
)
1047 VirtIODevice
*vdev
= opaque
;
1049 return (vdev
->host_features
>> 32) != 0;
1052 static const VMStateDescription vmstate_virtio_device_endian
= {
1053 .name
= "virtio/device_endian",
1055 .minimum_version_id
= 1,
1056 .needed
= &virtio_device_endian_needed
,
1057 .fields
= (VMStateField
[]) {
1058 VMSTATE_UINT8(device_endian
, VirtIODevice
),
1059 VMSTATE_END_OF_LIST()
1063 static const VMStateDescription vmstate_virtio_64bit_features
= {
1064 .name
= "virtio/64bit_features",
1066 .minimum_version_id
= 1,
1067 .needed
= &virtio_64bit_features_needed
,
1068 .fields
= (VMStateField
[]) {
1069 VMSTATE_UINT64(guest_features
, VirtIODevice
),
1070 VMSTATE_END_OF_LIST()
1074 static const VMStateDescription vmstate_virtio
= {
1077 .minimum_version_id
= 1,
1078 .minimum_version_id_old
= 1,
1079 .fields
= (VMStateField
[]) {
1080 VMSTATE_END_OF_LIST()
1082 .subsections
= (const VMStateDescription
*[]) {
1083 &vmstate_virtio_device_endian
,
1084 &vmstate_virtio_64bit_features
,
1089 void virtio_save(VirtIODevice
*vdev
, QEMUFile
*f
)
1091 BusState
*qbus
= qdev_get_parent_bus(DEVICE(vdev
));
1092 VirtioBusClass
*k
= VIRTIO_BUS_GET_CLASS(qbus
);
1093 VirtioDeviceClass
*vdc
= VIRTIO_DEVICE_GET_CLASS(vdev
);
1094 uint32_t guest_features_lo
= (vdev
->guest_features
& 0xffffffff);
1097 if (k
->save_config
) {
1098 k
->save_config(qbus
->parent
, f
);
1101 qemu_put_8s(f
, &vdev
->status
);
1102 qemu_put_8s(f
, &vdev
->isr
);
1103 qemu_put_be16s(f
, &vdev
->queue_sel
);
1104 qemu_put_be32s(f
, &guest_features_lo
);
1105 qemu_put_be32(f
, vdev
->config_len
);
1106 qemu_put_buffer(f
, vdev
->config
, vdev
->config_len
);
1108 for (i
= 0; i
< VIRTIO_QUEUE_MAX
; i
++) {
1109 if (vdev
->vq
[i
].vring
.num
== 0)
1113 qemu_put_be32(f
, i
);
1115 for (i
= 0; i
< VIRTIO_QUEUE_MAX
; i
++) {
1116 if (vdev
->vq
[i
].vring
.num
== 0)
1119 qemu_put_be32(f
, vdev
->vq
[i
].vring
.num
);
1120 if (k
->has_variable_vring_alignment
) {
1121 qemu_put_be32(f
, vdev
->vq
[i
].vring
.align
);
1123 /* XXX virtio-1 devices */
1124 qemu_put_be64(f
, vdev
->vq
[i
].vring
.desc
);
1125 qemu_put_be16s(f
, &vdev
->vq
[i
].last_avail_idx
);
1126 if (k
->save_queue
) {
1127 k
->save_queue(qbus
->parent
, i
, f
);
1131 if (vdc
->save
!= NULL
) {
1136 vmstate_save_state(f
, &vmstate_virtio
, vdev
, NULL
);
1139 static int virtio_set_features_nocheck(VirtIODevice
*vdev
, uint64_t val
)
1141 VirtioDeviceClass
*k
= VIRTIO_DEVICE_GET_CLASS(vdev
);
1142 bool bad
= (val
& ~(vdev
->host_features
)) != 0;
1144 val
&= vdev
->host_features
;
1145 if (k
->set_features
) {
1146 k
->set_features(vdev
, val
);
1148 vdev
->guest_features
= val
;
1149 return bad
? -1 : 0;
1152 int virtio_set_features(VirtIODevice
*vdev
, uint64_t val
)
1155 * The driver must not attempt to set features after feature negotiation
1158 if (vdev
->status
& VIRTIO_CONFIG_S_FEATURES_OK
) {
1161 return virtio_set_features_nocheck(vdev
, val
);
1164 int virtio_load(VirtIODevice
*vdev
, QEMUFile
*f
, int version_id
)
1170 BusState
*qbus
= qdev_get_parent_bus(DEVICE(vdev
));
1171 VirtioBusClass
*k
= VIRTIO_BUS_GET_CLASS(qbus
);
1172 VirtioDeviceClass
*vdc
= VIRTIO_DEVICE_GET_CLASS(vdev
);
1175 * We poison the endianness to ensure it does not get used before
1176 * subsections have been loaded.
1178 vdev
->device_endian
= VIRTIO_DEVICE_ENDIAN_UNKNOWN
;
1180 if (k
->load_config
) {
1181 ret
= k
->load_config(qbus
->parent
, f
);
1186 qemu_get_8s(f
, &vdev
->status
);
1187 qemu_get_8s(f
, &vdev
->isr
);
1188 qemu_get_be16s(f
, &vdev
->queue_sel
);
1189 if (vdev
->queue_sel
>= VIRTIO_QUEUE_MAX
) {
1192 qemu_get_be32s(f
, &features
);
1194 config_len
= qemu_get_be32(f
);
1197 * There are cases where the incoming config can be bigger or smaller
1198 * than what we have; so load what we have space for, and skip
1199 * any excess that's in the stream.
1201 qemu_get_buffer(f
, vdev
->config
, MIN(config_len
, vdev
->config_len
));
1203 while (config_len
> vdev
->config_len
) {
1208 num
= qemu_get_be32(f
);
1210 if (num
> VIRTIO_QUEUE_MAX
) {
1211 error_report("Invalid number of PCI queues: 0x%x", num
);
1215 for (i
= 0; i
< num
; i
++) {
1216 vdev
->vq
[i
].vring
.num
= qemu_get_be32(f
);
1217 if (k
->has_variable_vring_alignment
) {
1218 vdev
->vq
[i
].vring
.align
= qemu_get_be32(f
);
1220 vdev
->vq
[i
].vring
.desc
= qemu_get_be64(f
);
1221 qemu_get_be16s(f
, &vdev
->vq
[i
].last_avail_idx
);
1222 vdev
->vq
[i
].signalled_used_valid
= false;
1223 vdev
->vq
[i
].notification
= true;
1225 if (vdev
->vq
[i
].vring
.desc
) {
1226 /* XXX virtio-1 devices */
1227 virtio_queue_update_rings(vdev
, i
);
1228 } else if (vdev
->vq
[i
].last_avail_idx
) {
1229 error_report("VQ %d address 0x0 "
1230 "inconsistent with Host index 0x%x",
1231 i
, vdev
->vq
[i
].last_avail_idx
);
1234 if (k
->load_queue
) {
1235 ret
= k
->load_queue(qbus
->parent
, i
, f
);
1241 virtio_notify_vector(vdev
, VIRTIO_NO_VECTOR
);
1243 if (vdc
->load
!= NULL
) {
1244 ret
= vdc
->load(vdev
, f
, version_id
);
1251 ret
= vmstate_load_state(f
, &vmstate_virtio
, vdev
, 1);
1256 if (vdev
->device_endian
== VIRTIO_DEVICE_ENDIAN_UNKNOWN
) {
1257 vdev
->device_endian
= virtio_default_endian();
1260 if (virtio_64bit_features_needed(vdev
)) {
1262 * Subsection load filled vdev->guest_features. Run them
1263 * through virtio_set_features to sanity-check them against
1266 uint64_t features64
= vdev
->guest_features
;
1267 if (virtio_set_features_nocheck(vdev
, features64
) < 0) {
1268 error_report("Features 0x%" PRIx64
" unsupported. "
1269 "Allowed features: 0x%" PRIx64
,
1270 features64
, vdev
->host_features
);
1274 if (virtio_set_features_nocheck(vdev
, features
) < 0) {
1275 error_report("Features 0x%x unsupported. "
1276 "Allowed features: 0x%" PRIx64
,
1277 features
, vdev
->host_features
);
1282 for (i
= 0; i
< num
; i
++) {
1283 if (vdev
->vq
[i
].vring
.desc
) {
1285 nheads
= vring_avail_idx(&vdev
->vq
[i
]) - vdev
->vq
[i
].last_avail_idx
;
1286 /* Check it isn't doing strange things with descriptor numbers. */
1287 if (nheads
> vdev
->vq
[i
].vring
.num
) {
1288 error_report("VQ %d size 0x%x Guest index 0x%x "
1289 "inconsistent with Host index 0x%x: delta 0x%x",
1290 i
, vdev
->vq
[i
].vring
.num
,
1291 vring_avail_idx(&vdev
->vq
[i
]),
1292 vdev
->vq
[i
].last_avail_idx
, nheads
);
1301 void virtio_cleanup(VirtIODevice
*vdev
)
1303 qemu_del_vm_change_state_handler(vdev
->vmstate
);
1304 g_free(vdev
->config
);
1306 g_free(vdev
->vector_queues
);
1309 static void virtio_vmstate_change(void *opaque
, int running
, RunState state
)
1311 VirtIODevice
*vdev
= opaque
;
1312 BusState
*qbus
= qdev_get_parent_bus(DEVICE(vdev
));
1313 VirtioBusClass
*k
= VIRTIO_BUS_GET_CLASS(qbus
);
1314 bool backend_run
= running
&& (vdev
->status
& VIRTIO_CONFIG_S_DRIVER_OK
);
1315 vdev
->vm_running
= running
;
1318 virtio_set_status(vdev
, vdev
->status
);
1321 if (k
->vmstate_change
) {
1322 k
->vmstate_change(qbus
->parent
, backend_run
);
1326 virtio_set_status(vdev
, vdev
->status
);
1330 void virtio_instance_init_common(Object
*proxy_obj
, void *data
,
1331 size_t vdev_size
, const char *vdev_name
)
1333 DeviceState
*vdev
= data
;
1335 object_initialize(vdev
, vdev_size
, vdev_name
);
1336 object_property_add_child(proxy_obj
, "virtio-backend", OBJECT(vdev
), NULL
);
1337 object_unref(OBJECT(vdev
));
1338 qdev_alias_all_properties(vdev
, proxy_obj
);
1341 void virtio_init(VirtIODevice
*vdev
, const char *name
,
1342 uint16_t device_id
, size_t config_size
)
1344 BusState
*qbus
= qdev_get_parent_bus(DEVICE(vdev
));
1345 VirtioBusClass
*k
= VIRTIO_BUS_GET_CLASS(qbus
);
1347 int nvectors
= k
->query_nvectors
? k
->query_nvectors(qbus
->parent
) : 0;
1350 vdev
->vector_queues
=
1351 g_malloc0(sizeof(*vdev
->vector_queues
) * nvectors
);
1354 vdev
->device_id
= device_id
;
1357 vdev
->queue_sel
= 0;
1358 vdev
->config_vector
= VIRTIO_NO_VECTOR
;
1359 vdev
->vq
= g_malloc0(sizeof(VirtQueue
) * VIRTIO_QUEUE_MAX
);
1360 vdev
->vm_running
= runstate_is_running();
1361 for (i
= 0; i
< VIRTIO_QUEUE_MAX
; i
++) {
1362 vdev
->vq
[i
].vector
= VIRTIO_NO_VECTOR
;
1363 vdev
->vq
[i
].vdev
= vdev
;
1364 vdev
->vq
[i
].queue_index
= i
;
1368 vdev
->config_len
= config_size
;
1369 if (vdev
->config_len
) {
1370 vdev
->config
= g_malloc0(config_size
);
1372 vdev
->config
= NULL
;
1374 vdev
->vmstate
= qemu_add_vm_change_state_handler(virtio_vmstate_change
,
1376 vdev
->device_endian
= virtio_default_endian();
1379 hwaddr
virtio_queue_get_desc_addr(VirtIODevice
*vdev
, int n
)
1381 return vdev
->vq
[n
].vring
.desc
;
1384 hwaddr
virtio_queue_get_avail_addr(VirtIODevice
*vdev
, int n
)
1386 return vdev
->vq
[n
].vring
.avail
;
1389 hwaddr
virtio_queue_get_used_addr(VirtIODevice
*vdev
, int n
)
1391 return vdev
->vq
[n
].vring
.used
;
1394 hwaddr
virtio_queue_get_ring_addr(VirtIODevice
*vdev
, int n
)
1396 return vdev
->vq
[n
].vring
.desc
;
1399 hwaddr
virtio_queue_get_desc_size(VirtIODevice
*vdev
, int n
)
1401 return sizeof(VRingDesc
) * vdev
->vq
[n
].vring
.num
;
1404 hwaddr
virtio_queue_get_avail_size(VirtIODevice
*vdev
, int n
)
1406 return offsetof(VRingAvail
, ring
) +
1407 sizeof(uint64_t) * vdev
->vq
[n
].vring
.num
;
1410 hwaddr
virtio_queue_get_used_size(VirtIODevice
*vdev
, int n
)
1412 return offsetof(VRingUsed
, ring
) +
1413 sizeof(VRingUsedElem
) * vdev
->vq
[n
].vring
.num
;
1416 hwaddr
virtio_queue_get_ring_size(VirtIODevice
*vdev
, int n
)
1418 return vdev
->vq
[n
].vring
.used
- vdev
->vq
[n
].vring
.desc
+
1419 virtio_queue_get_used_size(vdev
, n
);
1422 uint16_t virtio_queue_get_last_avail_idx(VirtIODevice
*vdev
, int n
)
1424 return vdev
->vq
[n
].last_avail_idx
;
1427 void virtio_queue_set_last_avail_idx(VirtIODevice
*vdev
, int n
, uint16_t idx
)
1429 vdev
->vq
[n
].last_avail_idx
= idx
;
1432 void virtio_queue_invalidate_signalled_used(VirtIODevice
*vdev
, int n
)
1434 vdev
->vq
[n
].signalled_used_valid
= false;
1437 VirtQueue
*virtio_get_queue(VirtIODevice
*vdev
, int n
)
1439 return vdev
->vq
+ n
;
1442 uint16_t virtio_get_queue_index(VirtQueue
*vq
)
1444 return vq
->queue_index
;
1447 static void virtio_queue_guest_notifier_read(EventNotifier
*n
)
1449 VirtQueue
*vq
= container_of(n
, VirtQueue
, guest_notifier
);
1450 if (event_notifier_test_and_clear(n
)) {
1455 void virtio_queue_set_guest_notifier_fd_handler(VirtQueue
*vq
, bool assign
,
1458 if (assign
&& !with_irqfd
) {
1459 event_notifier_set_handler(&vq
->guest_notifier
,
1460 virtio_queue_guest_notifier_read
);
1462 event_notifier_set_handler(&vq
->guest_notifier
, NULL
);
1465 /* Test and clear notifier before closing it,
1466 * in case poll callback didn't have time to run. */
1467 virtio_queue_guest_notifier_read(&vq
->guest_notifier
);
1471 EventNotifier
*virtio_queue_get_guest_notifier(VirtQueue
*vq
)
1473 return &vq
->guest_notifier
;
1476 static void virtio_queue_host_notifier_read(EventNotifier
*n
)
1478 VirtQueue
*vq
= container_of(n
, VirtQueue
, host_notifier
);
1479 if (event_notifier_test_and_clear(n
)) {
1480 virtio_queue_notify_vq(vq
);
1484 void virtio_queue_set_host_notifier_fd_handler(VirtQueue
*vq
, bool assign
,
1487 if (assign
&& set_handler
) {
1488 event_notifier_set_handler(&vq
->host_notifier
,
1489 virtio_queue_host_notifier_read
);
1491 event_notifier_set_handler(&vq
->host_notifier
, NULL
);
1494 /* Test and clear notifier before after disabling event,
1495 * in case poll callback didn't have time to run. */
1496 virtio_queue_host_notifier_read(&vq
->host_notifier
);
1500 EventNotifier
*virtio_queue_get_host_notifier(VirtQueue
*vq
)
1502 return &vq
->host_notifier
;
1505 void virtio_device_set_child_bus_name(VirtIODevice
*vdev
, char *bus_name
)
1507 g_free(vdev
->bus_name
);
1508 vdev
->bus_name
= g_strdup(bus_name
);
1511 static void virtio_device_realize(DeviceState
*dev
, Error
**errp
)
1513 VirtIODevice
*vdev
= VIRTIO_DEVICE(dev
);
1514 VirtioDeviceClass
*vdc
= VIRTIO_DEVICE_GET_CLASS(dev
);
1517 if (vdc
->realize
!= NULL
) {
1518 vdc
->realize(dev
, &err
);
1520 error_propagate(errp
, err
);
1525 virtio_bus_device_plugged(vdev
, &err
);
1527 error_propagate(errp
, err
);
1532 static void virtio_device_unrealize(DeviceState
*dev
, Error
**errp
)
1534 VirtIODevice
*vdev
= VIRTIO_DEVICE(dev
);
1535 VirtioDeviceClass
*vdc
= VIRTIO_DEVICE_GET_CLASS(dev
);
1538 virtio_bus_device_unplugged(vdev
);
1540 if (vdc
->unrealize
!= NULL
) {
1541 vdc
->unrealize(dev
, &err
);
1543 error_propagate(errp
, err
);
1548 g_free(vdev
->bus_name
);
1549 vdev
->bus_name
= NULL
;
1552 static Property virtio_properties
[] = {
1553 DEFINE_VIRTIO_COMMON_FEATURES(VirtIODevice
, host_features
),
1554 DEFINE_PROP_END_OF_LIST(),
1557 static void virtio_device_class_init(ObjectClass
*klass
, void *data
)
1559 /* Set the default value here. */
1560 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1562 dc
->realize
= virtio_device_realize
;
1563 dc
->unrealize
= virtio_device_unrealize
;
1564 dc
->bus_type
= TYPE_VIRTIO_BUS
;
1565 dc
->props
= virtio_properties
;
1568 static const TypeInfo virtio_device_info
= {
1569 .name
= TYPE_VIRTIO_DEVICE
,
1570 .parent
= TYPE_DEVICE
,
1571 .instance_size
= sizeof(VirtIODevice
),
1572 .class_init
= virtio_device_class_init
,
1574 .class_size
= sizeof(VirtioDeviceClass
),
1577 static void virtio_register_types(void)
1579 type_register_static(&virtio_device_info
);
1582 type_init(virtio_register_types
)