From patchwork Wed Feb 1 15:07:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic PALLARDY X-Patchwork-Id: 9549917 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 971A260415 for ; Wed, 1 Feb 2017 15:09:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87FB128435 for ; Wed, 1 Feb 2017 15:09:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CDB228443; Wed, 1 Feb 2017 15:09:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E399528435 for ; Wed, 1 Feb 2017 15:09:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752305AbdBAPIz (ORCPT ); Wed, 1 Feb 2017 10:08:55 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:46829 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752165AbdBAPH1 (ORCPT ); Wed, 1 Feb 2017 10:07:27 -0500 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by m0046037.ppops.net (8.16.0.11/8.16.0.11) with SMTP id v11F4AAt005096; Wed, 1 Feb 2017 16:07:25 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-.pphosted.com with ESMTP id 288hxwc8an-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 01 Feb 2017 16:07:25 +0100 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 451CF34; Wed, 1 Feb 2017 15:07:24 +0000 (GMT) Received: from Webmail-eu.st.com (safex1hubcas4.st.com [10.75.90.69]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 22DA32ADF; Wed, 1 Feb 2017 15:07:24 +0000 (GMT) Received: from localhost (10.201.23.23) by webmail-eu.st.com (10.75.90.13) with Microsoft SMTP Server (TLS) id 8.3.444.0; Wed, 1 Feb 2017 16:07:23 +0100 From: Loic Pallardy To: , , CC: , , , , , , Subject: [PATCH v3 5/6] rpmsg: virtio_rpmsg: don't allocate buffer if provided by low level driver Date: Wed, 1 Feb 2017 16:07:11 +0100 Message-ID: <1485961632-21980-6-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1485961632-21980-1-git-send-email-loic.pallardy@st.com> References: <1485961632-21980-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-01_08:, , signatures=0 Sender: linux-remoteproc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- Changes since V1: - Alignment with open parenthesis. - Add vrp->bufs_dma intialization in virtio_rpmsg_get_config function Changes since V2: - Fix warnings reported by kbuild test robot --- drivers/rpmsg/virtio_rpmsg_bus.c | 59 ++++++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 080ee07..b347e34 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: @@ -915,9 +929,9 @@ static int rpmsg_probe(struct virtio_device *vdev) static const char * const names[] = { "input", "output" }; struct virtqueue *vqs[2]; struct virtproc_info *vrp; - void *bufs_va; + void *bufs_va = NULL; int err = 0, i; - size_t total_buf_space; + size_t total_buf_space = 0; bool notify; vrp = kzalloc(sizeof(*vrp), GFP_KERNEL); @@ -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); }