Skip to content

Commit 8109517

Browse files
arnopoandersson
authored andcommitted
rpmsg: ctrl: Introduce new RPMSG_CREATE/RELEASE_DEV_IOCTL controls
Allow the user space application to create and release an rpmsg device by adding RPMSG_CREATE_DEV_IOCTL and RPMSG_RELEASE_DEV_IOCTL ioctrls to the /dev/rpmsg_ctrl interface The RPMSG_CREATE_DEV_IOCTL Ioctl can be used to instantiate a local rpmsg device. Depending on the back-end implementation, the associated rpmsg driver is probed and a NS announcement can be sent to the remote processor. The RPMSG_RELEASE_DEV_IOCTL allows the user application to release a rpmsg device created either by the remote processor or with the RPMSG_CREATE_DEV_IOCTL call. Depending on the back-end implementation, the associated rpmsg driver is removed and a NS destroy rpmsg can be sent to the remote processor. Suggested-by: Mathieu Poirier <mathieu.poirier@linaro.org> Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> Link: https://lore.kernel.org/r/20220124102524.295783-12-arnaud.pouliquen@foss.st.com
1 parent bc69d10 commit 8109517

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

drivers/rpmsg/rpmsg_ctrl.c

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ static DEFINE_IDA(rpmsg_minor_ida);
4343
* @rpdev: underlaying rpmsg device
4444
* @cdev: cdev for the ctrl device
4545
* @dev: device for the ctrl device
46+
* @ctrl_lock: serialize the ioctrls.
4647
*/
4748
struct rpmsg_ctrldev {
4849
struct rpmsg_device *rpdev;
4950
struct cdev cdev;
5051
struct device dev;
52+
struct mutex ctrl_lock;
5153
};
5254

5355
static int rpmsg_ctrldev_open(struct inode *inode, struct file *filp)
@@ -76,9 +78,8 @@ static long rpmsg_ctrldev_ioctl(struct file *fp, unsigned int cmd,
7678
void __user *argp = (void __user *)arg;
7779
struct rpmsg_endpoint_info eptinfo;
7880
struct rpmsg_channel_info chinfo;
79-
80-
if (cmd != RPMSG_CREATE_EPT_IOCTL)
81-
return -EINVAL;
81+
struct rpmsg_device *rpdev;
82+
int ret = 0;
8283

8384
if (copy_from_user(&eptinfo, argp, sizeof(eptinfo)))
8485
return -EFAULT;
@@ -88,7 +89,33 @@ static long rpmsg_ctrldev_ioctl(struct file *fp, unsigned int cmd,
8889
chinfo.src = eptinfo.src;
8990
chinfo.dst = eptinfo.dst;
9091

91-
return rpmsg_chrdev_eptdev_create(ctrldev->rpdev, &ctrldev->dev, chinfo);
92+
mutex_lock(&ctrldev->ctrl_lock);
93+
switch (cmd) {
94+
case RPMSG_CREATE_EPT_IOCTL:
95+
ret = rpmsg_chrdev_eptdev_create(ctrldev->rpdev, &ctrldev->dev, chinfo);
96+
break;
97+
98+
case RPMSG_CREATE_DEV_IOCTL:
99+
rpdev = rpmsg_create_channel(ctrldev->rpdev, &chinfo);
100+
if (!rpdev) {
101+
dev_err(&ctrldev->dev, "failed to create %s channel\n", chinfo.name);
102+
ret = -ENXIO;
103+
}
104+
break;
105+
106+
case RPMSG_RELEASE_DEV_IOCTL:
107+
ret = rpmsg_release_channel(ctrldev->rpdev, &chinfo);
108+
if (ret)
109+
dev_err(&ctrldev->dev, "failed to release %s channel (%d)\n",
110+
chinfo.name, ret);
111+
break;
112+
113+
default:
114+
ret = -EINVAL;
115+
}
116+
mutex_unlock(&ctrldev->ctrl_lock);
117+
118+
return ret;
92119
};
93120

94121
static const struct file_operations rpmsg_ctrldev_fops = {
@@ -125,6 +152,7 @@ static int rpmsg_ctrldev_probe(struct rpmsg_device *rpdev)
125152
dev->parent = &rpdev->dev;
126153
dev->class = rpmsg_class;
127154

155+
mutex_init(&ctrldev->ctrl_lock);
128156
cdev_init(&ctrldev->cdev, &rpmsg_ctrldev_fops);
129157
ctrldev->cdev.owner = THIS_MODULE;
130158

include/uapi/linux/rpmsg.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,14 @@ struct rpmsg_endpoint_info {
3333
*/
3434
#define RPMSG_DESTROY_EPT_IOCTL _IO(0xb5, 0x2)
3535

36+
/**
37+
* Instantiate a new local rpmsg service device.
38+
*/
39+
#define RPMSG_CREATE_DEV_IOCTL _IOW(0xb5, 0x3, struct rpmsg_endpoint_info)
40+
41+
/**
42+
* Release a local rpmsg device.
43+
*/
44+
#define RPMSG_RELEASE_DEV_IOCTL _IOW(0xb5, 0x4, struct rpmsg_endpoint_info)
45+
3646
#endif

0 commit comments

Comments
 (0)