xref: /openbmc/qemu/hw/s390x/ccw-device.c (revision 520e210c)
1 /*
2  * Common device infrastructure for devices in the virtual css
3  *
4  * Copyright 2016 IBM Corp.
5  * Author(s): Jing Liu <liujbjl@linux.vnet.ibm.com>
6  *
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
9  * directory.
10  */
11 #include "qemu/osdep.h"
12 #include "ccw-device.h"
13 
14 static void ccw_device_refill_ids(CcwDevice *dev)
15 {
16     SubchDev *sch = dev->sch;
17 
18     assert(sch);
19 
20     dev->dev_id.cssid = sch->cssid;
21     dev->dev_id.ssid = sch->ssid;
22     dev->dev_id.devid = sch->devno;
23     dev->dev_id.valid = true;
24 
25     dev->subch_id.cssid = sch->cssid;
26     dev->subch_id.ssid = sch->ssid;
27     dev->subch_id.devid = sch->schid;
28     dev->subch_id.valid = true;
29 }
30 
31 static void ccw_device_realize(CcwDevice *dev, Error **errp)
32 {
33     ccw_device_refill_ids(dev);
34 }
35 
36 static Property ccw_device_properties[] = {
37     DEFINE_PROP_CSS_DEV_ID("devno", CcwDevice, devno),
38     DEFINE_PROP_CSS_DEV_ID_RO("dev_id", CcwDevice, dev_id),
39     DEFINE_PROP_CSS_DEV_ID_RO("subch_id", CcwDevice, subch_id),
40     DEFINE_PROP_END_OF_LIST(),
41 };
42 
43 static void ccw_device_reset(DeviceState *d)
44 {
45     CcwDevice *ccw_dev = CCW_DEVICE(d);
46 
47     css_reset_sch(ccw_dev->sch);
48 }
49 
50 static void ccw_device_class_init(ObjectClass *klass, void *data)
51 {
52     DeviceClass *dc = DEVICE_CLASS(klass);
53     CCWDeviceClass *k = CCW_DEVICE_CLASS(klass);
54 
55     k->realize = ccw_device_realize;
56     k->refill_ids = ccw_device_refill_ids;
57     dc->props = ccw_device_properties;
58     dc->reset = ccw_device_reset;
59 }
60 
61 const VMStateDescription vmstate_ccw_dev = {
62     .name = "s390_ccw_dev",
63     .version_id = 1,
64     .minimum_version_id = 1,
65     .fields = (VMStateField[]) {
66         VMSTATE_STRUCT_POINTER(sch, CcwDevice, vmstate_subch_dev, SubchDev),
67         VMSTATE_END_OF_LIST()
68     }
69 };
70 
71 static const TypeInfo ccw_device_info = {
72     .name = TYPE_CCW_DEVICE,
73     .parent = TYPE_DEVICE,
74     .instance_size = sizeof(CcwDevice),
75     .class_size = sizeof(CCWDeviceClass),
76     .class_init = ccw_device_class_init,
77     .abstract = true,
78 };
79 
80 static void ccw_device_register(void)
81 {
82     type_register_static(&ccw_device_info);
83 }
84 
85 type_init(ccw_device_register)
86