11dcac3e1SXiao Feng Ren /* 21dcac3e1SXiao Feng Ren * vfio based subchannel assignment support 31dcac3e1SXiao Feng Ren * 41dcac3e1SXiao Feng Ren * Copyright 2017 IBM Corp. 58fadea24SCornelia Huck * Copyright 2019 Red Hat, Inc. 68fadea24SCornelia Huck * 71dcac3e1SXiao Feng Ren * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com> 81dcac3e1SXiao Feng Ren * Xiao Feng Ren <renxiaof@linux.vnet.ibm.com> 91dcac3e1SXiao Feng Ren * Pierre Morel <pmorel@linux.vnet.ibm.com> 108fadea24SCornelia Huck * Cornelia Huck <cohuck@redhat.com> 111dcac3e1SXiao Feng Ren * 121dcac3e1SXiao Feng Ren * This work is licensed under the terms of the GNU GPL, version 2 or (at 1308b824aaSCornelia Huck * your option) any later version. See the COPYING file in the top-level 141dcac3e1SXiao Feng Ren * directory. 151dcac3e1SXiao Feng Ren */ 161dcac3e1SXiao Feng Ren 17e9808d09SPhilippe Mathieu-Daudé #include "qemu/osdep.h" 18e70f971aSZhenzhong Duan #include CONFIG_DEVICES /* CONFIG_IOMMUFD */ 191dcac3e1SXiao Feng Ren #include <linux/vfio.h> 20c14e706cSDong Jia Shi #include <linux/vfio_ccw.h> 211dcac3e1SXiao Feng Ren #include <sys/ioctl.h> 221dcac3e1SXiao Feng Ren 231dcac3e1SXiao Feng Ren #include "qapi/error.h" 241dcac3e1SXiao Feng Ren #include "hw/vfio/vfio-common.h" 25e70f971aSZhenzhong Duan #include "sysemu/iommufd.h" 261dcac3e1SXiao Feng Ren #include "hw/s390x/s390-ccw.h" 2744445d86SJason J. Herne #include "hw/s390x/vfio-ccw.h" 28a27bd6c7SMarkus Armbruster #include "hw/qdev-properties.h" 291dcac3e1SXiao Feng Ren #include "hw/s390x/ccw-device.h" 30d791937fSPhilippe Mathieu-Daudé #include "exec/address-spaces.h" 314886b3e9SDong Jia Shi #include "qemu/error-report.h" 32db725815SMarkus Armbruster #include "qemu/main-loop.h" 330b8fa32fSMarkus Armbruster #include "qemu/module.h" 341dcac3e1SXiao Feng Ren 3544445d86SJason J. Herne struct VFIOCCWDevice { 361dcac3e1SXiao Feng Ren S390CCWDevice cdev; 371dcac3e1SXiao Feng Ren VFIODevice vdev; 38c14e706cSDong Jia Shi uint64_t io_region_size; 39c14e706cSDong Jia Shi uint64_t io_region_offset; 40c14e706cSDong Jia Shi struct ccw_io_region *io_region; 418fadea24SCornelia Huck uint64_t async_cmd_region_size; 428fadea24SCornelia Huck uint64_t async_cmd_region_offset; 438fadea24SCornelia Huck struct ccw_cmd_region *async_cmd_region; 4446ea3841SFarhan Ali uint64_t schib_region_size; 4546ea3841SFarhan Ali uint64_t schib_region_offset; 4646ea3841SFarhan Ali struct ccw_schib_region *schib_region; 47f030532fSFarhan Ali uint64_t crw_region_size; 48f030532fSFarhan Ali uint64_t crw_region_offset; 49f030532fSFarhan Ali struct ccw_crw_region *crw_region; 504886b3e9SDong Jia Shi EventNotifier io_notifier; 51f030532fSFarhan Ali EventNotifier crw_notifier; 52b2f96f9eSEric Farman EventNotifier req_notifier; 539a51c9eeSHalil Pasic bool force_orb_pfch; 549a51c9eeSHalil Pasic bool warned_orb_pfch; 5544445d86SJason J. Herne }; 561dcac3e1SXiao Feng Ren 579a51c9eeSHalil Pasic static inline void warn_once_pfch(VFIOCCWDevice *vcdev, SubchDev *sch, 589a51c9eeSHalil Pasic const char *msg) 599a51c9eeSHalil Pasic { 60c55510b7SCornelia Huck warn_report_once_cond(&vcdev->warned_orb_pfch, 61c55510b7SCornelia Huck "vfio-ccw (devno %x.%x.%04x): %s", 629a51c9eeSHalil Pasic sch->cssid, sch->ssid, sch->devno, msg); 639a51c9eeSHalil Pasic } 649a51c9eeSHalil Pasic 651dcac3e1SXiao Feng Ren static void vfio_ccw_compute_needs_reset(VFIODevice *vdev) 661dcac3e1SXiao Feng Ren { 671dcac3e1SXiao Feng Ren vdev->needs_reset = false; 681dcac3e1SXiao Feng Ren } 691dcac3e1SXiao Feng Ren 701dcac3e1SXiao Feng Ren /* 711dcac3e1SXiao Feng Ren * We don't need vfio_hot_reset_multi and vfio_eoi operations for 721dcac3e1SXiao Feng Ren * vfio_ccw device now. 731dcac3e1SXiao Feng Ren */ 741dcac3e1SXiao Feng Ren struct VFIODeviceOps vfio_ccw_ops = { 751dcac3e1SXiao Feng Ren .vfio_compute_needs_reset = vfio_ccw_compute_needs_reset, 761dcac3e1SXiao Feng Ren }; 771dcac3e1SXiao Feng Ren 7866dc50f7SHalil Pasic static IOInstEnding vfio_ccw_handle_request(SubchDev *sch) 798ca2b376SXiao Feng Ren { 80ecba6468SPhilippe Mathieu-Daudé VFIOCCWDevice *vcdev = VFIO_CCW(sch->driver_data); 818ca2b376SXiao Feng Ren struct ccw_io_region *region = vcdev->io_region; 828ca2b376SXiao Feng Ren int ret; 838ca2b376SXiao Feng Ren 8424e58a7bSJared Rossi if (!(sch->orb.ctrl0 & ORB_CTRL0_MASK_PFCH) && vcdev->force_orb_pfch) { 859a51c9eeSHalil Pasic sch->orb.ctrl0 |= ORB_CTRL0_MASK_PFCH; 869a51c9eeSHalil Pasic warn_once_pfch(vcdev, sch, "PFCH flag forced"); 879a51c9eeSHalil Pasic } 889a51c9eeSHalil Pasic 898ca2b376SXiao Feng Ren QEMU_BUILD_BUG_ON(sizeof(region->orb_area) != sizeof(ORB)); 908ca2b376SXiao Feng Ren QEMU_BUILD_BUG_ON(sizeof(region->scsw_area) != sizeof(SCSW)); 918ca2b376SXiao Feng Ren QEMU_BUILD_BUG_ON(sizeof(region->irb_area) != sizeof(IRB)); 928ca2b376SXiao Feng Ren 938ca2b376SXiao Feng Ren memset(region, 0, sizeof(*region)); 948ca2b376SXiao Feng Ren 9566dc50f7SHalil Pasic memcpy(region->orb_area, &sch->orb, sizeof(ORB)); 9666dc50f7SHalil Pasic memcpy(region->scsw_area, &sch->curr_status.scsw, sizeof(SCSW)); 978ca2b376SXiao Feng Ren 988ca2b376SXiao Feng Ren again: 998ca2b376SXiao Feng Ren ret = pwrite(vcdev->vdev.fd, region, 1008ca2b376SXiao Feng Ren vcdev->io_region_size, vcdev->io_region_offset); 1018ca2b376SXiao Feng Ren if (ret != vcdev->io_region_size) { 1028ca2b376SXiao Feng Ren if (errno == EAGAIN) { 1038ca2b376SXiao Feng Ren goto again; 1048ca2b376SXiao Feng Ren } 10591f751dcSBoris Fiuczynski error_report("vfio-ccw: write I/O region failed with errno=%d", errno); 106d6cd6631SEric Farman ret = errno ? -errno : -EFAULT; 10766dc50f7SHalil Pasic } else { 108d6cd6631SEric Farman ret = 0; 1098ca2b376SXiao Feng Ren } 11066dc50f7SHalil Pasic switch (ret) { 11166dc50f7SHalil Pasic case 0: 11266dc50f7SHalil Pasic return IOINST_CC_EXPECTED; 11366dc50f7SHalil Pasic case -EBUSY: 11466dc50f7SHalil Pasic return IOINST_CC_BUSY; 11566dc50f7SHalil Pasic case -ENODEV: 11666dc50f7SHalil Pasic case -EACCES: 11766dc50f7SHalil Pasic return IOINST_CC_NOT_OPERATIONAL; 11866dc50f7SHalil Pasic case -EFAULT: 11966dc50f7SHalil Pasic default: 12066dc50f7SHalil Pasic sch_gen_unit_exception(sch); 12166dc50f7SHalil Pasic css_inject_io_interrupt(sch); 12266dc50f7SHalil Pasic return IOINST_CC_EXPECTED; 12366dc50f7SHalil Pasic } 1248ca2b376SXiao Feng Ren } 1258ca2b376SXiao Feng Ren 12646ea3841SFarhan Ali static IOInstEnding vfio_ccw_handle_store(SubchDev *sch) 12746ea3841SFarhan Ali { 128ecba6468SPhilippe Mathieu-Daudé VFIOCCWDevice *vcdev = VFIO_CCW(sch->driver_data); 12946ea3841SFarhan Ali SCHIB *schib = &sch->curr_status; 13046ea3841SFarhan Ali struct ccw_schib_region *region = vcdev->schib_region; 13146ea3841SFarhan Ali SCHIB *s; 13246ea3841SFarhan Ali int ret; 13346ea3841SFarhan Ali 13446ea3841SFarhan Ali /* schib region not available so nothing else to do */ 13546ea3841SFarhan Ali if (!region) { 13646ea3841SFarhan Ali return IOINST_CC_EXPECTED; 13746ea3841SFarhan Ali } 13846ea3841SFarhan Ali 13946ea3841SFarhan Ali memset(region, 0, sizeof(*region)); 14046ea3841SFarhan Ali ret = pread(vcdev->vdev.fd, region, vcdev->schib_region_size, 14146ea3841SFarhan Ali vcdev->schib_region_offset); 14246ea3841SFarhan Ali 14346ea3841SFarhan Ali if (ret == -1) { 14446ea3841SFarhan Ali /* 14546ea3841SFarhan Ali * Device is probably damaged, but store subchannel does not 14646ea3841SFarhan Ali * have a nonzero cc defined for this scenario. Log an error, 14746ea3841SFarhan Ali * and presume things are otherwise fine. 14846ea3841SFarhan Ali */ 14946ea3841SFarhan Ali error_report("vfio-ccw: store region read failed with errno=%d", errno); 15046ea3841SFarhan Ali return IOINST_CC_EXPECTED; 15146ea3841SFarhan Ali } 15246ea3841SFarhan Ali 15346ea3841SFarhan Ali /* 15446ea3841SFarhan Ali * Selectively copy path-related bits of the SCHIB, 15546ea3841SFarhan Ali * rather than copying the entire struct. 15646ea3841SFarhan Ali */ 15746ea3841SFarhan Ali s = (SCHIB *)region->schib_area; 15846ea3841SFarhan Ali schib->pmcw.pnom = s->pmcw.pnom; 15946ea3841SFarhan Ali schib->pmcw.lpum = s->pmcw.lpum; 16046ea3841SFarhan Ali schib->pmcw.pam = s->pmcw.pam; 16146ea3841SFarhan Ali schib->pmcw.pom = s->pmcw.pom; 16246ea3841SFarhan Ali 16346ea3841SFarhan Ali if (s->scsw.flags & SCSW_FLAGS_MASK_PNO) { 16446ea3841SFarhan Ali schib->scsw.flags |= SCSW_FLAGS_MASK_PNO; 16546ea3841SFarhan Ali } 16646ea3841SFarhan Ali 16746ea3841SFarhan Ali return IOINST_CC_EXPECTED; 16846ea3841SFarhan Ali } 16946ea3841SFarhan Ali 1708fadea24SCornelia Huck static int vfio_ccw_handle_clear(SubchDev *sch) 1718fadea24SCornelia Huck { 172ecba6468SPhilippe Mathieu-Daudé VFIOCCWDevice *vcdev = VFIO_CCW(sch->driver_data); 1738fadea24SCornelia Huck struct ccw_cmd_region *region = vcdev->async_cmd_region; 1748fadea24SCornelia Huck int ret; 1758fadea24SCornelia Huck 1768fadea24SCornelia Huck if (!vcdev->async_cmd_region) { 1778fadea24SCornelia Huck /* Async command region not available, fall back to emulation */ 1788fadea24SCornelia Huck return -ENOSYS; 1798fadea24SCornelia Huck } 1808fadea24SCornelia Huck 1818fadea24SCornelia Huck memset(region, 0, sizeof(*region)); 1828fadea24SCornelia Huck region->command = VFIO_CCW_ASYNC_CMD_CSCH; 1838fadea24SCornelia Huck 1848fadea24SCornelia Huck again: 1858fadea24SCornelia Huck ret = pwrite(vcdev->vdev.fd, region, 1868fadea24SCornelia Huck vcdev->async_cmd_region_size, vcdev->async_cmd_region_offset); 1878fadea24SCornelia Huck if (ret != vcdev->async_cmd_region_size) { 1888fadea24SCornelia Huck if (errno == EAGAIN) { 1898fadea24SCornelia Huck goto again; 1908fadea24SCornelia Huck } 1918fadea24SCornelia Huck error_report("vfio-ccw: write cmd region failed with errno=%d", errno); 192d6cd6631SEric Farman ret = errno ? -errno : -EFAULT; 1938fadea24SCornelia Huck } else { 194d6cd6631SEric Farman ret = 0; 1958fadea24SCornelia Huck } 1968fadea24SCornelia Huck switch (ret) { 1978fadea24SCornelia Huck case 0: 1988fadea24SCornelia Huck case -ENODEV: 1998fadea24SCornelia Huck case -EACCES: 200759a5d3bSCornelia Huck return ret; 2018fadea24SCornelia Huck case -EFAULT: 2028fadea24SCornelia Huck default: 2038fadea24SCornelia Huck sch_gen_unit_exception(sch); 2048fadea24SCornelia Huck css_inject_io_interrupt(sch); 2058fadea24SCornelia Huck return 0; 2068fadea24SCornelia Huck } 2078fadea24SCornelia Huck } 2088fadea24SCornelia Huck 2098fadea24SCornelia Huck static int vfio_ccw_handle_halt(SubchDev *sch) 2108fadea24SCornelia Huck { 211ecba6468SPhilippe Mathieu-Daudé VFIOCCWDevice *vcdev = VFIO_CCW(sch->driver_data); 2128fadea24SCornelia Huck struct ccw_cmd_region *region = vcdev->async_cmd_region; 2138fadea24SCornelia Huck int ret; 2148fadea24SCornelia Huck 2158fadea24SCornelia Huck if (!vcdev->async_cmd_region) { 2168fadea24SCornelia Huck /* Async command region not available, fall back to emulation */ 2178fadea24SCornelia Huck return -ENOSYS; 2188fadea24SCornelia Huck } 2198fadea24SCornelia Huck 2208fadea24SCornelia Huck memset(region, 0, sizeof(*region)); 2218fadea24SCornelia Huck region->command = VFIO_CCW_ASYNC_CMD_HSCH; 2228fadea24SCornelia Huck 2238fadea24SCornelia Huck again: 2248fadea24SCornelia Huck ret = pwrite(vcdev->vdev.fd, region, 2258fadea24SCornelia Huck vcdev->async_cmd_region_size, vcdev->async_cmd_region_offset); 2268fadea24SCornelia Huck if (ret != vcdev->async_cmd_region_size) { 2278fadea24SCornelia Huck if (errno == EAGAIN) { 2288fadea24SCornelia Huck goto again; 2298fadea24SCornelia Huck } 2308fadea24SCornelia Huck error_report("vfio-ccw: write cmd region failed with errno=%d", errno); 231d6cd6631SEric Farman ret = errno ? -errno : -EFAULT; 2328fadea24SCornelia Huck } else { 233d6cd6631SEric Farman ret = 0; 2348fadea24SCornelia Huck } 2358fadea24SCornelia Huck switch (ret) { 2368fadea24SCornelia Huck case 0: 2378fadea24SCornelia Huck case -EBUSY: 2388fadea24SCornelia Huck case -ENODEV: 2398fadea24SCornelia Huck case -EACCES: 240759a5d3bSCornelia Huck return ret; 2418fadea24SCornelia Huck case -EFAULT: 2428fadea24SCornelia Huck default: 2438fadea24SCornelia Huck sch_gen_unit_exception(sch); 2448fadea24SCornelia Huck css_inject_io_interrupt(sch); 2458fadea24SCornelia Huck return 0; 2468fadea24SCornelia Huck } 2478fadea24SCornelia Huck } 2488fadea24SCornelia Huck 2491dcac3e1SXiao Feng Ren static void vfio_ccw_reset(DeviceState *dev) 2501dcac3e1SXiao Feng Ren { 251ecba6468SPhilippe Mathieu-Daudé VFIOCCWDevice *vcdev = VFIO_CCW(dev); 2521dcac3e1SXiao Feng Ren 2531dcac3e1SXiao Feng Ren ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET); 2541dcac3e1SXiao Feng Ren } 2551dcac3e1SXiao Feng Ren 256f030532fSFarhan Ali static void vfio_ccw_crw_read(VFIOCCWDevice *vcdev) 257f030532fSFarhan Ali { 258f030532fSFarhan Ali struct ccw_crw_region *region = vcdev->crw_region; 259f030532fSFarhan Ali CRW crw; 260f030532fSFarhan Ali int size; 261f030532fSFarhan Ali 262f030532fSFarhan Ali /* Keep reading CRWs as long as data is returned */ 263f030532fSFarhan Ali do { 264f030532fSFarhan Ali memset(region, 0, sizeof(*region)); 265f030532fSFarhan Ali size = pread(vcdev->vdev.fd, region, vcdev->crw_region_size, 266f030532fSFarhan Ali vcdev->crw_region_offset); 267f030532fSFarhan Ali 268f030532fSFarhan Ali if (size == -1) { 269f030532fSFarhan Ali error_report("vfio-ccw: Read crw region failed with errno=%d", 270f030532fSFarhan Ali errno); 271f030532fSFarhan Ali break; 272f030532fSFarhan Ali } 273f030532fSFarhan Ali 274f030532fSFarhan Ali if (region->crw == 0) { 275f030532fSFarhan Ali /* No more CRWs to queue */ 276f030532fSFarhan Ali break; 277f030532fSFarhan Ali } 278f030532fSFarhan Ali 279f030532fSFarhan Ali memcpy(&crw, ®ion->crw, sizeof(CRW)); 280f030532fSFarhan Ali 281f030532fSFarhan Ali css_crw_add_to_queue(crw); 282f030532fSFarhan Ali } while (1); 283f030532fSFarhan Ali } 284f030532fSFarhan Ali 285b2f96f9eSEric Farman static void vfio_ccw_req_notifier_handler(void *opaque) 286b2f96f9eSEric Farman { 287b2f96f9eSEric Farman VFIOCCWDevice *vcdev = opaque; 288b2f96f9eSEric Farman Error *err = NULL; 289b2f96f9eSEric Farman 290b2f96f9eSEric Farman if (!event_notifier_test_and_clear(&vcdev->req_notifier)) { 291b2f96f9eSEric Farman return; 292b2f96f9eSEric Farman } 293b2f96f9eSEric Farman 294b2f96f9eSEric Farman qdev_unplug(DEVICE(vcdev), &err); 295b2f96f9eSEric Farman if (err) { 296b2f96f9eSEric Farman warn_reportf_err(err, VFIO_MSG_PREFIX, vcdev->vdev.name); 297b2f96f9eSEric Farman } 298b2f96f9eSEric Farman } 299b2f96f9eSEric Farman 300f030532fSFarhan Ali static void vfio_ccw_crw_notifier_handler(void *opaque) 301f030532fSFarhan Ali { 302f030532fSFarhan Ali VFIOCCWDevice *vcdev = opaque; 303f030532fSFarhan Ali 304f030532fSFarhan Ali while (event_notifier_test_and_clear(&vcdev->crw_notifier)) { 305f030532fSFarhan Ali vfio_ccw_crw_read(vcdev); 306f030532fSFarhan Ali } 307f030532fSFarhan Ali } 308f030532fSFarhan Ali 3094886b3e9SDong Jia Shi static void vfio_ccw_io_notifier_handler(void *opaque) 3104886b3e9SDong Jia Shi { 3114886b3e9SDong Jia Shi VFIOCCWDevice *vcdev = opaque; 3128ca2b376SXiao Feng Ren struct ccw_io_region *region = vcdev->io_region; 3134b447883SPhilippe Mathieu-Daudé CcwDevice *ccw_dev = CCW_DEVICE(vcdev); 3148ca2b376SXiao Feng Ren SubchDev *sch = ccw_dev->sch; 315e1d0b372SDaniel P. Berrangé SCHIB *schib = &sch->curr_status; 316e1d0b372SDaniel P. Berrangé SCSW s; 3178ca2b376SXiao Feng Ren IRB irb; 318c626710fSEric Farman ESW esw; 3198ca2b376SXiao Feng Ren int size; 3204886b3e9SDong Jia Shi 3214886b3e9SDong Jia Shi if (!event_notifier_test_and_clear(&vcdev->io_notifier)) { 3224886b3e9SDong Jia Shi return; 3234886b3e9SDong Jia Shi } 3248ca2b376SXiao Feng Ren 3258ca2b376SXiao Feng Ren size = pread(vcdev->vdev.fd, region, vcdev->io_region_size, 3268ca2b376SXiao Feng Ren vcdev->io_region_offset); 3278ca2b376SXiao Feng Ren if (size == -1) { 3288ca2b376SXiao Feng Ren switch (errno) { 3298ca2b376SXiao Feng Ren case ENODEV: 3308ca2b376SXiao Feng Ren /* Generate a deferred cc 3 condition. */ 331e1d0b372SDaniel P. Berrangé schib->scsw.flags |= SCSW_FLAGS_MASK_CC; 332e1d0b372SDaniel P. Berrangé schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; 333e1d0b372SDaniel P. Berrangé schib->scsw.ctrl |= (SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND); 3348ca2b376SXiao Feng Ren goto read_err; 3358ca2b376SXiao Feng Ren case EFAULT: 3368ca2b376SXiao Feng Ren /* Memory problem, generate channel data check. */ 337e1d0b372SDaniel P. Berrangé schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND; 338e1d0b372SDaniel P. Berrangé schib->scsw.cstat = SCSW_CSTAT_DATA_CHECK; 339e1d0b372SDaniel P. Berrangé schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; 340e1d0b372SDaniel P. Berrangé schib->scsw.ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | 3418ca2b376SXiao Feng Ren SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND; 3428ca2b376SXiao Feng Ren goto read_err; 3438ca2b376SXiao Feng Ren default: 3448ca2b376SXiao Feng Ren /* Error, generate channel program check. */ 345e1d0b372SDaniel P. Berrangé schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND; 346e1d0b372SDaniel P. Berrangé schib->scsw.cstat = SCSW_CSTAT_PROG_CHECK; 347e1d0b372SDaniel P. Berrangé schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; 348e1d0b372SDaniel P. Berrangé schib->scsw.ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | 3498ca2b376SXiao Feng Ren SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND; 3508ca2b376SXiao Feng Ren goto read_err; 3518ca2b376SXiao Feng Ren } 3528ca2b376SXiao Feng Ren } else if (size != vcdev->io_region_size) { 3538ca2b376SXiao Feng Ren /* Information transfer error, generate channel-control check. */ 354e1d0b372SDaniel P. Berrangé schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND; 355e1d0b372SDaniel P. Berrangé schib->scsw.cstat = SCSW_CSTAT_CHN_CTRL_CHK; 356e1d0b372SDaniel P. Berrangé schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; 357e1d0b372SDaniel P. Berrangé schib->scsw.ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | 3588ca2b376SXiao Feng Ren SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND; 3598ca2b376SXiao Feng Ren goto read_err; 3608ca2b376SXiao Feng Ren } 3618ca2b376SXiao Feng Ren 3628ca2b376SXiao Feng Ren memcpy(&irb, region->irb_area, sizeof(IRB)); 3638ca2b376SXiao Feng Ren 3648ca2b376SXiao Feng Ren /* Update control block via irb. */ 365e1d0b372SDaniel P. Berrangé s = schib->scsw; 366e1d0b372SDaniel P. Berrangé copy_scsw_to_guest(&s, &irb.scsw); 367e1d0b372SDaniel P. Berrangé schib->scsw = s; 3688ca2b376SXiao Feng Ren 369c626710fSEric Farman copy_esw_to_guest(&esw, &irb.esw); 370c626710fSEric Farman sch->esw = esw; 371c626710fSEric Farman 372334e7685SDong Jia Shi /* If a uint check is pending, copy sense data. */ 373e1d0b372SDaniel P. Berrangé if ((schib->scsw.dstat & SCSW_DSTAT_UNIT_CHECK) && 374e1d0b372SDaniel P. Berrangé (schib->pmcw.chars & PMCW_CHARS_MASK_CSENSE)) { 375334e7685SDong Jia Shi memcpy(sch->sense_data, irb.ecw, sizeof(irb.ecw)); 376334e7685SDong Jia Shi } 377334e7685SDong Jia Shi 3788ca2b376SXiao Feng Ren read_err: 3798ca2b376SXiao Feng Ren css_inject_io_interrupt(sch); 3804886b3e9SDong Jia Shi } 3814886b3e9SDong Jia Shi 3828aaeff97SCédric Le Goater static bool vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev, 383690e29b9SEric Farman unsigned int irq, 384690e29b9SEric Farman Error **errp) 3854886b3e9SDong Jia Shi { 3864886b3e9SDong Jia Shi VFIODevice *vdev = &vcdev->vdev; 38704f8e4f2SCédric Le Goater g_autofree struct vfio_irq_info *irq_info = NULL; 3884886b3e9SDong Jia Shi size_t argsz; 389b5e89f04SCornelia Huck int fd; 390690e29b9SEric Farman EventNotifier *notifier; 391690e29b9SEric Farman IOHandler *fd_read; 3924886b3e9SDong Jia Shi 393690e29b9SEric Farman switch (irq) { 394690e29b9SEric Farman case VFIO_CCW_IO_IRQ_INDEX: 395690e29b9SEric Farman notifier = &vcdev->io_notifier; 396690e29b9SEric Farman fd_read = vfio_ccw_io_notifier_handler; 397690e29b9SEric Farman break; 398f030532fSFarhan Ali case VFIO_CCW_CRW_IRQ_INDEX: 399f030532fSFarhan Ali notifier = &vcdev->crw_notifier; 400f030532fSFarhan Ali fd_read = vfio_ccw_crw_notifier_handler; 401f030532fSFarhan Ali break; 402b2f96f9eSEric Farman case VFIO_CCW_REQ_IRQ_INDEX: 403b2f96f9eSEric Farman notifier = &vcdev->req_notifier; 404b2f96f9eSEric Farman fd_read = vfio_ccw_req_notifier_handler; 405b2f96f9eSEric Farman break; 406690e29b9SEric Farman default: 407690e29b9SEric Farman error_setg(errp, "vfio: Unsupported device irq(%d)", irq); 4088aaeff97SCédric Le Goater return false; 409690e29b9SEric Farman } 410690e29b9SEric Farman 411690e29b9SEric Farman if (vdev->num_irqs < irq + 1) { 4126178d468SEric Farman error_setg(errp, "vfio: IRQ %u not available (number of irqs %u)", 4136178d468SEric Farman irq, vdev->num_irqs); 4148aaeff97SCédric Le Goater return false; 4154886b3e9SDong Jia Shi } 4164886b3e9SDong Jia Shi 41728e22d4bSJing Zhang argsz = sizeof(*irq_info); 4184886b3e9SDong Jia Shi irq_info = g_malloc0(argsz); 419690e29b9SEric Farman irq_info->index = irq; 4204886b3e9SDong Jia Shi irq_info->argsz = argsz; 4214886b3e9SDong Jia Shi if (ioctl(vdev->fd, VFIO_DEVICE_GET_IRQ_INFO, 4224886b3e9SDong Jia Shi irq_info) < 0 || irq_info->count < 1) { 4234886b3e9SDong Jia Shi error_setg_errno(errp, errno, "vfio: Error getting irq info"); 4248aaeff97SCédric Le Goater return false; 4254886b3e9SDong Jia Shi } 4264886b3e9SDong Jia Shi 427690e29b9SEric Farman if (event_notifier_init(notifier, 0)) { 4284886b3e9SDong Jia Shi error_setg_errno(errp, errno, 429690e29b9SEric Farman "vfio: Unable to init event notifier for irq (%d)", 430690e29b9SEric Farman irq); 4318aaeff97SCédric Le Goater return false; 4324886b3e9SDong Jia Shi } 4334886b3e9SDong Jia Shi 434690e29b9SEric Farman fd = event_notifier_get_fd(notifier); 435690e29b9SEric Farman qemu_set_fd_handler(fd, fd_read, NULL, vcdev); 4364886b3e9SDong Jia Shi 43784e37d02SZhenzhong Duan if (!vfio_set_irq_signaling(vdev, irq, 0, 438b5e89f04SCornelia Huck VFIO_IRQ_SET_ACTION_TRIGGER, fd, errp)) { 439b5e89f04SCornelia Huck qemu_set_fd_handler(fd, NULL, NULL, vcdev); 440690e29b9SEric Farman event_notifier_cleanup(notifier); 4414886b3e9SDong Jia Shi } 4428aaeff97SCédric Le Goater 4438aaeff97SCédric Le Goater return true; 4444886b3e9SDong Jia Shi } 4454886b3e9SDong Jia Shi 446690e29b9SEric Farman static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev, 447690e29b9SEric Farman unsigned int irq) 4484886b3e9SDong Jia Shi { 449b5e89f04SCornelia Huck Error *err = NULL; 450690e29b9SEric Farman EventNotifier *notifier; 4514886b3e9SDong Jia Shi 452690e29b9SEric Farman switch (irq) { 453690e29b9SEric Farman case VFIO_CCW_IO_IRQ_INDEX: 454690e29b9SEric Farman notifier = &vcdev->io_notifier; 455690e29b9SEric Farman break; 456f030532fSFarhan Ali case VFIO_CCW_CRW_IRQ_INDEX: 457f030532fSFarhan Ali notifier = &vcdev->crw_notifier; 458f030532fSFarhan Ali break; 459b2f96f9eSEric Farman case VFIO_CCW_REQ_IRQ_INDEX: 460b2f96f9eSEric Farman notifier = &vcdev->req_notifier; 461b2f96f9eSEric Farman break; 462690e29b9SEric Farman default: 463690e29b9SEric Farman error_report("vfio: Unsupported device irq(%d)", irq); 464690e29b9SEric Farman return; 465690e29b9SEric Farman } 466690e29b9SEric Farman 46784e37d02SZhenzhong Duan if (!vfio_set_irq_signaling(&vcdev->vdev, irq, 0, 468f5cf94cdSAlex Williamson VFIO_IRQ_SET_ACTION_TRIGGER, -1, &err)) { 469dcc9cf38SEric Farman warn_reportf_err(err, VFIO_MSG_PREFIX, vcdev->vdev.name); 4704886b3e9SDong Jia Shi } 4714886b3e9SDong Jia Shi 472690e29b9SEric Farman qemu_set_fd_handler(event_notifier_get_fd(notifier), 4734886b3e9SDong Jia Shi NULL, NULL, vcdev); 474690e29b9SEric Farman event_notifier_cleanup(notifier); 4754886b3e9SDong Jia Shi } 4764886b3e9SDong Jia Shi 477040f8d10SZhenzhong Duan static bool vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp) 478c14e706cSDong Jia Shi { 479c14e706cSDong Jia Shi VFIODevice *vdev = &vcdev->vdev; 480c14e706cSDong Jia Shi struct vfio_region_info *info; 481c14e706cSDong Jia Shi int ret; 482c14e706cSDong Jia Shi 483c14e706cSDong Jia Shi /* Sanity check device */ 484c14e706cSDong Jia Shi if (!(vdev->flags & VFIO_DEVICE_FLAGS_CCW)) { 485c14e706cSDong Jia Shi error_setg(errp, "vfio: Um, this isn't a vfio-ccw device"); 486040f8d10SZhenzhong Duan return false; 487c14e706cSDong Jia Shi } 488c14e706cSDong Jia Shi 4898fadea24SCornelia Huck /* 4908fadea24SCornelia Huck * We always expect at least the I/O region to be present. We also 4918fadea24SCornelia Huck * may have a variable number of regions governed by capabilities. 4928fadea24SCornelia Huck */ 493c14e706cSDong Jia Shi if (vdev->num_regions < VFIO_CCW_CONFIG_REGION_INDEX + 1) { 4948fadea24SCornelia Huck error_setg(errp, "vfio: too few regions (%u), expected at least %u", 4958fadea24SCornelia Huck vdev->num_regions, VFIO_CCW_CONFIG_REGION_INDEX + 1); 496040f8d10SZhenzhong Duan return false; 497c14e706cSDong Jia Shi } 498c14e706cSDong Jia Shi 499c14e706cSDong Jia Shi ret = vfio_get_region_info(vdev, VFIO_CCW_CONFIG_REGION_INDEX, &info); 500c14e706cSDong Jia Shi if (ret) { 501c14e706cSDong Jia Shi error_setg_errno(errp, -ret, "vfio: Error getting config info"); 502040f8d10SZhenzhong Duan return false; 503c14e706cSDong Jia Shi } 504c14e706cSDong Jia Shi 505c14e706cSDong Jia Shi vcdev->io_region_size = info->size; 506c14e706cSDong Jia Shi if (sizeof(*vcdev->io_region) != vcdev->io_region_size) { 507c14e706cSDong Jia Shi error_setg(errp, "vfio: Unexpected size of the I/O region"); 5082a3b9cbaSEric Farman goto out_err; 509c14e706cSDong Jia Shi } 510c14e706cSDong Jia Shi 511c14e706cSDong Jia Shi vcdev->io_region_offset = info->offset; 512c14e706cSDong Jia Shi vcdev->io_region = g_malloc0(info->size); 513c8726f7bSCornelia Huck g_free(info); 514c14e706cSDong Jia Shi 5158fadea24SCornelia Huck /* check for the optional async command region */ 5168fadea24SCornelia Huck ret = vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW, 5178fadea24SCornelia Huck VFIO_REGION_SUBTYPE_CCW_ASYNC_CMD, &info); 5188fadea24SCornelia Huck if (!ret) { 5198fadea24SCornelia Huck vcdev->async_cmd_region_size = info->size; 5208fadea24SCornelia Huck if (sizeof(*vcdev->async_cmd_region) != vcdev->async_cmd_region_size) { 5218fadea24SCornelia Huck error_setg(errp, "vfio: Unexpected size of the async cmd region"); 5222a3b9cbaSEric Farman goto out_err; 5238fadea24SCornelia Huck } 5248fadea24SCornelia Huck vcdev->async_cmd_region_offset = info->offset; 5258fadea24SCornelia Huck vcdev->async_cmd_region = g_malloc0(info->size); 526c8726f7bSCornelia Huck g_free(info); 5278fadea24SCornelia Huck } 5288fadea24SCornelia Huck 52946ea3841SFarhan Ali ret = vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW, 53046ea3841SFarhan Ali VFIO_REGION_SUBTYPE_CCW_SCHIB, &info); 53146ea3841SFarhan Ali if (!ret) { 53246ea3841SFarhan Ali vcdev->schib_region_size = info->size; 53346ea3841SFarhan Ali if (sizeof(*vcdev->schib_region) != vcdev->schib_region_size) { 53446ea3841SFarhan Ali error_setg(errp, "vfio: Unexpected size of the schib region"); 53546ea3841SFarhan Ali goto out_err; 53646ea3841SFarhan Ali } 53746ea3841SFarhan Ali vcdev->schib_region_offset = info->offset; 53846ea3841SFarhan Ali vcdev->schib_region = g_malloc(info->size); 539c8726f7bSCornelia Huck g_free(info); 54046ea3841SFarhan Ali } 54146ea3841SFarhan Ali 542f030532fSFarhan Ali ret = vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW, 543f030532fSFarhan Ali VFIO_REGION_SUBTYPE_CCW_CRW, &info); 544f030532fSFarhan Ali 545f030532fSFarhan Ali if (!ret) { 546f030532fSFarhan Ali vcdev->crw_region_size = info->size; 547f030532fSFarhan Ali if (sizeof(*vcdev->crw_region) != vcdev->crw_region_size) { 548f030532fSFarhan Ali error_setg(errp, "vfio: Unexpected size of the CRW region"); 549f030532fSFarhan Ali goto out_err; 550f030532fSFarhan Ali } 551f030532fSFarhan Ali vcdev->crw_region_offset = info->offset; 552f030532fSFarhan Ali vcdev->crw_region = g_malloc(info->size); 553c8726f7bSCornelia Huck g_free(info); 554f030532fSFarhan Ali } 555f030532fSFarhan Ali 556040f8d10SZhenzhong Duan return true; 5572a3b9cbaSEric Farman 5582a3b9cbaSEric Farman out_err: 559f030532fSFarhan Ali g_free(vcdev->crw_region); 56046ea3841SFarhan Ali g_free(vcdev->schib_region); 5612a3b9cbaSEric Farman g_free(vcdev->async_cmd_region); 5622a3b9cbaSEric Farman g_free(vcdev->io_region); 5632a3b9cbaSEric Farman g_free(info); 564040f8d10SZhenzhong Duan return false; 565c14e706cSDong Jia Shi } 566c14e706cSDong Jia Shi 567c14e706cSDong Jia Shi static void vfio_ccw_put_region(VFIOCCWDevice *vcdev) 568c14e706cSDong Jia Shi { 569f030532fSFarhan Ali g_free(vcdev->crw_region); 57046ea3841SFarhan Ali g_free(vcdev->schib_region); 5718fadea24SCornelia Huck g_free(vcdev->async_cmd_region); 572c14e706cSDong Jia Shi g_free(vcdev->io_region); 573c14e706cSDong Jia Shi } 574c14e706cSDong Jia Shi 5751dcac3e1SXiao Feng Ren static void vfio_ccw_realize(DeviceState *dev, Error **errp) 5761dcac3e1SXiao Feng Ren { 5770cea1f62SPhilippe Mathieu-Daudé S390CCWDevice *cdev = S390_CCW_DEVICE(dev); 578ecba6468SPhilippe Mathieu-Daudé VFIOCCWDevice *vcdev = VFIO_CCW(cdev); 5791dcac3e1SXiao Feng Ren S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev); 580e08041ecSEric Auger VFIODevice *vbasedev = &vcdev->vdev; 5811dcac3e1SXiao Feng Ren Error *err = NULL; 5821dcac3e1SXiao Feng Ren 5831dcac3e1SXiao Feng Ren /* Call the class init function for subchannel. */ 5841dcac3e1SXiao Feng Ren if (cdc->realize) { 5851aeebbd6SCédric Le Goater if (!cdc->realize(cdev, vcdev->vdev.sysfsdev, errp)) { 5861aeebbd6SCédric Le Goater return; 5871dcac3e1SXiao Feng Ren } 5881dcac3e1SXiao Feng Ren } 5891dcac3e1SXiao Feng Ren 590c6c6cf91SZhenzhong Duan if (!vfio_device_get_name(vbasedev, errp)) { 591fa805384SZhenzhong Duan goto out_unrealize; 592909a6254SZhenzhong Duan } 593909a6254SZhenzhong Duan 594b7754835SZhenzhong Duan if (!vfio_attach_device(cdev->mdevid, vbasedev, 595b7754835SZhenzhong Duan &address_space_memory, errp)) { 596e08041ecSEric Auger goto out_attach_dev_err; 5971dcac3e1SXiao Feng Ren } 5981dcac3e1SXiao Feng Ren 5991aeebbd6SCédric Le Goater if (!vfio_ccw_get_region(vcdev, errp)) { 600c14e706cSDong Jia Shi goto out_region_err; 601c14e706cSDong Jia Shi } 602c14e706cSDong Jia Shi 6031aeebbd6SCédric Le Goater if (!vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX, errp)) { 604b2f96f9eSEric Farman goto out_io_notifier_err; 6054886b3e9SDong Jia Shi } 6064886b3e9SDong Jia Shi 607f030532fSFarhan Ali if (vcdev->crw_region) { 6088aaeff97SCédric Le Goater if (!vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX, 6091aeebbd6SCédric Le Goater errp)) { 610dcc9cf38SEric Farman goto out_irq_notifier_err; 611f030532fSFarhan Ali } 612f030532fSFarhan Ali } 613f030532fSFarhan Ali 6148aaeff97SCédric Le Goater if (!vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_REQ_IRQ_INDEX, &err)) { 6156178d468SEric Farman /* 6166178d468SEric Farman * Report this error, but do not make it a failing condition. 6176178d468SEric Farman * Lack of this IRQ in the host does not prevent normal operation. 6186178d468SEric Farman */ 619*d48a5404SCédric Le Goater warn_report_err(err); 620b2f96f9eSEric Farman } 621b2f96f9eSEric Farman 6221dcac3e1SXiao Feng Ren return; 6231dcac3e1SXiao Feng Ren 624dcc9cf38SEric Farman out_irq_notifier_err: 625dcc9cf38SEric Farman vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_REQ_IRQ_INDEX); 626dcc9cf38SEric Farman vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX); 627b2f96f9eSEric Farman vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX); 628b2f96f9eSEric Farman out_io_notifier_err: 6294886b3e9SDong Jia Shi vfio_ccw_put_region(vcdev); 630c14e706cSDong Jia Shi out_region_err: 631e08041ecSEric Auger vfio_detach_device(vbasedev); 632e08041ecSEric Auger out_attach_dev_err: 633e08041ecSEric Auger g_free(vbasedev->name); 634fa805384SZhenzhong Duan out_unrealize: 6351dcac3e1SXiao Feng Ren if (cdc->unrealize) { 636b69c3c21SMarkus Armbruster cdc->unrealize(cdev); 6371dcac3e1SXiao Feng Ren } 6381dcac3e1SXiao Feng Ren } 6391dcac3e1SXiao Feng Ren 640b69c3c21SMarkus Armbruster static void vfio_ccw_unrealize(DeviceState *dev) 6411dcac3e1SXiao Feng Ren { 6420cea1f62SPhilippe Mathieu-Daudé S390CCWDevice *cdev = S390_CCW_DEVICE(dev); 643ecba6468SPhilippe Mathieu-Daudé VFIOCCWDevice *vcdev = VFIO_CCW(cdev); 6441dcac3e1SXiao Feng Ren S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev); 6451dcac3e1SXiao Feng Ren 646b2f96f9eSEric Farman vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_REQ_IRQ_INDEX); 647f030532fSFarhan Ali vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX); 648690e29b9SEric Farman vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX); 649c14e706cSDong Jia Shi vfio_ccw_put_region(vcdev); 650e08041ecSEric Auger vfio_detach_device(&vcdev->vdev); 651e08041ecSEric Auger g_free(vcdev->vdev.name); 6521dcac3e1SXiao Feng Ren 6531dcac3e1SXiao Feng Ren if (cdc->unrealize) { 654b69c3c21SMarkus Armbruster cdc->unrealize(cdev); 6551dcac3e1SXiao Feng Ren } 6561dcac3e1SXiao Feng Ren } 6571dcac3e1SXiao Feng Ren 6581dcac3e1SXiao Feng Ren static Property vfio_ccw_properties[] = { 6591dcac3e1SXiao Feng Ren DEFINE_PROP_STRING("sysfsdev", VFIOCCWDevice, vdev.sysfsdev), 6609a51c9eeSHalil Pasic DEFINE_PROP_BOOL("force-orb-pfch", VFIOCCWDevice, force_orb_pfch, false), 661e70f971aSZhenzhong Duan #ifdef CONFIG_IOMMUFD 662e70f971aSZhenzhong Duan DEFINE_PROP_LINK("iommufd", VFIOCCWDevice, vdev.iommufd, 663e70f971aSZhenzhong Duan TYPE_IOMMUFD_BACKEND, IOMMUFDBackend *), 664e70f971aSZhenzhong Duan #endif 6651dcac3e1SXiao Feng Ren DEFINE_PROP_END_OF_LIST(), 6661dcac3e1SXiao Feng Ren }; 6671dcac3e1SXiao Feng Ren 6681dcac3e1SXiao Feng Ren static const VMStateDescription vfio_ccw_vmstate = { 669da56e330SLi Qiang .name = "vfio-ccw", 6701dcac3e1SXiao Feng Ren .unmigratable = 1, 6711dcac3e1SXiao Feng Ren }; 6721dcac3e1SXiao Feng Ren 673909a6254SZhenzhong Duan static void vfio_ccw_instance_init(Object *obj) 674909a6254SZhenzhong Duan { 675909a6254SZhenzhong Duan VFIOCCWDevice *vcdev = VFIO_CCW(obj); 676c12b55adSZhenzhong Duan VFIODevice *vbasedev = &vcdev->vdev; 677909a6254SZhenzhong Duan 678c12b55adSZhenzhong Duan /* 679c12b55adSZhenzhong Duan * All vfio-ccw devices are believed to operate in a way compatible with 680c12b55adSZhenzhong Duan * discarding of memory in RAM blocks, ie. pages pinned in the host are 681c12b55adSZhenzhong Duan * in the current working set of the guest driver and therefore never 682c12b55adSZhenzhong Duan * overlap e.g., with pages available to the guest balloon driver. This 683c12b55adSZhenzhong Duan * needs to be set before vfio_get_device() for vfio common to handle 684c12b55adSZhenzhong Duan * ram_block_discard_disable(). 685c12b55adSZhenzhong Duan */ 6866106a329SZhenzhong Duan vfio_device_init(vbasedev, VFIO_DEVICE_TYPE_CCW, &vfio_ccw_ops, 6876106a329SZhenzhong Duan DEVICE(vcdev), true); 688909a6254SZhenzhong Duan } 689909a6254SZhenzhong Duan 690909a6254SZhenzhong Duan #ifdef CONFIG_IOMMUFD 691909a6254SZhenzhong Duan static void vfio_ccw_set_fd(Object *obj, const char *str, Error **errp) 692909a6254SZhenzhong Duan { 693909a6254SZhenzhong Duan vfio_device_set_fd(&VFIO_CCW(obj)->vdev, str, errp); 694909a6254SZhenzhong Duan } 695909a6254SZhenzhong Duan #endif 696909a6254SZhenzhong Duan 6971dcac3e1SXiao Feng Ren static void vfio_ccw_class_init(ObjectClass *klass, void *data) 6981dcac3e1SXiao Feng Ren { 6991dcac3e1SXiao Feng Ren DeviceClass *dc = DEVICE_CLASS(klass); 7008ca2b376SXiao Feng Ren S390CCWDeviceClass *cdc = S390_CCW_DEVICE_CLASS(klass); 7011dcac3e1SXiao Feng Ren 7024f67d30bSMarc-André Lureau device_class_set_props(dc, vfio_ccw_properties); 703909a6254SZhenzhong Duan #ifdef CONFIG_IOMMUFD 704909a6254SZhenzhong Duan object_class_property_add_str(klass, "fd", NULL, vfio_ccw_set_fd); 705909a6254SZhenzhong Duan #endif 7061dcac3e1SXiao Feng Ren dc->vmsd = &vfio_ccw_vmstate; 7071dcac3e1SXiao Feng Ren dc->desc = "VFIO-based subchannel assignment"; 708bd2aef10SCornelia Huck set_bit(DEVICE_CATEGORY_MISC, dc->categories); 7091dcac3e1SXiao Feng Ren dc->realize = vfio_ccw_realize; 7101dcac3e1SXiao Feng Ren dc->unrealize = vfio_ccw_unrealize; 7111dcac3e1SXiao Feng Ren dc->reset = vfio_ccw_reset; 7128ca2b376SXiao Feng Ren 7138ca2b376SXiao Feng Ren cdc->handle_request = vfio_ccw_handle_request; 7148fadea24SCornelia Huck cdc->handle_halt = vfio_ccw_handle_halt; 7158fadea24SCornelia Huck cdc->handle_clear = vfio_ccw_handle_clear; 71646ea3841SFarhan Ali cdc->handle_store = vfio_ccw_handle_store; 7171dcac3e1SXiao Feng Ren } 7181dcac3e1SXiao Feng Ren 7191dcac3e1SXiao Feng Ren static const TypeInfo vfio_ccw_info = { 7201dcac3e1SXiao Feng Ren .name = TYPE_VFIO_CCW, 7211dcac3e1SXiao Feng Ren .parent = TYPE_S390_CCW, 7221dcac3e1SXiao Feng Ren .instance_size = sizeof(VFIOCCWDevice), 723909a6254SZhenzhong Duan .instance_init = vfio_ccw_instance_init, 7241dcac3e1SXiao Feng Ren .class_init = vfio_ccw_class_init, 7251dcac3e1SXiao Feng Ren }; 7261dcac3e1SXiao Feng Ren 7271dcac3e1SXiao Feng Ren static void register_vfio_ccw_type(void) 7281dcac3e1SXiao Feng Ren { 7291dcac3e1SXiao Feng Ren type_register_static(&vfio_ccw_info); 7301dcac3e1SXiao Feng Ren } 7311dcac3e1SXiao Feng Ren 7321dcac3e1SXiao Feng Ren type_init(register_vfio_ccw_type) 733