From: Loic Pallardy <loic.pallardy@st.com>
To: <bjorn.andersson@linaro.org>, <ohad@wizery.com>, <lee.jones@linaro.org>
Cc: <loic.pallardy@st.com>, <linux-remoteproc@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <kernel@stlinux.com>,
<patrice.chotard@st.com>, <hugues.fruchet@st.com>,
<peter.griffin@linaro.org>
Subject: [PATCH v2 5/6] rpmsg: virtio_rpmsg: don't allocate buffer if provided by low level driver
Date: Tue, 31 Jan 2017 13:51:36 +0100 [thread overview]
Message-ID: <1485867097-6960-6-git-send-email-loic.pallardy@st.com> (raw)
In-Reply-To: <1485867097-6960-1-git-send-email-loic.pallardy@st.com>
Low level platform specific driver has the knowledge of the different
communication link constraints like fixed or secured memory region to
use for buffer allocation.
If virtual address is defined in virtio_rpmsg_cfg structure, a dedicated
memory pool buffer fitting platform requirements is available.
Rpmsg virtio layer should rely on it if its size is compliant with link
characteristics.
Signed-off-by: Loic Pallardy <loic.pallardy@st.com>
---
Changes since V1:
- Alignment with open parenthesis.
- Add vrp->bufs_dma intialization in virtio_rpmsg_get_config function
---
drivers/rpmsg/virtio_rpmsg_bus.c | 55 +++++++++++++++++++++++++++-------------
1 file changed, 37 insertions(+), 18 deletions(-)
diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index 080ee07..7c89210 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -57,6 +57,7 @@
* @sendq: wait queue of sending contexts waiting for a tx buffers
* @sleepers: number of senders that are waiting for a tx buffer
* @ns_ept: the bus's name service endpoint
+ * @ext_buffer: buffer allocated by low level driver
*
* This structure stores the rpmsg state of a given virtio remote processor
* device (there might be several virtio proc devices for each physical
@@ -76,6 +77,7 @@ struct virtproc_info {
wait_queue_head_t sendq;
atomic_t sleepers;
struct rpmsg_endpoint *ns_ept;
+ bool ext_buffer;
};
/* The feature bitmap for virtio rpmsg */
@@ -893,6 +895,7 @@ static int virtio_rpmsg_get_config(struct virtio_device *vdev)
ret = -EINVAL;
goto out;
}
+ vrp->bufs_dma = virtio_cfg.pa;
/* Check rpmsg buffer length */
total_buf_space = vrp->num_bufs * vrp->buf_size;
@@ -903,6 +906,17 @@ static int virtio_rpmsg_get_config(struct virtio_device *vdev)
ret = -ENOMEM;
goto out;
}
+
+ /* Level platform specific buffer driver ? */
+ if (virtio_cfg.va != -1) {
+ vrp->ext_buffer = true;
+ /* half of the buffers is dedicated for RX */
+ vrp->rbufs = (void *)(uintptr_t)virtio_cfg.va;
+
+ /* and half is dedicated for TX */
+ vrp->sbufs = (void *)(uintptr_t)virtio_cfg.va + total_buf_space / 2;
+ }
+
return !ret;
}
out:
@@ -958,25 +972,28 @@ static int rpmsg_probe(struct virtio_device *vdev)
if (err < 0)
goto free_vrp;
- total_buf_space = vrp->num_bufs * vrp->buf_size;
+ /* Allocate buffer if none provided by low level platform driver */
+ if (!vrp->ext_buffer) {
+ total_buf_space = vrp->num_bufs * vrp->buf_size;
/* allocate coherent memory for the buffers */
- bufs_va = dma_alloc_coherent(vdev->dev.parent->parent,
- total_buf_space, &vrp->bufs_dma,
- GFP_KERNEL);
- if (!bufs_va) {
- err = -ENOMEM;
- goto vqs_del;
- }
+ bufs_va = dma_alloc_coherent(vdev->dev.parent->parent,
+ total_buf_space, &vrp->bufs_dma,
+ GFP_KERNEL);
+ if (!bufs_va) {
+ err = -ENOMEM;
+ goto vqs_del;
+ }
- dev_dbg(&vdev->dev, "buffers: va %p, dma %pad\n",
- bufs_va, &vrp->bufs_dma);
+ dev_dbg(&vdev->dev, "buffers: va %p, dma %pad\n",
+ bufs_va, &vrp->bufs_dma);
- /* half of the buffers is dedicated for RX */
- vrp->rbufs = bufs_va;
+ /* half of the buffers is dedicated for RX */
+ vrp->rbufs = bufs_va;
- /* and half is dedicated for TX */
- vrp->sbufs = bufs_va + total_buf_space / 2;
+ /* and half is dedicated for TX */
+ vrp->sbufs = bufs_va + total_buf_space / 2;
+ }
/* set up the receive buffers */
for (i = 0; i < vrp->num_bufs / 2; i++) {
@@ -1027,8 +1044,9 @@ static int rpmsg_probe(struct virtio_device *vdev)
return 0;
free_coherent:
- dma_free_coherent(vdev->dev.parent->parent, total_buf_space,
- bufs_va, vrp->bufs_dma);
+ if (!vrp->ext_buffer)
+ dma_free_coherent(vdev->dev.parent->parent, total_buf_space,
+ bufs_va, vrp->bufs_dma);
vqs_del:
vdev->config->del_vqs(vrp->vdev);
free_vrp:
@@ -1062,8 +1080,9 @@ static void rpmsg_remove(struct virtio_device *vdev)
vdev->config->del_vqs(vrp->vdev);
- dma_free_coherent(vdev->dev.parent->parent, total_buf_space,
- vrp->rbufs, vrp->bufs_dma);
+ if (!vrp->ext_buffer)
+ dma_free_coherent(vdev->dev.parent->parent, total_buf_space,
+ vrp->rbufs, vrp->bufs_dma);
kfree(vrp);
}
--
1.9.1
next prev parent reply other threads:[~2017-01-31 12:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-31 12:51 [PATCH v2 0/6] virtio_rpmsg: make rpmsg channel configurable Loic Pallardy
2017-01-31 12:51 ` [PATCH v2 1/6] rpmsg: virtio_rpmsg: set rpmsg_buf_size customizable Loic Pallardy
2017-01-31 12:51 ` [PATCH v2 2/6] rpmsg: virtio_rpmsg_bus: fix sg_set_buf() when addr is not a valid kernel address Loic Pallardy
2017-01-31 12:51 ` [PATCH v2 3/6] include: virtio_rpmsg: add virtio rpmsg configuration structure Loic Pallardy
2017-01-31 12:51 ` [PATCH v2 4/6] rpmsg: virtio_rpmsg: get buffer configuration from virtio Loic Pallardy
2017-01-31 12:51 ` Loic Pallardy [this message]
2017-01-31 18:29 ` [PATCH v2 5/6] rpmsg: virtio_rpmsg: don't allocate buffer if provided by low level driver kbuild test robot
2017-01-31 12:51 ` [PATCH v2 6/6] rpmsg: virtio_rpmsg: set buffer configuration to virtio Loic Pallardy
2017-02-08 10:21 ` [PATCH v2 0/6] virtio_rpmsg: make rpmsg channel configurable Hugues FRUCHET
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1485867097-6960-6-git-send-email-loic.pallardy@st.com \
--to=loic.pallardy@st.com \
--cc=bjorn.andersson@linaro.org \
--cc=hugues.fruchet@st.com \
--cc=kernel@stlinux.com \
--cc=lee.jones@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=ohad@wizery.com \
--cc=patrice.chotard@st.com \
--cc=peter.griffin@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®