Skip to contentSkip to conversation

hw/sysbus: Document GPIO related functions

PATCH In review Philippe Mathieu-Daudé 3 participants 9 messages Dec 29, 2021 – Jan 6, 2022

lore
Share & tools
lore
#0 lore raw

cover hw/sysbus: Document GPIO related functions

Reduce the scope of a pair of qdev/sysbus functions, then document the sysbus functions related to creating and connecting GPIO lines.

Based-on: <[email protected]>

Philippe Mathieu-Daudé (3):
hw/qdev: Restrict qdev_get_gpio_out_connector() to qdev-internal.h hw/sysbus: Restrict sysbus_get_connected_irq() to sysbus-internal.h hw/sysbus: Document GPIO related functions

 hw/core/qdev-internal.h   | 15 +++++++++
 hw/core/sysbus-internal.h | 16 +++++++++
 include/hw/qdev-core.h    | 18 ----------
 include/hw/sysbus.h       | 69 ++++++++++++++++++++++++++++++++++++---
 hw/core/gpio.c            |  1 +
 hw/core/platform-bus.c    |  2 +-
 hw/core/sysbus.c          |  2 ++
 7 files changed, 99 insertions(+), 24 deletions(-)
 create mode 100644 hw/core/qdev-internal.h
 create mode 100644 hw/core/sysbus-internal.h
Signature · 1 line
2.33.1
#1 lore raw

PATCH 1/3 hw/qdev: Restrict qdev_get_gpio_out_connector() to qdev-internal.h

qdev_get_gpio_out_connector() is called by sysbus_get_connected_irq() which is only used by platform-bus.c; restrict it to hw/core/ by adding a local "qdev-internal.h" header.

---
 hw/core/qdev-internal.h | 15 +++++++++++++++
 include/hw/qdev-core.h  | 18 ------------------
 hw/core/gpio.c          |  1 +
 hw/core/sysbus.c        |  1 +
 4 files changed, 17 insertions(+), 18 deletions(-)
 create mode 100644 hw/core/qdev-internal.h
hw/core/qdev-internal.h new file +15 -0
new file mode 100644
index 00000000000..6ec17d0ea70
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * qdev internal helpers
+ *
+ * Copyright (c) 2009-2021 QEMU contributors
+ */
+#ifndef HW_CORE_QDEV_INTERNAL_H
+#define HW_CORE_QDEV_INTERNAL_H
+
+#include "hw/qdev-core.h"
+
+/* Following functions are only used by the platform-bus subsystem */
+qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n);
+
+#endif /* HW_CORE_QDEV_INTERNAL_H */
include/hw/qdev-core.h +0 -18
index d19c9417520..655899654bb 100644
@@ -532,24 +532,6 @@ void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
 void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
                                  qemu_irq input_pin);
 
