From patchwork Fri Nov 20 21:42:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11922623 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D545C2D0E4 for ; Fri, 20 Nov 2020 21:43:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 244842240B for ; Fri, 20 Nov 2020 21:43:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="JzyS/z+y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726556AbgKTVmt (ORCPT ); Fri, 20 Nov 2020 16:42:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727678AbgKTVms (ORCPT ); Fri, 20 Nov 2020 16:42:48 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13C10C061A04 for ; Fri, 20 Nov 2020 13:42:48 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id a18so9151531pfl.3 for ; Fri, 20 Nov 2020 13:42:48 -0800 (PST) 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=4qX2THs/dhWrDnWe2HpkQ84reF55tyq/NRsKrAKp/sc=; b=JzyS/z+yWgOovDCPVrd7FUuIHGI6Am40tDgwvIfBlFV960j9l8RyycvwMqUh2+I8v7 lSRkNb+P0jDab1gBynzE0RAIEV/drUOn+h+VxDoEUROvj33+NIL4MGhU2Lq/KY4MXHP5 J1j+COwvxzYKTB/3CgaibcW3oeU7lXhCeXlmsO3jzjVMhOLrA8yXI3ee0d07VrzyJvKZ SAbEeC40k3r4u1iradgkUJ9sZOZLjTE15zAy8dmoJEflCsYgIQjouIox3gexgJ5xonpg qtB+Z5zJ5+xrxrztTy9RSlT+5sD45HWzYi27wDGVU8z+VKXbqVeVAdA8PfOKXeXMeHOw F9HQ== 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=4qX2THs/dhWrDnWe2HpkQ84reF55tyq/NRsKrAKp/sc=; b=kggNr+t5ffRR7Vn1uMaV94aUtrXWUbbO1CDnbfhzIYqQiHKNm4xVnzvbxuAaMqir7K By9ut2Gh2dE3HrhPBCAPwXDUTchWACNb5jovbqgp0bmwuEDMCDyHxSfeSnw8YCG5Say5 HsZvMKX9gVUN7UY48gGfXLCgxnSP2k9/M2NUVYiZUXJkIMstlGhUANViN47EkREwy7KR IubG8kxu2xCresAxN9jjkso1o1RRfQUXMo1mZqMSCZ5B5xbPE3PSuPm3OocP1+nOZtcR /0vDhlpYiSy4BgEtfc6d/rfNA0sw9PSoousCqccZBZiElibPZ+FnqODr6VI1a0K57F9b Fm9Q== X-Gm-Message-State: AOAM530Lq8UoAh7QpyAlqgkUrX0pd1YxcARdifQPUY5F3xa/Py+Q+K2w +2EEsXLFOaUKQh7JJ5lGbGL9Pw== X-Google-Smtp-Source: ABdhPJzXs1Oo2LOli+ruv52/peMQHoXSY159bCeXhDh3WGYiOdwu4NNScWHaBa91OB2Vwqp/eVg5SQ== X-Received: by 2002:a17:90a:c003:: with SMTP id p3mr11967475pjt.221.1605908567623; Fri, 20 Nov 2020 13:42:47 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm4713197pfj.157.2020.11.20.13.42.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2020 13:42:47 -0800 (PST) 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 v7 1/8] rpmsg: Introduce __rpmsg{16|32|64} types Date: Fri, 20 Nov 2020 14:42:38 -0700 Message-Id: <20201120214245.172963-2-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120214245.172963-1-mathieu.poirier@linaro.org> References: <20201120214245.172963-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 9fe156d1c018..faf2daff6238 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -17,6 +17,7 @@ #include #include #include +#include #define RPMSG_ADDR_ANY 0xFFFFFFFF @@ -46,6 +47,7 @@ struct rpmsg_channel_info { * @dst: destination address * @ept: the rpmsg endpoint of this channel * @announce: if set, rpmsg will announce the creation/removal of this channel + * @little_endian: True if transport is using little endian byte representation */ struct rpmsg_device { struct device dev; @@ -55,6 +57,7 @@ struct rpmsg_device { u32 dst; struct rpmsg_endpoint *ept; bool announce; + bool little_endian; const struct rpmsg_device_ops *ops; }; @@ -111,6 +114,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) + return __rpmsg16_to_cpu(rpmsg_is_little_endian(), val); + else + return __rpmsg16_to_cpu(rpdev->little_endian, val); +} + +static inline __rpmsg16 cpu_to_rpmsg16(struct rpmsg_device *rpdev, u16 val) +{ + if (!rpdev) + return __cpu_to_rpmsg16(rpmsg_is_little_endian(), val); + else + return __cpu_to_rpmsg16(rpdev->little_endian, val); +} + +static inline u32 rpmsg32_to_cpu(struct rpmsg_device *rpdev, __rpmsg32 val) +{ + if (!rpdev) + return __rpmsg32_to_cpu(rpmsg_is_little_endian(), val); + else + return __rpmsg32_to_cpu(rpdev->little_endian, val); +} + +static inline __rpmsg32 cpu_to_rpmsg32(struct rpmsg_device *rpdev, u32 val) +{ + if (!rpdev) + return __cpu_to_rpmsg32(rpmsg_is_little_endian(), val); + else + return __cpu_to_rpmsg32(rpdev->little_endian, val); +} + +static inline u64 rpmsg64_to_cpu(struct rpmsg_device *rpdev, __rpmsg64 val) +{ + if (!rpdev) + return __rpmsg64_to_cpu(rpmsg_is_little_endian(), val); + else + return __rpmsg64_to_cpu(rpdev->little_endian, val); +} + +static inline __rpmsg64 cpu_to_rpmsg64(struct rpmsg_device *rpdev, u64 val) +{ + if (!rpdev) + return __cpu_to_rpmsg64(rpmsg_is_little_endian(), val); + else + return __cpu_to_rpmsg64(rpdev->little_endian, 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 Fri Nov 20 21:42:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11922635 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0AD87C64E90 for ; Fri, 20 Nov 2020 21:43:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B206F2467D for ; Fri, 20 Nov 2020 21:43:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="bWCckrEM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728097AbgKTVmu (ORCPT ); Fri, 20 Nov 2020 16:42:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727885AbgKTVmt (ORCPT ); Fri, 20 Nov 2020 16:42:49 -0500 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22B80C061A47 for ; Fri, 20 Nov 2020 13:42:49 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id y7so9124530pfq.11 for ; Fri, 20 Nov 2020 13:42:49 -0800 (PST) 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=FveG7gwXoxnfUqfAm1M6z1jk2IKd8VxnJz1cUoAZjBk=; b=bWCckrEMRPwsMJMS82E0mMchlA/hiEcY2NFvr6T2G22TLf6GL9OC5/4tqsW/w3+1z9 6uimEkSLni/xbPqQnq8DxRWzAjAnUvg4V7EuI6HkqAbcNYqyUrWHfj8/8hh1TImHSqJy BcpH2vk5Tz9TiM7jr1If/WFiZgEPfMQ2eeZI7rIqzwPGmqOTXvbM7ZOfcPXit61Fh7WY XPAEVeiP1QB/z3vw45YwLciDMGLJ1Z15lIalsV2jsz908g46vD6oI31u3iB8HDuE2y3n l5j5LSiTU3HX/wrcs7b6Ov/oTTLAnR5OzIzZhrNyJL+YJymxlL0HxDiX6ZN3qlkFD2J0 eN9A== 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=FveG7gwXoxnfUqfAm1M6z1jk2IKd8VxnJz1cUoAZjBk=; b=LXusf0E8hn7ZP5XQ9OYOiIsQH+nemMu2f59fert0YAzBOdsBB6GMYAsRHqmRf4WuuA CmBJbqM+sEcVklCpgrm6d2h7HTT7MgH8eo/kwx2hX6vSm5LYfbCmgzljzLyfPNtecK6q 8aE0ZmbsiRTVltwh6oNXJRpk8oElSWyw4VH28g/5iR1fAW2KBwSrZG5Fcdhq6izWMwDD HuqWAUGMTuLS08R6lOOKjMJ9/7VRohzVr8ZxoZdQBybcWbTaiyh+eeouBx+zduhzZlwm VPsXrZ04pGVEHfPTrT0DpQgwOtkqGyiORhEpZBcWh+MPYrASCmKf+M5dLgsNPpNXldJ3 8Jww== X-Gm-Message-State: AOAM532PFjzyvGzJJNxBe7eD5gnhASytN18OV9d2Y3c3PkIORpxHFYS2 nIfmJe3FBxFGSXBovMxIWc5YMA== X-Google-Smtp-Source: ABdhPJy4tI89KcwHbKlgFSUDHTRg4X9nKYEI28dCk1Qnv5DL2CTogDPh6pPWWx4ASr8CGwFPYBt9Ug== X-Received: by 2002:aa7:8744:0:b029:18b:a9e1:803d with SMTP id g4-20020aa787440000b029018ba9e1803dmr15188203pfo.50.1605908568699; Fri, 20 Nov 2020 13:42:48 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm4713197pfj.157.2020.11.20.13.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2020 13:42:48 -0800 (PST) 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 v7 2/8] rpmsg: virtio: Move from virtio to rpmsg byte conversion Date: Fri, 20 Nov 2020 14:42:39 -0700 Message-Id: <20201120214245.172963-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120214245.172963-1-mathieu.poirier@linaro.org> References: <20201120214245.172963-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 Reviewed-by: Arnaud Pouliquen --- drivers/rpmsg/virtio_rpmsg_bus.c | 53 +++++++++++++++++--------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 7d7ed4e5cce7..5259fbbc8e68 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; /** @@ -341,8 +341,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) @@ -365,8 +365,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) @@ -425,6 +425,7 @@ static struct rpmsg_device *rpmsg_create_channel(struct virtproc_info *vrp, rpdev->src = chinfo->src; rpdev->dst = chinfo->dst; rpdev->ops = &virtio_rpmsg_ops; + rpdev->little_endian = virtio_is_little_endian(vrp->vdev); /* * rpmsg server channels has predefined local address (for now), @@ -618,10 +619,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); @@ -710,14 +711,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 = virtio_is_little_endian(vrp->vdev); + 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); @@ -736,7 +738,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) @@ -750,7 +752,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); @@ -830,6 +832,7 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len, struct rpmsg_channel_info chinfo; struct virtproc_info *vrp = priv; struct device *dev = &vrp->vdev->dev; + bool little_endian = virtio_is_little_endian(vrp->vdev); int ret; #if defined(CONFIG_DYNAMIC_DEBUG) @@ -858,13 +861,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(little_endian, 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(little_endian, 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(little_endian, 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 Fri Nov 20 21:42:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11922637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6E38C64EBC for ; Fri, 20 Nov 2020 21:43:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7EC012240B for ; Fri, 20 Nov 2020 21:43:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="VzUNQrAE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728367AbgKTVnI (ORCPT ); Fri, 20 Nov 2020 16:43:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728174AbgKTVmu (ORCPT ); Fri, 20 Nov 2020 16:42:50 -0500 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 3CB65C0613CF for ; Fri, 20 Nov 2020 13:42:50 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id m9so8447070pgb.4 for ; Fri, 20 Nov 2020 13:42:50 -0800 (PST) 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=JnwwhkWQ3GeoAyW3l6kwgfA23oecuiB8HGCIRs5X5Aw=; b=VzUNQrAE4wFp3JCqzBDRItQY7d3iKu/bjxiETUpjz7KFyDIseKrdmQP2XNTMg0xkiI OQw3Zga7phPQJBVmwriflTkHTQuYUhkOif16K6MAzXfQutfYp8ugJDs14wQqpT11mRz3 VDS0qldQ1OH7vb3YnJveqwnJfdb3S7ytdIFVUXoXb6nFDTLitAMzXWvKoKunysc00Z9F VheyIho7s1GwBwGe6zW/1ymYAlQj/qhHQGqbHiB4Pmz4sv/ePpiFu4Uidpf047clRP8o ERcfzJviiftPSrcPSpcANhL8nVILqf6OWyAHhxA925gphG6gBcokQ78CCslA3dHTcQkf i4Vg== 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=JnwwhkWQ3GeoAyW3l6kwgfA23oecuiB8HGCIRs5X5Aw=; b=b8hLgQJHQJHjYz+yCP8yadr8J+YDrg9PYc8g9UMNm2kZol7BCL42WlqwhJxDZ4jRZF Y2WUpKQqT6HGfWjg6TkkRJtymsZceoLGJpcmPVkii6OagymQeAUA8CTk8QC75OiBgyfX ZiZUoYoJa8Y5jdH6vGCph7rMYWBatEZCylwj4vJ0BOVdpUPW5pA2ebJLyGP7CWU6Njxk ioMafswmyoIap/ZcSv9OkXpi1/VyoBLWDYJc+WAK/c+kLeNt7sRMQIzabarg9hk6ysIo flqCGw1S0lWlny0ofyr1KEHqIFgRbKuXRMnVl1awxJbyohxeYGD0x3PuJrpq6V872Gh/ tf3A== X-Gm-Message-State: AOAM5300BXEhXFp5L1sfjZNPKtuUmtyUwhyg6L/s18kcc75M2TDCwINu WwdfFibPMcOuj85PYcP7+8K17w== X-Google-Smtp-Source: ABdhPJxOTtuYstDLKctepxBS7KkotAln4vgrKRWz/Ij9cHcCnk2ExRqDEA1CI505Q5s/1Zcy21Dnaw== X-Received: by 2002:a17:90b:4a4b:: with SMTP id lb11mr6323001pjb.131.1605908569804; Fri, 20 Nov 2020 13:42:49 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm4713197pfj.157.2020.11.20.13.42.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2020 13:42:49 -0800 (PST) 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 v7 3/8] rpmsg: Move structure rpmsg_ns_msg to header file Date: Fri, 20 Nov 2020 14:42:40 -0700 Message-Id: <20201120214245.172963-4-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120214245.172963-1-mathieu.poirier@linaro.org> References: <20201120214245.172963-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org Move structure rpmsg_ns_msg to its own header file so that it can be used by other entities. Signed-off-by: Mathieu Poirier Reviewed-by: Arnaud Pouliquen --- drivers/rpmsg/virtio_rpmsg_bus.c | 32 +----------------------- include/linux/rpmsg/ns.h | 42 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 31 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 5259fbbc8e68..20d0cf909bea 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -93,34 +94,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]; - __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, -}; /** * struct virtio_rpmsg_channel - rpmsg channel descriptor @@ -167,9 +140,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..73ecc91dc26f --- /dev/null +++ b/include/linux/rpmsg/ns.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_RPMSG_NS_H +#define _LINUX_RPMSG_NS_H + +#include +#include +#include + +/** + * 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 From patchwork Fri Nov 20 21:42:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11922633 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6652DC64E8A for ; Fri, 20 Nov 2020 21:43:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 044E42240B for ; Fri, 20 Nov 2020 21:43:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="BQ2mStle" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728398AbgKTVmv (ORCPT ); Fri, 20 Nov 2020 16:42:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728348AbgKTVmv (ORCPT ); Fri, 20 Nov 2020 16:42:51 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 472B6C061A47 for ; Fri, 20 Nov 2020 13:42:51 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id m9so8447104pgb.4 for ; Fri, 20 Nov 2020 13:42:51 -0800 (PST) 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=C0V+Pj0ilaPOi+EzL05tF5APIQBX5vdWZzPetY3Iqd8=; b=BQ2mStleSEb6Vq7fzNOMEORpABuWVGX+OVYNXDrlZp3laXuQdzsp9CL9/KB6iKm3rA nqfv+WVK8PJkSdGFgUi0aDPkFlMCwi1HF9KqtfbGeCsQq0DzBcHFkmIWE4AtX3wz8MBN DiYMbLLeqYauKBa0yOzr5j0vfaGhAb/2QrmnH7QJtYAdSCXOJmAS5DUkoxUDpTBr2pYY yTP8+dy/EaoX4wy0ICiAVROMdEUwnF3E2iAemXTCAptqHKa+6l9Ba9092asqFdob7nNa telokoOdqILySOLocvqK2iftTdRweQ8IpdvSYbnWI6B6aFXeTEszTf/5qcg9aoFoyKB7 8TRw== 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=C0V+Pj0ilaPOi+EzL05tF5APIQBX5vdWZzPetY3Iqd8=; b=S4Hy9QmQuVl0tA+qRlH0tdKPSU7SUkEYmzCLd9Lly135KXIkO5beZERQuCIf/yLuDT uzFhHKothbNgUW03KT1NI0xcvfbSFFxfhp3IUvoEygWIHHzsslEz+BKiDFE20KZNQii9 zh3i9k4KE5YpCzcb3PZBzFuqedVTaJ6aO3cYhiiX6BhuSduolvt2uOd7A4dQ+LNEVkY3 oKH8o6EeH9pJaRDlJjkjCjTO5NIq955Dijj+Z+Rjpu+wzzeGUF5/NCgheFa6TPyWjtyh CqO5SV90yhSCJQUh1ROy8f/5sDkoMWnlOzMf7GB7xtYQj4qj2jKgo3SrhqSovK5CoFaq RVkw== X-Gm-Message-State: AOAM532vkpicGK/EtVPfBTy71Laxj6PQJAmbB04m99l3h87sesj2QocM mABThsMjt0dsX4p1vj9GzU0UzQ== X-Google-Smtp-Source: ABdhPJx0An3b+R1I2ZHms+oK4lKIOFr0gTovvFhZajuljF8WtiMdqH3URsRuYsyzOHedVl8cGBVecg== X-Received: by 2002:a17:90a:b118:: with SMTP id z24mr13018704pjq.102.1605908570843; Fri, 20 Nov 2020 13:42:50 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm4713197pfj.157.2020.11.20.13.42.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2020 13:42:50 -0800 (PST) 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 v7 4/8] rpmsg: virtio: Rename rpmsg_create_channel Date: Fri, 20 Nov 2020 14:42:41 -0700 Message-Id: <20201120214245.172963-5-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120214245.172963-1-mathieu.poirier@linaro.org> References: <20201120214245.172963-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 Reviewed-by: Guennadi Liakhovetski --- 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 20d0cf909bea..2253936593c5 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -365,8 +365,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; @@ -842,7 +842,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 Fri Nov 20 21:42:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11922631 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBC97C64E7C for ; Fri, 20 Nov 2020 21:43:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 85BC22240B for ; Fri, 20 Nov 2020 21:43:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="rsprrXgQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728553AbgKTVnE (ORCPT ); Fri, 20 Nov 2020 16:43:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728521AbgKTVmx (ORCPT ); Fri, 20 Nov 2020 16:42:53 -0500 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B804C061A04 for ; Fri, 20 Nov 2020 13:42:52 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id a18so9151672pfl.3 for ; Fri, 20 Nov 2020 13:42:52 -0800 (PST) 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=YpJGL4iVaQpB7OmyOGqz/Jf0POXHK+Nggf2uFVT9Buw=; b=rsprrXgQJ8Uxq1riKWhihy1oQMH/BBT8pLh6Z5YIbfumyJK4ixSQK3k6LnsVGQ1WOE EID9fHBgPrYlxGubouynSgoa/cjJZwycBwZPRP2gzxDiyi0Pyl1i+lRu4J/E7npqafBl kAKwcXcog/Kir1pfvgk+Fg7LQ239DGndiqza9kdbGoBa+gJE40fZdw5uyE+YxTGHan8x D6688IWtT7RThWkrPGHfTrkDIV8yUSRnn8Q+hBSVxBUS4DxJzfcO8r/Ja2WYxu3AUbnV 0AWocaPeoBm5aLIQmfZOEHf4a9r7kr5h9u0zLnumaIk46MaeS/zytw/cwXF0MX3lMqgB zbRA== 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=YpJGL4iVaQpB7OmyOGqz/Jf0POXHK+Nggf2uFVT9Buw=; b=ZicW0bKkRyHrlBAfhRii4gF/B8sZwDjGsKhLL7G6sKZ0F8bIa71Ujt6xJalm0FGMED pexzl8OKLGVbRFMcDa/PELDO+M5p3OVv58vPsarJLtkUrfJmOR71dpX8LP41c59nUDEK pooKswHD/zA8H5o4iwTbDZesXkoTUPbaRVik2ts/hZVejmJn0i7NTk2urkTFrknCGXCd nGFJbYF7P680kUqYBHYNn0tsfwc4CsL3beUCAjSJioWnbGU0mGYVwwa3W8UUq0wJGQ1D vd0pUP0jkqG6jeKjVLYmzRGnDqmvrZw4fbSvBrK63YAPeoDMkeWt2rD4eiQi6AEYCGFP bMug== X-Gm-Message-State: AOAM532DAtROyGf085Ok+nMrQiaIMhDca2bnRw9NrYFDIkkp/U7ViqbN 7IayQPVb2uCfjD4ctrXj6QYFOQ== X-Google-Smtp-Source: ABdhPJwG8ojTAM3LzlvZko1yKgzZTHIM/kSHXTPEW1lLwhIcriYMoHO4WDHWxjOocTsdcRguRLxlSw== X-Received: by 2002:a63:f944:: with SMTP id q4mr18079882pgk.98.1605908571882; Fri, 20 Nov 2020 13:42:51 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm4713197pfj.157.2020.11.20.13.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2020 13:42:51 -0800 (PST) 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 v7 5/8] rpmsg: core: Add channel creation internal API Date: Fri, 20 Nov 2020 14:42:42 -0700 Message-Id: <20201120214245.172963-6-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120214245.172963-1-mathieu.poirier@linaro.org> References: <20201120214245.172963-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 Reviewed-by: Guennadi Liakhovetski --- drivers/rpmsg/rpmsg_core.c | 44 ++++++++++++++++++++++++++++++++++ drivers/rpmsg/rpmsg_internal.h | 10 ++++++++ 2 files changed, 54 insertions(+) diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c index 91de940896e3..e5daee4f9373 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 3fc83cd50e98..f1de73e0f2d6 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,10 @@ * 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 +81,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 From patchwork Fri Nov 20 21:42:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11922629 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06C9CC56202 for ; Fri, 20 Nov 2020 21:43:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BD7E42408E for ; Fri, 20 Nov 2020 21:43:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="mHVx4nMr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728521AbgKTVnE (ORCPT ); Fri, 20 Nov 2020 16:43:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728367AbgKTVmx (ORCPT ); Fri, 20 Nov 2020 16:42:53 -0500 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C450C061A47 for ; Fri, 20 Nov 2020 13:42:53 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id 131so9136148pfb.9 for ; Fri, 20 Nov 2020 13:42:53 -0800 (PST) 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=zy3k3QU006yaoOz1NXa213YD9ZVtkyTeVCamwFEkkEQ=; b=mHVx4nMreWTzBAHDDMmYZXDqZmTt10XLrRXiZQrup3sGkBkxTudYjR55ls20nM5eW1 JmmqivHfvVfsui8YPxni6zeqnY09u38UAcAxPavMKmwVOyxQMCgOrcSCJ5YuTeGiBIU3 MRqBh9EIUAuzrVsupH8W9p1t8zaoNe9kLz1qM6PTl+AwQDI9aZg2IyHNfq429pebncYa mSRK5ytaY2LePH3dTwe8pyZ0zd8dXwRUAwJZh4SrbQS5pXauaIuhtFzEw38nDfAGiDhE 1fmmI4s5+Z0W465VJf5xAONWerTxW2/4i7Hk+/CoJaU6mTtchTzxgrna2DVHVj9zLI3R gcIw== 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=zy3k3QU006yaoOz1NXa213YD9ZVtkyTeVCamwFEkkEQ=; b=S3ykg5gug0Ndz0Jpz1GUG2nkamzqc2q/EpfsIfKJ2Qs40N3Y8fRB8zQBDq8NX2nDg4 adDQWJlu9rq1NLBwYldT7T+i5HsTEseQRVwaedAbKen0tF+U5eBUGpb84AuMgzdAUmW8 lxPG087QPezw0PyK4KRDP+o4LCyS+1LSLJO0CcV/iFYOvY9K1x+4344dBWYTtOxEocra NMlkgnlV6Zazk1269Y1J9F7H8YcAW4C2tD5i9/BpanMED+EVr5O48WX6uA1/8wCHY3wg jcEBW5m61BeqtLrEeyPR/eqKYxLvxkw6G6S+pIaSqFV4Tri3FbfXGOCMxf8FdeLpDAok sugA== X-Gm-Message-State: AOAM530XMkxBOAJR1/zOkjFQvL9nmuwrF/F6vkh+v0EBGPuAxsy+mTHM e0idPSaUprwc1j2EuCg6BDvPdSGVkFiGjg== X-Google-Smtp-Source: ABdhPJzDV/RbYKBqaRiwM48tr9/S9fRSo6t/9VSD2dhcy8do6dMdNAgMBeP8oattOr/L6XrG3E0dPQ== X-Received: by 2002:a17:90a:c401:: with SMTP id i1mr11822474pjt.184.1605908572867; Fri, 20 Nov 2020 13:42:52 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm4713197pfj.157.2020.11.20.13.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2020 13:42:52 -0800 (PST) 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 v7 6/8] rpmsg: virtio: Add rpmsg channel device ops Date: Fri, 20 Nov 2020 14:42:43 -0700 Message-Id: <20201120214245.172963-7-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120214245.172963-1-mathieu.poirier@linaro.org> References: <20201120214245.172963-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 Reviewed-by: Guennadi Liakhovetski --- 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 2253936593c5..6ec299f7f790 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -151,6 +151,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, @@ -255,6 +257,24 @@ static struct rpmsg_endpoint *__rpmsg_create_ept(struct virtproc_info *vrp, return NULL; } +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, @@ -347,6 +367,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, From patchwork Fri Nov 20 21:42:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11922625 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34533C64E7B for ; Fri, 20 Nov 2020 21:43:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D23092408E for ; Fri, 20 Nov 2020 21:43:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="deptNpfm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728622AbgKTVm4 (ORCPT ); Fri, 20 Nov 2020 16:42:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728597AbgKTVmz (ORCPT ); Fri, 20 Nov 2020 16:42:55 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BB61C061A48 for ; Fri, 20 Nov 2020 13:42:54 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id b63so9122102pfg.12 for ; Fri, 20 Nov 2020 13:42:54 -0800 (PST) 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=Jz6JCYyURz+3oCPXxnAvwJDQutjB3zynS7kiUzNmMdo=; b=deptNpfmflZwWDqDo3Id15PhX9Tird93huJPB1xqkiBorMz3shPfzHEgJjdZqZDTlh If82pWCZXM4wMn9wMLaenvqyC6JzycJ4r8O/eV9XVR0hzPgTqcT+OMxmc45lNRvuAvli 9Q2L1EbmmSHq0pxB2R5Hs5yS9BiscSj9rzYOE/+iUmYQ4kHkgIQZTsKtdUgZgx4UA6nA 091p5WQkWqK02a8XJmNzfWy4/kr9L8XBctt/ZI0HtXBx8g9As7CQ3LkBUK2eQea2xjqV m7R2mjl+o2rdao9tUbpEol1eMDn38ERrtGe+FWX1GFLy5apZxHiSvEw3FF4ZLB9OpnDA /aNg== 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=Jz6JCYyURz+3oCPXxnAvwJDQutjB3zynS7kiUzNmMdo=; b=pXYA7NyF7avIFhahJlQtqPGG+jC63aFwF85CzXRFl6d6IDQbdzJ1VVbfyl71cPXarN 9H1h9SMF8M0H+MeahIKB9fv3uh1KujOm2hqn58OKjo9tcqUKbZO5ADfzB2sMBW79zysU 2hnOWQMS6oPNNW/q2/pD4cYq58Sj657t++UbFBQaqqXWGuOsbyi3p+nQXr2pQxCRz5ux 7zumANll/Ky53NOqFFLXJksMF8kAhBM2qYVZrqXM5sQJCtqHEcjlmp613Fy9nB//ouMg ij5YHaW2DCScPANs0JXpcZYdEskEWjvMVgLvxLWu99oKUfE+W8Sop5B9DnvsRXWbtVSt Egpw== X-Gm-Message-State: AOAM531d/lhk7VxymKl89NZn3B5ZVQAwnWkF13zjcUKb5wnNSGnEZ2IM GPu6nDc0EEfTUPI0OZJ0paqWxQ== X-Google-Smtp-Source: ABdhPJzrztUNm2PRB0j1V6mCKN9yvNLsSqqp0ukcJoMO+nxm5elkxfF7LGalzdde7CuNXiNyy0n5IA== X-Received: by 2002:a65:6a50:: with SMTP id o16mr12342978pgu.292.1605908573849; Fri, 20 Nov 2020 13:42:53 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm4713197pfj.157.2020.11.20.13.42.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2020 13:42:53 -0800 (PST) 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 v7 7/8] rpmsg: Make rpmsg_{register|unregister}_device() public Date: Fri, 20 Nov 2020 14:42:44 -0700 Message-Id: <20201120214245.172963-8-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120214245.172963-1-mathieu.poirier@linaro.org> References: <20201120214245.172963-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 Reviewed-by: Guennadi Liakhovetski --- 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 f1de73e0f2d6..a76c344253bf 100644 --- a/drivers/rpmsg/rpmsg_internal.h +++ b/drivers/rpmsg/rpmsg_internal.h @@ -74,10 +74,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 faf2daff6238..a5db828b2420 100644 --- a/include/linux/rpmsg.h +++ b/include/linux/rpmsg.h @@ -164,8 +164,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 *); @@ -188,15 +189,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 Fri Nov 20 21:42:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 11922627 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52C24C64E7A for ; Fri, 20 Nov 2020 21:43:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 18F9E2240B for ; Fri, 20 Nov 2020 21:43:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="UtkdwYVx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728599AbgKTVm4 (ORCPT ); Fri, 20 Nov 2020 16:42:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728596AbgKTVmz (ORCPT ); Fri, 20 Nov 2020 16:42:55 -0500 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 709E0C061A04 for ; Fri, 20 Nov 2020 13:42:55 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id m9so8447254pgb.4 for ; Fri, 20 Nov 2020 13:42:55 -0800 (PST) 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=63rMQGgTveQJcbvHL2mx/Fk9RBk50g78bSEyxHKSZcQ=; b=UtkdwYVxWYYem2V8rU+RzKN2jmDFckKfsKlrokcoVTlCJUrDNLUGOZiUriZpQoqpOo LgLP9zifdEj0igh2atnYeeBjK8Rsa29VYVwCKVgB/G4EyOWnIWhUUdvsx+ntC1PmVUGW Hzs5qyBMFfw0obxXBEtNjoTvPRtabygbEE0c+Cskil6u/b/MsRp7vVvGRCYA72vxk4uq GtA/8qNzaootwNSNa+grkaThW5fdg1p4eF86hKnj0TcS7NUeoFDyVpZyCofG9qs3yqqA cY/vpDfL2pgf3JvjyzedpYeIke5O0JkufUJcuSekJL2xkAhfzb9PJxT6awk1Vtws3X4/ FJ/w== 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=63rMQGgTveQJcbvHL2mx/Fk9RBk50g78bSEyxHKSZcQ=; b=PdxOU3ma1DXiKfMpeINtnK+1Z2bAG8FoyGtzfMzczBWM3MpP9QafRWfHhdmdMXLg4V QKFSHoX1yF7LaCKBJt/s3o/EBrTvcOLGcZBldxUSux44nFViO8vUXNqeqGBQELkE+Nub f9hwBMAtumPkvYQE73U7jFy2jL54AIW23SzK9H46jCqxXUYOlX24bINR3RFCZBTsZIeV r9uLf8KC3A3HC0cI/PzBIrmZd49gZnnEqwSNZqQg7aIcMIsteo2gIci1pa71fTOXineJ Q9wk3ftJmQXfL6VHB5IGiNUb3FvP+clJiADg0CDoEAOiTbuExe9VpIQhcWiOFOEZOqAU zm+Q== X-Gm-Message-State: AOAM533t7UtFqGrgZ/F7GnFszVq/j3iNYycAGQwiRkuKMDyZNauk8gTT aOlQU5vTXBimOY5j023jYvjaksjTwPYotA== X-Google-Smtp-Source: ABdhPJyFOF0cow3f1y89onw/qO+L9XkPq1jkEvE/Hh0l/fGHzBbq28gHIgejUhm6fVt8+gs6ApO2eg== X-Received: by 2002:a17:90b:30d0:: with SMTP id hi16mr12164670pjb.144.1605908574903; Fri, 20 Nov 2020 13:42:54 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e8sm4713197pfj.157.2020.11.20.13.42.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Nov 2020 13:42:54 -0800 (PST) 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 v7 8/8] rpmsg: Turn name service into a stand alone driver Date: Fri, 20 Nov 2020 14:42:45 -0700 Message-Id: <20201120214245.172963-9-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201120214245.172963-1-mathieu.poirier@linaro.org> References: <20201120214245.172963-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: Mathieu Poirier Co-developed-by: Guennadi Liakhovetski Signed-off-by: Guennadi Liakhovetski Signed-off-by: Arnaud Pouliquen --- drivers/rpmsg/Kconfig | 9 +++ drivers/rpmsg/Makefile | 1 + drivers/rpmsg/rpmsg_ns.c | 126 +++++++++++++++++++++++++++++++ drivers/rpmsg/virtio_rpmsg_bus.c | 87 +++++---------------- include/linux/rpmsg/ns.h | 3 + 5 files changed, 159 insertions(+), 67 deletions(-) create mode 100644 drivers/rpmsg/rpmsg_ns.c diff --git a/drivers/rpmsg/Kconfig b/drivers/rpmsg/Kconfig index f96716893c2a..0b4407abdf13 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 @@ -62,6 +70,7 @@ config RPMSG_VIRTIO tristate "Virtio RPMSG bus driver" depends on HAS_DMA select RPMSG + select RPMSG_NS select VIRTIO endmenu 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..762ff1ae279f --- /dev/null +++ b/drivers/rpmsg/rpmsg_ns.c @@ -0,0 +1,126 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) STMicroelectronics 2020 - All Rights Reserved + */ +#include +#include +#include +#include +#include +#include + +#include "rpmsg_internal.h" + +/** + * 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. + */ +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); +} +EXPORT_SYMBOL(rpmsg_ns_register_device); + +/* 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 = KBUILD_MODNAME, + .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:" KBUILD_MODNAME); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 6ec299f7f790..e87d4cf926eb 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; }; /* The feature bitmap for virtio rpmsg */ @@ -815,69 +813,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; - bool little_endian = virtio_is_little_endian(vrp->vdev); - 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(little_endian, msg->addr); - - dev_info(dev, "%sing channel %s addr 0x%x\n", - __rpmsg32_to_cpu(little_endian, msg->flags) & RPMSG_NS_DESTROY ? - "destroy" : "creat", msg->name, chinfo.dst); - - if (__rpmsg32_to_cpu(little_endian, 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; @@ -953,14 +896,26 @@ 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->little_endian = virtio_is_little_endian(vrp->vdev); + + 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; } /* @@ -985,6 +940,7 @@ static int rpmsg_probe(struct virtio_device *vdev) return 0; free_coherent: + kfree(vch); dma_free_coherent(vdev->dev.parent, total_buf_space, bufs_va, vrp->bufs_dma); vqs_del: @@ -1013,9 +969,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 73ecc91dc26f..a7804edd6d58 100644 --- a/include/linux/rpmsg/ns.h +++ b/include/linux/rpmsg/ns.h @@ -4,6 +4,7 @@ #define _LINUX_RPMSG_NS_H #include +#include #include #include @@ -39,4 +40,6 @@ enum rpmsg_ns_flags { /* Address 53 is reserved for advertising remote services */ #define RPMSG_NS_ADDR (53) +int rpmsg_ns_register_device(struct rpmsg_device *rpdev); + #endif