Commit Graph

53 Commits

Author SHA1 Message Date
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
Yongrong Wang d0e4c4436e rpmsg_virtio: move rpmsg virtio cmd definition before the resource table
use reserved[2] in struct resource_table as the command, avoid the
resource table format do not follow the standard.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-10-03 09:37:24 +08:00
chao an 4195851845 drivers/rpmsg: replace metal_list_for_each to safety version
replace metal_list_for_each to safety version to avoid invalid access to deleted node in destory flow

Signed-off-by: chao an <anchao@lixiang.com>
2024-09-26 08:36:14 +08:00
Yongrong Wang 10e8b6c9f6 rptun/rpmsg_virtio: remove chip cmd and reuse the common ones
Add more common command for rptun and rpmsg_virtio frameworks,
also modify the rptun and rpmsg_virtio driver to use the common
commands.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-09-26 00:04:05 +08:00
Yongrong Wang 7c7d08d13a rptun.c/rpmsg_virtio.c: move panic logic from chip to rptun/rpmsg_virtio
Move the panic logic in common places, later we can move more logic to
the framework instead of having the drivers implement it repeatedly.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-09-26 00:04:05 +08:00
wangjianyu3 73b7128fb6 drivers/rpmsg: Fix a typo error of rpmsg_device_destory()
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2024-09-25 01:51:18 +08:00
wangjianyu3 b8029d28a3 drivers/rpmsg: Using safe list iterating in rpmsg_device_created()
To fix list access after delete error

Test:
  /* Export */
  rpmsgdev_export("SERVER", "/dev/DEVNAME");

  /* Register */
  rpmsgdev_register("CLIENT", "/dev/DEVNAME", "/dev/server-DEVNAME", 0);

Log:
  [ap] kasan_report: kasan detected a read access error, address at 0x40b7ae78,size is 8, return address: 0x402a3c50
  [ap] kasan_show_memory: Shadow bytes around the buggy address:
  [ap] kasan_show_memory:   0x40b7ae20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  [ap] kasan_show_memory:   0x40b7ae30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  [ap] kasan_show_memory:   0x40b7ae40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  [ap] kasan_show_memory:   0x40b7ae50: 20 af b7 40 00 00 00 00 c0 17 2a 40 00 00 00 00
  [ap] kasan_show_memory:   0x40b7ae60: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  [ap] kasan_show_memory:   0x40b7ae70: 00 00 00 00 00 00 00 00[b0 f7 b3 40 00 00 00 00]
  [ap] kasan_show_memory:   0x40b7ae80: c8 48 b8 40 00 00 00 00 00 00 00 00 00 00 00 00
  [ap] kasan_show_memory:   0x40b7ae90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  [ap] kasan_show_memory:   0x40b7aea0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  [ap] kasan_show_memory:   0x40b7aeb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

  $ addr2line -fe nuttx/nuttx 0x402a3c50
  rpmsg_device_created
  /workspace/nuttx/drivers/rpmsg/rpmsg.c:395 (discriminator 2)

Reported by rongyichang@xiaomi.com

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2024-09-25 01:51:18 +08:00
liaoao 4d35c60ba6 rpmsg_port_spi: set mreq to high to trigger next transmission
rpmsg_port_spi_connect can not be used here because peer may have not finished
the last transmission which will keep the sreq gpio in high level, and it will
read an error data frame.

Signed-off-by: liaoao <liaoao@xiaomi.com>
2024-09-17 01:55:51 +08:00
liaoao 88e0aeaad4 rpmsg_port_spi/slave: reorder rpmsg_port_initialize and rpmsg_port_spi_init hardware
Because the data transmision may has been started before
rpmsg_port_initialize(), this should be not allowed.

Signed-off-by: liaoao <liaoao@xiaomi.com>
2024-09-17 01:55:51 +08:00
liaoao 1f6ba6c7a7 rpmsg_port_spi: add pending logic for rpmsg port spi
To handle the situation that there is a req from peer side when
current transfer is not finished.

Signed-off-by: liaoao <liaoao@xiaomi.com>
2024-09-17 01:55:51 +08:00
liaoao 896f02bd67 rpmsg_port_spi: add nbits to spicfg
Support more spi config paramters for Rpmsg Port SPI/SPI Slave

Signed-off-by: liaoao <liaoao@xiaomi.com>
2024-09-17 01:55:51 +08:00
liaoao d724ddce0b rpmsg_port_spi: discard messages when disconnected
Disconnected logic optimization

Signed-off-by: liaoao <liaoao@xiaomi.com>
2024-09-17 01:55:51 +08:00
yintao 968da8b781 drivers/rpmsg: Add edge_create and edge_destroy for router
use cmd to notify the other cpu to destroy router edge device,
and dont destroy the other cpu's "router:ept"

Signed-off-by: yintao <yintao@xiaomi.com>
2024-09-17 01:55:51 +08:00
Bowen Wang 76572f9892 rpmsg/rpmsg_port_uart: add rpmsg uart port driver
Rpmsg Port Uart is a new rpmsg transport layer.
Just like the rpmsg port spi, the difference is that the physical
communication method changed from SPI to UART.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-09-17 01:55:51 +08:00
liaoao 4827063958 rpmsg_port_spi: add spi slave support
The rpmsg port spi slave version support

Signed-off-by: liaoao <liaoao@xiaomi.com>
2024-09-17 01:55:51 +08:00
liaoao 89ce5d5e02 rpmsg_port_spi: add get_local_cpuname api
add get_local_cpuname ops for rpmsg_port_spi

Signed-off-by: liaoao <liaoao@xiaomi.com>
2024-09-17 01:55:51 +08:00
liaoao 6a6fc8d883 rpmsg_port_spi:init cs gpio to be low
Transfer will be failure when the cs gpio status is low before
the first transfer.

Signed-off-by: liaoao <liaoao@xiaomi.com>
2024-09-17 01:55:51 +08:00
yintao 6e55812e59 drivers/rpmsg: Add get_local_cpuname in router
get_local_cpuname ops support for rpmsg router

Signed-off-by: yintao <yintao@xiaomi.com>
2024-09-17 01:55:51 +08:00
liaoao 4a356f6f6d rpmsg_port_spi: do not decrease when rx avail is already 0
Bug fix about the rpmsg port spi

Signed-off-by: liaoao <liaoao@xiaomi.com>
2024-09-17 01:55:51 +08:00
yintao 3fb39c6fc9 drivers/rpmsg: Use optimal rx size and tx size
Use the minimal tx and rx size form two edge cpu to maintain
the transmit buffer size not exceed the edge cpus' buffer size.

[edg0] tx <---> rx0 [hub] rx1 <---> tx [edge1]
       rx <---> tx0       tx1 <---> rx

edge0_tx = min(rx0, tx1);
edge0_rx = min(tx0, rx1);

edge1_tx = min(rx1, tx0);
edge1_rx = min(tx1, rx0);

Signed-off-by: yintao <yintao@xiaomi.com>
2024-09-17 01:55:51 +08:00
Bowen Wang ab47465dd5 drivers/rpmsg: add get_local_cpuname to rpmsg ops
Add get_local_cpuname to the rpmsg framework ops to support communicate
with the same remote core with multi rpmsg transport.

Some rpmsg services will send local cpu name to remote core and then let
remote core to connect local core by using this cpu name, when there are
multi rpmsg channels with same remote core, the remote core may connect
to incorrect core, so use the error rpmsg channel.

For example, there are two rpmsg channels between ap and audio:

ap core                     audio core
 [ap1] <-- rpmsg virtio1 --> [audio1]
 [ap2] <-- rpmsg virtio2 --> [audio2]

When we want to use the rpmsg virtio1 to communicate, ap core may send
local cpuname "ap2" to audio, so the audio core use remote cpu "ap2" to
connect with ap, and resulting in the use of incorrect rpmsg channel.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-09-17 01:55:51 +08:00
yintao 7bc7369102 drivers/rpmsg: Use tx buffer size as payload length
Directly use tx length received from hub as the tx payload length.

Signed-off-by: yintao <yintao@xiaomi.com>
2024-09-17 01:55:51 +08:00
yintao 7c933874e8 drivers/rpmsg: add rpmsg router support
Rpmsg Router is new rpmsg transport layer, it can router the rpmsg
messages to a cpu that not directly connected with local cpu by Rpmsg,
For the rpmsg services, it is as if there is a real Rpmsg Channel between
the local cpu and the remote cpu.

For examples, there are three cpus: ap, cp and audio.
ap and cp, ap and audio has share memory and be connected by Rpmsg VirtIO,
so ap and cp, ap and audio can communicate with each other by Rpmsg, but
cp can not communicate with audio direclty.

[cp] <-- rpmsg virtio --> [ap] <-- rpmsg virtio --> [audio]

With rpmsg router, the cp can communicate with audip by Rpmsg dereclty because
the router in ap will forward the rpmsg message from cp/audio to audio/cp, like
this:

 +<----- rpmsg router --> hub  <-- rpmsg router ------>+
 |                         |                           |
[cp] <-- rpmsg virtio --> [ap] <-- rpmsg virtio --> [audio]

Signed-off-by: yintao <yintao@xiaomi.com>
2024-09-17 01:55:51 +08:00
Bowen Wang a662c7aab3 rpmsg/rpmsg_port: judge notify_rx_free and notify_tx_ready before calling
Some lower layers do not need implement these two operations, so judge
them before calling.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-09-17 01:55:51 +08:00
Bowen Wang d27a9c516f rpmsg/Kconfig: move RPMSG_PORT outside RPMSG and select RPMSG direclty
All the RPMSG transport should direcly select the RPMSG like RPMSG_VIRTIO
does.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-09-17 01:55:51 +08:00
liaoao f7939a8081 rpmsg_port_spi: add spi transport layer
Add Rpmsg-Port-SPI transport layer.
Rpmsg Port SPI is a new rpmsg transport layer based on the Rpmsg Port,
it provides the capability for two SPI-connected (and two extra GPIO)
chips to communicate with each other using Rpmsg.

All already implemented Rpmsg Services can be used with this new transport
layer without any modifications.

Signed-off-by: liaoao <liaoao@xiaomi.com>
2024-09-17 01:55:51 +08:00
liaoao dd66a6b203 rpmsg_port:reduce len and avail of rpmsg_port_header_s to uint16_t
uint16_t is enough and more suitable

Signed-off-by: liaoao <liaoao@xiaomi.com>
2024-09-17 01:55:51 +08:00
liaoao 3d6abb1d86 rpmsg_port:add rpmsg_port_queue_nused api
Add nused api for lower layer to get the used buffer number

Signed-off-by: liaoao <liaoao@xiaomi.com>
2024-09-17 01:55:51 +08:00
liaoao 6d604ec487 rpmsg: add physical transport layer support
Rpmsg Physical Transport Layer is a new rpmsg transport, it's a
common part for the physical communication based rpmsg transport
layers such as Rpmsg-SPI and Rpmsg-Uart.

It implements three common parts:
1. Implement the NuttX and OpenAMP rpmsg frameworks' ops and the
rpmsg name service;
2. The buffer management and provide some APIs to lower layer to use;

Signed-off-by: liaoao <liaoao@xiaomi.com>
2024-09-17 01:55:51 +08:00
yintao 38af7001b6 drivers/rpmsg: fix the race condtion about rpmsg_device_created
xxx_rpmsg_device_created may be called repeatedly.

rptun thread				app thread

rptun_dev_start				xxx_rpmsg_init

...					rpmsg_register_callback
priv->...= rpmsg_ns_unbind;
priv->..= rptun_notify_wait;
					if (ns_unbind_cb)
(switch app thread)				device_created()
						xxx_rpmsg_device_created

					metal_list_add_tail(g_cb);
...
rpmsg_device_created();
	cb->device_created
	xxx_rpmsg_device_created;

Signed-off-by: yintao <yintao@xiaomi.com>
2024-09-14 17:34:52 +08:00
wangyongrong 00b6495419 rpmsg/CMakeLists.txt: add rpmsg_virtio_ivshmem.c in this file
rpmsg_virtio_ivshmem support Cmake compile too

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-09-14 17:34:52 +08:00
Xiang Xiao a235ada719 rpmsg_virtio_ivshmem: Replace work with wdog
Just rename, since it's a wdog, not a work.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-09-14 17:34:52 +08:00
wangyongrong ff399054c1 rptun/rpmsg_virtio: fix addrenv/raddrenv num error
Buf fix, simple_addrenv assume the last addrenv in addrenv array
be zero value

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-09-14 17:34:52 +08:00
liaoao 58c9c23765 rpmsg_ping:only sleep when ping->sleep is larger than 0
To avoid call sleep when sleep <= 0

