Skip to contentSkip to conversation

Enable Remote GPIO over RPMSG on i.MX Platform

PATCH In review Shenwei Wang 6 participants 68 messages Apr 22 – May 18

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v13 cover Enable Remote GPIO over RPMSG on i.MX Platform

Support the remote devices on the remote processor via the RPMSG bus on i.MX platform.

Changes in v13:
- drop the support for legacy NXP firmware.
- remove the fixed_up hooks from the rpmsg gpio driver.
- code cleanup.

Changes in v12:
- Fixed the "underline" warning reported by Randy.

Changes in v11:
- Expand RPMSG for the first time per Shuah's review comment.

Changes in v10:
- Update gpio-rpmsg.rst according to Daniel Baluta's review comments.
- Add a kernel CONFIG for fixed up handlers and only enable it on i.MX products.
- Fixed bugs reported by kernel test robot.

Changes in v9:
- Reuse the gpio-virtio design for command and IRQ type definitions.
- Remove msg_id, version, and vendor fields from the generic protocol.
- Add fixed-up handlers to support legacy firmware.

Changes in v8:
- Add "depends on REMOTEPROC" in Kconfig to fix the build error reported by the kernel test robot.
- Move the .rst patch before the .yaml patch.
- Handle the "ngpios" DT property based on Andrew's feedback.

Changes in v7:
- Reworked the driver to use the rpmsg_driver framework instead of platform_driver, based on feedback from Bjorn and Arnaud.
- Updated gpio-rpmsg.yaml and imx_rproc.yaml according to comments from Rob and Arnaud.
- Further refinements to gpio-rpmsg.yaml per Arnaud's feedback.

Changes in v6:
- make the driver more generic with the actions below:
rename the driver file to gpio-rpmsg.c
remove the imx related info in the function and variable names rename the imx_rpmsg.h to rpdev_info.h
create a gpio-rpmsg.yaml and refer it in imx_rproc.yaml
- update the gpio-rpmsg.rst according to the feedback from Andrew and move the source file to driver-api/gpio
- fix the bug reported by Zhongqiu Han
- remove the I2C related info

Changes in v5:
- move the gpio-rpmsg.rst from admin-guide to staging directory after discussion with Randy Dunlap.
- add include files with some code improvements per Bartosz's comments.

Changes in v4:
- add a documentation to describe the transport protocol per Andrew's comments.
- add a new handler to get the gpio direction.

Changes in v3:
- fix various format issue and return value check per Peng 's review comments.
- add the logic to also populate the subnodes which are not in the device map per Arnaud's request. (in imx_rproc.c)
- update the yaml per Frank's review comments.

Changes in v2:
- re-implemented the gpio driver per Linus Walleij's feedback by using GPIOLIB_IRQCHIP helper library.
- fix various format issue per Mathieu/Peng 's review comments.
- update the yaml doc per Rob's feedback

Shenwei Wang (4):
docs: driver-api: gpio: rpmsg gpio driver over rpmsg bus
dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support
gpio: rpmsg: add generic rpmsg GPIO driver
arm64: dts: imx8ulp: Add rpmsg node under imx_rproc

 .../devicetree/bindings/gpio/gpio-rpmsg.yaml  |  55 ++
 .../bindings/remoteproc/fsl,imx-rproc.yaml    |  53 ++
 Documentation/driver-api/gpio/gpio-rpmsg.rst  | 266 ++++++++
 Documentation/driver-api/gpio/index.rst       |   1 +
 arch/arm64/boot/dts/freescale/imx8ulp.dtsi    |  25 +
 drivers/gpio/Kconfig                          |  17 +
 drivers/gpio/Makefile                         |   1 +
 drivers/gpio/gpio-rpmsg.c                     | 573 ++++++++++++++++++
 8 files changed, 991 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-rpmsg.yaml
 create mode 100644 Documentation/driver-api/gpio/gpio-rpmsg.rst
 create mode 100644 drivers/gpio/gpio-rpmsg.c

--
2.43.0

#1 lore raw

PATCH v13 1/4 docs: driver-api: gpio: rpmsg gpio driver over rpmsg bus

Describes the gpio rpmsg transport protocol over the rpmsg bus between the remote system and Linux.

---
 Documentation/driver-api/gpio/gpio-rpmsg.rst | 266 +++++++++++++++++++
 Documentation/driver-api/gpio/index.rst      |   1 +
 2 files changed, 267 insertions(+)
 create mode 100644 Documentation/driver-api/gpio/gpio-rpmsg.rst
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +266 -0
new file mode 100644
index 000000000000..abfde68c9b0a
@@ -0,0 +1,266 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+GPIO RPMSG (Remote Processor Messaging) Protocol
+================================================
+
+The GPIO RPMSG transport protocol is used for communication and interaction
+with GPIO controllers on remote processors via the RPMSG bus.
+
+Message Format
+--------------
+
+The RPMSG message consists of a 6-byte packet with the following layout:
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   |type |cmd  |port |line |  data    |
+   +-----+-----+-----+-----+-----+----+
+
+- **type (Message Type)**: The message type can be one of:
+
+  - 0: GPIO_RPMSG_SEND
+  - 1: GPIO_RPMSG_REPLY
+  - 2: GPIO_RPMSG_NOTIFY
+
+- **cmd**: Command code, used for GPIO_RPMSG_SEND messages.
+
+- **port**: The GPIO port (bank) index.
+
+- **line**: The GPIO line (pin) index of the port.
+
+- **data**: See details in the command description below.
+
+- **reply err**: Error code from the remote core.
+
+  - 0: Success
+  - 1: General error (Early remote software only returns this unclassified error)
+  - 2: Not supported (A command is not supported by the remote firmware)
+  - 3: Resource not available (The resource is not allocated to Linux)
+  - 4: Resource busy (The resource is already in use)
+  - 5: Parameter error
+
+
+GPIO Commands
+-------------
+
+Commands are specified in the **Cmd** field for **GPIO_RPMSG_SEND** (Type=0) messages.
+
+The SEND message is always sent from Linux to the remote firmware. Each
+SEND corresponds to a single REPLY message. The GPIO driver should
+serialize messages and determine whether a REPLY message is required. If a
+REPLY message is expected but not received within the specified timeout
+period (currently 1 second in the Linux driver), the driver should return
+-ETIMEOUT.
+
+GET_DIRECTION (Cmd=2)
+~~~~~~~~~~~~~~~~~~~~~
+
+**Request:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 0   | 2   |port |line | 0   | 0  |
+   +-----+-----+-----+-----+-----+----+
+
+**Reply:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+
+
+- **err**: See above for definitions.
+
+- **dir**: Direction.
+
+  - 0: None
+  - 1: Output
+  - 2: Input
+
+SET_DIRECTION (Cmd=3)
+~~~~~~~~~~~~~~~~~~~~~
+
+**Request:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 0   | 3   |port |line | dir | 0  |
+   +-----+-----+-----+-----+-----+----+
+
+- **dir**: Direction.
+
+  - 0: None
+  - 1: Output
+  - 2: Input
+
+**Reply:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 3   |port |line | err | 0  |
+   +-----+-----+-----+-----+-----+----+
+
+- **err**: See above for definitions.
+
+
+GET_VALUE (Cmd=4)
+~~~~~~~~~~~~~~~~~
+
+**Request:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 0   | 4   |port |line | 0   | 0  |
+   +-----+-----+-----+-----+-----+----+
+
+**Reply:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 4   |port |line | err | val|
+   +-----+-----+-----+-----+-----+----+
+
+- **err**: See above for definitions.
+
+- **val**: Line level.
+
+  - 0: Low
+  - 1: High
+
+SET_VALUE (Cmd=5)
+~~~~~~~~~~~~~~~~~
+
+**Request:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 0   | 5   |port |line | val | 0  |
+   +-----+-----+-----+-----+-----+----+
+
+- **val**: Output level.
+
+  - 0: Low
+  - 1: High
+
+**Reply:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 5   |port |line | err | 0  |
+   +-----+-----+-----+-----+-----+----+
+
+- **err**: See above for definitions.
+
+SET_IRQ_TYPE (Cmd=6)
+~~~~~~~~~~~~~~~~~~~~
+
+**Request:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 0   | 6   |port |line | val | wk |
+   +-----+-----+-----+-----+-----+----+
+
+- **val**: IRQ types.
+
+  - 0: Interrupt disabled
+  - 1: Rising edge trigger
+  - 2: Falling edge trigger
+  - 3: Both edge trigger
+  - 4: High level trigger
+  - 8: Low level trigger
+
+- **wk**: Wakeup enable.
+
+  The remote system should always aim to stay in a power-efficient state by
+  shutting down or clock-gating the GPIO blocks that aren't in use. Since
+  the remoteproc driver is responsible for managing the power states of the
+  remote firmware, the GPIO driver does not require to know the firmware's
+  running states.
+
+  When the wakeup bit is set, the remote firmware should configure the line
+  as a wakeup source. The firmware should send the notification message to
+  Linux after it is woken from the GPIO line.
+
+  - 0: Disable wakeup from GPIO
+  - 1: Enable wakeup from GPIO
+
+**Reply:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 6   |port |line | err | 0  |
+   +-----+-----+-----+-----+-----+----+
+
+- **err**: See above for definitions.
+
+NOTIFY_REPLY (Cmd=10)
+~~~~~~~~~~~~~~~~~~~~~
+The reply message for the notification is optional. The remote firmware can
+implement it to simulate the interrupt acknowledgment behavior.
+
+**Request:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 0   | 10  |port |line |level| 0  |
+   +-----+-----+-----+-----+-----+----+
+
+- **port**: The GPIO port (bank) index.
+
+- **line**: The GPIO line (pin) index of the port.
+
+- **level**: GPIO line status.
+
+Notification Message
+--------------------
+
+Notifications are sent by the remote core and they have
+**Type=2 (GPIO_RPMSG_NOTIFY)**:
+
+When a GPIO line asserts an interrupt on the remote processor, the firmware
+should immediately mask the corresponding interrupt source and send a
+notification message to the Linux. Upon completion of the interrupt
+handling on the Linux side, the driver should issue a
+command **SET_IRQ_TYPE** to the firmware to unmask the interrupt.
+
+A Notification message can arrive between a SEND and its REPLY message,
+and the driver is expected to handle this scenario.
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 2   | 0   |port |line |type | 0  |
+   +-----+-----+-----+-----+-----+----+
+
+- **port**: The GPIO port (bank) index.
+
+- **line**: The GPIO line (pin) index of the port.
+
+- **type**: Optional parameter to indicate the trigger event type.
+
Documentation/driver-api/gpio/index.rst +1 -0
index bee58f709b9a..e5eb1f82f01f 100644
@@ -16,6 +16,7 @@ Contents:
    drivers-on-gpio
    bt8xxgpio
    pca953x
+   gpio-rpmsg
 
 Core
 ====
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH v13 1/4] docs: driver-api: gpio: rpmsg gpio driver over rpmsg bus

Quoted 25 lines · Shenwei Wang

Describes the gpio rpmsg transport protocol over the rpmsg bus between the remote system and Linux.

---
 Documentation/driver-api/gpio/gpio-rpmsg.rst | 266 +++++++++++++++++++
 Documentation/driver-api/gpio/index.rst      |   1 +
 2 files changed, 267 insertions(+)
 create mode 100644 Documentation/driver-api/gpio/gpio-rpmsg.rst
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +9 -0
new file mode 100644
index 000000000000..abfde68c9b0a
@@ -0,0 +1,266 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+GPIO RPMSG (Remote Processor Messaging) Protocol
+================================================
+
+The GPIO RPMSG transport protocol is used for communication and interaction
+with GPIO controllers on remote processors via the RPMSG bus.
+
+Message Format

Documentation/driver-api/gpio/gpio-rpmsg.rst line 19

Quoted 10 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +10 -0
+--------------
+
+The RPMSG message consists of a 6-byte packet with the following layout:
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   |type |cmd  |port |line |  data    |
+   +-----+-----+-----+-----+-----+----+

I will take a final decision on the 'port' field when I'm done reading the thread on how endpoints should be created.

Quoted 13 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +13 -0
+
+- **type (Message Type)**: The message type can be one of:
+
+  - 0: GPIO_RPMSG_SEND
+  - 1: GPIO_RPMSG_REPLY
+  - 2: GPIO_RPMSG_NOTIFY
+
+- **cmd**: Command code, used for GPIO_RPMSG_SEND messages.
+
+- **port**: The GPIO port (bank) index.
+
+- **line**: The GPIO line (pin) index of the port.
+

Documentation/driver-api/gpio/gpio-rpmsg.rst line 42

Quoted 10 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +10 -0
+- **data**: See details in the command description below.
+
+- **reply err**: Error code from the remote core.
+
+  - 0: Success
+  - 1: General error (Early remote software only returns this unclassified error)
+  - 2: Not supported (A command is not supported by the remote firmware)
+  - 3: Resource not available (The resource is not allocated to Linux)
+  - 4: Resource busy (The resource is already in use)
+  - 5: Parameter error

No. The virtio-GPIO specification does not define any of these. We are not re-inventing the specification, we are only using it on top of RPMSG. The only value for 'status' are VIRTIO_GPIO_STATUS_OK and VIRTIO_GPIO_STATUS_ERR. Modify the virtio-GPIO specification if you want to do something like this.

Quoted 15 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +15 -0
+
+
+GPIO Commands
+-------------
+
+Commands are specified in the **Cmd** field for **GPIO_RPMSG_SEND** (Type=0) messages.
+
+The SEND message is always sent from Linux to the remote firmware. Each
+SEND corresponds to a single REPLY message. The GPIO driver should
+serialize messages and determine whether a REPLY message is required. If a
+REPLY message is expected but not received within the specified timeout
+period (currently 1 second in the Linux driver), the driver should return
+-ETIMEOUT.
+
+GET_DIRECTION (Cmd=2)

Documentation/driver-api/gpio/gpio-rpmsg.rst line 67

Quoted 10 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +10 -0
+~~~~~~~~~~~~~~~~~~~~~
+
+**Request:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 0   | 2   |port |line | 0   | 0  |
+   +-----+-----+-----+-----+-----+----+

'line' should be 16 bit followed by a 32 bit value.

Documentation/driver-api/gpio/gpio-rpmsg.rst line 76

Quoted 9 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +9 -0
+
+**Reply:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+

Same as above, 'line' should be 16 bit. 'err' should be 'status' and 'dir' should be 'value'.

Quoted 10 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +10 -0
+
+- **err**: See above for definitions.
+
+- **dir**: Direction.
+
+  - 0: None
+  - 1: Output
+  - 2: Input
+
+SET_DIRECTION (Cmd=3)

Documentation/driver-api/gpio/gpio-rpmsg.rst line 96

Quoted 10 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +10 -0
+~~~~~~~~~~~~~~~~~~~~~
+
+**Request:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 0   | 3   |port |line | dir | 0  |
+   +-----+-----+-----+-----+-----+----+

Same as above, i.e 'line' is 16 bit follow by a 32 bit value.

Quoted 5 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +5 -0
+
+- **dir**: Direction.
+
+  - 0: None
+  - 1: Output

Documentation/driver-api/gpio/gpio-rpmsg.rst line 111

Quoted 10 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +10 -0
+  - 2: Input
+
+**Reply:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 3   |port |line | err | 0  |
+   +-----+-----+-----+-----+-----+----+

Same as my reply for GET_DIRECTION.

The same for all the other messages below. There should be a direct and obvious connection between this protocol and virtio-gpio. In fact I'm starting to wonder if we should have two endpoints per GPIO controller, one for the requestq and another one for the eventq. That would make this entire protocol unecessary. I will elaborate more later when I read Beleswar and Arnaud's conversation on that topic.

Quoted 85 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +85 -0
+
+- **err**: See above for definitions.
+
+
+GET_VALUE (Cmd=4)
+~~~~~~~~~~~~~~~~~
+
+**Request:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 0   | 4   |port |line | 0   | 0  |
+   +-----+-----+-----+-----+-----+----+
+
+**Reply:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 4   |port |line | err | val|
+   +-----+-----+-----+-----+-----+----+
+
+- **err**: See above for definitions.
+
+- **val**: Line level.
+
+  - 0: Low
+  - 1: High
+
+SET_VALUE (Cmd=5)
+~~~~~~~~~~~~~~~~~
+
+**Request:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 0   | 5   |port |line | val | 0  |
+   +-----+-----+-----+-----+-----+----+
+
+- **val**: Output level.
+
+  - 0: Low
+  - 1: High
+
+**Reply:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 5   |port |line | err | 0  |
+   +-----+-----+-----+-----+-----+----+
+
+- **err**: See above for definitions.
+
+SET_IRQ_TYPE (Cmd=6)
+~~~~~~~~~~~~~~~~~~~~
+
+**Request:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 0   | 6   |port |line | val | wk |
+   +-----+-----+-----+-----+-----+----+
+
+- **val**: IRQ types.
+
+  - 0: Interrupt disabled
+  - 1: Rising edge trigger
+  - 2: Falling edge trigger
+  - 3: Both edge trigger
+  - 4: High level trigger
+  - 8: Low level trigger
+
+- **wk**: Wakeup enable.
+
+  The remote system should always aim to stay in a power-efficient state by
+  shutting down or clock-gating the GPIO blocks that aren't in use. Since

Documentation/driver-api/gpio/gpio-rpmsg.rst line 206

Quoted 10 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +10 -0
+  the remoteproc driver is responsible for managing the power states of the
+  remote firmware, the GPIO driver does not require to know the firmware's
+  running states.
+
+  When the wakeup bit is set, the remote firmware should configure the line
+  as a wakeup source. The firmware should send the notification message to
+  Linux after it is woken from the GPIO line.
+
+  - 0: Disable wakeup from GPIO
+  - 1: Enable wakeup from GPIO

This is not part of the virtio-GPIO specification. Again, modify the virtio-GPIO specification to do this.

Quoted 21 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +21 -0
+
+**Reply:**
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 6   |port |line | err | 0  |
+   +-----+-----+-----+-----+-----+----+
+
+- **err**: See above for definitions.
+
+NOTIFY_REPLY (Cmd=10)
+~~~~~~~~~~~~~~~~~~~~~
+The reply message for the notification is optional. The remote firmware can
+implement it to simulate the interrupt acknowledgment behavior.
+
+**Request:**
+
+.. code-block:: none
+

Documentation/driver-api/gpio/gpio-rpmsg.rst line 237

Quoted 10 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +10 -0
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 0   | 10  |port |line |level| 0  |
+   +-----+-----+-----+-----+-----+----+
+
+- **port**: The GPIO port (bank) index.
+
+- **line**: The GPIO line (pin) index of the port.
+
+- **level**: GPIO line status.

No. In accordance with the specification, the only thing a device sends when an interrupt occurs is VIRTIO_GPIO_IRQ_STATUS_VALID, or VIRTIO_GPIO_IRQ_STATUS_INVALID to return the buffers back to the driver when interrupts are disabled.

Documentation/driver-api/gpio/gpio-rpmsg.rst line 244

Quoted 7 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +7 -0
+
+Notification Message
+--------------------
+
+Notifications are sent by the remote core and they have
+**Type=2 (GPIO_RPMSG_NOTIFY)**:
+

No. Once again, we are not re-writing the specification. Virtio-GPIO doesn't need this so I don't see whey virtio-rpmsg-gpio would.

Quoted 37 lines
Documentation/driver-api/gpio/gpio-rpmsg.rst new file +22 -0
+When a GPIO line asserts an interrupt on the remote processor, the firmware
+should immediately mask the corresponding interrupt source and send a
+notification message to the Linux. Upon completion of the interrupt
+handling on the Linux side, the driver should issue a
+command **SET_IRQ_TYPE** to the firmware to unmask the interrupt.
+
+A Notification message can arrive between a SEND and its REPLY message,
+and the driver is expected to handle this scenario.
+
+.. code-block:: none
+
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 2   | 0   |port |line |type | 0  |
+   +-----+-----+-----+-----+-----+----+
+
+- **port**: The GPIO port (bank) index.
+
+- **line**: The GPIO line (pin) index of the port.
+
+- **type**: Optional parameter to indicate the trigger event type.
+
Documentation/driver-api/gpio/index.rst +1 -0
index bee58f709b9a..e5eb1f82f01f 100644
@@ -16,6 +16,7 @@ Contents:
    drivers-on-gpio
    bt8xxgpio
    pca953x
+   gpio-rpmsg
 
 Core
 ====
Signature · 1 line
2.43.0
#3 lore raw

PATCH v13 2/4 dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support

In reply to Shenwei Wang

Remote processors may announce multiple GPIO controllers over an RPMSG channel. These GPIO controllers may require corresponding device tree nodes, especially when acting as providers, to supply phandles for their consumers.

Define an RPMSG node to work as a container for a group of RPMSG channels under the imx_rproc node. Each subnode within "rpmsg" represents an individual RPMSG channel. The name of each subnode corresponds to the channel name as defined by the remote processor.

All remote devices associated with a given channel are defined as child nodes under the corresponding channel node.

---
 .../devicetree/bindings/gpio/gpio-rpmsg.yaml  | 55 +++++++++++++++++++
 .../bindings/remoteproc/fsl,imx-rproc.yaml    | 53 ++++++++++++++++++
 2 files changed, 108 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-rpmsg.yaml
Documentation/devicetree/bindings/gpio/gpio-rpmsg.yaml new file +55 -0
new file mode 100644
index 000000000000..6c78b6850321
@@ -0,0 +1,55 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/gpio/gpio-rpmsg.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic RPMSG GPIO Controller
+
+maintainers:
+  - Shenwei Wang <[email protected]>
+
+description:
+  On an AMP platform, some GPIO controllers are exposed by the remote processor
+  through the RPMSG bus. The RPMSG GPIO transport protocol defines the packet
+  structure and communication flow between Linux and the remote firmware. Those
+  controllers are managed via this transport protocol. For more details of the
+  protocol, check the document below.
+  Documentation/driver-api/gpio/gpio-rpmsg.rst
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - fsl,rpmsg-gpio
+          - const: rpmsg-gpio
+      - const: rpmsg-gpio
+
+  reg:
+    description:
+      The reg property represents the index of the GPIO controllers. Since
+      the driver manages controllers on a remote system, this index tells
+      the remote system which controller to operate.
+    maxItems: 1
+
+  "#gpio-cells":
+    const: 2
+
+  gpio-controller: true
+
+  interrupt-controller: true
+
+  "#interrupt-cells":
+    const: 2
+
+required:
+  - compatible
+  - reg
+  - "#gpio-cells"
+  - "#interrupt-cells"
+
+allOf:
+  - $ref: /schemas/gpio/gpio.yaml#
+
+unevaluatedProperties: false
Documentation/devicetree/bindings/remoteproc/fsl,imx-rproc.yaml +53 -0

64 lines not on this page · raw message

Signature · 1 line
2.43.0
#4 lore raw

PATCH v13 3/4 gpio: rpmsg: add generic rpmsg GPIO driver

In reply to Shenwei Wang

On an AMP platform, the system may include two processors:
- An MCU running an RTOS
- An MPU running Linux

These processors communicate via the RPMSG protocol. The driver implements the standard GPIO interface, allowing the Linux side to control GPIO controllers which reside in the remote processor via RPMSG protocol.

Cc Bartosz Golaszewski <[email protected]>
Cc Andrew Lunn <[email protected]>
---
 drivers/gpio/Kconfig      |  17 ++
 drivers/gpio/Makefile     |   1 +
 drivers/gpio/gpio-rpmsg.c | 573 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 591 insertions(+)
 create mode 100644 drivers/gpio/gpio-rpmsg.c
drivers/gpio/Kconfig +17 -0
index 020e51e30317..4ad299fe3c6f 100644
@@ -1917,6 +1917,23 @@ config GPIO_SODAVILLE
 
 endmenu
 
+menu "RPMSG GPIO drivers"
+	depends on RPMSG
+
+config GPIO_RPMSG
+	tristate "Generic RPMSG GPIO support"
+	depends on OF && REMOTEPROC
+	select GPIOLIB_IRQCHIP
+	default REMOTEPROC
+	help
+	  Say yes here to support the generic GPIO functions over the RPMSG
+	  bus. Currently supported devices: i.MX7ULP, i.MX8ULP, i.MX8x, and
+	  i.MX9x.
+
+	  If unsure, say N.
+
+endmenu
+
 menu "SPI GPIO expanders"
 	depends on SPI_MASTER
 
drivers/gpio/Makefile +1 -0
index b267598b517d..ee75c0e65b8b 100644
@@ -157,6 +157,7 @@ obj-$(CONFIG_GPIO_RDC321X)		+= gpio-rdc321x.o
 obj-$(CONFIG_GPIO_REALTEK_OTTO)		+= gpio-realtek-otto.o
 obj-$(CONFIG_GPIO_REG)			+= gpio-reg.o
 obj-$(CONFIG_GPIO_ROCKCHIP)	+= gpio-rockchip.o
+obj-$(CONFIG_GPIO_RPMSG)		+= gpio-rpmsg.o
 obj-$(CONFIG_GPIO_RTD)			+= gpio-rtd.o
 obj-$(CONFIG_ARCH_SA1100)		+= gpio-sa1100.o
 obj-$(CONFIG_GPIO_SAMA5D2_PIOBU)	+= gpio-sama5d2-piobu.o
drivers/gpio/gpio-rpmsg.c new file +573 -0

573 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Hello Shenwei, Greetings,

Quoted 1 line · Shenwei Wang

On an AMP platform, the system may include two processors:

s/two/multiple

Quoted 1 line

- An MCU running an RTOS

s/An MCU/MCUs

Quoted 95 lines

- An MPU running Linux

These processors communicate via the RPMSG protocol. The driver implements the standard GPIO interface, allowing the Linux side to control GPIO controllers which reside in the remote processor via RPMSG protocol.

Cc Bartosz Golaszewski <[email protected]>
Cc Andrew Lunn <[email protected]>
---
  drivers/gpio/Kconfig      |  17 ++
  drivers/gpio/Makefile     |   1 +
  drivers/gpio/gpio-rpmsg.c | 573 ++++++++++++++++++++++++++++++++++++++
  3 files changed, 591 insertions(+)

create mode 100644 drivers/gpio/gpio-rpmsg.c

drivers/gpio/Kconfig +17 -0
index 020e51e30317..4ad299fe3c6f 100644
@@ -1917,6 +1917,23 @@ config GPIO_SODAVILLE
 
  endmenu
 
+menu "RPMSG GPIO drivers"
+	depends on RPMSG
+
+config GPIO_RPMSG
+	tristate "Generic RPMSG GPIO support"
+	depends on OF && REMOTEPROC
+	select GPIOLIB_IRQCHIP
+	default REMOTEPROC
+	help
+	  Say yes here to support the generic GPIO functions over the RPMSG
+	  bus. Currently supported devices: i.MX7ULP, i.MX8ULP, i.MX8x, and
+	  i.MX9x.
+
+	  If unsure, say N.
+
+endmenu
+
  menu "SPI GPIO expanders"
  	depends on SPI_MASTER
 
drivers/gpio/Makefile +1 -0
index b267598b517d..ee75c0e65b8b 100644
@@ -157,6 +157,7 @@ obj-$(CONFIG_GPIO_RDC321X)		+= gpio-rdc321x.o
  obj-$(CONFIG_GPIO_REALTEK_OTTO)		+= gpio-realtek-otto.o
  obj-$(CONFIG_GPIO_REG)			+= gpio-reg.o
  obj-$(CONFIG_GPIO_ROCKCHIP)	+= gpio-rockchip.o
+obj-$(CONFIG_GPIO_RPMSG)		+= gpio-rpmsg.o
  obj-$(CONFIG_GPIO_RTD)			+= gpio-rtd.o
  obj-$(CONFIG_ARCH_SA1100)		+= gpio-sa1100.o
  obj-$(CONFIG_GPIO_SAMA5D2_PIOBU)	+= gpio-sama5d2-piobu.o
drivers/gpio/gpio-rpmsg.c new file +32 -0
new file mode 100644
index 000000000000..993cde7af2fa
@@ -0,0 +1,573 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright 2026 NXP
+ *
+ * The driver exports a standard gpiochip interface to control
+ * the GPIO controllers via RPMSG on a remote processor.
+ */
+
+#include <linux/completion.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/gpio/driver.h>
+#include <linux/init.h>
+#include <linux/irqdomain.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/remoteproc.h>
+#include <linux/rpmsg.h>
+#include <linux/virtio_gpio.h>
+
+#define MAX_PORT_PER_CHANNEL    10
+#define GPIOS_PER_PORT_DEFAULT	32
+#define RPMSG_TIMEOUT		1000
+
+/* GPIO RPMSG Type */
+#define GPIO_RPMSG_SEND		0
+#define GPIO_RPMSG_REPLY	1

drivers/gpio/gpio-rpmsg.c line 42

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+#define GPIO_RPMSG_NOTIFY	2
+
+struct rpmsg_gpio_packet {
+	u8 type;	/* Message type */
+	u8 cmd;		/* Command code */
+	u8 port_idx;
+	u8 line;
+	u8 val1;
+	u8 val2;
+};

Could you please document the fields in these structs (and the below ones too)? From the code, it looks like while sending a message from Linux to Firmware; val1 and val2 are used to describe the values to set. Whereas while receiving a response, val1 represents a possible error code, and val2 represents the actual message of get type queries. If that is so, you might want to change the variable names to be more descriptive and also use a union.

drivers/gpio/gpio-rpmsg.c line 50

Quoted 8 lines
drivers/gpio/gpio-rpmsg.c new file +8 -0
+
+struct rpmsg_gpio_line {
+	u8 irq_shutdown;
+	u8 irq_unmask;
+	u8 irq_mask;
+	u32 irq_wake_enable;
+	u32 irq_type;
+	struct rpmsg_gpio_packet msg;

We don't need to have this field. More info at [0].

Quoted 17 lines
drivers/gpio/gpio-rpmsg.c new file +17 -0
+};
+
+struct rpmsg_gpio_info {
+	struct rpmsg_device *rpdev;
+	struct rpmsg_gpio_packet *reply_msg;
+	struct completion cmd_complete;
+	struct mutex lock;
+	void **port_store;
+};
+
+struct rpmsg_gpio_port {
+	struct gpio_chip gc;
+	struct rpmsg_gpio_line lines[GPIOS_PER_PORT_DEFAULT];
+	struct rpmsg_gpio_info info;
+	u32 ngpios;
+	u32 idx;
+};

drivers/gpio/gpio-rpmsg.c line 77

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+
+/**
+ * struct rpmsg_drvdata - driver data per channel.
+ * @rproc_name: the name of the remote proc.
+ * @recv_pkt: a pointer to the received packet for protocol fix up.
+ * @channel_devices: an array of the devices related to the rpdev.
+ */
+struct rpdev_drvdata {
+	const char *rproc_name;
+	void *recv_pkt;

I don't see any use of this field in the code?

drivers/gpio/gpio-rpmsg.c line 78

Quoted 1 line
drivers/gpio/gpio-rpmsg.c new file +1 -0
+	void *channel_devices[MAX_PORT_PER_CHANNEL];

So this is technically a rpmsg endpoint (struct rpmsg_endpoint) without naming it "endpoint". Every rpmsg endpoint has a reference to its parent rpmsg channel (struct rpmsg_device) which represents the same information here. So we should use the framework standard here.

This also allows for dynamic creation and deletion of ports too! (if/when the firmware supports it)

Which means at port init time, we should make a call to rpmsg_create_ept() for each port tying the same callback rpmsg_gpio_channel_callback(). And based on the 'u32 src', we could identify the appropriate gpio port in the callback.

Quoted 22 lines
drivers/gpio/gpio-rpmsg.c new file +22 -0
+};
+
+static int rpmsg_gpio_send_message(struct rpmsg_gpio_port *port,
+				   struct rpmsg_gpio_packet *msg)
+{
+	struct rpmsg_gpio_info *info = &port->info;
+	int ret;
+
+	reinit_completion(&info->cmd_complete);
+
+	ret = rpmsg_send(info->rpdev->ept, msg, sizeof(*msg));
+	if (ret) {
+		dev_err(&info->rpdev->dev, "rpmsg_send failed: %d\n", ret);
+		return ret;
+	}
+
+	ret = wait_for_completion_timeout(&info->cmd_complete,
+					  msecs_to_jiffies(RPMSG_TIMEOUT));
+	if (ret == 0) {
+		dev_err(&info->rpdev->dev, "rpmsg_send timeout!\n");
+		return -ETIMEDOUT;
+	}

drivers/gpio/gpio-rpmsg.c line 110

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+
+	if (info->reply_msg->val1) {
+		dev_err(&info->rpdev->dev, "remote core replies an error: %d!\n",
+			info->reply_msg->val1);
+		return -EINVAL;
+	}
+
+	/* copy the reply message */
+	memcpy(&port->lines[info->reply_msg->line].msg,
+	       info->reply_msg, sizeof(*info->reply_msg));

The rpmsg_gpio_port structure already holds a pointer to the reply message via ->info. We do not need this extra copy. More info at [0].

drivers/gpio/gpio-rpmsg.c line 118

Quoted 8 lines
drivers/gpio/gpio-rpmsg.c new file +8 -0
+
+	return 0;
+}
+
+static struct rpmsg_gpio_packet *
+rpmsg_gpio_msg_init_common(struct rpmsg_gpio_port *port, unsigned int line, u8 cmd)
+{
+	struct rpmsg_gpio_packet *msg = &port->lines[line].msg;

[0]: We really don't need to carry the stale message in the line structure everytime. While sending requests, we should just request a buffer from kzalloc and use it everytime. As far as response is concerned, we are holding a lock everytime we are sending any message, so we are sure the pointer in info->reply_msg would have the response to only one request that was sent.

drivers/gpio/gpio-rpmsg.c line 120

Quoted 2 lines
drivers/gpio/gpio-rpmsg.c new file +2 -0
+
+	memset(msg, 0, sizeof(*msg));

This also means we can get rid of this memset.

Quoted 11 lines
drivers/gpio/gpio-rpmsg.c new file +11 -0
+	msg->type = GPIO_RPMSG_SEND;
+	msg->cmd = cmd;
+	msg->port_idx = port->idx;
+	msg->line = line;
+
+	return msg;
+}
+
+static int rpmsg_gpio_get(struct gpio_chip *gc, unsigned int line)
+{
+	struct rpmsg_gpio_port *port = gpiochip_get_data(gc);

drivers/gpio/gpio-rpmsg.c line 141

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+	struct rpmsg_gpio_packet *msg;
+	int ret;
+
+	guard(mutex)(&port->info.lock);
+
+	msg = rpmsg_gpio_msg_init_common(port, line, VIRTIO_GPIO_MSG_GET_VALUE);
+
+	ret = rpmsg_gpio_send_message(port, msg);
+	if (!ret)
+		ret = !!port->lines[line].msg.val2;

Which means here & everywhere else, we could just read the reply message from !!port->info->reply_msg->val2

Quoted 121 lines
drivers/gpio/gpio-rpmsg.c new file +121 -0
+
+	return ret;
+}
+
+static int rpmsg_gpio_get_direction(struct gpio_chip *gc, unsigned int line)
+{
+	struct rpmsg_gpio_port *port = gpiochip_get_data(gc);
+	struct rpmsg_gpio_packet *msg;
+	int ret;
+
+	guard(mutex)(&port->info.lock);
+
+	msg = rpmsg_gpio_msg_init_common(port, line, VIRTIO_GPIO_MSG_GET_DIRECTION);
+
+	ret = rpmsg_gpio_send_message(port, msg);
+	if (ret)
+		return ret;
+
+	switch (port->lines[line].msg.val2) {
+	case VIRTIO_GPIO_DIRECTION_IN:
+		return GPIO_LINE_DIRECTION_IN;
+	case VIRTIO_GPIO_DIRECTION_OUT:
+		return GPIO_LINE_DIRECTION_OUT;
+	default:
+		break;
+	}
+
+	return -EINVAL;
+}
+
+static int rpmsg_gpio_direction_input(struct gpio_chip *gc, unsigned int line)
+{
+	struct rpmsg_gpio_port *port = gpiochip_get_data(gc);
+	struct rpmsg_gpio_packet *msg;
+
+	guard(mutex)(&port->info.lock);
+
+	msg = rpmsg_gpio_msg_init_common(port, line, VIRTIO_GPIO_MSG_SET_DIRECTION);
+	msg->val1 = VIRTIO_GPIO_DIRECTION_IN;
+
+	return rpmsg_gpio_send_message(port, msg);
+}
+
+static int rpmsg_gpio_set(struct gpio_chip *gc, unsigned int line, int val)
+{
+	struct rpmsg_gpio_port *port = gpiochip_get_data(gc);
+	struct rpmsg_gpio_packet *msg;
+
+	guard(mutex)(&port->info.lock);
+
+	msg = rpmsg_gpio_msg_init_common(port, line, VIRTIO_GPIO_MSG_SET_VALUE);
+	msg->val1 = val;
+
+	return rpmsg_gpio_send_message(port, msg);
+}
+
+static int rpmsg_gpio_direction_output(struct gpio_chip *gc, unsigned int line, int val)
+{
+	struct rpmsg_gpio_port *port = gpiochip_get_data(gc);
+	struct rpmsg_gpio_packet *msg;
+	int ret;
+
+	guard(mutex)(&port->info.lock);
+
+	msg = rpmsg_gpio_msg_init_common(port, line, VIRTIO_GPIO_MSG_SET_DIRECTION);
+	msg->val1 = VIRTIO_GPIO_DIRECTION_OUT;
+
+	ret = rpmsg_gpio_send_message(port, msg);
+	if (ret)
+		return ret;
+
+	msg = rpmsg_gpio_msg_init_common(port, line, VIRTIO_GPIO_MSG_SET_VALUE);
+	msg->val1 = val;
+
+	return rpmsg_gpio_send_message(port, msg);
+}
+
+static int gpio_rpmsg_irq_set_type(struct irq_data *d, u32 type)
+{
+	struct rpmsg_gpio_port *port = irq_data_get_irq_chip_data(d);
+	u32 line = d->hwirq;
+
+	switch (type) {
+	case IRQ_TYPE_EDGE_RISING:
+		type = VIRTIO_GPIO_IRQ_TYPE_EDGE_RISING;
+		irq_set_handler_locked(d, handle_simple_irq);
+		break;
+	case IRQ_TYPE_EDGE_FALLING:
+		type = VIRTIO_GPIO_IRQ_TYPE_EDGE_FALLING;
+		irq_set_handler_locked(d, handle_simple_irq);
+		break;
+	case IRQ_TYPE_EDGE_BOTH:
+		type = VIRTIO_GPIO_IRQ_TYPE_EDGE_BOTH;
+		irq_set_handler_locked(d, handle_simple_irq);
+		break;
+	case IRQ_TYPE_LEVEL_LOW:
+		type = VIRTIO_GPIO_IRQ_TYPE_LEVEL_LOW;
+		irq_set_handler_locked(d, handle_level_irq);
+		break;
+	case IRQ_TYPE_LEVEL_HIGH:
+		type = VIRTIO_GPIO_IRQ_TYPE_LEVEL_HIGH;
+		irq_set_handler_locked(d, handle_level_irq);
+		break;
+	default:
+		dev_err(&port->info.rpdev->dev, "unsupported irq type: %u\n", type);
+		return -EINVAL;
+	}
+
+	port->lines[line].irq_type = type;
+
+	return 0;
+}
+
+static int gpio_rpmsg_irq_set_wake(struct irq_data *d, u32 enable)
+{
+	struct rpmsg_gpio_port *port = irq_data_get_irq_chip_data(d);
+	u32 line = d->hwirq;
+
+	port->lines[line].irq_wake_enable = enable;
+
+	return 0;

drivers/gpio/gpio-rpmsg.c line 272

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+}
+
+/*
+ * This unmask/mask function is invoked in two situations:
+ *   - when an interrupt is being set up, and
+ *   - after an interrupt has occurred.
+ *
+ * The GPIO driver does not access hardware registers directly.
+ * Instead, it caches all relevant information locally, and then sends
+ * the accumulated state to the remote system at this stage.

It is actually sent at the .bus_sync_unlock() stage.

Quoted 145 lines
drivers/gpio/gpio-rpmsg.c new file +145 -0
+ */
+static void gpio_rpmsg_unmask_irq(struct irq_data *d)
+{
+	struct rpmsg_gpio_port *port = irq_data_get_irq_chip_data(d);
+	u32 line = d->hwirq;
+
+	port->lines[line].irq_unmask = 1;
+}
+
+static void gpio_rpmsg_mask_irq(struct irq_data *d)
+{
+	struct rpmsg_gpio_port *port = irq_data_get_irq_chip_data(d);
+	u32 line = d->hwirq;
+
+	/*
+	 * When an interrupt occurs, the remote system masks the interrupt
+	 * and then sends a notification to Linux. After Linux processes
+	 * that notification, it sends an RPMsg command back to the remote
+	 * system to unmask the interrupt again.
+	 */
+	port->lines[line].irq_mask = 1;
+}
+
+static void gpio_rpmsg_irq_shutdown(struct irq_data *d)
+{
+	struct rpmsg_gpio_port *port = irq_data_get_irq_chip_data(d);
+	u32 line = d->hwirq;
+
+	port->lines[line].irq_shutdown = 1;
+}
+
+static void gpio_rpmsg_irq_bus_lock(struct irq_data *d)
+{
+	struct rpmsg_gpio_port *port = irq_data_get_irq_chip_data(d);
+
+	mutex_lock(&port->info.lock);
+}
+
+static void gpio_rpmsg_irq_bus_sync_unlock(struct irq_data *d)
+{
+	struct rpmsg_gpio_port *port = irq_data_get_irq_chip_data(d);
+	struct rpmsg_gpio_packet *msg;
+	u32 line = d->hwirq;
+
+	/*
+	 * For mask irq, do nothing here.
+	 * The remote system will mask interrupt after an interrupt occurs,
+	 * and then send a notification to Linux system. After Linux system
+	 * handles the notification, it sends an rpmsg back to the remote
+	 * system to unmask this interrupt again.
+	 */
+	if (port->lines[line].irq_mask && !port->lines[line].irq_unmask) {
+		port->lines[line].irq_mask = 0;
+		mutex_unlock(&port->info.lock);
+		return;
+	}
+
+	msg = rpmsg_gpio_msg_init_common(port, line, VIRTIO_GPIO_MSG_IRQ_TYPE);
+
+	if (port->lines[line].irq_shutdown) {
+		port->lines[line].irq_shutdown = 0;
+		msg->val1 = VIRTIO_GPIO_IRQ_TYPE_NONE;
+		msg->val2 = 0;
+	} else {
+		msg->val1 = port->lines[line].irq_type;
+
+		if (port->lines[line].irq_unmask) {
+			msg->val2 = 0;
+			port->lines[line].irq_unmask = 0;
+		} else /* irq set wake */
+			msg->val2 = port->lines[line].irq_wake_enable;
+	}
+
+	rpmsg_gpio_send_message(port, msg);
+	mutex_unlock(&port->info.lock);
+}
+
+static const struct irq_chip gpio_rpmsg_irq_chip = {
+	.irq_mask = gpio_rpmsg_mask_irq,
+	.irq_unmask = gpio_rpmsg_unmask_irq,
+	.irq_set_wake = gpio_rpmsg_irq_set_wake,
+	.irq_set_type = gpio_rpmsg_irq_set_type,
+	.irq_shutdown = gpio_rpmsg_irq_shutdown,
+	.irq_bus_lock = gpio_rpmsg_irq_bus_lock,
+	.irq_bus_sync_unlock = gpio_rpmsg_irq_bus_sync_unlock,
+	.flags = IRQCHIP_IMMUTABLE,
+};
+
+static void rpmsg_gpio_remove_action(void *data)
+{
+	struct rpmsg_gpio_port *port = data;
+
+	port->info.port_store[port->idx] = NULL;
+}
+
+static int rpmsg_gpiochip_register(struct rpmsg_device *rpdev, struct device_node *np)
+{
+	struct rpdev_drvdata *drvdata = dev_get_drvdata(&rpdev->dev);
+	struct rpmsg_gpio_port *port;
+	struct gpio_irq_chip *girq;
+	struct gpio_chip *gc;
+	int ret;
+
+	port = devm_kzalloc(&rpdev->dev, sizeof(*port), GFP_KERNEL);
+	if (!port)
+		return -ENOMEM;
+
+	ret = of_property_read_u32(np, "reg", &port->idx);
+	if (ret)
+		return ret;
+
+	if (port->idx >= MAX_PORT_PER_CHANNEL)
+		return -EINVAL;
+
+	ret = devm_mutex_init(&rpdev->dev, &port->info.lock);
+	if (ret)
+		return ret;
+
+	ret = of_property_read_u32(np, "ngpios", &port->ngpios);
+	if (ret || port->ngpios > GPIOS_PER_PORT_DEFAULT)
+		port->ngpios = GPIOS_PER_PORT_DEFAULT;
+
+	port->info.reply_msg = devm_kzalloc(&rpdev->dev,
+					    sizeof(*port->info.reply_msg),
+					    GFP_KERNEL);
+	if (!port->info.reply_msg)
+		return -ENOMEM;
+
+	init_completion(&port->info.cmd_complete);
+	port->info.port_store = drvdata->channel_devices;
+	port->info.port_store[port->idx] = port;
+	port->info.rpdev = rpdev;
+
+	gc = &port->gc;
+	gc->owner = THIS_MODULE;
+	gc->parent = &rpdev->dev;
+	gc->fwnode = of_fwnode_handle(np);
+	gc->ngpio = port->ngpios;
+	gc->base = -1;
+	gc->label = devm_kasprintf(&rpdev->dev, GFP_KERNEL, "%s-gpio%d",
+				   drvdata->rproc_name, port->idx);
+
+	gc->direction_input = rpmsg_gpio_direction_input;
+	gc->direction_output = rpmsg_gpio_direction_output;
+	gc->get_direction = rpmsg_gpio_get_direction;

drivers/gpio/gpio-rpmsg.c line 427

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+	gc->get = rpmsg_gpio_get;
+	gc->set = rpmsg_gpio_set;
+
+	girq = &gc->irq;
+	gpio_irq_chip_set_chip(girq, &gpio_rpmsg_irq_chip);
+	girq->parent_handler = NULL;
+	girq->num_parents = 0;
+	girq->parents = NULL;
+	girq->chip->name = devm_kasprintf(&rpdev->dev, GFP_KERNEL, "%s-gpio%d",
+					  drvdata->rproc_name, port->idx);

We could just re-use gc->label here...

Quoted 87 lines
drivers/gpio/gpio-rpmsg.c new file +87 -0
+
+	ret = devm_add_action_or_reset(&rpdev->dev, rpmsg_gpio_remove_action, port);
+	if (ret)
+		return ret;
+
+	return devm_gpiochip_add_data(&rpdev->dev, gc, port);
+}
+
+static const char *rpmsg_get_rproc_node_name(struct rpmsg_device *rpdev)
+{
+	const char *name = NULL;
+	struct device_node *np;
+	struct rproc *rproc;
+
+	rproc = rproc_get_by_child(&rpdev->dev);
+	if (!rproc)
+		return NULL;
+
+	np = of_node_get(rproc->dev.of_node);
+	if (!np && rproc->dev.parent)
+		np = of_node_get(rproc->dev.parent->of_node);
+
+	if (np) {
+		name = devm_kstrdup(&rpdev->dev, np->name, GFP_KERNEL);
+		of_node_put(np);
+	}
+
+	return name;
+}
+
+static struct device_node *
+rpmsg_get_channel_ofnode(struct rpmsg_device *rpdev, char *chan_name)
+{
+	struct device_node *np_chan = NULL, *np;
+	struct rproc *rproc;
+
+	rproc = rproc_get_by_child(&rpdev->dev);
+	if (!rproc)
+		return NULL;
+
+	np = of_node_get(rproc->dev.of_node);
+	if (!np && rproc->dev.parent)
+		np = of_node_get(rproc->dev.parent->of_node);
+
+	/* The of_node_put() is performed by of_find_node_by_name(). */
+	if (np)
+		np_chan = of_find_node_by_name(np, chan_name);
+
+	return np_chan;
+}
+
+static int rpmsg_gpio_channel_callback(struct rpmsg_device *rpdev, void *data,
+				       int len, void *priv, u32 src)
+{
+	struct rpmsg_gpio_packet *msg = data;
+	struct rpmsg_gpio_port *port = NULL;
+	struct rpdev_drvdata *drvdata;
+
+	drvdata = dev_get_drvdata(&rpdev->dev);
+	if (!msg || !drvdata)
+		return -EINVAL;
+
+	if (msg->port_idx < MAX_PORT_PER_CHANNEL)
+		port = drvdata->channel_devices[msg->port_idx];
+
+	if (!port || msg->line >= port->ngpios) {
+		dev_err(&rpdev->dev, "wrong port index or line number. port:%d line:%d\n",
+			msg->port_idx, msg->line);
+		return -EINVAL;
+	}
+
+	if (msg->type == GPIO_RPMSG_REPLY) {
+		*port->info.reply_msg = *msg;
+		complete(&port->info.cmd_complete);
+	} else if (msg->type == GPIO_RPMSG_NOTIFY) {
+		generic_handle_domain_irq_safe(port->gc.irq.domain, msg->line);
+	} else {
+		dev_err(&rpdev->dev, "wrong command type (0x%x)\n", msg->type);
+	}
+
+	return 0;
+}
+
+static int rpmsg_gpio_channel_probe(struct rpmsg_device *rpdev)
+{
+	struct device *dev = &rpdev->dev;
+	struct rpdev_drvdata *drvdata;

drivers/gpio/gpio-rpmsg.c line 524

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+	struct device_node *np;
+	int ret = -ENODEV;
+
+	if (!dev->of_node) {
+		np = rpmsg_get_channel_ofnode(rpdev, rpdev->id.name);
+		if (np) {
+			dev->of_node = np;
+			set_primary_fwnode(dev, of_fwnode_handle(np));
+		}
+		return -EPROBE_DEFER;

I know this was asked in the v10 version also. But I don't think the answer is sufficient. Should we not continue the intialization of drvdata etc if np != 0? Why return a deferred probe, and let the kernel come back to it again to do the same stuff with extra latency?

We could just do:
if (!np) return -EPROBE_DEFER;
else {everything_else};

Quoted 9 lines
drivers/gpio/gpio-rpmsg.c new file +9 -0
+	}
+
+	drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
+	if (!drvdata)
+		return -ENOMEM;
+
+	drvdata->rproc_name = rpmsg_get_rproc_node_name(rpdev);
+	dev_set_drvdata(dev, drvdata);
+

drivers/gpio/gpio-rpmsg.c line 543

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+	for_each_child_of_node_scoped(dev->of_node, child) {
+		if (!of_device_is_available(child))
+			continue;
+
+		if (!of_match_node(dev->driver->of_match_table, child))
+			continue;
+
+		ret = rpmsg_gpiochip_register(rpdev, child);
+		if (ret < 0)
+			break;

Why break here? If one port initialization fails, it shouldn't impact the other port right? We should just log this and store the appropriate value in ret.

Thanks for your time,
Beleswar

Quoted 30 lines
drivers/gpio/gpio-rpmsg.c new file +30 -0
+	}
+
+	return ret;
+}
+
+static const struct of_device_id rpmsg_gpio_dt_ids[] = {
+	{ .compatible = "rpmsg-gpio" },
+	{ /* sentinel */ }
+};
+
+static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = {
+	{ .name = "rpmsg-io" },
+	{ },
+};
+MODULE_DEVICE_TABLE(rpmsg, rpmsg_gpio_channel_id_table);
+
+static struct rpmsg_driver rpmsg_gpio_channel_client = {
+	.callback	= rpmsg_gpio_channel_callback,
+	.id_table	= rpmsg_gpio_channel_id_table,
+	.probe		= rpmsg_gpio_channel_probe,
+	.drv		= {
+		.name	= KBUILD_MODNAME,
+		.of_match_table = rpmsg_gpio_dt_ids,
+	},
+};
+module_rpmsg_driver(rpmsg_gpio_channel_client);
+
+MODULE_AUTHOR("Shenwei Wang <[email protected]>");
+MODULE_DESCRIPTION("generic rpmsg gpio driver");
+MODULE_LICENSE("GPL");
#6 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 139 lines

-----Original Message-----
From: Padhi, Beleswar <[email protected]>
Sent: Sunday, April 26, 2026 7:44 AM
To: Shenwei Wang <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>
Cc: Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>; Andrew Lunn <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver Hello Shenwei, Greetings,

Quoted 1 line · Shenwei Wang

On an AMP platform, the system may include two processors:

s/two/multiple

Quoted 1 line

- An MCU running an RTOS

s/An MCU/MCUs

Quoted 7 lines

- An MPU running Linux

These processors communicate via the RPMSG protocol.
The driver implements the standard GPIO interface, allowing the Linux side to control GPIO controllers which reside in the remote processor via RPMSG protocol.

Quoted 7 lines
Cc Bartosz Golaszewski <[email protected]>
Cc Andrew Lunn <[email protected]>
---
  drivers/gpio/Kconfig      |  17 ++
  drivers/gpio/Makefile     |   1 +
  drivers/gpio/gpio-rpmsg.c | 573

++++++++++++++++++++++++++++++++++++++

drivers/gpio/Makefile obj-$(CONFIG_GPIO_RDC321X) += gpio-

Quoted 36 lines
  3 files changed, 591 insertions(+)

create mode 100644 drivers/gpio/gpio-rpmsg.c

drivers/gpio/Kconfig index renamed from drivers/gpio/Kconfig +0 -0

020e51e30317..4ad299fe3c6f 100644

drivers/gpio/Kconfig +17 -0
@@ -1917,6 +1917,23 @@ config GPIO_SODAVILLE
 
  endmenu
 
+menu "RPMSG GPIO drivers"
+     depends on RPMSG
+
+config GPIO_RPMSG
+     tristate "Generic RPMSG GPIO support"
+     depends on OF && REMOTEPROC
+     select GPIOLIB_IRQCHIP
+     default REMOTEPROC
+     help
+       Say yes here to support the generic GPIO functions over the RPMSG
+       bus. Currently supported devices: i.MX7ULP, i.MX8ULP, i.MX8x, and
+       i.MX9x.
+
+       If unsure, say N.
+
+endmenu
+
  menu "SPI GPIO expanders"
      depends on SPI_MASTER
 
drivers/gpio/Makefile index renamed from drivers/gpio/Makefile +0 -0

b267598b517d..ee75c0e65b8b 100644

drivers/gpio/Makefile +0 -0
@@ -157,6 +157,7 @@ obj-$(CONFIG_GPIO_RDC321X)                += gpio-

rdc321x.o

Quoted 44 lines
drivers/gpio/Makefile +1 -0
  obj-$(CONFIG_GPIO_REALTEK_OTTO)             += gpio-realtek-otto.o
  obj-$(CONFIG_GPIO_REG)                      += gpio-reg.o
  obj-$(CONFIG_GPIO_ROCKCHIP) += gpio-rockchip.o
+obj-$(CONFIG_GPIO_RPMSG)             += gpio-rpmsg.o
  obj-$(CONFIG_GPIO_RTD)                      += gpio-rtd.o
  obj-$(CONFIG_ARCH_SA1100)           += gpio-sa1100.o
  obj-$(CONFIG_GPIO_SAMA5D2_PIOBU)    += gpio-sama5d2-piobu.o
drivers/gpio/gpio-rpmsg.c new renamed from drivers/gpio/gpio-rpmsg.c +0 -0

file mode 100644 index 000000000000..993cde7af2fa

drivers/gpio/gpio-rpmsg.c new file +32 -0
@@ -0,0 +1,573 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright 2026 NXP
+ *
+ * The driver exports a standard gpiochip interface to control
+ * the GPIO controllers via RPMSG on a remote processor.
+ */
+
+#include <linux/completion.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/gpio/driver.h>
+#include <linux/init.h>
+#include <linux/irqdomain.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/of_platform.h>
+#include <linux/platform_device.h>
+#include <linux/remoteproc.h>
+#include <linux/rpmsg.h>
+#include <linux/virtio_gpio.h>
+
+#define MAX_PORT_PER_CHANNEL    10
+#define GPIOS_PER_PORT_DEFAULT       32
+#define RPMSG_TIMEOUT                1000
+
+/* GPIO RPMSG Type */
+#define GPIO_RPMSG_SEND              0
+#define GPIO_RPMSG_REPLY     1

drivers/gpio/gpio-rpmsg.c line 42

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+#define GPIO_RPMSG_NOTIFY    2
+
+struct rpmsg_gpio_packet {
+     u8 type;        /* Message type */
+     u8 cmd;         /* Command code */
+     u8 port_idx;
+     u8 line;
+     u8 val1;
+     u8 val2;
+};
Quoted 7 lines

Could you please document the fields in these structs (and the below ones too)? From the code, it looks like while sending a message from Linux to Firmware; val1 and val2 are used to describe the values to set. Whereas while receiving a response, val1 represents a possible error code, and val2 represents the actual message of get type queries. If that is so, you might want to change the variable names to be more descriptive and also use a union.

The fields in the two structs are fairly self-explanatory. Do we really need the additional comments? The previous version of the patch used a union, which was updated to support the fixed_up hooks. Now that the fixed_up hooks have been removed, I can revert this back to the union-based implementation.

Quoted 34 lines

drivers/gpio/gpio-rpmsg.c line 50

Quoted 8 lines
drivers/gpio/gpio-rpmsg.c new file +8 -0
+
+struct rpmsg_gpio_line {
+     u8 irq_shutdown;
+     u8 irq_unmask;
+     u8 irq_mask;
+     u32 irq_wake_enable;
+     u32 irq_type;
+     struct rpmsg_gpio_packet msg;

We don't need to have this field. More info at [0].

Quoted 22 lines
drivers/gpio/gpio-rpmsg.c new file +22 -0
+};
+
+struct rpmsg_gpio_info {
+     struct rpmsg_device *rpdev;
+     struct rpmsg_gpio_packet *reply_msg;
+     struct completion cmd_complete;
+     struct mutex lock;
+     void **port_store;
+};
+
+struct rpmsg_gpio_port {
+     struct gpio_chip gc;
+     struct rpmsg_gpio_line lines[GPIOS_PER_PORT_DEFAULT];
+     struct rpmsg_gpio_info info;
+     u32 ngpios;
+     u32 idx;
+};
+
+/**
+ * struct rpmsg_drvdata - driver data per channel.
+ * @rproc_name: the name of the remote proc.
+ * @recv_pkt: a pointer to the received packet for protocol fix up.
Quoted 9 lines

drivers/gpio/gpio-rpmsg.c line 77

Quoted 5 lines
drivers/gpio/gpio-rpmsg.c new file +5 -0
+ * @channel_devices: an array of the devices related to the rpdev.
+ */
+struct rpdev_drvdata {
+     const char *rproc_name;
+     void *recv_pkt;

I don't see any use of this field in the code?

Will remove it. It was there for fixed_up hooks.

Quoted 8 lines

drivers/gpio/gpio-rpmsg.c line 78

Quoted 1 line
drivers/gpio/gpio-rpmsg.c new file +1 -0
+     void *channel_devices[MAX_PORT_PER_CHANNEL];

So this is technically a rpmsg endpoint (struct rpmsg_endpoint) without naming it "endpoint". Every rpmsg endpoint has a reference to its parent rpmsg channel (struct rpmsg_device) which represents the same information here. So we should use the framework standard here.

Yes, agree to use "endpoint_devices".

Quoted 44 lines

This also allows for dynamic creation and deletion of ports too! (if/when the firmware supports it)

Which means at port init time, we should make a call to rpmsg_create_ept() for each port tying the same callback rpmsg_gpio_channel_callback(). And based on the 'u32 src', we could identify the appropriate gpio port in the callback.

Quoted 21 lines
drivers/gpio/gpio-rpmsg.c new file +21 -0
+};
+
+static int rpmsg_gpio_send_message(struct rpmsg_gpio_port *port,
+                                struct rpmsg_gpio_packet *msg) {
+     struct rpmsg_gpio_info *info = &port->info;
+     int ret;
+
+     reinit_completion(&info->cmd_complete);
+
+     ret = rpmsg_send(info->rpdev->ept, msg, sizeof(*msg));
+     if (ret) {
+             dev_err(&info->rpdev->dev, "rpmsg_send failed: %d\n", ret);
+             return ret;
+     }
+
+     ret = wait_for_completion_timeout(&info->cmd_complete,
+                                       msecs_to_jiffies(RPMSG_TIMEOUT));
+     if (ret == 0) {
+             dev_err(&info->rpdev->dev, "rpmsg_send timeout!\n");
+             return -ETIMEDOUT;
+     }

drivers/gpio/gpio-rpmsg.c line 110

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+
+     if (info->reply_msg->val1) {
+             dev_err(&info->rpdev->dev, "remote core replies an error: %d!\n",
+                     info->reply_msg->val1);
+             return -EINVAL;
+     }
+
+     /* copy the reply message */
+     memcpy(&port->lines[info->reply_msg->line].msg,
+            info->reply_msg, sizeof(*info->reply_msg));

The rpmsg_gpio_port structure already holds a pointer to the reply message via -

Quoted 1 line

info. We do not need this extra copy. More info at [0].

Quoted 16 lines

drivers/gpio/gpio-rpmsg.c line 118

Quoted 8 lines
drivers/gpio/gpio-rpmsg.c new file +8 -0
+
+     return 0;
+}
+
+static struct rpmsg_gpio_packet *
+rpmsg_gpio_msg_init_common(struct rpmsg_gpio_port *port, unsigned int
+line, u8 cmd) {
+     struct rpmsg_gpio_packet *msg = &port->lines[line].msg;

[0]: We really don't need to carry the stale message in the line structure everytime. While sending requests, we should just request a buffer from kzalloc and use it everytime. As far as response is concerned, we are holding a lock everytime we are sending any message, so we are sure the pointer in info-

Quoted 1 line

reply_msg would have the response to only one request that was sent.

looks reasonable.

Quoted 315 lines

drivers/gpio/gpio-rpmsg.c

Quoted 2 lines
drivers/gpio/gpio-rpmsg.c new file +2 -0
+
+     memset(msg, 0, sizeof(*msg));

This also means we can get rid of this memset.

Quoted 11 lines
drivers/gpio/gpio-rpmsg.c new file +11 -0
+     msg->type = GPIO_RPMSG_SEND;
+     msg->cmd = cmd;
+     msg->port_idx = port->idx;
+     msg->line = line;
+
+     return msg;
+}
+
+static int rpmsg_gpio_get(struct gpio_chip *gc, unsigned int line) {
+     struct rpmsg_gpio_port *port = gpiochip_get_data(gc);
+     struct rpmsg_gpio_packet *msg;

drivers/gpio/gpio-rpmsg.c line 141

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+     int ret;
+
+     guard(mutex)(&port->info.lock);
+
+     msg = rpmsg_gpio_msg_init_common(port, line,
+ VIRTIO_GPIO_MSG_GET_VALUE);
+
+     ret = rpmsg_gpio_send_message(port, msg);
+     if (!ret)
+             ret = !!port->lines[line].msg.val2;

Which means here & everywhere else, we could just read the reply message from !!port->info->reply_msg->val2

Quoted 29 lines
drivers/gpio/gpio-rpmsg.c new file +29 -0
+
+     return ret;
+}
+
+static int rpmsg_gpio_get_direction(struct gpio_chip *gc, unsigned
+int line) {
+     struct rpmsg_gpio_port *port = gpiochip_get_data(gc);
+     struct rpmsg_gpio_packet *msg;
+     int ret;
+
+     guard(mutex)(&port->info.lock);
+
+     msg = rpmsg_gpio_msg_init_common(port, line,
+ VIRTIO_GPIO_MSG_GET_DIRECTION);
+
+     ret = rpmsg_gpio_send_message(port, msg);
+     if (ret)
+             return ret;
+
+     switch (port->lines[line].msg.val2) {
+     case VIRTIO_GPIO_DIRECTION_IN:
+             return GPIO_LINE_DIRECTION_IN;
+     case VIRTIO_GPIO_DIRECTION_OUT:
+             return GPIO_LINE_DIRECTION_OUT;
+     default:
+             break;
+     }
+
+     return -EINVAL;

drivers/gpio/gpio-rpmsg.c

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+}
+
+static int rpmsg_gpio_direction_input(struct gpio_chip *gc, unsigned
+int line) {
+     struct rpmsg_gpio_port *port = gpiochip_get_data(gc);
+     struct rpmsg_gpio_packet *msg;
+
+     guard(mutex)(&port->info.lock);
+
+     msg = rpmsg_gpio_msg_init_common(port, line,

VIRTIO_GPIO_MSG_SET_DIRECTION);

drivers/gpio/gpio-rpmsg.c

Quoted 12 lines
drivers/gpio/gpio-rpmsg.c new file +12 -0
+     msg->val1 = VIRTIO_GPIO_DIRECTION_IN;
+
+     return rpmsg_gpio_send_message(port, msg); }
+
+static int rpmsg_gpio_set(struct gpio_chip *gc, unsigned int line,
+int val) {
+     struct rpmsg_gpio_port *port = gpiochip_get_data(gc);
+     struct rpmsg_gpio_packet *msg;
+
+     guard(mutex)(&port->info.lock);
+
+     msg = rpmsg_gpio_msg_init_common(port, line,

VIRTIO_GPIO_MSG_SET_VALUE);

drivers/gpio/gpio-rpmsg.c

Quoted 13 lines
drivers/gpio/gpio-rpmsg.c new file +13 -0
+     msg->val1 = val;
+
+     return rpmsg_gpio_send_message(port, msg); }
+
+static int rpmsg_gpio_direction_output(struct gpio_chip *gc, unsigned
+int line, int val) {
+     struct rpmsg_gpio_port *port = gpiochip_get_data(gc);
+     struct rpmsg_gpio_packet *msg;
+     int ret;
+
+     guard(mutex)(&port->info.lock);
+
+     msg = rpmsg_gpio_msg_init_common(port, line,

VIRTIO_GPIO_MSG_SET_DIRECTION);

drivers/gpio/gpio-rpmsg.c

Quoted 7 lines
drivers/gpio/gpio-rpmsg.c new file +7 -0
+     msg->val1 = VIRTIO_GPIO_DIRECTION_OUT;
+
+     ret = rpmsg_gpio_send_message(port, msg);
+     if (ret)
+             return ret;
+
+     msg = rpmsg_gpio_msg_init_common(port, line,

VIRTIO_GPIO_MSG_SET_VALUE);

Quoted 47 lines
drivers/gpio/gpio-rpmsg.c new file +47 -0
+     msg->val1 = val;
+
+     return rpmsg_gpio_send_message(port, msg); }
+
+static int gpio_rpmsg_irq_set_type(struct irq_data *d, u32 type) {
+     struct rpmsg_gpio_port *port = irq_data_get_irq_chip_data(d);
+     u32 line = d->hwirq;
+
+     switch (type) {
+     case IRQ_TYPE_EDGE_RISING:
+             type = VIRTIO_GPIO_IRQ_TYPE_EDGE_RISING;
+             irq_set_handler_locked(d, handle_simple_irq);
+             break;
+     case IRQ_TYPE_EDGE_FALLING:
+             type = VIRTIO_GPIO_IRQ_TYPE_EDGE_FALLING;
+             irq_set_handler_locked(d, handle_simple_irq);
+             break;
+     case IRQ_TYPE_EDGE_BOTH:
+             type = VIRTIO_GPIO_IRQ_TYPE_EDGE_BOTH;
+             irq_set_handler_locked(d, handle_simple_irq);
+             break;
+     case IRQ_TYPE_LEVEL_LOW:
+             type = VIRTIO_GPIO_IRQ_TYPE_LEVEL_LOW;
+             irq_set_handler_locked(d, handle_level_irq);
+             break;
+     case IRQ_TYPE_LEVEL_HIGH:
+             type = VIRTIO_GPIO_IRQ_TYPE_LEVEL_HIGH;
+             irq_set_handler_locked(d, handle_level_irq);
+             break;
+     default:
+             dev_err(&port->info.rpdev->dev, "unsupported irq type: %u\n", type);
+             return -EINVAL;
+     }
+
+     port->lines[line].irq_type = type;
+
+     return 0;
+}
+
+static int gpio_rpmsg_irq_set_wake(struct irq_data *d, u32 enable) {
+     struct rpmsg_gpio_port *port = irq_data_get_irq_chip_data(d);
+     u32 line = d->hwirq;
+
+     port->lines[line].irq_wake_enable = enable;
+
+     return 0;
+}

drivers/gpio/gpio-rpmsg.c line 272

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+
+/*
+ * This unmask/mask function is invoked in two situations:
+ *   - when an interrupt is being set up, and
+ *   - after an interrupt has occurred.
+ *
+ * The GPIO driver does not access hardware registers directly.
+ * Instead, it caches all relevant information locally, and then
+sends
+ * the accumulated state to the remote system at this stage.

It is actually sent at the .bus_sync_unlock() stage.

Quoted 136 lines

+ */

drivers/gpio/gpio-rpmsg.c new file +135 -0
+static void gpio_rpmsg_unmask_irq(struct irq_data *d) {
+     struct rpmsg_gpio_port *port = irq_data_get_irq_chip_data(d);
+     u32 line = d->hwirq;
+
+     port->lines[line].irq_unmask = 1; }
+
+static void gpio_rpmsg_mask_irq(struct irq_data *d) {
+     struct rpmsg_gpio_port *port = irq_data_get_irq_chip_data(d);
+     u32 line = d->hwirq;
+
+     /*
+      * When an interrupt occurs, the remote system masks the interrupt
+      * and then sends a notification to Linux. After Linux processes
+      * that notification, it sends an RPMsg command back to the remote
+      * system to unmask the interrupt again.
+      */
+     port->lines[line].irq_mask = 1;
+}
+
+static void gpio_rpmsg_irq_shutdown(struct irq_data *d) {
+     struct rpmsg_gpio_port *port = irq_data_get_irq_chip_data(d);
+     u32 line = d->hwirq;
+
+     port->lines[line].irq_shutdown = 1; }
+
+static void gpio_rpmsg_irq_bus_lock(struct irq_data *d) {
+     struct rpmsg_gpio_port *port = irq_data_get_irq_chip_data(d);
+
+     mutex_lock(&port->info.lock);
+}
+
+static void gpio_rpmsg_irq_bus_sync_unlock(struct irq_data *d) {
+     struct rpmsg_gpio_port *port = irq_data_get_irq_chip_data(d);
+     struct rpmsg_gpio_packet *msg;
+     u32 line = d->hwirq;
+
+     /*
+      * For mask irq, do nothing here.
+      * The remote system will mask interrupt after an interrupt occurs,
+      * and then send a notification to Linux system. After Linux system
+      * handles the notification, it sends an rpmsg back to the remote
+      * system to unmask this interrupt again.
+      */
+     if (port->lines[line].irq_mask && !port->lines[line].irq_unmask) {
+             port->lines[line].irq_mask = 0;
+             mutex_unlock(&port->info.lock);
+             return;
+     }
+
+     msg = rpmsg_gpio_msg_init_common(port, line,
+ VIRTIO_GPIO_MSG_IRQ_TYPE);
+
+     if (port->lines[line].irq_shutdown) {
+             port->lines[line].irq_shutdown = 0;
+             msg->val1 = VIRTIO_GPIO_IRQ_TYPE_NONE;
+             msg->val2 = 0;
+     } else {
+             msg->val1 = port->lines[line].irq_type;
+
+             if (port->lines[line].irq_unmask) {
+                     msg->val2 = 0;
+                     port->lines[line].irq_unmask = 0;
+             } else /* irq set wake */
+                     msg->val2 = port->lines[line].irq_wake_enable;
+     }
+
+     rpmsg_gpio_send_message(port, msg);
+     mutex_unlock(&port->info.lock);
+}
+
+static const struct irq_chip gpio_rpmsg_irq_chip = {
+     .irq_mask = gpio_rpmsg_mask_irq,
+     .irq_unmask = gpio_rpmsg_unmask_irq,
+     .irq_set_wake = gpio_rpmsg_irq_set_wake,
+     .irq_set_type = gpio_rpmsg_irq_set_type,
+     .irq_shutdown = gpio_rpmsg_irq_shutdown,
+     .irq_bus_lock = gpio_rpmsg_irq_bus_lock,
+     .irq_bus_sync_unlock = gpio_rpmsg_irq_bus_sync_unlock,
+     .flags = IRQCHIP_IMMUTABLE,
+};
+
+static void rpmsg_gpio_remove_action(void *data) {
+     struct rpmsg_gpio_port *port = data;
+
+     port->info.port_store[port->idx] = NULL; }
+
+static int rpmsg_gpiochip_register(struct rpmsg_device *rpdev, struct
+device_node *np) {
+     struct rpdev_drvdata *drvdata = dev_get_drvdata(&rpdev->dev);
+     struct rpmsg_gpio_port *port;
+     struct gpio_irq_chip *girq;
+     struct gpio_chip *gc;
+     int ret;
+
+     port = devm_kzalloc(&rpdev->dev, sizeof(*port), GFP_KERNEL);
+     if (!port)
+             return -ENOMEM;
+
+     ret = of_property_read_u32(np, "reg", &port->idx);
+     if (ret)
+             return ret;
+
+     if (port->idx >= MAX_PORT_PER_CHANNEL)
+             return -EINVAL;
+
+     ret = devm_mutex_init(&rpdev->dev, &port->info.lock);
+     if (ret)
+             return ret;
+
+     ret = of_property_read_u32(np, "ngpios", &port->ngpios);
+     if (ret || port->ngpios > GPIOS_PER_PORT_DEFAULT)
+             port->ngpios = GPIOS_PER_PORT_DEFAULT;
+
+     port->info.reply_msg = devm_kzalloc(&rpdev->dev,
+                                         sizeof(*port->info.reply_msg),
+                                         GFP_KERNEL);
+     if (!port->info.reply_msg)
+             return -ENOMEM;
+
+     init_completion(&port->info.cmd_complete);
+     port->info.port_store = drvdata->channel_devices;
+     port->info.port_store[port->idx] = port;
+     port->info.rpdev = rpdev;
+
+     gc = &port->gc;
+     gc->owner = THIS_MODULE;
+     gc->parent = &rpdev->dev;
+     gc->fwnode = of_fwnode_handle(np);
+     gc->ngpio = port->ngpios;
+     gc->base = -1;
+     gc->label = devm_kasprintf(&rpdev->dev, GFP_KERNEL, "%s-gpio%d",
+                                drvdata->rproc_name, port->idx);
+
+     gc->direction_input = rpmsg_gpio_direction_input;
+     gc->direction_output = rpmsg_gpio_direction_output;

drivers/gpio/gpio-rpmsg.c

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+     gc->get_direction = rpmsg_gpio_get_direction;
+     gc->get = rpmsg_gpio_get;
+     gc->set = rpmsg_gpio_set;
+
+     girq = &gc->irq;
+     gpio_irq_chip_set_chip(girq, &gpio_rpmsg_irq_chip);
+     girq->parent_handler = NULL;
+     girq->num_parents = 0;
+     girq->parents = NULL;
+     girq->chip->name = devm_kasprintf(&rpdev->dev, GFP_KERNEL, "%s-

gpio%d",

Quoted 5 lines
Quoted 2 lines

+ drvdata->rproc_name,
+ port->idx);

We could just re-use gc->label here...

We also want to include the remoteproc name (for example, remoteproc-cm33-gpio0), rather than just gpio0.

Quoted 105 lines

drivers/gpio/gpio-rpmsg.c

Quoted 3 lines
drivers/gpio/gpio-rpmsg.c new file +2 -0
+
+     ret = devm_add_action_or_reset(&rpdev->dev,

rpmsg_gpio_remove_action, port);

Quoted 39 lines
drivers/gpio/gpio-rpmsg.c new file +39 -0
+     if (ret)
+             return ret;
+
+     return devm_gpiochip_add_data(&rpdev->dev, gc, port); }
+
+static const char *rpmsg_get_rproc_node_name(struct rpmsg_device
+*rpdev) {
+     const char *name = NULL;
+     struct device_node *np;
+     struct rproc *rproc;
+
+     rproc = rproc_get_by_child(&rpdev->dev);
+     if (!rproc)
+             return NULL;
+
+     np = of_node_get(rproc->dev.of_node);
+     if (!np && rproc->dev.parent)
+             np = of_node_get(rproc->dev.parent->of_node);
+
+     if (np) {
+             name = devm_kstrdup(&rpdev->dev, np->name, GFP_KERNEL);
+             of_node_put(np);
+     }
+
+     return name;
+}
+
+static struct device_node *
+rpmsg_get_channel_ofnode(struct rpmsg_device *rpdev, char *chan_name)
+{
+     struct device_node *np_chan = NULL, *np;
+     struct rproc *rproc;
+
+     rproc = rproc_get_by_child(&rpdev->dev);
+     if (!rproc)
+             return NULL;
+
+     np = of_node_get(rproc->dev.of_node);
+     if (!np && rproc->dev.parent)

drivers/gpio/gpio-rpmsg.c

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+             np = of_node_get(rproc->dev.parent->of_node);
+
+     /* The of_node_put() is performed by of_find_node_by_name(). */
+     if (np)
+             np_chan = of_find_node_by_name(np, chan_name);
+
+     return np_chan;
+}
+
+static int rpmsg_gpio_channel_callback(struct rpmsg_device *rpdev, void

*data,

Quoted 4 lines
drivers/gpio/gpio-rpmsg.c new file +4 -0
+                                    int len, void *priv, u32 src) {
+     struct rpmsg_gpio_packet *msg = data;
+     struct rpmsg_gpio_port *port = NULL;
+     struct rpdev_drvdata *drvdata;

drivers/gpio/gpio-rpmsg.c

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+
+     drvdata = dev_get_drvdata(&rpdev->dev);
+     if (!msg || !drvdata)
+             return -EINVAL;
+
+     if (msg->port_idx < MAX_PORT_PER_CHANNEL)
+             port = drvdata->channel_devices[msg->port_idx];
+
+     if (!port || msg->line >= port->ngpios) {
+             dev_err(&rpdev->dev, "wrong port index or line number. port:%d

line:%d\n",

Quoted 19 lines
drivers/gpio/gpio-rpmsg.c new file +19 -0
+                     msg->port_idx, msg->line);
+             return -EINVAL;
+     }
+
+     if (msg->type == GPIO_RPMSG_REPLY) {
+             *port->info.reply_msg = *msg;
+             complete(&port->info.cmd_complete);
+     } else if (msg->type == GPIO_RPMSG_NOTIFY) {
+             generic_handle_domain_irq_safe(port->gc.irq.domain, msg->line);
+     } else {
+             dev_err(&rpdev->dev, "wrong command type (0x%x)\n", msg->type);
+     }
+
+     return 0;
+}
+
+static int rpmsg_gpio_channel_probe(struct rpmsg_device *rpdev) {
+     struct device *dev = &rpdev->dev;
+     struct rpdev_drvdata *drvdata;

drivers/gpio/gpio-rpmsg.c line 524

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+     struct device_node *np;
+     int ret = -ENODEV;
+
+     if (!dev->of_node) {
+             np = rpmsg_get_channel_ofnode(rpdev, rpdev->id.name);
+             if (np) {
+                     dev->of_node = np;
+                     set_primary_fwnode(dev, of_fwnode_handle(np));
+             }
+             return -EPROBE_DEFER;

I know this was asked in the v10 version also. But I don't think the answer is sufficient. Should we not continue the intialization of drvdata etc if np != 0? Why return a deferred probe, and let the kernel come back to it again to do the same stuff with extra latency?

Quoted 4 lines

We could just do:
if (!np) return -EPROBE_DEFER;
else {everything_else};

After configuring dev->of_node, it would be better to restart the driver probe process. This ensures that all required resources, such as pinctrl, clocks, and power domains, are properly set up if they are specified in the device node, before the probe function is invoked.

Thanks,
Shenwei

Quoted 57 lines
Quoted 9 lines
drivers/gpio/gpio-rpmsg.c new file +9 -0
+     }
+
+     drvdata = devm_kzalloc(dev, sizeof(*drvdata), GFP_KERNEL);
+     if (!drvdata)
+             return -ENOMEM;
+
+     drvdata->rproc_name = rpmsg_get_rproc_node_name(rpdev);
+     dev_set_drvdata(dev, drvdata);
+

drivers/gpio/gpio-rpmsg.c line 543

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+     for_each_child_of_node_scoped(dev->of_node, child) {
+             if (!of_device_is_available(child))
+                     continue;
+
+             if (!of_match_node(dev->driver->of_match_table, child))
+                     continue;
+
+             ret = rpmsg_gpiochip_register(rpdev, child);
+             if (ret < 0)
+                     break;

Why break here? If one port initialization fails, it shouldn't impact the other port right? We should just log this and store the appropriate value in ret.

Thanks for your time,
Beleswar

Quoted 30 lines
drivers/gpio/gpio-rpmsg.c new file +30 -0
+     }
+
+     return ret;
+}
+
+static const struct of_device_id rpmsg_gpio_dt_ids[] = {
+     { .compatible = "rpmsg-gpio" },
+     { /* sentinel */ }
+};
+
+static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = {
+     { .name = "rpmsg-io" },
+     { },
+};
+MODULE_DEVICE_TABLE(rpmsg, rpmsg_gpio_channel_id_table);
+
+static struct rpmsg_driver rpmsg_gpio_channel_client = {
+     .callback       = rpmsg_gpio_channel_callback,
+     .id_table       = rpmsg_gpio_channel_id_table,
+     .probe          = rpmsg_gpio_channel_probe,
+     .drv            = {
+             .name   = KBUILD_MODNAME,
+             .of_match_table = rpmsg_gpio_dt_ids,
+     },
+};
+module_rpmsg_driver(rpmsg_gpio_channel_client);
+
+MODULE_AUTHOR("Shenwei Wang <[email protected]>");
+MODULE_DESCRIPTION("generic rpmsg gpio driver");
+MODULE_LICENSE("GPL");
#7 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 18 lines
Quoted 10 lines

drivers/gpio/gpio-rpmsg.c line 42

Quoted 8 lines
drivers/gpio/gpio-rpmsg.c new file +8 -0
+struct rpmsg_gpio_packet {
+     u8 type;        /* Message type */
+     u8 cmd;         /* Command code */
+     u8 port_idx;
+     u8 line;
+     u8 val1;
+     u8 val2;
+};
Quoted 7 lines

Could you please document the fields in these structs (and the below ones too)? From the code, it looks like while sending a message from Linux to Firmware; val1 and val2 are used to describe the values to set. Whereas while receiving a response, val1 represents a possible error code, and val2 represents the actual message of get type queries. If that is so, you might want to change the variable names to be more descriptive and also use a union.

Quoted 3 lines

The fields in the two structs are fairly self-explanatory. Do we really need the additional comments? The previous version of the patch used a union, which was updated to support the fixed_up hooks. Now that the fixed_up hooks have been removed, I can revert this back to the union-based implementation.

I thought you had already adopted the virtio message format?

/* Possible values of the status field */
#define VIRTIO_GPIO_STATUS_OK 0x0
#define VIRTIO_GPIO_STATUS_ERR 0x1

struct virtio_gpio_response {
	__u8 status;
	__u8 value;
};

Seems pretty obvious what status means. value depends on the request, get_direction actually uses it, and it can be one of

#define VIRTIO_GPIO_DIRECTION_NONE 0x00
#define VIRTIO_GPIO_DIRECTION_OUT 0x01
#define VIRTIO_GPIO_DIRECTION_IN 0x02

and gpio_get uses it as a bool for the state of the GPIO.

Why do we need all the complexity for val1, val2, etc?

Andrew

#8 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 62 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:28 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 11 lines
Quoted 11 lines

drivers/gpio/gpio-rpmsg.c line 42

Quoted 8 lines
drivers/gpio/gpio-rpmsg.c new file +8 -0
+struct rpmsg_gpio_packet {
+     u8 type;        /* Message type */
+     u8 cmd;         /* Command code */
+     u8 port_idx;
+     u8 line;
+     u8 val1;
+     u8 val2;
+};

Could you please document the fields in these structs (and the below ones

too)?

Quoted 5 lines
Quoted 5 lines

From the code, it looks like while sending a message from Linux to Firmware; val1 and val2 are used to describe the values to set. Whereas while receiving a response, val1 represents a possible error code, and val2 represents the actual message of get type queries. If that is so, you might want to change the variable names to be more

descriptive and also use a union.

Quoted 3 lines
Quoted 1 line

The fields in the two structs are fairly self-explanatory. Do we really need the

additional comments?

Quoted 1 line

The previous version of the patch used a union, which was updated to support

the fixed_up hooks.

Quoted 1 line

Now that the fixed_up hooks have been removed, I can revert this back to the

union-based implementation.

I thought you had already adopted the virtio message format?

/* Possible values of the status field */
#define VIRTIO_GPIO_STATUS_OK 0x0
#define VIRTIO_GPIO_STATUS_ERR 0x1

struct virtio_gpio_response {
        __u8 status;
        __u8 value;
};

Seems pretty obvious what status means. value depends on the request, get_direction actually uses it, and it can be one of

Quoted 8 lines
#define VIRTIO_GPIO_DIRECTION_NONE              0x00
#define VIRTIO_GPIO_DIRECTION_OUT               0x01
#define VIRTIO_GPIO_DIRECTION_IN                0x02

and gpio_get uses it as a bool for the state of the GPIO.

Why do we need all the complexity for val1, val2, etc?

It is the same message format. Please see the message definition (GET_DIRECTION) below:

+GET_DIRECTION (Cmd=2)
+~~~~~~~~~~~~~~~~~~~~~
+
+**Request:**
+
+.. code-block:: none
+

+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 0   | 2   |port |line | 0   | 0  |
+   +-----+-----+-----+-----+-----+----+

+
+**Reply:**
+
+.. code-block:: none
+

+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+

+
+- **err**: See above for definitions.
+
+- **dir**: Direction.
+

+  - 0: None
+  - 1: Output
+  - 2: Input

+

Shenwei

Quoted 1 line

Andrew

#9 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Review

Quoted 11 lines
Quoted 4 lines
struct virtio_gpio_response {
        __u8 status;
        __u8 value;
};

It is the same message format. Please see the message definition (GET_DIRECTION) below:

(quoted diff) +4 -0
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Andrew

#10 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 26 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 6 lines
Quoted 4 lines
struct virtio_gpio_response {
        __u8 status;
        __u8 value;
};

It is the same message format. Please see the message definition

Quoted 9 lines

(GET_DIRECTION) below:

Review

Quoted 4 lines
(quoted diff) +4 -0
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and replies, and a second one for events. In contrast, rpmsg provides only a single communication channel, so a type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional line is introduced to handle both cases.

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to uniquely identify the target controller.

Shenwei

Quoted 1 line

Andrew

maintainer
#11 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 38 lines · Shenwei Wang
Quoted 26 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 6 lines
Quoted 4 lines
struct virtio_gpio_response {
        __u8 status;
        __u8 value;
};

It is the same message format. Please see the message definition

Quoted 9 lines

(GET_DIRECTION) below:

Review

Quoted 4 lines
(quoted diff) +4 -0
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Quoted 7 lines

Virtio uses two communication channels (virtqueues): one for requests and replies, and a second one for events. In contrast, rpmsg provides only a single communication channel, so a type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional line is introduced to handle both cases.

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing capability by way of endpoints. There is no need for a port field. One endpoint, one GPIO controller.

Quoted 4 lines

Shenwei

Quoted 1 line

Andrew

#12 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 67 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 36 lines · Shenwei Wang
Quoted 36 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 6 lines
Quoted 4 lines
struct virtio_gpio_response {
        __u8 status;
        __u8 value;
};

It is the same message format. Please see the message definition

(GET_DIRECTION) below:

Quoted 4 lines
(quoted diff) +4 -0
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+
Quoted 6 lines
Quoted 2 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 4 lines

In contrast, rpmsg provides only a single communication channel, so a type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

Quoted 9 lines

line is introduced to handle both cases.

Quoted 2 lines

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing capability by way of endpoints. There is no need for a port field. One endpoint, one GPIO controller.

You still need a way to let the remote side know which port the endpoint maps to, either by embedding the port information in the message (the current way), or by sending it separately.

Shenwei

Quoted 4 lines
Quoted 4 lines

Shenwei

Quoted 1 line

Andrew

maintainer
#13 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 73 lines · Shenwei Wang
Quoted 73 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 36 lines · Shenwei Wang
Quoted 36 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 6 lines
Quoted 4 lines
struct virtio_gpio_response {
        __u8 status;
        __u8 value;
};

It is the same message format. Please see the message definition

(GET_DIRECTION) below:

Quoted 4 lines
(quoted diff) +4 -0
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+
Quoted 6 lines
Quoted 2 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 4 lines

In contrast, rpmsg provides only a single communication channel, so a type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 2 lines

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

uniquely identify the target controller.

Quoted 9 lines
Quoted 4 lines

I have commented on this before - RPMSG is already providing multiplexing capability by way of endpoints. There is no need for a port field. One endpoint, one GPIO controller.

You still need a way to let the remote side know which port the endpoint maps to, either by embedding the port information in the message (the current way), or by sending it separately.

An endpoint is created with every namespace request. There should be one namespace request for every GPIO controller, which yields a unique endpoint for each controller and eliminates the need for an extra field to identify them.

Quoted 6 lines

Shenwei

Quoted 4 lines
Quoted 4 lines

Shenwei

Quoted 1 line

Andrew

#14 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Hi Mathieu,

Quoted 72 lines · Mathieu Poirier
Quoted 71 lines · Shenwei Wang
Quoted 71 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 33 lines · Shenwei Wang
Quoted 33 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 5 lines
Quoted 4 lines
struct virtio_gpio_response {
         __u8 status;
         __u8 value;
};

It is the same message format. Please see the message definition

(GET_DIRECTION) below:

Quoted 4 lines
(quoted diff) +4 -0
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+
Quoted 5 lines
Quoted 2 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 4 lines

In contrast, rpmsg provides only a single communication channel, so a type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 1 line

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing capability by way of endpoints. There is no need for a port field. One endpoint, one GPIO controller.

Quoted 8 lines
Quoted 4 lines

You still need a way to let the remote side know which port the endpoint maps to, either by embedding the port information in the message (the current way), or by sending it separately.

An endpoint is created with every namespace request. There should be one namespace request for every GPIO controller, which yields a unique endpoint for each controller and eliminates the need for an extra field to identify them.

Right, but this can still be done by just having one namespace request. We can create new endpoints bound to an existing namespace/channel by invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/[email protected]/

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io
   a. ept1 -> gpio-controller@1
   b. ept2 -> gpio-controller@2

2. namespace/channel#2 = rpmsg-i2c
   a. ept1 -> i2c@1
   b. ept2 -> i2c@2
   c. ept3 -> i2c@3

etc...

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

#15 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 126 lines

-----Original Message-----
From: Padhi, Beleswar <[email protected]>
Sent: Wednesday, April 29, 2026 1:07 PM
To: Mathieu Poirier <[email protected]>; Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver Hi Mathieu,

Quoted 1 line · Mathieu Poirier

On Wed, 29 Apr 2026 at 10:53, Shenwei Wang <[email protected]>

Quoted 22 lines · wrote:
Quoted 22 lines
Quoted 22 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver On Tue, Apr 28, 2026 at 03:24:59PM +0000, Shenwei Wang

Quoted 54 lines · wrote:
Quoted 54 lines
Quoted 54 lines
Quoted 33 lines
Quoted 33 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 5 lines
Quoted 4 lines
struct virtio_gpio_response {
         __u8 status;
         __u8 value;
};

It is the same message format. Please see the message definition

(GET_DIRECTION) below:

Quoted 4 lines
(quoted diff) +4 -0
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+
Quoted 6 lines
Quoted 2 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 5 lines

In contrast, rpmsg provides only a single communication channel, so a type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 2 lines

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing capability by way of endpoints. There is no need for a port field. One endpoint, one GPIO controller.

Quoted 8 lines
Quoted 4 lines

You still need a way to let the remote side know which port the endpoint maps to, either by embedding the port information in the message (the current way), or by sending it separately.

An endpoint is created with every namespace request. There should be one namespace request for every GPIO controller, which yields a unique endpoint for each controller and eliminates the need for an extra field to identify them.

Right, but this can still be done by just having one namespace request. We can create new endpoints bound to an existing namespace/channel by invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel/
.org%2Fall%2F29485742-6e49-482e-b73d- 228295daaeec%40ti.com%2F&data=05%7C02%7Cshenwei.wang%40nxp.com%7 Caba62d7a899849fd57f708dea61a1d8b%7C686ea1d3bc2b4c6fa92cd99c5c3016 35%7C0%7C0%7C639130828278097401%7CUnknown%7CTWFpbGZsb3d8eyJFb XB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpb CIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=NLLYQ0NZCnYKLT%2F2OMDZE SKgC%2Fme3FoUNqqEGBOIY2k%3D&reserved=0

My mental model looks like this for the complete picture:

Quoted 9 lines

1. namespace/channel#1 = rpmsg-io

    a. ept1 -> gpio-controller@1
    b. ept2 -> gpio-controller@2

2. namespace/channel#2 = rpmsg-i2c

    a. ept1 -> i2c@1
    b. ept2 -> i2c@2
    c. ept3 -> i2c@3

The GPIO nodes will act as providers.
Mapping the port index into the service name is a possible solution, but I don't believe it's better than embedding that information in the message. A stateless approach feels simpler and cleaner overall.

Thanks,
Shenwei

Quoted 7 lines

etc...

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

#16 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 126 lines · Shenwei Wang
Quoted 126 lines

-----Original Message-----
From: Padhi, Beleswar <[email protected]>
Sent: Wednesday, April 29, 2026 1:07 PM
To: Mathieu Poirier <[email protected]>; Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver Hi Mathieu,

Quoted 1 line · Mathieu Poirier

On Wed, 29 Apr 2026 at 10:53, Shenwei Wang <[email protected]>

Quoted 21 lines · wrote:
Quoted 21 lines
Quoted 21 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver On Tue, Apr 28, 2026 at 03:24:59PM +0000, Shenwei Wang

Quoted 53 lines · wrote:
Quoted 53 lines
Quoted 53 lines
Quoted 32 lines
Quoted 32 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 5 lines
Quoted 4 lines
struct virtio_gpio_response {
          __u8 status;
          __u8 value;
};

It is the same message format. Please see the message definition

(GET_DIRECTION) below:

Quoted 4 lines
(quoted diff) +4 -0
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+
Quoted 6 lines
Quoted 2 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 5 lines

In contrast, rpmsg provides only a single communication channel, so a type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 2 lines

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing capability by way of endpoints. There is no need for a port field. One endpoint, one GPIO controller.

Quoted 8 lines
Quoted 4 lines

You still need a way to let the remote side know which port the endpoint maps to, either by embedding the port information in the message (the current way), or by sending it separately.

An endpoint is created with every namespace request. There should be one namespace request for every GPIO controller, which yields a unique endpoint for each controller and eliminates the need for an extra field to identify them.

Right, but this can still be done by just having one namespace request. We can create new endpoints bound to an existing namespace/channel by invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel/
.org%2Fall%2F29485742-6e49-482e-b73d- 228295daaeec%40ti.com%2F&data=05%7C02%7Cshenwei.wang%40nxp.com%7 Caba62d7a899849fd57f708dea61a1d8b%7C686ea1d3bc2b4c6fa92cd99c5c3016 35%7C0%7C0%7C639130828278097401%7CUnknown%7CTWFpbGZsb3d8eyJFb XB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpb CIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=NLLYQ0NZCnYKLT%2F2OMDZE SKgC%2Fme3FoUNqqEGBOIY2k%3D&reserved=0

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io

     a. ept1 -> gpio-controller@1
     b. ept2 -> gpio-controller@2
Quoted 7 lines
Quoted 5 lines

2. namespace/channel#2 = rpmsg-i2c

     a. ept1 -> i2c@1
     b. ept2 -> i2c@2
     c. ept3 -> i2c@3

The GPIO nodes will act as providers.
Mapping the port index into the service name is a possible solution,

I am not suggesting this. Infact the opposite. Let there be a single rpmsg service "rpmsg-io" for gpio. And multiple endpoints within the service, each for one controller. Once you have relayed this info (dynamic ept addr corresponding to each port) back to the firmware, you no longer need the "port" field in the message anymore.

Did you get a chance to analyze this?:
https://lore.kernel.org/all/[email protected]/

Thanks,
Beleswar

Quoted 14 lines

but I don't believe it's better than
embedding that information in the message. A stateless approach feels simpler and cleaner overall.

Thanks,
Shenwei

Quoted 7 lines

etc...

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

maintainer
#17 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

In reply to Padhi, Beleswar
Quoted 86 lines · Beleswar

Hi Mathieu,

Quoted 72 lines · Mathieu Poirier
Quoted 71 lines · Shenwei Wang
Quoted 71 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 33 lines · Shenwei Wang
Quoted 33 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 5 lines
Quoted 4 lines
struct virtio_gpio_response {
         __u8 status;
         __u8 value;
};

It is the same message format. Please see the message definition

(GET_DIRECTION) below:

Quoted 4 lines
(quoted diff) +4 -0
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+
Quoted 5 lines
Quoted 2 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 4 lines

In contrast, rpmsg provides only a single communication channel, so a type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 1 line

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing capability by way of endpoints. There is no need for a port field. One endpoint, one GPIO controller.

Quoted 8 lines
Quoted 4 lines

You still need a way to let the remote side know which port the endpoint maps to, either by embedding the port information in the message (the current way), or by sending it separately.

An endpoint is created with every namespace request. There should be one namespace request for every GPIO controller, which yields a unique endpoint for each controller and eliminates the need for an extra field to identify them.

Quoted 5 lines

Right, but this can still be done by just having one namespace request. We can create new endpoints bound to an existing namespace/channel by invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io

    a. ept1 -> gpio-controller@1
    b. ept2 -> gpio-controller@2

I've asked for one endpoint per GPIO controller since the very beginning. I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints. I'll have to look at your link and reflect on that. Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level. This is the only way this work can move forward.

Quoted 14 lines

2. namespace/channel#2 = rpmsg-i2c

    a. ept1 -> i2c@1
    b. ept2 -> i2c@2
    c. ept3 -> i2c@3

etc...

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

#18 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Hello,

Quoted 102 lines · Mathieu Poirier
Quoted 86 lines · Beleswar

Hi Mathieu,

Quoted 72 lines · Mathieu Poirier
Quoted 71 lines · Shenwei Wang
Quoted 71 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 33 lines · Shenwei Wang
Quoted 33 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 5 lines
Quoted 4 lines
struct virtio_gpio_response {
          __u8 status;
          __u8 value;
};

It is the same message format. Please see the message definition

(GET_DIRECTION) below:

Quoted 4 lines
(quoted diff) +4 -0
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+
Quoted 5 lines
Quoted 2 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 4 lines

In contrast, rpmsg provides only a single communication channel, so a type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 1 line

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing capability by way of endpoints. There is no need for a port field. One endpoint, one GPIO controller.

Quoted 8 lines
Quoted 4 lines

You still need a way to let the remote side know which port the endpoint maps to, either by embedding the port information in the message (the current way), or by sending it separately.

An endpoint is created with every namespace request. There should be one namespace request for every GPIO controller, which yields a unique endpoint for each controller and eliminates the need for an extra field to identify them.

Quoted 5 lines

Right, but this can still be done by just having one namespace request. We can create new endpoints bound to an existing namespace/channel by invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io

     a. ept1 -> gpio-controller@1
     b. ept2 -> gpio-controller@2
Quoted 8 lines

I've asked for one endpoint per GPIO controller since the very beginning. I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints. I'll have to look at your link and reflect on that. Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level. This is the only way this work can move forward.

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

With a multi-namespace approach, the namespace could be rpmsg-io-[addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

- match the RPMsg probe with the DT,
- provide a simple mapping between the port and the endpoint on both sides,
- allow multiple endpoints on the remote side,
- provide a simple discovery mechanism for remote capabilities.

Regards,
Arnaud

Quoted 15 lines
Quoted 14 lines

2. namespace/channel#2 = rpmsg-i2c

     a. ept1 -> i2c@1
     b. ept2 -> i2c@2
     c. ept3 -> i2c@3

etc...

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

#19 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Hello Arnaud,

Quoted 114 lines · Arnaud POULIQUEN

Hello,

Quoted 102 lines · Mathieu Poirier
Quoted 86 lines · Beleswar

Hi Mathieu,

Quoted 72 lines · Mathieu Poirier
Quoted 71 lines · Shenwei Wang
Quoted 71 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 33 lines · Shenwei Wang
Quoted 33 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 5 lines
Quoted 4 lines

struct virtio_gpio_response {
          __u8 status;
          __u8 value;
};

It is the same message format. Please see the message definition

(GET_DIRECTION) below:

Quoted 4 lines

+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+

Quoted 5 lines
Quoted 2 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 4 lines

In contrast, rpmsg provides only a single communication channel, so a type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 1 line

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing capability by way of endpoints.  There is no need for a port field.  One endpoint, one GPIO controller.

Quoted 8 lines
Quoted 4 lines

You still need a way to let the remote side know which port the endpoint maps to, either by embedding the port information in the message (the current way), or by sending it separately.

An endpoint is created with every namespace request.  There should be one namespace request for every GPIO controller, which yields a unique endpoint for each controller and eliminates the need for an extra field to identify them.

Quoted 5 lines

Right, but this can still be done by just having one namespace request. We can create new endpoints bound to an existing namespace/channel by invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io
     a. ept1 -> gpio-controller@1
     b. ept2 -> gpio-controller@2

Quoted 8 lines

I've asked for one endpoint per GPIO controller since the very beginning.  I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints.  I'll have to look at your link and reflect on that.  Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level.  This is the only way this work can move forward.

Quoted 3 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this Linux need not have the port field in the message everytime its sending a message.

Quoted 2 lines

With a multi-namespace approach, the namespace could be rpmsg-io-[addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel                                                                                                                                                   
[    9.290275] virtio_rpmsg_bus virtio0: creating channel ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13: new channel: 0x401 -> 0xd!

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

Quoted 2 lines

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 1 line

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

Thanks,
Beleswar

Quoted 20 lines

Regards,
Arnaud

Quoted 15 lines
Quoted 14 lines

2. namespace/channel#2 = rpmsg-i2c
     a. ept1 -> i2c@1
     b. ept2 -> i2c@2
     c. ept3 -> i2c@3

etc...

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

#20 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 128 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 114 lines · Arnaud POULIQUEN

Hello,

Quoted 102 lines · Mathieu Poirier
Quoted 86 lines · Beleswar

Hi Mathieu,

Quoted 72 lines · Mathieu Poirier
Quoted 71 lines · Shenwei Wang
Quoted 71 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 33 lines · Shenwei Wang
Quoted 33 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 5 lines
Quoted 4 lines

struct virtio_gpio_response {
          __u8 status;
          __u8 value;
};

It is the same message format. Please see the message definition

(GET_DIRECTION) below:

Quoted 4 lines

+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+

Quoted 5 lines
Quoted 2 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 4 lines

In contrast, rpmsg provides only a single communication channel, so a type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 1 line

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing capability by way of endpoints.  There is no need for a port field.  One endpoint, one GPIO controller.

Quoted 8 lines
Quoted 4 lines

You still need a way to let the remote side know which port the endpoint maps to, either by embedding the port information in the message (the current way), or by sending it separately.

An endpoint is created with every namespace request.  There should be one namespace request for every GPIO controller, which yields a unique endpoint for each controller and eliminates the need for an extra field to identify them.

Quoted 5 lines

Right, but this can still be done by just having one namespace request. We can create new endpoints bound to an existing namespace/channel by invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io
     a. ept1 -> gpio-controller@1
     b. ept2 -> gpio-controller@2

Quoted 8 lines

I've asked for one endpoint per GPIO controller since the very beginning.  I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints.  I'll have to look at your link and reflect on that.  Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level.  This is the only way this work can move forward.

Quoted 3 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this Linux need not have the port field in the message everytime its sending a message.

Quoted 1 line
Quoted 6 lines
Quoted 1 line

With a multi-namespace approach, the namespace could be rpmsg-io-[addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here
my sentence should be;
With a multi-namespace approach, the namespace could be rpmsg-io-[port], where [port] corresponds to the GPIO controller port in the DT.

For instance:

      rpmsg {
        rpmsg-io {
          #address-cells = <1>;
          #size-cells = <0>;

          gpio@25 {
            compatible = "rpmsg-gpio";
            reg = <25>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };

          gpio@32 {
            compatible = "rpmsg-gpio";
            reg = <32>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };
        };
      };

rpmsg-io-25 would match with gpio@25
rpmsg-io-32 would match with gpio@32

Quoted 17 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13: new channel: 0x401 -> 0xd!
Quoted 3 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.

Quoted 22 lines
Quoted 4 lines

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 1 line

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 7 lines
Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Thanks and Regards,Arnaud

Quoted 24 lines

Thanks,
Beleswar

Quoted 20 lines

Regards,
Arnaud

Quoted 15 lines
Quoted 14 lines

2. namespace/channel#2 = rpmsg-i2c
     a. ept1 -> i2c@1
     b. ept2 -> i2c@2
     c. ept3 -> i2c@3

etc...

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

#21 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Hi Arnaud,

Quoted 16 lines · Arnaud POULIQUEN
Quoted 13 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 10 lines · Arnaud POULIQUEN

Hello,

Quoted 7 lines · Mathieu Poirier
Quoted 5 lines · Beleswar

Hi Mathieu,

Quoted 1 line · Mathieu Poirier

On Wed, 29 Apr 2026 at 10:53, Shenwei Wang <[email protected]> wrote:

[...]

Quoted 117 lines
Quoted 27 lines
Quoted 16 lines
Quoted 7 lines
Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io
      a. ept1 -> gpio-controller@1
      b. ept2 -> gpio-controller@2

Quoted 8 lines

I've asked for one endpoint per GPIO controller since the very beginning.  I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints.  I'll have to look at your link and reflect on that.  Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level.  This is the only way this work can move forward.

Quoted 3 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this Linux need not have the port field in the message everytime its sending a message.

Quoted 1 line
Quoted 6 lines
Quoted 1 line

With a multi-namespace approach, the namespace could be rpmsg-io-[addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here
my sentence should be;
 With a multi-namespace approach, the namespace could be rpmsg-io-[port], where [port] corresponds to the GPIO controller port in the DT.

For instance:

      rpmsg {
        rpmsg-io {
          #address-cells = <1>;
          #size-cells = <0>;

          gpio@25 {
            compatible = "rpmsg-gpio";
            reg = <25>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };

          gpio@32 {
            compatible = "rpmsg-gpio";
            reg = <32>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };
        };
      };

 rpmsg-io-25  would match with gpio@25
 rpmsg-io-32  would match with gpio@32

Quoted 17 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13: new channel: 0x401 -> 0xd!
Quoted 3 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.

Quoted 24 lines

Quoted 2 lines

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 1 line

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

Quoted 8 lines
Quoted 4 lines

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

In my solution, there is no need to have this map of endpoint to GPIO port at Linux side. This aligns more with virtio-gpio design as well.

Quoted 8 lines

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Sure, let me take an example:
Assumptions: 3 GPIO ports in DT, 3 endpoints in Linux (one per port), 1 endpoint in remote (0xd) and 1 rpmsg channel (rpmsg-io)

       rpmsg {
         rpmsg-io {
           #address-cells = <1>;
           #size-cells = <0>;

           gpio@25 {
             compatible = "rpmsg-gpio";
             reg = <25>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };

           gpio@32 {
             compatible = "rpmsg-gpio";
             reg = <32>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };

           gpio@35 {
             compatible = "rpmsg-gpio";
             reg = <35>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };
         };
       };

Code Flow:
1. "rpmsg-io" channel is announced from remote firmware with unique dst ept = 0xd.

2. rpmsg_core.c creates the default dynamic local ept for the channel ept = 0x405.

3. rpmsg_core.c assigns the allocated addr to rpdev device:
    rpdev->src = 0x405 and rpdev->dst = 0xd.

4. rpmsg_gpio_channel_probe() is triggered. For *each* of the GPIO ports
    in DT, it will trigger rpmsg_gpiochip_register() which will now:
       a. Call port->ept = rpmsg_create_ept(rpdev,
                                                                   rpmsg_gpio_channel_callback, port, {rpdev.id.name, RPMSG_ADDR_ANY, RPMSG_ADDR_ANY}); Ex- port->ept->addr = 0x408

       b. Prepare a 8-byte message having 2 fields:
           port->ept->addr (0x408) and port->idx (25)

       c. Send this message to remote firmware on default channel ept (0x405 -> 0xd) by:
           rpmsg_send(rpdev->ept, &message, sizeof(message));

       d. Remote side receives this message and creates a map of the linux_ept_addr to gpio_port. (0x408 <-> 25)

5. After this point, any gpio messages sent from Linux from gpio port endpoints (Ex- 0x408) can be decoded at remote side by looking up its map (Ex- map[0x408] = 25).

6. Any messages sent from remote to Linux for a particular gpio port can also be decoded at Linux by simply fetching the priv pointer to get the per-port device:
    struct rpmsg_gpio_port *port = priv;

So Linux does not need to send the port idx everytime while sending a gpio message anymore.

Thanks,
Beleswar

[...]

#22 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Hi Beleswar,

Quoted 231 lines · Beleswar Prasad Padhi

Hi Arnaud,

Quoted 16 lines · Arnaud POULIQUEN
Quoted 13 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 10 lines · Arnaud POULIQUEN

Hello,

Quoted 7 lines · Mathieu Poirier
Quoted 5 lines · Beleswar

Hi Mathieu,

Quoted 1 line · Mathieu Poirier

On Wed, 29 Apr 2026 at 10:53, Shenwei Wang <[email protected]> wrote:

[...]

Quoted 117 lines
Quoted 27 lines
Quoted 16 lines
Quoted 7 lines
Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io
      a. ept1 -> gpio-controller@1
      b. ept2 -> gpio-controller@2

Quoted 8 lines

I've asked for one endpoint per GPIO controller since the very beginning.  I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints.  I'll have to look at your link and reflect on that.  Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level.  This is the only way this work can move forward.

Quoted 3 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this Linux need not have the port field in the message everytime its sending a message.

Quoted 1 line
Quoted 6 lines
Quoted 1 line

With a multi-namespace approach, the namespace could be rpmsg-io-[addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here
my sentence should be;
 With a multi-namespace approach, the namespace could be rpmsg-io-[port], where [port] corresponds to the GPIO controller port in the DT.

For instance:

      rpmsg {
        rpmsg-io {
          #address-cells = <1>;
          #size-cells = <0>;

          gpio@25 {
            compatible = "rpmsg-gpio";
            reg = <25>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };

          gpio@32 {
            compatible = "rpmsg-gpio";
            reg = <32>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };
        };
      };

 rpmsg-io-25  would match with gpio@25
 rpmsg-io-32  would match with gpio@32

Quoted 17 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13: new channel: 0x401 -> 0xd!
Quoted 3 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.

Quoted 24 lines
Quoted 3 lines

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 1 line

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

Quoted 8 lines
Quoted 4 lines

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

In my solution, there is no need to have this map of endpoint to GPIO port at Linux side. This aligns more with virtio-gpio design as well.

Quoted 8 lines

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Sure, let me take an example:
Assumptions: 3 GPIO ports in DT, 3 endpoints in Linux (one per port), 1 endpoint in remote (0xd) and 1 rpmsg channel (rpmsg-io)

       rpmsg {
         rpmsg-io {
           #address-cells = <1>;
           #size-cells = <0>;

           gpio@25 {
             compatible = "rpmsg-gpio";
             reg = <25>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };

           gpio@32 {
             compatible = "rpmsg-gpio";
             reg = <32>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };

           gpio@35 {
             compatible = "rpmsg-gpio";
             reg = <35>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };
         };
       };

Code Flow:
1. "rpmsg-io" channel is announced from remote firmware with unique dst ept = 0xd.

2. rpmsg_core.c creates the default dynamic local ept for the channel ept = 0x405.

3. rpmsg_core.c assigns the allocated addr to rpdev device:
    rpdev->src = 0x405 and rpdev->dst = 0xd.

4. rpmsg_gpio_channel_probe() is triggered. For *each* of the GPIO ports
    in DT, it will trigger rpmsg_gpiochip_register() which will now:
       a. Call port->ept = rpmsg_create_ept(rpdev,
                                                                   rpmsg_gpio_channel_callback, port, {rpdev.id.name, RPMSG_ADDR_ANY, RPMSG_ADDR_ANY}); Ex- port->ept->addr = 0x408

       b. Prepare a 8-byte message having 2 fields:
           port->ept->addr (0x408) and port->idx (25)

       c. Send this message to remote firmware on default channel ept (0x405 -> 0xd) by:
           rpmsg_send(rpdev->ept, &message, sizeof(message));

       d. Remote side receives this message and creates a map of the linux_ept_addr to gpio_port. (0x408 <-> 25)

Quoted 9 lines

5. After this point, any gpio messages sent from Linux from gpio port endpoints (Ex- 0x408) can be decoded at remote side by looking up its map (Ex- map[0x408] = 25).

6. Any messages sent from remote to Linux for a particular gpio port can also be decoded at Linux by simply fetching the priv pointer to get the per-port device:
    struct rpmsg_gpio_port *port = priv;

Thanks for the details!

To sum up:
- the default endpoint acts as the GPIO controller (0x405),
- one extra Linux endpoint is created per port defined in DT.

This should work, but my concerns remain the same:

1) This implementation forces the remote processor to handle a single endpoint instead of one endpoint per port. This may add complexity to the remote firmware if each port is managed in a separate thread.

2) Linux, as a consumer, should not expose its capabilities to the remote side (in your proposal it enumerates the ports defined in the DT). In my view, the remote processor should expose its capabilities as the provider.

From my perspective, based on your proposal:
1) Linux should send a get_config message to the remote proc (0x405 ->
0xD). 2) The remote processor would respond with the list of ports, associated
with an remote endpoint addresses.
3) Linux would parse the response, compare it with the DT, enable the GPIO ports accordingly, creating it local endpoint and associating it with the remote endpoint.
Using name service to identify the ports should avoid step 1 & 2 ...

At the end, whatever solution is implemented, my main concern is that the Linux driver design should, if possible, avoid adding unnecessary complexity or limitations on the remote side (for instance in openAMP project).

Thanks,
Arnaud

Quoted 8 lines

So Linux does not need to send the port idx everytime while sending a gpio message anymore.

Thanks,
Beleswar

[...]

#23 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Hi Arnaud,

Quoted 4 lines · Arnaud POULIQUEN

Hi Beleswar,

On 5/4/26 10:17, Beleswar Prasad Padhi wrote:

[...]

Quoted 95 lines
Quoted 79 lines
Quoted 9 lines

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Sure, let me take an example:
Assumptions: 3 GPIO ports in DT, 3 endpoints in Linux (one per port), 1 endpoint in remote (0xd) and 1 rpmsg channel (rpmsg-io)

        rpmsg {
          rpmsg-io {
            #address-cells = <1>;
            #size-cells = <0>;

            gpio@25 {
              compatible = "rpmsg-gpio";
              reg = <25>;
              gpio-controller;
              #gpio-cells = <2>;
              #interrupt-cells = <2>;
              interrupt-controller;
            };

            gpio@32 {
              compatible = "rpmsg-gpio";
              reg = <32>;
              gpio-controller;
              #gpio-cells = <2>;
              #interrupt-cells = <2>;
              interrupt-controller;
            };

            gpio@35 {
              compatible = "rpmsg-gpio";
              reg = <35>;
              gpio-controller;
              #gpio-cells = <2>;
              #interrupt-cells = <2>;
              interrupt-controller;
            };
          };
        };

Code Flow:
1. "rpmsg-io" channel is announced from remote firmware with unique dst ept = 0xd.

2. rpmsg_core.c creates the default dynamic local ept for the channel ept = 0x405.

3. rpmsg_core.c assigns the allocated addr to rpdev device:
     rpdev->src = 0x405 and rpdev->dst = 0xd.

4. rpmsg_gpio_channel_probe() is triggered. For *each* of the GPIO ports
     in DT, it will trigger rpmsg_gpiochip_register() which will now:
        a. Call port->ept = rpmsg_create_ept(rpdev,
                                                                    rpmsg_gpio_channel_callback, port, {rpdev.id.name, RPMSG_ADDR_ANY, RPMSG_ADDR_ANY}); Ex- port->ept->addr = 0x408

        b. Prepare a 8-byte message having 2 fields:
            port->ept->addr (0x408) and port->idx (25)

        c. Send this message to remote firmware on default channel ept (0x405 -> 0xd) by:
            rpmsg_send(rpdev->ept, &message, sizeof(message));

        d. Remote side receives this message and creates a map of the linux_ept_addr to gpio_port. (0x408 <-> 25)

Quoted 9 lines

5. After this point, any gpio messages sent from Linux from gpio port endpoints (Ex- 0x408) can be decoded at remote side by looking up its map (Ex- map[0x408] = 25).

6. Any messages sent from remote to Linux for a particular gpio port can also be decoded at Linux by simply fetching the priv pointer to get the per-port device:
     struct rpmsg_gpio_port *port = priv;

Thanks for the details!

To sum up:
- the default endpoint acts as the GPIO controller (0x405),
- one extra Linux endpoint is created per port defined in DT.

Quoted 5 lines

This should work, but my concerns remain the same:

  1) This implementation forces the remote processor to handle a single endpoint instead of one endpoint per port. This may add complexity to the remote firmware if each port is managed in a separate thread.

A. Not really, I just chose 1 remote endpoint for this example as you suggested to. We can scale it for two-way communication via the get_config message like you suggested below.

B. Isn't it a bad design of the firmware if it is handling 10 gpio ports in 10 threads? The logic to handle all the ports is the same, only the parameters (e.g. line number, msg) is different.

Quoted 4 lines

  2) Linux, as a consumer, should not expose its capabilities to the remote
     side (in your proposal it enumerates the ports defined in the DT).     In my view, the remote processor should expose its capabilities as the provider.

Agreed on this.

Quoted 4 lines

From my perspective, based on your proposal:
 1) Linux should send a get_config message to the remote proc (0x405 -> 0xD). 2) The remote processor would respond with the list of ports, associated with an remote endpoint addresses.

Agreed, we can scale it for multiple remote endpoints like this.

Quoted 4 lines

 3) Linux would parse the response, compare it with the DT, enable the GPIO ports accordingly, creating it local endpoint and associating it with the remote endpoint.
Using name service to identify the ports should avoid step 1 & 2 ...

Yes, but won't that make a lot of hard-codings in the driver?

+static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = { +    { .name = "rpmsg-io-25" },
+    { .name = "rpmsg-io-32" },
+    { .name = "rpmsg-io-35" },
+    { },
+};

What if tomorrow another vendor decides to add more remoteproc controlled GPIO ports to Linux, they would have to update this struct in the driver everytime. And the port indexes (25/32/35) could also differ between vendors. We should make the driver dynamic i.e. vendor agnostic.

I think querying the remote firmware at runtime (step 1 & 2 above) is a common design pattern and makes the driver vendor agnostic. But feel free to correct me.

Quoted 4 lines

At the end, whatever solution is implemented, my main concern is that the Linux driver design should, if possible, avoid adding unnecessary complexity or limitations on the remote side (for instance in openAMP project).

Yes definitely, I want the same. Feel free to let me know if this does not suit with the OpenAMP project.

Thanks,
Beleswar

Quoted 14 lines

Thanks,
Arnaud

Quoted 8 lines

So Linux does not need to send the port idx everytime while sending a gpio message anymore.

Thanks,
Beleswar

[...]

#24 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Hi Beleswar

Quoted 157 lines · Beleswar Prasad Padhi

Hi Arnaud,

Quoted 4 lines · Arnaud POULIQUEN

Hi Beleswar,

On 5/4/26 10:17, Beleswar Prasad Padhi wrote:

[...]

Quoted 95 lines
Quoted 79 lines
Quoted 9 lines

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Sure, let me take an example:
Assumptions: 3 GPIO ports in DT, 3 endpoints in Linux (one per port), 1 endpoint in remote (0xd) and 1 rpmsg channel (rpmsg-io)

        rpmsg {
          rpmsg-io {
            #address-cells = <1>;
            #size-cells = <0>;

            gpio@25 {
              compatible = "rpmsg-gpio";
              reg = <25>;
              gpio-controller;
              #gpio-cells = <2>;
              #interrupt-cells = <2>;
              interrupt-controller;
            };

            gpio@32 {
              compatible = "rpmsg-gpio";
              reg = <32>;
              gpio-controller;
              #gpio-cells = <2>;
              #interrupt-cells = <2>;
              interrupt-controller;
            };

            gpio@35 {
              compatible = "rpmsg-gpio";
              reg = <35>;
              gpio-controller;
              #gpio-cells = <2>;
              #interrupt-cells = <2>;
              interrupt-controller;
            };
          };
        };

Code Flow:
1. "rpmsg-io" channel is announced from remote firmware with unique dst ept = 0xd.

2. rpmsg_core.c creates the default dynamic local ept for the channel ept = 0x405.

3. rpmsg_core.c assigns the allocated addr to rpdev device:
     rpdev->src = 0x405 and rpdev->dst = 0xd.

4. rpmsg_gpio_channel_probe() is triggered. For *each* of the GPIO ports
     in DT, it will trigger rpmsg_gpiochip_register() which will now:
        a. Call port->ept = rpmsg_create_ept(rpdev,
                                                                    rpmsg_gpio_channel_callback, port, {rpdev.id.name, RPMSG_ADDR_ANY, RPMSG_ADDR_ANY}); Ex- port->ept->addr = 0x408

        b. Prepare a 8-byte message having 2 fields:
            port->ept->addr (0x408) and port->idx (25)

        c. Send this message to remote firmware on default channel ept (0x405 -> 0xd) by:
            rpmsg_send(rpdev->ept, &message, sizeof(message));

        d. Remote side receives this message and creates a map of the linux_ept_addr to gpio_port. (0x408 <-> 25)

Quoted 9 lines

5. After this point, any gpio messages sent from Linux from gpio port endpoints (Ex- 0x408) can be decoded at remote side by looking up its map (Ex- map[0x408] = 25).

6. Any messages sent from remote to Linux for a particular gpio port can also be decoded at Linux by simply fetching the priv pointer to get the per-port device:
     struct rpmsg_gpio_port *port = priv;

Thanks for the details!

To sum up:
- the default endpoint acts as the GPIO controller (0x405),
- one extra Linux endpoint is created per port defined in DT.

Quoted 5 lines

This should work, but my concerns remain the same:

  1) This implementation forces the remote processor to handle a single endpoint instead of one endpoint per port. This may add complexity to the remote firmware if each port is managed in a separate thread.

A. Not really, I just chose 1 remote endpoint for this example as you
    suggested to. We can scale it for two-way communication via the get_config message like you suggested below.

B. Isn't it a bad design of the firmware if it is handling 10 gpio ports
    in 10 threads? The logic to handle all the ports is the same, only the parameters (e.g. line number, msg) is different.

Quoted 4 lines

  2) Linux, as a consumer, should not expose its capabilities to the remote
     side (in your proposal it enumerates the ports defined in the DT).     In my view, the remote processor should expose its capabilities as the provider.

Agreed on this.

Quoted 4 lines

From my perspective, based on your proposal:
 1) Linux should send a get_config message to the remote proc (0x405 -> 0xD). 2) The remote processor would respond with the list of ports, associated with an remote endpoint addresses.

Agreed, we can scale it for multiple remote endpoints like this.

Quoted 4 lines

 3) Linux would parse the response, compare it with the DT, enable the GPIO ports accordingly, creating it local endpoint and associating it with the remote endpoint.
Using name service to identify the ports should avoid step 1 & 2 ...

Yes, but won't that make a lot of hard-codings in the driver?

(quoted diff) +6 -0
+static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = {
+    { .name = "rpmsg-io-25" },
+    { .name = "rpmsg-io-32" },
+    { .name = "rpmsg-io-35" },
+    { },
+};

What if tomorrow another vendor decides to add more remoteproc controlled GPIO ports to Linux, they would have to update this struct in the driver everytime. And the port indexes (25/32/35) could also differ between vendors. We should make the driver dynamic i.e. vendor agnostic.

Quoted 4 lines

I think querying the remote firmware at runtime (step 1 & 2 above) is a common design pattern and makes the driver vendor agnostic. But feel free to correct me.

You are right. My proposal would require a patch in rpmsg-core. The idea of allowing a postfix in the compatible string has been discussed before, but, if I remember correctly, it was not concluded.

/* rpmsg devices and drivers are matched using the service name */ static inline int rpmsg_id_match(const struct rpmsg_device *rpdev,
const struct rpmsg_device_id *id)

{
	size_t len;

+ len = strnlen(id->name, RPMSG_NAME_SIZE);
+ if (len && id->name[len - 1] == '*')
+ return !strncmp(id->name, rpdev->id.name, len - 1);

	return strncmp(id->name, rpdev->id.name, RPMSG_NAME_SIZE) == 0;
}

Then, in rpmsg-gpio, and possibly in other drivers such as rpmsg-tty and a future rpmsg-i2c, we could use:

static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = {
    { .name = "rpmsg-io" },
    { .name = "rpmsg-io-*" },
    { },
};

If exact name matching is strongly required, then this proposal would not be suitable.

A third option would be a combination of both approaches: instantiate the device using the same name service from the remote side, as done in rpmsg-tty. In that case, a get_config message, or a similar mechanism, would also be needed to retrieve the port information from the remote side.

Tanmaya also proposed another alternative based on reserved addresses.

At this point, I suggest letting Mathieu review the discussion and recommend the most suitable approach.

Thanks,
Arnaud

Quoted 26 lines
Quoted 4 lines

At the end, whatever solution is implemented, my main concern is that the Linux driver design should, if possible, avoid adding unnecessary complexity or limitations on the remote side (for instance in openAMP project).

Yes definitely, I want the same. Feel free to let me know if this does not suit with the OpenAMP project.

Thanks,
Beleswar

Quoted 14 lines

Thanks,
Arnaud

Quoted 8 lines

So Linux does not need to send the port idx everytime while sending a gpio message anymore.

Thanks,
Beleswar

[...]

maintainer
#25 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 160 lines · Arnaud POULIQUEN

Hi Beleswar

Quoted 157 lines · Beleswar Prasad Padhi

Hi Arnaud,

Quoted 4 lines · Arnaud POULIQUEN

Hi Beleswar,

On 5/4/26 10:17, Beleswar Prasad Padhi wrote:

[...]

Quoted 95 lines
Quoted 79 lines
Quoted 9 lines

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Sure, let me take an example:
Assumptions: 3 GPIO ports in DT, 3 endpoints in Linux (one per port), 1 endpoint in remote (0xd) and 1 rpmsg channel (rpmsg-io)

        rpmsg {
          rpmsg-io {
            #address-cells = <1>;
            #size-cells = <0>;

            gpio@25 {
              compatible = "rpmsg-gpio";
              reg = <25>;
              gpio-controller;
              #gpio-cells = <2>;
              #interrupt-cells = <2>;
              interrupt-controller;
            };

            gpio@32 {
              compatible = "rpmsg-gpio";
              reg = <32>;
              gpio-controller;
              #gpio-cells = <2>;
              #interrupt-cells = <2>;
              interrupt-controller;
            };

            gpio@35 {
              compatible = "rpmsg-gpio";
              reg = <35>;
              gpio-controller;
              #gpio-cells = <2>;
              #interrupt-cells = <2>;
              interrupt-controller;
            };
          };
        };

Code Flow:
1. "rpmsg-io" channel is announced from remote firmware with unique dst ept = 0xd.

2. rpmsg_core.c creates the default dynamic local ept for the channel ept = 0x405.

3. rpmsg_core.c assigns the allocated addr to rpdev device:
     rpdev->src = 0x405 and rpdev->dst = 0xd.

4. rpmsg_gpio_channel_probe() is triggered. For *each* of the GPIO ports
     in DT, it will trigger rpmsg_gpiochip_register() which will now:
        a. Call port->ept = rpmsg_create_ept(rpdev,
                                                                    rpmsg_gpio_channel_callback, port, {rpdev.id.name, RPMSG_ADDR_ANY, RPMSG_ADDR_ANY}); Ex- port->ept->addr = 0x408

        b. Prepare a 8-byte message having 2 fields:
            port->ept->addr (0x408) and port->idx (25)

        c. Send this message to remote firmware on default channel ept (0x405 -> 0xd) by:
            rpmsg_send(rpdev->ept, &message, sizeof(message));

        d. Remote side receives this message and creates a map of the linux_ept_addr to gpio_port. (0x408 <-> 25)

Quoted 9 lines

5. After this point, any gpio messages sent from Linux from gpio port endpoints (Ex- 0x408) can be decoded at remote side by looking up its map (Ex- map[0x408] = 25).

6. Any messages sent from remote to Linux for a particular gpio port can also be decoded at Linux by simply fetching the priv pointer to get the per-port device:
     struct rpmsg_gpio_port *port = priv;

Thanks for the details!

To sum up:
- the default endpoint acts as the GPIO controller (0x405),
- one extra Linux endpoint is created per port defined in DT.

Quoted 5 lines

This should work, but my concerns remain the same:

  1) This implementation forces the remote processor to handle a single endpoint instead of one endpoint per port. This may add complexity to the remote firmware if each port is managed in a separate thread.

A. Not really, I just chose 1 remote endpoint for this example as you
    suggested to. We can scale it for two-way communication via the get_config message like you suggested below.

B. Isn't it a bad design of the firmware if it is handling 10 gpio ports
    in 10 threads? The logic to handle all the ports is the same, only the parameters (e.g. line number, msg) is different.

Quoted 4 lines

  2) Linux, as a consumer, should not expose its capabilities to the remote
     side (in your proposal it enumerates the ports defined in the DT).     In my view, the remote processor should expose its capabilities as the provider.

Agreed on this.

Quoted 4 lines

From my perspective, based on your proposal:
 1) Linux should send a get_config message to the remote proc (0x405 -> 0xD). 2) The remote processor would respond with the list of ports, associated with an remote endpoint addresses.

Agreed, we can scale it for multiple remote endpoints like this.

Quoted 4 lines

 3) Linux would parse the response, compare it with the DT, enable the GPIO ports accordingly, creating it local endpoint and associating it with the remote endpoint.
Using name service to identify the ports should avoid step 1 & 2 ...

Yes, but won't that make a lot of hard-codings in the driver?

(quoted diff) +6 -0
+static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = {
+    { .name = "rpmsg-io-25" },
+    { .name = "rpmsg-io-32" },
+    { .name = "rpmsg-io-35" },
+    { },
+};

What if tomorrow another vendor decides to add more remoteproc controlled GPIO ports to Linux, they would have to update this struct in the driver everytime. And the port indexes (25/32/35) could also differ between vendors. We should make the driver dynamic i.e. vendor agnostic.

Quoted 9 lines
Quoted 4 lines

I think querying the remote firmware at runtime (step 1 & 2 above) is a common design pattern and makes the driver vendor agnostic. But feel free to correct me.

You are right. My proposal would require a patch in rpmsg-core. The idea of allowing a postfix in the compatible string has been discussed before, but, if I remember correctly, it was not concluded.

I also remember discussing this. I even reviewed one of Arnaud's patch and submitted one myself. This must have been in 2020 and the reason why it wasn't merged has escaped my memory.

Quoted 13 lines

/* rpmsg devices and drivers are matched using the service name */ static inline int rpmsg_id_match(const struct rpmsg_device *rpdev,
const struct rpmsg_device_id *id)

{
	size_t len;
(quoted diff) +3 -0
+	len = strnlen(id->name, RPMSG_NAME_SIZE);
+	if (len && id->name[len - 1] == '*')
+		return !strncmp(id->name, rpdev->id.name, len - 1);
	return strncmp(id->name, rpdev->id.name, RPMSG_NAME_SIZE) == 0;
}
Quoted 7 lines

Then, in rpmsg-gpio, and possibly in other drivers such as rpmsg-tty and a future rpmsg-i2c, we could use:

static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = {
    { .name = "rpmsg-io" },
    { .name = "rpmsg-io-*" },
    { },
};

That was my initial approach. We don't even need an additional "rpmsg-io-*" in rpmsg_gpio_channel_id_table[]. All we need is:

/* rpmsg devices and drivers are matched using the service name */ static inline int rpmsg_id_match(const struct rpmsg_device *rpdev,
const struct rpmsg_device_id *id)
{
+ size_t len = strnlen(id->name, RPMSG_NAME_SIZE);

- return strncmp(id->name, rpdev->id.name, RPMSG_NAME_SIZE) == 0;
+ return strncmp(id->name, rpdev->id.name, len) == 0;
}

And let the rpmsg-virtio-gpio driver parse @rpdev->id.name to match with a GPIO controller in the DT.

Quoted 9 lines

If exact name matching is strongly required, then this proposal would not be suitablea.

A third option would be a combination of both approaches: instantiate the device using the same name service from the remote side, as done in rpmsg-tty. In that case, a get_config message, or a similar mechanism, would also be needed to retrieve the port information from the remote side.

I'm not overly fond of a get_config message because it is one more thing we have to define and maintain.

Arnaud: is there a get_config message already defined for rpmsg_tty?

Beleswar: Can you provide a link to a virtio device that would use a get_config message?

Quoted 35 lines

Tanmaya also proposed another alternative based on reserved addresses.

At this point, I suggest letting Mathieu review the discussion and recommend the most suitable approach.

Thanks,
Arnaud

Quoted 26 lines
Quoted 4 lines

At the end, whatever solution is implemented, my main concern is that the Linux driver design should, if possible, avoid adding unnecessary complexity or limitations on the remote side (for instance in openAMP project).

Yes definitely, I want the same. Feel free to let me know if this does not suit with the OpenAMP project.

Thanks,
Beleswar

Quoted 14 lines

Thanks,
Arnaud

Quoted 8 lines

So Linux does not need to send the port idx everytime while sending a gpio message anymore.

Thanks,
Beleswar

[...]

#26 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 87 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Thursday, May 7, 2026 12:13 PM
To: Arnaud POULIQUEN <[email protected]>
Cc: Beleswar Prasad Padhi <[email protected]>; Shenwei Wang <[email protected]>; Andrew Lunn <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

From my perspective, based on your proposal:
1) Linux should send a get_config message to the remote proc (0x405 ->

0xD). 2) The remote processor would respond with the list of ports, associated

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

with an remote endpoint addresses.

Agreed, we can scale it for multiple remote endpoints like this.

Quoted 1 line

3) Linux would parse the response, compare it with the DT, enable the

GPIO

Quoted 20 lines
Quoted 20 lines
Quoted 3 lines

ports accordingly, creating it local endpoint and associating it with the remote endpoint.
Using name service to identify the ports should avoid step 1 & 2 ...

Yes, but won't that make a lot of hard-codings in the driver?

(quoted diff) +6 -0
+static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = {
+    { .name = "rpmsg-io-25" },
+    { .name = "rpmsg-io-32" },
+    { .name = "rpmsg-io-35" },
+    { },
+};

What if tomorrow another vendor decides to add more remoteproc controlled GPIO ports to Linux, they would have to update this struct in the driver everytime. And the port indexes (25/32/35) could also differ between vendors. We should make the driver dynamic i.e. vendor agnostic.

Quoted 9 lines
Quoted 4 lines

I think querying the remote firmware at runtime (step 1 & 2 above) is a common design pattern and makes the driver vendor agnostic. But feel free to correct me.

You are right. My proposal would require a patch in rpmsg-core. The idea of allowing a postfix in the compatible string has been discussed before, but, if I remember correctly, it was not concluded.

I also remember discussing this. I even reviewed one of Arnaud's patch and submitted one myself. This must have been in 2020 and the reason why it wasn't merged has escaped my memory.

Quoted 12 lines

/* rpmsg devices and drivers are matched using the service name */ static inline int rpmsg_id_match(const struct rpmsg_device *rpdev,

                                const struct rpmsg_device_id *id) {
      size_t len;
(quoted diff) +3 -0
+     len = strnlen(id->name, RPMSG_NAME_SIZE);
+     if (len && id->name[len - 1] == '*')
+             return !strncmp(id->name, rpdev->id.name, len - 1);
 
      return strncmp(id->name, rpdev->id.name, RPMSG_NAME_SIZE) == 0;

}

Quoted 7 lines

Then, in rpmsg-gpio, and possibly in other drivers such as rpmsg-tty and a future rpmsg-i2c, we could use:

static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = {
    { .name = "rpmsg-io" },
    { .name = "rpmsg-io-*" },
    { },
};

That was my initial approach. We don't even need an additional "rpmsg-io-*" in rpmsg_gpio_channel_id_table[]. All we need is:

Quoted 9 lines

/* rpmsg devices and drivers are matched using the service name */ static inline int rpmsg_id_match(const struct rpmsg_device *rpdev,

                                 const struct rpmsg_device_id *id) {

+ size_t len = strnlen(id->name, RPMSG_NAME_SIZE);

- return strncmp(id->name, rpdev->id.name, RPMSG_NAME_SIZE) == 0;
+ return strncmp(id->name, rpdev->id.name, len) == 0;
}

If we encode the port index directly into ept->src, for example:

    ept->src = (baseaddr << 8) | port_index;

where baseaddr can be derived from the channel address, we can avoid the possible address conflict.

With this approach, the patch to rpmsg-core would no longer be necessary.

Thanks,
Shenwei

Quoted 58 lines

And let the rpmsg-virtio-gpio driver parse @rpdev->id.name to match with a GPIO controller in the DT.

Quoted 8 lines

If exact name matching is strongly required, then this proposal would not be suitablea.

A third option would be a combination of both approaches: instantiate the device using the same name service from the remote side, as done in rpmsg-tty. In that case, a get_config message, or a similar mechanism, would also be needed to retrieve the port information from the

remote side.

Quoted 1 line

I'm not overly fond of a get_config message because it is one more thing we have to define and maintain.

Arnaud: is there a get_config message already defined for rpmsg_tty?

Beleswar: Can you provide a link to a virtio device that would use a get_config message?

Quoted 12 lines

Tanmaya also proposed another alternative based on reserved addresses.

At this point, I suggest letting Mathieu review the discussion and recommend the most suitable approach.

Thanks,
Arnaud

Quoted 4 lines
Quoted 4 lines

At the end, whatever solution is implemented, my main concern is that the Linux driver design should, if possible, avoid adding unnecessary complexity or limitations on the remote side (for instance in

openAMP project).

Quoted 23 lines
Quoted 22 lines

Yes definitely, I want the same. Feel free to let me know if this does not suit with the OpenAMP project.

Thanks,
Beleswar

Quoted 14 lines

Thanks,
Arnaud

Quoted 8 lines

So Linux does not need to send the port idx everytime while sending a gpio message anymore.

Thanks,
Beleswar

[...]

maintainer
#27 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 92 lines · Shenwei Wang
Quoted 92 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Thursday, May 7, 2026 12:13 PM
To: Arnaud POULIQUEN <[email protected]>
Cc: Beleswar Prasad Padhi <[email protected]>; Shenwei Wang <[email protected]>; Andrew Lunn <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

From my perspective, based on your proposal:
1) Linux should send a get_config message to the remote proc (0x405 ->

0xD). 2) The remote processor would respond with the list of ports, associated

Quoted 6 lines
Quoted 6 lines
Quoted 1 line

with an remote endpoint addresses.

Agreed, we can scale it for multiple remote endpoints like this.

Quoted 1 line

3) Linux would parse the response, compare it with the DT, enable the

GPIO

Quoted 20 lines
Quoted 20 lines
Quoted 3 lines

ports accordingly, creating it local endpoint and associating it with the remote endpoint.
Using name service to identify the ports should avoid step 1 & 2 ...

Yes, but won't that make a lot of hard-codings in the driver?

(quoted diff) +6 -0
+static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = {
+    { .name = "rpmsg-io-25" },
+    { .name = "rpmsg-io-32" },
+    { .name = "rpmsg-io-35" },
+    { },
+};

What if tomorrow another vendor decides to add more remoteproc controlled GPIO ports to Linux, they would have to update this struct in the driver everytime. And the port indexes (25/32/35) could also differ between vendors. We should make the driver dynamic i.e. vendor agnostic.

Quoted 9 lines
Quoted 4 lines

I think querying the remote firmware at runtime (step 1 & 2 above) is a common design pattern and makes the driver vendor agnostic. But feel free to correct me.

You are right. My proposal would require a patch in rpmsg-core. The idea of allowing a postfix in the compatible string has been discussed before, but, if I remember correctly, it was not concluded.

I also remember discussing this. I even reviewed one of Arnaud's patch and submitted one myself. This must have been in 2020 and the reason why it wasn't merged has escaped my memory.

Quoted 12 lines

/* rpmsg devices and drivers are matched using the service name */ static inline int rpmsg_id_match(const struct rpmsg_device *rpdev,

                                const struct rpmsg_device_id *id) {
      size_t len;
(quoted diff) +3 -0
+     len = strnlen(id->name, RPMSG_NAME_SIZE);
+     if (len && id->name[len - 1] == '*')
+             return !strncmp(id->name, rpdev->id.name, len - 1);
 
      return strncmp(id->name, rpdev->id.name, RPMSG_NAME_SIZE) == 0;

}

Quoted 7 lines

Then, in rpmsg-gpio, and possibly in other drivers such as rpmsg-tty and a future rpmsg-i2c, we could use:

static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = {
    { .name = "rpmsg-io" },
    { .name = "rpmsg-io-*" },
    { },
};

That was my initial approach. We don't even need an additional "rpmsg-io-*" in rpmsg_gpio_channel_id_table[]. All we need is:

/* rpmsg devices and drivers are matched using the service name */ static inline int rpmsg_id_match(const struct rpmsg_device *rpdev,

                                 const struct rpmsg_device_id *id) {

+ size_t len = strnlen(id->name, RPMSG_NAME_SIZE);

Quoted 9 lines
Quoted 4 lines

- return strncmp(id->name, rpdev->id.name, RPMSG_NAME_SIZE) == 0;
+ return strncmp(id->name, rpdev->id.name, len) == 0;
}

If we encode the port index directly into ept->src, for example:

    ept->src = (baseaddr << 8) | port_index;

There is no rpmsg_endpoint::src. You likely meant ept->addr. This would work but not optimal on two front:

(1) rpms_endpoint::addr is a u32 and idr_alloc() returns an 'int'. As such there is a possibility of conflict. I concede the possibility is marginal, but it still exists.

(2) By proceeding this way, the kernel exposes the GPIO controller it knows about. It is preferrable to have the remote processor tell the kernel about the GPIO controller it wants.

I am done reviewing this revision. Given the amount of refactoring needed, I will not look at the code. Please refer to this reply [1] for what I am expecting in the next revision.

[1]. https://lwn.net/ml/all/CANLsYkwBk0KbN-k9ce+5=oT+scdZ3nU5AOr3Fz4zT=0AFzghDA@mail.gmail.com/

Quoted 65 lines

where baseaddr can be derived from the channel address, we can avoid the possible address conflict.

With this approach, the patch to rpmsg-core would no longer be necessary.

Thanks,
Shenwei

Quoted 58 lines

And let the rpmsg-virtio-gpio driver parse @rpdev->id.name to match with a GPIO controller in the DT.

Quoted 8 lines

If exact name matching is strongly required, then this proposal would not be suitablea.

A third option would be a combination of both approaches: instantiate the device using the same name service from the remote side, as done in rpmsg-tty. In that case, a get_config message, or a similar mechanism, would also be needed to retrieve the port information from the

remote side.

Quoted 1 line

I'm not overly fond of a get_config message because it is one more thing we have to define and maintain.

Arnaud: is there a get_config message already defined for rpmsg_tty?

Beleswar: Can you provide a link to a virtio device that would use a get_config message?

Quoted 12 lines

Tanmaya also proposed another alternative based on reserved addresses.

At this point, I suggest letting Mathieu review the discussion and recommend the most suitable approach.

Thanks,
Arnaud

Quoted 4 lines
Quoted 4 lines

At the end, whatever solution is implemented, my main concern is that the Linux driver design should, if possible, avoid adding unnecessary complexity or limitations on the remote side (for instance in

openAMP project).

Quoted 23 lines
Quoted 22 lines

Yes definitely, I want the same. Feel free to let me know if this does not suit with the OpenAMP project.

Thanks,
Beleswar

Quoted 14 lines

Thanks,
Arnaud

Quoted 8 lines

So Linux does not need to send the port idx everytime while sending a gpio message anymore.

Thanks,
Beleswar

[...]

#28 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 22 lines · Shenwei Wang
Quoted 17 lines
Quoted 5 lines

That was my initial approach. We don't even need an additional "rpmsg-io-*" in rpmsg_gpio_channel_id_table[]. All we need is:

Quoted 9 lines

/* rpmsg devices and drivers are matched using the service name */ static inline int rpmsg_id_match(const struct rpmsg_device *rpdev,

                                 const struct rpmsg_device_id *id) {

+ size_t len = strnlen(id->name, RPMSG_NAME_SIZE);

- return strncmp(id->name, rpdev->id.name, RPMSG_NAME_SIZE) == 0;
+ return strncmp(id->name, rpdev->id.name, len) == 0;
}

If we encode the port index directly into ept->src, for example:

Quoted 9 lines
Quoted 2 lines
    ept->src = (baseaddr << 8) | port_index;

There is no rpmsg_endpoint::src. You likely meant ept->addr. This would work but not optimal on two front:

(1) rpms_endpoint::addr is a u32 and idr_alloc() returns an 'int'. As such there is a possibility of conflict. I concede the possibility is marginal, but it still exists.

I think there may be a misunderstanding in the implementation. In this case, we do not need the return value from idr_alloc.

When the driver calls rpmsg_create_ept, it can pass an rpmsg_channel_info structure as an
input parameter. This allows you to specify the source address you want to bind.
Please refer to the definitions below:

struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev,
rpmsg_rx_cb_t cb, void *priv, struct rpmsg_channel_info chinfo)

struct rpmsg_channel_info {
	char name[RPMSG_NAME_SIZE];
	u32 src;
	u32 dst;
};
Quoted 4 lines

(2) By proceeding this way, the kernel exposes the GPIO controller it knows about. It is preferrable to have the remote processor tell the kernel about the GPIO controller it wants.

If everyone agrees with this namespace announcement approach, I will prepare the next revision based on it, even though it is not as clean as the source address encoding solution.

Shenwei

Quoted 4 lines

I am done reviewing this revision. Given the amount of refactoring needed, I will not look at the code. Please refer to this reply [1] for what I am expecting in the next revision.

#29 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 49 lines · Shenwei Wang
Quoted 22 lines · Shenwei Wang
Quoted 17 lines
Quoted 5 lines

That was my initial approach. We don't even need an additional "rpmsg-io-*" in rpmsg_gpio_channel_id_table[]. All we need is:

Quoted 9 lines

/* rpmsg devices and drivers are matched using the service name */ static inline int rpmsg_id_match(const struct rpmsg_device *rpdev,

                                 const struct rpmsg_device_id *id) {

+ size_t len = strnlen(id->name, RPMSG_NAME_SIZE);

- return strncmp(id->name, rpdev->id.name, RPMSG_NAME_SIZE) == 0;
+ return strncmp(id->name, rpdev->id.name, len) == 0;
}

If we encode the port index directly into ept->src, for example:

Quoted 9 lines
Quoted 2 lines
    ept->src = (baseaddr << 8) | port_index;

There is no rpmsg_endpoint::src. You likely meant ept->addr. This would work but not optimal on two front:

(1) rpms_endpoint::addr is a u32 and idr_alloc() returns an 'int'. As such there is a possibility of conflict. I concede the possibility is marginal, but it still exists.

I think there may be a misunderstanding in the implementation. In this case, we do not need the return value from idr_alloc.

When the driver calls rpmsg_create_ept, it can pass an rpmsg_channel_info structure as an
input parameter. This allows you to specify the source address you want to bind.
Please refer to the definitions below:

struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev,
rpmsg_rx_cb_t cb, void *priv, struct rpmsg_channel_info chinfo)

struct rpmsg_channel_info {
	char name[RPMSG_NAME_SIZE];
	u32 src;
	u32 dst;
};
Quoted 8 lines
Quoted 4 lines

(2) By proceeding this way, the kernel exposes the GPIO controller it knows about. It is preferrable to have the remote processor tell the kernel about the GPIO controller it wants.

If everyone agrees with this namespace announcement approach, I will prepare the next revision based on it, even though it is not as clean as the source address encoding solution.

I have ack on the namespace announcement approach. To me it is very simple contract between the firmware and the Linux which allows dynamic endpoint allocation without giving up security concerns. Also this approach can be easily extended for any other rpmsg devices like i2c, spi etc.. With the fix in the rpmsg_core.c, this will work. I will have to see the actual implementation in the next rev to provide further feedback.

Thanks,
Tanmay

Quoted 7 lines

Shenwei

Quoted 4 lines

I am done reviewing this revision. Given the amount of refactoring needed, I will not look at the code. Please refer to this reply [1] for what I am expecting in the next revision.

#30 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

In reply to Mathieu Poirier

Hi Mathieu,

Quoted 191 lines · Mathieu Poirier
Quoted 149 lines · Arnaud POULIQUEN

Hi Beleswar

Quoted 146 lines · Beleswar Prasad Padhi

Hi Arnaud,

Quoted 4 lines · Arnaud POULIQUEN

Hi Beleswar,

On 5/4/26 10:17, Beleswar Prasad Padhi wrote:

[...]

Quoted 91 lines
Quoted 76 lines
Quoted 7 lines

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Sure, let me take an example:
Assumptions: 3 GPIO ports in DT, 3 endpoints in Linux (one per port), 1 endpoint in remote (0xd) and 1 rpmsg channel (rpmsg-io)

          rpmsg {
            rpmsg-io {
              #address-cells = <1>;
              #size-cells = <0>;

              gpio@25 {
                compatible = "rpmsg-gpio";
                reg = <25>;
                gpio-controller;
                #gpio-cells = <2>;
                #interrupt-cells = <2>;
                interrupt-controller;
              };

              gpio@32 {
                compatible = "rpmsg-gpio";
                reg = <32>;
                gpio-controller;
                #gpio-cells = <2>;
                #interrupt-cells = <2>;
                interrupt-controller;
              };

              gpio@35 {
                compatible = "rpmsg-gpio";
                reg = <35>;
                gpio-controller;
                #gpio-cells = <2>;
                #interrupt-cells = <2>;
                interrupt-controller;
              };
            };
          };

Code Flow:
1. "rpmsg-io" channel is announced from remote firmware with unique dst ept = 0xd.

2. rpmsg_core.c creates the default dynamic local ept for the channel ept = 0x405.

3. rpmsg_core.c assigns the allocated addr to rpdev device:
     rpdev->src = 0x405 and rpdev->dst = 0xd.

4. rpmsg_gpio_channel_probe() is triggered. For *each* of the GPIO ports
     in DT, it will trigger rpmsg_gpiochip_register() which will now:
        a. Call port->ept = rpmsg_create_ept(rpdev,
                                                                    rpmsg_gpio_channel_callback, port, {rpdev.id.name, RPMSG_ADDR_ANY, RPMSG_ADDR_ANY}); Ex- port->ept->addr = 0x408

        b. Prepare a 8-byte message having 2 fields:
            port->ept->addr (0x408) and port->idx (25)

        c. Send this message to remote firmware on default channel ept (0x405 -> 0xd) by:
            rpmsg_send(rpdev->ept, &message, sizeof(message));

        d. Remote side receives this message and creates a map of the linux_ept_addr to gpio_port. (0x408 <-> 25)

Quoted 9 lines

5. After this point, any gpio messages sent from Linux from gpio port endpoints (Ex- 0x408) can be decoded at remote side by looking up its map (Ex- map[0x408] = 25).

6. Any messages sent from remote to Linux for a particular gpio port can also be decoded at Linux by simply fetching the priv pointer to get the per-port device:
     struct rpmsg_gpio_port *port = priv;

Thanks for the details!

To sum up:
- the default endpoint acts as the GPIO controller (0x405),
- one extra Linux endpoint is created per port defined in DT.

Quoted 5 lines

This should work, but my concerns remain the same:

  1) This implementation forces the remote processor to handle a single endpoint instead of one endpoint per port. This may add complexity to the remote firmware if each port is managed in a separate thread.

A. Not really, I just chose 1 remote endpoint for this example as you
    suggested to. We can scale it for two-way communication via the get_config message like you suggested below.

B. Isn't it a bad design of the firmware if it is handling 10 gpio ports
    in 10 threads? The logic to handle all the ports is the same, only the parameters (e.g. line number, msg) is different.

Quoted 3 lines

  2) Linux, as a consumer, should not expose its capabilities to the remote
     side (in your proposal it enumerates the ports defined in the DT).     In my view, the remote processor should expose its capabilities as the provider.

Agreed on this.

Quoted 3 lines

From my perspective, based on your proposal:
 1) Linux should send a get_config message to the remote proc (0x405 -> 0xD). 2) The remote processor would respond with the list of ports, associated with an remote endpoint addresses.

Agreed, we can scale it for multiple remote endpoints like this.

Quoted 4 lines

 3) Linux would parse the response, compare it with the DT, enable the GPIO ports accordingly, creating it local endpoint and associating it with the remote endpoint.
Using name service to identify the ports should avoid step 1 & 2 ...

Yes, but won't that make a lot of hard-codings in the driver?

(quoted diff) +6 -0
+static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = {
+    { .name = "rpmsg-io-25" },
+    { .name = "rpmsg-io-32" },
+    { .name = "rpmsg-io-35" },
+    { },
+};

What if tomorrow another vendor decides to add more remoteproc controlled GPIO ports to Linux, they would have to update this struct in the driver everytime. And the port indexes (25/32/35) could also differ between vendors. We should make the driver dynamic i.e. vendor agnostic.

Quoted 8 lines
Quoted 4 lines

I think querying the remote firmware at runtime (step 1 & 2 above) is a common design pattern and makes the driver vendor agnostic. But feel free to correct me.

You are right. My proposal would require a patch in rpmsg-core. The idea of allowing a postfix in the compatible string has been discussed before, but, if I remember correctly, it was not concluded.

I also remember discussing this. I even reviewed one of Arnaud's patch and submitted one myself. This must have been in 2020 and the reason why it wasn't merged has escaped my memory.

Quoted 13 lines

/* rpmsg devices and drivers are matched using the service name */ static inline int rpmsg_id_match(const struct rpmsg_device *rpdev,
const struct rpmsg_device_id *id)

{
	size_t len;
(quoted diff) +3 -0
+	len = strnlen(id->name, RPMSG_NAME_SIZE);
+	if (len && id->name[len - 1] == '*')
+		return !strncmp(id->name, rpdev->id.name, len - 1);
	return strncmp(id->name, rpdev->id.name, RPMSG_NAME_SIZE) == 0;
}
Quoted 7 lines

Then, in rpmsg-gpio, and possibly in other drivers such as rpmsg-tty and a future rpmsg-i2c, we could use:

static struct rpmsg_device_id rpmsg_gpio_channel_id_table[] = {
     { .name = "rpmsg-io" },
     { .name = "rpmsg-io-*" },
     { },
};

That was my initial approach. We don't even need an additional "rpmsg-io-*" in rpmsg_gpio_channel_id_table[]. All we need is:

/* rpmsg devices and drivers are matched using the service name */ static inline int rpmsg_id_match(const struct rpmsg_device *rpdev,
const struct rpmsg_device_id *id)
{
+ size_t len = strnlen(id->name, RPMSG_NAME_SIZE);

Quoted 3 lines

- return strncmp(id->name, rpdev->id.name, RPMSG_NAME_SIZE) == 0;
+ return strncmp(id->name, rpdev->id.name, len) == 0;
}

This wildcard channel matching is interesting. It would be good to know the reasons/cons why this patch was not concluded.

Quoted 12 lines

And let the rpmsg-virtio-gpio driver parse @rpdev->id.name to match with a GPIO controller in the DT.

Quoted 8 lines

If exact name matching is strongly required, then this proposal would not be suitablea.

A third option would be a combination of both approaches: instantiate the device using the same name service from the remote side, as done in rpmsg-tty. In that case, a get_config message, or a similar mechanism, would also be needed to retrieve the port information from the remote side.

Quoted 7 lines

I'm not overly fond of a get_config message because it is one more thing we have to define and maintain.

Arnaud: is there a get_config message already defined for rpmsg_tty?

Beleswar: Can you provide a link to a virtio device that would use a get_config message?

VirtIO typically uses the feature bits for negotiation and discovery. And such a get_config message would not be needed in VirtIO layer, as there is no multiplexing. It's a 1:1 mapping of device to driver instance.

Thanks,
Beleswar

[...]

#31 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

In reply to Mathieu Poirier

Hello Mathieu,

[...]

Quoted 11 lines
Quoted 6 lines

A third option would be a combination of both approaches: instantiate the device using the same name service from the remote side, as done in rpmsg-tty. In that case, a get_config message, or a similar mechanism, would also be needed to retrieve the port information from the remote side.

I'm not overly fond of a get_config message because it is one more thing we have to define and maintain.

Arnaud: is there a get_config message already defined for rpmsg_tty?

No there isn't.

Regards,
Arnaud

Quoted 39 lines

Beleswar: Can you provide a link to a virtio device that would use a get_config message?

Quoted 35 lines

Tanmaya also proposed another alternative based on reserved addresses.

At this point, I suggest letting Mathieu review the discussion and recommend the most suitable approach.

Thanks,
Arnaud

Quoted 26 lines
Quoted 4 lines

At the end, whatever solution is implemented, my main concern is that the Linux driver design should, if possible, avoid adding unnecessary complexity or limitations on the remote side (for instance in openAMP project).

Yes definitely, I want the same. Feel free to let me know if this does not suit with the OpenAMP project.

Thanks,
Beleswar

Quoted 14 lines

Thanks,
Arnaud

Quoted 8 lines

So Linux does not need to send the port idx everytime while sending a gpio message anymore.

Thanks,
Beleswar

[...]

#32 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

In reply to Beleswar Prasad Padhi
Quoted 271 lines

-----Original Message-----
From: Beleswar Prasad Padhi <[email protected]>
Sent: Monday, May 4, 2026 3:17 AM
To: Arnaud POULIQUEN <[email protected]>; Mathieu Poirier <[email protected]>
Cc: Shenwei Wang <[email protected]>; Andrew Lunn <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button

Hi Arnaud,

Quoted 15 lines · Arnaud POULIQUEN
Quoted 12 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 9 lines · Arnaud POULIQUEN

Hello,

Quoted 6 lines · Mathieu Poirier
Quoted 5 lines · Beleswar

Hi Mathieu,

Quoted 1 line · Mathieu Poirier

On Wed, 29 Apr 2026 at 10:53, Shenwei Wang

Quoted 1 line · <[email protected]> wrote:
Quoted 1 line
Quoted 1 line
Quoted 1 line

[...]

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io

      a. ept1 -> gpio-controller@1
      b. ept2 -> gpio-controller@2

I've asked for one endpoint per GPIO controller since the very beginning. I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints. I'll have to look at your link and reflect on that. Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level. This is the only way this work can move forward.

Quoted 1 line
Quoted 1 line
Quoted 1 line

I would be more in favor of Mathieu’s proposal: “An endpoint is created with

every namespace request.”

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

If the endpoint is created only on the Linux side, how do we match the Linux

endpoint address with the local port field on the remote side?

Quoted 9 lines
Quoted 9 lines

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this Linux need not have the port field in the message everytime its sending a message.

Quoted 2 lines

With a multi-namespace approach, the namespace could be rpmsg-io-[addr],

where [addr] corresponds to the GPIO controller address in the DT. This would:

Quoted 9 lines
Quoted 5 lines

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here my sentence should be; With a multi-namespace approach, the namespace could be rpmsg-io-[port], where [port] corresponds to the GPIO controller port in the

DT.

Quoted 29 lines

For instance:

      rpmsg {
        rpmsg-io {
          #address-cells = <1>;
          #size-cells = <0>;

          gpio@25 {
            compatible = "rpmsg-gpio";
            reg = <25>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };

          gpio@32 {
            compatible = "rpmsg-gpio";
            reg = <32>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };
        };
      };
Quoted 17 lines

rpmsg-io-25 would match with gpio@25
rpmsg-io-32 would match with gpio@32

Quoted 13 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel ti.ipc4.ping-pong addr

0xd

Quoted 1 line
Quoted 1 line

[  9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev addr

0xe

Quoted 1 line
Quoted 1 line

[  9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel

formed from src = 0x400 to dst = 0xe

Quoted 1 line
Quoted 1 line

[  9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13: new

channel: 0x401 -> 0xd!

Quoted 6 lines
Quoted 4 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the

port/controller, instead of the endpoint address.

Quoted 25 lines
Quoted 25 lines
Quoted 3 lines

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 2 lines

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

Quoted 8 lines
Quoted 4 lines

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

In my solution, there is no need to have this map of endpoint to GPIO port at Linux side. This aligns more with virtio-gpio design as well.

Quoted 8 lines

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Sure, let me take an example:
Assumptions: 3 GPIO ports in DT, 3 endpoints in Linux (one per port), 1 endpoint in remote (0xd) and 1 rpmsg channel (rpmsg-io)

       rpmsg {
         rpmsg-io {
           #address-cells = <1>;
           #size-cells = <0>;

           gpio@25 {
             compatible = "rpmsg-gpio";
             reg = <25>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };

           gpio@32 {
             compatible = "rpmsg-gpio";
             reg = <32>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };

           gpio@35 {
             compatible = "rpmsg-gpio";
             reg = <35>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };
         };
       };

Code Flow:
1. "rpmsg-io" channel is announced from remote firmware with unique dst

    ept = 0xd.

2. rpmsg_core.c creates the default dynamic local ept for the channel

    ept = 0x405.

3. rpmsg_core.c assigns the allocated addr to rpdev device:

    rpdev->src = 0x405 and rpdev->dst = 0xd.

4. rpmsg_gpio_channel_probe() is triggered. For *each* of the GPIO ports

    in DT, it will trigger rpmsg_gpiochip_register() which will now:
       a. Call port->ept = rpmsg_create_ept(rpdev,
                                                                   rpmsg_gpio_channel_callback,
                                                                   port,
                                                                  {rpdev.id.name,
                                                                   RPMSG_ADDR_ANY,
                                                                   RPMSG_ADDR_ANY});
           Ex- port->ept->addr = 0x408

       b. Prepare a 8-byte message having 2 fields:
           port->ept->addr (0x408) and port->idx (25)

       c. Send this message to remote firmware on default channel ept
           (0x405 -> 0xd) by:
           rpmsg_send(rpdev->ept, &message, sizeof(message));

       d. Remote side receives this message and creates a map of the
           linux_ept_addr to gpio_port. (0x408 <-> 25)

5. After this point, any gpio messages sent from Linux from gpio port

    endpoints (Ex- 0x408) can be decoded at remote side by looking up
    its map (Ex- map[0x408] = 25).
Quoted 8 lines

6. Any messages sent from remote to Linux for a particular gpio port can also be decoded at Linux by simply fetching the priv pointer to get the per-port device:
struct rpmsg_gpio_port *port = priv;

So Linux does not need to send the port idx everytime while sending a gpio message anymore.

I support the idea of encoding the port index directly into ept->addr.
To keep the design simple, we can rely on a predefined rule to derive ept->src, rather than exchanging additional configuration. One approach is to use the default channel address as the base address and encode the port index into the lower bits. For example:

    ept->src = (baseaddr << 8) | port_index;

With this scheme, the endpoint-to-port mapping can be encoded implicitly, eliminating the need for an extra message to exchange EPT and port mapping information.

Thanks,
Shenwei

Quoted 4 lines

Thanks,
Beleswar

[...]

#33 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

In reply to Arnaud POULIQUEN

Hello all,

I have started reviewing this work as well.
Thanks Shenwei for this work.

I have gone through only the current revision, and would like to provide idea on how to achieve GPIO number multiplexing with the RPMsg protocol. Also, have some bindings related question.

Please see below:

Quoted 129 lines · Arnaud POULIQUEN
Quoted 126 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 123 lines · Arnaud POULIQUEN

Hello,

Quoted 120 lines · Mathieu Poirier
Quoted 108 lines · Beleswar

Hi Mathieu,

Quoted 97 lines · Mathieu Poirier
Quoted 89 lines · Shenwei Wang
Quoted 81 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <b- [email protected]>; Linus
Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski
<[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson
<[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected];
Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl- linux-imx <linux-
[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 35 lines · Shenwei Wang
Quoted 35 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>;
Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 5 lines
Quoted 4 lines

struct virtio_gpio_response {
           __u8 status;
           __u8 value;
};

It is the same message format. Please see the message definition

(GET_DIRECTION) below:

Quoted 4 lines

+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+

Quoted 7 lines
Quoted 3 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 7 lines

In contrast, rpmsg provides only a single communication channel, so a
type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 2 lines

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

Quoted 8 lines

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing
capability by way of endpoints.  There is no need for a port field.  One endpoint,
one GPIO controller.

Quoted 6 lines

You still need a way to let the remote side know which port the endpoint maps to, either
by embedding the port information in the message (the current way), or by sending it
separately.

Quoted 5 lines

An endpoint is created with every namespace request.  There should be one namespace request for every GPIO controller, which yields a unique
endpoint for each controller and eliminates the need for an extra field to identify them.

Quoted 7 lines

Right, but this can still be done by just having one namespace request.
We can create new endpoints bound to an existing namespace/channel by invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/29485742-6e49-482e-
[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io
      a. ept1 -> gpio-controller@1
      b. ept2 -> gpio-controller@2

If my understanding of what gpio-controller is right, than this won't work. We need one rpmsg channel per gpio-controller, and in most cases there will be only one GPIO-controller on the remote side. If there are multiple or multiple instances of same controller, than we need separate channel name for that controller just like we would have separate device on the Linux.

Quoted 66 lines
Quoted 24 lines
Quoted 10 lines
Quoted 9 lines

I've asked for one endpoint per GPIO controller since the very beginning.  I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints.  I'll have to look at your link and reflect on that.  Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level.  This is the only way this work can move forward.

Quoted 5 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this
Linux need not have the port field in the message everytime its sending a message.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

With a multi-namespace approach, the namespace could be rpmsg-io- [addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here
my sentence should be;
 With a multi-namespace approach, the namespace could be rpmsg-io-[port], where [port] corresponds to the GPIO controller port in the DT.

For instance:

      rpmsg {
        rpmsg-io {
          #address-cells = <1>;
          #size-cells = <0>;

          gpio@25 {
            compatible = "rpmsg-gpio";
            reg = <25>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };

          gpio@32 {
            compatible = "rpmsg-gpio";
            reg = <32>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };
        };
      };

Quoted 3 lines

 rpmsg-io-25  would match with gpio@25
 rpmsg-io-32  would match with gpio@32

The problem with this approach is, we will endup creating way too many RPMsg devices/channels. i.e. one channel per one GPIO. That limits how many GPIOs can be handled by remote from memory perspective. At somepoint we might just run-out of number ept & channels created by the remote. As of now, open-amp library supports 128 epts I think.

Quoted 70 lines
Quoted 22 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel
ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev
addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel
formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13:
new channel: 0x401 -> 0xd!
Quoted 3 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.

Quoted 22 lines

Quoted 2 lines

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 2 lines

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 7 lines
Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Quoted 17 lines

Thanks and Regards,Arnaud

Quoted 15 lines

Thanks,
Beleswar

Quoted 11 lines

Regards,
Arnaud

Quoted 7 lines
Quoted 7 lines

2. namespace/channel#2 = rpmsg-i2c
      a. ept1 -> i2c@1
      b. ept2 -> i2c@2
      c. ept3 -> i2c@3

etc...

Just want to clear-up few terms before I jump to the solution:

**RPMsg channel/device**:
- These are devices announced by the remote processor, and created by
linux. They are created at: /sys/bus/rpmsg/devices
- The channel format: <name>.<src ept>.<dst ept>

**RPMsg endpoint**:
- Endpoint is differnt than channel. Single channel can have multiple
endpoints, and represented in the linux with: /dev/rpmsg? devices.

To create endpoint device, we have rpmsg_create_ept API, which takes channel information as input, which has src-ept, dst-ept.

Following is proposed solution:

1) Assign RPMsg channel/device per rpmsg-gpio controller (Not per GPIO pin/port).
- In our case that would be, single rpmsg-io node. (That makes me
question if bindings are correct or not).

2) Assign GPIO number as src ept.

i.e. *rpmsg-io.<GPIO number>.<dst ept>*. Do not randomly assign src endpoint.

Now, RPMSG channel by spec reserves first 1024 endpoints [1], so we can add 1024 offset to the GPIO number:

so, when calling rpmsg_create_ept() API, we assing src_endpoint as:
(GPIO_NUMBER + RPMSG_RESERVED_ADDRESSES)

Now on the remote side, there is single channel and only single-endpoint is needed that is mapped to the rpmsg-io channel callback.

That callback will receive all the payloads from the Linux, which will have src-ept i.e. (RPMSG_RESERVED_ADDRESSES + GPIO_NUMBER).

It can retrieve GPIO_NUMBER easily, and convert to appropriate pin based on platform specific logic.

This doesn't need PORT information at all. Also it makes sure that remote is using only single-endpoint so not much memory is used.

*Example*:
If only rpmsg-gpio channel is created by the remote side, than following is the representation of the devices when GPIO 25, 26, 27 is assigned to the rpmsg-io controller:

Linux Remote

rpmsg-channel: rpmsg-gpio.0x400.0x400

/dev/rpmsg0 - GPIO25 ept (rpmsg-gpio.0x419.0x400)-|
                                                  |
/dev/rpmsg1 - GPIO26 ept (rpmsg-gpio.0x41a.0x400)-|-> rpmsg-gpio.*.0x400
                                                  |
/dev/rpmsg2 - GPIO27 ept (rpmsg-gpio.0x41b.0x400)-|  0x400 ept callback.

*On remote side*:

ept_0x400_callback(..., int src_ept, ...,)

{
	int gpio_num = src_ept - RPMSG_RESERVED_ADDRESSES;
	// platform specific logic to convert gpio num to proper pin,
	// just like you would convert gpio num to pin on a linux gpio controller.
}

My question on the binding:

Why each GPIO is represented with the separate node? I think rpmsg-gpio can be represented just any other GPIO controller? Please let me know if I am missing something. So rpmsg channel/rpmsg device is not created per GPIO, but per controller. GPIO number multiplexing should be done with rpmsg src ept, that removes the need of having each GPIO as a separate node.

rpmsg_gpio: rpmsg-gpio@0 {
		compatible = "rpmsg-gpio";
		reg = <0>;
		gpio-controller;
		#gpio-cells = <2>;
		#interrupt-cells = <2>;
		interrupt-controller;
	};

Then in DT, use like regular GPIO, but with the rpmsg-gpio controller:

rpmsg-gpios = <&rpmsg_gpio (GPIO NUM) (flags)>;

If the intent to create separate gpio nodes was only for the channel creation, then it's not really needed.

[1]
https://github.com/torvalds/linux/blob/6d35786de28116ecf78797a62b84e6bf3c45aa5a/drivers/rpmsg/virtio_rpmsg_bus.c#L136

Quoted 11 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

#34 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Hi Tanmay,

Quoted 149 lines · Tanmay

Hello all,

I have started reviewing this work as well.
Thanks Shenwei for this work.

I have gone through only the current revision, and would like to provide idea on how to achieve GPIO number multiplexing with the RPMsg protocol. Also, have some bindings related question.

Please see below:

Quoted 129 lines · Arnaud POULIQUEN
Quoted 126 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 123 lines · Arnaud POULIQUEN

Hello,

Quoted 120 lines · Mathieu Poirier
Quoted 108 lines · Beleswar

Hi Mathieu,

Quoted 97 lines · Mathieu Poirier
Quoted 89 lines · Shenwei Wang
Quoted 81 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <b- [email protected]>; Linus
Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski
<[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson
<[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected];
Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl- linux-imx <linux-
[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 35 lines · Shenwei Wang
Quoted 35 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>;
Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 5 lines
Quoted 4 lines

struct virtio_gpio_response {
           __u8 status;
           __u8 value;
};

It is the same message format. Please see the message definition

(GET_DIRECTION) below:

Quoted 4 lines

+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+

Quoted 7 lines
Quoted 3 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 7 lines

In contrast, rpmsg provides only a single communication channel, so a
type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 2 lines

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

Quoted 8 lines

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing
capability by way of endpoints.  There is no need for a port field.  One endpoint,
one GPIO controller.

Quoted 6 lines

You still need a way to let the remote side know which port the endpoint maps to, either
by embedding the port information in the message (the current way), or by sending it
separately.

Quoted 5 lines

An endpoint is created with every namespace request.  There should be one namespace request for every GPIO controller, which yields a unique
endpoint for each controller and eliminates the need for an extra field to identify them.

Quoted 7 lines

Right, but this can still be done by just having one namespace request.
We can create new endpoints bound to an existing namespace/channel by invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/29485742-6e49-482e-
[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io
      a. ept1 -> gpio-controller@1
      b. ept2 -> gpio-controller@2

Quoted 6 lines

If my understanding of what gpio-controller is right, than this won't work. We need one rpmsg channel per gpio-controller, and in most cases there will be only one GPIO-controller on the remote side. If there are multiple or multiple instances of same controller, than we need separate channel name for that controller just like we would have separate device on the Linux.

As done in ehe rpmsg_tty driver it could be instantiated several times with the same channel/service name. This would imply a specific rpmsg to retreive the gpio controller index from the remote side.

Quoted 71 lines
Quoted 67 lines
Quoted 25 lines
Quoted 11 lines
Quoted 10 lines

I've asked for one endpoint per GPIO controller since the very beginning.  I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints.  I'll have to look at your link and reflect on that.  Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level.  This is the only way this work can move forward.

Quoted 5 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this
Linux need not have the port field in the message everytime its sending a message.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

With a multi-namespace approach, the namespace could be rpmsg-io- [addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here
my sentence should be;
 With a multi-namespace approach, the namespace could be rpmsg-io-[port], where [port] corresponds to the GPIO controller port in the DT.

For instance:

      rpmsg {
        rpmsg-io {
          #address-cells = <1>;
          #size-cells = <0>;

          gpio@25 {
            compatible = "rpmsg-gpio";
            reg = <25>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };

          gpio@32 {
            compatible = "rpmsg-gpio";
            reg = <32>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };
        };
      };

Quoted 3 lines

 rpmsg-io-25  would match with gpio@25
 rpmsg-io-32  would match with gpio@32

Quoted 5 lines

The problem with this approach is, we will endup creating way too many RPMsg devices/channels. i.e. one channel per one GPIO. That limits how many GPIOs can be handled by remote from memory perspective. At somepoint we might just run-out of number ept & channels created by the remote. As of now, open-amp library supports 128 epts I think.

Right, I proposed a solution in my previous answer to Beleswar who has the same concern.

Quoted 118 lines
Quoted 71 lines
Quoted 23 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel
ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev
addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel
formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13:
new channel: 0x401 -> 0xd!
Quoted 3 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.

Quoted 22 lines
Quoted 3 lines

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 2 lines

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 7 lines
Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Quoted 17 lines

Thanks and Regards,Arnaud

Quoted 15 lines

Thanks,
Beleswar

Quoted 11 lines

Regards,
Arnaud

Quoted 7 lines
Quoted 7 lines

2. namespace/channel#2 = rpmsg-i2c
      a. ept1 -> i2c@1
      b. ept2 -> i2c@2
      c. ept3 -> i2c@3

etc...

Just want to clear-up few terms before I jump to the solution:

**RPMsg channel/device**:
- These are devices announced by the remote processor, and created by
linux. They are created at: /sys/bus/rpmsg/devices
- The channel format: <name>.<src ept>.<dst ept>

**RPMsg endpoint**:
- Endpoint is differnt than channel. Single channel can have multiple
endpoints, and represented in the linux with: /dev/rpmsg? devices.

To create endpoint device, we have rpmsg_create_ept API, which takes channel information as input, which has src-ept, dst-ept.

Following is proposed solution:

1) Assign RPMsg channel/device per rpmsg-gpio controller (Not per GPIO pin/port).
- In our case that would be, single rpmsg-io node. (That makes me
question if bindings are correct or not).

2) Assign GPIO number as src ept.

i.e. *rpmsg-io.<GPIO number>.<dst ept>*. Do not randomly assign src endpoint.

Now, RPMSG channel by spec reserves first 1024 endpoints [1], so we can add 1024 offset to the GPIO number:

Quoted 8 lines

so, when calling rpmsg_create_ept() API, we assing src_endpoint as:
(GPIO_NUMBER + RPMSG_RESERVED_ADDRESSES)

Now on the remote side, there is single channel and only single-endpoint is needed that is mapped to the rpmsg-io channel callback.

That callback will receive all the payloads from the Linux, which will have src-ept i.e. (RPMSG_RESERVED_ADDRESSES + GPIO_NUMBER).

Interesting approach. I also tried to find a similar solution.

The question here is: how can we guarantee continuous addresses? Given the static and dynamic allocation of endpoint addresses that are implemented, my conclusion was that it is not reliable enough.

but perhaps I missed something...

Quoted 52 lines

It can retrieve GPIO_NUMBER easily, and convert to appropriate pin based on platform specific logic.

This doesn't need PORT information at all. Also it makes sure that remote is using only single-endpoint so not much memory is used.

*Example*:
If only rpmsg-gpio channel is created by the remote side, than following is the representation of the devices when GPIO 25, 26, 27 is assigned to the rpmsg-io controller:

Linux Remote

rpmsg-channel: rpmsg-gpio.0x400.0x400

/dev/rpmsg0 - GPIO25 ept (rpmsg-gpio.0x419.0x400)-|

                                                   |
/dev/rpmsg1 - GPIO26 ept (rpmsg-gpio.0x41a.0x400)-|-> rpmsg-gpio.*.0x400
                                                   |

/dev/rpmsg2 - GPIO27 ept (rpmsg-gpio.0x41b.0x400)-| 0x400 ept callback.

*On remote side*:

ept_0x400_callback(..., int src_ept, ...,)

{
	int gpio_num = src_ept - RPMSG_RESERVED_ADDRESSES;
	// platform specific logic to convert gpio num to proper pin,
	// just like you would convert gpio num to pin on a linux gpio controller.
}

My question on the binding:

Why each GPIO is represented with the separate node? I think rpmsg-gpio can be represented just any other GPIO controller? Please let me know if I am missing something. So rpmsg channel/rpmsg device is not created per GPIO, but per controller. GPIO number multiplexing should be done with rpmsg src ept, that removes the need of having each GPIO as a separate node.

rpmsg_gpio: rpmsg-gpio@0 {
		compatible = "rpmsg-gpio";
		reg = <0>;
		gpio-controller;
		#gpio-cells = <2>;
		#interrupt-cells = <2>;
		interrupt-controller;
	};

Then in DT, use like regular GPIO, but with the rpmsg-gpio controller:

Quoted 8 lines

rpmsg-gpios = <&rpmsg_gpio (GPIO NUM) (flags)>;

If the intent to create separate gpio nodes was only for the channel creation, then it's not really needed.

[1]
https://github.com/torvalds/linux/blob/6d35786de28116ecf78797a62b84e6bf3c45aa5a/drivers/rpmsg/virtio_rpmsg_bus.c#L136

It is already the case. bindings declare GPIO controllers, not directly GPIOs in:

[PATCH v13 2/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support

The discussion is around having an unique RPmsg endpoint for all GPIO controller or one RPmsg endpoint per GPIO controller.

Or did I misunderstand your questions?

Thanks,
Arnaud

Quoted 12 lines
Quoted 11 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 7 lines

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

#35 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 454 lines · Arnaud POULIQUEN

Hi Tanmay,

Quoted 155 lines · Tanmay

Hello all,

I have started reviewing this work as well.
Thanks Shenwei for this work.

I have gone through only the current revision, and would like to provide idea on how to achieve GPIO number multiplexing with the RPMsg protocol. Also, have some bindings related question.

Please see below:

Quoted 135 lines · Arnaud POULIQUEN
Quoted 132 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 129 lines · Arnaud POULIQUEN

Hello,

Quoted 126 lines · Mathieu Poirier
Quoted 113 lines · Beleswar

Hi Mathieu,

Quoted 101 lines · Mathieu Poirier
Quoted 93 lines · Shenwei Wang
Quoted 85 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <b- [email protected]>; Linus
Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski
<[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson
<[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected];
Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl- linux-imx <linux-
[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 39 lines · Shenwei Wang
Quoted 39 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof
Kozlowski <[email protected]>; Conor Dooley <[email protected]>;
Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha
Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg
GPIO driver

Quoted 6 lines

struct virtio_gpio_response {
            __u8 status;
            __u8 value;
};
It is the same message format. Please see the message
definition

(GET_DIRECTION) below:

Quoted 4 lines

+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+

Quoted 7 lines
Quoted 3 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 7 lines

In contrast, rpmsg provides only a single communication channel, so a
type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 2 lines

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

Quoted 8 lines

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing
capability by way of endpoints.  There is no need for a port field.  One endpoint,
one GPIO controller.

Quoted 6 lines

You still need a way to let the remote side know which port the endpoint maps to, either
by embedding the port information in the message (the current way), or by sending it
separately.

Quoted 6 lines

An endpoint is created with every namespace request.  There should be
one namespace request for every GPIO controller, which yields a unique
endpoint for each controller and eliminates the need for an extra field to identify them.

Quoted 8 lines

Right, but this can still be done by just having one namespace request.
We can create new endpoints bound to an existing namespace/ channel by
invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/29485742-6e49-482e-
[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io
       a. ept1 -> gpio-controller@1
       b. ept2 -> gpio-controller@2

Quoted 6 lines

If my understanding of what gpio-controller is right, than this won't work. We need one rpmsg channel per gpio-controller, and in most cases there will be only one GPIO-controller on the remote side. If there are multiple or multiple instances of same controller, than we need separate channel name for that controller just like we would have separate device on the Linux.

As done in ehe rpmsg_tty driver it could be instantiated several times with the same channel/service name. This would imply a specific rpmsg to retreive
the gpio controller index from the remote side.

Quoted 75 lines
Quoted 71 lines
Quoted 28 lines
Quoted 13 lines
Quoted 12 lines

I've asked for one endpoint per GPIO controller since the very beginning.  I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints.  I'll have to look at your link and reflect on
that.  Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level. This is
the only way this work can move forward.

Quoted 6 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this
Linux need not have the port field in the message everytime its sending a message.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

With a multi-namespace approach, the namespace could be rpmsg-io- [addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here
my sentence should be;
  With a multi-namespace approach, the namespace could be rpmsg-io- [port],
  where [port] corresponds to the GPIO controller port in the DT.

For instance:

       rpmsg {
         rpmsg-io {
           #address-cells = <1>;
           #size-cells = <0>;

           gpio@25 {
             compatible = "rpmsg-gpio";
             reg = <25>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };

           gpio@32 {
             compatible = "rpmsg-gpio";
             reg = <32>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };
         };
       };

Quoted 3 lines

  rpmsg-io-25  would match with gpio@25
  rpmsg-io-32  would match with gpio@32

Quoted 5 lines

The problem with this approach is, we will endup creating way too many RPMsg devices/channels. i.e. one channel per one GPIO. That limits how many GPIOs can be handled by remote from memory perspective. At somepoint we might just run-out of number ept & channels created by the remote. As of now, open-amp library supports 128 epts I think.

Right, I proposed a solution in my previous answer to Beleswar who has the same concern.

Quoted 118 lines
Quoted 71 lines
Quoted 23 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel
ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev
addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel
formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13:
new channel: 0x401 -> 0xd!
Quoted 3 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.

Quoted 22 lines

Quoted 2 lines

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 2 lines

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 7 lines
Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Quoted 17 lines

Thanks and Regards,Arnaud

Quoted 15 lines

Thanks,
Beleswar

Quoted 11 lines

Regards,
Arnaud

Quoted 7 lines
Quoted 7 lines

2. namespace/channel#2 = rpmsg-i2c
       a. ept1 -> i2c@1
       b. ept2 -> i2c@2
       c. ept3 -> i2c@3

etc...

Just want to clear-up few terms before I jump to the solution:

**RPMsg channel/device**:
   - These are devices announced by the remote processor, and created by linux. They are created at: /sys/bus/rpmsg/devices
   - The channel format: <name>.<src ept>.<dst ept>

**RPMsg endpoint**:
   - Endpoint is differnt than channel. Single channel can have multiple endpoints, and represented in the linux with: /dev/rpmsg? devices.

To create endpoint device, we have rpmsg_create_ept API, which takes channel information as input, which has src-ept, dst-ept.

Following is proposed solution:

1) Assign RPMsg channel/device per rpmsg-gpio controller (Not per GPIO pin/port).
   - In our case that would be, single rpmsg-io node. (That makes me question if bindings are correct or not).

2) Assign GPIO number as src ept.

i.e. *rpmsg-io.<GPIO number>.<dst ept>*. Do not randomly assign src endpoint.

Now, RPMSG channel by spec reserves first 1024 endpoints [1], so we can add 1024 offset to the GPIO number:

Quoted 8 lines

so, when calling rpmsg_create_ept() API, we assing src_endpoint as:
(GPIO_NUMBER + RPMSG_RESERVED_ADDRESSES)

Now on the remote side, there is single channel and only single-endpoint is needed that is mapped to the rpmsg-io channel callback.

That callback will receive all the payloads from the Linux, which will have src-ept i.e. (RPMSG_RESERVED_ADDRESSES + GPIO_NUMBER).

Interesting approach. I also tried to find a similar solution.

The question here is: how can we guarantee continuous addresses? Given the static and dynamic allocation of endpoint addresses that are implemented, my conclusion was that it is not reliable enough.

but perhaps I missed something...

Quoted 56 lines

It can retrieve GPIO_NUMBER easily, and convert to appropriate pin based on platform specific logic.

This doesn't need PORT information at all. Also it makes sure that remote is using only single-endpoint so not much memory is used.

*Example*:
If only rpmsg-gpio channel is created by the remote side, than following is the representation of the devices when GPIO 25, 26, 27 is assigned to the rpmsg-io controller:

Linux                                                      Remote

rpmsg-channel: rpmsg-gpio.0x400.0x400

/dev/rpmsg0 - GPIO25 ept (rpmsg-gpio.0x419.0x400)-|
                                                   | /dev/rpmsg1 - GPIO26 ept (rpmsg-gpio.0x41a.0x400)-|-> rpmsg-gpio.*.0x400 | /dev/rpmsg2 - GPIO27 ept (rpmsg-gpio.0x41b.0x400)-|  0x400 ept callback.

*On remote side*:

ept_0x400_callback(..., int src_ept, ...,)
{
    int gpio_num = src_ept - RPMSG_RESERVED_ADDRESSES; // platform specific logic to convert gpio num to proper pin, // just like you would convert gpio num to pin on a linux gpio controller.
}

My question on the binding:

Why each GPIO is represented with the separate node? I think rpmsg-gpio can be represented just any other GPIO controller? Please let me know if I am missing something. So rpmsg channel/rpmsg device is not created per GPIO, but per controller. GPIO number multiplexing should be done with rpmsg src ept, that removes the need of having each GPIO as a separate node.

rpmsg_gpio: rpmsg-gpio@0 {
        compatible = "rpmsg-gpio";
        reg = <0>;
        gpio-controller;
        #gpio-cells = <2>;
        #interrupt-cells = <2>;
        interrupt-controller;
    };

Then in DT, use like regular GPIO, but with the rpmsg-gpio controller:

rpmsg-gpios = <&rpmsg_gpio (GPIO NUM) (flags)>;

Quoted 8 lines

If the intent to create separate gpio nodes was only for the channel creation, then it's not really needed.

[1]
https://github.com/torvalds/linux/
blob/6d35786de28116ecf78797a62b84e6bf3c45aa5a/drivers/rpmsg/ virtio_rpmsg_bus.c#L136

Quoted 9 lines

It is already the case. bindings declare GPIO controllers, not directly GPIOs in:

[PATCH v13 2/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support

The discussion is around having an unique RPmsg endpoint for all GPIO controller or one RPmsg endpoint per GPIO controller.

Endpoint where remote side or linux side?

If unique endpoint on remote side per gpio controller then it makes sense.

Unique endpoint on linux side doesn't make sense. Instead, unique channel per gpio controller makes sense, and each channel will have multiple endpoints on linux side. As I replied to Beleswar on the other email, I will copy past my answer here too:

To be more specific:

Linux: remote:

ch1: rpmsg-gpio.-1.1024 -> gpio-controller@1024
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1024.
- gpio-line ept3

ch2: rpmsg-gpio.-1.1025 -> gpio-controller@1025
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1025.
- gpio-line ept3

On the remote side, we have to hardcode Which rpmsg controller is mapped to which endpoint.

Quoted 5 lines

Or did I misunderstand your questions?

Thanks,
Arnaud

I gave this patch more time yesterday, and I think the 'reg' property should represent remote endpoint, instead of the gpio-controller index.

So in this approach remote implementation is expected to provide hard-coded (static) endpoints for each gpio-controller instance, and that same number should be represented with the 'reg' property.

On remote side:

#define RPMSG_GPIO_0_CONTROLLER_EPT (RPMSG_RESERVED_ADDRESSES + 1) // 1024

ept_1024_callback() {

	// handle appropriate gpio port ()

}

On linux side:

So new representation of controller:

 rpmsg_gpio_0:   gpio@1024 {
             compatible = "rpmsg-gpio";
             reg = <1024>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };
 rpmsg_gpio_1:   gpio@1025 {
             compatible = "rpmsg-gpio";
             reg = <1025>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };

gpios = <&rpmsg_gpio_0 (GPIO NUM or PIN) flags>,

	<&rpmsg_gpio_1 (GPIO NUM or PIN) flags>;

Now in the linux driver:

You can easily retrieve destination endpoint when we want to send the command to the gpio controller via device's "reg" property.

This approach also provides built-in security as well. Because now gpio-controller instance is hardcoded with the endpoint callback, it can't be modified/addressed without changing the 'reg' property.

Just like you wouldn't change device address for the instance of the gpio-controller right?

This approach can be easily adapted to all the other rpmsg controllers as well.

So, dynamic endpoint allocation doesn't make sense in this case. Dynamic endpoint allocation makes more sense for user-space apps which don't really care about endpoints and only payloads.

But, here we are multiplexing device-addresses with endpoints, and so it has to be fixed, and presented via 'reg' property. So, firmware can't change device-address without Linux knowing it.

Thanks,
Tanmay

Quoted 14 lines
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

#36 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 486 lines · Tanmay
Quoted 454 lines · Arnaud POULIQUEN

Hi Tanmay,

Quoted 155 lines · Tanmay

Hello all,

I have started reviewing this work as well.
Thanks Shenwei for this work.

I have gone through only the current revision, and would like to provide idea on how to achieve GPIO number multiplexing with the RPMsg protocol. Also, have some bindings related question.

Please see below:

Quoted 135 lines · Arnaud POULIQUEN
Quoted 132 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 129 lines · Arnaud POULIQUEN

Hello,

Quoted 126 lines · Mathieu Poirier
Quoted 113 lines · Beleswar

Hi Mathieu,

Quoted 101 lines · Mathieu Poirier
Quoted 93 lines · Shenwei Wang
Quoted 85 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <b- [email protected]>; Linus
Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski
<[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson
<[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected];
Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl- linux-imx <linux-
[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 39 lines · Shenwei Wang
Quoted 39 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij
<[email protected]>; Bartosz Golaszewski <[email protected]>;
Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>;
Krzysztof
Kozlowski <[email protected]>; Conor Dooley
<[email protected]>;
Bjorn Andersson <[email protected]>; Mathieu Poirier
<[email protected]>; Frank Li <[email protected]>;
Sascha
Hauer <[email protected]>; Shuah Khan
<[email protected]>; [email protected]; linux-
[email protected]; [email protected]; Pengutronix
Kernel Team <[email protected]>; Fabio Estevam
<[email protected]>; Peng Fan <[email protected]>;
[email protected]; linux- [email protected];
[email protected]; linux-arm- [email protected];
dl-linux-imx <[email protected]>; Bartosz Golaszewski
<[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic
rpmsg
GPIO driver
struct virtio_gpio_response {
            __u8 status;
            __u8 value;
};
It is the same message format. Please see the message
definition
(GET_DIRECTION) below:

+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+

Quoted 7 lines
Quoted 3 lines

Sorry, but i don't see how two u8 vs six u8 are the same
message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 7 lines

In contrast, rpmsg provides only a single communication channel, so a
type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 2 lines

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

Quoted 8 lines

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing
capability by way of endpoints.  There is no need for a port field.  One endpoint,
one GPIO controller.

Quoted 6 lines

You still need a way to let the remote side know which port the endpoint maps to, either
by embedding the port information in the message (the current way), or by sending it
separately.

Quoted 6 lines

An endpoint is created with every namespace request.  There should be
one namespace request for every GPIO controller, which yields a unique
endpoint for each controller and eliminates the need for an extra field to identify them.

Quoted 8 lines

Right, but this can still be done by just having one namespace request.
We can create new endpoints bound to an existing namespace/ channel by
invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/29485742-6e49-482e-
[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io
       a. ept1 -> gpio-controller@1
       b. ept2 -> gpio-controller@2

Quoted 6 lines

If my understanding of what gpio-controller is right, than this won't work. We need one rpmsg channel per gpio-controller, and in most cases there will be only one GPIO-controller on the remote side. If there are multiple or multiple instances of same controller, than we need separate channel name for that controller just like we would have separate device on the Linux.

As done in ehe rpmsg_tty driver it could be instantiated several times with the same channel/service name. This would imply a specific rpmsg to retreive
the gpio controller index from the remote side.

Quoted 75 lines
Quoted 71 lines
Quoted 28 lines
Quoted 13 lines
Quoted 12 lines

I've asked for one endpoint per GPIO controller since the very beginning.  I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints.  I'll have to look at your link and reflect on
that.  Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level. This is
the only way this work can move forward.

Quoted 6 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this
Linux need not have the port field in the message everytime its sending a message.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

With a multi-namespace approach, the namespace could be rpmsg-io- [addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here
my sentence should be;
  With a multi-namespace approach, the namespace could be rpmsg-io- [port],
  where [port] corresponds to the GPIO controller port in the DT.

For instance:

       rpmsg {
         rpmsg-io {
           #address-cells = <1>;
           #size-cells = <0>;

           gpio@25 {
             compatible = "rpmsg-gpio";
             reg = <25>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };

           gpio@32 {
             compatible = "rpmsg-gpio";
             reg = <32>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };
         };
       };

Quoted 3 lines

  rpmsg-io-25  would match with gpio@25
  rpmsg-io-32  would match with gpio@32

Quoted 5 lines

The problem with this approach is, we will endup creating way too many RPMsg devices/channels. i.e. one channel per one GPIO. That limits how many GPIOs can be handled by remote from memory perspective. At somepoint we might just run-out of number ept & channels created by the remote. As of now, open-amp library supports 128 epts I think.

Right, I proposed a solution in my previous answer to Beleswar who has the same concern.

Quoted 118 lines
Quoted 71 lines
Quoted 23 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel
ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev
addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel
formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13:
new channel: 0x401 -> 0xd!
Quoted 3 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.

Quoted 22 lines

Quoted 2 lines

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 2 lines

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 7 lines
Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Quoted 17 lines

Thanks and Regards,Arnaud

Quoted 15 lines

Thanks,
Beleswar

Quoted 11 lines

Regards,
Arnaud

Quoted 7 lines
Quoted 7 lines

2. namespace/channel#2 = rpmsg-i2c
       a. ept1 -> i2c@1
       b. ept2 -> i2c@2
       c. ept3 -> i2c@3

etc...

Just want to clear-up few terms before I jump to the solution:

**RPMsg channel/device**:
   - These are devices announced by the remote processor, and created by linux. They are created at: /sys/bus/rpmsg/devices
   - The channel format: <name>.<src ept>.<dst ept>

**RPMsg endpoint**:
   - Endpoint is differnt than channel. Single channel can have multiple endpoints, and represented in the linux with: /dev/rpmsg? devices.

To create endpoint device, we have rpmsg_create_ept API, which takes channel information as input, which has src-ept, dst-ept.

Following is proposed solution:

1) Assign RPMsg channel/device per rpmsg-gpio controller (Not per GPIO pin/port).
   - In our case that would be, single rpmsg-io node. (That makes me question if bindings are correct or not).

2) Assign GPIO number as src ept.

i.e. *rpmsg-io.<GPIO number>.<dst ept>*. Do not randomly assign src endpoint.

Now, RPMSG channel by spec reserves first 1024 endpoints [1], so we can add 1024 offset to the GPIO number:

Quoted 8 lines

so, when calling rpmsg_create_ept() API, we assing src_endpoint as:
(GPIO_NUMBER + RPMSG_RESERVED_ADDRESSES)

Now on the remote side, there is single channel and only single-endpoint is needed that is mapped to the rpmsg-io channel callback.

That callback will receive all the payloads from the Linux, which will have src-ept i.e. (RPMSG_RESERVED_ADDRESSES + GPIO_NUMBER).

Interesting approach. I also tried to find a similar solution.

The question here is: how can we guarantee continuous addresses? Given the static and dynamic allocation of endpoint addresses that are implemented, my conclusion was that it is not reliable enough.

but perhaps I missed something...

Quoted 56 lines

It can retrieve GPIO_NUMBER easily, and convert to appropriate pin based on platform specific logic.

This doesn't need PORT information at all. Also it makes sure that remote is using only single-endpoint so not much memory is used.

*Example*:
If only rpmsg-gpio channel is created by the remote side, than following is the representation of the devices when GPIO 25, 26, 27 is assigned to the rpmsg-io controller:

Linux                                                      Remote

rpmsg-channel: rpmsg-gpio.0x400.0x400

/dev/rpmsg0 - GPIO25 ept (rpmsg-gpio.0x419.0x400)-|
                                                   | /dev/rpmsg1 - GPIO26 ept (rpmsg-gpio.0x41a.0x400)-|-> rpmsg-gpio.*.0x400 | /dev/rpmsg2 - GPIO27 ept (rpmsg-gpio.0x41b.0x400)-|  0x400 ept callback.

*On remote side*:

ept_0x400_callback(..., int src_ept, ...,)
{
    int gpio_num = src_ept - RPMSG_RESERVED_ADDRESSES; // platform specific logic to convert gpio num to proper pin, // just like you would convert gpio num to pin on a linux gpio controller.
}

My question on the binding:

Why each GPIO is represented with the separate node? I think rpmsg-gpio can be represented just any other GPIO controller? Please let me know if I am missing something. So rpmsg channel/rpmsg device is not created per GPIO, but per controller. GPIO number multiplexing should be done with rpmsg src ept, that removes the need of having each GPIO as a separate node.

rpmsg_gpio: rpmsg-gpio@0 {
        compatible = "rpmsg-gpio";
        reg = <0>;
        gpio-controller;
        #gpio-cells = <2>;
        #interrupt-cells = <2>;
        interrupt-controller;
    };

Then in DT, use like regular GPIO, but with the rpmsg-gpio controller:

rpmsg-gpios = <&rpmsg_gpio (GPIO NUM) (flags)>;

Quoted 8 lines

If the intent to create separate gpio nodes was only for the channel creation, then it's not really needed.

[1]
https://github.com/torvalds/linux/
blob/6d35786de28116ecf78797a62b84e6bf3c45aa5a/drivers/rpmsg/ virtio_rpmsg_bus.c#L136

Quoted 9 lines

It is already the case. bindings declare GPIO controllers, not directly GPIOs in:

[PATCH v13 2/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support

The discussion is around having an unique RPmsg endpoint for all GPIO controller or one RPmsg endpoint per GPIO controller.

Endpoint where remote side or linux side?

If unique endpoint on remote side per gpio controller then it makes sense.

Unique endpoint on linux side doesn't make sense. Instead, unique channel per gpio controller makes sense, and each channel will have multiple endpoints on linux side. As I replied to Beleswar on the other email, I will copy past my answer here too:

To be more specific:

Linux: remote:

ch1: rpmsg-gpio.-1.1024 -> gpio-controller@1024
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1024.
- gpio-line ept3

Quoted 5 lines

ch2: rpmsg-gpio.-1.1025 -> gpio-controller@1025
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1025.
- gpio-line ept3

Hi Mathieu,

So upon more brain storming in this approach I found limitation:

This approach won't work if host OS is any other OS but Linux. For example, if the remote OS is zephyr/baremetal using open-amp, then Only Linux <-> zephyr combination will work, and we won't be able to re-use this approach for zephyr <-> zephyr use case. The concept of rpmsg channel/device exist only in the linux kernel implementation. This brings another question: Should the protocol we decide work on other use cases as well? Or Linux must be the Host OS for this protocol ?

I think your & Arnaud's proposed approach of single endpoint per gpio-controller on both side makes more sense, as it will work regardless of any OS on host or remote side.

To be more specific this will look like following:

Host (Linux) Remote (baremetal/RTOS)

rpmsg ch/device 1:
- rpmsg ept 1 <------> rpmsg ept 1 gpio-controller 0

rpmsg ch/device 2:
- rpmsg ept 2 <------> rpmsg ept 2 gpio-controller 1

The question is, how to decide src ept, and dest ept on both sides? I still think it should be static endpoints.

I will get back with more reasoning on that.

Quoted 94 lines

On the remote side, we have to hardcode Which rpmsg controller is mapped to which endpoint.

Quoted 5 lines

Or did I misunderstand your questions?

Thanks,
Arnaud

I gave this patch more time yesterday, and I think the 'reg' property should represent remote endpoint, instead of the gpio-controller index.

So in this approach remote implementation is expected to provide hard-coded (static) endpoints for each gpio-controller instance, and that same number should be represented with the 'reg' property.

On remote side:

#define RPMSG_GPIO_0_CONTROLLER_EPT (RPMSG_RESERVED_ADDRESSES + 1) // 1024

ept_1024_callback() {

	// handle appropriate gpio port ()

}

On linux side:

So new representation of controller:

 rpmsg_gpio_0:   gpio@1024 {
             compatible = "rpmsg-gpio";
             reg = <1024>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };
 rpmsg_gpio_1:   gpio@1025 {
             compatible = "rpmsg-gpio";
             reg = <1025>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };

gpios = <&rpmsg_gpio_0 (GPIO NUM or PIN) flags>,

	<&rpmsg_gpio_1 (GPIO NUM or PIN) flags>;

Now in the linux driver:

You can easily retrieve destination endpoint when we want to send the command to the gpio controller via device's "reg" property.

This approach also provides built-in security as well. Because now gpio-controller instance is hardcoded with the endpoint callback, it can't be modified/addressed without changing the 'reg' property.

Just like you wouldn't change device address for the instance of the gpio-controller right?

This approach can be easily adapted to all the other rpmsg controllers as well.

So, dynamic endpoint allocation doesn't make sense in this case. Dynamic endpoint allocation makes more sense for user-space apps which don't really care about endpoints and only payloads.

But, here we are multiplexing device-addresses with endpoints, and so it has to be fixed, and presented via 'reg' property. So, firmware can't change device-address without Linux knowing it.

Thanks,
Tanmay

Quoted 14 lines
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

maintainer
#37 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 501 lines · Tanmay
Quoted 486 lines · Tanmay
Quoted 454 lines · Arnaud POULIQUEN

Hi Tanmay,

Quoted 155 lines · Tanmay

Hello all,

I have started reviewing this work as well.
Thanks Shenwei for this work.

I have gone through only the current revision, and would like to provide idea on how to achieve GPIO number multiplexing with the RPMsg protocol. Also, have some bindings related question.

Please see below:

Quoted 135 lines · Arnaud POULIQUEN
Quoted 132 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 129 lines · Arnaud POULIQUEN

Hello,

Quoted 126 lines · Mathieu Poirier
Quoted 113 lines · Beleswar

Hi Mathieu,

Quoted 101 lines · Mathieu Poirier
Quoted 93 lines · Shenwei Wang
Quoted 85 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <b- [email protected]>; Linus
Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski
<[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson
<[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected];
Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl- linux-imx <linux-
[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 46 lines · Shenwei Wang

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij
<[email protected]>; Bartosz Golaszewski <[email protected]>;
Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>;
Krzysztof
Kozlowski <[email protected]>; Conor Dooley
<[email protected]>;
Bjorn Andersson <[email protected]>; Mathieu Poirier
<[email protected]>; Frank Li <[email protected]>;
Sascha
Hauer <[email protected]>; Shuah Khan
<[email protected]>; [email protected]; linux-
[email protected]; [email protected]; Pengutronix
Kernel Team <[email protected]>; Fabio Estevam
<[email protected]>; Peng Fan <[email protected]>;
[email protected]; linux- [email protected];
[email protected]; linux-arm- [email protected];
dl-linux-imx <[email protected]>; Bartosz Golaszewski
<[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic
rpmsg
GPIO driver
struct virtio_gpio_response {
__u8 status;
__u8 value;
};
It is the same message format. Please see the message
definition
(GET_DIRECTION) below:

+ +-----+-----+-----+-----+-----+----+
+ |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+ | 1 | 2 |port |line | err | dir|
+ +-----+-----+-----+-----+-----+----+
Sorry, but i don't see how two u8 vs six u8 are the same
message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for
requests and

replies, and a second one for events.

Quoted 7 lines

In contrast, rpmsg provides only a single communication
channel, so a
type field is required to distinguish between different kinds
of messages.

Since rpmsg replies and events share the same message format,
an additional

line is introduced to handle both cases.

Quoted 2 lines

Finally, rpmsg supports multiple GPIO controllers, so a port
field is added to

Quoted 8 lines

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing
capability by way of endpoints. There is no need for a port field. One endpoint,
one GPIO controller.

Quoted 6 lines

You still need a way to let the remote side know which port the endpoint maps to, either
by embedding the port information in the message (the current way), or by sending it
separately.

Quoted 6 lines

An endpoint is created with every namespace request. There should be
one namespace request for every GPIO controller, which yields a unique
endpoint for each controller and eliminates the need for an extra field to identify them.

Quoted 8 lines

Right, but this can still be done by just having one namespace request.
We can create new endpoints bound to an existing namespace/ channel by
invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/29485742-6e49-482e-
[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io

       a. ept1 -> gpio-controller@1
       b. ept2 -> gpio-controller@2
Quoted 6 lines

If my understanding of what gpio-controller is right, than this won't work. We need one rpmsg channel per gpio-controller, and in most cases there will be only one GPIO-controller on the remote side. If there are multiple or multiple instances of same controller, than we need separate channel name for that controller just like we would have separate device on the Linux.

As done in ehe rpmsg_tty driver it could be instantiated several times with the same channel/service name. This would imply a specific rpmsg to retreive
the gpio controller index from the remote side.

Quoted 75 lines
Quoted 71 lines
Quoted 28 lines
Quoted 13 lines
Quoted 12 lines

I've asked for one endpoint per GPIO controller since the very beginning. I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints. I'll have to look at your link and reflect on
that. Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level. This is
the only way this work can move forward.

Quoted 6 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this
Linux need not have the port field in the message everytime its sending a message.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

With a multi-namespace approach, the namespace could be rpmsg-io- [addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here
my sentence should be;
With a multi-namespace approach, the namespace could be rpmsg-io-
[port],
where [port] corresponds to the GPIO controller port in the DT.

For instance:

       rpmsg {
         rpmsg-io {
           #address-cells = <1>;
           #size-cells = <0>;

           gpio@25 {
             compatible = "rpmsg-gpio";
             reg = <25>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };

           gpio@32 {
             compatible = "rpmsg-gpio";
             reg = <32>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };
         };
       };
Quoted 3 lines

rpmsg-io-25 would match with gpio@25
rpmsg-io-32 would match with gpio@32

Quoted 5 lines

The problem with this approach is, we will endup creating way too many RPMsg devices/channels. i.e. one channel per one GPIO. That limits how many GPIOs can be handled by remote from memory perspective. At somepoint we might just run-out of number ept & channels created by the remote. As of now, open-amp library supports 128 epts I think.

Right, I proposed a solution in my previous answer to Beleswar who has the same concern.

Quoted 118 lines
Quoted 71 lines
Quoted 23 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel
ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev
addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel
formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13:
new channel: 0x401 -> 0xd!
Quoted 3 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.

Quoted 22 lines
Quoted 3 lines

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 2 lines

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 7 lines
Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Quoted 17 lines

Thanks and Regards,Arnaud

Quoted 15 lines

Thanks,
Beleswar

Quoted 11 lines

Regards,
Arnaud

Quoted 7 lines
Quoted 7 lines

2. namespace/channel#2 = rpmsg-i2c

       a. ept1 -> i2c@1
       b. ept2 -> i2c@2
       c. ept3 -> i2c@3

etc...

Just want to clear-up few terms before I jump to the solution:

**RPMsg channel/device**:
- These are devices announced by the remote processor, and created by
linux. They are created at: /sys/bus/rpmsg/devices
- The channel format: <name>.<src ept>.<dst ept>

**RPMsg endpoint**:
- Endpoint is differnt than channel. Single channel can have multiple
endpoints, and represented in the linux with: /dev/rpmsg? devices.

To create endpoint device, we have rpmsg_create_ept API, which takes channel information as input, which has src-ept, dst-ept.

Following is proposed solution:

1) Assign RPMsg channel/device per rpmsg-gpio controller (Not per GPIO pin/port).
- In our case that would be, single rpmsg-io node. (That makes me
question if bindings are correct or not).

2) Assign GPIO number as src ept.

i.e. *rpmsg-io.<GPIO number>.<dst ept>*. Do not randomly assign src endpoint.

Now, RPMSG channel by spec reserves first 1024 endpoints [1], so we can add 1024 offset to the GPIO number:

Quoted 8 lines

so, when calling rpmsg_create_ept() API, we assing src_endpoint as:
(GPIO_NUMBER + RPMSG_RESERVED_ADDRESSES)

Now on the remote side, there is single channel and only single-endpoint is needed that is mapped to the rpmsg-io channel callback.

That callback will receive all the payloads from the Linux, which will have src-ept i.e. (RPMSG_RESERVED_ADDRESSES + GPIO_NUMBER).

Interesting approach. I also tried to find a similar solution.

The question here is: how can we guarantee continuous addresses? Given the static and dynamic allocation of endpoint addresses that are implemented, my conclusion was that it is not reliable enough.

but perhaps I missed something...

Quoted 56 lines

It can retrieve GPIO_NUMBER easily, and convert to appropriate pin based on platform specific logic.

This doesn't need PORT information at all. Also it makes sure that remote is using only single-endpoint so not much memory is used.

*Example*:
If only rpmsg-gpio channel is created by the remote side, than following is the representation of the devices when GPIO 25, 26, 27 is assigned to the rpmsg-io controller:

Linux Remote

rpmsg-channel: rpmsg-gpio.0x400.0x400

/dev/rpmsg0 - GPIO25 ept (rpmsg-gpio.0x419.0x400)-|

                                                   |
/dev/rpmsg1 - GPIO26 ept (rpmsg-gpio.0x41a.0x400)-|-> rpmsg-gpio.*.0x400
                                                   |

/dev/rpmsg2 - GPIO27 ept (rpmsg-gpio.0x41b.0x400)-| 0x400 ept callback.

*On remote side*:

ept_0x400_callback(..., int src_ept, ...,)

{
    int gpio_num = src_ept - RPMSG_RESERVED_ADDRESSES;
    // platform specific logic to convert gpio num to proper pin,
    // just like you would convert gpio num to pin on a linux gpio

controller.
}

My question on the binding:

Why each GPIO is represented with the separate node? I think rpmsg-gpio can be represented just any other GPIO controller? Please let me know if I am missing something. So rpmsg channel/rpmsg device is not created per GPIO, but per controller. GPIO number multiplexing should be done with rpmsg src ept, that removes the need of having each GPIO as a separate node.

rpmsg_gpio: rpmsg-gpio@0 {
        compatible = "rpmsg-gpio";
        reg = <0>;
        gpio-controller;
        #gpio-cells = <2>;
        #interrupt-cells = <2>;
        interrupt-controller;
    };

Then in DT, use like regular GPIO, but with the rpmsg-gpio controller:

rpmsg-gpios = <&rpmsg_gpio (GPIO NUM) (flags)>;

Quoted 8 lines

If the intent to create separate gpio nodes was only for the channel creation, then it's not really needed.

[1]
https://github.com/torvalds/linux/
blob/6d35786de28116ecf78797a62b84e6bf3c45aa5a/drivers/rpmsg/ virtio_rpmsg_bus.c#L136

Quoted 9 lines

It is already the case. bindings declare GPIO controllers, not directly GPIOs in:

[PATCH v13 2/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support

The discussion is around having an unique RPmsg endpoint for all GPIO controller or one RPmsg endpoint per GPIO controller.

Endpoint where remote side or linux side?

If unique endpoint on remote side per gpio controller then it makes sense.

Unique endpoint on linux side doesn't make sense. Instead, unique channel per gpio controller makes sense, and each channel will have multiple endpoints on linux side. As I replied to Beleswar on the other email, I will copy past my answer here too:

To be more specific:

Linux: remote:

ch1: rpmsg-gpio.-1.1024 -> gpio-controller@1024
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1024.
- gpio-line ept3

Quoted 5 lines

ch2: rpmsg-gpio.-1.1025 -> gpio-controller@1025
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1025.
- gpio-line ept3

Hi Mathieu,

So upon more brain storming in this approach I found limitation:

Quoted 8 lines

This approach won't work if host OS is any other OS but Linux. For example, if the remote OS is zephyr/baremetal using open-amp, then Only Linux <-> zephyr combination will work, and we won't be able to re-use this approach for zephyr <-> zephyr use case. The concept of rpmsg channel/device exist only in the linux kernel implementation. This brings another question: Should the protocol we decide work on other use cases as well? Or Linux must be the Host OS for this protocol ?

Linux and Zephyr are very distinct OS, each with their own subsystems and characteristics. The design we choose here involves RPMSG and, inherently, Linux. We can't make decisions based on what may potentially happen in Zephyr.

Quoted 5 lines

I think your & Arnaud's proposed approach of single endpoint per gpio-controller on both side makes more sense, as it will work regardless of any OS on host or remote side.

Arnaud, Beleswar, Andrew and I are all advocating for one endpoint per GPIO controller. The remaining issue it about the best way to work out source and destination addresses between Linux and the remote processor. I'm running out of time for today but I'll return to this thread with a final analysis by the end of the week.

Quoted 111 lines

To be more specific this will look like following:

Host (Linux) Remote (baremetal/RTOS)

rpmsg ch/device 1:
- rpmsg ept 1 <------> rpmsg ept 1 gpio-controller 0

rpmsg ch/device 2:
- rpmsg ept 2 <------> rpmsg ept 2 gpio-controller 1

The question is, how to decide src ept, and dest ept on both sides? I still think it should be static endpoints.

I will get back with more reasoning on that.

Quoted 94 lines

On the remote side, we have to hardcode Which rpmsg controller is mapped to which endpoint.

Quoted 5 lines

Or did I misunderstand your questions?

Thanks,
Arnaud

I gave this patch more time yesterday, and I think the 'reg' property should represent remote endpoint, instead of the gpio-controller index.

So in this approach remote implementation is expected to provide hard-coded (static) endpoints for each gpio-controller instance, and that same number should be represented with the 'reg' property.

On remote side:

#define RPMSG_GPIO_0_CONTROLLER_EPT (RPMSG_RESERVED_ADDRESSES + 1) // 1024

ept_1024_callback() {

      // handle appropriate gpio port ()

}

On linux side:

So new representation of controller:

 rpmsg_gpio_0:   gpio@1024 {
             compatible = "rpmsg-gpio";
             reg = <1024>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };
 rpmsg_gpio_1:   gpio@1025 {
             compatible = "rpmsg-gpio";
             reg = <1025>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };

gpios = <&rpmsg_gpio_0 (GPIO NUM or PIN) flags>,

      <&rpmsg_gpio_1 (GPIO NUM or PIN) flags>;

Now in the linux driver:

You can easily retrieve destination endpoint when we want to send the command to the gpio controller via device's "reg" property.

This approach also provides built-in security as well. Because now gpio-controller instance is hardcoded with the endpoint callback, it can't be modified/addressed without changing the 'reg' property.

Just like you wouldn't change device address for the instance of the gpio-controller right?

This approach can be easily adapted to all the other rpmsg controllers as well.

So, dynamic endpoint allocation doesn't make sense in this case. Dynamic endpoint allocation makes more sense for user-space apps which don't really care about endpoints and only payloads.

But, here we are multiplexing device-addresses with endpoints, and so it has to be fixed, and presented via 'reg' property. So, firmware can't change device-address without Linux knowing it.

Thanks,
Tanmay

Quoted 14 lines
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

#38 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 5 lines

Arnaud, Beleswar, Andrew and I are all advocating for one endpoint per GPIO controller. The remaining issue it about the best way to work out source and destination addresses between Linux and the remote processor. I'm running out of time for today but I'll return to this thread with a final analysis by the end of the week.

How many of the participants here will be in Minneapolis next week for the Embedded Linux Conference? There is even a talk about this:

https://osselcna2026.sched.com/event/2JQpx/building-virtual-drivers-with-rpmsg-key-design-principles-challenges-trade-offs-beleswar-prasad-padhi-texas-instruments?iframe=yes&w=100%&sidebar=yes&bg=no

Maybe we can get together and decide on the final design after the session.

Andrew

#39 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Hello Andrew,

Quoted 6 lines · Andrew Lunn
Quoted 5 lines

Arnaud, Beleswar, Andrew and I are all advocating for one endpoint per GPIO controller. The remaining issue it about the best way to work out source and destination addresses between Linux and the remote processor. I'm running out of time for today but I'll return to this thread with a final analysis by the end of the week.

Quoted 7 lines

How many of the participants here will be in Minneapolis next week for the Embedded Linux Conference? There is even a talk about this:

https://osselcna2026.sched.com/event/2JQpx/building-virtual-drivers-with-rpmsg-key-design-principles-challenges-trade-offs-beleswar-prasad-padhi-texas-instruments?iframe=yes&w=100%&sidebar=yes&bg=no

Maybe we can get together and decide on the final design after the session.

I won’t be there, but I can join remotely if a call is scheduled,

Regards,
Arnaud

Quoted 2 lines

Andrew

maintainer
#40 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

In reply to Andrew Lunn
Quoted 7 lines · Andrew Lunn
Quoted 6 lines

Arnaud, Beleswar, Andrew and I are all advocating for one endpoint per GPIO controller. The remaining issue it about the best way to work out source and destination addresses between Linux and the remote processor. I'm running out of time for today but I'll return to this thread with a final analysis by the end of the week.

Quoted 8 lines

How many of the participants here will be in Minneapolis next week for the Embedded Linux Conference? There is even a talk about this:

https://osselcna2026.sched.com/event/2JQpx/building-virtual-drivers-with-rpmsg-key-design-principles-challenges-trade-offs-beleswar-prasad-padhi-texas-instruments?iframe=yes&w=100%&sidebar=yes&bg=no

Maybe we can get together and decide on the final design after the session.

I will not be in Minneapolis next week. At this point I think things are converging into 2 main takeaways:

1) A serious refactoring of the protocol to include only what is available in the virtio-gpio specification [1].
2) The specification of GPIO controller number in an extension of the namespace announcement [2].

Shenwei proposed embedding the GPIO controller number in the endpoint's source address [3], something I'm ambivalent about and still have to look into. I also have to read Tanmay's latest comments. I'm hoping to be done with all that by the end of the week. With the above (1) and (2), a new patchset will be required to reset this thread.

Thanks,
Mathieu

[1]. https://lwn.net/ml/all/afjyH5JT0JS2j0L5@p14s/
[2]. https://lwn.net/ml/all/afzIABSh1xtMEGbf%40p14s/
[3]. https://lwn.net/ml/all/PAXPR04MB9185BFA6E7375FAD0B15B021893C2@PAXPR04MB9185.eurprd04.prod.outlook.com/

Quoted 1 line

Andrew

#41 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 14 lines · Mathieu Poirier
Quoted 5 lines · Andrew Lunn
Quoted 5 lines

Arnaud, Beleswar, Andrew and I are all advocating for one endpoint per GPIO controller. The remaining issue it about the best way to work out source and destination addresses between Linux and the remote processor. I'm running out of time for today but I'll return to this thread with a final analysis by the end of the week.

Quoted 8 lines

How many of the participants here will be in Minneapolis next week for the Embedded Linux Conference? There is even a talk about this:

https://osselcna2026.sched.com/event/2JQpx/building-virtual-drivers-with-rpmsg-key-design-principles-challenges-trade-offs-beleswar-prasad-padhi-texas-instruments?iframe=yes&w=100%&sidebar=yes&bg=no

Maybe we can get together and decide on the final design after the session.

Quoted 7 lines

I will not be in Minneapolis next week. At this point I think things are converging into 2 main takeaways:

1) A serious refactoring of the protocol to include only what is available in the virtio-gpio specification [1].
2) The specification of GPIO controller number in an extension of the namespace announcement [2].

Fair enough. I am also aligned to use this solution with the support for wildcard name service matching.

Thanks,
Beleswar

Quoted 16 lines

Shenwei proposed embedding the GPIO controller number in the endpoint's source address [3], something I'm ambivalent about and still have to look into. I also have to read Tanmay's latest comments. I'm hoping to be done with all that by the end of the week. With the above (1) and (2), a new patchset will be required to reset this thread.

Thanks,
Mathieu

[1]. https://lwn.net/ml/all/afjyH5JT0JS2j0L5@p14s/
[2]. https://lwn.net/ml/all/afzIABSh1xtMEGbf%40p14s/
[3]. https://lwn.net/ml/all/PAXPR04MB9185BFA6E7375FAD0B15B021893C2@PAXPR04MB9185.eurprd04.prod.outlook.com/

Quoted 1 line

Andrew

#42 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

In reply to Mathieu Poirier
Quoted 522 lines · Mathieu Poirier
Quoted 501 lines · Tanmay
Quoted 486 lines · Tanmay
Quoted 454 lines · Arnaud POULIQUEN

Hi Tanmay,

Quoted 155 lines · Tanmay

Hello all,

I have started reviewing this work as well.
Thanks Shenwei for this work.

I have gone through only the current revision, and would like to provide idea on how to achieve GPIO number multiplexing with the RPMsg protocol. Also, have some bindings related question.

Please see below:

Quoted 135 lines · Arnaud POULIQUEN
Quoted 132 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 129 lines · Arnaud POULIQUEN

Hello,

Quoted 126 lines · Mathieu Poirier
Quoted 113 lines · Beleswar

Hi Mathieu,

Quoted 101 lines · Mathieu Poirier
Quoted 93 lines · Shenwei Wang
Quoted 93 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <b-
[email protected]>; Linus
Walleij <[email protected]>; Bartosz Golaszewski
<[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>;
Krzysztof Kozlowski
<[email protected]>; Conor Dooley <[email protected]>; Bjorn
Andersson
<[email protected]>; Frank Li <[email protected]>; Sascha Hauer
<[email protected]>; Shuah Khan
<[email protected]>; linux-
[email protected]; [email protected]; linux-
[email protected];
Pengutronix Kernel Team <[email protected]>; Fabio Estevam
<[email protected]>; Peng Fan <[email protected]>;
[email protected]; [email protected];
[email protected]; [email protected]; dl-
linux-imx <linux-
[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic
rpmsg GPIO driver
On Tue, Apr 28, 2026 at 03:24:59PM +0000, Shenwei Wang wrote:

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij
<[email protected]>; Bartosz Golaszewski <[email protected]>;
Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>;
Krzysztof
Kozlowski <[email protected]>; Conor Dooley
<[email protected]>;
Bjorn Andersson <[email protected]>; Mathieu Poirier
<[email protected]>; Frank Li <[email protected]>;
Sascha
Hauer <[email protected]>; Shuah Khan
<[email protected]>; [email protected]; linux-
[email protected]; [email protected]; Pengutronix
Kernel Team <[email protected]>; Fabio Estevam
<[email protected]>; Peng Fan <[email protected]>;
[email protected]; linux- [email protected];
[email protected]; linux-arm- [email protected];
dl-linux-imx <[email protected]>; Bartosz Golaszewski
<[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic
rpmsg
GPIO driver
struct virtio_gpio_response {
__u8 status;
__u8 value;
};
It is the same message format. Please see the message
definition
(GET_DIRECTION) below:

+ +-----+-----+-----+-----+-----+----+
+ |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+ | 1 | 2 |port |line | err | dir|
+ +-----+-----+-----+-----+-----+----+
Sorry, but i don't see how two u8 vs six u8 are the same
message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for
requests and
replies, and a second one for events.
In contrast, rpmsg provides only a single communication
channel, so a
type field is required to distinguish between different kinds
of messages.

Since rpmsg replies and events share the same message format,
an additional
line is introduced to handle both cases.
Finally, rpmsg supports multiple GPIO controllers, so a port
field is added to
uniquely identify the target controller.

I have commented on this before - RPMSG is already providing
multiplexing
capability by way of endpoints. There is no need for a port
field. One endpoint,
one GPIO controller.

Quoted 6 lines

You still need a way to let the remote side know which port the endpoint maps to, either
by embedding the port information in the message (the current way), or by sending it
separately.

Quoted 6 lines

An endpoint is created with every namespace request. There should be
one namespace request for every GPIO controller, which yields a unique
endpoint for each controller and eliminates the need for an extra field to identify them.

Quoted 8 lines

Right, but this can still be done by just having one namespace request.
We can create new endpoints bound to an existing namespace/ channel by
invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/29485742-6e49-482e-
[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io

       a. ept1 -> gpio-controller@1
       b. ept2 -> gpio-controller@2
Quoted 6 lines

If my understanding of what gpio-controller is right, than this won't work. We need one rpmsg channel per gpio-controller, and in most cases there will be only one GPIO-controller on the remote side. If there are multiple or multiple instances of same controller, than we need separate channel name for that controller just like we would have separate device on the Linux.

As done in ehe rpmsg_tty driver it could be instantiated several times with the same channel/service name. This would imply a specific rpmsg to retreive
the gpio controller index from the remote side.

Quoted 75 lines
Quoted 71 lines
Quoted 28 lines
Quoted 13 lines
Quoted 12 lines

I've asked for one endpoint per GPIO controller since the very beginning. I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints. I'll have to look at your link and reflect on
that. Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level. This is
the only way this work can move forward.

Quoted 6 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this
Linux need not have the port field in the message everytime its sending a message.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

With a multi-namespace approach, the namespace could be rpmsg-io- [addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here
my sentence should be;
With a multi-namespace approach, the namespace could be rpmsg-io-
[port],
where [port] corresponds to the GPIO controller port in the DT.

For instance:

       rpmsg {
         rpmsg-io {
           #address-cells = <1>;
           #size-cells = <0>;

           gpio@25 {
             compatible = "rpmsg-gpio";
             reg = <25>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };

           gpio@32 {
             compatible = "rpmsg-gpio";
             reg = <32>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };
         };
       };
Quoted 3 lines

rpmsg-io-25 would match with gpio@25
rpmsg-io-32 would match with gpio@32

Quoted 5 lines

The problem with this approach is, we will endup creating way too many RPMsg devices/channels. i.e. one channel per one GPIO. That limits how many GPIOs can be handled by remote from memory perspective. At somepoint we might just run-out of number ept & channels created by the remote. As of now, open-amp library supports 128 epts I think.

Right, I proposed a solution in my previous answer to Beleswar who has the same concern.

Quoted 118 lines
Quoted 71 lines
Quoted 23 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel
ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev
addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel
formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13:
new channel: 0x401 -> 0xd!
Quoted 3 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.

Quoted 22 lines
Quoted 3 lines

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 2 lines

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 7 lines
Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Quoted 17 lines

Thanks and Regards,Arnaud

Quoted 15 lines

Thanks,
Beleswar

Quoted 11 lines

Regards,
Arnaud

Quoted 7 lines
Quoted 7 lines

2. namespace/channel#2 = rpmsg-i2c

       a. ept1 -> i2c@1
       b. ept2 -> i2c@2
       c. ept3 -> i2c@3

etc...

Just want to clear-up few terms before I jump to the solution:

**RPMsg channel/device**:
- These are devices announced by the remote processor, and created by
linux. They are created at: /sys/bus/rpmsg/devices
- The channel format: <name>.<src ept>.<dst ept>

**RPMsg endpoint**:
- Endpoint is differnt than channel. Single channel can have multiple
endpoints, and represented in the linux with: /dev/rpmsg? devices.

To create endpoint device, we have rpmsg_create_ept API, which takes channel information as input, which has src-ept, dst-ept.

Following is proposed solution:

1) Assign RPMsg channel/device per rpmsg-gpio controller (Not per GPIO pin/port).
- In our case that would be, single rpmsg-io node. (That makes me
question if bindings are correct or not).

2) Assign GPIO number as src ept.

i.e. *rpmsg-io.<GPIO number>.<dst ept>*. Do not randomly assign src endpoint.

Now, RPMSG channel by spec reserves first 1024 endpoints [1], so we can add 1024 offset to the GPIO number:

Quoted 8 lines

so, when calling rpmsg_create_ept() API, we assing src_endpoint as:
(GPIO_NUMBER + RPMSG_RESERVED_ADDRESSES)

Now on the remote side, there is single channel and only single-endpoint is needed that is mapped to the rpmsg-io channel callback.

That callback will receive all the payloads from the Linux, which will have src-ept i.e. (RPMSG_RESERVED_ADDRESSES + GPIO_NUMBER).

Interesting approach. I also tried to find a similar solution.

The question here is: how can we guarantee continuous addresses? Given the static and dynamic allocation of endpoint addresses that are implemented, my conclusion was that it is not reliable enough.

but perhaps I missed something...

Quoted 56 lines

It can retrieve GPIO_NUMBER easily, and convert to appropriate pin based on platform specific logic.

This doesn't need PORT information at all. Also it makes sure that remote is using only single-endpoint so not much memory is used.

*Example*:
If only rpmsg-gpio channel is created by the remote side, than following is the representation of the devices when GPIO 25, 26, 27 is assigned to the rpmsg-io controller:

Linux Remote

rpmsg-channel: rpmsg-gpio.0x400.0x400

/dev/rpmsg0 - GPIO25 ept (rpmsg-gpio.0x419.0x400)-|

                                                   |
/dev/rpmsg1 - GPIO26 ept (rpmsg-gpio.0x41a.0x400)-|-> rpmsg-gpio.*.0x400
                                                   |

/dev/rpmsg2 - GPIO27 ept (rpmsg-gpio.0x41b.0x400)-| 0x400 ept callback.

*On remote side*:

ept_0x400_callback(..., int src_ept, ...,)

{
    int gpio_num = src_ept - RPMSG_RESERVED_ADDRESSES;
    // platform specific logic to convert gpio num to proper pin,
    // just like you would convert gpio num to pin on a linux gpio

controller.
}

My question on the binding:

Why each GPIO is represented with the separate node? I think rpmsg-gpio can be represented just any other GPIO controller? Please let me know if I am missing something. So rpmsg channel/rpmsg device is not created per GPIO, but per controller. GPIO number multiplexing should be done with rpmsg src ept, that removes the need of having each GPIO as a separate node.

rpmsg_gpio: rpmsg-gpio@0 {
        compatible = "rpmsg-gpio";
        reg = <0>;
        gpio-controller;
        #gpio-cells = <2>;
        #interrupt-cells = <2>;
        interrupt-controller;
    };

Then in DT, use like regular GPIO, but with the rpmsg-gpio controller:

rpmsg-gpios = <&rpmsg_gpio (GPIO NUM) (flags)>;

Quoted 8 lines

If the intent to create separate gpio nodes was only for the channel creation, then it's not really needed.

[1]
https://github.com/torvalds/linux/
blob/6d35786de28116ecf78797a62b84e6bf3c45aa5a/drivers/rpmsg/ virtio_rpmsg_bus.c#L136

Quoted 9 lines

It is already the case. bindings declare GPIO controllers, not directly GPIOs in:

[PATCH v13 2/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support

The discussion is around having an unique RPmsg endpoint for all GPIO controller or one RPmsg endpoint per GPIO controller.

Endpoint where remote side or linux side?

If unique endpoint on remote side per gpio controller then it makes sense.

Unique endpoint on linux side doesn't make sense. Instead, unique channel per gpio controller makes sense, and each channel will have multiple endpoints on linux side. As I replied to Beleswar on the other email, I will copy past my answer here too:

To be more specific:

Linux: remote:

ch1: rpmsg-gpio.-1.1024 -> gpio-controller@1024
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1024.
- gpio-line ept3

Quoted 5 lines

ch2: rpmsg-gpio.-1.1025 -> gpio-controller@1025
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1025.
- gpio-line ept3

Hi Mathieu,

So upon more brain storming in this approach I found limitation:

Quoted 8 lines

This approach won't work if host OS is any other OS but Linux. For example, if the remote OS is zephyr/baremetal using open-amp, then Only Linux <-> zephyr combination will work, and we won't be able to re-use this approach for zephyr <-> zephyr use case. The concept of rpmsg channel/device exist only in the linux kernel implementation. This brings another question: Should the protocol we decide work on other use cases as well? Or Linux must be the Host OS for this protocol ?

Linux and Zephyr are very distinct OS, each with their own subsystems and characteristics. The design we choose here involves RPMSG and, inherently, Linux. We can't make decisions based on what may potentially happen in Zephyr.

Quoted 5 lines

I think your & Arnaud's proposed approach of single endpoint per gpio-controller on both side makes more sense, as it will work regardless of any OS on host or remote side.

Quoted 6 lines

Arnaud, Beleswar, Andrew and I are all advocating for one endpoint per GPIO controller. The remaining issue it about the best way to work out source and destination addresses between Linux and the remote processor. I'm running out of time for today but I'll return to this thread with a final analysis by the end of the week.

Okay. Then that means multiple endpoints on Linux side can be considered.

If we decide to go single-endpoint per device on both side, then for that here is the proposal to represent src ept and dst ept:

When we represent any device under rpmsg bus node, I think it should be considered remote's view of the adddress space. So ideally we can convert it to Linux view of the address space, via 'ranges' property.

So bindings should include 'ranges' property in the parent node. Then linux view of the start address becomes src ept, and remote view of the start address becomes dest ept. The remote view of the start address is expected to be the static src endpoint on the remote side.

Following representation of the rpmsg devices (gpio, i2c, spi or any other):

rpmsg {
#address-cells = <1>;
#size-cells = <1>;

  rpmsg-io {
    compatible = "rpmsg-io-bus";
    ranges = <remote_view_addr(dst ept) linux_view_addr(src ept) size>;
    #address-cells = <1>;
    #size-cells = <1>;
    gpio@remote_view_addr(or dst ept) {
      compatible = "rpmsg-io";
      reg = <remote_view_addr addr_space_size>;
      gpio-controller;
      #gpio-cells = <2>;
      interrupt-controller;
      #interrupt-cells = <2>;
    };

    ...
  };

};

Example device-tree:

rpmsg {
#address-cells = <1>;
#size-cells = <1>;

  rpmsg-io {
    compatible = "rpmsg-io-bus";
    ranges = <0x10000 0x50000 0x1000>,
             <0x20000 0x60000 0x1000>;
    #address-cells = <1>;
    #size-cells = <1>;
    gpio@10000 {
      compatible = "rpmsg-io";
      reg = <0x10000 0x1000>;
      gpio-controller;
      #gpio-cells = <2>;
      interrupt-controller;
      #interrupt-cells = <2>;
    };

    gpio@20000 {
      compatible = "rpmsg-io";
      reg = <0x20000 0x1000>;
      gpio-controller;
      #gpio-cells = <2>;
      interrupt-controller;
      #interrupt-cells = <2>;
    };
  };

};

Thanks,
Tanmay

Quoted 111 lines
Quoted 111 lines

To be more specific this will look like following:

Host (Linux) Remote (baremetal/RTOS)

rpmsg ch/device 1:
- rpmsg ept 1 <------> rpmsg ept 1 gpio-controller 0

rpmsg ch/device 2:
- rpmsg ept 2 <------> rpmsg ept 2 gpio-controller 1

The question is, how to decide src ept, and dest ept on both sides? I still think it should be static endpoints.

I will get back with more reasoning on that.

Quoted 94 lines

On the remote side, we have to hardcode Which rpmsg controller is mapped to which endpoint.

Quoted 5 lines

Or did I misunderstand your questions?

Thanks,
Arnaud

I gave this patch more time yesterday, and I think the 'reg' property should represent remote endpoint, instead of the gpio-controller index.

So in this approach remote implementation is expected to provide hard-coded (static) endpoints for each gpio-controller instance, and that same number should be represented with the 'reg' property.

On remote side:

#define RPMSG_GPIO_0_CONTROLLER_EPT (RPMSG_RESERVED_ADDRESSES + 1) // 1024

ept_1024_callback() {

      // handle appropriate gpio port ()

}

On linux side:

So new representation of controller:

 rpmsg_gpio_0:   gpio@1024 {
             compatible = "rpmsg-gpio";
             reg = <1024>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };
 rpmsg_gpio_1:   gpio@1025 {
             compatible = "rpmsg-gpio";
             reg = <1025>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };

gpios = <&rpmsg_gpio_0 (GPIO NUM or PIN) flags>,

      <&rpmsg_gpio_1 (GPIO NUM or PIN) flags>;

Now in the linux driver:

You can easily retrieve destination endpoint when we want to send the command to the gpio controller via device's "reg" property.

This approach also provides built-in security as well. Because now gpio-controller instance is hardcoded with the endpoint callback, it can't be modified/addressed without changing the 'reg' property.

Just like you wouldn't change device address for the instance of the gpio-controller right?

This approach can be easily adapted to all the other rpmsg controllers as well.

So, dynamic endpoint allocation doesn't make sense in this case. Dynamic endpoint allocation makes more sense for user-space apps which don't really care about endpoints and only payloads.

But, here we are multiplexing device-addresses with endpoints, and so it has to be fixed, and presented via 'reg' property. So, firmware can't change device-address without Linux knowing it.

Thanks,
Tanmay

Quoted 14 lines
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

maintainer
#43 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 525 lines · Tanmay
Quoted 522 lines · Mathieu Poirier
Quoted 501 lines · Tanmay
Quoted 486 lines · Tanmay
Quoted 454 lines · Arnaud POULIQUEN

Hi Tanmay,

Quoted 155 lines · Tanmay

Hello all,

I have started reviewing this work as well.
Thanks Shenwei for this work.

I have gone through only the current revision, and would like to provide idea on how to achieve GPIO number multiplexing with the RPMsg protocol. Also, have some bindings related question.

Please see below:

Quoted 135 lines · Arnaud POULIQUEN
Quoted 132 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 129 lines · Arnaud POULIQUEN

Hello,

Quoted 126 lines · Mathieu Poirier
Quoted 113 lines · Beleswar

Hi Mathieu,

Quoted 101 lines · Mathieu Poirier
Quoted 99 lines · Shenwei Wang

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <b-
[email protected]>; Linus
Walleij <[email protected]>; Bartosz Golaszewski
<[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>;
Krzysztof Kozlowski
<[email protected]>; Conor Dooley <[email protected]>; Bjorn
Andersson
<[email protected]>; Frank Li <[email protected]>; Sascha Hauer
<[email protected]>; Shuah Khan
<[email protected]>; linux-
[email protected]; [email protected]; linux-
[email protected];
Pengutronix Kernel Team <[email protected]>; Fabio Estevam
<[email protected]>; Peng Fan <[email protected]>;
[email protected]; [email protected];
[email protected]; [email protected]; dl-
linux-imx <linux-
[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic
rpmsg GPIO driver
On Tue, Apr 28, 2026 at 03:24:59PM +0000, Shenwei Wang wrote:

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij
<[email protected]>; Bartosz Golaszewski <[email protected]>;
Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>;
Krzysztof
Kozlowski <[email protected]>; Conor Dooley
<[email protected]>;
Bjorn Andersson <[email protected]>; Mathieu Poirier
<[email protected]>; Frank Li <[email protected]>;
Sascha
Hauer <[email protected]>; Shuah Khan
<[email protected]>; [email protected]; linux-
[email protected]; [email protected]; Pengutronix
Kernel Team <[email protected]>; Fabio Estevam
<[email protected]>; Peng Fan <[email protected]>;
[email protected]; linux- [email protected];
[email protected]; linux-arm- [email protected];
dl-linux-imx <[email protected]>; Bartosz Golaszewski
<[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic
rpmsg
GPIO driver
struct virtio_gpio_response {
__u8 status;
__u8 value;
};
It is the same message format. Please see the message
definition
(GET_DIRECTION) below:

+ +-----+-----+-----+-----+-----+----+
+ |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+ | 1 | 2 |port |line | err | dir|
+ +-----+-----+-----+-----+-----+----+
Sorry, but i don't see how two u8 vs six u8 are the same
message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for
requests and
replies, and a second one for events.
In contrast, rpmsg provides only a single communication
channel, so a
type field is required to distinguish between different kinds
of messages.

Since rpmsg replies and events share the same message format,
an additional
line is introduced to handle both cases.
Finally, rpmsg supports multiple GPIO controllers, so a port
field is added to
uniquely identify the target controller.

I have commented on this before - RPMSG is already providing
multiplexing
capability by way of endpoints. There is no need for a port
field. One endpoint,
one GPIO controller.

You still need a way to let the remote side know which port the
endpoint maps to, either
by embedding the port information in the message (the current
way), or by sending it
separately.

Quoted 6 lines

An endpoint is created with every namespace request. There should be
one namespace request for every GPIO controller, which yields a unique
endpoint for each controller and eliminates the need for an extra field to identify them.

Quoted 8 lines

Right, but this can still be done by just having one namespace request.
We can create new endpoints bound to an existing namespace/ channel by
invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/29485742-6e49-482e-
[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io

       a. ept1 -> gpio-controller@1
       b. ept2 -> gpio-controller@2
Quoted 6 lines

If my understanding of what gpio-controller is right, than this won't work. We need one rpmsg channel per gpio-controller, and in most cases there will be only one GPIO-controller on the remote side. If there are multiple or multiple instances of same controller, than we need separate channel name for that controller just like we would have separate device on the Linux.

As done in ehe rpmsg_tty driver it could be instantiated several times with the same channel/service name. This would imply a specific rpmsg to retreive
the gpio controller index from the remote side.

Quoted 75 lines
Quoted 71 lines
Quoted 28 lines
Quoted 13 lines
Quoted 12 lines

I've asked for one endpoint per GPIO controller since the very beginning. I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints. I'll have to look at your link and reflect on
that. Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level. This is
the only way this work can move forward.

Quoted 6 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this
Linux need not have the port field in the message everytime its sending a message.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

With a multi-namespace approach, the namespace could be rpmsg-io- [addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here
my sentence should be;
With a multi-namespace approach, the namespace could be rpmsg-io-
[port],
where [port] corresponds to the GPIO controller port in the DT.

For instance:

       rpmsg {
         rpmsg-io {
           #address-cells = <1>;
           #size-cells = <0>;

           gpio@25 {
             compatible = "rpmsg-gpio";
             reg = <25>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };

           gpio@32 {
             compatible = "rpmsg-gpio";
             reg = <32>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };
         };
       };
Quoted 3 lines

rpmsg-io-25 would match with gpio@25
rpmsg-io-32 would match with gpio@32

Quoted 5 lines

The problem with this approach is, we will endup creating way too many RPMsg devices/channels. i.e. one channel per one GPIO. That limits how many GPIOs can be handled by remote from memory perspective. At somepoint we might just run-out of number ept & channels created by the remote. As of now, open-amp library supports 128 epts I think.

Right, I proposed a solution in my previous answer to Beleswar who has the same concern.

Quoted 118 lines
Quoted 71 lines
Quoted 23 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel
ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev
addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel
formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13:
new channel: 0x401 -> 0xd!
Quoted 3 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.

Quoted 22 lines
Quoted 3 lines

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 2 lines

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 7 lines
Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Quoted 17 lines

Thanks and Regards,Arnaud

Quoted 15 lines

Thanks,
Beleswar

Quoted 11 lines

Regards,
Arnaud

Quoted 7 lines
Quoted 7 lines

2. namespace/channel#2 = rpmsg-i2c

       a. ept1 -> i2c@1
       b. ept2 -> i2c@2
       c. ept3 -> i2c@3

etc...

Just want to clear-up few terms before I jump to the solution:

**RPMsg channel/device**:
- These are devices announced by the remote processor, and created by
linux. They are created at: /sys/bus/rpmsg/devices
- The channel format: <name>.<src ept>.<dst ept>

**RPMsg endpoint**:
- Endpoint is differnt than channel. Single channel can have multiple
endpoints, and represented in the linux with: /dev/rpmsg? devices.

To create endpoint device, we have rpmsg_create_ept API, which takes channel information as input, which has src-ept, dst-ept.

Following is proposed solution:

1) Assign RPMsg channel/device per rpmsg-gpio controller (Not per GPIO pin/port).
- In our case that would be, single rpmsg-io node. (That makes me
question if bindings are correct or not).

2) Assign GPIO number as src ept.

i.e. *rpmsg-io.<GPIO number>.<dst ept>*. Do not randomly assign src endpoint.

Now, RPMSG channel by spec reserves first 1024 endpoints [1], so we can add 1024 offset to the GPIO number:

Quoted 8 lines

so, when calling rpmsg_create_ept() API, we assing src_endpoint as:
(GPIO_NUMBER + RPMSG_RESERVED_ADDRESSES)

Now on the remote side, there is single channel and only single-endpoint is needed that is mapped to the rpmsg-io channel callback.

That callback will receive all the payloads from the Linux, which will have src-ept i.e. (RPMSG_RESERVED_ADDRESSES + GPIO_NUMBER).

Interesting approach. I also tried to find a similar solution.

The question here is: how can we guarantee continuous addresses? Given the static and dynamic allocation of endpoint addresses that are implemented, my conclusion was that it is not reliable enough.

but perhaps I missed something...

Quoted 56 lines

It can retrieve GPIO_NUMBER easily, and convert to appropriate pin based on platform specific logic.

This doesn't need PORT information at all. Also it makes sure that remote is using only single-endpoint so not much memory is used.

*Example*:
If only rpmsg-gpio channel is created by the remote side, than following is the representation of the devices when GPIO 25, 26, 27 is assigned to the rpmsg-io controller:

Linux Remote

rpmsg-channel: rpmsg-gpio.0x400.0x400

/dev/rpmsg0 - GPIO25 ept (rpmsg-gpio.0x419.0x400)-|

                                                   |
/dev/rpmsg1 - GPIO26 ept (rpmsg-gpio.0x41a.0x400)-|-> rpmsg-gpio.*.0x400
                                                   |

/dev/rpmsg2 - GPIO27 ept (rpmsg-gpio.0x41b.0x400)-| 0x400 ept callback.

*On remote side*:

ept_0x400_callback(..., int src_ept, ...,)

{
    int gpio_num = src_ept - RPMSG_RESERVED_ADDRESSES;
    // platform specific logic to convert gpio num to proper pin,
    // just like you would convert gpio num to pin on a linux gpio

controller.
}

My question on the binding:

Why each GPIO is represented with the separate node? I think rpmsg-gpio can be represented just any other GPIO controller? Please let me know if I am missing something. So rpmsg channel/rpmsg device is not created per GPIO, but per controller. GPIO number multiplexing should be done with rpmsg src ept, that removes the need of having each GPIO as a separate node.

rpmsg_gpio: rpmsg-gpio@0 {
        compatible = "rpmsg-gpio";
        reg = <0>;
        gpio-controller;
        #gpio-cells = <2>;
        #interrupt-cells = <2>;
        interrupt-controller;
    };

Then in DT, use like regular GPIO, but with the rpmsg-gpio controller:

rpmsg-gpios = <&rpmsg_gpio (GPIO NUM) (flags)>;

Quoted 8 lines

If the intent to create separate gpio nodes was only for the channel creation, then it's not really needed.

[1]
https://github.com/torvalds/linux/
blob/6d35786de28116ecf78797a62b84e6bf3c45aa5a/drivers/rpmsg/ virtio_rpmsg_bus.c#L136

Quoted 9 lines

It is already the case. bindings declare GPIO controllers, not directly GPIOs in:

[PATCH v13 2/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support

The discussion is around having an unique RPmsg endpoint for all GPIO controller or one RPmsg endpoint per GPIO controller.

Endpoint where remote side or linux side?

If unique endpoint on remote side per gpio controller then it makes sense.

Unique endpoint on linux side doesn't make sense. Instead, unique channel per gpio controller makes sense, and each channel will have multiple endpoints on linux side. As I replied to Beleswar on the other email, I will copy past my answer here too:

To be more specific:

Linux: remote:

ch1: rpmsg-gpio.-1.1024 -> gpio-controller@1024
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1024.
- gpio-line ept3

Quoted 5 lines

ch2: rpmsg-gpio.-1.1025 -> gpio-controller@1025
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1025.
- gpio-line ept3

Hi Mathieu,

So upon more brain storming in this approach I found limitation:

Quoted 8 lines

This approach won't work if host OS is any other OS but Linux. For example, if the remote OS is zephyr/baremetal using open-amp, then Only Linux <-> zephyr combination will work, and we won't be able to re-use this approach for zephyr <-> zephyr use case. The concept of rpmsg channel/device exist only in the linux kernel implementation. This brings another question: Should the protocol we decide work on other use cases as well? Or Linux must be the Host OS for this protocol ?

Linux and Zephyr are very distinct OS, each with their own subsystems and characteristics. The design we choose here involves RPMSG and, inherently, Linux. We can't make decisions based on what may potentially happen in Zephyr.

Quoted 5 lines

I think your & Arnaud's proposed approach of single endpoint per gpio-controller on both side makes more sense, as it will work regardless of any OS on host or remote side.

Quoted 8 lines
Quoted 6 lines

Arnaud, Beleswar, Andrew and I are all advocating for one endpoint per GPIO controller. The remaining issue it about the best way to work out source and destination addresses between Linux and the remote processor. I'm running out of time for today but I'll return to this thread with a final analysis by the end of the week.

Okay. Then that means multiple endpoints on Linux side can be considered.

If there are multiple GPIO controllers then yes, there will be more than one endpoint. At this time I do now want to condiser other bus architectures (i2c, spi, ...) to avoid muddying an already difficult conversation.

Quoted 3 lines

If we decide to go single-endpoint per device on both side, then for that here is the proposal to represent src ept and dst ept:

I do not understand what you mean by "per device" - please be more specific.

Quoted 4 lines

When we represent any device under rpmsg bus node, I think it should be considered remote's view of the adddress space. So ideally we can convert it to Linux view of the address space, via 'ranges' property.

There is no address space to consider since there is no GPIO controller memory space to access. All that is done by the driver (remote processor) and completely hidden from Linux by rpmsg-virtio-gpio.

Quoted 185 lines

So bindings should include 'ranges' property in the parent node. Then linux view of the start address becomes src ept, and remote view of the start address becomes dest ept. The remote view of the start address is expected to be the static src endpoint on the remote side.

Following representation of the rpmsg devices (gpio, i2c, spi or any other):

rpmsg {
#address-cells = <1>;
#size-cells = <1>;

  rpmsg-io {
    compatible = "rpmsg-io-bus";
    ranges = <remote_view_addr(dst ept) linux_view_addr(src ept) size>;
    #address-cells = <1>;
    #size-cells = <1>;
    gpio@remote_view_addr(or dst ept) {
      compatible = "rpmsg-io";
      reg = <remote_view_addr addr_space_size>;
      gpio-controller;
      #gpio-cells = <2>;
      interrupt-controller;
      #interrupt-cells = <2>;
    };

    ...
  };

};

Example device-tree:

rpmsg {
#address-cells = <1>;
#size-cells = <1>;

  rpmsg-io {
    compatible = "rpmsg-io-bus";
    ranges = <0x10000 0x50000 0x1000>,
             <0x20000 0x60000 0x1000>;
    #address-cells = <1>;
    #size-cells = <1>;
    gpio@10000 {
      compatible = "rpmsg-io";
      reg = <0x10000 0x1000>;
      gpio-controller;
      #gpio-cells = <2>;
      interrupt-controller;
      #interrupt-cells = <2>;
    };

    gpio@20000 {
      compatible = "rpmsg-io";
      reg = <0x20000 0x1000>;
      gpio-controller;
      #gpio-cells = <2>;
      interrupt-controller;
      #interrupt-cells = <2>;
    };
  };

};

Thanks,
Tanmay

Quoted 111 lines
Quoted 111 lines

To be more specific this will look like following:

Host (Linux) Remote (baremetal/RTOS)

rpmsg ch/device 1:
- rpmsg ept 1 <------> rpmsg ept 1 gpio-controller 0

rpmsg ch/device 2:
- rpmsg ept 2 <------> rpmsg ept 2 gpio-controller 1

The question is, how to decide src ept, and dest ept on both sides? I still think it should be static endpoints.

I will get back with more reasoning on that.

Quoted 94 lines

On the remote side, we have to hardcode Which rpmsg controller is mapped to which endpoint.

Quoted 5 lines

Or did I misunderstand your questions?

Thanks,
Arnaud

I gave this patch more time yesterday, and I think the 'reg' property should represent remote endpoint, instead of the gpio-controller index.

So in this approach remote implementation is expected to provide hard-coded (static) endpoints for each gpio-controller instance, and that same number should be represented with the 'reg' property.

On remote side:

#define RPMSG_GPIO_0_CONTROLLER_EPT (RPMSG_RESERVED_ADDRESSES + 1) // 1024

ept_1024_callback() {

      // handle appropriate gpio port ()

}

On linux side:

So new representation of controller:

 rpmsg_gpio_0:   gpio@1024 {
             compatible = "rpmsg-gpio";
             reg = <1024>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };
 rpmsg_gpio_1:   gpio@1025 {
             compatible = "rpmsg-gpio";
             reg = <1025>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };

gpios = <&rpmsg_gpio_0 (GPIO NUM or PIN) flags>,

      <&rpmsg_gpio_1 (GPIO NUM or PIN) flags>;

Now in the linux driver:

You can easily retrieve destination endpoint when we want to send the command to the gpio controller via device's "reg" property.

This approach also provides built-in security as well. Because now gpio-controller instance is hardcoded with the endpoint callback, it can't be modified/addressed without changing the 'reg' property.

Just like you wouldn't change device address for the instance of the gpio-controller right?

This approach can be easily adapted to all the other rpmsg controllers as well.

So, dynamic endpoint allocation doesn't make sense in this case. Dynamic endpoint allocation makes more sense for user-space apps which don't really care about endpoints and only payloads.

But, here we are multiplexing device-addresses with endpoints, and so it has to be fixed, and presented via 'reg' property. So, firmware can't change device-address without Linux knowing it.

Thanks,
Tanmay

Quoted 14 lines
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

#44 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 540 lines · Mathieu Poirier
Quoted 525 lines · Tanmay
Quoted 522 lines · Mathieu Poirier
Quoted 501 lines · Tanmay
Quoted 486 lines · Tanmay
Quoted 454 lines · Arnaud POULIQUEN

Hi Tanmay,

Quoted 155 lines · Tanmay

Hello all,

I have started reviewing this work as well.
Thanks Shenwei for this work.

I have gone through only the current revision, and would like to provide idea on how to achieve GPIO number multiplexing with the RPMsg protocol. Also, have some bindings related question.

Please see below:

Quoted 135 lines · Arnaud POULIQUEN
Quoted 132 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 129 lines · Arnaud POULIQUEN

Hello,

Quoted 126 lines · Mathieu Poirier
Quoted 113 lines · Beleswar

Hi Mathieu,

Quoted 107 lines · Mathieu Poirier

On Wed, 29 Apr 2026 at 10:53, Shenwei Wang <[email protected]>
wrote:

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <b-
[email protected]>; Linus
Walleij <[email protected]>; Bartosz Golaszewski
<[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>;
Krzysztof Kozlowski
<[email protected]>; Conor Dooley <[email protected]>; Bjorn
Andersson
<[email protected]>; Frank Li <[email protected]>; Sascha Hauer
<[email protected]>; Shuah Khan
<[email protected]>; linux-
[email protected]; [email protected]; linux-
[email protected];
Pengutronix Kernel Team <[email protected]>; Fabio Estevam
<[email protected]>; Peng Fan <[email protected]>;
[email protected]; [email protected];
[email protected]; [email protected]; dl-
linux-imx <linux-
[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic
rpmsg GPIO driver
On Tue, Apr 28, 2026 at 03:24:59PM +0000, Shenwei Wang wrote:

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij
<[email protected]>; Bartosz Golaszewski <[email protected]>;
Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>;
Krzysztof
Kozlowski <[email protected]>; Conor Dooley
<[email protected]>;
Bjorn Andersson <[email protected]>; Mathieu Poirier
<[email protected]>; Frank Li <[email protected]>;
Sascha
Hauer <[email protected]>; Shuah Khan
<[email protected]>; [email protected]; linux-
[email protected]; [email protected]; Pengutronix
Kernel Team <[email protected]>; Fabio Estevam
<[email protected]>; Peng Fan <[email protected]>;
[email protected]; linux- [email protected];
[email protected]; linux-arm- [email protected];
dl-linux-imx <[email protected]>; Bartosz Golaszewski
<[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic
rpmsg
GPIO driver
struct virtio_gpio_response {
__u8 status;
__u8 value;
};
It is the same message format. Please see the message
definition
(GET_DIRECTION) below:

+ +-----+-----+-----+-----+-----+----+
+ |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+ | 1 | 2 |port |line | err | dir|
+ +-----+-----+-----+-----+-----+----+
Sorry, but i don't see how two u8 vs six u8 are the same
message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for
requests and
replies, and a second one for events.
In contrast, rpmsg provides only a single communication
channel, so a
type field is required to distinguish between different kinds
of messages.

Since rpmsg replies and events share the same message format,
an additional
line is introduced to handle both cases.
Finally, rpmsg supports multiple GPIO controllers, so a port
field is added to
uniquely identify the target controller.

I have commented on this before - RPMSG is already providing
multiplexing
capability by way of endpoints. There is no need for a port
field. One endpoint,
one GPIO controller.

You still need a way to let the remote side know which port the
endpoint maps to, either
by embedding the port information in the message (the current
way), or by sending it
separately.

An endpoint is created with every namespace request. There
should be
one namespace request for every GPIO controller, which yields a
unique
endpoint for each controller and eliminates the need for an extra
field to identify them.

Quoted 8 lines

Right, but this can still be done by just having one namespace request.
We can create new endpoints bound to an existing namespace/ channel by
invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/29485742-6e49-482e-
[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io

       a. ept1 -> gpio-controller@1
       b. ept2 -> gpio-controller@2
Quoted 6 lines

If my understanding of what gpio-controller is right, than this won't work. We need one rpmsg channel per gpio-controller, and in most cases there will be only one GPIO-controller on the remote side. If there are multiple or multiple instances of same controller, than we need separate channel name for that controller just like we would have separate device on the Linux.

As done in ehe rpmsg_tty driver it could be instantiated several times with the same channel/service name. This would imply a specific rpmsg to retreive
the gpio controller index from the remote side.

Quoted 75 lines
Quoted 71 lines
Quoted 28 lines
Quoted 13 lines
Quoted 12 lines

I've asked for one endpoint per GPIO controller since the very beginning. I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints. I'll have to look at your link and reflect on
that. Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level. This is
the only way this work can move forward.

Quoted 6 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this
Linux need not have the port field in the message everytime its sending a message.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

With a multi-namespace approach, the namespace could be rpmsg-io- [addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here
my sentence should be;
With a multi-namespace approach, the namespace could be rpmsg-io-
[port],
where [port] corresponds to the GPIO controller port in the DT.

For instance:

       rpmsg {
         rpmsg-io {
           #address-cells = <1>;
           #size-cells = <0>;

           gpio@25 {
             compatible = "rpmsg-gpio";
             reg = <25>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };

           gpio@32 {
             compatible = "rpmsg-gpio";
             reg = <32>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };
         };
       };
Quoted 3 lines

rpmsg-io-25 would match with gpio@25
rpmsg-io-32 would match with gpio@32

Quoted 5 lines

The problem with this approach is, we will endup creating way too many RPMsg devices/channels. i.e. one channel per one GPIO. That limits how many GPIOs can be handled by remote from memory perspective. At somepoint we might just run-out of number ept & channels created by the remote. As of now, open-amp library supports 128 epts I think.

Right, I proposed a solution in my previous answer to Beleswar who has the same concern.

Quoted 118 lines
Quoted 71 lines
Quoted 23 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel
ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev
addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel
formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13:
new channel: 0x401 -> 0xd!
Quoted 3 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.

Quoted 22 lines
Quoted 3 lines

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 2 lines

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 7 lines
Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Quoted 17 lines

Thanks and Regards,Arnaud

Quoted 15 lines

Thanks,
Beleswar

Quoted 11 lines

Regards,
Arnaud

Quoted 7 lines
Quoted 7 lines

2. namespace/channel#2 = rpmsg-i2c

       a. ept1 -> i2c@1
       b. ept2 -> i2c@2
       c. ept3 -> i2c@3

etc...

Just want to clear-up few terms before I jump to the solution:

**RPMsg channel/device**:
- These are devices announced by the remote processor, and created by
linux. They are created at: /sys/bus/rpmsg/devices
- The channel format: <name>.<src ept>.<dst ept>

**RPMsg endpoint**:
- Endpoint is differnt than channel. Single channel can have multiple
endpoints, and represented in the linux with: /dev/rpmsg? devices.

To create endpoint device, we have rpmsg_create_ept API, which takes channel information as input, which has src-ept, dst-ept.

Following is proposed solution:

1) Assign RPMsg channel/device per rpmsg-gpio controller (Not per GPIO pin/port).
- In our case that would be, single rpmsg-io node. (That makes me
question if bindings are correct or not).

2) Assign GPIO number as src ept.

i.e. *rpmsg-io.<GPIO number>.<dst ept>*. Do not randomly assign src endpoint.

Now, RPMSG channel by spec reserves first 1024 endpoints [1], so we can add 1024 offset to the GPIO number:

Quoted 8 lines

so, when calling rpmsg_create_ept() API, we assing src_endpoint as:
(GPIO_NUMBER + RPMSG_RESERVED_ADDRESSES)

Now on the remote side, there is single channel and only single-endpoint is needed that is mapped to the rpmsg-io channel callback.

That callback will receive all the payloads from the Linux, which will have src-ept i.e. (RPMSG_RESERVED_ADDRESSES + GPIO_NUMBER).

Interesting approach. I also tried to find a similar solution.

The question here is: how can we guarantee continuous addresses? Given the static and dynamic allocation of endpoint addresses that are implemented, my conclusion was that it is not reliable enough.

but perhaps I missed something...

Quoted 56 lines

It can retrieve GPIO_NUMBER easily, and convert to appropriate pin based on platform specific logic.

This doesn't need PORT information at all. Also it makes sure that remote is using only single-endpoint so not much memory is used.

*Example*:
If only rpmsg-gpio channel is created by the remote side, than following is the representation of the devices when GPIO 25, 26, 27 is assigned to the rpmsg-io controller:

Linux Remote

rpmsg-channel: rpmsg-gpio.0x400.0x400

/dev/rpmsg0 - GPIO25 ept (rpmsg-gpio.0x419.0x400)-|

                                                   |
/dev/rpmsg1 - GPIO26 ept (rpmsg-gpio.0x41a.0x400)-|-> rpmsg-gpio.*.0x400
                                                   |

/dev/rpmsg2 - GPIO27 ept (rpmsg-gpio.0x41b.0x400)-| 0x400 ept callback.

*On remote side*:

ept_0x400_callback(..., int src_ept, ...,)

{
    int gpio_num = src_ept - RPMSG_RESERVED_ADDRESSES;
    // platform specific logic to convert gpio num to proper pin,
    // just like you would convert gpio num to pin on a linux gpio

controller.
}

My question on the binding:

Why each GPIO is represented with the separate node? I think rpmsg-gpio can be represented just any other GPIO controller? Please let me know if I am missing something. So rpmsg channel/rpmsg device is not created per GPIO, but per controller. GPIO number multiplexing should be done with rpmsg src ept, that removes the need of having each GPIO as a separate node.

rpmsg_gpio: rpmsg-gpio@0 {
        compatible = "rpmsg-gpio";
        reg = <0>;
        gpio-controller;
        #gpio-cells = <2>;
        #interrupt-cells = <2>;
        interrupt-controller;
    };

Then in DT, use like regular GPIO, but with the rpmsg-gpio controller:

rpmsg-gpios = <&rpmsg_gpio (GPIO NUM) (flags)>;

Quoted 8 lines

If the intent to create separate gpio nodes was only for the channel creation, then it's not really needed.

[1]
https://github.com/torvalds/linux/
blob/6d35786de28116ecf78797a62b84e6bf3c45aa5a/drivers/rpmsg/ virtio_rpmsg_bus.c#L136

Quoted 9 lines

It is already the case. bindings declare GPIO controllers, not directly GPIOs in:

[PATCH v13 2/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support

The discussion is around having an unique RPmsg endpoint for all GPIO controller or one RPmsg endpoint per GPIO controller.

Endpoint where remote side or linux side?

If unique endpoint on remote side per gpio controller then it makes sense.

Unique endpoint on linux side doesn't make sense. Instead, unique channel per gpio controller makes sense, and each channel will have multiple endpoints on linux side. As I replied to Beleswar on the other email, I will copy past my answer here too:

To be more specific:

Linux: remote:

ch1: rpmsg-gpio.-1.1024 -> gpio-controller@1024
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1024.
- gpio-line ept3

Quoted 5 lines

ch2: rpmsg-gpio.-1.1025 -> gpio-controller@1025
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1025.
- gpio-line ept3

Hi Mathieu,

So upon more brain storming in this approach I found limitation:

Quoted 8 lines

This approach won't work if host OS is any other OS but Linux. For example, if the remote OS is zephyr/baremetal using open-amp, then Only Linux <-> zephyr combination will work, and we won't be able to re-use this approach for zephyr <-> zephyr use case. The concept of rpmsg channel/device exist only in the linux kernel implementation. This brings another question: Should the protocol we decide work on other use cases as well? Or Linux must be the Host OS for this protocol ?

Linux and Zephyr are very distinct OS, each with their own subsystems and characteristics. The design we choose here involves RPMSG and, inherently, Linux. We can't make decisions based on what may potentially happen in Zephyr.

Quoted 5 lines

I think your & Arnaud's proposed approach of single endpoint per gpio-controller on both side makes more sense, as it will work regardless of any OS on host or remote side.

Quoted 8 lines
Quoted 6 lines

Arnaud, Beleswar, Andrew and I are all advocating for one endpoint per GPIO controller. The remaining issue it about the best way to work out source and destination addresses between Linux and the remote processor. I'm running out of time for today but I'll return to this thread with a final analysis by the end of the week.

Okay. Then that means multiple endpoints on Linux side can be considered.

If there are multiple GPIO controllers then yes, there will be more than one endpoint. At this time I do now want to condiser other bus architectures (i2c, spi, ...) to avoid muddying an already difficult conversation.

Quoted 1 line
Quoted 5 lines
Quoted 2 lines

If we decide to go single-endpoint per device on both side, then for that here is the proposal to represent src ept and dst ept:

I do not understand what you mean by "per device" - please be more specific.

"per device" I mean, per rpmsg device/channel. In our case that would be per gpio-controller.

Quoted 9 lines
Quoted 4 lines

When we represent any device under rpmsg bus node, I think it should be considered remote's view of the adddress space. So ideally we can convert it to Linux view of the address space, via 'ranges' property.

There is no address space to consider since there is no GPIO controller memory space to access. All that is done by the driver (remote processor) and completely hidden from Linux by rpmsg-virtio-gpio.

So IMHO the dt-binding is the representation of the device hardware and is independent of how driver will access it. Any gpio-controller device node, we are just representing how gpio-controller hardware on the remote side looks like, and what is the corresponding view of the linux is.

The rpmsg-gpio driver is different than the platform gpio controller driver mainly in two ways:

1) How the driver is probed: rpmsg-gpio driver will be probed when corresponding rpmsg channel/device name-service announcment will happen from the remote side.

2) The GPIO Ops are not performed on the hardware directly, but it's done via rpmsg commands on the remote side.

However, the GPIO controller hardware remains the same. So bindings shoudln't change.

IMHO That means, if I want to move any existing GPIO-controller to the remote side, and want the rpmsg-gpio driver to handle it then, all I need to change is the compatible string of the current gpio-controller device node. The rest of the address space should remain the same, and leave ranges property empty. If the remote core has different view of the address space, then the device should contain remote's view and parent bus (rpmsg-io bus) should provide linux view via 'ranges' property.

That is just the device hw representation in the device-tree as rpmsg device. Same for any other type of the controller: i2c, spi etc.

Thanks,
Tanmay

Quoted 185 lines
Quoted 185 lines

So bindings should include 'ranges' property in the parent node. Then linux view of the start address becomes src ept, and remote view of the start address becomes dest ept. The remote view of the start address is expected to be the static src endpoint on the remote side.

Following representation of the rpmsg devices (gpio, i2c, spi or any other):

rpmsg {
#address-cells = <1>;
#size-cells = <1>;

  rpmsg-io {
    compatible = "rpmsg-io-bus";
    ranges = <remote_view_addr(dst ept) linux_view_addr(src ept) size>;
    #address-cells = <1>;
    #size-cells = <1>;
    gpio@remote_view_addr(or dst ept) {
      compatible = "rpmsg-io";
      reg = <remote_view_addr addr_space_size>;
      gpio-controller;
      #gpio-cells = <2>;
      interrupt-controller;
      #interrupt-cells = <2>;
    };

    ...
  };

};

Example device-tree:

rpmsg {
#address-cells = <1>;
#size-cells = <1>;

  rpmsg-io {
    compatible = "rpmsg-io-bus";
    ranges = <0x10000 0x50000 0x1000>,
             <0x20000 0x60000 0x1000>;
    #address-cells = <1>;
    #size-cells = <1>;
    gpio@10000 {
      compatible = "rpmsg-io";
      reg = <0x10000 0x1000>;
      gpio-controller;
      #gpio-cells = <2>;
      interrupt-controller;
      #interrupt-cells = <2>;
    };

    gpio@20000 {
      compatible = "rpmsg-io";
      reg = <0x20000 0x1000>;
      gpio-controller;
      #gpio-cells = <2>;
      interrupt-controller;
      #interrupt-cells = <2>;
    };
  };

};

Thanks,
Tanmay

Quoted 111 lines
Quoted 111 lines

To be more specific this will look like following:

Host (Linux) Remote (baremetal/RTOS)

rpmsg ch/device 1:
- rpmsg ept 1 <------> rpmsg ept 1 gpio-controller 0

rpmsg ch/device 2:
- rpmsg ept 2 <------> rpmsg ept 2 gpio-controller 1

The question is, how to decide src ept, and dest ept on both sides? I still think it should be static endpoints.

I will get back with more reasoning on that.

Quoted 94 lines

On the remote side, we have to hardcode Which rpmsg controller is mapped to which endpoint.

Quoted 5 lines

Or did I misunderstand your questions?

Thanks,
Arnaud

I gave this patch more time yesterday, and I think the 'reg' property should represent remote endpoint, instead of the gpio-controller index.

So in this approach remote implementation is expected to provide hard-coded (static) endpoints for each gpio-controller instance, and that same number should be represented with the 'reg' property.

On remote side:

#define RPMSG_GPIO_0_CONTROLLER_EPT (RPMSG_RESERVED_ADDRESSES + 1) // 1024

ept_1024_callback() {

      // handle appropriate gpio port ()

}

On linux side:

So new representation of controller:

 rpmsg_gpio_0:   gpio@1024 {
             compatible = "rpmsg-gpio";
             reg = <1024>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };
 rpmsg_gpio_1:   gpio@1025 {
             compatible = "rpmsg-gpio";
             reg = <1025>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };

gpios = <&rpmsg_gpio_0 (GPIO NUM or PIN) flags>,

      <&rpmsg_gpio_1 (GPIO NUM or PIN) flags>;

Now in the linux driver:

You can easily retrieve destination endpoint when we want to send the command to the gpio controller via device's "reg" property.

This approach also provides built-in security as well. Because now gpio-controller instance is hardcoded with the endpoint callback, it can't be modified/addressed without changing the 'reg' property.

Just like you wouldn't change device address for the instance of the gpio-controller right?

This approach can be easily adapted to all the other rpmsg controllers as well.

So, dynamic endpoint allocation doesn't make sense in this case. Dynamic endpoint allocation makes more sense for user-space apps which don't really care about endpoints and only payloads.

But, here we are multiplexing device-addresses with endpoints, and so it has to be fixed, and presented via 'reg' property. So, firmware can't change device-address without Linux knowing it.

Thanks,
Tanmay

Quoted 14 lines
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

maintainer
#45 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 568 lines · Tanmay
Quoted 540 lines · Mathieu Poirier
Quoted 525 lines · Tanmay
Quoted 522 lines · Mathieu Poirier
Quoted 501 lines · Tanmay
Quoted 486 lines · Tanmay
Quoted 454 lines · Arnaud POULIQUEN

Hi Tanmay,

Quoted 155 lines · Tanmay

Hello all,

I have started reviewing this work as well.
Thanks Shenwei for this work.

I have gone through only the current revision, and would like to provide idea on how to achieve GPIO number multiplexing with the RPMsg protocol. Also, have some bindings related question.

Please see below:

Quoted 135 lines · Arnaud POULIQUEN
Quoted 132 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 129 lines · Arnaud POULIQUEN

Hello,

Quoted 126 lines · Mathieu Poirier
Quoted 121 lines · Beleswar

Hi Mathieu,

On 4/29/2026 11:03 PM, Mathieu Poirier wrote:
On Wed, 29 Apr 2026 at 10:53, Shenwei Wang <[email protected]>
wrote:

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <b-
[email protected]>; Linus
Walleij <[email protected]>; Bartosz Golaszewski
<[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>;
Krzysztof Kozlowski
<[email protected]>; Conor Dooley <[email protected]>; Bjorn
Andersson
<[email protected]>; Frank Li <[email protected]>; Sascha Hauer
<[email protected]>; Shuah Khan
<[email protected]>; linux-
[email protected]; [email protected]; linux-
[email protected];
Pengutronix Kernel Team <[email protected]>; Fabio Estevam
<[email protected]>; Peng Fan <[email protected]>;
[email protected]; [email protected];
[email protected]; [email protected]; dl-
linux-imx <linux-
[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic
rpmsg GPIO driver
On Tue, Apr 28, 2026 at 03:24:59PM +0000, Shenwei Wang wrote:

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij
<[email protected]>; Bartosz Golaszewski <[email protected]>;
Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>;
Krzysztof
Kozlowski <[email protected]>; Conor Dooley
<[email protected]>;
Bjorn Andersson <[email protected]>; Mathieu Poirier
<[email protected]>; Frank Li <[email protected]>;
Sascha
Hauer <[email protected]>; Shuah Khan
<[email protected]>; [email protected]; linux-
[email protected]; [email protected]; Pengutronix
Kernel Team <[email protected]>; Fabio Estevam
<[email protected]>; Peng Fan <[email protected]>;
[email protected]; linux- [email protected];
[email protected]; linux-arm- [email protected];
dl-linux-imx <[email protected]>; Bartosz Golaszewski
<[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic
rpmsg
GPIO driver
struct virtio_gpio_response {
__u8 status;
__u8 value;
};
It is the same message format. Please see the message
definition
(GET_DIRECTION) below:

+ +-----+-----+-----+-----+-----+----+
+ |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+ | 1 | 2 |port |line | err | dir|
+ +-----+-----+-----+-----+-----+----+
Sorry, but i don't see how two u8 vs six u8 are the same
message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for
requests and
replies, and a second one for events.
In contrast, rpmsg provides only a single communication
channel, so a
type field is required to distinguish between different kinds
of messages.

Since rpmsg replies and events share the same message format,
an additional
line is introduced to handle both cases.
Finally, rpmsg supports multiple GPIO controllers, so a port
field is added to
uniquely identify the target controller.

I have commented on this before - RPMSG is already providing
multiplexing
capability by way of endpoints. There is no need for a port
field. One endpoint,
one GPIO controller.

You still need a way to let the remote side know which port the
endpoint maps to, either
by embedding the port information in the message (the current
way), or by sending it
separately.

An endpoint is created with every namespace request. There
should be
one namespace request for every GPIO controller, which yields a
unique
endpoint for each controller and eliminates the need for an extra
field to identify them.

Right, but this can still be done by just having one namespace
request.
We can create new endpoints bound to an existing namespace/
channel by
invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/29485742-6e49-482e-
[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io
a. ept1 -> gpio-controller@1
b. ept2 -> gpio-controller@2

Quoted 6 lines

If my understanding of what gpio-controller is right, than this won't work. We need one rpmsg channel per gpio-controller, and in most cases there will be only one GPIO-controller on the remote side. If there are multiple or multiple instances of same controller, than we need separate channel name for that controller just like we would have separate device on the Linux.

As done in ehe rpmsg_tty driver it could be instantiated several times with the same channel/service name. This would imply a specific rpmsg to retreive
the gpio controller index from the remote side.

Quoted 75 lines
Quoted 71 lines
Quoted 28 lines
Quoted 13 lines
Quoted 12 lines

I've asked for one endpoint per GPIO controller since the very beginning. I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints. I'll have to look at your link and reflect on
that. Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level. This is
the only way this work can move forward.

Quoted 6 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this
Linux need not have the port field in the message everytime its sending a message.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

With a multi-namespace approach, the namespace could be rpmsg-io- [addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here
my sentence should be;
With a multi-namespace approach, the namespace could be rpmsg-io-
[port],
where [port] corresponds to the GPIO controller port in the DT.

For instance:

       rpmsg {
         rpmsg-io {
           #address-cells = <1>;
           #size-cells = <0>;

           gpio@25 {
             compatible = "rpmsg-gpio";
             reg = <25>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };

           gpio@32 {
             compatible = "rpmsg-gpio";
             reg = <32>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };
         };
       };
Quoted 3 lines

rpmsg-io-25 would match with gpio@25
rpmsg-io-32 would match with gpio@32

Quoted 5 lines

The problem with this approach is, we will endup creating way too many RPMsg devices/channels. i.e. one channel per one GPIO. That limits how many GPIOs can be handled by remote from memory perspective. At somepoint we might just run-out of number ept & channels created by the remote. As of now, open-amp library supports 128 epts I think.

Right, I proposed a solution in my previous answer to Beleswar who has the same concern.

Quoted 118 lines
Quoted 71 lines
Quoted 23 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel
ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev
addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel
formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13:
new channel: 0x401 -> 0xd!
Quoted 3 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.

Quoted 22 lines
Quoted 3 lines

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 2 lines

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 7 lines
Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Quoted 17 lines

Thanks and Regards,Arnaud

Quoted 15 lines

Thanks,
Beleswar

Quoted 11 lines

Regards,
Arnaud

Quoted 7 lines
Quoted 7 lines

2. namespace/channel#2 = rpmsg-i2c
a. ept1 -> i2c@1
b. ept2 -> i2c@2
c. ept3 -> i2c@3

etc...

Just want to clear-up few terms before I jump to the solution:

**RPMsg channel/device**:
- These are devices announced by the remote processor, and created by
linux. They are created at: /sys/bus/rpmsg/devices
- The channel format: <name>.<src ept>.<dst ept>

**RPMsg endpoint**:
- Endpoint is differnt than channel. Single channel can have multiple
endpoints, and represented in the linux with: /dev/rpmsg? devices.

To create endpoint device, we have rpmsg_create_ept API, which takes channel information as input, which has src-ept, dst-ept.

Following is proposed solution:

1) Assign RPMsg channel/device per rpmsg-gpio controller (Not per GPIO pin/port).
- In our case that would be, single rpmsg-io node. (That makes me
question if bindings are correct or not).

2) Assign GPIO number as src ept.

i.e. *rpmsg-io.<GPIO number>.<dst ept>*. Do not randomly assign src endpoint.

Now, RPMSG channel by spec reserves first 1024 endpoints [1], so we can add 1024 offset to the GPIO number:

Quoted 8 lines

so, when calling rpmsg_create_ept() API, we assing src_endpoint as:
(GPIO_NUMBER + RPMSG_RESERVED_ADDRESSES)

Now on the remote side, there is single channel and only single-endpoint is needed that is mapped to the rpmsg-io channel callback.

That callback will receive all the payloads from the Linux, which will have src-ept i.e. (RPMSG_RESERVED_ADDRESSES + GPIO_NUMBER).

Interesting approach. I also tried to find a similar solution.

The question here is: how can we guarantee continuous addresses? Given the static and dynamic allocation of endpoint addresses that are implemented, my conclusion was that it is not reliable enough.

but perhaps I missed something...

Quoted 56 lines

It can retrieve GPIO_NUMBER easily, and convert to appropriate pin based on platform specific logic.

This doesn't need PORT information at all. Also it makes sure that remote is using only single-endpoint so not much memory is used.

*Example*:
If only rpmsg-gpio channel is created by the remote side, than following is the representation of the devices when GPIO 25, 26, 27 is assigned to the rpmsg-io controller:

Linux Remote

rpmsg-channel: rpmsg-gpio.0x400.0x400

/dev/rpmsg0 - GPIO25 ept (rpmsg-gpio.0x419.0x400)-|

                                                   |
/dev/rpmsg1 - GPIO26 ept (rpmsg-gpio.0x41a.0x400)-|-> rpmsg-gpio.*.0x400
                                                   |

/dev/rpmsg2 - GPIO27 ept (rpmsg-gpio.0x41b.0x400)-| 0x400 ept callback.

*On remote side*:

ept_0x400_callback(..., int src_ept, ...,)

{
    int gpio_num = src_ept - RPMSG_RESERVED_ADDRESSES;
    // platform specific logic to convert gpio num to proper pin,
    // just like you would convert gpio num to pin on a linux gpio

controller.
}

My question on the binding:

Why each GPIO is represented with the separate node? I think rpmsg-gpio can be represented just any other GPIO controller? Please let me know if I am missing something. So rpmsg channel/rpmsg device is not created per GPIO, but per controller. GPIO number multiplexing should be done with rpmsg src ept, that removes the need of having each GPIO as a separate node.

rpmsg_gpio: rpmsg-gpio@0 {
        compatible = "rpmsg-gpio";
        reg = <0>;
        gpio-controller;
        #gpio-cells = <2>;
        #interrupt-cells = <2>;
        interrupt-controller;
    };

Then in DT, use like regular GPIO, but with the rpmsg-gpio controller:

rpmsg-gpios = <&rpmsg_gpio (GPIO NUM) (flags)>;

Quoted 8 lines

If the intent to create separate gpio nodes was only for the channel creation, then it's not really needed.

[1]
https://github.com/torvalds/linux/
blob/6d35786de28116ecf78797a62b84e6bf3c45aa5a/drivers/rpmsg/ virtio_rpmsg_bus.c#L136

Quoted 9 lines

It is already the case. bindings declare GPIO controllers, not directly GPIOs in:

[PATCH v13 2/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support

The discussion is around having an unique RPmsg endpoint for all GPIO controller or one RPmsg endpoint per GPIO controller.

Endpoint where remote side or linux side?

If unique endpoint on remote side per gpio controller then it makes sense.

Unique endpoint on linux side doesn't make sense. Instead, unique channel per gpio controller makes sense, and each channel will have multiple endpoints on linux side. As I replied to Beleswar on the other email, I will copy past my answer here too:

To be more specific:

Linux: remote:

ch1: rpmsg-gpio.-1.1024 -> gpio-controller@1024
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1024.
- gpio-line ept3

Quoted 5 lines

ch2: rpmsg-gpio.-1.1025 -> gpio-controller@1025
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1025.
- gpio-line ept3

Hi Mathieu,

So upon more brain storming in this approach I found limitation:

Quoted 8 lines

This approach won't work if host OS is any other OS but Linux. For example, if the remote OS is zephyr/baremetal using open-amp, then Only Linux <-> zephyr combination will work, and we won't be able to re-use this approach for zephyr <-> zephyr use case. The concept of rpmsg channel/device exist only in the linux kernel implementation. This brings another question: Should the protocol we decide work on other use cases as well? Or Linux must be the Host OS for this protocol ?

Linux and Zephyr are very distinct OS, each with their own subsystems and characteristics. The design we choose here involves RPMSG and, inherently, Linux. We can't make decisions based on what may potentially happen in Zephyr.

Quoted 5 lines

I think your & Arnaud's proposed approach of single endpoint per gpio-controller on both side makes more sense, as it will work regardless of any OS on host or remote side.

Quoted 8 lines
Quoted 6 lines

Arnaud, Beleswar, Andrew and I are all advocating for one endpoint per GPIO controller. The remaining issue it about the best way to work out source and destination addresses between Linux and the remote processor. I'm running out of time for today but I'll return to this thread with a final analysis by the end of the week.

Okay. Then that means multiple endpoints on Linux side can be considered.

If there are multiple GPIO controllers then yes, there will be more than one endpoint. At this time I do now want to condiser other bus architectures (i2c, spi, ...) to avoid muddying an already difficult conversation.

Quoted 1 line
Quoted 5 lines
Quoted 2 lines

If we decide to go single-endpoint per device on both side, then for that here is the proposal to represent src ept and dst ept:

I do not understand what you mean by "per device" - please be more specific.

"per device" I mean, per rpmsg device/channel. In our case that would be per gpio-controller.

Quoted 9 lines
Quoted 4 lines

When we represent any device under rpmsg bus node, I think it should be considered remote's view of the adddress space. So ideally we can convert it to Linux view of the address space, via 'ranges' property.

There is no address space to consider since there is no GPIO controller memory space to access. All that is done by the driver (remote processor) and completely hidden from Linux by rpmsg-virtio-gpio.

So IMHO the dt-binding is the representation of the device hardware and is independent of how driver will access it. Any gpio-controller device node, we are just representing how gpio-controller hardware on the remote side looks like, and what is the corresponding view of the linux is.

Quoted 7 lines

The rpmsg-gpio driver is different than the platform gpio controller driver mainly in two ways:

1) How the driver is probed: rpmsg-gpio driver will be probed when corresponding rpmsg channel/device name-service announcment will happen from the remote side.

I agree.

Quoted 3 lines

2) The GPIO Ops are not performed on the hardware directly, but it's done via rpmsg commands on the remote side.

I agree.

Quoted 3 lines

However, the GPIO controller hardware remains the same. So bindings shoudln't change.

That is where I have a different point of view. There is no need to have information in the bindings the kernel won't use. We are advertizing virtio-gpio devices and as such should use virtio-gpio bindings. The only thing that changes is the transport method, i.e, encapsulated in RPMSG rather than directly over virtqueues.

Quoted 201 lines

IMHO That means, if I want to move any existing GPIO-controller to the remote side, and want the rpmsg-gpio driver to handle it then, all I need to change is the compatible string of the current gpio-controller device node. The rest of the address space should remain the same, and leave ranges property empty. If the remote core has different view of the address space, then the device should contain remote's view and parent bus (rpmsg-io bus) should provide linux view via 'ranges' property.

That is just the device hw representation in the device-tree as rpmsg device. Same for any other type of the controller: i2c, spi etc.

Thanks,
Tanmay

Quoted 185 lines
Quoted 185 lines

So bindings should include 'ranges' property in the parent node. Then linux view of the start address becomes src ept, and remote view of the start address becomes dest ept. The remote view of the start address is expected to be the static src endpoint on the remote side.

Following representation of the rpmsg devices (gpio, i2c, spi or any other):

rpmsg {
#address-cells = <1>;
#size-cells = <1>;

  rpmsg-io {
    compatible = "rpmsg-io-bus";
    ranges = <remote_view_addr(dst ept) linux_view_addr(src ept) size>;
    #address-cells = <1>;
    #size-cells = <1>;
    gpio@remote_view_addr(or dst ept) {
      compatible = "rpmsg-io";
      reg = <remote_view_addr addr_space_size>;
      gpio-controller;
      #gpio-cells = <2>;
      interrupt-controller;
      #interrupt-cells = <2>;
    };

    ...
  };

};

Example device-tree:

rpmsg {
#address-cells = <1>;
#size-cells = <1>;

  rpmsg-io {
    compatible = "rpmsg-io-bus";
    ranges = <0x10000 0x50000 0x1000>,
             <0x20000 0x60000 0x1000>;
    #address-cells = <1>;
    #size-cells = <1>;
    gpio@10000 {
      compatible = "rpmsg-io";
      reg = <0x10000 0x1000>;
      gpio-controller;
      #gpio-cells = <2>;
      interrupt-controller;
      #interrupt-cells = <2>;
    };

    gpio@20000 {
      compatible = "rpmsg-io";
      reg = <0x20000 0x1000>;
      gpio-controller;
      #gpio-cells = <2>;
      interrupt-controller;
      #interrupt-cells = <2>;
    };
  };

};

Thanks,
Tanmay

Quoted 111 lines
Quoted 111 lines

To be more specific this will look like following:

Host (Linux) Remote (baremetal/RTOS)

rpmsg ch/device 1:
- rpmsg ept 1 <------> rpmsg ept 1 gpio-controller 0

rpmsg ch/device 2:
- rpmsg ept 2 <------> rpmsg ept 2 gpio-controller 1

The question is, how to decide src ept, and dest ept on both sides? I still think it should be static endpoints.

I will get back with more reasoning on that.

Quoted 94 lines

On the remote side, we have to hardcode Which rpmsg controller is mapped to which endpoint.

Quoted 5 lines

Or did I misunderstand your questions?

Thanks,
Arnaud

I gave this patch more time yesterday, and I think the 'reg' property should represent remote endpoint, instead of the gpio-controller index.

So in this approach remote implementation is expected to provide hard-coded (static) endpoints for each gpio-controller instance, and that same number should be represented with the 'reg' property.

On remote side:

#define RPMSG_GPIO_0_CONTROLLER_EPT (RPMSG_RESERVED_ADDRESSES + 1) // 1024

ept_1024_callback() {

      // handle appropriate gpio port ()

}

On linux side:

So new representation of controller:

 rpmsg_gpio_0:   gpio@1024 {
             compatible = "rpmsg-gpio";
             reg = <1024>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };
 rpmsg_gpio_1:   gpio@1025 {
             compatible = "rpmsg-gpio";
             reg = <1025>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };

gpios = <&rpmsg_gpio_0 (GPIO NUM or PIN) flags>,

      <&rpmsg_gpio_1 (GPIO NUM or PIN) flags>;

Now in the linux driver:

You can easily retrieve destination endpoint when we want to send the command to the gpio controller via device's "reg" property.

This approach also provides built-in security as well. Because now gpio-controller instance is hardcoded with the endpoint callback, it can't be modified/addressed without changing the 'reg' property.

Just like you wouldn't change device address for the instance of the gpio-controller right?

This approach can be easily adapted to all the other rpmsg controllers as well.

So, dynamic endpoint allocation doesn't make sense in this case. Dynamic endpoint allocation makes more sense for user-space apps which don't really care about endpoints and only payloads.

But, here we are multiplexing device-addresses with endpoints, and so it has to be fixed, and presented via 'reg' property. So, firmware can't change device-address without Linux knowing it.

Thanks,
Tanmay

Quoted 14 lines
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 8 lines

This way device groups are isolated with each channel/namespace, and
instances within each device groups are also respected with specific
endpoints.

Thanks,
Beleswar

#46 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 589 lines · Mathieu Poirier
Quoted 568 lines · Tanmay
Quoted 540 lines · Mathieu Poirier
Quoted 525 lines · Tanmay
Quoted 522 lines · Mathieu Poirier
Quoted 501 lines · Tanmay
Quoted 486 lines · Tanmay
Quoted 454 lines · Arnaud POULIQUEN

Hi Tanmay,

Quoted 155 lines · Tanmay

Hello all,

I have started reviewing this work as well.
Thanks Shenwei for this work.

I have gone through only the current revision, and would like to provide idea on how to achieve GPIO number multiplexing with the RPMsg protocol. Also, have some bindings related question.

Please see below:

Quoted 135 lines · Arnaud POULIQUEN
Quoted 132 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 129 lines · Arnaud POULIQUEN

Hello,

Quoted 126 lines · Mathieu Poirier

On Wed, 29 Apr 2026 at 12:07, Padhi, Beleswar <[email protected]> wrote:

Hi Mathieu,

On 4/29/2026 11:03 PM, Mathieu Poirier wrote:
On Wed, 29 Apr 2026 at 10:53, Shenwei Wang <[email protected]>
wrote:

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <b-
[email protected]>; Linus
Walleij <[email protected]>; Bartosz Golaszewski
<[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>;
Krzysztof Kozlowski
<[email protected]>; Conor Dooley <[email protected]>; Bjorn
Andersson
<[email protected]>; Frank Li <[email protected]>; Sascha Hauer
<[email protected]>; Shuah Khan
<[email protected]>; linux-
[email protected]; [email protected]; linux-
[email protected];
Pengutronix Kernel Team <[email protected]>; Fabio Estevam
<[email protected]>; Peng Fan <[email protected]>;
[email protected]; [email protected];
[email protected]; [email protected]; dl-
linux-imx <linux-
[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic
rpmsg GPIO driver
On Tue, Apr 28, 2026 at 03:24:59PM +0000, Shenwei Wang wrote:

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij
<[email protected]>; Bartosz Golaszewski <[email protected]>;
Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>;
Krzysztof
Kozlowski <[email protected]>; Conor Dooley
<[email protected]>;
Bjorn Andersson <[email protected]>; Mathieu Poirier
<[email protected]>; Frank Li <[email protected]>;
Sascha
Hauer <[email protected]>; Shuah Khan
<[email protected]>; [email protected]; linux-
[email protected]; [email protected]; Pengutronix
Kernel Team <[email protected]>; Fabio Estevam
<[email protected]>; Peng Fan <[email protected]>;
[email protected]; linux- [email protected];
[email protected]; linux-arm- [email protected];
dl-linux-imx <[email protected]>; Bartosz Golaszewski
<[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic
rpmsg
GPIO driver
struct virtio_gpio_response {
__u8 status;
__u8 value;
};
It is the same message format. Please see the message
definition
(GET_DIRECTION) below:

+ +-----+-----+-----+-----+-----+----+
+ |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+ | 1 | 2 |port |line | err | dir|
+ +-----+-----+-----+-----+-----+----+
Sorry, but i don't see how two u8 vs six u8 are the same
message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for
requests and
replies, and a second one for events.
In contrast, rpmsg provides only a single communication
channel, so a
type field is required to distinguish between different kinds
of messages.

Since rpmsg replies and events share the same message format,
an additional
line is introduced to handle both cases.
Finally, rpmsg supports multiple GPIO controllers, so a port
field is added to
uniquely identify the target controller.

I have commented on this before - RPMSG is already providing
multiplexing
capability by way of endpoints. There is no need for a port
field. One endpoint,
one GPIO controller.

You still need a way to let the remote side know which port the
endpoint maps to, either
by embedding the port information in the message (the current
way), or by sending it
separately.

An endpoint is created with every namespace request. There
should be
one namespace request for every GPIO controller, which yields a
unique
endpoint for each controller and eliminates the need for an extra
field to identify them.

Right, but this can still be done by just having one namespace
request.
We can create new endpoints bound to an existing namespace/
channel by
invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/29485742-6e49-482e-
[email protected]/

I will look at your suggestion (i.e link above) later this week or
next week.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io
a. ept1 -> gpio-controller@1
b. ept2 -> gpio-controller@2

Quoted 6 lines

If my understanding of what gpio-controller is right, than this won't work. We need one rpmsg channel per gpio-controller, and in most cases there will be only one GPIO-controller on the remote side. If there are multiple or multiple instances of same controller, than we need separate channel name for that controller just like we would have separate device on the Linux.

As done in ehe rpmsg_tty driver it could be instantiated several times with the same channel/service name. This would imply a specific rpmsg to retreive
the gpio controller index from the remote side.

Quoted 75 lines
Quoted 71 lines
Quoted 28 lines
Quoted 13 lines
Quoted 12 lines

I've asked for one endpoint per GPIO controller since the very
beginning. I don't yet have a strong opinion on whether to use one
namespace request per GPIO controller or a single request that spins
off multiple endpoints. I'll have to look at your link and
reflect on
that. Regardless of how we proceed on that front, multiplexing needs
to happen at the endpoint level rather than the packet level.
This is
the only way this work can move forward.

Quoted 6 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this
Linux need not have the port field in the message everytime its sending a message.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

With a multi-namespace approach, the namespace could be rpmsg-io- [addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here
my sentence should be;
With a multi-namespace approach, the namespace could be rpmsg-io-
[port],
where [port] corresponds to the GPIO controller port in the DT.

For instance:

       rpmsg {
         rpmsg-io {
           #address-cells = <1>;
           #size-cells = <0>;

           gpio@25 {
             compatible = "rpmsg-gpio";
             reg = <25>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };

           gpio@32 {
             compatible = "rpmsg-gpio";
             reg = <32>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
           };
         };
       };
Quoted 3 lines

rpmsg-io-25 would match with gpio@25
rpmsg-io-32 would match with gpio@32

Quoted 5 lines

The problem with this approach is, we will endup creating way too many RPMsg devices/channels. i.e. one channel per one GPIO. That limits how many GPIOs can be handled by remote from memory perspective. At somepoint we might just run-out of number ept & channels created by the remote. As of now, open-amp library supports 128 epts I think.

Right, I proposed a solution in my previous answer to Beleswar who has the same concern.

Quoted 118 lines
Quoted 71 lines
Quoted 23 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel
ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev
addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel
formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13:
new channel: 0x401 -> 0xd!
Quoted 3 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.

Quoted 22 lines
Quoted 3 lines

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 2 lines

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 7 lines
Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Quoted 17 lines

Thanks and Regards,Arnaud

Quoted 15 lines

Thanks,
Beleswar

Quoted 11 lines

Regards,
Arnaud

Quoted 7 lines

2. namespace/channel#2 = rpmsg-i2c
a. ept1 -> i2c@1
b. ept2 -> i2c@2
c. ept3 -> i2c@3

etc...

Just want to clear-up few terms before I jump to the solution:

**RPMsg channel/device**:
- These are devices announced by the remote processor, and created by
linux. They are created at: /sys/bus/rpmsg/devices
- The channel format: <name>.<src ept>.<dst ept>

**RPMsg endpoint**:
- Endpoint is differnt than channel. Single channel can have multiple
endpoints, and represented in the linux with: /dev/rpmsg? devices.

To create endpoint device, we have rpmsg_create_ept API, which takes channel information as input, which has src-ept, dst-ept.

Following is proposed solution:

1) Assign RPMsg channel/device per rpmsg-gpio controller (Not per GPIO pin/port).
- In our case that would be, single rpmsg-io node. (That makes me
question if bindings are correct or not).

2) Assign GPIO number as src ept.

i.e. *rpmsg-io.<GPIO number>.<dst ept>*. Do not randomly assign src endpoint.

Now, RPMSG channel by spec reserves first 1024 endpoints [1], so we can add 1024 offset to the GPIO number:

Quoted 8 lines

so, when calling rpmsg_create_ept() API, we assing src_endpoint as:
(GPIO_NUMBER + RPMSG_RESERVED_ADDRESSES)

Now on the remote side, there is single channel and only single-endpoint is needed that is mapped to the rpmsg-io channel callback.

That callback will receive all the payloads from the Linux, which will have src-ept i.e. (RPMSG_RESERVED_ADDRESSES + GPIO_NUMBER).

Interesting approach. I also tried to find a similar solution.

The question here is: how can we guarantee continuous addresses? Given the static and dynamic allocation of endpoint addresses that are implemented, my conclusion was that it is not reliable enough.

but perhaps I missed something...

Quoted 56 lines

It can retrieve GPIO_NUMBER easily, and convert to appropriate pin based on platform specific logic.

This doesn't need PORT information at all. Also it makes sure that remote is using only single-endpoint so not much memory is used.

*Example*:
If only rpmsg-gpio channel is created by the remote side, than following is the representation of the devices when GPIO 25, 26, 27 is assigned to the rpmsg-io controller:

Linux Remote

rpmsg-channel: rpmsg-gpio.0x400.0x400

/dev/rpmsg0 - GPIO25 ept (rpmsg-gpio.0x419.0x400)-|

                                                   |
/dev/rpmsg1 - GPIO26 ept (rpmsg-gpio.0x41a.0x400)-|-> rpmsg-gpio.*.0x400
                                                   |

/dev/rpmsg2 - GPIO27 ept (rpmsg-gpio.0x41b.0x400)-| 0x400 ept callback.

*On remote side*:

ept_0x400_callback(..., int src_ept, ...,)

{
    int gpio_num = src_ept - RPMSG_RESERVED_ADDRESSES;
    // platform specific logic to convert gpio num to proper pin,
    // just like you would convert gpio num to pin on a linux gpio

controller.
}

My question on the binding:

Why each GPIO is represented with the separate node? I think rpmsg-gpio can be represented just any other GPIO controller? Please let me know if I am missing something. So rpmsg channel/rpmsg device is not created per GPIO, but per controller. GPIO number multiplexing should be done with rpmsg src ept, that removes the need of having each GPIO as a separate node.

rpmsg_gpio: rpmsg-gpio@0 {
        compatible = "rpmsg-gpio";
        reg = <0>;
        gpio-controller;
        #gpio-cells = <2>;
        #interrupt-cells = <2>;
        interrupt-controller;
    };

Then in DT, use like regular GPIO, but with the rpmsg-gpio controller:

rpmsg-gpios = <&rpmsg_gpio (GPIO NUM) (flags)>;

Quoted 8 lines

If the intent to create separate gpio nodes was only for the channel creation, then it's not really needed.

[1]
https://github.com/torvalds/linux/
blob/6d35786de28116ecf78797a62b84e6bf3c45aa5a/drivers/rpmsg/ virtio_rpmsg_bus.c#L136

Quoted 9 lines

It is already the case. bindings declare GPIO controllers, not directly GPIOs in:

[PATCH v13 2/4] dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support

The discussion is around having an unique RPmsg endpoint for all GPIO controller or one RPmsg endpoint per GPIO controller.

Endpoint where remote side or linux side?

If unique endpoint on remote side per gpio controller then it makes sense.

Unique endpoint on linux side doesn't make sense. Instead, unique channel per gpio controller makes sense, and each channel will have multiple endpoints on linux side. As I replied to Beleswar on the other email, I will copy past my answer here too:

To be more specific:

Linux: remote:

ch1: rpmsg-gpio.-1.1024 -> gpio-controller@1024
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1024.
- gpio-line ept3

Quoted 5 lines

ch2: rpmsg-gpio.-1.1025 -> gpio-controller@1025
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1025.
- gpio-line ept3

Hi Mathieu,

So upon more brain storming in this approach I found limitation:

Quoted 8 lines

This approach won't work if host OS is any other OS but Linux. For example, if the remote OS is zephyr/baremetal using open-amp, then Only Linux <-> zephyr combination will work, and we won't be able to re-use this approach for zephyr <-> zephyr use case. The concept of rpmsg channel/device exist only in the linux kernel implementation. This brings another question: Should the protocol we decide work on other use cases as well? Or Linux must be the Host OS for this protocol ?

Linux and Zephyr are very distinct OS, each with their own subsystems and characteristics. The design we choose here involves RPMSG and, inherently, Linux. We can't make decisions based on what may potentially happen in Zephyr.

Quoted 5 lines

I think your & Arnaud's proposed approach of single endpoint per gpio-controller on both side makes more sense, as it will work regardless of any OS on host or remote side.

Quoted 8 lines
Quoted 6 lines

Arnaud, Beleswar, Andrew and I are all advocating for one endpoint per GPIO controller. The remaining issue it about the best way to work out source and destination addresses between Linux and the remote processor. I'm running out of time for today but I'll return to this thread with a final analysis by the end of the week.

Okay. Then that means multiple endpoints on Linux side can be considered.

If there are multiple GPIO controllers then yes, there will be more than one endpoint. At this time I do now want to condiser other bus architectures (i2c, spi, ...) to avoid muddying an already difficult conversation.

Quoted 1 line
Quoted 5 lines
Quoted 2 lines

If we decide to go single-endpoint per device on both side, then for that here is the proposal to represent src ept and dst ept:

I do not understand what you mean by "per device" - please be more specific.

"per device" I mean, per rpmsg device/channel. In our case that would be per gpio-controller.

Quoted 9 lines
Quoted 4 lines

When we represent any device under rpmsg bus node, I think it should be considered remote's view of the adddress space. So ideally we can convert it to Linux view of the address space, via 'ranges' property.

There is no address space to consider since there is no GPIO controller memory space to access. All that is done by the driver (remote processor) and completely hidden from Linux by rpmsg-virtio-gpio.

So IMHO the dt-binding is the representation of the device hardware and is independent of how driver will access it. Any gpio-controller device node, we are just representing how gpio-controller hardware on the remote side looks like, and what is the corresponding view of the linux is.

Quoted 7 lines

The rpmsg-gpio driver is different than the platform gpio controller driver mainly in two ways:

1) How the driver is probed: rpmsg-gpio driver will be probed when corresponding rpmsg channel/device name-service announcment will happen from the remote side.

I agree.

Quoted 3 lines

2) The GPIO Ops are not performed on the hardware directly, but it's done via rpmsg commands on the remote side.

I agree.

Quoted 3 lines

However, the GPIO controller hardware remains the same. So bindings shoudln't change.

Quoted 6 lines

That is where I have a different point of view. There is no need to have information in the bindings the kernel won't use. We are advertizing virtio-gpio devices and as such should use virtio-gpio bindings. The only thing that changes is the transport method, i.e, encapsulated in RPMSG rather than directly over virtqueues.

I do not have deep knowledge of virtio-gpio devices, but in the bindings example "virtio-gpio.yaml", there is 'reg' property available for virtio-mmio transport:
https://github.com/torvalds/linux/blob/1f63dd8ca0dc05a8272bb8155f643c691d29bb11/Documentation/devicetree/bindings/gpio/gpio-virtio.yaml#L47

Also, I am actually asking to use 'reg' property to retrieve endpoint information in the rpmsg-gpio driver. please see below:

Quoted 33 lines
Quoted 33 lines

IMHO That means, if I want to move any existing GPIO-controller to the remote side, and want the rpmsg-gpio driver to handle it then, all I need to change is the compatible string of the current gpio-controller device node. The rest of the address space should remain the same, and leave ranges property empty. If the remote core has different view of the address space, then the device should contain remote's view and parent bus (rpmsg-io bus) should provide linux view via 'ranges' property.

That is just the device hw representation in the device-tree as rpmsg device. Same for any other type of the controller: i2c, spi etc.

Thanks,
Tanmay

Quoted 18 lines
Quoted 18 lines

So bindings should include 'ranges' property in the parent node. Then linux view of the start address becomes src ept, and remote view of the start address becomes dest ept. The remote view of the start address is expected to be the static src endpoint on the remote side.

Following representation of the rpmsg devices (gpio, i2c, spi or any other):

rpmsg {
#address-cells = <1>;
#size-cells = <1>;

  rpmsg-io {
    compatible = "rpmsg-io-bus";
    ranges = <remote_view_addr(dst ept) linux_view_addr(src ept) size>;
    #address-cells = <1>;
    #size-cells = <1>;
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
    gpio@remote_view_addr(or dst ept) {
      compatible = "rpmsg-io";
      reg = <remote_view_addr addr_space_size>;
      gpio-controller;
      #gpio-cells = <2>;
      interrupt-controller;
      #interrupt-cells = <2>;
    };

If we have 'reg' property as explained in above example, then we can use remote view of the start address of the device as dest-endpoint, and linux view of the start address of device (gpio-controller in our case) as src ept.

We use 'reg' property like this:

/* Get remote view of the start addr of gpio-controller */ of_property_read_reg(dev_node, 0, &dest_ept, &size);

/* Get linux view of the start addr of gpio-controller */ of_address_to_resource(dev_node, 0, &res); src_ept = res.start;

When sending rpmsg command we can use above endpoint informations rpmsg_sendto() API.

Note that remote has already done name service announcement using dst-ept (i.e. remote's view of the start address of the gpio-controller) by this time.

Thanks,
Tanmay

Quoted 159 lines
Quoted 159 lines
Quoted 158 lines
Quoted 158 lines
    ...
  };

};

Example device-tree:

rpmsg {
#address-cells = <1>;
#size-cells = <1>;

  rpmsg-io {
    compatible = "rpmsg-io-bus";
    ranges = <0x10000 0x50000 0x1000>,
             <0x20000 0x60000 0x1000>;
    #address-cells = <1>;
    #size-cells = <1>;
    gpio@10000 {
      compatible = "rpmsg-io";
      reg = <0x10000 0x1000>;
      gpio-controller;
      #gpio-cells = <2>;
      interrupt-controller;
      #interrupt-cells = <2>;
    };

    gpio@20000 {
      compatible = "rpmsg-io";
      reg = <0x20000 0x1000>;
      gpio-controller;
      #gpio-cells = <2>;
      interrupt-controller;
      #interrupt-cells = <2>;
    };
  };

};

Thanks,
Tanmay

Quoted 111 lines
Quoted 111 lines

To be more specific this will look like following:

Host (Linux) Remote (baremetal/RTOS)

rpmsg ch/device 1:
- rpmsg ept 1 <------> rpmsg ept 1 gpio-controller 0

rpmsg ch/device 2:
- rpmsg ept 2 <------> rpmsg ept 2 gpio-controller 1

The question is, how to decide src ept, and dest ept on both sides? I still think it should be static endpoints.

I will get back with more reasoning on that.

Quoted 94 lines

On the remote side, we have to hardcode Which rpmsg controller is mapped to which endpoint.

Quoted 5 lines

Or did I misunderstand your questions?

Thanks,
Arnaud

I gave this patch more time yesterday, and I think the 'reg' property should represent remote endpoint, instead of the gpio-controller index.

So in this approach remote implementation is expected to provide hard-coded (static) endpoints for each gpio-controller instance, and that same number should be represented with the 'reg' property.

On remote side:

#define RPMSG_GPIO_0_CONTROLLER_EPT (RPMSG_RESERVED_ADDRESSES + 1) // 1024

ept_1024_callback() {

      // handle appropriate gpio port ()

}

On linux side:

So new representation of controller:

 rpmsg_gpio_0:   gpio@1024 {
             compatible = "rpmsg-gpio";
             reg = <1024>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };
 rpmsg_gpio_1:   gpio@1025 {
             compatible = "rpmsg-gpio";
             reg = <1025>;
             gpio-controller;
             #gpio-cells = <2>;
             #interrupt-cells = <2>;
             interrupt-controller;
          };

gpios = <&rpmsg_gpio_0 (GPIO NUM or PIN) flags>,

      <&rpmsg_gpio_1 (GPIO NUM or PIN) flags>;

Now in the linux driver:

You can easily retrieve destination endpoint when we want to send the command to the gpio controller via device's "reg" property.

This approach also provides built-in security as well. Because now gpio-controller instance is hardcoded with the endpoint callback, it can't be modified/addressed without changing the 'reg' property.

Just like you wouldn't change device address for the instance of the gpio-controller right?

This approach can be easily adapted to all the other rpmsg controllers as well.

So, dynamic endpoint allocation doesn't make sense in this case. Dynamic endpoint allocation makes more sense for user-space apps which don't really care about endpoints and only payloads.

But, here we are multiplexing device-addresses with endpoints, and so it has to be fixed, and presented via 'reg' property. So, firmware can't change device-address without Linux knowing it.

Thanks,
Tanmay

Quoted 14 lines
Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines

This way device groups are isolated with each channel/namespace, and
instances within each device groups are also respected with specific
endpoints.

Thanks,
Beleswar

#47 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

In reply to Shah, Tanmay

Hi Tanmay,

Quoted 137 lines · Tanmay

Hello all,

I have started reviewing this work as well.
Thanks Shenwei for this work.

I have gone through only the current revision, and would like to provide idea on how to achieve GPIO number multiplexing with the RPMsg protocol. Also, have some bindings related question.

Please see below:

Quoted 125 lines · Arnaud POULIQUEN
Quoted 123 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 120 lines · Arnaud POULIQUEN

Hello,

Quoted 117 lines · Mathieu Poirier
Quoted 104 lines · Beleswar

Hi Mathieu,

Quoted 95 lines · Mathieu Poirier
Quoted 87 lines · Shenwei Wang
Quoted 79 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <b- [email protected]>; Linus
Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski
<[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson
<[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected];
Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl- linux-imx <linux-
[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 34 lines · Shenwei Wang
Quoted 34 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>;
Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 5 lines
Quoted 4 lines

struct virtio_gpio_response {
           __u8 status;
           __u8 value;
};

It is the same message format. Please see the message definition

(GET_DIRECTION) below:

Quoted 4 lines

+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+

Quoted 7 lines
Quoted 3 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 7 lines

In contrast, rpmsg provides only a single communication channel, so a
type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 2 lines

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

Quoted 8 lines

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing
capability by way of endpoints.  There is no need for a port field.  One endpoint,
one GPIO controller.

Quoted 6 lines

You still need a way to let the remote side know which port the endpoint maps to, either
by embedding the port information in the message (the current way), or by sending it
separately.

Quoted 5 lines

An endpoint is created with every namespace request.  There should be one namespace request for every GPIO controller, which yields a unique
endpoint for each controller and eliminates the need for an extra field to identify them.

Quoted 7 lines

Right, but this can still be done by just having one namespace request.
We can create new endpoints bound to an existing namespace/channel by invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/29485742-6e49-482e-
[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 2 lines

My mental model looks like this for the complete picture:

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

1. namespace/channel#1 = rpmsg-io
      a. ept1 -> gpio-controller@1
      b. ept2 -> gpio-controller@2

If my understanding of what gpio-controller is right, than this won't work. We need one rpmsg channel per gpio-controller, and in most cases there will be only one GPIO-controller on the remote side.

Why so? In the current v13 version, the remote side already handles 2 GPIO controllers.

Quoted 4 lines

If there are
multiple or multiple instances of same controller, than we need separate channel name for that controller just like we would have separate device on the Linux.

Why so? I think there is some confusion in the terminology:

GPIO controller = GPIO port (gpio@xyz) defined in the Device tree = struct rpmsg_gpio_port in code

GPIO line = Individual lines within each GPIO port (max = GPIOS_PER_PORT_DEFAULT) = struct rpmsg_gpio_line in code

Quoted 61 lines
Quoted 61 lines
Quoted 21 lines
Quoted 9 lines
Quoted 9 lines

I've asked for one endpoint per GPIO controller since the very beginning.  I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints.  I'll have to look at your link and reflect on that.  Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level.  This is the only way this work can move forward.

Quoted 5 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this
Linux need not have the port field in the message everytime its sending a message.

Quoted 7 lines
Quoted 3 lines

With a multi-namespace approach, the namespace could be rpmsg-io- [addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here
my sentence should be;
 With a multi-namespace approach, the namespace could be rpmsg-io-[port], where [port] corresponds to the GPIO controller port in the DT.

For instance:

      rpmsg {
        rpmsg-io {
          #address-cells = <1>;
          #size-cells = <0>;

          gpio@25 {
            compatible = "rpmsg-gpio";
            reg = <25>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };

          gpio@32 {
            compatible = "rpmsg-gpio";
            reg = <32>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };
        };
      };

Quoted 8 lines
Quoted 3 lines

 rpmsg-io-25  would match with gpio@25
 rpmsg-io-32  would match with gpio@32

The problem with this approach is, we will endup creating way too many RPMsg devices/channels. i.e. one channel per one GPIO. That limits how many GPIOs can be handled by remote from memory perspective. At somepoint we might just run-out of number ept & channels created by the remote. As of now, open-amp library supports 128 epts I think.

Arnaud was suggesting one channel per gpio controller, not per line. We will not have 128 gpio controllers....

Quoted 88 lines
Quoted 62 lines
Quoted 21 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel
ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev
addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel
formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13:
new channel: 0x401 -> 0xd!
Quoted 3 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.

Quoted 18 lines

Quoted 1 line

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 2 lines

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 6 lines
Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Quoted 15 lines

Thanks and Regards,Arnaud

Quoted 13 lines

Thanks,
Beleswar

Quoted 10 lines

Regards,
Arnaud

Quoted 7 lines
Quoted 7 lines

2. namespace/channel#2 = rpmsg-i2c
      a. ept1 -> i2c@1
      b. ept2 -> i2c@2
      c. ept3 -> i2c@3

etc...

Just want to clear-up few terms before I jump to the solution:

**RPMsg channel/device**:
- These are devices announced by the remote processor, and created by
linux. They are created at: /sys/bus/rpmsg/devices
- The channel format: <name>.<src ept>.<dst ept>

**RPMsg endpoint**:
- Endpoint is differnt than channel. Single channel can have multiple
endpoints, and represented in the linux with: /dev/rpmsg? devices.

Quoted 7 lines

To create endpoint device, we have rpmsg_create_ept API, which takes channel information as input, which has src-ept, dst-ept.

Following is proposed solution:

1) Assign RPMsg channel/device per rpmsg-gpio controller (Not per GPIO pin/port).

One channel per pin was not suggested earlier...

Quoted 51 lines

- In our case that would be, single rpmsg-io node. (That makes me
question if bindings are correct or not).

2) Assign GPIO number as src ept.

i.e. *rpmsg-io.<GPIO number>.<dst ept>*. Do not randomly assign src endpoint.

Now, RPMSG channel by spec reserves first 1024 endpoints [1], so we can add 1024 offset to the GPIO number:

so, when calling rpmsg_create_ept() API, we assing src_endpoint as:
(GPIO_NUMBER + RPMSG_RESERVED_ADDRESSES)

Now on the remote side, there is single channel and only single-endpoint is needed that is mapped to the rpmsg-io channel callback.

That callback will receive all the payloads from the Linux, which will have src-ept i.e. (RPMSG_RESERVED_ADDRESSES + GPIO_NUMBER).

It can retrieve GPIO_NUMBER easily, and convert to appropriate pin based on platform specific logic.

This doesn't need PORT information at all. Also it makes sure that remote is using only single-endpoint so not much memory is used.

*Example*:
If only rpmsg-gpio channel is created by the remote side, than following is the representation of the devices when GPIO 25, 26, 27 is assigned to the rpmsg-io controller:

Linux Remote

rpmsg-channel: rpmsg-gpio.0x400.0x400

/dev/rpmsg0 - GPIO25 ept (rpmsg-gpio.0x419.0x400)-|
                                                  |
/dev/rpmsg1 - GPIO26 ept (rpmsg-gpio.0x41a.0x400)-|-> rpmsg-gpio.*.0x400
                                                  |
/dev/rpmsg2 - GPIO27 ept (rpmsg-gpio.0x41b.0x400)-|  0x400 ept callback.

*On remote side*:

ept_0x400_callback(..., int src_ept, ...,)

{
	int gpio_num = src_ept - RPMSG_RESERVED_ADDRESSES;
	// platform specific logic to convert gpio num to proper pin,
	// just like you would convert gpio num to pin on a linux gpio controller.
}
Quoted 5 lines

My question on the binding:

Why each GPIO is represented with the separate node? I think rpmsg-gpio can be represented just any other GPIO controller? Please let me know if I am missing something.

These are separate GPIO controllers, not separate pins within the same GPIO controller. Could you revisit your solution with this update.

Thanks for your time,
Beleswar

#48 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 158 lines · Beleswar Prasad Padhi

Hi Tanmay,

Quoted 137 lines · Tanmay

Hello all,

I have started reviewing this work as well.
Thanks Shenwei for this work.

I have gone through only the current revision, and would like to provide idea on how to achieve GPIO number multiplexing with the RPMsg protocol. Also, have some bindings related question.

Please see below:

Quoted 125 lines · Arnaud POULIQUEN
Quoted 123 lines · Beleswar Prasad Padhi

Hello Arnaud,

Quoted 120 lines · Arnaud POULIQUEN

Hello,

Quoted 117 lines · Mathieu Poirier
Quoted 104 lines · Beleswar

Hi Mathieu,

Quoted 95 lines · Mathieu Poirier
Quoted 87 lines · Shenwei Wang
Quoted 79 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <b- [email protected]>; Linus
Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski
<[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson
<[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected];
Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl- linux-imx <linux-
[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 34 lines · Shenwei Wang
Quoted 34 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan
Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>;
Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 5 lines

struct virtio_gpio_response {
           __u8 status;
           __u8 value;
};
It is the same message format. Please see the message definition

(GET_DIRECTION) below:

Quoted 4 lines

+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+

Quoted 7 lines
Quoted 3 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 7 lines

In contrast, rpmsg provides only a single communication channel, so a
type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 2 lines

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

Quoted 8 lines

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing
capability by way of endpoints.  There is no need for a port field.  One endpoint,
one GPIO controller.

Quoted 6 lines

You still need a way to let the remote side know which port the endpoint maps to, either
by embedding the port information in the message (the current way), or by sending it
separately.

Quoted 5 lines

An endpoint is created with every namespace request.  There should be one namespace request for every GPIO controller, which yields a unique
endpoint for each controller and eliminates the need for an extra field to identify them.

Quoted 7 lines

Right, but this can still be done by just having one namespace request.
We can create new endpoints bound to an existing namespace/channel by invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/29485742-6e49-482e-
[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 2 lines

My mental model looks like this for the complete picture:

Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

1. namespace/channel#1 = rpmsg-io
      a. ept1 -> gpio-controller@1
      b. ept2 -> gpio-controller@2

If my understanding of what gpio-controller is right, than this won't work. We need one rpmsg channel per gpio-controller, and in most cases there will be only one GPIO-controller on the remote side.

Why so? In the current v13 version, the remote side already handles 2 GPIO controllers.

Quoted 4 lines

If there are
multiple or multiple instances of same controller, than we need separate channel name for that controller just like we would have separate device on the Linux.

Quoted 8 lines

Why so? I think there is some confusion in the terminology:

GPIO controller = GPIO port (gpio@xyz) defined in the Device tree = struct rpmsg_gpio_port in code

GPIO line = Individual lines within each GPIO port (max = GPIOS_PER_PORT_DEFAULT) = struct rpmsg_gpio_line in code

Okay, I understand now. So, same gpio controller has multiple instances.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

1. namespace/channel#1 = rpmsg-io

      a. ept1 -> gpio-controller@1
      b. ept2 -> gpio-controller@2

So, In that case above mentioned approach doesn't work.

Because, this approach is mapping endpoint to the gpio-controller. From linux's perspective, it needs to map rpmsg *channel* to the gpio-controller not the endpoint.

To be more specific:

Linux: remote:

ch1: rpmsg-gpio.-1.1024 -> gpio-controller@1024
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1024.
- gpio-line ept3

ch2: rpmsg-gpio.-1.1025 -> gpio-controller@1025
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1025.
- gpio-line ept3

On the remote side, we have to hardcode Which rpmsg controller is mapped to which endpoint.

Quoted 238 lines
Quoted 61 lines
Quoted 61 lines
Quoted 21 lines
Quoted 9 lines
Quoted 9 lines

I've asked for one endpoint per GPIO controller since the very beginning.  I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints.  I'll have to look at your link and reflect on that.  Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level.  This is the only way this work can move forward.

Quoted 5 lines

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Simply by sending a message to the remote containing the newly created endpoint and the port idx. Note that is this done just one time, after this
Linux need not have the port field in the message everytime its sending a message.

Quoted 7 lines
Quoted 3 lines

With a multi-namespace approach, the namespace could be rpmsg-io- [addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

You will face the same problem in this case also that you asked above:
"how do we match the Linux endpoint address with the local port field on the remote side?"

Sorry I probably introduced confusion here
my sentence should be;
 With a multi-namespace approach, the namespace could be rpmsg-io-[port], where [port] corresponds to the GPIO controller port in the DT.

For instance:

      rpmsg {
        rpmsg-io {
          #address-cells = <1>;
          #size-cells = <0>;

          gpio@25 {
            compatible = "rpmsg-gpio";
            reg = <25>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };

          gpio@32 {
            compatible = "rpmsg-gpio";
            reg = <32>;
            gpio-controller;
            #gpio-cells = <2>;
            #interrupt-cells = <2>;
            interrupt-controller;
          };
        };
      };

Quoted 8 lines
Quoted 3 lines

 rpmsg-io-25  would match with gpio@25
 rpmsg-io-32  would match with gpio@32

The problem with this approach is, we will endup creating way too many RPMsg devices/channels. i.e. one channel per one GPIO. That limits how many GPIOs can be handled by remote from memory perspective. At somepoint we might just run-out of number ept & channels created by the remote. As of now, open-amp library supports 128 epts I think.

Arnaud was suggesting one channel per gpio controller, not per line. We will not have 128 gpio controllers....

Quoted 88 lines
Quoted 62 lines
Quoted 21 lines

Because the endpoint that is created on a namespace request is also dynamic in nature. How will the remote know which endpoint addr Linux allocated for a namespace that it announced?

As an example/PoC, I created a firmware example which announces 2 name services to Linux, one is the standard "rpmsg_chrdev" and the other is a TI specific name service "ti.ipc4.ping-pong". You can see it created 2 different addresses (0x400 and 0x401) for each of the name service request from the same firmware:

root@j784s4-evm:~# dmesg | grep virtio0 | grep -i channel
[    9.290275] virtio_rpmsg_bus virtio0: creating channel
ti.ipc4.ping-pong addr 0xd
[    9.311230] virtio_rpmsg_bus virtio0: creating channel rpmsg_chrdev
addr 0xe
[    9.496645] rpmsg_chrdev virtio0.rpmsg_chrdev.-1.14: DEBUG: Channel
formed from src = 0x400 to dst = 0xe
[    9.707255] rpmsg_client_sample virtio0.ti.ipc4.ping-pong.-1.13:
new channel: 0x401 -> 0xd!
Quoted 3 lines

So in this case, rpmsg-io-1 can have different ept addr than rpmsg-io-2 Back to same problem. Simple solution is to reply to remote with the created ept addr and the index.

That why I would like to suggest to use the name service field to identify the port/controller, instead of the endpoint address.

Quoted 18 lines

Quoted 1 line

- match the RPMsg probe with the DT,

We can probe from all controllers with a single name service announcement too.

Quoted 2 lines

- provide a simple mapping between the port and the endpoint on both sides,

We are trying to get rid of this mapping from Linux side to adapt the gpio-virtio design.

Quoted 1 line

- allow multiple endpoints on the remote side,

We can support this as well with single nameservice model. There is no limitation. Remote has to send a message with its newly created ept that's all.

Quoted 6 lines
Quoted 1 line

- provide a simple discovery mechanism for remote capabilities.

A single announcement: "rpmsg-io" is also discovery mechanism.

Feel free to let me know if you have concerns with any of the suggestions!

My only concern, whatever the solution, is that we find a smart solution to associate the correct endpoint with the correct GPIO port/controller defined in the DT.

I may have misunderstood your solution. Could you please help me understand your proposal by explaining how you would handle three GPIO ports defined in the DT, considering that the endpoint addresses on the Linux side can be random?
If I assume there is a unique endpoint on the remote side, I do not understand how you can match, on the firmware side, the Linux endpoint address to the GPIO port.

Quoted 15 lines

Thanks and Regards,Arnaud

Quoted 13 lines

Thanks,
Beleswar

Quoted 10 lines

Regards,
Arnaud

Quoted 7 lines
Quoted 7 lines

2. namespace/channel#2 = rpmsg-i2c
      a. ept1 -> i2c@1
      b. ept2 -> i2c@2
      c. ept3 -> i2c@3

etc...

Just want to clear-up few terms before I jump to the solution:

**RPMsg channel/device**:
- These are devices announced by the remote processor, and created by
linux. They are created at: /sys/bus/rpmsg/devices
- The channel format: <name>.<src ept>.<dst ept>

**RPMsg endpoint**:
- Endpoint is differnt than channel. Single channel can have multiple
endpoints, and represented in the linux with: /dev/rpmsg? devices.

Quoted 7 lines

To create endpoint device, we have rpmsg_create_ept API, which takes channel information as input, which has src-ept, dst-ept.

Following is proposed solution:

1) Assign RPMsg channel/device per rpmsg-gpio controller (Not per GPIO pin/port).

One channel per pin was not suggested earlier...

Quoted 51 lines

- In our case that would be, single rpmsg-io node. (That makes me
question if bindings are correct or not).

2) Assign GPIO number as src ept.

i.e. *rpmsg-io.<GPIO number>.<dst ept>*. Do not randomly assign src endpoint.

Now, RPMSG channel by spec reserves first 1024 endpoints [1], so we can add 1024 offset to the GPIO number:

so, when calling rpmsg_create_ept() API, we assing src_endpoint as:
(GPIO_NUMBER + RPMSG_RESERVED_ADDRESSES)

Now on the remote side, there is single channel and only single-endpoint is needed that is mapped to the rpmsg-io channel callback.

That callback will receive all the payloads from the Linux, which will have src-ept i.e. (RPMSG_RESERVED_ADDRESSES + GPIO_NUMBER).

It can retrieve GPIO_NUMBER easily, and convert to appropriate pin based on platform specific logic.

This doesn't need PORT information at all. Also it makes sure that remote is using only single-endpoint so not much memory is used.

*Example*:
If only rpmsg-gpio channel is created by the remote side, than following is the representation of the devices when GPIO 25, 26, 27 is assigned to the rpmsg-io controller:

Linux Remote

rpmsg-channel: rpmsg-gpio.0x400.0x400

/dev/rpmsg0 - GPIO25 ept (rpmsg-gpio.0x419.0x400)-|
                                                  |
/dev/rpmsg1 - GPIO26 ept (rpmsg-gpio.0x41a.0x400)-|-> rpmsg-gpio.*.0x400
                                                  |
/dev/rpmsg2 - GPIO27 ept (rpmsg-gpio.0x41b.0x400)-|  0x400 ept callback.

*On remote side*:

ept_0x400_callback(..., int src_ept, ...,)

{
	int gpio_num = src_ept - RPMSG_RESERVED_ADDRESSES;
	// platform specific logic to convert gpio num to proper pin,
	// just like you would convert gpio num to pin on a linux gpio controller.
}
Quoted 5 lines

My question on the binding:

Why each GPIO is represented with the separate node? I think rpmsg-gpio can be represented just any other GPIO controller? Please let me know if I am missing something.

These are separate GPIO controllers, not separate pins within the same GPIO controller. Could you revisit your solution with this update.

Thanks for your time,
Beleswar

#49 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

On 5/5/2026 9:08 PM, Shah, Tanmay wrote:

[...]

Quoted 14 lines
Quoted 6 lines
Quoted 5 lines

If there are
multiple or multiple instances of same controller, than we need separate channel name for that controller just like we would have separate device on the Linux.

Quoted 8 lines

Why so? I think there is some confusion in the terminology:

GPIO controller = GPIO port (gpio@xyz) defined in the Device tree = struct rpmsg_gpio_port in code

GPIO line = Individual lines within each GPIO port (max = GPIOS_PER_PORT_DEFAULT) = struct rpmsg_gpio_line in code

Quoted 8 lines

Okay, I understand now. So, same gpio controller has multiple instances.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

1. namespace/channel#1 = rpmsg-io

       a. ept1 -> gpio-controller@1
       b. ept2 -> gpio-controller@2

So, In that case above mentioned approach doesn't work.

Because, this approach is mapping endpoint to the gpio-controller.

And what is the problem with that?

Quoted 3 lines

From
linux's perspective, it needs to map rpmsg *channel* to the gpio-controller not the endpoint.

Can you explain why it *needs* to?

Quoted 9 lines

To be more specific:

Linux: remote:

ch1: rpmsg-gpio.-1.1024 -> gpio-controller@1024
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1024.
- gpio-line ept3

This is a weird mapping. I am not suggesting one ept per gpio-line, rather one per gpio-controller. You can refer my detailed proposal here:

https://lore.kernel.org/all/[email protected]/

Quoted 5 lines

ch2: rpmsg-gpio.-1.1025 -> gpio-controller@1025
- gpio-line ept1
- gpio-line ept2 -> They all map to same callback_ept_1025.
- gpio-line ept3

[...]

Quoted 3 lines

On the remote side, we have to hardcode Which rpmsg controller is mapped to which endpoint.

Not necessarily, we can exchange this info at runtime.

Thanks,
Beleswar

maintainer
#50 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

In reply to Arnaud POULIQUEN
Quoted 120 lines · Arnaud POULIQUEN

Hello,

Quoted 102 lines · Mathieu Poirier
Quoted 86 lines · Beleswar

Hi Mathieu,

Quoted 72 lines · Mathieu Poirier
Quoted 71 lines · Shenwei Wang
Quoted 71 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 33 lines · Shenwei Wang
Quoted 33 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 5 lines
Quoted 4 lines
struct virtio_gpio_response {
          __u8 status;
          __u8 value;
};

It is the same message format. Please see the message definition

(GET_DIRECTION) below:

Quoted 4 lines
(quoted diff) +4 -0
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+
Quoted 5 lines
Quoted 2 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 4 lines

In contrast, rpmsg provides only a single communication channel, so a type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 1 line

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing capability by way of endpoints. There is no need for a port field. One endpoint, one GPIO controller.

Quoted 8 lines
Quoted 4 lines

You still need a way to let the remote side know which port the endpoint maps to, either by embedding the port information in the message (the current way), or by sending it separately.

An endpoint is created with every namespace request. There should be one namespace request for every GPIO controller, which yields a unique endpoint for each controller and eliminates the need for an extra field to identify them.

Quoted 5 lines

Right, but this can still be done by just having one namespace request. We can create new endpoints bound to an existing namespace/channel by invoking rpmsg_create_ept(). This is what I suggested here too:
https://lore.kernel.org/all/[email protected]/

I will look at your suggestion (i.e link above) later this week or next week.

Quoted 6 lines

My mental model looks like this for the complete picture:

1. namespace/channel#1 = rpmsg-io

     a. ept1 -> gpio-controller@1
     b. ept2 -> gpio-controller@2
Quoted 8 lines

I've asked for one endpoint per GPIO controller since the very beginning. I don't yet have a strong opinion on whether to use one namespace request per GPIO controller or a single request that spins off multiple endpoints. I'll have to look at your link and reflect on that. Regardless of how we proceed on that front, multiplexing needs to happen at the endpoint level rather than the packet level. This is the only way this work can move forward.

I would be more in favor of Mathieu’s proposal: “An endpoint is created with every namespace request.”

If the endpoint is created only on the Linux side, how do we match the Linux endpoint address with the local port field on the remote side?

Quoted 9 lines

With a multi-namespace approach, the namespace could be rpmsg-io-[addr], where [addr] corresponds to the GPIO controller address in the DT. This would:

- match the RPMsg probe with the DT,
- provide a simple mapping between the port and the endpoint on both sides,
- allow multiple endpoints on the remote side,
- provide a simple discovery mechanism for remote capabilities.

This is exactly what I had in mind but I'll finish reading this thread before expressing a final point of view. That said, the namespace announcement should be "rpmsg-gpio-[addr]" rather than "rpmsg-io-[addr]" to make sure there is no ambiguity on the meaning of "io".

More comments to come...

Quoted 19 lines

Regards,
Arnaud

Quoted 15 lines
Quoted 14 lines

2. namespace/channel#2 = rpmsg-i2c

     a. ept1 -> i2c@1
     b. ept2 -> i2c@2
     c. ept3 -> i2c@3

etc...

This way device groups are isolated with each channel/namespace, and instances within each device groups are also respected with specific endpoints.

Thanks,
Beleswar

#51 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

In reply to Shenwei Wang
Quoted 63 lines · Shenwei Wang
Quoted 63 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Wednesday, April 29, 2026 10:42 AM
To: Shenwei Wang <[email protected]>
Cc: Andrew Lunn <[email protected]>; Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 33 lines · Shenwei Wang
Quoted 33 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Monday, April 27, 2026 3:49 PM
To: Shenwei Wang <[email protected]>
Cc: Padhi, Beleswar <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 5 lines
Quoted 4 lines
struct virtio_gpio_response {
         __u8 status;
         __u8 value;
};

It is the same message format. Please see the message definition

(GET_DIRECTION) below:

Quoted 4 lines
(quoted diff) +4 -0
+   +-----+-----+-----+-----+-----+----+
+   |0x00 |0x01 |0x02 |0x03 |0x04 |0x05|
+   | 1   | 2   |port |line | err | dir|
+   +-----+-----+-----+-----+-----+----+
Quoted 5 lines
Quoted 2 lines

Sorry, but i don't see how two u8 vs six u8 are the same message format.

Some changes to the message format are necessary.

Virtio uses two communication channels (virtqueues): one for requests and

replies, and a second one for events.

Quoted 4 lines

In contrast, rpmsg provides only a single communication channel, so a type field is required to distinguish between different kinds of messages.

Since rpmsg replies and events share the same message format, an additional

line is introduced to handle both cases.

Quoted 8 lines
Quoted 7 lines
Quoted 1 line

Finally, rpmsg supports multiple GPIO controllers, so a port field is added to

uniquely identify the target controller.

I have commented on this before - RPMSG is already providing multiplexing capability by way of endpoints. There is no need for a port field. One endpoint, one GPIO controller.

You still need a way to let the remote side know which port the endpoint maps to,

About this, we only need to do this because you are defining the gpio controller instances "statically" in the device tree. I understand gpio nodes can act as providers, but I do not see any device referencing the gpio nodes you are defining in the device tree. If that is the case, you can completely remove the nodes from device tree, and "dynamically" announce the existence of these nodes from the firmware itself (similar to what is done for rpmsg-tty currently). In response to that announce message, Linux could send the "ept" it allocated for the controller. That way, Linux only cares about "ept" and there is no need to maintain port 'idx' info anywhere in the Linux side anymore.

Thanks,
Beleswar

#52 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 4 lines

About this, we only need to do this because you are defining the gpio controller instances "statically" in the device tree. I understand gpio nodes can act as providers, but I do not see any device referencing the gpio nodes you are defining in the device tree.

They probably come later, and a board specific. The GPIO controllers are probably SoC specific, so can be defined at the SoC .dtsi level. The users are then in the board .dts files.

This is how GPIOs are typically used. Same will be true of I2C, the SoC provides the I2C adaptor, the boards have devices on the bus, again, described in DT.

Andrew

#53 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

In reply to Shenwei Wang

On 28/04/26 00:53, Shenwei Wang wrote:
[...]

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpio/gpio-rpmsg.c new file +8 -0
+
+struct rpmsg_gpio_packet {
+     u8 type;        /* Message type */
+     u8 cmd;         /* Command code */
+     u8 port_idx;
+     u8 line;
+     u8 val1;
+     u8 val2;
Quoted 9 lines
Quoted 1 line

+};

Could you please document the fields in these structs (and the below ones too)? From the code, it looks like while sending a message from Linux to Firmware; val1 and val2 are used to describe the values to set. Whereas while receiving a response, val1 represents a possible error code, and val2 represents the actual message of get type queries. If that is so, you might want to change the variable names to be more descriptive and also use a union.

Quoted 1 line

The fields in the two structs are fairly self-explanatory. Do we really need the additional comments?

val1 and val2 sounded arbitrary, that's all. If we are moving away from that, then there is no need :)

[...]

Quoted 9 lines
Quoted 8 lines
Quoted 2 lines

+ void *channel_devices[MAX_PORT_PER_CHANNEL];

So this is technically a rpmsg endpoint (struct rpmsg_endpoint) without naming it "endpoint". Every rpmsg endpoint has a reference to its parent rpmsg channel (struct rpmsg_device) which represents the same information here. So we should use the framework standard here.

Yes, agree to use "endpoint_devices".

I did not mean to say to just change the variable name from "channel_devices" to "endpoint_devices". Infact you would not need to have this field & struct anymore.

Pseudo-code:
1. Add a 'struct rpmsg_endpoint *ept' field to struct rpmsg_gpio_port to maintain the ept to port idx map.

2. Call port->ept = rpmsg_create_ept(rpdev,
                                                            rpmsg_gpio_channel_callback, port, {rpdev.id.name, RPMSG_ADDR_ANY, RPMSG_ADDR_ANY}) from rpmsg_gpiochip_register().

3. Send msgs from local ept in rpmsg_gpio_send_message() by:
    rpmsg_send(port->ept, msg, sizeof(*msg));

4. Get the port info in rpmsg_gpio_channel_callback() by:
    struct rpmsg_gpio_port *port = priv;

Which also eliminates the need for struct rpdev_drvdata as you can just do rpmsg_get_rproc_node_name(rpdev) from rpmsg_gpiochip_register().

Quoted 9 lines
Quoted 9 lines

This also allows for dynamic creation and deletion of ports too! (if/when the firmware supports it)

Which means at port init time, we should make a call to rpmsg_create_ept() for each port tying the same callback rpmsg_gpio_channel_callback(). And based on the 'u32 src', we could identify the appropriate gpio port in the callback.

[...]

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
drivers/gpio/gpio-rpmsg.c new file +7 -0
+
+     girq = &gc->irq;
+     gpio_irq_chip_set_chip(girq, &gpio_rpmsg_irq_chip);
+     girq->parent_handler = NULL;
+     girq->num_parents = 0;
+     girq->parents = NULL;
+     girq->chip->name = devm_kasprintf(&rpdev->dev, GFP_KERNEL, "%s-
Quoted 6 lines
Quoted 5 lines

gpio%d",

Quoted 2 lines

+ drvdata->rproc_name,
+ port->idx);

We could just re-use gc->label here...

We also want to include the remoteproc name (for example, remoteproc-cm33-gpio0), rather than just gpio0.

Isn't it also included in the gc->label field?

gc->label = devm_kasprintf(&rpdev->dev, GFP_KERNEL, "%s-gpio%d", +                   drvdata->rproc_name, port->idx);

[...]

Quoted 21 lines
Quoted 21 lines
Quoted 5 lines
drivers/gpio/gpio-rpmsg.c new file +5 -0
+}
+
+static int rpmsg_gpio_channel_probe(struct rpmsg_device *rpdev) {
+     struct device *dev = &rpdev->dev;
+     struct rpdev_drvdata *drvdata;

drivers/gpio/gpio-rpmsg.c line 524

Quoted 10 lines
drivers/gpio/gpio-rpmsg.c new file +10 -0
+     struct device_node *np;
+     int ret = -ENODEV;
+
+     if (!dev->of_node) {
+             np = rpmsg_get_channel_ofnode(rpdev, rpdev->id.name);
+             if (np) {
+                     dev->of_node = np;
+                     set_primary_fwnode(dev, of_fwnode_handle(np));
+             }
+             return -EPROBE_DEFER;

I know this was asked in the v10 version also. But I don't think the answer is sufficient. Should we not continue the intialization of drvdata etc if np != 0? Why return a deferred probe, and let the kernel come back to it again to do the same stuff with extra latency?

Quoted 7 lines
Quoted 4 lines

We could just do:
if (!np) return -EPROBE_DEFER;
else {everything_else};

After configuring dev->of_node, it would be better to restart the driver probe process. This ensures that all required resources, such as pinctrl, clocks, and power domains, are properly set up if they are specified in the device node, before the probe function is invoked.

Hmm that makes sense to me... Thanks!

Thanks,
Beleswar

#54 lore raw

RE: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 41 lines

-----Original Message-----
From: Beleswar Prasad Padhi <[email protected]>
Sent: Tuesday, April 28, 2026 2:25 AM
To: Shenwei Wang <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>
Cc: Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>; Andrew Lunn <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver On 28/04/26 00:53, Shenwei Wang wrote:
[...]

Quoted 9 lines
Quoted 8 lines
Quoted 2 lines

+ void *channel_devices[MAX_PORT_PER_CHANNEL];

So this is technically a rpmsg endpoint (struct rpmsg_endpoint) without naming it "endpoint". Every rpmsg endpoint has a reference to its parent rpmsg channel (struct rpmsg_device) which represents the same information here. So we should use the framework standard here.

Yes, agree to use "endpoint_devices".

I did not mean to say to just change the variable name from "channel_devices" to "endpoint_devices". Infact you would not need to have this field & struct anymore.

Pseudo-code:
1. Add a 'struct rpmsg_endpoint *ept' field to struct rpmsg_gpio_port to maintain the ept to port idx map.

Quoted 7 lines

2. Call port->ept = rpmsg_create_ept(rpdev,
rpmsg_gpio_channel_callback, port, {rpdev.id.name, RPMSG_ADDR_ANY, RPMSG_ADDR_ANY})
from rpmsg_gpiochip_register().

On the Linux side, we invoke rpmsg_create_ept. What is expected from the remote system in this case? If the remote side does not need any extra support, this would be an excellent solution.

Thanks,
Shenwei

Quoted 9 lines

3. Send msgs from local ept in rpmsg_gpio_send_message() by:

    rpmsg_send(port->ept, msg, sizeof(*msg));

4. Get the port info in rpmsg_gpio_channel_callback() by:

    struct rpmsg_gpio_port *port = priv;

Which also eliminates the need for struct rpdev_drvdata as you can just do rpmsg_get_rproc_node_name(rpdev) from rpmsg_gpiochip_register().

#55 lore raw

Re: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 37 lines · Shenwei Wang
Quoted 37 lines

-----Original Message-----
From: Beleswar Prasad Padhi <[email protected]>
Sent: Tuesday, April 28, 2026 2:25 AM
To: Shenwei Wang <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>
Cc: Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>; Andrew Lunn <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver On 28/04/26 00:53, Shenwei Wang wrote:
[...]

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

+ void *channel_devices[MAX_PORT_PER_CHANNEL];

So this is technically a rpmsg endpoint (struct rpmsg_endpoint) without naming it "endpoint". Every rpmsg endpoint has a reference to its parent rpmsg channel (struct rpmsg_device) which represents the same information here. So we should use the framework standard here.

Yes, agree to use "endpoint_devices".

I did not mean to say to just change the variable name from "channel_devices" to "endpoint_devices". Infact you would not need to have this field & struct anymore.

Pseudo-code:
1. Add a 'struct rpmsg_endpoint *ept' field to struct rpmsg_gpio_port to maintain the ept to port idx map.

Quoted 8 lines
Quoted 7 lines

2. Call port->ept = rpmsg_create_ept(rpdev,
rpmsg_gpio_channel_callback, port, {rpdev.id.name, RPMSG_ADDR_ANY, RPMSG_ADDR_ANY})
from rpmsg_gpiochip_register().

On the Linux side, we invoke rpmsg_create_ept. What is expected from the remote system in this case?

Nothing extra in my opinion. rpmsg_create_ept() just creates a dynamic local endpoint address for Linux's usage. The firmware just has to make sure to reply to the same endpoint address where it received the message. This should already be in place IMO, because currently you are sending all messages in the default endpoint (rpdev->ept) which is also dynamic[1] and is created when the channel is created. And you receive the responses correctly. (Unless you have hard-coded the default ept address in the firmware)

[1]: https://github.com/torvalds/linux/blob/master/drivers/rpmsg/rpmsg_core.c#L480
(chinfo.src is RPMSG_ADDR_ANY)

Thanks,
Beleswar

Quoted 14 lines

If the remote side does not need any extra support, this would be an excellent solution.

Thanks,
Shenwei

Quoted 9 lines

3. Send msgs from local ept in rpmsg_gpio_send_message() by:

     rpmsg_send(port->ept, msg, sizeof(*msg));

4. Get the port info in rpmsg_gpio_channel_callback() by:

     struct rpmsg_gpio_port *port = priv;

Which also eliminates the need for struct rpdev_drvdata as you can just do rpmsg_get_rproc_node_name(rpdev) from rpmsg_gpiochip_register().

#56 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 73 lines

-----Original Message-----
From: Padhi, Beleswar <[email protected]>
Sent: Tuesday, April 28, 2026 10:11 AM
To: Shenwei Wang <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>
Cc: Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>; Andrew Lunn <[email protected]>
Subject: Re: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button

Quoted 46 lines · Shenwei Wang
Quoted 46 lines

-----Original Message-----
From: Beleswar Prasad Padhi <[email protected]>
Sent: Tuesday, April 28, 2026 2:25 AM
To: Shenwei Wang <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>
Cc: Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>; Andrew Lunn <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver On 28/04/26 00:53, Shenwei Wang wrote:
[...]

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

+ void *channel_devices[MAX_PORT_PER_CHANNEL];

So this is technically a rpmsg endpoint (struct rpmsg_endpoint) without naming it "endpoint". Every rpmsg endpoint has a reference to its parent rpmsg channel (struct rpmsg_device) which represents the same information here. So we should use the framework standard here.

Yes, agree to use "endpoint_devices".

I did not mean to say to just change the variable name from "channel_devices" to "endpoint_devices". Infact you would not need to have this field & struct anymore.

Pseudo-code:
1. Add a 'struct rpmsg_endpoint *ept' field to struct rpmsg_gpio_port to maintain the ept to port idx map.

2. Call port->ept = rpmsg_create_ept(rpdev,
rpmsg_gpio_channel_callback, port, {rpdev.id.name, RPMSG_ADDR_ANY, RPMSG_ADDR_ANY})
from rpmsg_gpiochip_register().

Quoted 8 lines
Quoted 1 line

On the Linux side, we invoke rpmsg_create_ept. What is expected from the

remote system in this case?

Nothing extra in my opinion. rpmsg_create_ept() just creates a dynamic local endpoint address for Linux's usage. The firmware just has to make sure to reply to the same endpoint address where it received the message. This should already be in place IMO, because currently you are sending all messages in the default

Since rpmsg_create_ept creates a new local endpoint address on the Linux side, how is the remote system expected to learn and use this new address for communication if no additional logic is added on the remote side?

Is this handled automatically by the rpmsg stack software, or does it require explicit support on the remote system to exchange and track endpoint addresses?

Thanks,
Shenwei

Quoted 34 lines

endpoint (rpdev->ept) which is also dynamic[1] and is created when the channel is created. And you receive the responses correctly. (Unless you have hard-coded the default ept address in the firmware)

[1]:
https://github.co/
m%2Ftorvalds%2Flinux%2Fblob%2Fmaster%2Fdrivers%2Frpmsg%2Frpmsg_core. c%23L480&data=05%7C02%7Cshenwei.wang%40nxp.com%7C4ec06bf01bb14dd 2625708dea5387471%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C6 39129859078622527%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRyd WUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D% 3D%7C0%7C%7C%7C&sdata=OUmjqOdWqiXSTjPDv1TUvrjKP1YTx9ji44SdGlIR2n Q%3D&reserved=0
(chinfo.src is RPMSG_ADDR_ANY)

Thanks,
Beleswar

Quoted 1 line

If the remote side does not need any extra support, this would be an excellent

solution.

Quoted 14 lines

Thanks,
Shenwei

Quoted 10 lines

3. Send msgs from local ept in rpmsg_gpio_send_message() by:

     rpmsg_send(port->ept, msg, sizeof(*msg));

4. Get the port info in rpmsg_gpio_channel_callback() by:

     struct rpmsg_gpio_port *port = priv;

Which also eliminates the need for struct rpdev_drvdata as you can just do
rpmsg_get_rproc_node_name(rpdev) from rpmsg_gpiochip_register().

#57 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 74 lines · Shenwei Wang
Quoted 74 lines

-----Original Message-----
From: Padhi, Beleswar <[email protected]>
Sent: Tuesday, April 28, 2026 10:11 AM
To: Shenwei Wang <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>
Cc: Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>; Andrew Lunn <[email protected]>
Subject: Re: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button

Quoted 37 lines · Shenwei Wang
Quoted 37 lines

-----Original Message-----
From: Beleswar Prasad Padhi <[email protected]>
Sent: Tuesday, April 28, 2026 2:25 AM
To: Shenwei Wang <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>
Cc: Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>; Andrew Lunn <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver On 28/04/26 00:53, Shenwei Wang wrote:
[...]

Quoted 7 lines
Quoted 6 lines
Quoted 1 line

+ void *channel_devices[MAX_PORT_PER_CHANNEL];

So this is technically a rpmsg endpoint (struct rpmsg_endpoint) without naming it "endpoint". Every rpmsg endpoint has a reference to its parent rpmsg channel (struct rpmsg_device) which represents the same information here. So we should use the framework standard here.

Yes, agree to use "endpoint_devices".

I did not mean to say to just change the variable name from "channel_devices" to "endpoint_devices". Infact you would not need to have this field & struct anymore.

Pseudo-code:
1. Add a 'struct rpmsg_endpoint *ept' field to struct rpmsg_gpio_port to maintain the ept to port idx map.

Quoted 8 lines
Quoted 7 lines

2. Call port->ept = rpmsg_create_ept(rpdev,
rpmsg_gpio_channel_callback, port, {rpdev.id.name, RPMSG_ADDR_ANY, RPMSG_ADDR_ANY})
from rpmsg_gpiochip_register().

On the Linux side, we invoke rpmsg_create_ept. What is expected from the

remote system in this case?

Quoted 7 lines
Quoted 4 lines

Nothing extra in my opinion. rpmsg_create_ept() just creates a dynamic local endpoint address for Linux's usage. The firmware just has to make sure to reply to the same endpoint address where it received the message. This should already be in place IMO, because currently you are sending all messages in the default

Since rpmsg_create_ept creates a new local endpoint address on the Linux side, how is the remote system expected to learn and use this new address for communication if no additional logic is added on the remote side?

Remote side learns the endpoint when it receives any message from Linux from the dynamic endpoint.

Lets say rpmsg_create_ept() allocates a dynamic local ept of 1026. When you send the message from this endpoint, the standard rpmsg header would have:

    85 struct rpmsg_hdr {
    86         __rpmsg32 src; // 1026
    87         __rpmsg32 dst; // rpdev->dst (e.g. 400) 88         __rpmsg32 reserved;
    89         __rpmsg16 len;
    90         __rpmsg16 flags;
    91         u8 data[];
    92 } __packed;

Remote side tracks the dynamic endpoint by reading src = 1026. And while sending the response it fills the header as:

    85 struct rpmsg_hdr {
    86         __rpmsg32 src; // 400
    87         __rpmsg32 dst; // 1026
    88         __rpmsg32 reserved;
    89         __rpmsg16 len;
    90         __rpmsg16 flags;
    91         u8 data[];
    92 } __packed;

Note: Remote firmware can also send messages from dynamically created endpoints on its side, and Linux can learn those in the same manner. The dynamic endpoint address is passed to the callback as 'u32 src'. So you could pass on the 'src' from rpmsg_gpio_channel_callback() to rpmsg_gpio_send_message() as 'dst' and call rpmsg_sendto(port->ept, msg, sizeof(*msg), dst) to reply to the dynamic endpoint on firmware's side.

Thanks,
Beleswar

Quoted 40 lines

Is this handled automatically by the rpmsg stack software, or does it require explicit support on the remote system to exchange and track endpoint addresses?

Thanks,
Shenwei

Quoted 33 lines

endpoint (rpdev->ept) which is also dynamic[1] and is created when the channel is created. And you receive the responses correctly. (Unless you have hard-coded the default ept address in the firmware)

[1]:
https://github.co/
m%2Ftorvalds%2Flinux%2Fblob%2Fmaster%2Fdrivers%2Frpmsg%2Frpmsg_core. c%23L480&data=05%7C02%7Cshenwei.wang%40nxp.com%7C4ec06bf01bb14dd 2625708dea5387471%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C6 39129859078622527%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRyd WUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D% 3D%7C0%7C%7C%7C&sdata=OUmjqOdWqiXSTjPDv1TUvrjKP1YTx9ji44SdGlIR2n Q%3D&reserved=0
(chinfo.src is RPMSG_ADDR_ANY)

Thanks,
Beleswar

Quoted 1 line

If the remote side does not need any extra support, this would be an excellent

solution.

Quoted 13 lines

Thanks,
Shenwei

Quoted 10 lines

3. Send msgs from local ept in rpmsg_gpio_send_message() by:

      rpmsg_send(port->ept, msg, sizeof(*msg));

4. Get the port info in rpmsg_gpio_channel_callback() by:

      struct rpmsg_gpio_port *port = priv;

Which also eliminates the need for struct rpdev_drvdata as you can just do
rpmsg_get_rproc_node_name(rpdev) from rpmsg_gpiochip_register().

#58 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 49 lines

-----Original Message-----
From: Padhi, Beleswar <[email protected]>
Sent: Tuesday, April 28, 2026 10:53 AM
To: Shenwei Wang <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>
Cc: Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>; Andrew Lunn <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 9 lines
Quoted 6 lines

Nothing extra in my opinion. rpmsg_create_ept() just creates a dynamic local endpoint address for Linux's usage. The firmware just has to make sure to reply to the same endpoint address where it received the message. This should already be in place IMO, because currently you are sending all messages in the default

Since rpmsg_create_ept creates a new local endpoint address on the Linux side, how is the remote system expected to learn and use this new address for communication if no additional logic is added on the remote

side?

Remote side learns the endpoint when it receives any message from Linux from the dynamic endpoint.

Lets say rpmsg_create_ept() allocates a dynamic local ept of 1026. When you send the message from this endpoint, the standard rpmsg header would have:

     85 struct rpmsg_hdr {
     86         __rpmsg32 src; // 1026
     87         __rpmsg32 dst; // rpdev->dst (e.g. 400)
     88         __rpmsg32 reserved;
     89         __rpmsg16 len;
     90         __rpmsg16 flags;
     91         u8 data[];
     92 } __packed;

Remote side tracks the dynamic endpoint by reading src = 1026. And while sending the response it fills the header as:

Quoted 9 lines
     85 struct rpmsg_hdr {
     86         __rpmsg32 src; // 400
     87         __rpmsg32 dst; // 1026
     88         __rpmsg32 reserved;
     89         __rpmsg16 len;
     90         __rpmsg16 flags;
     91         u8 data[];
     92 } __packed;

This explains how reply messages work in this scenario: the remote side can simply send the response back to the source address of the incoming message.

How does this work for notification messages initiated by the remote side? Should the remote system need to add additional logic to track the source address based on the GPIO instance?

Thanks,
Shenwei

Quoted 73 lines

Note: Remote firmware can also send messages from dynamically created endpoints on its side, and Linux can learn those in the same manner. The dynamic endpoint address is passed to the callback as 'u32 src'. So you could pass on the 'src' from rpmsg_gpio_channel_callback() to rpmsg_gpio_send_message() as 'dst' and call rpmsg_sendto(port->ept, msg, sizeof(*msg), dst) to reply to the dynamic endpoint on firmware's side.

Thanks,
Beleswar

Quoted 3 lines

Is this handled automatically by the rpmsg stack software, or does it require explicit support on the remote system to exchange and track endpoint

addresses?

Quoted 11 lines

Thanks,
Shenwei

Quoted 7 lines

endpoint (rpdev->ept) which is also dynamic[1] and is created when the channel is created. And you receive the responses correctly. (Unless you have hard-coded the default ept address in the firmware)

[1]:
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit

hub.co%2F&data=05%7C02%7Cshenwei.wang%40nxp.com%7C057bf7f0976749 5bcc3

Quoted 1 line
Quoted 1 line

108dea53e43f7%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C63912 98840

Quoted 1 line
Quoted 1 line

26686251%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiI wLjAu

Quoted 1 line
Quoted 1 line

MDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C %7C

Quoted 1 line
Quoted 1 line

&sdata=iSxGWEvYSyu29loP9b1R2bw8bvwR7pbzQ7D%2FGeB%2BUYE%3D&reser ved=0

Quoted 1 line
Quoted 1 line

m%2Ftorvalds%2Flinux%2Fblob%2Fmaster%2Fdrivers%2Frpmsg%2Frpmsg_core.

Quoted 1 line
Quoted 1 line

c%23L480&data=05%7C02%7Cshenwei.wang%40nxp.com%7C4ec06bf01bb14dd

Quoted 1 line
Quoted 1 line

2625708dea5387471%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C6

Quoted 1 line
Quoted 1 line

39129859078622527%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRyd

Quoted 1 line
Quoted 1 line

WUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%

Quoted 1 line
Quoted 1 line

3D%7C0%7C%7C%7C&sdata=OUmjqOdWqiXSTjPDv1TUvrjKP1YTx9ji44SdGlIR2n

Quoted 22 lines
Quoted 22 lines

Q%3D&reserved=0
(chinfo.src is RPMSG_ADDR_ANY)

Thanks,
Beleswar

Quoted 2 lines

If the remote side does not need any extra support, this would be an excellent

solution.

Quoted 13 lines

Thanks,
Shenwei

Quoted 10 lines

3. Send msgs from local ept in rpmsg_gpio_send_message() by:

      rpmsg_send(port->ept, msg, sizeof(*msg));

4. Get the port info in rpmsg_gpio_channel_callback() by:

      struct rpmsg_gpio_port *port = priv;

Which also eliminates the need for struct rpdev_drvdata as you can just do
rpmsg_get_rproc_node_name(rpdev) from rpmsg_gpiochip_register().

#59 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 56 lines · Shenwei Wang
Quoted 47 lines

-----Original Message-----
From: Padhi, Beleswar <[email protected]>
Sent: Tuesday, April 28, 2026 10:53 AM
To: Shenwei Wang <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>
Cc: Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>; Andrew Lunn <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 8 lines
Quoted 5 lines

Nothing extra in my opinion. rpmsg_create_ept() just creates a dynamic local endpoint address for Linux's usage. The firmware just has to make sure to reply to the same endpoint address where it received the message. This should already be in place IMO, because currently you are sending all messages in the default

Since rpmsg_create_ept creates a new local endpoint address on the Linux side, how is the remote system expected to learn and use this new address for communication if no additional logic is added on the remote

side?

Remote side learns the endpoint when it receives any message from Linux from the dynamic endpoint.

Lets say rpmsg_create_ept() allocates a dynamic local ept of 1026. When you send the message from this endpoint, the standard rpmsg header would have:

      85 struct rpmsg_hdr {
      86         __rpmsg32 src; // 1026
      87         __rpmsg32 dst; // rpdev->dst (e.g. 400)
      88         __rpmsg32 reserved;
      89         __rpmsg16 len;
      90         __rpmsg16 flags;
      91         u8 data[];
      92 } __packed;

Remote side tracks the dynamic endpoint by reading src = 1026. And while sending the response it fills the header as:

Quoted 9 lines
      85 struct rpmsg_hdr {
      86         __rpmsg32 src; // 400
      87         __rpmsg32 dst; // 1026
      88         __rpmsg32 reserved;
      89         __rpmsg16 len;
      90         __rpmsg16 flags;
      91         u8 data[];
      92 } __packed;
Quoted 5 lines

This explains how reply messages work in this scenario: the remote side can simply send the response back to the source address of the incoming message.

How does this work for notification messages initiated by the remote side? Should the remote system need to add additional logic to track the source address based on the GPIO instance?

You should already have the tracking logic in firmware. How else are you sending the notification messages from firmware with your current v13 implementation? Are you assuming the channel address to be always the same? If so, this is a bug and should be fixed in firmware because the address is generated dynamically. For example, if another core announces its name service first, then the channel address for your core would be different and the functionality would break.

Instead, you should have a map of ept to port idx in the firmware side when you receive a message from Linux (just like we would maintain it in struct rpmsg_gpio_port in Linux too).

Thanks,
Beleswar

[...]

#60 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 90 lines

-----Original Message-----
From: Padhi, Beleswar <[email protected]>
Sent: Wednesday, April 29, 2026 9:36 AM
To: Shenwei Wang <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>
Cc: Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>; Andrew Lunn <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 30 lines · Shenwei Wang
Quoted 30 lines

-----Original Message-----
From: Padhi, Beleswar <[email protected]>
Sent: Tuesday, April 28, 2026 10:53 AM
To: Shenwei Wang <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Mathieu Poirier <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>
Cc: Shuah Khan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; dl-linux-imx <[email protected]>; Bartosz Golaszewski <[email protected]>; Andrew Lunn <[email protected]>
Subject: [EXT] Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 9 lines
Quoted 5 lines

Nothing extra in my opinion. rpmsg_create_ept() just creates a dynamic local endpoint address for Linux's usage. The firmware just has to make sure to reply to the same endpoint address where it received the message. This should already be in place IMO, because currently you are sending all messages in the default

Since rpmsg_create_ept creates a new local endpoint address on the Linux side, how is the remote system expected to learn and use this new address for communication if no additional logic is added on the remote

Quoted 8 lines
Quoted 8 lines

side?

Remote side learns the endpoint when it receives any message from Linux from the dynamic endpoint.

Lets say rpmsg_create_ept() allocates a dynamic local ept of 1026. When you send the message from this endpoint, the standard rpmsg header

would have:

Quoted 22 lines
Quoted 13 lines
      85 struct rpmsg_hdr {
      86         __rpmsg32 src; // 1026
      87         __rpmsg32 dst; // rpdev->dst (e.g. 400)
      88         __rpmsg32 reserved;
      89         __rpmsg16 len;
      90         __rpmsg16 flags;
      91         u8 data[];
      92 } __packed;

Remote side tracks the dynamic endpoint by reading src = 1026. And while sending the response it fills the header as:

Quoted 9 lines
      85 struct rpmsg_hdr {
      86         __rpmsg32 src; // 400
      87         __rpmsg32 dst; // 1026
      88         __rpmsg32 reserved;
      89         __rpmsg16 len;
      90         __rpmsg16 flags;
      91         u8 data[];
      92 } __packed;
Quoted 2 lines

This explains how reply messages work in this scenario: the remote side can simply send the response back to the source address of the incoming

message.

Quoted 3 lines

How does this work for notification messages initiated by the remote side? Should the remote system need to add additional logic to track the source

address based on the GPIO instance?

Quoted 7 lines

You should already have the tracking logic in firmware. How else are you sending the notification messages from firmware with your current v13 implementation? Are you assuming the channel address to be always the same? If so, this is a bug and should be fixed in firmware because the address is generated dynamically. For example, if another core announces its name service first, then the channel address for your core would be different and the functionality would break.

In the v13 implementation, all GPIO instances share the default endpoint. As a result, the firmware does not need to track the port index, since the port index is embedded in each message.

With the new approach you proposed, we would create a separate endpoint for each GPIO controller. The GPIO controller information is derived from the corresponding DTS node, and the port index continues to be embedded in every message exchanged with the remote side, in accordance with the current message protocol.

However, in this model, the firmware still needs to add logic to track the mapping between the port index and the corresponding endpoint for notifications initiated by the remote side. Am I understanding this correctly?

Thanks,
Shenwei

Quoted 8 lines

Instead, you should have a map of ept to port idx in the firmware side when you receive a message from Linux (just like we would maintain it in struct rpmsg_gpio_port in Linux too).

Thanks,
Beleswar

[...]

#61 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

In reply to Padhi, Beleswar
Quoted 16 lines

Remote side learns the endpoint when it receives any message from Linux from the dynamic endpoint.

Lets say rpmsg_create_ept() allocates a dynamic local ept of 1026. When you send the message from this endpoint, the standard rpmsg header would have:

    85 struct rpmsg_hdr {
    86         __rpmsg32 src; // 1026
    87         __rpmsg32 dst; // rpdev->dst (e.g. 400) 88         __rpmsg32 reserved;
    89         __rpmsg16 len;
    90         __rpmsg16 flags;
    91         u8 data[];
    92 } __packed;

Quoted 2 lines

Remote side tracks the dynamic endpoint by reading src = 1026. And while sending the response it fills the header as:

I've never used rpmsg, so this might be a FAQ. How does the remote side know what the endpoint is to be used for? Here we are talking about GPIO. But the same hardware implements I2C, and a few other things. How do we indicate this endpoint is for GPIO?

Maybe also related, this hardware also supports a number of GPIO controllers. There has been some argument about if one endpoint should support multiple GPIO controllers. Or, like gpio-virtio, one endpoint represents one GPIO controller, and you instantiate multiple endpoints, one per controller. How can you tell the different instances of GPIO endpoints apart when they are dynamically created?

Andrew

#62 lore raw

Re: [PATCH v13 3/4] gpio: rpmsg: add generic rpmsg GPIO driver

Quoted 16 lines · Andrew Lunn
Quoted 16 lines

Remote side learns the endpoint when it receives any message from Linux from the dynamic endpoint.

Lets say rpmsg_create_ept() allocates a dynamic local ept of 1026. When you send the message from this endpoint, the standard rpmsg header would have:

    85 struct rpmsg_hdr {
    86         __rpmsg32 src; // 1026
    87         __rpmsg32 dst; // rpdev->dst (e.g. 400) 88         __rpmsg32 reserved;
    89         __rpmsg16 len;
    90         __rpmsg16 flags;
    91         u8 data[];
    92 } __packed;

Quoted 6 lines
Quoted 2 lines

Remote side tracks the dynamic endpoint by reading src = 1026. And while sending the response it fills the header as:

I've never used rpmsg, so this might be a FAQ. How does the remote side know what the endpoint is to be used for? Here we are talking about GPIO. But the same hardware implements I2C, and a few other things. How do we indicate this endpoint is for GPIO?

That's where the channel level isolation helps. GPIO ports are announced over "rpmsg-io" channel (parent of endpoint), i2c devices would be announced over "rpmsg-i2c" channel. The default epts in those channels would have separate addresses (e.g. 0xd for rpmsg-io and 0xe for rpmsg-i2c). The remote side would have bound a gpio_handling callback on addr 0xd and a i2c_handling callback on addr 0xe while doing the channel announcement. So while sending a GPIO msg from Linux, we should direct it to 0xd dst endpoint, and for sending a i2c message, we should direct it to 0xe dst endpoint (src ept can be anything). And without any extra effort, messages sent from dynamic epts at Linux land in the appropriate handler at remote even for separate device types.

Quoted 4 lines

Maybe also related, this hardware also supports a number of GPIO controllers. There has been some argument about if one endpoint should support multiple GPIO controllers.

IMO no...

Quoted 3 lines

Or, like gpio-virtio, one endpoint
represents one GPIO controller, and you instantiate multiple endpoints, one per controller.

Yes, this is what I am suggesting in the review of this version. Basically there should be one rpmsg channel per device type (e.g. gpio/i2c), and multiple rpmsg endpoints in one channel representing each instance of the device (e.g. gpio1, gpio2 etc.)

Quoted 2 lines

How can you tell the different
instances of GPIO endpoints apart when they are dynamically created?

Well by 2 ways:
1. We can maintain a map of the dynamically created ept and its corresponding instance number.This is useful while sending a message for a particular instance.
2. rpmsg_create_ept() takes a private data argument, so we just bind the per-instance data (struct rpmsg_gpio_port * in this case) to the ept. This is useful while receiving a message for a particular instance.

I have suggested an implementation for the same here:
https://lore.kernel.org/all/[email protected]/

Thanks,
Beleswar

#63 lore raw

PATCH v13 4/4 arm64: dts: imx8ulp: Add rpmsg node under imx_rproc

In reply to Shenwei Wang

Add the RPMSG bus node along with its GPIO subnodes to the device tree.

Enable remote device communication and GPIO control via RPMSG on the i.MX platform.

---
 arch/arm64/boot/dts/freescale/imx8ulp.dtsi | 25 ++++++++++++++++++++++
 1 file changed, 25 insertions(+)
arch/arm64/boot/dts/freescale/imx8ulp.dtsi +25 -0
index 1de3ad60c6aa..f1b984eb1203 100644
@@ -190,6 +190,31 @@ scmi_sensor: protocol@15 {
 	cm33: remoteproc-cm33 {
 		compatible = "fsl,imx8ulp-cm33";
 		status = "disabled";
+
+		rpmsg {
+			rpmsg-io {
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				rpmsg_gpioa: gpio@0 {
+					compatible = "rpmsg-gpio";
+					reg = <0>;
+					gpio-controller;
+					#gpio-cells = <2>;
+					#interrupt-cells = <2>;
+					interrupt-controller;
+				};
+
+				rpmsg_gpiob: gpio@1 {
+					compatible = "rpmsg-gpio";
+					reg = <1>;
+					gpio-controller;
+					#gpio-cells = <2>;
+					#interrupt-cells = <2>;
+					interrupt-controller;
+				};
+			};
+		};
 	};
 
 	soc: soc@0 {
Signature · 1 line
2.43.0
maintainer
#64 lore raw
In reply to Shenwei Wang

Once again Andrew Lunn was left out.

Quoted 95 lines · Shenwei Wang

Support the remote devices on the remote processor via the RPMSG bus on i.MX platform.

Changes in v13:
- drop the support for legacy NXP firmware.
- remove the fixed_up hooks from the rpmsg gpio driver.
- code cleanup.

Changes in v12:
- Fixed the "underline" warning reported by Randy.

Changes in v11:
- Expand RPMSG for the first time per Shuah's review comment.

Changes in v10:
- Update gpio-rpmsg.rst according to Daniel Baluta's review comments.
- Add a kernel CONFIG for fixed up handlers and only enable it on i.MX products.
- Fixed bugs reported by kernel test robot.

Changes in v9:
- Reuse the gpio-virtio design for command and IRQ type definitions.
- Remove msg_id, version, and vendor fields from the generic protocol.
- Add fixed-up handlers to support legacy firmware.

Changes in v8:
- Add "depends on REMOTEPROC" in Kconfig to fix the build error reported by the kernel test robot.
- Move the .rst patch before the .yaml patch.
- Handle the "ngpios" DT property based on Andrew's feedback.

Changes in v7:
- Reworked the driver to use the rpmsg_driver framework instead of platform_driver, based on feedback from Bjorn and Arnaud.
- Updated gpio-rpmsg.yaml and imx_rproc.yaml according to comments from Rob and Arnaud.
- Further refinements to gpio-rpmsg.yaml per Arnaud's feedback.

Changes in v6:
- make the driver more generic with the actions below:
rename the driver file to gpio-rpmsg.c
remove the imx related info in the function and variable names rename the imx_rpmsg.h to rpdev_info.h
create a gpio-rpmsg.yaml and refer it in imx_rproc.yaml
- update the gpio-rpmsg.rst according to the feedback from Andrew and move the source file to driver-api/gpio
- fix the bug reported by Zhongqiu Han
- remove the I2C related info

Changes in v5:
- move the gpio-rpmsg.rst from admin-guide to staging directory after discussion with Randy Dunlap.
- add include files with some code improvements per Bartosz's comments.

Changes in v4:
- add a documentation to describe the transport protocol per Andrew's comments.
- add a new handler to get the gpio direction.

Changes in v3:
- fix various format issue and return value check per Peng 's review comments.
- add the logic to also populate the subnodes which are not in the device map per Arnaud's request. (in imx_rproc.c)
- update the yaml per Frank's review comments.

Changes in v2:
- re-implemented the gpio driver per Linus Walleij's feedback by using GPIOLIB_IRQCHIP helper library.
- fix various format issue per Mathieu/Peng 's review comments.
- update the yaml doc per Rob's feedback

Shenwei Wang (4):
docs: driver-api: gpio: rpmsg gpio driver over rpmsg bus
dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support
gpio: rpmsg: add generic rpmsg GPIO driver
arm64: dts: imx8ulp: Add rpmsg node under imx_rproc

 .../devicetree/bindings/gpio/gpio-rpmsg.yaml  |  55 ++
 .../bindings/remoteproc/fsl,imx-rproc.yaml    |  53 ++
 Documentation/driver-api/gpio/gpio-rpmsg.rst  | 266 ++++++++
 Documentation/driver-api/gpio/index.rst       |   1 +
 arch/arm64/boot/dts/freescale/imx8ulp.dtsi    |  25 +
 drivers/gpio/Kconfig                          |  17 +
 drivers/gpio/Makefile                         |   1 +
 drivers/gpio/gpio-rpmsg.c                     | 573 ++++++++++++++++++
 8 files changed, 991 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-rpmsg.yaml
 create mode 100644 Documentation/driver-api/gpio/gpio-rpmsg.rst
 create mode 100644 drivers/gpio/gpio-rpmsg.c

--
2.43.0

#65 lore raw
Quoted 11 lines · Mathieu Poirier

Once again Andrew Lunn was left out.

Quoted 8 lines · Shenwei Wang

Support the remote devices on the remote processor via the RPMSG bus on i.MX platform.

Changes in v13:
- drop the support for legacy NXP firmware.
- remove the fixed_up hooks from the rpmsg gpio driver.
- code cleanup.

That looks like a step forward. Now we don't care about legacy NXP firmware, it makes it easier to make bigger changes, like use the messages format from gpio-virtio.

Andrew

#66 lore raw
Quoted 35 lines

-----Original Message-----
From: Andrew Lunn <[email protected]>
Sent: Thursday, April 23, 2026 8:54 AM
To: Mathieu Poirier <[email protected]>
Cc: Shenwei Wang <[email protected]>; Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux- [email protected]; [email protected]; [email protected]; Pengutronix Kernel Team <[email protected]>; Fabio Estevam <[email protected]>; Peng Fan <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-linux-imx <linux- [email protected]>
Subject: [EXT] Re: [PATCH v13 0/4] Enable Remote GPIO over RPMSG on i.MX Platform

Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button

Quoted 3 lines · Mathieu Poirier

Once again Andrew Lunn was left out.

On Wed, 22 Apr 2026 at 15:29, Shenwei Wang <[email protected]>

Quoted 4 lines · wrote:
Quoted 4 lines

Support the remote devices on the remote processor via the RPMSG bus on i.MX platform.

Quoted 9 lines
Quoted 4 lines
Quoted 4 lines

Changes in v13:
- drop the support for legacy NXP firmware.
- remove the fixed_up hooks from the rpmsg gpio driver.
- code cleanup.

That looks like a step forward. Now we don't care about legacy NXP firmware, it makes it easier to make bigger changes, like use the messages format from gpio- virtio.

The implementation adopts the gpio‑virtio design, including its commands, parameters, and error codes.

Shenwei

Quoted 1 line

Andrew

#67 lore raw
In reply to Mathieu Poirier
Quoted 12 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: Thursday, April 23, 2026 7:53 AM
To: Shenwei Wang <[email protected]>; Andrew Lunn <[email protected]>
Cc: Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Jonathan Corbet <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; Bjorn Andersson <[email protected]>; Frank Li <[email protected]>; Sascha Hauer <[email protected]>; Shuah Khan <[email protected]>; linux-

Quoted 2 lines

Once again Andrew Lunn was left out.

Seems an issue of get_maintainer.pl, but he is included in the thread for the gpio‑rpmsg driver patch..
Cc: Andrew Lunn <[email protected]>

Quoted 98 lines
Quoted 96 lines · Shenwei Wang

Support the remote devices on the remote processor via the RPMSG bus on i.MX platform.

Changes in v13:
- drop the support for legacy NXP firmware.
- remove the fixed_up hooks from the rpmsg gpio driver.
- code cleanup.

Changes in v12:
- Fixed the "underline" warning reported by Randy.

Changes in v11:
- Expand RPMSG for the first time per Shuah's review comment.

Changes in v10:
- Update gpio-rpmsg.rst according to Daniel Baluta's review comments.
- Add a kernel CONFIG for fixed up handlers and only enable it on i.MX products.
- Fixed bugs reported by kernel test robot.

Changes in v9:
- Reuse the gpio-virtio design for command and IRQ type definitions.
- Remove msg_id, version, and vendor fields from the generic protocol.
- Add fixed-up handlers to support legacy firmware.

Changes in v8:
- Add "depends on REMOTEPROC" in Kconfig to fix the build error reported by the kernel test robot.
- Move the .rst patch before the .yaml patch.
- Handle the "ngpios" DT property based on Andrew's feedback.

Changes in v7:
- Reworked the driver to use the rpmsg_driver framework instead of platform_driver, based on feedback from Bjorn and Arnaud.
- Updated gpio-rpmsg.yaml and imx_rproc.yaml according to comments from Rob and Arnaud.
- Further refinements to gpio-rpmsg.yaml per Arnaud's feedback.

Changes in v6:
- make the driver more generic with the actions below:
rename the driver file to gpio-rpmsg.c
remove the imx related info in the function and variable names rename the imx_rpmsg.h to rpdev_info.h
create a gpio-rpmsg.yaml and refer it in imx_rproc.yaml
- update the gpio-rpmsg.rst according to the feedback from Andrew and move the source file to driver-api/gpio
- fix the bug reported by Zhongqiu Han
- remove the I2C related info

Changes in v5:
- move the gpio-rpmsg.rst from admin-guide to staging directory after discussion with Randy Dunlap.
- add include files with some code improvements per Bartosz's comments.

Changes in v4:
- add a documentation to describe the transport protocol per Andrew's comments.
- add a new handler to get the gpio direction.

Changes in v3:
- fix various format issue and return value check per Peng 's review comments.
- add the logic to also populate the subnodes which are not in the device map per Arnaud's request. (in imx_rproc.c)
- update the yaml per Frank's review comments.

Changes in v2:
- re-implemented the gpio driver per Linus Walleij's feedback by using GPIOLIB_IRQCHIP helper library.
- fix various format issue per Mathieu/Peng 's review comments.
- update the yaml doc per Rob's feedback

Shenwei Wang (4):
docs: driver-api: gpio: rpmsg gpio driver over rpmsg bus
dt-bindings: remoteproc: imx_rproc: Add "rpmsg" subnode support
gpio: rpmsg: add generic rpmsg GPIO driver
arm64: dts: imx8ulp: Add rpmsg node under imx_rproc

 .../devicetree/bindings/gpio/gpio-rpmsg.yaml  |  55 ++
 .../bindings/remoteproc/fsl,imx-rproc.yaml    |  53 ++
 Documentation/driver-api/gpio/gpio-rpmsg.rst  | 266 ++++++++
 Documentation/driver-api/gpio/index.rst       |   1 +
 arch/arm64/boot/dts/freescale/imx8ulp.dtsi    |  25 +
 drivers/gpio/Kconfig                          |  17 +
 drivers/gpio/Makefile                         |   1 +
 drivers/gpio/gpio-rpmsg.c                     | 573 ++++++++++++++++++
 8 files changed, 991 insertions(+)
 create mode 100644
Documentation/devicetree/bindings/gpio/gpio-rpmsg.yaml
 create mode 100644 Documentation/driver-api/gpio/gpio-rpmsg.rst
 create mode 100644 drivers/gpio/gpio-rpmsg.c

--
2.43.0