Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 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 | */ |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 12 | |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 13 | #include "qemu/osdep.h" |
| 14 | #include "qapi/error.h" |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 15 | #include "hw/hotplug.h" |
Markus Armbruster | a27bd6c | 2019-08-12 07:23:51 +0200 | [diff] [blame] | 16 | #include "hw/qdev-properties.h" |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 17 | #include "hw/sysbus.h" |
| 18 | #include "qemu/bitops.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 19 | #include "qemu/module.h" |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 20 | #include "hw/s390x/css.h" |
Jing Liu | b804e8a | 2016-02-26 06:46:12 +0100 | [diff] [blame] | 21 | #include "ccw-device.h" |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 22 | #include "hw/s390x/css-bridge.h" |
| 23 | |
Jing Liu | b804e8a | 2016-02-26 06:46:12 +0100 | [diff] [blame] | 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 | |
Markus Armbruster | 981c3dc | 2020-06-10 07:31:56 +0200 | [diff] [blame] | 56 | qdev_unrealize(dev); |
Jing Liu | b804e8a | 2016-02-26 06:46:12 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Peter Maydell | 412a91f | 2024-01-19 16:35:11 +0000 | [diff] [blame] | 59 | static void virtual_css_bus_reset_hold(Object *obj) |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 60 | { |
| 61 | /* This should actually be modelled via the generic css */ |
| 62 | css_reset(); |
| 63 | } |
| 64 | |
Cornelia Huck | 2a79eb1 | 2016-07-11 12:55:44 +0200 | [diff] [blame] | 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 | VirtualCssBridge *bridge = |
| 70 | VIRTUAL_CSS_BRIDGE(qdev_get_parent_bus(dev)->parent); |
| 71 | |
| 72 | /* |
| 73 | * We can't provide a dev path for backward compatibility on |
| 74 | * older machines, as it is visible in the migration stream. |
| 75 | */ |
| 76 | return bridge->css_dev_path ? |
| 77 | g_strdup_printf("/%02x.%1x.%04x", sch->cssid, sch->ssid, sch->devno) : |
| 78 | NULL; |
| 79 | } |
| 80 | |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 81 | static void virtual_css_bus_class_init(ObjectClass *klass, void *data) |
| 82 | { |
| 83 | BusClass *k = BUS_CLASS(klass); |
Peter Maydell | 412a91f | 2024-01-19 16:35:11 +0000 | [diff] [blame] | 84 | ResettableClass *rc = RESETTABLE_CLASS(klass); |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 85 | |
Peter Maydell | 412a91f | 2024-01-19 16:35:11 +0000 | [diff] [blame] | 86 | rc->phases.hold = virtual_css_bus_reset_hold; |
Cornelia Huck | 2a79eb1 | 2016-07-11 12:55:44 +0200 | [diff] [blame] | 87 | k->get_dev_path = virtual_css_bus_get_dev_path; |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | static const TypeInfo virtual_css_bus_info = { |
| 91 | .name = TYPE_VIRTUAL_CSS_BUS, |
| 92 | .parent = TYPE_BUS, |
| 93 | .instance_size = sizeof(VirtualCssBus), |
| 94 | .class_init = virtual_css_bus_class_init, |
| 95 | }; |
| 96 | |
| 97 | VirtualCssBus *virtual_css_bus_init(void) |
| 98 | { |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 99 | BusState *bus; |
| 100 | DeviceState *dev; |
| 101 | |
| 102 | /* Create bridge device */ |
Markus Armbruster | 3e80f69 | 2020-06-10 07:31:58 +0200 | [diff] [blame] | 103 | dev = qdev_new(TYPE_VIRTUAL_CSS_BRIDGE); |
Cornelia Huck | 864c251 | 2017-11-28 14:08:14 +0100 | [diff] [blame] | 104 | object_property_add_child(qdev_get_machine(), TYPE_VIRTUAL_CSS_BRIDGE, |
Markus Armbruster | d262312 | 2020-05-05 17:29:22 +0200 | [diff] [blame] | 105 | OBJECT(dev)); |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 106 | |
| 107 | /* Create bus on bridge device */ |
Peter Maydell | 9388d17 | 2021-09-23 13:11:52 +0100 | [diff] [blame] | 108 | bus = qbus_new(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css"); |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 109 | |
| 110 | /* Enable hotplugging */ |
Markus Armbruster | 9bc6bfd | 2020-06-30 11:03:39 +0200 | [diff] [blame] | 111 | qbus_set_hotplug_handler(bus, OBJECT(dev)); |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 112 | |
Philippe Mathieu-Daudé | 840b449 | 2023-10-18 14:34:42 +0200 | [diff] [blame] | 113 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
| 114 | |
Fei Li | dde522b | 2016-11-24 11:10:39 +0100 | [diff] [blame] | 115 | css_register_io_adapters(CSS_IO_ADAPTER_VIRTIO, true, false, |
Fei Li | 1497c16 | 2017-03-07 04:07:44 +0100 | [diff] [blame] | 116 | 0, &error_abort); |
Fei Li | dde522b | 2016-11-24 11:10:39 +0100 | [diff] [blame] | 117 | |
Philippe Mathieu-Daudé | 840b449 | 2023-10-18 14:34:42 +0200 | [diff] [blame] | 118 | return VIRTUAL_CSS_BUS(bus); |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /***************** Virtual-css Bus Bridge Device ********************/ |
| 122 | |
Cornelia Huck | 2a79eb1 | 2016-07-11 12:55:44 +0200 | [diff] [blame] | 123 | static Property virtual_css_bridge_properties[] = { |
| 124 | DEFINE_PROP_BOOL("css_dev_path", VirtualCssBridge, css_dev_path, |
| 125 | true), |
| 126 | DEFINE_PROP_END_OF_LIST(), |
| 127 | }; |
| 128 | |
Halil Pasic | 99577c4 | 2017-12-06 15:44:37 +0100 | [diff] [blame] | 129 | static bool prop_get_true(Object *obj, Error **errp) |
| 130 | { |
| 131 | return true; |
| 132 | } |
| 133 | |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 134 | static void virtual_css_bridge_class_init(ObjectClass *klass, void *data) |
| 135 | { |
| 136 | HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass); |
| 137 | DeviceClass *dc = DEVICE_CLASS(klass); |
| 138 | |
Jing Liu | b804e8a | 2016-02-26 06:46:12 +0100 | [diff] [blame] | 139 | hc->unplug = ccw_device_unplug; |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 140 | set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); |
Marc-André Lureau | 4f67d30 | 2020-01-10 19:30:32 +0400 | [diff] [blame] | 141 | device_class_set_props(dc, virtual_css_bridge_properties); |
Halil Pasic | 99577c4 | 2017-12-06 15:44:37 +0100 | [diff] [blame] | 142 | object_class_property_add_bool(klass, "cssid-unrestricted", |
Markus Armbruster | d262312 | 2020-05-05 17:29:22 +0200 | [diff] [blame] | 143 | prop_get_true, NULL); |
Halil Pasic | 99577c4 | 2017-12-06 15:44:37 +0100 | [diff] [blame] | 144 | object_class_property_set_description(klass, "cssid-unrestricted", |
| 145 | "A css device can use any cssid, regardless whether virtual" |
Markus Armbruster | 7eecec7 | 2020-05-05 17:29:15 +0200 | [diff] [blame] | 146 | " or not (read only, always true)"); |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static const TypeInfo virtual_css_bridge_info = { |
| 150 | .name = TYPE_VIRTUAL_CSS_BRIDGE, |
| 151 | .parent = TYPE_SYS_BUS_DEVICE, |
Cornelia Huck | 2a79eb1 | 2016-07-11 12:55:44 +0200 | [diff] [blame] | 152 | .instance_size = sizeof(VirtualCssBridge), |
Jing Liu | dd70bd0 | 2015-11-06 12:32:40 +0100 | [diff] [blame] | 153 | .class_init = virtual_css_bridge_class_init, |
| 154 | .interfaces = (InterfaceInfo[]) { |
| 155 | { TYPE_HOTPLUG_HANDLER }, |
| 156 | { } |
| 157 | } |
| 158 | }; |
| 159 | |
| 160 | static void virtual_css_register(void) |
| 161 | { |
| 162 | type_register_static(&virtual_css_bridge_info); |
| 163 | type_register_static(&virtual_css_bus_info); |
| 164 | } |
| 165 | |
| 166 | type_init(virtual_css_register) |