1074a86fcSAnthony Liguori #ifndef QDEV_CORE_H 2074a86fcSAnthony Liguori #define QDEV_CORE_H 3074a86fcSAnthony Liguori 41de7afc9SPaolo Bonzini #include "qemu/queue.h" 51de7afc9SPaolo Bonzini #include "qemu/option.h" 6949fc823SMarcel Apfelbaum #include "qemu/bitmap.h" 714cccb61SPaolo Bonzini #include "qom/object.h" 8074a86fcSAnthony Liguori #include "hw/irq.h" 90ee4de6cSIgor Mammedov #include "hw/hotplug.h" 10074a86fcSAnthony Liguori 11074a86fcSAnthony Liguori enum { 12074a86fcSAnthony Liguori DEV_NVECTORS_UNSPECIFIED = -1, 13074a86fcSAnthony Liguori }; 14074a86fcSAnthony Liguori 15074a86fcSAnthony Liguori #define TYPE_DEVICE "device" 16074a86fcSAnthony Liguori #define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE) 17074a86fcSAnthony Liguori #define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE) 18074a86fcSAnthony Liguori #define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE) 19074a86fcSAnthony Liguori 203d1237fbSMarcel Apfelbaum typedef enum DeviceCategory { 213d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_BRIDGE, 223d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_USB, 233d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_STORAGE, 243d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_NETWORK, 253d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_INPUT, 263d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_DISPLAY, 273d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_SOUND, 283d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_MISC, 29ba31cc72SThomas Huth DEVICE_CATEGORY_CPU, 303d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_MAX 313d1237fbSMarcel Apfelbaum } DeviceCategory; 323d1237fbSMarcel Apfelbaum 33074a86fcSAnthony Liguori typedef int (*qdev_initfn)(DeviceState *dev); 34074a86fcSAnthony Liguori typedef int (*qdev_event)(DeviceState *dev); 35249d4172SAndreas Färber typedef void (*DeviceRealize)(DeviceState *dev, Error **errp); 36249d4172SAndreas Färber typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp); 37b850f664SPhilippe Mathieu-Daudé typedef void (*DeviceReset)(DeviceState *dev); 3802e7f85dSBandan Das typedef void (*BusRealize)(BusState *bus, Error **errp); 3902e7f85dSBandan Das typedef void (*BusUnrealize)(BusState *bus, Error **errp); 40074a86fcSAnthony Liguori 41074a86fcSAnthony Liguori struct VMStateDescription; 42074a86fcSAnthony Liguori 43249d4172SAndreas Färber /** 44249d4172SAndreas Färber * DeviceClass: 45249d4172SAndreas Färber * @props: Properties accessing state fields. 46249d4172SAndreas Färber * @realize: Callback function invoked when the #DeviceState:realized 47249d4172SAndreas Färber * property is changed to %true. The default invokes @init if not %NULL. 48249d4172SAndreas Färber * @unrealize: Callback function invoked when the #DeviceState:realized 49249d4172SAndreas Färber * property is changed to %false. 50249d4172SAndreas Färber * @init: Callback function invoked when the #DeviceState::realized property 51249d4172SAndreas Färber * is changed to %true. Deprecated, new types inheriting directly from 52249d4172SAndreas Färber * TYPE_DEVICE should use @realize instead, new leaf types should consult 53249d4172SAndreas Färber * their respective parent type. 541a37eca1SIgor Mammedov * @hotpluggable: indicates if #DeviceClass is hotpluggable, available 551a37eca1SIgor Mammedov * as readonly "hotpluggable" property of #DeviceState instance 56249d4172SAndreas Färber * 57249d4172SAndreas Färber * # Realization # 58249d4172SAndreas Färber * Devices are constructed in two stages, 59249d4172SAndreas Färber * 1) object instantiation via object_initialize() and 60249d4172SAndreas Färber * 2) device realization via #DeviceState:realized property. 61249d4172SAndreas Färber * The former may not fail (it might assert or exit), the latter may return 62249d4172SAndreas Färber * error information to the caller and must be re-entrant. 63249d4172SAndreas Färber * Trivial field initializations should go into #TypeInfo.instance_init. 64249d4172SAndreas Färber * Operations depending on @props static properties should go into @realize. 65249d4172SAndreas Färber * After successful realization, setting static properties will fail. 66249d4172SAndreas Färber * 67daeba969SMarkus Armbruster * As an interim step, the #DeviceState:realized property can also be 68daeba969SMarkus Armbruster * set with qdev_init_nofail(). 69249d4172SAndreas Färber * In the future, devices will propagate this state change to their children 70249d4172SAndreas Färber * and along busses they expose. 71249d4172SAndreas Färber * The point in time will be deferred to machine creation, so that values 72249d4172SAndreas Färber * set in @realize will not be introspectable beforehand. Therefore devices 73249d4172SAndreas Färber * must not create children during @realize; they should initialize them via 74249d4172SAndreas Färber * object_initialize() in their own #TypeInfo.instance_init and forward the 75249d4172SAndreas Färber * realization events appropriately. 76249d4172SAndreas Färber * 77249d4172SAndreas Färber * The @init callback is considered private to a particular bus implementation 78249d4172SAndreas Färber * (immediate abstract child types of TYPE_DEVICE). Derived leaf types set an 79249d4172SAndreas Färber * "init" callback on their parent class instead. 80782beb52SAndreas Färber * 81249d4172SAndreas Färber * Any type may override the @realize and/or @unrealize callbacks but needs 82782beb52SAndreas Färber * to call the parent type's implementation if keeping their functionality 83782beb52SAndreas Färber * is desired. Refer to QOM documentation for further discussion and examples. 84782beb52SAndreas Färber * 85782beb52SAndreas Färber * <note> 86782beb52SAndreas Färber * <para> 87249d4172SAndreas Färber * If a type derived directly from TYPE_DEVICE implements @realize, it does 88249d4172SAndreas Färber * not need to implement @init and therefore does not need to store and call 89249d4172SAndreas Färber * #DeviceClass' default @realize callback. 90782beb52SAndreas Färber * For other types consult the documentation and implementation of the 91782beb52SAndreas Färber * respective parent types. 92782beb52SAndreas Färber * </para> 93782beb52SAndreas Färber * </note> 94249d4172SAndreas Färber */ 95074a86fcSAnthony Liguori typedef struct DeviceClass { 96249d4172SAndreas Färber /*< private >*/ 97074a86fcSAnthony Liguori ObjectClass parent_class; 98249d4172SAndreas Färber /*< public >*/ 99074a86fcSAnthony Liguori 1003d1237fbSMarcel Apfelbaum DECLARE_BITMAP(categories, DEVICE_CATEGORY_MAX); 101074a86fcSAnthony Liguori const char *fw_name; 102074a86fcSAnthony Liguori const char *desc; 103074a86fcSAnthony Liguori Property *props; 104efec3dd6SMarkus Armbruster 105efec3dd6SMarkus Armbruster /* 106e90f2a8cSEduardo Habkost * Can this device be instantiated with -device / device_add? 107efec3dd6SMarkus Armbruster * All devices should support instantiation with device_add, and 108efec3dd6SMarkus Armbruster * this flag should not exist. But we're not there, yet. Some 109efec3dd6SMarkus Armbruster * devices fail to instantiate with cryptic error messages. 110efec3dd6SMarkus Armbruster * Others instantiate, but don't work. Exposing users to such 111e90f2a8cSEduardo Habkost * behavior would be cruel; clearing this flag will protect them. 112e90f2a8cSEduardo Habkost * It should never be cleared without a comment explaining why it 113e90f2a8cSEduardo Habkost * is cleared. 114efec3dd6SMarkus Armbruster * TODO remove once we're there 115efec3dd6SMarkus Armbruster */ 116e90f2a8cSEduardo Habkost bool user_creatable; 1171a37eca1SIgor Mammedov bool hotpluggable; 118074a86fcSAnthony Liguori 119074a86fcSAnthony Liguori /* callbacks */ 120b850f664SPhilippe Mathieu-Daudé DeviceReset reset; 121249d4172SAndreas Färber DeviceRealize realize; 122249d4172SAndreas Färber DeviceUnrealize unrealize; 123074a86fcSAnthony Liguori 124074a86fcSAnthony Liguori /* device state */ 125074a86fcSAnthony Liguori const struct VMStateDescription *vmsd; 126074a86fcSAnthony Liguori 127074a86fcSAnthony Liguori /* Private to qdev / bus. */ 128249d4172SAndreas Färber qdev_initfn init; /* TODO remove, once users are converted to realize */ 129fe6c2117SAndreas Färber qdev_event exit; /* TODO remove, once users are converted to unrealize */ 130074a86fcSAnthony Liguori const char *bus_type; 131074a86fcSAnthony Liguori } DeviceClass; 132074a86fcSAnthony Liguori 133a5f54290SPeter Crosthwaite typedef struct NamedGPIOList NamedGPIOList; 134a5f54290SPeter Crosthwaite 135a5f54290SPeter Crosthwaite struct NamedGPIOList { 136a5f54290SPeter Crosthwaite char *name; 137a5f54290SPeter Crosthwaite qemu_irq *in; 138a5f54290SPeter Crosthwaite int num_in; 139a5f54290SPeter Crosthwaite int num_out; 140a5f54290SPeter Crosthwaite QLIST_ENTRY(NamedGPIOList) node; 141a5f54290SPeter Crosthwaite }; 142a5f54290SPeter Crosthwaite 1437983c8a3SAndreas Färber /** 1447983c8a3SAndreas Färber * DeviceState: 1457983c8a3SAndreas Färber * @realized: Indicates whether the device has been fully constructed. 1467983c8a3SAndreas Färber * 1477983c8a3SAndreas Färber * This structure should not be accessed directly. We declare it here 1487983c8a3SAndreas Färber * so that it can be embedded in individual device state structures. 1497983c8a3SAndreas Färber */ 150074a86fcSAnthony Liguori struct DeviceState { 1517983c8a3SAndreas Färber /*< private >*/ 152074a86fcSAnthony Liguori Object parent_obj; 1537983c8a3SAndreas Färber /*< public >*/ 154074a86fcSAnthony Liguori 155074a86fcSAnthony Liguori const char *id; 15604162f8fSMichael Roth char *canonical_path; 1577983c8a3SAndreas Färber bool realized; 158352e8da7SPaolo Bonzini bool pending_deleted_event; 159074a86fcSAnthony Liguori QemuOpts *opts; 160074a86fcSAnthony Liguori int hotplugged; 161074a86fcSAnthony Liguori BusState *parent_bus; 162a5f54290SPeter Crosthwaite QLIST_HEAD(, NamedGPIOList) gpios; 163074a86fcSAnthony Liguori QLIST_HEAD(, BusState) child_bus; 164074a86fcSAnthony Liguori int num_child_bus; 165074a86fcSAnthony Liguori int instance_id_alias; 166074a86fcSAnthony Liguori int alias_required_for_version; 167074a86fcSAnthony Liguori }; 168074a86fcSAnthony Liguori 169707ff800SPaul Durrant struct DeviceListener { 170707ff800SPaul Durrant void (*realize)(DeviceListener *listener, DeviceState *dev); 171707ff800SPaul Durrant void (*unrealize)(DeviceListener *listener, DeviceState *dev); 172707ff800SPaul Durrant QTAILQ_ENTRY(DeviceListener) link; 173707ff800SPaul Durrant }; 174707ff800SPaul Durrant 175074a86fcSAnthony Liguori #define TYPE_BUS "bus" 176074a86fcSAnthony Liguori #define BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS) 177074a86fcSAnthony Liguori #define BUS_CLASS(klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS) 178074a86fcSAnthony Liguori #define BUS_GET_CLASS(obj) OBJECT_GET_CLASS(BusClass, (obj), TYPE_BUS) 179074a86fcSAnthony Liguori 180074a86fcSAnthony Liguori struct BusClass { 181074a86fcSAnthony Liguori ObjectClass parent_class; 182074a86fcSAnthony Liguori 183074a86fcSAnthony Liguori /* FIXME first arg should be BusState */ 184074a86fcSAnthony Liguori void (*print_dev)(Monitor *mon, DeviceState *dev, int indent); 185074a86fcSAnthony Liguori char *(*get_dev_path)(DeviceState *dev); 186074a86fcSAnthony Liguori /* 187074a86fcSAnthony Liguori * This callback is used to create Open Firmware device path in accordance 188074a86fcSAnthony Liguori * with OF spec http://forthworks.com/standards/of1275.pdf. Individual bus 189074a86fcSAnthony Liguori * bindings can be found at http://playground.sun.com/1275/bindings/. 190074a86fcSAnthony Liguori */ 191074a86fcSAnthony Liguori char *(*get_fw_dev_path)(DeviceState *dev); 192dcc20931SPaolo Bonzini void (*reset)(BusState *bus); 19302e7f85dSBandan Das BusRealize realize; 19402e7f85dSBandan Das BusUnrealize unrealize; 19502e7f85dSBandan Das 1961395af6fSKONRAD Frederic /* maximum devices allowed on the bus, 0: no limit. */ 1971395af6fSKONRAD Frederic int max_dev; 19861de3676SAlexander Graf /* number of automatically allocated bus ids (e.g. ide.0) */ 19961de3676SAlexander Graf int automatic_ids; 200074a86fcSAnthony Liguori }; 201074a86fcSAnthony Liguori 202074a86fcSAnthony Liguori typedef struct BusChild { 203074a86fcSAnthony Liguori DeviceState *child; 204074a86fcSAnthony Liguori int index; 205074a86fcSAnthony Liguori QTAILQ_ENTRY(BusChild) sibling; 206074a86fcSAnthony Liguori } BusChild; 207074a86fcSAnthony Liguori 2080ee4de6cSIgor Mammedov #define QDEV_HOTPLUG_HANDLER_PROPERTY "hotplug-handler" 2090ee4de6cSIgor Mammedov 210074a86fcSAnthony Liguori /** 211074a86fcSAnthony Liguori * BusState: 2120ee4de6cSIgor Mammedov * @hotplug_device: link to a hotplug device associated with bus. 213074a86fcSAnthony Liguori */ 214074a86fcSAnthony Liguori struct BusState { 215074a86fcSAnthony Liguori Object obj; 216074a86fcSAnthony Liguori DeviceState *parent; 217f73480c3SMarc-André Lureau char *name; 2180ee4de6cSIgor Mammedov HotplugHandler *hotplug_handler; 219074a86fcSAnthony Liguori int max_index; 22002e7f85dSBandan Das bool realized; 221074a86fcSAnthony Liguori QTAILQ_HEAD(ChildrenHead, BusChild) children; 222074a86fcSAnthony Liguori QLIST_ENTRY(BusState) sibling; 223074a86fcSAnthony Liguori }; 224074a86fcSAnthony Liguori 2255cc56cc6SPeter Maydell /** 2265cc56cc6SPeter Maydell * Property: 2275cc56cc6SPeter Maydell * @set_default: true if the default value should be set from @defval, 2285cc56cc6SPeter Maydell * in which case @info->set_default_value must not be NULL 2295cc56cc6SPeter Maydell * (if false then no default value is set by the property system 2305cc56cc6SPeter Maydell * and the field retains whatever value it was given by instance_init). 2315cc56cc6SPeter Maydell * @defval: default value for the property. This is used only if @set_default 2325cc56cc6SPeter Maydell * is true. 2335cc56cc6SPeter Maydell */ 234074a86fcSAnthony Liguori struct Property { 235074a86fcSAnthony Liguori const char *name; 2361b6b7d10SFam Zheng const PropertyInfo *info; 2373b6ca402SIldar Isaev ptrdiff_t offset; 238074a86fcSAnthony Liguori uint8_t bitnr; 2395cc56cc6SPeter Maydell bool set_default; 24076318657SMarc-André Lureau union { 24176318657SMarc-André Lureau int64_t i; 2423fb2111fSMarc-André Lureau uint64_t u; 24376318657SMarc-André Lureau } defval; 2440be6bfacSPeter Maydell int arrayoffset; 2451b6b7d10SFam Zheng const PropertyInfo *arrayinfo; 2460be6bfacSPeter Maydell int arrayfieldsize; 2475b4ff3c6SFam Zheng const char *link_type; 248074a86fcSAnthony Liguori }; 249074a86fcSAnthony Liguori 250074a86fcSAnthony Liguori struct PropertyInfo { 251074a86fcSAnthony Liguori const char *name; 25251b2e8c3SGonglei const char *description; 253f7abe0ecSMarc-André Lureau const QEnumLookup *enum_table; 254074a86fcSAnthony Liguori int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); 255a2740ad5SMarc-André Lureau void (*set_default_value)(Object *obj, const Property *prop); 256faabdbb7SFam Zheng void (*create)(Object *obj, Property *prop, Error **errp); 257074a86fcSAnthony Liguori ObjectPropertyAccessor *get; 258074a86fcSAnthony Liguori ObjectPropertyAccessor *set; 259074a86fcSAnthony Liguori ObjectPropertyRelease *release; 260074a86fcSAnthony Liguori }; 261074a86fcSAnthony Liguori 2629f9260a3SDon Slutz /** 2639f9260a3SDon Slutz * GlobalProperty: 264b3ce84feSEduardo Habkost * @user_provided: Set to true if property comes from user-provided config 265b3ce84feSEduardo Habkost * (command-line or config file). 266b3ce84feSEduardo Habkost * @used: Set to true if property was used when initializing a device. 26777280adbSEduardo Habkost * @errp: Error destination, used like first argument of error_setg() 26877280adbSEduardo Habkost * in case property setting fails later. If @errp is NULL, we 269b3443f43SGreg Kurz * print warnings instead of ignoring errors silently. For 270b3443f43SGreg Kurz * hotplugged devices, errp is always ignored and warnings are 271b3443f43SGreg Kurz * printed instead. 2729f9260a3SDon Slutz */ 273074a86fcSAnthony Liguori typedef struct GlobalProperty { 274074a86fcSAnthony Liguori const char *driver; 275074a86fcSAnthony Liguori const char *property; 276074a86fcSAnthony Liguori const char *value; 277b3ce84feSEduardo Habkost bool user_provided; 278b3ce84feSEduardo Habkost bool used; 27977280adbSEduardo Habkost Error **errp; 280074a86fcSAnthony Liguori } GlobalProperty; 281074a86fcSAnthony Liguori 282074a86fcSAnthony Liguori /*** Board API. This should go away once we have a machine config file. ***/ 283074a86fcSAnthony Liguori 284074a86fcSAnthony Liguori DeviceState *qdev_create(BusState *bus, const char *name); 285074a86fcSAnthony Liguori DeviceState *qdev_try_create(BusState *bus, const char *name); 286074a86fcSAnthony Liguori void qdev_init_nofail(DeviceState *dev); 287074a86fcSAnthony Liguori void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, 288074a86fcSAnthony Liguori int required_for_version); 28903fcbd9dSThomas Huth HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev); 290c06b2ffbSZhu Guihua HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev); 291074a86fcSAnthony Liguori void qdev_unplug(DeviceState *dev, Error **errp); 292014176f9SIgor Mammedov void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, 293014176f9SIgor Mammedov DeviceState *dev, Error **errp); 294074a86fcSAnthony Liguori void qdev_machine_creation_done(void); 295074a86fcSAnthony Liguori bool qdev_machine_modified(void); 296074a86fcSAnthony Liguori 297074a86fcSAnthony Liguori qemu_irq qdev_get_gpio_in(DeviceState *dev, int n); 298a5f54290SPeter Crosthwaite qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n); 299a5f54290SPeter Crosthwaite 300074a86fcSAnthony Liguori void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin); 301a5f54290SPeter Crosthwaite void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n, 302a5f54290SPeter Crosthwaite qemu_irq pin); 303b7973186SAlexander Graf qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n); 3040c24db2bSPeter Crosthwaite qemu_irq qdev_intercept_gpio_out(DeviceState *dev, qemu_irq icpt, 3050c24db2bSPeter Crosthwaite const char *name, int n); 306074a86fcSAnthony Liguori 307074a86fcSAnthony Liguori BusState *qdev_get_child_bus(DeviceState *dev, const char *name); 308074a86fcSAnthony Liguori 309074a86fcSAnthony Liguori /*** Device API. ***/ 310074a86fcSAnthony Liguori 311074a86fcSAnthony Liguori /* Register device properties. */ 312074a86fcSAnthony Liguori /* GPIO inputs also double as IRQ sinks. */ 313074a86fcSAnthony Liguori void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n); 314074a86fcSAnthony Liguori void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n); 315a5f54290SPeter Crosthwaite void qdev_init_gpio_in_named(DeviceState *dev, qemu_irq_handler handler, 316a5f54290SPeter Crosthwaite const char *name, int n); 317a5f54290SPeter Crosthwaite void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins, 318a5f54290SPeter Crosthwaite const char *name, int n); 319074a86fcSAnthony Liguori 32017a96a14SPeter Crosthwaite void qdev_pass_gpios(DeviceState *dev, DeviceState *container, 32117a96a14SPeter Crosthwaite const char *name); 32217a96a14SPeter Crosthwaite 323074a86fcSAnthony Liguori BusState *qdev_get_parent_bus(DeviceState *dev); 324074a86fcSAnthony Liguori 325074a86fcSAnthony Liguori /*** BUS API. ***/ 326074a86fcSAnthony Liguori 327074a86fcSAnthony Liguori DeviceState *qdev_find_recursive(BusState *bus, const char *id); 328074a86fcSAnthony Liguori 329074a86fcSAnthony Liguori /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */ 330074a86fcSAnthony Liguori typedef int (qbus_walkerfn)(BusState *bus, void *opaque); 331074a86fcSAnthony Liguori typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque); 332074a86fcSAnthony Liguori 333fb17dfe0SAndreas Färber void qbus_create_inplace(void *bus, size_t size, const char *typename, 334074a86fcSAnthony Liguori DeviceState *parent, const char *name); 335074a86fcSAnthony Liguori BusState *qbus_create(const char *typename, DeviceState *parent, const char *name); 336074a86fcSAnthony Liguori /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion, 337074a86fcSAnthony Liguori * < 0 if either devfn or busfn terminate walk somewhere in cursion, 338074a86fcSAnthony Liguori * 0 otherwise. */ 3390293214bSPaolo Bonzini int qbus_walk_children(BusState *bus, 3400293214bSPaolo Bonzini qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn, 3410293214bSPaolo Bonzini qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn, 3420293214bSPaolo Bonzini void *opaque); 3430293214bSPaolo Bonzini int qdev_walk_children(DeviceState *dev, 3440293214bSPaolo Bonzini qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn, 3450293214bSPaolo Bonzini qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn, 3460293214bSPaolo Bonzini void *opaque); 3470293214bSPaolo Bonzini 348074a86fcSAnthony Liguori void qdev_reset_all(DeviceState *dev); 349ff8de075SDavid Hildenbrand void qdev_reset_all_fn(void *opaque); 350d0508c36SPaolo Bonzini 351d0508c36SPaolo Bonzini /** 352d0508c36SPaolo Bonzini * @qbus_reset_all: 353d0508c36SPaolo Bonzini * @bus: Bus to be reset. 354d0508c36SPaolo Bonzini * 355d0508c36SPaolo Bonzini * Reset @bus and perform a bus-level ("hard") reset of all devices connected 356d0508c36SPaolo Bonzini * to it, including recursive processing of all buses below @bus itself. A 357d0508c36SPaolo Bonzini * hard reset means that qbus_reset_all will reset all state of the device. 358d0508c36SPaolo Bonzini * For PCI devices, for example, this will include the base address registers 359d0508c36SPaolo Bonzini * or configuration space. 360d0508c36SPaolo Bonzini */ 361d0508c36SPaolo Bonzini void qbus_reset_all(BusState *bus); 362074a86fcSAnthony Liguori void qbus_reset_all_fn(void *opaque); 363074a86fcSAnthony Liguori 364074a86fcSAnthony Liguori /* This should go away once we get rid of the NULL bus hack */ 365074a86fcSAnthony Liguori BusState *sysbus_get_default(void); 366074a86fcSAnthony Liguori 367074a86fcSAnthony Liguori char *qdev_get_fw_dev_path(DeviceState *dev); 3680be63901SGonglei char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev); 369074a86fcSAnthony Liguori 370074a86fcSAnthony Liguori /** 371074a86fcSAnthony Liguori * @qdev_machine_init 372074a86fcSAnthony Liguori * 373074a86fcSAnthony Liguori * Initialize platform devices before machine init. This is a hack until full 374074a86fcSAnthony Liguori * support for composition is added. 375074a86fcSAnthony Liguori */ 376074a86fcSAnthony Liguori void qdev_machine_init(void); 377074a86fcSAnthony Liguori 378074a86fcSAnthony Liguori /** 379074a86fcSAnthony Liguori * @device_reset 380074a86fcSAnthony Liguori * 381074a86fcSAnthony Liguori * Reset a single device (by calling the reset method). 382074a86fcSAnthony Liguori */ 383074a86fcSAnthony Liguori void device_reset(DeviceState *dev); 384074a86fcSAnthony Liguori 385*46795cf2SPhilippe Mathieu-Daudé void device_class_set_parent_reset(DeviceClass *dc, 386*46795cf2SPhilippe Mathieu-Daudé DeviceReset dev_reset, 387*46795cf2SPhilippe Mathieu-Daudé DeviceReset *parent_reset); 388*46795cf2SPhilippe Mathieu-Daudé void device_class_set_parent_realize(DeviceClass *dc, 389*46795cf2SPhilippe Mathieu-Daudé DeviceRealize dev_realize, 390*46795cf2SPhilippe Mathieu-Daudé DeviceRealize *parent_realize); 391*46795cf2SPhilippe Mathieu-Daudé void device_class_set_parent_unrealize(DeviceClass *dc, 392*46795cf2SPhilippe Mathieu-Daudé DeviceUnrealize dev_unrealize, 393*46795cf2SPhilippe Mathieu-Daudé DeviceUnrealize *parent_unrealize); 394*46795cf2SPhilippe Mathieu-Daudé 395074a86fcSAnthony Liguori const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev); 396074a86fcSAnthony Liguori 397074a86fcSAnthony Liguori const char *qdev_fw_name(DeviceState *dev); 398074a86fcSAnthony Liguori 399074a86fcSAnthony Liguori Object *qdev_get_machine(void); 400074a86fcSAnthony Liguori 401074a86fcSAnthony Liguori /* FIXME: make this a link<> */ 402074a86fcSAnthony Liguori void qdev_set_parent_bus(DeviceState *dev, BusState *bus); 403074a86fcSAnthony Liguori 4049bed84c1SJuan Quintela extern bool qdev_hotplug; 40521def24aSJuan Quintela extern bool qdev_hot_removed; 406074a86fcSAnthony Liguori 407074a86fcSAnthony Liguori char *qdev_get_dev_path(DeviceState *dev); 408074a86fcSAnthony Liguori 4094cae4d5aSMarcel Apfelbaum GSList *qdev_build_hotpluggable_device_list(Object *peripheral); 41066e56b13SZhu Guihua 411431bbb26SIgor Mammedov void qbus_set_hotplug_handler(BusState *bus, DeviceState *handler, 412431bbb26SIgor Mammedov Error **errp); 413431bbb26SIgor Mammedov 414431bbb26SIgor Mammedov void qbus_set_bus_hotplug_handler(BusState *bus, Error **errp); 41539b888bdSIgor Mammedov 41639b888bdSIgor Mammedov static inline bool qbus_is_hotpluggable(BusState *bus) 41739b888bdSIgor Mammedov { 4182d9a982fSIgor Mammedov return bus->hotplug_handler; 41939b888bdSIgor Mammedov } 420707ff800SPaul Durrant 421707ff800SPaul Durrant void device_listener_register(DeviceListener *listener); 422707ff800SPaul Durrant void device_listener_unregister(DeviceListener *listener); 423707ff800SPaul Durrant 424074a86fcSAnthony Liguori #endif 425