1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __M68K_UACCESS_H
3 #define __M68K_UACCESS_H
6 * User space memory access functions
8 #include <linux/compiler.h>
9 #include <linux/types.h>
10 #include <asm/segment.h>
12 /* We let the MMU do all checking */
13 static inline int access_ok(const void __user
*addr
,
20 * Not all varients of the 68k family support the notion of address spaces.
21 * The traditional 680x0 parts do, and they use the sfc/dfc registers and
22 * the "moves" instruction to access user space from kernel space. Other
23 * family members like ColdFire don't support this, and only have a single
24 * address space, and use the usual "move" instruction for user space access.
26 * Outside of this difference the user space access functions are the same.
27 * So lets keep the code simple and just define in what we need to use.
29 #ifdef CONFIG_CPU_HAS_ADDRESS_SPACES
35 extern int __put_user_bad(void);
36 extern int __get_user_bad(void);
38 #define __put_user_asm(res, x, ptr, bwl, reg, err) \
40 "1: "MOVES"."#bwl" %2,%1\n" \
42 " .section .fixup,\"ax\"\n" \
44 "10: moveq.l %3,%0\n" \
48 " .section __ex_table,\"a\"\n" \
53 : "+d" (res), "=m" (*(ptr)) \
54 : #reg (x), "i" (err))
57 * These are the main single-value transfer routines. They automatically
58 * use the right size if we just have the right pointer type.
61 #define __put_user(x, ptr) \
63 typeof(*(ptr)) __pu_val = (x); \
65 __chk_user_ptr(ptr); \
66 switch (sizeof (*(ptr))) { \
68 __put_user_asm(__pu_err, __pu_val, ptr, b, d, -EFAULT); \
71 __put_user_asm(__pu_err, __pu_val, ptr, w, r, -EFAULT); \
74 __put_user_asm(__pu_err, __pu_val, ptr, l, r, -EFAULT); \
78 const void __user *__pu_ptr = (ptr); \
80 "1: "MOVES".l %2,(%1)+\n" \
81 "2: "MOVES".l %R2,(%1)\n" \
83 " .section .fixup,\"ax\"\n" \
89 " .section __ex_table,\"a\"\n" \
95 : "+d" (__pu_err), "+a" (__pu_ptr) \
96 : "r" (__pu_val), "i" (-EFAULT) \
101 __pu_err = __put_user_bad(); \
106 #define put_user(x, ptr) __put_user(x, ptr)
109 #define __get_user_asm(res, x, ptr, type, bwl, reg, err) ({ \
112 "1: "MOVES"."#bwl" %2,%1\n" \
114 " .section .fixup,\"ax\"\n" \
116 "10: move.l %3,%0\n" \
121 " .section __ex_table,\"a\"\n" \
125 : "+d" (res), "=&" #reg (__gu_val) \
126 : "m" (*(ptr)), "i" (err)); \
127 (x) = (__force typeof(*(ptr)))(__force unsigned long)__gu_val; \
130 #define __get_user(x, ptr) \
133 __chk_user_ptr(ptr); \
134 switch (sizeof(*(ptr))) { \
136 __get_user_asm(__gu_err, x, ptr, u8, b, d, -EFAULT); \
139 __get_user_asm(__gu_err, x, ptr, u16, w, r, -EFAULT); \
142 __get_user_asm(__gu_err, x, ptr, u32, l, r, -EFAULT); \
145 const void *__gu_ptr = (ptr); \
148 __typeof__(*(ptr)) t; \
151 "1: "MOVES".l (%2)+,%1\n" \
152 "2: "MOVES".l (%2),%R1\n" \
154 " .section .fixup,\"ax\"\n" \
156 "10: move.l %3,%0\n" \
162 " .section __ex_table,\"a\"\n" \
167 : "+d" (__gu_err), "=&r" (__gu_val.l), \
175 __gu_err = __get_user_bad(); \
180 #define get_user(x, ptr) __get_user(x, ptr)
182 unsigned long __generic_copy_from_user(void *to
, const void __user
*from
, unsigned long n
);
183 unsigned long __generic_copy_to_user(void __user
*to
, const void *from
, unsigned long n
);
190 #define ____constant_copy_from_user_asm(res, to, from, tmp, n1, n2, n3, s1, s2, s3)\
192 "1: "MOVES"."#s1" (%2)+,%3\n" \
193 " move."#s1" %3,(%1)+\n" \
194 " .ifnc \""#s2"\",\"\"\n" \
195 "2: "MOVES"."#s2" (%2)+,%3\n" \
196 " move."#s2" %3,(%1)+\n" \
197 " .ifnc \""#s3"\",\"\"\n" \
198 "3: "MOVES"."#s3" (%2)+,%3\n" \
199 " move."#s3" %3,(%1)+\n" \
203 " .section __ex_table,\"a\"\n" \
206 " .ifnc \""#s2"\",\"\"\n" \
208 " .ifnc \""#s3"\",\"\"\n" \
214 " .section .fixup,\"ax\"\n" \
216 "10: addq.l #"#n1",%0\n" \
217 " .ifnc \""#s2"\",\"\"\n" \
218 "20: addq.l #"#n2",%0\n" \
219 " .ifnc \""#s3"\",\"\"\n" \
220 "30: addq.l #"#n3",%0\n" \
225 : "+d" (res), "+&a" (to), "+a" (from), "=&d" (tmp) \
228 #define ___constant_copy_from_user_asm(res, to, from, tmp, n1, n2, n3, s1, s2, s3)\
229 ____constant_copy_from_user_asm(res, to, from, tmp, n1, n2, n3, s1, s2, s3)
230 #define __constant_copy_from_user_asm(res, to, from, tmp, n1, n2, n3) \
231 ___constant_copy_from_user_asm(res, to, from, tmp, n1, n2, n3, \
232 __suffix##n1, __suffix##n2, __suffix##n3)
234 static __always_inline
unsigned long
235 __constant_copy_from_user(void *to
, const void __user
*from
, unsigned long n
)
237 unsigned long res
= 0, tmp
;
241 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 1, 0, 0);
244 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 2, 0, 0);
247 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 2, 1, 0);
250 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 0, 0);
253 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 1, 0);
256 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 2, 0);
259 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 2, 1);
262 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 4, 0);
265 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 4, 1);
268 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 4, 2);
271 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 4, 4);
274 /* we limit the inlined version to 3 moves */
275 return __generic_copy_from_user(to
, from
, n
);
281 #define __constant_copy_to_user_asm(res, to, from, tmp, n, s1, s2, s3) \
283 " move."#s1" (%2)+,%3\n" \
284 "11: "MOVES"."#s1" %3,(%1)+\n" \
285 "12: move."#s2" (%2)+,%3\n" \
286 "21: "MOVES"."#s2" %3,(%1)+\n" \
288 " .ifnc \""#s3"\",\"\"\n" \
289 " move."#s3" (%2)+,%3\n" \
290 "31: "MOVES"."#s3" %3,(%1)+\n" \
295 " .section __ex_table,\"a\"\n" \
301 " .ifnc \""#s3"\",\"\"\n" \
307 " .section .fixup,\"ax\"\n" \
309 "5: moveq.l #"#n",%0\n" \
312 : "+d" (res), "+a" (to), "+a" (from), "=&d" (tmp) \
315 static __always_inline
unsigned long
316 __constant_copy_to_user(void __user
*to
, const void *from
, unsigned long n
)
318 unsigned long res
= 0, tmp
;
322 __put_user_asm(res
, *(u8
*)from
, (u8 __user
*)to
, b
, d
, 1);
325 __put_user_asm(res
, *(u16
*)from
, (u16 __user
*)to
, w
, r
, 2);
328 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 3, w
, b
,);
331 __put_user_asm(res
, *(u32
*)from
, (u32 __user
*)to
, l
, r
, 4);
334 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 5, l
, b
,);
337 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 6, l
, w
,);
340 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 7, l
, w
, b
);
343 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 8, l
, l
,);
346 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 9, l
, l
, b
);
349 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 10, l
, l
, w
);
352 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 12, l
, l
, l
);
355 /* limit the inlined version to 3 moves */
356 return __generic_copy_to_user(to
, from
, n
);
362 static inline unsigned long
363 raw_copy_from_user(void *to
, const void __user
*from
, unsigned long n
)
365 if (__builtin_constant_p(n
))
366 return __constant_copy_from_user(to
, from
, n
);
367 return __generic_copy_from_user(to
, from
, n
);
370 static inline unsigned long
371 raw_copy_to_user(void __user
*to
, const void *from
, unsigned long n
)
373 if (__builtin_constant_p(n
))
374 return __constant_copy_to_user(to
, from
, n
);
375 return __generic_copy_to_user(to
, from
, n
);
377 #define INLINE_COPY_FROM_USER
378 #define INLINE_COPY_TO_USER
380 #define user_addr_max() \
381 (uaccess_kernel() ? ~0UL : TASK_SIZE)
383 extern long strncpy_from_user(char *dst
, const char __user
*src
, long count
);
384 extern __must_check
long strnlen_user(const char __user
*str
, long n
);
386 unsigned long __clear_user(void __user
*to
, unsigned long n
);
388 #define clear_user __clear_user
390 #endif /* _M68K_UACCESS_H */