From patchwork Tue Dec 22 10:57:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 346663 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6FBACC433E6 for ; Tue, 22 Dec 2020 11:00:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 459312310D for ; Tue, 22 Dec 2020 11:00:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725785AbgLVK6s (ORCPT ); Tue, 22 Dec 2020 05:58:48 -0500 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:60534 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725847AbgLVK6r (ORCPT ); Tue, 22 Dec 2020 05:58:47 -0500 Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0BMAv8qB017308; Tue, 22 Dec 2020 11:58:00 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=SW6rkfmrRTc6+NkBZszJEQdtfxV4dOOJDB9c4RqrY0w=; b=y+5kV2mzPk0Al9hlLlXmHXhWdQE3W5Z3KEJ0ojV3GHN0yweUp7/dZUB55XaqqlJeqlsc IerUqYgeemjMT8aki8DvPuU/1ocMOQo8cmEsr8qdTL+bugVrNUzC7l0vtBwSh5e4nQnG oQTYZSGStv9OOcf6mM23RX4MfAItCcHoscpxbpOkh9a5a+L9+5RWJk9zIGQdr6NcPg32 EcznobaSkd9pSTjwyxm4t9nCWE5tdAtaHHJWXd5c5nABgW95B99cDLe7Iha38RB94NeH zTP0HPzt0YEbnWHY/PaUfYXgAY9uJy95LT7eyWiw9puduFqcpZB+QwFsA4BNl/PlvmT6 kA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 35k7vva3gv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 22 Dec 2020 11:58:00 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id DD13910002A; Tue, 22 Dec 2020 11:57:59 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id C832E231601; Tue, 22 Dec 2020 11:57:59 +0100 (CET) Received: from localhost (10.75.127.50) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 22 Dec 2020 11:57:59 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier , Andy Gross CC: , , , , Subject: [PATCH v2 01/16] rpmsg: introduce RPMsg control driver for channel creation Date: Tue, 22 Dec 2020 11:57:11 +0100 Message-ID: <20201222105726.16906-2-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> References: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-22_04:2020-12-21,2020-12-22 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The RPMsg_ctrl driver is a duplication of the ioctrl part of the rpmsg_char driver to make generic the ioctl to manage channels by the userspace applications. As a first step, this driver just creates the /dev/rpmsg_ctl ( is the instance value). The ioctl is not implemented. Notice that this driver is associated to a RPMsg device with no endpoint. Instantiating this device as an RPMsg device allows to retrieve the associated RPMsg backend. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/Kconfig | 8 ++ drivers/rpmsg/Makefile | 1 + drivers/rpmsg/rpmsg_ctrl.c | 208 +++++++++++++++++++++++++++++++++++++ 3 files changed, 217 insertions(+) create mode 100644 drivers/rpmsg/rpmsg_ctrl.c diff --git a/drivers/rpmsg/Kconfig b/drivers/rpmsg/Kconfig index 0b4407abdf13..c9e602016c3b 100644 --- a/drivers/rpmsg/Kconfig +++ b/drivers/rpmsg/Kconfig @@ -23,6 +23,14 @@ config RPMSG_NS channel that probes the associated RPMsg device on remote endpoint service announcement. +config RPMSG_CTRL + tristate "RPMSG control interface" + depends on RPMSG + help + Say Y here to enable the support of the /dev/rpmsg_ctl API. this API + allows user-space programs to create channels with specific name, + source and destination addresses. + config RPMSG_MTK_SCP tristate "MediaTek SCP" depends on MTK_SCP diff --git a/drivers/rpmsg/Makefile b/drivers/rpmsg/Makefile index 8d452656f0ee..3c1bce9d0228 100644 --- a/drivers/rpmsg/Makefile +++ b/drivers/rpmsg/Makefile @@ -2,6 +2,7 @@ obj-$(CONFIG_RPMSG) += rpmsg_core.o obj-$(CONFIG_RPMSG_CHAR) += rpmsg_char.o obj-$(CONFIG_RPMSG_NS) += rpmsg_ns.o +obj-$(CONFIG_RPMSG_CTRL) += rpmsg_ctrl.o obj-$(CONFIG_RPMSG_MTK_SCP) += mtk_rpmsg.o qcom_glink-objs := qcom_glink_native.o qcom_glink_ssr.o obj-$(CONFIG_RPMSG_QCOM_GLINK) += qcom_glink.o diff --git a/drivers/rpmsg/rpmsg_ctrl.c b/drivers/rpmsg/rpmsg_ctrl.c new file mode 100644 index 000000000000..425c3e32ada4 --- /dev/null +++ b/drivers/rpmsg/rpmsg_ctrl.c @@ -0,0 +1,208 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) STMicroelectronics 2020 + */ + +#include +#include +#include +#include +#include "rpmsg_internal.h" +#include + +#define RPMSG_DEV_MAX (MINORMASK + 1) + +#define dev_to_ctrldev(dev) container_of(dev, struct rpmsg_ctrl_dev, dev) +#define cdev_to_ctrldev(i_cdev) container_of(i_cdev, struct rpmsg_ctrl_dev, cdev) + +/** + * struct rpmsg_ctrl_dev - control device for instantiating endpoint devices + * @rpdev: underlaying rpmsg device + * @cdev: cdev for the ctrl device + * @dev: device for the ctrl device + */ +struct rpmsg_ctrl_dev { + struct rpmsg_device *rpdev; + struct cdev cdev; + struct device dev; +}; + +static DEFINE_IDA(rpmsg_ctrl_ida); +static DEFINE_IDA(rpmsg_minor_ida); + +static dev_t rpmsg_major; + +static int rpmsg_ctrl_dev_open(struct inode *inode, struct file *filp) +{ + struct rpmsg_ctrl_dev *ctrldev = cdev_to_ctrldev(inode->i_cdev); + + get_device(&ctrldev->dev); + filp->private_data = ctrldev; + + return 0; +} + +static long rpmsg_ctrl_dev_ioctl(struct file *fp, unsigned int cmd, + unsigned long arg) +{ + struct rpmsg_ctrl_dev *ctrldev = fp->private_data; + + dev_info(&ctrldev->dev, "Control not yet implemented\n"); + + return 0; +}; + +static int rpmsg_ctrl_dev_release(struct inode *inode, struct file *filp) +{ + struct rpmsg_ctrl_dev *ctrldev = cdev_to_ctrldev(inode->i_cdev); + + put_device(&ctrldev->dev); + + return 0; +} + +static void rpmsg_ctrl_dev_release_device(struct device *dev) +{ + struct rpmsg_ctrl_dev *ctrldev = dev_to_ctrldev(dev); + + dev_err(dev, "%s\n", __func__); + + ida_simple_remove(&rpmsg_ctrl_ida, dev->id); + ida_simple_remove(&rpmsg_minor_ida, MINOR(dev->devt)); + cdev_del(&ctrldev->cdev); + kfree(ctrldev); +} + +static const struct file_operations rpmsg_ctrl_fops = { + .owner = THIS_MODULE, + .open = rpmsg_ctrl_dev_open, + .release = rpmsg_ctrl_dev_release, + .unlocked_ioctl = rpmsg_ctrl_dev_ioctl, + .compat_ioctl = compat_ptr_ioctl, +}; + +static int rpmsg_ctrl_add_control(struct rpmsg_ctrl_dev *ctrldev) +{ + struct device *dev = &ctrldev->dev; + int ret; + + cdev_init(&ctrldev->cdev, &rpmsg_ctrl_fops); + ctrldev->cdev.owner = THIS_MODULE; + + ret = ida_simple_get(&rpmsg_minor_ida, 0, RPMSG_DEV_MAX, GFP_KERNEL); + if (ret < 0) + return ret; + dev->devt = MKDEV(MAJOR(rpmsg_major), ret); + + dev_set_name(dev, "rpmsg_ctrl%d", dev->id); + + ret = cdev_add(&ctrldev->cdev, dev->devt, 1); + if (ret) + goto free_minor_ida; + + dev_info(dev, "add %s control for %s driver\n", + dev_name(dev), dev_name(dev->parent)); + + return 0; + +free_minor_ida: + ida_simple_remove(&rpmsg_minor_ida, MINOR(dev->devt)); + + return ret; +} + +static int rpmsg_ctrl_probe(struct rpmsg_device *rpdev) +{ + struct rpmsg_ctrl_dev *ctrldev; + struct device *dev; + int ret; + + ctrldev = kzalloc(sizeof(*ctrldev), GFP_KERNEL); + if (!ctrldev) + return -ENOMEM; + + ctrldev->rpdev = rpdev; + + dev = &ctrldev->dev; + device_initialize(dev); + dev->parent = &rpdev->dev; + + ret = ida_simple_get(&rpmsg_ctrl_ida, 0, 0, GFP_KERNEL); + if (ret < 0) + goto free_ctrldev; + + dev->id = ret; + + ret = rpmsg_ctrl_add_control(ctrldev); + if (ret < 0) + goto free_ctrl_ida; + + /* We can now rely on the release function for cleanup */ + dev->release = rpmsg_ctrl_dev_release_device; + + ret = device_add(dev); + if (ret) { + dev_err(&rpdev->dev, "device_add failed: %d\n", ret); + put_device(dev); + goto free_ctrl_ida; + } + + dev_set_drvdata(dev, ctrldev); + dev_set_drvdata(&rpdev->dev, ctrldev); + + return 0; + +free_ctrl_ida: + ida_simple_remove(&rpmsg_ctrl_ida, dev->id); +free_ctrldev: + put_device(dev); + kfree(ctrldev); + + return ret; +} + +static void rpmsg_ctrl_remove(struct rpmsg_device *rpdev) +{ + struct rpmsg_ctrl_dev *ctrldev = dev_get_drvdata(&rpdev->dev); + + device_del(&ctrldev->dev); + put_device(&ctrldev->dev); +} + +static struct rpmsg_driver rpmsg_ctrl_driver = { + .drv.name = KBUILD_MODNAME, + .probe = rpmsg_ctrl_probe, + .remove = rpmsg_ctrl_remove, +}; + +static int rpmsg_ctrl_init(void) +{ + int ret; + + ret = alloc_chrdev_region(&rpmsg_major, 0, RPMSG_DEV_MAX, "rpmsg"); + if (ret < 0) { + pr_err("rpmsg_ctrl: failed to allocate char dev region\n"); + return ret; + } + + ret = register_rpmsg_driver(&rpmsg_ctrl_driver); + if (ret < 0) { + pr_err("rpmsg_ctrl: failed to register rpmsg driver\n"); + unregister_chrdev_region(rpmsg_major, RPMSG_DEV_MAX); + } + + return ret; +} +postcore_initcall(rpmsg_ctrl_init); + +static void rpmsg_ctrl_exit(void) +{ + unregister_rpmsg_driver(&rpmsg_ctrl_driver); + unregister_chrdev_region(rpmsg_major, RPMSG_DEV_MAX); +} +module_exit(rpmsg_ctrl_exit); + +MODULE_DESCRIPTION("ioctl rpmsg driver"); +MODULE_AUTHOR("Arnaud Pouliquen "); +MODULE_ALIAS("rpmsg:" KBUILD_MODNAME); +MODULE_LICENSE("GPL v2"); From patchwork Tue Dec 22 10:57:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 346667 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C65A9C433DB for ; Tue, 22 Dec 2020 10:59:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9ED7923105 for ; Tue, 22 Dec 2020 10:59:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726612AbgLVK6w (ORCPT ); Tue, 22 Dec 2020 05:58:52 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:7620 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726472AbgLVK6w (ORCPT ); Tue, 22 Dec 2020 05:58:52 -0500 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0BMAw6QE012870; Tue, 22 Dec 2020 11:58:06 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=a5kQ5Np6UsVy5bkTQ0gOe+8K4aMl8RM3spGtSWwiTos=; b=7fL6zE5oFRT2KXN95V1A9Ypt0f+6TUAY4TuR9H0lwFJq5CtohzWa3n/46Eg2UUX+R2c/ WC35wmhsmNciMvZgF6/vnRLKYiJ2uFXsHVSpCMh03Le7pOSmRDWXXTJkcOyokqM1Tx26 AVs/kuMvl6wzfmaN3OEqivlSt5ppuKU+SNoC0UX+VeDCfMTd8+3w3yvgUIAtzlQ0Q3o+ b7BVbykRnaM1I4VxpUlU6/5mQAaRcAIhqDHVxAYZS+BduOcw+rFv1098GktYHAj5WfjN /HetKXbUUYxp95NhrGp5NxaxixpeYTvZ1LdxAGDeeTKdJsMHSxuhOr55fPZ+61cHp06F zw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 35k0eb3xbc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 22 Dec 2020 11:58:06 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 8C8B5100034; Tue, 22 Dec 2020 11:58:00 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 7D39E231603; Tue, 22 Dec 2020 11:58:00 +0100 (CET) Received: from localhost (10.75.127.50) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 22 Dec 2020 11:57:59 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier , Andy Gross CC: , , , , Subject: [PATCH v2 02/16] rpmsg: add RPMsg control API to register service Date: Tue, 22 Dec 2020 11:57:12 +0100 Message-ID: <20201222105726.16906-3-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> References: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-22_04:2020-12-21,2020-12-22 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Add API to register a RPMsg service to the control device. The rpmsg_drv_ctrl_info structure links a service to its driver. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/rpmsg_ctrl.c | 57 ++++++++++++++++++++++++++++++++++++++ include/linux/rpmsg.h | 31 +++++++++++++++++++++ include/uapi/linux/rpmsg.h | 14 ++++++++++ 3 files changed, 102 insertions(+) diff --git a/drivers/rpmsg/rpmsg_ctrl.c b/drivers/rpmsg/rpmsg_ctrl.c index 425c3e32ada4..065e2e304019 100644 --- a/drivers/rpmsg/rpmsg_ctrl.c +++ b/drivers/rpmsg/rpmsg_ctrl.c @@ -27,6 +27,20 @@ struct rpmsg_ctrl_dev { struct device dev; }; +/** + * struct rpmsg_ctl_info - control info list node + * @ctrl: control driver info + * @node: list node + * + * This structure is used by rpmsg_ctl to list the registered drivers services + */ +struct rpmsg_ctl_info { + const struct rpmsg_drv_ctrl_info *ctrl; + struct list_head node; +}; + +static LIST_HEAD(rpmsg_drv_list); + static DEFINE_IDA(rpmsg_ctrl_ida); static DEFINE_IDA(rpmsg_minor_ida); @@ -175,6 +189,49 @@ static struct rpmsg_driver rpmsg_ctrl_driver = { .remove = rpmsg_ctrl_remove, }; +/** + * rpmsg_ctrl_register_ctl() -register control for the associated service + * @ctrl: rpmsg driver information + * + * This function is called by the rpmsg driver to register a service that will + * be exposed to be instantiate by the application. + */ +int rpmsg_ctrl_register_ctl(const struct rpmsg_drv_ctrl_info *ctrl) +{ + struct rpmsg_ctl_info *drv_info; + + drv_info = kzalloc(sizeof(*drv_info), GFP_KERNEL); + if (!drv_info) + return -ENOMEM; + + drv_info->ctrl = ctrl; + + list_add_tail(&drv_info->node, &rpmsg_drv_list); + + return 0; +} +EXPORT_SYMBOL(rpmsg_ctrl_register_ctl); + +/** + * rpmsg_ctrl_unregister_ctl() -unregister control for the associated service + * @ctrl: the rpmsg control information + * + * This function is called by the rpmsg driver to unregister the associated + * service. + */ +void rpmsg_ctrl_unregister_ctl(const struct rpmsg_drv_ctrl_info *ctrl) +{ + struct rpmsg_ctl_info *drv_info, *tmp; + + list_for_each_entry_safe(drv_info, tmp, &rpmsg_drv_list, node) { + if (drv_info->ctrl == ctrl) { + list_del(&drv_info->node); + kfree(drv_info); + } + } +} +EXPORT_SYMBOL(rpmsg_ctrl_unregister_ctl); + static int rpmsg_ctrl_init(void) { int ret; diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index a5db828b2420..5d64704c2346 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -26,6 +26,19 @@ struct rpmsg_endpoint; struct rpmsg_device_ops; struct rpmsg_endpoint_ops; +/** + * struct rpmsg_drv_ctrl_info - rpmsg ctrl structure + * @drv_name: name of the associated driver + * @service: the associated rpmsg service listed in @rpmsg_services + * + * This structure is used by rpmsg_ctl to link the endpoint creation to the + * service rpmsg driver. + */ +struct rpmsg_drv_ctrl_info { + const char *drv_name; + u32 service; +}; + /** * struct rpmsg_channel_info - channel info representation * @name: name of service @@ -315,4 +328,22 @@ static inline __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, module_driver(__rpmsg_driver, register_rpmsg_driver, \ unregister_rpmsg_driver) +#if IS_ENABLED(CONFIG_RPMSG_CTRL) + +int rpmsg_ctrl_register_ctl(const struct rpmsg_drv_ctrl_info *ctrl); +void rpmsg_ctrl_unregister_ctl(const struct rpmsg_drv_ctrl_info *ctrl); + +#else + +static inline int rpmsg_ctrl_register_ctl(const struct rpmsg_drv_ctrl_info *ctrl) +{ + return 0; +} + +static inline void rpmsg_ctrl_unregister_ctl(const struct rpmsg_drv_ctrl_info *ctrl) +{ +} + +#endif /* IS_ENABLED(CONFIG_RPMSG_CTRL) */ + #endif /* _LINUX_RPMSG_H */ diff --git a/include/uapi/linux/rpmsg.h b/include/uapi/linux/rpmsg.h index e14c6dab4223..0b0cb028e0b3 100644 --- a/include/uapi/linux/rpmsg.h +++ b/include/uapi/linux/rpmsg.h @@ -9,6 +9,20 @@ #include #include +/** + * enum rpmsg_services - list of supported RPMsg services + * + * @RPMSG_RAW_SERVICE: char device RPMSG service + * @RPMSG_START_PRIVATE_SERVICES: private services have to be declared after. + */ +enum rpmsg_services { + /* Reserved services */ + RPMSG_RAW_SERVICE = 0, + + /* Private services */ + RPMSG_START_PRIVATE_SERVICES = 1024, +}; + /** * struct rpmsg_endpoint_info - endpoint info representation * @name: name of service From patchwork Tue Dec 22 10:57:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 346665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A9C46C432C3 for ; Tue, 22 Dec 2020 10:59:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 87E2C2310D for ; Tue, 22 Dec 2020 10:59:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726313AbgLVK6t (ORCPT ); Tue, 22 Dec 2020 05:58:49 -0500 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:7228 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725897AbgLVK6s (ORCPT ); Tue, 22 Dec 2020 05:58:48 -0500 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0BMAvYlk004475; Tue, 22 Dec 2020 11:58:02 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=Q34Pt7mQM73+LJGSyan1A/A1z8hmgrrHq/rT3Ow5ST8=; b=TY3glY+k2ggVKlL2hzeWpqarQZ0UeaVjNUSrcpXIkke9FO8uscDeIYkG0MN/vk23bcxL UYMbyHtoISl1NvJZbN82l5dRGysM1oh8hRAfO/g8mub7TJzof4QZMe5lO5xdfRbm4sm3 0wRuFO0U51NPT+QQAjIfPdP6fuPOvbdaix5A8N7swNhkwbskRluJRpRlvnPWQZOZtXfo I9u70irWPH+fuLNkQEVfy6aY3Hx1rFvKlwCiMchjhuEfjWrSHqSstC9PZbZgl5M78gt1 x5YVXJG3L0+MJQF4astLce+ehUQvYJoAz8gyQk1UtYsKf2zds5bpeMGNMKL+3bY7rcKT eQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 35k0d1bjth-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 22 Dec 2020 11:58:02 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 5F43110002A; Tue, 22 Dec 2020 11:58:01 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 430EF231603; Tue, 22 Dec 2020 11:58:01 +0100 (CET) Received: from localhost (10.75.127.48) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 22 Dec 2020 11:58:00 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier , Andy Gross CC: , , , , Subject: [PATCH v2 03/16] rpmsg: add override field in channel info Date: Tue, 22 Dec 2020 11:57:13 +0100 Message-ID: <20201222105726.16906-4-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> References: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG3NODE2.st.com (10.75.127.8) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-22_04:2020-12-21,2020-12-22 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The override field is already used in the rpmsg_device. Adding this field in the channel info allows to force the channel creation with a specified RPMsg service driver. Signed-off-by: Arnaud Pouliquen --- include/linux/rpmsg.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index 5d64704c2346..5681c585e235 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -44,11 +44,13 @@ struct rpmsg_drv_ctrl_info { * @name: name of service * @src: local address * @dst: destination address + * @driver_override: driver name to force a match */ struct rpmsg_channel_info { char name[RPMSG_NAME_SIZE]; u32 src; u32 dst; + const char *driver_override; }; /** From patchwork Tue Dec 22 10:57:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 346664 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F195C433DB for ; Tue, 22 Dec 2020 11:00:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3125523105 for ; Tue, 22 Dec 2020 11:00:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727036AbgLVK7r (ORCPT ); Tue, 22 Dec 2020 05:59:47 -0500 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:60546 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725854AbgLVK6s (ORCPT ); Tue, 22 Dec 2020 05:58:48 -0500 Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0BMAv6qd017298; Tue, 22 Dec 2020 11:58:02 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=14ixMlR3u345kc7IjufikRjZjTnNfAABnHJSVaxqAF8=; b=gL3JGK2phKWIhN8aEiqTBKP5nA+qfnkwhzrNNCtqNdzdC10HVT1HrEaP3ohxnwGwEPHH VfbXloCHO36ZInpAtcvRm0Yf2uWOt/h4QfUr+ahyJq1VfiT18qXiYkO3LNBVokvysdr6 vokQ4tDiK3gDohIc8+X5omsZgj5SBCO+Abir+a0qJ4SEnXAh0h2j7aI2Xn7dNp4iFT/w 5eGVa5lNTCVr09MasmN68UT/6pjiDBNeic57rI6VnLy3nTeRpEboNZ1qLu+DyS8hR74+ R9kJ5Xhbllwm+5TrfVA68bOOe2xCwuD5zB10Dig8yFVepxjGFHNeykv7PNEeWeYtf/Jw 6Q== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 35k7vva3gy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 22 Dec 2020 11:58:02 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0364910003A; Tue, 22 Dec 2020 11:58:02 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id E9E76231603; Tue, 22 Dec 2020 11:58:01 +0100 (CET) Received: from localhost (10.75.127.51) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 22 Dec 2020 11:58:01 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier , Andy Gross CC: , , , , Subject: [PATCH v2 04/16] rpmsg: ctrl: implement the ioctl function to create device Date: Tue, 22 Dec 2020 11:57:14 +0100 Message-ID: <20201222105726.16906-5-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> References: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG2NODE1.st.com (10.75.127.4) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-22_04:2020-12-21,2020-12-22 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Implement the ioctl function that parses the list of rpmsg drivers registered to create an associated device. To be ISO user API, in a first step, the driver_override is only allowed for the RPMsg raw service, supported by the rpmsg_char driver. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/rpmsg_ctrl.c | 43 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/drivers/rpmsg/rpmsg_ctrl.c b/drivers/rpmsg/rpmsg_ctrl.c index 065e2e304019..8381b5b2b794 100644 --- a/drivers/rpmsg/rpmsg_ctrl.c +++ b/drivers/rpmsg/rpmsg_ctrl.c @@ -56,12 +56,51 @@ static int rpmsg_ctrl_dev_open(struct inode *inode, struct file *filp) return 0; } +static const char *rpmsg_ctrl_get_drv_name(u32 service) +{ + struct rpmsg_ctl_info *drv_info; + + list_for_each_entry(drv_info, &rpmsg_drv_list, node) { + if (drv_info->ctrl->service == service) + return drv_info->ctrl->drv_name; + } + + return NULL; +} + static long rpmsg_ctrl_dev_ioctl(struct file *fp, unsigned int cmd, unsigned long arg) { struct rpmsg_ctrl_dev *ctrldev = fp->private_data; - - dev_info(&ctrldev->dev, "Control not yet implemented\n"); + void __user *argp = (void __user *)arg; + struct rpmsg_channel_info chinfo; + struct rpmsg_endpoint_info eptinfo; + struct rpmsg_device *newch; + + if (cmd != RPMSG_CREATE_EPT_IOCTL) + return -EINVAL; + + if (copy_from_user(&eptinfo, argp, sizeof(eptinfo))) + return -EFAULT; + + /* + * In a frst step only the rpmsg_raw service is supported. + * The override is foorced to RPMSG_RAW_SERVICE + */ + chinfo.driver_override = rpmsg_ctrl_get_drv_name(RPMSG_RAW_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; + } return 0; }; From patchwork Tue Dec 22 10:57:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 346666 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B259C4332D for ; Tue, 22 Dec 2020 10:59:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0477723103 for ; Tue, 22 Dec 2020 10:59:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727008AbgLVK7b (ORCPT ); Tue, 22 Dec 2020 05:59:31 -0500 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:53815 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725897AbgLVK6w (ORCPT ); Tue, 22 Dec 2020 05:58:52 -0500 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0BMAvIUK004003; Tue, 22 Dec 2020 11:58:05 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=i5G4OSHl8Y/N2J/A+l3Tj+VqlW43Rc+ecwFsHG5sGFg=; b=WRUUuuJxXrs9jPatrCFblGqbnxRgHzHkmzdi8Fyq9pxGTQ8KkdQSVr9JTcBl9Dg1GU4A MfwGiJ6Rw6jcBtVkGYx+JECaZcnw3L5C9TJZPZkBcFI1xg3sd8EGiiexnRdnGxNpxcJA qkD7y795cVPjGE6/czZ+X/fAvcfN74mMD/iOauqKVtshUdtEyFEftMpvsBZWm8W5AHoT V4fCGOwcUuQacUxRT//xnqOisUDEdY6uCUrK/lqI1l5pp67VZw4OGfV4FCM9iEqjeCX0 AzCmpbcmsmnfwOZnxM6rYs9sCq3d4+4NJu0sIApu9HmYfjMmxa0hquoWpS5sga2qL55U aw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 35k0d1bjts-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 22 Dec 2020 11:58:05 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 887BE10002A; Tue, 22 Dec 2020 11:58:05 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id F02A721BD81; Tue, 22 Dec 2020 11:58:04 +0100 (CET) Received: from localhost (10.75.127.50) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 22 Dec 2020 11:58:04 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier , Andy Gross CC: , , , , Subject: [PATCH v2 08/16] rpmsg: char: make char rpmsg a rpmsg device without the control part Date: Tue, 22 Dec 2020 11:57:18 +0100 Message-ID: <20201222105726.16906-9-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> References: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG4NODE3.st.com (10.75.127.12) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-22_04:2020-12-21,2020-12-22 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org The RPMsg control part is migrated to the rpmsg_ctrl.c. Clean up the code associated to the support of the /dev/rpmsgctrl0 and update the driver to only manage the char devices as a RPMsg generic service. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/rpmsg_char.c | 166 +++++++------------------------------ 1 file changed, 28 insertions(+), 138 deletions(-) diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c index 732f5caf068a..3d77f4d5fc32 100644 --- a/drivers/rpmsg/rpmsg_char.c +++ b/drivers/rpmsg/rpmsg_char.c @@ -28,16 +28,12 @@ static dev_t rpmsg_major; -static DEFINE_IDA(rpmsg_ctrl_ida); static DEFINE_IDA(rpmsg_ept_ida); static DEFINE_IDA(rpmsg_minor_ida); #define dev_to_eptdev(dev) container_of(dev, struct rpmsg_eptdev, dev) #define cdev_to_eptdev(i_cdev) container_of(i_cdev, struct rpmsg_eptdev, cdev) -#define dev_to_ctrldev(dev) container_of(dev, struct rpmsg_ctrldev, dev) -#define cdev_to_ctrldev(i_cdev) container_of(i_cdev, struct rpmsg_ctrldev, cdev) - /** * struct rpmsg_ctrldev - control device for instantiating endpoint devices * @rpdev: underlaying rpmsg device @@ -300,10 +296,8 @@ static void rpmsg_eptdev_release_device(struct device *dev) kfree(eptdev); } -static int rpmsg_eptdev_create(struct rpmsg_ctrldev *ctrldev, - struct rpmsg_channel_info chinfo) +static int rpmsg_chrdev_probe(struct rpmsg_device *rpdev) { - struct rpmsg_device *rpdev = ctrldev->rpdev; struct rpmsg_eptdev *eptdev; struct device *dev; int ret; @@ -314,7 +308,9 @@ static int rpmsg_eptdev_create(struct rpmsg_ctrldev *ctrldev, dev = &eptdev->dev; eptdev->rpdev = rpdev; - eptdev->chinfo = chinfo; + strncpy(eptdev->chinfo.name, rpdev->id.name, RPMSG_NAME_SIZE); + eptdev->chinfo.src = rpdev->src; + eptdev->chinfo.dst = rpdev->dst; mutex_init(&eptdev->ept_lock); spin_lock_init(&eptdev->queue_lock); @@ -322,15 +318,18 @@ static int rpmsg_eptdev_create(struct rpmsg_ctrldev *ctrldev, init_waitqueue_head(&eptdev->readq); device_initialize(dev); - dev->parent = &ctrldev->dev; + dev->parent = &rpdev->dev; dev_set_drvdata(dev, eptdev); cdev_init(&eptdev->cdev, &rpmsg_eptdev_fops); eptdev->cdev.owner = THIS_MODULE; ret = ida_simple_get(&rpmsg_minor_ida, 0, RPMSG_DEV_MAX, GFP_KERNEL); - if (ret < 0) + if (ret < 0) { + dev_err(dev, "failed to get IDA (%d)\n", ret); goto free_eptdev; + } + dev->devt = MKDEV(MAJOR(rpmsg_major), ret); ret = ida_simple_get(&rpmsg_ept_ida, 0, 0, GFP_KERNEL); @@ -340,8 +339,10 @@ static int rpmsg_eptdev_create(struct rpmsg_ctrldev *ctrldev, dev_set_name(dev, "rpmsg%d", ret); ret = cdev_add(&eptdev->cdev, dev->devt, 1); - if (ret) + if (ret) { + dev_err(&rpdev->dev, "failed to add char device(%d)\n", ret); goto free_ept_ida; + } /* We can now rely on the release function for cleanup */ dev->release = rpmsg_eptdev_release_device; @@ -352,6 +353,8 @@ static int rpmsg_eptdev_create(struct rpmsg_ctrldev *ctrldev, put_device(dev); } + dev_set_drvdata(&rpdev->dev, eptdev); + return ret; free_ept_ida: @@ -365,138 +368,25 @@ static int rpmsg_eptdev_create(struct rpmsg_ctrldev *ctrldev, return ret; } -static int rpmsg_ctrldev_open(struct inode *inode, struct file *filp) -{ - struct rpmsg_ctrldev *ctrldev = cdev_to_ctrldev(inode->i_cdev); - - get_device(&ctrldev->dev); - filp->private_data = ctrldev; - - return 0; -} - -static int rpmsg_ctrldev_release(struct inode *inode, struct file *filp) +static void rpmsg_chrdev_remove(struct rpmsg_device *rpdev) { - struct rpmsg_ctrldev *ctrldev = cdev_to_ctrldev(inode->i_cdev); + struct rpmsg_eptdev *eptdev = dev_get_drvdata(&rpdev->dev); - put_device(&ctrldev->dev); + /* Wake up any blocked readers */ + wake_up_interruptible(&eptdev->readq); - return 0; + device_del(&eptdev->dev); + put_device(&eptdev->dev); } -static long rpmsg_ctrldev_ioctl(struct file *fp, unsigned int cmd, - unsigned long arg) -{ - struct rpmsg_ctrldev *ctrldev = fp->private_data; - void __user *argp = (void __user *)arg; - struct rpmsg_endpoint_info eptinfo; - struct rpmsg_channel_info chinfo; - - if (cmd != RPMSG_CREATE_EPT_IOCTL) - return -EINVAL; - - if (copy_from_user(&eptinfo, argp, sizeof(eptinfo))) - return -EFAULT; - - memcpy(chinfo.name, eptinfo.name, RPMSG_NAME_SIZE); - chinfo.name[RPMSG_NAME_SIZE-1] = '\0'; - chinfo.src = eptinfo.src; - chinfo.dst = eptinfo.dst; - - return rpmsg_eptdev_create(ctrldev, chinfo); +static struct rpmsg_device_id rpmsg_chrdev_id_table[] = { + { .name = "rpmsg-raw" }, + { }, }; - -static const struct file_operations rpmsg_ctrldev_fops = { - .owner = THIS_MODULE, - .open = rpmsg_ctrldev_open, - .release = rpmsg_ctrldev_release, - .unlocked_ioctl = rpmsg_ctrldev_ioctl, - .compat_ioctl = compat_ptr_ioctl, -}; - -static void rpmsg_ctrldev_release_device(struct device *dev) -{ - struct rpmsg_ctrldev *ctrldev = dev_to_ctrldev(dev); - - ida_simple_remove(&rpmsg_ctrl_ida, dev->id); - ida_simple_remove(&rpmsg_minor_ida, MINOR(dev->devt)); - cdev_del(&ctrldev->cdev); - kfree(ctrldev); -} - -static int rpmsg_chrdev_probe(struct rpmsg_device *rpdev) -{ - struct rpmsg_ctrldev *ctrldev; - struct device *dev; - int ret; - - ctrldev = kzalloc(sizeof(*ctrldev), GFP_KERNEL); - if (!ctrldev) - return -ENOMEM; - - ctrldev->rpdev = rpdev; - - dev = &ctrldev->dev; - device_initialize(dev); - dev->parent = &rpdev->dev; - - cdev_init(&ctrldev->cdev, &rpmsg_ctrldev_fops); - ctrldev->cdev.owner = THIS_MODULE; - - ret = ida_simple_get(&rpmsg_minor_ida, 0, RPMSG_DEV_MAX, GFP_KERNEL); - if (ret < 0) - goto free_ctrldev; - dev->devt = MKDEV(MAJOR(rpmsg_major), ret); - - ret = ida_simple_get(&rpmsg_ctrl_ida, 0, 0, GFP_KERNEL); - if (ret < 0) - goto free_minor_ida; - dev->id = ret; - dev_set_name(&ctrldev->dev, "rpmsg_ctrl%d", ret); - - ret = cdev_add(&ctrldev->cdev, dev->devt, 1); - if (ret) - goto free_ctrl_ida; - - /* We can now rely on the release function for cleanup */ - dev->release = rpmsg_ctrldev_release_device; - - ret = device_add(dev); - if (ret) { - dev_err(&rpdev->dev, "device_add failed: %d\n", ret); - put_device(dev); - } - - dev_set_drvdata(&rpdev->dev, ctrldev); - - return ret; - -free_ctrl_ida: - ida_simple_remove(&rpmsg_ctrl_ida, dev->id); -free_minor_ida: - ida_simple_remove(&rpmsg_minor_ida, MINOR(dev->devt)); -free_ctrldev: - put_device(dev); - kfree(ctrldev); - - return ret; -} - -static void rpmsg_chrdev_remove(struct rpmsg_device *rpdev) -{ - struct rpmsg_ctrldev *ctrldev = dev_get_drvdata(&rpdev->dev); - int ret; - - /* Destroy all endpoints */ - ret = device_for_each_child(&ctrldev->dev, NULL, rpmsg_eptdev_destroy); - if (ret) - dev_warn(&rpdev->dev, "failed to nuke endpoints: %d\n", ret); - - device_del(&ctrldev->dev); - put_device(&ctrldev->dev); -} +MODULE_DEVICE_TABLE(rpmsg, rpmsg_chrdev_id_table); static struct rpmsg_driver rpmsg_chrdev_driver = { + .id_table = rpmsg_chrdev_id_table, .probe = rpmsg_chrdev_probe, .remove = rpmsg_chrdev_remove, .drv = { @@ -504,7 +394,7 @@ static struct rpmsg_driver rpmsg_chrdev_driver = { }, }; -static int rpmsg_char_init(void) +static int rpmsg_chrdev_init(void) { int ret; @@ -516,13 +406,13 @@ static int rpmsg_char_init(void) ret = register_rpmsg_driver(&rpmsg_chrdev_driver); if (ret < 0) { - pr_err("rpmsgchr: failed to register rpmsg driver\n"); + pr_err("rpmsg: failed to register rpmsg chrdev driver\n"); unregister_chrdev_region(rpmsg_major, RPMSG_DEV_MAX); } return ret; } -postcore_initcall(rpmsg_char_init); +postcore_initcall(rpmsg_chrdev_init); static void rpmsg_chrdev_exit(void) { From patchwork Tue Dec 22 10:57:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 346668 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EF61C43333 for ; Tue, 22 Dec 2020 10:59:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D056723103 for ; Tue, 22 Dec 2020 10:59:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726700AbgLVK6y (ORCPT ); Tue, 22 Dec 2020 05:58:54 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:39106 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725847AbgLVK6y (ORCPT ); Tue, 22 Dec 2020 05:58:54 -0500 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0BMAw7bS004508; Tue, 22 Dec 2020 11:58:08 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=FvUUYLv2sdHQDAD6TMTnFsgYR6QnR4DXZXkL8+B6VwY=; b=1oQB3pCeIgtSu1zbzjQT5Xa6VlRLXfLAvy93JORdtgYpHD2lrxw5oGxy5Z+AoO7OBoYF lk5sJmAmPxeJGQcZmxNslbXW0yxXZ0CyfO3Ot37ww4YfL2SdIB2zr67gY5cRDuXXMal2 r4cXDJ62RQcF62ZVN93J+Ymdw8wJyJy/GHw01lXI0YOR+dXWGhJR5JmZqgOcSo8gTyS4 tukQKhRn1mwNw+X80FOAhzhCtK99y06S70Ff5CcxkHq/JsqA65tLLyb6LWk6z1K3oUrw 2kj4KDi68tbGVaf0KbO0W/8N+YBCbgNRFq3ls1aRmLAU63X6YkJMCqEP83w48yoD+Zd6 Fw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 35k0cgky5d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 22 Dec 2020 11:58:08 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2CC1110002A; Tue, 22 Dec 2020 11:58:08 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 2038122ECB4; Tue, 22 Dec 2020 11:58:08 +0100 (CET) Received: from localhost (10.75.127.51) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 22 Dec 2020 11:58:07 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier , Andy Gross CC: , , , , Subject: [PATCH v2 12/16] rpmsg: virtio: use the driver_override in channel creation ops Date: Tue, 22 Dec 2020 11:57:22 +0100 Message-ID: <20201222105726.16906-13-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> References: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-22_04:2020-12-21,2020-12-22 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Use the override information from the channel info structure to set the rpdev override and so links the channel to a specific driver. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/virtio_rpmsg_bus.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index e87d4cf926eb..c1d4bc08b2a5 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -416,6 +416,7 @@ static struct rpmsg_device *__rpmsg_create_channel(struct virtproc_info *vrp, rpdev->dst = chinfo->dst; rpdev->ops = &virtio_rpmsg_ops; rpdev->little_endian = virtio_is_little_endian(vrp->vdev); + rpdev->driver_override = (char *)chinfo->driver_override; /* * rpmsg server channels has predefined local address (for now), From patchwork Tue Dec 22 10:57:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 346670 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2917C432C3 for ; Tue, 22 Dec 2020 10:59:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F70E2313C for ; Tue, 22 Dec 2020 10:59:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725847AbgLVK64 (ORCPT ); Tue, 22 Dec 2020 05:58:56 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:10238 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726666AbgLVK64 (ORCPT ); Tue, 22 Dec 2020 05:58:56 -0500 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0BMAw87T012890; Tue, 22 Dec 2020 11:58:10 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=9YJwuMmhvQjiQZdfwPozN0/SAPH4XLa1zY4sMK1+Xeg=; b=LeAUFUX7Ip/yc7kvLlcHnK+5FhabePxZma6STCdwPaRczv/OYzqvNyKBXq1FAZEV//xT kGnmaZ20KVgX1YxFkgtRqc4p64lipOqivFYKl8pg4DgiKOqDjQuYMyOheRqe3XcYJo6t iIXgsIqhOzVVcSyPlACyFo5lywcEGVjkCzG+czalBomy3+pbEGCbq5hS+U8G8pZARuTX dPoyhidDxg/vC8ADIKmZlF4nif61MA/hHvP10wYcJNCWhnLiwCOfF9PJaor65VmdZAlh aNA0D6G3C5vRy7iS669Ir8LjGBT05c3oojSEe37uLBsjTZI62usn1h05y5lRKvQ2PZqc IQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 35k0eb3xc6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 22 Dec 2020 11:58:10 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C270810002A; Tue, 22 Dec 2020 11:58:09 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id B51FB22ECB4; Tue, 22 Dec 2020 11:58:09 +0100 (CET) Received: from localhost (10.75.127.50) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 22 Dec 2020 11:58:09 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier , Andy Gross CC: , , , , Subject: [PATCH v2 14/16] rpmsg: glink: add create and release rpmsg channel ops Date: Tue, 22 Dec 2020 11:57:24 +0100 Message-ID: <20201222105726.16906-15-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> References: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-22_04:2020-12-21,2020-12-22 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Add the new ops introduced by the rpmsg_ns series and used by the rpmsg_ctrl driver to instantiate a new rpmsg channel. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/qcom_glink_native.c | 94 ++++++++++++++++++++++++------- 1 file changed, 75 insertions(+), 19 deletions(-) diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c index 27a05167c18c..d74c338de077 100644 --- a/drivers/rpmsg/qcom_glink_native.c +++ b/drivers/rpmsg/qcom_glink_native.c @@ -205,6 +205,9 @@ static const struct rpmsg_endpoint_ops glink_endpoint_ops; #define GLINK_FEATURE_INTENTLESS BIT(1) static void qcom_glink_rx_done_work(struct work_struct *work); +static struct rpmsg_device * +qcom_glink_create_rpdev(struct qcom_glink *glink, + struct rpmsg_channel_info *chinfo); static struct glink_channel *qcom_glink_alloc_channel(struct qcom_glink *glink, const char *name) @@ -1203,6 +1206,37 @@ static int qcom_glink_announce_create(struct rpmsg_device *rpdev) return 0; } +static struct rpmsg_device * +qcom_glink_create_channel(struct rpmsg_device *rp_parent, + struct rpmsg_channel_info *chinfo) +{ + struct glink_channel *channel = to_glink_channel(rp_parent->ept); + struct qcom_glink *glink = channel->glink; + struct rpmsg_device *rpdev; + const char *name = chinfo->name; + + channel = qcom_glink_alloc_channel(glink, name); + if (IS_ERR(channel)) + return ERR_PTR(PTR_ERR(channel)); + + rpdev = qcom_glink_create_rpdev(glink, chinfo); + if (!IS_ERR(rpdev)) { + rpdev->ept = &channel->ept; + channel->rpdev = rpdev; + } + + return rpdev; +} + +static int qcom_glink_release_channel(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo) +{ + struct glink_channel *channel = to_glink_channel(rpdev->ept); + struct qcom_glink *glink = channel->glink; + + return rpmsg_unregister_device(glink->dev, chinfo); +} + static void qcom_glink_destroy_ept(struct rpmsg_endpoint *ept) { struct glink_channel *channel = to_glink_channel(ept); @@ -1359,6 +1393,8 @@ static struct device_node *qcom_glink_match_channel(struct device_node *node, static const struct rpmsg_device_ops glink_device_ops = { .create_ept = qcom_glink_create_ept, .announce_create = qcom_glink_announce_create, + .create_channel = qcom_glink_create_channel, + .release_channel = qcom_glink_release_channel, }; static const struct rpmsg_endpoint_ops glink_endpoint_ops = { @@ -1376,13 +1412,45 @@ static void qcom_glink_rpdev_release(struct device *dev) kfree(rpdev); } +static struct rpmsg_device * +qcom_glink_create_rpdev(struct qcom_glink *glink, + struct rpmsg_channel_info *chinfo) +{ + struct rpmsg_device *rpdev; + struct device_node *node; + int ret; + + rpdev = kzalloc(sizeof(*rpdev), GFP_KERNEL); + if (!rpdev) + return ERR_PTR(-ENOMEM); + + strncpy(rpdev->id.name, chinfo->name, RPMSG_NAME_SIZE); + rpdev->src = chinfo->src; + rpdev->dst = chinfo->dst; + rpdev->ops = &glink_device_ops; + + node = qcom_glink_match_channel(glink->dev->of_node, chinfo->name); + rpdev->dev.of_node = node; + rpdev->dev.parent = glink->dev; + rpdev->dev.release = qcom_glink_rpdev_release; + rpdev->driver_override = (char *)chinfo->driver_override; + + ret = rpmsg_register_device(rpdev); + if (ret) { + kfree(rpdev); + return ERR_PTR(ret); + } + + return rpdev; +} + static int qcom_glink_rx_open(struct qcom_glink *glink, unsigned int rcid, char *name) { struct glink_channel *channel; struct rpmsg_device *rpdev; bool create_device = false; - struct device_node *node; + struct rpmsg_channel_info chinfo; int lcid; int ret; unsigned long flags; @@ -1416,27 +1484,15 @@ static int qcom_glink_rx_open(struct qcom_glink *glink, unsigned int rcid, complete_all(&channel->open_req); if (create_device) { - rpdev = kzalloc(sizeof(*rpdev), GFP_KERNEL); - if (!rpdev) { - ret = -ENOMEM; + strncpy(chinfo.name, channel->name, sizeof(chinfo.name)); + chinfo.src = RPMSG_ADDR_ANY; + chinfo.dst = RPMSG_ADDR_ANY; + rpdev = qcom_glink_create_rpdev(glink, &chinfo); + if (IS_ERR(rpdev)) { + ret = PTR_ERR(rpdev); goto rcid_remove; } - rpdev->ept = &channel->ept; - strncpy(rpdev->id.name, name, RPMSG_NAME_SIZE); - rpdev->src = RPMSG_ADDR_ANY; - rpdev->dst = RPMSG_ADDR_ANY; - rpdev->ops = &glink_device_ops; - - node = qcom_glink_match_channel(glink->dev->of_node, name); - rpdev->dev.of_node = node; - rpdev->dev.parent = glink->dev; - rpdev->dev.release = qcom_glink_rpdev_release; - - ret = rpmsg_register_device(rpdev); - if (ret) - goto rcid_remove; - channel->rpdev = rpdev; } From patchwork Tue Dec 22 10:57:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Pouliquen X-Patchwork-Id: 346669 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 175F2C433DB for ; Tue, 22 Dec 2020 10:59:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DC45023105 for ; Tue, 22 Dec 2020 10:59:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726837AbgLVK65 (ORCPT ); Tue, 22 Dec 2020 05:58:57 -0500 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:60602 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726681AbgLVK64 (ORCPT ); Tue, 22 Dec 2020 05:58:56 -0500 Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 0BMAvKvC017379; Tue, 22 Dec 2020 11:58:11 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=hSH+H/5k2tLr+GOxs0FZsD8RmN2qSemTHcqXNWMd+Kk=; b=akxDJVmAlcc8vCZTooD8MGXAmwVlQPkX5n52kvzCdN9l/knVvzjLf2eb5AHtvxrpa1P6 Z4aD3KF+Oxf1MOHAgKBH1H9+DvhIlQP43aq30zqiEHfM2Pdj4ndsFeI2mgW00gV7Rg0h /X9Z27iO8PElu5FZ0dKnNwmRhNWxweNulPgU+34oVPM0hQt0myDZOYno7vHm5uHeg6y7 wQMTWvOcJ1WRSLFRZdtUItIUtTH6OAleMCof8n1wlieSTC8cpdHMpJEf7vTAEhLczrst aXVovvAbU0goo92Qe9dNNDii28wvgxdoLiWFs3SYAsR6sYzGBqA9KoZkgMo+xj0awMMX SA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 35k7vva3hq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 22 Dec 2020 11:58:10 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 934F5100034; Tue, 22 Dec 2020 11:58:10 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 8663622ECB4; Tue, 22 Dec 2020 11:58:10 +0100 (CET) Received: from localhost (10.75.127.48) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 22 Dec 2020 11:58:10 +0100 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier , Andy Gross CC: , , , , Subject: [PATCH v2 15/16] rpmsg: smd: add create and release rpmsg channel ops Date: Tue, 22 Dec 2020 11:57:25 +0100 Message-ID: <20201222105726.16906-16-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> References: <20201222105726.16906-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.48] X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-22_04:2020-12-21,2020-12-22 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org Add the new ops introduced by the rpmsg_ns series and used by the rpmsg_ctrl driver to instantiate a new rpmsg channel. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/qcom_smd.c | 57 ++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/drivers/rpmsg/qcom_smd.c b/drivers/rpmsg/qcom_smd.c index 19903de6268d..40853702f54f 100644 --- a/drivers/rpmsg/qcom_smd.c +++ b/drivers/rpmsg/qcom_smd.c @@ -67,6 +67,7 @@ struct smd_channel_info_word; struct smd_channel_info_word_pair; static const struct rpmsg_endpoint_ops qcom_smd_endpoint_ops; +static const struct rpmsg_device_ops qcom_smd_device_ops; #define SMD_ALLOC_TBL_COUNT 2 #define SMD_ALLOC_TBL_SIZE 64 @@ -1013,6 +1014,52 @@ static struct device_node *qcom_smd_match_channel(struct device_node *edge_node, return NULL; } +static void qcom_smd_release_device(struct device *dev) +{ + struct rpmsg_device *rpdev = to_rpmsg_device(dev); + struct qcom_smd_device *qsdev = to_smd_device(rpdev); + + kfree(qsdev); +} + +static struct rpmsg_device * +qcom_smd_create_rpmsg_ch(struct rpmsg_device *rp_parent, + struct rpmsg_channel_info *chinfo) +{ + struct qcom_smd_device *qsdev, *qspdev = to_smd_device(rp_parent); + struct qcom_smd_edge *edge = qspdev->edge; + int ret; + + qsdev = kzalloc(sizeof(*qsdev), GFP_KERNEL); + if (!qsdev) + return ERR_PTR(-ENOMEM); + + qsdev->edge = edge; + strncpy(qsdev->rpdev.id.name, chinfo->name, RPMSG_NAME_SIZE); + qsdev->rpdev.src = chinfo->src; + qsdev->rpdev.dst = chinfo->dst; + qsdev->rpdev.ops = &qcom_smd_device_ops; + qsdev->rpdev.dev.parent = &edge->dev; + qsdev->rpdev.dev.release = qcom_smd_release_device; + qsdev->rpdev.driver_override = (char *)chinfo->driver_override; + + ret = rpmsg_register_device(&qsdev->rpdev); + if (ret) { + kfree(qsdev); + return ERR_PTR(ret); + } + + return &qsdev->rpdev; +} + +static int qcom_smd_release_rpmsg_ch(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo) +{ + struct qcom_smd_device *qsdev = to_smd_device(rpdev); + + return rpmsg_unregister_device(&qsdev->edge->dev, chinfo); +} + static int qcom_smd_announce_create(struct rpmsg_device *rpdev) { struct qcom_smd_endpoint *qept = to_smd_endpoint(rpdev->ept); @@ -1033,6 +1080,8 @@ static int qcom_smd_announce_create(struct rpmsg_device *rpdev) static const struct rpmsg_device_ops qcom_smd_device_ops = { .create_ept = qcom_smd_create_ept, .announce_create = qcom_smd_announce_create, + .create_channel = qcom_smd_create_rpmsg_ch, + .release_channel = qcom_smd_release_rpmsg_ch, }; static const struct rpmsg_endpoint_ops qcom_smd_endpoint_ops = { @@ -1042,14 +1091,6 @@ static const struct rpmsg_endpoint_ops qcom_smd_endpoint_ops = { .poll = qcom_smd_poll, }; -static void qcom_smd_release_device(struct device *dev) -{ - struct rpmsg_device *rpdev = to_rpmsg_device(dev); - struct qcom_smd_device *qsdev = to_smd_device(rpdev); - - kfree(qsdev); -} - /* * Create a smd client device for channel that is being opened. */