ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / pcmcia / mem_op.h
1 /*
2  * mem_op.h 1.13 2000/06/12 21:55:40
3  *
4  * The contents of this file are subject to the Mozilla Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License
7  * at http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific language governing rights and
12  * limitations under the License. 
13  *
14  * The initial developer of the original code is David A. Hinds
15  * <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds
16  * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
17  *
18  * Alternatively, the contents of this file may be used under the
19  * terms of the GNU General Public License version 2 (the "GPL"), in which
20  * case the provisions of the GPL are applicable instead of the
21  * above.  If you wish to allow the use of your version of this file
22  * only under the terms of the GPL and not to allow others to use
23  * your version of this file under the MPL, indicate your decision by
24  * deleting the provisions above and replace them with the notice and
25  * other provisions required by the GPL.  If you do not delete the
26  * provisions above, a recipient may use your version of this file
27  * under either the MPL or the GPL.
28  */
29
30 #ifndef _LINUX_MEM_OP_H
31 #define _LINUX_MEM_OP_H
32
33 #include <asm/uaccess.h>
34 #include <asm/io.h>
35
36 /*
37    If UNSAFE_MEMCPY is defined, we use the (optimized) system routines
38    to copy between a card and kernel memory.  These routines do 32-bit
39    operations which may not work with all PCMCIA controllers.  The
40    safe versions defined here will do only 8-bit and 16-bit accesses.
41 */
42
43 #ifdef UNSAFE_MEMCPY
44
45 #define copy_from_pc memcpy_fromio
46 #define copy_to_pc memcpy_toio
47
48 static inline void copy_pc_to_user(void *to, const void *from, size_t n)
49 {
50     size_t odd = (n & 3);
51     n -= odd;
52     while (n) {
53         put_user(__raw_readl(from), (int *)to);
54         (char *)from += 4; (char *)to += 4; n -= 4;
55     }
56     while (odd--)
57         put_user(readb((char *)from++), (char *)to++);
58 }
59
60 static inline void copy_user_to_pc(void *to, const void *from, size_t n)
61 {
62     int l;
63     char c;
64     size_t odd = (n & 3);
65     n -= odd;
66     while (n) {
67         get_user(l, (int *)from);
68         __raw_writel(l, to);
69         (char *)to += 4; (char *)from += 4; n -= 4;
70     }
71     while (odd--) {
72         get_user(c, (char *)from++);
73         writeb(c, (char *)to++);
74     }
75 }
76
77 #else /* UNSAFE_MEMCPY */
78
79 static inline void copy_from_pc(void *to, const void *from, size_t n)
80 {
81     size_t odd = (n & 1);
82     n -= odd;
83     while (n) {
84         u_short *t = to;
85
86         *t = __raw_readw(from);
87         to = (void *)((long)to + 2);
88         from = (const void *)((long)from + 2);
89         n -= 2;
90     }
91     if (odd)
92         *(u_char *)to = readb(from);
93 }
94
95 static inline void copy_to_pc(void *to, const void *from, size_t n)
96 {
97     size_t odd = (n & 1);
98     n -= odd;
99     while (n) {
100         __raw_writew(*(u_short *)from, to);
101         to = (void *)((long)to + 2);
102         from = (const void *)((long)from + 2);
103         n -= 2;
104     }
105     if (odd)
106         writeb(*(u_char *)from, to);
107 }
108
109 static inline void copy_pc_to_user(void *to, const void *from, size_t n)
110 {
111     size_t odd = (n & 1);
112     n -= odd;
113     while (n) {
114         put_user(__raw_readw(from), (short *)to);
115         to = (void *)((long)to + 2);
116         from = (const void *)((long)from + 2);
117         n -= 2;
118     }
119     if (odd)
120         put_user(readb(from), (char *)to);
121 }
122
123 static inline void copy_user_to_pc(void *to, const void *from, size_t n)
124 {
125     short s;
126     char c;
127     size_t odd = (n & 1);
128     n -= odd;
129     while (n) {
130         get_user(s, (short *)from);
131         __raw_writew(s, to);
132         to = (void *)((long)to + 2);
133         from = (const void *)((long)from + 2);
134         n -= 2;
135     }
136     if (odd) {
137         get_user(c, (char *)from);
138         writeb(c, to);
139     }
140 }
141
142 #endif /* UNSAFE_MEMCPY */
143
144 #endif /* _LINUX_MEM_OP_H */