|
|
298366 |
From ed35f9edcc420b4f8c1f909bc7cfb002a54f437b Mon Sep 17 00:00:00 2001
|
|
|
298366 |
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
298366 |
Date: Fri, 20 Sep 2013 16:57:50 +0200
|
|
|
298366 |
Subject: [PATCH] virtio-bus: remove vdev field
|
|
|
298366 |
|
|
|
298366 |
The vdev field is complicated to synchronize. Just access the
|
|
|
298366 |
BusState's list of children.
|
|
|
298366 |
|
|
|
298366 |
Cc: qemu-stable@nongnu.org
|
|
|
298366 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
298366 |
---
|
|
|
298366 |
hw/virtio/virtio-bus.c | 67 ++++++++++++++++++++++++------------------
|
|
|
298366 |
hw/virtio/virtio-mmio.c | 9 +++---
|
|
|
298366 |
hw/virtio/virtio-pci.c | 2 +-
|
|
|
298366 |
include/hw/virtio/virtio-bus.h | 16 +++++++---
|
|
|
298366 |
4 files changed, 57 insertions(+), 37 deletions(-)
|
|
|
298366 |
|
|
|
298366 |
diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
|
|
|
298366 |
index 6849a01..669ce38 100644
|
|
|
298366 |
--- a/hw/virtio/virtio-bus.c
|
|
|
298366 |
+++ b/hw/virtio/virtio-bus.c
|
|
|
298366 |
@@ -46,8 +46,6 @@ int virtio_bus_plug_device(VirtIODevice *vdev)
|
|
|
298366 |
VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
|
|
|
298366 |
DPRINTF("%s: plug device.\n", qbus->name);
|
|
|
298366 |
|
|
|
298366 |
- bus->vdev = vdev;
|
|
|
298366 |
-
|
|
|
298366 |
if (klass->device_plugged != NULL) {
|
|
|
298366 |
klass->device_plugged(qbus->parent);
|
|
|
298366 |
}
|
|
|
298366 |
@@ -58,75 +56,84 @@ int virtio_bus_plug_device(VirtIODevice *vdev)
|
|
|
298366 |
/* Reset the virtio_bus */
|
|
|
298366 |
void virtio_bus_reset(VirtioBusState *bus)
|
|
|
298366 |
{
|
|
|
298366 |
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
|
|
|
298366 |
+
|
|
|
298366 |
DPRINTF("%s: reset device.\n", qbus->name);
|
|
|
298366 |
- if (bus->vdev != NULL) {
|
|
|
298366 |
- virtio_reset(bus->vdev);
|
|
|
298366 |
+ if (vdev != NULL) {
|
|
|
298366 |
+ virtio_reset(vdev);
|
|
|
298366 |
}
|
|
|
298366 |
}
|
|
|
298366 |
|
|
|
298366 |
/* Destroy the VirtIODevice */
|
|
|
298366 |
void virtio_bus_destroy_device(VirtioBusState *bus)
|
|
|
298366 |
{
|
|
|
298366 |
- DeviceState *qdev;
|
|
|
298366 |
BusState *qbus = BUS(bus);
|
|
|
298366 |
VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
|
|
|
298366 |
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
|
|
|
298366 |
+
|
|
|
298366 |
DPRINTF("%s: remove device.\n", qbus->name);
|
|
|
298366 |
|
|
|
298366 |
- if (bus->vdev != NULL) {
|
|
|
298366 |
+ if (vdev != NULL) {
|
|
|
298366 |
if (klass->device_unplug != NULL) {
|
|
|
298366 |
klass->device_unplug(qbus->parent);
|
|
|
298366 |
}
|
|
|
298366 |
- qdev = DEVICE(bus->vdev);
|
|
|
298366 |
- qdev_free(qdev);
|
|
|
298366 |
- bus->vdev = NULL;
|
|
|
298366 |
+ qdev_free(DEVICE(vdev));
|
|
|
298366 |
}
|
|
|
298366 |
}
|
|
|
298366 |
|
|
|
298366 |
/* Get the device id of the plugged device. */
|
|
|
298366 |
uint16_t virtio_bus_get_vdev_id(VirtioBusState *bus)
|
|
|
298366 |
{
|
|
|
298366 |
- assert(bus->vdev != NULL);
|
|
|
298366 |
- return bus->vdev->device_id;
|
|
|
298366 |
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
|
|
|
298366 |
+ assert(vdev != NULL);
|
|
|
298366 |
+ return vdev->device_id;
|
|
|
298366 |
}
|
|
|
298366 |
|
|
|
298366 |
/* Get the config_len field of the plugged device. */
|
|
|
298366 |
size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus)
|
|
|
298366 |
{
|
|
|
298366 |
- assert(bus->vdev != NULL);
|
|
|
298366 |
- return bus->vdev->config_len;
|
|
|
298366 |
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
|
|
|
298366 |
+ assert(vdev != NULL);
|
|
|
298366 |
+ return vdev->config_len;
|
|
|
298366 |
}
|
|
|
298366 |
|
|
|
298366 |
/* Get the features of the plugged device. */
|
|
|
298366 |
uint32_t virtio_bus_get_vdev_features(VirtioBusState *bus,
|
|
|
298366 |
uint32_t requested_features)
|
|
|
298366 |
{
|
|
|
298366 |
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
|
|
|
298366 |
VirtioDeviceClass *k;
|
|
|
298366 |
- assert(bus->vdev != NULL);
|
|
|
298366 |
- k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
|
|
|
298366 |
+
|
|
|
298366 |
+ assert(vdev != NULL);
|
|
|
298366 |
+ k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
|
|
298366 |
assert(k->get_features != NULL);
|
|
|
298366 |
- return k->get_features(bus->vdev, requested_features);
|
|
|
298366 |
+ return k->get_features(vdev, requested_features);
|
|
|
298366 |
}
|
|
|
298366 |
|
|
|
298366 |
/* Set the features of the plugged device. */
|
|
|
298366 |
void virtio_bus_set_vdev_features(VirtioBusState *bus,
|
|
|
298366 |
uint32_t requested_features)
|
|
|
298366 |
{
|
|
|
298366 |
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
|
|
|
298366 |
VirtioDeviceClass *k;
|
|
|
298366 |
- assert(bus->vdev != NULL);
|
|
|
298366 |
- k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
|
|
|
298366 |
+
|
|
|
298366 |
+ assert(vdev != NULL);
|
|
|
298366 |
+ k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
|
|
298366 |
if (k->set_features != NULL) {
|
|
|
298366 |
- k->set_features(bus->vdev, requested_features);
|
|
|
298366 |
+ k->set_features(vdev, requested_features);
|
|
|
298366 |
}
|
|
|
298366 |
}
|
|
|
298366 |
|
|
|
298366 |
/* Get bad features of the plugged device. */
|
|
|
298366 |
uint32_t virtio_bus_get_vdev_bad_features(VirtioBusState *bus)
|
|
|
298366 |
{
|
|
|
298366 |
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
|
|
|
298366 |
VirtioDeviceClass *k;
|
|
|
298366 |
- assert(bus->vdev != NULL);
|
|
|
298366 |
- k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
|
|
|
298366 |
+
|
|
|
298366 |
+ assert(vdev != NULL);
|
|
|
298366 |
+ k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
|
|
298366 |
if (k->bad_features != NULL) {
|
|
|
298366 |
- return k->bad_features(bus->vdev);
|
|
|
298366 |
+ return k->bad_features(vdev);
|
|
|
298366 |
} else {
|
|
|
298366 |
return 0;
|
|
|
298366 |
}
|
|
|
298366 |
@@ -135,22 +142,26 @@ uint32_t virtio_bus_get_vdev_bad_features(VirtioBusState *bus)
|
|
|
298366 |
/* Get config of the plugged device. */
|
|
|
298366 |
void virtio_bus_get_vdev_config(VirtioBusState *bus, uint8_t *config)
|
|
|
298366 |
{
|
|
|
298366 |
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
|
|
|
298366 |
VirtioDeviceClass *k;
|
|
|
298366 |
- assert(bus->vdev != NULL);
|
|
|
298366 |
- k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
|
|
|
298366 |
+
|
|
|
298366 |
+ assert(vdev != NULL);
|
|
|
298366 |
+ k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
|
|
298366 |
if (k->get_config != NULL) {
|
|
|
298366 |
- k->get_config(bus->vdev, config);
|
|
|
298366 |
+ k->get_config(vdev, config);
|
|
|
298366 |
}
|
|
|
298366 |
}
|
|
|
298366 |
|
|
|
298366 |
/* Set config of the plugged device. */
|
|
|
298366 |
void virtio_bus_set_vdev_config(VirtioBusState *bus, uint8_t *config)
|
|
|
298366 |
{
|
|
|
298366 |
+ VirtIODevice *vdev = virtio_bus_get_device(bus);
|
|
|
298366 |
VirtioDeviceClass *k;
|
|
|
298366 |
- assert(bus->vdev != NULL);
|
|
|
298366 |
- k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
|
|
|
298366 |
+
|
|
|
298366 |
+ assert(vdev != NULL);
|
|
|
298366 |
+ k = VIRTIO_DEVICE_GET_CLASS(vdev);
|
|
|
298366 |
if (k->set_config != NULL) {
|
|
|
298366 |
- k->set_config(bus->vdev, config);
|
|
|
298366 |
+ k->set_config(vdev, config);
|
|
|
298366 |
}
|
|
|
298366 |
}
|
|
|
298366 |
|
|
|
298366 |
diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c
|
|
|
298366 |
index 4bd2953..8f7b764 100644
|
|
|
298366 |
--- a/hw/virtio/virtio-mmio.c
|
|
|
298366 |
+++ b/hw/virtio/virtio-mmio.c
|
|
|
298366 |
@@ -94,7 +94,7 @@ static void virtio_mmio_bus_new(VirtioBusState *bus, VirtIOMMIOProxy *dev);
|
|
|
298366 |
static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned size)
|
|
|
298366 |
{
|
|
|
298366 |
VirtIOMMIOProxy *proxy = (VirtIOMMIOProxy *)opaque;
|
|
|
298366 |
- VirtIODevice *vdev = proxy->bus.vdev;
|
|
|
298366 |
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
298366 |
|
|
|
298366 |
DPRINTF("virtio_mmio_read offset 0x%x\n", (int)offset);
|
|
|
298366 |
|
|
|
298366 |
@@ -184,7 +184,7 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value,
|
|
|
298366 |
unsigned size)
|
|
|
298366 |
{
|
|
|
298366 |
VirtIOMMIOProxy *proxy = (VirtIOMMIOProxy *)opaque;
|
|
|
298366 |
- VirtIODevice *vdev = proxy->bus.vdev;
|
|
|
298366 |
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
298366 |
|
|
|
298366 |
DPRINTF("virtio_mmio_write offset 0x%x value 0x%" PRIx64 "\n",
|
|
|
298366 |
(int)offset, value);
|
|
|
298366 |
@@ -297,12 +297,13 @@ static const MemoryRegionOps virtio_mem_ops = {
|
|
|
298366 |
static void virtio_mmio_update_irq(DeviceState *opaque, uint16_t vector)
|
|
|
298366 |
{
|
|
|
298366 |
VirtIOMMIOProxy *proxy = VIRTIO_MMIO(opaque);
|
|
|
298366 |
+ VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
|
|
|
298366 |
int level;
|
|
|
298366 |
|
|
|
298366 |
- if (!proxy->bus.vdev) {
|
|
|
298366 |
+ if (!vdev) {
|
|
|
298366 |
return;
|
|
|
298366 |
}
|
|
|
298366 |
- level = (proxy->bus.vdev->isr != 0);
|
|
|
298366 |
+ level = (vdev->isr != 0);
|
|
|
298366 |
DPRINTF("virtio_mmio setting IRQ %d\n", level);
|
|
|
298366 |
qemu_set_irq(proxy->irq, level);
|
|
|
298366 |
}
|
|
|
298366 |
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
|
|
|
298366 |
index 41b96ce..55617a6 100644
|
|
|
298366 |
--- a/hw/virtio/virtio-pci.c
|
|
|
298366 |
+++ b/hw/virtio/virtio-pci.c
|
|
|
298366 |
@@ -942,7 +942,7 @@ static void virtio_pci_device_plugged(DeviceState *d)
|
|
|
298366 |
uint8_t *config;
|
|
|
298366 |
uint32_t size;
|
|
|
298366 |
|
|
|
298366 |
- proxy->vdev = bus->vdev;
|
|
|
298366 |
+ proxy->vdev = virtio_bus_get_device(bus);
|
|
|
298366 |
|
|
|
298366 |
config = proxy->pci_dev.config;
|
|
|
298366 |
if (proxy->class_code) {
|
|
|
298366 |
diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h
|
|
|
298366 |
index 9217f85..ba0f86a 100644
|
|
|
298366 |
--- a/include/hw/virtio/virtio-bus.h
|
|
|
298366 |
+++ b/include/hw/virtio/virtio-bus.h
|
|
|
298366 |
@@ -72,10 +72,6 @@ typedef struct VirtioBusClass {
|
|
|
298366 |
|
|
|
298366 |
struct VirtioBusState {
|
|
|
298366 |
BusState parent_obj;
|
|
|
298366 |
- /*
|
|
|
298366 |
- * Only one VirtIODevice can be plugged on the bus.
|
|
|
298366 |
- */
|
|
|
298366 |
- VirtIODevice *vdev;
|
|
|
298366 |
};
|
|
|
298366 |
|
|
|
298366 |
int virtio_bus_plug_device(VirtIODevice *vdev);
|
|
|
298366 |
@@ -98,4 +94,16 @@ void virtio_bus_get_vdev_config(VirtioBusState *bus, uint8_t *config);
|
|
|
298366 |
/* Set config of the plugged device. */
|
|
|
298366 |
void virtio_bus_set_vdev_config(VirtioBusState *bus, uint8_t *config);
|
|
|
298366 |
|
|
|
298366 |
+static inline VirtIODevice *virtio_bus_get_device(VirtioBusState *bus)
|
|
|
298366 |
+{
|
|
|
298366 |
+ BusState *qbus = &bus->parent_obj;
|
|
|
298366 |
+ BusChild *kid = QTAILQ_FIRST(&qbus->children);
|
|
|
298366 |
+ DeviceState *qdev = kid ? kid->child : NULL;
|
|
|
298366 |
+
|
|
|
298366 |
+ /* This is used on the data path, the cast is guaranteed
|
|
|
298366 |
+ * to succeed by the qdev machinery.
|
|
|
298366 |
+ */
|
|
|
298366 |
+ return (VirtIODevice *)qdev;
|
|
|
298366 |
+}
|
|
|
298366 |
+
|
|
|
298366 |
#endif /* VIRTIO_BUS_H */
|