2 * arch/s390/lib/uaccess_mvcos.c
4 * Optimized user space space access functions based on mvcos.
6 * Copyright (C) IBM Corp. 2006
7 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
8 * Gerald Schaefer (gerald.schaefer@de.ibm.com)
11 #include <linux/errno.h>
13 #include <asm/uaccess.h>
14 #include <asm/futex.h>
30 extern size_t copy_from_user_std(size_t, const void __user *, void *);
31 extern size_t copy_to_user_std(size_t, void __user *, const void *);
33 size_t copy_from_user_mvcos(size_t size, const void __user *ptr, void *x)
35 register unsigned long reg0 asm("0") = 0x81UL;
36 unsigned long tmp1, tmp2;
40 "0: .insn ss,0xc80000000000,0(%0,%2),0(%1),0\n"
46 "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */
47 " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */
49 " "CLR" %0,%4\n" /* copy crosses next page boundary? */
51 "3: .insn ss,0xc80000000000,0(%4,%2),0(%1),0\n"
55 " "ALR" %4,%0\n" /* copy remaining size, subtract 1 */
56 " bras %3,6f\n" /* memset loop */
58 "5: xc 0(256,%2),0(%2)\n"
66 EX_TABLE(0b,2b) EX_TABLE(3b,4b)
67 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
68 : "d" (reg0) : "cc", "memory");
72 size_t copy_from_user_mvcos_check(size_t size, const void __user *ptr, void *x)
75 return copy_from_user_std(size, ptr, x);
76 return copy_from_user_mvcos(size, ptr, x);
79 size_t copy_to_user_mvcos(size_t size, void __user *ptr, const void *x)
81 register unsigned long reg0 asm("0") = 0x810000UL;
82 unsigned long tmp1, tmp2;
86 "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
92 "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */
93 " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */
95 " "CLR" %0,%4\n" /* copy crosses next page boundary? */
97 "3: .insn ss,0xc80000000000,0(%4,%1),0(%2),0\n"
102 EX_TABLE(0b,2b) EX_TABLE(3b,5b)
103 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
104 : "d" (reg0) : "cc", "memory");
108 size_t copy_to_user_mvcos_check(size_t size, void __user *ptr, const void *x)
111 return copy_to_user_std(size, ptr, x);
112 return copy_to_user_mvcos(size, ptr, x);
115 size_t copy_in_user_mvcos(size_t size, void __user *to, const void __user *from)
117 register unsigned long reg0 asm("0") = 0x810081UL;
118 unsigned long tmp1, tmp2;
121 /* FIXME: copy with reduced length. */
123 "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
132 : "+a" (size), "+a" (to), "+a" (from), "+a" (tmp1), "=a" (tmp2)
133 : "d" (reg0) : "cc", "memory");
137 size_t clear_user_mvcos(size_t size, void __user *to)
139 register unsigned long reg0 asm("0") = 0x810000UL;
140 unsigned long tmp1, tmp2;
144 "0: .insn ss,0xc80000000000,0(%0,%1),0(%4),0\n"
149 "2: la %3,4095(%1)\n"/* %4 = to + 4095 */
150 " nr %3,%2\n" /* %4 = (to + 4095) & -4096 */
152 " "CLR" %0,%3\n" /* copy crosses next page boundary? */
154 "3: .insn ss,0xc80000000000,0(%3,%1),0(%4),0\n"
159 EX_TABLE(0b,2b) EX_TABLE(3b,5b)
160 : "+a" (size), "+a" (to), "+a" (tmp1), "=a" (tmp2)
161 : "a" (empty_zero_page), "d" (reg0) : "cc", "memory");
165 extern size_t strnlen_user_std(size_t, const char __user *);
166 extern size_t strncpy_from_user_std(size_t, const char __user *, char *);
167 extern int futex_atomic_op(int, int __user *, int, int *);
168 extern int futex_atomic_cmpxchg(int __user *, int, int);
170 struct uaccess_ops uaccess_mvcos = {
171 .copy_from_user = copy_from_user_mvcos_check,
172 .copy_from_user_small = copy_from_user_std,
173 .copy_to_user = copy_to_user_mvcos_check,
174 .copy_to_user_small = copy_to_user_std,
175 .copy_in_user = copy_in_user_mvcos,
176 .clear_user = clear_user_mvcos,
177 .strnlen_user = strnlen_user_std,
178 .strncpy_from_user = strncpy_from_user_std,
179 .futex_atomic_op = futex_atomic_op,
180 .futex_atomic_cmpxchg = futex_atomic_cmpxchg,