From patchwork Tue Oct 13 23:25:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11837249 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 C28F81130 for ; Wed, 14 Oct 2020 09:30:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9885B206DD for ; Wed, 14 Oct 2020 09:30:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="ebOpZ9Qp" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727743AbgJNJTh (ORCPT ); Wed, 14 Oct 2020 05:19:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727133AbgJNJTg (ORCPT ); Wed, 14 Oct 2020 05:19:36 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2A18C08EA70 for ; Tue, 13 Oct 2020 16:25:22 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id o9so743350plx.10 for ; Tue, 13 Oct 2020 16:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T5+qdsDTVcz4rRfOTbXtw6enq/qmYTbuHet8yphp+jA=; b=ebOpZ9QpXR2dftdCCIs74a47xR5rZSQ06O6dFlNcQEAIfeZpi1dAV2ByMOAfNtntVG hNMJJzRMwS+AVeeUcm15xkrb5qaC+tehTlB2A9+53Yj0sYaqIi393r/3H1dYPVyJrMWi q63Qz8SKpowMpVzVP2f7sjJTTTFeUZ1rrqddSWAMn4ZNHq6UrJU7Ik5hTTl20Nbwvwgn zTzvM+tRVE1LKSAlhcshxsdpcQoKyAnDkvLcHZLcEuLN+DHBqSgy+rXHoWFzvVwk2LTV L7ia3yKg2iNHy4I3H5JGdmD15NKhg1aqtSCh/Gu4r4FXNNRWSbcsb5Nwxddi5RD4xVAX k0bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T5+qdsDTVcz4rRfOTbXtw6enq/qmYTbuHet8yphp+jA=; b=NJNzctOry1KDflYNSKHrfyPzYGbuGNcGEkgmzwrx4uMyuOzthXckD7u01+I4gbjazD ABrgku0N1yclly23Ys3J1I5mvwc8VCPMDsj7UVVrxCquKJBszbVliBbvgLoeaxGdk/X0 PL3saiO/ABFxS0qiAGXzD7AY4WTvkfW/zPuRDasW5/2oSeGPAI+FjpH1bdG8YJp+/DGx A5SmH0E/hE5WBMqEUV7wnG8dM70Ekziu2Ja+RujhrXCyQpRKqMUgfjrfPbLsn5N6b7fu Wj5+5SysHAgvlDLRyeR4Y2dKOL3HVQb/hjxdjpOVFXBru/zMIRixlMAUDPc9irNshm8I tPqw== X-Gm-Message-State: AOAM533yzSKMim/c8hx5Zee07T7fMwKDmM4dx21lEUVIuwqunyebHmW2 W9VkgaAxUENcaZK7jU+/nUjnTw== X-Google-Smtp-Source: ABdhPJy1z0AeoVRv+mwnHZD4UbkBuWxHZWZnL+iRxNZht514ZKhwBML20m9YulGZdDvy/KyyR4sSLg== X-Received: by 2002:a17:90b:383:: with SMTP id ga3mr735456pjb.2.1602631522496; Tue, 13 Oct 2020 16:25:22 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id b8sm791871pfr.159.2020.10.13.16.25.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Oct 2020 16:25:21 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: guennadi.liakhovetski@linux.intel.com, arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/9] rpmsg: Move rpmsg_endpoint_ops to rpmsg.h Date: Tue, 13 Oct 2020 17:25:11 -0600 Message-Id: <20201013232519.1367542-2-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201013232519.1367542-1-mathieu.poirier@linaro.org> References: <20201013232519.1367542-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Move structure rpmsg_endpoint_ops to header rpmsg.h so that it can be used by other entities. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/rpmsg/rpmsg_internal.h | 19 ------------------- include/linux/rpmsg.h | 24 +++++++++++++++++++++--- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h index 3fc83cd50e98..094cf968d2d3 100644 --- a/drivers/rpmsg/rpmsg_internal.h +++ b/drivers/rpmsg/rpmsg_internal.h @@ -18,25 +18,6 @@ #define to_rpmsg_device(d) container_of(d, struct rpmsg_device, dev) #define to_rpmsg_driver(d) container_of(d, struct rpmsg_driver, drv) -/** - * struct rpmsg_device_ops - indirection table for the rpmsg_device operations - * @create_ept: create backend-specific endpoint, required - * @announce_create: announce presence of new channel, optional - * @announce_destroy: announce destruction of channel, optional - * - * Indirection table for the operations that a rpmsg backend should implement. - * @announce_create and @announce_destroy are optional as the backend might - * advertise new channels implicitly by creating the endpoints. - */ -struct rpmsg_device_ops { - struct rpmsg_endpoint *(*create_ept)(struct rpmsg_device *rpdev, - rpmsg_rx_cb_t cb, void *priv, - struct rpmsg_channel_info chinfo); - - int (*announce_create)(struct rpmsg_device *ept); - int (*announce_destroy)(struct rpmsg_device *ept); -}; - /** * struct rpmsg_endpoint_ops - indirection table for rpmsg_endpoint operations * @destroy_ept: see @rpmsg_destroy_ept(), required diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index 9fe156d1c018..9fe1c54ae995 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -22,7 +22,6 @@ struct rpmsg_device; struct rpmsg_endpoint; -struct rpmsg_device_ops; struct rpmsg_endpoint_ops; /** @@ -37,6 +36,27 @@ struct rpmsg_channel_info { u32 dst; }; +typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32); + +/** + * struct rpmsg_device_ops - indirection table for the rpmsg_device operations + * @create_ept: create backend-specific endpoint, required + * @announce_create: announce presence of new channel, optional + * @announce_destroy: announce destruction of channel, optional + * + * Indirection table for the operations that a rpmsg backend should implement. + * @announce_create and @announce_destroy are optional as the backend might + * advertise new channels implicitly by creating the endpoints. + */ +struct rpmsg_device_ops { + struct rpmsg_endpoint *(*create_ept)(struct rpmsg_device *rpdev, + rpmsg_rx_cb_t cb, void *priv, + struct rpmsg_channel_info chinfo); + + int (*announce_create)(struct rpmsg_device *ept); + int (*announce_destroy)(struct rpmsg_device *ept); +}; + /** * rpmsg_device - device that belong to the rpmsg bus * @dev: the device struct @@ -59,8 +79,6 @@ struct rpmsg_device { const struct rpmsg_device_ops *ops; }; -typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32); - /** * struct rpmsg_endpoint - binds a local rpmsg address to its user * @rpdev: rpmsg channel device From patchwork Tue Oct 13 23:25:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11837131 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 9488515E6 for ; Wed, 14 Oct 2020 09:21:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6FD6120B1F for ; Wed, 14 Oct 2020 09:21:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="s3Zbw4lZ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730329AbgJNJVa (ORCPT ); Wed, 14 Oct 2020 05:21:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726318AbgJNJUl (ORCPT ); Wed, 14 Oct 2020 05:20:41 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45BF9C08EA72 for ; Tue, 13 Oct 2020 16:25:24 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id r10so716236pgb.10 for ; Tue, 13 Oct 2020 16:25:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JUQisvWm2gU+/6MOWBR2T8jHRg+cmB77+IKGZfHHqU0=; b=s3Zbw4lZ2wsutwyMbIPt9fSHI9a/5wHo7mOEipA/XYPVXiGhUXzIa+M79NOYJmWf0V mHMVDI/TM2BMgKAFXpBPdliiBpiPMVBdteO2cNsCwR143FpH8d+NZ05PTMq3gsUTYg6f /MRFj/6RnMJY+37mg95bQuMHHOxvDW2DE7NgtsjdMk//VXPhq3rsQxKzJ6O28ttwog0E Nh6j5knK5pc1TfCslUcPp5QtIWcQpDMSzFSCmVNQnKKh/nlUD+d8kNR+kRFwMUpufs9B 5xYuxM7WuhVYVKdZ1NFtEU1yLHB0I6n+T00oDja51MD0TNqMBTlHl54d4JWpNhzi5Sz0 nr2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JUQisvWm2gU+/6MOWBR2T8jHRg+cmB77+IKGZfHHqU0=; b=KNKS7FlRBvoEs0J+6f/kCjNV/njPzl7MepEuO3RdEUypE0ESPYVK3CJdj5ApQ50eWQ MMBFl3AkBM614GwTH/Y+/8JV5ZOP+UYjhs2DtZ2v02PgV88fDLvmte+PBDZOgLGrwK4u +PT/S5u8wauhMpbqmXtP5ivloreoy5zR9FdWzu7BhvfxceGsb0lhjHwDJTsBmWlCNC74 NXpS8Di17ZczBAbKMg4LtqP/+eqYaHAvP+FbkLaDT4pJBkKEc/4SaQ4LTtdLluZmZvOG 7HWs34D1OZBsoNFsCYokDKn1G3RBN5veh+daAhnXIDZ+UgtDtKg/258GEosoIA6rIv1U Hf9A== X-Gm-Message-State: AOAM533LFTmKpukDQqMkwX6z4lgas1cgoHEAivZRdqc34o4G/FVNjYRM kN0HhvtoxIX9jThtNSTpUE0PCA+y504/Zg== X-Google-Smtp-Source: ABdhPJzEUkRL+/OR6T2cdnYnpp5nW4YuazwK3S9P2CfIFcJVnpNbw88PfYzdHF1ZXB2/Czh5QLl46Q== X-Received: by 2002:a63:4f45:: with SMTP id p5mr1468752pgl.341.1602631523631; Tue, 13 Oct 2020 16:25:23 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id b8sm791871pfr.159.2020.10.13.16.25.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Oct 2020 16:25:23 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: guennadi.liakhovetski@linux.intel.com, arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/9] rpmsg: Introduce __rpmsg{16|32|64} types Date: Tue, 13 Oct 2020 17:25:12 -0600 Message-Id: <20201013232519.1367542-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201013232519.1367542-1-mathieu.poirier@linaro.org> References: <20201013232519.1367542-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Introduce __rpmsg{16|32|64} types along with byte order conversion functions based on an rpmsg_device operation as a foundation to make RPMSG modular and transport agnostic. Suggested-by: Guennadi Liakhovetski Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- include/linux/rpmsg.h | 51 ++++++++++++++++++++++++ include/linux/rpmsg_byteorder.h | 67 ++++++++++++++++++++++++++++++++ include/uapi/linux/rpmsg_types.h | 11 ++++++ 3 files changed, 129 insertions(+) create mode 100644 include/linux/rpmsg_byteorder.h create mode 100644 include/uapi/linux/rpmsg_types.h diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index 9fe1c54ae995..165e4c6d4cd3 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -17,6 +17,7 @@ #include #include #include +#include #define RPMSG_ADDR_ANY 0xFFFFFFFF @@ -40,6 +41,7 @@ typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32); /** * struct rpmsg_device_ops - indirection table for the rpmsg_device operations + * @is_little_endian: returns true if using little endian byte ordering * @create_ept: create backend-specific endpoint, required * @announce_create: announce presence of new channel, optional * @announce_destroy: announce destruction of channel, optional @@ -49,6 +51,7 @@ typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32); * advertise new channels implicitly by creating the endpoints. */ struct rpmsg_device_ops { + bool (*is_little_endian)(struct rpmsg_device *rpdev); struct rpmsg_endpoint *(*create_ept)(struct rpmsg_device *rpdev, rpmsg_rx_cb_t cb, void *priv, struct rpmsg_channel_info chinfo); @@ -129,6 +132,54 @@ struct rpmsg_driver { int (*callback)(struct rpmsg_device *, void *, int, void *, u32); }; +static inline u16 rpmsg16_to_cpu(struct rpmsg_device *rpdev, __rpmsg16 val) +{ + if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) + return __rpmsg16_to_cpu(rpmsg_is_little_endian(), val); + else + return __rpmsg16_to_cpu(rpdev->ops->is_little_endian(rpdev), val); +} + +static inline __rpmsg16 cpu_to_rpmsg16(struct rpmsg_device *rpdev, u16 val) +{ + if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) + return __cpu_to_rpmsg16(rpmsg_is_little_endian(), val); + else + return __cpu_to_rpmsg16(rpdev->ops->is_little_endian(rpdev), val); +} + +static inline u32 rpmsg32_to_cpu(struct rpmsg_device *rpdev, __rpmsg32 val) +{ + if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) + return __rpmsg32_to_cpu(rpmsg_is_little_endian(), val); + else + return __rpmsg32_to_cpu(rpdev->ops->is_little_endian(rpdev), val); +} + +static inline __rpmsg32 cpu_to_rpmsg32(struct rpmsg_device *rpdev, u32 val) +{ + if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) + return __cpu_to_rpmsg32(rpmsg_is_little_endian(), val); + else + return __cpu_to_rpmsg32(rpdev->ops->is_little_endian(rpdev), val); +} + +static inline u64 rpmsg64_to_cpu(struct rpmsg_device *rpdev, __rpmsg64 val) +{ + if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) + return __rpmsg64_to_cpu(rpmsg_is_little_endian(), val); + else + return __rpmsg64_to_cpu(rpdev->ops->is_little_endian(rpdev), val); +} + +static inline __rpmsg64 cpu_to_rpmsg64(struct rpmsg_device *rpdev, u64 val) +{ + if (!rpdev || !rpdev->ops || !rpdev->ops->is_little_endian) + return __cpu_to_rpmsg64(rpmsg_is_little_endian(), val); + else + return __cpu_to_rpmsg64(rpdev->ops->is_little_endian(rpdev), val); +} + #if IS_ENABLED(CONFIG_RPMSG) int register_rpmsg_device(struct rpmsg_device *dev); diff --git a/include/linux/rpmsg_byteorder.h b/include/linux/rpmsg_byteorder.h new file mode 100644 index 000000000000..c0f565dbad6d --- /dev/null +++ b/include/linux/rpmsg_byteorder.h @@ -0,0 +1,67 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Follows implementation found in linux/virtio_byteorder.h + */ +#ifndef _LINUX_RPMSG_BYTEORDER_H +#define _LINUX_RPMSG_BYTEORDER_H +#include +#include + +static inline bool rpmsg_is_little_endian(void) +{ +#ifdef __LITTLE_ENDIAN + return true; +#else + return false; +#endif +} + +static inline u16 __rpmsg16_to_cpu(bool little_endian, __rpmsg16 val) +{ + if (little_endian) + return le16_to_cpu((__force __le16)val); + else + return be16_to_cpu((__force __be16)val); +} + +static inline __rpmsg16 __cpu_to_rpmsg16(bool little_endian, u16 val) +{ + if (little_endian) + return (__force __rpmsg16)cpu_to_le16(val); + else + return (__force __rpmsg16)cpu_to_be16(val); +} + +static inline u32 __rpmsg32_to_cpu(bool little_endian, __rpmsg32 val) +{ + if (little_endian) + return le32_to_cpu((__force __le32)val); + else + return be32_to_cpu((__force __be32)val); +} + +static inline __rpmsg32 __cpu_to_rpmsg32(bool little_endian, u32 val) +{ + if (little_endian) + return (__force __rpmsg32)cpu_to_le32(val); + else + return (__force __rpmsg32)cpu_to_be32(val); +} + +static inline u64 __rpmsg64_to_cpu(bool little_endian, __rpmsg64 val) +{ + if (little_endian) + return le64_to_cpu((__force __le64)val); + else + return be64_to_cpu((__force __be64)val); +} + +static inline __rpmsg64 __cpu_to_rpmsg64(bool little_endian, u64 val) +{ + if (little_endian) + return (__force __rpmsg64)cpu_to_le64(val); + else + return (__force __rpmsg64)cpu_to_be64(val); +} + +#endif /* _LINUX_RPMSG_BYTEORDER_H */ diff --git a/include/uapi/linux/rpmsg_types.h b/include/uapi/linux/rpmsg_types.h new file mode 100644 index 000000000000..36e3b9404391 --- /dev/null +++ b/include/uapi/linux/rpmsg_types.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _UAPI_LINUX_RPMSG_TYPES_H +#define _UAPI_LINUX_RPMSG_TYPES_H + +#include + +typedef __u16 __bitwise __rpmsg16; +typedef __u32 __bitwise __rpmsg32; +typedef __u64 __bitwise __rpmsg64; + +#endif /* _UAPI_LINUX_RPMSG_TYPES_H */ From patchwork Tue Oct 13 23:25:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11837143 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 A35481130 for ; Wed, 14 Oct 2020 09:22:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6FB3022246 for ; Wed, 14 Oct 2020 09:22:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Zco7rub1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729848AbgJNJWF (ORCPT ); Wed, 14 Oct 2020 05:22:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731154AbgJNJVz (ORCPT ); Wed, 14 Oct 2020 05:21:55 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A061C08EA73 for ; Tue, 13 Oct 2020 16:25:25 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id a17so384126pju.1 for ; Tue, 13 Oct 2020 16:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Mv3AqdsXk34lvmbhy/w0WOQHCbmdUZwNkrverLNgIFw=; b=Zco7rub1ajhWwIuTzU92newmNnhdcRQwLGiO3egVls7ADGGbiLB8aRe1YYPOkE4MOu aGD8YT2Im7caamhK5tuGKBDteHoKIqjjIA65DlCkdMbzWb+JSrdVq2gqSVHx5h5sWOUc WjorI4vfZJiO1RT6sLLFtHDehcgRjscE6tu8x6fOJfJ2PVRJ9FCajkFAsmKVjMhn/l+n 4tjWpiScDZg+Y3g2kmWGjV590ong2Xo9JlgtpiIY7Oo6GZyj6aAHGtjLIz4iOINifHEK DP+rZAVfo0K0Niy9iiPmf3tOpu3wMw65tnparL1ASzfIqTnLi5U5NzPDFPs6OrDWf2Xi ypsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Mv3AqdsXk34lvmbhy/w0WOQHCbmdUZwNkrverLNgIFw=; b=trKC2hLBulmBQx92B1B1hwj6T5ZU5/y+O+9MX6+1uQ4dMQsJAgTcLg0ElAYw+fTGdP MaUL+7VABBySEVq7xyyLja6LzZ1qmn6CZZNP/wG/JYK1gcikhPfOR5Wr8xXog4gR6rPs NpkcQeT3IUESOB4+lPOo5jv/w1GQNAyWdf8v/P2F9lz/sZWs8UWMPuhvG+hFVH5nWmhV 3t7wVgz3mlIWH3sjQGkp4sVHM3NXtHgfBXhY+j2g+tadQ0YRZdoTMSEdKLzePrAKjiMQ zcC8Y2SFuAeHwf8c2Ebo/1dov8011jTnfj4PQ3TenDXpTj74acSnMuROxvz87IyxxJcM 2R2g== X-Gm-Message-State: AOAM530hh0ok7Bsl+9sLejti6Vt+PbyRp9yJmFIyI+vhfmxPrRAoefP3 3rRx4c1tVwBcCX821Bhx7nrzhw== X-Google-Smtp-Source: ABdhPJw+B7rpK0zF59iaO8J06TxDvR0JX3X0xAJvFHnUqEVUmmrpzBLTNI56qFphMS6gOGryzUTs0w== X-Received: by 2002:a17:902:b286:b029:d3:f6b1:3261 with SMTP id u6-20020a170902b286b02900d3f6b13261mr1656376plr.61.1602631524999; Tue, 13 Oct 2020 16:25:24 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id b8sm791871pfr.159.2020.10.13.16.25.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Oct 2020 16:25:24 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: guennadi.liakhovetski@linux.intel.com, arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/9] rpmsg: virtio: Move from virtio to rpmsg byte conversion Date: Tue, 13 Oct 2020 17:25:13 -0600 Message-Id: <20201013232519.1367542-4-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201013232519.1367542-1-mathieu.poirier@linaro.org> References: <20201013232519.1367542-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Use rpmsg byte conversion functions in order for the RPMSG headers and generic functions to be used by external entities. Signed-off-by: Mathieu Poirier --- drivers/rpmsg/virtio_rpmsg_bus.c | 60 +++++++++++++++++++------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 9006fc7f73d0..793fe924671f 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -19,11 +19,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -85,11 +85,11 @@ struct virtproc_info { * Every message sent(/received) on the rpmsg bus begins with this header. */ struct rpmsg_hdr { - __virtio32 src; - __virtio32 dst; - __virtio32 reserved; - __virtio16 len; - __virtio16 flags; + __rpmsg32 src; + __rpmsg32 dst; + __rpmsg32 reserved; + __rpmsg16 len; + __rpmsg16 flags; u8 data[]; } __packed; @@ -107,8 +107,8 @@ struct rpmsg_hdr { */ struct rpmsg_ns_msg { char name[RPMSG_NAME_SIZE]; - __virtio32 addr; - __virtio32 flags; + __rpmsg32 addr; + __rpmsg32 flags; } __packed; /** @@ -280,6 +280,14 @@ static struct rpmsg_endpoint *__rpmsg_create_ept(struct virtproc_info *vrp, return NULL; } +static bool virtio_rpmsg_is_little_endian(struct rpmsg_device *rpdev) +{ + struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(rpdev); + struct virtproc_info *vrp = vch->vrp; + + return virtio_is_little_endian(vrp->vdev); +} + static struct rpmsg_endpoint *virtio_rpmsg_create_ept(struct rpmsg_device *rpdev, rpmsg_rx_cb_t cb, void *priv, @@ -336,8 +344,8 @@ static int virtio_rpmsg_announce_create(struct rpmsg_device *rpdev) 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); + nsm.addr = cpu_to_rpmsg32(rpdev, rpdev->ept->addr); + nsm.flags = cpu_to_rpmsg32(rpdev, RPMSG_NS_CREATE); err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR); if (err) @@ -360,8 +368,8 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev) 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); + nsm.addr = cpu_to_rpmsg32(rpdev, rpdev->ept->addr); + nsm.flags = cpu_to_rpmsg32(rpdev, RPMSG_NS_DESTROY); err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR); if (err) @@ -372,6 +380,7 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev) } static const struct rpmsg_device_ops virtio_rpmsg_ops = { + .is_little_endian = virtio_rpmsg_is_little_endian, .create_ept = virtio_rpmsg_create_ept, .announce_create = virtio_rpmsg_announce_create, .announce_destroy = virtio_rpmsg_announce_destroy, @@ -613,10 +622,10 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev, } } - msg->len = cpu_to_virtio16(vrp->vdev, len); + msg->len = cpu_to_rpmsg16(rpdev, len); msg->flags = 0; - msg->src = cpu_to_virtio32(vrp->vdev, src); - msg->dst = cpu_to_virtio32(vrp->vdev, dst); + msg->src = cpu_to_rpmsg32(rpdev, src); + msg->dst = cpu_to_rpmsg32(rpdev, dst); msg->reserved = 0; memcpy(msg->data, data, len); @@ -705,14 +714,15 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, { struct rpmsg_endpoint *ept; struct scatterlist sg; - unsigned int msg_len = virtio16_to_cpu(vrp->vdev, msg->len); + bool little_endian = rpmsg_is_little_endian(); + unsigned int msg_len = __rpmsg16_to_cpu(little_endian, msg->len); int err; dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n", - virtio32_to_cpu(vrp->vdev, msg->src), - virtio32_to_cpu(vrp->vdev, msg->dst), msg_len, - virtio16_to_cpu(vrp->vdev, msg->flags), - virtio32_to_cpu(vrp->vdev, msg->reserved)); + __rpmsg32_to_cpu(little_endian, msg->src), + __rpmsg32_to_cpu(little_endian, msg->dst), msg_len, + __rpmsg16_to_cpu(little_endian, msg->flags), + __rpmsg32_to_cpu(little_endian, msg->reserved)); #if defined(CONFIG_DYNAMIC_DEBUG) dynamic_hex_dump("rpmsg_virtio RX: ", DUMP_PREFIX_NONE, 16, 1, msg, sizeof(*msg) + msg_len, true); @@ -731,7 +741,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, /* use the dst addr to fetch the callback of the appropriate user */ mutex_lock(&vrp->endpoints_lock); - ept = idr_find(&vrp->endpoints, virtio32_to_cpu(vrp->vdev, msg->dst)); + ept = idr_find(&vrp->endpoints, __rpmsg32_to_cpu(little_endian, msg->dst)); /* let's make sure no one deallocates ept while we use it */ if (ept) @@ -745,7 +755,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, if (ept->cb) ept->cb(ept->rpdev, msg->data, msg_len, ept->priv, - virtio32_to_cpu(vrp->vdev, msg->src)); + __rpmsg32_to_cpu(little_endian, msg->src)); mutex_unlock(&ept->cb_lock); @@ -853,13 +863,13 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len, strncpy(chinfo.name, msg->name, sizeof(chinfo.name)); chinfo.src = RPMSG_ADDR_ANY; - chinfo.dst = virtio32_to_cpu(vrp->vdev, msg->addr); + chinfo.dst = rpmsg32_to_cpu(rpdev, msg->addr); dev_info(dev, "%sing channel %s addr 0x%x\n", - virtio32_to_cpu(vrp->vdev, msg->flags) & RPMSG_NS_DESTROY ? + rpmsg32_to_cpu(rpdev, msg->flags) & RPMSG_NS_DESTROY ? "destroy" : "creat", msg->name, chinfo.dst); - if (virtio32_to_cpu(vrp->vdev, msg->flags) & RPMSG_NS_DESTROY) { + if (rpmsg32_to_cpu(rpdev, 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); From patchwork Tue Oct 13 23:25:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11837193 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 0D5551130 for ; Wed, 14 Oct 2020 09:23:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD54E206F4 for ; Wed, 14 Oct 2020 09:23:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="IeACXLI7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728418AbgJNJWu (ORCPT ); Wed, 14 Oct 2020 05:22:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731186AbgJNJV4 (ORCPT ); Wed, 14 Oct 2020 05:21:56 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A94D2C08EA75 for ; Tue, 13 Oct 2020 16:25:26 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id hk7so427514pjb.2 for ; Tue, 13 Oct 2020 16:25:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8/cb+6ARRrtk4RL3ZhsFEbwLitpFe1pF2QiRThqv3kw=; b=IeACXLI7uhaPptvACX6Id5vnuh+CAEhdvMt7+P7W9TjeZ5kX0Gi8GoTZSrhGou7nYC duZz0tWcEtKSw9psophtkb4V5wjSUd1452vMLio+QHf69EkNCkLC2ch/7Yr6NmHV58TY k7kWdKR06T6MdT9MfH70Ces9UTvCAhcAMGTAXyZxxiCwCjTsogN8OjVKblXGTUpVWbe1 OWoFu1TP71fgWXqtZvPjkAsBoHarIApwCoXSAT/2u+earSUenYfVdUVwqWRU2wujDjkN qlwQwdQfRV1HLa0uMe21rbg8F9urJuyN2S9lz4Md/Lb8E7ReyxS7nSFAI1Vv6sdeKYah 8/HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8/cb+6ARRrtk4RL3ZhsFEbwLitpFe1pF2QiRThqv3kw=; b=KMQZZhR4CDW61rD095CLnjgC96B8pT6Cvfbv5av7h9PILwcttmInOGaTxMJjQSva4F x8nJu0q8zEs/aMt5xKyl46FS3yoLMEjgyEVGP5joG8I+o8zV1l4PCCsgpAXmI+F5NzCQ dYRZ8eoIv7LpW0Kyl6jjGw7FchlrTm06lWfAoI1ksJF8n5UMbONIWYWLnynrRM4gmhlX REulDo+gRy67sQz76xKkWcReZRtgPCLt+hVZQhfhr587ixS2djDQFcoSrie19Ugls7gu rt28cfldyfou6qeYN4cSPn56N+n8uvV3iLm96Pv0hNyEKBogQT8bsQ3QT/sRYs5+nhUD 2aqg== X-Gm-Message-State: AOAM53378MOD9uLfdUoPnGmtYyHhVIznhnUpdrul3AGkpPhafVIscU/F TG8YizI+pvnzbqTXC3P+Kr7YKg== X-Google-Smtp-Source: ABdhPJzUZHoghshywR4fF8EKNfrFQxzUrmpWMLPgQe2yx0Tk6APXYTrNDrjPGa+YFroovWl/cumjzQ== X-Received: by 2002:a17:90a:c285:: with SMTP id f5mr700469pjt.87.1602631526242; Tue, 13 Oct 2020 16:25:26 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id b8sm791871pfr.159.2020.10.13.16.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Oct 2020 16:25:25 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: guennadi.liakhovetski@linux.intel.com, arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/9] rpmsg: Move rpmsg_hr and rpmsg_ns_msg to header file Date: Tue, 13 Oct 2020 17:25:14 -0600 Message-Id: <20201013232519.1367542-5-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201013232519.1367542-1-mathieu.poirier@linaro.org> References: <20201013232519.1367542-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Move structures rpmsg_hdr and rpmsg_ns_msg to their own header file so that they can be used by other entities. Signed-off-by: Mathieu Poirier --- drivers/rpmsg/virtio_rpmsg_bus.c | 58 ++---------------------------- include/linux/rpmsg_ns.h | 62 ++++++++++++++++++++++++++++++++ include/uapi/linux/rpmsg.h | 3 ++ 3 files changed, 67 insertions(+), 56 deletions(-) create mode 100644 include/linux/rpmsg_ns.h diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 793fe924671f..85f2acc4ed9f 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include @@ -27,6 +27,7 @@ #include #include #include +#include #include "rpmsg_internal.h" @@ -70,58 +71,6 @@ struct virtproc_info { struct rpmsg_endpoint *ns_ept; }; -/* The feature bitmap for virtio rpmsg */ -#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */ - -/** - * struct rpmsg_hdr - common header for all rpmsg messages - * @src: source address - * @dst: destination address - * @reserved: reserved for future use - * @len: length of payload (in bytes) - * @flags: message flags - * @data: @len bytes of message payload data - * - * Every message sent(/received) on the rpmsg bus begins with this header. - */ -struct rpmsg_hdr { - __rpmsg32 src; - __rpmsg32 dst; - __rpmsg32 reserved; - __rpmsg16 len; - __rpmsg16 flags; - 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]; - __rpmsg32 addr; - __rpmsg32 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 */ @@ -162,9 +111,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_ns.h b/include/linux/rpmsg_ns.h new file mode 100644 index 000000000000..3d836b8580b2 --- /dev/null +++ b/include/linux/rpmsg_ns.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_RPMSG_NS_H +#define _LINUX_RPMSG_NS_H + +#include +#include +#include + +/** + * struct rpmsg_hdr - common header for all rpmsg messages + * @src: source address + * @dst: destination address + * @reserved: reserved for future use + * @len: length of payload (in bytes) + * @flags: message flags + * @data: @len bytes of message payload data + * + * Every message sent(/received) on the rpmsg bus begins with this header. + */ +struct rpmsg_hdr { + __rpmsg32 src; + __rpmsg32 dst; + __rpmsg32 reserved; + __rpmsg16 len; + __rpmsg16 flags; + 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]; + __rpmsg32 addr; + __rpmsg32 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, +}; + +/* Address 53 is reserved for advertising remote services */ +#define RPMSG_NS_ADDR (53) + +#endif diff --git a/include/uapi/linux/rpmsg.h b/include/uapi/linux/rpmsg.h index e14c6dab4223..d669c04ef289 100644 --- a/include/uapi/linux/rpmsg.h +++ b/include/uapi/linux/rpmsg.h @@ -24,4 +24,7 @@ struct rpmsg_endpoint_info { #define RPMSG_CREATE_EPT_IOCTL _IOW(0xb5, 0x1, struct rpmsg_endpoint_info) #define RPMSG_DESTROY_EPT_IOCTL _IO(0xb5, 0x2) +/* The feature bitmap for virtio rpmsg */ +#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */ + #endif From patchwork Tue Oct 13 23:25:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11837215 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 702D81130 for ; Wed, 14 Oct 2020 09:24:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 46142206DD for ; Wed, 14 Oct 2020 09:24:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="YmFrCopN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730786AbgJNJYr (ORCPT ); Wed, 14 Oct 2020 05:24:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730527AbgJNJUC (ORCPT ); Wed, 14 Oct 2020 05:20:02 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0632EC08EA77 for ; Tue, 13 Oct 2020 16:25:28 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id y14so787335pfp.13 for ; Tue, 13 Oct 2020 16:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+GahyWSypfEwT9uS6WgR1EVJilbD+R1xTvJBHKJc9XE=; b=YmFrCopNTlwMHpVSctRlADa9tTikF+I4k4nziJkD70kXhUO2rF9SnWUSAHL3ISxxEJ lTxNT3R2wJTHIEE+FbSySVzOZ3vZ54EZ3ZhESZJRLE7oV6hu17dxsME511DvpMU9cQZo uQxCdx9kGw08cM/qDH56ktGjgW+oIus5lkKg0OUl4dlWUowl3pkXhAdKPG3kBG0OBshv IbZcB8xIbc//enos5xYaiTizQnJwAZ1eU62lVwqcLxYcm4t9Hub/FkHPqpKPb2IVjElq yuAiFY6YjkHN7gC/JgMBsnSb9CT3hfV5nkoLFphaAv1Osa8CpkTs3y5sIhDf6qTPWVTK 2Vyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+GahyWSypfEwT9uS6WgR1EVJilbD+R1xTvJBHKJc9XE=; b=G0aLV1C2UuIPqJs/XMcN//fyFdYPPlAoqwU/3X/aFI1GrQ/9YCDRCHUCdRwVaZLVLO IiPLfGZMcBaouiT6+aASw9fc4q7Ilz9n4DhmeUXdCiKoARKhJHRk7uIvqW7n0YGXL/L4 NFL5yfqOVyVlosCQQYUfBQzyjPGdDE0yGGPUigeimYyAR6FFUIgmbexRsY+2WIuh/kr5 /7zQi47gXgo9dmoa42z27350DelQQIH762g1Mh34qjpoIlAxb/iTC02Ufz1LVUkMN7vG oXsl3gCNwBgUCCdZN4Oz11k29QWfhR1fRmnuhEeWO4Ns6eCgrJX4wgOsO5fGFLbBlLBk GwcA== X-Gm-Message-State: AOAM531+gyUDFmgN67d3v2N8xc/OivxsuK1yC/bwZ4NzUGQwSZOBbFdm pl5pNUa9pFz7n8qkgXOQ4lXlXw== X-Google-Smtp-Source: ABdhPJwUUJW2kk45QEin98GKD9aqoUdihex32D7rFCGWnmD3eKWuZH6rT1vSebcSHBqVGXxaNYjuzw== X-Received: by 2002:a63:f744:: with SMTP id f4mr1554710pgk.34.1602631527580; Tue, 13 Oct 2020 16:25:27 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id b8sm791871pfr.159.2020.10.13.16.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Oct 2020 16:25:26 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: guennadi.liakhovetski@linux.intel.com, arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 5/9] rpmsg: virtio: Rename rpmsg_create_channel Date: Tue, 13 Oct 2020 17:25:15 -0600 Message-Id: <20201013232519.1367542-6-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201013232519.1367542-1-mathieu.poirier@linaro.org> References: <20201013232519.1367542-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org From: Arnaud Pouliquen Rename the internal function as it is internal, and as the name will be used in rpmsg_core. Signed-off-by: Arnaud Pouliquen Signed-off-by: Mathieu Poirier --- drivers/rpmsg/virtio_rpmsg_bus.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 85f2acc4ed9f..fca982b61c3b 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -345,8 +345,8 @@ 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; @@ -820,7 +820,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 Oct 13 23:25:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11837099 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 A40671130 for ; Wed, 14 Oct 2020 09:20:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7F3D320B1F for ; Wed, 14 Oct 2020 09:20:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="HVXiZAFV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730634AbgJNJUD (ORCPT ); Wed, 14 Oct 2020 05:20:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730362AbgJNJUB (ORCPT ); Wed, 14 Oct 2020 05:20:01 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EDD7C08EA7A for ; Tue, 13 Oct 2020 16:25:29 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id n9so720165pgf.9 for ; Tue, 13 Oct 2020 16:25:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8tfc/u3ngEc2adMkpXKOCwsLWllqbd3pOy732+G3iRI=; b=HVXiZAFVOrExa9CAZlR5lqXmXH32M58FgQ6yC9YjSndiHdQlPJOluTRq/whQ3c2e0U 78WK+rX3UxbIqDWJ0yj9cGgTDJY7fbIFmn6EyJqQFoeJw6DJnGpD0H+d9u1Pkspc1p5e 6cQPuqUcmFlTDtoGbGeCNK9QIWxNJwpgSqGeCAJNja/SzK2zw1YkIlSbSJlwXiOcRZxL 3I81GvyY6um130OnMKmIEafCi8WF0IpE7AjVm87bbG4DAAnvgaDq1fycixsI1a983OkA yb/YykcYA9P6EpJVHk/g4OxLHskH7rI0twN8zkJsa8uKnW9FAsCb2nGagzCG4uBOSKhd YPpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8tfc/u3ngEc2adMkpXKOCwsLWllqbd3pOy732+G3iRI=; b=Cr6FWmzPRv+2DRVUwC390pi/s9pr6eVngudoQ9U5GD8PT3JGXm1Rgm2HjAdBPN2LPG Ob1oMUli7rT0zxKrLmugkbwasJVQVFDVtjH1slCBxrOzV/9FIkCyRCI9uxTtngtpAFZ4 yrvs+mPrVz9Cr4QKDmDSNRmu3ccRLmkpHA/uP4kAALsTvq2lSxF9hsGhRxN6+5kdqx6S A1OrSjkZT2nB9zudX+QZPkycO7UQcLJHh7g+taaOmYzBvKuVJdSvRcLXY5Mm7qTNJjoz oy04HwkE2ZM5v1l1pe1pb+SBAAKLvOOJPqA2xhA6HsF5Wa/IoxqPV20FRsezRgobX+wd 9bsw== X-Gm-Message-State: AOAM532ne/Z8ZmeNMggFfLZm/4VP4dEKpqNNrzQln6TVYwS1krV0mCe+ CG+m/YcRlmnWM0xGhvujO9cZNA== X-Google-Smtp-Source: ABdhPJyfoG92S8sHKc8MSRzmfOC0+fOu2gOflvc1K9c8N/Hd34BGD+ryO4otBZ8765yE61Fmxcd6wQ== X-Received: by 2002:a63:4810:: with SMTP id v16mr1566057pga.374.1602631528718; Tue, 13 Oct 2020 16:25:28 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id b8sm791871pfr.159.2020.10.13.16.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Oct 2020 16:25:28 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: guennadi.liakhovetski@linux.intel.com, arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 6/9] rpmsg: core: Add channel creation internal API Date: Tue, 13 Oct 2020 17:25:16 -0600 Message-Id: <20201013232519.1367542-7-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201013232519.1367542-1-mathieu.poirier@linaro.org> References: <20201013232519.1367542-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org From: Arnaud Pouliquen 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 Signed-off-by: Mathieu Poirier --- drivers/rpmsg/rpmsg_core.c | 44 ++++++++++++++++++++++++++++++++++ drivers/rpmsg/rpmsg_internal.h | 4 ++++ include/linux/rpmsg.h | 6 +++++ 3 files changed, 54 insertions(+) diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c index a6361cad608b..a5c4b80debf3 100644 --- a/drivers/rpmsg/rpmsg_core.c +++ b/drivers/rpmsg/rpmsg_core.c @@ -20,6 +20,50 @@ #include "rpmsg_internal.h" +/** + * rpmsg_create_channel() - create a new rpmsg channel + * using its name and address info. + * @rpdev: rpmsg device + * @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 device + * @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 -ENXIO; + } + + 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 094cf968d2d3..b9b34b416b7b 100644 --- a/drivers/rpmsg/rpmsg_internal.h +++ b/drivers/rpmsg/rpmsg_internal.h @@ -56,6 +56,10 @@ 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 diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index 165e4c6d4cd3..eb70463a9f2e 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -42,6 +42,8 @@ typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32); /** * struct rpmsg_device_ops - indirection table for the rpmsg_device operations * @is_little_endian: returns true if using little endian byte ordering + * @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 @@ -52,6 +54,10 @@ typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32); */ struct rpmsg_device_ops { bool (*is_little_endian)(struct rpmsg_device *rpdev); + 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); From patchwork Tue Oct 13 23:25:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11837157 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 6007C14B5 for ; Wed, 14 Oct 2020 09:22:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2AC5A206DC for ; Wed, 14 Oct 2020 09:22:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="DReAvGur" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729143AbgJNJW1 (ORCPT ); Wed, 14 Oct 2020 05:22:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731136AbgJNJVv (ORCPT ); Wed, 14 Oct 2020 05:21:51 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F893C08EA7C for ; Tue, 13 Oct 2020 16:25:30 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id j7so734438pgk.5 for ; Tue, 13 Oct 2020 16:25:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ycxUYKRLNQGbeCvnapexQBRiRUEcK7gRrJqEvEJwNPU=; b=DReAvGur7O904kV9bwo2L59Z3mvZRc0h595iFLuMXVnNIjg1reLDaqCfs1ExYnuL0a xzkyYZMfg3qkxDFHouotKCI/T+UEp/ihm12qm1sAtj/fTpzqId7uRrTPLxUUbWZ38517 kdlIyO1xazLS69mHFCgSkWzuN0L/Az+SXZWaECt3NlRNN7jPH5pN2YVo3/oiQ6xAdR3P lxMJnhTu4FYgdmfecWxDNAkdXxToBCSW+tT5OK7d148gbNeZe0zmnELBGHx8BskptLpS C2PBZY4tmJsGur/D6IqtnRi7fjyV3gFOMZAjEU7oqqi8URV1XsQHhkYRP0D96WqTN2AJ crHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ycxUYKRLNQGbeCvnapexQBRiRUEcK7gRrJqEvEJwNPU=; b=d+ArI5xjs0drP9/rG1zjGgxyW7ZUCGsJkZ4F73cko5y5X21jGrA1C0OzKUah87wfqP 0SeXDQl5U3GL3S1Sf5Eo7QYc633l88ztFyjZQCkICI8UMAjo5wItxzCGgAe0RlDDwg3u lIvFGkHDLMahr25FpPktWY3IJjBUCojkjrPwykak/iGBMd8qvTevX4OO8bL6iGPArfaJ KdczxQTLyfquPLrRcLaAY6a9f1jfd/yTsqW7szlAXwwJUWUnNCP1bYPAbvHCZK8+eceg GXeNes8wtIMCXmmi8OcIAPqRRh46InJhAKte6psWKqxnOphyubDq4fcRJp1NfTUKIz4B 14XQ== X-Gm-Message-State: AOAM532ItcYIgV6jYxn1U7zBhvZlUf/WVh7VYqg1KKp9HhQj3B3hoG+z D/aAA3TBoGO83H/nGKPGfAZTww== X-Google-Smtp-Source: ABdhPJxgfavWpmuypj/8H9ULQUnlQNTptm5BF7sI12I+BEGDSeAMZy/ayCjKlengG3wmmLGtDjIMJg== X-Received: by 2002:a63:77c4:: with SMTP id s187mr1487622pgc.303.1602631529987; Tue, 13 Oct 2020 16:25:29 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id b8sm791871pfr.159.2020.10.13.16.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Oct 2020 16:25:29 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: guennadi.liakhovetski@linux.intel.com, arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 7/9] rpmsg: virtio: Add rpmsg channel device ops Date: Tue, 13 Oct 2020 17:25:17 -0600 Message-Id: <20201013232519.1367542-8-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201013232519.1367542-1-mathieu.poirier@linaro.org> References: <20201013232519.1367542-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org From: Arnaud Pouliquen Implement the create and release of the RPMsg channel for the RPMsg virtio bus. Signed-off-by: Arnaud Pouliquen Signed-off-by: Mathieu Poirier --- drivers/rpmsg/virtio_rpmsg_bus.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index fca982b61c3b..1488b9ddc18d 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -122,6 +122,8 @@ 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 * __rpmsg_create_channel(struct virtproc_info *vrp, + struct rpmsg_channel_info *chinfo); static const struct rpmsg_endpoint_ops virtio_endpoint_ops = { .destroy_ept = virtio_rpmsg_destroy_ept, @@ -234,6 +236,24 @@ static bool virtio_rpmsg_is_little_endian(struct rpmsg_device *rpdev) return virtio_is_little_endian(vrp->vdev); } +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); +} + static struct rpmsg_endpoint *virtio_rpmsg_create_ept(struct rpmsg_device *rpdev, rpmsg_rx_cb_t cb, void *priv, @@ -327,6 +347,8 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev) static const struct rpmsg_device_ops virtio_rpmsg_ops = { .is_little_endian = virtio_rpmsg_is_little_endian, + .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, From patchwork Tue Oct 13 23:25:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11837091 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 3E7741130 for ; Wed, 14 Oct 2020 09:19:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0E56E20878 for ; Wed, 14 Oct 2020 09:19:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="pcw3QpIs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730350AbgJNJTk (ORCPT ); Wed, 14 Oct 2020 05:19:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729691AbgJNJTi (ORCPT ); Wed, 14 Oct 2020 05:19:38 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 814A2C08EA7E for ; Tue, 13 Oct 2020 16:25:31 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id a17so384269pju.1 for ; Tue, 13 Oct 2020 16:25:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X3n2ho81UJxHjYAOtHKEObboyFHoWnbr7nY2GT8du90=; b=pcw3QpIsWZbgV4mYT17/ZkDzS9GUQwNuXdpUMmPVIXjiAHjDxVe2fclc667n1Mf/Yp jO7VVcFUwEnza/M2gr9UFAmzm7fcu+0IcEV+Apl+mye532Kte5e44raMMe+WExzPBQni dRdyZVioPHp0H6EVxrlYtgayiGzaOsG3ZOtA7a0s1kvc7uD0IsmBsb6LZTYHVCsW9N/H 8aWdr2fJd0V5n/s5OHrD23yLxp47xaIbDnKYQNkLmBzwYf7mnYVwqniLy9Au9PG9Tzv3 ZvqvJq8WayGzHYEvBuDpjfrxtxk+Cp+ERTsySzfYL06z2XJ3R6nQAg1bX86fGXVXGL9v COHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X3n2ho81UJxHjYAOtHKEObboyFHoWnbr7nY2GT8du90=; b=AOgwFzBPIBOjmlqQVBSYf5k1MVzciIzXnb+mqv2fNaOVDay/1mmFmMZgB4UXEHshw9 BX4rwAW5ae6BUv+NvIqdWnR51HBS3LhnVM71uinb/qnEYfONFaXDuOnmod6i7Ns1CVXx 9lv9F/HgQl1ASl9OJirN/Z9IL21I9GruNET5EpO/7jegWTnVAX4b0D7A4QD8ZNVwLJcv UpLtk9KDQX3MUd2DIFi9cX753uMsg4eNSFNAVmJMOUA6RMF1z4nadf0sqU+OngShlJyF kdJ5M9aC1C0vxuMxTDGZAyNkpz0BgfFRuh8K2uPrZqJkKDmqYNGFPE47/LMJaCD9q7Dt wngQ== X-Gm-Message-State: AOAM530ZK/jtkQInXsXmqEiVOXPia6bm0igImeI/eXDgiMddxdHpMe5j DPmNmntlY/57NvH/BNpDVeKCUA== X-Google-Smtp-Source: ABdhPJwUl0alPVSwthinpn9vl5ZeslA2Ow8z+un8kBTktbxsOB0px02HyluHPifSwZurWsCmmfN8yw== X-Received: by 2002:a17:902:6b44:b029:d3:e78a:8ab6 with SMTP id g4-20020a1709026b44b02900d3e78a8ab6mr1695546plt.72.1602631531099; Tue, 13 Oct 2020 16:25:31 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id b8sm791871pfr.159.2020.10.13.16.25.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Oct 2020 16:25:30 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: guennadi.liakhovetski@linux.intel.com, arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 8/9] rpmsg: Make rpmsg_{register|unregister}_device() public Date: Tue, 13 Oct 2020 17:25:18 -0600 Message-Id: <20201013232519.1367542-9-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201013232519.1367542-1-mathieu.poirier@linaro.org> References: <20201013232519.1367542-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Make function rpmsg_register_device() and rpmsg_unregister_device() functions public so that they can be used by other clients. While doing so get rid of two obsolete function, i.e register_rpmsg_device() and unregister_rpmsg_device(), to prevent confusion. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/rpmsg/rpmsg_internal.h | 4 ---- include/linux/rpmsg.h | 12 ++++++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h index b9b34b416b7b..70de053581bd 100644 --- a/drivers/rpmsg/rpmsg_internal.h +++ b/drivers/rpmsg/rpmsg_internal.h @@ -49,10 +49,6 @@ struct rpmsg_endpoint_ops { poll_table *wait); }; -int rpmsg_register_device(struct rpmsg_device *rpdev); -int rpmsg_unregister_device(struct device *parent, - struct rpmsg_channel_info *chinfo); - struct device *rpmsg_find_device(struct device *parent, struct rpmsg_channel_info *chinfo); diff --git a/include/linux/rpmsg.h b/include/linux/rpmsg.h index eb70463a9f2e..0b3ec18ddbaa 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -188,8 +188,9 @@ static inline __rpmsg64 cpu_to_rpmsg64(struct rpmsg_device *rpdev, u64 val) #if IS_ENABLED(CONFIG_RPMSG) -int register_rpmsg_device(struct rpmsg_device *dev); -void unregister_rpmsg_device(struct rpmsg_device *dev); +int rpmsg_register_device(struct rpmsg_device *rpdev); +int rpmsg_unregister_device(struct device *parent, + struct rpmsg_channel_info *chinfo); int __register_rpmsg_driver(struct rpmsg_driver *drv, struct module *owner); void unregister_rpmsg_driver(struct rpmsg_driver *drv); void rpmsg_destroy_ept(struct rpmsg_endpoint *); @@ -212,15 +213,18 @@ __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp, #else -static inline int register_rpmsg_device(struct rpmsg_device *dev) +static inline int rpmsg_register_device(struct rpmsg_device *rpdev) { return -ENXIO; } -static inline void unregister_rpmsg_device(struct rpmsg_device *dev) +static inline int rpmsg_unregister_device(struct device *parent, + struct rpmsg_channel_info *chinfo) { /* This shouldn't be possible */ WARN_ON(1); + + return -ENXIO; } static inline int __register_rpmsg_driver(struct rpmsg_driver *drv, From patchwork Tue Oct 13 23:25:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11837207 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 4E4D914B5 for ; Wed, 14 Oct 2020 09:24:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0D703206F4 for ; Wed, 14 Oct 2020 09:24:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="vfYybF6X" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729301AbgJNJYg (ORCPT ); Wed, 14 Oct 2020 05:24:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730812AbgJNJUK (ORCPT ); Wed, 14 Oct 2020 05:20:10 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3631C08EAC1 for ; Tue, 13 Oct 2020 16:25:32 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id x13so726796pgp.7 for ; Tue, 13 Oct 2020 16:25:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l3Mt/0E9AmGeziRvZyZJfVySy927OsM82c2xG5wHBJ0=; b=vfYybF6Xx0JLOBoKy7O795Xg8FWZlvzUUw3+rZbNAkKS20S6kK9UqruBKkRvb4NFTT S/JVwIEXLyhr4NhAg9LjErZNpknyoEcWy+uKGvjxLbYDEm30mdceLxutDoxM7tsjMkeJ ZX5NvHVVsFr750r8QTsZsi+hSKZprNApmk7Z0U2lISuY6a2lN5MyEHWWT8ogNr8e+Kf+ pgExKU4ko7atGtnhawaT2p2k/swPbGmc2kxlekEwKj9OQWgKinm1dGNm+Ckm+jvMvKg0 jG9R/edlQW/1xBEceYAfqfKfMgyXZfHeO99hzQKjZ/zbd7h8oyAYpGiF+p6ItWzo72ZY AghQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l3Mt/0E9AmGeziRvZyZJfVySy927OsM82c2xG5wHBJ0=; b=BPuKSf2ZQ0DNGvkJR+Oc069bm8nvp4p3Gi3Q/aNTWJUSCIeZgw34cGS+RYiLY3j971 2Xo2aevwLArJz5DafGcMZwpBB/z4PKSvWRbBKc8Cs7wjJtkP39DRvYfm6eHRU3N7Tccz BfBB0+CsQGUMTZ3gfgZAePwe4DAVZD7FvOCjmL3eTUHBIiHZ60fqWp+raxCL+ilu4FxD MHGDhGcfRByapyX1QYAF0iprzEBhM6kzOD/32PgjtPxX2s/DdHWjnqk/dzMNNxfZBndP kaLRGB4xKcVrj+eYPK2aSLj8V3mGP+pXL82EpGtThXCE3DatBXJnLZWOHM33/FQPvlIL mbLQ== X-Gm-Message-State: AOAM5320HQ9NpDeAsOSzMUg0rCo71hnZVauDDyY1F5lMm1sZifwz8xm/ GS/G90TYCb0x0VwUhvq2GRidcQ== X-Google-Smtp-Source: ABdhPJzEJ/TDl6Cn89HkHFRbim59nkC5HRgyfhLFGK1p4KY7VJEs3812nYPYwy822nyv33PvfjArcA== X-Received: by 2002:a63:f815:: with SMTP id n21mr1573710pgh.410.1602631532303; Tue, 13 Oct 2020 16:25:32 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id b8sm791871pfr.159.2020.10.13.16.25.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Oct 2020 16:25:31 -0700 (PDT) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: guennadi.liakhovetski@linux.intel.com, arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 9/9] rpmsg: Turn name service into a stand alone driver Date: Tue, 13 Oct 2020 17:25:19 -0600 Message-Id: <20201013232519.1367542-10-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201013232519.1367542-1-mathieu.poirier@linaro.org> References: <20201013232519.1367542-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org From: Arnaud Pouliquen Make the RPMSG name service announcement a stand alone driver so that it can be reused by other subsystems. It is also the first step in making the functionatlity transport independent, i.e that is not tied to virtIO. Co-developed-by: Mathieu Poirier Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/Kconfig | 8 +++ drivers/rpmsg/Makefile | 1 + drivers/rpmsg/rpmsg_ns.c | 110 +++++++++++++++++++++++++++++++ drivers/rpmsg/virtio_rpmsg_bus.c | 84 +++++------------------ include/linux/rpmsg_ns.h | 17 +++++ 5 files changed, 154 insertions(+), 66 deletions(-) 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_ns.c b/drivers/rpmsg/rpmsg_ns.c new file mode 100644 index 000000000000..65be20583c8f --- /dev/null +++ b/drivers/rpmsg/rpmsg_ns.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) STMicroelectronics 2020 - All Rights Reserved + */ +#include +#include +#include +#include +#include +#include +#include + +#include "rpmsg_internal.h" + +/* 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.parent; + 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 = rpmsg32_to_cpu(rpdev, msg->addr); + + dev_info(dev, "%sing channel %s addr 0x%x\n", + rpmsg32_to_cpu(rpdev, msg->flags) & RPMSG_NS_DESTROY ? + "destroy" : "creat", msg->name, chinfo.dst); + + if (rpmsg32_to_cpu(rpdev, msg->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_endpoint *ns_ept; + struct rpmsg_channel_info ns_chinfo = { + .src = RPMSG_NS_ADDR, + .dst = RPMSG_NS_ADDR, + .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"); diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 1488b9ddc18d..a5284dc40ac5 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -49,7 +49,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 @@ -68,7 +67,6 @@ struct virtproc_info { struct mutex endpoints_lock; wait_queue_head_t sendq; atomic_t sleepers; - struct rpmsg_endpoint *ns_ept; }; /** @@ -794,68 +792,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 = rpmsg32_to_cpu(rpdev, msg->addr); - - dev_info(dev, "%sing channel %s addr 0x%x\n", - rpmsg32_to_cpu(rpdev, msg->flags) & RPMSG_NS_DESTROY ? - "destroy" : "creat", msg->name, chinfo.dst); - - if (rpmsg32_to_cpu(rpdev, 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; @@ -931,14 +875,25 @@ 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) + goto free_coherent; } /* @@ -991,9 +946,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); diff --git a/include/linux/rpmsg_ns.h b/include/linux/rpmsg_ns.h index 3d836b8580b2..9e529ef40ce5 100644 --- a/include/linux/rpmsg_ns.h +++ b/include/linux/rpmsg_ns.h @@ -59,4 +59,21 @@ enum rpmsg_ns_flags { /* Address 53 is reserved for advertising remote services */ #define RPMSG_NS_ADDR (53) +/** + * 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