2 * Common device infrastructure for devices in the virtual css
4 * Copyright 2016 IBM Corp.
5 * Author(s): Jing Liu <liujbjl@linux.vnet.ibm.com>
7 * This work is licensed under the terms of the GNU GPL, version 2 or (at
8 * your option) any later version. See the COPYING file in the top-level
12 #include "qemu/osdep.h"
13 #include "ccw-device.h"
14 #include "hw/qdev-properties.h"
15 #include "qemu/module.h"
17 static void ccw_device_refill_ids(CcwDevice
*dev
)
19 SubchDev
*sch
= dev
->sch
;
23 dev
->dev_id
.cssid
= sch
->cssid
;
24 dev
->dev_id
.ssid
= sch
->ssid
;
25 dev
->dev_id
.devid
= sch
->devno
;
26 dev
->dev_id
.valid
= true;
28 dev
->subch_id
.cssid
= sch
->cssid
;
29 dev
->subch_id
.ssid
= sch
->ssid
;
30 dev
->subch_id
.devid
= sch
->schid
;
31 dev
->subch_id
.valid
= true;
34 static void ccw_device_realize(CcwDevice
*dev
, Error
**errp
)
36 ccw_device_refill_ids(dev
);
39 static Property ccw_device_properties
[] = {
40 DEFINE_PROP_CSS_DEV_ID("devno", CcwDevice
, devno
),
41 DEFINE_PROP_CSS_DEV_ID_RO("dev_id", CcwDevice
, dev_id
),
42 DEFINE_PROP_CSS_DEV_ID_RO("subch_id", CcwDevice
, subch_id
),
43 DEFINE_PROP_END_OF_LIST(),
46 static void ccw_device_reset(DeviceState
*d
)
48 CcwDevice
*ccw_dev
= CCW_DEVICE(d
);
50 css_reset_sch(ccw_dev
->sch
);
53 static void ccw_device_class_init(ObjectClass
*klass
, void *data
)
55 DeviceClass
*dc
= DEVICE_CLASS(klass
);
56 CCWDeviceClass
*k
= CCW_DEVICE_CLASS(klass
);
58 k
->realize
= ccw_device_realize
;
59 k
->refill_ids
= ccw_device_refill_ids
;
60 device_class_set_props(dc
, ccw_device_properties
);
61 dc
->reset
= ccw_device_reset
;
62 dc
->bus_type
= TYPE_VIRTUAL_CSS_BUS
;
65 const VMStateDescription vmstate_ccw_dev
= {
66 .name
= "s390_ccw_dev",
68 .minimum_version_id
= 1,
69 .fields
= (const VMStateField
[]) {
70 VMSTATE_STRUCT_POINTER(sch
, CcwDevice
, vmstate_subch_dev
, SubchDev
),
75 static const TypeInfo ccw_device_info
= {
76 .name
= TYPE_CCW_DEVICE
,
77 .parent
= TYPE_DEVICE
,
78 .instance_size
= sizeof(CcwDevice
),
79 .class_size
= sizeof(CCWDeviceClass
),
80 .class_init
= ccw_device_class_init
,
84 static void ccw_device_register(void)
86 type_register_static(&ccw_device_info
);
89 type_init(ccw_device_register
)