Igor Mammedov | 9f117d4 | 2014-02-05 16:36:44 +0100 | [diff] [blame] | 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 | |
| 15 | #include "qom/object.h" |
| 16 | #include "qemu/typedefs.h" |
| 17 | |
| 18 | #define TYPE_HOTPLUG_HANDLER "hotplug-handler" |
| 19 | |
| 20 | #define HOTPLUG_HANDLER_CLASS(klass) \ |
| 21 | OBJECT_CLASS_CHECK(HotplugHandlerClass, (klass), TYPE_HOTPLUG_HANDLER) |
| 22 | #define HOTPLUG_HANDLER_GET_CLASS(obj) \ |
| 23 | OBJECT_GET_CLASS(HotplugHandlerClass, (obj), TYPE_HOTPLUG_HANDLER) |
| 24 | #define HOTPLUG_HANDLER(obj) \ |
| 25 | INTERFACE_CHECK(HotplugHandler, (obj), TYPE_HOTPLUG_HANDLER) |
| 26 | |
| 27 | |
| 28 | typedef struct HotplugHandler { |
| 29 | /* <private> */ |
| 30 | Object Parent; |
| 31 | } HotplugHandler; |
| 32 | |
| 33 | /** |
| 34 | * hotplug_fn: |
| 35 | * @plug_handler: a device performing plug/uplug action |
| 36 | * @plugged_dev: a device that has been (un)plugged |
| 37 | * @errp: returns an error if this function fails |
| 38 | */ |
| 39 | typedef void (*hotplug_fn)(HotplugHandler *plug_handler, |
| 40 | DeviceState *plugged_dev, Error **errp); |
| 41 | |
| 42 | /** |
| 43 | * HotplugDeviceClass: |
| 44 | * |
| 45 | * Interface to be implemented by a device performing |
| 46 | * hardware (un)plug functions. |
| 47 | * |
| 48 | * @parent: Opaque parent interface. |
| 49 | * @plug: plug callback. |
Igor Mammedov | 14d5a28 | 2014-09-26 09:28:19 +0000 | [diff] [blame] | 50 | * @unplug_request: unplug request callback. |
| 51 | * Used as a means to initiate device unplug for devices that |
| 52 | * require asynchronous unplug handling. |
Igor Mammedov | 181a2c6 | 2014-09-26 09:28:20 +0000 | [diff] [blame] | 53 | * @unplug: unplug callback. |
| 54 | * Used for device removal with devices that implement |
Stefan Weil | b4952c3 | 2015-01-03 14:41:39 +0100 | [diff] [blame] | 55 | * asynchronous and synchronous (surprise) removal. |
Igor Mammedov | 9f117d4 | 2014-02-05 16:36:44 +0100 | [diff] [blame] | 56 | */ |
| 57 | typedef struct HotplugHandlerClass { |
| 58 | /* <private> */ |
| 59 | InterfaceClass parent; |
| 60 | |
| 61 | /* <public> */ |
| 62 | hotplug_fn plug; |
Igor Mammedov | 14d5a28 | 2014-09-26 09:28:19 +0000 | [diff] [blame] | 63 | hotplug_fn unplug_request; |
Igor Mammedov | 181a2c6 | 2014-09-26 09:28:20 +0000 | [diff] [blame] | 64 | hotplug_fn unplug; |
Igor Mammedov | 9f117d4 | 2014-02-05 16:36:44 +0100 | [diff] [blame] | 65 | } HotplugHandlerClass; |
| 66 | |
| 67 | /** |
| 68 | * hotplug_handler_plug: |
| 69 | * |
| 70 | * Call #HotplugHandlerClass.plug callback of @plug_handler. |
| 71 | */ |
| 72 | void hotplug_handler_plug(HotplugHandler *plug_handler, |
| 73 | DeviceState *plugged_dev, |
| 74 | Error **errp); |
| 75 | |
| 76 | /** |
Igor Mammedov | 14d5a28 | 2014-09-26 09:28:19 +0000 | [diff] [blame] | 77 | * hotplug_handler_unplug_request: |
Igor Mammedov | 9f117d4 | 2014-02-05 16:36:44 +0100 | [diff] [blame] | 78 | * |
Igor Mammedov | 14d5a28 | 2014-09-26 09:28:19 +0000 | [diff] [blame] | 79 | * Calls #HotplugHandlerClass.unplug_request callback of @plug_handler. |
Igor Mammedov | 9f117d4 | 2014-02-05 16:36:44 +0100 | [diff] [blame] | 80 | */ |
Igor Mammedov | 14d5a28 | 2014-09-26 09:28:19 +0000 | [diff] [blame] | 81 | void hotplug_handler_unplug_request(HotplugHandler *plug_handler, |
| 82 | DeviceState *plugged_dev, |
| 83 | Error **errp); |
Igor Mammedov | 181a2c6 | 2014-09-26 09:28:20 +0000 | [diff] [blame] | 84 | /** |
| 85 | * hotplug_handler_unplug: |
| 86 | * |
| 87 | * Calls #HotplugHandlerClass.unplug callback of @plug_handler. |
| 88 | */ |
| 89 | void hotplug_handler_unplug(HotplugHandler *plug_handler, |
| 90 | DeviceState *plugged_dev, |
| 91 | Error **errp); |
Igor Mammedov | 9f117d4 | 2014-02-05 16:36:44 +0100 | [diff] [blame] | 92 | #endif |