public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] add new DMA_ADDR_T_SIZE define
@ 2003-02-19 16:26 Ion Badulescu
  2003-02-19 17:20 ` Randy.Dunlap
  2003-02-19 22:01 ` David S. Miller
  0 siblings, 2 replies; 19+ messages in thread
From: Ion Badulescu @ 2003-02-19 16:26 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

Hi Linus,

This patch adds a new preprocessor define called DMA_ADDR_T_SIZE for all 
architectures, for the benefit of those drivers who care about its size 
(and yes, starfire is one of them).

Alternatives are:

1. a really ugly #ifdef in every single driver, which is error-prone and 
likely to break (see drivers/net/starfire.c around line 274 and have a 
barf bag ready).

2. always cast it to u64, which adds unnecessary overhead to 32-bit 
platforms.

3. use run-time checks all over the place, of the 
"sizeof(dma_addr_t)==sizeof(u64)" kind, which adds unnecessary overhead to 
all platforms.

4. use the results from pci_set_dma_mask(), which still amounts to 
unnecessary run-time overhead on platforms which have a 32-bit dma_addr_t 
to begin with.

So I think a define in each architecture's types.h file is the cleanest 
way to approach this, and that's what my patch does.

Comments and/or suggestions are appreciated.

Thanks,
Ion

-- 
  It is better to keep your mouth shut and be thought a fool,
            than to open it and remove all doubt.
-------------------------------------------------------
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-alpha/types.h linux-2.5.62/include/asm-alpha/types.h
--- linux-2.5.62.vanilla/include/asm-alpha/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-alpha/types.h	Wed Feb 19 10:19:57 2003
@@ -53,6 +53,7 @@
 typedef signed long s64;
 typedef unsigned long u64;
 
+#define DMA_ADDR_T_SIZE 64
 typedef u64 dma_addr_t;
 typedef u64 dma64_addr_t;
 
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-arm/types.h linux-2.5.62/include/asm-arm/types.h
--- linux-2.5.62.vanilla/include/asm-arm/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-arm/types.h	Wed Feb 19 10:19:40 2003
@@ -48,7 +48,7 @@
 typedef unsigned long long u64;
 
 /* Dma addresses are 32-bits wide.  */
-
+#define DMA_ADDR_T_SIZE 32
 typedef u32 dma_addr_t;
 typedef u32 dma64_addr_t;
 
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-cris/types.h linux-2.5.62/include/asm-cris/types.h
--- linux-2.5.62.vanilla/include/asm-cris/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-cris/types.h	Wed Feb 19 10:19:24 2003
@@ -48,7 +48,7 @@
 typedef unsigned long long u64;
 
 /* Dma addresses are 32-bits wide, just like our other addresses.  */
- 
+#define DMA_ADDR_T_SIZE 32
 typedef u32 dma_addr_t;
 
 #endif /* __ASSEMBLY__ */
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-i386/types.h linux-2.5.62/include/asm-i386/types.h
--- linux-2.5.62.vanilla/include/asm-i386/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-i386/types.h	Wed Feb 19 10:19:10 2003
@@ -52,8 +52,10 @@
 /* DMA addresses come in generic and 64-bit flavours.  */
 
 #ifdef CONFIG_HIGHMEM
+#define DMA_ADDR_T_SIZE 64
 typedef u64 dma_addr_t;
 #else
+#define DMA_ADDR_T_SIZE 32
 typedef u32 dma_addr_t;
 #endif
 typedef u64 dma64_addr_t;
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-ia64/types.h linux-2.5.62/include/asm-ia64/types.h
--- linux-2.5.62.vanilla/include/asm-ia64/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-ia64/types.h	Wed Feb 19 10:18:31 2003
@@ -62,7 +62,7 @@
 #define BITS_PER_LONG 64
 
 /* DMA addresses are 64-bits wide, in general.  */
-
+#define DMA_ADDR_T_SIZE 64
 typedef u64 dma_addr_t;
 
 # endif /* __KERNEL__ */
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-m68k/types.h linux-2.5.62/include/asm-m68k/types.h
--- linux-2.5.62.vanilla/include/asm-m68k/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-m68k/types.h	Wed Feb 19 10:18:20 2003
@@ -56,7 +56,7 @@
 typedef unsigned long long u64;
 
 /* DMA addresses are always 32-bits wide */
-
+#define DMA_ADDR_T_SIZE 32
 typedef u32 dma_addr_t;
 typedef u32 dma64_addr_t;
 
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-m68knommu/types.h linux-2.5.62/include/asm-m68knommu/types.h
--- linux-2.5.62.vanilla/include/asm-m68knommu/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-m68knommu/types.h	Wed Feb 19 10:18:02 2003
@@ -56,7 +56,7 @@
 typedef unsigned long long u64;
 
 /* Dma addresses are 32-bits wide.  */
