peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0008-virtio-ccw-remove-vdev-field.patch

298366
From a9b1f1aeba8167ae90aecea9b8ca223faf33ae90 Mon Sep 17 00:00:00 2001
298366
From: Paolo Bonzini <pbonzini@redhat.com>
298366
Date: Fri, 20 Sep 2013 16:57:52 +0200
298366
Subject: [PATCH] virtio-ccw: 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/s390x/virtio-ccw.c | 80 ++++++++++++++++++++++++++++-----------------------
298366
 1 file changed, 44 insertions(+), 36 deletions(-)
298366
298366
diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c
298366
index 8835bd4..0fc7387 100644
298366
--- a/hw/s390x/virtio-ccw.c
298366
+++ b/hw/s390x/virtio-ccw.c
298366
@@ -56,9 +56,10 @@ static const TypeInfo virtual_css_bus_info = {
298366
 VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
298366
 {
298366
     VirtIODevice *vdev = NULL;
298366
+    VirtioCcwDevice *dev = sch->driver_data;
298366
 
298366
-    if (sch->driver_data) {
298366
-        vdev = ((VirtioCcwDevice *)sch->driver_data)->vdev;
298366
+    if (dev) {
298366
+        vdev = virtio_bus_get_device(&dev->bus);
298366
     }
298366
     return vdev;
298366
 }
298366
@@ -66,7 +67,8 @@ VirtIODevice *virtio_ccw_get_vdev(SubchDev *sch)
298366
 static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n,
298366
                                               bool assign, bool set_handler)
298366
 {
298366
-    VirtQueue *vq = virtio_get_queue(dev->vdev, n);
298366
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
298366
+    VirtQueue *vq = virtio_get_queue(vdev, n);
298366
     EventNotifier *notifier = virtio_queue_get_host_notifier(vq);
298366
     int r = 0;
298366
     SubchDev *sch = dev->sch;
298366
@@ -96,6 +98,7 @@ static int virtio_ccw_set_guest2host_notifier(VirtioCcwDevice *dev, int n,
298366
 
298366
 static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
298366
 {
298366
+    VirtIODevice *vdev;
298366
     int n, r;
298366
 
298366
     if (!(dev->flags & VIRTIO_CCW_FLAG_USE_IOEVENTFD) ||
298366
@@ -103,8 +106,9 @@ static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
298366
         dev->ioeventfd_started) {
298366
         return;
298366
     }
298366
+    vdev = virtio_bus_get_device(&dev->bus);
298366
     for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
298366
-        if (!virtio_queue_get_num(dev->vdev, n)) {
298366
+        if (!virtio_queue_get_num(vdev, n)) {
298366
             continue;
298366
         }
298366
         r = virtio_ccw_set_guest2host_notifier(dev, n, true, true);
298366
@@ -117,7 +121,7 @@ static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
298366
 
298366
   assign_error:
298366
     while (--n >= 0) {
298366
-        if (!virtio_queue_get_num(dev->vdev, n)) {
298366
+        if (!virtio_queue_get_num(vdev, n)) {
298366
             continue;
298366
         }
298366
         r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
298366
@@ -131,13 +135,15 @@ static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev)
298366
 
298366
 static void virtio_ccw_stop_ioeventfd(VirtioCcwDevice *dev)
298366
 {
298366
+    VirtIODevice *vdev;
298366
     int n, r;
298366
 
298366
     if (!dev->ioeventfd_started) {
298366
         return;
298366
     }
298366
+    vdev = virtio_bus_get_device(&dev->bus);
298366
     for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) {
298366
-        if (!virtio_queue_get_num(dev->vdev, n)) {
298366
+        if (!virtio_queue_get_num(vdev, n)) {
298366
             continue;
298366
         }
298366
         r = virtio_ccw_set_guest2host_notifier(dev, n, false, false);
298366
@@ -188,7 +194,7 @@ typedef struct VirtioFeatDesc {
298366
 static int virtio_ccw_set_vqs(SubchDev *sch, uint64_t addr, uint32_t align,
298366
                               uint16_t index, uint16_t num)
298366
 {
298366
-    VirtioCcwDevice *dev = sch->driver_data;
298366
+    VirtIODevice *vdev = virtio_ccw_get_vdev(sch);
298366
 
298366
     if (index > VIRTIO_PCI_QUEUE_MAX) {
298366
         return -EINVAL;
298366
@@ -199,23 +205,23 @@ static int virtio_ccw_set_vqs(SubchDev *sch, uint64_t addr, uint32_t align,
298366
         return -EINVAL;
298366
     }
298366
 
298366
-    if (!dev) {
298366
+    if (!vdev) {
298366
         return -EINVAL;
298366
     }
298366
 
298366
-    virtio_queue_set_addr(dev->vdev, index, addr);
298366
+    virtio_queue_set_addr(vdev, index, addr);
298366
     if (!addr) {
298366
-        virtio_queue_set_vector(dev->vdev, index, 0);
298366
+        virtio_queue_set_vector(vdev, index, 0);
298366
     } else {
298366
         /* Fail if we don't have a big enough queue. */
298366
         /* TODO: Add interface to handle vring.num changing */
298366
-        if (virtio_queue_get_num(dev->vdev, index) > num) {
298366
+        if (virtio_queue_get_num(vdev, index) > num) {
298366
             return -EINVAL;
298366
         }
298366
-        virtio_queue_set_vector(dev->vdev, index, index);
298366
+        virtio_queue_set_vector(vdev, index, index);
298366
     }
298366
     /* tell notify handler in case of config change */
298366
-    dev->vdev->config_vector = VIRTIO_PCI_QUEUE_MAX;
298366
+    vdev->config_vector = VIRTIO_PCI_QUEUE_MAX;
298366
     return 0;
298366
 }
298366
 
298366
@@ -229,6 +235,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
298366
     hwaddr indicators;
298366
     VqConfigBlock vq_config;
298366
     VirtioCcwDevice *dev = sch->driver_data;
298366
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
298366
     bool check_len;
298366
     int len;
298366
     hwaddr hw_len;
298366
@@ -271,7 +278,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
298366
         break;
298366
     case CCW_CMD_VDEV_RESET:
298366
         virtio_ccw_stop_ioeventfd(dev);
298366
-        virtio_reset(dev->vdev);
298366
+        virtio_reset(vdev);
298366
         ret = 0;
298366
         break;
298366
     case CCW_CMD_READ_FEAT:
298366
@@ -318,7 +325,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
298366
             features.features = ldl_le_phys(ccw.cda);
298366
             if (features.index < ARRAY_SIZE(dev->host_features)) {
298366
                 virtio_bus_set_vdev_features(&dev->bus, features.features);
298366
-                dev->vdev->guest_features = features.features;
298366
+                vdev->guest_features = features.features;
298366
             } else {
298366
                 /*
298366
                  * If the guest supports more feature bits, assert that it
298366
@@ -336,30 +343,30 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
298366
         break;
298366
     case CCW_CMD_READ_CONF:
298366
         if (check_len) {
298366
-            if (ccw.count > dev->vdev->config_len) {
298366
+            if (ccw.count > vdev->config_len) {
298366
                 ret = -EINVAL;
298366
                 break;
298366
             }
298366
         }
298366
-        len = MIN(ccw.count, dev->vdev->config_len);
298366
+        len = MIN(ccw.count, vdev->config_len);
298366
         if (!ccw.cda) {
298366
             ret = -EFAULT;
298366
         } else {
298366
-            virtio_bus_get_vdev_config(&dev->bus, dev->vdev->config);
298366
+            virtio_bus_get_vdev_config(&dev->bus, vdev->config);
298366
             /* XXX config space endianness */
298366
-            cpu_physical_memory_write(ccw.cda, dev->vdev->config, len);
298366
+            cpu_physical_memory_write(ccw.cda, vdev->config, len);
298366
             sch->curr_status.scsw.count = ccw.count - len;
298366
             ret = 0;
298366
         }
298366
         break;
298366
     case CCW_CMD_WRITE_CONF:
298366
         if (check_len) {
298366
-            if (ccw.count > dev->vdev->config_len) {
298366
+            if (ccw.count > vdev->config_len) {
298366
                 ret = -EINVAL;
298366
                 break;
298366
             }
298366
         }
298366
-        len = MIN(ccw.count, dev->vdev->config_len);
298366
+        len = MIN(ccw.count, vdev->config_len);
298366
         hw_len = len;
298366
         if (!ccw.cda) {
298366
             ret = -EFAULT;
298366
@@ -370,9 +377,9 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
298366
             } else {
298366
                 len = hw_len;
298366
                 /* XXX config space endianness */
298366
-                memcpy(dev->vdev->config, config, len);
298366
+                memcpy(vdev->config, config, len);
298366
                 cpu_physical_memory_unmap(config, hw_len, 0, hw_len);
298366
-                virtio_bus_set_vdev_config(&dev->bus, dev->vdev->config);
298366
+                virtio_bus_set_vdev_config(&dev->bus, vdev->config);
298366
                 sch->curr_status.scsw.count = ccw.count - len;
298366
                 ret = 0;
298366
             }
298366
@@ -396,9 +403,9 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
298366
             if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
298366
                 virtio_ccw_stop_ioeventfd(dev);
298366
             }
298366
-            virtio_set_status(dev->vdev, status);
298366
-            if (dev->vdev->status == 0) {
298366
-                virtio_reset(dev->vdev);
298366
+            virtio_set_status(vdev, status);
298366
+            if (vdev->status == 0) {
298366
+                virtio_reset(vdev);
298366
             }
298366
             if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
298366
                 virtio_ccw_start_ioeventfd(dev);
298366
@@ -462,7 +469,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw)
298366
             ret = -EFAULT;
298366
         } else {
298366
             vq_config.index = lduw_phys(ccw.cda);
298366
-            vq_config.num_max = virtio_queue_get_num(dev->vdev,
298366
+            vq_config.num_max = virtio_queue_get_num(vdev,
298366
                                                      vq_config.index);
298366
             stw_phys(ccw.cda + sizeof(vq_config.index), vq_config.num_max);
298366
             sch->curr_status.scsw.count = ccw.count - sizeof(vq_config);
298366
@@ -494,7 +501,6 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)
298366
     sch->driver_data = dev;
298366
     dev->sch = sch;
298366
 
298366
-    dev->vdev = vdev;
298366
     dev->indicators = 0;
298366
 
298366
     /* Initialize subchannel structure. */
298366
@@ -607,7 +613,7 @@ static int virtio_ccw_device_init(VirtioCcwDevice *dev, VirtIODevice *vdev)
298366
     memset(&sch->id, 0, sizeof(SenseId));
298366
     sch->id.reserved = 0xff;
298366
     sch->id.cu_type = VIRTIO_CCW_CU_TYPE;
298366
-    sch->id.cu_model = dev->vdev->device_id;
298366
+    sch->id.cu_model = vdev->device_id;
298366
 
298366
     /* Only the first 32 feature bits are used. */
298366
     dev->host_features[0] = virtio_bus_get_vdev_features(&dev->bus,
298366
@@ -891,9 +897,10 @@ static unsigned virtio_ccw_get_features(DeviceState *d)
298366
 static void virtio_ccw_reset(DeviceState *d)
298366
 {
298366
     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
298366
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
298366
 
298366
     virtio_ccw_stop_ioeventfd(dev);
298366
-    virtio_reset(dev->vdev);
298366
+    virtio_reset(vdev);
298366
     css_reset_sch(dev->sch);
298366
     dev->indicators = 0;
298366
     dev->indicators2 = 0;
298366
@@ -933,9 +940,10 @@ static int virtio_ccw_set_host_notifier(DeviceState *d, int n, bool assign)
298366
 static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
298366
                                          bool assign, bool with_irqfd)
298366
 {
298366
-    VirtQueue *vq = virtio_get_queue(dev->vdev, n);
298366
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
298366
+    VirtQueue *vq = virtio_get_queue(vdev, n);
298366
     EventNotifier *notifier = virtio_queue_get_guest_notifier(vq);
298366
-    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(dev->vdev);
298366
+    VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
298366
 
298366
     if (assign) {
298366
         int r = event_notifier_init(notifier, 0);
298366
@@ -951,16 +959,16 @@ static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n,
298366
          * land in qemu (and only the irq fd) in this code.
298366
          */
298366
         if (k->guest_notifier_mask) {
298366
-            k->guest_notifier_mask(dev->vdev, n, false);
298366
+            k->guest_notifier_mask(vdev, n, false);
298366
         }
298366
         /* get lost events and re-inject */
298366
         if (k->guest_notifier_pending &&
298366
-            k->guest_notifier_pending(dev->vdev, n)) {
298366
+            k->guest_notifier_pending(vdev, n)) {
298366
             event_notifier_set(notifier);
298366
         }
298366
     } else {
298366
         if (k->guest_notifier_mask) {
298366
-            k->guest_notifier_mask(dev->vdev, n, true);
298366
+            k->guest_notifier_mask(vdev, n, true);
298366
         }
298366
         virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd);
298366
         event_notifier_cleanup(notifier);
298366
@@ -972,7 +980,7 @@ static int virtio_ccw_set_guest_notifiers(DeviceState *d, int nvqs,
298366
                                           bool assigned)
298366
 {
298366
     VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d);
298366
-    VirtIODevice *vdev = dev->vdev;
298366
+    VirtIODevice *vdev = virtio_bus_get_device(&dev->bus);
298366
     int r, n;
298366
 
298366
     for (n = 0; n < nvqs; n++) {