linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* add a new dma_alloc_noncontiguous API
@ 2021-01-28 14:58 Christoph Hellwig
  2021-01-28 14:58 ` [PATCH 1/6] dma-mapping: remove the {alloc,free}_noncoherent methods Christoph Hellwig
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: Christoph Hellwig @ 2021-01-28 14:58 UTC (permalink / raw)
  To: Mauro Carvalho Chehab, Marek Szyprowski, Tomasz Figa,
	Ricardo Ribalda, Sergey Senozhatsky, iommu
  Cc: Robin Murphy, linux-doc, linux-kernel, linux-media

Hi all,

this series adds the new noncontiguous DMA allocation API requested by
various media driver maintainers.

^ permalink raw reply	[flat|nested] 13+ messages in thread
* [PATCH 1/6] dma-mapping: remove the {alloc,free}_noncoherent methods
@ 2020-11-24 15:38 Ricardo Ribalda
  0 siblings, 0 replies; 13+ messages in thread
From: Ricardo Ribalda @ 2020-11-24 15:38 UTC (permalink / raw)
  To: Christoph Hellwig, Mauro Carvalho Chehab, Marek Szyprowski,
	IOMMU DRIVERS, Joerg Roedel, Robin Murphy,
	Linux Doc Mailing List, Linux Kernel Mailing List,
	Linux Media Mailing List, Tomasz Figa, Sergey Senozhatsky

From: Christoph Hellwig <hch@lst.de>

It turns out allowing non-contigous allocations here was a rather bad
idea, as we'll now need to define ways to get the pages for mmaping
or dma_buf sharing.  Revert this change and stick to the original
concept.  A different API for the use case of non-contigous allocations
will be added back later.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 drivers/iommu/dma-iommu.c   | 30 ------------------------------
 include/linux/dma-map-ops.h |  5 -----
 kernel/dma/mapping.c        | 33 ++++++---------------------------
 3 files changed, 6 insertions(+), 62 deletions(-)

diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 0cbcd3fc3e7e..73249732afd3 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -1054,34 +1054,6 @@ static void *iommu_dma_alloc(struct device *dev, size_t size,
 	return cpu_addr;
 }
 
-#ifdef CONFIG_DMA_REMAP
-static void *iommu_dma_alloc_noncoherent(struct device *dev, size_t size,
-		dma_addr_t *handle, enum dma_data_direction dir, gfp_t gfp)
-{
-	if (!gfpflags_allow_blocking(gfp)) {
-		struct page *page;
-
-		page = dma_common_alloc_pages(dev, size, handle, dir, gfp);
-		if (!page)
-			return NULL;
-		return page_address(page);
-	}
-
-	return iommu_dma_alloc_remap(dev, size, handle, gfp | __GFP_ZERO,
-				     PAGE_KERNEL, 0);
-}
-
-static void iommu_dma_free_noncoherent(struct device *dev, size_t size,
-		void *cpu_addr, dma_addr_t handle, enum dma_data_direction dir)
-{
-	__iommu_dma_unmap(dev, handle, size);
-	__iommu_dma_free(dev, size, cpu_addr);
-}
-#else
-#define iommu_dma_alloc_noncoherent		NULL
-#define iommu_dma_free_noncoherent		NULL
-#endif /* CONFIG_DMA_REMAP */
-
 static int iommu_dma_mmap(struct device *dev, struct vm_area_struct *vma,
 		void *cpu_addr, dma_addr_t dma_addr, size_t size,
 		unsigned long attrs)
@@ -1152,8 +1124,6 @@ static const struct dma_map_ops iommu_dma_ops = {
 	.free			= iommu_dma_free,
 	.alloc_pages		= dma_common_alloc_pages,
 	.free_pages		= dma_common_free_pages,
-	.alloc_noncoherent	= iommu_dma_alloc_noncoherent,
-	.free_noncoherent	= iommu_dma_free_noncoherent,
 	.mmap			= iommu_dma_mmap,
 	.get_sgtable		= iommu_dma_get_sgtable,
 	.map_page		= iommu_dma_map_page,
diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h
index a5f89fc4d6df..3d1f91464bcf 100644
--- a/include/linux/dma-map-ops.h
+++ b/include/linux/dma-map-ops.h
@@ -22,11 +22,6 @@ struct dma_map_ops {
 			gfp_t gfp);
 	void (*free_pages)(struct device *dev, size_t size, struct page *vaddr,
 			dma_addr_t dma_handle, enum dma_data_direction dir);
-	void *(*alloc_noncoherent)(struct device *dev, size_t size,
-			dma_addr_t *dma_handle, enum dma_data_direction dir,
-			gfp_t gfp);
-	void (*free_noncoherent)(struct device *dev, size_t size, void *vaddr,
-			dma_addr_t dma_handle, enum dma_data_direction dir);
 	int (*mmap)(struct device *, struct vm_area_struct *,
 			void *, dma_addr_t, size_t, unsigned long attrs);
 
diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c
index 51bb8fa8eb89..d3032513c54b 100644
--- a/kernel/dma/mapping.c
+++ b/kernel/dma/mapping.c
@@ -514,40 +514,19 @@ EXPORT_SYMBOL_GPL(dma_free_pages);
 void *dma_alloc_noncoherent(struct device *dev, size_t size,
 		dma_addr_t *dma_handle, enum dma_data_direction dir, gfp_t gfp)
 {
-	const struct dma_map_ops *ops = get_dma_ops(dev);
-	void *vaddr;
-
-	if (!ops || !ops->alloc_noncoherent) {
-		struct page *page;
-
-		page = dma_alloc_pages(dev, size, dma_handle, dir, gfp);
-		if (!page)
-			return NULL;
-		return page_address(page);
-	}
+	struct page *page;
 
-	size = PAGE_ALIGN(size);
-	vaddr = ops->alloc_noncoherent(dev, size, dma_handle, dir, gfp);
-	if (vaddr)
-		debug_dma_map_page(dev, virt_to_page(vaddr), 0, size, dir,
-				   *dma_handle);
-	return vaddr;
+	page = dma_alloc_pages(dev, size, dma_handle, dir, gfp);
+	if (!page)
+		return NULL;
+	return page_address(page);
 }
 EXPORT_SYMBOL_GPL(dma_alloc_noncoherent);
 
 void dma_free_noncoherent(struct device *dev, size_t size, void *vaddr,
 		dma_addr_t dma_handle, enum dma_data_direction dir)
 {
-	const struct dma_map_ops *ops = get_dma_ops(dev);
-
-	if (!ops || !ops->free_noncoherent) {
-		dma_free_pages(dev, size, virt_to_page(vaddr), dma_handle, dir);
-		return;
-	}
-
-	size = PAGE_ALIGN(size);
-	debug_dma_unmap_page(dev, dma_handle, size, dir);
-	ops->free_noncoherent(dev, size, vaddr, dma_handle, dir);
+	dma_free_pages(dev, size, virt_to_page(vaddr), dma_handle, dir);
 }
 EXPORT_SYMBOL_GPL(dma_free_noncoherent);
 
-- 
2.29.2.454.gaff20da3a2-goog


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-02-01 16:38 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-28 14:58 add a new dma_alloc_noncontiguous API Christoph Hellwig
2021-01-28 14:58 ` [PATCH 1/6] dma-mapping: remove the {alloc,free}_noncoherent methods Christoph Hellwig
2021-01-28 14:58 ` [PATCH 2/6] dma-mapping: add a dma_mmap_pages helper Christoph Hellwig
2021-01-28 15:41   ` David Laight
2021-01-28 14:58 ` [PATCH 3/6] dma-mapping: add a dma_alloc_noncontiguous API Christoph Hellwig
2021-01-28 14:58 ` [PATCH 4/6] dma-iommu: refactor iommu_dma_alloc_remap Christoph Hellwig
2021-01-28 14:58 ` [PATCH 5/6] dma-iommu: implement ->alloc_noncontiguous Christoph Hellwig
2021-01-28 14:58 ` [PATCH 6/6] media: uvcvideo: Use dma_alloc_noncontiguos API Christoph Hellwig
2021-01-28 15:09   ` Christoph Hellwig
2021-01-28 17:00     ` Ricardo Ribalda
2021-02-01 16:37       ` Christoph Hellwig
2021-01-28 16:43   ` Ricardo Ribalda
  -- strict thread matches above, loose matches on Subject: below --
2020-11-24 15:38 [PATCH 1/6] dma-mapping: remove the {alloc,free}_noncoherent methods Ricardo Ribalda

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).