[ARM] pxa: update defconfig for Verdex Pro
[linux-2.6/verdex.git] / arch / s390 / lib / uaccess_std.c
blob07deaeee14c833e20557d5a57f4799c9de261944
1 /*
2 * arch/s390/lib/uaccess_std.c
4 * Standard user space access functions based on mvcp/mvcs and doing
5 * interesting things in the secondary space mode.
7 * Copyright (C) IBM Corp. 2006
8 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
9 * Gerald Schaefer (gerald.schaefer@de.ibm.com)
12 #include <linux/errno.h>
13 #include <linux/mm.h>
14 #include <linux/uaccess.h>
15 #include <asm/futex.h>
16 #include "uaccess.h"
18 #ifndef __s390x__
19 #define AHI "ahi"
20 #define ALR "alr"
21 #define CLR "clr"
22 #define LHI "lhi"
23 #define SLR "slr"
24 #else
25 #define AHI "aghi"
26 #define ALR "algr"
27 #define CLR "clgr"
28 #define LHI "lghi"
29 #define SLR "slgr"
30 #endif
32 size_t copy_from_user_std(size_t size, const void __user *ptr, void *x)
34 unsigned long tmp1, tmp2;
36 tmp1 = -256UL;
37 asm volatile(
38 "0: mvcp 0(%0,%2),0(%1),%3\n"
39 "10:jz 8f\n"
40 "1:"ALR" %0,%3\n"
41 " la %1,256(%1)\n"
42 " la %2,256(%2)\n"
43 "2: mvcp 0(%0,%2),0(%1),%3\n"
44 "11:jnz 1b\n"
45 " j 8f\n"
46 "3: la %4,255(%1)\n" /* %4 = ptr + 255 */
47 " "LHI" %3,-4096\n"
48 " nr %4,%3\n" /* %4 = (ptr + 255) & -4096 */
49 " "SLR" %4,%1\n"
50 " "CLR" %0,%4\n" /* copy crosses next page boundary? */
51 " jnh 5f\n"
52 "4: mvcp 0(%4,%2),0(%1),%3\n"
53 "12:"SLR" %0,%4\n"
54 " "ALR" %2,%4\n"
55 "5:"LHI" %4,-1\n"
56 " "ALR" %4,%0\n" /* copy remaining size, subtract 1 */
57 " bras %3,7f\n" /* memset loop */
58 " xc 0(1,%2),0(%2)\n"
59 "6: xc 0(256,%2),0(%2)\n"
60 " la %2,256(%2)\n"
61 "7:"AHI" %4,-256\n"
62 " jnm 6b\n"
63 " ex %4,0(%3)\n"
64 " j 9f\n"
65 "8:"SLR" %0,%0\n"
66 "9: \n"
67 EX_TABLE(0b,3b) EX_TABLE(2b,3b) EX_TABLE(4b,5b)
68 EX_TABLE(10b,3b) EX_TABLE(11b,3b) EX_TABLE(12b,5b)
69 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
70 : : "cc", "memory");
71 return size;
74 static size_t copy_from_user_std_check(size_t size, const void __user *ptr,
75 void *x)
77 if (size <= 1024)
78 return copy_from_user_std(size, ptr, x);
79 return copy_from_user_pt(size, ptr, x);
82 size_t copy_to_user_std(size_t size, void __user *ptr, const void *x)
84 unsigned long tmp1, tmp2;
86 tmp1 = -256UL;
87 asm volatile(
88 "0: mvcs 0(%0,%1),0(%2),%3\n"
89 "7: jz 5f\n"
90 "1:"ALR" %0,%3\n"
91 " la %1,256(%1)\n"
92 " la %2,256(%2)\n"
93 "2: mvcs 0(%0,%1),0(%2),%3\n"
94 "8: jnz 1b\n"
95 " j 5f\n"
96 "3: la %4,255(%1)\n" /* %4 = ptr + 255 */
97 " "LHI" %3,-4096\n"
98 " nr %4,%3\n" /* %4 = (ptr + 255) & -4096 */
99 " "SLR" %4,%1\n"
100 " "CLR" %0,%4\n" /* copy crosses next page boundary? */
101 " jnh 6f\n"
102 "4: mvcs 0(%4,%1),0(%2),%3\n"
103 "9:"SLR" %0,%4\n"
104 " j 6f\n"
105 "5:"SLR" %0,%0\n"
106 "6: \n"
107 EX_TABLE(0b,3b) EX_TABLE(2b,3b) EX_TABLE(4b,6b)
108 EX_TABLE(7b,3b) EX_TABLE(8b,3b) EX_TABLE(9b,6b)
109 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
110 : : "cc", "memory");
111 return size;
114 static size_t copy_to_user_std_check(size_t size, void __user *ptr,
115 const void *x)
117 if (size <= 1024)
118 return copy_to_user_std(size, ptr, x);
119 return copy_to_user_pt(size, ptr, x);
122 static size_t copy_in_user_std(size_t size, void __user *to,
123 const void __user *from)
125 unsigned long tmp1;
127 asm volatile(
128 " "AHI" %0,-1\n"
129 " jo 5f\n"
130 " sacf 256\n"
131 " bras %3,3f\n"
132 "0:"AHI" %0,257\n"
133 "1: mvc 0(1,%1),0(%2)\n"
134 " la %1,1(%1)\n"
135 " la %2,1(%2)\n"
136 " "AHI" %0,-1\n"
137 " jnz 1b\n"
138 " j 5f\n"
139 "2: mvc 0(256,%1),0(%2)\n"
140 " la %1,256(%1)\n"
141 " la %2,256(%2)\n"
142 "3:"AHI" %0,-256\n"
143 " jnm 2b\n"
144 "4: ex %0,1b-0b(%3)\n"
145 " sacf 0\n"
146 "5: "SLR" %0,%0\n"
147 "6:\n"
148 EX_TABLE(1b,6b) EX_TABLE(2b,0b) EX_TABLE(4b,0b)
149 : "+a" (size), "+a" (to), "+a" (from), "=a" (tmp1)
150 : : "cc", "memory");
151 return size;
154 static size_t clear_user_std(size_t size, void __user *to)
156 unsigned long tmp1, tmp2;
158 asm volatile(
159 " "AHI" %0,-1\n"
160 " jo 5f\n"
161 " sacf 256\n"
162 " bras %3,3f\n"
163 " xc 0(1,%1),0(%1)\n"
164 "0:"AHI" %0,257\n"
165 " la %2,255(%1)\n" /* %2 = ptr + 255 */
166 " srl %2,12\n"
167 " sll %2,12\n" /* %2 = (ptr + 255) & -4096 */
168 " "SLR" %2,%1\n"
169 " "CLR" %0,%2\n" /* clear crosses next page boundary? */
170 " jnh 5f\n"
171 " "AHI" %2,-1\n"
172 "1: ex %2,0(%3)\n"
173 " "AHI" %2,1\n"
174 " "SLR" %0,%2\n"
175 " j 5f\n"
176 "2: xc 0(256,%1),0(%1)\n"
177 " la %1,256(%1)\n"
178 "3:"AHI" %0,-256\n"
179 " jnm 2b\n"
180 "4: ex %0,0(%3)\n"
181 " sacf 0\n"
182 "5: "SLR" %0,%0\n"
183 "6:\n"
184 EX_TABLE(1b,6b) EX_TABLE(2b,0b) EX_TABLE(4b,0b)
185 : "+a" (size), "+a" (to), "=a" (tmp1), "=a" (tmp2)
186 : : "cc", "memory");
187 return size;
190 size_t strnlen_user_std(size_t size, const char __user *src)
192 register unsigned long reg0 asm("0") = 0UL;
193 unsigned long tmp1, tmp2;
195 asm volatile(
196 " la %2,0(%1)\n"
197 " la %3,0(%0,%1)\n"
198 " "SLR" %0,%0\n"
199 " sacf 256\n"
200 "0: srst %3,%2\n"
201 " jo 0b\n"
202 " la %0,1(%3)\n" /* strnlen_user results includes \0 */
203 " "SLR" %0,%1\n"
204 "1: sacf 0\n"
205 EX_TABLE(0b,1b)
206 : "+a" (size), "+a" (src), "=a" (tmp1), "=a" (tmp2)
207 : "d" (reg0) : "cc", "memory");
208 return size;
211 size_t strncpy_from_user_std(size_t size, const char __user *src, char *dst)
213 register unsigned long reg0 asm("0") = 0UL;
214 unsigned long tmp1, tmp2;
216 asm volatile(
217 " la %3,0(%1)\n"
218 " la %4,0(%0,%1)\n"
219 " sacf 256\n"
220 "0: srst %4,%3\n"
221 " jo 0b\n"
222 " sacf 0\n"
223 " la %0,0(%4)\n"
224 " jh 1f\n" /* found \0 in string ? */
225 " "AHI" %4,1\n" /* include \0 in copy */
226 "1:"SLR" %0,%1\n" /* %0 = return length (without \0) */
227 " "SLR" %4,%1\n" /* %4 = copy length (including \0) */
228 "2: mvcp 0(%4,%2),0(%1),%5\n"
229 " jz 9f\n"
230 "3:"AHI" %4,-256\n"
231 " la %1,256(%1)\n"
232 " la %2,256(%2)\n"
233 "4: mvcp 0(%4,%2),0(%1),%5\n"
234 " jnz 3b\n"
235 " j 9f\n"
236 "7: sacf 0\n"
237 "8:"LHI" %0,%6\n"
238 "9:\n"
239 EX_TABLE(0b,7b) EX_TABLE(2b,8b) EX_TABLE(4b,8b)
240 : "+a" (size), "+a" (src), "+d" (dst), "=a" (tmp1), "=a" (tmp2)
241 : "d" (reg0), "K" (-EFAULT) : "cc", "memory");
242 return size;
245 #define __futex_atomic_op(insn, ret, oldval, newval, uaddr, oparg) \
246 asm volatile( \
247 " sacf 256\n" \
248 "0: l %1,0(%6)\n" \
249 "1:"insn \
250 "2: cs %1,%2,0(%6)\n" \
251 "3: jl 1b\n" \
252 " lhi %0,0\n" \
253 "4: sacf 0\n" \
254 EX_TABLE(0b,4b) EX_TABLE(2b,4b) EX_TABLE(3b,4b) \
255 : "=d" (ret), "=&d" (oldval), "=&d" (newval), \
256 "=m" (*uaddr) \
257 : "0" (-EFAULT), "d" (oparg), "a" (uaddr), \
258 "m" (*uaddr) : "cc");
260 int futex_atomic_op_std(int op, int __user *uaddr, int oparg, int *old)
262 int oldval = 0, newval, ret;
264 switch (op) {
265 case FUTEX_OP_SET:
266 __futex_atomic_op("lr %2,%5\n",
267 ret, oldval, newval, uaddr, oparg);
268 break;
269 case FUTEX_OP_ADD:
270 __futex_atomic_op("lr %2,%1\nar %2,%5\n",
271 ret, oldval, newval, uaddr, oparg);
272 break;
273 case FUTEX_OP_OR:
274 __futex_atomic_op("lr %2,%1\nor %2,%5\n",
275 ret, oldval, newval, uaddr, oparg);
276 break;
277 case FUTEX_OP_ANDN:
278 __futex_atomic_op("lr %2,%1\nnr %2,%5\n",
279 ret, oldval, newval, uaddr, oparg);
280 break;
281 case FUTEX_OP_XOR:
282 __futex_atomic_op("lr %2,%1\nxr %2,%5\n",
283 ret, oldval, newval, uaddr, oparg);
284 break;
285 default:
286 ret = -ENOSYS;
288 *old = oldval;
289 return ret;
292 int futex_atomic_cmpxchg_std(int __user *uaddr, int oldval, int newval)
294 int ret;
296 asm volatile(
297 " sacf 256\n"
298 "0: cs %1,%4,0(%5)\n"
299 "1: lr %0,%1\n"
300 "2: sacf 0\n"
301 EX_TABLE(0b,2b) EX_TABLE(1b,2b)
302 : "=d" (ret), "+d" (oldval), "=m" (*uaddr)
303 : "0" (-EFAULT), "d" (newval), "a" (uaddr), "m" (*uaddr)
304 : "cc", "memory" );
305 return ret;
308 struct uaccess_ops uaccess_std = {
309 .copy_from_user = copy_from_user_std_check,
310 .copy_from_user_small = copy_from_user_std,
311 .copy_to_user = copy_to_user_std_check,
312 .copy_to_user_small = copy_to_user_std,
313 .copy_in_user = copy_in_user_std,
314 .clear_user = clear_user_std,
315 .strnlen_user = strnlen_user_std,
316 .strncpy_from_user = strncpy_from_user_std,
317 .futex_atomic_op = futex_atomic_op_std,
318 .futex_atomic_cmpxchg = futex_atomic_cmpxchg_std,