[Linux-stm32] [PATCH 13/13] rpmsg: ctrl: add support of the endpoints release

Arnaud Pouliquen arnaud.pouliquen at st.com
Fri Jul 31 12:10:43 UTC 2020


Add the support of the release of an endpoint using the ioctl
interface.
The endpoint is identified using its name, its source address
and is destination address.
To support legacy a new ioctl ioctl is created instead of updating
RPMSG_DESTROY_EPT_IOCTL.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen at st.com>
---
 drivers/rpmsg/rpmsg_ctrl.c | 35 ++++++++++++++++++++++++-----------
 include/uapi/linux/rpmsg.h |  1 +
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/drivers/rpmsg/rpmsg_ctrl.c b/drivers/rpmsg/rpmsg_ctrl.c
index d2a6dbb8798f..d696247970c2 100644
--- a/drivers/rpmsg/rpmsg_ctrl.c
+++ b/drivers/rpmsg/rpmsg_ctrl.c
@@ -75,26 +75,39 @@ static long rpmsg_ctrl_dev_ioctl(struct file *fp, unsigned int cmd,
 	struct rpmsg_channel_info chinfo;
 	struct rpmsg_endpoint_info eptinfo;
 	struct rpmsg_device *newch;
-
-	if (cmd != RPMSG_CREATE_EPT_IOCTL)
-		return -EINVAL;
+	int ret;
 
 	if (copy_from_user(&eptinfo, argp, sizeof(eptinfo)))
 		return -EFAULT;
 
-	chinfo.driver_override = rpmsg_ctrl_get_drv_name(eptinfo.service);
-	if (!chinfo.driver_override)
-		return -ENODEV;
-
 	memcpy(chinfo.name, eptinfo.name, RPMSG_NAME_SIZE);
 	chinfo.name[RPMSG_NAME_SIZE - 1] = '\0';
 	chinfo.src = eptinfo.src;
 	chinfo.dst = eptinfo.dst;
 
-	newch = rpmsg_create_channel(ctrldev->rpdev, &chinfo);
-	if (!newch) {
-		dev_err(&ctrldev->dev, "rpmsg_create_channel failed\n");
-		return -ENXIO;
+	switch (cmd) {
+	case RPMSG_CREATE_EPT_IOCTL:
+		chinfo.driver_override =
+				rpmsg_ctrl_get_drv_name(eptinfo.service);
+		if (!chinfo.driver_override)
+			return -ENODEV;
+
+		newch = rpmsg_create_channel(ctrldev->rpdev, &chinfo);
+		if (!newch) {
+			dev_err(&ctrldev->dev, "rpmsg_create_channel failed\n");
+			return -ENXIO;
+		}
+		break;
+	case RPMSG_RELEASE_EPT_IOCTL:
+		ret = rpmsg_release_channel(ctrldev->rpdev, &chinfo);
+		if (ret) {
+			dev_err(&ctrldev->dev,
+				"rpmsg_release_channel failed: %d\n", ret);
+			return ret;
+		}
+		break;
+	default:
+		return -EINVAL;
 	}
 
 	return 0;
diff --git a/include/uapi/linux/rpmsg.h b/include/uapi/linux/rpmsg.h
index 2ccc10ffacd4..74d821ee5f8c 100644
--- a/include/uapi/linux/rpmsg.h
+++ b/include/uapi/linux/rpmsg.h
@@ -39,5 +39,6 @@ struct rpmsg_endpoint_info {
 
 #define RPMSG_CREATE_EPT_IOCTL	_IOW(0xb5, 0x1, struct rpmsg_endpoint_info)
 #define RPMSG_DESTROY_EPT_IOCTL	_IO(0xb5, 0x2)
+#define RPMSG_RELEASE_EPT_IOCTL	_IOW(0xb5, 0x3, struct rpmsg_endpoint_info)
 
 #endif
-- 
2.17.1




More information about the Linux-stm32 mailing list