blob: ef8fa2b15bed8aca02842aea77830bbc13f9193e [file] [log] [blame]
Tony Krowiaka51b3152018-10-10 13:03:06 -04001/*
2 * ap bridge
3 *
4 * Copyright 2018 IBM Corp.
5 *
6 * This work is licensed under the terms of the GNU GPL, version 2 or (at
7 * your option) any later version. See the COPYING file in the top-level
8 * directory.
9 */
Markus Armbruster0b8fa322019-05-23 16:35:07 +020010
Tony Krowiaka51b3152018-10-10 13:03:06 -040011#include "qemu/osdep.h"
12#include "qapi/error.h"
13#include "hw/sysbus.h"
14#include "qemu/bitops.h"
Markus Armbruster0b8fa322019-05-23 16:35:07 +020015#include "qemu/module.h"
Tony Krowiaka51b3152018-10-10 13:03:06 -040016#include "hw/s390x/ap-bridge.h"
17#include "cpu.h"
18
19static char *ap_bus_get_dev_path(DeviceState *dev)
20{
21 /* at most one */
22 return g_strdup_printf("/1");
23}
24
25static void ap_bus_class_init(ObjectClass *oc, void *data)
26{
27 BusClass *k = BUS_CLASS(oc);
28
29 k->get_dev_path = ap_bus_get_dev_path;
30 /* More than one ap device does not make sense */
31 k->max_dev = 1;
32}
33
34static const TypeInfo ap_bus_info = {
35 .name = TYPE_AP_BUS,
36 .parent = TYPE_BUS,
37 .instance_size = 0,
38 .class_init = ap_bus_class_init,
39};
40
41void s390_init_ap(void)
42{
43 DeviceState *dev;
Tony Krowiak374b78e2019-02-18 14:49:56 -050044 BusState *bus;
Tony Krowiaka51b3152018-10-10 13:03:06 -040045
46 /* If no AP instructions then no need for AP bridge */
47 if (!s390_has_feat(S390_FEAT_AP)) {
48 return;
49 }
50
51 /* Create bridge device */
Markus Armbruster3e80f692020-06-10 07:31:58 +020052 dev = qdev_new(TYPE_AP_BRIDGE);
Tony Krowiaka51b3152018-10-10 13:03:06 -040053 object_property_add_child(qdev_get_machine(), TYPE_AP_BRIDGE,
Markus Armbrusterd2623122020-05-05 17:29:22 +020054 OBJECT(dev));
Markus Armbruster3c6ef472020-06-10 07:32:34 +020055 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
Tony Krowiaka51b3152018-10-10 13:03:06 -040056
57 /* Create bus on bridge device */
Peter Maydell9388d172021-09-23 13:11:52 +010058 bus = qbus_new(TYPE_AP_BUS, dev, TYPE_AP_BUS);
Tony Krowiak374b78e2019-02-18 14:49:56 -050059
60 /* Enable hotplugging */
Markus Armbruster9bc6bfd2020-06-30 11:03:39 +020061 qbus_set_hotplug_handler(bus, OBJECT(dev));
Tony Krowiaka51b3152018-10-10 13:03:06 -040062 }
63
64static void ap_bridge_class_init(ObjectClass *oc, void *data)
65{
66 DeviceClass *dc = DEVICE_CLASS(oc);
Tony Krowiak374b78e2019-02-18 14:49:56 -050067 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
Tony Krowiaka51b3152018-10-10 13:03:06 -040068
Tony Krowiak374b78e2019-02-18 14:49:56 -050069 hc->unplug = qdev_simple_device_unplug_cb;
Tony Krowiaka51b3152018-10-10 13:03:06 -040070 set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
71}
72
73static const TypeInfo ap_bridge_info = {
74 .name = TYPE_AP_BRIDGE,
75 .parent = TYPE_SYS_BUS_DEVICE,
76 .instance_size = 0,
77 .class_init = ap_bridge_class_init,
Tony Krowiak374b78e2019-02-18 14:49:56 -050078 .interfaces = (InterfaceInfo[]) {
79 { TYPE_HOTPLUG_HANDLER },
80 { }
81 }
Tony Krowiaka51b3152018-10-10 13:03:06 -040082};
83
84static void ap_register(void)
85{
86 type_register_static(&ap_bridge_info);
87 type_register_static(&ap_bus_info);
88}
89
90type_init(ap_register)