xref: /openbmc/qemu/hw/s390x/ccw-device.c (revision e53c136f)
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 
12 #include "qemu/osdep.h"
13 #include "ccw-device.h"
14 #include "hw/qdev-properties.h"
15 #include "qemu/module.h"
16 
17 static void ccw_device_refill_ids(CcwDevice *dev)
18 {
19     SubchDev *sch = dev->sch;
20 
21     assert(sch);
22 
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;
27 
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;
32 }
33 
34 static bool ccw_device_realize(CcwDevice *dev, Error **errp)
35 {
36     ccw_device_refill_ids(dev);
37     return true;
38 }
39 
40 static Property ccw_device_properties[] = {
41     DEFINE_PROP_CSS_DEV_ID("devno", CcwDevice, devno),
42     DEFINE_PROP_CSS_DEV_ID_RO("dev_id", CcwDevice, dev_id),
43     DEFINE_PROP_CSS_DEV_ID_RO("subch_id", CcwDevice, subch_id),
44     DEFINE_PROP_END_OF_LIST(),
45 };
46 
47 static void ccw_device_reset_hold(Object *obj, ResetType type)
48 {
49     CcwDevice *ccw_dev = CCW_DEVICE(obj);
50 
51     css_reset_sch(ccw_dev->sch);
52 }
53 
54 static void ccw_device_class_init(ObjectClass *klass, void *data)
55 {
56     DeviceClass *dc = DEVICE_CLASS(klass);
57     CCWDeviceClass *k = CCW_DEVICE_CLASS(klass);
58     ResettableClass *rc = RESETTABLE_CLASS(klass);
59 
60     k->realize = ccw_device_realize;
61     k->refill_ids = ccw_device_refill_ids;
62     device_class_set_props(dc, ccw_device_properties);
63     rc->phases.hold = ccw_device_reset_hold;
64     dc->bus_type = TYPE_VIRTUAL_CSS_BUS;
65 }
66 
67 const VMStateDescription vmstate_ccw_dev = {
68     .name = "s390_ccw_dev",
69     .version_id = 1,
70     .minimum_version_id = 1,
71     .fields = (const VMStateField[]) {
72         VMSTATE_STRUCT_POINTER(sch, CcwDevice, vmstate_subch_dev, SubchDev),
73         VMSTATE_END_OF_LIST()
74     }
75 };
76 
77 static const TypeInfo ccw_device_info = {
78     .name = TYPE_CCW_DEVICE,
79     .parent = TYPE_DEVICE,
80     .instance_size = sizeof(CcwDevice),
81     .class_size = sizeof(CCWDeviceClass),
82     .class_init = ccw_device_class_init,
83     .abstract = true,
84 };
85 
86 static void ccw_device_register(void)
87 {
88     type_register_static(&ccw_device_info);
89 }
90 
91 type_init(ccw_device_register)
92