From patchwork Wed Dec 7 20:35:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic PALLARDY X-Patchwork-Id: 9465209 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 5F9C360512 for ; Wed, 7 Dec 2016 20:36:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61F0E28427 for ; Wed, 7 Dec 2016 20:36:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 570722855E; Wed, 7 Dec 2016 20:36:54 +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=ham 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 EC4ED28427 for ; Wed, 7 Dec 2016 20:36:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932674AbcLGUgx (ORCPT ); Wed, 7 Dec 2016 15:36:53 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:52313 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932561AbcLGUgx (ORCPT ); Wed, 7 Dec 2016 15:36:53 -0500 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id uB7KYZ6H026369; Wed, 7 Dec 2016 21:36:51 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-.pphosted.com with ESMTP id 2756tnbubj-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 07 Dec 2016 21:36:51 +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 7ED9A31; Wed, 7 Dec 2016 20:36:50 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas21.st.com [10.75.90.44]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 66AB34EB5; Wed, 7 Dec 2016 20:36:50 +0000 (GMT) Received: from localhost (10.129.5.76) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.294.0; Wed, 7 Dec 2016 21:36:49 +0100 From: Loic Pallardy To: , , , CC: , , Subject: [PATCH v1 4/6] rpmsg: virtio_rpmsg: get buffer configuration from virtio Date: Wed, 7 Dec 2016 21:35:39 +0100 Message-ID: <1481142941-15616-5-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1481142941-15616-1-git-send-email-loic.pallardy@st.com> References: <1481142941-15616-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.129.5.76] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-12-07_06:, , 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 Some coprocessors have memory mapping constraints which require predefined buffer location or specific buffer size different from default definition. Coprocessor resources are defined in associated firmware resource table. Remoteproc offers access to firmware resource table via virtio get interface. This patch modifies rpmsg_probe sequence to: - retrieve rpmsg buffer configuration (if any) - verify and apply configuration - allocate buffer according to requested configuration Signed-off-by: Loic Pallardy --- drivers/rpmsg/virtio_rpmsg_bus.c | 52 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 0810d1f..1a97af8 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -871,6 +872,45 @@ static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len, return 0; } +static int virtio_rpmsg_get_config(struct virtio_device *vdev) +{ + struct virtio_rpmsg_cfg virtio_cfg; + struct virtproc_info *vrp = vdev->priv; + size_t total_buf_space; + int ret = 0; + + memset(&virtio_cfg, 0, sizeof(virtio_cfg)); + vdev->config->get(vdev, RPMSG_CONFIG_OFFSET, &virtio_cfg, + sizeof(virtio_cfg)); + + if (virtio_cfg.id == VIRTIO_ID_RPMSG && virtio_cfg.version == 1 && + virtio_cfg.reserved == 0) { + if (virtio_cfg.buf_size <= MAX_RPMSG_BUF_SIZE) { + vrp->buf_size = virtio_cfg.buf_size; + } else { + WARN_ON(1); + dev_warn(&vdev->dev, "Requested RPMsg buffer size too big: %d\n", + vrp->buf_size); + ret = -EINVAL; + goto out; + } + vrp->bufs_dma = virtio_cfg.pa; + + /* Check rpmsg buffer length */ + total_buf_space = vrp->num_bufs * vrp->buf_size; + if ((virtio_cfg.len != -1) && (total_buf_space > virtio_cfg.len)) { + dev_warn(&vdev->dev, "Not enough memory for buffers: %d\n", + total_buf_space); + ret = -ENOMEM; + goto out; + } + return !ret; + } +out: + return ret; + +} + static int rpmsg_probe(struct virtio_device *vdev) { vq_callback_t *vq_cbs[] = { rpmsg_recv_done, rpmsg_xmit_done }; @@ -901,6 +941,8 @@ static int rpmsg_probe(struct virtio_device *vdev) vrp->rvq = vqs[0]; vrp->svq = vqs[1]; + vdev->priv = vrp; + /* we expect symmetric tx/rx vrings */ WARN_ON(virtqueue_get_vring_size(vrp->rvq) != virtqueue_get_vring_size(vrp->svq)); @@ -911,9 +953,15 @@ static int rpmsg_probe(struct virtio_device *vdev) else vrp->num_bufs = MAX_RPMSG_NUM_BUFS; + vrp->buf_size = MAX_RPMSG_BUF_SIZE; + + /* Try to get rpmsg configuration if any */ + err = virtio_rpmsg_get_config(vdev); + if (err < 0) + goto free_vrp; + 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); @@ -946,8 +994,6 @@ static int rpmsg_probe(struct virtio_device *vdev) /* suppress "tx-complete" interrupts */ virtqueue_disable_cb(vrp->svq); - vdev->priv = vrp; - /* if supported by the remote processor, enable the name service */ if (virtio_has_feature(vdev, VIRTIO_RPMSG_F_NS)) { /* a dedicated endpoint handles the name service msgs */