-/**
- * qdev_get_gpio_out_connector: Get the qemu_irq connected to an output GPIO
- * @dev: Device whose output GPIO we are interested in
- * @name: Name of the output GPIO array
- * @n: Number of the output GPIO line within that array
- *
- * Returns whatever qemu_irq is currently connected to the specified
- * output GPIO line of @dev. This will be NULL if the output GPIO line
- * has never been wired up to the anything.  Note that the qemu_irq
- * returned does not belong to @dev -- it will be the input GPIO or
- * IRQ of whichever device the board code has connected up to @dev's
- * output GPIO.
- *
- * You probably don't need to use this function -- it is used only
- * by the platform-bus subsystem.
- */
-qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n);
-
 /**
  * qdev_intercept_gpio_out: Intercept an existing GPIO connection
  * @dev: Device to intercept the outbound GPIO line from
hw/core/gpio.c +1 -0
index 80d07a6ec99..513ccbd1062 100644
@@ -21,6 +21,7 @@
 #include "hw/qdev-core.h"
 #include "hw/irq.h"
 #include "qapi/error.h"
+#include "qdev-internal.h"
 
 static NamedGPIOList *qdev_get_named_gpio_list(DeviceState *dev,
                                                const char *name)
hw/core/sysbus.c +1 -0
index 05c1da3d311..0e6773c8df7 100644
@@ -23,6 +23,7 @@
 #include "hw/sysbus.h"
 #include "monitor/monitor.h"
 #include "exec/address-spaces.h"
+#include "qdev-internal.h"
 
 static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
 static char *sysbus_get_fw_dev_path(DeviceState *dev);
Signature · 1 line
2.33.1
Reviewed-by Yanan Wang on v1 1/3
#2 lore raw

Re: [PATCH 1/3] hw/qdev: Restrict qdev_get_gpio_out_connector() to qdev-internal.h

Hi,

Quoted 21 lines · Philippe Mathieu-Daudé

qdev_get_gpio_out_connector() is called by sysbus_get_connected_irq() which is only used by platform-bus.c; restrict it to hw/core/ by adding a local "qdev-internal.h" header.

---
  hw/core/qdev-internal.h | 15 +++++++++++++++
  include/hw/qdev-core.h  | 18 ------------------
  hw/core/gpio.c          |  1 +
  hw/core/sysbus.c        |  1 +
  4 files changed, 17 insertions(+), 18 deletions(-)

create mode 100644 hw/core/qdev-internal.h

hw/core/qdev-internal.h new file +2 -0
new file mode 100644
index 00000000000..6ec17d0ea70
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*

hw/core/qdev-internal.h line 12

Quoted 10 lines
hw/core/qdev-internal.h new file +10 -0
+ * qdev internal helpers
+ *
+ * Copyright (c) 2009-2021 QEMU contributors
+ */
+#ifndef HW_CORE_QDEV_INTERNAL_H
+#define HW_CORE_QDEV_INTERNAL_H
+
+#include "hw/qdev-core.h"
+
+/* Following functions are only used by the platform-bus subsystem */

Could it be better to also keep the original function comment here?

Quoted 49 lines
hw/core/qdev-internal.h new file +3 -0
+qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n);
+
+#endif /* HW_CORE_QDEV_INTERNAL_H */
include/hw/qdev-core.h +0 -18
index d19c9417520..655899654bb 100644
@@ -532,24 +532,6 @@ void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
  void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
                                   qemu_irq input_pin);
 
-/**
- * qdev_get_gpio_out_connector: Get the qemu_irq connected to an output GPIO
- * @dev: Device whose output GPIO we are interested in
- * @name: Name of the output GPIO array
- * @n: Number of the output GPIO line within that array
- *
- * Returns whatever qemu_irq is currently connected to the specified
- * output GPIO line of @dev. This will be NULL if the output GPIO line
- * has never been wired up to the anything.  Note that the qemu_irq
- * returned does not belong to @dev -- it will be the input GPIO or
- * IRQ of whichever device the board code has connected up to @dev's
- * output GPIO.
- *
- * You probably don't need to use this function -- it is used only
- * by the platform-bus subsystem.
- */
-qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n);
-
  /**
   * qdev_intercept_gpio_out: Intercept an existing GPIO connection
   * @dev: Device to intercept the outbound GPIO line from
hw/core/gpio.c +1 -0
index 80d07a6ec99..513ccbd1062 100644
@@ -21,6 +21,7 @@
  #include "hw/qdev-core.h"
  #include "hw/irq.h"
  #include "qapi/error.h"
+#include "qdev-internal.h"
 
  static NamedGPIOList *qdev_get_named_gpio_list(DeviceState *dev,
                                                 const char *name)
hw/core/sysbus.c +0 -0
index 05c1da3d311..0e6773c8df7 100644

hw/core/sysbus.c line 29

Quoted 7 lines
hw/core/sysbus.c +1 -0
@@ -23,6 +23,7 @@
  #include "hw/sysbus.h"
  #include "monitor/monitor.h"
  #include "exec/address-spaces.h"
+#include "qdev-internal.h"
 
  static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
  static char *sysbus_get_fw_dev_path(DeviceState *dev);

Otherwise, the tweak looks reasonable:

Thanks,
Yanan

#3 lore raw

Re: [PATCH 1/3] hw/qdev: Restrict qdev_get_gpio_out_connector() to qdev-internal.h

Quoted 27 lines · wangyanan (Y)

Hi,

Quoted 24 lines · Philippe Mathieu-Daudé

qdev_get_gpio_out_connector() is called by sysbus_get_connected_irq() which is only used by platform-bus.c; restrict it to hw/core/ by adding a local "qdev-internal.h" header.

---
  hw/core/qdev-internal.h | 15 +++++++++++++++
  include/hw/qdev-core.h  | 18 ------------------
  hw/core/gpio.c          |  1 +
  hw/core/sysbus.c        |  1 +

  4 files changed, 17 insertions(+), 18 deletions(-)

  create mode 100644 hw/core/qdev-internal.h

hw/core/qdev-internal.h new file +5 -0
new file mode 100644
index 00000000000..6ec17d0ea70
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * qdev internal helpers
+ *
+ * Copyright (c) 2009-2021 QEMU contributors
Quoted 8 lines

hw/core/qdev-internal.h line 12

Quoted 7 lines
hw/core/qdev-internal.h new file +7 -0
+ */
+#ifndef HW_CORE_QDEV_INTERNAL_H
+#define HW_CORE_QDEV_INTERNAL_H
+
+#include "hw/qdev-core.h"
+
+/* Following functions are only used by the platform-bus subsystem */

