From patchwork Tue Mar 28 11:49:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic PALLARDY X-Patchwork-Id: 9648929 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 A5EBB601D7 for ; Tue, 28 Mar 2017 11:53:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D79327CF3 for ; Tue, 28 Mar 2017 11:53:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 91E8428236; Tue, 28 Mar 2017 11:53:26 +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 0275F27CF3 for ; Tue, 28 Mar 2017 11:53:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751494AbdC1Lw5 (ORCPT ); Tue, 28 Mar 2017 07:52:57 -0400 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:46581 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751780AbdC1LwD (ORCPT ); Tue, 28 Mar 2017 07:52:03 -0400 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 v2SBnc75015453; Tue, 28 Mar 2017 13:50:01 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-.pphosted.com with ESMTP id 29dm9kg27f-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 28 Mar 2017 13:50:01 +0200 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 5F70731; Tue, 28 Mar 2017 11:50:00 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag7node2.st.com [10.75.127.20]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 2C18B2945; Tue, 28 Mar 2017 11:50:00 +0000 (GMT) Received: from localhost (10.75.127.46) by SFHDAG7NODE2.st.com (10.75.127.20) with Microsoft SMTP Server (TLS) id 15.0.1178.4; Tue, 28 Mar 2017 13:49:59 +0200 From: Loic Pallardy To: , , CC: , , , , , Subject: [PATCH v4 4/5] rpmsg: virtio_rpmsg: get buffer configuration from virtio Date: Tue, 28 Mar 2017 13:49:46 +0200 Message-ID: <1490701787-15205-5-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490701787-15205-1-git-send-email-loic.pallardy@st.com> References: <1490701787-15205-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.46] X-ClientProxiedBy: SFHDAG3NODE3.st.com (10.75.127.9) To SFHDAG7NODE2.st.com (10.75.127.20) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-28_10:, , 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 --- Changes since V1: - Move Rpmsg buffer physical address initialization in patch 5 "rpmsg: virtio_rpmsg: don't allocate buffer if provided by low level driver" - Remove extra lines No change since v2. --- drivers/rpmsg/virtio_rpmsg_bus.c | 48 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 1c7cde9..69285c1 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 @@ -870,6 +871,44 @@ 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; + } + + /* 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 }; @@ -900,6 +939,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)); @@ -912,6 +953,11 @@ static int rpmsg_probe(struct virtio_device *vdev) 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 */ @@ -947,8 +993,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 */