Skip to content

Commit f030532

Browse files
Farhan Alicohuck
authored andcommitted
vfio-ccw: Add support for the CRW region and IRQ
The crw region can be used to obtain information about Channel Report Words (CRW) from vfio-ccw driver. Currently only channel-path related CRWs are passed to QEMU from vfio-ccw driver. Signed-off-by: Farhan Ali <[email protected]> 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 f6dde1b commit f030532

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

hw/vfio/ccw.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ struct VFIOCCWDevice {
4444
uint64_t schib_region_size;
4545
uint64_t schib_region_offset;
4646
struct ccw_schib_region *schib_region;
47+
uint64_t crw_region_size;
48+
uint64_t crw_region_offset;
49+
struct ccw_crw_region *crw_region;
4750
EventNotifier io_notifier;
51+
EventNotifier crw_notifier;
4852
bool force_orb_pfch;
4953
bool warned_orb_pfch;
5054
};
@@ -254,6 +258,44 @@ static void vfio_ccw_reset(DeviceState *dev)
254258
ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
255259
}
256260

261+
static void vfio_ccw_crw_read(VFIOCCWDevice *vcdev)
262+
{
263+
struct ccw_crw_region *region = vcdev->crw_region;
264+
CRW crw;
265+
int size;
266+
267+
/* Keep reading CRWs as long as data is returned */
268+
do {
269+
memset(region, 0, sizeof(*region));
270+
size = pread(vcdev->vdev.fd, region, vcdev->crw_region_size,
271+
vcdev->crw_region_offset);
272+
273+
if (size == -1) {
274+
error_report("vfio-ccw: Read crw region failed with errno=%d",
275+
errno);
276+
break;
277+
}
278+
279+
if (region->crw == 0) {
280+
/* No more CRWs to queue */
281+
break;
282+
}
283+
284+
memcpy(&crw, &region->crw, sizeof(CRW));
285+
286+
css_crw_add_to_queue(crw);
287+
} while (1);
288+
}
289+
290+
static void vfio_ccw_crw_notifier_handler(void *opaque)
291+
{
292+
VFIOCCWDevice *vcdev = opaque;
293+
294+
while (event_notifier_test_and_clear(&vcdev->crw_notifier)) {
295+
vfio_ccw_crw_read(vcdev);
296+
}
297+
}
298+
257299
static void vfio_ccw_io_notifier_handler(void *opaque)
258300
{
259301
VFIOCCWDevice *vcdev = opaque;
@@ -340,6 +382,10 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
340382
notifier = &vcdev->io_notifier;
341383
fd_read = vfio_ccw_io_notifier_handler;
342384
break;
385+
case VFIO_CCW_CRW_IRQ_INDEX:
386+
notifier = &vcdev->crw_notifier;
387+
fd_read = vfio_ccw_crw_notifier_handler;
388+
break;
343389
default:
344390
error_setg(errp, "vfio: Unsupported device irq(%d)", irq);
345391
return;
@@ -391,6 +437,9 @@ static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev,
391437
case VFIO_CCW_IO_IRQ_INDEX:
392438
notifier = &vcdev->io_notifier;
393439
break;
440+
case VFIO_CCW_CRW_IRQ_INDEX:
441+
notifier = &vcdev->crw_notifier;
442+
break;
394443
default:
395444
error_report("vfio: Unsupported device irq(%d)", irq);
396445
return;
@@ -468,10 +517,24 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
468517
vcdev->schib_region = g_malloc(info->size);
469518
}
470519

520+
ret = vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW,
521+
VFIO_REGION_SUBTYPE_CCW_CRW, &info);
522+
523+
if (!ret) {
524+
vcdev->crw_region_size = info->size;
525+
if (sizeof(*vcdev->crw_region) != vcdev->crw_region_size) {
526+
error_setg(errp, "vfio: Unexpected size of the CRW region");
527+
goto out_err;
528+
}
529+
vcdev->crw_region_offset = info->offset;
530+
vcdev->crw_region = g_malloc(info->size);
531+
}
532+
471533
g_free(info);
472534
return;
473535

474536
out_err:
537+
g_free(vcdev->crw_region);
475538
g_free(vcdev->schib_region);
476539
g_free(vcdev->async_cmd_region);
477540
g_free(vcdev->io_region);
@@ -481,6 +544,7 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
481544

482545
static void vfio_ccw_put_region(VFIOCCWDevice *vcdev)
483546
{
547+
g_free(vcdev->crw_region);
484548
g_free(vcdev->schib_region);
485549
g_free(vcdev->async_cmd_region);
486550
g_free(vcdev->io_region);
@@ -596,6 +660,14 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
596660
goto out_notifier_err;
597661
}
598662

663+
if (vcdev->crw_region) {
664+
vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX, &err);
665+
if (err) {
666+
vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX);
667+
goto out_notifier_err;
668+
}
669+
}
670+
599671
return;
600672

601673
out_notifier_err:
@@ -620,6 +692,7 @@ static void vfio_ccw_unrealize(DeviceState *dev)
620692
S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
621693
VFIOGroup *group = vcdev->vdev.group;
622694

695+
vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX);
623696
vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX);
624697
vfio_ccw_put_region(vcdev);
625698
vfio_ccw_put_device(vcdev);

0 commit comments

Comments
 (0)