Commit 9dd87c2a authored by Loic Pallardy's avatar Loic Pallardy Committed by Bjorn Andersson

rpmsg: virtio_rpmsg_bus: fix sg_set_buf() when addr is not a valid kernel address

To specify memory for remoteproc, we declare (dma_declare_coherent_memory())
an area which is ioremap'ed to the vmalloc area.  However, this address is
not a kernel address so virt_addr_valid(buf) fails.
Signed-off-by: default avatarLudovic Barre <ludovic.barre@st.com>
Signed-off-by: default avatarLoic Pallardy <loic.pallardy@st.com>
Acked-by: default avatarPatrice Chotard <patrice.chotard@st.com>
Tested-by: default avatarSuman Anna <s-anna@ti.com>
Signed-off-by: default avatarBjorn Andersson <bjorn.andersson@linaro.org>
parent f93848f9
...@@ -194,6 +194,28 @@ static const struct rpmsg_endpoint_ops virtio_endpoint_ops = { ...@@ -194,6 +194,28 @@ static const struct rpmsg_endpoint_ops virtio_endpoint_ops = {
.trysend_offchannel = virtio_rpmsg_trysend_offchannel, .trysend_offchannel = virtio_rpmsg_trysend_offchannel,
}; };
/**
* rpmsg_sg_init - initialize scatterlist according to cpu address location
* @sg: scatterlist to fill
* @cpu_addr: virtual address of the buffer
* @len: buffer length
*
* An internal function filling scatterlist according to virtual address
* location (in vmalloc or in kernel).
*/
static void
rpmsg_sg_init(struct scatterlist *sg, void *cpu_addr, unsigned int len)
{
if (is_vmalloc_addr(cpu_addr)) {
sg_init_table(sg, 1);
sg_set_page(sg, vmalloc_to_page(cpu_addr), len,
offset_in_page(cpu_addr));
} else {
WARN_ON(!virt_addr_valid(cpu_addr));
sg_init_one(sg, cpu_addr, len);
}
}
/** /**
* __ept_release() - deallocate an rpmsg endpoint * __ept_release() - deallocate an rpmsg endpoint
* @kref: the ept's reference count * @kref: the ept's reference count
...@@ -612,7 +634,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev, ...@@ -612,7 +634,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
msg, sizeof(*msg) + msg->len, true); msg, sizeof(*msg) + msg->len, true);
#endif #endif
sg_init_one(&sg, msg, sizeof(*msg) + len); rpmsg_sg_init(&sg, msg, sizeof(*msg) + len);
mutex_lock(&vrp->tx_lock); mutex_lock(&vrp->tx_lock);
...@@ -736,7 +758,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, ...@@ -736,7 +758,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
dev_warn(dev, "msg received with no recipient\n"); dev_warn(dev, "msg received with no recipient\n");
/* publish the real size of the buffer */ /* publish the real size of the buffer */
sg_init_one(&sg, msg, vrp->buf_size); rpmsg_sg_init(&sg, msg, vrp->buf_size);
/* add the buffer back to the remote processor's virtqueue */ /* add the buffer back to the remote processor's virtqueue */
err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, msg, GFP_KERNEL); err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, msg, GFP_KERNEL);
...@@ -920,7 +942,7 @@ static int rpmsg_probe(struct virtio_device *vdev) ...@@ -920,7 +942,7 @@ static int rpmsg_probe(struct virtio_device *vdev)
struct scatterlist sg; struct scatterlist sg;
void *cpu_addr = vrp->rbufs + i * vrp->buf_size; void *cpu_addr = vrp->rbufs + i * vrp->buf_size;
sg_init_one(&sg, cpu_addr, vrp->buf_size); rpmsg_sg_init(&sg, cpu_addr, vrp->buf_size);
err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, cpu_addr, err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, cpu_addr,
GFP_KERNEL); GFP_KERNEL);
......
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