d5d831ea7bc697c858f50e672fe17332371d509b
[sfrench/cifs-2.6.git] / include / asm-parisc / uaccess.h
1 #ifndef __PARISC_UACCESS_H
2 #define __PARISC_UACCESS_H
3
4 /*
5  * User space memory access functions
6  */
7 #include <asm/page.h>
8 #include <asm/system.h>
9 #include <asm/cache.h>
10 #include <asm-generic/uaccess.h>
11
12 #define VERIFY_READ 0
13 #define VERIFY_WRITE 1
14
15 #define KERNEL_DS       ((mm_segment_t){0})
16 #define USER_DS         ((mm_segment_t){1})
17
18 #define segment_eq(a,b) ((a).seg == (b).seg)
19
20 #define get_ds()        (KERNEL_DS)
21 #define get_fs()        (current_thread_info()->addr_limit)
22 #define set_fs(x)       (current_thread_info()->addr_limit = (x))
23
24 /*
25  * Note that since kernel addresses are in a separate address space on
26  * parisc, we don't need to do anything for access_ok().
27  * We just let the page fault handler do the right thing. This also means
28  * that put_user is the same as __put_user, etc.
29  */
30
31 extern int __get_kernel_bad(void);
32 extern int __get_user_bad(void);
33 extern int __put_kernel_bad(void);
34 extern int __put_user_bad(void);
35
36 static inline long access_ok(int type, const void __user * addr,
37                 unsigned long size)
38 {
39         return 1;
40 }
41
42 #define put_user __put_user
43 #define get_user __get_user
44
45 #if !defined(CONFIG_64BIT)
46 #define LDD_KERNEL(ptr)         __get_kernel_bad();
47 #define LDD_USER(ptr)           __get_user_bad();
48 #define STD_KERNEL(x, ptr)      __put_kernel_asm64(x,ptr)
49 #define STD_USER(x, ptr)        __put_user_asm64(x,ptr)
50 #define ASM_WORD_INSN           ".word\t"
51 #else
52 #define LDD_KERNEL(ptr)         __get_kernel_asm("ldd",ptr)
53 #define LDD_USER(ptr)           __get_user_asm("ldd",ptr)
54 #define STD_KERNEL(x, ptr)      __put_kernel_asm("std",x,ptr)
55 #define STD_USER(x, ptr)        __put_user_asm("std",x,ptr)
56 #define ASM_WORD_INSN           ".dword\t"
57 #endif
58
59 /*
60  * The exception table contains two values: the first is an address
61  * for an instruction that is allowed to fault, and the second is
62  * the address to the fixup routine. 
63  */
64
65 struct exception_table_entry {
66         unsigned long insn;  /* address of insn that is allowed to fault.   */
67         long fixup;          /* fixup routine */
68 };
69
70 /*
71  * The page fault handler stores, in a per-cpu area, the following information
72  * if a fixup routine is available.
73  */
74 struct exception_data {
75         unsigned long fault_ip;
76         unsigned long fault_space;
77         unsigned long fault_addr;
78 };
79
80 #define __get_user(x,ptr)                               \
81 ({                                                      \
82         register long __gu_err __asm__ ("r8") = 0;      \
83         register long __gu_val __asm__ ("r9") = 0;      \
84                                                         \
85         if (segment_eq(get_fs(),KERNEL_DS)) {           \
86             switch (sizeof(*(ptr))) {                   \
87             case 1: __get_kernel_asm("ldb",ptr); break; \
88             case 2: __get_kernel_asm("ldh",ptr); break; \
89             case 4: __get_kernel_asm("ldw",ptr); break; \
90             case 8: LDD_KERNEL(ptr); break;             \
91             default: __get_kernel_bad(); break;         \
92             }                                           \
93         }                                               \
94         else {                                          \
95             switch (sizeof(*(ptr))) {                   \
96             case 1: __get_user_asm("ldb",ptr); break;   \
97             case 2: __get_user_asm("ldh",ptr); break;   \
98             case 4: __get_user_asm("ldw",ptr); break;   \
99             case 8: LDD_USER(ptr);  break;              \
100             default: __get_user_bad(); break;           \
101             }                                           \
102         }                                               \
103                                                         \
104         (x) = (__typeof__(*(ptr))) __gu_val;            \
105         __gu_err;                                       \
106 })
107
108 #define __get_kernel_asm(ldx,ptr)                       \
109         __asm__("\n1:\t" ldx "\t0(%2),%0\n"             \
110                 "\t.section __ex_table,\"aw\"\n"        \
111                 "\t" ASM_WORD_INSN                      \
112                         "1b,fixup_get_user_skip_1\n"    \
113                 "\t.previous"                           \
114                 : "=r"(__gu_val), "=r"(__gu_err)        \
115                 : "r"(ptr), "1"(__gu_err)               \
116                 : "r1");
117
118 #define __get_user_asm(ldx,ptr)                         \
119         __asm__("\n1:\t" ldx "\t0(%%sr3,%2),%0\n"       \
120                 "\t.section __ex_table,\"aw\"\n"        \
121                 "\t" ASM_WORD_INSN                      \
122                         "1b,fixup_get_user_skip_1\n"    \
123                 "\t.previous"                           \
124                 : "=r"(__gu_val), "=r"(__gu_err)        \
125                 : "r"(ptr), "1"(__gu_err)               \
126                 : "r1");
127
128 #define __put_user(x,ptr)                                       \
129 ({                                                              \
130         register long __pu_err __asm__ ("r8") = 0;              \
131         __typeof__(*(ptr)) __x = (__typeof__(*(ptr)))(x);       \
132                                                                 \
133         if (segment_eq(get_fs(),KERNEL_DS)) {                   \
134             switch (sizeof(*(ptr))) {                           \
135             case 1: __put_kernel_asm("stb",__x,ptr); break;     \
136             case 2: __put_kernel_asm("sth",__x,ptr); break;     \
137             case 4: __put_kernel_asm("stw",__x,ptr); break;     \
138             case 8: STD_KERNEL(__x,ptr); break;                 \
139             default: __put_kernel_bad(); break;                 \
140             }                                                   \
141         }                                                       \
142         else {                                                  \
143             switch (sizeof(*(ptr))) {                           \
144             case 1: __put_user_asm("stb",__x,ptr); break;       \
145             case 2: __put_user_asm("sth",__x,ptr); break;       \
146             case 4: __put_user_asm("stw",__x,ptr); break;       \
147             case 8: STD_USER(__x,ptr); break;                   \
148             default: __put_user_bad(); break;                   \
149             }                                                   \
150         }                                                       \
151                                                                 \
152         __pu_err;                                               \
153 })
154
155 /*
156  * The "__put_user/kernel_asm()" macros tell gcc they read from memory
157  * instead of writing. This is because they do not write to any memory
158  * gcc knows about, so there are no aliasing issues. These macros must
159  * also be aware that "fixup_put_user_skip_[12]" are executed in the
160  * context of the fault, and any registers used there must be listed
161  * as clobbers. In this case only "r1" is used by the current routines.
162  * r8/r9 are already listed as err/val.
163  */
164
165 #define __put_kernel_asm(stx,x,ptr)                         \
166         __asm__ __volatile__ (                              \
167                 "\n1:\t" stx "\t%2,0(%1)\n"                 \
168                 "\t.section __ex_table,\"aw\"\n"            \
169                 "\t" ASM_WORD_INSN                          \
170                         "1b,fixup_put_user_skip_1\n"        \
171                 "\t.previous"                               \
172                 : "=r"(__pu_err)                            \
173                 : "r"(ptr), "r"(x), "0"(__pu_err)           \
174                 : "r1")
175
176 #define __put_user_asm(stx,x,ptr)                           \
177         __asm__ __volatile__ (                              \
178                 "\n1:\t" stx "\t%2,0(%%sr3,%1)\n"           \
179                 "\t.section __ex_table,\"aw\"\n"            \
180                 "\t" ASM_WORD_INSN                          \
181                         "1b,fixup_put_user_skip_1\n"        \
182                 "\t.previous"                               \
183                 : "=r"(__pu_err)                            \
184                 : "r"(ptr), "r"(x), "0"(__pu_err)           \
185                 : "r1")
186
187
188 #if !defined(CONFIG_64BIT)
189
190 #define __put_kernel_asm64(__val,ptr) do {                  \
191         u64 __val64 = (u64)(__val);                         \
192         u32 hi = (__val64) >> 32;                           \
193         u32 lo = (__val64) & 0xffffffff;                    \
194         __asm__ __volatile__ (                              \
195                 "\n1:\tstw %2,0(%1)\n"                      \
196                 "\n2:\tstw %3,4(%1)\n"                      \
197                 "\t.section __ex_table,\"aw\"\n"            \
198                  "\t.word\t1b,fixup_put_user_skip_2\n"      \
199                  "\t.word\t2b,fixup_put_user_skip_1\n"      \
200                  "\t.previous"                              \
201                 : "=r"(__pu_err)                            \
202                 : "r"(ptr), "r"(hi), "r"(lo), "0"(__pu_err) \
203                 : "r1");                                    \
204 } while (0)
205
206 #define __put_user_asm64(__val,ptr) do {                    \
207         u64 __val64 = (u64)(__val);                         \
208         u32 hi = (__val64) >> 32;                           \
209         u32 lo = (__val64) & 0xffffffff;                    \
210         __asm__ __volatile__ (                              \
211                 "\n1:\tstw %2,0(%%sr3,%1)\n"                \
212                 "\n2:\tstw %3,4(%%sr3,%1)\n"                \
213                 "\t.section __ex_table,\"aw\"\n"            \
214                  "\t.word\t1b,fixup_put_user_skip_2\n"      \
215                  "\t.word\t2b,fixup_put_user_skip_1\n"      \
216                  "\t.previous"                              \
217                 : "=r"(__pu_err)                            \
218                 : "r"(ptr), "r"(hi), "r"(lo), "0"(__pu_err) \
219                 : "r1");                                    \
220 } while (0)
221
222 #endif /* !defined(CONFIG_64BIT) */
223
224
225 /*
226  * Complex access routines -- external declarations
227  */
228
229 extern unsigned long lcopy_to_user(void __user *, const void *, unsigned long);
230 extern unsigned long lcopy_from_user(void *, const void __user *, unsigned long);
231 extern unsigned long lcopy_in_user(void __user *, const void __user *, unsigned long);
232 extern long lstrncpy_from_user(char *, const char __user *, long);
233 extern unsigned lclear_user(void __user *,unsigned long);
234 extern long lstrnlen_user(const char __user *,long);
235
236 /*
237  * Complex access routines -- macros
238  */
239
240 #define strncpy_from_user lstrncpy_from_user
241 #define strnlen_user lstrnlen_user
242 #define strlen_user(str) lstrnlen_user(str, 0x7fffffffL)
243 #define clear_user lclear_user
244 #define __clear_user lclear_user
245
246 unsigned long copy_to_user(void __user *dst, const void *src, unsigned long len);
247 #define __copy_to_user copy_to_user
248 unsigned long copy_from_user(void *dst, const void __user *src, unsigned long len);
249 #define __copy_from_user copy_from_user
250 unsigned long copy_in_user(void __user *dst, const void __user *src, unsigned long len);
251 #define __copy_in_user copy_in_user
252 #define __copy_to_user_inatomic __copy_to_user
253 #define __copy_from_user_inatomic __copy_from_user
254
255 #endif /* __PARISC_UACCESS_H */