Commit Graph

65 Commits

Author SHA1 Message Date
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
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