ap-bridge.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  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. */
  10. #include "qemu/osdep.h"
  11. #include "qapi/error.h"
  12. #include "hw/sysbus.h"
  13. #include "qemu/bitops.h"
  14. #include "qemu/module.h"
  15. #include "hw/s390x/ap-bridge.h"
  16. #include "cpu.h"
  17. static char *ap_bus_get_dev_path(DeviceState *dev)
  18. {
  19. /* at most one */
  20. return g_strdup_printf("/1");
  21. }
  22. static void ap_bus_class_init(ObjectClass *oc, void *data)
  23. {
  24. BusClass *k = BUS_CLASS(oc);
  25. k->get_dev_path = ap_bus_get_dev_path;
  26. /* More than one ap device does not make sense */
  27. k->max_dev = 1;
  28. }
  29. static const TypeInfo ap_bus_info = {
  30. .name = TYPE_AP_BUS,
  31. .parent = TYPE_BUS,
  32. .instance_size = 0,
  33. .class_init = ap_bus_class_init,
  34. };
  35. void s390_init_ap(void)
  36. {
  37. DeviceState *dev;
  38. BusState *bus;
  39. /* If no AP instructions then no need for AP bridge */
  40. if (!s390_has_feat(S390_FEAT_AP)) {
  41. return;
  42. }
  43. /* Create bridge device */
  44. dev = qdev_new(TYPE_AP_BRIDGE);
  45. object_property_add_child(qdev_get_machine(), TYPE_AP_BRIDGE,
  46. OBJECT(dev));
  47. sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
  48. /* Create bus on bridge device */
  49. bus = qbus_new(TYPE_AP_BUS, dev, TYPE_AP_BUS);
  50. /* Enable hotplugging */
  51. qbus_set_hotplug_handler(bus, OBJECT(dev));
  52. }
  53. static void ap_bridge_class_init(ObjectClass *oc, void *data)
  54. {
  55. DeviceClass *dc = DEVICE_CLASS(oc);
  56. HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc);
  57. hc->unplug = qdev_simple_device_unplug_cb;
  58. set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
  59. }
  60. static const TypeInfo ap_bridge_info = {
  61. .name = TYPE_AP_BRIDGE,
  62. .parent = TYPE_SYS_BUS_DEVICE,
  63. .instance_size = 0,
  64. .class_init = ap_bridge_class_init,
  65. .interfaces = (InterfaceInfo[]) {
  66. { TYPE_HOTPLUG_HANDLER },
  67. { }
  68. }
  69. };
  70. static void ap_register(void)
  71. {
  72. type_register_static(&ap_bridge_info);
  73. type_register_static(&ap_bus_info);
  74. }
  75. type_init(ap_register)