Could it be better to also keep the original function comment here?

We could, but this include being now internal, it seems superfluous.

Since Peter documented this function, let see if he has an preference.

Quoted 60 lines
Quoted 56 lines
hw/core/qdev-internal.h new file +1 -0
+qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char

*name, int n);

hw/core/qdev-internal.h new file +2 -0
+
+#endif /* HW_CORE_QDEV_INTERNAL_H */
include/hw/qdev-core.h +0 -0
index d19c9417520..655899654bb 100644
@@ -532,24 +532,6 @@ void qdev_connect_gpio_out(DeviceState *dev, int
 n, qemu_irq pin);
   void qdev_connect_gpio_out_named(DeviceState *dev, const char *name,
 int n,
                                    qemu_irq input_pin);

  -/**
- * qdev_get_gpio_out_connector: Get the qemu_irq connected to an output GPIO
- * @dev: Device whose output GPIO we are interested in
- * @name: Name of the output GPIO array
- * @n: Number of the output GPIO line within that array
- *
- * Returns whatever qemu_irq is currently connected to the specified
- * output GPIO line of @dev. This will be NULL if the output GPIO line
- * has never been wired up to the anything.  Note that the qemu_irq
- * returned does not belong to @dev -- it will be the input GPIO or
- * IRQ of whichever device the board code has connected up to @dev's
- * output GPIO.
- *
- * You probably don't need to use this function -- it is used only
- * by the platform-bus subsystem.
- */
-qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n);
-
  /**
   * qdev_intercept_gpio_out: Intercept an existing GPIO connection
   * @dev: Device to intercept the outbound GPIO line from

hw/core/gpio.c +1 -0
index 80d07a6ec99..513ccbd1062 100644
@@ -21,6 +21,7 @@
   #include "hw/qdev-core.h"
   #include "hw/irq.h"
   #include "qapi/error.h"
+#include "qdev-internal.h"
     static NamedGPIOList *qdev_get_named_gpio_list(DeviceState *dev,
                                                  const char *name)
hw/core/sysbus.c +1 -0
index 05c1da3d311..0e6773c8df7 100644
@@ -23,6 +23,7 @@
   #include "hw/sysbus.h"
   #include "monitor/monitor.h"
   #include "exec/address-spaces.h"
+#include "qdev-internal.h"
Quoted 3 lines

    static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
  static char *sysbus_get_fw_dev_path(DeviceState *dev);

Otherwise, the tweak looks reasonable:

Quoted 1 line

Thanks,

Phil.

#4 lore raw

Re: [PATCH 1/3] hw/qdev: Restrict qdev_get_gpio_out_connector() to qdev-internal.h

Quoted 36 lines · Philippe Mathieu-Daudé
Quoted 27 lines · wangyanan (Y)

Hi,

Quoted 24 lines · Philippe Mathieu-Daudé

qdev_get_gpio_out_connector() is called by sysbus_get_connected_irq() which is only used by platform-bus.c; restrict it to hw/core/ by adding a local "qdev-internal.h" header.

---
   hw/core/qdev-internal.h | 15 +++++++++++++++
   include/hw/qdev-core.h  | 18 ------------------
   hw/core/gpio.c          |  1 +
   hw/core/sysbus.c        |  1 +
   4 files changed, 17 insertions(+), 18 deletions(-)

  create mode 100644 hw/core/qdev-internal.h

hw/core/qdev-internal.h new file +5 -0
new file mode 100644
index 00000000000..6ec17d0ea70
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * qdev internal helpers
+ *
+ * Copyright (c) 2009-2021 QEMU contributors
Quoted 8 lines

hw/core/qdev-internal.h line 12

Quoted 7 lines
hw/core/qdev-internal.h new file +7 -0
+ */
+#ifndef HW_CORE_QDEV_INTERNAL_H
+#define HW_CORE_QDEV_INTERNAL_H
+
+#include "hw/qdev-core.h"
+
+/* Following functions are only used by the platform-bus subsystem */

