Commit cf21e106cd9b34a12a533191932a8a08a1f5ebe4
1 parent
9d07d757
Virtio-net qdev conversion
Signed-off-by: Paul Brook <paul@codesourcery.com>
Showing
8 changed files
with
40 additions
and
32 deletions
hw/pci.c
hw/virtio-balloon.c
... | ... | @@ -172,16 +172,20 @@ static int virtio_balloon_load(QEMUFile *f, void *opaque, int version_id) |
172 | 172 | void *virtio_balloon_init(PCIBus *bus) |
173 | 173 | { |
174 | 174 | VirtIOBalloon *s; |
175 | + PCIDevice *d; | |
175 | 176 | |
176 | - s = (VirtIOBalloon *)virtio_init_pci(bus, "virtio-balloon", | |
177 | + d = pci_register_device(bus, "virtio-balloon", sizeof(VirtIOBalloon), | |
178 | + -1, NULL, NULL); | |
179 | + if (!d) | |
180 | + return NULL; | |
181 | + | |
182 | + s = (VirtIOBalloon *)virtio_init_pci(d, "virtio-balloon", | |
177 | 183 | PCI_VENDOR_ID_REDHAT_QUMRANET, |
178 | 184 | PCI_DEVICE_ID_VIRTIO_BALLOON, |
179 | 185 | PCI_VENDOR_ID_REDHAT_QUMRANET, |
180 | 186 | VIRTIO_ID_BALLOON, |
181 | 187 | PCI_CLASS_MEMORY_RAM, 0x00, |
182 | - 8, sizeof(VirtIOBalloon)); | |
183 | - if (s == NULL) | |
184 | - return NULL; | |
188 | + 8); | |
185 | 189 | |
186 | 190 | s->vdev.get_config = virtio_balloon_get_config; |
187 | 191 | s->vdev.set_config = virtio_balloon_set_config; | ... | ... |
hw/virtio-blk.c
... | ... | @@ -353,16 +353,20 @@ void *virtio_blk_init(PCIBus *bus, BlockDriverState *bs) |
353 | 353 | VirtIOBlock *s; |
354 | 354 | int cylinders, heads, secs; |
355 | 355 | static int virtio_blk_id; |
356 | + PCIDevice *d; | |
356 | 357 | |
357 | - s = (VirtIOBlock *)virtio_init_pci(bus, "virtio-blk", | |
358 | + d = pci_register_device(bus, "virtio-blk", sizeof(VirtIOBlock), | |
359 | + -1, NULL, NULL); | |
360 | + if (!d) | |
361 | + return NULL; | |
362 | + | |
363 | + s = (VirtIOBlock *)virtio_init_pci(d, "virtio-blk", | |
358 | 364 | PCI_VENDOR_ID_REDHAT_QUMRANET, |
359 | 365 | PCI_DEVICE_ID_VIRTIO_BLOCK, |
360 | 366 | PCI_VENDOR_ID_REDHAT_QUMRANET, |
361 | 367 | VIRTIO_ID_BLOCK, |
362 | 368 | PCI_CLASS_STORAGE_OTHER, 0x00, |
363 | - sizeof(struct virtio_blk_config), sizeof(VirtIOBlock)); | |
364 | - if (!s) | |
365 | - return NULL; | |
369 | + sizeof(struct virtio_blk_config)); | |
366 | 370 | |
367 | 371 | s->vdev.get_config = virtio_blk_update_config; |
368 | 372 | s->vdev.get_features = virtio_blk_get_features; | ... | ... |
hw/virtio-console.c
... | ... | @@ -126,14 +126,20 @@ static int virtio_console_load(QEMUFile *f, void *opaque, int version_id) |
126 | 126 | void *virtio_console_init(PCIBus *bus, CharDriverState *chr) |
127 | 127 | { |
128 | 128 | VirtIOConsole *s; |
129 | + PCIDevice *d; | |
129 | 130 | |
130 | - s = (VirtIOConsole *)virtio_init_pci(bus, "virtio-console", | |
131 | + d = pci_register_device(bus, "virtio-console", sizeof(VirtIOConsole), | |
132 | + -1, NULL, NULL); | |
133 | + if (!d) | |
134 | + return NULL; | |
135 | + | |
136 | + s = (VirtIOConsole *)virtio_init_pci(d, "virtio-console", | |
131 | 137 | PCI_VENDOR_ID_REDHAT_QUMRANET, |
132 | 138 | PCI_DEVICE_ID_VIRTIO_CONSOLE, |
133 | 139 | PCI_VENDOR_ID_REDHAT_QUMRANET, |
134 | 140 | VIRTIO_ID_CONSOLE, |
135 | 141 | PCI_CLASS_DISPLAY_OTHER, 0x00, |
136 | - 0, sizeof(VirtIOConsole)); | |
142 | + 0); | |
137 | 143 | if (s == NULL) |
138 | 144 | return NULL; |
139 | 145 | ... | ... |
hw/virtio-net.c
... | ... | @@ -585,21 +585,18 @@ static void virtio_net_cleanup(VLANClientState *vc) |
585 | 585 | virtio_cleanup(&n->vdev); |
586 | 586 | } |
587 | 587 | |
588 | -PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn) | |
588 | +static void virtio_net_init(PCIDevice *pci_dev) | |
589 | 589 | { |
590 | 590 | VirtIONet *n; |
591 | 591 | static int virtio_net_id; |
592 | 592 | |
593 | - n = (VirtIONet *)virtio_init_pci(bus, "virtio-net", | |
593 | + n = (VirtIONet *)virtio_init_pci(pci_dev, "virtio-net", | |
594 | 594 | PCI_VENDOR_ID_REDHAT_QUMRANET, |
595 | 595 | PCI_DEVICE_ID_VIRTIO_NET, |
596 | 596 | PCI_VENDOR_ID_REDHAT_QUMRANET, |
597 | 597 | VIRTIO_ID_NET, |
598 | 598 | PCI_CLASS_NETWORK_ETHERNET, 0x00, |
599 | - sizeof(struct virtio_net_config), | |
600 | - sizeof(VirtIONet)); | |
601 | - if (!n) | |
602 | - return NULL; | |
599 | + sizeof(struct virtio_net_config)); | |
603 | 600 | |
604 | 601 | n->vdev.get_config = virtio_net_get_config; |
605 | 602 | n->vdev.set_config = virtio_net_set_config; |
... | ... | @@ -610,9 +607,9 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn) |
610 | 607 | n->rx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_rx); |
611 | 608 | n->tx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_tx); |
612 | 609 | n->ctrl_vq = virtio_add_queue(&n->vdev, 16, virtio_net_handle_ctrl); |
613 | - memcpy(n->mac, nd->macaddr, ETH_ALEN); | |
610 | + qdev_get_macaddr(&pci_dev->qdev, n->mac); | |
614 | 611 | n->status = VIRTIO_NET_S_LINK_UP; |
615 | - n->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, | |
612 | + n->vc = qdev_get_vlan_client(&pci_dev->qdev, | |
616 | 613 | virtio_net_receive, |
617 | 614 | virtio_net_can_receive, |
618 | 615 | virtio_net_cleanup, n); |
... | ... | @@ -631,5 +628,11 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn) |
631 | 628 | |
632 | 629 | register_savevm("virtio-net", virtio_net_id++, VIRTIO_NET_VM_VERSION, |
633 | 630 | virtio_net_save, virtio_net_load, n); |
634 | - return (PCIDevice *)n; | |
635 | 631 | } |
632 | + | |
633 | +static void virtio_net_register_devices(void) | |
634 | +{ | |
635 | + pci_qdev_register("virtio_net", sizeof(VirtIONet), virtio_net_init); | |
636 | +} | |
637 | + | |
638 | +device_init(virtio_net_register_devices) | ... | ... |
hw/virtio-net.h
hw/virtio.c
... | ... | @@ -757,22 +757,16 @@ void virtio_cleanup(VirtIODevice *vdev) |
757 | 757 | qemu_free(vdev->vq); |
758 | 758 | } |
759 | 759 | |
760 | -VirtIODevice *virtio_init_pci(PCIBus *bus, const char *name, | |
760 | +VirtIODevice *virtio_init_pci(PCIDevice *pci_dev, const char *name, | |
761 | 761 | uint16_t vendor, uint16_t device, |
762 | 762 | uint16_t subvendor, uint16_t subdevice, |
763 | 763 | uint16_t class_code, uint8_t pif, |
764 | - size_t config_size, size_t struct_size) | |
764 | + size_t config_size) | |
765 | 765 | { |
766 | 766 | VirtIODevice *vdev; |
767 | - PCIDevice *pci_dev; | |
768 | 767 | uint8_t *config; |
769 | 768 | uint32_t size; |
770 | 769 | |
771 | - pci_dev = pci_register_device(bus, name, struct_size, | |
772 | - -1, NULL, NULL); | |
773 | - if (!pci_dev) | |
774 | - return NULL; | |
775 | - | |
776 | 770 | vdev = to_virtio_device(pci_dev); |
777 | 771 | |
778 | 772 | vdev->status = 0; | ... | ... |
hw/virtio.h
... | ... | @@ -92,11 +92,11 @@ struct VirtIODevice |
92 | 92 | VirtQueue *vq; |
93 | 93 | }; |
94 | 94 | |
95 | -VirtIODevice *virtio_init_pci(PCIBus *bus, const char *name, | |
95 | +VirtIODevice *virtio_init_pci(PCIDevice *pci_dev, const char *name, | |
96 | 96 | uint16_t vendor, uint16_t device, |
97 | 97 | uint16_t subvendor, uint16_t subdevice, |
98 | 98 | uint16_t class_code, uint8_t pif, |
99 | - size_t config_size, size_t struct_size); | |
99 | + size_t config_size); | |
100 | 100 | |
101 | 101 | VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size, |
102 | 102 | void (*handle_output)(VirtIODevice *, | ... | ... |