Commit graph

102 commits

Author SHA1 Message Date
yintao
f671ec648e drivers/rpmsg: add signals router for rpmsg router
Now the rpmsg router transport also support get the signals, and
this signals value is modified by other physical rpmsg transport
(port, virtio) other routed by the rpmsg router.

Signed-off-by: yintao <yintao@xiaomi.com>
2026-01-15 16:13:24 -03:00
yintao
492abaa052 drivers/rpmsg: unitfy the rpmsg signals from transport to struct rpmsg_s
Now all the rpmsg transport use the signals in struct rpmsg_s instead
add element in its own private struct.

Signed-off-by: yintao <yintao@xiaomi.com>
2026-01-15 16:13:24 -03:00
Bowen Wang
2a8acac159 rpmsg/rpmsg_port_uart: drop all the packets when reconnect to peer
1. move drop packets function from port spi to port;
2. add drop packets logic when reconnect to peer;

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Signed-off-by: liaoao <liaoao@xiaomi.com>
2026-01-09 09:48:18 +08:00
Bowen Wang
3d764939c8 rpmsg/rpmsg_port_uart: set the signals based on the suspend/reusme state
Now peer's state can be get by the rpmsg_get_signals() api

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2026-01-09 09:48:18 +08:00
Bowen Wang
b8ad562fcb rpmsg/rpmsg_port_uart: add poweroff support
Peer can send poweroff command and local will shutdown the uart
device and wait for the next connect

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2026-01-09 09:48:18 +08:00
Bowen Wang
8ba084329d rpmsg/rpmsg_port_uart: add wakeup feauture for rpmsg_port_uart
Wakeup peer when peer is in low power mode

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2026-01-09 09:48:18 +08:00
mazhuang
45f6d86f37 drivers/rpmsg: add rpmsg_test to test rpmsg hold/release rx buffer
rpmsg_test is a rpmsg api test service inside the kernel, and user
can use ioctl to start this test.

Signed-off-by: mazhuang <mazhuang@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Signed-off-by: wangshaoxin <wangshaoxin@xiaomi.com>
2026-01-08 22:44:35 +08:00
Bowen Wang
f4cfc9579d drivers/rptun: change the notify wait return type after upgrade OpenAMP
return -EAGAIN will cause rpmsg_virtio_get_tx_payload_buffer() in
OpenAMP break immediately, but should return to the sleep() logic
to wait buffer is return.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2026-01-08 12:05:46 +08:00
Yongrong Wang
9d6edc37e7 rpmsg: fix rpmsg dead lock and ns bind race condition problem
If a ns_bind message come at between traverse g_rpmsg_cb and add g_rpmsg_cb list,
the cb->node has not been added to the g_rpmsg_cb list yet.
So rpmsg_ns_bind will not find this callback and not call the cb->ns_bind()
to notify the rpmsg services.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2026-01-07 22:47:09 +08:00
liaoao
f9272fa090 rpmsg_port_spi: fix reconnect failed issue
The reconnect will fail because the state changes to connecting when
shutdown cmd is still in process.

And after the shutdown cmd processed, it will reset the state to
unconnected, even though the connect cmd is in ready list,
it will still not be processed.

This patch solve this issue.

Signed-off-by: liaoao <liaoao@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2026-01-07 22:47:00 +08:00
liaoao
bc58b0d837 rpmsg_port_spi/slave: fix the reconnect issue during shutdown process
If connect cmd is dropped during the shutdown cmd process, it will
not be able to reconnect because current side will not try to send
connect cmd after shutdown cmd processed.

So change state to connecting when received connect cmd during the
shutdown cmd process.

Signed-off-by: liaoao <liaoao@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2026-01-07 22:47:00 +08:00
liaoao
ec06af22b8 rpmsg_port_spi.c: setfreq to 0 to shutdown the spi device
In the stop process, add SPI_SETFREQUENCY(rpspi->spi, 0) to stutdown
the spi device.

Signed-off-by: liaoao <liaoao@xiaomi.com>
2026-01-07 22:47:00 +08:00
liaoao
1fba4986c9 rpmsg_port_spi/slave: add suspend/resume notify
Now rpmsg port spi can receive peer's suspend and resume command,
suspend command means peer enter into the lowpower state and
resume command means peer waked up