Signed-off-by: liaoao <liaoao@xiaomi.com>
2024-09-14 17:34:52 +08:00
wangyongrong c84409a2cd rpmsg_virtio_ivshmem.c: Replace work queue with wdog
rpmsg_virtio_ivshmem polling mode use wdog to loop instead work
queue, beacause wdog has better performance

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-09-14 17:34:52 +08:00
wangyongrong 57cb0cb66f rpmsg_virtio_ivshmem.c: rpmsg virtio ivshmem msix interrupt support
Change the rpmsg_virtio_ivshmem from pci bus based to
pci-ivshmem bus based, so rpmsg_virtio_ivshmem can support interrupt
mode and also support the multi instance.

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-09-14 17:34:52 +08:00
wangyongrong 3ca717ef4a rpmsg_virtio_ivshmem.c: fix VIRTIO_RPMSG_F_BUFSZ not used caused restart err
Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-09-14 17:34:52 +08:00
wangyongrong d96fe98591 nuttx/rpmsg_virtio.c: fix invalid use of undefined type ‘struct rpmsg_hdr’ err
rpmsg/rpmsg_virtio.c:320:49: error: invalid use of undefined type ‘struct rpmsg_hdr’
  320 |                                         rx ? hdr->dst : hdr->src);

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-09-14 17:34:52 +08:00
Bowen Wang 1f96a0b5e9 drivers/rpmsg: fix recursive assert when call rpmsg_dump_all() in irq
Because call mutex lock is forbidden in interrupt.

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-09-14 17:34:52 +08:00
Yongrong Wang 67e41d0e32 rpmsg/rpmsg_virtio_ivshmem: add rpmsg virtio ivshmem support
rpmsg_virtio_ivshmem is a ivshmem based rpmsg virtio driver,
with this driver, we can use the rpmsg virtio in qemu platfrom

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-09-14 17:34:52 +08:00
Yongrong Wang af0bde8bca rpmsg virtio: add rpmsg virtio wrapper support
Rpmsg VirtIO is a virtio transport implementation for Rpmsg, and
it's different to the rptun framework.

rpmsg_virtio.c implements the rpmsg virtio transport layer by itself
to avoid use the remoteproc implementation in OpenAMP to save code
size, so it can be treated as a lightweight version of rptun.
Therefore, rpmsg_virtio.c only support the communication feature and
do not support contoll the life cycle of the remote core.
But benefit by it's small footprint, it can be used in the chips with
small flash.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-09-14 17:34:52 +08:00
Yongrong Wang e359c661d8 rpmsg ping: fix rpmsg_ping_ept_cb rpmsg send length
The rpmsg ping response length should not include the data length.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-09-14 17:34:52 +08:00
Xiang Xiao 56745e300a rpmsg: Reformat drivers/rpmsg/rpmsg.c
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-08-27 01:48:16 +08:00
Yongrong Wang 88ec55f6af rpmsg.c: move onceinit judge logic to common part
move rptun/rpmsg_virtio onceinit judge logic to rpmsg_register.

Signed-off-by: Yongrong Wang <wangyongrong@xiaomi.com>
2024-08-27 01:48:16 +08:00
simbit18 7677f10d3f fix nxstyle
fix Relative file path does not match actual file.
2024-04-16 19:09:12 +08:00
wangyongrong 10a8c2be92 rptun ioctl: Strip rpmsg ioctl and rptun ioctl.
rptun ioctl only handle RPTUNIOC_START, RPTUNIOC_STOP, RPTUNIOC_RESET,
rpmsg ioctl handles the public ioctl commands part.

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-02-19 02:15:45 -08:00
Bowen Wang fcfd5e8ebf rpmsg/Kconfig: add rpmsg_local_name to replace rptun_local_name
Because rpmsg service depends on RPMSG, make rpmsg socket use the
RPMSG_LOCAL_NAME

Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2024-02-18 04:09:34 -08:00
Xiang Xiao 42dad89211 rpmsg/ping: Replace UINT_MAX with CLOCK_MAX
since clock_t may map to either 32-bit or 64-bit integer type,
UINT_MAX may not be the maximum value of clock_t.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-02-16 22:16:31 +02:00
Yanfeng Liu b258680949 rpmsg/rpmsg_ping: tenative fix for build issue
rpmsg_ping.c is blocking CI checks for RPTUN related patches like #11673.
this patch simply fix the compilation issue of rpmsg_ping.c:

- line 191: overflow conversion from "long unsigned int" to "unsigned int"
- line 226: "sendlen" used uninitialized

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-02-08 12:38:21 -03:00
wangyongrong ce832c6377 rptun_ping: Strip rptun_ping out of rptun and rename to rpmsg_ping
It should be possible to use ping without rptun being enabled, so striped rptun_ping out of rptun and rename to rpmsg_ping.

Signed-off-by: wangyongrong <wangyongrong@xiaomi.com>
2024-01-30 04:08:59 -08:00