Commit 5f2f6b7d authored by Mathieu Poirier's avatar Mathieu Poirier Committed by Bjorn Andersson

rpmsg: virtio: Move from virtio to rpmsg byte conversion

Use rpmsg byte conversion functions in order for the RPMSG
headers and generic functions to be used by external entities.
Tested-by: default avatarGuennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Signed-off-by: default avatarMathieu Poirier <mathieu.poirier@linaro.org>
Reviewed-by: default avatarArnaud Pouliquen <arnaud.pouliquen@st.com>
Reviewed-by: default avatarGuennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Link: https://lore.kernel.org/r/20201120214245.172963-3-mathieu.poirier@linaro.orgSigned-off-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
parent 6bef0380
...@@ -19,11 +19,11 @@ ...@@ -19,11 +19,11 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/of_device.h> #include <linux/of_device.h>
#include <linux/rpmsg.h> #include <linux/rpmsg.h>
#include <linux/rpmsg/byteorder.h>
#include <linux/scatterlist.h> #include <linux/scatterlist.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/virtio.h> #include <linux/virtio.h>
#include <linux/virtio_byteorder.h>
#include <linux/virtio_ids.h> #include <linux/virtio_ids.h>
#include <linux/virtio_config.h> #include <linux/virtio_config.h>
#include <linux/wait.h> #include <linux/wait.h>
...@@ -85,11 +85,11 @@ struct virtproc_info { ...@@ -85,11 +85,11 @@ struct virtproc_info {
* Every message sent(/received) on the rpmsg bus begins with this header. * Every message sent(/received) on the rpmsg bus begins with this header.
*/ */
struct rpmsg_hdr { struct rpmsg_hdr {
__virtio32 src; __rpmsg32 src;
__virtio32 dst; __rpmsg32 dst;
__virtio32 reserved; __rpmsg32 reserved;
__virtio16 len; __rpmsg16 len;
__virtio16 flags; __rpmsg16 flags;
u8 data[]; u8 data[];
} __packed; } __packed;
...@@ -107,8 +107,8 @@ struct rpmsg_hdr { ...@@ -107,8 +107,8 @@ struct rpmsg_hdr {
*/ */
struct rpmsg_ns_msg { struct rpmsg_ns_msg {
char name[RPMSG_NAME_SIZE]; char name[RPMSG_NAME_SIZE];
__virtio32 addr; __rpmsg32 addr;
__virtio32 flags; __rpmsg32 flags;
} __packed; } __packed;
/** /**
...@@ -341,8 +341,8 @@ static int virtio_rpmsg_announce_create(struct rpmsg_device *rpdev) ...@@ -341,8 +341,8 @@ static int virtio_rpmsg_announce_create(struct rpmsg_device *rpdev)
struct rpmsg_ns_msg nsm; struct rpmsg_ns_msg nsm;
strncpy(nsm.name, rpdev->id.name, RPMSG_NAME_SIZE); strncpy(nsm.name, rpdev->id.name, RPMSG_NAME_SIZE);
nsm.addr = cpu_to_virtio32(vrp->vdev, rpdev->ept->addr); nsm.addr = cpu_to_rpmsg32(rpdev, rpdev->ept->addr);
nsm.flags = cpu_to_virtio32(vrp->vdev, RPMSG_NS_CREATE); nsm.flags = cpu_to_rpmsg32(rpdev, RPMSG_NS_CREATE);
err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR); err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR);
if (err) if (err)
...@@ -365,8 +365,8 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev) ...@@ -365,8 +365,8 @@ static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev)
struct rpmsg_ns_msg nsm; struct rpmsg_ns_msg nsm;
strncpy(nsm.name, rpdev->id.name, RPMSG_NAME_SIZE); strncpy(nsm.name, rpdev->id.name, RPMSG_NAME_SIZE);
nsm.addr = cpu_to_virtio32(vrp->vdev, rpdev->ept->addr); nsm.addr = cpu_to_rpmsg32(rpdev, rpdev->ept->addr);
nsm.flags = cpu_to_virtio32(vrp->vdev, RPMSG_NS_DESTROY); nsm.flags = cpu_to_rpmsg32(rpdev, RPMSG_NS_DESTROY);
err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR); err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR);
if (err) if (err)
...@@ -425,6 +425,7 @@ static struct rpmsg_device *rpmsg_create_channel(struct virtproc_info *vrp, ...@@ -425,6 +425,7 @@ static struct rpmsg_device *rpmsg_create_channel(struct virtproc_info *vrp,
rpdev->src = chinfo->src; rpdev->src = chinfo->src;
rpdev->dst = chinfo->dst; rpdev->dst = chinfo->dst;
rpdev->ops = &virtio_rpmsg_ops; rpdev->ops = &virtio_rpmsg_ops;
rpdev->little_endian = virtio_is_little_endian(vrp->vdev);
/* /*
* rpmsg server channels has predefined local address (for now), * rpmsg server channels has predefined local address (for now),
...@@ -618,10 +619,10 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev, ...@@ -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->flags = 0;
msg->src = cpu_to_virtio32(vrp->vdev, src); msg->src = cpu_to_rpmsg32(rpdev, src);
msg->dst = cpu_to_virtio32(vrp->vdev, dst); msg->dst = cpu_to_rpmsg32(rpdev, dst);
msg->reserved = 0; msg->reserved = 0;
memcpy(msg->data, data, len); memcpy(msg->data, data, len);
...@@ -710,14 +711,15 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, ...@@ -710,14 +711,15 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
{ {
struct rpmsg_endpoint *ept; struct rpmsg_endpoint *ept;
struct scatterlist sg; 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; int err;
dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n", dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n",
virtio32_to_cpu(vrp->vdev, msg->src), __rpmsg32_to_cpu(little_endian, msg->src),
virtio32_to_cpu(vrp->vdev, msg->dst), msg_len, __rpmsg32_to_cpu(little_endian, msg->dst), msg_len,
virtio16_to_cpu(vrp->vdev, msg->flags), __rpmsg16_to_cpu(little_endian, msg->flags),
virtio32_to_cpu(vrp->vdev, msg->reserved)); __rpmsg32_to_cpu(little_endian, msg->reserved));
#if defined(CONFIG_DYNAMIC_DEBUG) #if defined(CONFIG_DYNAMIC_DEBUG)
dynamic_hex_dump("rpmsg_virtio RX: ", DUMP_PREFIX_NONE, 16, 1, dynamic_hex_dump("rpmsg_virtio RX: ", DUMP_PREFIX_NONE, 16, 1,
msg, sizeof(*msg) + msg_len, true); msg, sizeof(*msg) + msg_len, true);
...@@ -736,7 +738,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, ...@@ -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 */ /* use the dst addr to fetch the callback of the appropriate user */
mutex_lock(&vrp->endpoints_lock); 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 */ /* let's make sure no one deallocates ept while we use it */
if (ept) if (ept)
...@@ -750,7 +752,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, ...@@ -750,7 +752,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
if (ept->cb) if (ept->cb)
ept->cb(ept->rpdev, msg->data, msg_len, ept->priv, 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); mutex_unlock(&ept->cb_lock);
...@@ -830,6 +832,7 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len, ...@@ -830,6 +832,7 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
struct rpmsg_channel_info chinfo; struct rpmsg_channel_info chinfo;
struct virtproc_info *vrp = priv; struct virtproc_info *vrp = priv;
struct device *dev = &vrp->vdev->dev; struct device *dev = &vrp->vdev->dev;
bool little_endian = virtio_is_little_endian(vrp->vdev);
int ret; int ret;
#if defined(CONFIG_DYNAMIC_DEBUG) #if defined(CONFIG_DYNAMIC_DEBUG)
...@@ -858,13 +861,13 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len, ...@@ -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)); strncpy(chinfo.name, msg->name, sizeof(chinfo.name));
chinfo.src = RPMSG_ADDR_ANY; 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", 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); "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); ret = rpmsg_unregister_device(&vrp->vdev->dev, &chinfo);
if (ret) if (ret)
dev_err(dev, "rpmsg_destroy_channel failed: %d\n", ret); dev_err(dev, "rpmsg_destroy_channel failed: %d\n", ret);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment