From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A4C1C282CE for ; Wed, 13 Feb 2019 18:30:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1137A2086C for ; Wed, 13 Feb 2019 18:30:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="cHtr++Zb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405159AbfBMSaT (ORCPT ); Wed, 13 Feb 2019 13:30:19 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:57452 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405121AbfBMSaL (ORCPT ); Wed, 13 Feb 2019 13:30:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=jTffWlkFt2JYLnFvAIZTtBcJsUCs4l8k9rN3MnCYb2U=; b=cHtr++ZbCSUO57D2Hn0V5Gxxt8 fOzgtXHiTNk4dNTajaP3PhUIu9nPgDo8c2Khwifi3Byr4ymGJyr3iybFDUmrZrMhjn12eSK1l1jfd UhMjcFcEiFCtvSSVnyoBc9O7CuQeH7DczXYr3tZHeYZz+7POETt6x6BhYM2IZSpwUM0vNjDl1r5z8 JFigFbduIWYXgqnw84XqgpWN3HjSDCbeunpVldyZWluxiszmsKxm3tGmbtC4PhJCK7AMjJtmQBHkl DcPnarsiDXpno3s6WAM6yOHdAPnIl6U7V89k2SzlwAMk7blRrIIeoXz/Ih5XFT+/FwBJKDueQTBdA /K6c9XAw==; Received: from 089144210182.atnat0019.highway.a1.net ([89.144.210.182] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gtzIM-0000bi-F5; Wed, 13 Feb 2019 18:30:06 +0000 From: Christoph Hellwig To: Robin Murphy Cc: Joerg Roedel , Catalin Marinas , Will Deacon , Tom Lendacky , iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 17/21] dma-iommu: refactor iommu_dma_alloc Date: Wed, 13 Feb 2019 19:29:16 +0100 Message-Id: <20190213182920.16764-18-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190213182920.16764-1-hch@lst.de> References: <20190213182920.16764-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Split all functionality related to non-coherent devices into a separate helper, and make the decision flow more obvious. Signed-off-by: Christoph Hellwig --- drivers/iommu/dma-iommu.c | 51 +++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 5a7ca5271532..5f3c70c65d50 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -768,6 +768,22 @@ static void *iommu_dma_alloc_pool(struct device *dev, size_t size, return vaddr; } +static void *iommu_dma_alloc_noncoherent(struct device *dev, size_t size, + dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) +{ + /* + * In atomic context we can't remap anything, so we'll only get the + * virtually contiguous buffer we need by way of a physically + * contiguous allocation. + */ + if (!gfpflags_allow_blocking(gfp)) + return iommu_dma_alloc_pool(dev, size, dma_handle, gfp, attrs); + if (attrs & DMA_ATTR_FORCE_CONTIGUOUS) + return iommu_dma_alloc_contiguous_remap(dev, size, dma_handle, + gfp, attrs); + return iommu_dma_alloc_remap(dev, size, dma_handle, gfp, attrs); +} + static void iommu_dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size, enum dma_data_direction dir) { @@ -1041,40 +1057,23 @@ static void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle, } static void *iommu_dma_alloc(struct device *dev, size_t size, - dma_addr_t *handle, gfp_t gfp, unsigned long attrs) + dma_addr_t *dma_handle, gfp_t gfp, unsigned long attrs) { - bool coherent = dev_is_dma_coherent(dev); - size_t iosize = size; - void *addr; - /* * Some drivers rely on this, and we probably don't want the * possibility of stale kernel data being read by devices anyway. */ gfp |= __GFP_ZERO; - if (!gfpflags_allow_blocking(gfp)) { - /* - * In atomic context we can't remap anything, so we'll only - * get the virtually contiguous buffer we need by way of a - * physically contiguous allocation. - */ - if (!coherent) - return iommu_dma_alloc_pool(dev, iosize, handle, gfp, - attrs); - return iommu_dma_alloc_contiguous(dev, iosize, handle, gfp, + if (!dev_is_dma_coherent(dev)) + return iommu_dma_alloc_noncoherent(dev, size, dma_handle, gfp, attrs); - } else if (attrs & DMA_ATTR_FORCE_CONTIGUOUS) { - if (coherent) - addr = iommu_dma_alloc_contiguous(dev, iosize, handle, - gfp, attrs); - else - addr = iommu_dma_alloc_contiguous_remap(dev, iosize, - handle, gfp, attrs); - } else { - addr = iommu_dma_alloc_remap(dev, iosize, handle, gfp, attrs); - } - return addr; + + if (gfpflags_allow_blocking(gfp) && + !(attrs & DMA_ATTR_FORCE_CONTIGUOUS)) + return iommu_dma_alloc_remap(dev, size, dma_handle, gfp, attrs); + + return iommu_dma_alloc_contiguous(dev, size, dma_handle, gfp, attrs); } static void iommu_dma_free(struct device *dev, size_t size, void *cpu_addr, -- 2.20.1