From patchwork Thu Jan 31 15:41:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang Xiao X-Patchwork-Id: 10790829 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 069A914E1 for ; Thu, 31 Jan 2019 15:42:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF98B31439 for ; Thu, 31 Jan 2019 15:42:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4EC131468; Thu, 31 Jan 2019 15:42:18 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,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 B1F1E3145F for ; Thu, 31 Jan 2019 15:42:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733306AbfAaPl5 (ORCPT ); Thu, 31 Jan 2019 10:41:57 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:45754 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733294AbfAaPl5 (ORCPT ); Thu, 31 Jan 2019 10:41:57 -0500 Received: by mail-pf1-f193.google.com with SMTP id g62so1618350pfd.12; Thu, 31 Jan 2019 07:41:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LPEnAs1s1euCAFGxf6zSo7VBhGEAMz6C30FuyvD2OCk=; b=IPeKV09kexzXO5G17YF+vT/FyQHcVvceIdPUHvIiVtBO7tHmOyClX3jJ6C07kfyyvP KE2s/7xylEh6pCjTjTRPXZWw/0n3TkayYO90KE9lgN6dXqVZ2nmyEZMPtYYr5NOu/sS6 mOmsa55U9ktJT9SLioGX8B4VzvGwT8VAbJ3LTkoFvCoDASAq3SJBMx+loLwu2lzJi5jE +YZecA+5Y47ba2+DOMfTuA92qWPZOgA0TBGFoVkYh6Zw783GvCV3dSw9zRBbFwB8QrNR 0Nr9TeTp869idkNFxUEwkzymcoTXraUvd5cNrXirSWK9eOy396ERiAt4KbFl9Wv/9/Ha ZMbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LPEnAs1s1euCAFGxf6zSo7VBhGEAMz6C30FuyvD2OCk=; b=Wr/rAD/QWD2VgdAQCmzmT7chZWVrU3AHQQeN1yxUvpcavZJX4CKDh1sLEVhS54slRn gaPv/F4qinKPFSXSlg1PfVzEZ0tnADTnM64vHJmZCnn3RUO8RqhLqmx/loAVDJxAE+3k YWZY4jENc7+ks7Jofcex011zuMC6ixAoYR8TwhCWcAsoD9TbkFIKv7/3AQuZek3WVang WgclAcN3b7SOQ065JzE2Cm/bA9MP3MRpE6DH5zeq1CKXKzif8ioXlBTXY4CpeqOjauvT B+PaC0hIDBBwuFT04bQ18CsvVRMUNrr2mdDM5gmj5/QsEzPHplNK4AzhKybCrJUh3mGm KMhA== X-Gm-Message-State: AJcUukf0u16pUcB5HtdVisCtNzuFBGTBfmo1zLnWygFuaeYiPlRsaCGm 9CPwWcZUOchHbRzXqX1GH1kJqijK5mI= X-Google-Smtp-Source: ALg8bN5HqGGemWW7RH8/B136FlEi1+H2nGm5alHHEpVbne3VbDBq7QUm0G8bM3SpGWIA1GJKb02SKw== X-Received: by 2002:a62:8e19:: with SMTP id k25mr35280609pfe.185.1548949315498; Thu, 31 Jan 2019 07:41:55 -0800 (PST) Received: from localhost.localdomain ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id b2sm6622435pgg.87.2019.01.31.07.41.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 31 Jan 2019 07:41:54 -0800 (PST) From: Xiang Xiao X-Google-Original-From: Xiang Xiao To: ohad@wizery.com, bjorn.andersson@linaro.org, wendy.liang@xilinx.com, arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Xiang Xiao Subject: [PATCH 1/3] rpmsg: virtio_rpmsg_bus: allow the different vring size for send/recv Date: Thu, 31 Jan 2019 23:41:18 +0800 Message-Id: <1548949280-31794-2-git-send-email-xiaoxiang@xiaomi.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548949280-31794-1-git-send-email-xiaoxiang@xiaomi.com> References: <1548949280-31794-1-git-send-email-xiaoxiang@xiaomi.com> 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 it's useful if the communication throughput is different from each side Signed-off-by: Xiang Xiao Acked-by:Arnaud POULIQUEN --- drivers/rpmsg/virtio_rpmsg_bus.c | 47 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 664f957..fb0d2eb 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -36,8 +36,9 @@ * @svq: tx virtqueue * @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 + * @num_rbufs: total number of buffers for rx + * @num_sbufs: total number of buffers for 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. @@ -57,7 +58,8 @@ struct virtproc_info { struct virtio_device *vdev; struct virtqueue *rvq, *svq; void *rbufs, *sbufs; - unsigned int num_bufs; + unsigned int num_rbufs; + unsigned int num_sbufs; unsigned int buf_size; int last_sbuf; dma_addr_t bufs_dma; @@ -136,7 +138,7 @@ struct virtio_rpmsg_channel { /* * We're allocating buffers of 512 bytes each for communications. The * number of buffers will be computed from the number of buffers supported - * by the vring, upto a maximum of 512 buffers (256 in each direction). + * by the vring, up to a maximum of 256 in each direction. * * Each buffer will have 16 bytes for the msg header and 496 bytes for * the payload. @@ -151,7 +153,7 @@ struct virtio_rpmsg_channel { * can change this without changing anything in the firmware of the remote * processor. */ -#define MAX_RPMSG_NUM_BUFS (512) +#define MAX_RPMSG_NUM_BUFS (256) #define MAX_RPMSG_BUF_SIZE (512) /* @@ -446,11 +448,8 @@ static void *get_a_tx_buf(struct virtproc_info *vrp) /* support multiple concurrent senders */ mutex_lock(&vrp->tx_lock); - /* - * either pick the next unused tx buffer - * (half of our buffers are used for sending messages) - */ - if (vrp->last_sbuf < vrp->num_bufs / 2) + /* either pick the next unused tx buffer */ + if (vrp->last_sbuf < vrp->num_sbufs) ret = vrp->sbufs + vrp->buf_size * vrp->last_sbuf++; /* or recycle a used one */ else @@ -897,19 +896,20 @@ static int rpmsg_probe(struct virtio_device *vdev) vrp->rvq = vqs[0]; vrp->svq = vqs[1]; - /* we expect symmetric tx/rx vrings */ - WARN_ON(virtqueue_get_vring_size(vrp->rvq) != - virtqueue_get_vring_size(vrp->svq)); - /* we need less buffers if vrings are small */ - if (virtqueue_get_vring_size(vrp->rvq) < MAX_RPMSG_NUM_BUFS / 2) - vrp->num_bufs = virtqueue_get_vring_size(vrp->rvq) * 2; + if (virtqueue_get_vring_size(vrp->rvq) < MAX_RPMSG_NUM_BUFS) + vrp->num_rbufs = virtqueue_get_vring_size(vrp->rvq); + else + vrp->num_rbufs = MAX_RPMSG_NUM_BUFS; + + if (virtqueue_get_vring_size(vrp->svq) < MAX_RPMSG_NUM_BUFS) + vrp->num_sbufs = virtqueue_get_vring_size(vrp->svq); else - vrp->num_bufs = MAX_RPMSG_NUM_BUFS; + vrp->num_sbufs = MAX_RPMSG_NUM_BUFS; vrp->buf_size = MAX_RPMSG_BUF_SIZE; - total_buf_space = vrp->num_bufs * vrp->buf_size; + total_buf_space = (vrp->num_rbufs + vrp->num_sbufs) * vrp->buf_size; /* allocate coherent memory for the buffers */ bufs_va = dma_alloc_coherent(vdev->dev.parent->parent, @@ -923,14 +923,14 @@ static int rpmsg_probe(struct virtio_device *vdev) dev_dbg(&vdev->dev, "buffers: va %p, dma %pad\n", bufs_va, &vrp->bufs_dma); - /* half of the buffers is dedicated for RX */ + /* first part 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 second part is dedicated for TX */ + vrp->sbufs = bufs_va + vrp->num_rbufs * vrp->buf_size; /* set up the receive buffers */ - for (i = 0; i < vrp->num_bufs / 2; i++) { + for (i = 0; i < vrp->num_rbufs; i++) { struct scatterlist sg; void *cpu_addr = vrp->rbufs + i * vrp->buf_size; @@ -999,7 +999,8 @@ 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 * vrp->buf_size; + unsigned int num_bufs = vrp->num_rbufs + vrp->num_sbufs; + size_t total_buf_space = num_bufs * vrp->buf_size; int ret; vdev->config->reset(vdev); From patchwork Thu Jan 31 15:41:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang Xiao X-Patchwork-Id: 10790827 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D14013A4 for ; Thu, 31 Jan 2019 15:42:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9213A3144A for ; Thu, 31 Jan 2019 15:42:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 865B331433; Thu, 31 Jan 2019 15:42: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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,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 E410431458 for ; Thu, 31 Jan 2019 15:42:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732719AbfAaPl7 (ORCPT ); Thu, 31 Jan 2019 10:41:59 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40701 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726060AbfAaPl6 (ORCPT ); Thu, 31 Jan 2019 10:41:58 -0500 Received: by mail-pg1-f193.google.com with SMTP id z10so1504904pgp.7; Thu, 31 Jan 2019 07:41:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YUn9Hz1mapneAAsBheVMXQ6anQd8S3NPWykszUHVa8w=; b=YZf+RP8HS1fxhfDMDVHKG2QZiLP9B7UKiRlJImDMVqC8NnpGCBMdKB19Ro9eKuSXmb l0opY/WKwmid1utJ5omHLDqJnPJlOXdzZWPjh6W8BmYk/ey/ryNZky/gtcjG5Ctp29Gb ehKUjuTgs/fWzhFkUGgMIQFDlODomeNv+N2Np6HwVizA0Rsjf8b/kmszWRw7ekaDiky/ QeKI6B6KJIR4J+BXBuFeFiy/jn23XwQjZ9IrM5x4Rq95RGeOZ30ZwIfx9b5CfDzh0eLO 4uO9LvZgCJyyyS1/kh9zLgFLq0FSZc0Mw7zA8fOAlnIkFt5LrzqduU3Pw2y/kNYa22KX H+pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YUn9Hz1mapneAAsBheVMXQ6anQd8S3NPWykszUHVa8w=; b=qDvVRbmsID2s6HuJYWg/+/o6x3UslSntdGYjnzvnLlM9siS+5bOq2VbJMiP8Stz8Bn 0EPhsWSH7BPowlcVe6x8JarCMumD2mq/WvioiZUlgqYz/C5kejFYHLkRWbCBwunjeYCF OESn8Pk1OBIjlWCkKUnvUYD3aa+t1/FoVT4a0cApWUmU7Zn/0jVsvERM4srBrpwrPVBQ s8qv+7OMcV/SNEj79QdmcPBkfiUwvWahufzZseEE+IjcwTMWpfP/bNmMGs5grV8PbD/d buys3+1Viymqyvezb4rjkbvXhNvycQQdXFWmToDl8vR/odJrGd/EUmSXpDZn/HjXNcal u4Cg== X-Gm-Message-State: AJcUukcJJbIXLFgZuQSPSl1a2nw5rCrem2ahljAbvuKnIv27iOWp40oV OiM6nSMdWpPpQmKYz7txqq0= X-Google-Smtp-Source: ALg8bN4BvhOXXTaCfC/s2uVWRDUxyEvONlSsft2rqhc2ZWiT7lI9OBBlJmAx/GMGq0AwYzO4TznAag== X-Received: by 2002:a63:dc0c:: with SMTP id s12mr32319712pgg.398.1548949317903; Thu, 31 Jan 2019 07:41:57 -0800 (PST) Received: from localhost.localdomain ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id b2sm6622435pgg.87.2019.01.31.07.41.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 31 Jan 2019 07:41:57 -0800 (PST) From: Xiang Xiao X-Google-Original-From: Xiang Xiao To: ohad@wizery.com, bjorn.andersson@linaro.org, wendy.liang@xilinx.com, arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Xiang Xiao Subject: [PATCH 2/3] rpmsg: virtio_rpmsg_bus: allocate rx/tx buffer separately Date: Thu, 31 Jan 2019 23:41:19 +0800 Message-Id: <1548949280-31794-3-git-send-email-xiaoxiang@xiaomi.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548949280-31794-1-git-send-email-xiaoxiang@xiaomi.com> References: <1548949280-31794-1-git-send-email-xiaoxiang@xiaomi.com> 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 many dma allocator align the returned address with buffer size, so two small allocation could reduce the alignment requirement and save the the memory space wasted by the potential alignment. Signed-off-by: Xiang Xiao --- drivers/rpmsg/virtio_rpmsg_bus.c | 58 +++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index fb0d2eb..59c4554 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -40,7 +40,8 @@ * @num_sbufs: total number of buffers for 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 + * @rbufs_dma: dma base addr of rx buffers + * @sbufs_dma: dma base addr of tx buffers * @tx_lock: protects svq, sbufs and sleepers, to allow concurrent senders. * sending a message might require waking up a dozing remote * processor, which involves sleeping, hence the mutex. @@ -62,7 +63,8 @@ struct virtproc_info { unsigned int num_sbufs; unsigned int buf_size; int last_sbuf; - dma_addr_t bufs_dma; + dma_addr_t rbufs_dma; + dma_addr_t sbufs_dma; struct mutex tx_lock; struct idr endpoints; struct mutex endpoints_lock; @@ -872,9 +874,7 @@ 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; int err = 0, i; - size_t total_buf_space; bool notify; vrp = kzalloc(sizeof(*vrp), GFP_KERNEL); @@ -909,25 +909,28 @@ static int rpmsg_probe(struct virtio_device *vdev) vrp->buf_size = MAX_RPMSG_BUF_SIZE; - total_buf_space = (vrp->num_rbufs + vrp->num_sbufs) * 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) { + vrp->rbufs = dma_alloc_coherent(vdev->dev.parent->parent, + vrp->num_rbufs * vrp->buf_size, + &vrp->rbufs_dma, GFP_KERNEL); + if (!vrp->rbufs) { err = -ENOMEM; goto vqs_del; } - dev_dbg(&vdev->dev, "buffers: va %p, dma %pad\n", - bufs_va, &vrp->bufs_dma); + dev_dbg(&vdev->dev, "rx buffers: va %p, dma 0x%pad\n", + vrp->rbufs, &vrp->rbufs_dma); - /* first part of the buffers is dedicated for RX */ - vrp->rbufs = bufs_va; + vrp->sbufs = dma_alloc_coherent(vdev->dev.parent->parent, + vrp->num_sbufs * vrp->buf_size, + &vrp->sbufs_dma, GFP_KERNEL); + if (!vrp->sbufs) { + err = -ENOMEM; + goto free_rbufs; + } - /* and second part is dedicated for TX */ - vrp->sbufs = bufs_va + vrp->num_rbufs * vrp->buf_size; + dev_dbg(&vdev->dev, "tx buffers: va %p, dma 0x%pad\n", + vrp->sbufs, &vrp->sbufs_dma); /* set up the receive buffers */ for (i = 0; i < vrp->num_rbufs; i++) { @@ -954,7 +957,7 @@ static int rpmsg_probe(struct virtio_device *vdev) if (!vrp->ns_ept) { dev_err(&vdev->dev, "failed to create the ns ept\n"); err = -ENOMEM; - goto free_coherent; + goto free_sbufs; } } @@ -979,9 +982,14 @@ 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); +free_sbufs: + dma_free_coherent(vdev->dev.parent->parent, + vrp->num_sbufs * vrp->buf_size, + vrp->sbufs, vrp->sbufs_dma); +free_rbufs: + dma_free_coherent(vdev->dev.parent->parent, + vrp->num_rbufs * vrp->buf_size, + vrp->rbufs, vrp->rbufs_dma); vqs_del: vdev->config->del_vqs(vrp->vdev); free_vrp: @@ -999,8 +1007,6 @@ static int rpmsg_remove_device(struct device *dev, void *data) static void rpmsg_remove(struct virtio_device *vdev) { struct virtproc_info *vrp = vdev->priv; - unsigned int num_bufs = vrp->num_rbufs + vrp->num_sbufs; - size_t total_buf_space = num_bufs * vrp->buf_size; int ret; vdev->config->reset(vdev); @@ -1016,8 +1022,12 @@ 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); + dma_free_coherent(vdev->dev.parent->parent, + vrp->num_sbufs * vrp->buf_size, + vrp->sbufs, vrp->sbufs_dma); + dma_free_coherent(vdev->dev.parent->parent, + vrp->num_rbufs * vrp->buf_size, + vrp->rbufs, vrp->rbufs_dma); kfree(vrp); } From patchwork Thu Jan 31 15:41:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang Xiao X-Patchwork-Id: 10790825 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 253C514E1 for ; Thu, 31 Jan 2019 15:42:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 190DF31443 for ; Thu, 31 Jan 2019 15:42:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 159223145E; Thu, 31 Jan 2019 15:42:04 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,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 CB2703145B for ; Thu, 31 Jan 2019 15:42:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387726AbfAaPmC (ORCPT ); Thu, 31 Jan 2019 10:42:02 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:42878 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726060AbfAaPmB (ORCPT ); Thu, 31 Jan 2019 10:42:01 -0500 Received: by mail-pg1-f194.google.com with SMTP id d72so1499249pga.9; Thu, 31 Jan 2019 07:42:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=I8VVx1Bzqq4HqI1/o34OWmPP0PQlH5I+uT7NAiVx8YY=; b=BGHlg8rdJ2f0xnz4wMoxGFF4pPkb/EAmLQeWaYvSEfKHSF7/9iVvhGWR+m3bnm+ulV l7k8kRLFInHEtde9/lnFvBPuE3fcoPsXsYTVcEJym5ee+7/5yaZ8jAmKWq7WrYXZjU/6 NJKLa576+bI7GpbGCdj8Yv7gtpGSizfMU0uZYBbOKmEellLzQ0QSjWlrFk3g7kc/RFS9 naz6sW9xsZPZM4mWSSr0jwiT0+yN4XSn0vzrgynS79SNgH2yzeMcL6OwM5VNMCShe7Je vcnzDBmBLpugPIGE9BPYAbWOHTRy8e64B0Of3sC965i2I9SBtdLxn27wpm29tYgPVPSX lLMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=I8VVx1Bzqq4HqI1/o34OWmPP0PQlH5I+uT7NAiVx8YY=; b=bumxVoVWBgwd45jlIeAFcc5F3UzRnSoHbH7h/aG39TUJ5AJklaXRRktYNVUHOufFG1 kB7MVsYKs0IB10ekxh5CCL1DMJFm5xNRuiSDoYmfsHzBhr/BVBD8SnlZRG3USnw1MsGv nNHpeFRu2ojUSPzhtakLmX6nPSfEg0KquCiNt1wT9ADLClgKUrzzQSceyPJlJqrrOlby jS6oobh74000FPdJeMfhV4kJOYoObtmN/QIibn4IVi/k12OVSh7LX4AP+7lGVZfHQxBp ARYky/6T4H+bAW5bCZ1TvR59pDGh9/X3Uii7h5rC30w0pF1vmusn60d2c/IgIzfIyEtd Lg8g== X-Gm-Message-State: AJcUukeUjvDZUtMoVKE7QlcHwK8nNU0Xh+Ycz7XdcrmcSEob86xW9xq2 VGaEYIZLNUceRz3mgccUebY= X-Google-Smtp-Source: ALg8bN7VGZpNB38CnkW6VNZY5oZnMyaEqG/MPE3tcIz5mx+d3/8pKpRavkzgt/MwzZgu3zQpZhqolg== X-Received: by 2002:a63:f241:: with SMTP id d1mr32136038pgk.2.1548949320309; Thu, 31 Jan 2019 07:42:00 -0800 (PST) Received: from localhost.localdomain ([43.224.245.179]) by smtp.gmail.com with ESMTPSA id b2sm6622435pgg.87.2019.01.31.07.41.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 31 Jan 2019 07:41:59 -0800 (PST) From: Xiang Xiao X-Google-Original-From: Xiang Xiao To: ohad@wizery.com, bjorn.andersson@linaro.org, wendy.liang@xilinx.com, arnaud.pouliquen@st.com, linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Xiang Xiao Subject: [PATCH 3/3] rpmsg: virtio_rpmsg_bus: get buffer size from config space Date: Thu, 31 Jan 2019 23:41:20 +0800 Message-Id: <1548949280-31794-4-git-send-email-xiaoxiang@xiaomi.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548949280-31794-1-git-send-email-xiaoxiang@xiaomi.com> References: <1548949280-31794-1-git-send-email-xiaoxiang@xiaomi.com> 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 512 bytes isn't always suitable for all case, let firmware maker decide the best value from resource table. enable by VIRTIO_RPMSG_F_BUFSZ feature bit. Signed-off-by: Xiang Xiao --- drivers/rpmsg/virtio_rpmsg_bus.c | 50 +++++++++++++++++++++++++-------------- include/uapi/linux/virtio_rpmsg.h | 24 +++++++++++++++++++ 2 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 include/uapi/linux/virtio_rpmsg.h diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index 59c4554..049dd97 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -38,7 +39,8 @@ * @sbufs: kernel address of tx buffers * @num_rbufs: total number of buffers for rx * @num_sbufs: total number of buffers for tx - * @buf_size: size of one rx or tx buffer + * @rbuf_size: size of one rx buffer + * @sbuf_size: size of one tx buffer * @last_sbuf: index of last tx buffer used * @rbufs_dma: dma base addr of rx buffers * @sbufs_dma: dma base addr of tx buffers @@ -61,7 +63,8 @@ struct virtproc_info { void *rbufs, *sbufs; unsigned int num_rbufs; unsigned int num_sbufs; - unsigned int buf_size; + unsigned int rbuf_size; + unsigned int sbuf_size; int last_sbuf; dma_addr_t rbufs_dma; dma_addr_t sbufs_dma; @@ -73,9 +76,6 @@ struct virtproc_info { struct rpmsg_endpoint *ns_ept; }; -/* The feature bitmap for virtio rpmsg */ -#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */ - /** * struct rpmsg_hdr - common header for all rpmsg messages * @src: source address @@ -452,7 +452,7 @@ static void *get_a_tx_buf(struct virtproc_info *vrp) /* either pick the next unused tx buffer */ if (vrp->last_sbuf < vrp->num_sbufs) - ret = vrp->sbufs + vrp->buf_size * vrp->last_sbuf++; + ret = vrp->sbufs + vrp->sbuf_size * vrp->last_sbuf++; /* or recycle a used one */ else ret = virtqueue_get_buf(vrp->svq, &len); @@ -578,7 +578,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 > vrp->buf_size - sizeof(struct rpmsg_hdr)) { + if (len > vrp->sbuf_size - sizeof(struct rpmsg_hdr)) { dev_err(dev, "message is too big (%d)\n", len); return -EMSGSIZE; } @@ -718,7 +718,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 > vrp->buf_size || + if (len > vrp->rbuf_size || msg->len > (len - sizeof(struct rpmsg_hdr))) { dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg->len); return -EINVAL; @@ -751,7 +751,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 */ - rpmsg_sg_init(&sg, msg, vrp->buf_size); + rpmsg_sg_init(&sg, msg, vrp->rbuf_size); /* add the buffer back to the remote processor's virtqueue */ err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, msg, GFP_KERNEL); @@ -907,11 +907,24 @@ static int rpmsg_probe(struct virtio_device *vdev) else vrp->num_sbufs = MAX_RPMSG_NUM_BUFS; - vrp->buf_size = MAX_RPMSG_BUF_SIZE; + /* try to get buffer size from config space */ + if (virtio_has_feature(vdev, VIRTIO_RPMSG_F_BUFSZ)) { + /* note: virtio_rpmsg_config is defined from remote view */ + virtio_cread(vdev, struct virtio_rpmsg_config, + txbuf_size, &vrp->rbuf_size); + virtio_cread(vdev, struct virtio_rpmsg_config, + rxbuf_size, &vrp->sbuf_size); + } + + /* use the default if resource table doesn't provide one */ + if (!vrp->rbuf_size) + vrp->rbuf_size = MAX_RPMSG_BUF_SIZE; + if (!vrp->sbuf_size) + vrp->sbuf_size = MAX_RPMSG_BUF_SIZE; /* allocate coherent memory for the buffers */ vrp->rbufs = dma_alloc_coherent(vdev->dev.parent->parent, - vrp->num_rbufs * vrp->buf_size, + vrp->num_rbufs * vrp->rbuf_size, &vrp->rbufs_dma, GFP_KERNEL); if (!vrp->rbufs) { err = -ENOMEM; @@ -922,7 +935,7 @@ static int rpmsg_probe(struct virtio_device *vdev) vrp->rbufs, &vrp->rbufs_dma); vrp->sbufs = dma_alloc_coherent(vdev->dev.parent->parent, - vrp->num_sbufs * vrp->buf_size, + vrp->num_sbufs * vrp->sbuf_size, &vrp->sbufs_dma, GFP_KERNEL); if (!vrp->sbufs) { err = -ENOMEM; @@ -935,9 +948,9 @@ static int rpmsg_probe(struct virtio_device *vdev) /* set up the receive buffers */ for (i = 0; i < vrp->num_rbufs; i++) { struct scatterlist sg; - void *cpu_addr = vrp->rbufs + i * vrp->buf_size; + void *cpu_addr = vrp->rbufs + i * vrp->rbuf_size; - rpmsg_sg_init(&sg, cpu_addr, vrp->buf_size); + rpmsg_sg_init(&sg, cpu_addr, vrp->rbuf_size); err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, cpu_addr, GFP_KERNEL); @@ -984,11 +997,11 @@ static int rpmsg_probe(struct virtio_device *vdev) free_sbufs: dma_free_coherent(vdev->dev.parent->parent, - vrp->num_sbufs * vrp->buf_size, + vrp->num_sbufs * vrp->sbuf_size, vrp->sbufs, vrp->sbufs_dma); free_rbufs: dma_free_coherent(vdev->dev.parent->parent, - vrp->num_rbufs * vrp->buf_size, + vrp->num_rbufs * vrp->rbuf_size, vrp->rbufs, vrp->rbufs_dma); vqs_del: vdev->config->del_vqs(vrp->vdev); @@ -1023,10 +1036,10 @@ static void rpmsg_remove(struct virtio_device *vdev) vdev->config->del_vqs(vrp->vdev); dma_free_coherent(vdev->dev.parent->parent, - vrp->num_sbufs * vrp->buf_size, + vrp->num_sbufs * vrp->sbuf_size, vrp->sbufs, vrp->sbufs_dma); dma_free_coherent(vdev->dev.parent->parent, - vrp->num_rbufs * vrp->buf_size, + vrp->num_rbufs * vrp->rbuf_size, vrp->rbufs, vrp->rbufs_dma); kfree(vrp); @@ -1039,6 +1052,7 @@ static struct virtio_device_id id_table[] = { static unsigned int features[] = { VIRTIO_RPMSG_F_NS, + VIRTIO_RPMSG_F_BUFSZ, }; static struct virtio_driver virtio_ipc_driver = { diff --git a/include/uapi/linux/virtio_rpmsg.h b/include/uapi/linux/virtio_rpmsg.h new file mode 100644 index 0000000..24fa0dd --- /dev/null +++ b/include/uapi/linux/virtio_rpmsg.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Copyright (C) Pinecone Inc. 2019 + * Copyright (C) Xiang Xiao + */ + +#ifndef _UAPI_LINUX_VIRTIO_RPMSG_H +#define _UAPI_LINUX_VIRTIO_RPMSG_H + +#include + +/* The feature bitmap for virtio rpmsg */ +#define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */ +#define VIRTIO_RPMSG_F_BUFSZ 2 /* RP get buffer size from config space */ + +struct virtio_rpmsg_config { + /* The tx/rx individual buffer size(if VIRTIO_RPMSG_F_BUFSZ) */ + __u32 txbuf_size; + __u32 rxbuf_size; + __u32 reserved[14]; /* Reserve for the future use */ + /* Put the customize config here */ +} __attribute__((packed)); + +#endif /* _UAPI_LINUX_VIRTIO_RPMSG_H */