css-bridge.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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/sysbus.h"
  16. #include "qemu/bitops.h"
  17. #include "hw/s390x/css.h"
  18. #include "ccw-device.h"
  19. #include "hw/s390x/css-bridge.h"
  20. #include "cpu.h"
  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. if (k->unplug) {
  34. k->unplug(hotplug_dev, dev, &err);
  35. if (err) {
  36. error_propagate(errp, err);
  37. return;
  38. }
  39. }
  40. /*
  41. * We should arrive here only for device_del, since we don't support
  42. * direct hot(un)plug of channels.
  43. */
  44. assert(sch != NULL);
  45. /* Subchannel is now disabled and no longer valid. */
  46. sch->curr_status.pmcw.flags &= ~(PMCW_FLAGS_MASK_ENA |
  47. PMCW_FLAGS_MASK_DNV);
  48. css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid, 1, 0);
  49. object_unparent(OBJECT(dev));
  50. }
  51. static void virtual_css_bus_reset(BusState *qbus)
  52. {
  53. /* This should actually be modelled via the generic css */
  54. css_reset();
  55. }
  56. static char *virtual_css_bus_get_dev_path(DeviceState *dev)
  57. {
  58. CcwDevice *ccw_dev = CCW_DEVICE(dev);
  59. SubchDev *sch = ccw_dev->sch;
  60. VirtualCssBridge *bridge =
  61. VIRTUAL_CSS_BRIDGE(qdev_get_parent_bus(dev)->parent);
  62. /*
  63. * We can't provide a dev path for backward compatibility on
  64. * older machines, as it is visible in the migration stream.
  65. */
  66. return bridge->css_dev_path ?
  67. g_strdup_printf("/%02x.%1x.%04x", sch->cssid, sch->ssid, sch->devno) :
  68. NULL;
  69. }
  70. static void virtual_css_bus_class_init(ObjectClass *klass, void *data)
  71. {
  72. BusClass *k = BUS_CLASS(klass);
  73. k->reset = virtual_css_bus_reset;
  74. k->get_dev_path = virtual_css_bus_get_dev_path;
  75. }
  76. static const TypeInfo virtual_css_bus_info = {
  77. .name = TYPE_VIRTUAL_CSS_BUS,
  78. .parent = TYPE_BUS,
  79. .instance_size = sizeof(VirtualCssBus),
  80. .class_init = virtual_css_bus_class_init,
  81. };
  82. VirtualCssBus *virtual_css_bus_init(void)
  83. {
  84. VirtualCssBus *cbus;
  85. BusState *bus;
  86. DeviceState *dev;
  87. /* Create bridge device */
  88. dev = qdev_create(NULL, TYPE_VIRTUAL_CSS_BRIDGE);
  89. qdev_init_nofail(dev);
  90. /* Create bus on bridge device */
  91. bus = qbus_create(TYPE_VIRTUAL_CSS_BUS, dev, "virtual-css");
  92. cbus = VIRTUAL_CSS_BUS(bus);
  93. cbus->squash_mcss = s390_get_squash_mcss();
  94. /* Enable hotplugging */
  95. qbus_set_hotplug_handler(bus, dev, &error_abort);
  96. css_register_io_adapters(CSS_IO_ADAPTER_VIRTIO, true, false,
  97. &error_abort);
  98. return cbus;
  99. }
  100. /***************** Virtual-css Bus Bridge Device ********************/
  101. static Property virtual_css_bridge_properties[] = {
  102. DEFINE_PROP_BOOL("css_dev_path", VirtualCssBridge, css_dev_path,
  103. true),
  104. DEFINE_PROP_END_OF_LIST(),
  105. };
  106. static void virtual_css_bridge_class_init(ObjectClass *klass, void *data)
  107. {
  108. HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
  109. DeviceClass *dc = DEVICE_CLASS(klass);
  110. hc->unplug = ccw_device_unplug;
  111. set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
  112. dc->props = virtual_css_bridge_properties;
  113. }
  114. static const TypeInfo virtual_css_bridge_info = {
  115. .name = TYPE_VIRTUAL_CSS_BRIDGE,
  116. .parent = TYPE_SYS_BUS_DEVICE,
  117. .instance_size = sizeof(VirtualCssBridge),
  118. .class_init = virtual_css_bridge_class_init,
  119. .interfaces = (InterfaceInfo[]) {
  120. { TYPE_HOTPLUG_HANDLER },
  121. { }
  122. }
  123. };
  124. static void virtual_css_register(void)
  125. {
  126. type_register_static(&virtual_css_bridge_info);
  127. type_register_static(&virtual_css_bus_info);
  128. }
  129. type_init(virtual_css_register)