From: Cornelia Huck <cohuck@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Eric Farman <farman@linux.ibm.com>,
qemu-s390x@nongnu.org, Cornelia Huck <cohuck@redhat.com>,
qemu-devel@nongnu.org
Subject: [PULL 4/7] vfio-ccw: Refactor ccw irq handler
Date: Thu, 18 Jun 2020 17:38:51 +0200 [thread overview]
Message-ID: <20200618153854.271723-5-cohuck@redhat.com> (raw)
In-Reply-To: <20200618153854.271723-1-cohuck@redhat.com>
From: Eric Farman <farman@linux.ibm.com>
Make it easier to add new ones in the future.
Signed-off-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Message-Id: <20200505125757.98209-5-farman@linux.ibm.com>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
---
hw/vfio/ccw.c | 58 +++++++++++++++++++++++++++++++++++++--------------
1 file changed, 42 insertions(+), 16 deletions(-)
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index f5a5e038aa45..47e43ea6068c 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -324,22 +324,36 @@ read_err:
css_inject_io_interrupt(sch);
}
-static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **errp)
+static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
+ unsigned int irq,
+ Error **errp)
{
VFIODevice *vdev = &vcdev->vdev;
struct vfio_irq_info *irq_info;
size_t argsz;
int fd;
+ EventNotifier *notifier;
+ IOHandler *fd_read;
+
+ switch (irq) {
+ case VFIO_CCW_IO_IRQ_INDEX:
+ notifier = &vcdev->io_notifier;
+ fd_read = vfio_ccw_io_notifier_handler;
+ break;
+ default:
+ error_setg(errp, "vfio: Unsupported device irq(%d)", irq);
+ return;
+ }
- if (vdev->num_irqs < VFIO_CCW_IO_IRQ_INDEX + 1) {
- error_setg(errp, "vfio: unexpected number of io irqs %u",
+ if (vdev->num_irqs < irq + 1) {
+ error_setg(errp, "vfio: unexpected number of irqs %u",
vdev->num_irqs);
return;
}
argsz = sizeof(*irq_info);
irq_info = g_malloc0(argsz);
- irq_info->index = VFIO_CCW_IO_IRQ_INDEX;
+ irq_info->index = irq;
irq_info->argsz = argsz;
if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO,
irq_info) < 0 || irq_info->count < 1) {
@@ -347,37 +361,49 @@ static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **errp)
goto out_free_info;
}
- if (event_notifier_init(&vcdev->io_notifier, 0)) {
+ if (event_notifier_init(notifier, 0)) {
error_setg_errno(errp, errno,
- "vfio: Unable to init event notifier for IO");
+ "vfio: Unable to init event notifier for irq (%d)",
+ irq);
goto out_free_info;
}
- fd = event_notifier_get_fd(&vcdev->io_notifier);
- qemu_set_fd_handler(fd, vfio_ccw_io_notifier_handler, NULL, vcdev);
+ fd = event_notifier_get_fd(notifier);
+ qemu_set_fd_handler(fd, fd_read, NULL, vcdev);
- if (vfio_set_irq_signaling(vdev, VFIO_CCW_IO_IRQ_INDEX, 0,
+ if (vfio_set_irq_signaling(vdev, irq, 0,
VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) {
qemu_set_fd_handler(fd, NULL, NULL, vcdev);
- event_notifier_cleanup(&vcdev->io_notifier);
+ event_notifier_cleanup(notifier);
}
out_free_info:
g_free(irq_info);
}
-static void vfio_ccw_unregister_io_notifier(VFIOCCWDevice *vcdev)
+static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev,
+ unsigned int irq)
{
Error *err = NULL;
+ EventNotifier *notifier;
+
+ switch (irq) {
+ case VFIO_CCW_IO_IRQ_INDEX:
+ notifier = &vcdev->io_notifier;
+ break;
+ default:
+ error_report("vfio: Unsupported device irq(%d)", irq);
+ return;
+ }
- if (vfio_set_irq_signaling(&vcdev->vdev, VFIO_CCW_IO_IRQ_INDEX, 0,
+ if (vfio_set_irq_signaling(&vcdev->vdev, irq, 0,
VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) {
error_reportf_err(err, VFIO_MSG_PREFIX, vcdev->vdev.name);
}
- qemu_set_fd_handler(event_notifier_get_fd(&vcdev->io_notifier),
+ qemu_set_fd_handler(event_notifier_get_fd(notifier),
NULL, NULL, vcdev);
- event_notifier_cleanup(&vcdev->io_notifier);
+ event_notifier_cleanup(notifier);
}
static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
@@ -565,7 +591,7 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
goto out_region_err;
}
- vfio_ccw_register_io_notifier(vcdev, &err);
+ vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX, &err);
if (err) {
goto out_notifier_err;
}
@@ -594,7 +620,7 @@ static void vfio_ccw_unrealize(DeviceState *dev)
S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
VFIOGroup *group = vcdev->vdev.group;
- vfio_ccw_unregister_io_notifier(vcdev);
+ vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX);
vfio_ccw_put_region(vcdev);
vfio_ccw_put_device(vcdev);
vfio_put_group(group);
--
2.25.4
next prev parent reply other threads:[~2020-06-18 15:43 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-18 15:38 [PULL 0/7] s390x update Cornelia Huck
2020-06-18 15:38 ` [PULL 1/7] Linux headers: update Cornelia Huck
2020-06-18 15:38 ` [PULL 2/7] vfio-ccw: Refactor cleanup of regions Cornelia Huck
2020-06-18 15:38 ` [PULL 3/7] vfio-ccw: Add support for the schib region Cornelia Huck
2020-06-18 15:38 ` Cornelia Huck [this message]
2020-06-18 15:38 ` [PULL 5/7] s390x/css: Refactor the css_queue_crw() routine Cornelia Huck
2020-06-18 15:38 ` [PULL 6/7] vfio-ccw: Add support for the CRW region and IRQ Cornelia Huck
2020-06-18 15:38 ` [PULL 7/7] docs/s390x: fix vfio-ap device_del description Cornelia Huck
2020-06-18 16:29 ` [PULL 0/7] s390x update no-reply
2020-06-19 12:10 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200618153854.271723-5-cohuck@redhat.com \
--to=cohuck@redhat.com \
--cc=farman@linux.ibm.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).