]>
Commit | Line | Data |
---|---|---|
dd70bd0d JL |
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 | #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 | ||
62 | static void virtual_css_bus_class_init(ObjectClass *klass, void *data) | |
63 | { | |
64 | BusClass *k = BUS_CLASS(klass); | |
65 | ||
66 | k->reset = virtual_css_bus_reset; | |
67 | } | |
68 | ||
69 | static const TypeInfo virtual_css_bus_info = { | |
70 | .name = TYPE_VIRTUAL_CSS_BUS, | |
71 | .parent = TYPE_BUS, | |
72 | .instance_size = sizeof(VirtualCssBus), | |
73 | .class_init = virtual_css_bus_class_init, | |
74 | }; | |
75 | ||
76 | VirtualCssBus *virtual_css_bus_init(void) | |
77 | { | |
78 | VirtualCssBus *cbus; | |
79 | BusState *bus; | |
80 | DeviceState *dev; | |
81 | ||
82 | /* Create bridge device */ | |
83 | dev = qdev_create(NULL, TYPE_VIRTUAL_CSS_BRIDGE); | |
84 | qdev_init_nofail(dev); | |
85 | ||
86 | /* Create bus on bridge device */ | |
87 | bus = qbus_create(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css"); | |
88 | cbus = VIRTUAL_CSS_BUS(bus); | |
89 | ||
90 | /* Enable hotplugging */ | |
91 | qbus_set_hotplug_handler(bus, dev, &error_abort); | |
92 | ||
93 | return cbus; | |
94 | } | |
95 | ||
96 | /***************** Virtual-css Bus Bridge Device ********************/ | |
97 | ||
98 | static void virtual_css_bridge_class_init(ObjectClass *klass, void *data) | |
99 | { | |
100 | HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass); | |
101 | DeviceClass *dc = DEVICE_CLASS(klass); | |
102 | ||
b804e8a6 | 103 | hc->unplug = ccw_device_unplug; |
dd70bd0d JL |
104 | set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); |
105 | } | |
106 | ||
107 | static const TypeInfo virtual_css_bridge_info = { | |
108 | .name = TYPE_VIRTUAL_CSS_BRIDGE, | |
109 | .parent = TYPE_SYS_BUS_DEVICE, | |
110 | .instance_size = sizeof(SysBusDevice), | |
111 | .class_init = virtual_css_bridge_class_init, | |
112 | .interfaces = (InterfaceInfo[]) { | |
113 | { TYPE_HOTPLUG_HANDLER }, | |
114 | { } | |
115 | } | |
116 | }; | |
117 | ||
118 | static void virtual_css_register(void) | |
119 | { | |
120 | type_register_static(&virtual_css_bridge_info); | |
121 | type_register_static(&virtual_css_bus_info); | |
122 | } | |
123 | ||
124 | type_init(virtual_css_register) |