Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1286437ybt; Thu, 2 Jul 2020 01:24:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNjW9w939IqcNHPhOuOk3vWfme7J1QHxlKZsVAGoXfgKwPqaMyiBtMaFbT8GS73bgBCBzn X-Received: by 2002:a17:906:fa9b:: with SMTP id lt27mr25169100ejb.365.1593678276629; Thu, 02 Jul 2020 01:24:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593678276; cv=none; d=google.com; s=arc-20160816; b=OjVZU4vsHt7l5IemQYhrO4Cc48uXVl2U1eG6OsHUZomETyezGbmP+9Cu78BUHF0H1T N58pztXXZjSgc3yQ9TQnxj6XhgC6FdeybZNUG3AVu72DSyolBw5726mOyb+pFTM/QHDE 53sbK0BUayQU+c5QtdK1F9YiHdbojeFx8Z/z8RTAzAt4jPSVRVGa7Vecgd3fSYR5z772 IXbETrOPPiN6/qKVeiJpSImSKAzz8nOm5nb03z6MrREhVqprMXxWCgp0pQn4vwuZahJE ZcU4YARgdUN85R++474xal47aBUwkFuEh+dNLVp1GiT3+v+oKvXJN1pOSvCUZOfPo3IM C/XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=33BgNyAskD4tPtltq/G/c+6YM0cxUZYr1ZA8AxsWt2I=; b=GPNMgVGpWW/ta27qDrqR7IqPTGcQQI129u+JHna+3uVBOEcGdUXEB8KmNxoU0hwyZS 1SqiCGTHjP02+W5XP9ZpBbhr6VibxpSSBif+w4g6SHFsm+it+GaGoWPIPYdLfYZY19Y7 QwzXKJFuB8/potI6seNU6IZ5tdITph9Wm9n2wp+vAp1U44ctrz9DkRZvU5KEnbIHWQvU Bva2K5JHP0GobnQdCX1ZAPjvaiRWIhPBitj0tHNU/tF0c1hTrP0YtYjYbxC2T3bAeD2u F8hwpjZ3ABTpdhpFbpdCoEibxemDLBp5NgknV6yT+7nUez1Vjj5aFa+TKCR4VSYcQeI+ daFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=vw7QPSUT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u12si2683711eja.373.2020.07.02.01.24.12; Thu, 02 Jul 2020 01:24:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=vw7QPSUT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728601AbgGBIXV (ORCPT + 99 others); Thu, 2 Jul 2020 04:23:21 -0400 Received: from fllv0015.ext.ti.com ([198.47.19.141]:34564 "EHLO fllv0015.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728585AbgGBIXP (ORCPT ); Thu, 2 Jul 2020 04:23:15 -0400 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 0628N4OM017422; Thu, 2 Jul 2020 03:23:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1593678184; bh=33BgNyAskD4tPtltq/G/c+6YM0cxUZYr1ZA8AxsWt2I=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=vw7QPSUTKuZgj+GGqy+fujjjqAOcGN41ewsIzNJue29GXuL9A+DLJjyd3tqBdh5BH O9/Rfrx1a9YJNcgGMO2Eh2drcJN2jYNr9Sx9EIE9PySCFwDqgs8l0elpxZ+a7oBiSf gqpT9osCNxXgKtOLe7vjZSZii8dZ43XKpUewjFVg= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 0628N4t0031613 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 2 Jul 2020 03:23:04 -0500 Received: from DFLE101.ent.ti.com (10.64.6.22) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Thu, 2 Jul 2020 03:23:04 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DFLE101.ent.ti.com (10.64.6.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via Frontend Transport; Thu, 2 Jul 2020 03:23:03 -0500 Received: from a0393678ub.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 0628LiYP006145; Thu, 2 Jul 2020 03:22:58 -0500 From: Kishon Vijay Abraham I To: Ohad Ben-Cohen , Bjorn Andersson , Jon Mason , Dave Jiang , Allen Hubbe , Lorenzo Pieralisi , Bjorn Helgaas , "Michael S. Tsirkin" , Jason Wang , Paolo Bonzini , Stefan Hajnoczi , Stefano Garzarella CC: , , , , , , , Subject: [RFC PATCH 13/22] rpmsg: virtio_rpmsg_bus: Use virtio_alloc_buffer() and virtio_free_buffer() Date: Thu, 2 Jul 2020 13:51:34 +0530 Message-ID: <20200702082143.25259-14-kishon@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200702082143.25259-1-kishon@ti.com> References: <20200702082143.25259-1-kishon@ti.com> MIME-Version: 1.0 Content-Type: text/plain X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use virtio_alloc_buffer() and virtio_free_buffer() to allocate and free memory buffer respectively. Only if buffer allocation using virtio_alloc_buffer() try using dma_alloc_coherent(). This is required for devices like NTB to use rpmsg for communicating with other host. Signed-off-by: Kishon Vijay Abraham I --- drivers/rpmsg/virtio_rpmsg_bus.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c index f91143b25af7..2b25a8ae1539 100644 --- a/drivers/rpmsg/virtio_rpmsg_bus.c +++ b/drivers/rpmsg/virtio_rpmsg_bus.c @@ -882,13 +882,16 @@ static int rpmsg_probe(struct virtio_device *vdev) total_buf_space = vrp->num_bufs * vrp->buf_size; - /* allocate coherent memory for the buffers */ - bufs_va = dma_alloc_coherent(vdev->dev.parent, - total_buf_space, &vrp->bufs_dma, - GFP_KERNEL); + bufs_va = virtio_alloc_buffer(vdev, total_buf_space); if (!bufs_va) { - err = -ENOMEM; - goto vqs_del; + /* allocate coherent memory for the buffers */ + bufs_va = dma_alloc_coherent(vdev->dev.parent, + total_buf_space, &vrp->bufs_dma, + GFP_KERNEL); + if (!bufs_va) { + err = -ENOMEM; + goto vqs_del; + } } dev_dbg(&vdev->dev, "buffers: va %pK, dma %pad\n", @@ -951,8 +954,13 @@ static int rpmsg_probe(struct virtio_device *vdev) return 0; free_coherent: - dma_free_coherent(vdev->dev.parent, total_buf_space, - bufs_va, vrp->bufs_dma); + if (!vrp->bufs_dma) { + virtio_free_buffer(vdev, bufs_va, total_buf_space); + } else { + dma_free_coherent(vdev->dev.parent, total_buf_space, + bufs_va, vrp->bufs_dma); + } + vqs_del: vdev->config->del_vqs(vrp->vdev); free_vrp: @@ -986,8 +994,12 @@ static void rpmsg_remove(struct virtio_device *vdev) vdev->config->del_vqs(vrp->vdev); - dma_free_coherent(vdev->dev.parent, total_buf_space, - vrp->rbufs, vrp->bufs_dma); + if (!vrp->bufs_dma) { + virtio_free_buffer(vdev, vrp->rbufs, total_buf_space); + } else { + dma_free_coherent(vdev->dev.parent, total_buf_space, + vrp->rbufs, vrp->bufs_dma); + } kfree(vrp); } -- 2.17.1