virtio: remove virtiobindings.

This remove virtio-bindings, and use class instead.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
Message-id: 1366791683-5350-6-git-send-email-fred.konrad@greensocs.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
KONRAD Frederic 2013-04-24 10:21:21 +02:00 committed by Anthony Liguori
parent 181103cd52
commit 1c81944983
11 changed files with 73 additions and 122 deletions

View File

@ -23,6 +23,7 @@
#include "hw/virtio/virtio-blk.h" #include "hw/virtio/virtio-blk.h"
#include "virtio-blk.h" #include "virtio-blk.h"
#include "block/aio.h" #include "block/aio.h"
#include "hw/virtio/virtio-bus.h"
enum { enum {
SEG_MAX = 126, /* maximum number of I/O segments */ SEG_MAX = 126, /* maximum number of I/O segments */
@ -455,6 +456,8 @@ void virtio_blk_data_plane_destroy(VirtIOBlockDataPlane *s)
void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s) void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
{ {
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s->vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
VirtQueue *vq; VirtQueue *vq;
int i; int i;
@ -470,8 +473,7 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
s->ctx = aio_context_new(); s->ctx = aio_context_new();
/* Set up guest notifier (irq) */ /* Set up guest notifier (irq) */
if (s->vdev->binding->set_guest_notifiers(s->vdev->binding_opaque, 1, if (k->set_guest_notifiers(qbus->parent, 1, true) != 0) {
true) != 0) {
fprintf(stderr, "virtio-blk failed to set guest notifier, " fprintf(stderr, "virtio-blk failed to set guest notifier, "
"ensure -enable-kvm is set\n"); "ensure -enable-kvm is set\n");
exit(1); exit(1);
@ -479,8 +481,7 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
s->guest_notifier = virtio_queue_get_guest_notifier(vq); s->guest_notifier = virtio_queue_get_guest_notifier(vq);
/* Set up virtqueue notify */ /* Set up virtqueue notify */
if (s->vdev->binding->set_host_notifier(s->vdev->binding_opaque, if (k->set_host_notifier(qbus->parent, 0, true) != 0) {
0, true) != 0) {
fprintf(stderr, "virtio-blk failed to set host notifier\n"); fprintf(stderr, "virtio-blk failed to set host notifier\n");
exit(1); exit(1);
} }
@ -508,6 +509,8 @@ void virtio_blk_data_plane_start(VirtIOBlockDataPlane *s)
void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s) void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s)
{ {
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(s->vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
if (!s->started || s->stopping) { if (!s->started || s->stopping) {
return; return;
} }
@ -527,12 +530,12 @@ void virtio_blk_data_plane_stop(VirtIOBlockDataPlane *s)
ioq_cleanup(&s->ioqueue); ioq_cleanup(&s->ioqueue);
aio_set_event_notifier(s->ctx, &s->host_notifier, NULL, NULL); aio_set_event_notifier(s->ctx, &s->host_notifier, NULL, NULL);
s->vdev->binding->set_host_notifier(s->vdev->binding_opaque, 0, false); k->set_host_notifier(qbus->parent, 0, false);
aio_context_unref(s->ctx); aio_context_unref(s->ctx);
/* Clean up guest notifier (irq) */ /* Clean up guest notifier (irq) */
s->vdev->binding->set_guest_notifiers(s->vdev->binding_opaque, 1, false); k->set_guest_notifiers(qbus->parent, 1, false);
vring_teardown(&s->vring); vring_teardown(&s->vring);
s->started = false; s->started = false;

View File

@ -37,6 +37,7 @@
#include <stdio.h> #include <stdio.h>
#include "hw/virtio/vhost.h" #include "hw/virtio/vhost.h"
#include "hw/virtio/virtio-bus.h"
struct vhost_net { struct vhost_net {
struct vhost_dev dev; struct vhost_dev dev;
@ -211,9 +212,12 @@ static void vhost_net_stop_one(struct vhost_net *net,
int vhost_net_start(VirtIODevice *dev, NetClientState *ncs, int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
int total_queues) int total_queues)
{ {
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
VirtioBusState *vbus = VIRTIO_BUS(qbus);
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
int r, i = 0; int r, i = 0;
if (!dev->binding->set_guest_notifiers) { if (!k->set_guest_notifiers) {
error_report("binding does not support guest notifiers"); error_report("binding does not support guest notifiers");
r = -ENOSYS; r = -ENOSYS;
goto err; goto err;
@ -227,9 +231,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
} }
} }
r = dev->binding->set_guest_notifiers(dev->binding_opaque, r = k->set_guest_notifiers(qbus->parent, total_queues * 2, true);
total_queues * 2,
true);
if (r < 0) { if (r < 0) {
error_report("Error binding guest notifier: %d", -r); error_report("Error binding guest notifier: %d", -r);
goto err; goto err;
@ -247,11 +249,12 @@ err:
void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs, void vhost_net_stop(VirtIODevice *dev, NetClientState *ncs,
int total_queues) int total_queues)
{ {
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(dev)));
VirtioBusState *vbus = VIRTIO_BUS(qbus);
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
int i, r; int i, r;
r = dev->binding->set_guest_notifiers(dev->binding_opaque, r = k->set_guest_notifiers(qbus->parent, total_queues * 2, false);
total_queues * 2,
false);
if (r < 0) { if (r < 0) {
fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", r); fprintf(stderr, "vhost guest notifier cleanup failed: %d\n", r);
fflush(stderr); fflush(stderr);

View File

@ -55,8 +55,6 @@ static const TypeInfo s390_virtio_bus_info = {
.instance_size = sizeof(VirtIOS390Bus), .instance_size = sizeof(VirtIOS390Bus),
}; };
static const VirtIOBindings virtio_s390_bindings;
static ram_addr_t s390_virtio_device_num_vq(VirtIOS390Device *dev); static ram_addr_t s390_virtio_device_num_vq(VirtIOS390Device *dev);
/* length of VirtIO device pages */ /* length of VirtIO device pages */
@ -140,7 +138,6 @@ static int s390_virtio_device_init(VirtIOS390Device *dev, VirtIODevice *vdev)
bus->dev_offs += dev_len; bus->dev_offs += dev_len;
virtio_bind_device(vdev, &virtio_s390_bindings, DEVICE(dev));
dev->host_features = virtio_bus_get_vdev_features(&dev->bus, dev->host_features = virtio_bus_get_vdev_features(&dev->bus,
dev->host_features); dev->host_features);
s390_virtio_device_sync(dev); s390_virtio_device_sync(dev);
@ -466,11 +463,6 @@ static unsigned virtio_s390_get_features(DeviceState *d)
/**************** S390 Virtio Bus Device Descriptions *******************/ /**************** S390 Virtio Bus Device Descriptions *******************/
static const VirtIOBindings virtio_s390_bindings = {
.notify = virtio_s390_notify,
.get_features = virtio_s390_get_features,
};
static Property s390_virtio_net_properties[] = { static Property s390_virtio_net_properties[] = {
DEFINE_NIC_PROPERTIES(VirtIONetS390, vdev.nic_conf), DEFINE_NIC_PROPERTIES(VirtIONetS390, vdev.nic_conf),
DEFINE_VIRTIO_NET_FEATURES(VirtIOS390Device, host_features), DEFINE_VIRTIO_NET_FEATURES(VirtIOS390Device, host_features),

View File

@ -53,8 +53,6 @@ static const TypeInfo virtual_css_bus_info = {
.class_init = virtual_css_bus_class_init, .class_init = virtual_css_bus_class_init,
}; };
static const VirtIOBindings virtio_ccw_bindings;
VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch) VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
{ {
VirtIODevice *vdev = NULL; VirtIODevice *vdev = NULL;
@ -521,7 +519,6 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)
sch->id.cu_type = VIRTIO_CCW_CU_TYPE; sch->id.cu_type = VIRTIO_CCW_CU_TYPE;
sch->id.cu_model = dev->vdev->device_id; sch->id.cu_model = dev->vdev->device_id;
virtio_bind_device(vdev, &virtio_ccw_bindings, DEVICE(dev));
/* Only the first 32 feature bits are used. */ /* Only the first 32 feature bits are used. */
dev->host_features[0] = virtio_bus_get_vdev_features(&dev->bus, dev->host_features[0] = virtio_bus_get_vdev_features(&dev->bus,
dev->host_features[0]); dev->host_features[0]);
@ -777,11 +774,6 @@ static void virtio_ccw_reset(DeviceState *d)
/**************** Virtio-ccw Bus Device Descriptions *******************/ /**************** Virtio-ccw Bus Device Descriptions *******************/
static const VirtIOBindings virtio_ccw_bindings = {
.notify = virtio_ccw_notify,
.get_features = virtio_ccw_get_features,
};
static Property virtio_ccw_net_properties[] = { static Property virtio_ccw_net_properties[] = {
DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id), DEFINE_PROP_STRING("devno", VirtioCcwDevice, bus_id),
DEFINE_VIRTIO_NET_FEATURES(VirtioCcwDevice, host_features[0]), DEFINE_VIRTIO_NET_FEATURES(VirtioCcwDevice, host_features[0]),

View File

@ -22,6 +22,7 @@
#include "hw/virtio/vhost-scsi.h" #include "hw/virtio/vhost-scsi.h"
#include "hw/virtio/vhost.h" #include "hw/virtio/vhost.h"
#include "hw/virtio/virtio-scsi.h" #include "hw/virtio/virtio-scsi.h"
#include "hw/virtio/virtio-bus.h"
static int vhost_scsi_set_endpoint(VHostSCSI *s) static int vhost_scsi_set_endpoint(VHostSCSI *s)
{ {
@ -52,8 +53,10 @@ static int vhost_scsi_start(VHostSCSI *s)
{ {
int ret, abi_version, i; int ret, abi_version, i;
VirtIODevice *vdev = VIRTIO_DEVICE(s); VirtIODevice *vdev = VIRTIO_DEVICE(s);
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
if (!vdev->binding->set_guest_notifiers) { if (!k->set_guest_notifiers) {
error_report("binding does not support guest notifiers"); error_report("binding does not support guest notifiers");
return -ENOSYS; return -ENOSYS;
} }
@ -88,7 +91,7 @@ static int vhost_scsi_start(VHostSCSI *s)
goto err_vhost_stop; goto err_vhost_stop;
} }
ret = vdev->binding->set_guest_notifiers(vdev->binding_opaque, s->dev.nvqs, true); ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, true);
if (ret < 0) { if (ret < 0) {
error_report("Error binding guest notifier"); error_report("Error binding guest notifier");
goto err_endpoint; goto err_endpoint;
@ -116,11 +119,12 @@ err_notifiers:
static void vhost_scsi_stop(VHostSCSI *s) static void vhost_scsi_stop(VHostSCSI *s)
{ {
VirtIODevice *vdev = VIRTIO_DEVICE(s); VirtIODevice *vdev = VIRTIO_DEVICE(s);
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
int ret = 0; int ret = 0;
if (!vdev->binding->set_guest_notifiers) { if (!k->set_guest_notifiers) {
ret = vdev->binding->set_guest_notifiers(vdev->binding_opaque, ret = k->set_guest_notifiers(qbus->parent, s->dev.nvqs, false);
s->dev.nvqs, false);
if (ret < 0) { if (ret < 0) {
error_report("vhost guest notifier cleanup failed: %d\n", ret); error_report("vhost guest notifier cleanup failed: %d\n", ret);
} }

View File

@ -19,6 +19,7 @@
#include "qemu/range.h" #include "qemu/range.h"
#include <linux/vhost.h> #include <linux/vhost.h>
#include "exec/address-spaces.h" #include "exec/address-spaces.h"
#include "hw/virtio/virtio-bus.h"
static void vhost_dev_sync_region(struct vhost_dev *dev, static void vhost_dev_sync_region(struct vhost_dev *dev,
MemoryRegionSection *section, MemoryRegionSection *section,
@ -892,9 +893,13 @@ void vhost_dev_cleanup(struct vhost_dev *hdev)
bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev) bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev)
{ {
return !vdev->binding->query_guest_notifiers || BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
vdev->binding->query_guest_notifiers(vdev->binding_opaque) || VirtioBusState *vbus = VIRTIO_BUS(qbus);
hdev->force; VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
return !k->query_guest_notifiers ||
k->query_guest_notifiers(qbus->parent) ||
hdev->force;
} }
/* Stop processing guest IO notifications in qemu. /* Stop processing guest IO notifications in qemu.
@ -902,17 +907,18 @@ bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev)
*/ */
int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev) int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
{ {
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
VirtioBusState *vbus = VIRTIO_BUS(qbus);
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
int i, r; int i, r;
if (!vdev->binding->set_host_notifier) { if (!k->set_host_notifier) {
fprintf(stderr, "binding does not support host notifiers\n"); fprintf(stderr, "binding does not support host notifiers\n");
r = -ENOSYS; r = -ENOSYS;
goto fail; goto fail;
} }
for (i = 0; i < hdev->nvqs; ++i) { for (i = 0; i < hdev->nvqs; ++i) {
r = vdev->binding->set_host_notifier(vdev->binding_opaque, r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, true);
hdev->vq_index + i,
true);
if (r < 0) { if (r < 0) {
fprintf(stderr, "vhost VQ %d notifier binding failed: %d\n", i, -r); fprintf(stderr, "vhost VQ %d notifier binding failed: %d\n", i, -r);
goto fail_vq; goto fail_vq;
@ -922,9 +928,7 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
return 0; return 0;
fail_vq: fail_vq:
while (--i >= 0) { while (--i >= 0) {
r = vdev->binding->set_host_notifier(vdev->binding_opaque, r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, false);
hdev->vq_index + i,
false);
if (r < 0) { if (r < 0) {
fprintf(stderr, "vhost VQ %d notifier cleanup error: %d\n", i, -r); fprintf(stderr, "vhost VQ %d notifier cleanup error: %d\n", i, -r);
fflush(stderr); fflush(stderr);
@ -942,12 +946,13 @@ fail:
*/ */
void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev) void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev)
{ {
BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
VirtioBusState *vbus = VIRTIO_BUS(qbus);
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
int i, r; int i, r;
for (i = 0; i < hdev->nvqs; ++i) { for (i = 0; i < hdev->nvqs; ++i) {
r = vdev->binding->set_host_notifier(vdev->binding_opaque, r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, false);
hdev->vq_index + i,
false);
if (r < 0) { if (r < 0) {
fprintf(stderr, "vhost VQ %d notifier cleanup failed: %d\n", i, -r); fprintf(stderr, "vhost VQ %d notifier cleanup failed: %d\n", i, -r);
fflush(stderr); fflush(stderr);

View File

@ -48,23 +48,6 @@ int virtio_bus_plug_device(VirtIODevice *vdev)
bus->vdev = vdev; bus->vdev = vdev;
/*
* The lines below will disappear when we drop VirtIOBindings, at the end
* of the series.
*/
bus->bindings.notify = klass->notify;
bus->bindings.save_config = klass->save_config;
bus->bindings.save_queue = klass->save_queue;
bus->bindings.load_config = klass->load_config;
bus->bindings.load_queue = klass->load_queue;
bus->bindings.load_done = klass->load_done;
bus->bindings.get_features = klass->get_features;
bus->bindings.query_guest_notifiers = klass->query_guest_notifiers;
bus->bindings.set_guest_notifiers = klass->set_guest_notifiers;
bus->bindings.set_host_notifier = klass->set_host_notifier;
bus->bindings.vmstate_change = klass->vmstate_change;
virtio_bind_device(bus->vdev, &bus->bindings, qbus->parent);
if (klass->device_plugged != NULL) { if (klass->device_plugged != NULL) {
klass->device_plugged(qbus->parent); klass->device_plugged(qbus->parent);
} }

View File

@ -879,19 +879,6 @@ static void virtio_pci_vmstate_change(DeviceState *d, bool running)
} }
} }
static const VirtIOBindings virtio_pci_bindings = {
.notify = virtio_pci_notify,
.save_config = virtio_pci_save_config,
.load_config = virtio_pci_load_config,
.save_queue = virtio_pci_save_queue,
.load_queue = virtio_pci_load_queue,
.get_features = virtio_pci_get_features,
.query_guest_notifiers = virtio_pci_query_guest_notifiers,
.set_host_notifier = virtio_pci_set_host_notifier,
.set_guest_notifiers = virtio_pci_set_guest_notifiers,
.vmstate_change = virtio_pci_vmstate_change,
};
#ifdef CONFIG_VIRTFS #ifdef CONFIG_VIRTFS
static int virtio_9p_init_pci(VirtIOPCIProxy *vpci_dev) static int virtio_9p_init_pci(VirtIOPCIProxy *vpci_dev)
{ {

View File

@ -507,8 +507,11 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
/* virtio device */ /* virtio device */
static void virtio_notify_vector(VirtIODevice *vdev, uint16_t vector) static void virtio_notify_vector(VirtIODevice *vdev, uint16_t vector)
{ {
if (vdev->binding->notify) { BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
vdev->binding->notify(vdev->binding_opaque, vector); VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
if (k->notify) {
k->notify(qbus->parent, vector);
} }
} }
@ -789,10 +792,13 @@ void virtio_notify_config(VirtIODevice *vdev)
void virtio_save(VirtIODevice *vdev, QEMUFile *f) void virtio_save(VirtIODevice *vdev, QEMUFile *f)
{ {
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
int i; int i;
if (vdev->binding->save_config) if (k->save_config) {
vdev->binding->save_config(vdev->binding_opaque, f); k->save_config(qbus->parent, f);
}
qemu_put_8s(f, &vdev->status); qemu_put_8s(f, &vdev->status);
qemu_put_8s(f, &vdev->isr); qemu_put_8s(f, &vdev->isr);
@ -815,16 +821,18 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
qemu_put_be32(f, vdev->vq[i].vring.num); qemu_put_be32(f, vdev->vq[i].vring.num);
qemu_put_be64(f, vdev->vq[i].pa); qemu_put_be64(f, vdev->vq[i].pa);
qemu_put_be16s(f, &vdev->vq[i].last_avail_idx); qemu_put_be16s(f, &vdev->vq[i].last_avail_idx);
if (vdev->binding->save_queue) if (k->save_queue) {
vdev->binding->save_queue(vdev->binding_opaque, i, f); k->save_queue(qbus->parent, i, f);
}
} }
} }
int virtio_set_features(VirtIODevice *vdev, uint32_t val) int virtio_set_features(VirtIODevice *vdev, uint32_t val)
{ {
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
VirtioBusClass *vbusk = VIRTIO_BUS_GET_CLASS(qbus);
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
uint32_t supported_features = uint32_t supported_features = vbusk->get_features(qbus->parent);
vdev->binding->get_features(vdev->binding_opaque);
bool bad = (val & ~supported_features) != 0; bool bad = (val & ~supported_features) != 0;
val &= supported_features; val &= supported_features;
@ -840,9 +848,11 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
int num, i, ret; int num, i, ret;
uint32_t features; uint32_t features;
uint32_t supported_features; uint32_t supported_features;
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
if (vdev->binding->load_config) { if (k->load_config) {
ret = vdev->binding->load_config(vdev->binding_opaque, f); ret = k->load_config(qbus->parent, f);
if (ret) if (ret)
return ret; return ret;
} }
@ -853,7 +863,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
qemu_get_be32s(f, &features); qemu_get_be32s(f, &features);
if (virtio_set_features(vdev, features) < 0) { if (virtio_set_features(vdev, features) < 0) {
supported_features = vdev->binding->get_features(vdev->binding_opaque); supported_features = k->get_features(qbus->parent);
error_report("Features 0x%x unsupported. Allowed features: 0x%x", error_report("Features 0x%x unsupported. Allowed features: 0x%x",
features, supported_features); features, supported_features);
return -1; return -1;
@ -889,8 +899,8 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
i, vdev->vq[i].last_avail_idx); i, vdev->vq[i].last_avail_idx);
return -1; return -1;
} }
if (vdev->binding->load_queue) { if (k->load_queue) {
ret = vdev->binding->load_queue(vdev->binding_opaque, i, f); ret = k->load_queue(qbus->parent, i, f);
if (ret) if (ret)
return ret; return ret;
} }
@ -916,6 +926,8 @@ void virtio_cleanup(VirtIODevice *vdev)
static void virtio_vmstate_change(void *opaque, int running, RunState state) static void virtio_vmstate_change(void *opaque, int running, RunState state)
{ {
VirtIODevice *vdev = opaque; VirtIODevice *vdev = opaque;
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
bool backend_run = running && (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK); bool backend_run = running && (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK);
vdev->vm_running = running; vdev->vm_running = running;
@ -923,8 +935,8 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
virtio_set_status(vdev, vdev->status); virtio_set_status(vdev, vdev->status);
} }
if (vdev->binding->vmstate_change) { if (k->vmstate_change) {
vdev->binding->vmstate_change(vdev->binding_opaque, backend_run); k->vmstate_change(qbus->parent, backend_run);
} }
if (!backend_run) { if (!backend_run) {
@ -969,13 +981,6 @@ VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
return vdev; return vdev;
} }
void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
DeviceState *opaque)
{
vdev->binding = binding;
vdev->binding_opaque = opaque;
}
hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n) hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n)
{ {
return vdev->vq[n].vring.desc; return vdev->vq[n].vring.desc;

View File

@ -70,10 +70,6 @@ struct VirtioBusState {
* Only one VirtIODevice can be plugged on the bus. * Only one VirtIODevice can be plugged on the bus.
*/ */
VirtIODevice *vdev; VirtIODevice *vdev;
/*
* This will be removed at the end of the series.
*/
VirtIOBindings bindings;
}; };
int virtio_bus_plug_device(VirtIODevice *vdev); int virtio_bus_plug_device(VirtIODevice *vdev);

View File

@ -90,20 +90,6 @@ typedef struct VirtQueueElement
struct iovec out_sg[VIRTQUEUE_MAX_SIZE]; struct iovec out_sg[VIRTQUEUE_MAX_SIZE];
} VirtQueueElement; } VirtQueueElement;
typedef struct {
void (*notify)(DeviceState *d, uint16_t vector);
void (*save_config)(DeviceState *d, QEMUFile *f);
void (*save_queue)(DeviceState *d, int n, QEMUFile *f);
int (*load_config)(DeviceState *d, QEMUFile *f);
int (*load_queue)(DeviceState *d, int n, QEMUFile *f);
int (*load_done)(DeviceState *d, QEMUFile *f);
unsigned (*get_features)(DeviceState *d);
bool (*query_guest_notifiers)(DeviceState *d);
int (*set_guest_notifiers)(DeviceState *d, int nvqs, bool assigned);
int (*set_host_notifier)(DeviceState *d, int n, bool assigned);
void (*vmstate_change)(DeviceState *d, bool running);
} VirtIOBindings;
#define VIRTIO_PCI_QUEUE_MAX 64 #define VIRTIO_PCI_QUEUE_MAX 64
#define VIRTIO_NO_VECTOR 0xffff #define VIRTIO_NO_VECTOR 0xffff
@ -129,8 +115,6 @@ struct VirtIODevice
uint16_t config_vector; uint16_t config_vector;
int nvectors; int nvectors;
VirtQueue *vq; VirtQueue *vq;
const VirtIOBindings *binding;
DeviceState *binding_opaque;
uint16_t device_id; uint16_t device_id;
bool vm_running; bool vm_running;
VMChangeStateEntry *vmstate; VMChangeStateEntry *vmstate;
@ -223,9 +207,6 @@ void virtio_reset(void *opaque);
void virtio_update_irq(VirtIODevice *vdev); void virtio_update_irq(VirtIODevice *vdev);
int virtio_set_features(VirtIODevice *vdev, uint32_t val); int virtio_set_features(VirtIODevice *vdev, uint32_t val);
void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
DeviceState *opaque);
/* Base devices. */ /* Base devices. */
typedef struct VirtIOBlkConf VirtIOBlkConf; typedef struct VirtIOBlkConf VirtIOBlkConf;
struct virtio_net_conf; struct virtio_net_conf;