[GFS2] Fix up merge of Linus' kernel into GFS2
[pandora-kernel.git] / 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    4f\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   5f\n"
48                 "3: .insn ss,0xc80000000000,0(%4,%2),0(%1),0\n"
49                 "  "SLR"  %0,%4\n"
50                 "   j     5f\n"
51                 "4:"SLR"  %0,%0\n"
52                 "5: \n"
53                 EX_TABLE(0b,2b) EX_TABLE(3b,5b)
54                 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
55                 : "d" (reg0) : "cc", "memory");
56         return size;
57 }
58
59 size_t copy_to_user_mvcos(size_t size, void __user *ptr, const void *x)
60 {
61         register unsigned long reg0 asm("0") = 0x810000UL;
62         unsigned long tmp1, tmp2;
63
64         tmp1 = -4096UL;
65         asm volatile(
66                 "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
67                 "   jz    4f\n"
68                 "1:"ALR"  %0,%3\n"
69                 "  "SLR"  %1,%3\n"
70                 "  "SLR"  %2,%3\n"
71                 "   j     0b\n"
72                 "2: la    %4,4095(%1)\n"/* %4 = ptr + 4095 */
73                 "   nr    %4,%3\n"      /* %4 = (ptr + 4095) & -4096 */
74                 "  "SLR"  %4,%1\n"
75                 "  "CLR"  %0,%4\n"      /* copy crosses next page boundary? */
76                 "   jnh   5f\n"
77                 "3: .insn ss,0xc80000000000,0(%4,%1),0(%2),0\n"
78                 "  "SLR"  %0,%4\n"
79                 "   j     5f\n"
80                 "4:"SLR"  %0,%0\n"
81                 "5: \n"
82                 EX_TABLE(0b,2b) EX_TABLE(3b,5b)
83                 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
84                 : "d" (reg0) : "cc", "memory");
85         return size;
86 }
87
88 size_t copy_in_user_mvcos(size_t size, void __user *to, const void __user *from)
89 {
90         register unsigned long reg0 asm("0") = 0x810081UL;
91         unsigned long tmp1, tmp2;
92
93         tmp1 = -4096UL;
94         /* FIXME: copy with reduced length. */
95         asm volatile(
96                 "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
97                 "   jz    2f\n"
98                 "1:"ALR"  %0,%3\n"
99                 "  "SLR"  %1,%3\n"
100                 "  "SLR"  %2,%3\n"
101                 "   j     0b\n"
102                 "2:"SLR"  %0,%0\n"
103                 "3: \n"
104                 EX_TABLE(0b,3b)
105                 : "+a" (size), "+a" (to), "+a" (from), "+a" (tmp1), "=a" (tmp2)
106                 : "d" (reg0) : "cc", "memory");
107         return size;
108 }
109
110 size_t clear_user_mvcos(size_t size, void __user *to)
111 {
112         register unsigned long reg0 asm("0") = 0x810000UL;
113         unsigned long tmp1, tmp2;
114
115         tmp1 = -4096UL;
116         asm volatile(
117                 "0: .insn ss,0xc80000000000,0(%0,%1),0(%4),0\n"
118                 "   jz    4f\n"
119                 "1:"ALR"  %0,%2\n"
120                 "  "SLR"  %1,%2\n"
121                 "   j     0b\n"
122                 "2: la    %3,4095(%1)\n"/* %4 = to + 4095 */
123                 "   nr    %3,%2\n"      /* %4 = (to + 4095) & -4096 */
124                 "  "SLR"  %3,%1\n"
125                 "  "CLR"  %0,%3\n"      /* copy crosses next page boundary? */
126                 "   jnh   5f\n"
127                 "3: .insn ss,0xc80000000000,0(%3,%1),0(%4),0\n"
128                 "  "SLR"  %0,%3\n"
129                 "   j     5f\n"
130                 "4:"SLR"  %0,%0\n"
131                 "5: \n"
132                 EX_TABLE(0b,2b) EX_TABLE(3b,5b)
133                 : "+a" (size), "+a" (to), "+a" (tmp1), "=a" (tmp2)
134                 : "a" (empty_zero_page), "d" (reg0) : "cc", "memory");
135         return size;
136 }
137
138 extern size_t copy_from_user_std_small(size_t, const void __user *, void *);
139 extern size_t copy_to_user_std_small(size_t, void __user *, const void *);
140 extern size_t strnlen_user_std(size_t, const char __user *);
141 extern size_t strncpy_from_user_std(size_t, const char __user *, char *);
142 extern int futex_atomic_op(int, int __user *, int, int *);
143 extern int futex_atomic_cmpxchg(int __user *, int, int);
144
145 struct uaccess_ops uaccess_mvcos = {
146         .copy_from_user = copy_from_user_mvcos,
147         .copy_from_user_small = copy_from_user_std_small,
148         .copy_to_user = copy_to_user_mvcos,
149         .copy_to_user_small = copy_to_user_std_small,
150         .copy_in_user = copy_in_user_mvcos,
151         .clear_user = clear_user_mvcos,
152         .strnlen_user = strnlen_user_std,
153         .strncpy_from_user = strncpy_from_user_std,
154         .futex_atomic_op = futex_atomic_op,
155         .futex_atomic_cmpxchg = futex_atomic_cmpxchg,
156 };