2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-23 12:43:55 +08:00

rpmsg updates for v5.9

This ensures that rpmsg uses little-endian, per the VirtIO 1.0
 specification.
 -----BEGIN PGP SIGNATURE-----
 
 iQJPBAABCAA5FiEEBd4DzF816k8JZtUlCx85Pw2ZrcUFAl8yKzcbHGJqb3JuLmFu
 ZGVyc3NvbkBsaW5hcm8ub3JnAAoJEAsfOT8Nma3FyJYP/3jeDGupCc88bRuY0pVB
 tScUb5WbbBO9zK4Xz6TkQpPpaBj60P2M7yiBOx4OG/G0/96M9gBteQKfNZhysoVu
 +Uha6lVXbPSZoicRZaFR2ItH9AdpOV+HJ1oWesWudiMKASuZzhFfVIvtxTU4tSIj
 aWGEEJPXiXTVEeO86NE2C5o9kh1Ulsohe/S3nn8EiNu/AU5pDsfoc7heLpZqznjZ
 3rT8mwJEPaviZEL92Cu8EPZAviC8OD0wb+QZHfEAXRwbNgZEEuM6zX5fLhBv7HJ3
 iCqlmgNZunj4FR4QWlST/lrJTHCvAUzVFvlt+KKh/YixWCqR+yzrAEm4NOf/lfqC
 3hOHbPoccDSY0Fi+bX7E1DzOoJxiHsBAZwSd75IKfCmXSEoMSI6/jVSN2nkcUzVn
 DlzmwsABWobPZAcRILr+kQtB3DAIijSxP9zCmLFF0chuHUn+IwcY/EObPnFUneLB
 JFYTPE6hvHgY99TiqJARZoy9wC+zsZqh0a1zfun/BL2k7eMpzu1C5yM7yTMBJB/8
 /SEak9JACXSaYC5UGotduvB9vdghrBoy+44vcaXG/Q7EWd86/ovmTgeqnLrTxp53
 aBy2u/IgVn995tpklHeMObiimjCSK6JiNXmNpS2uUD8TSKWGUYykdaNMeDwA9kQ5
 7xeeCun9CGkCviMQIzyXw/ZX
 =ZCvJ
 -----END PGP SIGNATURE-----

Merge tag 'rpmsg-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/andersson/remoteproc

Pull rpmsg update from Bjorn Andersson:
 "This ensures that rpmsg uses little-endian, per the VirtIO 1.0
  specification"

* tag 'rpmsg-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/andersson/remoteproc:
  rpmsg: virtio: add endianness conversions
This commit is contained in:
Linus Torvalds 2020-08-11 11:13:17 -07:00
commit dded87afda

View File

@ -23,6 +23,7 @@
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/virtio.h>
#include <linux/virtio_byteorder.h>
#include <linux/virtio_ids.h>
#include <linux/virtio_config.h>
#include <linux/wait.h>
@ -84,11 +85,11 @@ struct virtproc_info {
* Every message sent(/received) on the rpmsg bus begins with this header.
*/
struct rpmsg_hdr {
u32 src;
u32 dst;
u32 reserved;
u16 len;
u16 flags;
__virtio32 src;
__virtio32 dst;
__virtio32 reserved;
__virtio16 len;
__virtio16 flags;
u8 data[];
} __packed;
@ -106,8 +107,8 @@ struct rpmsg_hdr {
*/
struct rpmsg_ns_msg {
char name[RPMSG_NAME_SIZE];
u32 addr;
u32 flags;
__virtio32 addr;
__virtio32 flags;
} __packed;
/**
@ -335,8 +336,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 = rpdev->ept->addr;
nsm.flags = RPMSG_NS_CREATE;
nsm.addr = cpu_to_virtio32(vrp->vdev, rpdev->ept->addr);
nsm.flags = cpu_to_virtio32(vrp->vdev, RPMSG_NS_CREATE);
err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR);
if (err)
@ -359,8 +360,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 = rpdev->ept->addr;
nsm.flags = RPMSG_NS_DESTROY;
nsm.addr = cpu_to_virtio32(vrp->vdev, rpdev->ept->addr);
nsm.flags = cpu_to_virtio32(vrp->vdev, RPMSG_NS_DESTROY);
err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR);
if (err)
@ -612,18 +613,18 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
}
}
msg->len = len;
msg->len = cpu_to_virtio16(vrp->vdev, len);
msg->flags = 0;
msg->src = src;
msg->dst = dst;
msg->src = cpu_to_virtio32(vrp->vdev, src);
msg->dst = cpu_to_virtio32(vrp->vdev, dst);
msg->reserved = 0;
memcpy(msg->data, data, len);
dev_dbg(dev, "TX From 0x%x, To 0x%x, Len %d, Flags %d, Reserved %d\n",
msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
src, dst, len, msg->flags, msg->reserved);
#if defined(CONFIG_DYNAMIC_DEBUG)
dynamic_hex_dump("rpmsg_virtio TX: ", DUMP_PREFIX_NONE, 16, 1,
msg, sizeof(*msg) + msg->len, true);
msg, sizeof(*msg) + len, true);
#endif
rpmsg_sg_init(&sg, msg, sizeof(*msg) + len);
@ -704,13 +705,17 @@ 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);
int err;
dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n",
msg->src, msg->dst, msg->len, msg->flags, msg->reserved);
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));
#if defined(CONFIG_DYNAMIC_DEBUG)
dynamic_hex_dump("rpmsg_virtio RX: ", DUMP_PREFIX_NONE, 16, 1,
msg, sizeof(*msg) + msg->len, true);
msg, sizeof(*msg) + msg_len, true);
#endif
/*
@ -718,15 +723,15 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
* the reported payload length.
*/
if (len > vrp->buf_size ||
msg->len > (len - sizeof(struct rpmsg_hdr))) {
dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg->len);
msg_len > (len - sizeof(struct rpmsg_hdr))) {
dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg_len);
return -EINVAL;
}
/* use the dst addr to fetch the callback of the appropriate user */
mutex_lock(&vrp->endpoints_lock);
ept = idr_find(&vrp->endpoints, msg->dst);
ept = idr_find(&vrp->endpoints, virtio32_to_cpu(vrp->vdev, msg->dst));
/* let's make sure no one deallocates ept while we use it */
if (ept)
@ -739,8 +744,8 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
mutex_lock(&ept->cb_lock);
if (ept->cb)
ept->cb(ept->rpdev, msg->data, msg->len, ept->priv,
msg->src);
ept->cb(ept->rpdev, msg->data, msg_len, ept->priv,
virtio32_to_cpu(vrp->vdev, msg->src));
mutex_unlock(&ept->cb_lock);
@ -846,15 +851,15 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len,
/* don't trust the remote processor for null terminating the name */
msg->name[RPMSG_NAME_SIZE - 1] = '\0';
dev_info(dev, "%sing channel %s addr 0x%x\n",
msg->flags & RPMSG_NS_DESTROY ? "destroy" : "creat",
msg->name, msg->addr);
strncpy(chinfo.name, msg->name, sizeof(chinfo.name));
chinfo.src = RPMSG_ADDR_ANY;
chinfo.dst = msg->addr;
chinfo.dst = virtio32_to_cpu(vrp->vdev, msg->addr);
if (msg->flags & RPMSG_NS_DESTROY) {
dev_info(dev, "%sing channel %s addr 0x%x\n",
virtio32_to_cpu(vrp->vdev, msg->flags) & RPMSG_NS_DESTROY ?
"destroy" : "creat", msg->name, chinfo.dst);
if (virtio32_to_cpu(vrp->vdev, 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);