Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7271573imu; Thu, 31 Jan 2019 07:42:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN6m/WeWadJTgK7K2gV7aCIvEaFSH+U+eOGxdB9Bm7VQcrGKi03Yb9PLiiGAn2hBtan5lSYF X-Received: by 2002:a17:902:2b84:: with SMTP id l4mr35473799plb.191.1548949346961; Thu, 31 Jan 2019 07:42:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548949346; cv=none; d=google.com; s=arc-20160816; b=aMA42K/MGMQ05+IfmLlKckIUOTuh9SXPlbsZxpAn3LcQ5TmJ0u5fyeS7teJRD5s2Ks nGNAAp+wHItPthcj5R+TAVsRf2HR28duFa7W3FmHSizE4l6LgfQFrCtPMF1IBU1gEZiQ 7PjNaoutbG+5lXapPk2nW1hvDdTX6pYMymoy0HOkgld7z6EDPePiRlW32CyYnZ6L20om f9XwYlkUhpr+5n9q4yo/eeY8H2EFIIY9I0allhnztdtT+t4D2hQxan97YYy7WFJHwwdw SosSPNLO/rKNOTiOqRA2bE7tzM/3zwRy0PmK35jI0RNqzScodtO+2u+XROtlVquRSuJ5 6TFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=YUn9Hz1mapneAAsBheVMXQ6anQd8S3NPWykszUHVa8w=; b=YMKuqb7I3olwo8m8gP0beUZp1cAruPkxeRc+EkiVrFFFtQjr2ap4XvFsoyE9WAdxGD RLzvrzEphdANpDVhGJjnxudnmDSIypx6SjSs041v/dwCDavwP1Rp0jEJeZOJpXHr/eWR ook8B3x7CuFQ120XuB5eAcETJNSjc2At3hdhCStp6gcysQ8jSV/NXD5NZPjU1aCUlw8X wDvW1X0TWkXJIg6C2L1DZhy0IbkcuUxhc9OPGln+Lze6q0xyTpQWNfbKy0zfPJkoBuE1 9Z7zn1JqzwD1xm1GC6St5htdaSY5ENtCL8i0zUSL5bLBjWgEgjwzNDXD538Z264WK0q4 vt0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YZf+RP8H; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r11si5278494pli.175.2019.01.31.07.42.11; Thu, 31 Jan 2019 07:42:26 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YZf+RP8H; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387680AbfAaPl7 (ORCPT + 99 others); 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-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); } -- 2.7.4