Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp847767pxb; Thu, 5 Nov 2020 14:52:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4Hl3oGu860S6Wz9Gze81NC7ZAPJNrzZtp2CZ0s6ZQRPz8o+qSd4fc1yVPgZBEOqfFF+6E X-Received: by 2002:a17:906:128d:: with SMTP id k13mr4576551ejb.78.1604616750701; Thu, 05 Nov 2020 14:52:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604616750; cv=none; d=google.com; s=arc-20160816; b=rr5w5p6w4LFwYv1qiwmo1Sn+rT+ztifds3yVp1OLknwie0zcI96kmXrCxfnMo14KeW AwLIhNXHIs3BtkoEjhdohkn2c0uFBU3NbzCogfFh40x5rxhplpP3dRpBojWxa8e+mvwv nuf8O8mhrEavyTrLvQgfL+keK2oBudCC/5xSdg2/3dWbWNXi7l+rnGJB8okwIDUQ3qss acpI9Ma1mFuUDvG7Efsj12gh5OPOjugM17GftSPSapMfjEPuzZBrnpQpiusRWV6UmQR0 5VhlTTIkP8vub1FR2AoRrixJjEb6ZgTlc06bC5oVkMGXyQFPAY2wMaHPOyqzjGdu/qq9 eccw== 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=ntxn3CuS74pm0wczt7oEbIfUnPIYAZjfh4BbHbjzfzyRGCe4Pd0Z0iL4hWWG3WVuwW 7uo4Y4Iy6YQPLClEL9Xx2Lc9jahxYsA/LZ2D4/OCPPSl7keE9PLhwbr60pgIuqeEayIw fLz7EBwNTA2ttuxnrc1k/ats4L9UT4FayX4EY8FrTIpFJDtO5J01Z2fQCtt3Wi+CH6RJ sJz0wjQZqqxzN6lAyiUSLRJ1pLHrOVK78j+xlru4pFtp/9u8aXWsQelru6TonhYPt9ah JkqRhcxxWRiV+issDjdFms4p5GF2rE9YtqqY5fX/w/o9tiX+s/jwu4RniT6i1sc9mP8+ jx9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b4llI9RH; 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 z17si2120722eja.372.2020.11.05.14.52.08; Thu, 05 Nov 2020 14:52:30 -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=b4llI9RH; 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 S1732444AbgKEWuf (ORCPT + 99 others); Thu, 5 Nov 2020 17:50:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732369AbgKEWuc (ORCPT ); Thu, 5 Nov 2020 17:50:32 -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 8EAFCC0613D2 for ; Thu, 5 Nov 2020 14:50:32 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id 13so2528530pfy.4 for ; Thu, 05 Nov 2020 14:50:32 -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=b4llI9RHG/2Humq5N5H7SvY6Y2SEyH1wZ6+1Ddn9Hzz0nuUfXNbKpxhXXSZKBGFP6R EepxDrwGVKHAXq72JIT1fvhOFP7Qc1Zn4unihk+UKFvz2Nrdno+VNlKmAfaIHU/LGpgS kbndnL937GoKuS065o5UMZUbBmXDa1hY4ejjAH1OQjZl/2qhbMLrl0nF0RHl140f39vn Q/Av8Q8iUGLtO/tjmGh/4cvhsDM+UfvQ+DyebkhHg03YJ4P+vF2Qnl3KiGyuM96+/Byj 9R5flc8UEsjJ8LN3t2JTfKd9dcY6FQBDqEk7pJVmXIph4ooblBvBZRNRnSk/ocUaitFH qd5g== 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=IwZr60mrX3I7VslPNn5UPhDCMiApEFX7v//LFA9XCNRNY4lk7pyBlGXnU4GURkGC1p rKG2iiK5ElhiuTHbMLtqEfmocaHaBEFJWHICzzOyv0nHWDl5zCjobwYGpWEnT5ZyQ+st fgFti0MSHOxEYSsI57feRx1EDx43Kymq7+rlAjpCrBTka57aCNK2AwSr9r5PYwE+RpCq y3awh7a4rOZ7R7jcmE0edhBbEY6a3P4hFvW0x4kDHeMUYDX/cHhd6knTE/t0T792jnOS p6mTXsgDIiS91jkIKA1R7ktBiFFLSsD16dDLqyQHyUni7+Q28B+dTuogbBM8RQXK5gFy uIHw== X-Gm-Message-State: AOAM5327fTQsZ6BkesNn9VhOZPqsgFQLOPyRNoLVUTf8zHwUv8543rW8 GKL16OQJKsFUeqmfcics4MW6oQ== X-Received: by 2002:a17:90b:118b:: with SMTP id gk11mr4771452pjb.178.1604616632151; Thu, 05 Nov 2020 14:50:32 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id d145sm3854501pfd.136.2020.11.05.14.50.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2020 14:50:31 -0800 (PST) From: Mathieu Poirier To: ohad@wizery.com, bjorn.andersson@linaro.org Cc: guennadi.liakhovetski@linux.intel.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 2/8] rpmsg: virtio: Move from virtio to rpmsg byte conversion Date: Thu, 5 Nov 2020 15:50:22 -0700 Message-Id: <20201105225028.3058818-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201105225028.3058818-1-mathieu.poirier@linaro.org> References: <20201105225028.3058818-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