Skip to contentSkip to conversation

sparc: unify dma-mapping_32.h and dma-mapping_64.h

PATCH In review FUJITA Tomonori 4 participants 11 messages May 15, 2009 – Jun 11, 2009 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

cover sparc: unify dma-mapping_32.h and dma-mapping_64.h

This patchset unifies dma-mapping_32.h and dma-mapping_64.h, that is, it uses dma-mapping.h instead and removes dma-mapping_32.h and dma-mapping_64.h.

In short, this patchset modifies SPARC32 to use struct dma_map ops.

I like to see architectures implement the dma API in the similar way.

Thanks,

 arch/sparc/include/asm/dma-mapping.h    |  168 ++++++++++++++++++++++++++++++-
 arch/sparc/include/asm/dma-mapping_32.h |   60 -----------
 arch/sparc/include/asm/dma-mapping_64.h |  154 ----------------------------
 arch/sparc/kernel/dma.c                 |  127 +++++++----------------
 arch/sparc/kernel/iommu.c               |   15 ++--
 arch/sparc/kernel/pci_sun4v.c           |   15 ++--
 6 files changed, 218 insertions(+), 321 deletions(-)
#1 lore raw

PATCH 1/4 sparc: move the duplication in dma-mapping_{32|64}.h to dma-mapping.h

---
 arch/sparc/include/asm/dma-mapping.h    |   42 +++++++++++++++++++++++++++++++
 arch/sparc/include/asm/dma-mapping_32.h |   18 -------------
 arch/sparc/include/asm/dma-mapping_64.h |   40 -----------------------------
 arch/sparc/kernel/dma.c                 |   30 ----------------------
 4 files changed, 42 insertions(+), 88 deletions(-)
arch/sparc/include/asm/dma-mapping.h +42 -0
index 0f4150e..8c911ea 100644
@@ -5,4 +5,46 @@
 #else
 #include <asm/dma-mapping_32.h>
 #endif
+
+#define DMA_ERROR_CODE	(~(dma_addr_t)0x0)
+
+extern int dma_supported(struct device *dev, u64 mask);
+extern int dma_set_mask(struct device *dev, u64 dma_mask);
+
+static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
+{
+	return (dma_addr = DMA_ERROR_CODE);
+}
+
+static inline int dma_get_cache_alignment(void)
+{
+	/*
+	 * no easy way to get cache size on all processors, so return
+	 * the maximum possible, to be safe
+	 */
+	return (1 << INTERNODE_CACHE_SHIFT);
+}
+
+#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
+#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
+#define dma_is_consistent(d, h)	(1)
+
+static inline void dma_sync_single_range_for_cpu(struct device *dev,
+						 dma_addr_t dma_handle,
+						 unsigned long offset,
+						 size_t size,
+						 enum dma_data_direction dir)
+{
+	dma_sync_single_for_cpu(dev, dma_handle+offset, size, dir);
+}
+
+static inline void dma_sync_single_range_for_device(struct device *dev,
+						    dma_addr_t dma_handle,
+						    unsigned long offset,
+						    size_t size,
+						    enum dma_data_direction dir)
+{
+	dma_sync_single_for_device(dev, dma_handle+offset, size, dir);
+}
+
 #endif
arch/sparc/include/asm/dma-mapping_32.h +0 -18
index 8a57ea0..7f09c85 100644
@@ -7,10 +7,6 @@ struct device;
 struct scatterlist;
 struct page;
 
-#define DMA_ERROR_CODE	(~(dma_addr_t)0x0)
-
-extern int dma_supported(struct device *dev, u64 mask);
-extern int dma_set_mask(struct device *dev, u64 dma_mask);
 extern void *dma_alloc_coherent(struct device *dev, size_t size,
 				dma_addr_t *dma_handle, gfp_t flag);
 extern void dma_free_coherent(struct device *dev, size_t size,
@@ -37,24 +33,10 @@ extern void dma_sync_single_for_device(struct device *dev,
 				       dma_addr_t dma_handle,
 				       size_t size,
 				       enum dma_data_direction direction);
-extern void dma_sync_single_range_for_cpu(struct device *dev,
-					  dma_addr_t dma_handle,
-					  unsigned long offset,
-					  size_t size,
-					  enum dma_data_direction direction);
-extern void dma_sync_single_range_for_device(struct device *dev,
-					     dma_addr_t dma_handle,
-					     unsigned long offset, size_t size,
-					     enum dma_data_direction direction);
 extern void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
 				int nelems, enum dma_data_direction direction);
 extern void dma_sync_sg_for_device(struct device *dev,
 				   struct scatterlist *sg, int nelems,
 				   enum dma_data_direction direction);
