Skip to contentSkip to conversation

What types are the parameters of memcpy_toio?

DISCUSSION Roland Dreier 1 participant 2 messages May 17, 2004

lore
Share & tools
lore
#0 lore raw

This may be a silly question, but what are the types of the parameters of memcpy_toio and memcpy_fromio? I was under the impression that IO addresses are "cookies" and not pointers, and hence should be kept as unsigned long.

However, <asm-x86_64/io.h> declares them as

void *memcpy_fromio(void*,const void*,unsigned);
void *memcpy_toio(void*,const void*,unsigned);

which means my code (which uses unsigned long) gets warnings like

warning: passing arg 1 of `memcpy_toio' makes pointer from integer without a cast

Other architectures seem to expect the IO address to be unsigned long and explicitly cast it to a pointer.

Thanks,
Roland

#1 lore raw

memcpy_to/fromio cleanups for x86_64

My query about the types of the parameters for memcpy_toio and memcpy_fromio was met with silence. Maybe some code can speak a little louder.

Here is a patch for x86_64 that brings memcpy_toio and memcpy_fromio more into line with other architectures (my approach is based on what ia64 does), and cleans things up a little.

First of all, it makes the IO address parameter an unsigned long, so that code that treats IO addresses as unsigned long does not get warnings like

warning: passing arg 1 of `memcpy_toio' makes pointer from integer without a cast

Second, I moved the EXPORT_SYMBOL directly into io.c (shrinking x8664_ksyms.c by a few lines). This means that io.o should be moved from lib-y to obj-y, since otherwise __memcpy_toio and __memcpy_fromio might not be included in the kernel.

Comments? Look good? Does anyone care :)?

Thanks,
Roland

arch/x86_64/kernel/x8664_ksyms.c +0 -3
Index: linux-2.6.6/arch/x86_64/kernel/x8664_ksyms.c
===================================================================
@@ -216,6 +216,3 @@
 #endif
 
 EXPORT_SYMBOL(sys_ioctl);
-
-EXPORT_SYMBOL(memcpy_toio);
-EXPORT_SYMBOL(memcpy_fromio);
arch/x86_64/lib/Makefile +3 -1
Index: linux-2.6.6/arch/x86_64/lib/Makefile
===================================================================
@@ -4,9 +4,11 @@
 
 CFLAGS_csum-partial.o := -funroll-loops
 
+obj-y := io.o
+
 lib-y := csum-partial.o csum-copy.o csum-wrappers.o delay.o \
 	usercopy.o getuser.o putuser.o  \
-	thunk.o io.o clear_page.o copy_page.o bitstr.o
+	thunk.o clear_page.o copy_page.o bitstr.o
 lib-y += memcpy.o memmove.o memset.o copy_user.o
 
 lib-$(CONFIG_HAVE_DEC_LOCK) += dec_and_lock.o
arch/x86_64/lib/io.c +6 -4
Index: linux-2.6.6/arch/x86_64/lib/io.c
===================================================================
@@ -2,12 +2,14 @@
 #include <asm/io.h>
 #include <linux/module.h>
 
-void *memcpy_toio(void *dst,const void*src,unsigned len)
+void *__memcpy_toio(unsigned long dst,const void*src,unsigned len)
 {
-	return __inline_memcpy(dst,src,len);
+	return __inline_memcpy((void *) dst,src,len);
 }
+EXPORT_SYMBOL(__memcpy_toio);
 
-void *memcpy_fromio(void *dst,const void*src,unsigned len)
+void *__memcpy_fromio(void *dst,unsigned long src,unsigned len)
 {
-	return __inline_memcpy(dst,src,len);
+	return __inline_memcpy(dst,(const void *) src,len);
 }
+EXPORT_SYMBOL(__memcpy_fromio);
include/asm-x86_64/io.h +7 -2
Index: linux-2.6.6/include/asm-x86_64/io.h
===================================================================
@@ -195,8 +195,13 @@
 #define __raw_writel writel
 #define __raw_writeq writeq
 
-void *memcpy_fromio(void*,const void*,unsigned); 
-void *memcpy_toio(void*,const void*,unsigned); 
+void *__memcpy_fromio(void*,unsigned long,unsigned);
+void *__memcpy_toio(unsigned long,const void*,unsigned);
+
+#define memcpy_fromio(to,from,len) \
+  __memcpy_fromio((to),(unsigned long)(from),(len))
+#define memcpy_toio(to,from,len) \
+  __memcpy_toio((unsigned long)(to),(from),(len))
 #define memset_io(a,b,c)	memset((void *)(a),(b),(c))
 
 /*