Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1318064pxa; Thu, 20 Aug 2020 08:15:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyZdk4GYyRMCdNFQXS90eo9QZsEuVAIy6NcMlnKTVUXrwSsmyemel+hIItktoGXl98B8LL X-Received: by 2002:a05:6402:1d17:: with SMTP id dg23mr3396015edb.198.1597936526363; Thu, 20 Aug 2020 08:15:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597936526; cv=none; d=google.com; s=arc-20160816; b=p1VTM0jf15kDqpAQujgjmn6SDxhNLd80aSMHo94HXceR0A00qz9yMcvYEPyTq1Jx9G MbeKmJiAAx/Ef6wxy/Oaac/ziOV6qxK5US+5lfbf5TqAPZkthvXl9wvjKmvfBFMest6g XWVYv4fgoh4gAPQIb8FXTGZ87qF4Z1vGan/JEJIrsfRL1M5vi1peTSBkuu7KhqOqYzYa 8UkkmmFjZ0JfUGtBKbbfLUeQ5dflQOtqZgLTcDLhGpj9or2HqCLbI9X9DAvv9MD0Zuke xJaPkGxgSz9jdjtZHSiGG+D5JeSuxR4b2soisX33A9ZVa+YBJU/yayjQFgJbn27rYbnj ALkA== 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; bh=6b7Hll+stB5dvIE5b+e1mGAvzZvle07Eo9bOt+mCuxM=; b=m/okT6hOixwfhtxlSQXtUwdXJ9xGJL3OlKNgdCrH6FEJexvv6QQHBY0HzJo6tJuYm0 PeBf9ZEoQprtFiMWLX50LEkt5kozg8a+2PdlTOrNRDEj0AnblfQfEzcE/bVRZQHFeWMz JkUb8Ey+wTZW05DPu3htCVQb9sbO4E45UwoF9aZkJWRXGK9DiYHunVcE0Pa38TrdZtP0 6iSGTTyKaIGo8ivHBqX/TZQDztPopvtPVY6mCxYPSn1jtx5jeuLZ+ubzgHyEZG8i6tK5 0NTssm9vlNsgbeNu2UdbxJQ0FOtA53Pmnany3hCeVLhdLtHSmSY+GMt6Ui4FANGlgaAi iqXA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bu20si1470902edb.537.2020.08.20.08.15.02; Thu, 20 Aug 2020 08:15:26 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729331AbgHTPM5 (ORCPT + 99 others); Thu, 20 Aug 2020 11:12:57 -0400 Received: from foss.arm.com ([217.140.110.172]:40790 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728613AbgHTPJG (ORCPT ); Thu, 20 Aug 2020 11:09:06 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3C0E61045; Thu, 20 Aug 2020 08:09:05 -0700 (PDT) Received: from e121345-lin.cambridge.arm.com (e121345-lin.cambridge.arm.com [10.1.196.37]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A3F923F6CF; Thu, 20 Aug 2020 08:09:01 -0700 (PDT) From: Robin Murphy To: hch@lst.de, joro@8bytes.org, linux@armlinux.org.uk Cc: will@kernel.org, inki.dae@samsung.com, sw0312.kim@samsung.com, kyungmin.park@samsung.com, m.szyprowski@samsung.com, agross@kernel.org, bjorn.andersson@linaro.org, thierry.reding@gmail.com, jonathanh@nvidia.com, vdumpa@nvidia.com, digetx@gmail.com, matthias.bgg@gmail.com, yong.wu@mediatek.com, geert+renesas@glider.be, magnus.damm@gmail.com, t-kristo@ti.com, s-anna@ti.com, laurent.pinchart@ideasonboard.com, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, linux-samsung-soc@vger.kernel.org, linux-tegra@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-mediatek@lists.infradead.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/18] ARM/dma-mapping: Merge IOMMU ops Date: Thu, 20 Aug 2020 16:08:22 +0100 Message-Id: X-Mailer: git-send-email 2.28.0.dirty In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The dma_sync_* operations are now the only difference between the coherent and non-coherent IOMMU ops. Some minor tweaks to make those safe for coherent devices with minimal overhead, and we can condense down to a single set of DMA ops. Signed-off-by: Robin Murphy --- arch/arm/mm/dma-mapping.c | 41 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 1bb7e9608f75..0537c97cebe1 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1677,6 +1677,9 @@ static void arm_iommu_sync_sg_for_cpu(struct device *dev, struct scatterlist *s; int i; + if (dev->dma_coherent) + return; + for_each_sg(sg, s, nents, i) __dma_page_dev_to_cpu(sg_page(s), s->offset, s->length, dir); @@ -1696,6 +1699,9 @@ static void arm_iommu_sync_sg_for_device(struct device *dev, struct scatterlist *s; int i; + if (dev->dma_coherent) + return; + for_each_sg(sg, s, nents, i) __dma_page_cpu_to_dev(sg_page(s), s->offset, s->length, dir); } @@ -1829,12 +1835,13 @@ static void arm_iommu_sync_single_for_cpu(struct device *dev, { struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); dma_addr_t iova = handle & PAGE_MASK; - struct page *page = phys_to_page(iommu_iova_to_phys(mapping->domain, iova)); + struct page *page; unsigned int offset = handle & ~PAGE_MASK; - if (!iova) + if (dev->dma_coherent || !iova) return; + page = phys_to_page(iommu_iova_to_phys(mapping->domain, iova)); __dma_page_dev_to_cpu(page, offset, size, dir); } @@ -1843,12 +1850,13 @@ static void arm_iommu_sync_single_for_device(struct device *dev, { struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev); dma_addr_t iova = handle & PAGE_MASK; - struct page *page = phys_to_page(iommu_iova_to_phys(mapping->domain, iova)); + struct page *page; unsigned int offset = handle & ~PAGE_MASK; - if (!iova) + if (dev->dma_coherent || !iova) return; + page = phys_to_page(iommu_iova_to_phys(mapping->domain, iova)); __dma_page_cpu_to_dev(page, offset, size, dir); } @@ -1872,22 +1880,6 @@ static const struct dma_map_ops iommu_ops = { .unmap_resource = arm_iommu_unmap_resource, }; -static const struct dma_map_ops iommu_coherent_ops = { - .alloc = arm_iommu_alloc_attrs, - .free = arm_iommu_free_attrs, - .mmap = arm_iommu_mmap_attrs, - .get_sgtable = arm_iommu_get_sgtable, - - .map_page = arm_iommu_map_page, - .unmap_page = arm_iommu_unmap_page, - - .map_sg = arm_iommu_map_sg, - .unmap_sg = arm_iommu_unmap_sg, - - .map_resource = arm_iommu_map_resource, - .unmap_resource = arm_iommu_unmap_resource, -}; - /** * arm_iommu_create_mapping * @bus: pointer to the bus holding the client device (for IOMMU calls) @@ -2067,11 +2059,6 @@ void arm_iommu_detach_device(struct device *dev) } EXPORT_SYMBOL_GPL(arm_iommu_detach_device); -static const struct dma_map_ops *arm_get_iommu_dma_map_ops(bool coherent) -{ - return coherent ? &iommu_coherent_ops : &iommu_ops; -} - static bool arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size, const struct iommu_ops *iommu) { @@ -2118,8 +2105,6 @@ static bool arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size, static void arm_teardown_iommu_dma_ops(struct device *dev) { } -#define arm_get_iommu_dma_map_ops arm_get_dma_map_ops - #endif /* CONFIG_ARM_DMA_USE_IOMMU */ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, @@ -2141,7 +2126,7 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, return; if (arm_setup_iommu_dma_ops(dev, dma_base, size, iommu)) - dma_ops = arm_get_iommu_dma_map_ops(coherent); + dma_ops = &iommu_ops; else dma_ops = arm_get_dma_map_ops(coherent); -- 2.28.0.dirty