aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hw/pci.c1
-rw-r--r--hw/virtio-balloon.c12
-rw-r--r--hw/virtio-blk.c12
-rw-r--r--hw/virtio-console.c10
-rw-r--r--hw/virtio-net.c21
-rw-r--r--hw/virtio-net.h2
-rw-r--r--hw/virtio.c10
-rw-r--r--hw/virtio.h4
8 files changed, 40 insertions, 32 deletions
diff --git a/hw/pci.c b/hw/pci.c
index 1a1a83daf0..644e8f7137 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -25,7 +25,6 @@
#include "pci.h"
#include "monitor.h"
#include "net.h"
-#include "virtio-net.h"
#include "sysemu.h"
//#define DEBUG_PCI
diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index 079f49890d..b8f9184e11 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -172,16 +172,20 @@ static int virtio_balloon_load(QEMUFile *f, void *opaque, int version_id)
void *virtio_balloon_init(PCIBus *bus)
{
VirtIOBalloon *s;
+ PCIDevice *d;
- s = (VirtIOBalloon *)virtio_init_pci(bus, "virtio-balloon",
+ d = pci_register_device(bus, "virtio-balloon", sizeof(VirtIOBalloon),
+ -1, NULL, NULL);
+ if (!d)
+ return NULL;
+
+ s = (VirtIOBalloon *)virtio_init_pci(d, "virtio-balloon",
PCI_VENDOR_ID_REDHAT_QUMRANET,
PCI_DEVICE_ID_VIRTIO_BALLOON,
PCI_VENDOR_ID_REDHAT_QUMRANET,
VIRTIO_ID_BALLOON,
PCI_CLASS_MEMORY_RAM, 0x00,
- 8, sizeof(VirtIOBalloon));
- if (s == NULL)
- return NULL;
+ 8);
s->vdev.get_config = virtio_balloon_get_config;
s->vdev.set_config = virtio_balloon_set_config;
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index dad4ef08c2..b80302b689 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -353,16 +353,20 @@ void *virtio_blk_init(PCIBus *bus, BlockDriverState *bs)
VirtIOBlock *s;
int cylinders, heads, secs;
static int virtio_blk_id;
+ PCIDevice *d;
- s = (VirtIOBlock *)virtio_init_pci(bus, "virtio-blk",
+ d = pci_register_device(bus, "virtio-blk", sizeof(VirtIOBlock),
+ -1, NULL, NULL);
+ if (!d)
+ return NULL;
+
+ s = (VirtIOBlock *)virtio_init_pci(d, "virtio-blk",
PCI_VENDOR_ID_REDHAT_QUMRANET,
PCI_DEVICE_ID_VIRTIO_BLOCK,
PCI_VENDOR_ID_REDHAT_QUMRANET,
VIRTIO_ID_BLOCK,
PCI_CLASS_STORAGE_OTHER, 0x00,
- sizeof(struct virtio_blk_config), sizeof(VirtIOBlock));
- if (!s)
- return NULL;
+ sizeof(struct virtio_blk_config));
s->vdev.get_config = virtio_blk_update_config;
s->vdev.get_features = virtio_blk_get_features;
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index b263281d8f..c006d90a95 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -126,14 +126,20 @@ static int virtio_console_load(QEMUFile *f, void *opaque, int version_id)
void *virtio_console_init(PCIBus *bus, CharDriverState *chr)
{
VirtIOConsole *s;
+ PCIDevice *d;
- s = (VirtIOConsole *)virtio_init_pci(bus, "virtio-console",
+ d = pci_register_device(bus, "virtio-console", sizeof(VirtIOConsole),
+ -1, NULL, NULL);
+ if (!d)
+ return NULL;
+
+ s = (VirtIOConsole *)virtio_init_pci(d, "virtio-console",
PCI_VENDOR_ID_REDHAT_QUMRANET,
PCI_DEVICE_ID_VIRTIO_CONSOLE,
PCI_VENDOR_ID_REDHAT_QUMRANET,
VIRTIO_ID_CONSOLE,
PCI_CLASS_DISPLAY_OTHER, 0x00,
- 0, sizeof(VirtIOConsole));
+ 0);
if (s == NULL)
return NULL;
diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index f9717c02e1..3764170437 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -585,21 +585,18 @@ static void virtio_net_cleanup(VLANClientState *vc)
virtio_cleanup(&n->vdev);
}
-PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
+static void virtio_net_init(PCIDevice *pci_dev)
{
VirtIONet *n;
static int virtio_net_id;
- n = (VirtIONet *)virtio_init_pci(bus, "virtio-net",
+ n = (VirtIONet *)virtio_init_pci(pci_dev, "virtio-net",
PCI_VENDOR_ID_REDHAT_QUMRANET,
PCI_DEVICE_ID_VIRTIO_NET,
PCI_VENDOR_ID_REDHAT_QUMRANET,
VIRTIO_ID_NET,
PCI_CLASS_NETWORK_ETHERNET, 0x00,
- sizeof(struct virtio_net_config),
- sizeof(VirtIONet));
- if (!n)
- return NULL;
+ sizeof(struct virtio_net_config));
n->vdev.get_config = virtio_net_get_config;
n->vdev.set_config = virtio_net_set_config;
@@ -610,9 +607,9 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
n->rx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_rx);
n->tx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_tx);
n->ctrl_vq = virtio_add_queue(&n->vdev, 16, virtio_net_handle_ctrl);
- memcpy(n->mac, nd->macaddr, ETH_ALEN);
+ qdev_get_macaddr(&pci_dev->qdev, n->mac);
n->status = VIRTIO_NET_S_LINK_UP;
- n->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
+ n->vc = qdev_get_vlan_client(&pci_dev->qdev,
virtio_net_receive,
virtio_net_can_receive,
virtio_net_cleanup, n);
@@ -631,5 +628,11 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
register_savevm("virtio-net", virtio_net_id++, VIRTIO_NET_VM_VERSION,
virtio_net_save, virtio_net_load, n);
- return (PCIDevice *)n;
}
+
+static void virtio_net_register_devices(void)
+{
+ pci_qdev_register("virtio_net", sizeof(VirtIONet), virtio_net_init);
+}
+
+device_init(virtio_net_register_devices)
diff --git a/hw/virtio-net.h b/hw/virtio-net.h
index 4e203496b2..390fe10224 100644
--- a/hw/virtio-net.h
+++ b/hw/virtio-net.h
@@ -85,8 +85,6 @@ struct virtio_net_hdr_mrg_rxbuf
uint16_t num_buffers; /* Number of merged rx buffers */
};
-PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn);
-
/*
* Control virtqueue data structures
*
diff --git a/hw/virtio.c b/hw/virtio.c
index 78c7637658..21108c5c2b 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -757,22 +757,16 @@ void virtio_cleanup(VirtIODevice *vdev)
qemu_free(vdev->vq);
}
-VirtIODevice *virtio_init_pci(PCIBus *bus, const char *name,
+VirtIODevice *virtio_init_pci(PCIDevice *pci_dev, const char *name,
uint16_t vendor, uint16_t device,
uint16_t subvendor, uint16_t subdevice,
uint16_t class_code, uint8_t pif,
- size_t config_size, size_t struct_size)
+ size_t config_size)
{
VirtIODevice *vdev;
- PCIDevice *pci_dev;
uint8_t *config;
uint32_t size;
- pci_dev = pci_register_device(bus, name, struct_size,
- -1, NULL, NULL);
- if (!pci_dev)
- return NULL;
-
vdev = to_virtio_device(pci_dev);
vdev->status = 0;
diff --git a/hw/virtio.h b/hw/virtio.h
index 935b118545..99d8d72a03 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -92,11 +92,11 @@ struct VirtIODevice
VirtQueue *vq;
};
-VirtIODevice *virtio_init_pci(PCIBus *bus, const char *name,
+VirtIODevice *virtio_init_pci(PCIDevice *pci_dev, const char *name,
uint16_t vendor, uint16_t device,
uint16_t subvendor, uint16_t subdevice,
uint16_t class_code, uint8_t pif,
- size_t config_size, size_t struct_size);
+ size_t config_size);
VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
void (*handle_output)(VirtIODevice *,