rpmsgexport implementation

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
Bjorn Andersson
2016-12-06 18:11:54 -08:00
parent 83b45f6d3b
commit 5c7299d47c
4 changed files with 132 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
*.o
rpmsgexport
+17
View File
@@ -0,0 +1,17 @@
OUT := rpmsgexport
CFLAGS := -Wall -g -O2
LDFLAGS :=
prefix := /usr/local
SRCS := rpmsgexport.c
OBJS := $(SRCS:.c=.o)
$(OUT): $(OBJS)
$(CC) $(LDFLAGS) -o $@ $^
install: $(OUT)
install -D -m 755 $< $(DESTDIR)$(prefix)/bin/$<
clean:
rm -f $(OUT) $(OBJS)
+24
View File
@@ -0,0 +1,24 @@
rpmsgexport
===========
rpmsgexport implements RPMSG_CREATE_EPT_IOCTL for usage in udev rules to
automatically create endpoint devices as remoteproc devices are booted.
An example of udev-rule that automatically exposes the APPS_RIVA_CTRL channel
to user space as the pronto core comes up:
ACTION=="add", SUBSYSTEM=="rpmsg", \
KERNEL=="rpmsg_ctrl[0-9]*", \
ATTRS{rpmsg_name}=="pronto", \
RUN+="rpmsgexport /dev/$name APPS_RIVA_CTRL"
Which together with the following two udev rules creates a nice directory
structure of rpmsg endpoint devices under /dev/rpmsg:
SUBSYSTEM=="rpmsg", KERNEL=="rpmsg_ctrl[0-9]*", \
ATTRS{rpmsg_name}=="?*", \
SYMLINK+="rpmsg/$attr{rpmsg_name}/ctrl"
SUBSYSTEM=="rpmsg", KERNEL=="rpmsg[0-9]*", \
ATTR{name}=="?*", \
ATTRS{rpmsg_name}=="?*", \
SYMLINK+="rpmsg/$attr{rpmsg_name}/$attr{name}"
+89
View File
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2016, Linaro Ltd.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/ioctl.h>
#include <err.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
struct rpmsg_endpoint_info {
char name[32];
uint32_t src;
uint32_t dst;
};
#define RPMSG_CREATE_EPT_IOCTL _IOW(0xb5, 0x1, struct rpmsg_endpoint_info)
static void usage(void)
{
extern char *__progname;
fprintf(stderr, "%s <ctrl> <name> [<src> <dst>]\n", __progname);
exit(1);
}
int main(int argc, char **argv)
{
struct rpmsg_endpoint_info ept;
int ret;
int fd;
if (argc != 3 && argc != 5)
usage();
fd = open(argv[1], O_RDWR);
if (fd < 0)
err(1, "failed to open %s\n", argv[1]);
strncpy(ept.name, argv[2], sizeof(ept.name));
ept.name[sizeof(ept.name)-1] = '\0';
if (argc == 4) {
ept.src = atoi(argv[3]);
ept.dst = atoi(argv[4]);
if (!ept.src || !ept.dst)
usage();
}
ret = ioctl(fd, RPMSG_CREATE_EPT_IOCTL, &ept);
if (ret < 0) {
fprintf(stderr, "failed to create endpoint");
exit(1);
}
close(fd);
return 0;
}