]>
Commit | Line | Data |
---|---|---|
dd70bd0d JL |
1 | /* |
2 | * css bridge implementation | |
3 | * | |
4 | * Copyright 2012,2016 IBM Corp. | |
5 | * Author(s): Cornelia Huck <[email protected]> | |
6 | * Pierre Morel <[email protected]> | |
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 | #include "qemu/osdep.h" | |
13 | #include "qapi/error.h" | |
dd70bd0d JL |
14 | #include "hw/hotplug.h" |
15 | #include "hw/sysbus.h" | |
16 | #include "qemu/bitops.h" | |
17 | #include "hw/s390x/css.h" | |
b804e8a6 | 18 | #include "ccw-device.h" |
dd70bd0d JL |
19 | #include "hw/s390x/css-bridge.h" |
20 | ||
b804e8a6 JL |
21 | /* |
22 | * Invoke device-specific unplug handler, disable the subchannel | |
23 | * (including sending a channel report to the guest) and remove the | |
24 | * device from the virtual css bus. | |
25 | */ | |
26 | static void ccw_device_unplug(HotplugHandler *hotplug_dev, | |
27 | DeviceState *dev, Error **errp) | |
28 | { | |
29 | CcwDevice *ccw_dev = CCW_DEVICE(dev); | |
30 | CCWDeviceClass *k = CCW_DEVICE_GET_CLASS(ccw_dev); | |
31 | SubchDev *sch = ccw_dev->sch; | |
32 | Error *err = NULL; | |
33 | ||
34 | if (k->unplug) { | |
35 | k->unplug(hotplug_dev, dev, &err); | |
36 | if (err) { | |
37 | error_propagate(errp, err); | |
38 | return; | |
39 | } | |
40 | } | |
41 | ||
42 | /* | |
43 | * We should arrive here only for device_del, since we don't support | |
44 | * direct hot(un)plug of channels. | |
45 | */ | |
46 | assert(sch != NULL); | |
47 | /* Subchannel is now disabled and no longer valid. */ | |
48 | sch->curr_status.pmcw.flags &= ~(PMCW_FLAGS_MASK_ENA | | |
49 | PMCW_FLAGS_MASK_DNV); | |
50 | ||
51 | css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, 1, 0); | |
52 | ||
53 | object_unparent(OBJECT(dev)); | |
54 | } | |
55 | ||
dd70bd0d JL |
56 | static void virtual_css_bus_reset(BusState *qbus) |
57 | { | |
58 | /* This should actually be modelled via the generic css */ | |
59 | css_reset(); | |
60 | } | |
61 | ||
2a79eb1a CH |
62 | static char *virtual_css_bus_get_dev_path(DeviceState *dev) |
63 | { | |
64 | CcwDevice *ccw_dev = CCW_DEVICE(dev); | |
65 | SubchDev *sch = ccw_dev->sch; | |
66 | VirtualCssBridge *bridge = | |
67 | VIRTUAL_CSS_BRIDGE(qdev_get_parent_bus(dev)->parent); | |
68 | ||
69 | /* | |
70 | * We can't provide a dev path for backward compatibility on | |
71 | * older machines, as it is visible in the migration stream. | |
72 | */ | |
73 | return bridge->css_dev_path ? | |
74 | g_strdup_printf("/%02x.%1x.%04x", sch->cssid, sch->ssid, sch->devno) : | |
75 | NULL; | |
76 | } | |
77 | ||
dd70bd0d JL |
78 | static void virtual_css_bus_class_init(ObjectClass *klass, void *data) |
79 | { | |
80 | BusClass *k = BUS_CLASS(klass); | |
81 | ||
82 | k->reset = virtual_css_bus_reset; | |
2a79eb1a | 83 | k->get_dev_path = virtual_css_bus_get_dev_path; |
dd70bd0d JL |
84 | } |
85 | ||
86 | static const TypeInfo virtual_css_bus_info = { | |
87 | .name = TYPE_VIRTUAL_CSS_BUS, | |
88 | .parent = TYPE_BUS, | |
89 | .instance_size = sizeof(VirtualCssBus), | |
90 | .class_init = virtual_css_bus_class_init, | |
91 | }; | |
92 | ||
93 | VirtualCssBus *virtual_css_bus_init(void) | |
94 | { | |
95 | VirtualCssBus *cbus; | |
96 | BusState *bus; | |
97 | DeviceState *dev; | |
98 | ||
99 | /* Create bridge device */ | |
100 | dev = qdev_create(NULL, TYPE_VIRTUAL_CSS_BRIDGE); | |
101 | qdev_init_nofail(dev); | |
102 | ||
103 | /* Create bus on bridge device */ | |
104 | bus = qbus_create(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css"); | |
105 | cbus = VIRTUAL_CSS_BUS(bus); | |
106 | ||
107 | /* Enable hotplugging */ | |
108 | qbus_set_hotplug_handler(bus, dev, &error_abort); | |
109 | ||
dde522bb FL |
110 | css_register_io_adapters(CSS_IO_ADAPTER_VIRTIO, true, false, |
111 | &error_abort); | |
112 | ||
dd70bd0d JL |
113 | return cbus; |
114 | } | |
115 | ||
116 | /***************** Virtual-css Bus Bridge Device ********************/ | |
117 | ||
2a79eb1a CH |
118 | static Property virtual_css_bridge_properties[] = { |
119 | DEFINE_PROP_BOOL("css_dev_path", VirtualCssBridge, css_dev_path, | |
120 | true), | |
121 | DEFINE_PROP_END_OF_LIST(), | |
122 | }; | |
123 | ||
dd70bd0d JL |
124 | static void virtual_css_bridge_class_init(ObjectClass *klass, void *data) |
125 | { | |
126 | HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass); | |
127 | DeviceClass *dc = DEVICE_CLASS(klass); | |
128 | ||
b804e8a6 | 129 | hc->unplug = ccw_device_unplug; |
dd70bd0d | 130 | set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); |
2a79eb1a | 131 | dc->props = virtual_css_bridge_properties; |
dd70bd0d JL |
132 | } |
133 | ||
134 | static const TypeInfo virtual_css_bridge_info = { | |
135 | .name = TYPE_VIRTUAL_CSS_BRIDGE, | |
136 | .parent = TYPE_SYS_BUS_DEVICE, | |
2a79eb1a | 137 | .instance_size = sizeof(VirtualCssBridge), |
dd70bd0d JL |
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) |