rpmsg: Introduce "poll" to endpoint ops
PATCH v3 1/4 rpmsg: Introduce "poll" to endpoint ops
This allows rpmsg backends to implement polling of the outgoing buffer, which provides poll support to user space when using the rpmsg character device.
---
Changes since v2:
- None
Changes since v1:
- New patch
drivers/rpmsg/rpmsg_core.c | 20 ++++++++++++++++++++ drivers/rpmsg/rpmsg_internal.h | 3 +++ include/linux/rpmsg.h | 13 +++++++++++++ 3 files changed, 36 insertions(+)
drivers/rpmsg/rpmsg_core.c +20 -0
@@ -240,6 +240,26 @@ int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)EXPORT_SYMBOL (rpmsg_trysendto);/** +* rpmsg_poll() - poll the endpoint's send buffers +* @ept: the rpmsg endpoint +* @filp: file for poll_wait() +* @wait: poll_table for poll_wait() +* +* Returns mask representing the current state of the endpoint's send buffers +*/ +unsigned int rpmsg_poll (struct rpmsg_endpoint *ept,struct file *filp, +poll_table *wait) +{ +if (WARN_ON (!ept)) +return 0 ; +if (!ept->ops->poll) +return 0 ; + +return ept->ops->poll (ept, filp, wait); +} +EXPORT_SYMBOL (rpmsg_poll); + +/** * rpmsg_send_offchannel() - send a message using explicit src/dst addresses * @ept: the rpmsg endpoint * @src: source address
drivers/rpmsg/rpmsg_internal.h +3 -0
@@ -21,6 +21,7 @@#define __RPMSG_INTERNAL_H__#include <linux/rpmsg.h> +#include <linux/poll.h> #define to_rpmsg_device (d) container_of(d, struct rpmsg_device, dev)#define to_rpmsg_driver (d) container_of(d, struct rpmsg_driver, drv)
@@ -70,6 +71,8 @@ struct rpmsg_endpoint_ops {int (*trysendto)(struct rpmsg_endpoint *ept,void *data,int len,u32 dst);int (*trysend_offchannel)(struct rpmsg_endpoint *ept,u32 src,u32 dst,void *data,int len); +unsigned int (*poll)(struct rpmsg_endpoint *ept,struct file *filp, +poll_table *wait); };int rpmsg_register_device (struct rpmsg_device *rpdev);
include/linux/rpmsg.h +13 -0
@@ -41,6 +41,7 @@#include <linux/mod_devicetable.h> #include <linux/kref.h> #include <linux/mutex.h> +#include <linux/poll.h> #define RPMSG_ADDR_ANY 0xFFFFFFFF
@@ -156,6 +157,9 @@ int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);int rpmsg_trysend_offchannel (struct rpmsg_endpoint *ept,u32 src,u32 dst,void *data,int len); +unsigned int rpmsg_poll (struct rpmsg_endpoint *ept,struct file *filp, +poll_table *wait); +#else static inline int register_rpmsg_device (struct rpmsg_device *dev)
@@ -254,6 +258,15 @@ static inline int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, return -ENXIO; } +static inline unsigned int rpmsg_poll (struct rpmsg_endpoint *ept, +struct file *filp,poll_table *wait) +{ +/* This shouldn't be possible */ +WARN_ON (1 ); + +return 0 ; +} +#endif /* IS_ENABLED(CONFIG_RPMSG) */ /* use a macro to avoid include chaining to get THIS_MODULE */
Signature · 1 line
2.11.0
PATCH v3 2/4 rpmsg: qcom_smd: Implement endpoint "poll"
Add support for polling the status of the write buffer so that user space can use rpmsg character devices in non-blocking mode.
---
Changes since v2:
- None
Changes since v1:
- New patch
drivers/rpmsg/qcom_smd.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
drivers/rpmsg/qcom_smd.c +16 -0
@@ -919,6 +919,21 @@ static int qcom_smd_trysend(struct rpmsg_endpoint *ept, void *data, int len)return __qcom_smd_send (qsept->qsch, data, len, false); } +static unsigned int qcom_smd_poll (struct rpmsg_endpoint *ept, +struct file *filp,poll_table *wait) +{ +struct qcom_smd_endpoint *qsept =to_smd_endpoint (ept); +struct qcom_smd_channel *channel = qsept->qsch; +unsigned int mask =0 ; + +poll_wait (filp, &channel->fblockread_event, wait); + +if (qcom_smd_get_tx_avail (channel) >20 ) + mask |=POLLOUT |POLLWRNORM ; + +return mask; +} +/* * Finds the device_node for the smd child interested in this channel. */
@@ -951,6 +966,7 @@ static const struct rpmsg_endpoint_ops qcom_smd_endpoint_ops = { .destroy_ept = qcom_smd_destroy_ept, .send = qcom_smd_send, .trysend = qcom_smd_trysend, + .poll = qcom_smd_poll, };/*
Signature · 1 line
2.11.0
PATCH v3 3/4 rpmsg: Driver for user space endpoint interface
In reply to Bjorn AnderssonThis driver allows rpmsg instances to expose access to rpmsg endpoints to user space processes. It provides a control interface, allowing userspace to export endpoints and an endpoint interface for each exposed endpoint.
The implementation is based on prior art by Texas Instrument, Google, PetaLogix and was derived from a FreeRTOS performance statistics driver written by Michal Simek.
The control interface provides a "create endpoint" ioctl, which is fed a name, source and destination address. The three values are used to create the endpoint, in a backend-specific way, and a rpmsg endpoint device is created - with the three parameters are available in sysfs for udev usage.
E.g. to create an endpoint device for one of the Qualcomm SMD channel related to DIAG one would issue:
struct rpmsg_endpoint_info info = { "DIAG_CNTL", 0, 0 };
int fd = open("/dev/rpmsg_ctrl0", O_RDWR);
ioctl(fd, RPMSG_CREATE_EPT_IOCTL, &info);Each created endpoint device shows up as an individual character device in /dev, allowing permission to be controlled on a per-endpoint basis. The rpmsg endpoint will be created and destroyed following the opening and closing of the endpoint device, allowing rpmsg backends to open and close the physical channel, if supported by the wire protocol.
---
Changes since v2:
- Use memdup_user()
- Add MODULE_LICENSE
Changes since v1:
- Add separate Kconfig option
- Add poll support
- Added some kerneldoc
- Corrected synchronization issue for destruction of open endpoints racing on rpmsg_destroy_ept()
- Corrected error paths issues related to ida handling
Documentation/ioctl/ioctl-number.txt | 1 + drivers/rpmsg/Kconfig | 8 + drivers/rpmsg/Makefile | 1 + drivers/rpmsg/rpmsg_char.c | 585 +++++++++++++++++++++++++++++++++++ drivers/rpmsg/rpmsg_internal.h | 15 + include/uapi/linux/rpmsg.h | 35 +++ 6 files changed, 645 insertions(+) create mode 100644 drivers/rpmsg/rpmsg_char.c create mode 100644 include/uapi/linux/rpmsg.h
Documentation/ioctl/ioctl-number.txt +1 -0
@@ -321,6 +321,7 @@ Code Seq#(hex) Include File Comments 0xB1 00-1F PPPoX <mailto:[email protected]> 0xB3 00 linux/mmc/ioctl.h 0xB4 00-0F linux/gpio.h <mailto:[email protected]> +0xB5 00-0F uapi/linux/rpmsg.h <mailto:[email protected]> 0xC0 00-0F linux/usb/iowarrior.h 0xCA 00-0F uapi/misc/cxl.h 0xCA 80-8F uapi/scsi/cxlflash_ioctl.h
drivers/rpmsg/Kconfig +8 -0
@@ -4,6 +4,14 @@ menu "Rpmsg drivers" config RPMSG tristate +config RPMSG_CHAR + tristate "RPMSG device interface" + depends on RPMSG + help + Say Y here to export rpmsg endpoints as device files, usually found + in /dev. They make it possible for user-space programs to send and + receive rpmsg packets. + config RPMSG_QCOM_SMD tristate "Qualcomm Shared Memory Driver (SMD)" depends on QCOM_SMEM
drivers/rpmsg/Makefile +1 -0
@@ -1,3 +1,4 @@ obj-$(CONFIG_RPMSG) += rpmsg_core.o +obj-$(CONFIG_RPMSG_CHAR) += rpmsg_char.o obj-$(CONFIG_RPMSG_QCOM_SMD) += qcom_smd.o obj-$(CONFIG_RPMSG_VIRTIO) += virtio_rpmsg_bus.o
drivers/rpmsg/rpmsg_char.c new file +585 -0
585 lines not on this page · raw message
drivers/rpmsg/rpmsg_internal.h +15 -0
@@ -82,4 +82,19 @@ int rpmsg_unregister_device(struct device *parent,struct device *rpmsg_find_device (struct device *parent,struct rpmsg_channel_info *chinfo); +/** +* rpmsg_chrdev_register_device() - register chrdev device based on rpdev +* @rpdev: prepared rpdev to be used for creating endpoints +* +* This function wraps rpmsg_register_device() preparing the rpdev for use as +* basis for the rpmsg chrdev. +*/ +static inline int rpmsg_chrdev_register_device (struct rpmsg_device *rpdev) +{ +strcpy (rpdev->id.name,"rpmsg_chrdev" ); + rpdev->driver_override ="rpmsg_chrdev" ; + +return rpmsg_register_device (rpdev); +} +#endif
include/uapi/linux/rpmsg.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Copyright (c) 2016, Linaro Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _UAPI_RPMSG_H_ +#define _UAPI_RPMSG_H_ + +#include <linux/ioctl.h> +#include <linux/types.h> + +/** +* struct rpmsg_endpoint_info - endpoint info representation +* @name: name of service +* @src: local address +* @dst: destination address +*/ +struct rpmsg_endpoint_info { +char name[32 ]; +__u32 src; +__u32 dst; +}; + +#define RPMSG_CREATE_EPT_IOCTL _IOW(0xb5, 0x1, struct rpmsg_endpoint_info) +#define RPMSG_DESTROY_EPT_IOCTL _IO(0xb5, 0x2) + +#endif
Signature · 1 line
2.11.0
PATCH v3 4/4 rpmsg: smd: Register rpmsg user space interface for edges
In reply to Bjorn AnderssonCreate and register a rpmsg device for use with the rpmsg user space interface, allowing user space to access SMD channels.
Also provide the "rpmsg_name" device attribute to expose the edge name in sysfs, allowing the user to write udev rules for specific rpmsg devices and their children.
---
Changes since v2:
- None
Changes since v1:
- Moved rpmsg_name attribute to different patch
drivers/rpmsg/qcom_smd.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
drivers/rpmsg/qcom_smd.c +20 -0
@@ -1002,6 +1002,20 @@ static int qcom_smd_create_device(struct qcom_smd_channel *channel)return rpmsg_register_device (rpdev); } +static int qcom_smd_create_chrdev (struct qcom_smd_edge *edge) +{ +struct qcom_smd_device *qsdev; + + qsdev =kzalloc (sizeof (*qsdev),GFP_KERNEL ); +if (!qsdev) +return -ENOMEM ; + + qsdev->edge = edge; + qsdev->rpdev.ops = &qcom_smd_device_ops; + qsdev->rpdev.dev.parent = &edge->dev; +return rpmsg_chrdev_register_device (&qsdev->rpdev); +} +/* * Allocate the qcom_smd_channel object for a newly found smd channel, * retrieving and validating the smem items involved.
@@ -1357,6 +1371,12 @@ struct qcom_smd_edge *qcom_smd_register_edge(struct device *parent, goto unregister_dev; } + ret =qcom_smd_create_chrdev (edge); +if (ret) { +dev_err (&edge->dev,"failed to register chrdev for edge\n" ); + goto unregister_dev; + } +schedule_work (&edge->scan_work);return edge;
Signature · 1 line
2.11.0