Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5746954pxj; Wed, 23 Jun 2021 08:09:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFwH1FOCKAQ9rF7AOU9x/YlAJ1wzKErzgMngaLbGfSSlmKjrX4YQxdEZFBC6erN/A+tjeO X-Received: by 2002:a6b:7c07:: with SMTP id m7mr14380iok.47.1624460954162; Wed, 23 Jun 2021 08:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624460954; cv=none; d=google.com; s=arc-20160816; b=YpePKFZngpFE6lTB2DtSOoBT8qzCvs/P92g7xEENtKo7Y95m1+2yz836a3o542sftb Lrq3csLllYYuroj0e9IdR+SlG6f6WoJy+6GgpQBwVqywpQ+SSfKqgXbrSgI7dCbgEQcj MSt8oao61TS3ivqjaK1Ke9BKJVuCCCYJ211Ys2rQRsaiHtFRjyfLzZJh9sDr4IJ8AMDA cSJhFkR+UtEC2Jcir7e8Dr78TxrNj+a/4NCYmrhR7PwatKdxPiLfwt7qkaw4oDBWmGWx Pi6Lq+IhoctTlvhvUHAhsYS/ksf7U7NOcYKH8ovyTtkOH8Wvh5FBVTEfcbOWPcL3vf5x untQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qor8IDfXqtXwE4FJUTMJlIEuinvs4TdpF5ViY4rId8Y=; b=ZdDqjYbclEWKGnSiApT/Ed7L187fSWmGJXRlWpI2pzK3EdIOyNG6dZDc5Sqc7yK/PQ twi6iF9mv1OdHxTpHKmQ02miFtXbFHBziMM6h4W808GAZHYsyKIUo7A1t6h29XB5ZVaW BJzh7BzAA+EivpziQ6gbaIKjt5Cz0zFOd5DDS3qt8ByTzVa2lfXcpTaFGfHwUct/47kj CR5V38cgrz/RoE2bslTHSe9OWD4vIftMxEz1Hqf3WgrBCZCGlpaJuk1fb5U7vKF9RFmo AaLSWaURCekcodbn3FnXAcFLFXSblopaoateQwwLXGTKKAQCw4cxx6hEsmyzU4/dx6ek NeGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=8SXvwQhS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s21si229582jan.102.2021.06.23.08.09.02; Wed, 23 Jun 2021 08:09:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=8SXvwQhS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231326AbhFWPKp (ORCPT + 99 others); Wed, 23 Jun 2021 11:10:45 -0400 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:43535 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231229AbhFWPKj (ORCPT ); Wed, 23 Jun 2021 11:10:39 -0400 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 15NF20CV031734; Wed, 23 Jun 2021 17:08:14 +0200 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=qor8IDfXqtXwE4FJUTMJlIEuinvs4TdpF5ViY4rId8Y=; b=8SXvwQhSSVL0mqULs+y2ApobECB2JCcz07vkCIOOK+C0CF7rTejoEcsOrc17XmqbsjRQ nTJtiNyf2KsFMGGt0chLyMIRhyP8RhQ10fRY5U0awwLk2Hl/p50bRMd3GvOwulvgM9hd UZqd5K8B2w729MGRDJGFc8/uEdCFsEVJSQFfrBpNmFMmMOpo5VfHTwKTprsI8tqSCmO1 JpPVSXjeke6yTY+l67XDUAaG6OVL8b5pWhvQpbhdGSjOQ5TCUubcl/IcXb8RsmQR5N8G na8ocJBwwqcV8n/h34bbIOvaP/fFjrZwt7zPXHeWZU1Wn/juA09vF2OgEstJCyg/yCx6 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 39bwdckhq0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 23 Jun 2021 17:08:14 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 90F4A100034; Wed, 23 Jun 2021 17:08:13 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 7D86C22D186; Wed, 23 Jun 2021 17:08:13 +0200 (CEST) Received: from localhost (10.75.127.48) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 23 Jun 2021 17:08:12 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , , Subject: [PATCH v2 4/4] rpmsg: char: Introduce the "rpmsg-raw" channel Date: Wed, 23 Jun 2021 17:05:04 +0200 Message-ID: <20210623150504.14450-5-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210623150504.14450-1-arnaud.pouliquen@foss.st.com> References: <20210623150504.14450-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.48] 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.391,18.0.790 definitions=2021-06-23_09:2021-06-23,2021-06-23 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allows to probe the endpoint device on a remote name service announcement, by registering a rpmsg_driverfor the "rpmsg-raw" channel. With this patch the /dev/rpmsgX interface can be instantiated by the remote firmware. Signed-off-by: Arnaud Pouliquen --- update vs V1: - management of the default endpoint creation in the driver probe. --- drivers/rpmsg/rpmsg_char.c | 75 +++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c index a75dce1e29d8..3748de00c97b 100644 --- a/drivers/rpmsg/rpmsg_char.c +++ b/drivers/rpmsg/rpmsg_char.c @@ -25,6 +25,8 @@ #include "rpmsg_char.h" +#define RPMSG_CHAR_DEVNAME "rpmsg-raw" + static dev_t rpmsg_major; static struct class *rpmsg_class; @@ -421,6 +423,61 @@ int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent } EXPORT_SYMBOL(rpmsg_chrdev_eptdev_create); +static int rpmsg_chrdev_probe(struct rpmsg_device *rpdev) +{ + struct rpmsg_channel_info chinfo; + struct rpmsg_eptdev *eptdev; + struct rpmsg_endpoint *ept; + + memcpy(chinfo.name, RPMSG_CHAR_DEVNAME, sizeof(RPMSG_CHAR_DEVNAME)); + chinfo.src = rpdev->src; + chinfo.dst = rpdev->dst; + + eptdev = __rpmsg_chrdev_eptdev_create(rpdev, &rpdev->dev, chinfo); + if (IS_ERR(eptdev)) + return PTR_ERR(eptdev); + + /* + * Create the default endpoint associated to the rpmsg device and provide rpmsg_eptdev + * structure as callback private data. + */ + ept = rpmsg_create_default_ept(rpdev, rpmsg_ept_cb, eptdev, eptdev->chinfo); + if (!ept) { + dev_err(&rpdev->dev, "failed to create %s\n", eptdev->chinfo.name); + put_device(&eptdev->dev); + return -EINVAL; + } + + /* + * Do not allow the creation and release of an endpoint on /dev/rpmsgX open and close, + * reuse the default endpoint instead + */ + eptdev->static_ept = true; + + return 0; +} + +static void rpmsg_chrdev_remove(struct rpmsg_device *rpdev) +{ + int ret; + + ret = device_for_each_child(&rpdev->dev, NULL, rpmsg_chrdev_eptdev_destroy); + if (ret) + dev_warn(&rpdev->dev, "failed to destroy endpoints: %d\n", ret); +} + +static struct rpmsg_device_id rpmsg_chrdev_id_table[] = { + { .name = RPMSG_CHAR_DEVNAME }, + { }, +}; + +static struct rpmsg_driver rpmsg_chrdev_driver = { + .probe = rpmsg_chrdev_probe, + .remove = rpmsg_chrdev_remove, + .id_table = rpmsg_chrdev_id_table, + .drv.name = "rpmsg_chrdev", +}; + static int rpmsg_chrdev_init(void) { int ret; @@ -434,16 +491,30 @@ static int rpmsg_chrdev_init(void) rpmsg_class = class_create(THIS_MODULE, "rpmsg"); if (IS_ERR(rpmsg_class)) { pr_err("failed to create rpmsg class\n"); - unregister_chrdev_region(rpmsg_major, RPMSG_DEV_MAX); - return PTR_ERR(rpmsg_class); + ret = PTR_ERR(rpmsg_class); + goto free_region; + } + + ret = register_rpmsg_driver(&rpmsg_chrdev_driver); + if (ret < 0) { + pr_err("rpmsg: failed to register rpmsg raw driver\n"); + goto free_class; } return 0; + +free_class: + class_destroy(rpmsg_class); +free_region: + unregister_chrdev_region(rpmsg_major, RPMSG_DEV_MAX); + + return ret; } postcore_initcall(rpmsg_chrdev_init); static void rpmsg_chrdev_exit(void) { + unregister_rpmsg_driver(&rpmsg_chrdev_driver); class_destroy(rpmsg_class); unregister_chrdev_region(rpmsg_major, RPMSG_DEV_MAX); } -- 2.17.1