Skip to content

drivers/rptun: replace the command mailbox with a status bitmap - #21542

Merged
GUIDINGLI merged 14 commits into
apache:masterfrom
CV-Bowen:up/P57-rptun-status
Nov 11, 2026
Merged

GUIDINGLI merged 14 commits into
apache:masterfrom
CV-Bowen:up/P57-rptun-status

Conversation

@CV-Bowen

@CV-Bowen CV-Bowen commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Replace the rptun command mailbox in the resource table with a status
bitmap, and fold the panic API into reset.

  • include/sys/boardctl.h: define the reset cause types
    unconditionally; rptun exchanges BOARDIOC_SOFTRESETCAUSE_* with the
    peer also without CONFIG_BOARDCTL_RESET.
  • Fold RPTUNIOC_PANIC, RPTUN_CMD_PANIC and ops->panic into reset
    with BOARDIOC_SOFTRESETCAUSE_PANIC as the value; ops->reset and
    rptun_reset() take an unsigned long reason and ops->reset
    returns int. stm32h7 and nrf53 are converted.
  • One panic notifier and one reboot notifier (stop the peers on
    restart/poweroff) for all rptun devices.
  • Number RPTUNIOC_* from 1 now that rptun has its own ioctl base.
  • Replace the master/slave command words with a status bitmap per side:
    a core sets the bit of its reset reason, flushes it and notifies the
    peer, which panics or resets. ivshmem uses hdr.ver as its ready
    flag and sim drops its stop command, both of which used the command
    words. ops->reset returning -ENOTSUP falls back to the bitmap.
    RPTUN_CMD_TIMEOUT_MS becomes RPTUN_STATUS_TIMEOUT_MS.
  • Smaller fixes on the way: skip status handling before the resource
    table is loaded, and return the reset result from RPTUNIOC_RESET.
  • The first commit fixes nxstyle errors already on master in the three
    arch rptun drivers.

Impact

API/ABI break for rptun users: rptun_panic(), RPTUN_PANIC(),
ops->panic and RPTUNIOC_PANIC are removed (use rptun_reset()
with BOARDIOC_SOFTRESETCAUSE_PANIC); ops->reset is now
int (*)(dev, unsigned long); RPTUNIOC_* values change. Both cores
of a link must run this version, since the resource table words change
meaning. Kconfig: RPTUN_CMD_TIMEOUT_MS is renamed
RPTUN_STATUS_TIMEOUT_MS. nsh's rptun command and nxinit only need a
rebuild.

Testing

Host: Ubuntu 22.04.5 LTS x86_64, QEMU version 10.2.1, sim: cc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, qemu-armv8a: aarch64-none-elf-gcc (Arm GNU Toolchain 12.2.Rel1 (Build arm-12.24)) 12.2.1 20221205

Every commit builds without warnings on sim:rpserver,
qemu-armv8a:rpserver, qemu-armv7a:rpserver, nucleo-h745zi:nsh_cm7_rptun,
nucleo-h745zi:nsh_cm4_rptun, nrf5340-dk:rptun_cpuapp and
nrf5340-dk:rptun_cpunet.

Reset reasons over the status bitmap, qemu-armv8a:rpserver +
qemu-armv8a:rpproxy (ivshmem rptun), booted as in their README; from
the server:

server> rpmsg ping all 3 64 3 0
server> rptun reset /dev/rptun/proxy 2     # BOARDIOC_SOFTRESETCAUSE_PANIC
master this PR
ping 3/3 3/3
reset ... 2 (panic) the value goes out as a plain reset; the proxy asserts in its rx interrupt (see below) proxy: FATAL: Panic by remote core: server and panics

rptun reset /dev/rptun/proxy 0 (user reboot) asserts on the proxy on
master and with this PR alike: the peer runs boardctl(BOARDIOC_RESET)
from its rx notification in interrupt context, and the reboot notifier
of rpmsg_port_uart then waits on an event:

Assertion failed event != ((void*)0) && (...)
  at file: /sched/event/event_wait.c:120 task: Idle_Task
nxevent_tickwait / rpmsg_port_uart_reboot_notifier / boardctl
rptun_check_peer_status (rptun_check_command on master) / rptun_callback
rptun_ivshmem_wdog / wd_timer / arm64_arch_timer_compare_isr

Deferring that boardctl() to a work queue is left to a follow-up PR.

Not run: stm32h7 and nrf53 on hardware (build only).

Baseline: No regression in rpmsg: sim:rpserver/rpproxy and qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping, rpmsgfs; 15/15). qemu-armv8a was built with LIBC_ENVPATH and BINFMT_CHECKEXEC disabled, which current master needs for nxinit to start nsh there; unrelated to this change.

@github-actions github-actions Bot added Arch: arm Issues related to ARM (32-bit) architecture Arch: simulator Issues related to the SIMulator Area: Drivers Drivers issues Size: M The size of the change in this PR is medium labels Nov 7, 2026
acassis
acassis previously approved these changes Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