-extern int dma_mapping_error(struct device *dev, dma_addr_t dma_addr);
-extern int dma_get_cache_alignment(void);
-
-#define dma_alloc_noncoherent	dma_alloc_coherent
-#define dma_free_noncoherent	dma_free_coherent
 
 #endif /* _ASM_SPARC_DMA_MAPPING_H */
arch/sparc/include/asm/dma-mapping_64.h +0 -40
index bfa64f9..017ae70 100644
@@ -4,8 +4,6 @@
 #include <linux/scatterlist.h>
 #include <linux/mm.h>
 
-#define DMA_ERROR_CODE	(~(dma_addr_t)0x0)
-
 struct dma_ops {
 	void *(*alloc_coherent)(struct device *dev, size_t size,
 				dma_addr_t *dma_handle, gfp_t flag);
@@ -31,9 +29,6 @@ struct dma_ops {
 };
 extern const struct dma_ops *dma_ops;
 
-extern int dma_supported(struct device *dev, u64 mask);
-extern int dma_set_mask(struct device *dev, u64 dma_mask);
-
 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
 				       dma_addr_t *dma_handle, gfp_t flag)
 {
@@ -102,25 +97,6 @@ static inline void dma_sync_single_for_device(struct device *dev,
 	/* No flushing needed to sync cpu writes to the device.  */
 }
 
-static inline void dma_sync_single_range_for_cpu(struct device *dev,
-						 dma_addr_t dma_handle,
-						 unsigned long offset,
-						 size_t size,
-						 enum dma_data_direction direction)
-{
-	dma_sync_single_for_cpu(dev, dma_handle+offset, size, direction);
-}
-
-static inline void dma_sync_single_range_for_device(struct device *dev,
-						    dma_addr_t dma_handle,
-						    unsigned long offset,
-						    size_t size,
-						    enum dma_data_direction direction)
-{
-	/* No flushing needed to sync cpu writes to the device.  */
-}
-
-
 static inline void dma_sync_sg_for_cpu(struct device *dev,
 				       struct scatterlist *sg, int nelems,
 				       enum dma_data_direction direction)
@@ -135,20 +111,4 @@ static inline void dma_sync_sg_for_device(struct device *dev,
 	/* No flushing needed to sync cpu writes to the device.  */
 }
 
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-	return (dma_addr = DMA_ERROR_CODE);
-}
-
-static inline int dma_get_cache_alignment(void)
-{
-	/* no easy way to get cache size on all processors, so return
-	 * the maximum possible, to be safe */
-	return (1 << INTERNODE_CACHE_SHIFT);
-}
-
-#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
-#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
-#define dma_is_consistent(d, h)	(1)
-
 #endif /* _ASM_SPARC64_DMA_MAPPING_H */
arch/sparc/kernel/dma.c +0 -30
index ebc8403..3c9ff4f 100644
@@ -167,24 +167,6 @@ void dma_sync_single_for_device(struct device *dev, dma_addr_t dma_handle,
 }
 EXPORT_SYMBOL(dma_sync_single_for_device);
 
-void dma_sync_single_range_for_cpu(struct device *dev,
-				   dma_addr_t dma_handle,
-				   unsigned long offset,
-				   size_t size,
-				   enum dma_data_direction direction)
-{
-	dma_sync_single_for_cpu(dev, dma_handle+offset, size, direction);
-}
-EXPORT_SYMBOL(dma_sync_single_range_for_cpu);
-
-void dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
-				      unsigned long offset, size_t size,
-				      enum dma_data_direction direction)
-{
-	dma_sync_single_for_device(dev, dma_handle+offset, size, direction);
-}
-EXPORT_SYMBOL(dma_sync_single_range_for_device);
-
 void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
 			 int nelems, enum dma_data_direction direction)
 {
@@ -213,15 +195,3 @@ void dma_sync_sg_for_device(struct device *dev,
 	BUG();
 }
 EXPORT_SYMBOL(dma_sync_sg_for_device);
-
-int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-	return (dma_addr = DMA_ERROR_CODE);
-}
-EXPORT_SYMBOL(dma_mapping_error);
-
-int dma_get_cache_alignment(void)
-{
-	return 32;
-}
-EXPORT_SYMBOL(dma_get_cache_alignment);
Signature · 1 line
1.6.0.6
#2 lore raw

PATCH 1/4 sparc: move the duplication in dma-mapping_{32|64}.h to dma-mapping.h

From: FUJITA Tomonori <[email protected]>

This patchset unifies dma-mapping_32.h and dma-mapping_64.h, that is, it uses dma-mapping.h instead and removes dma-mapping_32.h and dma-mapping_64.h.

In short, this patchset modifies SPARC32 to use struct dma_map ops.

I like to see architectures implement the dma API in the similar way.

This patch:

Move the duplication in dma-mapping_{32|64}.h to dma-mapping.h.

---

 arch/sparc/include/asm/dma-mapping.h    |   42 ++++++++++++++++++++++
 arch/sparc/include/asm/dma-mapping_32.h |   18 ---------
 arch/sparc/include/asm/dma-mapping_64.h |   40 --------------------
 arch/sparc/kernel/dma.c                 |   30 ---------------
 4 files changed, 42 insertions(+), 88 deletions(-)
arch/sparc/include/asm/dma-mapping.h renamed from arch/sparc/include/asm/dma-mapping.h~sparc-move-the-duplication-in-dma-mapping_3264h-to-dma-mappingh +42 -0
diff -puN arch/sparc/include/asm/dma-mapping.h~sparc-move-the-duplication-in-dma-mapping_3264h-to-dma-mappingh arch/sparc/include/asm/dma-mapping.h
@@ -5,4 +5,46 @@
 #else
 #include <asm/dma-mapping_32.h>
 #endif
+
+#define DMA_ERROR_CODE	(~(dma_addr_t)0x0)
+
+extern int dma_supported(struct device *dev, u64 mask);
+extern int dma_set_mask(struct device *dev, u64 dma_mask);
+
+static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
+{
+	return (dma_addr = DMA_ERROR_CODE);
+}
+
+static inline int dma_get_cache_alignment(void)
+{
+	/*
+	 * no easy way to get cache size on all processors, so return
+	 * the maximum possible, to be safe
+	 */
+	return (1 << INTERNODE_CACHE_SHIFT);
+}
+
+#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
+#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
+#define dma_is_consistent(d, h)	(1)
+
+static inline void dma_sync_single_range_for_cpu(struct device *dev,
+						 dma_addr_t dma_handle,
+						 unsigned long offset,
+						 size_t size,
+						 enum dma_data_direction dir)
+{
+	dma_sync_single_for_cpu(dev, dma_handle+offset, size, dir);
+}
+
+static inline void dma_sync_single_range_for_device(struct device *dev,
+						    dma_addr_t dma_handle,
+						    unsigned long offset,
+						    size_t size,
+						    enum dma_data_direction dir)
+{
+	dma_sync_single_for_device(dev, dma_handle+offset, size, dir);
+}
+
 #endif
arch/sparc/include/asm/dma-mapping_32.h renamed from arch/sparc/include/asm/dma-mapping_32.h~sparc-move-the-duplication-in-dma-mapping_3264h-to-dma-mappingh +0 -18
diff -puN arch/sparc/include/asm/dma-mapping_32.h~sparc-move-the-duplication-in-dma-mapping_3264h-to-dma-mappingh arch/sparc/include/asm/dma-mapping_32.h
@@ -7,10 +7,6 @@ struct device;
 struct scatterlist;
 struct page;
 
-#define DMA_ERROR_CODE	(~(dma_addr_t)0x0)
-
-extern int dma_supported(struct device *dev, u64 mask);
-extern int dma_set_mask(struct device *dev, u64 dma_mask);
 extern void *dma_alloc_coherent(struct device *dev, size_t size,
 				dma_addr_t *dma_handle, gfp_t flag);
 extern void dma_free_coherent(struct device *dev, size_t size,
@@ -37,24 +33,10 @@ extern void dma_sync_single_for_device(s
 				       dma_addr_t dma_handle,
 				       size_t size,
 				       enum dma_data_direction direction);
-extern void dma_sync_single_range_for_cpu(struct device *dev,
-					  dma_addr_t dma_handle,
-					  unsigned long offset,
-					  size_t size,
-					  enum dma_data_direction direction);
-extern void dma_sync_single_range_for_device(struct device *dev,
-					     dma_addr_t dma_handle,
-					     unsigned long offset, size_t size,
-					     enum dma_data_direction direction);
 extern void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
 				int nelems, enum dma_data_direction direction);
 extern void dma_sync_sg_for_device(struct device *dev,
 				   struct scatterlist *sg, int nelems,
 				   enum dma_data_direction direction);
-extern int dma_mapping_error(struct device *dev, dma_addr_t dma_addr);
-extern int dma_get_cache_alignment(void);
-
-#define dma_alloc_noncoherent	dma_alloc_coherent
-#define dma_free_noncoherent	dma_free_coherent
 
 #endif /* _ASM_SPARC_DMA_MAPPING_H */
arch/sparc/include/asm/dma-mapping_64.h renamed from arch/sparc/include/asm/dma-mapping_64.h~sparc-move-the-duplication-in-dma-mapping_3264h-to-dma-mappingh +0 -40
diff -puN arch/sparc/include/asm/dma-mapping_64.h~sparc-move-the-duplication-in-dma-mapping_3264h-to-dma-mappingh arch/sparc/include/asm/dma-mapping_64.h
@@ -4,8 +4,6 @@
 #include <linux/scatterlist.h>
 #include <linux/mm.h>
 
-#define DMA_ERROR_CODE	(~(dma_addr_t)0x0)
-
 struct dma_ops {
 	void *(*alloc_coherent)(struct device *dev, size_t size,
 				dma_addr_t *dma_handle, gfp_t flag);
@@ -31,9 +29,6 @@ struct dma_ops {
 };
 extern const struct dma_ops *dma_ops;
 
-extern int dma_supported(struct device *dev, u64 mask);
-extern int dma_set_mask(struct device *dev, u64 dma_mask);
-
 static inline void *dma_alloc_coherent(struct device *dev, size_t size,
 				       dma_addr_t *dma_handle, gfp_t flag)
 {
@@ -102,25 +97,6 @@ static inline void dma_sync_single_for_d
 	/* No flushing needed to sync cpu writes to the device.  */
 }
 
-static inline void dma_sync_single_range_for_cpu(struct device *dev,
-						 dma_addr_t dma_handle,
-						 unsigned long offset,
-						 size_t size,
-						 enum dma_data_direction direction)
-{
-	dma_sync_single_for_cpu(dev, dma_handle+offset, size, direction);
-}
-
-static inline void dma_sync_single_range_for_device(struct device *dev,
-						    dma_addr_t dma_handle,
-						    unsigned long offset,
-						    size_t size,
-						    enum dma_data_direction direction)
-{
-	/* No flushing needed to sync cpu writes to the device.  */
-}
-
-
 static inline void dma_sync_sg_for_cpu(struct device *dev,
 				       struct scatterlist *sg, int nelems,
 				       enum dma_data_direction direction)
@@ -135,20 +111,4 @@ static inline void dma_sync_sg_for_devic
 	/* No flushing needed to sync cpu writes to the device.  */
 }
 
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-	return (dma_addr = DMA_ERROR_CODE);
-}
-
-static inline int dma_get_cache_alignment(void)
-{
-	/* no easy way to get cache size on all processors, so return
-	 * the maximum possible, to be safe */
-	return (1 << INTERNODE_CACHE_SHIFT);
-}
-
-#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
-#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
-#define dma_is_consistent(d, h)	(1)
-
 #endif /* _ASM_SPARC64_DMA_MAPPING_H */
arch/sparc/kernel/dma.c renamed from arch/sparc/kernel/dma.c~sparc-move-the-duplication-in-dma-mapping_3264h-to-dma-mappingh +0 -30
diff -puN arch/sparc/kernel/dma.c~sparc-move-the-duplication-in-dma-mapping_3264h-to-dma-mappingh arch/sparc/kernel/dma.c
@@ -167,24 +167,6 @@ void dma_sync_single_for_device(struct d
 }
 EXPORT_SYMBOL(dma_sync_single_for_device);
 
-void dma_sync_single_range_for_cpu(struct device *dev,
-				   dma_addr_t dma_handle,
-				   unsigned long offset,
-				   size_t size,
-				   enum dma_data_direction direction)
-{
-	dma_sync_single_for_cpu(dev, dma_handle+offset, size, direction);
-}
-EXPORT_SYMBOL(dma_sync_single_range_for_cpu);
-
-void dma_sync_single_range_for_device(struct device *dev, dma_addr_t dma_handle,
-				      unsigned long offset, size_t size,
-				      enum dma_data_direction direction)
-{
-	dma_sync_single_for_device(dev, dma_handle+offset, size, direction);
-}
-EXPORT_SYMBOL(dma_sync_single_range_for_device);
-
 void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg,
 			 int nelems, enum dma_data_direction direction)
 {
@@ -213,15 +195,3 @@ void dma_sync_sg_for_device(struct devic
 	BUG();
 }
 EXPORT_SYMBOL(dma_sync_sg_for_device);
-
-int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
-{
-	return (dma_addr = DMA_ERROR_CODE);
-}
-EXPORT_SYMBOL(dma_mapping_error);
-
-int dma_get_cache_alignment(void)
-{
-	return 32;
-}
-EXPORT_SYMBOL(dma_get_cache_alignment);

_

#4 lore raw

PATCH 2/4 sparc: add sync_single_for_device and sync_sg_for_device to struct dma_ops

In reply to FUJITA Tomonori

This adds sync_single_for_device() and sync_sg_for_device() to struct
dma_ops in order to unify dma-mpping_{32|64}.h. dma-mpping_32.h needs them though dma-mpping_64.h doesn't.

---
 arch/sparc/include/asm/dma-mapping_64.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
arch/sparc/include/asm/dma-mapping_64.h +6 -0
index 017ae70..0c4fb1f 100644
@@ -23,9 +23,15 @@ struct dma_ops {
 	void (*sync_single_for_cpu)(struct device *dev,
 				    dma_addr_t dma_handle, size_t size,
 				    enum dma_data_direction direction);
+	void (*sync_single_for_device)(struct device *dev,
+				       dma_addr_t dma_handle, size_t size,
+				       enum dma_data_direction direction);
 	void (*sync_sg_for_cpu)(struct device *dev, struct scatterlist *sg,
 				int nelems,
 				enum dma_data_direction direction);
+	void (*sync_sg_for_device)(struct device *dev,
+				   struct scatterlist *sg, int nents,
+				   enum dma_data_direction dir);
 };
 extern const struct dma_ops *dma_ops;
 
Signature · 1 line
1.6.0.6
#5 lore raw

PATCH 3/4 sparc: use dma_map_page instead of dma_map_single

In reply to FUJITA Tomonori

This patch converts dma_map_single and dma_unmap_single to use map_page and unmap_page respectively and removes unnecessary map_single and unmap_single. map_page can be used to implement map_single but the opposite is impossible. Having only dma_map_page in struct dma_ops is enough.

---
 arch/sparc/include/asm/dma-mapping_64.h |   23 ++++++++++++-----------
 arch/sparc/kernel/iommu.c               |   15 ++++++++-------
 arch/sparc/kernel/pci_sun4v.c           |   15 ++++++++-------
 3 files changed, 28 insertions(+), 25 deletions(-)
arch/sparc/include/asm/dma-mapping_64.h +12 -11
index 0c4fb1f..579757e 100644
@@ -9,12 +9,12 @@ struct dma_ops {
 				dma_addr_t *dma_handle, gfp_t flag);
 	void (*free_coherent)(struct device *dev, size_t size,
 			      void *cpu_addr, dma_addr_t dma_handle);
-	dma_addr_t (*map_single)(struct device *dev, void *cpu_addr,
-				 size_t size,
-				 enum dma_data_direction direction);
-	void (*unmap_single)(struct device *dev, dma_addr_t dma_addr,
-			     size_t size,
-			     enum dma_data_direction direction);
+	dma_addr_t (*map_page)(struct device *dev, struct page *page,
+			       unsigned long offset, size_t size,
+			       enum dma_data_direction direction);
+	void (*unmap_page)(struct device *dev, dma_addr_t dma_addr,
+			   size_t size,
+			   enum dma_data_direction direction);
 	int (*map_sg)(struct device *dev, struct scatterlist *sg, int nents,
 		      enum dma_data_direction direction);
 	void (*unmap_sg)(struct device *dev, struct scatterlist *sg,
@@ -51,29 +51,30 @@ static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
 					size_t size,
 					enum dma_data_direction direction)
 {
-	return dma_ops->map_single(dev, cpu_addr, size, direction);
+	return dma_ops->map_page(dev, virt_to_page(cpu_addr),
+				 (unsigned long)cpu_addr & ~PAGE_MASK, size,
+				 direction);
 }
 
 static inline void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
 				    size_t size,
 				    enum dma_data_direction direction)
 {
-	dma_ops->unmap_single(dev, dma_addr, size, direction);
+	dma_ops->unmap_page(dev, dma_addr, size, direction);
 }
 
 static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
 				      unsigned long offset, size_t size,
 				      enum dma_data_direction direction)
 {
-	return dma_ops->map_single(dev, page_address(page) + offset,
-				   size, direction);
+	return dma_ops->map_page(dev, page, offset, size, direction);
 }
 
 static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
 				  size_t size,
 				  enum dma_data_direction direction)
 {
-	dma_ops->unmap_single(dev, dma_address, size, direction);
+	dma_ops->unmap_page(dev, dma_address, size, direction);
 }
 
 static inline int dma_map_sg(struct device *dev, struct scatterlist *sg,
arch/sparc/kernel/iommu.c +8 -7
index d8900e1..0aeaefe 100644
@@ -351,8 +351,9 @@ static void dma_4u_free_coherent(struct device *dev, size_t size,
 		free_pages((unsigned long)cpu, order);
 }
 
-static dma_addr_t dma_4u_map_single(struct device *dev, void *ptr, size_t sz,
-				    enum dma_data_direction direction)
+static dma_addr_t dma_4u_map_page(struct device *dev, struct page *page,
+				  unsigned long offset, size_t sz,
+				  enum dma_data_direction direction)
 {
 	struct iommu *iommu;
 	struct strbuf *strbuf;
@@ -368,7 +369,7 @@ static dma_addr_t dma_4u_map_single(struct device *dev, void *ptr, size_t sz,
 	if (unlikely(direction = DMA_NONE))
 		goto bad_no_ctx;
 
-	oaddr = (unsigned long)ptr;
+	oaddr = (unsigned long)(page_address(page) + offset);
 	npages = IO_PAGE_ALIGN(oaddr + sz) - (oaddr & IO_PAGE_MASK);
 	npages >>= IO_PAGE_SHIFT;
 
@@ -472,8 +473,8 @@ do_flush_sync:
 		       vaddr, ctx, npages);
 }
 
-static void dma_4u_unmap_single(struct device *dev, dma_addr_t bus_addr,
-				size_t sz, enum dma_data_direction direction)
+static void dma_4u_unmap_page(struct device *dev, dma_addr_t bus_addr,
+			      size_t sz, enum dma_data_direction direction)
 {
 	struct iommu *iommu;
 	struct strbuf *strbuf;
@@ -824,8 +825,8 @@ static void dma_4u_sync_sg_for_cpu(struct device *dev,
 static const struct dma_ops sun4u_dma_ops = {
 	.alloc_coherent		= dma_4u_alloc_coherent,
 	.free_coherent		= dma_4u_free_coherent,
-	.map_single		= dma_4u_map_single,
-	.unmap_single		= dma_4u_unmap_single,
+	.map_page		= dma_4u_map_page,
+	.unmap_page		= dma_4u_unmap_page,
 	.map_sg			= dma_4u_map_sg,
 	.unmap_sg		= dma_4u_unmap_sg,
 	.sync_single_for_cpu	= dma_4u_sync_single_for_cpu,
arch/sparc/kernel/pci_sun4v.c +8 -7
index 5db5ebe..2485eaa 100644
@@ -230,8 +230,9 @@ static void dma_4v_free_coherent(struct device *dev, size_t size, void *cpu,
 		free_pages((unsigned long)cpu, order);
 }
 
-static dma_addr_t dma_4v_map_single(struct device *dev, void *ptr, size_t sz,
-				    enum dma_data_direction direction)
+static dma_addr_t dma_4v_map_page(struct device *dev, struct page *page,
+				  unsigned long offset, size_t sz,
+				  enum dma_data_direction direction)
 {
 	struct iommu *iommu;
 	unsigned long flags, npages, oaddr;
@@ -245,7 +246,7 @@ static dma_addr_t dma_4v_map_single(struct device *dev, void *ptr, size_t sz,
 	if (unlikely(direction = DMA_NONE))
 		goto bad;
 
-	oaddr = (unsigned long)ptr;
+	oaddr = (unsigned long)(page_address(page) + offset);
 	npages = IO_PAGE_ALIGN(oaddr + sz) - (oaddr & IO_PAGE_MASK);
 	npages >>= IO_PAGE_SHIFT;
 
@@ -294,8 +295,8 @@ iommu_map_fail:
 	return DMA_ERROR_CODE;
 }
 
-static void dma_4v_unmap_single(struct device *dev, dma_addr_t bus_addr,
-				size_t sz, enum dma_data_direction direction)
+static void dma_4v_unmap_page(struct device *dev, dma_addr_t bus_addr,
+			      size_t sz, enum dma_data_direction direction)
 {
 	struct pci_pbm_info *pbm;
 	struct iommu *iommu;
@@ -537,8 +538,8 @@ static void dma_4v_sync_sg_for_cpu(struct device *dev,
 static const struct dma_ops sun4v_dma_ops = {
 	.alloc_coherent			= dma_4v_alloc_coherent,
 	.free_coherent			= dma_4v_free_coherent,
-	.map_single			= dma_4v_map_single,
-	.unmap_single			= dma_4v_unmap_single,
+	.map_page			= dma_4v_map_page,
+	.unmap_page			= dma_4v_unmap_page,
 	.map_sg				= dma_4v_map_sg,
 	.unmap_sg			= dma_4v_unmap_sg,
 	.sync_single_for_cpu		= dma_4v_sync_single_for_cpu,
Signature · 1 line
1.6.0.6
#6 lore raw

PATCH 4/4 sparc: remove dma-mapping_{32|64}.h

In reply to FUJITA Tomonori

This modifies SPARC32 to use struct dma_map ops. It means that we can remove dma-mapping_{32|64}.h.

---
 arch/sparc/include/asm/dma-mapping.h    |  148 +++++++++++++++++++++++++++----
 arch/sparc/include/asm/dma-mapping_32.h |   42 ---------
 arch/sparc/include/asm/dma-mapping_64.h |  121 -------------------------
 arch/sparc/kernel/dma.c                 |   99 ++++++++------------
 4 files changed, 172 insertions(+), 238 deletions(-)
 delete mode 100644 arch/sparc/include/asm/dma-mapping_32.h
 delete mode 100644 arch/sparc/include/asm/dma-mapping_64.h
arch/sparc/include/asm/dma-mapping.h +132 -16
index 8c911ea..204e4bf 100644
@@ -1,33 +1,134 @@
 #ifndef ___ASM_SPARC_DMA_MAPPING_H
 #define ___ASM_SPARC_DMA_MAPPING_H
-#if defined(__sparc__) && defined(__arch64__)
-#include <asm/dma-mapping_64.h>
-#else
-#include <asm/dma-mapping_32.h>
-#endif
+
+#include <linux/scatterlist.h>
+#include <linux/mm.h>
 
 #define DMA_ERROR_CODE	(~(dma_addr_t)0x0)
 
 extern int dma_supported(struct device *dev, u64 mask);
 extern int dma_set_mask(struct device *dev, u64 dma_mask);
 
-static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
+#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
+#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
+#define dma_is_consistent(d, h)	(1)
+
+struct dma_ops {
+	void *(*alloc_coherent)(struct device *dev, size_t size,
+				dma_addr_t *dma_handle, gfp_t flag);
+	void (*free_coherent)(struct device *dev, size_t size,
+			      void *cpu_addr, dma_addr_t dma_handle);
+	dma_addr_t (*map_page)(struct device *dev, struct page *page,
+			       unsigned long offset, size_t size,
+			       enum dma_data_direction direction);
+	void (*unmap_page)(struct device *dev, dma_addr_t dma_addr,
+			   size_t size,
+			   enum dma_data_direction direction);
+	int (*map_sg)(struct device *dev, struct scatterlist *sg, int nents,
+		      enum dma_data_direction direction);
+	void (*unmap_sg)(struct device *dev, struct scatterlist *sg,
+			 int nhwentries,
+			 enum dma_data_direction direction);
+	void (*sync_single_for_cpu)(struct device *dev,
+				    dma_addr_t dma_handle, size_t size,
+				    enum dma_data_direction direction);
+	void (*sync_single_for_device)(struct device *dev,
+				       dma_addr_t dma_handle, size_t size,
+				       enum dma_data_direction direction);
+	void (*sync_sg_for_cpu)(struct device *dev, struct scatterlist *sg,
+				int nelems,
+				enum dma_data_direction direction);
+	void (*sync_sg_for_device)(struct device *dev,
+				   struct scatterlist *sg, int nents,
+				   enum dma_data_direction dir);
+};
+extern const struct dma_ops *dma_ops;
+
+static inline void *dma_alloc_coherent(struct device *dev, size_t size,
+				       dma_addr_t *dma_handle, gfp_t flag)
 {
-	return (dma_addr = DMA_ERROR_CODE);
+	return dma_ops->alloc_coherent(dev, size, dma_handle, flag);
 }
 
-static inline int dma_get_cache_alignment(void)
+static inline void dma_free_coherent(struct device *dev, size_t size,
+				     void *cpu_addr, dma_addr_t dma_handle)
 {
-	/*
-	 * no easy way to get cache size on all processors, so return
-	 * the maximum possible, to be safe
-	 */
-	return (1 << INTERNODE_CACHE_SHIFT);
+	dma_ops->free_coherent(dev, size, cpu_addr, dma_handle);
 }
 
-#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
-#define dma_free_noncoherent(d, s, v, h) dma_free_coherent(d, s, v, h)
-#define dma_is_consistent(d, h)	(1)
+static inline dma_addr_t dma_map_single(struct device *dev, void *cpu_addr,
+					size_t size,
+					enum dma_data_direction direction)
+{
+	return dma_ops->map_page(dev, virt_to_page(cpu_addr),
+				 (unsigned long)cpu_addr & ~PAGE_MASK, size,
+				 direction);
+}
+
+static inline void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
+				    size_t size,
+				    enum dma_data_direction direction)
+{
+	dma_ops->unmap_page(dev, dma_addr, size, direction);
+}
+
+static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
+				      unsigned long offset, size_t size,
+				      enum dma_data_direction direction)
+{
+	return dma_ops->map_page(dev, page, offset, size, direction);
+}
+
+static inline void dma_unmap_page(struct device *dev, dma_addr_t dma_address,
+				  size_t size,
+				  enum dma_data_direction direction)
+{
+	dma_ops->unmap_page(dev, dma_address, size, direction);
+}
+
+static inline int dma_map_sg(struct device *dev, struct scatterlist *sg,
+			     int nents, enum dma_data_direction direction)
+{
+	return dma_ops->map_sg(dev, sg, nents, direction);
+}
+
+static inline void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
+				int nents, enum dma_data_direction direction)
+{
+	dma_ops->unmap_sg(dev, sg, nents, direction);
+}
+
+static inline void dma_sync_single_for_cpu(struct device *dev,
+					   dma_addr_t dma_handle, size_t size,
+					   enum dma_data_direction direction)
+{
+	dma_ops->sync_single_for_cpu(dev, dma_handle, size, direction);
+}
+
+static inline void dma_sync_single_for_device(struct device *dev,
+					      dma_addr_t dma_handle,
+					      size_t size,
+					      enum dma_data_direction direction)
+{
+	if (dma_ops->sync_single_for_device)
+		dma_ops->sync_single_for_device(dev, dma_handle, size,
+						direction);
+}
+
+static inline void dma_sync_sg_for_cpu(struct device *dev,
+				       struct scatterlist *sg, int nelems,
+				       enum dma_data_direction direction)
+{
+	dma_ops->sync_sg_for_cpu(dev, sg, nelems, direction);
+}
+
+static inline void dma_sync_sg_for_device(struct device *dev,
+					  struct scatterlist *sg, int nelems,
+					  enum dma_data_direction direction)
+{
+	if (dma_ops->sync_sg_for_device)
+		dma_ops->sync_sg_for_device(dev, sg, nelems, direction);
+}
 
 static inline void dma_sync_single_range_for_cpu(struct device *dev,
 						 dma_addr_t dma_handle,
@@ -47,4 +148,19 @@ static inline void dma_sync_single_range_for_device(struct device *dev,
 	dma_sync_single_for_device(dev, dma_handle+offset, size, dir);
 }
 
+
+static inline int dma_mapping_error(struct device *dev, dma_addr_t dma_addr)
+{
+	return (dma_addr = DMA_ERROR_CODE);
+}
+
+static inline int dma_get_cache_alignment(void)
+{
+	/*
+	 * no easy way to get cache size on all processors, so return
+	 * the maximum possible, to be safe
+	 */
+	return (1 << INTERNODE_CACHE_SHIFT);
+}
+
 #endif
arch/sparc/include/asm/dma-mapping_32.h deleted +0 -42

42 lines not on this page · raw message

arch/sparc/include/asm/dma-mapping_64.h deleted +0 -121

121 lines not on this page · raw message

arch/sparc/kernel/dma.c +40 -59

171 lines not on this page · raw message

Signature · 1 line
1.6.0.6
#7 lore raw
In reply to FUJITA Tomonori
Quoted 4 lines · FUJITA Tomonori

This patchset unifies dma-mapping_32.h and dma-mapping_64.h, that is, it uses dma-mapping.h instead and removes dma-mapping_32.h and dma-mapping_64.h.

I just boot tested this patch set on sparc32 and it works fine.

#8 lore raw
Quoted 6 lines · On Thu, 28 May 2009 23:39:20 -0400 Robert Reif <[email protected]> wrote:
Quoted 4 lines · FUJITA Tomonori

This patchset unifies dma-mapping_32.h and dma-mapping_64.h, that is, it uses dma-mapping.h instead and removes dma-mapping_32.h and dma-mapping_64.h.

I just boot tested this patch set on sparc32 and it works fine.

Great, thanks a lot!

David, any comments?

maintainer
#9 lore raw

From: FUJITA Tomonori <[email protected]>
Date: Mon, 1 Jun 2009 11:18:38 +0900

Quoted 8 lines
Quoted 5 lines · On Thu, 28 May 2009 23:39:20 -0400 Robert Reif <[email protected]> wrote:
Quoted 4 lines · FUJITA Tomonori

This patchset unifies dma-mapping_32.h and dma-mapping_64.h, that is, it uses dma-mapping.h instead and removes dma-mapping_32.h and dma-mapping_64.h.

Quoted 5 lines
Quoted 1 line

I just boot tested this patch set on sparc32 and it works fine.

Great, thanks a lot!

David, any comments?

It's simply in my backlog as I've been concentrating exclusively on networking and have had zero time for Sparc lately.

maintainer
#10 lore raw
In reply to Robert Reif

From: Robert Reif <[email protected]>
Date: Thu, 28 May 2009 23:39:20 -0400

Quoted 6 lines
Quoted 4 lines · FUJITA Tomonori

This patchset unifies dma-mapping_32.h and dma-mapping_64.h, that is, it uses dma-mapping.h instead and removes dma-mapping_32.h and dma-mapping_64.h.

I just boot tested this patch set on sparc32 and it works fine.

All applied and I added a tested-by: for Robert to the commits.

Thanks!