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 #include "ipl.h" 17 #include "qapi/visitor.h" 18 #include "qemu/ctype.h" 19 #include "qapi/error.h" 20 21 static void ccw_device_refill_ids(CcwDevice *dev) 22 { 23 SubchDev *sch = dev->sch; 24 25 assert(sch); 26 27 dev->dev_id.cssid = sch->cssid; 28 dev->dev_id.ssid = sch->ssid; 29 dev->dev_id.devid = sch->devno; 30 dev->dev_id.valid = true; 31 32 dev->subch_id.cssid = sch->cssid; 33 dev->subch_id.ssid = sch->ssid; 34 dev->subch_id.devid = sch->schid; 35 dev->subch_id.valid = true; 36 } 37 38 static bool ccw_device_realize(CcwDevice *dev, Error **errp) 39 { 40 ccw_device_refill_ids(dev); 41 return true; 42 } 43 44 static void ccw_device_get_loadparm(Object *obj, Visitor *v, 45 const char *name, void *opaque, 46 Error **errp) 47 { 48 CcwDevice *dev = CCW_DEVICE(obj); 49 char *str = g_strndup((char *) dev->loadparm, sizeof(dev->loadparm)); 50 51 visit_type_str(v, name, &str, errp); 52 g_free(str); 53 } 54 55 static void ccw_device_set_loadparm(Object *obj, Visitor *v, 56 const char *name, void *opaque, 57 Error **errp) 58 { 59 CcwDevice *dev = CCW_DEVICE(obj); 60 char *val; 61 int index; 62 63 index = object_property_get_int(obj, "bootindex", NULL); 64 65 if (index < 0) { 66 error_setg(errp, "LOADPARM is only valid for boot devices!"); 67 } 68 69 if (!visit_type_str(v, name, &val, errp)) { 70 return; 71 } 72 73 s390_ipl_fmt_loadparm(dev->loadparm, val, errp); 74 } 75 76 static const PropertyInfo ccw_loadparm = { 77 .name = "ccw_loadparm", 78 .description = "Up to 8 chars in set of [A-Za-z0-9. ] to pass" 79 " to the guest loader/kernel", 80 .get = ccw_device_get_loadparm, 81 .set = ccw_device_set_loadparm, 82 }; 83 84 static Property ccw_device_properties[] = { 85 DEFINE_PROP_CSS_DEV_ID("devno", CcwDevice, devno), 86 DEFINE_PROP_CSS_DEV_ID_RO("dev_id", CcwDevice, dev_id), 87 DEFINE_PROP_CSS_DEV_ID_RO("subch_id", CcwDevice, subch_id), 88 DEFINE_PROP("loadparm", CcwDevice, loadparm, ccw_loadparm, 89 typeof(uint8_t[8])), 90 DEFINE_PROP_END_OF_LIST(), 91 }; 92 93 static void ccw_device_reset_hold(Object *obj, ResetType type) 94 { 95 CcwDevice *ccw_dev = CCW_DEVICE(obj); 96 97 css_reset_sch(ccw_dev->sch); 98 } 99 100 static void ccw_device_class_init(ObjectClass *klass, void *data) 101 { 102 DeviceClass *dc = DEVICE_CLASS(klass); 103 CCWDeviceClass *k = CCW_DEVICE_CLASS(klass); 104 ResettableClass *rc = RESETTABLE_CLASS(klass); 105 106 k->realize = ccw_device_realize; 107 k->refill_ids = ccw_device_refill_ids; 108 device_class_set_props(dc, ccw_device_properties); 109 rc->phases.hold = ccw_device_reset_hold; 110 dc->bus_type = TYPE_VIRTUAL_CSS_BUS; 111 } 112 113 const VMStateDescription vmstate_ccw_dev = { 114 .name = "s390_ccw_dev", 115 .version_id = 1, 116 .minimum_version_id = 1, 117 .fields = (const VMStateField[]) { 118 VMSTATE_STRUCT_POINTER(sch, CcwDevice, vmstate_subch_dev, SubchDev), 119 VMSTATE_END_OF_LIST() 120 } 121 }; 122 123 static const TypeInfo ccw_device_info = { 124 .name = TYPE_CCW_DEVICE, 125 .parent = TYPE_DEVICE, 126 .instance_size = sizeof(CcwDevice), 127 .class_size = sizeof(CCWDeviceClass), 128 .class_init = ccw_device_class_init, 129 .abstract = true, 130 }; 131 132 static void ccw_device_register(void) 133 { 134 type_register_static(&ccw_device_info); 135 } 136 137 type_init(ccw_device_register) 138