linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] include/asm-ppc/dma-mapping.h macro patch
@ 2004-12-07 13:20 Jason McMullan
  2004-12-07 15:03 ` Christoph Hellwig
  0 siblings, 1 reply; 3+ messages in thread
From: Jason McMullan @ 2004-12-07 13:20 UTC (permalink / raw)
  To: linuxppc-dev, linuxppc-embedded, linux-kernel

Signed-off-by: Jason McMullan <jason.mcmullan@timesys.com>
Summary: [ppc] dma-mapping.h - Fix macro semantics
Description:
	This patch makes the macros for dma_* semantically
	equivalent to the functions they mask. For example,
	dma_cache_inv(func_with_side_effects(), sizeof(foo))
	will execure 'func_with_side_effects()' in the function
	case, but would not execute it in the macro case.
	This patch fixes this discrepancy.
Comment: More landmines like this may be all over the kernel.
	 Janitor project, anyone?


--- linux-2.6.9.old/include/asm-ppc/dma-mapping.h	2004-12-07 08:14:32.769502853 -0500
+++ linux-2.6.9/include/asm-ppc/dma-mapping.h	2004-12-07 08:14:02.777362775 -0500
@@ -36,22 +36,22 @@
  * Cache coherent cores.
  */
 
-#define dma_cache_inv(_start,_size)		do { } while (0)
-#define dma_cache_wback(_start,_size)		do { } while (0)
-#define dma_cache_wback_inv(_start,_size)	do { } while (0)
-
-#define __dma_alloc_coherent(gfp, size, handle)	NULL
-#define __dma_free_coherent(size, addr)		do { } while (0)
-#define __dma_sync(addr, size, rw)		do { } while (0)
-#define __dma_sync_page(pg, off, sz, rw)	do { } while (0)
+#define dma_cache_inv(_start,_size)		do { (void)(_start); (void)(_size); } while (0)
+#define dma_cache_wback(_start,_size)		do { (void)(_start); (void)(_size); } while (0)
+#define dma_cache_wback_inv(_start,_size)	do { (void)(_start); (void)(_size); } while (0)
+
+#define __dma_alloc_coherent(gfp, size, handle)	((void)(gfp),(void)(size),(void)(handle),NULL)
+#define __dma_free_coherent(size, addr)		do { (void)(size); (void)(addr); } while (0)
+#define __dma_sync(addr, size, rw)		do { (void)(addr); (void)(size); (void)(rw); } while (0)
+#define __dma_sync_page(pg, off, sz, rw)	do { (void)(pg); (void)(off); (void)(sz); (void)(rw); } while (0)
 
 #endif /* ! CONFIG_NOT_COHERENT_CACHE */
 
-#define dma_supported(dev, mask)	(1)
+#define dma_supported(dev, mask)	((void)(dev), (void)(mask), 1)
 
 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
 {
-	if (!dev->dma_mask || !dma_supported(dev, mask))
+	if (!dev->dma_mask || !dma_supported(dev, dma_mask))
 		return -EIO;
 
 	*dev->dma_mask = dma_mask;
@@ -121,7 +121,7 @@
 }
 
 /* We do nothing. */
-#define dma_unmap_page(dev, handle, size, dir)	do { } while (0)
+#define dma_unmap_page(dev, handle, size, dir)	do { (void)(dev); (void)(handle); (void)(size); (void)(dir); } while (0)
 
 static inline int
 dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
@@ -141,7 +141,7 @@
 }
 
 /* We don't do anything here. */
-#define dma_unmap_sg(dev, sg, nents, dir)	do { } while (0)
+#define dma_unmap_sg(dev, sg, nents, dir)	do { (void)(dev); (void)(sg); (void)(nents); (void)(dir); } while (0)
 
 static inline void
 dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
@@ -190,9 +190,9 @@
 #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)
 #ifdef CONFIG_NOT_COHERENT_CACHE
-#define dma_is_consistent(d)	(0)
+#define dma_is_consistent(d)	((void)(d), 0)
 #else
-#define dma_is_consistent(d)	(1)
+#define dma_is_consistent(d)	((void)(d), 1)
 #endif
 
 static inline int dma_get_cache_alignment(void)
-- 
Jason McMullan <jason.mcmullan@timesys.com>
TimeSys Corporation

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

* Re: [PATCH] include/asm-ppc/dma-mapping.h macro patch
  2004-12-07 13:20 Jason McMullan
@ 2004-12-07 15:03 ` Christoph Hellwig
  0 siblings, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2004-12-07 15:03 UTC (permalink / raw)
  To: Jason McMullan; +Cc: linuxppc-dev, linux-kernel, linuxppc-embedded

> +#define dma_cache_inv(_start,_size)		do { (void)(_start); (void)(_size); } while (0)

this looks really horrible.  What about turning these into inlines?

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

* Re: [PATCH] include/asm-ppc/dma-mapping.h macro patch
@ 2004-12-08 16:41 Jason McMullan
  0 siblings, 0 replies; 3+ messages in thread
From: Jason McMullan @ 2004-12-08 16:41 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: linuxppc-dev, linux-kernel, linuxppc-embedded

On Tue, 2004-12-07 at 15:03 +0000, Christoph Hellwig wrote:
> +#define dma_cache_inv(_start,_size)		do { (void)(_start);
> (void)(_size); } while (0)
> 
> this looks really horrible.  What about turning these into inlines?
> 

Sure thing:

Signed-off-by: Jason McMullan <jason.mcmullan@timesys.com>
Summary: [ppc] dma-mapping.h - Fix macro semantics
Release: Dec 8, 2004
Description:
        This patch makes the macros for dma_* semantically
        equivalent to the functions they mask. For example,
        dma_cache_inv(func_with_side_effects(), sizeof(foo))
        will execure 'func_with_side_effects()' in the function
        case, but would not execute it in the macro case.
        This patch fixes this discrepancy using 'static inline'
	functions.

--- linux-orig/include/asm-ppc/dma-mapping.h
+++ linux/include/asm-ppc/dma-mapping.h
@@ -24,34 +24,43 @@
 extern void __dma_sync(void *vaddr, size_t size, int direction);
 extern void __dma_sync_page(struct page *page, unsigned long offset,
 				 size_t size, int direction);
-#define dma_cache_inv(_start,_size) \
-	invalidate_dcache_range(_start, (_start + _size))
-#define dma_cache_wback(_start,_size) \
-	clean_dcache_range(_start, (_start + _size))
-#define dma_cache_wback_inv(_start,_size) \
-	flush_dcache_range(_start, (_start + _size))
+
+static inline void dma_cache_inv(unsigned long _start,size_t _size)
+{
+	invalidate_dcache_range(_start, (_start + _size));
+}
+
+static inline void dma_cache_wback(unsigned long _start,size_t _size)
+{
+	clean_dcache_range(_start, (_start + _size));
+}
+
+static inline void dma_cache_wback_inv(unsigned long _start,size_t _size)
+{
+	flush_dcache_range(_start, (_start + _size));
+}
 
 #else /* ! CONFIG_NOT_COHERENT_CACHE */
 /*
  * Cache coherent cores.
  */
 
-#define dma_cache_inv(_start,_size)		do { } while (0)
-#define dma_cache_wback(_start,_size)		do { } while (0)
-#define dma_cache_wback_inv(_start,_size)	do { } while (0)
+static inline void dma_cache_inv(unsigned long _start,size_t _size) {}
+static inline void dma_cache_wback(unsigned long _start,size_t _size) {}
+static inline void dma_cache_wback_inv(unsigned long _start,size_t _size) {}
 
-#define __dma_alloc_coherent(gfp, size, handle)	NULL
-#define __dma_free_coherent(size, addr)		do { } while (0)
-#define __dma_sync(addr, size, rw)		do { } while (0)
-#define __dma_sync_page(pg, off, sz, rw)	do { } while (0)
+static inline void *__dma_alloc_coherent(size_t size, dma_addr_t handle, int gfp) { return NULL; }
+static inline void __dma_free_coherent(size_t size, void *vaddr) {}
+static inline void __dma_sync(void *vaddr, size_t size, int rw) {}
+static inline void __dma_sync_page(struct page *pg, unsigned long off, size_t sz, int rw) {}
 
 #endif /* ! CONFIG_NOT_COHERENT_CACHE */
 
-#define dma_supported(dev, mask)	(1)
+static inline int dma_supported(struct device *dev, u64 dma_mask) { return 1; }
 
 static inline int dma_set_mask(struct device *dev, u64 dma_mask)
 {
-	if (!dev->dma_mask || !dma_supported(dev, mask))
+	if (!dev->dma_mask || !dma_supported(dev, dma_mask))
 		return -EIO;
 
 	*dev->dma_mask = dma_mask;
@@ -106,7 +115,11 @@
 }
 
 /* We do nothing. */
-#define dma_unmap_single(dev, addr, size, dir)	do { } while (0)
+static inline void
+dma_unmap_single(struct device *dev, unsigned long addr, size_t size,
+	         enum dma_data_direction direction)
+{
+}
 
 static inline dma_addr_t
 dma_map_page(struct device *dev, struct page *page,
@@ -121,7 +134,9 @@
 }
 
 /* We do nothing. */
-#define dma_unmap_page(dev, handle, size, dir)	do { } while (0)
+static inline void
+dma_unmap_page(struct device *dev, dma_addr_t dma_handle,
+		size_t size, enum dma_data_direction direction) {}
 
 static inline int
 dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
@@ -141,7 +156,9 @@
 }
 
 /* We don't do anything here. */
-#define dma_unmap_sg(dev, sg, nents, dir)	do { } while (0)
+static inline void
+dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
+	     enum dma_data_direction dir) {}
 
 static inline void
 dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle,
@@ -190,9 +207,9 @@
 #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)
 #ifdef CONFIG_NOT_COHERENT_CACHE
-#define dma_is_consistent(d)	(0)
+static inline int dma_is_consistent(dma_addr_t dma_handle) { return 0; }
 #else
-#define dma_is_consistent(d)	(1)
+static inline int dma_is_consistent(dma_addr_t dma_handle) { return 1; }
 #endif
 
 static inline int dma_get_cache_alignment(void)

-- 
Jason McMullan <jason.mcmullan@timesys.com>
TimeSys Corporation

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

end of thread, other threads:[~2004-12-08 16:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-08 16:41 [PATCH] include/asm-ppc/dma-mapping.h macro patch Jason McMullan
  -- strict thread matches above, loose matches on Subject: below --
2004-12-07 13:20 Jason McMullan
2004-12-07 15:03 ` Christoph Hellwig

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