2 * vfio based subchannel assignment support
4 * Copyright 2017 IBM Corp.
5 * Copyright 2019 Red Hat, Inc.
7 * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
8 * Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
9 * Pierre Morel <pmorel@linux.vnet.ibm.com>
10 * Cornelia Huck <cohuck@redhat.com>
12 * This work is licensed under the terms of the GNU GPL, version 2 or (at
13 * your option) any later version. See the COPYING file in the top-level
17 #include "qemu/osdep.h"
18 #include <linux/vfio.h>
19 #include <linux/vfio_ccw.h>
20 #include <sys/ioctl.h>
22 #include "qapi/error.h"
23 #include "hw/sysbus.h"
24 #include "hw/vfio/vfio.h"
25 #include "hw/vfio/vfio-common.h"
26 #include "hw/s390x/s390-ccw.h"
27 #include "hw/s390x/vfio-ccw.h"
28 #include "hw/qdev-properties.h"
29 #include "hw/s390x/ccw-device.h"
30 #include "exec/address-spaces.h"
31 #include "qemu/error-report.h"
32 #include "qemu/main-loop.h"
33 #include "qemu/module.h"
35 struct VFIOCCWDevice
{
38 uint64_t io_region_size
;
39 uint64_t io_region_offset
;
40 struct ccw_io_region
*io_region
;
41 uint64_t async_cmd_region_size
;
42 uint64_t async_cmd_region_offset
;
43 struct ccw_cmd_region
*async_cmd_region
;
44 uint64_t schib_region_size
;
45 uint64_t schib_region_offset
;
46 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
;
50 EventNotifier io_notifier
;
51 EventNotifier crw_notifier
;
52 EventNotifier req_notifier
;
57 static inline void warn_once_pfch(VFIOCCWDevice
*vcdev
, SubchDev
*sch
,
60 warn_report_once_cond(&vcdev
->warned_orb_pfch
,
61 "vfio-ccw (devno %x.%x.%04x): %s",
62 sch
->cssid
, sch
->ssid
, sch
->devno
, msg
);
65 static void vfio_ccw_compute_needs_reset(VFIODevice
*vdev
)
67 vdev
->needs_reset
= false;
71 * We don't need vfio_hot_reset_multi and vfio_eoi operations for
72 * vfio_ccw device now.
74 struct VFIODeviceOps vfio_ccw_ops
= {
75 .vfio_compute_needs_reset
= vfio_ccw_compute_needs_reset
,
78 static IOInstEnding
vfio_ccw_handle_request(SubchDev
*sch
)
80 S390CCWDevice
*cdev
= sch
->driver_data
;
81 VFIOCCWDevice
*vcdev
= DO_UPCAST(VFIOCCWDevice
, cdev
, cdev
);
82 struct ccw_io_region
*region
= vcdev
->io_region
;
85 if (!(sch
->orb
.ctrl0
& ORB_CTRL0_MASK_PFCH
) && vcdev
->force_orb_pfch
) {
86 sch
->orb
.ctrl0
|= ORB_CTRL0_MASK_PFCH
;
87 warn_once_pfch(vcdev
, sch
, "PFCH flag forced");
90 QEMU_BUILD_BUG_ON(sizeof(region
->orb_area
) != sizeof(ORB
));
91 QEMU_BUILD_BUG_ON(sizeof(region
->scsw_area
) != sizeof(SCSW
));
92 QEMU_BUILD_BUG_ON(sizeof(region
->irb_area
) != sizeof(IRB
));
94 memset(region
, 0, sizeof(*region
));
96 memcpy(region
->orb_area
, &sch
->orb
, sizeof(ORB
));
97 memcpy(region
->scsw_area
, &sch
->curr_status
.scsw
, sizeof(SCSW
));
100 ret
= pwrite(vcdev
->vdev
.fd
, region
,
101 vcdev
->io_region_size
, vcdev
->io_region_offset
);
102 if (ret
!= vcdev
->io_region_size
) {
103 if (errno
== EAGAIN
) {
106 error_report("vfio-ccw: write I/O region failed with errno=%d", errno
);
107 ret
= errno
? -errno
: -EFAULT
;
113 return IOINST_CC_EXPECTED
;
115 return IOINST_CC_BUSY
;
118 return IOINST_CC_NOT_OPERATIONAL
;
121 sch_gen_unit_exception(sch
);
122 css_inject_io_interrupt(sch
);
123 return IOINST_CC_EXPECTED
;
127 static IOInstEnding
vfio_ccw_handle_store(SubchDev
*sch
)
129 S390CCWDevice
*cdev
= sch
->driver_data
;
130 VFIOCCWDevice
*vcdev
= DO_UPCAST(VFIOCCWDevice
, cdev
, cdev
);
131 SCHIB
*schib
= &sch
->curr_status
;
132 struct ccw_schib_region
*region
= vcdev
->schib_region
;
136 /* schib region not available so nothing else to do */
138 return IOINST_CC_EXPECTED
;
141 memset(region
, 0, sizeof(*region
));
142 ret
= pread(vcdev
->vdev
.fd
, region
, vcdev
->schib_region_size
,
143 vcdev
->schib_region_offset
);
147 * Device is probably damaged, but store subchannel does not
148 * have a nonzero cc defined for this scenario. Log an error,
149 * and presume things are otherwise fine.
151 error_report("vfio-ccw: store region read failed with errno=%d", errno
);
152 return IOINST_CC_EXPECTED
;
156 * Selectively copy path-related bits of the SCHIB,
157 * rather than copying the entire struct.
159 s
= (SCHIB
*)region
->schib_area
;
160 schib
->pmcw
.pnom
= s
->pmcw
.pnom
;
161 schib
->pmcw
.lpum
= s
->pmcw
.lpum
;
162 schib
->pmcw
.pam
= s
->pmcw
.pam
;
163 schib
->pmcw
.pom
= s
->pmcw
.pom
;
165 if (s
->scsw
.flags
& SCSW_FLAGS_MASK_PNO
) {
166 schib
->scsw
.flags
|= SCSW_FLAGS_MASK_PNO
;
169 return IOINST_CC_EXPECTED
;
172 static int vfio_ccw_handle_clear(SubchDev
*sch
)
174 S390CCWDevice
*cdev
= sch
->driver_data
;
175 VFIOCCWDevice
*vcdev
= DO_UPCAST(VFIOCCWDevice
, cdev
, cdev
);
176 struct ccw_cmd_region
*region
= vcdev
->async_cmd_region
;
179 if (!vcdev
->async_cmd_region
) {
180 /* Async command region not available, fall back to emulation */
184 memset(region
, 0, sizeof(*region
));
185 region
->command
= VFIO_CCW_ASYNC_CMD_CSCH
;
188 ret
= pwrite(vcdev
->vdev
.fd
, region
,
189 vcdev
->async_cmd_region_size
, vcdev
->async_cmd_region_offset
);
190 if (ret
!= vcdev
->async_cmd_region_size
) {
191 if (errno
== EAGAIN
) {
194 error_report("vfio-ccw: write cmd region failed with errno=%d", errno
);
195 ret
= errno
? -errno
: -EFAULT
;
206 sch_gen_unit_exception(sch
);
207 css_inject_io_interrupt(sch
);
212 static int vfio_ccw_handle_halt(SubchDev
*sch
)
214 S390CCWDevice
*cdev
= sch
->driver_data
;
215 VFIOCCWDevice
*vcdev
= DO_UPCAST(VFIOCCWDevice
, cdev
, cdev
);
216 struct ccw_cmd_region
*region
= vcdev
->async_cmd_region
;
219 if (!vcdev
->async_cmd_region
) {
220 /* Async command region not available, fall back to emulation */
224 memset(region
, 0, sizeof(*region
));
225 region
->command
= VFIO_CCW_ASYNC_CMD_HSCH
;
228 ret
= pwrite(vcdev
->vdev
.fd
, region
,
229 vcdev
->async_cmd_region_size
, vcdev
->async_cmd_region_offset
);
230 if (ret
!= vcdev
->async_cmd_region_size
) {
231 if (errno
== EAGAIN
) {
234 error_report("vfio-ccw: write cmd region failed with errno=%d", errno
);
235 ret
= errno
? -errno
: -EFAULT
;
247 sch_gen_unit_exception(sch
);
248 css_inject_io_interrupt(sch
);
253 static void vfio_ccw_reset(DeviceState
*dev
)
255 CcwDevice
*ccw_dev
= DO_UPCAST(CcwDevice
, parent_obj
, dev
);
256 S390CCWDevice
*cdev
= DO_UPCAST(S390CCWDevice
, parent_obj
, ccw_dev
);
257 VFIOCCWDevice
*vcdev
= DO_UPCAST(VFIOCCWDevice
, cdev
, cdev
);
259 ioctl(vcdev
->vdev
.fd
, VFIO_DEVICE_RESET
);
262 static void vfio_ccw_crw_read(VFIOCCWDevice
*vcdev
)
264 struct ccw_crw_region
*region
= vcdev
->crw_region
;
268 /* Keep reading CRWs as long as data is returned */
270 memset(region
, 0, sizeof(*region
));
271 size
= pread(vcdev
->vdev
.fd
, region
, vcdev
->crw_region_size
,
272 vcdev
->crw_region_offset
);
275 error_report("vfio-ccw: Read crw region failed with errno=%d",
280 if (region
->crw
== 0) {
281 /* No more CRWs to queue */
285 memcpy(&crw
, ®ion
->crw
, sizeof(CRW
));
287 css_crw_add_to_queue(crw
);
291 static void vfio_ccw_req_notifier_handler(void *opaque
)
293 VFIOCCWDevice
*vcdev
= opaque
;
296 if (!event_notifier_test_and_clear(&vcdev
->req_notifier
)) {
300 qdev_unplug(DEVICE(vcdev
), &err
);
302 warn_reportf_err(err
, VFIO_MSG_PREFIX
, vcdev
->vdev
.name
);
306 static void vfio_ccw_crw_notifier_handler(void *opaque
)
308 VFIOCCWDevice
*vcdev
= opaque
;
310 while (event_notifier_test_and_clear(&vcdev
->crw_notifier
)) {
311 vfio_ccw_crw_read(vcdev
);
315 static void vfio_ccw_io_notifier_handler(void *opaque
)
317 VFIOCCWDevice
*vcdev
= opaque
;
318 struct ccw_io_region
*region
= vcdev
->io_region
;
319 S390CCWDevice
*cdev
= S390_CCW_DEVICE(vcdev
);
320 CcwDevice
*ccw_dev
= CCW_DEVICE(cdev
);
321 SubchDev
*sch
= ccw_dev
->sch
;
322 SCHIB
*schib
= &sch
->curr_status
;
327 if (!event_notifier_test_and_clear(&vcdev
->io_notifier
)) {
331 size
= pread(vcdev
->vdev
.fd
, region
, vcdev
->io_region_size
,
332 vcdev
->io_region_offset
);
336 /* Generate a deferred cc 3 condition. */
337 schib
->scsw
.flags
|= SCSW_FLAGS_MASK_CC
;
338 schib
->scsw
.ctrl
&= ~SCSW_CTRL_MASK_STCTL
;
339 schib
->scsw
.ctrl
|= (SCSW_STCTL_ALERT
| SCSW_STCTL_STATUS_PEND
);
342 /* Memory problem, generate channel data check. */
343 schib
->scsw
.ctrl
&= ~SCSW_ACTL_START_PEND
;
344 schib
->scsw
.cstat
= SCSW_CSTAT_DATA_CHECK
;
345 schib
->scsw
.ctrl
&= ~SCSW_CTRL_MASK_STCTL
;
346 schib
->scsw
.ctrl
|= SCSW_STCTL_PRIMARY
| SCSW_STCTL_SECONDARY
|
347 SCSW_STCTL_ALERT
| SCSW_STCTL_STATUS_PEND
;
350 /* Error, generate channel program check. */
351 schib
->scsw
.ctrl
&= ~SCSW_ACTL_START_PEND
;
352 schib
->scsw
.cstat
= SCSW_CSTAT_PROG_CHECK
;
353 schib
->scsw
.ctrl
&= ~SCSW_CTRL_MASK_STCTL
;
354 schib
->scsw
.ctrl
|= SCSW_STCTL_PRIMARY
| SCSW_STCTL_SECONDARY
|
355 SCSW_STCTL_ALERT
| SCSW_STCTL_STATUS_PEND
;
358 } else if (size
!= vcdev
->io_region_size
) {
359 /* Information transfer error, generate channel-control check. */
360 schib
->scsw
.ctrl
&= ~SCSW_ACTL_START_PEND
;
361 schib
->scsw
.cstat
= SCSW_CSTAT_CHN_CTRL_CHK
;
362 schib
->scsw
.ctrl
&= ~SCSW_CTRL_MASK_STCTL
;
363 schib
->scsw
.ctrl
|= SCSW_STCTL_PRIMARY
| SCSW_STCTL_SECONDARY
|
364 SCSW_STCTL_ALERT
| SCSW_STCTL_STATUS_PEND
;
368 memcpy(&irb
, region
->irb_area
, sizeof(IRB
));
370 /* Update control block via irb. */
372 copy_scsw_to_guest(&s
, &irb
.scsw
);
375 /* If a uint check is pending, copy sense data. */
376 if ((schib
->scsw
.dstat
& SCSW_DSTAT_UNIT_CHECK
) &&
377 (schib
->pmcw
.chars
& PMCW_CHARS_MASK_CSENSE
)) {
378 memcpy(sch
->sense_data
, irb
.ecw
, sizeof(irb
.ecw
));
382 css_inject_io_interrupt(sch
);
385 static void vfio_ccw_register_irq_notifier(VFIOCCWDevice
*vcdev
,
389 VFIODevice
*vdev
= &vcdev
->vdev
;
390 struct vfio_irq_info
*irq_info
;
393 EventNotifier
*notifier
;
397 case VFIO_CCW_IO_IRQ_INDEX
:
398 notifier
= &vcdev
->io_notifier
;
399 fd_read
= vfio_ccw_io_notifier_handler
;
401 case VFIO_CCW_CRW_IRQ_INDEX
:
402 notifier
= &vcdev
->crw_notifier
;
403 fd_read
= vfio_ccw_crw_notifier_handler
;
405 case VFIO_CCW_REQ_IRQ_INDEX
:
406 notifier
= &vcdev
->req_notifier
;
407 fd_read
= vfio_ccw_req_notifier_handler
;
410 error_setg(errp
, "vfio: Unsupported device irq(%d)", irq
);
414 if (vdev
->num_irqs
< irq
+ 1) {
415 error_setg(errp
, "vfio: unexpected number of irqs %u",
420 argsz
= sizeof(*irq_info
);
421 irq_info
= g_malloc0(argsz
);
422 irq_info
->index
= irq
;
423 irq_info
->argsz
= argsz
;
424 if (ioctl(vdev
->fd
, VFIO_DEVICE_GET_IRQ_INFO
,
425 irq_info
) < 0 || irq_info
->count
< 1) {
426 error_setg_errno(errp
, errno
, "vfio: Error getting irq info");
430 if (event_notifier_init(notifier
, 0)) {
431 error_setg_errno(errp
, errno
,
432 "vfio: Unable to init event notifier for irq (%d)",
437 fd
= event_notifier_get_fd(notifier
);
438 qemu_set_fd_handler(fd
, fd_read
, NULL
, vcdev
);
440 if (vfio_set_irq_signaling(vdev
, irq
, 0,
441 VFIO_IRQ_SET_ACTION_TRIGGER
, fd
, errp
)) {
442 qemu_set_fd_handler(fd
, NULL
, NULL
, vcdev
);
443 event_notifier_cleanup(notifier
);
450 static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice
*vcdev
,
454 EventNotifier
*notifier
;
457 case VFIO_CCW_IO_IRQ_INDEX
:
458 notifier
= &vcdev
->io_notifier
;
460 case VFIO_CCW_CRW_IRQ_INDEX
:
461 notifier
= &vcdev
->crw_notifier
;
463 case VFIO_CCW_REQ_IRQ_INDEX
:
464 notifier
= &vcdev
->req_notifier
;
467 error_report("vfio: Unsupported device irq(%d)", irq
);
471 if (vfio_set_irq_signaling(&vcdev
->vdev
, irq
, 0,
472 VFIO_IRQ_SET_ACTION_TRIGGER
, -1, &err
)) {
473 error_reportf_err(err
, VFIO_MSG_PREFIX
, vcdev
->vdev
.name
);
476 qemu_set_fd_handler(event_notifier_get_fd(notifier
),
478 event_notifier_cleanup(notifier
);
481 static void vfio_ccw_get_region(VFIOCCWDevice
*vcdev
, Error
**errp
)
483 VFIODevice
*vdev
= &vcdev
->vdev
;
484 struct vfio_region_info
*info
;
487 /* Sanity check device */
488 if (!(vdev
->flags
& VFIO_DEVICE_FLAGS_CCW
)) {
489 error_setg(errp
, "vfio: Um, this isn't a vfio-ccw device");
494 * We always expect at least the I/O region to be present. We also
495 * may have a variable number of regions governed by capabilities.
497 if (vdev
->num_regions
< VFIO_CCW_CONFIG_REGION_INDEX
+ 1) {
498 error_setg(errp
, "vfio: too few regions (%u), expected at least %u",
499 vdev
->num_regions
, VFIO_CCW_CONFIG_REGION_INDEX
+ 1);
503 ret
= vfio_get_region_info(vdev
, VFIO_CCW_CONFIG_REGION_INDEX
, &info
);
505 error_setg_errno(errp
, -ret
, "vfio: Error getting config info");
509 vcdev
->io_region_size
= info
->size
;
510 if (sizeof(*vcdev
->io_region
) != vcdev
->io_region_size
) {
511 error_setg(errp
, "vfio: Unexpected size of the I/O region");
515 vcdev
->io_region_offset
= info
->offset
;
516 vcdev
->io_region
= g_malloc0(info
->size
);
519 /* check for the optional async command region */
520 ret
= vfio_get_dev_region_info(vdev
, VFIO_REGION_TYPE_CCW
,
521 VFIO_REGION_SUBTYPE_CCW_ASYNC_CMD
, &info
);
523 vcdev
->async_cmd_region_size
= info
->size
;
524 if (sizeof(*vcdev
->async_cmd_region
) != vcdev
->async_cmd_region_size
) {
525 error_setg(errp
, "vfio: Unexpected size of the async cmd region");
528 vcdev
->async_cmd_region_offset
= info
->offset
;
529 vcdev
->async_cmd_region
= g_malloc0(info
->size
);
533 ret
= vfio_get_dev_region_info(vdev
, VFIO_REGION_TYPE_CCW
,
534 VFIO_REGION_SUBTYPE_CCW_SCHIB
, &info
);
536 vcdev
->schib_region_size
= info
->size
;
537 if (sizeof(*vcdev
->schib_region
) != vcdev
->schib_region_size
) {
538 error_setg(errp
, "vfio: Unexpected size of the schib region");
541 vcdev
->schib_region_offset
= info
->offset
;
542 vcdev
->schib_region
= g_malloc(info
->size
);
546 ret
= vfio_get_dev_region_info(vdev
, VFIO_REGION_TYPE_CCW
,
547 VFIO_REGION_SUBTYPE_CCW_CRW
, &info
);
550 vcdev
->crw_region_size
= info
->size
;
551 if (sizeof(*vcdev
->crw_region
) != vcdev
->crw_region_size
) {
552 error_setg(errp
, "vfio: Unexpected size of the CRW region");
555 vcdev
->crw_region_offset
= info
->offset
;
556 vcdev
->crw_region
= g_malloc(info
->size
);
563 g_free(vcdev
->crw_region
);
564 g_free(vcdev
->schib_region
);
565 g_free(vcdev
->async_cmd_region
);
566 g_free(vcdev
->io_region
);
571 static void vfio_ccw_put_region(VFIOCCWDevice
*vcdev
)
573 g_free(vcdev
->crw_region
);
574 g_free(vcdev
->schib_region
);
575 g_free(vcdev
->async_cmd_region
);
576 g_free(vcdev
->io_region
);
579 static void vfio_ccw_put_device(VFIOCCWDevice
*vcdev
)
581 g_free(vcdev
->vdev
.name
);
582 vfio_put_base_device(&vcdev
->vdev
);
585 static void vfio_ccw_get_device(VFIOGroup
*group
, VFIOCCWDevice
*vcdev
,
588 char *name
= g_strdup_printf("%x.%x.%04x", vcdev
->cdev
.hostid
.cssid
,
589 vcdev
->cdev
.hostid
.ssid
,
590 vcdev
->cdev
.hostid
.devid
);
591 VFIODevice
*vbasedev
;
593 QLIST_FOREACH(vbasedev
, &group
->device_list
, next
) {
594 if (strcmp(vbasedev
->name
, name
) == 0) {
595 error_setg(errp
, "vfio: subchannel %s has already been attached",
602 * All vfio-ccw devices are believed to operate in a way compatible with
603 * discarding of memory in RAM blocks, ie. pages pinned in the host are
604 * in the current working set of the guest driver and therefore never
605 * overlap e.g., with pages available to the guest balloon driver. This
606 * needs to be set before vfio_get_device() for vfio common to handle
607 * ram_block_discard_disable().
609 vcdev
->vdev
.ram_block_discard_allowed
= true;
611 if (vfio_get_device(group
, vcdev
->cdev
.mdevid
, &vcdev
->vdev
, errp
)) {
615 vcdev
->vdev
.ops
= &vfio_ccw_ops
;
616 vcdev
->vdev
.type
= VFIO_DEVICE_TYPE_CCW
;
617 vcdev
->vdev
.name
= name
;
618 vcdev
->vdev
.dev
= &vcdev
->cdev
.parent_obj
.parent_obj
;
626 static VFIOGroup
*vfio_ccw_get_group(S390CCWDevice
*cdev
, Error
**errp
)
628 char *tmp
, group_path
[PATH_MAX
];
632 tmp
= g_strdup_printf("/sys/bus/css/devices/%x.%x.%04x/%s/iommu_group",
633 cdev
->hostid
.cssid
, cdev
->hostid
.ssid
,
634 cdev
->hostid
.devid
, cdev
->mdevid
);
635 len
= readlink(tmp
, group_path
, sizeof(group_path
));
638 if (len
<= 0 || len
>= sizeof(group_path
)) {
639 error_setg(errp
, "vfio: no iommu_group found");
645 if (sscanf(basename(group_path
), "%d", &groupid
) != 1) {
646 error_setg(errp
, "vfio: failed to read %s", group_path
);
650 return vfio_get_group(groupid
, &address_space_memory
, errp
);
653 static void vfio_ccw_realize(DeviceState
*dev
, Error
**errp
)
656 CcwDevice
*ccw_dev
= DO_UPCAST(CcwDevice
, parent_obj
, dev
);
657 S390CCWDevice
*cdev
= DO_UPCAST(S390CCWDevice
, parent_obj
, ccw_dev
);
658 VFIOCCWDevice
*vcdev
= DO_UPCAST(VFIOCCWDevice
, cdev
, cdev
);
659 S390CCWDeviceClass
*cdc
= S390_CCW_DEVICE_GET_CLASS(cdev
);
662 /* Call the class init function for subchannel. */
664 cdc
->realize(cdev
, vcdev
->vdev
.sysfsdev
, &err
);
666 goto out_err_propagate
;
670 group
= vfio_ccw_get_group(cdev
, &err
);
675 vfio_ccw_get_device(group
, vcdev
, &err
);
680 vfio_ccw_get_region(vcdev
, &err
);
685 vfio_ccw_register_irq_notifier(vcdev
, VFIO_CCW_IO_IRQ_INDEX
, &err
);
687 goto out_io_notifier_err
;
690 if (vcdev
->crw_region
) {
691 vfio_ccw_register_irq_notifier(vcdev
, VFIO_CCW_CRW_IRQ_INDEX
, &err
);
693 goto out_crw_notifier_err
;
697 vfio_ccw_register_irq_notifier(vcdev
, VFIO_CCW_REQ_IRQ_INDEX
, &err
);
699 goto out_req_notifier_err
;
704 out_req_notifier_err
:
705 vfio_ccw_unregister_irq_notifier(vcdev
, VFIO_CCW_CRW_IRQ_INDEX
);
706 out_crw_notifier_err
:
707 vfio_ccw_unregister_irq_notifier(vcdev
, VFIO_CCW_IO_IRQ_INDEX
);
709 vfio_ccw_put_region(vcdev
);
711 vfio_ccw_put_device(vcdev
);
713 vfio_put_group(group
);
715 if (cdc
->unrealize
) {
716 cdc
->unrealize(cdev
);
719 error_propagate(errp
, err
);
722 static void vfio_ccw_unrealize(DeviceState
*dev
)
724 CcwDevice
*ccw_dev
= DO_UPCAST(CcwDevice
, parent_obj
, dev
);
725 S390CCWDevice
*cdev
= DO_UPCAST(S390CCWDevice
, parent_obj
, ccw_dev
);
726 VFIOCCWDevice
*vcdev
= DO_UPCAST(VFIOCCWDevice
, cdev
, cdev
);
727 S390CCWDeviceClass
*cdc
= S390_CCW_DEVICE_GET_CLASS(cdev
);
728 VFIOGroup
*group
= vcdev
->vdev
.group
;
730 vfio_ccw_unregister_irq_notifier(vcdev
, VFIO_CCW_REQ_IRQ_INDEX
);
731 vfio_ccw_unregister_irq_notifier(vcdev
, VFIO_CCW_CRW_IRQ_INDEX
);
732 vfio_ccw_unregister_irq_notifier(vcdev
, VFIO_CCW_IO_IRQ_INDEX
);
733 vfio_ccw_put_region(vcdev
);
734 vfio_ccw_put_device(vcdev
);
735 vfio_put_group(group
);
737 if (cdc
->unrealize
) {
738 cdc
->unrealize(cdev
);
742 static Property vfio_ccw_properties
[] = {
743 DEFINE_PROP_STRING("sysfsdev", VFIOCCWDevice
, vdev
.sysfsdev
),
744 DEFINE_PROP_BOOL("force-orb-pfch", VFIOCCWDevice
, force_orb_pfch
, false),
745 DEFINE_PROP_END_OF_LIST(),
748 static const VMStateDescription vfio_ccw_vmstate
= {
753 static void vfio_ccw_class_init(ObjectClass
*klass
, void *data
)
755 DeviceClass
*dc
= DEVICE_CLASS(klass
);
756 S390CCWDeviceClass
*cdc
= S390_CCW_DEVICE_CLASS(klass
);
758 device_class_set_props(dc
, vfio_ccw_properties
);
759 dc
->vmsd
= &vfio_ccw_vmstate
;
760 dc
->desc
= "VFIO-based subchannel assignment";
761 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
762 dc
->realize
= vfio_ccw_realize
;
763 dc
->unrealize
= vfio_ccw_unrealize
;
764 dc
->reset
= vfio_ccw_reset
;
766 cdc
->handle_request
= vfio_ccw_handle_request
;
767 cdc
->handle_halt
= vfio_ccw_handle_halt
;
768 cdc
->handle_clear
= vfio_ccw_handle_clear
;
769 cdc
->handle_store
= vfio_ccw_handle_store
;
772 static const TypeInfo vfio_ccw_info
= {
773 .name
= TYPE_VFIO_CCW
,
774 .parent
= TYPE_S390_CCW
,
775 .instance_size
= sizeof(VFIOCCWDevice
),
776 .class_init
= vfio_ccw_class_init
,
779 static void register_vfio_ccw_type(void)
781 type_register_static(&vfio_ccw_info
);
784 type_init(register_vfio_ccw_type
)