lightnvm: NVM should depend on HAS_DMA
[deliverable/linux.git] / arch / parisc / include / asm / 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/cache.h>
9 #include <asm/errno.h>
10 #include <asm-generic/uaccess-unaligned.h>
11
12 #include <linux/bug.h>
13
14 #define VERIFY_READ 0
15 #define VERIFY_WRITE 1
16
17 #define KERNEL_DS ((mm_segment_t){0})
18 #define USER_DS ((mm_segment_t){1})
19
20 #define segment_eq(a, b) ((a).seg == (b).seg)
21
22 #define get_ds() (KERNEL_DS)
23 #define get_fs() (current_thread_info()->addr_limit)
24 #define set_fs(x) (current_thread_info()->addr_limit = (x))
25
26 /*
27 * Note that since kernel addresses are in a separate address space on
28 * parisc, we don't need to do anything for access_ok().
29 * We just let the page fault handler do the right thing. This also means
30 * that put_user is the same as __put_user, etc.
31 */
32
33 static inline long access_ok(int type, const void __user * addr,
34 unsigned long size)
35 {
36 return 1;
37 }
38
39 #define put_user __put_user
40 #define get_user __get_user
41
42 #if !defined(CONFIG_64BIT)
43 #define LDD_USER(ptr) __get_user_asm64(ptr)
44 #define STD_USER(x, ptr) __put_user_asm64(x, ptr)
45 #else
46 #define LDD_USER(ptr) __get_user_asm("ldd", ptr)
47 #define STD_USER(x, ptr) __put_user_asm("std", x, ptr)
48 #endif
49
50 /*
51 * The exception table contains two values: the first is the relative offset to
52 * the address of the instruction that is allowed to fault, and the second is
53 * the relative offset to the address of the fixup routine. Since relative
54 * addresses are used, 32bit values are sufficient even on 64bit kernel.
55 */
56
57 #define ARCH_HAS_RELATIVE_EXTABLE
58 struct exception_table_entry {
59 int insn; /* relative address of insn that is allowed to fault. */
60 int fixup; /* relative address of fixup routine */
61 };
62
63 #define ASM_EXCEPTIONTABLE_ENTRY( fault_addr, except_addr )\
64 ".section __ex_table,\"aw\"\n" \
65 ".word (" #fault_addr " - .), (" #except_addr " - .)\n\t" \
66 ".previous\n"
67
68 /*
69 * The page fault handler stores, in a per-cpu area, the following information
70 * if a fixup routine is available.
71 */
72 struct exception_data {
73 unsigned long fault_ip;
74 unsigned long fault_gp;
75 unsigned long fault_space;
76 unsigned long fault_addr;
77 };
78
79 /*
80 * load_sr2() preloads the space register %%sr2 - based on the value of
81 * get_fs() - with either a value of 0 to access kernel space (KERNEL_DS which
82 * is 0), or with the current value of %%sr3 to access user space (USER_DS)
83 * memory. The following __get_user_asm() and __put_user_asm() functions have
84 * %%sr2 hard-coded to access the requested memory.
85 */
86 #define load_sr2() \
87 __asm__(" or,= %0,%%r0,%%r0\n\t" \
88 " mfsp %%sr3,%0\n\t" \
89 " mtsp %0,%%sr2\n\t" \
90 : : "r"(get_fs()) : )
91
92 #define __get_user(x, ptr) \
93 ({ \
94 register long __gu_err __asm__ ("r8") = 0; \
95 register long __gu_val __asm__ ("r9") = 0; \
96 \
97 load_sr2(); \
98 switch (sizeof(*(ptr))) { \
99 case 1: __get_user_asm("ldb", ptr); break; \
100 case 2: __get_user_asm("ldh", ptr); break; \
101 case 4: __get_user_asm("ldw", ptr); break; \
102 case 8: LDD_USER(ptr); break; \
103 default: BUILD_BUG(); break; \
104 } \
105 \
106 (x) = (__force __typeof__(*(ptr))) __gu_val; \
107 __gu_err; \
108 })
109
110 #define __get_user_asm(ldx, ptr) \
111 __asm__("\n1:\t" ldx "\t0(%%sr2,%2),%0\n\t" \
112 ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_get_user_skip_1)\
113 : "=r"(__gu_val), "=r"(__gu_err) \
114 : "r"(ptr), "1"(__gu_err) \
115 : "r1");
116
117 #if !defined(CONFIG_64BIT)
118
119 #define __get_user_asm64(ptr) \
120 __asm__("\n1:\tldw 0(%%sr2,%2),%0" \
121 "\n2:\tldw 4(%%sr2,%2),%R0\n\t" \
122 ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_get_user_skip_2)\
123 ASM_EXCEPTIONTABLE_ENTRY(2b, fixup_get_user_skip_1)\
124 : "=r"(__gu_val), "=r"(__gu_err) \
125 : "r"(ptr), "1"(__gu_err) \
126 : "r1");
127
128 #endif /* !defined(CONFIG_64BIT) */
129
130
131 #define __put_user(x, ptr) \
132 ({ \
133 register long __pu_err __asm__ ("r8") = 0; \
134 __typeof__(*(ptr)) __x = (__typeof__(*(ptr)))(x); \
135 \
136 load_sr2(); \
137 switch (sizeof(*(ptr))) { \
138 case 1: __put_user_asm("stb", __x, ptr); break; \
139 case 2: __put_user_asm("sth", __x, ptr); break; \
140 case 4: __put_user_asm("stw", __x, ptr); break; \
141 case 8: STD_USER(__x, ptr); break; \
142 default: BUILD_BUG(); break; \
143 } \
144 \
145 __pu_err; \
146 })
147
148 /*
149 * The "__put_user/kernel_asm()" macros tell gcc they read from memory
150 * instead of writing. This is because they do not write to any memory
151 * gcc knows about, so there are no aliasing issues. These macros must
152 * also be aware that "fixup_put_user_skip_[12]" are executed in the
153 * context of the fault, and any registers used there must be listed
154 * as clobbers. In this case only "r1" is used by the current routines.
155 * r8/r9 are already listed as err/val.
156 */
157
158 #define __put_user_asm(stx, x, ptr) \
159 __asm__ __volatile__ ( \
160 "\n1:\t" stx "\t%2,0(%%sr2,%1)\n\t" \
161 ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_put_user_skip_1)\
162 : "=r"(__pu_err) \
163 : "r"(ptr), "r"(x), "0"(__pu_err) \
164 : "r1")
165
166
167 #if !defined(CONFIG_64BIT)
168
169 #define __put_user_asm64(__val, ptr) do { \
170 __asm__ __volatile__ ( \
171 "\n1:\tstw %2,0(%%sr2,%1)" \
172 "\n2:\tstw %R2,4(%%sr2,%1)\n\t" \
173 ASM_EXCEPTIONTABLE_ENTRY(1b, fixup_put_user_skip_2)\
174 ASM_EXCEPTIONTABLE_ENTRY(2b, fixup_put_user_skip_1)\
175 : "=r"(__pu_err) \
176 : "r"(ptr), "r"(__val), "0"(__pu_err) \
177 : "r1"); \
178 } while (0)
179
180 #endif /* !defined(CONFIG_64BIT) */
181
182
183 /*
184 * Complex access routines -- external declarations
185 */
186
187 extern unsigned long lcopy_to_user(void __user *, const void *, unsigned long);
188 extern unsigned long lcopy_from_user(void *, const void __user *, unsigned long);
189 extern unsigned long lcopy_in_user(void __user *, const void __user *, unsigned long);
190 extern long strncpy_from_user(char *, const char __user *, long);
191 extern unsigned lclear_user(void __user *, unsigned long);
192 extern long lstrnlen_user(const char __user *, long);
193 /*
194 * Complex access routines -- macros
195 */
196 #define user_addr_max() (~0UL)
197
198 #define strnlen_user lstrnlen_user
199 #define strlen_user(str) lstrnlen_user(str, 0x7fffffffL)
200 #define clear_user lclear_user
201 #define __clear_user lclear_user
202
203 unsigned long copy_to_user(void __user *dst, const void *src, unsigned long len);
204 #define __copy_to_user copy_to_user
205 unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long len);
206 unsigned long copy_in_user(void __user *dst, const void __user *src, unsigned long len);
207 #define __copy_in_user copy_in_user
208 #define __copy_to_user_inatomic __copy_to_user
209 #define __copy_from_user_inatomic __copy_from_user
210
211 extern void copy_from_user_overflow(void)
212 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
213 __compiletime_error("copy_from_user() buffer size is not provably correct")
214 #else
215 __compiletime_warning("copy_from_user() buffer size is not provably correct")
216 #endif
217 ;
218
219 static inline unsigned long __must_check copy_from_user(void *to,
220 const void __user *from,
221 unsigned long n)
222 {
223 int sz = __compiletime_object_size(to);
224 int ret = -EFAULT;
225
226 if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
227 ret = __copy_from_user(to, from, n);
228 else
229 copy_from_user_overflow();
230
231 return ret;
232 }
233
234 struct pt_regs;
235 int fixup_exception(struct pt_regs *regs);
236
237 #endif /* __PARISC_UACCESS_H */
This page took 0.038292 seconds and 5 git commands to generate.