2 * Optimized user space space access functions based on mvcos.
4 * Copyright IBM Corp. 2006
5 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
6 * Gerald Schaefer (gerald.schaefer@de.ibm.com)
9 #include <linux/errno.h>
11 #include <asm/uaccess.h>
12 #include <asm/futex.h>
29 static size_t copy_from_user_mvcos(size_t size, const void __user *ptr, void *x)
31 register unsigned long reg0 asm("0") = 0x81UL;
32 unsigned long tmp1, tmp2;
36 "0: .insn ss,0xc80000000000,0(%0,%2),0(%1),0\n"
42 "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */
43 " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */
45 " "CLR" %0,%4\n" /* copy crosses next page boundary? */
47 "3: .insn ss,0xc80000000000,0(%4,%2),0(%1),0\n"
51 " "ALR" %4,%0\n" /* copy remaining size, subtract 1 */
52 " bras %3,6f\n" /* memset loop */
54 "5: xc 0(256,%2),0(%2)\n"
62 EX_TABLE(0b,2b) EX_TABLE(3b,4b) EX_TABLE(9b,2b) EX_TABLE(10b,4b)
63 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
64 : "d" (reg0) : "cc", "memory");
68 static size_t copy_from_user_mvcos_check(size_t size, const void __user *ptr, void *x)
71 return copy_from_user_std(size, ptr, x);
72 return copy_from_user_mvcos(size, ptr, x);
75 static size_t copy_to_user_mvcos(size_t size, void __user *ptr, const void *x)
77 register unsigned long reg0 asm("0") = 0x810000UL;
78 unsigned long tmp1, tmp2;
82 "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
88 "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */
89 " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */
91 " "CLR" %0,%4\n" /* copy crosses next page boundary? */
93 "3: .insn ss,0xc80000000000,0(%4,%1),0(%2),0\n"
98 EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b)
99 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
100 : "d" (reg0) : "cc", "memory");
104 static size_t copy_to_user_mvcos_check(size_t size, void __user *ptr,
108 return copy_to_user_std(size, ptr, x);
109 return copy_to_user_mvcos(size, ptr, x);
112 static size_t copy_in_user_mvcos(size_t size, void __user *to,
113 const void __user *from)
115 register unsigned long reg0 asm("0") = 0x810081UL;
116 unsigned long tmp1, tmp2;
119 /* FIXME: copy with reduced length. */
121 "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
130 : "+a" (size), "+a" (to), "+a" (from), "+a" (tmp1), "=a" (tmp2)
131 : "d" (reg0) : "cc", "memory");
135 static size_t clear_user_mvcos(size_t size, void __user *to)
137 register unsigned long reg0 asm("0") = 0x810000UL;
138 unsigned long tmp1, tmp2;
142 "0: .insn ss,0xc80000000000,0(%0,%1),0(%4),0\n"
147 "2: la %3,4095(%1)\n"/* %4 = to + 4095 */
148 " nr %3,%2\n" /* %4 = (to + 4095) & -4096 */
150 " "CLR" %0,%3\n" /* copy crosses next page boundary? */
152 "3: .insn ss,0xc80000000000,0(%3,%1),0(%4),0\n"
157 EX_TABLE(0b,2b) EX_TABLE(3b,5b)
158 : "+a" (size), "+a" (to), "+a" (tmp1), "=a" (tmp2)
159 : "a" (empty_zero_page), "d" (reg0) : "cc", "memory");
163 static size_t strnlen_user_mvcos(size_t count, const char __user *src)
165 size_t done, len, offset, len_str;
170 offset = (size_t)src & ~PAGE_MASK;
171 len = min(256UL, PAGE_SIZE - offset);
172 len = min(count - done, len);
173 if (copy_from_user_mvcos(len, src, buf))
175 len_str = strnlen(buf, len);
178 } while ((len_str == len) && (done < count));
182 static size_t strncpy_from_user_mvcos(size_t count, const char __user *src,
185 size_t done, len, offset, len_str;
187 if (unlikely(!count))
191 offset = (size_t)src & ~PAGE_MASK;
192 len = min(count - done, PAGE_SIZE - offset);
193 if (copy_from_user_mvcos(len, src, dst))
195 len_str = strnlen(dst, len);
199 } while ((len_str == len) && (done < count));
203 struct uaccess_ops uaccess_mvcos = {
204 .copy_from_user = copy_from_user_mvcos_check,
205 .copy_from_user_small = copy_from_user_std,
206 .copy_to_user = copy_to_user_mvcos_check,
207 .copy_to_user_small = copy_to_user_std,
208 .copy_in_user = copy_in_user_mvcos,
209 .clear_user = clear_user_mvcos,
210 .strnlen_user = strnlen_user_std,
211 .strncpy_from_user = strncpy_from_user_std,
212 .futex_atomic_op = futex_atomic_op_std,
213 .futex_atomic_cmpxchg = futex_atomic_cmpxchg_std,
216 struct uaccess_ops uaccess_mvcos_switch = {
217 .copy_from_user = copy_from_user_mvcos,
218 .copy_from_user_small = copy_from_user_mvcos,
219 .copy_to_user = copy_to_user_mvcos,
220 .copy_to_user_small = copy_to_user_mvcos,
221 .copy_in_user = copy_in_user_mvcos,
222 .clear_user = clear_user_mvcos,
223 .strnlen_user = strnlen_user_mvcos,
224 .strncpy_from_user = strncpy_from_user_mvcos,
225 .futex_atomic_op = futex_atomic_op_pt,
226 .futex_atomic_cmpxchg = futex_atomic_cmpxchg_pt,