2
0

hotplug.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Hotplug handler interface.
  3. *
  4. * Copyright (c) 2014 Red Hat Inc.
  5. *
  6. * Authors:
  7. * Igor Mammedov <imammedo@redhat.com>,
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2 or later.
  10. * See the COPYING file in the top-level directory.
  11. */
  12. #ifndef HOTPLUG_H
  13. #define HOTPLUG_H
  14. #include "qom/object.h"
  15. #define TYPE_HOTPLUG_HANDLER "hotplug-handler"
  16. typedef struct HotplugHandlerClass HotplugHandlerClass;
  17. DECLARE_CLASS_CHECKERS(HotplugHandlerClass, HOTPLUG_HANDLER,
  18. TYPE_HOTPLUG_HANDLER)
  19. #define HOTPLUG_HANDLER(obj) \
  20. INTERFACE_CHECK(HotplugHandler, (obj), TYPE_HOTPLUG_HANDLER)
  21. typedef struct HotplugHandler HotplugHandler;
  22. /**
  23. * hotplug_fn:
  24. * @plug_handler: a device performing plug/uplug action
  25. * @plugged_dev: a device that has been (un)plugged
  26. * @errp: returns an error if this function fails
  27. */
  28. typedef void (*hotplug_fn)(HotplugHandler *plug_handler,
  29. DeviceState *plugged_dev, Error **errp);
  30. /**
  31. * HotplugDeviceClass:
  32. *
  33. * Interface to be implemented by a device performing
  34. * hardware (un)plug functions.
  35. *
  36. * @parent: Opaque parent interface.
  37. * @pre_plug: pre plug callback called at start of device.realize(true)
  38. * @plug: plug callback called at end of device.realize(true).
  39. * @unplug_request: unplug request callback.
  40. * Used as a means to initiate device unplug for devices that
  41. * require asynchronous unplug handling.
  42. * @unplug: unplug callback.
  43. * Used for device removal with devices that implement
  44. * asynchronous and synchronous (surprise) removal.
  45. * @is_hotpluggable_bus: called to check if bus/its parent allow hotplug on bus
  46. */
  47. struct HotplugHandlerClass {
  48. /* <private> */
  49. InterfaceClass parent;
  50. /* <public> */
  51. hotplug_fn pre_plug;
  52. hotplug_fn plug;
  53. hotplug_fn unplug_request;
  54. hotplug_fn unplug;
  55. bool (*is_hotpluggable_bus)(HotplugHandler *plug_handler, BusState *bus);
  56. };
  57. /**
  58. * hotplug_handler_plug:
  59. *
  60. * Call #HotplugHandlerClass.plug callback of @plug_handler.
  61. */
  62. void hotplug_handler_plug(HotplugHandler *plug_handler,
  63. DeviceState *plugged_dev,
  64. Error **errp);
  65. /**
  66. * hotplug_handler_pre_plug:
  67. *
  68. * Call #HotplugHandlerClass.pre_plug callback of @plug_handler.
  69. */
  70. void hotplug_handler_pre_plug(HotplugHandler *plug_handler,
  71. DeviceState *plugged_dev,
  72. Error **errp);
  73. /**
  74. * hotplug_handler_unplug_request:
  75. *
  76. * Calls #HotplugHandlerClass.unplug_request callback of @plug_handler.
  77. */
  78. void hotplug_handler_unplug_request(HotplugHandler *plug_handler,
  79. DeviceState *plugged_dev,
  80. Error **errp);
  81. /**
  82. * hotplug_handler_unplug:
  83. *
  84. * Calls #HotplugHandlerClass.unplug callback of @plug_handler.
  85. */
  86. void hotplug_handler_unplug(HotplugHandler *plug_handler,
  87. DeviceState *plugged_dev,
  88. Error **errp);
  89. #endif