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 "qemu/module.h" 15 16 static void ccw_device_refill_ids(CcwDevice *dev) 17 { 18 SubchDev *sch = dev->sch; 19 20 assert(sch); 21 22 dev->dev_id.cssid = sch->cssid; 23 dev->dev_id.ssid = sch->ssid; 24 dev->dev_id.devid = sch->devno; 25 dev->dev_id.valid = true; 26 27 dev->subch_id.cssid = sch->cssid; 28 dev->subch_id.ssid = sch->ssid; 29 dev->subch_id.devid = sch->schid; 30 dev->subch_id.valid = true; 31 } 32 33 static void ccw_device_realize(CcwDevice *dev, Error **errp) 34 { 35 ccw_device_refill_ids(dev); 36 } 37 38 static Property ccw_device_properties[] = { 39 DEFINE_PROP_CSS_DEV_ID("devno", CcwDevice, devno), 40 DEFINE_PROP_CSS_DEV_ID_RO("dev_id", CcwDevice, dev_id), 41 DEFINE_PROP_CSS_DEV_ID_RO("subch_id", CcwDevice, subch_id), 42 DEFINE_PROP_END_OF_LIST(), 43 }; 44 45 static void ccw_device_reset(DeviceState *d) 46 { 47 CcwDevice *ccw_dev = CCW_DEVICE(d); 48 49 css_reset_sch(ccw_dev->sch); 50 } 51 52 static void ccw_device_class_init(ObjectClass *klass, void *data) 53 { 54 DeviceClass *dc = DEVICE_CLASS(klass); 55 CCWDeviceClass *k = CCW_DEVICE_CLASS(klass); 56 57 k->realize = ccw_device_realize; 58 k->refill_ids = ccw_device_refill_ids; 59 dc->props = ccw_device_properties; 60 dc->reset = ccw_device_reset; 61 } 62 63 const VMStateDescription vmstate_ccw_dev = { 64 .name = "s390_ccw_dev", 65 .version_id = 1, 66 .minimum_version_id = 1, 67 .fields = (VMStateField[]) { 68 VMSTATE_STRUCT_POINTER(sch, CcwDevice, vmstate_subch_dev, SubchDev), 69 VMSTATE_END_OF_LIST() 70 } 71 }; 72 73 static const TypeInfo ccw_device_info = { 74 .name = TYPE_CCW_DEVICE, 75 .parent = TYPE_DEVICE, 76 .instance_size = sizeof(CcwDevice), 77 .class_size = sizeof(CCWDeviceClass), 78 .class_init = ccw_device_class_init, 79 .abstract = true, 80 }; 81 82 static void ccw_device_register(void) 83 { 84 type_register_static(&ccw_device_info); 85 } 86 87 type_init(ccw_device_register) 88