Skip to content

Commit 690e29b

Browse files
efarmancohuck
authored andcommitted
vfio-ccw: Refactor ccw irq handler
Make it easier to add new ones in the future. Signed-off-by: Eric Farman <[email protected]> Reviewed-by: Cornelia Huck <[email protected]> Message-Id: <[email protected]> Signed-off-by: Cornelia Huck <[email protected]>
1 parent 46ea384 commit 690e29b

File tree

1 file changed

+42
-16
lines changed

1 file changed

+42
-16
lines changed

hw/vfio/ccw.c

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -324,60 +324,86 @@ static void vfio_ccw_io_notifier_handler(void *opaque)
324324
css_inject_io_interrupt(sch);
325325
}
326326

327-
static void vfio_ccw_register_io_notifier(VFIOCCWDevice *vcdev, Error **errp)
327+
static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
328+
unsigned int irq,
329+
Error **errp)
328330
{
329331
VFIODevice *vdev = &vcdev->vdev;
330332
struct vfio_irq_info *irq_info;
331333
size_t argsz;
332334
int fd;
335+
EventNotifier *notifier;
336+
IOHandler *fd_read;
337+
338+
switch (irq) {
339+
case VFIO_CCW_IO_IRQ_INDEX:
340+
notifier = &vcdev->io_notifier;
341+
fd_read = vfio_ccw_io_notifier_handler;
342+
break;
343+
default:
344+
error_setg(errp, "vfio: Unsupported device irq(%d)", irq);
345+
return;
346+
}
333347

334-
if (vdev->num_irqs < VFIO_CCW_IO_IRQ_INDEX + 1) {
335-
error_setg(errp, "vfio: unexpected number of io irqs %u",
348+
if (vdev->num_irqs < irq + 1) {
349+
error_setg(errp, "vfio: unexpected number of irqs %u",
336350
vdev->num_irqs);
337351
return;
338352
}
339353

340354
argsz = sizeof(*irq_info);
341355
irq_info = g_malloc0(argsz);
342-
irq_info->index = VFIO_CCW_IO_IRQ_INDEX;
356+
irq_info->index = irq;
343357
irq_info->argsz = argsz;
344358
if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO,
345359
irq_info) < 0 || irq_info->count < 1) {
346360
error_setg_errno(errp, errno, "vfio: Error getting irq info");
347361
goto out_free_info;
348362
}
349363

350-
if (event_notifier_init(&vcdev->io_notifier, 0)) {
364+
if (event_notifier_init(notifier, 0)) {
351365
error_setg_errno(errp, errno,
352-
"vfio: Unable to init event notifier for IO");
366+
"vfio: Unable to init event notifier for irq (%d)",
367+
irq);
353368
goto out_free_info;
354369
}
355370

356-
fd = event_notifier_get_fd(&vcdev->io_notifier);
357-
qemu_set_fd_handler(fd, vfio_ccw_io_notifier_handler, NULL, vcdev);
371+
fd = event_notifier_get_fd(notifier);
372+
qemu_set_fd_handler(fd, fd_read, NULL, vcdev);
358373

359-
if (vfio_set_irq_signaling(vdev, VFIO_CCW_IO_IRQ_INDEX, 0,
374+
if (vfio_set_irq_signaling(vdev, irq, 0,
360375
VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) {
361376
qemu_set_fd_handler(fd, NULL, NULL, vcdev);
362-
event_notifier_cleanup(&vcdev->io_notifier);
377+
event_notifier_cleanup(notifier);
363378
}
364379

365380
out_free_info:
366381
g_free(irq_info);
367382
}
368383

369-
static void vfio_ccw_unregister_io_notifier(VFIOCCWDevice *vcdev)
384+
static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev,
385+
unsigned int irq)
370386
{
371387
Error *err = NULL;
388+
EventNotifier *notifier;
389+
390+
switch (irq) {
391+
case VFIO_CCW_IO_IRQ_INDEX:
392+
notifier = &vcdev->io_notifier;
393+
break;
394+
default:
395+
error_report("vfio: Unsupported device irq(%d)", irq);
396+
return;
397+
}
372398

373-
if (vfio_set_irq_signaling(&vcdev->vdev, VFIO_CCW_IO_IRQ_INDEX, 0,
399+
if (vfio_set_irq_signaling(&vcdev->vdev, irq, 0,
374400
VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) {
375401
error_reportf_err(err, VFIO_MSG_PREFIX, vcdev->vdev.name);
376402
}
377403

378-
qemu_set_fd_handler(event_notifier_get_fd(&vcdev->io_notifier),
404+
qemu_set_fd_handler(event_notifier_get_fd(notifier),
379405
NULL, NULL, vcdev);
380-
event_notifier_cleanup(&vcdev->io_notifier);
406+
event_notifier_cleanup(notifier);
381407
}
382408

383409
static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
@@ -565,7 +591,7 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
565591
goto out_region_err;
566592
}
567593

568-
vfio_ccw_register_io_notifier(vcdev, &err);
594+
vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX, &err);
569595
if (err) {
570596
goto out_notifier_err;
571597
}
@@ -594,7 +620,7 @@ static void vfio_ccw_unrealize(DeviceState *dev)
594620
S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
595621
VFIOGroup *group = vcdev->vdev.group;
596622

597-
vfio_ccw_unregister_io_notifier(vcdev);
623+
vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX);
598624
vfio_ccw_put_region(vcdev);
599625
vfio_ccw_put_device(vcdev);
600626
vfio_put_group(group);

0 commit comments

Comments
 (0)