CV-Bowen and others added 14 commits November 9, 2026 21:02
Add the blank line after declarations that tools/nxstyle requires,
so later changes to these files pass checkpatch.  No functional change.

Signed-off-by: Bowen Wang <[email protected]>
enum boardioc_reset_cause_e and enum boardioc_softreset_subreason_e were
only defined with CONFIG_BOARDCTL and CONFIG_BOARDCTL_RESET or
CONFIG_BOARDCTL_RESET_CAUSE. rptun uses BOARDIOC_SOFTRESETCAUSE_* as the
reset reason it exchanges with the peer, also on configurations without
those options (e.g. sim:rpserver, icicle:rpmsg-ch1), so define them
outside both guards.

Signed-off-by: Bowen Wang <[email protected]>
A panic is one reason to reset the peer, so fold RPTUNIOC_PANIC,
RPTUN_CMD_PANIC and ops->panic into RPTUNIOC_RESET, RPTUN_CMD_RESET and
ops->reset, with BOARDIOC_SOFTRESETCAUSE_PANIC as the value. ops->reset
and rptun_reset() take an unsigned long reason; the stm32h7 and nrf53
drivers signal their panic channel for that value.

Signed-off-by: Bowen Wang <[email protected]>
Each rptun device registered its own panic notifier that reset only
that peer. Register one notifier and reset all peers through
rptun_ioctl_foreach(), as the reboot notifier added next does.

Signed-off-by: Bowen Wang <[email protected]>
Register a reboot notifier, called last, that stops all peers on
SYS_RESTART and SYS_POWER_OFF, so they shut down with this core.

Signed-off-by: Bowen Wang <[email protected]>
The rptun ioctls have their own _RPTUNBASE now, so they no longer
need to start at 100 to stay clear of the rpmsg ones.

Signed-off-by: Bowen Wang <[email protected]>
The slave signalled that its resource table was ready with
RPTUN_CMD_READY in the command words, which the status bitmap replaces.
Write hdr.ver last instead, and have the master poll it.

Signed-off-by: wangshaoxin <[email protected]>
Signed-off-by: Bowen Wang <[email protected]>
sim_rptun stopped the peer with RPTUN_CMD_STOP in the command words,
which the status bitmap replaces; the peer is stopped through the
regular rptun stop path.

Signed-off-by: wangshaoxin <[email protected]>
Signed-off-by: Bowen Wang <[email protected]>
The master and slave command words in the resource table carried one
command at a time and needed an ack, so a command could be lost and a
core could not tell which state its peer was in. Replace them with a
status bitmap per side: each core sets the bit of its reset reason
(BOARDIOC_SOFTRESETCAUSE_*) and notifies the peer, which panics or
resets accordingly.

Signed-off-by: wangshaoxin <[email protected]>
ops->reset returns int, so rptun can tell whether the driver handled
the reset. The stm32h7 and nrf53 drivers return OK.

Signed-off-by: wangshaoxin <[email protected]>
Signed-off-by: Bowen Wang <[email protected]>
Use ops->reset when the driver has one; if it returns -ENOTSUP, or
there is none, set the reason in the status bitmap. Any other error is
returned as is.

Signed-off-by: wangshaoxin <[email protected]>
Signed-off-by: Bowen Wang <[email protected]>
rptun_dev_reset() and rptun_check_peer_status() can run before the
resource table is loaded; return instead of dereferencing a NULL
rsc_table.

Signed-off-by: wangshaoxin <[email protected]>
Signed-off-by: Bowen Wang <[email protected]>
Return -EINVAL when the resource table is not ready and the result of
ops->reset otherwise, instead of always reporting success.

Signed-off-by: Bowen Wang <[email protected]>
The status bitmap lives in the resource table, which may be cacheable.
Flush it after setting a bit and invalidate it before reading the
peer's, with RPTUN_FLUSH()/RPTUN_INVALIDATE() (no-ops without
CONFIG_OPENAMP_CACHE).

Signed-off-by: Bowen Wang <[email protected]>
@CV-Bowen
CV-Bowen force-pushed the up/P57-rptun-status branch from ef71d8c to a5e8982 Compare November 9, 2026 14:26
@GUIDINGLI
GUIDINGLI merged commit e8b03da into apache:master Nov 11, 2026
54 checks passed
xiaoxiang781216 pushed a commit that referenced this pull request Nov 12, 2026
verdin-mx8mp:rpmsg runs from the 128 KB ITCM.  After #21582 and #21542
the image does not fit (CI):

  arm-none-eabi-ld: region `flash' overflowed by 112 bytes

The rpmsg configuration has CONFIG_LIBC_LOCALE from the nsh
configuration of the board, where the C++ library needs it.  The rpmsg
configuration has no C++ and nothing in it uses locale support.  Disable
it: this saves 352 bytes.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: arm Issues related to ARM (32-bit) architecture Arch: simulator Issues related to the SIMulator Area: Drivers Drivers issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants