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_class_init(ObjectClass *klass, void *data) 44 { 45 DeviceClass *dc = DEVICE_CLASS(klass); 46 CCWDeviceClass *k = CCW_DEVICE_CLASS(klass); 47 48 k->realize = ccw_device_realize; 49 k->refill_ids = ccw_device_refill_ids; 50 dc->props = ccw_device_properties; 51 } 52 53 const VMStateDescription vmstate_ccw_dev = { 54 .name = "s390_ccw_dev", 55 .version_id = 1, 56 .minimum_version_id = 1, 57 .fields = (VMStateField[]) { 58 VMSTATE_STRUCT_POINTER(sch, CcwDevice, vmstate_subch_dev, SubchDev), 59 VMSTATE_END_OF_LIST() 60 } 61 }; 62 63 static const TypeInfo ccw_device_info = { 64 .name = TYPE_CCW_DEVICE, 65 .parent = TYPE_DEVICE, 66 .instance_size = sizeof(CcwDevice), 67 .class_size = sizeof(CCWDeviceClass), 68 .class_init = ccw_device_class_init, 69 .abstract = true, 70 }; 71 72 static void ccw_device_register(void) 73 { 74 type_register_static(&ccw_device_info); 75 } 76 77 type_init(ccw_device_register) 78