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 static const TypeInfo ccw_device_info = { 54 .name = TYPE_CCW_DEVICE, 55 .parent = TYPE_DEVICE, 56 .instance_size = sizeof(CcwDevice), 57 .class_size = sizeof(CCWDeviceClass), 58 .class_init = ccw_device_class_init, 59 .abstract = true, 60 }; 61 62 static void ccw_device_register(void) 63 { 64 type_register_static(&ccw_device_info); 65 } 66 67 type_init(ccw_device_register) 68