2
0

css-bridge.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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"
  14. #include "hw/hotplug.h"
  15. #include "hw/qdev-properties.h"
  16. #include "hw/sysbus.h"
  17. #include "qemu/bitops.h"
  18. #include "qemu/module.h"
  19. #include "hw/s390x/css.h"
  20. #include "ccw-device.h"
  21. #include "hw/s390x/css-bridge.h"
  22. /*
  23. * Invoke device-specific unplug handler, disable the subchannel
  24. * (including sending a channel report to the guest) and remove the
  25. * device from the virtual css bus.
  26. */
  27. static void ccw_device_unplug(HotplugHandler *hotplug_dev,
  28. DeviceState *dev, Error **errp)
  29. {
  30. CcwDevice *ccw_dev = CCW_DEVICE(dev);
  31. CCWDeviceClass *k = CCW_DEVICE_GET_CLASS(ccw_dev);
  32. SubchDev *sch = ccw_dev->sch;
  33. Error *err = NULL;
  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. * We should arrive here only for device_del, since we don't support
  43. * direct hot(un)plug of channels.
  44. */
  45. assert(sch != NULL);
  46. /* Subchannel is now disabled and no longer valid. */
  47. sch->curr_status.pmcw.flags &= ~(PMCW_FLAGS_MASK_ENA |
  48. PMCW_FLAGS_MASK_DNV);
  49. css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, 1, 0);
  50. qdev_unrealize(dev);
  51. }
  52. static void virtual_css_bus_reset_hold(Object *obj, ResetType type)
  53. {
  54. /* This should actually be modelled via the generic css */
  55. css_reset();
  56. }
  57. static char *virtual_css_bus_get_dev_path(DeviceState *dev)
  58. {
  59. CcwDevice *ccw_dev = CCW_DEVICE(dev);
  60. SubchDev *sch = ccw_dev->sch;
  61. VirtualCssBridge *bridge =
  62. VIRTUAL_CSS_BRIDGE(qdev_get_parent_bus(dev)->parent);
  63. /*
  64. * We can't provide a dev path for backward compatibility on
  65. * older machines, as it is visible in the migration stream.
  66. */
  67. return bridge->css_dev_path ?
  68. g_strdup_printf("/%02x.%1x.%04x", sch->cssid, sch->ssid, sch->devno) :
  69. NULL;
  70. }
  71. static void virtual_css_bus_class_init(ObjectClass *klass, void *data)
  72. {
  73. BusClass *k = BUS_CLASS(klass);
  74. ResettableClass *rc = RESETTABLE_CLASS(klass);
  75. rc->phases.hold = virtual_css_bus_reset_hold;
  76. k->get_dev_path = virtual_css_bus_get_dev_path;
  77. }
  78. static const TypeInfo virtual_css_bus_info = {
  79. .name = TYPE_VIRTUAL_CSS_BUS,
  80. .parent = TYPE_BUS,
  81. .instance_size = sizeof(VirtualCssBus),
  82. .class_init = virtual_css_bus_class_init,
  83. };
  84. VirtualCssBus *virtual_css_bus_init(void)
  85. {
  86. BusState *bus;
  87. DeviceState *dev;
  88. /* Create bridge device */
  89. dev = qdev_new(TYPE_VIRTUAL_CSS_BRIDGE);
  90. object_property_add_child(qdev_get_machine(), TYPE_VIRTUAL_CSS_BRIDGE,
  91. OBJECT(dev));
  92. /* Create bus on bridge device */
  93. bus = qbus_new(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
  94. /* Enable hotplugging */
  95. qbus_set_hotplug_handler(bus, OBJECT(dev));
  96. sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
  97. css_register_io_adapters(CSS_IO_ADAPTER_VIRTIO, true, false,
  98. 0, &error_abort);
  99. return VIRTUAL_CSS_BUS(bus);
  100. }
  101. /***************** Virtual-css Bus Bridge Device ********************/
  102. static Property virtual_css_bridge_properties[] = {
  103. DEFINE_PROP_BOOL("css_dev_path", VirtualCssBridge, css_dev_path,
  104. true),
  105. DEFINE_PROP_END_OF_LIST(),
  106. };
  107. static bool prop_get_true(Object *obj, Error **errp)
  108. {
  109. return true;
  110. }
  111. static void virtual_css_bridge_class_init(ObjectClass *klass, void *data)
  112. {
  113. HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
  114. DeviceClass *dc = DEVICE_CLASS(klass);
  115. hc->unplug = ccw_device_unplug;
  116. set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
  117. device_class_set_props(dc, virtual_css_bridge_properties);
  118. object_class_property_add_bool(klass, "cssid-unrestricted",
  119. prop_get_true, NULL);
  120. object_class_property_set_description(klass, "cssid-unrestricted",
  121. "A css device can use any cssid, regardless whether virtual"
  122. " or not (read only, always true)");
  123. }
  124. static const TypeInfo virtual_css_bridge_info = {
  125. .name = TYPE_VIRTUAL_CSS_BRIDGE,
  126. .parent = TYPE_SYS_BUS_DEVICE,
  127. .instance_size = sizeof(VirtualCssBridge),
  128. .class_init = virtual_css_bridge_class_init,
  129. .interfaces = (InterfaceInfo[]) {
  130. { TYPE_HOTPLUG_HANDLER },
  131. { }
  132. }
  133. };
  134. static void virtual_css_register(void)
  135. {
  136. type_register_static(&virtual_css_bridge_info);
  137. type_register_static(&virtual_css_bus_info);
  138. }
  139. type_init(virtual_css_register)