hotplug.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #include "qemu/osdep.h"
  13. #include "hw/hotplug.h"
  14. #include "qemu/module.h"
  15. void hotplug_handler_pre_plug(HotplugHandler *plug_handler,
  16. DeviceState *plugged_dev,
  17. Error **errp)
  18. {
  19. HotplugHandlerClass *hdc = HOTPLUG_HANDLER_GET_CLASS(plug_handler);
  20. if (hdc->pre_plug) {
  21. hdc->pre_plug(plug_handler, plugged_dev, errp);
  22. }
  23. }
  24. void hotplug_handler_plug(HotplugHandler *plug_handler,
  25. DeviceState *plugged_dev,
  26. Error **errp)
  27. {
  28. HotplugHandlerClass *hdc = HOTPLUG_HANDLER_GET_CLASS(plug_handler);
  29. if (hdc->plug) {
  30. hdc->plug(plug_handler, plugged_dev, errp);
  31. }
  32. }
  33. void hotplug_handler_unplug_request(HotplugHandler *plug_handler,
  34. DeviceState *plugged_dev,
  35. Error **errp)
  36. {
  37. HotplugHandlerClass *hdc = HOTPLUG_HANDLER_GET_CLASS(plug_handler);
  38. if (hdc->unplug_request) {
  39. hdc->unplug_request(plug_handler, plugged_dev, errp);
  40. }
  41. }
  42. void hotplug_handler_unplug(HotplugHandler *plug_handler,
  43. DeviceState *plugged_dev,
  44. Error **errp)
  45. {
  46. HotplugHandlerClass *hdc = HOTPLUG_HANDLER_GET_CLASS(plug_handler);
  47. if (hdc->unplug) {
  48. hdc->unplug(plug_handler, plugged_dev, errp);
  49. }
  50. }
  51. static const TypeInfo hotplug_handler_info = {
  52. .name = TYPE_HOTPLUG_HANDLER,
  53. .parent = TYPE_INTERFACE,
  54. .class_size = sizeof(HotplugHandlerClass),
  55. };
  56. static void hotplug_handler_register_types(void)
  57. {
  58. type_register_static(&hotplug_handler_info);
  59. }
  60. type_init(hotplug_handler_register_types)