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" 9*e965ffa7SStefan Hajnoczi #include "sysemu/sysemu.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 33249d4172SAndreas Färber typedef void (*DeviceRealize)(DeviceState *dev, Error **errp); 34249d4172SAndreas Färber typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp); 35b850f664SPhilippe Mathieu-Daudé typedef void (*DeviceReset)(DeviceState *dev); 3602e7f85dSBandan Das typedef void (*BusRealize)(BusState *bus, Error **errp); 3702e7f85dSBandan Das typedef void (*BusUnrealize)(BusState *bus, Error **errp); 38074a86fcSAnthony Liguori 39074a86fcSAnthony Liguori struct VMStateDescription; 40074a86fcSAnthony Liguori 41249d4172SAndreas Färber /** 42249d4172SAndreas Färber * DeviceClass: 43249d4172SAndreas Färber * @props: Properties accessing state fields. 44249d4172SAndreas Färber * @realize: Callback function invoked when the #DeviceState:realized 45ff46d9d4SPhilippe Mathieu-Daudé * property is changed to %true. 46249d4172SAndreas Färber * @unrealize: Callback function invoked when the #DeviceState:realized 47249d4172SAndreas Färber * property is changed to %false. 481a37eca1SIgor Mammedov * @hotpluggable: indicates if #DeviceClass is hotpluggable, available 491a37eca1SIgor Mammedov * as readonly "hotpluggable" property of #DeviceState instance 50249d4172SAndreas Färber * 51249d4172SAndreas Färber * # Realization # 52249d4172SAndreas Färber * Devices are constructed in two stages, 53249d4172SAndreas Färber * 1) object instantiation via object_initialize() and 54249d4172SAndreas Färber * 2) device realization via #DeviceState:realized property. 556038f989SThomas Huth * The former may not fail (and must not abort or exit, since it is called 566038f989SThomas Huth * during device introspection already), and the latter may return error 576038f989SThomas Huth * information to the caller and must be re-entrant. 58249d4172SAndreas Färber * Trivial field initializations should go into #TypeInfo.instance_init. 59249d4172SAndreas Färber * Operations depending on @props static properties should go into @realize. 60249d4172SAndreas Färber * After successful realization, setting static properties will fail. 61249d4172SAndreas Färber * 62daeba969SMarkus Armbruster * As an interim step, the #DeviceState:realized property can also be 63daeba969SMarkus Armbruster * set with qdev_init_nofail(). 64249d4172SAndreas Färber * In the future, devices will propagate this state change to their children 65249d4172SAndreas Färber * and along busses they expose. 66249d4172SAndreas Färber * The point in time will be deferred to machine creation, so that values 67249d4172SAndreas Färber * set in @realize will not be introspectable beforehand. Therefore devices 68249d4172SAndreas Färber * must not create children during @realize; they should initialize them via 69249d4172SAndreas Färber * object_initialize() in their own #TypeInfo.instance_init and forward the 70249d4172SAndreas Färber * realization events appropriately. 71249d4172SAndreas Färber * 72249d4172SAndreas Färber * Any type may override the @realize and/or @unrealize callbacks but needs 73782beb52SAndreas Färber * to call the parent type's implementation if keeping their functionality 74782beb52SAndreas Färber * is desired. Refer to QOM documentation for further discussion and examples. 75782beb52SAndreas Färber * 76782beb52SAndreas Färber * <note> 77782beb52SAndreas Färber * <para> 78ff46d9d4SPhilippe Mathieu-Daudé * Since TYPE_DEVICE doesn't implement @realize and @unrealize, types 79ff46d9d4SPhilippe Mathieu-Daudé * derived directly from it need not call their parent's @realize and 80ff46d9d4SPhilippe Mathieu-Daudé * @unrealize. 81782beb52SAndreas Färber * For other types consult the documentation and implementation of the 82782beb52SAndreas Färber * respective parent types. 83782beb52SAndreas Färber * </para> 84782beb52SAndreas Färber * </note> 85249d4172SAndreas Färber */ 86074a86fcSAnthony Liguori typedef struct DeviceClass { 87249d4172SAndreas Färber /*< private >*/ 88074a86fcSAnthony Liguori ObjectClass parent_class; 89249d4172SAndreas Färber /*< public >*/ 90074a86fcSAnthony Liguori 913d1237fbSMarcel Apfelbaum DECLARE_BITMAP(categories, DEVICE_CATEGORY_MAX); 92074a86fcSAnthony Liguori const char *fw_name; 93074a86fcSAnthony Liguori const char *desc; 94074a86fcSAnthony Liguori Property *props; 95efec3dd6SMarkus Armbruster 96efec3dd6SMarkus Armbruster /* 97e90f2a8cSEduardo Habkost * Can this device be instantiated with -device / device_add? 98efec3dd6SMarkus Armbruster * All devices should support instantiation with device_add, and 99efec3dd6SMarkus Armbruster * this flag should not exist. But we're not there, yet. Some 100efec3dd6SMarkus Armbruster * devices fail to instantiate with cryptic error messages. 101efec3dd6SMarkus Armbruster * Others instantiate, but don't work. Exposing users to such 102e90f2a8cSEduardo Habkost * behavior would be cruel; clearing this flag will protect them. 103e90f2a8cSEduardo Habkost * It should never be cleared without a comment explaining why it 104e90f2a8cSEduardo Habkost * is cleared. 105efec3dd6SMarkus Armbruster * TODO remove once we're there 106efec3dd6SMarkus Armbruster */ 107e90f2a8cSEduardo Habkost bool user_creatable; 1081a37eca1SIgor Mammedov bool hotpluggable; 109074a86fcSAnthony Liguori 110074a86fcSAnthony Liguori /* callbacks */ 111b850f664SPhilippe Mathieu-Daudé DeviceReset reset; 112249d4172SAndreas Färber DeviceRealize realize; 113249d4172SAndreas Färber DeviceUnrealize unrealize; 114074a86fcSAnthony Liguori 115074a86fcSAnthony Liguori /* device state */ 116074a86fcSAnthony Liguori const struct VMStateDescription *vmsd; 117074a86fcSAnthony Liguori 118074a86fcSAnthony Liguori /* Private to qdev / bus. */ 119074a86fcSAnthony Liguori const char *bus_type; 120074a86fcSAnthony Liguori } DeviceClass; 121074a86fcSAnthony Liguori 122a5f54290SPeter Crosthwaite typedef struct NamedGPIOList NamedGPIOList; 123a5f54290SPeter Crosthwaite 124a5f54290SPeter Crosthwaite struct NamedGPIOList { 125a5f54290SPeter Crosthwaite char *name; 126a5f54290SPeter Crosthwaite qemu_irq *in; 127a5f54290SPeter Crosthwaite int num_in; 128a5f54290SPeter Crosthwaite int num_out; 129a5f54290SPeter Crosthwaite QLIST_ENTRY(NamedGPIOList) node; 130a5f54290SPeter Crosthwaite }; 131a5f54290SPeter Crosthwaite 1327983c8a3SAndreas Färber /** 1337983c8a3SAndreas Färber * DeviceState: 1347983c8a3SAndreas Färber * @realized: Indicates whether the device has been fully constructed. 1357983c8a3SAndreas Färber * 1367983c8a3SAndreas Färber * This structure should not be accessed directly. We declare it here 1377983c8a3SAndreas Färber * so that it can be embedded in individual device state structures. 1387983c8a3SAndreas Färber */ 139074a86fcSAnthony Liguori struct DeviceState { 1407983c8a3SAndreas Färber /*< private >*/ 141074a86fcSAnthony Liguori Object parent_obj; 1427983c8a3SAndreas Färber /*< public >*/ 143074a86fcSAnthony Liguori 144074a86fcSAnthony Liguori const char *id; 14504162f8fSMichael Roth char *canonical_path; 1467983c8a3SAndreas Färber bool realized; 147352e8da7SPaolo Bonzini bool pending_deleted_event; 148074a86fcSAnthony Liguori QemuOpts *opts; 149074a86fcSAnthony Liguori int hotplugged; 150074a86fcSAnthony Liguori BusState *parent_bus; 151a5f54290SPeter Crosthwaite QLIST_HEAD(, NamedGPIOList) gpios; 152074a86fcSAnthony Liguori QLIST_HEAD(, BusState) child_bus; 153074a86fcSAnthony Liguori int num_child_bus; 154074a86fcSAnthony Liguori int instance_id_alias; 155074a86fcSAnthony Liguori int alias_required_for_version; 156074a86fcSAnthony Liguori }; 157074a86fcSAnthony Liguori 158707ff800SPaul Durrant struct DeviceListener { 159707ff800SPaul Durrant void (*realize)(DeviceListener *listener, DeviceState *dev); 160707ff800SPaul Durrant void (*unrealize)(DeviceListener *listener, DeviceState *dev); 161707ff800SPaul Durrant QTAILQ_ENTRY(DeviceListener) link; 162707ff800SPaul Durrant }; 163707ff800SPaul Durrant 164074a86fcSAnthony Liguori #define TYPE_BUS "bus" 165074a86fcSAnthony Liguori #define BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS) 166074a86fcSAnthony Liguori #define BUS_CLASS(klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS) 167074a86fcSAnthony Liguori #define BUS_GET_CLASS(obj) OBJECT_GET_CLASS(BusClass, (obj), TYPE_BUS) 168074a86fcSAnthony Liguori 169074a86fcSAnthony Liguori struct BusClass { 170074a86fcSAnthony Liguori ObjectClass parent_class; 171074a86fcSAnthony Liguori 172074a86fcSAnthony Liguori /* FIXME first arg should be BusState */ 173074a86fcSAnthony Liguori void (*print_dev)(Monitor *mon, DeviceState *dev, int indent); 174074a86fcSAnthony Liguori char *(*get_dev_path)(DeviceState *dev); 175074a86fcSAnthony Liguori /* 176074a86fcSAnthony Liguori * This callback is used to create Open Firmware device path in accordance 177074a86fcSAnthony Liguori * with OF spec http://forthworks.com/standards/of1275.pdf. Individual bus 178074a86fcSAnthony Liguori * bindings can be found at http://playground.sun.com/1275/bindings/. 179074a86fcSAnthony Liguori */ 180074a86fcSAnthony Liguori char *(*get_fw_dev_path)(DeviceState *dev); 181dcc20931SPaolo Bonzini void (*reset)(BusState *bus); 18202e7f85dSBandan Das BusRealize realize; 18302e7f85dSBandan Das BusUnrealize unrealize; 18402e7f85dSBandan Das 1851395af6fSKONRAD Frederic /* maximum devices allowed on the bus, 0: no limit. */ 1861395af6fSKONRAD Frederic int max_dev; 18761de3676SAlexander Graf /* number of automatically allocated bus ids (e.g. ide.0) */ 18861de3676SAlexander Graf int automatic_ids; 189074a86fcSAnthony Liguori }; 190074a86fcSAnthony Liguori 191074a86fcSAnthony Liguori typedef struct BusChild { 192074a86fcSAnthony Liguori DeviceState *child; 193074a86fcSAnthony Liguori int index; 194074a86fcSAnthony Liguori QTAILQ_ENTRY(BusChild) sibling; 195074a86fcSAnthony Liguori } BusChild; 196074a86fcSAnthony Liguori 1970ee4de6cSIgor Mammedov #define QDEV_HOTPLUG_HANDLER_PROPERTY "hotplug-handler" 1980ee4de6cSIgor Mammedov 199074a86fcSAnthony Liguori /** 200074a86fcSAnthony Liguori * BusState: 20127c6ef1bSLi Qiang * @hotplug_handler: link to a hotplug handler associated with bus. 202074a86fcSAnthony Liguori */ 203074a86fcSAnthony Liguori struct BusState { 204074a86fcSAnthony Liguori Object obj; 205074a86fcSAnthony Liguori DeviceState *parent; 206f73480c3SMarc-André Lureau char *name; 2070ee4de6cSIgor Mammedov HotplugHandler *hotplug_handler; 208074a86fcSAnthony Liguori int max_index; 20902e7f85dSBandan Das bool realized; 21012b2e9f3STony Krowiak int num_children; 211eae3eb3eSPaolo Bonzini QTAILQ_HEAD(, BusChild) children; 212074a86fcSAnthony Liguori QLIST_ENTRY(BusState) sibling; 213074a86fcSAnthony Liguori }; 214074a86fcSAnthony Liguori 2155cc56cc6SPeter Maydell /** 2165cc56cc6SPeter Maydell * Property: 2175cc56cc6SPeter Maydell * @set_default: true if the default value should be set from @defval, 2185cc56cc6SPeter Maydell * in which case @info->set_default_value must not be NULL 2195cc56cc6SPeter Maydell * (if false then no default value is set by the property system 2205cc56cc6SPeter Maydell * and the field retains whatever value it was given by instance_init). 2215cc56cc6SPeter Maydell * @defval: default value for the property. This is used only if @set_default 2225cc56cc6SPeter Maydell * is true. 2235cc56cc6SPeter Maydell */ 224074a86fcSAnthony Liguori struct Property { 225074a86fcSAnthony Liguori const char *name; 2261b6b7d10SFam Zheng const PropertyInfo *info; 2273b6ca402SIldar Isaev ptrdiff_t offset; 228074a86fcSAnthony Liguori uint8_t bitnr; 2295cc56cc6SPeter Maydell bool set_default; 23076318657SMarc-André Lureau union { 23176318657SMarc-André Lureau int64_t i; 2323fb2111fSMarc-André Lureau uint64_t u; 23376318657SMarc-André Lureau } defval; 2340be6bfacSPeter Maydell int arrayoffset; 2351b6b7d10SFam Zheng const PropertyInfo *arrayinfo; 2360be6bfacSPeter Maydell int arrayfieldsize; 2375b4ff3c6SFam Zheng const char *link_type; 238074a86fcSAnthony Liguori }; 239074a86fcSAnthony Liguori 240074a86fcSAnthony Liguori struct PropertyInfo { 241074a86fcSAnthony Liguori const char *name; 24251b2e8c3SGonglei const char *description; 243f7abe0ecSMarc-André Lureau const QEnumLookup *enum_table; 244074a86fcSAnthony Liguori int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); 245a2740ad5SMarc-André Lureau void (*set_default_value)(Object *obj, const Property *prop); 246faabdbb7SFam Zheng void (*create)(Object *obj, Property *prop, Error **errp); 247074a86fcSAnthony Liguori ObjectPropertyAccessor *get; 248074a86fcSAnthony Liguori ObjectPropertyAccessor *set; 249074a86fcSAnthony Liguori ObjectPropertyRelease *release; 250074a86fcSAnthony Liguori }; 251074a86fcSAnthony Liguori 2529f9260a3SDon Slutz /** 2539f9260a3SDon Slutz * GlobalProperty: 254b3ce84feSEduardo Habkost * @used: Set to true if property was used when initializing a device. 255cff8b715SMarc-André Lureau * 256cff8b715SMarc-André Lureau * An error is fatal for non-hotplugged devices, when the global is applied. 2579f9260a3SDon Slutz */ 258074a86fcSAnthony Liguori typedef struct GlobalProperty { 259074a86fcSAnthony Liguori const char *driver; 260074a86fcSAnthony Liguori const char *property; 261074a86fcSAnthony Liguori const char *value; 262b3ce84feSEduardo Habkost bool used; 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é 426074a86fcSAnthony Liguori const struct 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 454*e965ffa7SStefan Hajnoczi VMChangeStateEntry *qdev_add_vm_change_state_handler(DeviceState *dev, 455*e965ffa7SStefan Hajnoczi VMChangeStateHandler *cb, 456*e965ffa7SStefan Hajnoczi void *opaque); 457*e965ffa7SStefan Hajnoczi 458074a86fcSAnthony Liguori #endif 459