]> err.no Git - linux-2.6/blob - arch/s390/lib/uaccess_mvcos.c
Merge ../linus
[linux-2.6] / arch / s390 / lib / uaccess_mvcos.c
1 /*
2  *  arch/s390/lib/uaccess_mvcos.c
3  *
4  *  Optimized user space space access functions based on mvcos.
5  *
6  *    Copyright (C) IBM Corp. 2006
7  *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
8  *               Gerald Schaefer (gerald.schaefer@de.ibm.com)
9  */
10
11 #include <linux/errno.h>
12 #include <linux/mm.h>
13 #include <asm/uaccess.h>
14 #include <asm/futex.h>
15
16 #ifndef __s390x__
17 #define AHI     "ahi"
18 #define ALR     "alr"
19 #define CLR     "clr"
20 #define LHI     "lhi"
21 #define SLR     "slr"
22 #else
23 #define AHI     "aghi"
24 #define ALR     "algr"
25 #define CLR     "clgr"
26 #define LHI     "lghi"
27 #define SLR     "slgr"
28 #endif
29
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 *);
32
33 size_t copy_from_user_mvcos(size_t size, const void __user *ptr, void *x)
34 {
35         register unsigned long reg0 asm("0") = 0x81UL;
36         unsigned long tmp1, tmp2;
37
38         tmp1 = -4096UL;
39         asm volatile(
40                 "0: .insn ss,0xc80000000000,0(%0,%2),0(%1),0\n"
41                 "   jz    7f\n"
42                 "1:"ALR"  %0,%3\n"
43                 "  "SLR"  %1,%3\n"
44                 "  "SLR"  %2,%3\n"
45                 "   j     0b\n"
46                 "2: la    %4,4095(%1)\n"/* %4 = ptr + 4095 */
47                 "   nr    %4,%3\n"      /* %4 = (ptr + 4095) & -4096 */
48                 "  "SLR"  %4,%1\n"
49                 "  "CLR"  %0,%4\n"      /* copy crosses next page boundary? */
50                 "   jnh   4f\n"
51                 "3: .insn ss,0xc80000000000,0(%4,%2),0(%1),0\n"
52                 "  "SLR"  %0,%4\n"
53                 "  "ALR"  %2,%4\n"
54                 "4:"LHI"  %4,-1\n"
55                 "  "ALR"  %4,%0\n"      /* copy remaining size, subtract 1 */
56                 "   bras  %3,6f\n"      /* memset loop */
57                 "   xc    0(1,%2),0(%2)\n"
58                 "5: xc    0(256,%2),0(%2)\n"
59                 "   la    %2,256(%2)\n"
60                 "6:"AHI"  %4,-256\n"
61                 "   jnm   5b\n"
62                 "   ex    %4,0(%3)\n"
63                 "   j     8f\n"
64                 "7:"SLR"  %0,%0\n"
65                 "8: \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");
69         return size;
70 }
71
72 size_t copy_from_user_mvcos_check(size_t size, const void __user *ptr, void *x)
73 {
74         if (size <= 256)
75                 return copy_from_user_std(size, ptr, x);
76         return copy_from_user_mvcos(size, ptr, x);
77 }
78
79 size_t copy_to_user_mvcos(size_t size, void __user *ptr, const void *x)
80 {
81         register unsigned long reg0 asm("0") = 0x810000UL;
82         unsigned long tmp1, tmp2;
83
84         tmp1 = -4096UL;
85         asm volatile(
86                 "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
87                 "   jz    4f\n"
88                 "1:"ALR"  %0,%3\n"
89                 "  "SLR"  %1,%3\n"
90                 "  "SLR"  %2,%3\n"
91                 "   j     0b\n"
92                 "2: la    %4,4095(%1)\n"/* %4 = ptr + 4095 */
93                 "   nr    %4,%3\n"      /* %4 = (ptr + 4095) & -4096 */
94                 "  "SLR"  %4,%1\n"
95                 "  "CLR"  %0,%4\n"      /* copy crosses next page boundary? */
96                 "   jnh   5f\n"
97                 "3: .insn ss,0xc80000000000,0(%4,%1),0(%2),0\n"
98                 "  "SLR"  %0,%4\n"
99                 "   j     5f\n"
100                 "4:"SLR"  %0,%0\n"
101                 "5: \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");
105         return size;
106 }
107
108 size_t copy_to_user_mvcos_check(size_t size, void __user *ptr, const void *x)
109 {
110         if (size <= 256)
111                 return copy_to_user_std(size, ptr, x);
112         return copy_to_user_mvcos(size, ptr, x);
113 }
114
115 size_t copy_in_user_mvcos(size_t size, void __user *to, const void __user *from)
116 {
117         register unsigned long reg0 asm("0") = 0x810081UL;
118         unsigned long tmp1, tmp2;
119
120         tmp1 = -4096UL;
121         /* FIXME: copy with reduced length. */
122         asm volatile(
123                 "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
124                 "   jz    2f\n"
125                 "1:"ALR"  %0,%3\n"
126                 "  "SLR"  %1,%3\n"
127                 "  "SLR"  %2,%3\n"
128                 "   j     0b\n"
129                 "2:"SLR"  %0,%0\n"
130                 "3: \n"
131                 EX_TABLE(0b,3b)
132                 : "+a" (size), "+a" (to), "+a" (from), "+a" (tmp1), "=a" (tmp2)
133                 : "d" (reg0) : "cc", "memory");
134         return size;
135 }
136
137 size_t clear_user_mvcos(size_t size, void __user *to)
138 {
139         register unsigned long reg0 asm("0") = 0x810000UL;
140         unsigned long tmp1, tmp2;
141
142         tmp1 = -4096UL;
143         asm volatile(
144                 "0: .insn ss,0xc80000000000,0(%0,%1),0(%4),0\n"
145                 "   jz    4f\n"
146                 "1:"ALR"  %0,%2\n"
147                 "  "SLR"  %1,%2\n"
148                 "   j     0b\n"
149                 "2: la    %3,4095(%1)\n"/* %4 = to + 4095 */
150                 "   nr    %3,%2\n"      /* %4 = (to + 4095) & -4096 */
151                 "  "SLR"  %3,%1\n"
152                 "  "CLR"  %0,%3\n"      /* copy crosses next page boundary? */
153                 "   jnh   5f\n"
154                 "3: .insn ss,0xc80000000000,0(%3,%1),0(%4),0\n"
155                 "  "SLR"  %0,%3\n"
156                 "   j     5f\n"
157                 "4:"SLR"  %0,%0\n"
158                 "5: \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");
162         return size;
163 }
164
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);
169
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,
181 };