1 #ifndef QDEV_CORE_H 2 #define QDEV_CORE_H 3 4 #include "qemu/queue.h" 5 #include "qemu/bitmap.h" 6 #include "qom/object.h" 7 #include "hw/hotplug.h" 8 #include "hw/resettable.h" 9 10 enum { 11 DEV_NVECTORS_UNSPECIFIED = -1, 12 }; 13 14 #define TYPE_DEVICE "device" 15 OBJECT_DECLARE_TYPE(DeviceState, DeviceClass, DEVICE) 16 17 typedef enum DeviceCategory { 18 DEVICE_CATEGORY_BRIDGE, 19 DEVICE_CATEGORY_USB, 20 DEVICE_CATEGORY_STORAGE, 21 DEVICE_CATEGORY_NETWORK, 22 DEVICE_CATEGORY_INPUT, 23 DEVICE_CATEGORY_DISPLAY, 24 DEVICE_CATEGORY_SOUND, 25 DEVICE_CATEGORY_MISC, 26 DEVICE_CATEGORY_CPU, 27 DEVICE_CATEGORY_MAX 28 } DeviceCategory; 29 30 typedef void (*DeviceRealize)(DeviceState *dev, Error **errp); 31 typedef void (*DeviceUnrealize)(DeviceState *dev); 32 typedef void (*DeviceReset)(DeviceState *dev); 33 typedef void (*BusRealize)(BusState *bus, Error **errp); 34 typedef void (*BusUnrealize)(BusState *bus); 35 36 /** 37 * DeviceClass: 38 * @props: Properties accessing state fields. 39 * @realize: Callback function invoked when the #DeviceState:realized 40 * property is changed to %true. 41 * @unrealize: Callback function invoked when the #DeviceState:realized 42 * property is changed to %false. 43 * @hotpluggable: indicates if #DeviceClass is hotpluggable, available 44 * as readonly "hotpluggable" property of #DeviceState instance 45 * 46 * # Realization # 47 * Devices are constructed in two stages, 48 * 1) object instantiation via object_initialize() and 49 * 2) device realization via #DeviceState:realized property. 50 * The former may not fail (and must not abort or exit, since it is called 51 * during device introspection already), and the latter may return error 52 * information to the caller and must be re-entrant. 53 * Trivial field initializations should go into #TypeInfo.instance_init. 54 * Operations depending on @props static properties should go into @realize. 55 * After successful realization, setting static properties will fail. 56 * 57 * As an interim step, the #DeviceState:realized property can also be 58 * set with qdev_realize(). 59 * In the future, devices will propagate this state change to their children 60 * and along busses they expose. 61 * The point in time will be deferred to machine creation, so that values 62 * set in @realize will not be introspectable beforehand. Therefore devices 63 * must not create children during @realize; they should initialize them via 64 * object_initialize() in their own #TypeInfo.instance_init and forward the 65 * realization events appropriately. 66 * 67 * Any type may override the @realize and/or @unrealize callbacks but needs 68 * to call the parent type's implementation if keeping their functionality 69 * is desired. Refer to QOM documentation for further discussion and examples. 70 * 71 * <note> 72 * <para> 73 * Since TYPE_DEVICE doesn't implement @realize and @unrealize, types 74 * derived directly from it need not call their parent's @realize and 75 * @unrealize. 76 * For other types consult the documentation and implementation of the 77 * respective parent types. 78 * </para> 79 * </note> 80 * 81 * # Hiding a device # 82 * To hide a device, a DeviceListener function should_be_hidden() needs to 83 * be registered. 84 * It can be used to defer adding a device and therefore hide it from the 85 * guest. The handler registering to this DeviceListener can save the QOpts 86 * passed to it for re-using it later and must return that it wants the device 87 * to be/remain hidden or not. When the handler function decides the device 88 * shall not be hidden it will be added in qdev_device_add() and 89 * realized as any other device. Otherwise qdev_device_add() will return early 90 * without adding the device. The guest will not see a "hidden" device 91 * until it was marked don't hide and qdev_device_add called again. 92 * 93 */ 94 struct DeviceClass { 95 /*< private >*/ 96 ObjectClass parent_class; 97 /*< public >*/ 98 99 DECLARE_BITMAP(categories, DEVICE_CATEGORY_MAX); 100 const char *fw_name; 101 const char *desc; 102 103 /* 104 * The underscore at the end ensures a compile-time error if someone 105 * assigns to dc->props instead of using device_class_set_props. 106 */ 107 Property *props_; 108 109 /* 110 * Can this device be instantiated with -device / device_add? 111 * All devices should support instantiation with device_add, and 112 * this flag should not exist. But we're not there, yet. Some 113 * devices fail to instantiate with cryptic error messages. 114 * Others instantiate, but don't work. Exposing users to such 115 * behavior would be cruel; clearing this flag will protect them. 116 * It should never be cleared without a comment explaining why it 117 * is cleared. 118 * TODO remove once we're there 119 */ 120 bool user_creatable; 121 bool hotpluggable; 122 123 /* callbacks */ 124 /* 125 * Reset method here is deprecated and replaced by methods in the 126 * resettable class interface to implement a multi-phase reset. 127 * TODO: remove once every reset callback is unused 128 */ 129 DeviceReset reset; 130 DeviceRealize realize; 131 DeviceUnrealize unrealize; 132 133 /* device state */ 134 const VMStateDescription *vmsd; 135 136 /* Private to qdev / bus. */ 137 const char *bus_type; 138 }; 139 140 typedef struct NamedGPIOList NamedGPIOList; 141 142 struct NamedGPIOList { 143 char *name; 144 qemu_irq *in; 145 int num_in; 146 int num_out; 147 QLIST_ENTRY(NamedGPIOList) node; 148 }; 149 150 typedef struct Clock Clock; 151 typedef struct NamedClockList NamedClockList; 152 153 struct NamedClockList { 154 char *name; 155 Clock *clock; 156 bool output; 157 bool alias; 158 QLIST_ENTRY(NamedClockList) node; 159 }; 160 161 /** 162 * DeviceState: 163 * @realized: Indicates whether the device has been fully constructed. 164 * @reset: ResettableState for the device; handled by Resettable interface. 165 * 166 * This structure should not be accessed directly. We declare it here 167 * so that it can be embedded in individual device state structures. 168 */ 169 struct DeviceState { 170 /*< private >*/ 171 Object parent_obj; 172 /*< public >*/ 173 174 const char *id; 175 char *canonical_path; 176 bool realized; 177 bool pending_deleted_event; 178 QemuOpts *opts; 179 int hotplugged; 180 bool allow_unplug_during_migration; 181 BusState *parent_bus; 182 QLIST_HEAD(, NamedGPIOList) gpios; 183 QLIST_HEAD(, NamedClockList) clocks; 184 QLIST_HEAD(, BusState) child_bus; 185 int num_child_bus; 186 int instance_id_alias; 187 int alias_required_for_version; 188 ResettableState reset; 189 }; 190 191 struct DeviceListener { 192 void (*realize)(DeviceListener *listener, DeviceState *dev); 193 void (*unrealize)(DeviceListener *listener, DeviceState *dev); 194 /* 195 * This callback is called upon init of the DeviceState and allows to 196 * inform qdev that a device should be hidden, depending on the device 197 * opts, for example, to hide a standby device. 198 */ 199 int (*should_be_hidden)(DeviceListener *listener, QemuOpts *device_opts); 200 QTAILQ_ENTRY(DeviceListener) link; 201 }; 202 203 #define TYPE_BUS "bus" 204 DECLARE_OBJ_CHECKERS(BusState, BusClass, 205 BUS, TYPE_BUS) 206 207 struct BusClass { 208 ObjectClass parent_class; 209 210 /* FIXME first arg should be BusState */ 211 void (*print_dev)(Monitor *mon, DeviceState *dev, int indent); 212 char *(*get_dev_path)(DeviceState *dev); 213 214 /* 215 * This callback is used to create Open Firmware device path in accordance 216 * with OF spec http://forthworks.com/standards/of1275.pdf. Individual bus 217 * bindings can be found at http://playground.sun.com/1275/bindings/. 218 */ 219 char *(*get_fw_dev_path)(DeviceState *dev); 220 221 void (*reset)(BusState *bus); 222 223 /* 224 * Return whether the device can be added to @bus, 225 * based on the address that was set (via device properties) 226 * before realize. If not, on return @errp contains the 227 * human-readable error message. 228 */ 229 bool (*check_address)(BusState *bus, DeviceState *dev, Error **errp); 230 231 BusRealize realize; 232 BusUnrealize unrealize; 233 234 /* maximum devices allowed on the bus, 0: no limit. */ 235 int max_dev; 236 /* number of automatically allocated bus ids (e.g. ide.0) */ 237 int automatic_ids; 238 }; 239 240 typedef struct BusChild { 241 DeviceState *child; 242 int index; 243 QTAILQ_ENTRY(BusChild) sibling; 244 } BusChild; 245 246 #define QDEV_HOTPLUG_HANDLER_PROPERTY "hotplug-handler" 247 248 /** 249 * BusState: 250 * @hotplug_handler: link to a hotplug handler associated with bus. 251 * @reset: ResettableState for the bus; handled by Resettable interface. 252 */ 253 struct BusState { 254 Object obj; 255 DeviceState *parent; 256 char *name; 257 HotplugHandler *hotplug_handler; 258 int max_index; 259 bool realized; 260 int num_children; 261 QTAILQ_HEAD(, BusChild) children; 262 QLIST_ENTRY(BusState) sibling; 263 ResettableState reset; 264 }; 265 266 /** 267 * Property: 268 * @set_default: true if the default value should be set from @defval, 269 * in which case @info->set_default_value must not be NULL 270 * (if false then no default value is set by the property system 271 * and the field retains whatever value it was given by instance_init). 272 * @defval: default value for the property. This is used only if @set_default 273 * is true. 274 */ 275 struct Property { 276 const char *name; 277 const PropertyInfo *info; 278 ptrdiff_t offset; 279 uint8_t bitnr; 280 bool set_default; 281 union { 282 int64_t i; 283 uint64_t u; 284 } defval; 285 int arrayoffset; 286 const PropertyInfo *arrayinfo; 287 int arrayfieldsize; 288 const char *link_type; 289 }; 290 291 struct PropertyInfo { 292 const char *name; 293 const char *description; 294 const QEnumLookup *enum_table; 295 int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); 296 void (*set_default_value)(ObjectProperty *op, const Property *prop); 297 void (*create)(ObjectClass *oc, Property *prop); 298 ObjectPropertyAccessor *get; 299 ObjectPropertyAccessor *set; 300 ObjectPropertyRelease *release; 301 }; 302 303 /** 304 * GlobalProperty: 305 * @used: Set to true if property was used when initializing a device. 306 * @optional: If set to true, GlobalProperty will be skipped without errors 307 * if the property doesn't exist. 308 * 309 * An error is fatal for non-hotplugged devices, when the global is applied. 310 */ 311 typedef struct GlobalProperty { 312 const char *driver; 313 const char *property; 314 const char *value; 315 bool used; 316 bool optional; 317 } GlobalProperty; 318 319 static inline void 320 compat_props_add(GPtrArray *arr, 321 GlobalProperty props[], size_t nelem) 322 { 323 int i; 324 for (i = 0; i < nelem; i++) { 325 g_ptr_array_add(arr, (void *)&props[i]); 326 } 327 } 328 329 /*** Board API. This should go away once we have a machine config file. ***/ 330 331 /** 332 * qdev_new: Create a device on the heap 333 * @name: device type to create (we assert() that this type exists) 334 * 335 * This only allocates the memory and initializes the device state 336 * structure, ready for the caller to set properties if they wish. 337 * The device still needs to be realized. 338 * The returned object has a reference count of 1. 339 */ 340 DeviceState *qdev_new(const char *name); 341 /** 342 * qdev_try_new: Try to create a device on the heap 343 * @name: device type to create 344 * 345 * This is like qdev_new(), except it returns %NULL when type @name 346 * does not exist, rather than asserting. 347 */ 348 DeviceState *qdev_try_new(const char *name); 349 /** 350 * qdev_realize: Realize @dev. 351 * @dev: device to realize 352 * @bus: bus to plug it into (may be NULL) 353 * @errp: pointer to error object 354 * 355 * "Realize" the device, i.e. perform the second phase of device 356 * initialization. 357 * @dev must not be plugged into a bus already. 358 * If @bus, plug @dev into @bus. This takes a reference to @dev. 359 * If @dev has no QOM parent, make one up, taking another reference. 360 * On success, return true. 361 * On failure, store an error through @errp and return false. 362 * 363 * If you created @dev using qdev_new(), you probably want to use 364 * qdev_realize_and_unref() instead. 365 */ 366 bool qdev_realize(DeviceState *dev, BusState *bus, Error **errp); 367 /** 368 * qdev_realize_and_unref: Realize @dev and drop a reference 369 * @dev: device to realize 370 * @bus: bus to plug it into (may be NULL) 371 * @errp: pointer to error object 372 * 373 * Realize @dev and drop a reference. 374 * This is like qdev_realize(), except the caller must hold a 375 * (private) reference, which is dropped on return regardless of 376 * success or failure. Intended use:: 377 * 378 * dev = qdev_new(); 379 * [...] 380 * qdev_realize_and_unref(dev, bus, errp); 381 * 382 * Now @dev can go away without further ado. 383 * 384 * If you are embedding the device into some other QOM device and 385 * initialized it via some variant on object_initialize_child() then 386 * do not use this function, because that family of functions arrange 387 * for the only reference to the child device to be held by the parent 388 * via the child<> property, and so the reference-count-drop done here 389 * would be incorrect. For that use case you want qdev_realize(). 390 */ 391 bool qdev_realize_and_unref(DeviceState *dev, BusState *bus, Error **errp); 392 /** 393 * qdev_unrealize: Unrealize a device 394 * @dev: device to unrealize 395 * 396 * This function will "unrealize" a device, which is the first phase 397 * of correctly destroying a device that has been realized. It will: 398 * 399 * - unrealize any child buses by calling qbus_unrealize() 400 * (this will recursively unrealize any devices on those buses) 401 * - call the the unrealize method of @dev 402 * 403 * The device can then be freed by causing its reference count to go 404 * to zero. 405 * 406 * Warning: most devices in QEMU do not expect to be unrealized. Only 407 * devices which are hot-unpluggable should be unrealized (as part of 408 * the unplugging process); all other devices are expected to last for 409 * the life of the simulation and should not be unrealized and freed. 410 */ 411 void qdev_unrealize(DeviceState *dev); 412 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, 413 int required_for_version); 414 HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev); 415 HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev); 416 bool qdev_hotplug_allowed(DeviceState *dev, Error **errp); 417 /** 418 * qdev_get_hotplug_handler: Get handler responsible for device wiring 419 * 420 * Find HOTPLUG_HANDLER for @dev that provides [pre|un]plug callbacks for it. 421 * 422 * Note: in case @dev has a parent bus, it will be returned as handler unless 423 * machine handler overrides it. 424 * 425 * Returns: pointer to object that implements TYPE_HOTPLUG_HANDLER interface 426 * or NULL if there aren't any. 427 */ 428 HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev); 429 void qdev_unplug(DeviceState *dev, Error **errp); 430 void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, 431 DeviceState *dev, Error **errp); 432 void qdev_machine_creation_done(void); 433 bool qdev_machine_modified(void); 434 435 /** 436 * qdev_get_gpio_in: Get one of a device's anonymous input GPIO lines 437 * @dev: Device whose GPIO we want 438 * @n: Number of the anonymous GPIO line (which must be in range) 439 * 440 * Returns the qemu_irq corresponding to an anonymous input GPIO line 441 * (which the device has set up with qdev_init_gpio_in()). The index 442 * @n of the GPIO line must be valid (i.e. be at least 0 and less than 443 * the total number of anonymous input GPIOs the device has); this 444 * function will assert() if passed an invalid index. 445 * 446 * This function is intended to be used by board code or SoC "container" 447 * device models to wire up the GPIO lines; usually the return value 448 * will be passed to qdev_connect_gpio_out() or a similar function to 449 * connect another device's output GPIO line to this input. 450 * 451 * For named input GPIO lines, use qdev_get_gpio_in_named(). 452 */ 453 qemu_irq qdev_get_gpio_in(DeviceState *dev, int n); 454 /** 455 * qdev_get_gpio_in_named: Get one of a device's named input GPIO lines 456 * @dev: Device whose GPIO we want 457 * @name: Name of the input GPIO array 458 * @n: Number of the GPIO line in that array (which must be in range) 459 * 460 * Returns the qemu_irq corresponding to a named input GPIO line 461 * (which the device has set up with qdev_init_gpio_in_named()). 462 * The @name string must correspond to an input GPIO array which exists on 463 * the device, and the index @n of the GPIO line must be valid (i.e. 464 * be at least 0 and less than the total number of input GPIOs in that 465 * array); this function will assert() if passed an invalid name or index. 466 * 467 * For anonymous input GPIO lines, use qdev_get_gpio_in(). 468 */ 469 qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n); 470 471 /** 472 * qdev_connect_gpio_out: Connect one of a device's anonymous output GPIO lines 473 * @dev: Device whose GPIO to connect 474 * @n: Number of the anonymous output GPIO line (which must be in range) 475 * @pin: qemu_irq to connect the output line to 476 * 477 * This function connects an anonymous output GPIO line on a device 478 * up to an arbitrary qemu_irq, so that when the device asserts that 479 * output GPIO line, the qemu_irq's callback is invoked. 480 * The index @n of the GPIO line must be valid (i.e. be at least 0 and 481 * less than the total number of anonymous output GPIOs the device has 482 * created with qdev_init_gpio_out()); otherwise this function will assert(). 483 * 484 * Outbound GPIO lines can be connected to any qemu_irq, but the common 485 * case is connecting them to another device's inbound GPIO line, using 486 * the qemu_irq returned by qdev_get_gpio_in() or qdev_get_gpio_in_named(). 487 * 488 * It is not valid to try to connect one outbound GPIO to multiple 489 * qemu_irqs at once, or to connect multiple outbound GPIOs to the 490 * same qemu_irq. (Warning: there is no assertion or other guard to 491 * catch this error: the model will just not do the right thing.) 492 * Instead, for fan-out you can use the TYPE_IRQ_SPLIT device: connect 493 * a device's outbound GPIO to the splitter's input, and connect each 494 * of the splitter's outputs to a different device. For fan-in you 495 * can use the TYPE_OR_IRQ device, which is a model of a logical OR 496 * gate with multiple inputs and one output. 497 * 498 * For named output GPIO lines, use qdev_connect_gpio_out_named(). 499 */ 500 void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin); 501 /** 502 * qdev_connect_gpio_out: Connect one of a device's anonymous output GPIO lines 503 * @dev: Device whose GPIO to connect 504 * @name: Name of the output GPIO array 505 * @n: Number of the anonymous output GPIO line (which must be in range) 506 * @pin: qemu_irq to connect the output line to 507 * 508 * This function connects an anonymous output GPIO line on a device 509 * up to an arbitrary qemu_irq, so that when the device asserts that 510 * output GPIO line, the qemu_irq's callback is invoked. 511 * The @name string must correspond to an output GPIO array which exists on 512 * the device, and the index @n of the GPIO line must be valid (i.e. 513 * be at least 0 and less than the total number of input GPIOs in that 514 * array); this function will assert() if passed an invalid name or index. 515 * 516 * Outbound GPIO lines can be connected to any qemu_irq, but the common 517 * case is connecting them to another device's inbound GPIO line, using 518 * the qemu_irq returned by qdev_get_gpio_in() or qdev_get_gpio_in_named(). 519 * 520 * It is not valid to try to connect one outbound GPIO to multiple 521 * qemu_irqs at once, or to connect multiple outbound GPIOs to the 522 * same qemu_irq; see qdev_connect_gpio_out() for details. 523 * 524 * For named output GPIO lines, use qdev_connect_gpio_out_named(). 525 */ 526 void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n, 527 qemu_irq pin); 528 /** 529 * qdev_get_gpio_out_connector: Get the qemu_irq connected to an output GPIO 530 * @dev: Device whose output GPIO we are interested in 531 * @name: Name of the output GPIO array 532 * @n: Number of the output GPIO line within that array 533 * 534 * Returns whatever qemu_irq is currently connected to the specified 535 * output GPIO line of @dev. This will be NULL if the output GPIO line 536 * has never been wired up to the anything. Note that the qemu_irq 537 * returned does not belong to @dev -- it will be the input GPIO or 538 * IRQ of whichever device the board code has connected up to @dev's 539 * output GPIO. 540 * 541 * You probably don't need to use this function -- it is used only 542 * by the platform-bus subsystem. 543 */ 544 qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n); 545 /** 546 * qdev_intercept_gpio_out: Intercept an existing GPIO connection 547 * @dev: Device to intercept the outbound GPIO line from 548 * @icpt: New qemu_irq to connect instead 549 * @name: Name of the output GPIO array 550 * @n: Number of the GPIO line in the array 551 * 552 * This function is provided only for use by the qtest testing framework 553 * and is not suitable for use in non-testing parts of QEMU. 554 * 555 * This function breaks an existing connection of an outbound GPIO 556 * line from @dev, and replaces it with the new qemu_irq @icpt, as if 557 * ``qdev_connect_gpio_out_named(dev, icpt, name, n)`` had been called. 558 * The previously connected qemu_irq is returned, so it can be restored 559 * by a second call to qdev_intercept_gpio_out() if desired. 560 */ 561 qemu_irq qdev_intercept_gpio_out(DeviceState *dev, qemu_irq icpt, 562 const char *name, int n); 563 564 BusState *qdev_get_child_bus(DeviceState *dev, const char *name); 565 566 /*** Device API. ***/ 567 568 /** 569 * qdev_init_gpio_in: create an array of anonymous input GPIO lines 570 * @dev: Device to create input GPIOs for 571 * @handler: Function to call when GPIO line value is set 572 * @n: Number of GPIO lines to create 573 * 574 * Devices should use functions in the qdev_init_gpio_in* family in 575 * their instance_init or realize methods to create any input GPIO 576 * lines they need. There is no functional difference between 577 * anonymous and named GPIO lines. Stylistically, named GPIOs are 578 * preferable (easier to understand at callsites) unless a device 579 * has exactly one uniform kind of GPIO input whose purpose is obvious. 580 * Note that input GPIO lines can serve as 'sinks' for IRQ lines. 581 * 582 * See qdev_get_gpio_in() for how code that uses such a device can get 583 * hold of an input GPIO line to manipulate it. 584 */ 585 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n); 586 /** 587 * qdev_init_gpio_out: create an array of anonymous output GPIO lines 588 * @dev: Device to create output GPIOs for 589 * @pins: Pointer to qemu_irq or qemu_irq array for the GPIO lines 590 * @n: Number of GPIO lines to create 591 * 592 * Devices should use functions in the qdev_init_gpio_out* family 593 * in their instance_init or realize methods to create any output 594 * GPIO lines they need. There is no functional difference between 595 * anonymous and named GPIO lines. Stylistically, named GPIOs are 596 * preferable (easier to understand at callsites) unless a device 597 * has exactly one uniform kind of GPIO output whose purpose is obvious. 598 * 599 * The @pins argument should be a pointer to either a "qemu_irq" 600 * (if @n == 1) or a "qemu_irq []" array (if @n > 1) in the device's 601 * state structure. The device implementation can then raise and 602 * lower the GPIO line by calling qemu_set_irq(). (If anything is 603 * connected to the other end of the GPIO this will cause the handler 604 * function for that input GPIO to be called.) 605 * 606 * See qdev_connect_gpio_out() for how code that uses such a device 607 * can connect to one of its output GPIO lines. 608 */ 609 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n); 610 /** 611 * qdev_init_gpio_out: create an array of named output GPIO lines 612 * @dev: Device to create output GPIOs for 613 * @pins: Pointer to qemu_irq or qemu_irq array for the GPIO lines 614 * @name: Name to give this array of GPIO lines 615 * @n: Number of GPIO lines to create 616 * 617 * Like qdev_init_gpio_out(), but creates an array of GPIO output lines 618 * with a name. Code using the device can then connect these GPIO lines 619 * using qdev_connect_gpio_out_named(). 620 */ 621 void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins, 622 const char *name, int n); 623 /** 624 * qdev_init_gpio_in_named_with_opaque: create an array of input GPIO lines 625 * for the specified device 626 * 627 * @dev: Device to create input GPIOs for 628 * @handler: Function to call when GPIO line value is set 629 * @opaque: Opaque data pointer to pass to @handler 630 * @name: Name of the GPIO input (must be unique for this device) 631 * @n: Number of GPIO lines in this input set 632 */ 633 void qdev_init_gpio_in_named_with_opaque(DeviceState *dev, 634 qemu_irq_handler handler, 635 void *opaque, 636 const char *name, int n); 637 638 /** 639 * qdev_init_gpio_in_named: create an array of input GPIO lines 640 * for the specified device 641 * 642 * Like qdev_init_gpio_in_named_with_opaque(), but the opaque pointer 643 * passed to the handler is @dev (which is the most commonly desired behaviour). 644 */ 645 static inline void qdev_init_gpio_in_named(DeviceState *dev, 646 qemu_irq_handler handler, 647 const char *name, int n) 648 { 649 qdev_init_gpio_in_named_with_opaque(dev, handler, dev, name, n); 650 } 651 652 /** 653 * qdev_pass_gpios: create GPIO lines on container which pass through to device 654 * @dev: Device which has GPIO lines 655 * @container: Container device which needs to expose them 656 * @name: Name of GPIO array to pass through (NULL for the anonymous GPIO array) 657 * 658 * In QEMU, complicated devices like SoCs are often modelled with a 659 * "container" QOM device which itself contains other QOM devices and 660 * which wires them up appropriately. This function allows the container 661 * to create GPIO arrays on itself which simply pass through to a GPIO 662 * array of one of its internal devices. 663 * 664 * If @dev has both input and output GPIOs named @name then both will 665 * be passed through. It is not possible to pass a subset of the array 666 * with this function. 667 * 668 * To users of the container device, the GPIO array created on @container 669 * behaves exactly like any other. 670 */ 671 void qdev_pass_gpios(DeviceState *dev, DeviceState *container, 672 const char *name); 673 674 BusState *qdev_get_parent_bus(DeviceState *dev); 675 676 /*** BUS API. ***/ 677 678 DeviceState *qdev_find_recursive(BusState *bus, const char *id); 679 680 /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */ 681 typedef int (qbus_walkerfn)(BusState *bus, void *opaque); 682 typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque); 683 684 void qbus_create_inplace(void *bus, size_t size, const char *typename, 685 DeviceState *parent, const char *name); 686 BusState *qbus_create(const char *typename, DeviceState *parent, const char *name); 687 bool qbus_realize(BusState *bus, Error **errp); 688 void qbus_unrealize(BusState *bus); 689 690 /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion, 691 * < 0 if either devfn or busfn terminate walk somewhere in cursion, 692 * 0 otherwise. */ 693 int qbus_walk_children(BusState *bus, 694 qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn, 695 qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn, 696 void *opaque); 697 int qdev_walk_children(DeviceState *dev, 698 qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn, 699 qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn, 700 void *opaque); 701 702 /** 703 * @qdev_reset_all: 704 * Reset @dev. See @qbus_reset_all() for more details. 705 * 706 * Note: This function is deprecated and will be removed when it becomes unused. 707 * Please use device_cold_reset() now. 708 */ 709 void qdev_reset_all(DeviceState *dev); 710 void qdev_reset_all_fn(void *opaque); 711 712 /** 713 * @qbus_reset_all: 714 * @bus: Bus to be reset. 715 * 716 * Reset @bus and perform a bus-level ("hard") reset of all devices connected 717 * to it, including recursive processing of all buses below @bus itself. A 718 * hard reset means that qbus_reset_all will reset all state of the device. 719 * For PCI devices, for example, this will include the base address registers 720 * or configuration space. 721 * 722 * Note: This function is deprecated and will be removed when it becomes unused. 723 * Please use bus_cold_reset() now. 724 */ 725 void qbus_reset_all(BusState *bus); 726 void qbus_reset_all_fn(void *opaque); 727 728 /** 729 * device_cold_reset: 730 * Reset device @dev and perform a recursive processing using the resettable 731 * interface. It triggers a RESET_TYPE_COLD. 732 */ 733 void device_cold_reset(DeviceState *dev); 734 735 /** 736 * bus_cold_reset: 737 * 738 * Reset bus @bus and perform a recursive processing using the resettable 739 * interface. It triggers a RESET_TYPE_COLD. 740 */ 741 void bus_cold_reset(BusState *bus); 742 743 /** 744 * device_is_in_reset: 745 * Return true if the device @dev is currently being reset. 746 */ 747 bool device_is_in_reset(DeviceState *dev); 748 749 /** 750 * bus_is_in_reset: 751 * Return true if the bus @bus is currently being reset. 752 */ 753 bool bus_is_in_reset(BusState *bus); 754 755 /* This should go away once we get rid of the NULL bus hack */ 756 BusState *sysbus_get_default(void); 757 758 char *qdev_get_fw_dev_path(DeviceState *dev); 759 char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev); 760 761 /** 762 * @qdev_machine_init 763 * 764 * Initialize platform devices before machine init. This is a hack until full 765 * support for composition is added. 766 */ 767 void qdev_machine_init(void); 768 769 /** 770 * device_legacy_reset: 771 * 772 * Reset a single device (by calling the reset method). 773 * Note: This function is deprecated and will be removed when it becomes unused. 774 * Please use device_cold_reset() now. 775 */ 776 void device_legacy_reset(DeviceState *dev); 777 778 void device_class_set_props(DeviceClass *dc, Property *props); 779 780 /** 781 * device_class_set_parent_reset: 782 * TODO: remove the function when DeviceClass's reset method 783 * is not used anymore. 784 */ 785 void device_class_set_parent_reset(DeviceClass *dc, 786 DeviceReset dev_reset, 787 DeviceReset *parent_reset); 788 void device_class_set_parent_realize(DeviceClass *dc, 789 DeviceRealize dev_realize, 790 DeviceRealize *parent_realize); 791 void device_class_set_parent_unrealize(DeviceClass *dc, 792 DeviceUnrealize dev_unrealize, 793 DeviceUnrealize *parent_unrealize); 794 795 const VMStateDescription *qdev_get_vmsd(DeviceState *dev); 796 797 const char *qdev_fw_name(DeviceState *dev); 798 799 Object *qdev_get_machine(void); 800 801 /* FIXME: make this a link<> */ 802 bool qdev_set_parent_bus(DeviceState *dev, BusState *bus, Error **errp); 803 804 extern bool qdev_hotplug; 805 extern bool qdev_hot_removed; 806 807 char *qdev_get_dev_path(DeviceState *dev); 808 809 void qbus_set_hotplug_handler(BusState *bus, Object *handler); 810 void qbus_set_bus_hotplug_handler(BusState *bus); 811 812 static inline bool qbus_is_hotpluggable(BusState *bus) 813 { 814 return bus->hotplug_handler; 815 } 816 817 void device_listener_register(DeviceListener *listener); 818 void device_listener_unregister(DeviceListener *listener); 819 820 /** 821 * @qdev_should_hide_device: 822 * @opts: QemuOpts as passed on cmdline. 823 * 824 * Check if a device should be added. 825 * When a device is added via qdev_device_add() this will be called, 826 * and return if the device should be added now or not. 827 */ 828 bool qdev_should_hide_device(QemuOpts *opts); 829 830 #endif 831