xref: /openbmc/qemu/include/hw/hotplug.h (revision ba632924)
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 
17 #define TYPE_HOTPLUG_HANDLER "hotplug-handler"
18 
19 #define HOTPLUG_HANDLER_CLASS(klass) \
20      OBJECT_CLASS_CHECK(HotplugHandlerClass, (klass), TYPE_HOTPLUG_HANDLER)
21 #define HOTPLUG_HANDLER_GET_CLASS(obj) \
22      OBJECT_GET_CLASS(HotplugHandlerClass, (obj), TYPE_HOTPLUG_HANDLER)
23 #define HOTPLUG_HANDLER(obj) \
24      INTERFACE_CHECK(HotplugHandler, (obj), TYPE_HOTPLUG_HANDLER)
25 
26 typedef struct HotplugHandler HotplugHandler;
27 
28 /**
29  * hotplug_fn:
30  * @plug_handler: a device performing plug/uplug action
31  * @plugged_dev: a device that has been (un)plugged
32  * @errp: returns an error if this function fails
33  */
34 typedef void (*hotplug_fn)(HotplugHandler *plug_handler,
35                            DeviceState *plugged_dev, Error **errp);
36 
37 /**
38  * HotplugDeviceClass:
39  *
40  * Interface to be implemented by a device performing
41  * hardware (un)plug functions.
42  *
43  * @parent: Opaque parent interface.
44  * @pre_plug: pre plug callback called at start of device.realize(true)
45  * @plug: plug callback called at end of device.realize(true).
46  * @unplug_request: unplug request callback.
47  *                  Used as a means to initiate device unplug for devices that
48  *                  require asynchronous unplug handling.
49  * @unplug: unplug callback.
50  *          Used for device removal with devices that implement
51  *          asynchronous and synchronous (surprise) removal.
52  */
53 typedef struct HotplugHandlerClass {
54     /* <private> */
55     InterfaceClass parent;
56 
57     /* <public> */
58     hotplug_fn pre_plug;
59     hotplug_fn plug;
60     hotplug_fn unplug_request;
61     hotplug_fn unplug;
62 } HotplugHandlerClass;
63 
64 /**
65  * hotplug_handler_plug:
66  *
67  * Call #HotplugHandlerClass.plug callback of @plug_handler.
68  */
69 void hotplug_handler_plug(HotplugHandler *plug_handler,
70                           DeviceState *plugged_dev,
71                           Error **errp);
72 
73 /**
74  * hotplug_handler_pre_plug:
75  *
76  * Call #HotplugHandlerClass.pre_plug callback of @plug_handler.
77  */
78 void hotplug_handler_pre_plug(HotplugHandler *plug_handler,
79                               DeviceState *plugged_dev,
80                               Error **errp);
81 
82 /**
83  * hotplug_handler_unplug_request:
84  *
85  * Calls #HotplugHandlerClass.unplug_request callback of @plug_handler.
86  */
87 void hotplug_handler_unplug_request(HotplugHandler *plug_handler,
88                                     DeviceState *plugged_dev,
89                                     Error **errp);
90 /**
91  * hotplug_handler_unplug:
92  *
93  * Calls #HotplugHandlerClass.unplug callback of @plug_handler.
94  */
95 void hotplug_handler_unplug(HotplugHandler *plug_handler,
96                             DeviceState *plugged_dev,
97                             Error **errp);
98 #endif
99