@@ -196,16 +196,16 @@ static int virtio_rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src,
* location (in vmalloc or in kernel).
*/
static void
-rpmsg_sg_init(struct scatterlist *sg, void *cpu_addr, unsigned int len)
+rpmsg_sg_init(struct virtproc_info *vrp, 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);
- }
+ unsigned int offset;
+ dma_addr_t dev_add = vrp->bufs_dma + (cpu_addr - vrp->rbufs);
+ struct page *page = phys_to_page(dma_to_phys(vrp->bufs_dev, dev_add));
+
+ offset = offset_in_page(cpu_addr);
+ sg_init_table(sg, 1);
+ sg_set_page(sg, page, len, offset);
}
/**
@@ -626,7 +626,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev,
msg, sizeof(*msg) + msg->len, true);
#endif
- rpmsg_sg_init(&sg, msg, sizeof(*msg) + len);
+ rpmsg_sg_init(vrp, &sg, msg, sizeof(*msg) + len);
mutex_lock(&vrp->tx_lock);
@@ -750,7 +750,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev,
dev_warn(dev, "msg received with no recipient\n");
/* publish the real size of the buffer */
- rpmsg_sg_init(&sg, msg, vrp->buf_size);
+ rpmsg_sg_init(vrp, &sg, msg, vrp->buf_size);
/* add the buffer back to the remote processor's virtqueue */
err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, msg, GFP_KERNEL);
@@ -934,7 +934,7 @@ static int rpmsg_probe(struct virtio_device *vdev)
struct scatterlist sg;
void *cpu_addr = vrp->rbufs + i * vrp->buf_size;
- rpmsg_sg_init(&sg, cpu_addr, vrp->buf_size);
+ rpmsg_sg_init(vrp, &sg, cpu_addr, vrp->buf_size);
err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, cpu_addr,
GFP_KERNEL);