blob: c35d0a383f0015759efb8ecf6f2eedfba343c385 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Hans-Joachim Picht155af2f2009-06-16 10:30:52 +02002 * Copyright IBM Corp. 1999, 2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
Hans-Joachim Picht155af2f2009-06-16 10:30:52 +02004 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6
7#ifndef __ASM_SYSTEM_H
8#define __ASM_SYSTEM_H
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/kernel.h>
Heiko Carstens320c04c2008-12-25 13:38:40 +010011#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <asm/types.h>
13#include <asm/ptrace.h>
14#include <asm/setup.h>
Heiko Carstens77fa2242005-06-25 14:55:30 -070015#include <asm/processor.h>
Heiko Carstens484875b2008-04-30 13:38:43 +020016#include <asm/lowcore.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18#ifdef __KERNEL__
19
20struct task_struct;
21
22extern struct task_struct *__switch_to(void *, void *);
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static inline void save_fp_regs(s390_fp_regs *fpregs)
25{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020026 asm volatile(
Martin Schwidefsky987bcda2010-02-26 22:37:31 +010027 " std 0,%O0+8(%R0)\n"
28 " std 2,%O0+24(%R0)\n"
29 " std 4,%O0+40(%R0)\n"
30 " std 6,%O0+56(%R0)"
31 : "=Q" (*fpregs) : "Q" (*fpregs));
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 if (!MACHINE_HAS_IEEE)
33 return;
34 asm volatile(
Martin Schwidefsky987bcda2010-02-26 22:37:31 +010035 " stfpc %0\n"
36 " std 1,%O0+16(%R0)\n"
37 " std 3,%O0+32(%R0)\n"
38 " std 5,%O0+48(%R0)\n"
39 " std 7,%O0+64(%R0)\n"
40 " std 8,%O0+72(%R0)\n"
41 " std 9,%O0+80(%R0)\n"
42 " std 10,%O0+88(%R0)\n"
43 " std 11,%O0+96(%R0)\n"
44 " std 12,%O0+104(%R0)\n"
45 " std 13,%O0+112(%R0)\n"
46 " std 14,%O0+120(%R0)\n"
47 " std 15,%O0+128(%R0)\n"
48 : "=Q" (*fpregs) : "Q" (*fpregs));
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
51static inline void restore_fp_regs(s390_fp_regs *fpregs)
52{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +020053 asm volatile(
Martin Schwidefsky987bcda2010-02-26 22:37:31 +010054 " ld 0,%O0+8(%R0)\n"
55 " ld 2,%O0+24(%R0)\n"
56 " ld 4,%O0+40(%R0)\n"
57 " ld 6,%O0+56(%R0)"
58 : : "Q" (*fpregs));
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 if (!MACHINE_HAS_IEEE)
60 return;
61 asm volatile(
Martin Schwidefsky987bcda2010-02-26 22:37:31 +010062 " lfpc %0\n"
63 " ld 1,%O0+16(%R0)\n"
64 " ld 3,%O0+32(%R0)\n"
65 " ld 5,%O0+48(%R0)\n"
66 " ld 7,%O0+64(%R0)\n"
67 " ld 8,%O0+72(%R0)\n"
68 " ld 9,%O0+80(%R0)\n"
69 " ld 10,%O0+88(%R0)\n"
70 " ld 11,%O0+96(%R0)\n"
71 " ld 12,%O0+104(%R0)\n"
72 " ld 13,%O0+112(%R0)\n"
73 " ld 14,%O0+120(%R0)\n"
74 " ld 15,%O0+128(%R0)\n"
75 : : "Q" (*fpregs));
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
77
78static inline void save_access_regs(unsigned int *acrs)
79{
Martin Schwidefsky987bcda2010-02-26 22:37:31 +010080 asm volatile("stam 0,15,%0" : "=Q" (*acrs));
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
83static inline void restore_access_regs(unsigned int *acrs)
84{
Martin Schwidefsky987bcda2010-02-26 22:37:31 +010085 asm volatile("lam 0,15,%0" : : "Q" (*acrs));
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
Heiko Carstensfdb6d072010-10-25 16:10:18 +020088#define switch_to(prev,next,last) do { \
89 if (prev == next) \
90 break; \
91 if (prev->mm) { \
92 save_fp_regs(&prev->thread.fp_regs); \
93 save_access_regs(&prev->thread.acrs[0]); \
94 } \
95 if (next->mm) { \
96 restore_fp_regs(&next->thread.fp_regs); \
97 restore_access_regs(&next->thread.acrs[0]); \
98 } \
99 prev = __switch_to(prev,next); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100} while (0)
101
Martin Schwidefskyaa5e97c2008-12-31 15:11:39 +0100102extern void account_vtime(struct task_struct *, struct task_struct *);
Martin Schwidefsky1f1c12a2006-01-14 13:21:03 -0800103extern void account_tick_vtime(struct task_struct *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Heiko Carstens29b08d22006-12-04 15:40:40 +0100105#ifdef CONFIG_PFAULT
106extern void pfault_irq_init(void);
107extern int pfault_init(void);
108extern void pfault_fini(void);
109#else /* CONFIG_PFAULT */
110#define pfault_irq_init() do { } while (0)
111#define pfault_init() ({-1;})
112#define pfault_fini() do { } while (0)
113#endif /* CONFIG_PFAULT */
114
Martin Schwidefsky45e576b2008-05-07 09:22:59 +0200115extern void cmma_init(void);
Michael Holzheu92fe3132010-03-24 11:49:50 +0100116extern int memcpy_real(void *, void *, size_t);
Martin Schwidefsky45e576b2008-05-07 09:22:59 +0200117
Heiko Carstens5ee24d952005-06-30 02:58:48 -0700118#define finish_arch_switch(prev) do { \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 set_fs(current->thread.mm_segment); \
Martin Schwidefskyaa5e97c2008-12-31 15:11:39 +0100120 account_vtime(prev, current); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121} while (0)
122
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200123#define nop() asm volatile("nop")
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Heiko Carstens5a651c92006-07-17 16:09:18 +0200125#define xchg(ptr,x) \
126({ \
127 __typeof__(*(ptr)) __ret; \
128 __ret = (__typeof__(*(ptr))) \
129 __xchg((unsigned long)(x), (void *)(ptr),sizeof(*(ptr))); \
130 __ret; \
131})
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Heiko Carstens210d3a92007-10-12 16:11:41 +0200133extern void __xchg_called_with_bad_pointer(void);
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135static inline unsigned long __xchg(unsigned long x, void * ptr, int size)
136{
137 unsigned long addr, old;
138 int shift;
139
140 switch (size) {
141 case 1:
142 addr = (unsigned long) ptr;
143 shift = (3 ^ (addr & 3)) << 3;
144 addr ^= addr & 3;
145 asm volatile(
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100146 " l %0,%4\n"
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200147 "0: lr 0,%0\n"
148 " nr 0,%3\n"
149 " or 0,%2\n"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100150 " cs %0,0,%4\n"
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200151 " jl 0b\n"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100152 : "=&d" (old), "=Q" (*(int *) addr)
153 : "d" (x << shift), "d" (~(255 << shift)),
154 "Q" (*(int *) addr) : "memory", "cc", "0");
Heiko Carstens210d3a92007-10-12 16:11:41 +0200155 return old >> shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 case 2:
157 addr = (unsigned long) ptr;
158 shift = (2 ^ (addr & 2)) << 3;
159 addr ^= addr & 2;
160 asm volatile(
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100161 " l %0,%4\n"
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200162 "0: lr 0,%0\n"
163 " nr 0,%3\n"
164 " or 0,%2\n"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100165 " cs %0,0,%4\n"
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200166 " jl 0b\n"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100167 : "=&d" (old), "=Q" (*(int *) addr)
168 : "d" (x << shift), "d" (~(65535 << shift)),
169 "Q" (*(int *) addr) : "memory", "cc", "0");
Heiko Carstens210d3a92007-10-12 16:11:41 +0200170 return old >> shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 case 4:
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200172 asm volatile(
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100173 " l %0,%3\n"
174 "0: cs %0,%2,%3\n"
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200175 " jl 0b\n"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100176 : "=&d" (old), "=Q" (*(int *) ptr)
177 : "d" (x), "Q" (*(int *) ptr)
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200178 : "memory", "cc");
Heiko Carstens210d3a92007-10-12 16:11:41 +0200179 return old;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180#ifdef __s390x__
181 case 8:
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200182 asm volatile(
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100183 " lg %0,%3\n"
184 "0: csg %0,%2,%3\n"
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200185 " jl 0b\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 : "=&d" (old), "=m" (*(long *) ptr)
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100187 : "d" (x), "Q" (*(long *) ptr)
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200188 : "memory", "cc");
Heiko Carstens210d3a92007-10-12 16:11:41 +0200189 return old;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190#endif /* __s390x__ */
Heiko Carstens210d3a92007-10-12 16:11:41 +0200191 }
192 __xchg_called_with_bad_pointer();
193 return x;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194}
195
196/*
197 * Atomic compare and exchange. Compare OLD with MEM, if identical,
198 * store NEW in MEM. Return the initial value in MEM. Success is
199 * indicated by comparing RETURN with OLD.
200 */
201
202#define __HAVE_ARCH_CMPXCHG 1
203
Mathieu Desnoyersfe413012008-02-07 00:16:24 -0800204#define cmpxchg(ptr, o, n) \
205 ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
206 (unsigned long)(n), sizeof(*(ptr))))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Heiko Carstens210d3a92007-10-12 16:11:41 +0200208extern void __cmpxchg_called_with_bad_pointer(void);
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210static inline unsigned long
211__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
212{
213 unsigned long addr, prev, tmp;
214 int shift;
215
216 switch (size) {
217 case 1:
218 addr = (unsigned long) ptr;
219 shift = (3 ^ (addr & 3)) << 3;
220 addr ^= addr & 3;
221 asm volatile(
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100222 " l %0,%2\n"
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200223 "0: nr %0,%5\n"
224 " lr %1,%0\n"
Christian Borntraeger1bff77922010-03-24 11:49:52 +0100225 " or %0,%3\n"
226 " or %1,%4\n"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100227 " cs %0,%1,%2\n"
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200228 " jnl 1f\n"
229 " xr %1,%0\n"
230 " nr %1,%5\n"
231 " jnz 0b\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 "1:"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100233 : "=&d" (prev), "=&d" (tmp), "=Q" (*(int *) ptr)
234 : "d" (old << shift), "d" (new << shift),
235 "d" (~(255 << shift)), "Q" (*(int *) ptr)
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200236 : "memory", "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 return prev >> shift;
238 case 2:
239 addr = (unsigned long) ptr;
240 shift = (2 ^ (addr & 2)) << 3;
241 addr ^= addr & 2;
242 asm volatile(
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100243 " l %0,%2\n"
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200244 "0: nr %0,%5\n"
245 " lr %1,%0\n"
Christian Borntraeger1bff77922010-03-24 11:49:52 +0100246 " or %0,%3\n"
247 " or %1,%4\n"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100248 " cs %0,%1,%2\n"
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200249 " jnl 1f\n"
250 " xr %1,%0\n"
251 " nr %1,%5\n"
252 " jnz 0b\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 "1:"
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100254 : "=&d" (prev), "=&d" (tmp), "=Q" (*(int *) ptr)
255 : "d" (old << shift), "d" (new << shift),
256 "d" (~(65535 << shift)), "Q" (*(int *) ptr)
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200257 : "memory", "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 return prev >> shift;
259 case 4:
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200260 asm volatile(
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100261 " cs %0,%3,%1\n"
262 : "=&d" (prev), "=Q" (*(int *) ptr)
263 : "0" (old), "d" (new), "Q" (*(int *) ptr)
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200264 : "memory", "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 return prev;
266#ifdef __s390x__
267 case 8:
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200268 asm volatile(
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100269 " csg %0,%3,%1\n"
270 : "=&d" (prev), "=Q" (*(long *) ptr)
271 : "0" (old), "d" (new), "Q" (*(long *) ptr)
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200272 : "memory", "cc");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 return prev;
274#endif /* __s390x__ */
275 }
Heiko Carstens210d3a92007-10-12 16:11:41 +0200276 __cmpxchg_called_with_bad_pointer();
277 return old;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278}
279
280/*
281 * Force strict CPU ordering.
282 * And yes, this is required on UP too when we're talking
283 * to devices.
284 *
285 * This is very similar to the ppc eieio/sync instruction in that is
286 * does a checkpoint syncronisation & makes sure that
287 * all memory ops have completed wrt other CPU's ( see 7-15 POP DJB ).
288 */
289
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200290#define eieio() asm volatile("bcr 15,0" : : : "memory")
291#define SYNC_OTHER_CORES(x) eieio()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292#define mb() eieio()
293#define rmb() eieio()
294#define wmb() eieio()
295#define read_barrier_depends() do { } while(0)
296#define smp_mb() mb()
297#define smp_rmb() rmb()
298#define smp_wmb() wmb()
299#define smp_read_barrier_depends() read_barrier_depends()
300#define smp_mb__before_clear_bit() smp_mb()
301#define smp_mb__after_clear_bit() smp_mb()
302
303
304#define set_mb(var, value) do { var = value; mb(); } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306#ifdef __s390x__
307
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200308#define __ctl_load(array, low, high) ({ \
309 typedef struct { char _[sizeof(array)]; } addrtype; \
310 asm volatile( \
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100311 " lctlg %1,%2,%0\n" \
312 : : "Q" (*(addrtype *)(&array)), \
313 "i" (low), "i" (high)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 })
315
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200316#define __ctl_store(array, low, high) ({ \
317 typedef struct { char _[sizeof(array)]; } addrtype; \
318 asm volatile( \
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100319 " stctg %1,%2,%0\n" \
320 : "=Q" (*(addrtype *)(&array)) \
321 : "i" (low), "i" (high)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 })
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324#else /* __s390x__ */
325
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200326#define __ctl_load(array, low, high) ({ \
327 typedef struct { char _[sizeof(array)]; } addrtype; \
328 asm volatile( \
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100329 " lctl %1,%2,%0\n" \
330 : : "Q" (*(addrtype *)(&array)), \
331 "i" (low), "i" (high)); \
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200332})
333
334#define __ctl_store(array, low, high) ({ \
335 typedef struct { char _[sizeof(array)]; } addrtype; \
336 asm volatile( \
Martin Schwidefsky987bcda2010-02-26 22:37:31 +0100337 " stctl %1,%2,%0\n" \
338 : "=Q" (*(addrtype *)(&array)) \
339 : "i" (low), "i" (high)); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 })
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342#endif /* __s390x__ */
343
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200344#define __ctl_set_bit(cr, bit) ({ \
345 unsigned long __dummy; \
346 __ctl_store(__dummy, cr, cr); \
347 __dummy |= 1UL << (bit); \
348 __ctl_load(__dummy, cr, cr); \
349})
350
351#define __ctl_clear_bit(cr, bit) ({ \
352 unsigned long __dummy; \
353 __ctl_store(__dummy, cr, cr); \
354 __dummy &= ~(1UL << (bit)); \
355 __ctl_load(__dummy, cr, cr); \
356})
357
Heiko Carstens1f194a42006-07-03 00:24:46 -0700358#include <linux/irqflags.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Mathieu Desnoyersfe413012008-02-07 00:16:24 -0800360#include <asm-generic/cmpxchg-local.h>
361
362static inline unsigned long __cmpxchg_local(volatile void *ptr,
363 unsigned long old,
364 unsigned long new, int size)
365{
366 switch (size) {
367 case 1:
368 case 2:
369 case 4:
370#ifdef __s390x__
371 case 8:
372#endif
373 return __cmpxchg(ptr, old, new, size);
374 default:
375 return __cmpxchg_local_generic(ptr, old, new, size);
376 }
377
378 return old;
379}
380
381/*
382 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
383 * them available.
384 */
385#define cmpxchg_local(ptr, o, n) \
386 ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \
387 (unsigned long)(n), sizeof(*(ptr))))
388#ifdef __s390x__
389#define cmpxchg64_local(ptr, o, n) \
390 ({ \
391 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
392 cmpxchg_local((ptr), (o), (n)); \
393 })
394#else
395#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
396#endif
397
Heiko Carstens77fa2242005-06-25 14:55:30 -0700398/*
399 * Use to set psw mask except for the first byte which
400 * won't be changed by this function.
401 */
402static inline void
403__set_psw_mask(unsigned long mask)
404{
David Howellsdf9ee292010-10-07 14:08:55 +0100405 __load_psw_mask(mask | (arch_local_save_flags() & ~(-1UL >> 8)));
Heiko Carstens77fa2242005-06-25 14:55:30 -0700406}
407
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100408#define local_mcck_enable() __set_psw_mask(psw_kernel_bits)
409#define local_mcck_disable() __set_psw_mask(psw_kernel_bits & ~PSW_MASK_MCHECK)
Heiko Carstens77fa2242005-06-25 14:55:30 -0700410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#ifdef CONFIG_SMP
412
413extern void smp_ctl_set_bit(int cr, int bit);
414extern void smp_ctl_clear_bit(int cr, int bit);
415#define ctl_set_bit(cr, bit) smp_ctl_set_bit(cr, bit)
416#define ctl_clear_bit(cr, bit) smp_ctl_clear_bit(cr, bit)
417
418#else
419
420#define ctl_set_bit(cr, bit) __ctl_set_bit(cr, bit)
421#define ctl_clear_bit(cr, bit) __ctl_clear_bit(cr, bit)
422
423#endif /* CONFIG_SMP */
424
Heiko Carstens484875b2008-04-30 13:38:43 +0200425static inline unsigned int stfl(void)
426{
427 asm volatile(
428 " .insn s,0xb2b10000,0(0)\n" /* stfl */
429 "0:\n"
430 EX_TABLE(0b,0b));
431 return S390_lowcore.stfl_fac_list;
432}
433
Heiko Carstens320c04c2008-12-25 13:38:40 +0100434static inline int __stfle(unsigned long long *list, int doublewords)
435{
436 typedef struct { unsigned long long _[doublewords]; } addrtype;
437 register unsigned long __nr asm("0") = doublewords - 1;
438
439 asm volatile(".insn s,0xb2b00000,%0" /* stfle */
440 : "=m" (*(addrtype *) list), "+d" (__nr) : : "cc");
441 return __nr + 1;
442}
443
444static inline int stfle(unsigned long long *list, int doublewords)
445{
446 if (!(stfl() & (1UL << 24)))
447 return -EOPNOTSUPP;
448 return __stfle(list, doublewords);
449}
450
Heiko Carstens2e5061e2008-04-30 13:38:45 +0200451static inline unsigned short stap(void)
452{
453 unsigned short cpu_address;
454
455 asm volatile("stap %0" : "=m" (cpu_address));
456 return cpu_address;
457}
458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459extern void (*_machine_restart)(char *command);
460extern void (*_machine_halt)(void);
461extern void (*_machine_power_off)(void);
462
463#define arch_align_stack(x) (x)
464
Hans-Joachim Picht155af2f2009-06-16 10:30:52 +0200465static inline int tprot(unsigned long addr)
466{
467 int rc = -EFAULT;
468
469 asm volatile(
470 " tprot 0(%1),0\n"
471 "0: ipm %0\n"
472 " srl %0,28\n"
473 "1:\n"
474 EX_TABLE(0b,1b)
475 : "+d" (rc) : "a" (addr) : "cc");
476 return rc;
477}
478
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479#endif /* __KERNEL__ */
480
481#endif