Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2839743pxb; Tue, 13 Apr 2021 11:23:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3P9UUmCTd+e62c0eyA2WCK6EYBh0191EKUnxWUDaPYwi2owSxDehphKa9ojSYu+85hVR9 X-Received: by 2002:a05:6402:34f:: with SMTP id r15mr35596665edw.195.1618338217032; Tue, 13 Apr 2021 11:23:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618338217; cv=none; d=google.com; s=arc-20160816; b=TyQBXPfKTIAwFtJYszVv8jxcQCvl8/noZJmLcStGdSNFuYjD10m6QjEuPX78/z3Hnr 5pKIZVWRaqKAsKnT+hNdCqK5j7Rod+6d5vuc+vIodzvhXMl/BjNRW6WE5I70IppJlkhu FyUU6O3l3LpD30SJcrIfisiuHYwc0KqOWQzFRPJRgVfJ/MrslWOY6n2qhuHyXzcBA7aG nUwfxcLjFxt4inwzod2BAj/LInEwnxR9Y4sZGsCMFSsTa2w8Zkun51NLHmc1zV7xkmzZ 9LPVXOhmnHvZdpgOndOq+ifd/b/y0WfzBXuWL/4o9aSizE32jt1UfFnRARxWskGARXUT ZrBQ== 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=+oTL4g90zRRYBKheVDMDByO+/9wE2RBSRnj0O6Up2sM=; b=Y2m5ArTzw7qrNxQp1Us0Jq3K9nV4B9A1ewTmJBuYGXJh+4BkF4nK/asUCNpKUbj7Sd fuVzt28BZDa6WDWs6F8DJqVfEhSg2IF0ti2EeMS23jof0bTzQ3eE0zslA6hyihKYuWSX DTQc4Aqvt4F4QZTJCGj8iyJccEk0g9l4ACJlqNOOMmo5jzQP0Lq8hlM3Gu3MGPQ5SVm/ wbn6S5Im8FIxrkU6HbUnihvWCniDjr9jxGXyAMKUEX7eyQS8LqXTQbZ3NDeSFuhgNsdr 9cuzvs0sulxzwulwtbXfPjwkJ1YaqUe8+TeBY+P5ubaiwdWOLKjxDH3B+62w+3O3NqIi TFLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=SoxqWzhw; 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 d14si10808264edy.9.2021.04.13.11.23.13; Tue, 13 Apr 2021 11:23:37 -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=SoxqWzhw; 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 S1346134AbhDMNqO (ORCPT + 99 others); Tue, 13 Apr 2021 09:46:14 -0400 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:10340 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346080AbhDMNpp (ORCPT ); Tue, 13 Apr 2021 09:45:45 -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 13DDgBmX020003; Tue, 13 Apr 2021 15:45:23 +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=+oTL4g90zRRYBKheVDMDByO+/9wE2RBSRnj0O6Up2sM=; b=SoxqWzhwL5qqv91kAmVhK1J+nv+79/tvsPc4Zo84ZufKO7EaOBfjiQ2qvabuyMGxfRI0 ttv6FfA2KU9EXWJin4LLiomSnNZLAlRSyCO1oGR+rjl7Yk5gxb0jKZvUyfzuLCeQdrpN G+/kglDr0n9v2PGzNeDvohKOoSRlvD6FYPUwPBg1k4OhsrS3b3wFpxy+P9CTSIjzTW0M 5gKfkK2y2w3NGWDvpxaCaGTS6oQ2qMs1Ds+HtJRNtzzIqx1hPUSGDVlQg/N/0MwOW9Sl GJ/8Y8kO8NLvA9CV8dloMrQsQtxnmCdZhzbY+XVbM5AFBiNoJPQASfRLp7b/rvJsxo3W Zg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 37vwg94ngh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 13 Apr 2021 15:45:23 +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 438E110002A; Tue, 13 Apr 2021 15:45:23 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 3643C226C5A; Tue, 13 Apr 2021 15:45:23 +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; Tue, 13 Apr 2021 15:45:22 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , Subject: [PATCH v2 5/7] rpmsg: char: Introduce a rpmsg driver for the rpmsg char device Date: Tue, 13 Apr 2021 15:44:56 +0200 Message-ID: <20210413134458.17912-6-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210413134458.17912-1-arnaud.pouliquen@foss.st.com> References: <20210413134458.17912-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 Content-Type: text/plain 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.391,18.0.761 definitions=2021-04-13_07:2021-04-13,2021-04-13 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A rpmsg char device allows to probe the endpoint device on a remote name service announcement. With this patch the /dev/rpmsgX interface is created either by a user application or by the remote firmware. Signed-off-by: Arnaud Pouliquen --- update from V1: - add missing unregister_rpmsg_driver call on module exit. --- drivers/rpmsg/rpmsg_char.c | 59 +++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/drivers/rpmsg/rpmsg_char.c b/drivers/rpmsg/rpmsg_char.c index a64249d83172..4606787b7011 100644 --- a/drivers/rpmsg/rpmsg_char.c +++ b/drivers/rpmsg/rpmsg_char.c @@ -26,6 +26,8 @@ #include "rpmsg_char.h" #include "rpmsg_internal.h" +#define RPMSG_CHAR_DEVNAME "rpmsg-raw" + static dev_t rpmsg_major; static DEFINE_IDA(rpmsg_ept_ida); @@ -403,13 +405,67 @@ int rpmsg_chrdev_create_eptdev(struct rpmsg_device *rpdev, struct device *parent } EXPORT_SYMBOL(rpmsg_chrdev_create_eptdev); +static int rpmsg_chrdev_probe(struct rpmsg_device *rpdev) +{ + struct rpmsg_channel_info chinfo; + struct rpmsg_eptdev *eptdev; + + if (!rpdev->ept) + return -EINVAL; + + memcpy(chinfo.name, RPMSG_CHAR_DEVNAME, sizeof(RPMSG_CHAR_DEVNAME)); + chinfo.src = rpdev->src; + chinfo.dst = rpdev->dst; + + eptdev = __rpmsg_chrdev_create_eptdev(rpdev, &rpdev->dev, chinfo, NULL); + if (IS_ERR(eptdev)) + return PTR_ERR(eptdev); + + /* Set the private field of the default endpoint to retrieve context on callback. */ + rpdev->ept->priv = eptdev; + + return 0; +} + +static void rpmsg_chrdev_remove(struct rpmsg_device *rpdev) +{ + int ret; + + ret = device_for_each_child(&rpdev->dev, NULL, rpmsg_chrdev_destroy_eptdev); + 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, + .callback = rpmsg_ept_cb, + .drv = { + .name = "rpmsg_chrdev", + }, +}; + static int rpmsg_chrdev_init(void) { int ret; ret = alloc_chrdev_region(&rpmsg_major, 0, RPMSG_DEV_MAX, "rpmsg_char"); - if (ret < 0) + if (ret < 0) { pr_err("rpmsg: failed to allocate char dev region\n"); + return ret; + } + + ret = register_rpmsg_driver(&rpmsg_chrdev_driver); + if (ret < 0) { + pr_err("rpmsg: failed to register rpmsg raw driver\n"); + unregister_chrdev_region(rpmsg_major, RPMSG_DEV_MAX); + } return ret; } @@ -417,6 +473,7 @@ postcore_initcall(rpmsg_chrdev_init); static void rpmsg_chrdev_exit(void) { + unregister_rpmsg_driver(&rpmsg_chrdev_driver); unregister_chrdev_region(rpmsg_major, RPMSG_DEV_MAX); } module_exit(rpmsg_chrdev_exit); -- 2.17.1