4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * The initial developer of the original code is David A. Hinds
9 * <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
12 * (C) 1999 David A. Hinds
15 #ifndef _LINUX_MEM_OP_H
16 #define _LINUX_MEM_OP_H
18 #include <asm/uaccess.h>
22 If UNSAFE_MEMCPY is defined, we use the (optimized) system routines
23 to copy between a card and kernel memory. These routines do 32-bit
24 operations which may not work with all PCMCIA controllers. The
25 safe versions defined here will do only 8-bit and 16-bit accesses.
30 #define copy_from_pc memcpy_fromio
31 #define copy_to_pc memcpy_toio
33 static inline void copy_pc_to_user(void *to
, const void *from
, size_t n
)
38 put_user(__raw_readl(from
), (int *)to
);
39 (char *)from
+= 4; (char *)to
+= 4; n
-= 4;
42 put_user(readb((char *)from
++), (char *)to
++);
45 static inline void copy_user_to_pc(void *to
, const void *from
, size_t n
)
52 get_user(l
, (int *)from
);
54 (char *)to
+= 4; (char *)from
+= 4; n
-= 4;
57 get_user(c
, (char *)from
++);
58 writeb(c
, (char *)to
++);
62 #else /* UNSAFE_MEMCPY */
64 static inline void copy_from_pc(void *to
, void __iomem
*from
, size_t n
)
67 __u16 __iomem
*f
= from
;
70 *t
++ = __raw_readw(f
++);
72 *(__u8
*)t
= readb(f
);
75 static inline void copy_to_pc(void __iomem
*to
, const void *from
, size_t n
)
77 __u16 __iomem
*t
= to
;
78 const __u16
*f
= from
;
80 for (n
>>= 1; n
; n
--)
81 __raw_writew(*f
++, t
++);
83 writeb(*(__u8
*)f
, t
);
86 static inline void copy_pc_to_user(void __user
*to
, void __iomem
*from
, size_t n
)
89 __u16 __iomem
*f
= from
;
91 for (n
>>= 1; n
; n
--)
92 put_user(__raw_readw(f
++), t
++);
94 put_user(readb(f
), (char __user
*)t
);
97 static inline void copy_user_to_pc(void __iomem
*to
, void __user
*from
, size_t n
)
99 __u16 __user
*f
= from
;
100 __u16 __iomem
*t
= to
;
103 size_t odd
= (n
& 1);
104 for (n
>>= 1; n
; n
--) {
106 __raw_writew(s
, t
++);
109 get_user(c
, (char __user
*)f
);
114 #endif /* UNSAFE_MEMCPY */
116 #endif /* _LINUX_MEM_OP_H */