From patchwork Tue Aug 25 16:49:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 11735981 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 30C5E722 for ; Tue, 25 Aug 2020 16:52:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 141E12074D for ; Tue, 25 Aug 2020 16:52:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=st.com header.i=@st.com header.b="b22u3Msv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726713AbgHYQww (ORCPT ); Tue, 25 Aug 2020 12:52:52 -0400 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:11314 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726119AbgHYQwW (ORCPT ); Tue, 25 Aug 2020 12:52:22 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07PGlRRJ007563; Tue, 25 Aug 2020 18:52:14 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=PWq2Fd9CmuFDcof5DhJA8swylSAL/EhvY4+9u/ySbmQ=; b=b22u3Msvsh3z0x0BiS4tc2furm5WHFoVmBDnxKlEIi7gOiEeGts7CdM0gthVK87tAB2X XTDz8aMwg5aiZgEGSyyAmKM0X3tKP9kJaBfVRYySB7KijVPQr3RySFhcisMlZjT/h++2 4cB95wHa211O7kW91V6F4jKr1mw3GT9w5IpBY61pDWQTzKN4uGMrBeMU3oRLuWRzdX7m r9EwcueF8mdZuIHEp6LW6b2qdtdlX9qC+WXlUGb2yMUyItyH1VmAxnxNu8gmp42I2Xoj lHPnTbP9ky7dPNP5y2LDQluaCIuVLdYpIT8m3GMcHxLo6Y1rdVlhoCn1oXgGdJD0zKDW hQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 333b2mm0jp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2020 18:52: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 1A8DE10002A; Tue, 25 Aug 2020 18:52:14 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node1.st.com [10.75.127.7]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 0BCAC2A5E44; Tue, 25 Aug 2020 18:52:14 +0200 (CEST) Received: from localhost (10.75.127.46) by SFHDAG3NODE1.st.com (10.75.127.7) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 25 Aug 2020 18:52:13 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , Subject: [PATCH v2 1/8] rpmsg: virtio: rename rpmsg_create_channel Date: Tue, 25 Aug 2020 18:49:00 +0200 Message-ID: <20200825164907.3642-2-arnaud.pouliquen@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200825164907.3642-1-arnaud.pouliquen@st.com> References: <20200825164907.3642-1-arnaud.pouliquen@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG6NODE2.st.com (10.75.127.17) To SFHDAG3NODE1.st.com (10.75.127.7) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-25_06:2020-08-25,2020-08-25 signatures=0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Rename the internal function as it is internal, and as the name will be used in rpmsg_core. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/virtio_rpmsg_bus.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 9006fc7f73d0..736bc7b9dea8 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -390,8 +390,9 @@ static void virtio_rpmsg_release_device(struct device *dev) * this function will be used to create both static and dynamic * channels. */ -static struct rpmsg_device *rpmsg_create_channel(struct virtproc_info *vrp, - struct rpmsg_channel_info *chinfo) +static struct rpmsg_device * +__rpmsg_create_channel(struct virtproc_info *vrp, + struct rpmsg_channel_info *chinfo) { struct virtio_rpmsg_channel *vch; struct rpmsg_device *rpdev; @@ -864,7 +865,7 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len, if (ret) dev_err(dev, "rpmsg_destroy_channel failed: %d\n", ret); } else { - newch = rpmsg_create_channel(vrp, &chinfo); + newch = __rpmsg_create_channel(vrp, &chinfo); if (!newch) dev_err(dev, "rpmsg_create_channel failed\n"); } From patchwork Tue Aug 25 16:49:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 11735987 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A399E138A for ; Tue, 25 Aug 2020 16:53:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 839AC207BC for ; Tue, 25 Aug 2020 16:53:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=st.com header.i=@st.com header.b="ts/rfNXw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726772AbgHYQxI (ORCPT ); Tue, 25 Aug 2020 12:53:08 -0400 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:38408 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726180AbgHYQwW (ORCPT ); Tue, 25 Aug 2020 12:52:22 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07PGmbAS019652; Tue, 25 Aug 2020 18:52:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=FV+yGzCorer44bS2EQ3ZmV/Ce/Z43eVcESLLlSmmrtQ=; b=ts/rfNXw8XcHx9MORqLI/c1cY4/On+1quw5XXosxG3vgZgBvawzSXAf6p1O3wnQ3wD5h 7R+N0ULAYOIJSRXD09cm414YHafVHbmApBBYkpXb4FvlvJkAfjXl2Cv0Hrbvo+dsG/n/ oP/1Yef9HcRqtT/ujJ/Zx5qLMAconKyZO8iKGfVLoVTqP6ewhTI/CeOLpThwtFZaUjIb wb0dlLih+EfkHFoHJrIk0evqX7tHU8II5QrAkKhp7ve7AJtKIeHrWi6yl5dOjI2XI9MI /1+4itjOLlZYlNX8uNVIeWjR+EGssQDs1Pr7NXx1t0Dl7wtbOASKrAev/Twx1wqljN7X 0g== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 333b6x405t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2020 18:52:15 +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 330D610002A; Tue, 25 Aug 2020 18:52:15 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node1.st.com [10.75.127.7]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 287602AE6AA; Tue, 25 Aug 2020 18:52:15 +0200 (CEST) Received: from localhost (10.75.127.45) by SFHDAG3NODE1.st.com (10.75.127.7) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 25 Aug 2020 18:52:14 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , Subject: [PATCH v2 2/8] rpmsg: core: add channel creation internal API Date: Tue, 25 Aug 2020 18:49:01 +0200 Message-ID: <20200825164907.3642-3-arnaud.pouliquen@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200825164907.3642-1-arnaud.pouliquen@st.com> References: <20200825164907.3642-1-arnaud.pouliquen@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG4NODE2.st.com (10.75.127.11) To SFHDAG3NODE1.st.com (10.75.127.7) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-25_06:2020-08-25,2020-08-25 signatures=0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Add the channel creation API as a first step to be able to define the name service announcement as a rpmsg driver independent from the RPMsg virtio bus. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/rpmsg_core.c | 45 ++++++++++++++++++++++++++++++++++ drivers/rpmsg/rpmsg_internal.h | 12 +++++++++ 2 files changed, 57 insertions(+) diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c index a6361cad608b..97c15c1a0cc8 100644 --- a/drivers/rpmsg/rpmsg_core.c +++ b/drivers/rpmsg/rpmsg_core.c @@ -20,6 +20,51 @@ #include "rpmsg_internal.h" +/** + * rpmsg_create_channel() - create a new rpmsg channel + * using its name and address info. + * @rpdev: rpmsg driver + * @chinfo: channel_info to bind + * + * Returns a pointer to the new rpmsg device on success, or NULL on error. + */ +struct rpmsg_device * + rpmsg_create_channel(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo) +{ + if (WARN_ON(!rpdev)) + return NULL; + if (!rpdev->ops || !rpdev->ops->create_channel) { + dev_err(&rpdev->dev, "no create_channel ops found\n"); + return NULL; + } + + return rpdev->ops->create_channel(rpdev, chinfo); +} +EXPORT_SYMBOL(rpmsg_create_channel); + +/** + * rpmsg_release_channel() - release a rpmsg channel + * using its name and address info. + * @rpdev: rpmsg driver + * @chinfo: channel_info to bind + * + * Returns 0 on success or an appropriate error value. + */ +int rpmsg_release_channel(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo) +{ + if (WARN_ON(!rpdev)) + return -EINVAL; + if (!rpdev->ops || !rpdev->ops->release_channel) { + dev_err(&rpdev->dev, "no release_channel ops found\n"); + return -EPERM; + } + + return rpdev->ops->release_channel(rpdev, chinfo); +} +EXPORT_SYMBOL(rpmsg_release_channel); + /** * rpmsg_create_ept() - create a new rpmsg_endpoint * @rpdev: rpmsg channel device diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h index 3fc83cd50e98..d5ab286d0e5e 100644 --- a/drivers/rpmsg/rpmsg_internal.h +++ b/drivers/rpmsg/rpmsg_internal.h @@ -20,6 +20,8 @@ /** * struct rpmsg_device_ops - indirection table for the rpmsg_device operations + * @create_channel: create backend-specific channel, optional + * @release_channel: release backend-specific channel, optional * @create_ept: create backend-specific endpoint, required * @announce_create: announce presence of new channel, optional * @announce_destroy: announce destruction of channel, optional @@ -29,6 +31,11 @@ * advertise new channels implicitly by creating the endpoints. */ struct rpmsg_device_ops { + struct rpmsg_device *(*create_channel)(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo); + int (*release_channel)(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo); + struct rpmsg_endpoint *(*create_ept)(struct rpmsg_device *rpdev, rpmsg_rx_cb_t cb, void *priv, struct rpmsg_channel_info chinfo); @@ -75,6 +82,11 @@ int rpmsg_unregister_device(struct device *parent, struct device *rpmsg_find_device(struct device *parent, struct rpmsg_channel_info *chinfo); +struct rpmsg_device * + rpmsg_create_channel(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo); +int rpmsg_release_channel(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo); /** * rpmsg_chrdev_register_device() - register chrdev device based on rpdev * @rpdev: prepared rpdev to be used for creating endpoints From patchwork Tue Aug 25 16:49:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 11735983 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7521D138A for ; Tue, 25 Aug 2020 16:53:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 571F320782 for ; Tue, 25 Aug 2020 16:53:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=st.com header.i=@st.com header.b="dqywmQwn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726119AbgHYQxH (ORCPT ); Tue, 25 Aug 2020 12:53:07 -0400 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:11320 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726225AbgHYQwW (ORCPT ); Tue, 25 Aug 2020 12:52:22 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07PGlScp007570; Tue, 25 Aug 2020 18:52:16 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=kMfl9Sr0LMliL5b6+fSDTyEPWpdoi90a8Uixu9L/D/s=; b=dqywmQwnEVN8HISkx0BMcvRXW8eEi4Vwi3C7ILXASH0UOvUSWMNHA3D6HEBzMCh58V3u urAs3rNDVQt2eUGjmHUDq0ead2s8NGyaCHd5tHj8GpQxMSkBghgmaapMxna8dV9iz/eI fxITQ5pcUmlifLnVaIpSO6elxDqbkeUGU1enmNM5/rTqi1xe60MEm+uFD7H+kQGp8rTm lLa2ngUvlJyXUWll8hEXTVSvyubEcoBrwHdLQQoWsWY424hZ9N+PoVIgpw/RLmb3S3Pj jfA/NaOt2O/xIDvkgwFM4YttqyUUq1pfZrufDXkPOvCJujKubOt1Q2dTya55agEKaWzb 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 333b2mm0jq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2020 18:52:16 +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 3C7DB10002A; Tue, 25 Aug 2020 18:52:16 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node1.st.com [10.75.127.7]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 31D5E2AE6AA; Tue, 25 Aug 2020 18:52:16 +0200 (CEST) Received: from localhost (10.75.127.45) by SFHDAG3NODE1.st.com (10.75.127.7) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 25 Aug 2020 18:52:15 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , Subject: [PATCH v2 3/8] rpmsg: virtio: add rpmsg channel device ops Date: Tue, 25 Aug 2020 18:49:02 +0200 Message-ID: <20200825164907.3642-4-arnaud.pouliquen@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200825164907.3642-1-arnaud.pouliquen@st.com> References: <20200825164907.3642-1-arnaud.pouliquen@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG6NODE2.st.com (10.75.127.17) To SFHDAG3NODE1.st.com (10.75.127.7) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-25_06:2020-08-25,2020-08-25 signatures=0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Implement the create and release of the RPMsg channel for the RPMsg virtio bus. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/virtio_rpmsg_bus.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 736bc7b9dea8..910d30818901 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -176,6 +176,12 @@ static int virtio_rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst); static int virtio_rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, void *data, int len); +static struct rpmsg_device * + virtio_rpmsg_create_channel(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo); +static int virtio_rpmsg_release_channel(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo); + static const struct rpmsg_endpoint_ops virtio_endpoint_ops = { .destroy_ept = virtio_rpmsg_destroy_ept, @@ -372,6 +378,8 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev) } static const struct rpmsg_device_ops virtio_rpmsg_ops = { + .create_channel = virtio_rpmsg_create_channel, + .release_channel = virtio_rpmsg_release_channel, .create_ept = virtio_rpmsg_create_ept, .announce_create = virtio_rpmsg_announce_create, .announce_destroy = virtio_rpmsg_announce_destroy, @@ -439,6 +447,25 @@ __rpmsg_create_channel(struct virtproc_info *vrp, return rpdev; } +static struct rpmsg_device * + virtio_rpmsg_create_channel(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo) +{ + struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(rpdev); + struct virtproc_info *vrp = vch->vrp; + + return __rpmsg_create_channel(vrp, chinfo); +} + +static int virtio_rpmsg_release_channel(struct rpmsg_device *rpdev, + struct rpmsg_channel_info *chinfo) +{ + struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(rpdev); + struct virtproc_info *vrp = vch->vrp; + + return rpmsg_unregister_device(&vrp->vdev->dev, chinfo); +} + /* super simple buffer "allocator" that is just enough for now */ static void *get_a_tx_buf(struct virtproc_info *vrp) { From patchwork Tue Aug 25 16:49:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 11735969 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 45341722 for ; Tue, 25 Aug 2020 16:52:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EFA3A2074D for ; Tue, 25 Aug 2020 16:52:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=st.com header.i=@st.com header.b="mg8NEeHW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726541AbgHYQwa (ORCPT ); Tue, 25 Aug 2020 12:52:30 -0400 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:14880 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726257AbgHYQwW (ORCPT ); Tue, 25 Aug 2020 12:52:22 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07PGma4t019638; Tue, 25 Aug 2020 18:52:17 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=0GCBgslDZw0GYxmu1/0QyIojItqk9H/Ui6PIwaiTKBw=; b=mg8NEeHWeIDRhaYlBKOrdtT6jbEVUimzAHa2GzUgIJpxgEIndV1wt6cKtQrVEqgsrLQD Vc6WsdsxIidudWCXIb1HkomJPGPY9RRDEyfZvuKxcbGV6OyC6HimW6rkrE1z5seZxPBL gQQ7oIQ9wm4fGL2CCMKM4ptDCG4FxYgUGD3XDY4oENheEmk4+xnOIff7IMq2ivZZ15zk 52lQWN300HuMf+FihCjHSf/5nz70OSn0Bmjx03tmvBRnPfaBC7mMl1jfm44g6tl8ncQ0 uMwNJEhV5uGp3y+UFtHZg8gTrIeSZpx+Y2sswwiHfSr92tTS1ti4MEplGXVNjbyjEWim Jw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 333b6x405v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2020 18:52:17 +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 5CDBB10002A; Tue, 25 Aug 2020 18:52:17 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node1.st.com [10.75.127.7]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 4E9872AE6AA; Tue, 25 Aug 2020 18:52:17 +0200 (CEST) Received: from localhost (10.75.127.47) by SFHDAG3NODE1.st.com (10.75.127.7) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 25 Aug 2020 18:52:16 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , Subject: [PATCH v2 4/8] rpmsg: define the name service announcement as reserved address Date: Tue, 25 Aug 2020 18:49:03 +0200 Message-ID: <20200825164907.3642-5-arnaud.pouliquen@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200825164907.3642-1-arnaud.pouliquen@st.com> References: <20200825164907.3642-1-arnaud.pouliquen@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG1NODE1.st.com (10.75.127.1) To SFHDAG3NODE1.st.com (10.75.127.7) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-25_06:2020-08-25,2020-08-25 signatures=0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org The address 53 is reserved for the dynamic RPMsg device management on name service announcement. Define this address in a reserved enum list. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/virtio_rpmsg_bus.c | 3 --- include/linux/rpmsg.h | 9 +++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 910d30818901..b2927661868c 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -162,9 +162,6 @@ struct virtio_rpmsg_channel { */ #define RPMSG_RESERVED_ADDRESSES (1024) -/* Address 53 is reserved for advertising remote services */ -#define RPMSG_NS_ADDR (53) - static void virtio_rpmsg_destroy_ept(struct rpmsg_endpoint *ept); static int virtio_rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len); static int virtio_rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index 9fe156d1c018..5496d27c6f8c 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -20,6 +20,15 @@ #define RPMSG_ADDR_ANY 0xFFFFFFFF +/** + * enum rpmsg_ns_flags - List of reserved RPMsg addresses + * + * @RPMSG_NS_ADDR: remote services advertising for dynamic allocation + */ +enum rpmsg_reserved_addr { + RPMSG_NS_ADDR = 53, +}; + struct rpmsg_device; struct rpmsg_endpoint; struct rpmsg_device_ops; From patchwork Tue Aug 25 16:49:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 11735977 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60DC5722 for ; Tue, 25 Aug 2020 16:52:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D325207F7 for ; Tue, 25 Aug 2020 16:52:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=st.com header.i=@st.com header.b="NTuV4Ke+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726646AbgHYQwp (ORCPT ); Tue, 25 Aug 2020 12:52:45 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:4852 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726432AbgHYQwX (ORCPT ); Tue, 25 Aug 2020 12:52:23 -0400 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07PGlZhj022125; Tue, 25 Aug 2020 18:52:19 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=MdBHNAciaOZT/V6lYVJZytJnA49Ho8CJeT11yWtBVAc=; b=NTuV4Ke+r1k5ix9giVOQtefYjS4rEJkJDLQyJWRXRRgRoRZfaDVkBc4H41Bq5MHGhe1Z DPKeSmrA1ZKkQ67gpAh4EIAm7jZ36VXKUrPYAMpqLBhD/12ULUPMNLvxzcnufix8RDyV bulM1NzfKBvniLjFRhVehBfONw5/5szyaoeD56Mpkmkbyj+JZZbNaoaS6KYHz3MVXJAX CzWQIRjt5E68a9IhpE6tZcq3lh4MqiALXo/V69VM651D1RqaAIRWrTboiCGurqRHfDol jZCVtgp+xyP4HfhA6Y6IWRapjNn1lUGR75Iv5xSRocSWSyHIh+xiCh+GP521SMUIPhFB 6A== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 333b3hc2y3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2020 18:52:19 +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 9D2C3100034; Tue, 25 Aug 2020 18:52:18 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node1.st.com [10.75.127.7]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 928882AE6AA; Tue, 25 Aug 2020 18:52:18 +0200 (CEST) Received: from localhost (10.75.127.46) by SFHDAG3NODE1.st.com (10.75.127.7) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 25 Aug 2020 18:52:17 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , Subject: [PATCH v2 5/8] rpmsg: introduce reserved rpmsg driver for ns announcement Date: Tue, 25 Aug 2020 18:49:04 +0200 Message-ID: <20200825164907.3642-6-arnaud.pouliquen@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200825164907.3642-1-arnaud.pouliquen@st.com> References: <20200825164907.3642-1-arnaud.pouliquen@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG7NODE3.st.com (10.75.127.21) To SFHDAG3NODE1.st.com (10.75.127.7) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-25_06:2020-08-25,2020-08-25 signatures=0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org The name service announcement should not be linked to the RPMsg virtio bus but to the RPMsg protocol itself. This patch proposes to break the dependency with the RPmsg virtio bus by the introduction of the reserved RPMsg name service driver which will be in charge of managing the RPMsg name service announcement. This first patch only implements the probe and the RPMsg endpoint to manage create and release channels remote requests. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/Kconfig | 8 ++ drivers/rpmsg/Makefile | 1 + drivers/rpmsg/rpmsg_internal.h | 17 +++++ drivers/rpmsg/rpmsg_ns.c | 135 +++++++++++++++++++++++++++++++++ 4 files changed, 161 insertions(+) create mode 100644 drivers/rpmsg/rpmsg_ns.c diff --git a/drivers/rpmsg/Kconfig b/drivers/rpmsg/Kconfig index f96716893c2a..c3fc75e6514b 100644 --- a/drivers/rpmsg/Kconfig +++ b/drivers/rpmsg/Kconfig @@ -15,6 +15,14 @@ config RPMSG_CHAR in /dev. They make it possible for user-space programs to send and receive rpmsg packets. +config RPMSG_NS + tristate "RPMSG name service announcement" + depends on RPMSG + help + Say Y here to enable the support of the name service announcement + channel that probes the associated RPMsg device on remote endpoint + service announcement. + config RPMSG_MTK_SCP tristate "MediaTek SCP" depends on MTK_SCP diff --git a/drivers/rpmsg/Makefile b/drivers/rpmsg/Makefile index ffe932ef6050..8d452656f0ee 100644 --- a/drivers/rpmsg/Makefile +++ b/drivers/rpmsg/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_RPMSG) += rpmsg_core.o obj-$(CONFIG_RPMSG_CHAR) += rpmsg_char.o +obj-$(CONFIG_RPMSG_NS) += rpmsg_ns.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_internal.h b/drivers/rpmsg/rpmsg_internal.h index d5ab286d0e5e..641b48f6bf2a 100644 --- a/drivers/rpmsg/rpmsg_internal.h +++ b/drivers/rpmsg/rpmsg_internal.h @@ -102,4 +102,21 @@ static inline int rpmsg_chrdev_register_device(struct rpmsg_device *rpdev) return rpmsg_register_device(rpdev); } +/** + * rpmsg_ns_register_device() - register name service device based on rpdev + * @rpdev: prepared rpdev to be used for creating endpoints + * + * This function wraps rpmsg_register_device() preparing the rpdev for use as + * basis for the rpmsg name service device. + */ +static inline int rpmsg_ns_register_device(struct rpmsg_device *rpdev) +{ + strcpy(rpdev->id.name, "rpmsg_ns"); + rpdev->driver_override = "rpmsg_ns"; + rpdev->src = RPMSG_NS_ADDR; + rpdev->dst = RPMSG_NS_ADDR; + + return rpmsg_register_device(rpdev); +} + #endif diff --git a/drivers/rpmsg/rpmsg_ns.c b/drivers/rpmsg/rpmsg_ns.c new file mode 100644 index 000000000000..3c929b6976a6 --- /dev/null +++ b/drivers/rpmsg/rpmsg_ns.c @@ -0,0 +1,135 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) STMicroelectronics 2020 - All Rights Reserved + */ +#include +#include +#include +#include +#include "rpmsg_internal.h" + +/** + * enum rpmsg_ns_flags - dynamic name service announcement flags + * + * @RPMSG_NS_CREATE: a new remote service was just created + * @RPMSG_NS_DESTROY: a known remote service was just destroyed + */ +enum rpmsg_ns_flags { + RPMSG_NS_CREATE = 0, + RPMSG_NS_DESTROY = 1, +}; + +/** + * struct rpmsg_ns_msg - dynamic name service announcement message + * @name: name of remote service that is published + * @addr: address of remote service that is published + * @flags: indicates whether service is created or destroyed + * + * This message is sent across to publish a new service, or announce + * about its removal. When we receive these messages, an appropriate + * rpmsg channel (i.e device) is created/destroyed. In turn, the ->probe() + * or ->remove() handler of the appropriate rpmsg driver will be invoked + * (if/as-soon-as one is registered). + */ +struct rpmsg_ns_msg { + char name[RPMSG_NAME_SIZE]; + __le32 addr; + __le32 flags; +} __packed; + +/* Invoked when a name service announcement arrives */ +static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len, + void *priv, u32 src) +{ + struct rpmsg_ns_msg *msg = data; + struct rpmsg_device *newch; + struct rpmsg_channel_info chinfo; + struct device *dev = &rpdev->dev; + unsigned int flags = le32_to_cpu(msg->flags); + int ret; + +#if defined(CONFIG_DYNAMIC_DEBUG) + dynamic_hex_dump("NS announcement: ", DUMP_PREFIX_NONE, 16, 1, + data, len, true); +#endif + + if (len != sizeof(*msg)) { + dev_err(dev, "malformed ns msg (%d)\n", len); + return -EINVAL; + } + + /* Don't trust the remote processor for null terminating the name */ + msg->name[RPMSG_NAME_SIZE - 1] = '\0'; + + strncpy(chinfo.name, msg->name, sizeof(chinfo.name)); + chinfo.src = RPMSG_ADDR_ANY; + chinfo.dst = le32_to_cpu(msg->addr); + + dev_info(dev, "%sing channel %s addr 0x%x\n", + (flags & RPMSG_NS_DESTROY) ? "destroy" : "creat", + msg->name, chinfo.dst); + + if (flags & RPMSG_NS_DESTROY) { + ret = rpmsg_release_channel(rpdev, &chinfo); + if (ret) + dev_err(dev, "rpmsg_destroy_channel failed: %d\n", ret); + } else { + newch = rpmsg_create_channel(rpdev, &chinfo); + if (!newch) + dev_err(dev, "rpmsg_create_channel failed\n"); + } + + return 0; +} + +static int rpmsg_ns_probe(struct rpmsg_device *rpdev) +{ + struct rpmsg_channel_info ns_chinfo; + struct rpmsg_endpoint *ns_ept; + + ns_chinfo.src = RPMSG_NS_ADDR; + ns_chinfo.dst = RPMSG_NS_ADDR; + strcpy(ns_chinfo.name, "name_service"); + + /* + * Create the NS announcement service endpoint associated to the RPMsg + * device. The endpoint will be automatically destroyed when the RPMsg + * device will be deleted. + */ + ns_ept = rpmsg_create_ept(rpdev, rpmsg_ns_cb, NULL, ns_chinfo); + if (!ns_ept) { + dev_err(&rpdev->dev, "failed to create the ns ept\n"); + return -ENOMEM; + } + rpdev->ept = ns_ept; + + return 0; +} + +static struct rpmsg_driver rpmsg_ns_driver = { + .drv.name = "rpmsg_ns", + .probe = rpmsg_ns_probe, +}; + +static int rpmsg_ns_init(void) +{ + int ret; + + ret = register_rpmsg_driver(&rpmsg_ns_driver); + if (ret < 0) + pr_err("%s: Failed to register rpmsg driver\n", __func__); + + return ret; +} +postcore_initcall(rpmsg_ns_init); + +static void rpmsg_ns_exit(void) +{ + unregister_rpmsg_driver(&rpmsg_ns_driver); +} +module_exit(rpmsg_ns_exit); + +MODULE_DESCRIPTION("Name service announcement rpmsg Driver"); +MODULE_AUTHOR("Arnaud Pouliquen "); +MODULE_ALIAS("rpmsg_ns"); +MODULE_LICENSE("GPL v2"); From patchwork Tue Aug 25 16:49:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 11735975 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 16B0B138A for ; Tue, 25 Aug 2020 16:52:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE29B2075F for ; Tue, 25 Aug 2020 16:52:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=st.com header.i=@st.com header.b="YGKA1kki" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726633AbgHYQwh (ORCPT ); Tue, 25 Aug 2020 12:52:37 -0400 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:58091 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726090AbgHYQwX (ORCPT ); Tue, 25 Aug 2020 12:52:23 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07PGlScq007570; Tue, 25 Aug 2020 18:52:20 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=bFaFCJlPre9ESUbxiA1qF6tDhs9qqazLruK9j4B6DF4=; b=YGKA1kkid+xyPaVr3qgFlp4iD6MSSLQKG2gSaJPdN7RD53lB1s16HBE+Id+6oG2S3eVM KhodJoAs6GrdtDZrviKi9aMuRWQN9tf1i8KybjB1hrqdjWg6IImUqs8KYvjyRniIIfL4 bI5VpKBRXQUFyBrhvU7sICqHLVl5/CvMuyLtInH5sU3fJFfK2pIwzsVt25si0FADedce dsz60Gn01ZacMp/ukIidF5EOjNCOZPiLQ37Y5GrmWab4tWJMUsEp1Hs16Cl9T9MkEkFi fjYuUNPmvzAnQg75GF5Lk7LPAZonQKo2dtyg9hAqLgtjtSnUCe76z+i2/7kapQBXNEYA yg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 333b2mm0jx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2020 18:52:20 +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 B875F10002A; Tue, 25 Aug 2020 18:52:19 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node1.st.com [10.75.127.7]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id AD6FA2AE6AA; Tue, 25 Aug 2020 18:52:19 +0200 (CEST) Received: from localhost (10.75.127.44) by SFHDAG3NODE1.st.com (10.75.127.7) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 25 Aug 2020 18:52:19 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , Subject: [PATCH v2 6/8] rpmsg: virtio: use rpmsg ns device for the ns announcement Date: Tue, 25 Aug 2020 18:49:05 +0200 Message-ID: <20200825164907.3642-7-arnaud.pouliquen@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200825164907.3642-1-arnaud.pouliquen@st.com> References: <20200825164907.3642-1-arnaud.pouliquen@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG8NODE2.st.com (10.75.127.23) To SFHDAG3NODE1.st.com (10.75.127.7) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-25_06:2020-08-25,2020-08-25 signatures=0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org As generic NS driver is available, rely on it for NS management instead of managing it in RPMsg virtio bus. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/Kconfig | 1 + drivers/rpmsg/virtio_rpmsg_bus.c | 86 ++++++++------------------------ 2 files changed, 21 insertions(+), 66 deletions(-) diff --git a/drivers/rpmsg/Kconfig b/drivers/rpmsg/Kconfig index c3fc75e6514b..1394114782d2 100644 --- a/drivers/rpmsg/Kconfig +++ b/drivers/rpmsg/Kconfig @@ -71,5 +71,6 @@ config RPMSG_VIRTIO depends on HAS_DMA select RPMSG select VIRTIO + select RPMSG_NS endmenu diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index b2927661868c..f771fdae150e 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -48,7 +48,6 @@ * @endpoints_lock: lock of the endpoints set * @sendq: wait queue of sending contexts waiting for a tx buffers * @sleepers: number of senders that are waiting for a tx buffer - * @ns_ept: the bus's name service endpoint * * This structure stores the rpmsg state of a given virtio remote processor * device (there might be several virtio proc devices for each physical @@ -67,7 +66,6 @@ struct virtproc_info { struct mutex endpoints_lock; wait_queue_head_t sendq; atomic_t sleepers; - struct rpmsg_endpoint *ns_ept; }; /* The feature bitmap for virtio rpmsg */ @@ -841,68 +839,14 @@ static void rpmsg_xmit_done(struct virtqueue *svq) wake_up_interruptible(&vrp->sendq); } -/* invoked when a name service announcement arrives */ -static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len, - void *priv, u32 src) -{ - struct rpmsg_ns_msg *msg = data; - struct rpmsg_device *newch; - struct rpmsg_channel_info chinfo; - struct virtproc_info *vrp = priv; - struct device *dev = &vrp->vdev->dev; - int ret; - -#if defined(CONFIG_DYNAMIC_DEBUG) - dynamic_hex_dump("NS announcement: ", DUMP_PREFIX_NONE, 16, 1, - data, len, true); -#endif - - if (len != sizeof(*msg)) { - dev_err(dev, "malformed ns msg (%d)\n", len); - return -EINVAL; - } - - /* - * the name service ept does _not_ belong to a real rpmsg channel, - * and is handled by the rpmsg bus itself. - * for sanity reasons, make sure a valid rpdev has _not_ sneaked - * in somehow. - */ - if (rpdev) { - dev_err(dev, "anomaly: ns ept has an rpdev handle\n"); - return -EINVAL; - } - - /* don't trust the remote processor for null terminating the name */ - msg->name[RPMSG_NAME_SIZE - 1] = '\0'; - - strncpy(chinfo.name, msg->name, sizeof(chinfo.name)); - chinfo.src = RPMSG_ADDR_ANY; - chinfo.dst = virtio32_to_cpu(vrp->vdev, msg->addr); - - dev_info(dev, "%sing channel %s addr 0x%x\n", - virtio32_to_cpu(vrp->vdev, msg->flags) & RPMSG_NS_DESTROY ? - "destroy" : "creat", msg->name, chinfo.dst); - - if (virtio32_to_cpu(vrp->vdev, msg->flags) & RPMSG_NS_DESTROY) { - ret = rpmsg_unregister_device(&vrp->vdev->dev, &chinfo); - if (ret) - dev_err(dev, "rpmsg_destroy_channel failed: %d\n", ret); - } else { - newch = __rpmsg_create_channel(vrp, &chinfo); - if (!newch) - dev_err(dev, "rpmsg_create_channel failed\n"); - } - - return 0; -} - static int rpmsg_probe(struct virtio_device *vdev) { vq_callback_t *vq_cbs[] = { rpmsg_recv_done, rpmsg_xmit_done }; static const char * const names[] = { "input", "output" }; struct virtqueue *vqs[2]; struct virtproc_info *vrp; + struct virtio_rpmsg_channel *vch; + struct rpmsg_device *rpdev_ns; void *bufs_va; int err = 0, i; size_t total_buf_space; @@ -978,14 +922,27 @@ static int rpmsg_probe(struct virtio_device *vdev) /* if supported by the remote processor, enable the name service */ if (virtio_has_feature(vdev, VIRTIO_RPMSG_F_NS)) { - /* a dedicated endpoint handles the name service msgs */ - vrp->ns_ept = __rpmsg_create_ept(vrp, NULL, rpmsg_ns_cb, - vrp, RPMSG_NS_ADDR); - if (!vrp->ns_ept) { - dev_err(&vdev->dev, "failed to create the ns ept\n"); + vch = kzalloc(sizeof(*vch), GFP_KERNEL); + if (!vch) { err = -ENOMEM; goto free_coherent; } + + /* Link the channel to our vrp */ + vch->vrp = vrp; + + /* Assign public information to the rpmsg_device */ + rpdev_ns = &vch->rpdev; + rpdev_ns->ops = &virtio_rpmsg_ops; + + rpdev_ns->dev.parent = &vrp->vdev->dev; + rpdev_ns->dev.release = virtio_rpmsg_release_device; + + err = rpmsg_ns_register_device(rpdev_ns); + if (err) { + kfree(vch); + goto free_coherent; + } } /* @@ -1038,9 +995,6 @@ static void rpmsg_remove(struct virtio_device *vdev) if (ret) dev_warn(&vdev->dev, "can't remove rpmsg device: %d\n", ret); - if (vrp->ns_ept) - __rpmsg_destroy_ept(vrp, vrp->ns_ept); - idr_destroy(&vrp->endpoints); vdev->config->del_vqs(vrp->vdev); From patchwork Tue Aug 25 16:49:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 11735973 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 667B6722 for ; Tue, 25 Aug 2020 16:52:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A13E2075F for ; Tue, 25 Aug 2020 16:52:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=st.com header.i=@st.com header.b="aAfO25ZI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726551AbgHYQwa (ORCPT ); Tue, 25 Aug 2020 12:52:30 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:41072 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726471AbgHYQwZ (ORCPT ); Tue, 25 Aug 2020 12:52:25 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07PGkt5Q010046; Tue, 25 Aug 2020 18:52:21 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=qO78AbgiBHwh2Bo0X12NYYis5HJeGCLxxhU0UT9xviY=; b=aAfO25ZI4SAeBGoRwLnME9q5VhkRDqo7owLRBKYbYa3K7k5qhWoVp6CKzFYz4XjV4kMS 5AomSvchdshLSsN3pI/u32uudGtYr3n93vH72R7fOVJsKJmcmyRfKDVDYfYaK5IHyAjp RPrm/e4Yjh3e4XfqGdioSEtsVT7RFh7zLWZJKgWojevExStQRzsS2L7EAKJsNnw7KUYl mI3tZTDno9MEegvVuU1Ip8KsWZQMXPvRYajl9Oh2b1ktN8DfAPwnpXuEH1sDBXdwkxVV rACeHqTRnhidUSKwGZUATENrZ4mlBsZRDXFzJlansyGAFDUq11xd7rZsSHH4QiKwGQFp XA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 332t8fpmpd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2020 18:52:21 +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 E8B2610002A; Tue, 25 Aug 2020 18:52:20 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node1.st.com [10.75.127.7]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id DE55D2AE6AA; Tue, 25 Aug 2020 18:52:20 +0200 (CEST) Received: from localhost (10.75.127.46) by SFHDAG3NODE1.st.com (10.75.127.7) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 25 Aug 2020 18:52:20 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , Subject: [PATCH v2 7/8] rpmsg: ns: add name service announcement service Date: Tue, 25 Aug 2020 18:49:06 +0200 Message-ID: <20200825164907.3642-8-arnaud.pouliquen@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200825164907.3642-1-arnaud.pouliquen@st.com> References: <20200825164907.3642-1-arnaud.pouliquen@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG7NODE1.st.com (10.75.127.19) To SFHDAG3NODE1.st.com (10.75.127.7) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-25_06:2020-08-25,2020-08-25 signatures=0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org As the RPMsg driver is in charge of the name service announcement, create an API to send channel creation and destruction to the remote processor. Notice that the source address of the message sent is now RPMSG_NS_ADDR. Legacy implementation was to send the message with source address corresponding to the ept created. RPMSG_NS_ADDR as source address make sense as we want to send a message belonging to the NS announcement service and the created ept address is already in the message payload. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/rpmsg_internal.h | 3 +++ drivers/rpmsg/rpmsg_ns.c | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h index 641b48f6bf2a..d1549e5cb607 100644 --- a/drivers/rpmsg/rpmsg_internal.h +++ b/drivers/rpmsg/rpmsg_internal.h @@ -119,4 +119,7 @@ static inline int rpmsg_ns_register_device(struct rpmsg_device *rpdev) return rpmsg_register_device(rpdev); } +int rpmsg_ns_announce_create(struct rpmsg_device *rpdev); +int rpmsg_ns_announce_destroy(struct rpmsg_device *rpdev); + #endif diff --git a/drivers/rpmsg/rpmsg_ns.c b/drivers/rpmsg/rpmsg_ns.c index 3c929b6976a6..2a34e36a592d 100644 --- a/drivers/rpmsg/rpmsg_ns.c +++ b/drivers/rpmsg/rpmsg_ns.c @@ -37,6 +37,45 @@ struct rpmsg_ns_msg { __le32 flags; } __packed; +/** + * rpmsg_ns_announce_create() - announce to the remote processor + * the service creation or destruction + * @rpdev: the rpmsg channel + * @ns_flag: related to the @rpmsg_ns_flags enum + * + * This function can be called on a channel creation or destruction to inform + * the remote processor, using the reserved name service anouncement channel. + */ +static int rpmsg_ns_channel_announce(struct rpmsg_device *rpdev, int ns_flag) +{ + struct rpmsg_ns_msg nsm; + + if (!rpdev->announce || !rpdev->ept) + return 0; + + if (ns_flag != RPMSG_NS_CREATE && ns_flag != RPMSG_NS_DESTROY) + return -EINVAL; + + strncpy(nsm.name, rpdev->id.name, RPMSG_NAME_SIZE); + nsm.addr = cpu_to_le32(rpdev->ept->addr); + nsm.flags = cpu_to_le32(ns_flag); + + return rpmsg_send_offchannel(rpdev->ept, RPMSG_NS_ADDR, RPMSG_NS_ADDR, + &nsm, sizeof(nsm)); +} + +int rpmsg_ns_announce_create(struct rpmsg_device *rpdev) +{ + return rpmsg_ns_channel_announce(rpdev, RPMSG_NS_CREATE); +} +EXPORT_SYMBOL(rpmsg_ns_announce_create); + +int rpmsg_ns_announce_destroy(struct rpmsg_device *rpdev) +{ + return rpmsg_ns_channel_announce(rpdev, RPMSG_NS_DESTROY); +} +EXPORT_SYMBOL(rpmsg_ns_announce_destroy); + /* Invoked when a name service announcement arrives */ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len, void *priv, u32 src) From patchwork Tue Aug 25 16:49:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud POULIQUEN X-Patchwork-Id: 11735971 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 31CE0138A for ; Tue, 25 Aug 2020 16:52:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1581B2075F for ; Tue, 25 Aug 2020 16:52:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=st.com header.i=@st.com header.b="NowFBprX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726580AbgHYQwb (ORCPT ); Tue, 25 Aug 2020 12:52:31 -0400 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:38894 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726483AbgHYQw0 (ORCPT ); Tue, 25 Aug 2020 12:52:26 -0400 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07PGmZSc019634; Tue, 25 Aug 2020 18:52:22 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=u6EYUC0xcRE70s9suBWPO0FSC0+bERZDODPG0q9BHrI=; b=NowFBprX6iCB0n1vfOwFNf31Ug7be9tG+l5tyhKVx7FrYv0smpcSM3cFtcqFQCz57Bay 6Bmmd9RnfGEfewXwAcptIVYrliaVr20HHNuYB2tQxVasd4GxwuCUfMB973duOqzG3GpA voSbyt5so5Tg7qWKuKrysAf5KOj2IjrkrzGtze8RL2oKJ5hfCZpObYbBkviBOVGan6Ew VihCtMMh5JEG9ryGpXjthvd5OpbfwQms9oAJek5OkcRfRsg9NqM6idhvOBApcBxgQrXK W5N/LkK+qQBiAeSUoX2f+5thfH3Ep/1Xj/maTfhWMphWJ8NytY+baq/r7OGXd61emNFC OA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 333b6x4067-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Aug 2020 18:52:22 +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 5CF8310002A; Tue, 25 Aug 2020 18:52:22 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node1.st.com [10.75.127.7]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 50F9C2AE6AA; Tue, 25 Aug 2020 18:52:22 +0200 (CEST) Received: from localhost (10.75.127.45) by SFHDAG3NODE1.st.com (10.75.127.7) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 25 Aug 2020 18:52:21 +0200 From: Arnaud Pouliquen To: Bjorn Andersson , Ohad Ben-Cohen , Mathieu Poirier CC: , , , Subject: [PATCH v2 8/8] rpmsg: virtio: use rpmsg_ns driver to manage ns announcement Date: Tue, 25 Aug 2020 18:49:07 +0200 Message-ID: <20200825164907.3642-9-arnaud.pouliquen@st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200825164907.3642-1-arnaud.pouliquen@st.com> References: <20200825164907.3642-1-arnaud.pouliquen@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG3NODE3.st.com (10.75.127.9) To SFHDAG3NODE1.st.com (10.75.127.7) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-25_06:2020-08-25,2020-08-25 signatures=0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Use the new rpmsg_ns API to send the name service announcements if the VIRTIO_RPMSG_F_NS is set, else just not implement the ops. Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/virtio_rpmsg_bus.c | 94 +++++--------------------------- 1 file changed, 13 insertions(+), 81 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index f771fdae150e..3c771a6392be 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -91,35 +91,6 @@ struct rpmsg_hdr { u8 data[]; } __packed; -/** - * struct rpmsg_ns_msg - dynamic name service announcement message - * @name: name of remote service that is published - * @addr: address of remote service that is published - * @flags: indicates whether service is created or destroyed - * - * This message is sent across to publish a new service, or announce - * about its removal. When we receive these messages, an appropriate - * rpmsg channel (i.e device) is created/destroyed. In turn, the ->probe() - * or ->remove() handler of the appropriate rpmsg driver will be invoked - * (if/as-soon-as one is registered). - */ -struct rpmsg_ns_msg { - char name[RPMSG_NAME_SIZE]; - __virtio32 addr; - __virtio32 flags; -} __packed; - -/** - * enum rpmsg_ns_flags - dynamic name service announcement flags - * - * @RPMSG_NS_CREATE: a new remote service was just created - * @RPMSG_NS_DESTROY: a known remote service was just destroyed - */ -enum rpmsg_ns_flags { - RPMSG_NS_CREATE = 0, - RPMSG_NS_DESTROY = 1, -}; - /** * @vrp: the remote processor this channel belongs to */ @@ -324,60 +295,18 @@ static void virtio_rpmsg_destroy_ept(struct rpmsg_endpoint *ept) __rpmsg_destroy_ept(vch->vrp, ept); } -static int virtio_rpmsg_announce_create(struct rpmsg_device *rpdev) -{ - struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(rpdev); - struct virtproc_info *vrp = vch->vrp; - struct device *dev = &rpdev->dev; - int err = 0; - - /* need to tell remote processor's name service about this channel ? */ - if (rpdev->announce && rpdev->ept && - virtio_has_feature(vrp->vdev, VIRTIO_RPMSG_F_NS)) { - struct rpmsg_ns_msg nsm; - - strncpy(nsm.name, rpdev->id.name, RPMSG_NAME_SIZE); - nsm.addr = cpu_to_virtio32(vrp->vdev, rpdev->ept->addr); - nsm.flags = cpu_to_virtio32(vrp->vdev, RPMSG_NS_CREATE); - - err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR); - if (err) - dev_err(dev, "failed to announce service %d\n", err); - } - - return err; -} - -static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev) -{ - struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(rpdev); - struct virtproc_info *vrp = vch->vrp; - struct device *dev = &rpdev->dev; - int err = 0; - - /* tell remote processor's name service we're removing this channel */ - if (rpdev->announce && rpdev->ept && - virtio_has_feature(vrp->vdev, VIRTIO_RPMSG_F_NS)) { - struct rpmsg_ns_msg nsm; - - strncpy(nsm.name, rpdev->id.name, RPMSG_NAME_SIZE); - nsm.addr = cpu_to_virtio32(vrp->vdev, rpdev->ept->addr); - nsm.flags = cpu_to_virtio32(vrp->vdev, RPMSG_NS_DESTROY); - - err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR); - if (err) - dev_err(dev, "failed to announce service %d\n", err); - } - - return err; -} - static const struct rpmsg_device_ops virtio_rpmsg_ops = { .create_channel = virtio_rpmsg_create_channel, .release_channel = virtio_rpmsg_release_channel, .create_ept = virtio_rpmsg_create_ept, - .announce_create = virtio_rpmsg_announce_create, - .announce_destroy = virtio_rpmsg_announce_destroy, +}; + +static const struct rpmsg_device_ops virtio_rpmsg_w_nsa_ops = { + .create_channel = virtio_rpmsg_create_channel, + .release_channel = virtio_rpmsg_release_channel, + .create_ept = virtio_rpmsg_create_ept, + .announce_create = rpmsg_ns_announce_create, + .announce_destroy = rpmsg_ns_announce_destroy, }; static void virtio_rpmsg_release_device(struct device *dev) @@ -423,7 +352,10 @@ __rpmsg_create_channel(struct virtproc_info *vrp, rpdev = &vch->rpdev; rpdev->src = chinfo->src; rpdev->dst = chinfo->dst; - rpdev->ops = &virtio_rpmsg_ops; + if (virtio_has_feature(vrp->vdev, VIRTIO_RPMSG_F_NS)) + rpdev->ops = &virtio_rpmsg_w_nsa_ops; + else + rpdev->ops = &virtio_rpmsg_ops; /* * rpmsg server channels has predefined local address (for now), @@ -933,7 +865,7 @@ static int rpmsg_probe(struct virtio_device *vdev) /* Assign public information to the rpmsg_device */ rpdev_ns = &vch->rpdev; - rpdev_ns->ops = &virtio_rpmsg_ops; + rpdev_ns->ops = &virtio_rpmsg_w_nsa_ops; rpdev_ns->dev.parent = &vrp->vdev->dev; rpdev_ns->dev.release = virtio_rpmsg_release_device;