@@ -424,24 +424,192 @@ void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,
424
424
void qdev_machine_creation_done (void );
425
425
bool qdev_machine_modified (void );
426
426
427
+ /**
428
+ * qdev_get_gpio_in: Get one of a device's anonymous input GPIO lines
429
+ * @dev: Device whose GPIO we want
430
+ * @n: Number of the anonymous GPIO line (which must be in range)
431
+ *
432
+ * Returns the qemu_irq corresponding to an anonymous input GPIO line
433
+ * (which the device has set up with qdev_init_gpio_in()). The index
434
+ * @n of the GPIO line must be valid (i.e. be at least 0 and less than
435
+ * the total number of anonymous input GPIOs the device has); this
436
+ * function will assert() if passed an invalid index.
437
+ *
438
+ * This function is intended to be used by board code or SoC "container"
439
+ * device models to wire up the GPIO lines; usually the return value
440
+ * will be passed to qdev_connect_gpio_out() or a similar function to
441
+ * connect another device's output GPIO line to this input.
442
+ *
443
+ * For named input GPIO lines, use qdev_get_gpio_in_named().
444
+ */
427
445
qemu_irq qdev_get_gpio_in (DeviceState * dev , int n );
446
+ /**
447
+ * qdev_get_gpio_in_named: Get one of a device's named input GPIO lines
448
+ * @dev: Device whose GPIO we want
449
+ * @name: Name of the input GPIO array
450
+ * @n: Number of the GPIO line in that array (which must be in range)
451
+ *
452
+ * Returns the qemu_irq corresponding to a named input GPIO line
453
+ * (which the device has set up with qdev_init_gpio_in_named()).
454
+ * The @name string must correspond to an input GPIO array which exists on
455
+ * the device, and the index @n of the GPIO line must be valid (i.e.
456
+ * be at least 0 and less than the total number of input GPIOs in that
457
+ * array); this function will assert() if passed an invalid name or index.
458
+ *
459
+ * For anonymous input GPIO lines, use qdev_get_gpio_in().
460
+ */
428
461
qemu_irq qdev_get_gpio_in_named (DeviceState * dev , const char * name , int n );
429
462
463
+ /**
464
+ * qdev_connect_gpio_out: Connect one of a device's anonymous output GPIO lines
465
+ * @dev: Device whose GPIO to connect
466
+ * @n: Number of the anonymous output GPIO line (which must be in range)
467
+ * @pin: qemu_irq to connect the output line to
468
+ *
469
+ * This function connects an anonymous output GPIO line on a device
470
+ * up to an arbitrary qemu_irq, so that when the device asserts that
471
+ * output GPIO line, the qemu_irq's callback is invoked.
472
+ * The index @n of the GPIO line must be valid (i.e. be at least 0 and
473
+ * less than the total number of anonymous output GPIOs the device has
474
+ * created with qdev_init_gpio_out()); otherwise this function will assert().
475
+ *
476
+ * Outbound GPIO lines can be connected to any qemu_irq, but the common
477
+ * case is connecting them to another device's inbound GPIO line, using
478
+ * the qemu_irq returned by qdev_get_gpio_in() or qdev_get_gpio_in_named().
479
+ *
480
+ * It is not valid to try to connect one outbound GPIO to multiple
481
+ * qemu_irqs at once, or to connect multiple outbound GPIOs to the
482
+ * same qemu_irq. (Warning: there is no assertion or other guard to
483
+ * catch this error: the model will just not do the right thing.)
484
+ * Instead, for fan-out you can use the TYPE_IRQ_SPLIT device: connect
485
+ * a device's outbound GPIO to the splitter's input, and connect each
486
+ * of the splitter's outputs to a different device. For fan-in you
487
+ * can use the TYPE_OR_IRQ device, which is a model of a logical OR
488
+ * gate with multiple inputs and one output.
489
+ *
490
+ * For named output GPIO lines, use qdev_connect_gpio_out_named().
491
+ */
430
492
void qdev_connect_gpio_out (DeviceState * dev , int n , qemu_irq pin );
493
+ /**
494
+ * qdev_connect_gpio_out: Connect one of a device's anonymous output GPIO lines
495
+ * @dev: Device whose GPIO to connect
496
+ * @name: Name of the output GPIO array
497
+ * @n: Number of the anonymous output GPIO line (which must be in range)
498
+ * @pin: qemu_irq to connect the output line to
499
+ *
500
+ * This function connects an anonymous output GPIO line on a device
501
+ * up to an arbitrary qemu_irq, so that when the device asserts that
502
+ * output GPIO line, the qemu_irq's callback is invoked.
503
+ * The @name string must correspond to an output GPIO array which exists on
504
+ * the device, and the index @n of the GPIO line must be valid (i.e.
505
+ * be at least 0 and less than the total number of input GPIOs in that
506
+ * array); this function will assert() if passed an invalid name or index.
507
+ *
508
+ * Outbound GPIO lines can be connected to any qemu_irq, but the common
509
+ * case is connecting them to another device's inbound GPIO line, using
510
+ * the qemu_irq returned by qdev_get_gpio_in() or qdev_get_gpio_in_named().
511
+ *
512
+ * It is not valid to try to connect one outbound GPIO to multiple
513
+ * qemu_irqs at once, or to connect multiple outbound GPIOs to the
514
+ * same qemu_irq; see qdev_connect_gpio_out() for details.
515
+ *
516
+ * For named output GPIO lines, use qdev_connect_gpio_out_named().
517
+ */
431
518
void qdev_connect_gpio_out_named (DeviceState * dev , const char * name , int n ,
432
519
qemu_irq pin );
520
+ /**
521
+ * qdev_get_gpio_out_connector: Get the qemu_irq connected to an output GPIO
522
+ * @dev: Device whose output GPIO we are interested in
523
+ * @name: Name of the output GPIO array
524
+ * @n: Number of the output GPIO line within that array
525
+ *
526
+ * Returns whatever qemu_irq is currently connected to the specified
527
+ * output GPIO line of @dev. This will be NULL if the output GPIO line
528
+ * has never been wired up to the anything. Note that the qemu_irq
529
+ * returned does not belong to @dev -- it will be the input GPIO or
530
+ * IRQ of whichever device the board code has connected up to @dev's
531
+ * output GPIO.
532
+ *
533
+ * You probably don't need to use this function -- it is used only
534
+ * by the platform-bus subsystem.
535
+ */
433
536
qemu_irq qdev_get_gpio_out_connector (DeviceState * dev , const char * name , int n );
537
+ /**
538
+ * qdev_intercept_gpio_out: Intercept an existing GPIO connection
539
+ * @dev: Device to intercept the outbound GPIO line from
540
+ * @icpt: New qemu_irq to connect instead
541
+ * @name: Name of the output GPIO array
542
+ * @n: Number of the GPIO line in the array
543
+ *
544
+ * This function is provided only for use by the qtest testing framework
545
+ * and is not suitable for use in non-testing parts of QEMU.
546
+ *
547
+ * This function breaks an existing connection of an outbound GPIO
548
+ * line from @dev, and replaces it with the new qemu_irq @icpt, as if
549
+ * ``qdev_connect_gpio_out_named(dev, icpt, name, n)`` had been called.
550
+ * The previously connected qemu_irq is returned, so it can be restored
551
+ * by a second call to qdev_intercept_gpio_out() if desired.
552
+ */
434
553
qemu_irq qdev_intercept_gpio_out (DeviceState * dev , qemu_irq icpt ,
435
554
const char * name , int n );
436
555
437
556
BusState * qdev_get_child_bus (DeviceState * dev , const char * name );
438
557
439
558
/*** Device API. ***/
440
559
441
- /* Register device properties. */
442
- /* GPIO inputs also double as IRQ sinks. */
560
+ /**
561
+ * qdev_init_gpio_in: create an array of anonymous input GPIO lines
562
+ * @dev: Device to create input GPIOs for
563
+ * @handler: Function to call when GPIO line value is set
564
+ * @n: Number of GPIO lines to create
565
+ *
566
+ * Devices should use functions in the qdev_init_gpio_in* family in
567
+ * their instance_init or realize methods to create any input GPIO
568
+ * lines they need. There is no functional difference between
569
+ * anonymous and named GPIO lines. Stylistically, named GPIOs are
570
+ * preferable (easier to understand at callsites) unless a device
571
+ * has exactly one uniform kind of GPIO input whose purpose is obvious.
572
+ * Note that input GPIO lines can serve as 'sinks' for IRQ lines.
573
+ *
574
+ * See qdev_get_gpio_in() for how code that uses such a device can get
575
+ * hold of an input GPIO line to manipulate it.
576
+ */
443
577
void qdev_init_gpio_in (DeviceState * dev , qemu_irq_handler handler , int n );
578
+ /**
579
+ * qdev_init_gpio_out: create an array of anonymous output GPIO lines
580
+ * @dev: Device to create output GPIOs for
581
+ * @pins: Pointer to qemu_irq or qemu_irq array for the GPIO lines
582
+ * @n: Number of GPIO lines to create
583
+ *
584
+ * Devices should use functions in the qdev_init_gpio_out* family
585
+ * in their instance_init or realize methods to create any output
586
+ * GPIO lines they need. There is no functional difference between
587
+ * anonymous and named GPIO lines. Stylistically, named GPIOs are
588
+ * preferable (easier to understand at callsites) unless a device
589
+ * has exactly one uniform kind of GPIO output whose purpose is obvious.
590
+ *
591
+ * The @pins argument should be a pointer to either a "qemu_irq"
592
+ * (if @n == 1) or a "qemu_irq []" array (if @n > 1) in the device's
593
+ * state structure. The device implementation can then raise and
594
+ * lower the GPIO line by calling qemu_set_irq(). (If anything is
595
+ * connected to the other end of the GPIO this will cause the handler
596
+ * function for that input GPIO to be called.)
597
+ *
598
+ * See qdev_connect_gpio_out() for how code that uses such a device
599
+ * can connect to one of its output GPIO lines.
600
+ */
444
601
void qdev_init_gpio_out (DeviceState * dev , qemu_irq * pins , int n );
602
+ /**
603
+ * qdev_init_gpio_out: create an array of named output GPIO lines
604
+ * @dev: Device to create output GPIOs for
605
+ * @pins: Pointer to qemu_irq or qemu_irq array for the GPIO lines
606
+ * @name: Name to give this array of GPIO lines
607
+ * @n: Number of GPIO lines to create
608
+ *
609
+ * Like qdev_init_gpio_out(), but creates an array of GPIO output lines
610
+ * with a name. Code using the device can then connect these GPIO lines
611
+ * using qdev_connect_gpio_out_named().
612
+ */
445
613
void qdev_init_gpio_out_named (DeviceState * dev , qemu_irq * pins ,
446
614
const char * name , int n );
447
615
/**
@@ -473,6 +641,25 @@ static inline void qdev_init_gpio_in_named(DeviceState *dev,
473
641
qdev_init_gpio_in_named_with_opaque (dev , handler , dev , name , n );
474
642
}
475
643
644
+ /**
645
+ * qdev_pass_gpios: create GPIO lines on container which pass through to device
646
+ * @dev: Device which has GPIO lines
647
+ * @container: Container device which needs to expose them
648
+ * @name: Name of GPIO array to pass through (NULL for the anonymous GPIO array)
649
+ *
650
+ * In QEMU, complicated devices like SoCs are often modelled with a
651
+ * "container" QOM device which itself contains other QOM devices and
652
+ * which wires them up appropriately. This function allows the container
653
+ * to create GPIO arrays on itself which simply pass through to a GPIO
654
+ * array of one of its internal devices.
655
+ *
656
+ * If @dev has both input and output GPIOs named @name then both will
657
+ * be passed through. It is not possible to pass a subset of the array
658
+ * with this function.
659
+ *
660
+ * To users of the container device, the GPIO array created on @container
661
+ * behaves exactly like any other.
662
+ */
476
663
void qdev_pass_gpios (DeviceState * dev , DeviceState * container ,
477
664
const char * name );
478
665
0 commit comments