4 * Copyright IBM, Corp. 2007
5 * Copyright (c) 2009 CodeSourcery
8 * Anthony Liguori <aliguori@us.ibm.com>
9 * Paul Brook <paul@codesourcery.com>
11 * This work is licensed under the terms of the GNU GPL, version 2. See
12 * the COPYING file in the top-level directory.
19 #include "virtio-blk.h"
20 #include "virtio-net.h"
22 #include "qemu-error.h"
28 /* from Linux's linux/virtio_pci.h */
30 /* A 32-bit r/o bitmask of the features supported by the host */
31 #define VIRTIO_PCI_HOST_FEATURES 0
33 /* A 32-bit r/w bitmask of features activated by the guest */
34 #define VIRTIO_PCI_GUEST_FEATURES 4
36 /* A 32-bit r/w PFN for the currently selected queue */
37 #define VIRTIO_PCI_QUEUE_PFN 8
39 /* A 16-bit r/o queue size for the currently selected queue */
40 #define VIRTIO_PCI_QUEUE_NUM 12
42 /* A 16-bit r/w queue selector */
43 #define VIRTIO_PCI_QUEUE_SEL 14
45 /* A 16-bit r/w queue notifier */
46 #define VIRTIO_PCI_QUEUE_NOTIFY 16
48 /* An 8-bit device status register. */
49 #define VIRTIO_PCI_STATUS 18
51 /* An 8-bit r/o interrupt status register. Reading the value will return the
52 * current contents of the ISR and will also clear it. This is effectively
53 * a read-and-acknowledge. */
54 #define VIRTIO_PCI_ISR 19
56 /* MSI-X registers: only enabled if MSI-X is enabled. */
57 /* A 16-bit vector for configuration changes. */
58 #define VIRTIO_MSI_CONFIG_VECTOR 20
59 /* A 16-bit vector for selected queue notifications. */
60 #define VIRTIO_MSI_QUEUE_VECTOR 22
62 /* Config space size */
63 #define VIRTIO_PCI_CONFIG_NOMSI 20
64 #define VIRTIO_PCI_CONFIG_MSI 24
65 #define VIRTIO_PCI_REGION_SIZE(dev) (msix_present(dev) ? \
66 VIRTIO_PCI_CONFIG_MSI : \
67 VIRTIO_PCI_CONFIG_NOMSI)
69 /* The remaining space is defined by each driver as the per-driver
70 * configuration space */
71 #define VIRTIO_PCI_CONFIG(dev) (msix_enabled(dev) ? \
72 VIRTIO_PCI_CONFIG_MSI : \
73 VIRTIO_PCI_CONFIG_NOMSI)
75 /* Virtio ABI version, if we increment this, we break the guest driver. */
76 #define VIRTIO_PCI_ABI_VERSION 0
78 /* How many bits to shift physical queue address written to QUEUE_PFN.
79 * 12 is historical, and due to x86 page size. */
80 #define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12
82 /* We can catch some guest bugs inside here so we continue supporting older
84 #define VIRTIO_PCI_BUG_BUS_MASTER (1 << 0)
86 /* QEMU doesn't strictly need write barriers since everything runs in
87 * lock-step. We'll leave the calls to wmb() in though to make it obvious for
88 * KVM or if kqemu gets SMP support.
90 #define wmb() do { } while (0)
103 uint32_t host_features
;
107 /* Max. number of ports we can have for a the virtio-serial device */
108 uint32_t max_virtserial_ports
;
113 static void virtio_pci_notify(void *opaque
, uint16_t vector
)
115 VirtIOPCIProxy
*proxy
= opaque
;
116 if (msix_enabled(&proxy
->pci_dev
))
117 msix_notify(&proxy
->pci_dev
, vector
);
119 qemu_set_irq(proxy
->pci_dev
.irq
[0], proxy
->vdev
->isr
& 1);
122 static void virtio_pci_save_config(void * opaque
, QEMUFile
*f
)
124 VirtIOPCIProxy
*proxy
= opaque
;
125 pci_device_save(&proxy
->pci_dev
, f
);
126 msix_save(&proxy
->pci_dev
, f
);
127 if (msix_present(&proxy
->pci_dev
))
128 qemu_put_be16(f
, proxy
->vdev
->config_vector
);
131 static void virtio_pci_save_queue(void * opaque
, int n
, QEMUFile
*f
)
133 VirtIOPCIProxy
*proxy
= opaque
;
134 if (msix_present(&proxy
->pci_dev
))
135 qemu_put_be16(f
, virtio_queue_vector(proxy
->vdev
, n
));
138 static int virtio_pci_load_config(void * opaque
, QEMUFile
*f
)
140 VirtIOPCIProxy
*proxy
= opaque
;
142 ret
= pci_device_load(&proxy
->pci_dev
, f
);
146 msix_load(&proxy
->pci_dev
, f
);
147 if (msix_present(&proxy
->pci_dev
)) {
148 qemu_get_be16s(f
, &proxy
->vdev
->config_vector
);
150 proxy
->vdev
->config_vector
= VIRTIO_NO_VECTOR
;
152 if (proxy
->vdev
->config_vector
!= VIRTIO_NO_VECTOR
) {
153 return msix_vector_use(&proxy
->pci_dev
, proxy
->vdev
->config_vector
);
156 /* Try to find out if the guest has bus master disabled, but is
157 in ready state. Then we have a buggy guest OS. */
158 if ((proxy
->vdev
->status
& VIRTIO_CONFIG_S_DRIVER_OK
) &&
159 !(proxy
->pci_dev
.config
[PCI_COMMAND
] & PCI_COMMAND_MASTER
)) {
160 proxy
->bugs
|= VIRTIO_PCI_BUG_BUS_MASTER
;
165 static int virtio_pci_load_queue(void * opaque
, int n
, QEMUFile
*f
)
167 VirtIOPCIProxy
*proxy
= opaque
;
169 if (msix_present(&proxy
->pci_dev
)) {
170 qemu_get_be16s(f
, &vector
);
172 vector
= VIRTIO_NO_VECTOR
;
174 virtio_queue_set_vector(proxy
->vdev
, n
, vector
);
175 if (vector
!= VIRTIO_NO_VECTOR
) {
176 return msix_vector_use(&proxy
->pci_dev
, vector
);
181 static void virtio_pci_reset(DeviceState
*d
)
183 VirtIOPCIProxy
*proxy
= container_of(d
, VirtIOPCIProxy
, pci_dev
.qdev
);
184 virtio_reset(proxy
->vdev
);
185 msix_reset(&proxy
->pci_dev
);
189 static void virtio_ioport_write(void *opaque
, uint32_t addr
, uint32_t val
)
191 VirtIOPCIProxy
*proxy
= opaque
;
192 VirtIODevice
*vdev
= proxy
->vdev
;
193 target_phys_addr_t pa
;
196 case VIRTIO_PCI_GUEST_FEATURES
:
197 /* Guest does not negotiate properly? We have to assume nothing. */
198 if (val
& (1 << VIRTIO_F_BAD_FEATURE
)) {
199 if (vdev
->bad_features
)
200 val
= proxy
->host_features
& vdev
->bad_features(vdev
);
204 if (vdev
->set_features
)
205 vdev
->set_features(vdev
, val
);
206 vdev
->guest_features
= val
;
208 case VIRTIO_PCI_QUEUE_PFN
:
209 pa
= (target_phys_addr_t
)val
<< VIRTIO_PCI_QUEUE_ADDR_SHIFT
;
211 virtio_reset(proxy
->vdev
);
212 msix_unuse_all_vectors(&proxy
->pci_dev
);
215 virtio_queue_set_addr(vdev
, vdev
->queue_sel
, pa
);
217 case VIRTIO_PCI_QUEUE_SEL
:
218 if (val
< VIRTIO_PCI_QUEUE_MAX
)
219 vdev
->queue_sel
= val
;
221 case VIRTIO_PCI_QUEUE_NOTIFY
:
222 virtio_queue_notify(vdev
, val
);
224 case VIRTIO_PCI_STATUS
:
225 virtio_set_status(vdev
, val
& 0xFF);
226 if (vdev
->status
== 0) {
227 virtio_reset(proxy
->vdev
);
228 msix_unuse_all_vectors(&proxy
->pci_dev
);
231 /* Linux before 2.6.34 sets the device as OK without enabling
232 the PCI device bus master bit. In this case we need to disable
233 some safety checks. */
234 if ((val
& VIRTIO_CONFIG_S_DRIVER_OK
) &&
235 !(proxy
->pci_dev
.config
[PCI_COMMAND
] & PCI_COMMAND_MASTER
)) {
236 proxy
->bugs
|= VIRTIO_PCI_BUG_BUS_MASTER
;
239 case VIRTIO_MSI_CONFIG_VECTOR
:
240 msix_vector_unuse(&proxy
->pci_dev
, vdev
->config_vector
);
241 /* Make it possible for guest to discover an error took place. */
242 if (msix_vector_use(&proxy
->pci_dev
, val
) < 0)
243 val
= VIRTIO_NO_VECTOR
;
244 vdev
->config_vector
= val
;
246 case VIRTIO_MSI_QUEUE_VECTOR
:
247 msix_vector_unuse(&proxy
->pci_dev
,
248 virtio_queue_vector(vdev
, vdev
->queue_sel
));
249 /* Make it possible for guest to discover an error took place. */
250 if (msix_vector_use(&proxy
->pci_dev
, val
) < 0)
251 val
= VIRTIO_NO_VECTOR
;
252 virtio_queue_set_vector(vdev
, vdev
->queue_sel
, val
);
255 fprintf(stderr
, "%s: unexpected address 0x%x value 0x%x\n",
256 __func__
, addr
, val
);
261 static uint32_t virtio_ioport_read(VirtIOPCIProxy
*proxy
, uint32_t addr
)
263 VirtIODevice
*vdev
= proxy
->vdev
;
264 uint32_t ret
= 0xFFFFFFFF;
267 case VIRTIO_PCI_HOST_FEATURES
:
268 ret
= proxy
->host_features
;
270 case VIRTIO_PCI_GUEST_FEATURES
:
271 ret
= vdev
->guest_features
;
273 case VIRTIO_PCI_QUEUE_PFN
:
274 ret
= virtio_queue_get_addr(vdev
, vdev
->queue_sel
)
275 >> VIRTIO_PCI_QUEUE_ADDR_SHIFT
;
277 case VIRTIO_PCI_QUEUE_NUM
:
278 ret
= virtio_queue_get_num(vdev
, vdev
->queue_sel
);
280 case VIRTIO_PCI_QUEUE_SEL
:
281 ret
= vdev
->queue_sel
;
283 case VIRTIO_PCI_STATUS
:
287 /* reading from the ISR also clears it. */
290 qemu_set_irq(proxy
->pci_dev
.irq
[0], 0);
292 case VIRTIO_MSI_CONFIG_VECTOR
:
293 ret
= vdev
->config_vector
;
295 case VIRTIO_MSI_QUEUE_VECTOR
:
296 ret
= virtio_queue_vector(vdev
, vdev
->queue_sel
);
305 static uint32_t virtio_pci_config_readb(void *opaque
, uint32_t addr
)
307 VirtIOPCIProxy
*proxy
= opaque
;
308 uint32_t config
= VIRTIO_PCI_CONFIG(&proxy
->pci_dev
);
311 return virtio_ioport_read(proxy
, addr
);
313 return virtio_config_readb(proxy
->vdev
, addr
);
316 static uint32_t virtio_pci_config_readw(void *opaque
, uint32_t addr
)
318 VirtIOPCIProxy
*proxy
= opaque
;
319 uint32_t config
= VIRTIO_PCI_CONFIG(&proxy
->pci_dev
);
322 return virtio_ioport_read(proxy
, addr
);
324 return virtio_config_readw(proxy
->vdev
, addr
);
327 static uint32_t virtio_pci_config_readl(void *opaque
, uint32_t addr
)
329 VirtIOPCIProxy
*proxy
= opaque
;
330 uint32_t config
= VIRTIO_PCI_CONFIG(&proxy
->pci_dev
);
333 return virtio_ioport_read(proxy
, addr
);
335 return virtio_config_readl(proxy
->vdev
, addr
);
338 static void virtio_pci_config_writeb(void *opaque
, uint32_t addr
, uint32_t val
)
340 VirtIOPCIProxy
*proxy
= opaque
;
341 uint32_t config
= VIRTIO_PCI_CONFIG(&proxy
->pci_dev
);
344 virtio_ioport_write(proxy
, addr
, val
);
348 virtio_config_writeb(proxy
->vdev
, addr
, val
);
351 static void virtio_pci_config_writew(void *opaque
, uint32_t addr
, uint32_t val
)
353 VirtIOPCIProxy
*proxy
= opaque
;
354 uint32_t config
= VIRTIO_PCI_CONFIG(&proxy
->pci_dev
);
357 virtio_ioport_write(proxy
, addr
, val
);
361 virtio_config_writew(proxy
->vdev
, addr
, val
);
364 static void virtio_pci_config_writel(void *opaque
, uint32_t addr
, uint32_t val
)
366 VirtIOPCIProxy
*proxy
= opaque
;
367 uint32_t config
= VIRTIO_PCI_CONFIG(&proxy
->pci_dev
);
370 virtio_ioport_write(proxy
, addr
, val
);
374 virtio_config_writel(proxy
->vdev
, addr
, val
);
377 static void virtio_map(PCIDevice
*pci_dev
, int region_num
,
378 pcibus_t addr
, pcibus_t size
, int type
)
380 VirtIOPCIProxy
*proxy
= container_of(pci_dev
, VirtIOPCIProxy
, pci_dev
);
381 VirtIODevice
*vdev
= proxy
->vdev
;
382 unsigned config_len
= VIRTIO_PCI_REGION_SIZE(pci_dev
) + vdev
->config_len
;
386 register_ioport_write(addr
, config_len
, 1, virtio_pci_config_writeb
, proxy
);
387 register_ioport_write(addr
, config_len
, 2, virtio_pci_config_writew
, proxy
);
388 register_ioport_write(addr
, config_len
, 4, virtio_pci_config_writel
, proxy
);
389 register_ioport_read(addr
, config_len
, 1, virtio_pci_config_readb
, proxy
);
390 register_ioport_read(addr
, config_len
, 2, virtio_pci_config_readw
, proxy
);
391 register_ioport_read(addr
, config_len
, 4, virtio_pci_config_readl
, proxy
);
393 if (vdev
->config_len
)
394 vdev
->get_config(vdev
, vdev
->config
);
397 static void virtio_write_config(PCIDevice
*pci_dev
, uint32_t address
,
398 uint32_t val
, int len
)
400 VirtIOPCIProxy
*proxy
= DO_UPCAST(VirtIOPCIProxy
, pci_dev
, pci_dev
);
402 if (PCI_COMMAND
== address
) {
403 if (!(val
& PCI_COMMAND_MASTER
)) {
404 if (!(proxy
->bugs
& VIRTIO_PCI_BUG_BUS_MASTER
)) {
405 virtio_set_status(proxy
->vdev
,
406 proxy
->vdev
->status
& ~VIRTIO_CONFIG_S_DRIVER_OK
);
411 pci_default_write_config(pci_dev
, address
, val
, len
);
412 msix_write_config(pci_dev
, address
, val
, len
);
415 static unsigned virtio_pci_get_features(void *opaque
)
417 VirtIOPCIProxy
*proxy
= opaque
;
418 return proxy
->host_features
;
421 static void virtio_pci_guest_notifier_read(void *opaque
)
423 VirtQueue
*vq
= opaque
;
424 EventNotifier
*n
= virtio_queue_get_guest_notifier(vq
);
425 if (event_notifier_test_and_clear(n
)) {
430 static int virtio_pci_set_guest_notifier(void *opaque
, int n
, bool assign
)
432 VirtIOPCIProxy
*proxy
= opaque
;
433 VirtQueue
*vq
= virtio_get_queue(proxy
->vdev
, n
);
434 EventNotifier
*notifier
= virtio_queue_get_guest_notifier(vq
);
437 int r
= event_notifier_init(notifier
, 0);
441 qemu_set_fd_handler(event_notifier_get_fd(notifier
),
442 virtio_pci_guest_notifier_read
, NULL
, vq
);
444 qemu_set_fd_handler(event_notifier_get_fd(notifier
),
446 event_notifier_cleanup(notifier
);
452 static int virtio_pci_set_host_notifier(void *opaque
, int n
, bool assign
)
454 VirtIOPCIProxy
*proxy
= opaque
;
455 VirtQueue
*vq
= virtio_get_queue(proxy
->vdev
, n
);
456 EventNotifier
*notifier
= virtio_queue_get_host_notifier(vq
);
459 r
= event_notifier_init(notifier
, 1);
463 r
= kvm_set_ioeventfd_pio_word(event_notifier_get_fd(notifier
),
464 proxy
->addr
+ VIRTIO_PCI_QUEUE_NOTIFY
,
467 event_notifier_cleanup(notifier
);
470 r
= kvm_set_ioeventfd_pio_word(event_notifier_get_fd(notifier
),
471 proxy
->addr
+ VIRTIO_PCI_QUEUE_NOTIFY
,
476 event_notifier_cleanup(notifier
);
481 static const VirtIOBindings virtio_pci_bindings
= {
482 .notify
= virtio_pci_notify
,
483 .save_config
= virtio_pci_save_config
,
484 .load_config
= virtio_pci_load_config
,
485 .save_queue
= virtio_pci_save_queue
,
486 .load_queue
= virtio_pci_load_queue
,
487 .get_features
= virtio_pci_get_features
,
488 .set_host_notifier
= virtio_pci_set_host_notifier
,
489 .set_guest_notifier
= virtio_pci_set_guest_notifier
,
492 static void virtio_init_pci(VirtIOPCIProxy
*proxy
, VirtIODevice
*vdev
,
493 uint16_t vendor
, uint16_t device
,
494 uint16_t class_code
, uint8_t pif
)
501 config
= proxy
->pci_dev
.config
;
502 pci_config_set_vendor_id(config
, vendor
);
503 pci_config_set_device_id(config
, device
);
505 config
[0x08] = VIRTIO_PCI_ABI_VERSION
;
508 pci_config_set_class(config
, class_code
);
510 config
[0x2c] = vendor
& 0xFF;
511 config
[0x2d] = (vendor
>> 8) & 0xFF;
512 config
[0x2e] = vdev
->device_id
& 0xFF;
513 config
[0x2f] = (vdev
->device_id
>> 8) & 0xFF;
517 if (vdev
->nvectors
&& !msix_init(&proxy
->pci_dev
, vdev
->nvectors
, 1, 0)) {
518 pci_register_bar(&proxy
->pci_dev
, 1,
519 msix_bar_size(&proxy
->pci_dev
),
520 PCI_BASE_ADDRESS_SPACE_MEMORY
,
525 proxy
->pci_dev
.config_write
= virtio_write_config
;
527 size
= VIRTIO_PCI_REGION_SIZE(&proxy
->pci_dev
) + vdev
->config_len
;
529 size
= 1 << qemu_fls(size
);
531 pci_register_bar(&proxy
->pci_dev
, 0, size
, PCI_BASE_ADDRESS_SPACE_IO
,
534 virtio_bind_device(vdev
, &virtio_pci_bindings
, proxy
);
535 proxy
->host_features
|= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY
;
536 proxy
->host_features
|= 0x1 << VIRTIO_F_BAD_FEATURE
;
537 proxy
->host_features
= vdev
->get_features(vdev
, proxy
->host_features
);
540 static int virtio_blk_init_pci(PCIDevice
*pci_dev
)
542 VirtIOPCIProxy
*proxy
= DO_UPCAST(VirtIOPCIProxy
, pci_dev
, pci_dev
);
545 if (proxy
->class_code
!= PCI_CLASS_STORAGE_SCSI
&&
546 proxy
->class_code
!= PCI_CLASS_STORAGE_OTHER
)
547 proxy
->class_code
= PCI_CLASS_STORAGE_SCSI
;
549 vdev
= virtio_blk_init(&pci_dev
->qdev
, &proxy
->block
);
553 vdev
->nvectors
= proxy
->nvectors
;
554 virtio_init_pci(proxy
, vdev
,
555 PCI_VENDOR_ID_REDHAT_QUMRANET
,
556 PCI_DEVICE_ID_VIRTIO_BLOCK
,
557 proxy
->class_code
, 0x00);
558 /* make the actual value visible */
559 proxy
->nvectors
= vdev
->nvectors
;
563 static int virtio_exit_pci(PCIDevice
*pci_dev
)
565 return msix_uninit(pci_dev
);
568 static int virtio_blk_exit_pci(PCIDevice
*pci_dev
)
570 VirtIOPCIProxy
*proxy
= DO_UPCAST(VirtIOPCIProxy
, pci_dev
, pci_dev
);
572 virtio_blk_exit(proxy
->vdev
);
573 blockdev_mark_auto_del(proxy
->block
.bs
);
574 return virtio_exit_pci(pci_dev
);
577 static int virtio_serial_init_pci(PCIDevice
*pci_dev
)
579 VirtIOPCIProxy
*proxy
= DO_UPCAST(VirtIOPCIProxy
, pci_dev
, pci_dev
);
582 if (proxy
->class_code
!= PCI_CLASS_COMMUNICATION_OTHER
&&
583 proxy
->class_code
!= PCI_CLASS_DISPLAY_OTHER
&& /* qemu 0.10 */
584 proxy
->class_code
!= PCI_CLASS_OTHERS
) /* qemu-kvm */
585 proxy
->class_code
= PCI_CLASS_COMMUNICATION_OTHER
;
587 vdev
= virtio_serial_init(&pci_dev
->qdev
, proxy
->max_virtserial_ports
);
591 vdev
->nvectors
= proxy
->nvectors
== DEV_NVECTORS_UNSPECIFIED
592 ? proxy
->max_virtserial_ports
+ 1
594 virtio_init_pci(proxy
, vdev
,
595 PCI_VENDOR_ID_REDHAT_QUMRANET
,
596 PCI_DEVICE_ID_VIRTIO_CONSOLE
,
597 proxy
->class_code
, 0x00);
598 proxy
->nvectors
= vdev
->nvectors
;
602 static int virtio_serial_exit_pci(PCIDevice
*pci_dev
)
604 VirtIOPCIProxy
*proxy
= DO_UPCAST(VirtIOPCIProxy
, pci_dev
, pci_dev
);
606 virtio_serial_exit(proxy
->vdev
);
607 return virtio_exit_pci(pci_dev
);
610 static int virtio_net_init_pci(PCIDevice
*pci_dev
)
612 VirtIOPCIProxy
*proxy
= DO_UPCAST(VirtIOPCIProxy
, pci_dev
, pci_dev
);
615 vdev
= virtio_net_init(&pci_dev
->qdev
, &proxy
->nic
);
617 vdev
->nvectors
= proxy
->nvectors
;
618 virtio_init_pci(proxy
, vdev
,
619 PCI_VENDOR_ID_REDHAT_QUMRANET
,
620 PCI_DEVICE_ID_VIRTIO_NET
,
621 PCI_CLASS_NETWORK_ETHERNET
,
624 /* make the actual value visible */
625 proxy
->nvectors
= vdev
->nvectors
;
629 static int virtio_net_exit_pci(PCIDevice
*pci_dev
)
631 VirtIOPCIProxy
*proxy
= DO_UPCAST(VirtIOPCIProxy
, pci_dev
, pci_dev
);
633 virtio_net_exit(proxy
->vdev
);
634 return virtio_exit_pci(pci_dev
);
637 static int virtio_balloon_init_pci(PCIDevice
*pci_dev
)
639 VirtIOPCIProxy
*proxy
= DO_UPCAST(VirtIOPCIProxy
, pci_dev
, pci_dev
);
642 vdev
= virtio_balloon_init(&pci_dev
->qdev
);
643 virtio_init_pci(proxy
, vdev
,
644 PCI_VENDOR_ID_REDHAT_QUMRANET
,
645 PCI_DEVICE_ID_VIRTIO_BALLOON
,
646 PCI_CLASS_MEMORY_RAM
,
652 static int virtio_9p_init_pci(PCIDevice
*pci_dev
)
654 VirtIOPCIProxy
*proxy
= DO_UPCAST(VirtIOPCIProxy
, pci_dev
, pci_dev
);
657 vdev
= virtio_9p_init(&pci_dev
->qdev
, &proxy
->fsconf
);
658 virtio_init_pci(proxy
, vdev
,
659 PCI_VENDOR_ID_REDHAT_QUMRANET
,
668 static PCIDeviceInfo virtio_info
[] = {
670 .qdev
.name
= "virtio-blk-pci",
671 .qdev
.size
= sizeof(VirtIOPCIProxy
),
672 .init
= virtio_blk_init_pci
,
673 .exit
= virtio_blk_exit_pci
,
674 .qdev
.props
= (Property
[]) {
675 DEFINE_PROP_HEX32("class", VirtIOPCIProxy
, class_code
, 0),
676 DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy
, block
),
677 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy
, nvectors
, 2),
678 DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy
, host_features
),
679 DEFINE_PROP_END_OF_LIST(),
681 .qdev
.reset
= virtio_pci_reset
,
683 .qdev
.name
= "virtio-net-pci",
684 .qdev
.size
= sizeof(VirtIOPCIProxy
),
685 .init
= virtio_net_init_pci
,
686 .exit
= virtio_net_exit_pci
,
687 .romfile
= "pxe-virtio.bin",
688 .qdev
.props
= (Property
[]) {
689 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy
, nvectors
, 3),
690 DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy
, host_features
),
691 DEFINE_NIC_PROPERTIES(VirtIOPCIProxy
, nic
),
692 DEFINE_PROP_END_OF_LIST(),
694 .qdev
.reset
= virtio_pci_reset
,
696 .qdev
.name
= "virtio-serial-pci",
697 .qdev
.alias
= "virtio-serial",
698 .qdev
.size
= sizeof(VirtIOPCIProxy
),
699 .init
= virtio_serial_init_pci
,
700 .exit
= virtio_serial_exit_pci
,
701 .qdev
.props
= (Property
[]) {
702 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy
, nvectors
,
703 DEV_NVECTORS_UNSPECIFIED
),
704 DEFINE_PROP_HEX32("class", VirtIOPCIProxy
, class_code
, 0),
705 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy
, host_features
),
706 DEFINE_PROP_UINT32("max_ports", VirtIOPCIProxy
, max_virtserial_ports
,
708 DEFINE_PROP_END_OF_LIST(),
710 .qdev
.reset
= virtio_pci_reset
,
712 .qdev
.name
= "virtio-balloon-pci",
713 .qdev
.size
= sizeof(VirtIOPCIProxy
),
714 .init
= virtio_balloon_init_pci
,
715 .exit
= virtio_exit_pci
,
716 .qdev
.props
= (Property
[]) {
717 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy
, host_features
),
718 DEFINE_PROP_END_OF_LIST(),
720 .qdev
.reset
= virtio_pci_reset
,
723 .qdev
.name
= "virtio-9p-pci",
724 .qdev
.size
= sizeof(VirtIOPCIProxy
),
725 .init
= virtio_9p_init_pci
,
726 .qdev
.props
= (Property
[]) {
727 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy
, host_features
),
728 DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy
, fsconf
.tag
),
729 DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy
, fsconf
.fsdev_id
),
730 DEFINE_PROP_END_OF_LIST(),
738 static void virtio_pci_register_devices(void)
740 pci_qdev_register_many(virtio_info
);
743 device_init(virtio_pci_register_devices
)