1074a86fcSAnthony Liguori #ifndef QDEV_CORE_H 2074a86fcSAnthony Liguori #define QDEV_CORE_H 3074a86fcSAnthony Liguori 41de7afc9SPaolo Bonzini #include "qemu/queue.h" 5949fc823SMarcel Apfelbaum #include "qemu/bitmap.h" 614cccb61SPaolo Bonzini #include "qom/object.h" 70ee4de6cSIgor Mammedov #include "hw/hotplug.h" 8*c11256aaSDamien Hedde #include "hw/resettable.h" 9074a86fcSAnthony Liguori 10074a86fcSAnthony Liguori enum { 11074a86fcSAnthony Liguori DEV_NVECTORS_UNSPECIFIED = -1, 12074a86fcSAnthony Liguori }; 13074a86fcSAnthony Liguori 14074a86fcSAnthony Liguori #define TYPE_DEVICE "device" 15074a86fcSAnthony Liguori #define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE) 16074a86fcSAnthony Liguori #define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE) 17074a86fcSAnthony Liguori #define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE) 18074a86fcSAnthony Liguori 193d1237fbSMarcel Apfelbaum typedef enum DeviceCategory { 203d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_BRIDGE, 213d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_USB, 223d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_STORAGE, 233d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_NETWORK, 243d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_INPUT, 253d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_DISPLAY, 263d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_SOUND, 273d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_MISC, 28ba31cc72SThomas Huth DEVICE_CATEGORY_CPU, 293d1237fbSMarcel Apfelbaum DEVICE_CATEGORY_MAX 303d1237fbSMarcel Apfelbaum } DeviceCategory; 313d1237fbSMarcel Apfelbaum 32249d4172SAndreas Färber typedef void (*DeviceRealize)(DeviceState *dev, Error **errp); 33249d4172SAndreas Färber typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp); 34b850f664SPhilippe Mathieu-Daudé typedef void (*DeviceReset)(DeviceState *dev); 3502e7f85dSBandan Das typedef void (*BusRealize)(BusState *bus, Error **errp); 3602e7f85dSBandan Das typedef void (*BusUnrealize)(BusState *bus, Error **errp); 37074a86fcSAnthony Liguori 38249d4172SAndreas Färber /** 39249d4172SAndreas Färber * DeviceClass: 40249d4172SAndreas Färber * @props: Properties accessing state fields. 41249d4172SAndreas Färber * @realize: Callback function invoked when the #DeviceState:realized 42ff46d9d4SPhilippe Mathieu-Daudé * property is changed to %true. 43249d4172SAndreas Färber * @unrealize: Callback function invoked when the #DeviceState:realized 44249d4172SAndreas Färber * property is changed to %false. 451a37eca1SIgor Mammedov * @hotpluggable: indicates if #DeviceClass is hotpluggable, available 461a37eca1SIgor Mammedov * as readonly "hotpluggable" property of #DeviceState instance 47249d4172SAndreas Färber * 48249d4172SAndreas Färber * # Realization # 49249d4172SAndreas Färber * Devices are constructed in two stages, 50249d4172SAndreas Färber * 1) object instantiation via object_initialize() and 51249d4172SAndreas Färber * 2) device realization via #DeviceState:realized property. 526038f989SThomas Huth * The former may not fail (and must not abort or exit, since it is called 536038f989SThomas Huth * during device introspection already), and the latter may return error 546038f989SThomas Huth * information to the caller and must be re-entrant. 55249d4172SAndreas Färber * Trivial field initializations should go into #TypeInfo.instance_init. 56249d4172SAndreas Färber * Operations depending on @props static properties should go into @realize. 57249d4172SAndreas Färber * After successful realization, setting static properties will fail. 58249d4172SAndreas Färber * 59daeba969SMarkus Armbruster * As an interim step, the #DeviceState:realized property can also be 60daeba969SMarkus Armbruster * set with qdev_init_nofail(). 61249d4172SAndreas Färber * In the future, devices will propagate this state change to their children 62249d4172SAndreas Färber * and along busses they expose. 63249d4172SAndreas Färber * The point in time will be deferred to machine creation, so that values 64249d4172SAndreas Färber * set in @realize will not be introspectable beforehand. Therefore devices 65249d4172SAndreas Färber * must not create children during @realize; they should initialize them via 66249d4172SAndreas Färber * object_initialize() in their own #TypeInfo.instance_init and forward the 67249d4172SAndreas Färber * realization events appropriately. 68249d4172SAndreas Färber * 69249d4172SAndreas Färber * Any type may override the @realize and/or @unrealize callbacks but needs 70782beb52SAndreas Färber * to call the parent type's implementation if keeping their functionality 71782beb52SAndreas Färber * is desired. Refer to QOM documentation for further discussion and examples. 72782beb52SAndreas Färber * 73782beb52SAndreas Färber * <note> 74782beb52SAndreas Färber * <para> 75ff46d9d4SPhilippe Mathieu-Daudé * Since TYPE_DEVICE doesn't implement @realize and @unrealize, types 76ff46d9d4SPhilippe Mathieu-Daudé * derived directly from it need not call their parent's @realize and 77ff46d9d4SPhilippe Mathieu-Daudé * @unrealize. 78782beb52SAndreas Färber * For other types consult the documentation and implementation of the 79782beb52SAndreas Färber * respective parent types. 80782beb52SAndreas Färber * </para> 81782beb52SAndreas Färber * </note> 82f3a85056SJens Freimann * 83f3a85056SJens Freimann * # Hiding a device # 84f3a85056SJens Freimann * To hide a device, a DeviceListener function should_be_hidden() needs to 85f3a85056SJens Freimann * be registered. 86f3a85056SJens Freimann * It can be used to defer adding a device and therefore hide it from the 87f3a85056SJens Freimann * guest. The handler registering to this DeviceListener can save the QOpts 88f3a85056SJens Freimann * passed to it for re-using it later and must return that it wants the device 89f3a85056SJens Freimann * to be/remain hidden or not. When the handler function decides the device 90f3a85056SJens Freimann * shall not be hidden it will be added in qdev_device_add() and 91f3a85056SJens Freimann * realized as any other device. Otherwise qdev_device_add() will return early 92f3a85056SJens Freimann * without adding the device. The guest will not see a "hidden" device 93f3a85056SJens Freimann * until it was marked don't hide and qdev_device_add called again. 94f3a85056SJens Freimann * 95249d4172SAndreas Färber */ 96074a86fcSAnthony Liguori typedef struct DeviceClass { 97249d4172SAndreas Färber /*< private >*/ 98074a86fcSAnthony Liguori ObjectClass parent_class; 99249d4172SAndreas Färber /*< public >*/ 100074a86fcSAnthony Liguori 1013d1237fbSMarcel Apfelbaum DECLARE_BITMAP(categories, DEVICE_CATEGORY_MAX); 102074a86fcSAnthony Liguori const char *fw_name; 103074a86fcSAnthony Liguori const char *desc; 104385d8f22SPaolo Bonzini 105385d8f22SPaolo Bonzini /* 106385d8f22SPaolo Bonzini * The underscore at the end ensures a compile-time error if someone 107385d8f22SPaolo Bonzini * assigns to dc->props instead of using device_class_set_props. 108385d8f22SPaolo Bonzini */ 109385d8f22SPaolo Bonzini Property *props_; 110efec3dd6SMarkus Armbruster 111efec3dd6SMarkus Armbruster /* 112e90f2a8cSEduardo Habkost * Can this device be instantiated with -device / device_add? 113efec3dd6SMarkus Armbruster * All devices should support instantiation with device_add, and 114efec3dd6SMarkus Armbruster * this flag should not exist. But we're not there, yet. Some 115efec3dd6SMarkus Armbruster * devices fail to instantiate with cryptic error messages. 116efec3dd6SMarkus Armbruster * Others instantiate, but don't work. Exposing users to such 117e90f2a8cSEduardo Habkost * behavior would be cruel; clearing this flag will protect them. 118e90f2a8cSEduardo Habkost * It should never be cleared without a comment explaining why it 119e90f2a8cSEduardo Habkost * is cleared. 120efec3dd6SMarkus Armbruster * TODO remove once we're there 121efec3dd6SMarkus Armbruster */ 122e90f2a8cSEduardo Habkost bool user_creatable; 1231a37eca1SIgor Mammedov bool hotpluggable; 124074a86fcSAnthony Liguori 125074a86fcSAnthony Liguori /* callbacks */ 126*c11256aaSDamien Hedde /* 127*c11256aaSDamien Hedde * Reset method here is deprecated and replaced by methods in the 128*c11256aaSDamien Hedde * resettable class interface to implement a multi-phase reset. 129*c11256aaSDamien Hedde * TODO: remove once every reset callback is unused 130*c11256aaSDamien Hedde */ 131b850f664SPhilippe Mathieu-Daudé DeviceReset reset; 132249d4172SAndreas Färber DeviceRealize realize; 133249d4172SAndreas Färber DeviceUnrealize unrealize; 134074a86fcSAnthony Liguori 135074a86fcSAnthony Liguori /* device state */ 1368a9358ccSMarkus Armbruster const VMStateDescription *vmsd; 137074a86fcSAnthony Liguori 138074a86fcSAnthony Liguori /* Private to qdev / bus. */ 139074a86fcSAnthony Liguori const char *bus_type; 140074a86fcSAnthony Liguori } DeviceClass; 141074a86fcSAnthony Liguori 142a5f54290SPeter Crosthwaite typedef struct NamedGPIOList NamedGPIOList; 143a5f54290SPeter Crosthwaite 144a5f54290SPeter Crosthwaite struct NamedGPIOList { 145a5f54290SPeter Crosthwaite char *name; 146a5f54290SPeter Crosthwaite qemu_irq *in; 147a5f54290SPeter Crosthwaite int num_in; 148a5f54290SPeter Crosthwaite int num_out; 149a5f54290SPeter Crosthwaite QLIST_ENTRY(NamedGPIOList) node; 150a5f54290SPeter Crosthwaite }; 151a5f54290SPeter Crosthwaite 1527983c8a3SAndreas Färber /** 1537983c8a3SAndreas Färber * DeviceState: 1547983c8a3SAndreas Färber * @realized: Indicates whether the device has been fully constructed. 155*c11256aaSDamien Hedde * @reset: ResettableState for the device; handled by Resettable interface. 1567983c8a3SAndreas Färber * 1577983c8a3SAndreas Färber * This structure should not be accessed directly. We declare it here 1587983c8a3SAndreas Färber * so that it can be embedded in individual device state structures. 1597983c8a3SAndreas Färber */ 160074a86fcSAnthony Liguori struct DeviceState { 1617983c8a3SAndreas Färber /*< private >*/ 162074a86fcSAnthony Liguori Object parent_obj; 1637983c8a3SAndreas Färber /*< public >*/ 164074a86fcSAnthony Liguori 165074a86fcSAnthony Liguori const char *id; 16604162f8fSMichael Roth char *canonical_path; 1677983c8a3SAndreas Färber bool realized; 168352e8da7SPaolo Bonzini bool pending_deleted_event; 169074a86fcSAnthony Liguori QemuOpts *opts; 170074a86fcSAnthony Liguori int hotplugged; 171a1190ab6SJens Freimann bool allow_unplug_during_migration; 172074a86fcSAnthony Liguori BusState *parent_bus; 173a5f54290SPeter Crosthwaite QLIST_HEAD(, NamedGPIOList) gpios; 174074a86fcSAnthony Liguori QLIST_HEAD(, BusState) child_bus; 175074a86fcSAnthony Liguori int num_child_bus; 176074a86fcSAnthony Liguori int instance_id_alias; 177074a86fcSAnthony Liguori int alias_required_for_version; 178*c11256aaSDamien Hedde ResettableState reset; 179074a86fcSAnthony Liguori }; 180074a86fcSAnthony Liguori 181707ff800SPaul Durrant struct DeviceListener { 182707ff800SPaul Durrant void (*realize)(DeviceListener *listener, DeviceState *dev); 183707ff800SPaul Durrant void (*unrealize)(DeviceListener *listener, DeviceState *dev); 184f3a85056SJens Freimann /* 185f3a85056SJens Freimann * This callback is called upon init of the DeviceState and allows to 186f3a85056SJens Freimann * inform qdev that a device should be hidden, depending on the device 187f3a85056SJens Freimann * opts, for example, to hide a standby device. 188f3a85056SJens Freimann */ 189f3a85056SJens Freimann int (*should_be_hidden)(DeviceListener *listener, QemuOpts *device_opts); 190707ff800SPaul Durrant QTAILQ_ENTRY(DeviceListener) link; 191707ff800SPaul Durrant }; 192707ff800SPaul Durrant 193074a86fcSAnthony Liguori #define TYPE_BUS "bus" 194074a86fcSAnthony Liguori #define BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS) 195074a86fcSAnthony Liguori #define BUS_CLASS(klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS) 196074a86fcSAnthony Liguori #define BUS_GET_CLASS(obj) OBJECT_GET_CLASS(BusClass, (obj), TYPE_BUS) 197074a86fcSAnthony Liguori 198074a86fcSAnthony Liguori struct BusClass { 199074a86fcSAnthony Liguori ObjectClass parent_class; 200074a86fcSAnthony Liguori 201074a86fcSAnthony Liguori /* FIXME first arg should be BusState */ 202074a86fcSAnthony Liguori void (*print_dev)(Monitor *mon, DeviceState *dev, int indent); 203074a86fcSAnthony Liguori char *(*get_dev_path)(DeviceState *dev); 204074a86fcSAnthony Liguori /* 205074a86fcSAnthony Liguori * This callback is used to create Open Firmware device path in accordance 206074a86fcSAnthony Liguori * with OF spec http://forthworks.com/standards/of1275.pdf. Individual bus 207074a86fcSAnthony Liguori * bindings can be found at http://playground.sun.com/1275/bindings/. 208074a86fcSAnthony Liguori */ 209074a86fcSAnthony Liguori char *(*get_fw_dev_path)(DeviceState *dev); 210dcc20931SPaolo Bonzini void (*reset)(BusState *bus); 21102e7f85dSBandan Das BusRealize realize; 21202e7f85dSBandan Das BusUnrealize unrealize; 21302e7f85dSBandan Das 2141395af6fSKONRAD Frederic /* maximum devices allowed on the bus, 0: no limit. */ 2151395af6fSKONRAD Frederic int max_dev; 21661de3676SAlexander Graf /* number of automatically allocated bus ids (e.g. ide.0) */ 21761de3676SAlexander Graf int automatic_ids; 218074a86fcSAnthony Liguori }; 219074a86fcSAnthony Liguori 220074a86fcSAnthony Liguori typedef struct BusChild { 221074a86fcSAnthony Liguori DeviceState *child; 222074a86fcSAnthony Liguori int index; 223074a86fcSAnthony Liguori QTAILQ_ENTRY(BusChild) sibling; 224074a86fcSAnthony Liguori } BusChild; 225074a86fcSAnthony Liguori 2260ee4de6cSIgor Mammedov #define QDEV_HOTPLUG_HANDLER_PROPERTY "hotplug-handler" 2270ee4de6cSIgor Mammedov 228074a86fcSAnthony Liguori /** 229074a86fcSAnthony Liguori * BusState: 23027c6ef1bSLi Qiang * @hotplug_handler: link to a hotplug handler associated with bus. 231*c11256aaSDamien Hedde * @reset: ResettableState for the bus; handled by Resettable interface. 232074a86fcSAnthony Liguori */ 233074a86fcSAnthony Liguori struct BusState { 234074a86fcSAnthony Liguori Object obj; 235074a86fcSAnthony Liguori DeviceState *parent; 236f73480c3SMarc-André Lureau char *name; 2370ee4de6cSIgor Mammedov HotplugHandler *hotplug_handler; 238074a86fcSAnthony Liguori int max_index; 23902e7f85dSBandan Das bool realized; 24012b2e9f3STony Krowiak int num_children; 241eae3eb3eSPaolo Bonzini QTAILQ_HEAD(, BusChild) children; 242074a86fcSAnthony Liguori QLIST_ENTRY(BusState) sibling; 243*c11256aaSDamien Hedde ResettableState reset; 244074a86fcSAnthony Liguori }; 245074a86fcSAnthony Liguori 2465cc56cc6SPeter Maydell /** 2475cc56cc6SPeter Maydell * Property: 2485cc56cc6SPeter Maydell * @set_default: true if the default value should be set from @defval, 2495cc56cc6SPeter Maydell * in which case @info->set_default_value must not be NULL 2505cc56cc6SPeter Maydell * (if false then no default value is set by the property system 2515cc56cc6SPeter Maydell * and the field retains whatever value it was given by instance_init). 2525cc56cc6SPeter Maydell * @defval: default value for the property. This is used only if @set_default 2535cc56cc6SPeter Maydell * is true. 2545cc56cc6SPeter Maydell */ 255074a86fcSAnthony Liguori struct Property { 256074a86fcSAnthony Liguori const char *name; 2571b6b7d10SFam Zheng const PropertyInfo *info; 2583b6ca402SIldar Isaev ptrdiff_t offset; 259074a86fcSAnthony Liguori uint8_t bitnr; 2605cc56cc6SPeter Maydell bool set_default; 26176318657SMarc-André Lureau union { 26276318657SMarc-André Lureau int64_t i; 2633fb2111fSMarc-André Lureau uint64_t u; 26476318657SMarc-André Lureau } defval; 2650be6bfacSPeter Maydell int arrayoffset; 2661b6b7d10SFam Zheng const PropertyInfo *arrayinfo; 2670be6bfacSPeter Maydell int arrayfieldsize; 2685b4ff3c6SFam Zheng const char *link_type; 269074a86fcSAnthony Liguori }; 270074a86fcSAnthony Liguori 271074a86fcSAnthony Liguori struct PropertyInfo { 272074a86fcSAnthony Liguori const char *name; 27351b2e8c3SGonglei const char *description; 274f7abe0ecSMarc-André Lureau const QEnumLookup *enum_table; 275074a86fcSAnthony Liguori int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); 27677b06bbaSMarc-André Lureau void (*set_default_value)(ObjectProperty *op, const Property *prop); 27777b06bbaSMarc-André Lureau void (*create)(ObjectClass *oc, Property *prop, Error **errp); 278074a86fcSAnthony Liguori ObjectPropertyAccessor *get; 279074a86fcSAnthony Liguori ObjectPropertyAccessor *set; 280074a86fcSAnthony Liguori ObjectPropertyRelease *release; 281074a86fcSAnthony Liguori }; 282074a86fcSAnthony Liguori 2839f9260a3SDon Slutz /** 2849f9260a3SDon Slutz * GlobalProperty: 285b3ce84feSEduardo Habkost * @used: Set to true if property was used when initializing a device. 28692fd453cSDr. David Alan Gilbert * @optional: If set to true, GlobalProperty will be skipped without errors 28792fd453cSDr. David Alan Gilbert * if the property doesn't exist. 288cff8b715SMarc-André Lureau * 289cff8b715SMarc-André Lureau * An error is fatal for non-hotplugged devices, when the global is applied. 2909f9260a3SDon Slutz */ 291074a86fcSAnthony Liguori typedef struct GlobalProperty { 292074a86fcSAnthony Liguori const char *driver; 293074a86fcSAnthony Liguori const char *property; 294074a86fcSAnthony Liguori const char *value; 295b3ce84feSEduardo Habkost bool used; 29692fd453cSDr. David Alan Gilbert bool optional; 297074a86fcSAnthony Liguori } GlobalProperty; 298074a86fcSAnthony Liguori 299ea9ce893SMarc-André Lureau static inline void 300ea9ce893SMarc-André Lureau compat_props_add(GPtrArray *arr, 301ea9ce893SMarc-André Lureau GlobalProperty props[], size_t nelem) 302ea9ce893SMarc-André Lureau { 303ea9ce893SMarc-André Lureau int i; 304ea9ce893SMarc-André Lureau for (i = 0; i < nelem; i++) { 305ea9ce893SMarc-André Lureau g_ptr_array_add(arr, (void *)&props[i]); 306ea9ce893SMarc-André Lureau } 307ea9ce893SMarc-André Lureau } 308ea9ce893SMarc-André Lureau 309074a86fcSAnthony Liguori /*** Board API. This should go away once we have a machine config file. ***/ 310074a86fcSAnthony Liguori 311074a86fcSAnthony Liguori DeviceState *qdev_create(BusState *bus, const char *name); 312074a86fcSAnthony Liguori DeviceState *qdev_try_create(BusState *bus, const char *name); 313074a86fcSAnthony Liguori void qdev_init_nofail(DeviceState *dev); 314074a86fcSAnthony Liguori void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, 315074a86fcSAnthony Liguori int required_for_version); 31614405c27SDavid Hildenbrand HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev); 31703fcbd9dSThomas Huth HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev); 318d2321d31SPeter Xu bool qdev_hotplug_allowed(DeviceState *dev, Error **errp); 31917cc0128SIgor Mammedov /** 32017cc0128SIgor Mammedov * qdev_get_hotplug_handler: Get handler responsible for device wiring 32117cc0128SIgor Mammedov * 32217cc0128SIgor Mammedov * Find HOTPLUG_HANDLER for @dev that provides [pre|un]plug callbacks for it. 32317cc0128SIgor Mammedov * 32417cc0128SIgor Mammedov * Note: in case @dev has a parent bus, it will be returned as handler unless 32517cc0128SIgor Mammedov * machine handler overrides it. 32617cc0128SIgor Mammedov * 32717cc0128SIgor Mammedov * Returns: pointer to object that implements TYPE_HOTPLUG_HANDLER interface 32817cc0128SIgor Mammedov * or NULL if there aren't any. 32917cc0128SIgor Mammedov */ 330c06b2ffbSZhu Guihua HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev); 331074a86fcSAnthony Liguori void qdev_unplug(DeviceState *dev, Error **errp); 332014176f9SIgor Mammedov void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, 333014176f9SIgor Mammedov DeviceState *dev, Error **errp); 334074a86fcSAnthony Liguori void qdev_machine_creation_done(void); 335074a86fcSAnthony Liguori bool qdev_machine_modified(void); 336074a86fcSAnthony Liguori 337074a86fcSAnthony Liguori qemu_irq qdev_get_gpio_in(DeviceState *dev, int n); 338a5f54290SPeter Crosthwaite qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n); 339a5f54290SPeter Crosthwaite 340074a86fcSAnthony Liguori void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin); 341a5f54290SPeter Crosthwaite void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n, 342a5f54290SPeter Crosthwaite qemu_irq pin); 343b7973186SAlexander Graf qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n); 3440c24db2bSPeter Crosthwaite qemu_irq qdev_intercept_gpio_out(DeviceState *dev, qemu_irq icpt, 3450c24db2bSPeter Crosthwaite const char *name, int n); 346074a86fcSAnthony Liguori 347074a86fcSAnthony Liguori BusState *qdev_get_child_bus(DeviceState *dev, const char *name); 348074a86fcSAnthony Liguori 349074a86fcSAnthony Liguori /*** Device API. ***/ 350074a86fcSAnthony Liguori 351074a86fcSAnthony Liguori /* Register device properties. */ 352074a86fcSAnthony Liguori /* GPIO inputs also double as IRQ sinks. */ 353074a86fcSAnthony Liguori void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n); 354074a86fcSAnthony Liguori void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n); 355a5f54290SPeter Crosthwaite void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins, 356a5f54290SPeter Crosthwaite const char *name, int n); 3574a151677SPeter Maydell /** 3584a151677SPeter Maydell * qdev_init_gpio_in_named_with_opaque: create an array of input GPIO lines 3594a151677SPeter Maydell * for the specified device 3604a151677SPeter Maydell * 3614a151677SPeter Maydell * @dev: Device to create input GPIOs for 3624a151677SPeter Maydell * @handler: Function to call when GPIO line value is set 3634a151677SPeter Maydell * @opaque: Opaque data pointer to pass to @handler 3644a151677SPeter Maydell * @name: Name of the GPIO input (must be unique for this device) 3654a151677SPeter Maydell * @n: Number of GPIO lines in this input set 3664a151677SPeter Maydell */ 3674a151677SPeter Maydell void qdev_init_gpio_in_named_with_opaque(DeviceState *dev, 3684a151677SPeter Maydell qemu_irq_handler handler, 3694a151677SPeter Maydell void *opaque, 3704a151677SPeter Maydell const char *name, int n); 3714a151677SPeter Maydell 3724a151677SPeter Maydell /** 3734a151677SPeter Maydell * qdev_init_gpio_in_named: create an array of input GPIO lines 3744a151677SPeter Maydell * for the specified device 3754a151677SPeter Maydell * 3764a151677SPeter Maydell * Like qdev_init_gpio_in_named_with_opaque(), but the opaque pointer 3774a151677SPeter Maydell * passed to the handler is @dev (which is the most commonly desired behaviour). 3784a151677SPeter Maydell */ 3794a151677SPeter Maydell static inline void qdev_init_gpio_in_named(DeviceState *dev, 3804a151677SPeter Maydell qemu_irq_handler handler, 3814a151677SPeter Maydell const char *name, int n) 3824a151677SPeter Maydell { 3834a151677SPeter Maydell qdev_init_gpio_in_named_with_opaque(dev, handler, dev, name, n); 3844a151677SPeter Maydell } 385074a86fcSAnthony Liguori 38617a96a14SPeter Crosthwaite void qdev_pass_gpios(DeviceState *dev, DeviceState *container, 38717a96a14SPeter Crosthwaite const char *name); 38817a96a14SPeter Crosthwaite 389074a86fcSAnthony Liguori BusState *qdev_get_parent_bus(DeviceState *dev); 390074a86fcSAnthony Liguori 391074a86fcSAnthony Liguori /*** BUS API. ***/ 392074a86fcSAnthony Liguori 393074a86fcSAnthony Liguori DeviceState *qdev_find_recursive(BusState *bus, const char *id); 394074a86fcSAnthony Liguori 395074a86fcSAnthony Liguori /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */ 396074a86fcSAnthony Liguori typedef int (qbus_walkerfn)(BusState *bus, void *opaque); 397074a86fcSAnthony Liguori typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque); 398074a86fcSAnthony Liguori 399fb17dfe0SAndreas Färber void qbus_create_inplace(void *bus, size_t size, const char *typename, 400074a86fcSAnthony Liguori DeviceState *parent, const char *name); 401074a86fcSAnthony Liguori BusState *qbus_create(const char *typename, DeviceState *parent, const char *name); 402074a86fcSAnthony Liguori /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion, 403074a86fcSAnthony Liguori * < 0 if either devfn or busfn terminate walk somewhere in cursion, 404074a86fcSAnthony Liguori * 0 otherwise. */ 4050293214bSPaolo Bonzini int qbus_walk_children(BusState *bus, 4060293214bSPaolo Bonzini qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn, 4070293214bSPaolo Bonzini qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn, 4080293214bSPaolo Bonzini void *opaque); 4090293214bSPaolo Bonzini int qdev_walk_children(DeviceState *dev, 4100293214bSPaolo Bonzini qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn, 4110293214bSPaolo Bonzini qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn, 4120293214bSPaolo Bonzini void *opaque); 4130293214bSPaolo Bonzini 414074a86fcSAnthony Liguori void qdev_reset_all(DeviceState *dev); 415ff8de075SDavid Hildenbrand void qdev_reset_all_fn(void *opaque); 416d0508c36SPaolo Bonzini 417d0508c36SPaolo Bonzini /** 418d0508c36SPaolo Bonzini * @qbus_reset_all: 419d0508c36SPaolo Bonzini * @bus: Bus to be reset. 420d0508c36SPaolo Bonzini * 421d0508c36SPaolo Bonzini * Reset @bus and perform a bus-level ("hard") reset of all devices connected 422d0508c36SPaolo Bonzini * to it, including recursive processing of all buses below @bus itself. A 423d0508c36SPaolo Bonzini * hard reset means that qbus_reset_all will reset all state of the device. 424d0508c36SPaolo Bonzini * For PCI devices, for example, this will include the base address registers 425d0508c36SPaolo Bonzini * or configuration space. 426d0508c36SPaolo Bonzini */ 427d0508c36SPaolo Bonzini void qbus_reset_all(BusState *bus); 428074a86fcSAnthony Liguori void qbus_reset_all_fn(void *opaque); 429074a86fcSAnthony Liguori 430*c11256aaSDamien Hedde /** 431*c11256aaSDamien Hedde * device_is_in_reset: 432*c11256aaSDamien Hedde * Return true if the device @dev is currently being reset. 433*c11256aaSDamien Hedde */ 434*c11256aaSDamien Hedde bool device_is_in_reset(DeviceState *dev); 435*c11256aaSDamien Hedde 436*c11256aaSDamien Hedde /** 437*c11256aaSDamien Hedde * bus_is_in_reset: 438*c11256aaSDamien Hedde * Return true if the bus @bus is currently being reset. 439*c11256aaSDamien Hedde */ 440*c11256aaSDamien Hedde bool bus_is_in_reset(BusState *bus); 441*c11256aaSDamien Hedde 442074a86fcSAnthony Liguori /* This should go away once we get rid of the NULL bus hack */ 443074a86fcSAnthony Liguori BusState *sysbus_get_default(void); 444074a86fcSAnthony Liguori 445074a86fcSAnthony Liguori char *qdev_get_fw_dev_path(DeviceState *dev); 4460be63901SGonglei char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev); 447074a86fcSAnthony Liguori 448074a86fcSAnthony Liguori /** 449074a86fcSAnthony Liguori * @qdev_machine_init 450074a86fcSAnthony Liguori * 451074a86fcSAnthony Liguori * Initialize platform devices before machine init. This is a hack until full 452074a86fcSAnthony Liguori * support for composition is added. 453074a86fcSAnthony Liguori */ 454074a86fcSAnthony Liguori void qdev_machine_init(void); 455074a86fcSAnthony Liguori 456074a86fcSAnthony Liguori /** 457f703a04cSDamien Hedde * device_legacy_reset: 458074a86fcSAnthony Liguori * 459074a86fcSAnthony Liguori * Reset a single device (by calling the reset method). 460074a86fcSAnthony Liguori */ 461f703a04cSDamien Hedde void device_legacy_reset(DeviceState *dev); 462074a86fcSAnthony Liguori 4634f67d30bSMarc-André Lureau void device_class_set_props(DeviceClass *dc, Property *props); 4644f67d30bSMarc-André Lureau 465*c11256aaSDamien Hedde /** 466*c11256aaSDamien Hedde * device_class_set_parent_reset: 467*c11256aaSDamien Hedde * TODO: remove the function when DeviceClass's reset method 468*c11256aaSDamien Hedde * is not used anymore. 469*c11256aaSDamien Hedde */ 47046795cf2SPhilippe Mathieu-Daudé void device_class_set_parent_reset(DeviceClass *dc, 47146795cf2SPhilippe Mathieu-Daudé DeviceReset dev_reset, 47246795cf2SPhilippe Mathieu-Daudé DeviceReset *parent_reset); 47346795cf2SPhilippe Mathieu-Daudé void device_class_set_parent_realize(DeviceClass *dc, 47446795cf2SPhilippe Mathieu-Daudé DeviceRealize dev_realize, 47546795cf2SPhilippe Mathieu-Daudé DeviceRealize *parent_realize); 47646795cf2SPhilippe Mathieu-Daudé void device_class_set_parent_unrealize(DeviceClass *dc, 47746795cf2SPhilippe Mathieu-Daudé DeviceUnrealize dev_unrealize, 47846795cf2SPhilippe Mathieu-Daudé DeviceUnrealize *parent_unrealize); 47946795cf2SPhilippe Mathieu-Daudé 4808a9358ccSMarkus Armbruster const VMStateDescription *qdev_get_vmsd(DeviceState *dev); 481074a86fcSAnthony Liguori 482074a86fcSAnthony Liguori const char *qdev_fw_name(DeviceState *dev); 483074a86fcSAnthony Liguori 484074a86fcSAnthony Liguori Object *qdev_get_machine(void); 485074a86fcSAnthony Liguori 486074a86fcSAnthony Liguori /* FIXME: make this a link<> */ 487074a86fcSAnthony Liguori void qdev_set_parent_bus(DeviceState *dev, BusState *bus); 488074a86fcSAnthony Liguori 4899bed84c1SJuan Quintela extern bool qdev_hotplug; 49021def24aSJuan Quintela extern bool qdev_hot_removed; 491074a86fcSAnthony Liguori 492074a86fcSAnthony Liguori char *qdev_get_dev_path(DeviceState *dev); 493074a86fcSAnthony Liguori 49494d1cc5fSMichael Roth void qbus_set_hotplug_handler(BusState *bus, Object *handler, Error **errp); 495431bbb26SIgor Mammedov 496431bbb26SIgor Mammedov void qbus_set_bus_hotplug_handler(BusState *bus, Error **errp); 49739b888bdSIgor Mammedov 49839b888bdSIgor Mammedov static inline bool qbus_is_hotpluggable(BusState *bus) 49939b888bdSIgor Mammedov { 5002d9a982fSIgor Mammedov return bus->hotplug_handler; 50139b888bdSIgor Mammedov } 502707ff800SPaul Durrant 503707ff800SPaul Durrant void device_listener_register(DeviceListener *listener); 504707ff800SPaul Durrant void device_listener_unregister(DeviceListener *listener); 505707ff800SPaul Durrant 506f3a85056SJens Freimann /** 507f3a85056SJens Freimann * @qdev_should_hide_device: 508f3a85056SJens Freimann * @opts: QemuOpts as passed on cmdline. 509f3a85056SJens Freimann * 510f3a85056SJens Freimann * Check if a device should be added. 511f3a85056SJens Freimann * When a device is added via qdev_device_add() this will be called, 512f3a85056SJens Freimann * and return if the device should be added now or not. 513f3a85056SJens Freimann */ 514f3a85056SJens Freimann bool qdev_should_hide_device(QemuOpts *opts); 515f3a85056SJens Freimann 516074a86fcSAnthony Liguori #endif 517