Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp654851pxb; Wed, 18 Nov 2020 13:38:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYFkMf9ALqvFX1RAhe6jbV1lZJ9T1g8UPY5IGrBIjsfffIVmzAi/q5ZumYps42pQqHTNSE X-Received: by 2002:a17:906:ae52:: with SMTP id lf18mr27160334ejb.9.1605735539428; Wed, 18 Nov 2020 13:38:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605735539; cv=none; d=google.com; s=arc-20160816; b=CAqvXkTAWa9IDybNWqi0L34lbLSMJmmXy81bSVXh+8Y5H78ixgRFy7SB1pZ81wFJO7 USq1B737jnXVvKGM4nwiqYMYjSQcSWOvDAEikaao1spe89bMiEiEhH1x52LJNvYRs9RW pIyUnzWj04VYMbbctw+phK82b3r2g55VAMDj29hcAFxxvS4WkDKeR+Pt+dZ9/NPphKF4 JKLiRiXxis2/aNX7wl6D2Hu+JUelP+x9hEtoWjrRPxvGb86Ht9vswoIyOsYjgzZ3uzQQ nSNqExlbOKaaz/ontmKAsRpbDk/MqlQiHuElwd+DXniHhcMg7+w/RVf/b4gPEzyP9bnn 5/tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4qX2THs/dhWrDnWe2HpkQ84reF55tyq/NRsKrAKp/sc=; b=OeGxzBOQUXu/2/X3gzJick4qLvioPJmGiTe3ntQNxajQvt8H0UW/DnbZ4Wf71Nk+U2 b/L+X7htQvU+b+0STdhCpKixMEZyKQtBKF0FJHYBCDFUoIQo3EfhdxCJO9sF7PQcYSyU OsGnNOAlxGXnWkpaGFaZ2fBJKKpjixMDzf37UZdGnufhNVy1Hs1v3SDVo3MMRYJNrByg wCTt3N53p0MFbu2ZqijSnaRSy7201lvOgs11m60J0xPNUykV6oanUQWY0VWkzqXFHEsT AiyNQZG6in4jV+5EAFTldhPb7HokxwbtXAM/V11xhDCtvI4ih9CWWYf4Dx8shtiv4/y0 6GKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ssBe4dTd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c20si19999329ejr.515.2020.11.18.13.38.35; Wed, 18 Nov 2020 13:38:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ssBe4dTd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727132AbgKRVhF (ORCPT + 99 others); Wed, 18 Nov 2020 16:37:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725879AbgKRVhD (ORCPT ); Wed, 18 Nov 2020 16:37:03 -0500 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 BCCAFC0613D6 for ; Wed, 18 Nov 2020 13:37:03 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id g7so2397306pfc.2 for ; Wed, 18 Nov 2020 13:37:03 -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=ssBe4dTdoYPDp/kN0llgubSehUVENKnGdE0MRnY/hArF6phgxDu/5eUCx3TM10SwM4 Ys5GY25sMp5Is6DYaif9bNlWlJ8ttzdb6uOiwJTcRIgJ7YzOuDriem+amD1Cx0HpQYKX MOZ0SjJiwooT2P0xCPOTgQ6x5qmPi9UrGGqaXuZHIB0sLhaLid38QOveCk7UUky9cfqi CDQmTav9P/bzp+vtT49750yutS842WJ03PKIfoiySx93VNISwXRQftQAY7FnwUEjFAHX yh9sVrOLONeH3zd2SpHQ/YqahrB1SQV9LIQuDMFJi/3vyBV4m49wLkNPzB5Y2ZGHm6GT bHhQ== 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=FzjzcW3QqhGcGVosDG2cCdwJ1jefZ8FC+0dWf7snCxMEWzCP0kxCj3zxhqY4lJS6QK TFqMCNHhSsQ2mWGLDtZM51UqEvlNujIhuADZmklha5PPNHrx+o4gIYN25xe+u8FBwciD LPRSF+/MItQtczoeBHDmh+nCO9Axu1xu4aH+nKnH/pwt+FsirlzfzpBmTm5iz8m0JvBJ k7oQv2tgKv3u2wq/MKSNCM/Nc3BkNYkQC0IEI7iBwF0JrDbwzUQpz9vHvJwwn7AeyQbo 9ewOPNE86BHXstRwWl8K62eLqDlWnJkQP7GyQ/pUYP35zR0fvJK4FFagWOg3ThvikD6Z 0Cyw== X-Gm-Message-State: AOAM5308ixNNUozOPXUp4uvJxokPRIo5+DlYp/uQwAnUiMBWcEbV3sIL z4gH3bmDAvadZsTuJC8jWFwJvg== X-Received: by 2002:a17:90a:564d:: with SMTP id d13mr1017275pji.31.1605735423353; Wed, 18 Nov 2020 13:37:03 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id e6sm26575694pfn.190.2020.11.18.13.37.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 13:37:02 -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 v6 1/8] rpmsg: Introduce __rpmsg{16|32|64} types Date: Wed, 18 Nov 2020 14:36:53 -0700 Message-Id: <20201118213700.74106-2-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201118213700.74106-1-mathieu.poirier@linaro.org> References: <20201118213700.74106-1-mathieu.poirier@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 */ -- 2.25.1