linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: x86@kernel.org, linux-arm-kernel@lists.infradead.org,
	xen-devel@lists.xenproject.org, linux-c6x-dev@linux-c6x.org,
	linux-hexagon@vger.kernel.org, linux-ia64@vger.kernel.org,
	linux-mips@linux-mips.org, openrisc@lists.librecores.org,
	linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org,
	linux-sh@vger.kernel.org, sparclinux@vger.kernel.org,
	linux-xtensa@linux-xtensa.org, dmaengine@vger.kernel.org,
	linux-tegra@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-samsung-soc@vger.kernel.org,
	iommu@lists.linux-foundation.org, netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 25/44] arm: implement ->mapping_error
Date: Thu,  8 Jun 2017 15:25:50 +0200	[thread overview]
Message-ID: <20170608132609.32662-26-hch@lst.de> (raw)
In-Reply-To: <20170608132609.32662-1-hch@lst.de>

DMA_ERROR_CODE is going to go away, so don't rely on it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 arch/arm/common/dmabounce.c        | 16 ++++++++++++---
 arch/arm/include/asm/dma-iommu.h   |  2 ++
 arch/arm/include/asm/dma-mapping.h |  1 -
 arch/arm/mm/dma-mapping.c          | 41 ++++++++++++++++++++++++--------------
 4 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/arch/arm/common/dmabounce.c b/arch/arm/common/dmabounce.c
index 9b1b7be2ec0e..bad457395ff1 100644
--- a/arch/arm/common/dmabounce.c
+++ b/arch/arm/common/dmabounce.c
@@ -33,6 +33,7 @@
 #include <linux/scatterlist.h>
 
 #include <asm/cacheflush.h>
+#include <asm/dma-iommu.h>
 
 #undef STATS
 