These two commands can let us know peer's running status, so we
will modify the rpmsg signals to let the rpmsg service can get
peer's running state too.

Signed-off-by: liaoao <liaoao@xiaomi.com>
2026-01-07 22:47:00 +08:00
liaoao
a41c2cb741 rpmsg_port_spi: add support for peer's shutting down notify
Shutdown mean peer's want to disconnect the connection untial
peer want connect with local side again.

After receive shutdown command, local will clear the state until
reconnecting and clear the gpio status to avoid the leak current.

Signed-off-by: liaoao <liaoao@xiaomi.com>
2026-01-07 22:47:00 +08:00
liaoao
01b022fdd0 rpmsg_port_spi_slave: only drop tx queue used buffer when unconnecting
because rxq may have received peer's reconnection data, so we can
connect with peer again.

Signed-off-by: liaoao <liaoao@xiaomi.com>
2026-01-07 22:47:00 +08:00
liaoao
972dae38a2 rpmsg_port_spi: add connecting/disconnecting status for port spi
to make sure the connecting process will not be interrupted

Signed-off-by: liaoao <liaoao@xiaomi.com>
2026-01-07 22:47:00 +08:00
liaoao
d4a787aebf rpmsg_port_spi: only drop tx queue used buffer when unconnecting
Because rxq may have received reconnection data, when connect state
changed to unconnected but the reconnect data has not been processed,
and during that time there is a tx buffer to be sent, the
drop_packets may drop the reconnect data and two sides can not
reconnected anymore.

Signed-off-by: liaoao <liaoao@xiaomi.com>
2026-01-07 22:47:00 +08:00
liaoao
39ff211469 rpmsg_port_spi: add log to know spi complete callback not called
1. add error log when transferring keeps rasing because of no spi
exchange complete callback;
2. this log can also be used to check if there is an interrupt has
been caught when peer side keeps trying to send data;

Signed-off-by: liaoao <liaoao@xiaomi.com>
2026-01-07 22:47:00 +08:00
liaoao
880160bfca rpmsg_port_spi: add more detail debug info for transfer failed
Add log to know the error command and aviable buffer number

Signed-off-by: liaoao <liaoao@xiaomi.com>
2026-01-07 22:47:00 +08:00
yintao
ad08484cdb rpmsg: fix rpmsg_router_hub_unbind crash when reconnect
0x106b9ad2 in metal_list_del (node=<optimized out>) at /home/yintao/O61/nuttx/include/metal/list.h:85
rpmsg_unregister_endpoint (ept=0x1857ba30) at open-amp/lib/rpmsg/rpmsg.c:296
rpmsg_destroy_ept (ept=0x1857ba30) at open-amp/lib/rpmsg/rpmsg.c:389
0x102b871a in rpmsg_router_hub_unbind (ept=0x1857b330) at rpmsg/rpmsg_router_hub.c:139
0x102b7fec in rpmsg_device_destory (rpmsg=rpmsg@entry=0x1859e4e8) at rpmsg/rpmsg.c:486
0x102b9928 in rpmsg_port_unregister (port=port@entry=0x1859e4e8) at rpmsg/rpmsg_port.c:749
0x102b9bca in rpmsg_port_spi_process_packet (rxhdr=0x185ba718, rpspi=<optimized out>) at rpmsg/rpmsg_port_spi.c:408
rpmsg_port_spi_thread (argc=<optimized out>, argv=<optimized out>) at rpmsg/rpmsg_port_spi.c:452
0x102aa96e in nxtask_start () at task/task_start.c:111

