Merge branch 'sched-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[deliverable/linux.git] / arch / s390 / lib / uaccess_mvcos.c
... / ...
CommitLineData
1/*
2 * Optimized user space space access functions based on mvcos.
3 *
4 * Copyright IBM Corp. 2006
5 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
6 * Gerald Schaefer (gerald.schaefer@de.ibm.com)
7 */
8
9#include <linux/errno.h>
10#include <linux/mm.h>
11#include <asm/uaccess.h>
12#include <asm/futex.h>
13#include "uaccess.h"
14
15#ifndef CONFIG_64BIT
16#define AHI "ahi"
17#define ALR "alr"
18#define CLR "clr"
19#define LHI "lhi"
20#define SLR "slr"
21#else
22#define AHI "aghi"
23#define ALR "algr"
24#define CLR "clgr"
25#define LHI "lghi"
26#define SLR "slgr"
27#endif
28
29static size_t copy_from_user_mvcos(size_t size, const void __user *ptr, void *x)
30{
31 register unsigned long reg0 asm("0") = 0x81UL;
32 unsigned long tmp1, tmp2;
33
34 tmp1 = -4096UL;
35 asm volatile(
36 "0: .insn ss,0xc80000000000,0(%0,%2),0(%1),0\n"
37 "9: jz 7f\n"
38 "1:"ALR" %0,%3\n"
39 " "SLR" %1,%3\n"
40 " "SLR" %2,%3\n"
41 " j 0b\n"
42 "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */
43 " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */
44 " "SLR" %4,%1\n"
45 " "CLR" %0,%4\n" /* copy crosses next page boundary? */
46 " jnh 4f\n"
47 "3: .insn ss,0xc80000000000,0(%4,%2),0(%1),0\n"
48 "10:"SLR" %0,%4\n"
49 " "ALR" %2,%4\n"
50 "4:"LHI" %4,-1\n"
51 " "ALR" %4,%0\n" /* copy remaining size, subtract 1 */
52 " bras %3,6f\n" /* memset loop */
53 " xc 0(1,%2),0(%2)\n"
54 "5: xc 0(256,%2),0(%2)\n"
55 " la %2,256(%2)\n"
56 "6:"AHI" %4,-256\n"
57 " jnm 5b\n"
58 " ex %4,0(%3)\n"
59 " j 8f\n"
60 "7:"SLR" %0,%0\n"
61 "8: \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");
65 return size;
66}
67
68static size_t copy_to_user_mvcos(size_t size, void __user *ptr, const void *x)
69{
70 register unsigned long reg0 asm("0") = 0x810000UL;
71 unsigned long tmp1, tmp2;
72
73 tmp1 = -4096UL;
74 asm volatile(
75 "0: .insn ss,0xc80000000000,0(%0,%1),0(%2),0\n"
76 "6: jz 4f\n"
77 "1:"ALR" %0,%3\n"
78 " "SLR" %1,%3\n"
79 " "SLR" %2,%3\n"
80 " j 0b\n"
81 "2: la %4,4095(%1)\n"/* %4 = ptr + 4095 */
82 " nr %4,%3\n" /* %4 = (ptr + 4095) & -4096 */
83 " "SLR" %4,%1\n"
84 " "CLR" %0,%4\n" /* copy crosses next page boundary? */
85 " jnh 5f\n"
86 "3: .insn ss,0xc80000000000,0(%4,%1),0(%2),0\n"
87 "7:"SLR" %0,%4\n"
88 " j 5f\n"
89 "4:"SLR" %0,%0\n"
90 "5: \n"
91 EX_TABLE(0b,2b) EX_TABLE(3b,5b) EX_TABLE(6b,2b) EX_TABLE(7b,5b)
92 : "+a" (size), "+a" (ptr), "+a" (x), "+a" (tmp1), "=a" (tmp2)
93 : "d" (reg0) : "cc", "memory");
94 return size;
95}
96
97static size_t copy_in_user_mvcos(size_t size, void __user *to,
98 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
120static 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
148static size_t strnlen_user_mvcos(size_t count, const char __user *src)
149{
150 size_t done, len, offset, len_str;
151 char buf[256];
152
153 done = 0;
154 do {
155 offset = (size_t)src & ~PAGE_MASK;
156 len = min(256UL, PAGE_SIZE - offset);
157 len = min(count - done, len);
158 if (copy_from_user_mvcos(len, src, buf))
159 return 0;
160 len_str = strnlen(buf, len);
161 done += len_str;
162 src += len_str;
163 } while ((len_str == len) && (done < count));
164 return done + 1;
165}
166
167static size_t strncpy_from_user_mvcos(size_t count, const char __user *src,
168 char *dst)
169{
170 size_t done, len, offset, len_str;
171
172 if (unlikely(!count))
173 return 0;
174 done = 0;
175 do {
176 offset = (size_t)src & ~PAGE_MASK;
177 len = min(count - done, PAGE_SIZE - offset);
178 if (copy_from_user_mvcos(len, src, dst))
179 return -EFAULT;
180 len_str = strnlen(dst, len);
181 done += len_str;
182 src += len_str;
183 dst += len_str;
184 } while ((len_str == len) && (done < count));
185 return done;
186}
187
188struct uaccess_ops uaccess_mvcos = {
189 .copy_from_user = copy_from_user_mvcos,
190 .copy_to_user = copy_to_user_mvcos,
191 .copy_in_user = copy_in_user_mvcos,
192 .clear_user = clear_user_mvcos,
193 .strnlen_user = strnlen_user_mvcos,
194 .strncpy_from_user = strncpy_from_user_mvcos,
195 .futex_atomic_op = futex_atomic_op_pt,
196 .futex_atomic_cmpxchg = futex_atomic_cmpxchg_pt,
197};
This page took 0.038706 seconds and 5 git commands to generate.