@@ -256,7 +257,7 @@ static inline dma_addr_t map_single(struct device *dev, void *ptr, size_t size,
 	if (buf == NULL) {
 		dev_err(dev, "%s: unable to map unsafe buffer %p!\n",
 		       __func__, ptr);
-		return DMA_ERROR_CODE;
+		return ARM_MAPPING_ERROR;
 	}
 
 	dev_dbg(dev, "%s: unsafe buffer %p (dma=%#x) mapped to %p (dma=%#x)\n",
@@ -326,7 +327,7 @@ static dma_addr_t dmabounce_map_page(struct device *dev, struct page *page,
 
 	ret = needs_bounce(dev, dma_addr, size);
 	if (ret < 0)
-		return DMA_ERROR_CODE;
+		return ARM_MAPPING_ERROR;
 
 	if (ret == 0) {
 		arm_dma_ops.sync_single_for_device(dev, dma_addr, size, dir);
@@ -335,7 +336,7 @@ static dma_addr_t dmabounce_map_page(struct device *dev, struct page *page,
 
 	if (PageHighMem(page)) {
 		dev_err(dev, "DMA buffer bouncing of HIGHMEM pages is not supported\n");
-		return DMA_ERROR_CODE;
+		return ARM_MAPPING_ERROR;
 	}
 
 	return map_single(dev, page_address(page) + offset, size, dir, attrs);
@@ -452,6 +453,14 @@ static int dmabounce_set_mask(struct device *dev, u64 dma_mask)
 	return arm_dma_ops.set_dma_mask(dev, dma_mask);
 }
 
+static int dmabounce_mapping_error(struct device *dev, dma_addr_t dma_addr)
+{
+	if (dev->archdata.dmabounce)
+		return 0;
+
+	return arm_dma_ops.mapping_error(dev, dma_addr);
+}
+
 static const struct dma_map_ops dmabounce_ops = {
 	.alloc			= arm_dma_alloc,
 	.free			= arm_dma_free,
@@ -466,6 +475,7 @@ static const struct dma_map_ops dmabounce_ops = {
 	.sync_sg_for_cpu	= arm_dma_sync_sg_for_cpu,
 	.sync_sg_for_device	= arm_dma_sync_sg_for_device,
 	.set_dma_mask		= dmabounce_set_mask,
+	.mapping_error		= dmabounce_mapping_error,
 };
 
 static int dmabounce_init_pool(struct dmabounce_pool *pool, struct device *dev,
diff --git a/arch/arm/include/asm/dma-iommu.h b/arch/arm/include/asm/dma-iommu.h
index 2ef282f96651..389a26a10ea3 100644
--- a/arch/arm/include/asm/dma-iommu.h
+++ b/arch/arm/include/asm/dma-iommu.h
@@ -9,6 +9,8 @@
 #include <linux/kmemcheck.h>
 #include <linux/kref.h>
 
+#define ARM_MAPPING_ERROR		(~(dma_addr_t)0x0)
+
 struct dma_iommu_mapping {
 	/* iommu specific data */
 	struct iommu_domain	*domain;
diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h
index 680d3f3889e7..52a8fd5a8edb 100644
--- a/arch/arm/include/asm/dma-mapping.h
+++ b/arch/arm/include/asm/dma-mapping.h
@@ -12,7 +12,6 @@
 #include <xen/xen.h>
 #include <asm/xen/hypervisor.h>
 
-#define DMA_ERROR_CODE	(~(dma_addr_t)0x0)
 extern const struct dma_map_ops arm_dma_ops;
 extern const struct dma_map_ops arm_coherent_dma_ops;
 
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index c742dfd2967b..2dbc94b5fe5c 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -180,6 +180,11 @@ static void arm_dma_sync_single_for_device(struct device *dev,
 	__dma_page_cpu_to_dev(page, offset, size, dir);
 }
 
+static int arm_dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
+{
+	return dma_addr == ARM_MAPPING_ERROR;
+}
+
 const struct dma_map_ops arm_dma_ops = {
 	.alloc			= arm_dma_alloc,
 	.free			= arm_dma_free,
@@ -193,6 +198,7 @@ const struct dma_map_ops arm_dma_ops = {
 	.sync_single_for_device	= arm_dma_sync_single_for_device,
 	.sync_sg_for_cpu	= arm_dma_sync_sg_for_cpu,
 	.sync_sg_for_device	= arm_dma_sync_sg_for_device,
+	.mapping_error		= arm_dma_mapping_error,
 };
 EXPORT_SYMBOL(arm_dma_ops);
 
@@ -211,6 +217,7 @@ const struct dma_map_ops arm_coherent_dma_ops = {
 	.get_sgtable		= arm_dma_get_sgtable,
 	.map_page		= arm_coherent_dma_map_page,
 	.map_sg			= arm_dma_map_sg,
+	.mapping_error		= arm_dma_mapping_error,
 };
 EXPORT_SYMBOL(arm_coherent_dma_ops);
 
@@ -799,7 +806,7 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
 	gfp &= ~(__GFP_COMP);
 	args.gfp = gfp;
 
-	*handle = DMA_ERROR_CODE;
+	*handle = ARM_MAPPING_ERROR;
 	allowblock = gfpflags_allow_blocking(gfp);
 	cma = allowblock ? dev_get_cma_area(dev) : false;
 
@@ -1254,7 +1261,7 @@ static inline dma_addr_t __alloc_iova(struct dma_iommu_mapping *mapping,
 	if (i == mapping->nr_bitmaps) {
 		if (extend_iommu_mapping(mapping)) {
 			spin_unlock_irqrestore(&mapping->lock, flags);
-			return DMA_ERROR_CODE;
+			return ARM_MAPPING_ERROR;
 		}
 
 		start = bitmap_find_next_zero_area(mapping->bitmaps[i],
@@ -1262,7 +1269,7 @@ static inline dma_addr_t __alloc_iova(struct dma_iommu_mapping *mapping,
 
 		if (start > mapping->bits) {
 			spin_unlock_irqrestore(&mapping->lock, flags);
-			return DMA_ERROR_CODE;
+			return ARM_MAPPING_ERROR;
 		}
 
 		bitmap_set(mapping->bitmaps[i], start, count);
@@ -1445,7 +1452,7 @@ __iommu_create_mapping(struct device *dev, struct page **pages, size_t size,
 	int i;
 
 	dma_addr = __alloc_iova(mapping, size);
-	if (dma_addr == DMA_ERROR_CODE)
+	if (dma_addr == ARM_MAPPING_ERROR)
 		return dma_addr;
 
 	iova = dma_addr;
@@ -1472,7 +1479,7 @@ __iommu_create_mapping(struct device *dev, struct page **pages, size_t size,
 fail:
 	iommu_unmap(mapping->domain, dma_addr, iova-dma_addr);
 	__free_iova(mapping, dma_addr, size);
-	return DMA_ERROR_CODE;
+	return ARM_MAPPING_ERROR;
 }
 
 static int __iommu_remove_mapping(struct device *dev, dma_addr_t iova, size_t size)
@@ -1533,7 +1540,7 @@ static void *__iommu_alloc_simple(struct device *dev, size_t size, gfp_t gfp,
 		return NULL;
 
 	*handle = __iommu_create_mapping(dev, &page, size, attrs);
-	if (*handle == DMA_ERROR_CODE)
+	if (*handle == ARM_MAPPING_ERROR)
 		goto err_mapping;
 
 	return addr;
@@ -1561,7 +1568,7 @@ static void *__arm_iommu_alloc_attrs(struct device *dev, size_t size,
 	struct page **pages;
 	void *addr = NULL;
 
-	*handle = DMA_ERROR_CODE;
+	*handle = ARM_MAPPING_ERROR;
 	size = PAGE_ALIGN(size);
 
 	if (coherent_flag  == COHERENT || !gfpflags_allow_blocking(gfp))
@@ -1582,7 +1589,7 @@ static void *__arm_iommu_alloc_attrs(struct device *dev, size_t size,
 		return NULL;
 
 	*handle = __iommu_create_mapping(dev, pages, size, attrs);
-	if (*handle == DMA_ERROR_CODE)
+	if (*handle == ARM_MAPPING_ERROR)
 		goto err_buffer;
 
 	if (attrs & DMA_ATTR_NO_KERNEL_MAPPING)
@@ -1732,10 +1739,10 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
 	int prot;
 
 	size = PAGE_ALIGN(size);
-	*handle = DMA_ERROR_CODE;
+	*handle = ARM_MAPPING_ERROR;
 
 	iova_base = iova = __alloc_iova(mapping, size);
-	if (iova == DMA_ERROR_CODE)
+	if (iova == ARM_MAPPING_ERROR)
 		return -ENOMEM;
 
 	for (count = 0, s = sg; count < (size >> PAGE_SHIFT); s = sg_next(s)) {
@@ -1775,7 +1782,7 @@ static int __iommu_map_sg(struct device *dev, struct scatterlist *sg, int nents,
 	for (i = 1; i < nents; i++) {
 		s = sg_next(s);
 
-		s->dma_address = DMA_ERROR_CODE;
+		s->dma_address = ARM_MAPPING_ERROR;
 		s->dma_length = 0;
 
 		if (s->offset || (size & ~PAGE_MASK) || size + s->length > max) {
@@ -1950,7 +1957,7 @@ static dma_addr_t arm_coherent_iommu_map_page(struct device *dev, struct page *p
 	int ret, prot, len = PAGE_ALIGN(size + offset);
 
 	dma_addr = __alloc_iova(mapping, len);
-	if (dma_addr == DMA_ERROR_CODE)
+	if (dma_addr == ARM_MAPPING_ERROR)
 		return dma_addr;
 
 	prot = __dma_info_to_prot(dir, attrs);
@@ -1962,7 +1969,7 @@ static dma_addr_t arm_coherent_iommu_map_page(struct device *dev, struct page *p
 	return dma_addr + offset;
 fail:
 	__free_iova(mapping, dma_addr, len);
-	return DMA_ERROR_CODE;
+	return ARM_MAPPING_ERROR;
 }
 
 /**
@@ -2056,7 +2063,7 @@ static dma_addr_t arm_iommu_map_resource(struct device *dev,
 	size_t len = PAGE_ALIGN(size + offset);
 
 	dma_addr = __alloc_iova(mapping, len);
-	if (dma_addr == DMA_ERROR_CODE)
+	if (dma_addr == ARM_MAPPING_ERROR)
 		return dma_addr;
 
 	prot = __dma_info_to_prot(dir, attrs) | IOMMU_MMIO;
@@ -2068,7 +2075,7 @@ static dma_addr_t arm_iommu_map_resource(struct device *dev,
 	return dma_addr + offset;
 fail:
 	__free_iova(mapping, dma_addr, len);
-	return DMA_ERROR_CODE;
+	return ARM_MAPPING_ERROR;
 }
 
 /**
@@ -2140,6 +2147,8 @@ const struct dma_map_ops iommu_ops = {
 
 	.map_resource		= arm_iommu_map_resource,
 	.unmap_resource		= arm_iommu_unmap_resource,
+
+	.mapping_error		= arm_dma_mapping_error,
 };
 
 const struct dma_map_ops iommu_coherent_ops = {
@@ -2156,6 +2165,8 @@ const struct dma_map_ops iommu_coherent_ops = {
 
 	.map_resource	= arm_iommu_map_resource,
 	.unmap_resource	= arm_iommu_unmap_resource,
+
+	.mapping_error		= arm_dma_mapping_error,
 };
 
 /**
-- 
2.11.0

  parent reply	other threads:[~2017-06-08 13:34 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-08 13:25 clean up and modularize arch dma_mapping interface Christoph Hellwig
2017-06-08 13:25 ` [PATCH 01/44] firmware/ivc: use dma_mapping_error Christoph Hellwig
2017-06-13 12:35   ` Thierry Reding
2017-06-08 13:25 ` [PATCH 02/44] ibmveth: properly unwind on init errors Christoph Hellwig
2017-06-08 14:21   ` David Miller
2017-06-08 13:25 ` [PATCH 03/44] dmaengine: ioat: don't use DMA_ERROR_CODE Christoph Hellwig
2017-06-08 16:32   ` Dave Jiang
2017-06-14  8:31   ` Vinod Koul
2017-06-08 13:25 ` [PATCH 04/44] drm/exynos: " Christoph Hellwig
2017-06-08 13:25 ` [PATCH 05/44] drm/armada: don't abuse DMA_ERROR_CODE Christoph Hellwig
2017-06-08 13:25 ` [PATCH 06/44] iommu/dma: don't rely on DMA_ERROR_CODE Christoph Hellwig
2017-06-08 13:59   ` Robin Murphy
2017-06-16  8:37     ` Christoph Hellwig
2017-06-08 13:25 ` [PATCH 07/44] xen-swiotlb: consolidate xen_swiotlb_dma_ops Christoph Hellwig
2017-06-11  2:36   ` Konrad Rzeszutek Wilk
2017-06-08 13:25 ` [PATCH 08/44] xen-swiotlb: implement ->mapping_error Christoph Hellwig
2017-06-11  2:37   ` Konrad Rzeszutek Wilk
2017-06-08 13:25 ` [PATCH 09/44] c6x: remove DMA_ERROR_CODE Christoph Hellwig
2017-06-08 13:25 ` [PATCH 10/44] ia64: " Christoph Hellwig
2017-06-08 13:25 ` [PATCH 11/44] m32r: " Christoph Hellwig
2017-06-08 13:25 ` [PATCH 12/44] microblaze: " Christoph Hellwig
2017-06-08 13:25 ` [PATCH 13/44] openrisc: " Christoph Hellwig
2017-06-08 13:25 ` [PATCH 14/44] sh: " Christoph Hellwig
2017-06-08 13:25 ` [PATCH 15/44] xtensa: " Christoph Hellwig
2017-06-08 13:25 ` [PATCH 16/44] arm64: " Christoph Hellwig
2017-06-08 14:02   ` Robin Murphy
2017-06-08 13:25 ` [PATCH 17/44] hexagon: switch to use ->mapping_error for error reporting Christoph Hellwig
2017-06-16  0:19   ` Richard Kuo
2017-06-08 13:25 ` [PATCH 18/44] iommu/amd: implement ->mapping_error Christoph Hellwig
2017-06-08 13:25 ` [PATCH 19/44] s390: " Christoph Hellwig
2017-06-08 16:23   ` Gerald Schaefer
2017-06-08 13:25 ` [PATCH 20/44] sparc: " Christoph Hellwig
2017-06-08 14:24   ` David Miller
2017-06-08 13:25 ` [PATCH 21/44] powerpc: " Christoph Hellwig
2017-06-14  9:17   ` Michael Ellerman
2017-06-08 13:25 ` [PATCH 22/44] x86/pci-nommu: " Christoph Hellwig
2017-06-08 13:25 ` [PATCH 23/44] x86/calgary: " Christoph Hellwig
2017-06-08 13:25 ` [PATCH 24/44] x86: remove DMA_ERROR_CODE Christoph Hellwig
2017-06-08 13:25 ` Christoph Hellwig [this message]
2017-06-08 14:43   ` [PATCH 25/44] arm: implement ->mapping_error Russell King - ARM Linux
2017-06-16  8:43     ` Christoph Hellwig
2017-06-08 13:25 ` [PATCH 26/44] dma-mapping: remove DMA_ERROR_CODE Christoph Hellwig
2017-06-08 13:25 ` [PATCH 27/44] sparc: remove leon_dma_ops Christoph Hellwig
2017-06-08 14:22   ` David Miller
2017-06-12  8:06   ` Andreas Larsson
2017-06-16  8:45     ` Christoph Hellwig
2017-06-08 13:25 ` [PATCH 28/44] sparc: remove arch specific dma_supported implementations Christoph Hellwig
2017-06-08 14:22   ` Julian Calaby
2017-06-16  8:47     ` Christoph Hellwig
2017-06-08 14:24   ` David Miller
2017-06-08 13:25 ` [PATCH 29/44] dma-noop: remove dma_supported and mapping_error methods Christoph Hellwig
2017-06-08 13:25 ` [PATCH 30/44] dma-virt: " Christoph Hellwig
2017-06-08 13:25 ` [PATCH 31/44] hexagon: remove arch-specific dma_supported implementation Christoph Hellwig
2017-06-16  0:20   ` Richard Kuo
2017-06-08 13:25 ` [PATCH 32/44] hexagon: remove the unused dma_is_consistent prototype Christoph Hellwig
2017-06-08 13:25 ` [PATCH 33/44] openrisc: remove arch-specific dma_supported implementation Christoph Hellwig
2017-06-09 12:20   ` Geert Uytterhoeven
2017-06-16  8:39     ` Christoph Hellwig
2017-06-08 13:25 ` [PATCH 34/44] arm: remove arch specific " Christoph Hellwig
2017-06-08 13:26 ` [PATCH 35/44] x86: " Christoph Hellwig
2017-06-08 13:26 ` [PATCH 36/44] dma-mapping: remove HAVE_ARCH_DMA_SUPPORTED Christoph Hellwig
2017-06-08 13:26 ` [PATCH 37/44] mips/loongson64: implement ->dma_supported instead of ->set_dma_mask Christoph Hellwig
2017-06-08 13:26 ` [PATCH 38/44] arm: " Christoph Hellwig
2017-06-08 13:26 ` [PATCH 39/44] xen-swiotlb: remove xen_swiotlb_set_dma_mask Christoph Hellwig
2017-06-08 13:26 ` [PATCH 40/44] tile: remove dma_supported and mapping_error methods Christoph Hellwig
2017-06-08 13:26 ` [PATCH 41/44] powerpc/cell: clean up fixed mapping dma_ops initialization Christoph Hellwig
2017-06-08 13:26 ` [PATCH 42/44] powerpc/cell: use the dma_supported method for ops switching Christoph Hellwig
2017-06-08 13:26 ` [PATCH 43/44] dma-mapping: remove the set_dma_mask method Christoph Hellwig
2017-06-08 13:26 ` [PATCH 44/44] powerpc: merge __dma_set_mask into dma_set_mask Christoph Hellwig
2017-06-08 14:21 ` clean up and modularize arch dma_mapping interface David Miller
2017-06-20  9:19 ` Daniel Vetter
2017-06-20 13:17   ` Christoph Hellwig
2017-06-16 18:10 clean up and modularize arch dma_mapping interface V2 Christoph Hellwig
2017-06-16 18:10 ` [PATCH 25/44] arm: implement ->mapping_error Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170608132609.32662-26-hch@lst.de \
    --to=hch@lst.de \
    --cc=dmaengine@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-c6x-dev@linux-c6x.org \
    --cc=linux-hexagon@vger.kernel.org \
    --cc=linux-ia64@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=linux-xtensa@linux-xtensa.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=netdev@vger.kernel.org \
    --cc=openrisc@lists.librecores.org \
    --cc=sparclinux@vger.kernel.org \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).