thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
ddf19c
From ee9b03e774641fba8baaf85256706fcc5e8d8efa Mon Sep 17 00:00:00 2001
ddf19c
From: Cornelia Huck <cohuck@redhat.com>
ddf19c
Date: Tue, 23 Jun 2020 09:25:40 -0400
ddf19c
Subject: [PATCH 06/12] vfio-ccw: Refactor ccw irq handler
ddf19c
ddf19c
RH-Author: Cornelia Huck <cohuck@redhat.com>
ddf19c
Message-id: <20200623092543.358315-7-cohuck@redhat.com>
ddf19c
Patchwork-id: 97695
ddf19c
O-Subject: [RHEL-8.3.0 qemu-kvm PATCH 6/9] vfio-ccw: Refactor ccw irq handler
ddf19c
Bugzilla: 1660916
ddf19c
RH-Acked-by: Claudio Imbrenda <cimbrend@redhat.com>
ddf19c
RH-Acked-by: David Hildenbrand <david@redhat.com>
ddf19c
RH-Acked-by: Thomas Huth <thuth@redhat.com>
ddf19c
ddf19c
From: Eric Farman <farman@linux.ibm.com>
ddf19c
ddf19c
Make it easier to add new ones in the future.
ddf19c
ddf19c
Signed-off-by: Eric Farman <farman@linux.ibm.com>
ddf19c
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
ddf19c
Message-Id: <20200505125757.98209-5-farman@linux.ibm.com>
ddf19c
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
ddf19c
(cherry picked from commit 690e29b91102ac69810b35fe72cd90bc9fa1fff7)
ddf19c
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 hw/vfio/ccw.c | 58 +++++++++++++++++++++++++++++++++++++--------------
ddf19c
 1 file changed, 42 insertions(+), 16 deletions(-)
ddf19c
ddf19c
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
ddf19c
index 859ad646f1..94a0d9840d 100644
ddf19c
--- a/hw/vfio/ccw.c
ddf19c
+++ b/hw/vfio/ccw.c
ddf19c
@@ -324,22 +324,36 @@ read_err:
ddf19c
     css_inject_io_interrupt(sch);
ddf19c
 }
ddf19c
 
ddf19c
-static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **errp)
ddf19c
+static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
ddf19c
+                                           unsigned int irq,
ddf19c
+                                           Error **errp)
ddf19c
 {
ddf19c
     VFIODevice *vdev = &vcdev->vdev;
ddf19c
     struct vfio_irq_info *irq_info;
ddf19c
     size_t argsz;
ddf19c
     int fd;
ddf19c
+    EventNotifier *notifier;
ddf19c
+    IOHandler *fd_read;
ddf19c
+
ddf19c
+    switch (irq) {
ddf19c
+    case VFIO_CCW_IO_IRQ_INDEX:
ddf19c
+        notifier = &vcdev->io_notifier;
ddf19c
+        fd_read = vfio_ccw_io_notifier_handler;
ddf19c
+        break;
ddf19c
+    default:
ddf19c
+        error_setg(errp, "vfio: Unsupported device irq(%d)", irq);
ddf19c
+        return;
ddf19c
+    }
ddf19c
 
ddf19c
-    if (vdev->num_irqs < VFIO_CCW_IO_IRQ_INDEX + 1) {
ddf19c
-        error_setg(errp, "vfio: unexpected number of io irqs %u",
ddf19c
+    if (vdev->num_irqs < irq + 1) {
ddf19c
+        error_setg(errp, "vfio: unexpected number of irqs %u",
ddf19c
                    vdev->num_irqs);
ddf19c
         return;
ddf19c
     }
ddf19c
 
ddf19c
     argsz = sizeof(*irq_info);
ddf19c
     irq_info = g_malloc0(argsz);
ddf19c
-    irq_info->index = VFIO_CCW_IO_IRQ_INDEX;
ddf19c
+    irq_info->index = irq;
ddf19c
     irq_info->argsz = argsz;
ddf19c
     if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO,
ddf19c
               irq_info) < 0 || irq_info->count < 1) {
ddf19c
@@ -347,37 +361,49 @@ static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **errp)
ddf19c
         goto out_free_info;
ddf19c
     }
ddf19c
 
ddf19c
-    if (event_notifier_init(&vcdev->io_notifier, 0)) {
ddf19c
+    if (event_notifier_init(notifier, 0)) {
ddf19c
         error_setg_errno(errp, errno,
ddf19c
-                         "vfio: Unable to init event notifier for IO");
ddf19c
+                         "vfio: Unable to init event notifier for irq (%d)",
ddf19c
+                         irq);
ddf19c
         goto out_free_info;
ddf19c
     }
ddf19c
 
ddf19c
-    fd = event_notifier_get_fd(&vcdev->io_notifier);
ddf19c
-    qemu_set_fd_handler(fd, vfio_ccw_io_notifier_handler, NULL, vcdev);
ddf19c
+    fd = event_notifier_get_fd(notifier);
ddf19c
+    qemu_set_fd_handler(fd, fd_read, NULL, vcdev);
ddf19c
 
ddf19c
-    if (vfio_set_irq_signaling(vdev, VFIO_CCW_IO_IRQ_INDEX, 0,
ddf19c
+    if (vfio_set_irq_signaling(vdev, irq, 0,
ddf19c
                                VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) {
ddf19c
         qemu_set_fd_handler(fd, NULL, NULL, vcdev);
ddf19c
-        event_notifier_cleanup(&vcdev->io_notifier);
ddf19c
+        event_notifier_cleanup(notifier);
ddf19c
     }
ddf19c
 
ddf19c
 out_free_info:
ddf19c
     g_free(irq_info);
ddf19c
 }
ddf19c
 
ddf19c
-static void vfio_ccw_unregister_io_notifier(VFIOCCWDevice *vcdev)
ddf19c
+static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev,
ddf19c
+                                             unsigned int irq)
ddf19c
 {
ddf19c
     Error *err = NULL;
ddf19c
+    EventNotifier *notifier;
ddf19c
+
ddf19c
+    switch (irq) {
ddf19c
+    case VFIO_CCW_IO_IRQ_INDEX:
ddf19c
+        notifier = &vcdev->io_notifier;
ddf19c
+        break;
ddf19c
+    default:
ddf19c
+        error_report("vfio: Unsupported device irq(%d)", irq);
ddf19c
+        return;
ddf19c
+    }
ddf19c
 
ddf19c
-    if (vfio_set_irq_signaling(&vcdev->vdev, VFIO_CCW_IO_IRQ_INDEX, 0,
ddf19c
+    if (vfio_set_irq_signaling(&vcdev->vdev, irq, 0,
ddf19c
                                VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) {
ddf19c
         error_reportf_err(err, VFIO_MSG_PREFIX, vcdev->vdev.name);
ddf19c
     }
ddf19c
 
ddf19c
-    qemu_set_fd_handler(event_notifier_get_fd(&vcdev->io_notifier),
ddf19c
+    qemu_set_fd_handler(event_notifier_get_fd(notifier),
ddf19c
                         NULL, NULL, vcdev);
ddf19c
-    event_notifier_cleanup(&vcdev->io_notifier);
ddf19c
+    event_notifier_cleanup(notifier);
ddf19c
 }
ddf19c
 
ddf19c
 static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
ddf19c
@@ -565,7 +591,7 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
ddf19c
         goto out_region_err;
ddf19c
     }
ddf19c
 
ddf19c
-    vfio_ccw_register_io_notifier(vcdev, &err;;
ddf19c
+    vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX, &err;;
ddf19c
     if (err) {
ddf19c
         goto out_notifier_err;
ddf19c
     }
ddf19c
@@ -594,7 +620,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
ddf19c
     S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
ddf19c
     VFIOGroup *group = vcdev->vdev.group;
ddf19c
 
ddf19c
-    vfio_ccw_unregister_io_notifier(vcdev);
ddf19c
+    vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX);
ddf19c
     vfio_ccw_put_region(vcdev);
ddf19c
     vfio_ccw_put_device(vcdev);
ddf19c
     vfio_put_group(group);
ddf19c
-- 
ddf19c
2.27.0
ddf19c