]> err.no Git - linux-2.6/blob - arch/s390/lib/uaccess_mvcos.c
Merge branch 'master' into upstream
[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 size_t copy_from_user_mvcos(size_t size, const void __user *ptr, void *x)
31 {
32         register unsigned long reg0 asm("0") = 0x81UL;
33         unsigned long tmp1, tmp2;
34
35         tmp1 = -4096UL;
36         asm volatile(
37                 "0: .insn ss,0xc80000000000,0(%0,%2),0(%1),0\n"
38                 "   jz    7f\n"
39                 "1:"ALR"  %0,%3\n"
40                 "  "SLR"  %1,%3\n"
41                 "  "SLR"  %2,%3\n"
42                 "   j     0b\n"
43                 "2: la    %4,4095(%1)\n"/* %4 = ptr + 4095 */
44                 "   nr    %4,%3\n"      /* %4 = (ptr + 4095) & -4096 */
45                 "  "SLR"  %4,%1\n"
46                 "  "CLR"  %0,%4\n"      /* copy crosses next page boundary? */
47                 "   jnh   4f\n"
48                 "3: .insn ss,0xc80000000000,0(%4,%2),0(%1),0\n"
49                 "  "SLR"  %0,%4\n"
50                 "  "ALR"  %2,%4\n"
51                 "4:"LHI"  %4,-1\n"
52                 "  "ALR"  %4,%0\n"      /* copy remaining size, subtract 1 */
53                 "   bras  %3,6f\n"      /* memset loop */
54                 "   xc    0(1,%2),0(%2)\n"
55                 "5: xc    0(256,%2),0(%2)\n"
56                 "   la    %2,256(%2)\n"
57                 "6:"AHI"  %4,-256\n"
58                 "   jnm   5b\n"
59                 "   ex    %4,0(%3)\n"
60                 "   j     8f\n"
61                 "7:"SLR"  %0,%0\n"
62                 "8: \n"
63                 EX_TABLE(0b,2b) EX_TABLE(3b,4b)
64                 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
65                 : "d" (reg0) : "cc", "memory");
66         return size;
67 }
68
69 size_t copy_to_user_mvcos(size_t size, void __user *ptr, const void *x)
70 {
71         register unsigned long reg0 asm("0") = 0x810000UL;
72         unsigned long tmp1, tmp2;
73
74         tmp1 = -4096UL;
75         asm volatile(
76                 "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
77                 "   jz    4f\n"
78                 "1:"ALR"  %0,%3\n"
79                 "  "SLR"  %1,%3\n"
80                 "  "SLR"  %2,%3\n"
81                 "   j     0b\n"
82                 "2: la    %4,4095(%1)\n"/* %4 = ptr + 4095 */
83                 "   nr    %4,%3\n"      /* %4 = (ptr + 4095) & -4096 */
84                 "  "SLR"  %4,%1\n"
85                 "  "CLR"  %0,%4\n"      /* copy crosses next page boundary? */
86                 "   jnh   5f\n"
87                 "3: .insn ss,0xc80000000000,0(%4,%1),0(%2),0\n"
88                 "  "SLR"  %0,%4\n"
89                 "   j     5f\n"
90                 "4:"SLR"  %0,%0\n"
91                 "5: \n"
92                 EX_TABLE(0b,2b) EX_TABLE(3b,5b)
93                 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
94                 : "d" (reg0) : "cc", "memory");
95         return size;
96 }
97
98 size_t copy_in_user_mvcos(size_t size, void __user *to, const void __user *from)
99 {
100         register unsigned long reg0 asm("0") = 0x810081UL;
101         unsigned long tmp1, tmp2;
102
103         tmp1 = -4096UL;
104         /* FIXME: copy with reduced length. */
105         asm volatile(
106                 "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
107                 "   jz    2f\n"
108                 "1:"ALR"  %0,%3\n"
109                 "  "SLR"  %1,%3\n"
110                 "  "SLR"  %2,%3\n"
111                 "   j     0b\n"
112                 "2:"SLR"  %0,%0\n"
113                 "3: \n"
114                 EX_TABLE(0b,3b)
115                 : "+a" (size), "+a" (to), "+a" (from), "+a" (tmp1), "=a" (tmp2)
116                 : "d" (reg0) : "cc", "memory");
117         return size;
118 }
119
120 size_t clear_user_mvcos(size_t size, void __user *to)
121 {
122         register unsigned long reg0 asm("0") = 0x810000UL;
123         unsigned long tmp1, tmp2;
124
125         tmp1 = -4096UL;
126         asm volatile(
127                 "0: .insn ss,0xc80000000000,0(%0,%1),0(%4),0\n"
128                 "   jz    4f\n"
129                 "1:"ALR"  %0,%2\n"
130                 "  "SLR"  %1,%2\n"
131                 "   j     0b\n"
132                 "2: la    %3,4095(%1)\n"/* %4 = to + 4095 */
133                 "   nr    %3,%2\n"      /* %4 = (to + 4095) & -4096 */
134                 "  "SLR"  %3,%1\n"
135                 "  "CLR"  %0,%3\n"      /* copy crosses next page boundary? */
136                 "   jnh   5f\n"
137                 "3: .insn ss,0xc80000000000,0(%3,%1),0(%4),0\n"
138                 "  "SLR"  %0,%3\n"
139                 "   j     5f\n"
140                 "4:"SLR"  %0,%0\n"
141                 "5: \n"
142                 EX_TABLE(0b,2b) EX_TABLE(3b,5b)
143                 : "+a" (size), "+a" (to), "+a" (tmp1), "=a" (tmp2)
144                 : "a" (empty_zero_page), "d" (reg0) : "cc", "memory");
145         return size;
146 }
147
148 extern size_t copy_from_user_std_small(size_t, const void __user *, void *);
149 extern size_t copy_to_user_std_small(size_t, void __user *, const void *);
150 extern size_t strnlen_user_std(size_t, const char __user *);
151 extern size_t strncpy_from_user_std(size_t, const char __user *, char *);
152 extern int futex_atomic_op(int, int __user *, int, int *);
153 extern int futex_atomic_cmpxchg(int __user *, int, int);
154
155 struct uaccess_ops uaccess_mvcos = {
156         .copy_from_user = copy_from_user_mvcos,
157         .copy_from_user_small = copy_from_user_std_small,
158         .copy_to_user = copy_to_user_mvcos,
159         .copy_to_user_small = copy_to_user_std_small,
160         .copy_in_user = copy_in_user_mvcos,
161         .clear_user = clear_user_mvcos,
162         .strnlen_user = strnlen_user_std,
163         .strncpy_from_user = strncpy_from_user_std,
164         .futex_atomic_op = futex_atomic_op,
165         .futex_atomic_cmpxchg = futex_atomic_cmpxchg,
166 };