2
0

css-bridge.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. return g_strdup_printf("/%02x.%1x.%04x", sch->cssid, sch->ssid, sch->devno);
  62. }
  63. static void virtual_css_bus_class_init(ObjectClass *klass, void *data)
  64. {
  65. BusClass *k = BUS_CLASS(klass);
  66. ResettableClass *rc = RESETTABLE_CLASS(klass);
  67. rc->phases.hold = virtual_css_bus_reset_hold;
  68. k->get_dev_path = virtual_css_bus_get_dev_path;
  69. }
  70. static const TypeInfo virtual_css_bus_info = {
  71. .name = TYPE_VIRTUAL_CSS_BUS,
  72. .parent = TYPE_BUS,
  73. .instance_size = sizeof(VirtualCssBus),
  74. .class_init = virtual_css_bus_class_init,
  75. };
  76. VirtualCssBus *virtual_css_bus_init(void)
  77. {
  78. BusState *bus;
  79. DeviceState *dev;
  80. /* Create bridge device */
  81. dev = qdev_new(TYPE_VIRTUAL_CSS_BRIDGE);
  82. object_property_add_child(qdev_get_machine(), TYPE_VIRTUAL_CSS_BRIDGE,
  83. OBJECT(dev));
  84. /* Create bus on bridge device */
  85. bus = qbus_new(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
  86. /* Enable hotplugging */
  87. qbus_set_hotplug_handler(bus, OBJECT(dev));
  88. sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
  89. css_register_io_adapters(CSS_IO_ADAPTER_VIRTIO, true, false,
  90. 0, &error_abort);
  91. return VIRTUAL_CSS_BUS(bus);
  92. }
  93. /***************** Virtual-css Bus Bridge Device ********************/
  94. static bool prop_get_true(Object *obj, Error **errp)
  95. {
  96. return true;
  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. hc->unplug = ccw_device_unplug;
  103. set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
  104. object_class_property_add_bool(klass, "cssid-unrestricted",
  105. prop_get_true, NULL);
  106. object_class_property_set_description(klass, "cssid-unrestricted",
  107. "A css device can use any cssid, regardless whether virtual"
  108. " or not (read only, always true)");
  109. }
  110. static const TypeInfo virtual_css_bridge_info = {
  111. .name = TYPE_VIRTUAL_CSS_BRIDGE,
  112. .parent = TYPE_SYS_BUS_DEVICE,
  113. .instance_size = sizeof(VirtualCssBridge),
  114. .class_init = virtual_css_bridge_class_init,
  115. .interfaces = (InterfaceInfo[]) {
  116. { TYPE_HOTPLUG_HANDLER },
  117. { }
  118. }
  119. };
  120. static void virtual_css_register(void)
  121. {
  122. type_register_static(&virtual_css_bridge_info);
  123. type_register_static(&virtual_css_bus_info);
  124. }
  125. type_init(virtual_css_register)