Socket based IPC over RPMSG for user threads
cover Socket based IPC over RPMSG for user threads
Hi all,
This patch implements an IPC service using the remoteproc/rpmsg framework. The IPC is intended to be used between threads running on different processors. The IPC service is provided to user threads via socket APIs.
As the rpmsg-ti socket implementation does, I registered the address familiy AF_RPMSG (and PF_RMPSG) to be used with this socket. The address format is "rproc_id:port_num", where rproc_id is the remote processor identifier statically defined in the DT, port_num is an integer acting as TCP/UDP port numbers (this is _not_ the rpmsg endpoint).
All the IPC messages between master and a specific remote are transported using an unique rpmsg channel whose id is "rpmsg-proto". This socket system supports only one rpmsg channel of type "rpmsg-proto" per rproc.
The rpmsg socket layer provides a transport protocol that allows message multiplexing/demultiplexing. Basically it adds a header to the message payload that contains source and destination port numbers (like UDP header).
User threads can create and use a rpmsg socket by means of the usual socket APIs: bind, connect, sendto, recvfrom.
Rpmsg socket type can be either SOCK_DGRAM or SOCK_SEQPACKET. The basic difference is that the former discards the new packets when the vring buffer is full, while the latter blocks the send on the source side until the receiver frees a vring slot.
In order to provide the remoteprocs with static addresses I'm currently using aliases in the device tree. Alias format is "rproc%d" where %d is the alias ID, used as rproc address. However, I've noticed you added a rproc OF look-up function to obtain a rproc reference ginven an index. I think in theory that this index can be used as rproc address, but I have not seen any code using this function nor documentation explaining the "rprocs" phandle usage. Despite that I'd like to use the "rprocs" list instead of aliases, in order to maintain everything aligned, but I'm not actually sure this works as I have understood.
For now I decided to use DT aliases as the TI code does.
This patch wants to incentive a discussion about socket IPC over rpmsg, that is _not_ the exposition of the rpmsg bus to userspace.
Best regards,
Michele
Michele Rodolfi (2):
rpmsg: support for retreiving processor ID from a rpmsg_channel net/rpmsg: add support for socket based IPC over rpmsg
drivers/remoteproc/remoteproc_core.c | 21 + drivers/remoteproc/remoteproc_virtio.c | 21 + drivers/rpmsg/virtio_rpmsg_bus.c | 20 + include/linux/remoteproc.h | 2 + include/linux/rpmsg.h | 1 + include/linux/socket.h | 5 +- include/uapi/linux/rpmsg_socket.h | 48 ++ net/Kconfig | 1 + net/Makefile | 1 + net/rpmsg/Kconfig | 10 + net/rpmsg/Makefile | 1 + net/rpmsg/rpmsg_proto.c | 847 +++++++++++++++++++++++++++++++++ 12 files changed, 976 insertions(+), 2 deletions(-) create mode 100644 include/uapi/linux/rpmsg_socket.h create mode 100644 net/rpmsg/Kconfig create mode 100644 net/rpmsg/Makefile create mode 100644 net/rpmsg/rpmsg_proto.c
Signature · 1 line
2.7.4
PATCH 1/2 rpmsg: support for retreiving processor ID from a rpmsg_channel
added function rproc_vdev_to_rproc_safe to remoteproc_virtio.c. added function rproc_get_alias_id to remoteproc_core.c. added function rpmsg_get_virtio_dev to virtio_rpmsg_bus.c. Remote processor IDs are defined in the Device Tree using aliases.
This patch is created from the code in the TI repository
http://git.ti.com/rpmsg/remoteproc branch rpmsg-ti-linux-4.4.y
--- drivers/remoteproc/remoteproc_core.c | 21 +++++++++++++++++++++ drivers/remoteproc/remoteproc_virtio.c | 21 +++++++++++++++++++++ drivers/rpmsg/virtio_rpmsg_bus.c | 20 ++++++++++++++++++++ include/linux/remoteproc.h | 2 ++ include/linux/rpmsg.h | 1 + 5 files changed, 65 insertions(+)
drivers/remoteproc/remoteproc_core.c +21 -0
@@ -1028,6 +1028,27 @@ static void rproc_crash_handler_work(struct work_struct *work) }/** +* rproc_get_alias_id() - return the alias id for the rproc device +* @rproc: handle of a remote processor +* +* Each rproc device is associated with a platform device, but since the +* devices are created from device tree, they do not have a valid platform +* device id. This function returns an alternate DT-based alias id, and is +* useful for clients needing to know an id for a processor. It is assumed +* that the devices were given proper alias ids. +* +* Return: alias id associated with the rproc +*/ +int rproc_get_alias_id (struct rproc *rproc) +{ +struct device *dev = rproc->dev.parent; +struct device_node *np = dev->of_node; + +return of_alias_get_id (np,"rproc" ); +} +EXPORT_SYMBOL (rproc_get_alias_id); + +/** * __rproc_boot() - boot a remote processor * @rproc: handle of a remote processor * @wait: wait for rproc registration completion
drivers/remoteproc/remoteproc_virtio.c +21 -0
@@ -361,3 +361,24 @@ void rproc_remove_virtio_dev(struct rproc_vdev *rvdev) {unregister_virtio_device (&rvdev->vdev); } + +/** +* rproc_vdev_to_rproc_safe() - Deduces a remoteproc from a virtio device +* @vdev: The virtio_device +* +* This function deduces the remoteproc from a given virtio device safely. If +* the virtio device is not one used by remoteproc, return NULL (as opposed to +* vdev_to_rproc which would return an invalid pointer) +*/ +struct rproc *rproc_vdev_to_rproc_safe (struct virtio_device *vdev) +{ +struct rproc_vdev *rvdev; + +if (!vdev->dev.parent/*|| vdev->dev.parent->type != &rproc_type*/ ) +return NULL ; + + rvdev =vdev_to_rvdev (vdev); + +return rvdev->rproc; +} +EXPORT_SYMBOL (rproc_vdev_to_rproc_safe);
drivers/rpmsg/virtio_rpmsg_bus.c +20 -0
@@ -468,6 +468,26 @@ static void rpmsg_release_device(struct device *dev)kfree (rpdev); } + +/** +* rpmsg_get_virtio_dev - Get underlying virtio device +* @rpdev: the rpmsg channel +* +* Returns the underlying remoteproc virtio device, if one exists. +* Returns NULL otherwise. +* NOTE: This function needs to be defined here since the definition of +* struct virtproc_info is in this file. +*/ +struct virtio_device *rpmsg_get_virtio_dev (struct rpmsg_channel *rpdev) +{ +if (!rpdev || !rpdev->vrp) +return NULL ; + +return rpdev->vrp->vdev; +} +EXPORT_SYMBOL (rpmsg_get_virtio_dev); + +/* * match an rpmsg channel with a channel info struct. * this is used to make sure we're not creating rpmsg devices for channels
include/linux/remoteproc.h +2 -0
@@ -498,6 +498,8 @@ int rproc_del(struct rproc *rproc);int rproc_boot (struct rproc *rproc);void rproc_shutdown (struct rproc *rproc);void rproc_report_crash (struct rproc *rproc,enum rproc_crash_type type); +struct rproc *rproc_vdev_to_rproc_safe (struct virtio_device *vdev); +int rproc_get_alias_id (struct rproc *rproc);static inline struct rproc_vdev *vdev_to_rvdev (struct virtio_device *vdev) {
include/linux/rpmsg.h +1 -0
@@ -174,6 +174,7 @@ struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_channel *, rpmsg_rx_cb_t cb, void *priv, u32 addr);int rpmsg_send_offchannel_raw (struct rpmsg_channel *,u32 ,u32 ,void *,int ,bool ); +struct virtio_device *rpmsg_get_virtio_dev (struct rpmsg_channel *rpdev);/* use a macro to avoid include chaining to get THIS_MODULE */ #define register_rpmsg_driver (drv) \
Signature · 1 line
2.7.4
PATCH 2/2 net/rpmsg: add support for socket based IPC over rpmsg
In reply to Michele RodolfiThis patch add support for a new socket address and protocol
family: AF_RPMSG. The rpmsg socket driver implements a new transport protocol in order to provide user threads with IPC.
This patch is created from the code in TI repository:
http://git.ti.com/rpmsg/remoteproc branch rpmsg-ti-linux-4.4.y
--- include/linux/socket.h | 5 +- include/uapi/linux/rpmsg_socket.h | 48 +++ net/Kconfig | 1 + net/Makefile | 1 + net/rpmsg/Kconfig | 10 + net/rpmsg/Makefile | 1 + net/rpmsg/rpmsg_proto.c | 847 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 911 insertions(+), 2 deletions(-) create mode 100644 include/uapi/linux/rpmsg_socket.h create mode 100644 net/rpmsg/Kconfig create mode 100644 net/rpmsg/Makefile create mode 100644 net/rpmsg/rpmsg_proto.c
include/linux/socket.h +3 -2
@@ -202,8 +202,8 @@ struct ucred {#define AF_VSOCK 40/* vSockets */ #define AF_KCM 41/* Kernel Connection Multiplexor*/ #define AF_QIPCRTR 42/* Qualcomm IPC Router */ - -#define AF_MAX 43/* For now.. */ +#define AF_RPMSG 43/* Rpmsg sockets */ +#define AF_MAX 44/* For now.. */ /* Protocol families, same as address families. */ #define PF_UNSPEC AF_UNSPEC
@@ -251,6 +251,7 @@ struct ucred {#define PF_VSOCK AF_VSOCK#define PF_KCM AF_KCM#define PF_QIPCRTR AF_QIPCRTR +#define PF_RPMSG AF_RPMSG#define PF_MAX AF_MAX/* Maximum queue length specifiable by listen. */
include/uapi/linux/rpmsg_socket.h new file +48 -0
48 lines not on this page · raw message
net/Kconfig +1 -0
@@ -392,6 +392,7 @@ source "net/9p/Kconfig" source "net/caif/Kconfig" source "net/ceph/Kconfig" source "net/nfc/Kconfig" +source "net/rpmsg/Kconfig" config LWTUNNEL bool "Network light weight tunnels"
net/Makefile +1 -0
@@ -80,3 +80,4 @@ obj-y += l3mdev/ endif obj-$(CONFIG_QRTR) += qrtr/ obj-$(CONFIG_NET_NCSI) += ncsi/ +obj-$(CONFIG_RPMSG_PROTO) += rpmsg/
net/rpmsg/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +# +# Rpmsg proto socket +# + +config RPMSG_PROTO + tristate "Rpmsg Socket protocol" + select REMOTEPROC + select RPMSG + help + API socket for rpmsg communications
net/rpmsg/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_RPMSG_PROTO) += rpmsg_proto.o
net/rpmsg/rpmsg_proto.c new file +847 -0
847 lines not on this page · raw message
Signature · 1 line
2.7.4