1 /* 2 * css bridge implementation 3 * 4 * Copyright 2012,2016 IBM Corp. 5 * Author(s): Cornelia Huck <cornelia.huck@de.ibm.com> 6 * Pierre Morel <pmorel@linux.vnet.ibm.com> 7 * 8 * This work is licensed under the terms of the GNU GPL, version 2 or (at 9 * your option) any later version. See the COPYING file in the top-level 10 * directory. 11 */ 12 13 #include "qemu/osdep.h" 14 #include "qapi/error.h" 15 #include "hw/hotplug.h" 16 #include "hw/qdev-properties.h" 17 #include "hw/sysbus.h" 18 #include "qemu/bitops.h" 19 #include "qemu/module.h" 20 #include "hw/s390x/css.h" 21 #include "ccw-device.h" 22 #include "hw/s390x/css-bridge.h" 23 24 /* 25 * Invoke device-specific unplug handler, disable the subchannel 26 * (including sending a channel report to the guest) and remove the 27 * device from the virtual css bus. 28 */ 29 static void ccw_device_unplug(HotplugHandler *hotplug_dev, 30 DeviceState *dev, Error **errp) 31 { 32 CcwDevice *ccw_dev = CCW_DEVICE(dev); 33 CCWDeviceClass *k = CCW_DEVICE_GET_CLASS(ccw_dev); 34 SubchDev *sch = ccw_dev->sch; 35 Error *err = NULL; 36 37 if (k->unplug) { 38 k->unplug(hotplug_dev, dev, &err); 39 if (err) { 40 error_propagate(errp, err); 41 return; 42 } 43 } 44 45 /* 46 * We should arrive here only for device_del, since we don't support 47 * direct hot(un)plug of channels. 48 */ 49 assert(sch != NULL); 50 /* Subchannel is now disabled and no longer valid. */ 51 sch->curr_status.pmcw.flags &= ~(PMCW_FLAGS_MASK_ENA | 52 PMCW_FLAGS_MASK_DNV); 53 54 css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, 1, 0); 55 56 qdev_unrealize(dev); 57 } 58 59 static void virtual_css_bus_reset_hold(Object *obj, ResetType type) 60 { 61 /* This should actually be modelled via the generic css */ 62 css_reset(); 63 } 64 65 static char *virtual_css_bus_get_dev_path(DeviceState *dev) 66 { 67 CcwDevice *ccw_dev = CCW_DEVICE(dev); 68 SubchDev *sch = ccw_dev->sch; 69 70 return g_strdup_printf("/%02x.%1x.%04x", sch->cssid, sch->ssid, sch->devno); 71 } 72 73 static void virtual_css_bus_class_init(ObjectClass *klass, void *data) 74 { 75 BusClass *k = BUS_CLASS(klass); 76 ResettableClass *rc = RESETTABLE_CLASS(klass); 77 78 rc->phases.hold = virtual_css_bus_reset_hold; 79 k->get_dev_path = virtual_css_bus_get_dev_path; 80 } 81 82 static const TypeInfo virtual_css_bus_info = { 83 .name = TYPE_VIRTUAL_CSS_BUS, 84 .parent = TYPE_BUS, 85 .instance_size = sizeof(VirtualCssBus), 86 .class_init = virtual_css_bus_class_init, 87 }; 88 89 VirtualCssBus *virtual_css_bus_init(void) 90 { 91 BusState *bus; 92 DeviceState *dev; 93 94 /* Create bridge device */ 95 dev = qdev_new(TYPE_VIRTUAL_CSS_BRIDGE); 96 object_property_add_child(qdev_get_machine(), TYPE_VIRTUAL_CSS_BRIDGE, 97 OBJECT(dev)); 98 99 /* Create bus on bridge device */ 100 bus = qbus_new(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css"); 101 102 /* Enable hotplugging */ 103 qbus_set_hotplug_handler(bus, OBJECT(dev)); 104 105 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); 106 107 css_register_io_adapters(CSS_IO_ADAPTER_VIRTIO, true, false, 108 0, &error_abort); 109 110 return VIRTUAL_CSS_BUS(bus); 111 } 112 113 /***************** Virtual-css Bus Bridge Device ********************/ 114 115 static bool prop_get_true(Object *obj, Error **errp) 116 { 117 return true; 118 } 119 120 static void virtual_css_bridge_class_init(ObjectClass *klass, void *data) 121 { 122 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass); 123 DeviceClass *dc = DEVICE_CLASS(klass); 124 125 hc->unplug = ccw_device_unplug; 126 set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); 127 object_class_property_add_bool(klass, "cssid-unrestricted", 128 prop_get_true, NULL); 129 object_class_property_set_description(klass, "cssid-unrestricted", 130 "A css device can use any cssid, regardless whether virtual" 131 " or not (read only, always true)"); 132 } 133 134 static const TypeInfo virtual_css_bridge_info = { 135 .name = TYPE_VIRTUAL_CSS_BRIDGE, 136 .parent = TYPE_SYS_BUS_DEVICE, 137 .instance_size = sizeof(VirtualCssBridge), 138 .class_init = virtual_css_bridge_class_init, 139 .interfaces = (InterfaceInfo[]) { 140 { TYPE_HOTPLUG_HANDLER }, 141 { } 142 } 143 }; 144 145 static void virtual_css_register(void) 146 { 147 type_register_static(&virtual_css_bridge_info); 148 type_register_static(&virtual_css_bus_info); 149 } 150 151 type_init(virtual_css_register) 152