Signed-off-by: yintao <yintao@xiaomi.com>
2026-01-07 22:41:48 +08:00
yintao
773db122a3 drivers/rpmsg: fix double free at rpmsg_router_hub_unbind
/home/yintao/o61-2800/nuttx/libs/libc/assert/lib_assert.c:36
mempool_release
/home/yintao/o61-2800/nuttx/mm/mempool/mempool.c:431 (discriminator 1)
mempool_multiple_free
/home/yintao/o61-2800/nuttx/mm/mempool/mempool_multiple.c:637
mm_free
/home/yintao/o61-2800/nuttx/mm/mm_heap/mm_free.c:248
free
/home/yintao/o61-2800/nuttx/mm/umm_heap/umm_free.c:49
rpmsg_router_hub_unbind
/home/yintao/o61-2800/nuttx/drivers/rpmsg/rpmsg_router_hub.c:127
rpmsg_virtio_ns_callback
/home/yintao/o61-2800/nuttx/openamp/open-amp/lib/rpmsg/rpmsg_virtio.c:684
rpmsg_virtio_rx_callback
/home/yintao/o61-2800/nuttx/openamp/open-amp/lib/rpmsg/rpmsg_virtio.c:599
virtqueue_notification
/home/yintao/o61-2800/nuttx/openamp/open-amp/lib/virtio/virtqueue.c:600
rproc_virtio_notified
/home/yintao/o61-2800/nuttx/openamp/open-amp/lib/remoteproc/remoteproc_virtio.c:394
remoteproc_get_notification
/home/yintao/o61-2800/nuttx/openamp/open-amp/lib/remoteproc/remoteproc.c:1059
rptun_worker
/home/yintao/o61-2800/nuttx/drivers/rptun/rptun.c:324
rptun_worker
/home/yintao/o61-2800/nuttx/drivers/rptun/rptun.c:324
nxtask_start
/home/yintao/o61-2800/nuttx/sched/task/task_start.c:111

Signed-off-by: yintao <yintao@xiaomi.com>
2026-01-07 22:41:48 +08:00
liaoao
4cad404831 rpmsg_port: print remotes's running state in rpmsg_port_dump
Now rpmsg dump can print the remote core's running/sleep state

Signed-off-by: liaoao <liaoao@xiaomi.com>
2026-01-06 02:15:43 +08:00
liaoao
59d6263bec rpmsg_port: add rpmsg_port_get_signals api
And set signal_running when rpmsg devices registered

Now rpmsg port transport support to get the remote core's state
by api rpmsg_get_signals()

Signed-off-by: liaoao <liaoao@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2026-01-06 02:15:43 +08:00
Yongrong Wang
906d5a8204 rpmsg: Add rpmsg_get_signals API and rpmsg transport ops support
provide get_signals ops to the transport layer implementation.
add rpmsg_get_signals API for rpmsg service to get remote core's
status.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2026-01-06 02:15:43 +08:00
liaoao
d019a638ab rpmsg: call unbound_cb if service used as server/client when it is destroyed
Before this patch, the rpmsg services will not be destroied after
call the rpmsg_device_destory(). And will cause error after
call rpmsg_device_created() at the secound connecting witt peer.

Signed-off-by: liaoao <liaoao@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2026-01-04 21:06:10 +08:00
Bowen Wang
02ac99ae1c drivers/rpmsg: no need check held status after change to rmutex
metal_mutex has been changed to rmutex_t, so do not need check
the held status again.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2026-01-04 21:06:10 +08:00
chao an
87f134cfaa sched/sleep: replace all Signal-based sleep implement to Scheduled sleep
Nuttx currently has 2 types of sleep interfaces:

1. Signal-scheduled sleep: nxsig_sleep() / nxsig_usleep() / nxsig_nanosleep()
Weaknesses:
a. Signal-dependent: The signal-scheduled sleep method is bound to the signal framework, while some driver sleep operations do not depend on signals.
b. Timespec conversion: Signal-scheduled sleep involves timespec conversion, which has a significant impact on performance.

2. Busy sleep: up_mdelay() / up_udelay()
Weaknesses:
a. Does not actively trigger scheduling, occupy the CPU loading.

3. New interfaces: Scheduled sleep: nxsched_sleep() / nxsched_usleep() / nxsched_msleep() / nxsched_ticksleep()
Strengths:
a. Does not depend on the signal framework.
b. Tick-based, without additional computational overhead.

Currently, the Nuttx driver framework extensively uses nxsig_* interfaces. However, the driver does not need to rely on signals or timespec conversion.
Therefore, a new set of APIs is added to reduce dependencies on other modules.