Could it be better to also keep the original function comment here?

Quoted 1 line

We could, but this include being now internal, it seems superfluous.

Ok, makes sense to me. :)

Thanks,
Yanan

Quoted 68 lines

Since Peter documented this function, let see if he has an preference.

Quoted 60 lines
Quoted 52 lines
hw/core/qdev-internal.h new file +1 -0
+qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char

*name, int n);

hw/core/qdev-internal.h new file +2 -0
+
+#endif /* HW_CORE_QDEV_INTERNAL_H */
include/hw/qdev-core.h +0 -1
index d19c9417520..655899654bb 100644
@@ -532,24 +532,6 @@ void qdev_connect_gpio_out(DeviceState *dev, int
 n, qemu_irq pin);
   void qdev_connect_gpio_out_named(DeviceState *dev, const char *name,
 int n,
                                    qemu_irq input_pin);
   -/**
- * qdev_get_gpio_out_connector: Get the qemu_irq connected to an

output GPIO
- * @dev: Device whose output GPIO we are interested in
- * @name: Name of the output GPIO array
- * @n: Number of the output GPIO line within that array
- *
- * Returns whatever qemu_irq is currently connected to the specified
- * output GPIO line of @dev. This will be NULL if the output GPIO line
- * has never been wired up to the anything.  Note that the qemu_irq
- * returned does not belong to @dev -- it will be the input GPIO or
- * IRQ of whichever device the board code has connected up to @dev's
- * output GPIO.
- *
- * You probably don't need to use this function -- it is used only
- * by the platform-bus subsystem.
- */
-qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n);

include/hw/qdev-core.h +0 -1
-
   /**
    * qdev_intercept_gpio_out: Intercept an existing GPIO connection
    * @dev: Device to intercept the outbound GPIO line from
hw/core/gpio.c +1 -0
index 80d07a6ec99..513ccbd1062 100644
@@ -21,6 +21,7 @@
   #include "hw/qdev-core.h"
   #include "hw/irq.h"
   #include "qapi/error.h"
+#include "qdev-internal.h"
     static NamedGPIOList *qdev_get_named_gpio_list(DeviceState *dev,
                                                  const char *name)
hw/core/sysbus.c +0 -0
index 05c1da3d311..0e6773c8df7 100644

hw/core/sysbus.c line 29

Quoted 7 lines
hw/core/sysbus.c +1 -0
@@ -23,6 +23,7 @@
   #include "hw/sysbus.h"
   #include "monitor/monitor.h"
   #include "exec/address-spaces.h"
+#include "qdev-internal.h"
     static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int
 indent);
   static char *sysbus_get_fw_dev_path(DeviceState *dev);

Otherwise, the tweak looks reasonable:

Quoted 1 line

Thanks,

Phil.

.

#5 lore raw

PATCH 2/3 hw/sysbus: Restrict sysbus_get_connected_irq() to sysbus-internal.h

In reply to Philippe Mathieu-Daudé

sysbus_get_connected_irq() and sysbus_is_irq_connected() are only used by platform-bus.c; restrict them to hw/core/ by adding a local "sysbus-internal.h" header.

---
 hw/core/sysbus-internal.h | 16 ++++++++++++++++
 include/hw/sysbus.h       |  2 --
 hw/core/platform-bus.c    |  2 +-
 hw/core/sysbus.c          |  1 +
 4 files changed, 18 insertions(+), 3 deletions(-)
 create mode 100644 hw/core/sysbus-internal.h
hw/core/sysbus-internal.h new file +16 -0
new file mode 100644
index 00000000000..991b3e3159c
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * SysBus internal helpers
+ *
+ * Copyright (c) 2021 QEMU contributors
+ */
+#ifndef HW_CORE_SYSBUS_INTERNAL_H
+#define HW_CORE_SYSBUS_INTERNAL_H
+
+#include "hw/sysbus.h"
+
+/* Following functions are only used by the platform-bus subsystem */
+qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n);
+bool sysbus_is_irq_connected(SysBusDevice *dev, int n);
+
+#endif /* HW_CORE_SYSBUS_INTERNAL_H */
include/hw/sysbus.h +0 -2
index 3564b7b6a22..24645ee7996 100644
@@ -77,8 +77,6 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size);
 bool sysbus_has_irq(SysBusDevice *dev, int n);
 bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n);
 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
-bool sysbus_is_irq_connected(SysBusDevice *dev, int n);
-qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n);
 void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
 void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
                              int priority);
hw/core/platform-bus.c +1 -1
index b8487b26b67..016fb71eba1 100644
@@ -25,7 +25,7 @@
 #include "qapi/error.h"
 #include "qemu/error-report.h"
 #include "qemu/module.h"
-
+#include "sysbus-internal.h"
 
 /*
  * Returns the PlatformBus IRQ number for a SysBusDevice irq number or -1 if
hw/core/sysbus.c +1 -0
index 0e6773c8df7..dcd7beda184 100644
@@ -24,6 +24,7 @@
 #include "monitor/monitor.h"
 #include "exec/address-spaces.h"
 #include "qdev-internal.h"
+#include "sysbus-internal.h"
 
 static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
 static char *sysbus_get_fw_dev_path(DeviceState *dev);
Signature · 1 line
2.33.1
Reviewed-by Yanan Wang on v1 2/3
#6 lore raw

Re: [PATCH 2/3] hw/sysbus: Restrict sysbus_get_connected_irq() to sysbus-internal.h

Quoted 4 lines · Philippe Mathieu-Daudé

sysbus_get_connected_irq() and sysbus_is_irq_connected() are only used by platform-bus.c; restrict them to hw/core/ by adding a local "sysbus-internal.h" header.

Quoted 8 lines
---
  hw/core/sysbus-internal.h | 16 ++++++++++++++++
  include/hw/sysbus.h       |  2 --
  hw/core/platform-bus.c    |  2 +-
  hw/core/sysbus.c          |  1 +
  4 files changed, 18 insertions(+), 3 deletions(-)

create mode 100644 hw/core/sysbus-internal.h

Thanks,
Yanan

Quoted 60 lines
hw/core/sysbus-internal.h new file +16 -0
new file mode 100644
index 00000000000..991b3e3159c
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * SysBus internal helpers
+ *
+ * Copyright (c) 2021 QEMU contributors
+ */
+#ifndef HW_CORE_SYSBUS_INTERNAL_H
+#define HW_CORE_SYSBUS_INTERNAL_H
+
+#include "hw/sysbus.h"
+
+/* Following functions are only used by the platform-bus subsystem */
+qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n);
+bool sysbus_is_irq_connected(SysBusDevice *dev, int n);
+
+#endif /* HW_CORE_SYSBUS_INTERNAL_H */
include/hw/sysbus.h +0 -2
index 3564b7b6a22..24645ee7996 100644
@@ -77,8 +77,6 @@ void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size);
  bool sysbus_has_irq(SysBusDevice *dev, int n);
  bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n);
  void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
