CV-Bowen opened a new pull request, #21981:
URL: https://github.com/apache/nuttx/pull/21981
## Summary
NuttX has no generic way for an application to talk to a remote rpmsg
service: each service needs its own driver. Linux has `rpmsg_char` for
this; this PR adds the same interface:
- `include/nuttx/rpmsg/rpmsg.h`: the ioctls and `struct
rpmsg_endpoint_info` of Linux `<linux/rpmsg.h>`
(`RPMSG_CREATE_EPT_IOCTL`, `RPMSG_CREATE_DEV_IOCTL`,
`RPMSG_RELEASE_DEV_IOCTL`, `RPMSG_DESTROY_EPT_IOCTL`, and the flow
control ones).
- `drivers/rpmsg: add the rpmsg char driver` (`CONFIG_RPMSG_CHAR`):
`RPMSG_CREATE_EPT_IOCTL` / `RPMSG_CREATE_DEV_IOCTL` on
`/dev/rpmsg/<cpu>` creates an endpoint and registers
`/dev/rpmsg-<name>`, which supports `read()`, `write()` and `poll()`;
received messages are queued until read, and the peer's name service
destroy makes `read()` return `-ECONNRESET` and `poll()` report
`POLLHUP`.
- `rpmsg_char: prefix the endpoint name with "rpmsg-raw-"`, the service
name the Linux driver binds to, so a NuttX and a Linux rpmsg char
endpoint find each other.
- `rpmsg_char: copy into the reader's buffer directly` when a reader is
already waiting.
## Impact
- New Kconfig `RPMSG_CHAR` (default n) and `RPMSG_CHAR_NPOLLWAITERS`.
- New public ioctls 8..13 in `include/nuttx/rpmsg/rpmsg.h` and `struct
rpmsg_endpoint_info`; the existing ioctl numbers do not change.
- No change unless `RPMSG_CHAR` is enabled.
## 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
qemu-armv8a:rpserver + qemu-armv8a:rpproxy (rptun ivshmem), both with
`CONFIG_RPMSG_CHAR`. The server runs the `rpmsgchar` test program
(nuttx-apps `examples/rpmsgchar`, apache/nuttx-apps#{appspr}); the proxy
runs a small test-only echo server (below, not in this PR) that creates
the same endpoints with `RPMSG_CREATE_DEV_IOCTL`, writes back every
message, and releases an endpoint once the peer destroys it.
| test | result (3 runs) |
|---|---|
| `rpmsgchar -t echo -c /dev/rpmsg/proxy -n t0`: 1000 write/read round trips
of 12 bytes over `/dev/rpmsg-t0` | `Finish the echo test`, the echo server
counts 1000 messages |
| `rpmsgchar -t destroy -c /dev/rpmsg/proxy -n d`: create 100 endpoints, one
round trip each, then release them all | `End the destroy test`; no
`/dev/rpmsg-d*` left on the server, heap back to the same number of chunks |
On master `RPMSG_CHAR` does not exist.
<details><summary>log</summary>
```
echo: serving /dev/rpmsg-t0
Open rpmsg char device /dev/rpmsg-t0
Start the echo test
Finish the echo test
echo: exit after 1000 messages
echo: serving 100 endpoints
Start the destroy test
End the destroy test
```
</details>
<details><summary>test-only echo server</summary>
```c
#include <nuttx/config.h>
#include <fcntl.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <nuttx/rpmsg/rpmsg.h>
static int create(int ctrl, const char *name)
{
struct rpmsg_endpoint_info info;
char path[64];
memset(&info, 0, sizeof(info));
strlcpy(info.name, name, sizeof(info.name));
info.src = RPMSG_ADDR_ANY;
info.dst = RPMSG_ADDR_ANY;
if (ioctl(ctrl, RPMSG_CREATE_DEV_IOCTL, &info) < 0)
{
return -1;
}
snprintf(path, sizeof(path), "/dev/rpmsg-%s", name);
return open(path, O_RDWR);
}
int main(int argc, char *argv[])
{
struct rpmsg_endpoint_info info;
char name[RPMSG_NAME_SIZE];
char buf[512];
ssize_t n;
long cnt = 0;
int ctrl;
int fd;
int i;
if (argc < 3)
{
printf("usage: %s <ctrl> <name> [count]\n", argv[0]);
return 1;
}
ctrl = open(argv[1], O_RDWR);
if (ctrl < 0)
{
printf("echo: open %s failed\n", argv[1]);
return 1;
}
if (argc == 3)
{
fd = create(ctrl, argv[2]);
if (fd < 0)
{
printf("echo: create %s failed\n", argv[2]);
return 1;
}
printf("echo: serving /dev/rpmsg-%s\n", argv[2]);
while ((n = read(fd, buf, sizeof(buf))) > 0)
{
if (write(fd, buf, n) != n)
{
break;
}
cnt++;
}
printf("echo: exit after %ld messages\n", cnt);
close(fd);
return 0;
}
int num = atoi(argv[3]);
struct pollfd *fds = calloc(num, sizeof(*fds));
int left = num;
for (i = 0; i < num; i++)
{
snprintf(name, sizeof(name), "%s%d", argv[2], i);
fds[i].fd = create(ctrl, name);
fds[i].events = POLLIN;
if (fds[i].fd < 0)
{
printf("echo: create %s failed\n", name);
return 1;
}
}
printf("echo: serving %d endpoints\n", num);
while (left > 0 && poll(fds, num, -1) > 0)
{
for (i = 0; i < num; i++)
{
if (fds[i].fd < 0 || fds[i].revents == 0)
{
continue;
}
/* Echo, and keep the endpoint until the peer releases it */
n = read(fds[i].fd, buf, sizeof(buf));
if (n > 0)
{
if (write(fds[i].fd, buf, n) == n)
{
cnt++;
}
continue;
}
close(fds[i].fd);
snprintf(name, sizeof(name), "%s%d", argv[2], i);
memset(&info, 0, sizeof(info));
strlcpy(info.name, name, sizeof(info.name));
info.src = RPMSG_ADDR_ANY;
info.dst = RPMSG_ADDR_ANY;
ioctl(ctrl, RPMSG_RELEASE_DEV_IOCTL, &info);
fds[i].fd = -1;
left--;
}
}
printf("echo: %ld of %d endpoints echoed and released\n", cnt, num);
free(fds);
return 0;
}
```
</details>
Every commit builds with no warning on sim:rpserver with and without
`CONFIG_RPMSG_CHAR`.
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]