From patchwork Wed Feb 1 15:07:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 93051 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2460458qgi; Wed, 1 Feb 2017 07:09:49 -0800 (PST) X-Received: by 10.99.129.193 with SMTP id t184mr4192838pgd.129.1485961789598; Wed, 01 Feb 2017 07:09:49 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i7si13543492plk.191.2017.02.01.07.09.49; Wed, 01 Feb 2017 07:09:49 -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 S1752300AbdBAPH0 (ORCPT + 25 others); Wed, 1 Feb 2017 10:07:26 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:4257 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752165AbdBAPHY (ORCPT ); Wed, 1 Feb 2017 10:07:24 -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 v11F2Kw9025329; Wed, 1 Feb 2017 16:07:21 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-.pphosted.com with ESMTP id 288hn1va6p-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 01 Feb 2017 16:07:21 +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 36D8538; Wed, 1 Feb 2017 15:07:20 +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 1772A2ADF; Wed, 1 Feb 2017 15:07:20 +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:19 +0100 From: Loic Pallardy To: , , CC: , , , , , , Subject: [PATCH v3 1/6] rpmsg: virtio_rpmsg: set rpmsg_buf_size customizable Date: Wed, 1 Feb 2017 16:07:07 +0100 Message-ID: <1485961632-21980-2-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rpmsg buffer size is currently fixed to 512 bytes. This patch introduces a new capability in struct virtproc_info to tune shared buffer size between host and coprocessor according to the needs. Signed-off-by: Loic Pallardy --- Changes since V1: - Initialize vrp->num_bufs before use. - Alignment with open parenthesis. No change since v2. --- drivers/rpmsg/virtio_rpmsg_bus.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) -- 1.9.1 diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 3090b0d..d387589 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -45,6 +45,7 @@ * @rbufs: kernel address of rx buffers * @sbufs: kernel address of tx buffers * @num_bufs: total number of buffers for rx and tx + * @buf_size: size of one rx or tx buffer * @last_sbuf: index of last tx buffer used * @bufs_dma: dma base addr of the buffers * @tx_lock: protects svq, sbufs and sleepers, to allow concurrent senders. @@ -65,6 +66,7 @@ struct virtproc_info { struct virtqueue *rvq, *svq; void *rbufs, *sbufs; unsigned int num_bufs; + unsigned int buf_size; int last_sbuf; dma_addr_t bufs_dma; struct mutex tx_lock; @@ -158,7 +160,7 @@ struct virtio_rpmsg_channel { * processor. */ #define MAX_RPMSG_NUM_BUFS (512) -#define RPMSG_BUF_SIZE (512) +#define MAX_RPMSG_BUF_SIZE (512) /* * Local addresses are dynamically allocated on-demand. @@ -429,7 +431,7 @@ static void *get_a_tx_buf(struct virtproc_info *vrp) * (half of our buffers are used for sending messages) */ if (vrp->last_sbuf < vrp->num_bufs / 2) - ret = vrp->sbufs + RPMSG_BUF_SIZE * vrp->last_sbuf++; + ret = vrp->sbufs + vrp->buf_size * vrp->last_sbuf++; /* or recycle a used one */ else ret = virtqueue_get_buf(vrp->svq, &len); @@ -555,7 +557,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev, * messaging), or to improve the buffer allocator, to support * variable-length buffer sizes. */ - if (len > RPMSG_BUF_SIZE - sizeof(struct rpmsg_hdr)) { + if (len > vrp->buf_size - sizeof(struct rpmsg_hdr)) { dev_err(dev, "message is too big (%d)\n", len); return -EMSGSIZE; } @@ -696,7 +698,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, * We currently use fixed-sized buffers, so trivially sanitize * the reported payload length. */ - if (len > RPMSG_BUF_SIZE || + if (len > vrp->buf_size || msg->len > (len - sizeof(struct rpmsg_hdr))) { dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg->len); return -EINVAL; @@ -729,7 +731,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, dev_warn(dev, "msg received with no recipient\n"); /* publish the real size of the buffer */ - sg_init_one(&sg, msg, RPMSG_BUF_SIZE); + sg_init_one(&sg, msg, vrp->buf_size); /* add the buffer back to the remote processor's virtqueue */ err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, msg, GFP_KERNEL); @@ -886,7 +888,9 @@ static int rpmsg_probe(struct virtio_device *vdev) else vrp->num_bufs = MAX_RPMSG_NUM_BUFS; - total_buf_space = vrp->num_bufs * RPMSG_BUF_SIZE; + vrp->buf_size = MAX_RPMSG_BUF_SIZE; + + total_buf_space = vrp->num_bufs * vrp->buf_size; /* allocate coherent memory for the buffers */ bufs_va = dma_alloc_coherent(vdev->dev.parent->parent, @@ -909,9 +913,9 @@ static int rpmsg_probe(struct virtio_device *vdev) /* set up the receive buffers */ for (i = 0; i < vrp->num_bufs / 2; i++) { struct scatterlist sg; - void *cpu_addr = vrp->rbufs + i * RPMSG_BUF_SIZE; + void *cpu_addr = vrp->rbufs + i * vrp->buf_size; - sg_init_one(&sg, cpu_addr, RPMSG_BUF_SIZE); + sg_init_one(&sg, cpu_addr, vrp->buf_size); err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, cpu_addr, GFP_KERNEL); @@ -976,7 +980,7 @@ static int rpmsg_remove_device(struct device *dev, void *data) static void rpmsg_remove(struct virtio_device *vdev) { struct virtproc_info *vrp = vdev->priv; - size_t total_buf_space = vrp->num_bufs * RPMSG_BUF_SIZE; + size_t total_buf_space = vrp->num_bufs * vrp->buf_size; int ret; vdev->config->reset(vdev); From patchwork Wed Feb 1 15:07:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 93044 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2459445qgi; Wed, 1 Feb 2017 07:07:54 -0800 (PST) X-Received: by 10.99.170.70 with SMTP id x6mr4298701pgo.14.1485961674097; Wed, 01 Feb 2017 07:07:54 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a3si19387481pln.255.2017.02.01.07.07.53; Wed, 01 Feb 2017 07:07:54 -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 S1752337AbdBAPHw (ORCPT + 25 others); Wed, 1 Feb 2017 10:07:52 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:27943 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752485AbdBAPH3 (ORCPT ); Wed, 1 Feb 2017 10:07:29 -0500 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id v11F13mT015505; Wed, 1 Feb 2017 16:07:22 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-.pphosted.com with ESMTP id 288ha952fm-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 01 Feb 2017 16:07:21 +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 464BF31; Wed, 1 Feb 2017 15:07:21 +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 2685C2ADF; Wed, 1 Feb 2017 15:07:21 +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:20 +0100 From: Loic Pallardy To: , , CC: , , , , , , , Ludovic Barre Subject: [PATCH v3 2/6] rpmsg: virtio_rpmsg_bus: fix sg_set_buf() when addr is not a valid kernel address Date: Wed, 1 Feb 2017 16:07:08 +0100 Message-ID: <1485961632-21980-3-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To specify memory for remoteproc, we declare (dma_declare_coherent_memory()) an area which is ioremap'ed to the vmalloc area. However, this address is not a kernel address so virt_addr_valid(buf) fails. Signed-off-by: Ludovic Barre Signed-off-by: Loic Pallardy Acked-by: Patrice Chotard Tested-by: Suman Anna --- Changes since V1: - Remove extra line. No change since v2. --- drivers/rpmsg/virtio_rpmsg_bus.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) -- 1.9.1 diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index d387589..c8d0d6d 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -195,6 +195,28 @@ static int virtio_rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, }; /** + * rpmsg_sg_init - initialize scatterlist according to cpu address location + * @sg: scatterlist to fill + * @cpu_addr: virtual address of the buffer + * @len: buffer length + * + * An internal function filling scatterlist according to virtual address + * location (in vmalloc or in kernel). + */ +static void +rpmsg_sg_init(struct scatterlist *sg, void *cpu_addr, unsigned int len) +{ + if (is_vmalloc_addr(cpu_addr)) { + sg_init_table(sg, 1); + sg_set_page(sg, vmalloc_to_page(cpu_addr), len, + offset_in_page(cpu_addr)); + } else { + WARN_ON(!virt_addr_valid(cpu_addr)); + sg_init_one(sg, cpu_addr, len); + } +} + +/** * __ept_release() - deallocate an rpmsg endpoint * @kref: the ept's reference count * @@ -606,7 +628,7 @@ static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev, msg, sizeof(*msg) + msg->len, true); #endif - sg_init_one(&sg, msg, sizeof(*msg) + len); + rpmsg_sg_init(&sg, msg, sizeof(*msg) + len); mutex_lock(&vrp->tx_lock); @@ -731,7 +753,7 @@ static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, dev_warn(dev, "msg received with no recipient\n"); /* publish the real size of the buffer */ - sg_init_one(&sg, msg, vrp->buf_size); + rpmsg_sg_init(&sg, msg, vrp->buf_size); /* add the buffer back to the remote processor's virtqueue */ err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, msg, GFP_KERNEL); @@ -915,7 +937,7 @@ static int rpmsg_probe(struct virtio_device *vdev) struct scatterlist sg; void *cpu_addr = vrp->rbufs + i * vrp->buf_size; - sg_init_one(&sg, cpu_addr, vrp->buf_size); + rpmsg_sg_init(&sg, cpu_addr, vrp->buf_size); err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, cpu_addr, GFP_KERNEL); From patchwork Wed Feb 1 15:07:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 93042 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2459251qgi; Wed, 1 Feb 2017 07:07:30 -0800 (PST) X-Received: by 10.84.130.99 with SMTP id 90mr5095059plc.167.1485961650294; Wed, 01 Feb 2017 07:07:30 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b189si14628150pga.105.2017.02.01.07.07.29; Wed, 01 Feb 2017 07:07:30 -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 S1752482AbdBAPH2 (ORCPT + 25 others); Wed, 1 Feb 2017 10:07:28 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:20316 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752175AbdBAPHZ (ORCPT ); Wed, 1 Feb 2017 10:07:25 -0500 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id v11F14Z6015510; Wed, 1 Feb 2017 16:07:22 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-.pphosted.com with ESMTP id 288ha952fn-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 01 Feb 2017 16:07:22 +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 3FEF638; Wed, 1 Feb 2017 15:07:22 +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 28A1B2ADF; Wed, 1 Feb 2017 15:07:22 +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:21 +0100 From: Loic Pallardy To: , , CC: , , , , , , Subject: [PATCH v3 3/6] include: virtio_rpmsg: add virtio rpmsg configuration structure Date: Wed, 1 Feb 2017 16:07:09 +0100 Message-ID: <1485961632-21980-4-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rpmsg channel configuration should be identical on host and coprocessor side. This patch proposes a new structure named struct virtio_rpmsg_cfg to gather all configuration information to characterize the communication link and. This structure will be exchanged with coprocessor via the resource table, expanding struct fw_rsc_vdev. It will guarantee that host and coprocessor will share the same information. virtio_rpmsg will access it thanks to virtio get and set features. Presence of struct virtio_rpmsg_cfg is optional. Signed-off-by: Loic Pallardy --- No change since V1 --- include/linux/rpmsg/virtio_rpmsg.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 include/linux/rpmsg/virtio_rpmsg.h -- 1.9.1 diff --git a/include/linux/rpmsg/virtio_rpmsg.h b/include/linux/rpmsg/virtio_rpmsg.h new file mode 100644 index 0000000..5f3f0d0 --- /dev/null +++ b/include/linux/rpmsg/virtio_rpmsg.h @@ -0,0 +1,32 @@ + +#ifndef _LINUX_VIRTIO_RPMSG_H +#define _LINUX_VIRTIO_RPMSG_H + +/* Offset in struct fw_rsc_vdev */ +#define RPMSG_CONFIG_OFFSET 0 + +/** + * struct virtio_rpmsg_cfg - optional configuration field for virtio rpmsg + * provided at probe time by virtio (get/set) + * @id: virtio cfg id (as in virtio_ids.h) + * @version: virtio_rpmsg_cfg structure version number + * @va: virtual address (used when buffer allocated by low level driver) + * @da: device address + * @pa: physical address + * @len: length (in bytes) + * @buf_size: size of rpmsg buffer size (defined by firmware else default value + * used) + * @reserved: reserved (must be zero) + */ +struct virtio_rpmsg_cfg { + u32 id; + u32 version; + u64 va; + u32 da; + u32 pa; + u32 len; + u32 buf_size; + u32 reserved; +} __packed; + +#endif From patchwork Wed Feb 1 15:07:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 93052 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2460474qgi; Wed, 1 Feb 2017 07:09:51 -0800 (PST) X-Received: by 10.98.214.73 with SMTP id r70mr4140141pfg.89.1485961791340; Wed, 01 Feb 2017 07:09:51 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i7si13543492plk.191.2017.02.01.07.09.49; Wed, 01 Feb 2017 07:09:51 -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 S1752596AbdBAPJO (ORCPT + 25 others); Wed, 1 Feb 2017 10:09:14 -0500 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:61295 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752227AbdBAPH0 (ORCPT ); Wed, 1 Feb 2017 10:07:26 -0500 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-00178001.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id v11F14Z7015510; Wed, 1 Feb 2017 16:07:24 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-.pphosted.com with ESMTP id 288ha952fr-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 01 Feb 2017 16:07:24 +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 3D9B031; Wed, 1 Feb 2017 15:07:23 +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 2391F2ADF; Wed, 1 Feb 2017 15:07:23 +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:22 +0100 From: Loic Pallardy To: , , CC: , , , , , , Subject: [PATCH v3 4/6] rpmsg: virtio_rpmsg: get buffer configuration from virtio Date: Wed, 1 Feb 2017 16:07:10 +0100 Message-ID: <1485961632-21980-5-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-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 No change since v2. --- 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 */ 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: 93050 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2460017qgi; Wed, 1 Feb 2017 07:08:58 -0800 (PST) X-Received: by 10.84.130.99 with SMTP id 90mr5105886plc.167.1485961738052; Wed, 01 Feb 2017 07:08:58 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x8si19394499plm.134.2017.02.01.07.08.57; Wed, 01 Feb 2017 07:08:58 -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 S1752582AbdBAPIz (ORCPT + 25 others); 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 1.9.1 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); } From patchwork Wed Feb 1 15:07:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Pallardy X-Patchwork-Id: 93043 Delivered-To: patch@linaro.org Received: by 10.140.20.99 with SMTP id 90csp2459264qgi; Wed, 1 Feb 2017 07:07:32 -0800 (PST) X-Received: by 10.84.209.172 with SMTP id y41mr5083899plh.96.1485961652013; Wed, 01 Feb 2017 07:07:32 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b189si14628150pga.105.2017.02.01.07.07.31; Wed, 01 Feb 2017 07:07:31 -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 S1752508AbdBAPHa (ORCPT + 25 others); Wed, 1 Feb 2017 10:07:30 -0500 Received: from mx07-00178001.pphosted.com ([62.209.51.94]:49099 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752471AbdBAPH2 (ORCPT ); Wed, 1 Feb 2017 10:07:28 -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 v11F2KwA025329; Wed, 1 Feb 2017 16:07:26 +0100 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-.pphosted.com with ESMTP id 288hn1va6y-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 01 Feb 2017 16:07:26 +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 2CB0731; Wed, 1 Feb 2017 15:07:25 +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 0E1BD2ADF; Wed, 1 Feb 2017 15:07:25 +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:24 +0100 From: Loic Pallardy To: , , CC: , , , , , , Subject: [PATCH v3 6/6] rpmsg: virtio_rpmsg: set buffer configuration to virtio Date: Wed, 1 Feb 2017 16:07:12 +0100 Message-ID: <1485961632-21980-7-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rpmsg is allocating buffer one dedicated communication link with some specificity like number of buffers, size of one buffer... These characteristics should be shared with remote coprocessor to guarantee communication link coherency. Proposal is to update rpmsg configuration fields in coprocessor firmware resource table if it exists. This is possible thanks to virtio set interface which allows to update cfg fields of struct fw_rsc_vdev. Signed-off-by: Loic Pallardy --- Changes since V1: - Set virtio_cfg.da to -1 (any address) by default - Add comment about IOMMU support No change since v2. --- drivers/rpmsg/virtio_rpmsg_bus.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) -- 1.9.1 diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index b347e34..d9af556 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -923,6 +923,27 @@ static int virtio_rpmsg_get_config(struct virtio_device *vdev) return ret; } +static void virtio_rpmsg_set_config(struct virtio_device *vdev) +{ + struct virtio_rpmsg_cfg virtio_cfg; + struct virtproc_info *vrp = vdev->priv; + + /* fill virtio_cfg struct */ + memset(&virtio_cfg, 0, sizeof(virtio_cfg)); + virtio_cfg.id = VIRTIO_ID_RPMSG; + /* + * IOMMU not managed at the time being, set device address to (-1) + * meaning any address value. + */ + virtio_cfg.da = -1; + virtio_cfg.pa = vrp->bufs_dma; + virtio_cfg.len = vrp->num_bufs * vrp->buf_size; + virtio_cfg.buf_size = vrp->buf_size; + + vdev->config->set(vdev, RPMSG_CONFIG_OFFSET, &virtio_cfg, + sizeof(virtio_cfg)); +} + static int rpmsg_probe(struct virtio_device *vdev) { vq_callback_t *vq_cbs[] = { rpmsg_recv_done, rpmsg_xmit_done }; @@ -933,6 +954,7 @@ static int rpmsg_probe(struct virtio_device *vdev) int err = 0, i; size_t total_buf_space = 0; bool notify; + bool has_cfg = false; vrp = kzalloc(sizeof(*vrp), GFP_KERNEL); if (!vrp) @@ -972,6 +994,9 @@ static int rpmsg_probe(struct virtio_device *vdev) if (err < 0) goto free_vrp; + if (err) + has_cfg = true; + /* Allocate buffer if none provided by low level platform driver */ if (!vrp->ext_buffer) { total_buf_space = vrp->num_bufs * vrp->buf_size; @@ -993,6 +1018,10 @@ static int rpmsg_probe(struct virtio_device *vdev) /* and half is dedicated for TX */ vrp->sbufs = bufs_va + total_buf_space / 2; + + /* Notify configuration to coprocessor */ + if (has_cfg) + virtio_rpmsg_set_config(vdev); } /* set up the receive buffers */