-bool sysbus_is_irq_connected(SysBusDevice *dev, int n);
-qemu_irq sysbus_get_connected_irq(SysBusDevice *dev, int n);
  void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
  void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
                               int priority);
hw/core/platform-bus.c +1 -1
index b8487b26b67..016fb71eba1 100644
@@ -25,7 +25,7 @@
  #include "qapi/error.h"
  #include "qemu/error-report.h"
  #include "qemu/module.h"
-
+#include "sysbus-internal.h"
 
  /*
   * Returns the PlatformBus IRQ number for a SysBusDevice irq number or -1 if
hw/core/sysbus.c +1 -0
index 0e6773c8df7..dcd7beda184 100644
@@ -24,6 +24,7 @@
  #include "monitor/monitor.h"
  #include "exec/address-spaces.h"
  #include "qdev-internal.h"
+#include "sysbus-internal.h"
 
  static void sysbus_dev_print(Monitor *mon, DeviceState *dev, int indent);
  static char *sysbus_get_fw_dev_path(DeviceState *dev);
#7 lore raw

PATCH 3/3 hw/sysbus: Document GPIO related functions

In reply to Philippe Mathieu-Daudé

Similarly to cd07d7f9f51 ("qdev: Document GPIO related functions"), add documentation comments for the various sysbus functions related to creating and connecting GPIO lines.

---
 include/hw/sysbus.h | 67 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 64 insertions(+), 3 deletions(-)
include/hw/sysbus.h +64 -3
index 24645ee7996..7b2b7c7faaa 100644
@@ -69,14 +69,75 @@ typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);
 
 void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
 MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
-void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);
-void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
-void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size);
 
+/**
+ * sysbus_init_irq: Create an output GPIO line
+ * @dev: Sysbus device to create output GPIO for
+ * @irq: Pointer to qemu_irq for the GPIO lines
+ *
+ * Sysbus devices should use this function in their instance_init
+ * or realize methods to create any output GPIO lines they need.
+ *
+ * The @irq argument should be a pointer to either a "qemu_irq" in
+ * the device's state structure. The device implementation can then raise
+ * and lower the GPIO line by calling qemu_set_irq(). (If anything is
+ * connected to the other end of the GPIO this will cause the handler
+ * function for that input GPIO to be called.)
+ *
+ * See sysbus_connect_irq() for how code that uses such a device can
+ * connect to one of its output GPIO lines.
+ *
+ * There is no need to release the @pins allocated array because it
+ * will be automatically released when @dev calls its instance_finalize()
+ * handler.
+ */
+void sysbus_init_irq(SysBusDevice *dev, qemu_irq *irq);
+
+/**
+ * sysbus_pass_irq: Create GPIO lines on container which pass through
+ *                  to a target device
+ * @dev: Device which needs to expose GPIO lines
+ * @target: Device which has GPIO lines
+ *
+ * This function allows a container device to create GPIO arrays on itself
+ * which simply pass through to a GPIO array of another device. It is
+ * useful when modelling complex devices such system-on-chip, where a
+ * sysbus device contains other sysbus devices.
+ *
+ * It is not possible to pass a subset of the GPIO lines with this function.
+ *
+ * To users of the container sysbus device, the GPIO array created on @dev
+ * behaves exactly like any other.
+ */
+void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
+
+void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size);
 
 bool sysbus_has_irq(SysBusDevice *dev, int n);
 bool sysbus_has_mmio(SysBusDevice *dev, unsigned int n);
