Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp462241pxv; Thu, 1 Jul 2021 02:05:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8JoeYeYmy/1hXbs4bNFSnJKwIveF1i+S3UDuxynOqLS0sVAhPAFGlxXdOkcyZBqUCm8/E X-Received: by 2002:a05:6602:2287:: with SMTP id d7mr11745814iod.172.1625130332796; Thu, 01 Jul 2021 02:05:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625130332; cv=none; d=google.com; s=arc-20160816; b=L/rvA9UlgPk1dIU7CFTZrf20MsRa5ElZoveJqvkGx43soeDALgXJB2qBnqw6XG5MNz pWxoOXnlaCqbC1R+Ysp6rhhTZRVKVppYj1x6IBfN3IBJftnCZfXzSJlHB2IRJM+E7R19 +D6QexRcMRWL7lJ9KdTRqzRJfJ+FO1cgV7zHF/hVPLTFXxKLEOxBjV7Wrcj+fI+o3A21 qR6SDx4bwR52V/GyQelCexeFO3bfPA0BiphVMXD8J1b07aQv0iHhmZKfyW+igjq2qWvH UBedmCypv01lG8Pac+OS2p3fpTSs7b609WK4gKgWG+ZuHC6G8wMeI+tSDjjIdEj8Qv5b NjuA== 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=LlO6IEU/SHg8OshK55jgAWx+zUTY73wIGvLbPSDyfuQ=; b=VCgEFJLoXXuO9EJ8MJaR1LyvJ13LBETiNXcimNm1xfIURfh3VQFBHb6WwnG4gNzpzG CohX7T74XDCPeXCSEHQokGVGq0oowDnv/DJ7NZ4KXx8TM3rhMlcKjCbeS69t19Htp7yi 4MY1zGNiTHmevlIS4e1GWIE6G7jdIHvCXS2JaVI8g6xGo5FgSkl06CSHVR3q8yt9OMXr lQcZKF0APKCovSDthJdnIRvnwMilauq6SDO2OI6l11vc4zIKaaQqJBT/kz57bosjn4U+ gdEQqvHRmVCHINSjx6RHBfC/zXGkB4gFiaK6HC19BLMbw44cPel2jereCOCMwoxw00Ih f//w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=yXsvUKJi; 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 h9si2897618jaj.40.2021.07.01.02.05.20; Thu, 01 Jul 2021 02:05:32 -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=yXsvUKJi; 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 S235736AbhGAJHE (ORCPT + 99 others); Thu, 1 Jul 2021 05:07:04 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:17202 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235662AbhGAJHB (ORCPT ); Thu, 1 Jul 2021 05:07:01 -0400 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 16192pIi005219; Thu, 1 Jul 2021 11:04:26 +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=LlO6IEU/SHg8OshK55jgAWx+zUTY73wIGvLbPSDyfuQ=; b=yXsvUKJiHG0V3fZP8VQ7QwpnwL4E7YAIRmnkvb3XvNWV1tiiYEja7vKaEEyGf374NQlq xSOlAnA++KR05PJL4DbbqhEJVA/RHeEVZmiq46Et2wITA1nOknUlRA6XTl18gS+7cdw2 TiyfwB2YfVlvE8hL8UtuUFHXxtEYN2KS+tplPFKymy1mJgLUBYYMhw0Dirfr6yoYxKnG SR03nT+t6arMzLvEKPRwje8W7oDPQ0Jsc2tZRlA5imkv/eNUtCNCRopOjpzGNEkwWgnE DNM0thRrar/t4qrnY+4nbCsTH+jW5/Gn2MPFwGcVs1AsaB6NR+lO79fdfO7AB+uAXVDk Iw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 39h7yj2bkg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Jul 2021 11:04:26 +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 03F6A10002A; Thu, 1 Jul 2021 11:04:26 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id E9C282138C8; Thu, 1 Jul 2021 11:04:25 +0200 (CEST) Received: from localhost (10.75.127.47) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 1 Jul 2021 11:04:25 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , , Subject: [PATCH v3 4/4] rpmsg: char: Introduce the "rpmsg-raw" channel Date: Thu, 1 Jul 2021 11:04:13 +0200 Message-ID: <20210701090413.3104-5-arnaud.pouliquen@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210701090413.3104-1-arnaud.pouliquen@foss.st.com> References: <20210701090413.3104-1-arnaud.pouliquen@foss.st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) 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-07-01_06:2021-06-30,2021-07-01 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 Reviewed-by: Mathieu Poirier --- 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 bd728d90ba4c..1b7b610e113d 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