(This PR also aims to make signals optional, further reducing the code size of Nuttx.)

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-10-17 14:05:02 +08:00
Lars Kruse
3ce85ca54e style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
chao an
4e1e833b05 drivers/rpmsg: correct crc16 catalogue to CRC-16/IBM
This is the pair implementation relative to the Linux kernel

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-04-10 11:45:26 +08:00
lijing.ly
6bd191e7e0 drivers/rpmsg/Kconfig: Add SPI dependency for RPMSG_PORT_SPI
If SPI dependency is not set, the following warning will be generated during compilation:

[109/1450] Building C object drivers/CMakeFiles/drivers.dir/rpmsg/rpmsg_port_spi.c.o
/data/code/nuttxspace/nuttx/drivers/rpmsg/rpmsg_port_spi.c: In function ‘rpmsg_port_spi_exchange’:
/data/code/nuttxspace/nuttx/drivers/rpmsg/rpmsg_port_spi.c:233:3: warning: implicit declaration of function ‘SPI_EXCHANGE’ [-Wimplicit-function-declaration]
  233 |   SPI_EXCHANGE(rpspi->spi, txhdr, rpspi->rxhdr,
      |   ^~~~~~~~~~~~
[1450/1450] Pac SIM with dynamic libs in nuttx.tgz

Signed-off-by: lijing.ly <lijing.ly@bytedance.com>
2025-02-19 14:52:22 -03:00
chao an
45f2a4b2cb drivers/rpmsg_port_uart: remove debug message of datalen
datalen message after file_read is always 0

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-01-23 18:14:16 +08:00
wangjianyu3
4211ce3212 drivers/rpmsg: update format string
The `file_write()` may return negative `errno`.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2025-01-22 23:18:36 +08:00
chao an
ada75b0b93 drivers/rpmsg: fix compiler warning
In file included from nuttx/drivers/rpmsg/rpmsg_port_uart.c:27:
nuttx/drivers/rpmsg/rpmsg_port_uart.c: In function ‘rpmsg_port_uart_send_connect_req’:
nuttx/drivers/rpmsg/rpmsg_port_uart.c:219:16: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
  219 |       rpmsgerr("Send connect request failed, ret=%d\n", ret);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~
      |                                                         |
      |                                                         ssize_t {aka long int}
nuttx/drivers/rpmsg/rpmsg_port_uart.c:219:51: note: format string is defined here
  219 |       rpmsgerr("Send connect request failed, ret=%d\n", ret);
      |                                                  ~^
      |                                                   |
      |                                                   int
      |                                                  %ld
nuttx/drivers/rpmsg/rpmsg_port_uart.c: In function ‘rpmsg_port_uart_send_connect_ack’:
nuttx/drivers/rpmsg/rpmsg_port_uart.c:235:16: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘ssize_t’ {aka ‘long int’} [-Wformat=]
  235 |       rpmsgerr("Send connect ack failed, ret=%d\n", ret);
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  ~~~
      |                                                     |
      |                                                     ssize_t {aka long int}
nuttx/drivers/rpmsg/rpmsg_port_uart.c:235:47: note: format string is defined here
  235 |       rpmsgerr("Send connect ack failed, ret=%d\n", ret);
      |                                              ~^
      |                                               |
      |                                               int
      |                                              %ld

Signed-off-by: chao an <anchao.archer@bytedance.com>
2025-01-22 16:54:14 +08:00
Bowen Wang
f0a3c43a54 rpmsg/rpmsg_virtio_lite: rename rpmsg_virtio to rpmsg_virtio_lite
Because rpmsg_virtio_lite is a better name to inform user that the
rpmsg virtio (original name) is a lite implementation of rpmsg virtio.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-12-28 22:43:20 -03:00
chao an
67c8159404 drivers/rpmsg: fix typo intialize -> initialize
Signed-off-by: chao an <anchao@lixiang.com>
2024-12-17 20:48:07 +08:00
zhangyuan29
dcea1b90e7 arch_atomic: only support atomic_xx and atomic64_xx function
Modify the kernel to use only atomic_xx and atomic64_xx interfaces,
avoiding the use of sizeof or typeof to determine the type of
atomic operations, thereby simplifying the kernel's atomic
interface operations.

Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
2024-12-04 14:03:14 +01:00
Alin Jerpelea
286d37026c drivers: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-11-06 18:02:25 +08:00
ligd
662bbeb33e container_of: fix compile failed cause of list.h not support container_of
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-10-23 20:10:43 +08:00
Bowen Wang
320b1b8011 rpmsg_virtio: move notify_wait_cb to struct rpmsg_virtio_device
notify_wait_cb has been moved to struct rpmsg_virtio_device, so
change rpmsg_virtio.c transport too.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-22 08:55:57 +08:00
buxiasen
ed14c1d3a6 rpmsg/virtio: fix compile issue, feature uint32_t to uint64_t
Has change the virtio feature bit to 64bit, so rpmsg virtio need
change to 64bit too.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-10-22 08:55:57 +08:00
Bowen Wang
313d6df787 include/nuttx.h: replace all the align macros to nuttx version
1. add IS_ALIGNED()  definitions for NuttX;
2. replace all the ALIGN_UP() and ALIGN_DOWN() to use common
   align implementation;

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-11 16:55:43 +08:00
Yongrong Wang
976c4173f0 rpmsg_ping.c: fix msg data memset length
The range of memset exceeds the size of the buffer

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-10-11 14:59:26 +08:00
Yongrong Wang
4b77dd03db rpmsg_ping.c: change msg cmd type for more compatible
Use bit mask method to represent the command, because it's more
convenient to express multiple characteristics simultaneously.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-10-11 14:59:26 +08:00
Yongrong Wang
1cf97ac4d0 rpmsg_ping.c: improve log level to LOG_EMERG
Usually rpmsg ping logs are needed during testing,
but too many other module logs can easily overwrite it,
so improve the rpmsg ping log level, later we can setlogmask to
a higher log level to mask other modules' logs.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-10-11 14:59:26 +08:00
Yongrong Wang
b96ad59d69 rpmsg_ping.c: change check data to fluctuation value
We can found the error happend packet more accurately based
on the data value.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-10-11 14:59:26 +08:00
wangyongrong
5aeb644bc5 virtio: adapt to the new OpenAMP
Sync all the virtio api usage to sync with new OpenAMP

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-10-09 23:32:58 +08:00
wangyongrong
8e799ff823 rpmsg: upgrade API passing on parameters with the upgrade of OpenAMP
All the rpmsg transport layer and rpmsg services sync the API
with new OpenAMP

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-10-09 23:32:58 +08:00
wangshaoxin
6feec8e4c5 rpmsg_port.c:add rpmsg_port_dump function
[01/01 00:02:48] [187] [ EMERG] [ap] Remote: wit
[01/01 00:02:48] [187] [ EMERG] [ap] ept NS
[01/01 00:02:48] [187] [ EMERG] [ap] ept rpmsg-sensor
[01/01 00:02:48] [187] [ EMERG] [ap] ept rpmsg-ping
[01/01 00:02:48] [187] [ EMERG] [ap] rpmsg_port queue RX: {used: 0, avail: 5}
[01/01 00:02:48] [187] [ EMERG] [ap] rpmsg buffer list:
[01/01 00:02:48] [187] [ EMERG] [ap] rpmsg_port queue TX: {used: 4, avail: 0}
[01/01 00:02:48] [187] [ EMERG] [ap] rpmsg buffer list:
[01/01 00:02:48] [187] [ EMERG] [ap]  TX buffer 0x619b84a8 hold by rpmsg-ping
[01/01 00:02:48] [187] [ EMERG] [ap]  TX buffer 0x619b86a8 hold by rpmsg-ping
[01/01 00:02:48] [187] [ EMERG] [ap]  TX buffer 0x619b88a8 hold by rpmsg-ping
[01/01 00:02:48] [187] [ EMERG] [ap]  TX buffer 0x619b8aa8 hold by rpmsg-ping

Signed-off-by: wangshaoxin <wangshaoxin@xiaomi.com>
2024-10-08 23:34:50 +08:00
Bowen Wang
064eb5fd35 rpmsg services: should release the tx buffer when rpmsg_send_nocopy failed
Otherwise, the tx buffer will be discarded and can no longer be obtained

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-10-08 18:26:39 +08:00
Xiang Xiao
2aaaa7632f rpmsg/ivshmem: Skip unregistering ivshmem driver
since ivshmem device may insert again

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-10-05 12:05:13 -03:00