+
+/**
+ * sysbus_connect_irq: Connect a sysbus device output GPIO line
+ * @dev: sysbus device whose GPIO to connect
+ * @n: Number of the output GPIO line (which must be in range)
+ * @pin: qemu_irq to connect the output line to
+ *
+ * This function connects an output GPIO line on a sysbus device
+ * up to an arbitrary qemu_irq, so that when the device asserts that
+ * output GPIO line, the qemu_irq's callback is invoked.
+ * The index @n of the GPIO line must be valid, otherwise this function
+ * will assert().
+ *
+ * Outbound GPIO lines can be connected to any qemu_irq, but the common
+ * case is connecting them to another device's inbound GPIO line, using
+ * the qemu_irq returned by qdev_get_gpio_in() or qdev_get_gpio_in_named().
+ *
+ * It is not valid to try to connect one outbound GPIO to multiple
+ * qemu_irqs at once, or to connect multiple outbound GPIOs to the
+ * same qemu_irq; see qdev_connect_gpio_out() for details.
+ */
 void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq);
+
 void sysbus_mmio_map(SysBusDevice *dev, int n, hwaddr addr);
 void sysbus_mmio_map_overlap(SysBusDevice *dev, int n, hwaddr addr,
                              int priority);
Signature · 1 line
2.33.1
#8 lore raw
Quoted 19 lines · Philippe Mathieu-Daudé

Similarly to cd07d7f9f51 ("qdev: Document GPIO related functions"), add documentation comments for the various sysbus functions related to creating and connecting GPIO lines.

---
 include/hw/sysbus.h | 67 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 64 insertions(+), 3 deletions(-)
include/hw/sysbus.h +0 -1
index 24645ee7996..7b2b7c7faaa 100644
@@ -69,14 +69,75 @@ typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);
 
 void sysbus_init_mmio(SysBusDevice *dev, MemoryRegion *memory);
 MemoryRegion *sysbus_mmio_get_region(SysBusDevice *dev, int n);
-void sysbus_init_irq(SysBusDevice *dev, qemu_irq *p);

include/hw/sysbus.h typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque); · line 79

Quoted 10 lines
include/hw/sysbus.h +7 -2
-void sysbus_pass_irq(SysBusDevice *dev, SysBusDevice *target);
-void sysbus_init_ioports(SysBusDevice *dev, uint32_t ioport, uint32_t size);
 
+/**
+ * sysbus_init_irq: Create an output GPIO line
+ * @dev: Sysbus device to create output GPIO for
+ * @irq: Pointer to qemu_irq for the GPIO lines
+ *
+ * Sysbus devices should use this function in their instance_init
+ * or realize methods to create any output GPIO lines they need.

It's true that this works with a qemu_irq which can be used as an arbitrary GPIO line. But mostly we use sysbus_init_irq() when creating things which are actually outbound IRQ lines, and qdev_init_gpio_out{,_named}() when creating generic output GPIO lines. So we should phrase the documentation of these functions to steer readers towards following that convention.

(Looking at the code, I discover that under the hood the "sysbus irq" code is really using a named output GPIO array with a specific name (SYSBUS_DEVICE_GPIO_IRQ,
aka "sysbus-irq"). The only functional difference is that a sysbus device can be notified when one of its IRQs is connected, which is a nasty hack for the benefit of platform vfio.)

include/hw/sysbus.h typedef void FindSysbusDeviceFunc(SysBusDevice *sbdev, void *opaque);

Quoted 3 lines
include/hw/sysbus.h +3 -0
+ *
+ * The @irq argument should be a pointer to either a "qemu_irq" in
+ * the device's state structure.

Missing "or ..." clause, or should "either" be deleted ?

Quoted 4 lines

The device implementation can then raise
+ * and lower the GPIO line by calling qemu_set_irq(). (If anything is
+ * connected to the other end of the GPIO this will cause the handler
+ * function for that input GPIO to be called.)

Quoted 8 lines

+ *
+ * See sysbus_connect_irq() for how code that uses such a device can
+ * connect to one of its output GPIO lines.
+ *
+ * There is no need to release the @pins allocated array because it
+ * will be automatically released when @dev calls its instance_finalize()
+ * handler.
+ */

thanks
-- PMM