2 * s390 CCW Assignment Support
4 * Copyright 2017 IBM Corp
5 * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
6 * Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
7 * Pierre Morel <pmorel@linux.vnet.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2
10 * or (at your option) any later version. See the COPYING file in the
11 * top-level directory.
14 #include "qemu/osdep.h"
16 #include "qapi/error.h"
17 #include "hw/sysbus.h"
18 #include "hw/s390x/css.h"
19 #include "hw/s390x/css-bridge.h"
20 #include "hw/s390x/s390-ccw.h"
22 IOInstEnding
s390_ccw_cmd_request(SubchDev
*sch
)
24 S390CCWDeviceClass
*cdc
= S390_CCW_DEVICE_GET_CLASS(sch
->driver_data
);
26 if (!cdc
->handle_request
) {
27 return IOINST_CC_STATUS_PRESENT
;
29 return cdc
->handle_request(sch
);
32 static void s390_ccw_get_dev_info(S390CCWDevice
*cdev
,
36 unsigned int cssid
, ssid
, devid
;
37 char dev_path
[PATH_MAX
] = {0}, *tmp
;
40 error_setg(errp
, "No host device provided");
41 error_append_hint(errp
,
42 "Use -device vfio-ccw,sysfsdev=PATH_TO_DEVICE\n");
46 if (!realpath(sysfsdev
, dev_path
)) {
47 error_setg_errno(errp
, errno
, "Host device '%s' not found", sysfsdev
);
51 cdev
->mdevid
= g_path_get_basename(dev_path
);
53 tmp
= basename(dirname(dev_path
));
54 if (sscanf(tmp
, "%2x.%1x.%4x", &cssid
, &ssid
, &devid
) != 3) {
55 error_setg_errno(errp
, errno
, "Failed to read %s", tmp
);
59 cdev
->hostid
.cssid
= cssid
;
60 cdev
->hostid
.ssid
= ssid
;
61 cdev
->hostid
.devid
= devid
;
62 cdev
->hostid
.valid
= true;
65 static void s390_ccw_realize(S390CCWDevice
*cdev
, char *sysfsdev
, Error
**errp
)
67 CcwDevice
*ccw_dev
= CCW_DEVICE(cdev
);
68 CCWDeviceClass
*ck
= CCW_DEVICE_GET_CLASS(ccw_dev
);
69 DeviceState
*parent
= DEVICE(ccw_dev
);
74 s390_ccw_get_dev_info(cdev
, sysfsdev
, &err
);
76 goto out_err_propagate
;
79 sch
= css_create_sch(ccw_dev
->devno
, &err
);
83 sch
->driver_data
= cdev
;
84 sch
->do_subchannel_work
= do_subchannel_work_passthrough
;
87 ret
= css_sch_build_schib(sch
, &cdev
->hostid
);
89 error_setg_errno(&err
, -ret
, "%s: Failed to build initial schib",
94 ck
->realize(ccw_dev
, &err
);
99 css_generate_sch_crws(sch
->cssid
, sch
->ssid
, sch
->schid
,
100 parent
->hotplugged
, 1);
104 css_subch_assign(sch
->cssid
, sch
->ssid
, sch
->schid
, sch
->devno
, NULL
);
108 g_free(cdev
->mdevid
);
110 error_propagate(errp
, err
);
113 static void s390_ccw_unrealize(S390CCWDevice
*cdev
, Error
**errp
)
115 CcwDevice
*ccw_dev
= CCW_DEVICE(cdev
);
116 SubchDev
*sch
= ccw_dev
->sch
;
119 css_subch_assign(sch
->cssid
, sch
->ssid
, sch
->schid
, sch
->devno
, NULL
);
124 g_free(cdev
->mdevid
);
127 static void s390_ccw_class_init(ObjectClass
*klass
, void *data
)
129 DeviceClass
*dc
= DEVICE_CLASS(klass
);
130 S390CCWDeviceClass
*cdc
= S390_CCW_DEVICE_CLASS(klass
);
132 dc
->bus_type
= TYPE_VIRTUAL_CSS_BUS
;
133 cdc
->realize
= s390_ccw_realize
;
134 cdc
->unrealize
= s390_ccw_unrealize
;
137 static const TypeInfo s390_ccw_info
= {
138 .name
= TYPE_S390_CCW
,
139 .parent
= TYPE_CCW_DEVICE
,
140 .instance_size
= sizeof(S390CCWDevice
),
141 .class_size
= sizeof(S390CCWDeviceClass
),
142 .class_init
= s390_ccw_class_init
,
146 static void register_s390_ccw_type(void)
148 type_register_static(&s390_ccw_info
);
151 type_init(register_s390_ccw_type
)