1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __M68K_UACCESS_H
3 #define __M68K_UACCESS_H
8 * User space memory access functions
10 #include <linux/compiler.h>
11 #include <linux/types.h>
12 #include <asm/segment.h>
13 #include <asm/extable.h>
15 /* We let the MMU do all checking */
16 static inline int access_ok(const void __user
*addr
,
23 * Not all varients of the 68k family support the notion of address spaces.
24 * The traditional 680x0 parts do, and they use the sfc/dfc registers and
25 * the "moves" instruction to access user space from kernel space. Other
26 * family members like ColdFire don't support this, and only have a single
27 * address space, and use the usual "move" instruction for user space access.
29 * Outside of this difference the user space access functions are the same.
30 * So lets keep the code simple and just define in what we need to use.
32 #ifdef CONFIG_CPU_HAS_ADDRESS_SPACES
38 extern int __put_user_bad(void);
39 extern int __get_user_bad(void);
41 #define __put_user_asm(res, x, ptr, bwl, reg, err) \
43 "1: "MOVES"."#bwl" %2,%1\n" \
45 " .section .fixup,\"ax\"\n" \
47 "10: moveq.l %3,%0\n" \
51 " .section __ex_table,\"a\"\n" \
56 : "+d" (res), "=m" (*(ptr)) \
57 : #reg (x), "i" (err))
60 * These are the main single-value transfer routines. They automatically
61 * use the right size if we just have the right pointer type.
64 #define __put_user(x, ptr) \
66 typeof(*(ptr)) __pu_val = (x); \
68 __chk_user_ptr(ptr); \
69 switch (sizeof (*(ptr))) { \
71 __put_user_asm(__pu_err, __pu_val, ptr, b, d, -EFAULT); \
74 __put_user_asm(__pu_err, __pu_val, ptr, w, r, -EFAULT); \
77 __put_user_asm(__pu_err, __pu_val, ptr, l, r, -EFAULT); \
81 const void __user *__pu_ptr = (ptr); \
83 "1: "MOVES".l %2,(%1)+\n" \
84 "2: "MOVES".l %R2,(%1)\n" \
86 " .section .fixup,\"ax\"\n" \
92 " .section __ex_table,\"a\"\n" \
98 : "+d" (__pu_err), "+a" (__pu_ptr) \
99 : "r" (__pu_val), "i" (-EFAULT) \
104 __pu_err = __put_user_bad(); \
109 #define put_user(x, ptr) __put_user(x, ptr)
112 #define __get_user_asm(res, x, ptr, type, bwl, reg, err) ({ \
115 "1: "MOVES"."#bwl" %2,%1\n" \
117 " .section .fixup,\"ax\"\n" \
119 "10: move.l %3,%0\n" \
124 " .section __ex_table,\"a\"\n" \
128 : "+d" (res), "=&" #reg (__gu_val) \
129 : "m" (*(ptr)), "i" (err)); \
130 (x) = (__force typeof(*(ptr)))(__force unsigned long)__gu_val; \
133 #define __get_user(x, ptr) \
136 __chk_user_ptr(ptr); \
137 switch (sizeof(*(ptr))) { \
139 __get_user_asm(__gu_err, x, ptr, u8, b, d, -EFAULT); \
142 __get_user_asm(__gu_err, x, ptr, u16, w, r, -EFAULT); \
145 __get_user_asm(__gu_err, x, ptr, u32, l, r, -EFAULT); \
148 const void __user *__gu_ptr = (ptr); \
151 __typeof__(*(ptr)) t; \
154 "1: "MOVES".l (%2)+,%1\n" \
155 "2: "MOVES".l (%2),%R1\n" \
157 " .section .fixup,\"ax\"\n" \
159 "10: move.l %3,%0\n" \
165 " .section __ex_table,\"a\"\n" \
170 : "+d" (__gu_err), "=&r" (__gu_val.l), \
178 __gu_err = __get_user_bad(); \
183 #define get_user(x, ptr) __get_user(x, ptr)
185 unsigned long __generic_copy_from_user(void *to
, const void __user
*from
, unsigned long n
);
186 unsigned long __generic_copy_to_user(void __user
*to
, const void *from
, unsigned long n
);
193 #define ____constant_copy_from_user_asm(res, to, from, tmp, n1, n2, n3, s1, s2, s3)\
195 "1: "MOVES"."#s1" (%2)+,%3\n" \
196 " move."#s1" %3,(%1)+\n" \
197 " .ifnc \""#s2"\",\"\"\n" \
198 "2: "MOVES"."#s2" (%2)+,%3\n" \
199 " move."#s2" %3,(%1)+\n" \
200 " .ifnc \""#s3"\",\"\"\n" \
201 "3: "MOVES"."#s3" (%2)+,%3\n" \
202 " move."#s3" %3,(%1)+\n" \
206 " .section __ex_table,\"a\"\n" \
209 " .ifnc \""#s2"\",\"\"\n" \
211 " .ifnc \""#s3"\",\"\"\n" \
217 " .section .fixup,\"ax\"\n" \
219 "10: addq.l #"#n1",%0\n" \
220 " .ifnc \""#s2"\",\"\"\n" \
221 "20: addq.l #"#n2",%0\n" \
222 " .ifnc \""#s3"\",\"\"\n" \
223 "30: addq.l #"#n3",%0\n" \
228 : "+d" (res), "+&a" (to), "+a" (from), "=&d" (tmp) \
231 #define ___constant_copy_from_user_asm(res, to, from, tmp, n1, n2, n3, s1, s2, s3)\
232 ____constant_copy_from_user_asm(res, to, from, tmp, n1, n2, n3, s1, s2, s3)
233 #define __constant_copy_from_user_asm(res, to, from, tmp, n1, n2, n3) \
234 ___constant_copy_from_user_asm(res, to, from, tmp, n1, n2, n3, \
235 __suffix##n1, __suffix##n2, __suffix##n3)
237 static __always_inline
unsigned long
238 __constant_copy_from_user(void *to
, const void __user
*from
, unsigned long n
)
240 unsigned long res
= 0, tmp
;
244 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 1, 0, 0);
247 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 2, 0, 0);
250 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 2, 1, 0);
253 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 0, 0);
256 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 1, 0);
259 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 2, 0);
262 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 2, 1);
265 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 4, 0);
268 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 4, 1);
271 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 4, 2);
274 __constant_copy_from_user_asm(res
, to
, from
, tmp
, 4, 4, 4);
277 /* we limit the inlined version to 3 moves */
278 return __generic_copy_from_user(to
, from
, n
);
284 #define __constant_copy_to_user_asm(res, to, from, tmp, n, s1, s2, s3) \
286 " move."#s1" (%2)+,%3\n" \
287 "11: "MOVES"."#s1" %3,(%1)+\n" \
288 "12: move."#s2" (%2)+,%3\n" \
289 "21: "MOVES"."#s2" %3,(%1)+\n" \
291 " .ifnc \""#s3"\",\"\"\n" \
292 " move."#s3" (%2)+,%3\n" \
293 "31: "MOVES"."#s3" %3,(%1)+\n" \
298 " .section __ex_table,\"a\"\n" \
304 " .ifnc \""#s3"\",\"\"\n" \
310 " .section .fixup,\"ax\"\n" \
312 "5: moveq.l #"#n",%0\n" \
315 : "+d" (res), "+a" (to), "+a" (from), "=&d" (tmp) \
318 static __always_inline
unsigned long
319 __constant_copy_to_user(void __user
*to
, const void *from
, unsigned long n
)
321 unsigned long res
= 0, tmp
;
325 __put_user_asm(res
, *(u8
*)from
, (u8 __user
*)to
, b
, d
, 1);
328 __put_user_asm(res
, *(u16
*)from
, (u16 __user
*)to
, w
, r
, 2);
331 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 3, w
, b
,);
334 __put_user_asm(res
, *(u32
*)from
, (u32 __user
*)to
, l
, r
, 4);
337 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 5, l
, b
,);
340 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 6, l
, w
,);
343 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 7, l
, w
, b
);
346 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 8, l
, l
,);
349 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 9, l
, l
, b
);
352 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 10, l
, l
, w
);
355 __constant_copy_to_user_asm(res
, to
, from
, tmp
, 12, l
, l
, l
);
358 /* limit the inlined version to 3 moves */
359 return __generic_copy_to_user(to
, from
, n
);
365 static inline unsigned long
366 raw_copy_from_user(void *to
, const void __user
*from
, unsigned long n
)
368 if (__builtin_constant_p(n
))
369 return __constant_copy_from_user(to
, from
, n
);
370 return __generic_copy_from_user(to
, from
, n
);
373 static inline unsigned long
374 raw_copy_to_user(void __user
*to
, const void *from
, unsigned long n
)
376 if (__builtin_constant_p(n
))
377 return __constant_copy_to_user(to
, from
, n
);
378 return __generic_copy_to_user(to
, from
, n
);
380 #define INLINE_COPY_FROM_USER
381 #define INLINE_COPY_TO_USER
383 #define user_addr_max() \
384 (uaccess_kernel() ? ~0UL : TASK_SIZE)
386 extern long strncpy_from_user(char *dst
, const char __user
*src
, long count
);
387 extern __must_check
long strnlen_user(const char __user
*str
, long n
);
389 unsigned long __clear_user(void __user
*to
, unsigned long n
);
391 #define clear_user __clear_user
393 #else /* !CONFIG_MMU */
394 #include <asm-generic/uaccess.h>
397 #endif /* _M68K_UACCESS_H */