From patchwork Tue Jan 31 12:51:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 92978 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp1910389qgi; Tue, 31 Jan 2017 04:57:40 -0800 (PST) X-Received: by 10.84.150.129 with SMTP id h1mr39741755plh.9.1485867460304; Tue, 31 Jan 2017 04:57:40 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t11si15894322plm.267.2017.01.31.04.57.39; Tue, 31 Jan 2017 04:57:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752190AbdAaM5h (ORCPT + 25 others); Tue, 31 Jan 2017 07:57:37 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:58999 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751929AbdAaM4f (ORCPT ); Tue, 31 Jan 2017 07:56:35 -0500 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id v0VCl0kt013092; Tue, 31 Jan 2017 13:55:51 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-.pphosted.com with ESMTP id 288hn1pq45-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 31 Jan 2017 13:55: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 7FA7231; Tue, 31 Jan 2017 12:55:50 +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 5C9A82AFB; Tue, 31 Jan 2017 12:55:50 +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; Tue, 31 Jan 2017 13:55:49 +0100 From: Loic Pallardy To: , , CC: , , , , , , Subject: [PATCH v2 4/6] rpmsg: virtio_rpmsg: get buffer configuration from virtio Date: Tue, 31 Jan 2017 13:51:35 +0100 Message-ID: <1485867097-6960-5-git-send-email-loic.pallardy@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1485867097-6960-1-git-send-email-loic.pallardy@st.com> References: <1485867097-6960-1-git-send-email-loic.pallardy@st.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-01-31_05:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/rpmsg/virtio_rpmsg_bus.c | 48 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) -- 1.9.1 diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index c8d0d6d..080ee07 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 */