xref: /qemu/include/hw/qdev-core.h (revision 27c6ef1b5857b1447f0a0f8da4bd7df3e1a7a637)
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"
7074a86fcSAnthony Liguori #include "hw/irq.h"
80ee4de6cSIgor Mammedov #include "hw/hotplug.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 
38074a86fcSAnthony Liguori struct VMStateDescription;
39074a86fcSAnthony Liguori 
40249d4172SAndreas Färber /**
41249d4172SAndreas Färber  * DeviceClass:
42249d4172SAndreas Färber  * @props: Properties accessing state fields.
43249d4172SAndreas Färber  * @realize: Callback function invoked when the #DeviceState:realized
44ff46d9d4SPhilippe Mathieu-Daudé  * property is changed to %true.
45249d4172SAndreas Färber  * @unrealize: Callback function invoked when the #DeviceState:realized
46249d4172SAndreas Färber  * property is changed to %false.
471a37eca1SIgor Mammedov  * @hotpluggable: indicates if #DeviceClass is hotpluggable, available
481a37eca1SIgor Mammedov  * as readonly "hotpluggable" property of #DeviceState instance
49249d4172SAndreas Färber  *
50249d4172SAndreas Färber  * # Realization #
51249d4172SAndreas Färber  * Devices are constructed in two stages,
52249d4172SAndreas Färber  * 1) object instantiation via object_initialize() and
53249d4172SAndreas Färber  * 2) device realization via #DeviceState:realized property.
546038f989SThomas Huth  * The former may not fail (and must not abort or exit, since it is called
556038f989SThomas Huth  * during device introspection already), and the latter may return error
566038f989SThomas Huth  * information to the caller and must be re-entrant.
57249d4172SAndreas Färber  * Trivial field initializations should go into #TypeInfo.instance_init.
58249d4172SAndreas Färber  * Operations depending on @props static properties should go into @realize.
59249d4172SAndreas Färber  * After successful realization, setting static properties will fail.
60249d4172SAndreas Färber  *
61daeba969SMarkus Armbruster  * As an interim step, the #DeviceState:realized property can also be
62daeba969SMarkus Armbruster  * set with qdev_init_nofail().
63249d4172SAndreas Färber  * In the future, devices will propagate this state change to their children
64249d4172SAndreas Färber  * and along busses they expose.
65249d4172SAndreas Färber  * The point in time will be deferred to machine creation, so that values
66249d4172SAndreas Färber  * set in @realize will not be introspectable beforehand. Therefore devices
67249d4172SAndreas Färber  * must not create children during @realize; they should initialize them via
68249d4172SAndreas Färber  * object_initialize() in their own #TypeInfo.instance_init and forward the
69249d4172SAndreas Färber  * realization events appropriately.
70249d4172SAndreas Färber  *
71249d4172SAndreas Färber  * Any type may override the @realize and/or @unrealize callbacks but needs
72782beb52SAndreas Färber  * to call the parent type's implementation if keeping their functionality
73782beb52SAndreas Färber  * is desired. Refer to QOM documentation for further discussion and examples.
74782beb52SAndreas Färber  *
75782beb52SAndreas Färber  * <note>
76782beb52SAndreas Färber  *   <para>
77ff46d9d4SPhilippe Mathieu-Daudé  * Since TYPE_DEVICE doesn't implement @realize and @unrealize, types
78ff46d9d4SPhilippe Mathieu-Daudé  * derived directly from it need not call their parent's @realize and
79ff46d9d4SPhilippe Mathieu-Daudé  * @unrealize.
80782beb52SAndreas Färber  * For other types consult the documentation and implementation of the
81782beb52SAndreas Färber  * respective parent types.
82782beb52SAndreas Färber  *   </para>
83782beb52SAndreas Färber  * </note>
84249d4172SAndreas Färber  */
85074a86fcSAnthony Liguori typedef struct DeviceClass {
86249d4172SAndreas Färber     /*< private >*/
87074a86fcSAnthony Liguori     ObjectClass parent_class;
88249d4172SAndreas Färber     /*< public >*/
89074a86fcSAnthony Liguori 
903d1237fbSMarcel Apfelbaum     DECLARE_BITMAP(categories, DEVICE_CATEGORY_MAX);
91074a86fcSAnthony Liguori     const char *fw_name;
92074a86fcSAnthony Liguori     const char *desc;
93074a86fcSAnthony Liguori     Property *props;
94efec3dd6SMarkus Armbruster 
95efec3dd6SMarkus Armbruster     /*
96e90f2a8cSEduardo Habkost      * Can this device be instantiated with -device / device_add?
97efec3dd6SMarkus Armbruster      * All devices should support instantiation with device_add, and
98efec3dd6SMarkus Armbruster      * this flag should not exist.  But we're not there, yet.  Some
99efec3dd6SMarkus Armbruster      * devices fail to instantiate with cryptic error messages.
100efec3dd6SMarkus Armbruster      * Others instantiate, but don't work.  Exposing users to such
101e90f2a8cSEduardo Habkost      * behavior would be cruel; clearing this flag will protect them.
102e90f2a8cSEduardo Habkost      * It should never be cleared without a comment explaining why it
103e90f2a8cSEduardo Habkost      * is cleared.
104efec3dd6SMarkus Armbruster      * TODO remove once we're there
105efec3dd6SMarkus Armbruster      */
106e90f2a8cSEduardo Habkost     bool user_creatable;
1071a37eca1SIgor Mammedov     bool hotpluggable;
108074a86fcSAnthony Liguori 
109074a86fcSAnthony Liguori     /* callbacks */
110b850f664SPhilippe Mathieu-Daudé     DeviceReset reset;
111249d4172SAndreas Färber     DeviceRealize realize;
112249d4172SAndreas Färber     DeviceUnrealize unrealize;
113074a86fcSAnthony Liguori 
114074a86fcSAnthony Liguori     /* device state */
115074a86fcSAnthony Liguori     const struct VMStateDescription *vmsd;
116074a86fcSAnthony Liguori 
117074a86fcSAnthony Liguori     /* Private to qdev / bus.  */
118074a86fcSAnthony Liguori     const char *bus_type;
119074a86fcSAnthony Liguori } DeviceClass;
120074a86fcSAnthony Liguori 
121a5f54290SPeter Crosthwaite typedef struct NamedGPIOList NamedGPIOList;
122a5f54290SPeter Crosthwaite 
123a5f54290SPeter Crosthwaite struct NamedGPIOList {
124a5f54290SPeter Crosthwaite     char *name;
125a5f54290SPeter Crosthwaite     qemu_irq *in;
126a5f54290SPeter Crosthwaite     int num_in;
127a5f54290SPeter Crosthwaite     int num_out;
128a5f54290SPeter Crosthwaite     QLIST_ENTRY(NamedGPIOList) node;
129a5f54290SPeter Crosthwaite };
130a5f54290SPeter Crosthwaite 
1317983c8a3SAndreas Färber /**
1327983c8a3SAndreas Färber  * DeviceState:
1337983c8a3SAndreas Färber  * @realized: Indicates whether the device has been fully constructed.
1347983c8a3SAndreas Färber  *
1357983c8a3SAndreas Färber  * This structure should not be accessed directly.  We declare it here
1367983c8a3SAndreas Färber  * so that it can be embedded in individual device state structures.
1377983c8a3SAndreas Färber  */
138074a86fcSAnthony Liguori struct DeviceState {
1397983c8a3SAndreas Färber     /*< private >*/
140074a86fcSAnthony Liguori     Object parent_obj;
1417983c8a3SAndreas Färber     /*< public >*/
142074a86fcSAnthony Liguori 
143074a86fcSAnthony Liguori     const char *id;
14404162f8fSMichael Roth     char *canonical_path;
1457983c8a3SAndreas Färber     bool realized;
146352e8da7SPaolo Bonzini     bool pending_deleted_event;
147074a86fcSAnthony Liguori     QemuOpts *opts;
148074a86fcSAnthony Liguori     int hotplugged;
149074a86fcSAnthony Liguori     BusState *parent_bus;
150a5f54290SPeter Crosthwaite     QLIST_HEAD(, NamedGPIOList) gpios;
151074a86fcSAnthony Liguori     QLIST_HEAD(, BusState) child_bus;
152074a86fcSAnthony Liguori     int num_child_bus;
153074a86fcSAnthony Liguori     int instance_id_alias;
154074a86fcSAnthony Liguori     int alias_required_for_version;
155074a86fcSAnthony Liguori };
156074a86fcSAnthony Liguori 
157707ff800SPaul Durrant struct DeviceListener {
158707ff800SPaul Durrant     void (*realize)(DeviceListener *listener, DeviceState *dev);
159707ff800SPaul Durrant     void (*unrealize)(DeviceListener *listener, DeviceState *dev);
160707ff800SPaul Durrant     QTAILQ_ENTRY(DeviceListener) link;
161707ff800SPaul Durrant };
162707ff800SPaul Durrant 
163074a86fcSAnthony Liguori #define TYPE_BUS "bus"
164074a86fcSAnthony Liguori #define BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS)
165074a86fcSAnthony Liguori #define BUS_CLASS(klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS)
166074a86fcSAnthony Liguori #define BUS_GET_CLASS(obj) OBJECT_GET_CLASS(BusClass, (obj), TYPE_BUS)
167074a86fcSAnthony Liguori 
168074a86fcSAnthony Liguori struct BusClass {
169074a86fcSAnthony Liguori     ObjectClass parent_class;
170074a86fcSAnthony Liguori 
171074a86fcSAnthony Liguori     /* FIXME first arg should be BusState */
172074a86fcSAnthony Liguori     void (*print_dev)(Monitor *mon, DeviceState *dev, int indent);
173074a86fcSAnthony Liguori     char *(*get_dev_path)(DeviceState *dev);
174074a86fcSAnthony Liguori     /*
175074a86fcSAnthony Liguori      * This callback is used to create Open Firmware device path in accordance
176074a86fcSAnthony Liguori      * with OF spec http://forthworks.com/standards/of1275.pdf. Individual bus
177074a86fcSAnthony Liguori      * bindings can be found at http://playground.sun.com/1275/bindings/.
178074a86fcSAnthony Liguori      */
179074a86fcSAnthony Liguori     char *(*get_fw_dev_path)(DeviceState *dev);
180dcc20931SPaolo Bonzini     void (*reset)(BusState *bus);
18102e7f85dSBandan Das     BusRealize realize;
18202e7f85dSBandan Das     BusUnrealize unrealize;
18302e7f85dSBandan Das 
1841395af6fSKONRAD Frederic     /* maximum devices allowed on the bus, 0: no limit. */
1851395af6fSKONRAD Frederic     int max_dev;
18661de3676SAlexander Graf     /* number of automatically allocated bus ids (e.g. ide.0) */
18761de3676SAlexander Graf     int automatic_ids;
188074a86fcSAnthony Liguori };
189074a86fcSAnthony Liguori 
190074a86fcSAnthony Liguori typedef struct BusChild {
191074a86fcSAnthony Liguori     DeviceState *child;
192074a86fcSAnthony Liguori     int index;
193074a86fcSAnthony Liguori     QTAILQ_ENTRY(BusChild) sibling;
194074a86fcSAnthony Liguori } BusChild;
195074a86fcSAnthony Liguori 
1960ee4de6cSIgor Mammedov #define QDEV_HOTPLUG_HANDLER_PROPERTY "hotplug-handler"
1970ee4de6cSIgor Mammedov 
198074a86fcSAnthony Liguori /**
199074a86fcSAnthony Liguori  * BusState:
200*27c6ef1bSLi Qiang  * @hotplug_handler: link to a hotplug handler associated with bus.
201074a86fcSAnthony Liguori  */
202074a86fcSAnthony Liguori struct BusState {
203074a86fcSAnthony Liguori     Object obj;
204074a86fcSAnthony Liguori     DeviceState *parent;
205f73480c3SMarc-André Lureau     char *name;
2060ee4de6cSIgor Mammedov     HotplugHandler *hotplug_handler;
207074a86fcSAnthony Liguori     int max_index;
20802e7f85dSBandan Das     bool realized;
209074a86fcSAnthony Liguori     QTAILQ_HEAD(ChildrenHead, BusChild) children;
210074a86fcSAnthony Liguori     QLIST_ENTRY(BusState) sibling;
211074a86fcSAnthony Liguori };
212074a86fcSAnthony Liguori 
2135cc56cc6SPeter Maydell /**
2145cc56cc6SPeter Maydell  * Property:
2155cc56cc6SPeter Maydell  * @set_default: true if the default value should be set from @defval,
2165cc56cc6SPeter Maydell  *    in which case @info->set_default_value must not be NULL
2175cc56cc6SPeter Maydell  *    (if false then no default value is set by the property system
2185cc56cc6SPeter Maydell  *     and the field retains whatever value it was given by instance_init).
2195cc56cc6SPeter Maydell  * @defval: default value for the property. This is used only if @set_default
2205cc56cc6SPeter Maydell  *     is true.
2215cc56cc6SPeter Maydell  */
222074a86fcSAnthony Liguori struct Property {
223074a86fcSAnthony Liguori     const char   *name;
2241b6b7d10SFam Zheng     const PropertyInfo *info;
2253b6ca402SIldar Isaev     ptrdiff_t    offset;
226074a86fcSAnthony Liguori     uint8_t      bitnr;
2275cc56cc6SPeter Maydell     bool         set_default;
22876318657SMarc-André Lureau     union {
22976318657SMarc-André Lureau         int64_t i;
2303fb2111fSMarc-André Lureau         uint64_t u;
23176318657SMarc-André Lureau     } defval;
2320be6bfacSPeter Maydell     int          arrayoffset;
2331b6b7d10SFam Zheng     const PropertyInfo *arrayinfo;
2340be6bfacSPeter Maydell     int          arrayfieldsize;
2355b4ff3c6SFam Zheng     const char   *link_type;
236074a86fcSAnthony Liguori };
237074a86fcSAnthony Liguori 
238074a86fcSAnthony Liguori struct PropertyInfo {
239074a86fcSAnthony Liguori     const char *name;
24051b2e8c3SGonglei     const char *description;
241f7abe0ecSMarc-André Lureau     const QEnumLookup *enum_table;
242074a86fcSAnthony Liguori     int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
243a2740ad5SMarc-André Lureau     void (*set_default_value)(Object *obj, const Property *prop);
244faabdbb7SFam Zheng     void (*create)(Object *obj, Property *prop, Error **errp);
245074a86fcSAnthony Liguori     ObjectPropertyAccessor *get;
246074a86fcSAnthony Liguori     ObjectPropertyAccessor *set;
247074a86fcSAnthony Liguori     ObjectPropertyRelease *release;
248074a86fcSAnthony Liguori };
249074a86fcSAnthony Liguori 
2509f9260a3SDon Slutz /**
2519f9260a3SDon Slutz  * GlobalProperty:
252b3ce84feSEduardo Habkost  * @user_provided: Set to true if property comes from user-provided config
253b3ce84feSEduardo Habkost  * (command-line or config file).
254b3ce84feSEduardo Habkost  * @used: Set to true if property was used when initializing a device.
25577280adbSEduardo Habkost  * @errp: Error destination, used like first argument of error_setg()
25677280adbSEduardo Habkost  *        in case property setting fails later. If @errp is NULL, we
257b3443f43SGreg Kurz  *        print warnings instead of ignoring errors silently. For
258b3443f43SGreg Kurz  *        hotplugged devices, errp is always ignored and warnings are
259b3443f43SGreg Kurz  *        printed instead.
2609f9260a3SDon Slutz  */
261074a86fcSAnthony Liguori typedef struct GlobalProperty {
262074a86fcSAnthony Liguori     const char *driver;
263074a86fcSAnthony Liguori     const char *property;
264074a86fcSAnthony Liguori     const char *value;
265b3ce84feSEduardo Habkost     bool user_provided;
266b3ce84feSEduardo Habkost     bool used;
26777280adbSEduardo Habkost     Error **errp;
268074a86fcSAnthony Liguori } GlobalProperty;
269074a86fcSAnthony Liguori 
270074a86fcSAnthony Liguori /*** Board API.  This should go away once we have a machine config file.  ***/
271074a86fcSAnthony Liguori 
272074a86fcSAnthony Liguori DeviceState *qdev_create(BusState *bus, const char *name);
273074a86fcSAnthony Liguori DeviceState *qdev_try_create(BusState *bus, const char *name);
274074a86fcSAnthony Liguori void qdev_init_nofail(DeviceState *dev);
275074a86fcSAnthony Liguori void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
276074a86fcSAnthony Liguori                                  int required_for_version);
27703fcbd9dSThomas Huth HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev);
278c06b2ffbSZhu Guihua HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev);
279074a86fcSAnthony Liguori void qdev_unplug(DeviceState *dev, Error **errp);
280014176f9SIgor Mammedov void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,
281014176f9SIgor Mammedov                                   DeviceState *dev, Error **errp);
282074a86fcSAnthony Liguori void qdev_machine_creation_done(void);
283074a86fcSAnthony Liguori bool qdev_machine_modified(void);
284074a86fcSAnthony Liguori 
285074a86fcSAnthony Liguori qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
286a5f54290SPeter Crosthwaite qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n);
287a5f54290SPeter Crosthwaite 
288074a86fcSAnthony Liguori void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
289a5f54290SPeter Crosthwaite void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
290a5f54290SPeter Crosthwaite                                  qemu_irq pin);
291b7973186SAlexander Graf qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n);
2920c24db2bSPeter Crosthwaite qemu_irq qdev_intercept_gpio_out(DeviceState *dev, qemu_irq icpt,
2930c24db2bSPeter Crosthwaite                                  const char *name, int n);
294074a86fcSAnthony Liguori 
295074a86fcSAnthony Liguori BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
296074a86fcSAnthony Liguori 
297074a86fcSAnthony Liguori /*** Device API.  ***/
298074a86fcSAnthony Liguori 
299074a86fcSAnthony Liguori /* Register device properties.  */
300074a86fcSAnthony Liguori /* GPIO inputs also double as IRQ sinks.  */
301074a86fcSAnthony Liguori void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
302074a86fcSAnthony Liguori void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
303a5f54290SPeter Crosthwaite void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins,
304a5f54290SPeter Crosthwaite                               const char *name, int n);
3054a151677SPeter Maydell /**
3064a151677SPeter Maydell  * qdev_init_gpio_in_named_with_opaque: create an array of input GPIO lines
3074a151677SPeter Maydell  *   for the specified device
3084a151677SPeter Maydell  *
3094a151677SPeter Maydell  * @dev: Device to create input GPIOs for
3104a151677SPeter Maydell  * @handler: Function to call when GPIO line value is set
3114a151677SPeter Maydell  * @opaque: Opaque data pointer to pass to @handler
3124a151677SPeter Maydell  * @name: Name of the GPIO input (must be unique for this device)
3134a151677SPeter Maydell  * @n: Number of GPIO lines in this input set
3144a151677SPeter Maydell  */
3154a151677SPeter Maydell void qdev_init_gpio_in_named_with_opaque(DeviceState *dev,
3164a151677SPeter Maydell                                          qemu_irq_handler handler,
3174a151677SPeter Maydell                                          void *opaque,
3184a151677SPeter Maydell                                          const char *name, int n);
3194a151677SPeter Maydell 
3204a151677SPeter Maydell /**
3214a151677SPeter Maydell  * qdev_init_gpio_in_named: create an array of input GPIO lines
3224a151677SPeter Maydell  *   for the specified device
3234a151677SPeter Maydell  *
3244a151677SPeter Maydell  * Like qdev_init_gpio_in_named_with_opaque(), but the opaque pointer
3254a151677SPeter Maydell  * passed to the handler is @dev (which is the most commonly desired behaviour).
3264a151677SPeter Maydell  */
3274a151677SPeter Maydell static inline void qdev_init_gpio_in_named(DeviceState *dev,
3284a151677SPeter Maydell                                            qemu_irq_handler handler,
3294a151677SPeter Maydell                                            const char *name, int n)
3304a151677SPeter Maydell {
3314a151677SPeter Maydell     qdev_init_gpio_in_named_with_opaque(dev, handler, dev, name, n);
3324a151677SPeter Maydell }
333074a86fcSAnthony Liguori 
33417a96a14SPeter Crosthwaite void qdev_pass_gpios(DeviceState *dev, DeviceState *container,
33517a96a14SPeter Crosthwaite                      const char *name);
33617a96a14SPeter Crosthwaite 
337074a86fcSAnthony Liguori BusState *qdev_get_parent_bus(DeviceState *dev);
338074a86fcSAnthony Liguori 
339074a86fcSAnthony Liguori /*** BUS API. ***/
340074a86fcSAnthony Liguori 
341074a86fcSAnthony Liguori DeviceState *qdev_find_recursive(BusState *bus, const char *id);
342074a86fcSAnthony Liguori 
343074a86fcSAnthony Liguori /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
344074a86fcSAnthony Liguori typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
345074a86fcSAnthony Liguori typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
346074a86fcSAnthony Liguori 
347fb17dfe0SAndreas Färber void qbus_create_inplace(void *bus, size_t size, const char *typename,
348074a86fcSAnthony Liguori                          DeviceState *parent, const char *name);
349074a86fcSAnthony Liguori BusState *qbus_create(const char *typename, DeviceState *parent, const char *name);
350074a86fcSAnthony Liguori /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion,
351074a86fcSAnthony Liguori  *         < 0 if either devfn or busfn terminate walk somewhere in cursion,
352074a86fcSAnthony Liguori  *           0 otherwise. */
3530293214bSPaolo Bonzini int qbus_walk_children(BusState *bus,
3540293214bSPaolo Bonzini                        qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn,
3550293214bSPaolo Bonzini                        qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn,
3560293214bSPaolo Bonzini                        void *opaque);
3570293214bSPaolo Bonzini int qdev_walk_children(DeviceState *dev,
3580293214bSPaolo Bonzini                        qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn,
3590293214bSPaolo Bonzini                        qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn,
3600293214bSPaolo Bonzini                        void *opaque);
3610293214bSPaolo Bonzini 
362074a86fcSAnthony Liguori void qdev_reset_all(DeviceState *dev);
363ff8de075SDavid Hildenbrand void qdev_reset_all_fn(void *opaque);
364d0508c36SPaolo Bonzini 
365d0508c36SPaolo Bonzini /**
366d0508c36SPaolo Bonzini  * @qbus_reset_all:
367d0508c36SPaolo Bonzini  * @bus: Bus to be reset.
368d0508c36SPaolo Bonzini  *
369d0508c36SPaolo Bonzini  * Reset @bus and perform a bus-level ("hard") reset of all devices connected
370d0508c36SPaolo Bonzini  * to it, including recursive processing of all buses below @bus itself.  A
371d0508c36SPaolo Bonzini  * hard reset means that qbus_reset_all will reset all state of the device.
372d0508c36SPaolo Bonzini  * For PCI devices, for example, this will include the base address registers
373d0508c36SPaolo Bonzini  * or configuration space.
374d0508c36SPaolo Bonzini  */
375d0508c36SPaolo Bonzini void qbus_reset_all(BusState *bus);
376074a86fcSAnthony Liguori void qbus_reset_all_fn(void *opaque);
377074a86fcSAnthony Liguori 
378074a86fcSAnthony Liguori /* This should go away once we get rid of the NULL bus hack */
379074a86fcSAnthony Liguori BusState *sysbus_get_default(void);
380074a86fcSAnthony Liguori 
381074a86fcSAnthony Liguori char *qdev_get_fw_dev_path(DeviceState *dev);
3820be63901SGonglei char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev);
383074a86fcSAnthony Liguori 
384074a86fcSAnthony Liguori /**
385074a86fcSAnthony Liguori  * @qdev_machine_init
386074a86fcSAnthony Liguori  *
387074a86fcSAnthony Liguori  * Initialize platform devices before machine init.  This is a hack until full
388074a86fcSAnthony Liguori  * support for composition is added.
389074a86fcSAnthony Liguori  */
390074a86fcSAnthony Liguori void qdev_machine_init(void);
391074a86fcSAnthony Liguori 
392074a86fcSAnthony Liguori /**
393074a86fcSAnthony Liguori  * @device_reset
394074a86fcSAnthony Liguori  *
395074a86fcSAnthony Liguori  * Reset a single device (by calling the reset method).
396074a86fcSAnthony Liguori  */
397074a86fcSAnthony Liguori void device_reset(DeviceState *dev);
398074a86fcSAnthony Liguori 
39946795cf2SPhilippe Mathieu-Daudé void device_class_set_parent_reset(DeviceClass *dc,
40046795cf2SPhilippe Mathieu-Daudé                                    DeviceReset dev_reset,
40146795cf2SPhilippe Mathieu-Daudé                                    DeviceReset *parent_reset);
40246795cf2SPhilippe Mathieu-Daudé void device_class_set_parent_realize(DeviceClass *dc,
40346795cf2SPhilippe Mathieu-Daudé                                      DeviceRealize dev_realize,
40446795cf2SPhilippe Mathieu-Daudé                                      DeviceRealize *parent_realize);
40546795cf2SPhilippe Mathieu-Daudé void device_class_set_parent_unrealize(DeviceClass *dc,
40646795cf2SPhilippe Mathieu-Daudé                                        DeviceUnrealize dev_unrealize,
40746795cf2SPhilippe Mathieu-Daudé                                        DeviceUnrealize *parent_unrealize);
40846795cf2SPhilippe Mathieu-Daudé 
409074a86fcSAnthony Liguori const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev);
410074a86fcSAnthony Liguori 
411074a86fcSAnthony Liguori const char *qdev_fw_name(DeviceState *dev);
412074a86fcSAnthony Liguori 
413074a86fcSAnthony Liguori Object *qdev_get_machine(void);
414074a86fcSAnthony Liguori 
415074a86fcSAnthony Liguori /* FIXME: make this a link<> */
416074a86fcSAnthony Liguori void qdev_set_parent_bus(DeviceState *dev, BusState *bus);
417074a86fcSAnthony Liguori 
4189bed84c1SJuan Quintela extern bool qdev_hotplug;
41921def24aSJuan Quintela extern bool qdev_hot_removed;
420074a86fcSAnthony Liguori 
421074a86fcSAnthony Liguori char *qdev_get_dev_path(DeviceState *dev);
422074a86fcSAnthony Liguori 
4234cae4d5aSMarcel Apfelbaum GSList *qdev_build_hotpluggable_device_list(Object *peripheral);
42466e56b13SZhu Guihua 
425431bbb26SIgor Mammedov void qbus_set_hotplug_handler(BusState *bus, DeviceState *handler,
426431bbb26SIgor Mammedov                               Error **errp);
427431bbb26SIgor Mammedov 
428431bbb26SIgor Mammedov void qbus_set_bus_hotplug_handler(BusState *bus, Error **errp);
42939b888bdSIgor Mammedov 
43039b888bdSIgor Mammedov static inline bool qbus_is_hotpluggable(BusState *bus)
43139b888bdSIgor Mammedov {
4322d9a982fSIgor Mammedov    return bus->hotplug_handler;
43339b888bdSIgor Mammedov }
434707ff800SPaul Durrant 
435707ff800SPaul Durrant void device_listener_register(DeviceListener *listener);
436707ff800SPaul Durrant void device_listener_unregister(DeviceListener *listener);
437707ff800SPaul Durrant 
438074a86fcSAnthony Liguori #endif
439