Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5065523img; Wed, 27 Mar 2019 01:07:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/q0TpzJ6ZnhUGzwOGO8caPIIxo29hngrmV5k3FIXj8N66a0TiGa6pNkVMIZGE3guTlUYH X-Received: by 2002:aa7:8609:: with SMTP id p9mr33961811pfn.166.1553674021143; Wed, 27 Mar 2019 01:07:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553674021; cv=none; d=google.com; s=arc-20160816; b=HMxq86FcTdLmZilZ2iizSnfzmhjIKw06BVtMJ8ljlDbIoMRL1w9tKEVwRbOPWeM+Js ZhwWJjWRyIaqnmyqcDymtU8QZq9J2CW9Ui/I3vw0xesExuO6ZkWMW5/WK1+awV4VN81Z viSTWgInyXesT/iOZ7bVMkiuKsINpaSOSDBqx/5fXqriXBOmdl2v9ykcZKA6oIAgxF7P szE2oeOQQictx5rePrrzuXsCwCT/Eo4oHBNKgAEI2QozDIoW38qVYkj9Mz1Wkq14GOoF u2ogHsFrmlYb9qfLEiaHPVfRdt8hDFlidF9en4SvzdiybSgDqxhqV58yM8QTuGz9Qlac 6VCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=OMEu+uGgCvsJfEy2oq3BSPLG12mwQ1W+zA4NNTTHNEE=; b=Xk9DiZjHdoHPhfo68FdQu7lUcGBreL6kJXNj1W1H7hj/tVAH90bNzei0WVwBz5HJ9D KORT85p0s8rvNSZf3jCxbJ2doPwNmJUsKRz3ehmAej/Z+12bQwtGF+OCxo4OjxGIB6Is Y/5ifH0kePHFlV2JNH7YNy58qY0rFPxlCL+I810EEYQ6ztyzmxpUuwebmaGT35CADFim r95ah68ivmaKp8Nd/pwecEW7deZoAtCYt03LvLps+1Yc6wbUIhn3YgPPbgZOTWQjjpgY SbAeJch5zgzVyPRL6n9pxTTEff3Mv5hyaIKNP0Ordps0CHUfELSkSO8kbJsIIsYnsXFP EHsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=hq0NGWzq; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h29si10051200pfd.180.2019.03.27.01.06.45; Wed, 27 Mar 2019 01:07:01 -0700 (PDT) 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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=hq0NGWzq; 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 S1732552AbfC0IFr (ORCPT + 99 others); Wed, 27 Mar 2019 04:05:47 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:60770 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732432AbfC0IFp (ORCPT ); Wed, 27 Mar 2019 04:05:45 -0400 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=OMEu+uGgCvsJfEy2oq3BSPLG12mwQ1W+zA4NNTTHNEE=; b=hq0NGWzqivPCtSYFcsUfY9g9UK eVuU4FVL1nNl6zrqkxz31AExcfEKvGZBq/bhOoG1jfj+n9fzOoEPOR1YUSBBohF2cOMdb7sFQc+yO LnSr+jifjG0p9q5n7kLcVmJvKQ9kva2e1dq/pA6v64dLI+fi0wrvxVUt76FGLy9bd0usn+oDldeP9 pqe0mYx6sqIUPRGszt6h+d6aIJtRPv4rWaAGIf0jhQSRPU2rrl2bH97clEgYn3BkKduJVVeQakpGo qAE2SLCBE2dojYGqBGB06oQQl94qXApsBKcZGvDg0DggHyze9HuqaL6drOFbenSFmmcyd7laZEivF Rh8V2KQg==; Received: from 213-225-14-48.nat.highway.a1.net ([213.225.14.48] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1h93Z5-0006cg-Vk; Wed, 27 Mar 2019 08:05:40 +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 10/21] dma-iommu: move __iommu_dma_map Date: Wed, 27 Mar 2019 09:04:37 +0100 Message-Id: <20190327080448.5500-11-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190327080448.5500-1-hch@lst.de> References: <20190327080448.5500-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 Moving this function up to its unmap counterpart helps to keep related code together for the following changes. Signed-off-by: Christoph Hellwig --- drivers/iommu/dma-iommu.c | 46 +++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 57f2d8621112..4d46beeea5b7 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -435,6 +435,29 @@ static void __iommu_dma_unmap(struct iommu_domain *domain, dma_addr_t dma_addr, iommu_dma_free_iova(cookie, dma_addr, size); } +static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, + size_t size, int prot, struct iommu_domain *domain) +{ + struct iommu_dma_cookie *cookie = domain->iova_cookie; + size_t iova_off = 0; + dma_addr_t iova; + + if (cookie->type == IOMMU_DMA_IOVA_COOKIE) { + iova_off = iova_offset(&cookie->iovad, phys); + size = iova_align(&cookie->iovad, size + iova_off); + } + + iova = iommu_dma_alloc_iova(domain, size, dma_get_mask(dev), dev); + if (!iova) + return DMA_MAPPING_ERROR; + + if (iommu_map(domain, iova, phys - iova_off, size, prot)) { + iommu_dma_free_iova(cookie, iova, size); + return DMA_MAPPING_ERROR; + } + return iova + iova_off; +} + static void __iommu_dma_free_pages(struct page **pages, int count) { while (count--) @@ -689,29 +712,6 @@ static void iommu_dma_sync_sg_for_device(struct device *dev, arch_sync_dma_for_device(dev, sg_phys(sg), sg->length, dir); } -static dma_addr_t __iommu_dma_map(struct device *dev, phys_addr_t phys, - size_t size, int prot, struct iommu_domain *domain) -{ - struct iommu_dma_cookie *cookie = domain->iova_cookie; - size_t iova_off = 0; - dma_addr_t iova; - - if (cookie->type == IOMMU_DMA_IOVA_COOKIE) { - iova_off = iova_offset(&cookie->iovad, phys); - size = iova_align(&cookie->iovad, size + iova_off); - } - - iova = iommu_dma_alloc_iova(domain, size, dma_get_mask(dev), dev); - if (!iova) - return DMA_MAPPING_ERROR; - - if (iommu_map(domain, iova, phys - iova_off, size, prot)) { - iommu_dma_free_iova(cookie, iova, size); - return DMA_MAPPING_ERROR; - } - return iova + iova_off; -} - static dma_addr_t __iommu_dma_map_page(struct device *dev, struct page *page, unsigned long offset, size_t size, int prot) { -- 2.20.1