xref: /qemu/include/hw/qdev-core.h (revision 8a9358cc6e6a6ba3685e1b6e8bbf6fa194a38379)
1074a86fcSAnthony Liguori #ifndef QDEV_CORE_H
2074a86fcSAnthony Liguori #define QDEV_CORE_H
3074a86fcSAnthony Liguori 
41de7afc9SPaolo Bonzini #include "qemu/queue.h"
5949fc823SMarcel Apfelbaum #include "qemu/bitmap.h"
614cccb61SPaolo Bonzini #include "qom/object.h"
70ee4de6cSIgor Mammedov #include "hw/hotplug.h"
8e965ffa7SStefan Hajnoczi #include "sysemu/sysemu.h"
9074a86fcSAnthony Liguori 
10074a86fcSAnthony Liguori enum {
11074a86fcSAnthony Liguori     DEV_NVECTORS_UNSPECIFIED = -1,
12074a86fcSAnthony Liguori };
13074a86fcSAnthony Liguori 
14074a86fcSAnthony Liguori #define TYPE_DEVICE "device"
15074a86fcSAnthony Liguori #define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
16074a86fcSAnthony Liguori #define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE)
17074a86fcSAnthony Liguori #define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE)
18074a86fcSAnthony Liguori 
193d1237fbSMarcel Apfelbaum typedef enum DeviceCategory {
203d1237fbSMarcel Apfelbaum     DEVICE_CATEGORY_BRIDGE,
213d1237fbSMarcel Apfelbaum     DEVICE_CATEGORY_USB,
223d1237fbSMarcel Apfelbaum     DEVICE_CATEGORY_STORAGE,
233d1237fbSMarcel Apfelbaum     DEVICE_CATEGORY_NETWORK,
243d1237fbSMarcel Apfelbaum     DEVICE_CATEGORY_INPUT,
253d1237fbSMarcel Apfelbaum     DEVICE_CATEGORY_DISPLAY,
263d1237fbSMarcel Apfelbaum     DEVICE_CATEGORY_SOUND,
273d1237fbSMarcel Apfelbaum     DEVICE_CATEGORY_MISC,
28ba31cc72SThomas Huth     DEVICE_CATEGORY_CPU,
293d1237fbSMarcel Apfelbaum     DEVICE_CATEGORY_MAX
303d1237fbSMarcel Apfelbaum } DeviceCategory;
313d1237fbSMarcel Apfelbaum 
32249d4172SAndreas Färber typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
33249d4172SAndreas Färber typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp);
34b850f664SPhilippe Mathieu-Daudé typedef void (*DeviceReset)(DeviceState *dev);
3502e7f85dSBandan Das typedef void (*BusRealize)(BusState *bus, Error **errp);
3602e7f85dSBandan Das typedef void (*BusUnrealize)(BusState *bus, Error **errp);
37074a86fcSAnthony Liguori 
38249d4172SAndreas Färber /**
39249d4172SAndreas Färber  * DeviceClass:
40249d4172SAndreas Färber  * @props: Properties accessing state fields.
41249d4172SAndreas Färber  * @realize: Callback function invoked when the #DeviceState:realized
42ff46d9d4SPhilippe Mathieu-Daudé  * property is changed to %true.
43249d4172SAndreas Färber  * @unrealize: Callback function invoked when the #DeviceState:realized
44249d4172SAndreas Färber  * property is changed to %false.
451a37eca1SIgor Mammedov  * @hotpluggable: indicates if #DeviceClass is hotpluggable, available
461a37eca1SIgor Mammedov  * as readonly "hotpluggable" property of #DeviceState instance
47249d4172SAndreas Färber  *
48249d4172SAndreas Färber  * # Realization #
49249d4172SAndreas Färber  * Devices are constructed in two stages,
50249d4172SAndreas Färber  * 1) object instantiation via object_initialize() and
51249d4172SAndreas Färber  * 2) device realization via #DeviceState:realized property.
526038f989SThomas Huth  * The former may not fail (and must not abort or exit, since it is called
536038f989SThomas Huth  * during device introspection already), and the latter may return error
546038f989SThomas Huth  * information to the caller and must be re-entrant.
55249d4172SAndreas Färber  * Trivial field initializations should go into #TypeInfo.instance_init.
56249d4172SAndreas Färber  * Operations depending on @props static properties should go into @realize.
57249d4172SAndreas Färber  * After successful realization, setting static properties will fail.
58249d4172SAndreas Färber  *
59daeba969SMarkus Armbruster  * As an interim step, the #DeviceState:realized property can also be
60daeba969SMarkus Armbruster  * set with qdev_init_nofail().
61249d4172SAndreas Färber  * In the future, devices will propagate this state change to their children
62249d4172SAndreas Färber  * and along busses they expose.
63249d4172SAndreas Färber  * The point in time will be deferred to machine creation, so that values
64249d4172SAndreas Färber  * set in @realize will not be introspectable beforehand. Therefore devices
65249d4172SAndreas Färber  * must not create children during @realize; they should initialize them via
66249d4172SAndreas Färber  * object_initialize() in their own #TypeInfo.instance_init and forward the
67249d4172SAndreas Färber  * realization events appropriately.
68249d4172SAndreas Färber  *
69249d4172SAndreas Färber  * Any type may override the @realize and/or @unrealize callbacks but needs
70782beb52SAndreas Färber  * to call the parent type's implementation if keeping their functionality
71782beb52SAndreas Färber  * is desired. Refer to QOM documentation for further discussion and examples.
72782beb52SAndreas Färber  *
73782beb52SAndreas Färber  * <note>
74782beb52SAndreas Färber  *   <para>
75ff46d9d4SPhilippe Mathieu-Daudé  * Since TYPE_DEVICE doesn't implement @realize and @unrealize, types
76ff46d9d4SPhilippe Mathieu-Daudé  * derived directly from it need not call their parent's @realize and
77ff46d9d4SPhilippe Mathieu-Daudé  * @unrealize.
78782beb52SAndreas Färber  * For other types consult the documentation and implementation of the
79782beb52SAndreas Färber  * respective parent types.
80782beb52SAndreas Färber  *   </para>
81782beb52SAndreas Färber  * </note>
82249d4172SAndreas Färber  */
83074a86fcSAnthony Liguori typedef struct DeviceClass {
84249d4172SAndreas Färber     /*< private >*/
85074a86fcSAnthony Liguori     ObjectClass parent_class;
86249d4172SAndreas Färber     /*< public >*/
87074a86fcSAnthony Liguori 
883d1237fbSMarcel Apfelbaum     DECLARE_BITMAP(categories, DEVICE_CATEGORY_MAX);
89074a86fcSAnthony Liguori     const char *fw_name;
90074a86fcSAnthony Liguori     const char *desc;
91074a86fcSAnthony Liguori     Property *props;
92efec3dd6SMarkus Armbruster 
93efec3dd6SMarkus Armbruster     /*
94e90f2a8cSEduardo Habkost      * Can this device be instantiated with -device / device_add?
95efec3dd6SMarkus Armbruster      * All devices should support instantiation with device_add, and
96efec3dd6SMarkus Armbruster      * this flag should not exist.  But we're not there, yet.  Some
97efec3dd6SMarkus Armbruster      * devices fail to instantiate with cryptic error messages.
98efec3dd6SMarkus Armbruster      * Others instantiate, but don't work.  Exposing users to such
99e90f2a8cSEduardo Habkost      * behavior would be cruel; clearing this flag will protect them.
100e90f2a8cSEduardo Habkost      * It should never be cleared without a comment explaining why it
101e90f2a8cSEduardo Habkost      * is cleared.
102efec3dd6SMarkus Armbruster      * TODO remove once we're there
103efec3dd6SMarkus Armbruster      */
104e90f2a8cSEduardo Habkost     bool user_creatable;
1051a37eca1SIgor Mammedov     bool hotpluggable;
106074a86fcSAnthony Liguori 
107074a86fcSAnthony Liguori     /* callbacks */
108b850f664SPhilippe Mathieu-Daudé     DeviceReset reset;
109249d4172SAndreas Färber     DeviceRealize realize;
110249d4172SAndreas Färber     DeviceUnrealize unrealize;
111074a86fcSAnthony Liguori 
112074a86fcSAnthony Liguori     /* device state */
113*8a9358ccSMarkus Armbruster     const VMStateDescription *vmsd;
114074a86fcSAnthony Liguori 
115074a86fcSAnthony Liguori     /* Private to qdev / bus.  */
116074a86fcSAnthony Liguori     const char *bus_type;
117074a86fcSAnthony Liguori } DeviceClass;
118074a86fcSAnthony Liguori 
119a5f54290SPeter Crosthwaite typedef struct NamedGPIOList NamedGPIOList;
120a5f54290SPeter Crosthwaite 
121a5f54290SPeter Crosthwaite struct NamedGPIOList {
122a5f54290SPeter Crosthwaite     char *name;
123a5f54290SPeter Crosthwaite     qemu_irq *in;
124a5f54290SPeter Crosthwaite     int num_in;
125a5f54290SPeter Crosthwaite     int num_out;
126a5f54290SPeter Crosthwaite     QLIST_ENTRY(NamedGPIOList) node;
127a5f54290SPeter Crosthwaite };
128a5f54290SPeter Crosthwaite 
1297983c8a3SAndreas Färber /**
1307983c8a3SAndreas Färber  * DeviceState:
1317983c8a3SAndreas Färber  * @realized: Indicates whether the device has been fully constructed.
1327983c8a3SAndreas Färber  *
1337983c8a3SAndreas Färber  * This structure should not be accessed directly.  We declare it here
1347983c8a3SAndreas Färber  * so that it can be embedded in individual device state structures.
1357983c8a3SAndreas Färber  */
136074a86fcSAnthony Liguori struct DeviceState {
1377983c8a3SAndreas Färber     /*< private >*/
138074a86fcSAnthony Liguori     Object parent_obj;
1397983c8a3SAndreas Färber     /*< public >*/
140074a86fcSAnthony Liguori 
141074a86fcSAnthony Liguori     const char *id;
14204162f8fSMichael Roth     char *canonical_path;
1437983c8a3SAndreas Färber     bool realized;
144352e8da7SPaolo Bonzini     bool pending_deleted_event;
145074a86fcSAnthony Liguori     QemuOpts *opts;
146074a86fcSAnthony Liguori     int hotplugged;
147074a86fcSAnthony Liguori     BusState *parent_bus;
148a5f54290SPeter Crosthwaite     QLIST_HEAD(, NamedGPIOList) gpios;
149074a86fcSAnthony Liguori     QLIST_HEAD(, BusState) child_bus;
150074a86fcSAnthony Liguori     int num_child_bus;
151074a86fcSAnthony Liguori     int instance_id_alias;
152074a86fcSAnthony Liguori     int alias_required_for_version;
153074a86fcSAnthony Liguori };
154074a86fcSAnthony Liguori 
155707ff800SPaul Durrant struct DeviceListener {
156707ff800SPaul Durrant     void (*realize)(DeviceListener *listener, DeviceState *dev);
157707ff800SPaul Durrant     void (*unrealize)(DeviceListener *listener, DeviceState *dev);
158707ff800SPaul Durrant     QTAILQ_ENTRY(DeviceListener) link;
159707ff800SPaul Durrant };
160707ff800SPaul Durrant 
161074a86fcSAnthony Liguori #define TYPE_BUS "bus"
162074a86fcSAnthony Liguori #define BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS)
163074a86fcSAnthony Liguori #define BUS_CLASS(klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS)
164074a86fcSAnthony Liguori #define BUS_GET_CLASS(obj) OBJECT_GET_CLASS(BusClass, (obj), TYPE_BUS)
165074a86fcSAnthony Liguori 
166074a86fcSAnthony Liguori struct BusClass {
167074a86fcSAnthony Liguori     ObjectClass parent_class;
168074a86fcSAnthony Liguori 
169074a86fcSAnthony Liguori     /* FIXME first arg should be BusState */
170074a86fcSAnthony Liguori     void (*print_dev)(Monitor *mon, DeviceState *dev, int indent);
171074a86fcSAnthony Liguori     char *(*get_dev_path)(DeviceState *dev);
172074a86fcSAnthony Liguori     /*
173074a86fcSAnthony Liguori      * This callback is used to create Open Firmware device path in accordance
174074a86fcSAnthony Liguori      * with OF spec http://forthworks.com/standards/of1275.pdf. Individual bus
175074a86fcSAnthony Liguori      * bindings can be found at http://playground.sun.com/1275/bindings/.
176074a86fcSAnthony Liguori      */
177074a86fcSAnthony Liguori     char *(*get_fw_dev_path)(DeviceState *dev);
178dcc20931SPaolo Bonzini     void (*reset)(BusState *bus);
17902e7f85dSBandan Das     BusRealize realize;
18002e7f85dSBandan Das     BusUnrealize unrealize;
18102e7f85dSBandan Das 
1821395af6fSKONRAD Frederic     /* maximum devices allowed on the bus, 0: no limit. */
1831395af6fSKONRAD Frederic     int max_dev;
18461de3676SAlexander Graf     /* number of automatically allocated bus ids (e.g. ide.0) */
18561de3676SAlexander Graf     int automatic_ids;
186074a86fcSAnthony Liguori };
187074a86fcSAnthony Liguori 
188074a86fcSAnthony Liguori typedef struct BusChild {
189074a86fcSAnthony Liguori     DeviceState *child;
190074a86fcSAnthony Liguori     int index;
191074a86fcSAnthony Liguori     QTAILQ_ENTRY(BusChild) sibling;
192074a86fcSAnthony Liguori } BusChild;
193074a86fcSAnthony Liguori 
1940ee4de6cSIgor Mammedov #define QDEV_HOTPLUG_HANDLER_PROPERTY "hotplug-handler"
1950ee4de6cSIgor Mammedov 
196074a86fcSAnthony Liguori /**
197074a86fcSAnthony Liguori  * BusState:
19827c6ef1bSLi Qiang  * @hotplug_handler: link to a hotplug handler associated with bus.
199074a86fcSAnthony Liguori  */
200074a86fcSAnthony Liguori struct BusState {
201074a86fcSAnthony Liguori     Object obj;
202074a86fcSAnthony Liguori     DeviceState *parent;
203f73480c3SMarc-André Lureau     char *name;
2040ee4de6cSIgor Mammedov     HotplugHandler *hotplug_handler;
205074a86fcSAnthony Liguori     int max_index;
20602e7f85dSBandan Das     bool realized;
20712b2e9f3STony Krowiak     int num_children;
208eae3eb3eSPaolo Bonzini     QTAILQ_HEAD(, BusChild) children;
209074a86fcSAnthony Liguori     QLIST_ENTRY(BusState) sibling;
210074a86fcSAnthony Liguori };
211074a86fcSAnthony Liguori 
2125cc56cc6SPeter Maydell /**
2135cc56cc6SPeter Maydell  * Property:
2145cc56cc6SPeter Maydell  * @set_default: true if the default value should be set from @defval,
2155cc56cc6SPeter Maydell  *    in which case @info->set_default_value must not be NULL
2165cc56cc6SPeter Maydell  *    (if false then no default value is set by the property system
2175cc56cc6SPeter Maydell  *     and the field retains whatever value it was given by instance_init).
2185cc56cc6SPeter Maydell  * @defval: default value for the property. This is used only if @set_default
2195cc56cc6SPeter Maydell  *     is true.
2205cc56cc6SPeter Maydell  */
221074a86fcSAnthony Liguori struct Property {
222074a86fcSAnthony Liguori     const char   *name;
2231b6b7d10SFam Zheng     const PropertyInfo *info;
2243b6ca402SIldar Isaev     ptrdiff_t    offset;
225074a86fcSAnthony Liguori     uint8_t      bitnr;
2265cc56cc6SPeter Maydell     bool         set_default;
22776318657SMarc-André Lureau     union {
22876318657SMarc-André Lureau         int64_t i;
2293fb2111fSMarc-André Lureau         uint64_t u;
23076318657SMarc-André Lureau     } defval;
2310be6bfacSPeter Maydell     int          arrayoffset;
2321b6b7d10SFam Zheng     const PropertyInfo *arrayinfo;
2330be6bfacSPeter Maydell     int          arrayfieldsize;
2345b4ff3c6SFam Zheng     const char   *link_type;
235074a86fcSAnthony Liguori };
236074a86fcSAnthony Liguori 
237074a86fcSAnthony Liguori struct PropertyInfo {
238074a86fcSAnthony Liguori     const char *name;
23951b2e8c3SGonglei     const char *description;
240f7abe0ecSMarc-André Lureau     const QEnumLookup *enum_table;
241074a86fcSAnthony Liguori     int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
242a2740ad5SMarc-André Lureau     void (*set_default_value)(Object *obj, const Property *prop);
243faabdbb7SFam Zheng     void (*create)(Object *obj, Property *prop, Error **errp);
244074a86fcSAnthony Liguori     ObjectPropertyAccessor *get;
245074a86fcSAnthony Liguori     ObjectPropertyAccessor *set;
246074a86fcSAnthony Liguori     ObjectPropertyRelease *release;
247074a86fcSAnthony Liguori };
248074a86fcSAnthony Liguori 
2499f9260a3SDon Slutz /**
2509f9260a3SDon Slutz  * GlobalProperty:
251b3ce84feSEduardo Habkost  * @used: Set to true if property was used when initializing a device.
25292fd453cSDr. David Alan Gilbert  * @optional: If set to true, GlobalProperty will be skipped without errors
25392fd453cSDr. David Alan Gilbert  *            if the property doesn't exist.
254cff8b715SMarc-André Lureau  *
255cff8b715SMarc-André Lureau  * An error is fatal for non-hotplugged devices, when the global is applied.
2569f9260a3SDon Slutz  */
257074a86fcSAnthony Liguori typedef struct GlobalProperty {
258074a86fcSAnthony Liguori     const char *driver;
259074a86fcSAnthony Liguori     const char *property;
260074a86fcSAnthony Liguori     const char *value;
261b3ce84feSEduardo Habkost     bool used;
26292fd453cSDr. David Alan Gilbert     bool optional;
263074a86fcSAnthony Liguori } GlobalProperty;
264074a86fcSAnthony Liguori 
265ea9ce893SMarc-André Lureau static inline void
266ea9ce893SMarc-André Lureau compat_props_add(GPtrArray *arr,
267ea9ce893SMarc-André Lureau                  GlobalProperty props[], size_t nelem)
268ea9ce893SMarc-André Lureau {
269ea9ce893SMarc-André Lureau     int i;
270ea9ce893SMarc-André Lureau     for (i = 0; i < nelem; i++) {
271ea9ce893SMarc-André Lureau         g_ptr_array_add(arr, (void *)&props[i]);
272ea9ce893SMarc-André Lureau     }
273ea9ce893SMarc-André Lureau }
274ea9ce893SMarc-André Lureau 
275074a86fcSAnthony Liguori /*** Board API.  This should go away once we have a machine config file.  ***/
276074a86fcSAnthony Liguori 
277074a86fcSAnthony Liguori DeviceState *qdev_create(BusState *bus, const char *name);
278074a86fcSAnthony Liguori DeviceState *qdev_try_create(BusState *bus, const char *name);
279074a86fcSAnthony Liguori void qdev_init_nofail(DeviceState *dev);
280074a86fcSAnthony Liguori void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
281074a86fcSAnthony Liguori                                  int required_for_version);
28214405c27SDavid Hildenbrand HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev);
28303fcbd9dSThomas Huth HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev);
28417cc0128SIgor Mammedov /**
28517cc0128SIgor Mammedov  * qdev_get_hotplug_handler: Get handler responsible for device wiring
28617cc0128SIgor Mammedov  *
28717cc0128SIgor Mammedov  * Find HOTPLUG_HANDLER for @dev that provides [pre|un]plug callbacks for it.
28817cc0128SIgor Mammedov  *
28917cc0128SIgor Mammedov  * Note: in case @dev has a parent bus, it will be returned as handler unless
29017cc0128SIgor Mammedov  * machine handler overrides it.
29117cc0128SIgor Mammedov  *
29217cc0128SIgor Mammedov  * Returns: pointer to object that implements TYPE_HOTPLUG_HANDLER interface
29317cc0128SIgor Mammedov  *          or NULL if there aren't any.
29417cc0128SIgor Mammedov  */
295c06b2ffbSZhu Guihua HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev);
296074a86fcSAnthony Liguori void qdev_unplug(DeviceState *dev, Error **errp);
297014176f9SIgor Mammedov void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,
298014176f9SIgor Mammedov                                   DeviceState *dev, Error **errp);
299074a86fcSAnthony Liguori void qdev_machine_creation_done(void);
300074a86fcSAnthony Liguori bool qdev_machine_modified(void);
301074a86fcSAnthony Liguori 
302074a86fcSAnthony Liguori qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
303a5f54290SPeter Crosthwaite qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n);
304a5f54290SPeter Crosthwaite 
305074a86fcSAnthony Liguori void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
306a5f54290SPeter Crosthwaite void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
307a5f54290SPeter Crosthwaite                                  qemu_irq pin);
308b7973186SAlexander Graf qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n);
3090c24db2bSPeter Crosthwaite qemu_irq qdev_intercept_gpio_out(DeviceState *dev, qemu_irq icpt,
3100c24db2bSPeter Crosthwaite                                  const char *name, int n);
311074a86fcSAnthony Liguori 
312074a86fcSAnthony Liguori BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
313074a86fcSAnthony Liguori 
314074a86fcSAnthony Liguori /*** Device API.  ***/
315074a86fcSAnthony Liguori 
316074a86fcSAnthony Liguori /* Register device properties.  */
317074a86fcSAnthony Liguori /* GPIO inputs also double as IRQ sinks.  */
318074a86fcSAnthony Liguori void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
319074a86fcSAnthony Liguori void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
320a5f54290SPeter Crosthwaite void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins,
321a5f54290SPeter Crosthwaite                               const char *name, int n);
3224a151677SPeter Maydell /**
3234a151677SPeter Maydell  * qdev_init_gpio_in_named_with_opaque: create an array of input GPIO lines
3244a151677SPeter Maydell  *   for the specified device
3254a151677SPeter Maydell  *
3264a151677SPeter Maydell  * @dev: Device to create input GPIOs for
3274a151677SPeter Maydell  * @handler: Function to call when GPIO line value is set
3284a151677SPeter Maydell  * @opaque: Opaque data pointer to pass to @handler
3294a151677SPeter Maydell  * @name: Name of the GPIO input (must be unique for this device)
3304a151677SPeter Maydell  * @n: Number of GPIO lines in this input set
3314a151677SPeter Maydell  */
3324a151677SPeter Maydell void qdev_init_gpio_in_named_with_opaque(DeviceState *dev,
3334a151677SPeter Maydell                                          qemu_irq_handler handler,
3344a151677SPeter Maydell                                          void *opaque,
3354a151677SPeter Maydell                                          const char *name, int n);
3364a151677SPeter Maydell 
3374a151677SPeter Maydell /**
3384a151677SPeter Maydell  * qdev_init_gpio_in_named: create an array of input GPIO lines
3394a151677SPeter Maydell  *   for the specified device
3404a151677SPeter Maydell  *
3414a151677SPeter Maydell  * Like qdev_init_gpio_in_named_with_opaque(), but the opaque pointer
3424a151677SPeter Maydell  * passed to the handler is @dev (which is the most commonly desired behaviour).
3434a151677SPeter Maydell  */
3444a151677SPeter Maydell static inline void qdev_init_gpio_in_named(DeviceState *dev,
3454a151677SPeter Maydell                                            qemu_irq_handler handler,
3464a151677SPeter Maydell                                            const char *name, int n)
3474a151677SPeter Maydell {
3484a151677SPeter Maydell     qdev_init_gpio_in_named_with_opaque(dev, handler, dev, name, n);
3494a151677SPeter Maydell }
350074a86fcSAnthony Liguori 
35117a96a14SPeter Crosthwaite void qdev_pass_gpios(DeviceState *dev, DeviceState *container,
35217a96a14SPeter Crosthwaite                      const char *name);
35317a96a14SPeter Crosthwaite 
354074a86fcSAnthony Liguori BusState *qdev_get_parent_bus(DeviceState *dev);
355074a86fcSAnthony Liguori 
356074a86fcSAnthony Liguori /*** BUS API. ***/
357074a86fcSAnthony Liguori 
358074a86fcSAnthony Liguori DeviceState *qdev_find_recursive(BusState *bus, const char *id);
359074a86fcSAnthony Liguori 
360074a86fcSAnthony Liguori /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
361074a86fcSAnthony Liguori typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
362074a86fcSAnthony Liguori typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
363074a86fcSAnthony Liguori 
364fb17dfe0SAndreas Färber void qbus_create_inplace(void *bus, size_t size, const char *typename,
365074a86fcSAnthony Liguori                          DeviceState *parent, const char *name);
366074a86fcSAnthony Liguori BusState *qbus_create(const char *typename, DeviceState *parent, const char *name);
367074a86fcSAnthony Liguori /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion,
368074a86fcSAnthony Liguori  *         < 0 if either devfn or busfn terminate walk somewhere in cursion,
369074a86fcSAnthony Liguori  *           0 otherwise. */
3700293214bSPaolo Bonzini int qbus_walk_children(BusState *bus,
3710293214bSPaolo Bonzini                        qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn,
3720293214bSPaolo Bonzini                        qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn,
3730293214bSPaolo Bonzini                        void *opaque);
3740293214bSPaolo Bonzini int qdev_walk_children(DeviceState *dev,
3750293214bSPaolo Bonzini                        qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn,
3760293214bSPaolo Bonzini                        qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn,
3770293214bSPaolo Bonzini                        void *opaque);
3780293214bSPaolo Bonzini 
379074a86fcSAnthony Liguori void qdev_reset_all(DeviceState *dev);
380ff8de075SDavid Hildenbrand void qdev_reset_all_fn(void *opaque);
381d0508c36SPaolo Bonzini 
382d0508c36SPaolo Bonzini /**
383d0508c36SPaolo Bonzini  * @qbus_reset_all:
384d0508c36SPaolo Bonzini  * @bus: Bus to be reset.
385d0508c36SPaolo Bonzini  *
386d0508c36SPaolo Bonzini  * Reset @bus and perform a bus-level ("hard") reset of all devices connected
387d0508c36SPaolo Bonzini  * to it, including recursive processing of all buses below @bus itself.  A
388d0508c36SPaolo Bonzini  * hard reset means that qbus_reset_all will reset all state of the device.
389d0508c36SPaolo Bonzini  * For PCI devices, for example, this will include the base address registers
390d0508c36SPaolo Bonzini  * or configuration space.
391d0508c36SPaolo Bonzini  */
392d0508c36SPaolo Bonzini void qbus_reset_all(BusState *bus);
393074a86fcSAnthony Liguori void qbus_reset_all_fn(void *opaque);
394074a86fcSAnthony Liguori 
395074a86fcSAnthony Liguori /* This should go away once we get rid of the NULL bus hack */
396074a86fcSAnthony Liguori BusState *sysbus_get_default(void);
397074a86fcSAnthony Liguori 
398074a86fcSAnthony Liguori char *qdev_get_fw_dev_path(DeviceState *dev);
3990be63901SGonglei char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev);
400074a86fcSAnthony Liguori 
401074a86fcSAnthony Liguori /**
402074a86fcSAnthony Liguori  * @qdev_machine_init
403074a86fcSAnthony Liguori  *
404074a86fcSAnthony Liguori  * Initialize platform devices before machine init.  This is a hack until full
405074a86fcSAnthony Liguori  * support for composition is added.
406074a86fcSAnthony Liguori  */
407074a86fcSAnthony Liguori void qdev_machine_init(void);
408074a86fcSAnthony Liguori 
409074a86fcSAnthony Liguori /**
410074a86fcSAnthony Liguori  * @device_reset
411074a86fcSAnthony Liguori  *
412074a86fcSAnthony Liguori  * Reset a single device (by calling the reset method).
413074a86fcSAnthony Liguori  */
414074a86fcSAnthony Liguori void device_reset(DeviceState *dev);
415074a86fcSAnthony Liguori 
41646795cf2SPhilippe Mathieu-Daudé void device_class_set_parent_reset(DeviceClass *dc,
41746795cf2SPhilippe Mathieu-Daudé                                    DeviceReset dev_reset,
41846795cf2SPhilippe Mathieu-Daudé                                    DeviceReset *parent_reset);
41946795cf2SPhilippe Mathieu-Daudé void device_class_set_parent_realize(DeviceClass *dc,
42046795cf2SPhilippe Mathieu-Daudé                                      DeviceRealize dev_realize,
42146795cf2SPhilippe Mathieu-Daudé                                      DeviceRealize *parent_realize);
42246795cf2SPhilippe Mathieu-Daudé void device_class_set_parent_unrealize(DeviceClass *dc,
42346795cf2SPhilippe Mathieu-Daudé                                        DeviceUnrealize dev_unrealize,
42446795cf2SPhilippe Mathieu-Daudé                                        DeviceUnrealize *parent_unrealize);
42546795cf2SPhilippe Mathieu-Daudé 
426*8a9358ccSMarkus Armbruster const VMStateDescription *qdev_get_vmsd(DeviceState *dev);
427074a86fcSAnthony Liguori 
428074a86fcSAnthony Liguori const char *qdev_fw_name(DeviceState *dev);
429074a86fcSAnthony Liguori 
430074a86fcSAnthony Liguori Object *qdev_get_machine(void);
431074a86fcSAnthony Liguori 
432074a86fcSAnthony Liguori /* FIXME: make this a link<> */
433074a86fcSAnthony Liguori void qdev_set_parent_bus(DeviceState *dev, BusState *bus);
434074a86fcSAnthony Liguori 
4359bed84c1SJuan Quintela extern bool qdev_hotplug;
43621def24aSJuan Quintela extern bool qdev_hot_removed;
437074a86fcSAnthony Liguori 
438074a86fcSAnthony Liguori char *qdev_get_dev_path(DeviceState *dev);
439074a86fcSAnthony Liguori 
4404cae4d5aSMarcel Apfelbaum GSList *qdev_build_hotpluggable_device_list(Object *peripheral);
44166e56b13SZhu Guihua 
44294d1cc5fSMichael Roth void qbus_set_hotplug_handler(BusState *bus, Object *handler, Error **errp);
443431bbb26SIgor Mammedov 
444431bbb26SIgor Mammedov void qbus_set_bus_hotplug_handler(BusState *bus, Error **errp);
44539b888bdSIgor Mammedov 
44639b888bdSIgor Mammedov static inline bool qbus_is_hotpluggable(BusState *bus)
44739b888bdSIgor Mammedov {
4482d9a982fSIgor Mammedov    return bus->hotplug_handler;
44939b888bdSIgor Mammedov }
450707ff800SPaul Durrant 
451707ff800SPaul Durrant void device_listener_register(DeviceListener *listener);
452707ff800SPaul Durrant void device_listener_unregister(DeviceListener *listener);
453707ff800SPaul Durrant 
454e965ffa7SStefan Hajnoczi VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev,
455e965ffa7SStefan Hajnoczi                                                      VMChangeStateHandler *cb,
456e965ffa7SStefan Hajnoczi                                                      void *opaque);
457e965ffa7SStefan Hajnoczi 
458074a86fcSAnthony Liguori #endif
459