Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Hans-Joachim Picht | 155af2f | 2009-06-16 10:30:52 +0200 | [diff] [blame] | 2 | * Copyright IBM Corp. 1999, 2009 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Hans-Joachim Picht | 155af2f | 2009-06-16 10:30:52 +0200 | [diff] [blame] | 4 | * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __ASM_SYSTEM_H |
| 8 | #define __ASM_SYSTEM_H |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/kernel.h> |
Heiko Carstens | 320c04c | 2008-12-25 13:38:40 +0100 | [diff] [blame] | 11 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <asm/types.h> |
| 13 | #include <asm/ptrace.h> |
| 14 | #include <asm/setup.h> |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 15 | #include <asm/processor.h> |
Heiko Carstens | 484875b | 2008-04-30 13:38:43 +0200 | [diff] [blame] | 16 | #include <asm/lowcore.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #ifdef __KERNEL__ |
| 19 | |
| 20 | struct task_struct; |
| 21 | |
| 22 | extern struct task_struct *__switch_to(void *, void *); |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 23 | extern void update_per_regs(struct task_struct *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | static inline void save_fp_regs(s390_fp_regs *fpregs) |
| 26 | { |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 27 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 28 | " std 0,%O0+8(%R0)\n" |
| 29 | " std 2,%O0+24(%R0)\n" |
| 30 | " std 4,%O0+40(%R0)\n" |
| 31 | " std 6,%O0+56(%R0)" |
| 32 | : "=Q" (*fpregs) : "Q" (*fpregs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | if (!MACHINE_HAS_IEEE) |
| 34 | return; |
| 35 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 36 | " stfpc %0\n" |
| 37 | " std 1,%O0+16(%R0)\n" |
| 38 | " std 3,%O0+32(%R0)\n" |
| 39 | " std 5,%O0+48(%R0)\n" |
| 40 | " std 7,%O0+64(%R0)\n" |
| 41 | " std 8,%O0+72(%R0)\n" |
| 42 | " std 9,%O0+80(%R0)\n" |
| 43 | " std 10,%O0+88(%R0)\n" |
| 44 | " std 11,%O0+96(%R0)\n" |
| 45 | " std 12,%O0+104(%R0)\n" |
| 46 | " std 13,%O0+112(%R0)\n" |
| 47 | " std 14,%O0+120(%R0)\n" |
| 48 | " std 15,%O0+128(%R0)\n" |
| 49 | : "=Q" (*fpregs) : "Q" (*fpregs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | static inline void restore_fp_regs(s390_fp_regs *fpregs) |
| 53 | { |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 54 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 55 | " ld 0,%O0+8(%R0)\n" |
| 56 | " ld 2,%O0+24(%R0)\n" |
| 57 | " ld 4,%O0+40(%R0)\n" |
| 58 | " ld 6,%O0+56(%R0)" |
| 59 | : : "Q" (*fpregs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | if (!MACHINE_HAS_IEEE) |
| 61 | return; |
| 62 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 63 | " lfpc %0\n" |
| 64 | " ld 1,%O0+16(%R0)\n" |
| 65 | " ld 3,%O0+32(%R0)\n" |
| 66 | " ld 5,%O0+48(%R0)\n" |
| 67 | " ld 7,%O0+64(%R0)\n" |
| 68 | " ld 8,%O0+72(%R0)\n" |
| 69 | " ld 9,%O0+80(%R0)\n" |
| 70 | " ld 10,%O0+88(%R0)\n" |
| 71 | " ld 11,%O0+96(%R0)\n" |
| 72 | " ld 12,%O0+104(%R0)\n" |
| 73 | " ld 13,%O0+112(%R0)\n" |
| 74 | " ld 14,%O0+120(%R0)\n" |
| 75 | " ld 15,%O0+128(%R0)\n" |
| 76 | : : "Q" (*fpregs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static inline void save_access_regs(unsigned int *acrs) |
| 80 | { |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 81 | asm volatile("stam 0,15,%0" : "=Q" (*acrs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static inline void restore_access_regs(unsigned int *acrs) |
| 85 | { |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 86 | asm volatile("lam 0,15,%0" : : "Q" (*acrs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Heiko Carstens | fdb6d07 | 2010-10-25 16:10:18 +0200 | [diff] [blame] | 89 | #define switch_to(prev,next,last) do { \ |
Heiko Carstens | fdb6d07 | 2010-10-25 16:10:18 +0200 | [diff] [blame] | 90 | if (prev->mm) { \ |
| 91 | save_fp_regs(&prev->thread.fp_regs); \ |
| 92 | save_access_regs(&prev->thread.acrs[0]); \ |
| 93 | } \ |
| 94 | if (next->mm) { \ |
| 95 | restore_fp_regs(&next->thread.fp_regs); \ |
| 96 | restore_access_regs(&next->thread.acrs[0]); \ |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 97 | update_per_regs(next); \ |
Heiko Carstens | fdb6d07 | 2010-10-25 16:10:18 +0200 | [diff] [blame] | 98 | } \ |
| 99 | prev = __switch_to(prev,next); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } while (0) |
| 101 | |
Martin Schwidefsky | aa5e97c | 2008-12-31 15:11:39 +0100 | [diff] [blame] | 102 | extern void account_vtime(struct task_struct *, struct task_struct *); |
Martin Schwidefsky | 1f1c12a | 2006-01-14 13:21:03 -0800 | [diff] [blame] | 103 | extern void account_tick_vtime(struct task_struct *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Heiko Carstens | 29b08d2 | 2006-12-04 15:40:40 +0100 | [diff] [blame] | 105 | #ifdef CONFIG_PFAULT |
Heiko Carstens | 29b08d2 | 2006-12-04 15:40:40 +0100 | [diff] [blame] | 106 | extern int pfault_init(void); |
| 107 | extern void pfault_fini(void); |
| 108 | #else /* CONFIG_PFAULT */ |
Heiko Carstens | 29b08d2 | 2006-12-04 15:40:40 +0100 | [diff] [blame] | 109 | #define pfault_init() ({-1;}) |
| 110 | #define pfault_fini() do { } while (0) |
| 111 | #endif /* CONFIG_PFAULT */ |
| 112 | |
Martin Schwidefsky | 45e576b | 2008-05-07 09:22:59 +0200 | [diff] [blame] | 113 | extern void cmma_init(void); |
Michael Holzheu | 92fe313 | 2010-03-24 11:49:50 +0100 | [diff] [blame] | 114 | extern int memcpy_real(void *, void *, size_t); |
Martin Schwidefsky | 45e576b | 2008-05-07 09:22:59 +0200 | [diff] [blame] | 115 | |
Heiko Carstens | 5ee24d95 | 2005-06-30 02:58:48 -0700 | [diff] [blame] | 116 | #define finish_arch_switch(prev) do { \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | set_fs(current->thread.mm_segment); \ |
Martin Schwidefsky | aa5e97c | 2008-12-31 15:11:39 +0100 | [diff] [blame] | 118 | account_vtime(prev, current); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } while (0) |
| 120 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 121 | #define nop() asm volatile("nop") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Heiko Carstens | 5a651c9 | 2006-07-17 16:09:18 +0200 | [diff] [blame] | 123 | #define xchg(ptr,x) \ |
| 124 | ({ \ |
| 125 | __typeof__(*(ptr)) __ret; \ |
| 126 | __ret = (__typeof__(*(ptr))) \ |
| 127 | __xchg((unsigned long)(x), (void *)(ptr),sizeof(*(ptr))); \ |
| 128 | __ret; \ |
| 129 | }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Heiko Carstens | 210d3a9 | 2007-10-12 16:11:41 +0200 | [diff] [blame] | 131 | extern void __xchg_called_with_bad_pointer(void); |
| 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | static inline unsigned long __xchg(unsigned long x, void * ptr, int size) |
| 134 | { |
| 135 | unsigned long addr, old; |
| 136 | int shift; |
| 137 | |
| 138 | switch (size) { |
| 139 | case 1: |
| 140 | addr = (unsigned long) ptr; |
| 141 | shift = (3 ^ (addr & 3)) << 3; |
| 142 | addr ^= addr & 3; |
| 143 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 144 | " l %0,%4\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 145 | "0: lr 0,%0\n" |
| 146 | " nr 0,%3\n" |
| 147 | " or 0,%2\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 148 | " cs %0,0,%4\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 149 | " jl 0b\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 150 | : "=&d" (old), "=Q" (*(int *) addr) |
| 151 | : "d" (x << shift), "d" (~(255 << shift)), |
| 152 | "Q" (*(int *) addr) : "memory", "cc", "0"); |
Heiko Carstens | 210d3a9 | 2007-10-12 16:11:41 +0200 | [diff] [blame] | 153 | return old >> shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | case 2: |
| 155 | addr = (unsigned long) ptr; |
| 156 | shift = (2 ^ (addr & 2)) << 3; |
| 157 | addr ^= addr & 2; |
| 158 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 159 | " l %0,%4\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 160 | "0: lr 0,%0\n" |
| 161 | " nr 0,%3\n" |
| 162 | " or 0,%2\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 163 | " cs %0,0,%4\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 164 | " jl 0b\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 165 | : "=&d" (old), "=Q" (*(int *) addr) |
| 166 | : "d" (x << shift), "d" (~(65535 << shift)), |
| 167 | "Q" (*(int *) addr) : "memory", "cc", "0"); |
Heiko Carstens | 210d3a9 | 2007-10-12 16:11:41 +0200 | [diff] [blame] | 168 | return old >> shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | case 4: |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 170 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 171 | " l %0,%3\n" |
| 172 | "0: cs %0,%2,%3\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 173 | " jl 0b\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 174 | : "=&d" (old), "=Q" (*(int *) ptr) |
| 175 | : "d" (x), "Q" (*(int *) ptr) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 176 | : "memory", "cc"); |
Heiko Carstens | 210d3a9 | 2007-10-12 16:11:41 +0200 | [diff] [blame] | 177 | return old; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | #ifdef __s390x__ |
| 179 | case 8: |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 180 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 181 | " lg %0,%3\n" |
| 182 | "0: csg %0,%2,%3\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 183 | " jl 0b\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | : "=&d" (old), "=m" (*(long *) ptr) |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 185 | : "d" (x), "Q" (*(long *) ptr) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 186 | : "memory", "cc"); |
Heiko Carstens | 210d3a9 | 2007-10-12 16:11:41 +0200 | [diff] [blame] | 187 | return old; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | #endif /* __s390x__ */ |
Heiko Carstens | 210d3a9 | 2007-10-12 16:11:41 +0200 | [diff] [blame] | 189 | } |
| 190 | __xchg_called_with_bad_pointer(); |
| 191 | return x; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /* |
| 195 | * Atomic compare and exchange. Compare OLD with MEM, if identical, |
| 196 | * store NEW in MEM. Return the initial value in MEM. Success is |
| 197 | * indicated by comparing RETURN with OLD. |
| 198 | */ |
| 199 | |
| 200 | #define __HAVE_ARCH_CMPXCHG 1 |
| 201 | |
Mathieu Desnoyers | fe41301 | 2008-02-07 00:16:24 -0800 | [diff] [blame] | 202 | #define cmpxchg(ptr, o, n) \ |
| 203 | ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \ |
| 204 | (unsigned long)(n), sizeof(*(ptr)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | |
Heiko Carstens | 210d3a9 | 2007-10-12 16:11:41 +0200 | [diff] [blame] | 206 | extern void __cmpxchg_called_with_bad_pointer(void); |
| 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | static inline unsigned long |
| 209 | __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size) |
| 210 | { |
| 211 | unsigned long addr, prev, tmp; |
| 212 | int shift; |
| 213 | |
| 214 | switch (size) { |
| 215 | case 1: |
| 216 | addr = (unsigned long) ptr; |
| 217 | shift = (3 ^ (addr & 3)) << 3; |
| 218 | addr ^= addr & 3; |
| 219 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 220 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 221 | "0: nr %0,%5\n" |
| 222 | " lr %1,%0\n" |
Christian Borntraeger | 1bff7792 | 2010-03-24 11:49:52 +0100 | [diff] [blame] | 223 | " or %0,%3\n" |
| 224 | " or %1,%4\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 225 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 226 | " jnl 1f\n" |
| 227 | " xr %1,%0\n" |
| 228 | " nr %1,%5\n" |
| 229 | " jnz 0b\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | "1:" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 231 | : "=&d" (prev), "=&d" (tmp), "=Q" (*(int *) ptr) |
| 232 | : "d" (old << shift), "d" (new << shift), |
| 233 | "d" (~(255 << shift)), "Q" (*(int *) ptr) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 234 | : "memory", "cc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | return prev >> shift; |
| 236 | case 2: |
| 237 | addr = (unsigned long) ptr; |
| 238 | shift = (2 ^ (addr & 2)) << 3; |
| 239 | addr ^= addr & 2; |
| 240 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 241 | " l %0,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 242 | "0: nr %0,%5\n" |
| 243 | " lr %1,%0\n" |
Christian Borntraeger | 1bff7792 | 2010-03-24 11:49:52 +0100 | [diff] [blame] | 244 | " or %0,%3\n" |
| 245 | " or %1,%4\n" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 246 | " cs %0,%1,%2\n" |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 247 | " jnl 1f\n" |
| 248 | " xr %1,%0\n" |
| 249 | " nr %1,%5\n" |
| 250 | " jnz 0b\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | "1:" |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 252 | : "=&d" (prev), "=&d" (tmp), "=Q" (*(int *) ptr) |
| 253 | : "d" (old << shift), "d" (new << shift), |
| 254 | "d" (~(65535 << shift)), "Q" (*(int *) ptr) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 255 | : "memory", "cc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | return prev >> shift; |
| 257 | case 4: |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 258 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 259 | " cs %0,%3,%1\n" |
| 260 | : "=&d" (prev), "=Q" (*(int *) ptr) |
| 261 | : "0" (old), "d" (new), "Q" (*(int *) ptr) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 262 | : "memory", "cc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | return prev; |
| 264 | #ifdef __s390x__ |
| 265 | case 8: |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 266 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 267 | " csg %0,%3,%1\n" |
| 268 | : "=&d" (prev), "=Q" (*(long *) ptr) |
| 269 | : "0" (old), "d" (new), "Q" (*(long *) ptr) |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 270 | : "memory", "cc"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | return prev; |
| 272 | #endif /* __s390x__ */ |
| 273 | } |
Heiko Carstens | 210d3a9 | 2007-10-12 16:11:41 +0200 | [diff] [blame] | 274 | __cmpxchg_called_with_bad_pointer(); |
| 275 | return old; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /* |
| 279 | * Force strict CPU ordering. |
| 280 | * And yes, this is required on UP too when we're talking |
| 281 | * to devices. |
| 282 | * |
| 283 | * This is very similar to the ppc eieio/sync instruction in that is |
| 284 | * does a checkpoint syncronisation & makes sure that |
| 285 | * all memory ops have completed wrt other CPU's ( see 7-15 POP DJB ). |
| 286 | */ |
| 287 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 288 | #define eieio() asm volatile("bcr 15,0" : : : "memory") |
| 289 | #define SYNC_OTHER_CORES(x) eieio() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | #define mb() eieio() |
| 291 | #define rmb() eieio() |
| 292 | #define wmb() eieio() |
| 293 | #define read_barrier_depends() do { } while(0) |
| 294 | #define smp_mb() mb() |
| 295 | #define smp_rmb() rmb() |
| 296 | #define smp_wmb() wmb() |
| 297 | #define smp_read_barrier_depends() read_barrier_depends() |
| 298 | #define smp_mb__before_clear_bit() smp_mb() |
| 299 | #define smp_mb__after_clear_bit() smp_mb() |
| 300 | |
| 301 | |
| 302 | #define set_mb(var, value) do { var = value; mb(); } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | #ifdef __s390x__ |
| 305 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 306 | #define __ctl_load(array, low, high) ({ \ |
| 307 | typedef struct { char _[sizeof(array)]; } addrtype; \ |
| 308 | asm volatile( \ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 309 | " lctlg %1,%2,%0\n" \ |
| 310 | : : "Q" (*(addrtype *)(&array)), \ |
| 311 | "i" (low), "i" (high)); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | }) |
| 313 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 314 | #define __ctl_store(array, low, high) ({ \ |
| 315 | typedef struct { char _[sizeof(array)]; } addrtype; \ |
| 316 | asm volatile( \ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 317 | " stctg %1,%2,%0\n" \ |
| 318 | : "=Q" (*(addrtype *)(&array)) \ |
| 319 | : "i" (low), "i" (high)); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | }) |
| 321 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | #else /* __s390x__ */ |
| 323 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 324 | #define __ctl_load(array, low, high) ({ \ |
| 325 | typedef struct { char _[sizeof(array)]; } addrtype; \ |
| 326 | asm volatile( \ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 327 | " lctl %1,%2,%0\n" \ |
| 328 | : : "Q" (*(addrtype *)(&array)), \ |
| 329 | "i" (low), "i" (high)); \ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 330 | }) |
| 331 | |
| 332 | #define __ctl_store(array, low, high) ({ \ |
| 333 | typedef struct { char _[sizeof(array)]; } addrtype; \ |
| 334 | asm volatile( \ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 335 | " stctl %1,%2,%0\n" \ |
| 336 | : "=Q" (*(addrtype *)(&array)) \ |
| 337 | : "i" (low), "i" (high)); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | }) |
| 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | #endif /* __s390x__ */ |
| 341 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 342 | #define __ctl_set_bit(cr, bit) ({ \ |
| 343 | unsigned long __dummy; \ |
| 344 | __ctl_store(__dummy, cr, cr); \ |
| 345 | __dummy |= 1UL << (bit); \ |
| 346 | __ctl_load(__dummy, cr, cr); \ |
| 347 | }) |
| 348 | |
| 349 | #define __ctl_clear_bit(cr, bit) ({ \ |
| 350 | unsigned long __dummy; \ |
| 351 | __ctl_store(__dummy, cr, cr); \ |
| 352 | __dummy &= ~(1UL << (bit)); \ |
| 353 | __ctl_load(__dummy, cr, cr); \ |
| 354 | }) |
| 355 | |
Heiko Carstens | 1f194a4 | 2006-07-03 00:24:46 -0700 | [diff] [blame] | 356 | #include <linux/irqflags.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Mathieu Desnoyers | fe41301 | 2008-02-07 00:16:24 -0800 | [diff] [blame] | 358 | #include <asm-generic/cmpxchg-local.h> |
| 359 | |
| 360 | static inline unsigned long __cmpxchg_local(volatile void *ptr, |
| 361 | unsigned long old, |
| 362 | unsigned long new, int size) |
| 363 | { |
| 364 | switch (size) { |
| 365 | case 1: |
| 366 | case 2: |
| 367 | case 4: |
| 368 | #ifdef __s390x__ |
| 369 | case 8: |
| 370 | #endif |
| 371 | return __cmpxchg(ptr, old, new, size); |
| 372 | default: |
| 373 | return __cmpxchg_local_generic(ptr, old, new, size); |
| 374 | } |
| 375 | |
| 376 | return old; |
| 377 | } |
| 378 | |
| 379 | /* |
| 380 | * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make |
| 381 | * them available. |
| 382 | */ |
| 383 | #define cmpxchg_local(ptr, o, n) \ |
| 384 | ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \ |
| 385 | (unsigned long)(n), sizeof(*(ptr)))) |
| 386 | #ifdef __s390x__ |
| 387 | #define cmpxchg64_local(ptr, o, n) \ |
| 388 | ({ \ |
| 389 | BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ |
| 390 | cmpxchg_local((ptr), (o), (n)); \ |
| 391 | }) |
| 392 | #else |
| 393 | #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n)) |
| 394 | #endif |
| 395 | |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 396 | /* |
| 397 | * Use to set psw mask except for the first byte which |
| 398 | * won't be changed by this function. |
| 399 | */ |
| 400 | static inline void |
| 401 | __set_psw_mask(unsigned long mask) |
| 402 | { |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 403 | __load_psw_mask(mask | (arch_local_save_flags() & ~(-1UL >> 8))); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 406 | #define local_mcck_enable() __set_psw_mask(psw_kernel_bits) |
| 407 | #define local_mcck_disable() __set_psw_mask(psw_kernel_bits & ~PSW_MASK_MCHECK) |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 408 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | #ifdef CONFIG_SMP |
| 410 | |
| 411 | extern void smp_ctl_set_bit(int cr, int bit); |
| 412 | extern void smp_ctl_clear_bit(int cr, int bit); |
| 413 | #define ctl_set_bit(cr, bit) smp_ctl_set_bit(cr, bit) |
| 414 | #define ctl_clear_bit(cr, bit) smp_ctl_clear_bit(cr, bit) |
| 415 | |
| 416 | #else |
| 417 | |
| 418 | #define ctl_set_bit(cr, bit) __ctl_set_bit(cr, bit) |
| 419 | #define ctl_clear_bit(cr, bit) __ctl_clear_bit(cr, bit) |
| 420 | |
| 421 | #endif /* CONFIG_SMP */ |
| 422 | |
Martin Schwidefsky | 14375bc | 2010-10-25 16:10:51 +0200 | [diff] [blame] | 423 | #define MAX_FACILITY_BIT (256*8) /* stfle_fac_list has 256 bytes */ |
Heiko Carstens | 484875b | 2008-04-30 13:38:43 +0200 | [diff] [blame] | 424 | |
Martin Schwidefsky | 14375bc | 2010-10-25 16:10:51 +0200 | [diff] [blame] | 425 | /* |
| 426 | * The test_facility function uses the bit odering where the MSB is bit 0. |
| 427 | * That makes it easier to query facility bits with the bit number as |
| 428 | * documented in the Principles of Operation. |
| 429 | */ |
| 430 | static inline int test_facility(unsigned long nr) |
Heiko Carstens | 320c04c | 2008-12-25 13:38:40 +0100 | [diff] [blame] | 431 | { |
Martin Schwidefsky | 14375bc | 2010-10-25 16:10:51 +0200 | [diff] [blame] | 432 | unsigned char *ptr; |
Heiko Carstens | 320c04c | 2008-12-25 13:38:40 +0100 | [diff] [blame] | 433 | |
Martin Schwidefsky | 14375bc | 2010-10-25 16:10:51 +0200 | [diff] [blame] | 434 | if (nr >= MAX_FACILITY_BIT) |
| 435 | return 0; |
| 436 | ptr = (unsigned char *) &S390_lowcore.stfle_fac_list + (nr >> 3); |
| 437 | return (*ptr & (0x80 >> (nr & 7))) != 0; |
Heiko Carstens | 320c04c | 2008-12-25 13:38:40 +0100 | [diff] [blame] | 438 | } |
| 439 | |
Heiko Carstens | 2e5061e | 2008-04-30 13:38:45 +0200 | [diff] [blame] | 440 | static inline unsigned short stap(void) |
| 441 | { |
| 442 | unsigned short cpu_address; |
| 443 | |
| 444 | asm volatile("stap %0" : "=m" (cpu_address)); |
| 445 | return cpu_address; |
| 446 | } |
| 447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | extern void (*_machine_restart)(char *command); |
| 449 | extern void (*_machine_halt)(void); |
| 450 | extern void (*_machine_power_off)(void); |
| 451 | |
Heiko Carstens | 9887a1f | 2011-01-12 09:55:28 +0100 | [diff] [blame] | 452 | extern unsigned long arch_align_stack(unsigned long sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
Hans-Joachim Picht | 155af2f | 2009-06-16 10:30:52 +0200 | [diff] [blame] | 454 | static inline int tprot(unsigned long addr) |
| 455 | { |
| 456 | int rc = -EFAULT; |
| 457 | |
| 458 | asm volatile( |
| 459 | " tprot 0(%1),0\n" |
| 460 | "0: ipm %0\n" |
| 461 | " srl %0,28\n" |
| 462 | "1:\n" |
| 463 | EX_TABLE(0b,1b) |
| 464 | : "+d" (rc) : "a" (addr) : "cc"); |
| 465 | return rc; |
| 466 | } |
| 467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | #endif /* __KERNEL__ */ |
| 469 | |
| 470 | #endif |