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: 20027c6ef1bSLi 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; 209*12b2e9f3STony Krowiak int num_children; 210eae3eb3eSPaolo Bonzini QTAILQ_HEAD(, BusChild) children; 211074a86fcSAnthony Liguori QLIST_ENTRY(BusState) sibling; 212074a86fcSAnthony Liguori }; 213074a86fcSAnthony Liguori 2145cc56cc6SPeter Maydell /** 2155cc56cc6SPeter Maydell * Property: 2165cc56cc6SPeter Maydell * @set_default: true if the default value should be set from @defval, 2175cc56cc6SPeter Maydell * in which case @info->set_default_value must not be NULL 2185cc56cc6SPeter Maydell * (if false then no default value is set by the property system 2195cc56cc6SPeter Maydell * and the field retains whatever value it was given by instance_init). 2205cc56cc6SPeter Maydell * @defval: default value for the property. This is used only if @set_default 2215cc56cc6SPeter Maydell * is true. 2225cc56cc6SPeter Maydell */ 223074a86fcSAnthony Liguori struct Property { 224074a86fcSAnthony Liguori const char *name; 2251b6b7d10SFam Zheng const PropertyInfo *info; 2263b6ca402SIldar Isaev ptrdiff_t offset; 227074a86fcSAnthony Liguori uint8_t bitnr; 2285cc56cc6SPeter Maydell bool set_default; 22976318657SMarc-André Lureau union { 23076318657SMarc-André Lureau int64_t i; 2313fb2111fSMarc-André Lureau uint64_t u; 23276318657SMarc-André Lureau } defval; 2330be6bfacSPeter Maydell int arrayoffset; 2341b6b7d10SFam Zheng const PropertyInfo *arrayinfo; 2350be6bfacSPeter Maydell int arrayfieldsize; 2365b4ff3c6SFam Zheng const char *link_type; 237074a86fcSAnthony Liguori }; 238074a86fcSAnthony Liguori 239074a86fcSAnthony Liguori struct PropertyInfo { 240074a86fcSAnthony Liguori const char *name; 24151b2e8c3SGonglei const char *description; 242f7abe0ecSMarc-André Lureau const QEnumLookup *enum_table; 243074a86fcSAnthony Liguori int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); 244a2740ad5SMarc-André Lureau void (*set_default_value)(Object *obj, const Property *prop); 245faabdbb7SFam Zheng void (*create)(Object *obj, Property *prop, Error **errp); 246074a86fcSAnthony Liguori ObjectPropertyAccessor *get; 247074a86fcSAnthony Liguori ObjectPropertyAccessor *set; 248074a86fcSAnthony Liguori ObjectPropertyRelease *release; 249074a86fcSAnthony Liguori }; 250074a86fcSAnthony Liguori 2519f9260a3SDon Slutz /** 2529f9260a3SDon Slutz * GlobalProperty: 253b3ce84feSEduardo Habkost * @used: Set to true if property was used when initializing a device. 254d7741743SEduardo Habkost * @optional: If set to true, GlobalProperty will be skipped without errors 255d7741743SEduardo Habkost * if the property doesn't exist. 256cff8b715SMarc-André Lureau * 257cff8b715SMarc-André Lureau * An error is fatal for non-hotplugged devices, when the global is applied. 2589f9260a3SDon Slutz */ 259074a86fcSAnthony Liguori typedef struct GlobalProperty { 260074a86fcSAnthony Liguori const char *driver; 261074a86fcSAnthony Liguori const char *property; 262074a86fcSAnthony Liguori const char *value; 263b3ce84feSEduardo Habkost bool used; 264d7741743SEduardo Habkost bool optional; 265074a86fcSAnthony Liguori } GlobalProperty; 266074a86fcSAnthony Liguori 267ea9ce893SMarc-André Lureau static inline void 268ea9ce893SMarc-André Lureau compat_props_add(GPtrArray *arr, 269ea9ce893SMarc-André Lureau GlobalProperty props[], size_t nelem) 270ea9ce893SMarc-André Lureau { 271ea9ce893SMarc-André Lureau int i; 272ea9ce893SMarc-André Lureau for (i = 0; i < nelem; i++) { 273ea9ce893SMarc-André Lureau g_ptr_array_add(arr, (void *)&props[i]); 274ea9ce893SMarc-André Lureau } 275ea9ce893SMarc-André Lureau } 276ea9ce893SMarc-André Lureau 277074a86fcSAnthony Liguori /*** Board API. This should go away once we have a machine config file. ***/ 278074a86fcSAnthony Liguori 279074a86fcSAnthony Liguori DeviceState *qdev_create(BusState *bus, const char *name); 280074a86fcSAnthony Liguori DeviceState *qdev_try_create(BusState *bus, const char *name); 281074a86fcSAnthony Liguori void qdev_init_nofail(DeviceState *dev); 282074a86fcSAnthony Liguori void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, 283074a86fcSAnthony Liguori int required_for_version); 28403fcbd9dSThomas Huth HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev); 285c06b2ffbSZhu Guihua HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev); 286074a86fcSAnthony Liguori void qdev_unplug(DeviceState *dev, Error **errp); 287014176f9SIgor Mammedov void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, 288014176f9SIgor Mammedov DeviceState *dev, Error **errp); 289074a86fcSAnthony Liguori void qdev_machine_creation_done(void); 290074a86fcSAnthony Liguori bool qdev_machine_modified(void); 291074a86fcSAnthony Liguori 292074a86fcSAnthony Liguori qemu_irq qdev_get_gpio_in(DeviceState *dev, int n); 293a5f54290SPeter Crosthwaite qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n); 294a5f54290SPeter Crosthwaite 295074a86fcSAnthony Liguori void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin); 296a5f54290SPeter Crosthwaite void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n, 297a5f54290SPeter Crosthwaite qemu_irq pin); 298b7973186SAlexander Graf qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n); 2990c24db2bSPeter Crosthwaite qemu_irq qdev_intercept_gpio_out(DeviceState *dev, qemu_irq icpt, 3000c24db2bSPeter Crosthwaite const char *name, int n); 301074a86fcSAnthony Liguori 302074a86fcSAnthony Liguori BusState *qdev_get_child_bus(DeviceState *dev, const char *name); 303074a86fcSAnthony Liguori 304074a86fcSAnthony Liguori /*** Device API. ***/ 305074a86fcSAnthony Liguori 306074a86fcSAnthony Liguori /* Register device properties. */ 307074a86fcSAnthony Liguori /* GPIO inputs also double as IRQ sinks. */ 308074a86fcSAnthony Liguori void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n); 309074a86fcSAnthony Liguori void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n); 310a5f54290SPeter Crosthwaite void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins, 311a5f54290SPeter Crosthwaite const char *name, int n); 3124a151677SPeter Maydell /** 3134a151677SPeter Maydell * qdev_init_gpio_in_named_with_opaque: create an array of input GPIO lines 3144a151677SPeter Maydell * for the specified device 3154a151677SPeter Maydell * 3164a151677SPeter Maydell * @dev: Device to create input GPIOs for 3174a151677SPeter Maydell * @handler: Function to call when GPIO line value is set 3184a151677SPeter Maydell * @opaque: Opaque data pointer to pass to @handler 3194a151677SPeter Maydell * @name: Name of the GPIO input (must be unique for this device) 3204a151677SPeter Maydell * @n: Number of GPIO lines in this input set 3214a151677SPeter Maydell */ 3224a151677SPeter Maydell void qdev_init_gpio_in_named_with_opaque(DeviceState *dev, 3234a151677SPeter Maydell qemu_irq_handler handler, 3244a151677SPeter Maydell void *opaque, 3254a151677SPeter Maydell const char *name, int n); 3264a151677SPeter Maydell 3274a151677SPeter Maydell /** 3284a151677SPeter Maydell * qdev_init_gpio_in_named: create an array of input GPIO lines 3294a151677SPeter Maydell * for the specified device 3304a151677SPeter Maydell * 3314a151677SPeter Maydell * Like qdev_init_gpio_in_named_with_opaque(), but the opaque pointer 3324a151677SPeter Maydell * passed to the handler is @dev (which is the most commonly desired behaviour). 3334a151677SPeter Maydell */ 3344a151677SPeter Maydell static inline void qdev_init_gpio_in_named(DeviceState *dev, 3354a151677SPeter Maydell qemu_irq_handler handler, 3364a151677SPeter Maydell const char *name, int n) 3374a151677SPeter Maydell { 3384a151677SPeter Maydell qdev_init_gpio_in_named_with_opaque(dev, handler, dev, name, n); 3394a151677SPeter Maydell } 340074a86fcSAnthony Liguori 34117a96a14SPeter Crosthwaite void qdev_pass_gpios(DeviceState *dev, DeviceState *container, 34217a96a14SPeter Crosthwaite const char *name); 34317a96a14SPeter Crosthwaite 344074a86fcSAnthony Liguori BusState *qdev_get_parent_bus(DeviceState *dev); 345074a86fcSAnthony Liguori 346074a86fcSAnthony Liguori /*** BUS API. ***/ 347074a86fcSAnthony Liguori 348074a86fcSAnthony Liguori DeviceState *qdev_find_recursive(BusState *bus, const char *id); 349074a86fcSAnthony Liguori 350074a86fcSAnthony Liguori /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */ 351074a86fcSAnthony Liguori typedef int (qbus_walkerfn)(BusState *bus, void *opaque); 352074a86fcSAnthony Liguori typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque); 353074a86fcSAnthony Liguori 354fb17dfe0SAndreas Färber void qbus_create_inplace(void *bus, size_t size, const char *typename, 355074a86fcSAnthony Liguori DeviceState *parent, const char *name); 356074a86fcSAnthony Liguori BusState *qbus_create(const char *typename, DeviceState *parent, const char *name); 357074a86fcSAnthony Liguori /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion, 358074a86fcSAnthony Liguori * < 0 if either devfn or busfn terminate walk somewhere in cursion, 359074a86fcSAnthony Liguori * 0 otherwise. */ 3600293214bSPaolo Bonzini int qbus_walk_children(BusState *bus, 3610293214bSPaolo Bonzini qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn, 3620293214bSPaolo Bonzini qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn, 3630293214bSPaolo Bonzini void *opaque); 3640293214bSPaolo Bonzini int qdev_walk_children(DeviceState *dev, 3650293214bSPaolo Bonzini qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn, 3660293214bSPaolo Bonzini qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn, 3670293214bSPaolo Bonzini void *opaque); 3680293214bSPaolo Bonzini 369074a86fcSAnthony Liguori void qdev_reset_all(DeviceState *dev); 370ff8de075SDavid Hildenbrand void qdev_reset_all_fn(void *opaque); 371d0508c36SPaolo Bonzini 372d0508c36SPaolo Bonzini /** 373d0508c36SPaolo Bonzini * @qbus_reset_all: 374d0508c36SPaolo Bonzini * @bus: Bus to be reset. 375d0508c36SPaolo Bonzini * 376d0508c36SPaolo Bonzini * Reset @bus and perform a bus-level ("hard") reset of all devices connected 377d0508c36SPaolo Bonzini * to it, including recursive processing of all buses below @bus itself. A 378d0508c36SPaolo Bonzini * hard reset means that qbus_reset_all will reset all state of the device. 379d0508c36SPaolo Bonzini * For PCI devices, for example, this will include the base address registers 380d0508c36SPaolo Bonzini * or configuration space. 381d0508c36SPaolo Bonzini */ 382d0508c36SPaolo Bonzini void qbus_reset_all(BusState *bus); 383074a86fcSAnthony Liguori void qbus_reset_all_fn(void *opaque); 384074a86fcSAnthony Liguori 385074a86fcSAnthony Liguori /* This should go away once we get rid of the NULL bus hack */ 386074a86fcSAnthony Liguori BusState *sysbus_get_default(void); 387074a86fcSAnthony Liguori 388074a86fcSAnthony Liguori char *qdev_get_fw_dev_path(DeviceState *dev); 3890be63901SGonglei char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev); 390074a86fcSAnthony Liguori 391074a86fcSAnthony Liguori /** 392074a86fcSAnthony Liguori * @qdev_machine_init 393074a86fcSAnthony Liguori * 394074a86fcSAnthony Liguori * Initialize platform devices before machine init. This is a hack until full 395074a86fcSAnthony Liguori * support for composition is added. 396074a86fcSAnthony Liguori */ 397074a86fcSAnthony Liguori void qdev_machine_init(void); 398074a86fcSAnthony Liguori 399074a86fcSAnthony Liguori /** 400074a86fcSAnthony Liguori * @device_reset 401074a86fcSAnthony Liguori * 402074a86fcSAnthony Liguori * Reset a single device (by calling the reset method). 403074a86fcSAnthony Liguori */ 404074a86fcSAnthony Liguori void device_reset(DeviceState *dev); 405074a86fcSAnthony Liguori 40646795cf2SPhilippe Mathieu-Daudé void device_class_set_parent_reset(DeviceClass *dc, 40746795cf2SPhilippe Mathieu-Daudé DeviceReset dev_reset, 40846795cf2SPhilippe Mathieu-Daudé DeviceReset *parent_reset); 40946795cf2SPhilippe Mathieu-Daudé void device_class_set_parent_realize(DeviceClass *dc, 41046795cf2SPhilippe Mathieu-Daudé DeviceRealize dev_realize, 41146795cf2SPhilippe Mathieu-Daudé DeviceRealize *parent_realize); 41246795cf2SPhilippe Mathieu-Daudé void device_class_set_parent_unrealize(DeviceClass *dc, 41346795cf2SPhilippe Mathieu-Daudé DeviceUnrealize dev_unrealize, 41446795cf2SPhilippe Mathieu-Daudé DeviceUnrealize *parent_unrealize); 41546795cf2SPhilippe Mathieu-Daudé 416074a86fcSAnthony Liguori const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev); 417074a86fcSAnthony Liguori 418074a86fcSAnthony Liguori const char *qdev_fw_name(DeviceState *dev); 419074a86fcSAnthony Liguori 420074a86fcSAnthony Liguori Object *qdev_get_machine(void); 421074a86fcSAnthony Liguori 4221c3994f6SMarc-André Lureau void object_apply_compat_props(Object *obj); 4231c3994f6SMarc-André Lureau 424074a86fcSAnthony Liguori /* FIXME: make this a link<> */ 425074a86fcSAnthony Liguori void qdev_set_parent_bus(DeviceState *dev, BusState *bus); 426074a86fcSAnthony Liguori 4279bed84c1SJuan Quintela extern bool qdev_hotplug; 42821def24aSJuan Quintela extern bool qdev_hot_removed; 429074a86fcSAnthony Liguori 430074a86fcSAnthony Liguori char *qdev_get_dev_path(DeviceState *dev); 431074a86fcSAnthony Liguori 4324cae4d5aSMarcel Apfelbaum GSList *qdev_build_hotpluggable_device_list(Object *peripheral); 43366e56b13SZhu Guihua 43494d1cc5fSMichael Roth void qbus_set_hotplug_handler(BusState *bus, Object *handler, Error **errp); 435431bbb26SIgor Mammedov 436431bbb26SIgor Mammedov void qbus_set_bus_hotplug_handler(BusState *bus, Error **errp); 43739b888bdSIgor Mammedov 43839b888bdSIgor Mammedov static inline bool qbus_is_hotpluggable(BusState *bus) 43939b888bdSIgor Mammedov { 4402d9a982fSIgor Mammedov return bus->hotplug_handler; 44139b888bdSIgor Mammedov } 442707ff800SPaul Durrant 443707ff800SPaul Durrant void device_listener_register(DeviceListener *listener); 444707ff800SPaul Durrant void device_listener_unregister(DeviceListener *listener); 445707ff800SPaul Durrant 446074a86fcSAnthony Liguori #endif 447