1 #include <linux/string.h> 2 #include <linux/module.h> 3 #include <linux/io.h> 4 5 /* Originally from i386/string.h */ 6 static __always_inline void __iomem_memcpy(void *to, const void *from, size_t n) 7 { 8 unsigned long d0, d1, d2; 9 asm volatile("rep ; movsl\n\t" 10 "testb $2,%b4\n\t" 11 "je 1f\n\t" 12 "movsw\n" 13 "1:\ttestb $1,%b4\n\t" 14 "je 2f\n\t" 15 "movsb\n" 16 "2:" 17 : "=&c" (d0), "=&D" (d1), "=&S" (d2) 18 : "0" (n / 4), "q" (n), "1" ((long)to), "2" ((long)from) 19 : "memory"); 20 } 21 22 void memcpy_fromio(void *to, const volatile void __iomem *from, size_t n) 23 { 24 __iomem_memcpy(to, (const void *)from, n); 25 } 26 EXPORT_SYMBOL(memcpy_fromio); 27 28 void memcpy_toio(volatile void __iomem *to, const void *from, size_t n) 29 { 30 __iomem_memcpy((void *)to, (const void *) from, n); 31 } 32 EXPORT_SYMBOL(memcpy_toio); 33 34 void memset_io(volatile void __iomem *a, int b, size_t c) 35 { 36 /* 37 * TODO: memset can mangle the IO patterns quite a bit. 38 * perhaps it would be better to use a dumb one: 39 */ 40 memset((void *)a, b, c); 41 } 42 EXPORT_SYMBOL(memset_io); 43