-
+#define DMA_ADDR_T_SIZE 32
 typedef u32 dma_addr_t;
 
 #endif /* __ASSEMBLY__ */
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-mips/types.h linux-2.5.62/include/asm-mips/types.h
--- linux-2.5.62.vanilla/include/asm-mips/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-mips/types.h	Wed Feb 19 10:17:50 2003
@@ -76,6 +76,7 @@
 
 #endif
 
+#define DMA_ADDR_T_SIZE 32			/* XXX is this right? */
 typedef unsigned long dma_addr_t;
 
 #endif /* __ASSEMBLY__ */
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-mips64/types.h linux-2.5.62/include/asm-mips64/types.h
--- linux-2.5.62.vanilla/include/asm-mips64/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-mips64/types.h	Wed Feb 19 10:17:05 2003
@@ -75,6 +75,7 @@
 
 #endif
 
+#define DMA_ADDR_T_SIZE 64			/* XXX is this right? */
 typedef unsigned long dma_addr_t;
 
 #endif /* __ASSEMBLY__ */
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-parisc/types.h linux-2.5.62/include/asm-parisc/types.h
--- linux-2.5.62.vanilla/include/asm-parisc/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-parisc/types.h	Wed Feb 19 10:16:22 2003
@@ -52,7 +52,7 @@
 typedef unsigned long long u64;
 
 /* Dma addresses are 32-bits wide.  */
-
+#define DMA_ADDR_T_SIZE 32
 typedef u32 dma_addr_t;
 typedef u64 dma64_addr_t;
 
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-ppc/types.h linux-2.5.62/include/asm-ppc/types.h
--- linux-2.5.62.vanilla/include/asm-ppc/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-ppc/types.h	Wed Feb 19 10:16:10 2003
@@ -52,6 +52,7 @@
 typedef __vector128 vector128;
 
 /* DMA addresses are 32-bits wide */
+#define DMA_ADDR_T_SIZE 32
 typedef u32 dma_addr_t;
 typedef u64 dma64_addr_t;
 
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-ppc64/types.h linux-2.5.62/include/asm-ppc64/types.h
--- linux-2.5.62.vanilla/include/asm-ppc64/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-ppc64/types.h	Wed Feb 19 10:15:43 2003
@@ -63,6 +63,7 @@
 
 typedef __vector128 vector128;
 
+#define DMA_ADDR_T_SIZE 32
 typedef u32 dma_addr_t;
 typedef u64 dma64_addr_t;
 
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-s390/types.h linux-2.5.62/include/asm-s390/types.h
--- linux-2.5.62.vanilla/include/asm-s390/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-s390/types.h	Wed Feb 19 10:15:32 2003
@@ -60,6 +60,7 @@
 typedef signed long long s64;
 typedef unsigned long long u64;
 
