yeahuh / rpms / qemu-kvm

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