cleanup
[linux-2.4.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
35 /*
36    If UNSAFE_MEMCPY is defined, we use the (optimized) system routines
37    to copy between a card and kernel memory.  These routines do 32-bit
38    operations which may not work with all PCMCIA controllers.  The
39    safe versions defined here will do only 8-bit and 16-bit accesses.
40 */
41
42 #ifdef UNSAFE_MEMCPY
43
44 #define copy_from_pc memcpy_fromio
45 #define copy_to_pc memcpy_toio
46
47 static inline void copy_pc_to_user(void *to, const void *from, size_t n)
48 {
49     size_t odd = (n & 3);
50     n -= odd;
51     while (n) {
52         put_user(__raw_readl(from), (int *)to);
53         (char *)from += 4; (char *)to += 4; n -= 4;
54     }
55     while (odd--)
56         put_user(readb((char *)from++), (char *)to++);
57 }
58
59 static inline void copy_user_to_pc(void *to, const void *from, size_t n)
60 {
61     int l;
62     char c;
63     size_t odd = (n & 3);
64     n -= odd;
65     while (n) {
66         get_user(l, (int *)from);
67         __raw_writel(l, to);
68         (char *)to += 4; (char *)from += 4; n -= 4;
69     }
70     while (odd--) {
71         get_user(c, (char *)from++);
72         writeb(c, (char *)to++);
73     }
74 }
75
76 #else /* UNSAFE_MEMCPY */
77
78 static inline void copy_from_pc(void *to, const void *from, size_t n)
79 {
80     size_t odd = (n & 1);
81     n -= odd;
82     while (n) {
83         *(u_short *)to = __raw_readw(from);
84         to = (void *)((long)to + 2);
85         from = (const void *)((long)from + 2);
86         n -= 2;
87     }
88     if (odd)
89         *(u_char *)to = readb(from);
90 }
91
92 static inline void copy_to_pc(void *to, const void *from, size_t n)
93 {
94     size_t odd = (n & 1);
95     n -= odd;
96     while (n) {
97         __raw_writew(*(u_short *)from, to);
98         to = (void *)((long)to + 2);
99         from = (const void *)((long)from + 2);
100         n -= 2;
101     }
102     if (odd)
103         writeb(*(u_char *)from, to);
104 }
105
106 static inline void copy_pc_to_user(void *to, const void *from, size_t n)
107 {
108     size_t odd = (n & 1);
109     n -= odd;
110     while (n) {
111         put_user(__raw_readw(from), (short *)to);
112         to = (void *)((long)to + 2);
113         from = (const void *)((long)from + 2);
114         n -= 2;
115     }
116     if (odd)
117         put_user(readb(from), (char *)to);
118 }
119
120 static inline void copy_user_to_pc(void *to, const void *from, size_t n)
121 {
122     short s;
123     char c;
124     size_t odd = (n & 1);
125     n -= odd;
126     while (n) {
127         get_user(s, (short *)from);
128         __raw_writew(s, to);
129         to = (void *)((long)to + 2);
130         from = (const void *)((long)from + 2);
131         n -= 2;
132     }
133     if (odd) {
134         get_user(c, (char *)from);
135         writeb(c, to);
136     }
137 }
138
139 #endif /* UNSAFE_MEMCPY */
140
141 #endif /* _LINUX_MEM_OP_H */