+#define DMA_ADDR_T_SIZE 32
 typedef u32 dma_addr_t;
 
 typedef union {
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-s390x/types.h linux-2.5.62/include/asm-s390x/types.h
--- linux-2.5.62.vanilla/include/asm-s390x/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-s390x/types.h	Wed Feb 19 10:15:18 2003
@@ -61,6 +61,7 @@
 typedef signed long s64;
 typedef unsigned  long u64;
 
+#define DMA_ADDR_T_SIZE 32
 typedef u32 dma_addr_t;
 
 #endif /* __ASSEMBLY__ */
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-sh/types.h linux-2.5.62/include/asm-sh/types.h
--- linux-2.5.62.vanilla/include/asm-sh/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-sh/types.h	Wed Feb 19 10:15:05 2003
@@ -48,7 +48,7 @@
 typedef unsigned long long u64;
 
 /* Dma addresses are 32-bits wide.  */
-
+#define DMA_ADDR_T_SIZE 32
 typedef u32 dma_addr_t;
 
 #endif /* __ASSEMBLY__ */
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-sparc/types.h linux-2.5.62/include/asm-sparc/types.h
--- linux-2.5.62.vanilla/include/asm-sparc/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-sparc/types.h	Wed Feb 19 10:14:47 2003
@@ -51,6 +51,7 @@
 typedef __signed__ long long s64;
 typedef unsigned long long u64;
 
+#define DMA_ADDR_T_SIZE 32
 typedef u32 dma_addr_t;
 typedef u32 dma64_addr_t;
 
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-sparc64/types.h linux-2.5.62/include/asm-sparc64/types.h
--- linux-2.5.62.vanilla/include/asm-sparc64/types.h	Thu Feb 13 15:22:22 2003
+++ linux-2.5.62/include/asm-sparc64/types.h	Wed Feb 19 10:14:31 2003
@@ -52,7 +52,7 @@
 typedef unsigned long u64;
 
 /* Dma addresses come in generic and 64-bit flavours.  */
-
+#define DMA_ADDR_T_SIZE 32
 typedef u32 dma_addr_t;
 typedef u64 dma64_addr_t;
 
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-v850/types.h linux-2.5.62/include/asm-v850/types.h
--- linux-2.5.62.vanilla/include/asm-v850/types.h	Thu Feb 13 15:22:23 2003
+++ linux-2.5.62/include/asm-v850/types.h	Wed Feb 19 10:13:34 2003
@@ -56,7 +56,7 @@
 typedef unsigned long long u64;
 
 /* Dma addresses are 32-bits wide.  */
-
+#define DMA_ADDR_T_SIZE 32
 typedef u32 dma_addr_t;
 
 #endif /* !__ASSEMBLY__ */
diff -urX diff_kernel_excludes linux-2.5.62.vanilla/include/asm-x86_64/types.h linux-2.5.62/include/asm-x86_64/types.h
--- linux-2.5.62.vanilla/include/asm-x86_64/types.h	Thu Feb 13 15:22:23 2003
+++ linux-2.5.62/include/asm-x86_64/types.h	Wed Feb 19 10:13:21 2003
@@ -45,6 +45,7 @@
 typedef signed long long s64;
 typedef unsigned long long u64;
 
+#define DMA_ADDR_T_SIZE 64
 typedef u64 dma64_addr_t;
 typedef u64 dma_addr_t;
 



^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re: [PATCH] add new DMA_ADDR_T_SIZE define
@ 2003-02-19 18:11 James Bottomley
  2003-02-19 18:20 ` Ion Badulescu
  0 siblings, 1 reply; 19+ messages in thread
From: James Bottomley @ 2003-02-19 18:11 UTC (permalink / raw)
  To: Ion Badulescu; +Cc: linux-kernel



> 3. use run-time checks all over the place, of the 
> "sizeof(dma_addr_t)==sizeof(u64)" kind, which adds unnecessary
> overhead to 
> all platforms.

Actually, these aren't technically run time checks.  Although the cpp
can't be used for sizeof(), the compiler (at least gcc) does seem to
have enough sense to optimise away if(..) branches it has enough
information to know won't be taken at compile time.

As long as this optimisation works, I think the if(sizeof(..)) checks
are fine for this.

James




^ permalink raw reply	[flat|nested] 19+ messages in thread
* Re: [PATCH] add new DMA_ADDR_T_SIZE define
@ 2003-02-23  7:02 Albert Cahalan
  2003-02-23  7:00 ` David S. Miller
  0 siblings, 1 reply; 19+ messages in thread
From: Albert Cahalan @ 2003-02-23  7:02 UTC (permalink / raw)
  To: linux-kernel; +Cc: davem, rddunlap

David S. Miller writes:
> On Wed, 2003-02-19 at 09:28, Ion Badulescu wrote:

>> then you're probably debugging, not performance-tuning,
>> so the cast to u64 is acceptable.
>
> Not true, you must cast to 'long long' as there is no
> appropriate printf format string for u64 that works
> warning-free on all systems.

Casts are ugly and they hide bugs. There is a fix
for this problem: make u64 be "unsigned long long"
for every arch. That works for both 32-bit and 64-bit
systems. Likewise, choose "unsigned" for u32 even
if an "unsigned long" would work for a given arch.



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

end of thread, other threads:[~2003-02-23  7:14 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-19 16:26 [PATCH] add new DMA_ADDR_T_SIZE define Ion Badulescu
2003-02-19 17:20 ` Randy.Dunlap
2003-02-19 17:28   ` Ion Badulescu
2003-02-19 22:06     ` David S. Miller
2003-02-19 22:04       ` Ion Badulescu
2003-02-19 22:06   ` David S. Miller
2003-02-19 21:48     ` Jeff Garzik
2003-02-22 10:06       ` Ingo Oeser
2003-02-19 22:01 ` David S. Miller
  -- strict thread matches above, loose matches on Subject: below --
2003-02-19 18:11 James Bottomley
2003-02-19 18:20 ` Ion Badulescu
2003-02-19 22:07   ` David S. Miller
2003-02-19 22:41     ` Ion Badulescu
2003-02-19 22:29       ` David S. Miller
2003-02-19 22:53         ` Ion Badulescu
2003-02-19 22:38           ` David S. Miller
2003-02-23  7:02 Albert Cahalan
2003-02-23  7:00 ` David S. Miller
2003-02-23  7:20   ` Albert Cahalan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox