Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp655917pxb; Wed, 18 Nov 2020 13:41:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRPVlwFWa9K9FuSKN4m1Kk3JPYf96vnwApshb9nea+51EROihJA7QaY1ItXL2XXGM8DQ7m X-Received: by 2002:a50:a6d0:: with SMTP id f16mr26966244edc.135.1605735662100; Wed, 18 Nov 2020 13:41:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605735662; cv=none; d=google.com; s=arc-20160816; b=ZsgVL4W4tPcOZHHsO/GvmU98JLVdOGtPozLsR0VI0Rbwo2soPDuTzATqwfhKiJvNQC L5bWjA+Udp5bEjI+Cg5xl9EE7iylW3Pj4Whl7dcYymFcjnrTot4kIcnSWTgXXC6xiupn 3UZv74oLXcRyvQPz8ArIx9IpSWdoPqgqHtHIy4OKqt+/ODvtYUsLPaVB8oqoBgwMRyiz Ax3ic8++Aqm8jAR3DOpM0ANPxzZG+hWJJdHprYbtdqmLzNwGbXa4HqvtQS1AOnKaGd4n rhzMz9aAdNltuZu/5k5vGCcsiNlTRcPFE2cI0thaIw86AEC8BjbL1o8QUeHSyUcl/XsR ESRw== 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=FveG7gwXoxnfUqfAm1M6z1jk2IKd8VxnJz1cUoAZjBk=; b=nrAmBWfv6IjGU2j6cG3kkSn9Rfe9GAN2Bdkrb3NztV4Rl3q9Ow7bNPJUbFq89RDVDP gBHAavfmbhgs+I99+CHZXm0+Mf8zAvw9w7X5bgnb5OF9o+19BXKPkuRS+qpkTHaK1fSo /FeADy3jENXSNFnZ91IcTvS9aKNfKt9emC8kKakytkCxfJdASq4AmahprvqaU7sdHHHt FmUvgMuOimMpY51kNaJM+TUY94TFKSCOVPUbiBhZeD5c01xpbOAaGpUc6KvE/DO5HwXt CRhn5Ano5xBirMLN0X/kdFcp8oMujDoiSAtr2zw4QsuQXgqO9xEMSfMrbMmzXPcysZWZ mA6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vmAj+dxg; 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 r22si10084715edq.46.2020.11.18.13.40.35; Wed, 18 Nov 2020 13:41:02 -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=vmAj+dxg; 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 S1727164AbgKRVhH (ORCPT + 99 others); Wed, 18 Nov 2020 16:37:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727131AbgKRVhF (ORCPT ); Wed, 18 Nov 2020 16:37:05 -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 E2CB2C0613D6 for ; Wed, 18 Nov 2020 13:37:04 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id 81so2219700pgf.0 for ; Wed, 18 Nov 2020 13:37:04 -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=vmAj+dxgLtPefqa6k3LzHLJ4WQV50D9CIMqRnQgzpAeuIoqum7B9HJcdwQPNb/i0+L L/uDU9kiNtjejNOZpRNidi2/Hg+7EdgAiaGVFSWaMIpHgm22EsIFd2yKZGic2+QCVEAy /2RaAo+ioaYP/MKmCcgpdql6neWDtNXEHpY3OgS9fPanhobsDbdPgixG1xfCQMB/fmOY Q9IcRxK1B/aGRPe5GTgCfLR+18c8PAQr26Xe+KxVedu29akJs0K/4cFs4FtoebHWdbdf zlV1P7tgZS9HGg0yR8/2wLQfTNojP3UiQKSdf1rohRTCiRggyC+Au9Ep3SivaP6uQ+JC fBDQ== 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=EhK74YN7rKTZeXTLm5Pmaagd5MTcj2+oFuJK0LRnccDnKLm6zj4s8YIJD9mZJEUdPt 5Isym2I9GvZb/XGh3UiPZgFTJ8HQkZ33VUd1qPTo+Gnmpqw3tDA043lllm0RlC9ms75t 75X9rCmBan3hSinkMIwB2p1DUJ3IIa7YyM/c5pFOquajUUQjBrpsfli1+CVkj0UJ0scv at7u9pm9qOBbYD1I2XTVXCmaCXiskZcjZyG2cmmtFsGVbJUpmWrIn7+P+2MymnSM5h/3 YWo5bP/NquqTrKZuBRHoS4pCO+2671ZjuTVsybrkX+p0U5YhDG/mFU9a8QAC6831d/6Z gs/Q== X-Gm-Message-State: AOAM533vhw2sFMPcpPzAW7rQFwhSGOC4gLMCvlYi16pdHK9fZDPDjUMh mJFumNR/QxFJ1fY5dUOKt/sIUQ== X-Received: by 2002:a63:e24:: with SMTP id d36mr9878602pgl.373.1605735424421; Wed, 18 Nov 2020 13:37:04 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Nov 2020 13:37:03 -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 2/8] rpmsg: virtio: Move from virtio to rpmsg byte conversion Date: Wed, 18 Nov 2020 14:36:54 -0700 Message-Id: <20201118213700.74106-3-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 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); -- 2.25.1