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 /* from Linux's linux/virtio_pci.h */
21 /* A 32-bit r/o bitmask of the features supported by the host */
22 #define VIRTIO_PCI_HOST_FEATURES 0
24 /* A 32-bit r/w bitmask of features activated by the guest */
25 #define VIRTIO_PCI_GUEST_FEATURES 4
27 /* A 32-bit r/w PFN for the currently selected queue */
28 #define VIRTIO_PCI_QUEUE_PFN 8
30 /* A 16-bit r/o queue size for the currently selected queue */
31 #define VIRTIO_PCI_QUEUE_NUM 12
33 /* A 16-bit r/w queue selector */
34 #define VIRTIO_PCI_QUEUE_SEL 14
36 /* A 16-bit r/w queue notifier */
37 #define VIRTIO_PCI_QUEUE_NOTIFY 16
39 /* An 8-bit device status register. */
40 #define VIRTIO_PCI_STATUS 18
42 /* An 8-bit r/o interrupt status register. Reading the value will return the
43 * current contents of the ISR and will also clear it. This is effectively
44 * a read-and-acknowledge. */
45 #define VIRTIO_PCI_ISR 19
47 #define VIRTIO_PCI_CONFIG 20
49 /* Virtio ABI version, if we increment this, we break the guest driver. */
50 #define VIRTIO_PCI_ABI_VERSION 0
52 /* How many bits to shift physical queue address written to QUEUE_PFN.
53 * 12 is historical, and due to x86 page size. */
54 #define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12
56 /* The alignment to use between consumer and producer parts of vring.
57 * x86 pagesize again. */
58 #define VIRTIO_PCI_VRING_ALIGN 4096
60 /* QEMU doesn't strictly need write barriers since everything runs in
61 * lock-step. We'll leave the calls to wmb() in though to make it obvious for
62 * KVM or if kqemu gets SMP support.
64 #define wmb() do { } while (0)
66 typedef struct VRingDesc
74 typedef struct VRingAvail
81 typedef struct VRingUsedElem
87 typedef struct VRingUsed
91 VRingUsedElem ring
[0];
97 target_phys_addr_t desc
;
98 target_phys_addr_t avail
;
99 target_phys_addr_t used
;
106 uint16_t last_avail_idx
;
108 void (*handle_output
)(VirtIODevice
*vdev
, VirtQueue
*vq
);
111 #define VIRTIO_PCI_QUEUE_MAX 16
113 /* virt queue functions */
114 static void virtqueue_init(VirtQueue
*vq
, target_phys_addr_t pa
)
117 vq
->vring
.avail
= pa
+ vq
->vring
.num
* sizeof(VRingDesc
);
118 vq
->vring
.used
= vring_align(vq
->vring
.avail
+
119 offsetof(VRingAvail
, ring
[vq
->vring
.num
]),
120 VIRTIO_PCI_VRING_ALIGN
);
123 static inline uint64_t vring_desc_addr(VirtQueue
*vq
, int i
)
125 target_phys_addr_t pa
;
126 pa
= vq
->vring
.desc
+ sizeof(VRingDesc
) * i
+ offsetof(VRingDesc
, addr
);
130 static inline uint32_t vring_desc_len(VirtQueue
*vq
, int i
)
132 target_phys_addr_t pa
;
133 pa
= vq
->vring
.desc
+ sizeof(VRingDesc
) * i
+ offsetof(VRingDesc
, len
);
137 static inline uint16_t vring_desc_flags(VirtQueue
*vq
, int i
)
139 target_phys_addr_t pa
;
140 pa
= vq
->vring
.desc
+ sizeof(VRingDesc
) * i
+ offsetof(VRingDesc
, flags
);
141 return lduw_phys(pa
);
144 static inline uint16_t vring_desc_next(VirtQueue
*vq
, int i
)
146 target_phys_addr_t pa
;
147 pa
= vq
->vring
.desc
+ sizeof(VRingDesc
) * i
+ offsetof(VRingDesc
, next
);
148 return lduw_phys(pa
);
151 static inline uint16_t vring_avail_flags(VirtQueue
*vq
)
153 target_phys_addr_t pa
;
154 pa
= vq
->vring
.avail
+ offsetof(VRingAvail
, flags
);
155 return lduw_phys(pa
);
158 static inline uint16_t vring_avail_idx(VirtQueue
*vq
)
160 target_phys_addr_t pa
;
161 pa
= vq
->vring
.avail
+ offsetof(VRingAvail
, idx
);
162 return lduw_phys(pa
);
165 static inline uint16_t vring_avail_ring(VirtQueue
*vq
, int i
)
167 target_phys_addr_t pa
;
168 pa
= vq
->vring
.avail
+ offsetof(VRingAvail
, ring
[i
]);
169 return lduw_phys(pa
);
172 static inline void vring_used_ring_id(VirtQueue
*vq
, int i
, uint32_t val
)
174 target_phys_addr_t pa
;
175 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, ring
[i
].id
);
179 static inline void vring_used_ring_len(VirtQueue
*vq
, int i
, uint32_t val
)
181 target_phys_addr_t pa
;
182 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, ring
[i
].len
);
186 static uint16_t vring_used_idx(VirtQueue
*vq
)
188 target_phys_addr_t pa
;
189 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, idx
);
190 return lduw_phys(pa
);
193 static inline void vring_used_idx_increment(VirtQueue
*vq
, uint16_t val
)
195 target_phys_addr_t pa
;
196 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, idx
);
197 stw_phys(pa
, vring_used_idx(vq
) + val
);
200 static inline void vring_used_flags_set_bit(VirtQueue
*vq
, int mask
)
202 target_phys_addr_t pa
;
203 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, flags
);
204 stw_phys(pa
, lduw_phys(pa
) | mask
);
207 static inline void vring_used_flags_unset_bit(VirtQueue
*vq
, int mask
)
209 target_phys_addr_t pa
;
210 pa
= vq
->vring
.used
+ offsetof(VRingUsed
, flags
);
211 stw_phys(pa
, lduw_phys(pa
) & ~mask
);
214 void virtio_queue_set_notification(VirtQueue
*vq
, int enable
)
217 vring_used_flags_unset_bit(vq
, VRING_USED_F_NO_NOTIFY
);
219 vring_used_flags_set_bit(vq
, VRING_USED_F_NO_NOTIFY
);
222 int virtio_queue_ready(VirtQueue
*vq
)
224 return vq
->vring
.avail
!= 0;
227 int virtio_queue_empty(VirtQueue
*vq
)
229 return vring_avail_idx(vq
) == vq
->last_avail_idx
;
232 void virtqueue_fill(VirtQueue
*vq
, const VirtQueueElement
*elem
,
233 unsigned int len
, unsigned int idx
)
239 for (i
= 0; i
< elem
->in_num
; i
++) {
240 size_t size
= MIN(len
- offset
, elem
->in_sg
[i
].iov_len
);
242 cpu_physical_memory_unmap(elem
->in_sg
[i
].iov_base
,
243 elem
->in_sg
[i
].iov_len
,
246 offset
+= elem
->in_sg
[i
].iov_len
;
249 for (i
= 0; i
< elem
->out_num
; i
++)
250 cpu_physical_memory_unmap(elem
->out_sg
[i
].iov_base
,
251 elem
->out_sg
[i
].iov_len
,
252 0, elem
->out_sg
[i
].iov_len
);
254 idx
= (idx
+ vring_used_idx(vq
)) % vq
->vring
.num
;
256 /* Get a pointer to the next entry in the used ring. */
257 vring_used_ring_id(vq
, idx
, elem
->index
);
258 vring_used_ring_len(vq
, idx
, len
);
261 void virtqueue_flush(VirtQueue
*vq
, unsigned int count
)
263 /* Make sure buffer is written before we update index. */
265 vring_used_idx_increment(vq
, count
);
269 void virtqueue_push(VirtQueue
*vq
, const VirtQueueElement
*elem
,
272 virtqueue_fill(vq
, elem
, len
, 0);
273 virtqueue_flush(vq
, 1);
276 static int virtqueue_num_heads(VirtQueue
*vq
, unsigned int idx
)
278 uint16_t num_heads
= vring_avail_idx(vq
) - idx
;
280 /* Check it isn't doing very strange things with descriptor numbers. */
281 if (num_heads
> vq
->vring
.num
) {
282 fprintf(stderr
, "Guest moved used index from %u to %u",
283 idx
, vring_avail_idx(vq
));
290 static unsigned int virtqueue_get_head(VirtQueue
*vq
, unsigned int idx
)
294 /* Grab the next descriptor number they're advertising, and increment
295 * the index we've seen. */
296 head
= vring_avail_ring(vq
, idx
% vq
->vring
.num
);
298 /* If their number is silly, that's a fatal mistake. */
299 if (head
>= vq
->vring
.num
) {
300 fprintf(stderr
, "Guest says index %u is available", head
);
307 static unsigned virtqueue_next_desc(VirtQueue
*vq
, unsigned int i
)
311 /* If this descriptor says it doesn't chain, we're done. */
312 if (!(vring_desc_flags(vq
, i
) & VRING_DESC_F_NEXT
))
313 return vq
->vring
.num
;
315 /* Check they're not leading us off end of descriptors. */
316 next
= vring_desc_next(vq
, i
);
317 /* Make sure compiler knows to grab that: we don't want it changing! */
320 if (next
>= vq
->vring
.num
) {
321 fprintf(stderr
, "Desc next is %u", next
);
328 int virtqueue_avail_bytes(VirtQueue
*vq
, int in_bytes
, int out_bytes
)
331 int num_bufs
, in_total
, out_total
;
333 idx
= vq
->last_avail_idx
;
335 num_bufs
= in_total
= out_total
= 0;
336 while (virtqueue_num_heads(vq
, idx
)) {
339 i
= virtqueue_get_head(vq
, idx
++);
341 /* If we've got too many, that implies a descriptor loop. */
342 if (++num_bufs
> vq
->vring
.num
) {
343 fprintf(stderr
, "Looped descriptor");
347 if (vring_desc_flags(vq
, i
) & VRING_DESC_F_WRITE
) {
349 (in_total
+= vring_desc_len(vq
, i
)) >= in_bytes
)
353 (out_total
+= vring_desc_len(vq
, i
)) >= out_bytes
)
356 } while ((i
= virtqueue_next_desc(vq
, i
)) != vq
->vring
.num
);
362 int virtqueue_pop(VirtQueue
*vq
, VirtQueueElement
*elem
)
364 unsigned int i
, head
;
365 target_phys_addr_t len
;
367 if (!virtqueue_num_heads(vq
, vq
->last_avail_idx
))
370 /* When we start there are none of either input nor output. */
371 elem
->out_num
= elem
->in_num
= 0;
373 i
= head
= virtqueue_get_head(vq
, vq
->last_avail_idx
++);
378 if (vring_desc_flags(vq
, i
) & VRING_DESC_F_WRITE
) {
379 elem
->in_addr
[elem
->in_num
] = vring_desc_addr(vq
, i
);
380 sg
= &elem
->in_sg
[elem
->in_num
++];
383 sg
= &elem
->out_sg
[elem
->out_num
++];
385 /* Grab the first descriptor, and check it's OK. */
386 sg
->iov_len
= vring_desc_len(vq
, i
);
389 sg
->iov_base
= cpu_physical_memory_map(vring_desc_addr(vq
, i
), &len
, is_write
);
391 if (sg
->iov_base
== NULL
|| len
!= sg
->iov_len
) {
392 fprintf(stderr
, "virtio: trying to map MMIO memory\n");
396 /* If we've got too many, that implies a descriptor loop. */
397 if ((elem
->in_num
+ elem
->out_num
) > vq
->vring
.num
) {
398 fprintf(stderr
, "Looped descriptor");
401 } while ((i
= virtqueue_next_desc(vq
, i
)) != vq
->vring
.num
);
407 return elem
->in_num
+ elem
->out_num
;
412 static VirtIODevice
*to_virtio_device(PCIDevice
*pci_dev
)
414 return (VirtIODevice
*)pci_dev
;
417 static void virtio_update_irq(VirtIODevice
*vdev
)
419 qemu_set_irq(vdev
->pci_dev
.irq
[0], vdev
->isr
& 1);
422 static void virtio_reset(void *opaque
)
424 VirtIODevice
*vdev
= opaque
;
434 virtio_update_irq(vdev
);
436 for(i
= 0; i
< VIRTIO_PCI_QUEUE_MAX
; i
++) {
437 vdev
->vq
[i
].vring
.desc
= 0;
438 vdev
->vq
[i
].vring
.avail
= 0;
439 vdev
->vq
[i
].vring
.used
= 0;
440 vdev
->vq
[i
].last_avail_idx
= 0;
445 static void virtio_ioport_write(void *opaque
, uint32_t addr
, uint32_t val
)
447 VirtIODevice
*vdev
= to_virtio_device(opaque
);
453 case VIRTIO_PCI_GUEST_FEATURES
:
454 /* Guest does not negotiate properly? We have to assume nothing. */
455 if (val
& (1 << VIRTIO_F_BAD_FEATURE
)) {
456 if (vdev
->bad_features
)
457 val
= vdev
->bad_features(vdev
);
461 if (vdev
->set_features
)
462 vdev
->set_features(vdev
, val
);
463 vdev
->features
= val
;
465 case VIRTIO_PCI_QUEUE_PFN
:
466 pa
= (ram_addr_t
)val
<< VIRTIO_PCI_QUEUE_ADDR_SHIFT
;
467 vdev
->vq
[vdev
->queue_sel
].pfn
= val
;
471 virtqueue_init(&vdev
->vq
[vdev
->queue_sel
], pa
);
474 case VIRTIO_PCI_QUEUE_SEL
:
475 if (val
< VIRTIO_PCI_QUEUE_MAX
)
476 vdev
->queue_sel
= val
;
478 case VIRTIO_PCI_QUEUE_NOTIFY
:
479 if (val
< VIRTIO_PCI_QUEUE_MAX
&& vdev
->vq
[val
].vring
.desc
)
480 vdev
->vq
[val
].handle_output(vdev
, &vdev
->vq
[val
]);
482 case VIRTIO_PCI_STATUS
:
483 vdev
->status
= val
& 0xFF;
484 if (vdev
->status
== 0)
490 static uint32_t virtio_ioport_read(void *opaque
, uint32_t addr
)
492 VirtIODevice
*vdev
= to_virtio_device(opaque
);
493 uint32_t ret
= 0xFFFFFFFF;
498 case VIRTIO_PCI_HOST_FEATURES
:
499 ret
= vdev
->get_features(vdev
);
500 ret
|= (1 << VIRTIO_F_NOTIFY_ON_EMPTY
) | (1 << VIRTIO_F_BAD_FEATURE
);
502 case VIRTIO_PCI_GUEST_FEATURES
:
503 ret
= vdev
->features
;
505 case VIRTIO_PCI_QUEUE_PFN
:
506 ret
= vdev
->vq
[vdev
->queue_sel
].pfn
;
508 case VIRTIO_PCI_QUEUE_NUM
:
509 ret
= vdev
->vq
[vdev
->queue_sel
].vring
.num
;
511 case VIRTIO_PCI_QUEUE_SEL
:
512 ret
= vdev
->queue_sel
;
514 case VIRTIO_PCI_STATUS
:
518 /* reading from the ISR also clears it. */
521 virtio_update_irq(vdev
);
530 static uint32_t virtio_config_readb(void *opaque
, uint32_t addr
)
532 VirtIODevice
*vdev
= opaque
;
535 vdev
->get_config(vdev
, vdev
->config
);
537 addr
-= vdev
->addr
+ VIRTIO_PCI_CONFIG
;
538 if (addr
> (vdev
->config_len
- sizeof(val
)))
541 memcpy(&val
, vdev
->config
+ addr
, sizeof(val
));
545 static uint32_t virtio_config_readw(void *opaque
, uint32_t addr
)
547 VirtIODevice
*vdev
= opaque
;
550 vdev
->get_config(vdev
, vdev
->config
);
552 addr
-= vdev
->addr
+ VIRTIO_PCI_CONFIG
;
553 if (addr
> (vdev
->config_len
- sizeof(val
)))
556 memcpy(&val
, vdev
->config
+ addr
, sizeof(val
));
560 static uint32_t virtio_config_readl(void *opaque
, uint32_t addr
)
562 VirtIODevice
*vdev
= opaque
;
565 vdev
->get_config(vdev
, vdev
->config
);
567 addr
-= vdev
->addr
+ VIRTIO_PCI_CONFIG
;
568 if (addr
> (vdev
->config_len
- sizeof(val
)))
571 memcpy(&val
, vdev
->config
+ addr
, sizeof(val
));
575 static void virtio_config_writeb(void *opaque
, uint32_t addr
, uint32_t data
)
577 VirtIODevice
*vdev
= opaque
;
580 addr
-= vdev
->addr
+ VIRTIO_PCI_CONFIG
;
581 if (addr
> (vdev
->config_len
- sizeof(val
)))
584 memcpy(vdev
->config
+ addr
, &val
, sizeof(val
));
586 if (vdev
->set_config
)
587 vdev
->set_config(vdev
, vdev
->config
);
590 static void virtio_config_writew(void *opaque
, uint32_t addr
, uint32_t data
)
592 VirtIODevice
*vdev
= opaque
;
595 addr
-= vdev
->addr
+ VIRTIO_PCI_CONFIG
;
596 if (addr
> (vdev
->config_len
- sizeof(val
)))
599 memcpy(vdev
->config
+ addr
, &val
, sizeof(val
));
601 if (vdev
->set_config
)
602 vdev
->set_config(vdev
, vdev
->config
);
605 static void virtio_config_writel(void *opaque
, uint32_t addr
, uint32_t data
)
607 VirtIODevice
*vdev
= opaque
;
610 addr
-= vdev
->addr
+ VIRTIO_PCI_CONFIG
;
611 if (addr
> (vdev
->config_len
- sizeof(val
)))
614 memcpy(vdev
->config
+ addr
, &val
, sizeof(val
));
616 if (vdev
->set_config
)
617 vdev
->set_config(vdev
, vdev
->config
);
620 static void virtio_map(PCIDevice
*pci_dev
, int region_num
,
621 uint32_t addr
, uint32_t size
, int type
)
623 VirtIODevice
*vdev
= to_virtio_device(pci_dev
);
627 for (i
= 0; i
< 3; i
++) {
628 register_ioport_write(addr
, 20, 1 << i
, virtio_ioport_write
, vdev
);
629 register_ioport_read(addr
, 20, 1 << i
, virtio_ioport_read
, vdev
);
632 if (vdev
->config_len
) {
633 register_ioport_write(addr
+ 20, vdev
->config_len
, 1,
634 virtio_config_writeb
, vdev
);
635 register_ioport_write(addr
+ 20, vdev
->config_len
, 2,
636 virtio_config_writew
, vdev
);
637 register_ioport_write(addr
+ 20, vdev
->config_len
, 4,
638 virtio_config_writel
, vdev
);
639 register_ioport_read(addr
+ 20, vdev
->config_len
, 1,
640 virtio_config_readb
, vdev
);
641 register_ioport_read(addr
+ 20, vdev
->config_len
, 2,
642 virtio_config_readw
, vdev
);
643 register_ioport_read(addr
+ 20, vdev
->config_len
, 4,
644 virtio_config_readl
, vdev
);
646 vdev
->get_config(vdev
, vdev
->config
);
650 VirtQueue
*virtio_add_queue(VirtIODevice
*vdev
, int queue_size
,
651 void (*handle_output
)(VirtIODevice
*, VirtQueue
*))
655 for (i
= 0; i
< VIRTIO_PCI_QUEUE_MAX
; i
++) {
656 if (vdev
->vq
[i
].vring
.num
== 0)
660 if (i
== VIRTIO_PCI_QUEUE_MAX
|| queue_size
> VIRTQUEUE_MAX_SIZE
)
663 vdev
->vq
[i
].vring
.num
= queue_size
;
664 vdev
->vq
[i
].handle_output
= handle_output
;
669 void virtio_notify(VirtIODevice
*vdev
, VirtQueue
*vq
)
671 /* Always notify when queue is empty (when feature acknowledge) */
672 if ((vring_avail_flags(vq
) & VRING_AVAIL_F_NO_INTERRUPT
) &&
673 (!(vdev
->features
& (1 << VIRTIO_F_NOTIFY_ON_EMPTY
)) ||
674 (vq
->inuse
|| vring_avail_idx(vq
) != vq
->last_avail_idx
)))
678 virtio_update_irq(vdev
);
681 void virtio_notify_config(VirtIODevice
*vdev
)
683 if (!(vdev
->status
& VIRTIO_CONFIG_S_DRIVER_OK
))
687 virtio_update_irq(vdev
);
690 void virtio_save(VirtIODevice
*vdev
, QEMUFile
*f
)
694 pci_device_save(&vdev
->pci_dev
, f
);
696 qemu_put_be32s(f
, &vdev
->addr
);
697 qemu_put_8s(f
, &vdev
->status
);
698 qemu_put_8s(f
, &vdev
->isr
);
699 qemu_put_be16s(f
, &vdev
->queue_sel
);
700 qemu_put_be32s(f
, &vdev
->features
);
701 qemu_put_be32(f
, vdev
->config_len
);
702 qemu_put_buffer(f
, vdev
->config
, vdev
->config_len
);
704 for (i
= 0; i
< VIRTIO_PCI_QUEUE_MAX
; i
++) {
705 if (vdev
->vq
[i
].vring
.num
== 0)
711 for (i
= 0; i
< VIRTIO_PCI_QUEUE_MAX
; i
++) {
712 if (vdev
->vq
[i
].vring
.num
== 0)
715 qemu_put_be32(f
, vdev
->vq
[i
].vring
.num
);
716 qemu_put_be32s(f
, &vdev
->vq
[i
].pfn
);
717 qemu_put_be16s(f
, &vdev
->vq
[i
].last_avail_idx
);
721 void virtio_load(VirtIODevice
*vdev
, QEMUFile
*f
)
725 pci_device_load(&vdev
->pci_dev
, f
);
727 qemu_get_be32s(f
, &vdev
->addr
);
728 qemu_get_8s(f
, &vdev
->status
);
729 qemu_get_8s(f
, &vdev
->isr
);
730 qemu_get_be16s(f
, &vdev
->queue_sel
);
731 qemu_get_be32s(f
, &vdev
->features
);
732 vdev
->config_len
= qemu_get_be32(f
);
733 qemu_get_buffer(f
, vdev
->config
, vdev
->config_len
);
735 num
= qemu_get_be32(f
);
737 for (i
= 0; i
< num
; i
++) {
738 vdev
->vq
[i
].vring
.num
= qemu_get_be32(f
);
739 qemu_get_be32s(f
, &vdev
->vq
[i
].pfn
);
740 qemu_get_be16s(f
, &vdev
->vq
[i
].last_avail_idx
);
742 if (vdev
->vq
[i
].pfn
) {
743 target_phys_addr_t pa
;
745 pa
= (ram_addr_t
)vdev
->vq
[i
].pfn
<< VIRTIO_PCI_QUEUE_ADDR_SHIFT
;
746 virtqueue_init(&vdev
->vq
[i
], pa
);
750 virtio_update_irq(vdev
);
753 void virtio_cleanup(VirtIODevice
*vdev
)
756 qemu_free(vdev
->config
);
760 VirtIODevice
*virtio_init_pci(PCIDevice
*pci_dev
, const char *name
,
761 uint16_t vendor
, uint16_t device
,
762 uint16_t subvendor
, uint16_t subdevice
,
763 uint16_t class_code
, uint8_t pif
,
770 vdev
= to_virtio_device(pci_dev
);
775 vdev
->vq
= qemu_mallocz(sizeof(VirtQueue
) * VIRTIO_PCI_QUEUE_MAX
);
777 config
= pci_dev
->config
;
778 pci_config_set_vendor_id(config
, vendor
);
779 pci_config_set_device_id(config
, device
);
781 config
[0x08] = VIRTIO_PCI_ABI_VERSION
;
784 pci_config_set_class(config
, class_code
);
785 config
[PCI_HEADER_TYPE
] = PCI_HEADER_TYPE_NORMAL
;
787 config
[0x2c] = subvendor
& 0xFF;
788 config
[0x2d] = (subvendor
>> 8) & 0xFF;
789 config
[0x2e] = subdevice
& 0xFF;
790 config
[0x2f] = (subdevice
>> 8) & 0xFF;
795 vdev
->config_len
= config_size
;
796 if (vdev
->config_len
)
797 vdev
->config
= qemu_mallocz(config_size
);
801 size
= 20 + config_size
;
803 size
= 1 << qemu_fls(size
);
805 pci_register_io_region(pci_dev
, 0, size
, PCI_ADDRESS_SPACE_IO
,
807 qemu_register_reset(virtio_reset
, vdev
);