Update to a hopefully more future proof FSF address
[qemu/aliguori-queue.git] / hw / virtio-pci.c
blob7ddf6122820f1c83e5696e0d1b084c3d8659c3c9
1 /*
2 * Virtio PCI Bindings
4 * Copyright IBM, Corp. 2007
5 * Copyright (c) 2009 CodeSourcery
7 * Authors:
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.
16 #include <inttypes.h>
18 #include "virtio.h"
19 #include "virtio-blk.h"
20 #include "virtio-net.h"
21 #include "pci.h"
22 #include "qemu-error.h"
23 #include "msix.h"
24 #include "net.h"
25 #include "block_int.h"
26 #include "loader.h"
27 #include "kvm.h"
29 /* from Linux's linux/virtio_pci.h */
31 /* A 32-bit r/o bitmask of the features supported by the host */
32 #define VIRTIO_PCI_HOST_FEATURES 0
34 /* A 32-bit r/w bitmask of features activated by the guest */
35 #define VIRTIO_PCI_GUEST_FEATURES 4
37 /* A 32-bit r/w PFN for the currently selected queue */
38 #define VIRTIO_PCI_QUEUE_PFN 8
40 /* A 16-bit r/o queue size for the currently selected queue */
41 #define VIRTIO_PCI_QUEUE_NUM 12
43 /* A 16-bit r/w queue selector */
44 #define VIRTIO_PCI_QUEUE_SEL 14
46 /* A 16-bit r/w queue notifier */
47 #define VIRTIO_PCI_QUEUE_NOTIFY 16
49 /* An 8-bit device status register. */
50 #define VIRTIO_PCI_STATUS 18
52 /* An 8-bit r/o interrupt status register. Reading the value will return the
53 * current contents of the ISR and will also clear it. This is effectively
54 * a read-and-acknowledge. */
55 #define VIRTIO_PCI_ISR 19
57 /* MSI-X registers: only enabled if MSI-X is enabled. */
58 /* A 16-bit vector for configuration changes. */
59 #define VIRTIO_MSI_CONFIG_VECTOR 20
60 /* A 16-bit vector for selected queue notifications. */
61 #define VIRTIO_MSI_QUEUE_VECTOR 22
63 /* Config space size */
64 #define VIRTIO_PCI_CONFIG_NOMSI 20
65 #define VIRTIO_PCI_CONFIG_MSI 24
66 #define VIRTIO_PCI_REGION_SIZE(dev) (msix_present(dev) ? \
67 VIRTIO_PCI_CONFIG_MSI : \
68 VIRTIO_PCI_CONFIG_NOMSI)
70 /* The remaining space is defined by each driver as the per-driver
71 * configuration space */
72 #define VIRTIO_PCI_CONFIG(dev) (msix_enabled(dev) ? \
73 VIRTIO_PCI_CONFIG_MSI : \
74 VIRTIO_PCI_CONFIG_NOMSI)
76 /* Virtio ABI version, if we increment this, we break the guest driver. */
77 #define VIRTIO_PCI_ABI_VERSION 0
79 /* How many bits to shift physical queue address written to QUEUE_PFN.
80 * 12 is historical, and due to x86 page size. */
81 #define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12
83 /* We can catch some guest bugs inside here so we continue supporting older
84 guests. */
85 #define VIRTIO_PCI_BUG_BUS_MASTER (1 << 0)
87 /* QEMU doesn't strictly need write barriers since everything runs in
88 * lock-step. We'll leave the calls to wmb() in though to make it obvious for
89 * KVM or if kqemu gets SMP support.
91 #define wmb() do { } while (0)
93 /* PCI bindings. */
95 typedef struct {
96 PCIDevice pci_dev;
97 VirtIODevice *vdev;
98 uint32_t bugs;
99 uint32_t addr;
100 uint32_t class_code;
101 uint32_t nvectors;
102 BlockConf block;
103 NICConf nic;
104 uint32_t host_features;
105 #ifdef CONFIG_LINUX
106 V9fsConf fsconf;
107 #endif
108 /* Max. number of ports we can have for a the virtio-serial device */
109 uint32_t max_virtserial_ports;
110 } VirtIOPCIProxy;
112 /* virtio device */
114 static void virtio_pci_notify(void *opaque, uint16_t vector)
116 VirtIOPCIProxy *proxy = opaque;
117 if (msix_enabled(&proxy->pci_dev))
118 msix_notify(&proxy->pci_dev, vector);
119 else
120 qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1);
123 static void virtio_pci_save_config(void * opaque, QEMUFile *f)
125 VirtIOPCIProxy *proxy = opaque;
126 pci_device_save(&proxy->pci_dev, f);
127 msix_save(&proxy->pci_dev, f);
128 if (msix_present(&proxy->pci_dev))
129 qemu_put_be16(f, proxy->vdev->config_vector);
132 static void virtio_pci_save_queue(void * opaque, int n, QEMUFile *f)
134 VirtIOPCIProxy *proxy = opaque;
135 if (msix_present(&proxy->pci_dev))
136 qemu_put_be16(f, virtio_queue_vector(proxy->vdev, n));
139 static int virtio_pci_load_config(void * opaque, QEMUFile *f)
141 VirtIOPCIProxy *proxy = opaque;
142 int ret;
143 ret = pci_device_load(&proxy->pci_dev, f);
144 if (ret) {
145 return ret;
147 msix_load(&proxy->pci_dev, f);
148 if (msix_present(&proxy->pci_dev)) {
149 qemu_get_be16s(f, &proxy->vdev->config_vector);
150 } else {
151 proxy->vdev->config_vector = VIRTIO_NO_VECTOR;
153 if (proxy->vdev->config_vector != VIRTIO_NO_VECTOR) {
154 return msix_vector_use(&proxy->pci_dev, proxy->vdev->config_vector);
157 /* Try to find out if the guest has bus master disabled, but is
158 in ready state. Then we have a buggy guest OS. */
159 if (!(proxy->vdev->status & VIRTIO_CONFIG_S_DRIVER_OK) &&
160 !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
161 proxy->bugs |= VIRTIO_PCI_BUG_BUS_MASTER;
163 return 0;
166 static int virtio_pci_load_queue(void * opaque, int n, QEMUFile *f)
168 VirtIOPCIProxy *proxy = opaque;
169 uint16_t vector;
170 if (msix_present(&proxy->pci_dev)) {
171 qemu_get_be16s(f, &vector);
172 } else {
173 vector = VIRTIO_NO_VECTOR;
175 virtio_queue_set_vector(proxy->vdev, n, vector);
176 if (vector != VIRTIO_NO_VECTOR) {
177 return msix_vector_use(&proxy->pci_dev, vector);
179 return 0;
182 static void virtio_pci_reset(DeviceState *d)
184 VirtIOPCIProxy *proxy = container_of(d, VirtIOPCIProxy, pci_dev.qdev);
185 virtio_reset(proxy->vdev);
186 msix_reset(&proxy->pci_dev);
187 proxy->bugs = 0;
190 static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
192 VirtIOPCIProxy *proxy = opaque;
193 VirtIODevice *vdev = proxy->vdev;
194 target_phys_addr_t pa;
196 switch (addr) {
197 case VIRTIO_PCI_GUEST_FEATURES:
198 /* Guest does not negotiate properly? We have to assume nothing. */
199 if (val & (1 << VIRTIO_F_BAD_FEATURE)) {
200 if (vdev->bad_features)
201 val = proxy->host_features & vdev->bad_features(vdev);
202 else
203 val = 0;
205 if (vdev->set_features)
206 vdev->set_features(vdev, val);
207 vdev->guest_features = val;
208 break;
209 case VIRTIO_PCI_QUEUE_PFN:
210 pa = (target_phys_addr_t)val << VIRTIO_PCI_QUEUE_ADDR_SHIFT;
211 if (pa == 0) {
212 virtio_reset(proxy->vdev);
213 msix_unuse_all_vectors(&proxy->pci_dev);
215 else
216 virtio_queue_set_addr(vdev, vdev->queue_sel, pa);
217 break;
218 case VIRTIO_PCI_QUEUE_SEL:
219 if (val < VIRTIO_PCI_QUEUE_MAX)
220 vdev->queue_sel = val;
221 break;
222 case VIRTIO_PCI_QUEUE_NOTIFY:
223 virtio_queue_notify(vdev, val);
224 break;
225 case VIRTIO_PCI_STATUS:
226 virtio_set_status(vdev, val & 0xFF);
227 if (vdev->status == 0) {
228 virtio_reset(proxy->vdev);
229 msix_unuse_all_vectors(&proxy->pci_dev);
232 /* Linux before 2.6.34 sets the device as OK without enabling
233 the PCI device bus master bit. In this case we need to disable
234 some safety checks. */
235 if ((val & VIRTIO_CONFIG_S_DRIVER_OK) &&
236 !(proxy->pci_dev.config[PCI_COMMAND] & PCI_COMMAND_MASTER)) {
237 proxy->bugs |= VIRTIO_PCI_BUG_BUS_MASTER;
239 break;
240 case VIRTIO_MSI_CONFIG_VECTOR:
241 msix_vector_unuse(&proxy->pci_dev, vdev->config_vector);
242 /* Make it possible for guest to discover an error took place. */
243 if (msix_vector_use(&proxy->pci_dev, val) < 0)
244 val = VIRTIO_NO_VECTOR;
245 vdev->config_vector = val;
246 break;
247 case VIRTIO_MSI_QUEUE_VECTOR:
248 msix_vector_unuse(&proxy->pci_dev,
249 virtio_queue_vector(vdev, vdev->queue_sel));
250 /* Make it possible for guest to discover an error took place. */
251 if (msix_vector_use(&proxy->pci_dev, val) < 0)
252 val = VIRTIO_NO_VECTOR;
253 virtio_queue_set_vector(vdev, vdev->queue_sel, val);
254 break;
255 default:
256 fprintf(stderr, "%s: unexpected address 0x%x value 0x%x\n",
257 __func__, addr, val);
258 break;
262 static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr)
264 VirtIODevice *vdev = proxy->vdev;
265 uint32_t ret = 0xFFFFFFFF;
267 switch (addr) {
268 case VIRTIO_PCI_HOST_FEATURES:
269 ret = proxy->host_features;
270 break;
271 case VIRTIO_PCI_GUEST_FEATURES:
272 ret = vdev->guest_features;
273 break;
274 case VIRTIO_PCI_QUEUE_PFN:
275 ret = virtio_queue_get_addr(vdev, vdev->queue_sel)
276 >> VIRTIO_PCI_QUEUE_ADDR_SHIFT;
277 break;
278 case VIRTIO_PCI_QUEUE_NUM:
279 ret = virtio_queue_get_num(vdev, vdev->queue_sel);
280 break;
281 case VIRTIO_PCI_QUEUE_SEL:
282 ret = vdev->queue_sel;
283 break;
284 case VIRTIO_PCI_STATUS:
285 ret = vdev->status;
286 break;
287 case VIRTIO_PCI_ISR:
288 /* reading from the ISR also clears it. */
289 ret = vdev->isr;
290 vdev->isr = 0;
291 qemu_set_irq(proxy->pci_dev.irq[0], 0);
292 break;
293 case VIRTIO_MSI_CONFIG_VECTOR:
294 ret = vdev->config_vector;
295 break;
296 case VIRTIO_MSI_QUEUE_VECTOR:
297 ret = virtio_queue_vector(vdev, vdev->queue_sel);
298 break;
299 default:
300 break;
303 return ret;
306 static uint32_t virtio_pci_config_readb(void *opaque, uint32_t addr)
308 VirtIOPCIProxy *proxy = opaque;
309 uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
310 addr -= proxy->addr;
311 if (addr < config)
312 return virtio_ioport_read(proxy, addr);
313 addr -= config;
314 return virtio_config_readb(proxy->vdev, addr);
317 static uint32_t virtio_pci_config_readw(void *opaque, uint32_t addr)
319 VirtIOPCIProxy *proxy = opaque;
320 uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
321 addr -= proxy->addr;
322 if (addr < config)
323 return virtio_ioport_read(proxy, addr);
324 addr -= config;
325 return virtio_config_readw(proxy->vdev, addr);
328 static uint32_t virtio_pci_config_readl(void *opaque, uint32_t addr)
330 VirtIOPCIProxy *proxy = opaque;
331 uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
332 addr -= proxy->addr;
333 if (addr < config)
334 return virtio_ioport_read(proxy, addr);
335 addr -= config;
336 return virtio_config_readl(proxy->vdev, addr);
339 static void virtio_pci_config_writeb(void *opaque, uint32_t addr, uint32_t val)
341 VirtIOPCIProxy *proxy = opaque;
342 uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
343 addr -= proxy->addr;
344 if (addr < config) {
345 virtio_ioport_write(proxy, addr, val);
346 return;
348 addr -= config;
349 virtio_config_writeb(proxy->vdev, addr, val);
352 static void virtio_pci_config_writew(void *opaque, uint32_t addr, uint32_t val)
354 VirtIOPCIProxy *proxy = opaque;
355 uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
356 addr -= proxy->addr;
357 if (addr < config) {
358 virtio_ioport_write(proxy, addr, val);
359 return;
361 addr -= config;
362 virtio_config_writew(proxy->vdev, addr, val);
365 static void virtio_pci_config_writel(void *opaque, uint32_t addr, uint32_t val)
367 VirtIOPCIProxy *proxy = opaque;
368 uint32_t config = VIRTIO_PCI_CONFIG(&proxy->pci_dev);
369 addr -= proxy->addr;
370 if (addr < config) {
371 virtio_ioport_write(proxy, addr, val);
372 return;
374 addr -= config;
375 virtio_config_writel(proxy->vdev, addr, val);
378 static void virtio_map(PCIDevice *pci_dev, int region_num,
379 pcibus_t addr, pcibus_t size, int type)
381 VirtIOPCIProxy *proxy = container_of(pci_dev, VirtIOPCIProxy, pci_dev);
382 VirtIODevice *vdev = proxy->vdev;
383 unsigned config_len = VIRTIO_PCI_REGION_SIZE(pci_dev) + vdev->config_len;
385 proxy->addr = addr;
387 register_ioport_write(addr, config_len, 1, virtio_pci_config_writeb, proxy);
388 register_ioport_write(addr, config_len, 2, virtio_pci_config_writew, proxy);
389 register_ioport_write(addr, config_len, 4, virtio_pci_config_writel, proxy);
390 register_ioport_read(addr, config_len, 1, virtio_pci_config_readb, proxy);
391 register_ioport_read(addr, config_len, 2, virtio_pci_config_readw, proxy);
392 register_ioport_read(addr, config_len, 4, virtio_pci_config_readl, proxy);
394 if (vdev->config_len)
395 vdev->get_config(vdev, vdev->config);
398 static void virtio_write_config(PCIDevice *pci_dev, uint32_t address,
399 uint32_t val, int len)
401 VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
403 if (PCI_COMMAND == address) {
404 if (!(val & PCI_COMMAND_MASTER)) {
405 if (!(proxy->bugs & VIRTIO_PCI_BUG_BUS_MASTER)) {
406 virtio_set_status(proxy->vdev,
407 proxy->vdev->status & ~VIRTIO_CONFIG_S_DRIVER_OK);
412 pci_default_write_config(pci_dev, address, val, len);
413 msix_write_config(pci_dev, address, val, len);
416 static unsigned virtio_pci_get_features(void *opaque)
418 VirtIOPCIProxy *proxy = opaque;
419 return proxy->host_features;
422 static void virtio_pci_guest_notifier_read(void *opaque)
424 VirtQueue *vq = opaque;
425 EventNotifier *n = virtio_queue_get_guest_notifier(vq);
426 if (event_notifier_test_and_clear(n)) {
427 virtio_irq(vq);
431 static int virtio_pci_set_guest_notifier(void *opaque, int n, bool assign)
433 VirtIOPCIProxy *proxy = opaque;
434 VirtQueue *vq = virtio_get_queue(proxy->vdev, n);
435 EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
437 if (assign) {
438 int r = event_notifier_init(notifier, 0);
439 if (r < 0) {
440 return r;
442 qemu_set_fd_handler(event_notifier_get_fd(notifier),
443 virtio_pci_guest_notifier_read, NULL, vq);
444 } else {
445 qemu_set_fd_handler(event_notifier_get_fd(notifier),
446 NULL, NULL, NULL);
447 event_notifier_cleanup(notifier);
450 return 0;
453 static int virtio_pci_set_host_notifier(void *opaque, int n, bool assign)
455 VirtIOPCIProxy *proxy = opaque;
456 VirtQueue *vq = virtio_get_queue(proxy->vdev, n);
457 EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
458 int r;
459 if (assign) {
460 r = event_notifier_init(notifier, 1);
461 if (r < 0) {
462 return r;
464 r = kvm_set_ioeventfd_pio_word(event_notifier_get_fd(notifier),
465 proxy->addr + VIRTIO_PCI_QUEUE_NOTIFY,
466 n, assign);
467 if (r < 0) {
468 event_notifier_cleanup(notifier);
470 } else {
471 r = kvm_set_ioeventfd_pio_word(event_notifier_get_fd(notifier),
472 proxy->addr + VIRTIO_PCI_QUEUE_NOTIFY,
473 n, assign);
474 if (r < 0) {
475 return r;
477 event_notifier_cleanup(notifier);
479 return r;
482 static const VirtIOBindings virtio_pci_bindings = {
483 .notify = virtio_pci_notify,
484 .save_config = virtio_pci_save_config,
485 .load_config = virtio_pci_load_config,
486 .save_queue = virtio_pci_save_queue,
487 .load_queue = virtio_pci_load_queue,
488 .get_features = virtio_pci_get_features,
489 .set_host_notifier = virtio_pci_set_host_notifier,
490 .set_guest_notifier = virtio_pci_set_guest_notifier,
493 static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,
494 uint16_t vendor, uint16_t device,
495 uint16_t class_code, uint8_t pif)
497 uint8_t *config;
498 uint32_t size;
500 proxy->vdev = vdev;
502 config = proxy->pci_dev.config;
503 pci_config_set_vendor_id(config, vendor);
504 pci_config_set_device_id(config, device);
506 config[0x08] = VIRTIO_PCI_ABI_VERSION;
508 config[0x09] = pif;
509 pci_config_set_class(config, class_code);
510 config[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL;
512 config[0x2c] = vendor & 0xFF;
513 config[0x2d] = (vendor >> 8) & 0xFF;
514 config[0x2e] = vdev->device_id & 0xFF;
515 config[0x2f] = (vdev->device_id >> 8) & 0xFF;
517 config[0x3d] = 1;
519 if (vdev->nvectors && !msix_init(&proxy->pci_dev, vdev->nvectors, 1, 0)) {
520 pci_register_bar(&proxy->pci_dev, 1,
521 msix_bar_size(&proxy->pci_dev),
522 PCI_BASE_ADDRESS_SPACE_MEMORY,
523 msix_mmio_map);
524 } else
525 vdev->nvectors = 0;
527 proxy->pci_dev.config_write = virtio_write_config;
529 size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev) + vdev->config_len;
530 if (size & (size-1))
531 size = 1 << qemu_fls(size);
533 pci_register_bar(&proxy->pci_dev, 0, size, PCI_BASE_ADDRESS_SPACE_IO,
534 virtio_map);
536 virtio_bind_device(vdev, &virtio_pci_bindings, proxy);
537 proxy->host_features |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY;
538 proxy->host_features |= 0x1 << VIRTIO_F_BAD_FEATURE;
539 proxy->host_features = vdev->get_features(vdev, proxy->host_features);
542 static int virtio_blk_init_pci(PCIDevice *pci_dev)
544 VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
545 VirtIODevice *vdev;
547 if (proxy->class_code != PCI_CLASS_STORAGE_SCSI &&
548 proxy->class_code != PCI_CLASS_STORAGE_OTHER)
549 proxy->class_code = PCI_CLASS_STORAGE_SCSI;
551 if (!proxy->block.dinfo) {
552 error_report("virtio-blk-pci: drive property not set");
553 return -1;
555 vdev = virtio_blk_init(&pci_dev->qdev, &proxy->block);
556 vdev->nvectors = proxy->nvectors;
557 virtio_init_pci(proxy, vdev,
558 PCI_VENDOR_ID_REDHAT_QUMRANET,
559 PCI_DEVICE_ID_VIRTIO_BLOCK,
560 proxy->class_code, 0x00);
561 /* make the actual value visible */
562 proxy->nvectors = vdev->nvectors;
563 return 0;
566 static int virtio_exit_pci(PCIDevice *pci_dev)
568 return msix_uninit(pci_dev);
571 static int virtio_blk_exit_pci(PCIDevice *pci_dev)
573 VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
575 drive_uninit(proxy->block.dinfo);
576 return virtio_exit_pci(pci_dev);
579 static int virtio_serial_init_pci(PCIDevice *pci_dev)
581 VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
582 VirtIODevice *vdev;
584 if (proxy->class_code != PCI_CLASS_COMMUNICATION_OTHER &&
585 proxy->class_code != PCI_CLASS_DISPLAY_OTHER && /* qemu 0.10 */
586 proxy->class_code != PCI_CLASS_OTHERS) /* qemu-kvm */
587 proxy->class_code = PCI_CLASS_COMMUNICATION_OTHER;
589 vdev = virtio_serial_init(&pci_dev->qdev, proxy->max_virtserial_ports);
590 if (!vdev) {
591 return -1;
593 vdev->nvectors = proxy->nvectors == DEV_NVECTORS_UNSPECIFIED
594 ? proxy->max_virtserial_ports + 1
595 : proxy->nvectors;
596 virtio_init_pci(proxy, vdev,
597 PCI_VENDOR_ID_REDHAT_QUMRANET,
598 PCI_DEVICE_ID_VIRTIO_CONSOLE,
599 proxy->class_code, 0x00);
600 proxy->nvectors = vdev->nvectors;
601 return 0;
604 static int virtio_net_init_pci(PCIDevice *pci_dev)
606 VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
607 VirtIODevice *vdev;
609 vdev = virtio_net_init(&pci_dev->qdev, &proxy->nic);
611 vdev->nvectors = proxy->nvectors;
612 virtio_init_pci(proxy, vdev,
613 PCI_VENDOR_ID_REDHAT_QUMRANET,
614 PCI_DEVICE_ID_VIRTIO_NET,
615 PCI_CLASS_NETWORK_ETHERNET,
616 0x00);
618 /* make the actual value visible */
619 proxy->nvectors = vdev->nvectors;
620 return 0;
623 static int virtio_net_exit_pci(PCIDevice *pci_dev)
625 VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
627 virtio_net_exit(proxy->vdev);
628 return virtio_exit_pci(pci_dev);
631 static int virtio_balloon_init_pci(PCIDevice *pci_dev)
633 VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
634 VirtIODevice *vdev;
636 vdev = virtio_balloon_init(&pci_dev->qdev);
637 virtio_init_pci(proxy, vdev,
638 PCI_VENDOR_ID_REDHAT_QUMRANET,
639 PCI_DEVICE_ID_VIRTIO_BALLOON,
640 PCI_CLASS_MEMORY_RAM,
641 0x00);
642 return 0;
645 #ifdef CONFIG_LINUX
646 static int virtio_9p_init_pci(PCIDevice *pci_dev)
648 VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
649 VirtIODevice *vdev;
651 vdev = virtio_9p_init(&pci_dev->qdev, &proxy->fsconf);
652 virtio_init_pci(proxy, vdev,
653 PCI_VENDOR_ID_REDHAT_QUMRANET,
654 0x1009,
655 0x2,
656 0x00);
658 return 0;
660 #endif
662 static PCIDeviceInfo virtio_info[] = {
664 .qdev.name = "virtio-blk-pci",
665 .qdev.size = sizeof(VirtIOPCIProxy),
666 .init = virtio_blk_init_pci,
667 .exit = virtio_blk_exit_pci,
668 .qdev.props = (Property[]) {
669 DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
670 DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, block),
671 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
672 DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
673 DEFINE_PROP_END_OF_LIST(),
675 .qdev.reset = virtio_pci_reset,
677 .qdev.name = "virtio-net-pci",
678 .qdev.size = sizeof(VirtIOPCIProxy),
679 .init = virtio_net_init_pci,
680 .exit = virtio_net_exit_pci,
681 .romfile = "pxe-virtio.bin",
682 .qdev.props = (Property[]) {
683 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
684 DEFINE_VIRTIO_NET_FEATURES(VirtIOPCIProxy, host_features),
685 DEFINE_NIC_PROPERTIES(VirtIOPCIProxy, nic),
686 DEFINE_PROP_END_OF_LIST(),
688 .qdev.reset = virtio_pci_reset,
690 .qdev.name = "virtio-serial-pci",
691 .qdev.alias = "virtio-serial",
692 .qdev.size = sizeof(VirtIOPCIProxy),
693 .init = virtio_serial_init_pci,
694 .exit = virtio_exit_pci,
695 .qdev.props = (Property[]) {
696 DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors,
697 DEV_NVECTORS_UNSPECIFIED),
698 DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
699 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
700 DEFINE_PROP_UINT32("max_ports", VirtIOPCIProxy, max_virtserial_ports,
701 31),
702 DEFINE_PROP_END_OF_LIST(),
704 .qdev.reset = virtio_pci_reset,
706 .qdev.name = "virtio-balloon-pci",
707 .qdev.size = sizeof(VirtIOPCIProxy),
708 .init = virtio_balloon_init_pci,
709 .exit = virtio_exit_pci,
710 .qdev.props = (Property[]) {
711 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
712 DEFINE_PROP_END_OF_LIST(),
714 .qdev.reset = virtio_pci_reset,
716 #ifdef CONFIG_LINUX
717 .qdev.name = "virtio-9p-pci",
718 .qdev.size = sizeof(VirtIOPCIProxy),
719 .init = virtio_9p_init_pci,
720 .qdev.props = (Property[]) {
721 DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features),
722 DEFINE_PROP_STRING("mount_tag", VirtIOPCIProxy, fsconf.tag),
723 DEFINE_PROP_STRING("fsdev", VirtIOPCIProxy, fsconf.fsdev_id),
724 DEFINE_PROP_END_OF_LIST(),
726 }, {
727 #endif
728 /* end of list */
732 static void virtio_pci_register_devices(void)
734 pci_qdev_register_many(virtio_info);
737 device_init(virtio_pci_register_devices)