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> |
Heiko Carstens | a2c9dbe | 2011-03-23 10:16:05 +0100 | [diff] [blame] | 17 | #include <asm/cmpxchg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | #ifdef __KERNEL__ |
| 20 | |
| 21 | struct task_struct; |
| 22 | |
| 23 | extern struct task_struct *__switch_to(void *, void *); |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 24 | extern void update_per_regs(struct task_struct *task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | static inline void save_fp_regs(s390_fp_regs *fpregs) |
| 27 | { |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 28 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 29 | " std 0,%O0+8(%R0)\n" |
| 30 | " std 2,%O0+24(%R0)\n" |
| 31 | " std 4,%O0+40(%R0)\n" |
| 32 | " std 6,%O0+56(%R0)" |
| 33 | : "=Q" (*fpregs) : "Q" (*fpregs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | if (!MACHINE_HAS_IEEE) |
| 35 | return; |
| 36 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 37 | " stfpc %0\n" |
| 38 | " std 1,%O0+16(%R0)\n" |
| 39 | " std 3,%O0+32(%R0)\n" |
| 40 | " std 5,%O0+48(%R0)\n" |
| 41 | " std 7,%O0+64(%R0)\n" |
| 42 | " std 8,%O0+72(%R0)\n" |
| 43 | " std 9,%O0+80(%R0)\n" |
| 44 | " std 10,%O0+88(%R0)\n" |
| 45 | " std 11,%O0+96(%R0)\n" |
| 46 | " std 12,%O0+104(%R0)\n" |
| 47 | " std 13,%O0+112(%R0)\n" |
| 48 | " std 14,%O0+120(%R0)\n" |
| 49 | " std 15,%O0+128(%R0)\n" |
| 50 | : "=Q" (*fpregs) : "Q" (*fpregs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | static inline void restore_fp_regs(s390_fp_regs *fpregs) |
| 54 | { |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 55 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 56 | " ld 0,%O0+8(%R0)\n" |
| 57 | " ld 2,%O0+24(%R0)\n" |
| 58 | " ld 4,%O0+40(%R0)\n" |
| 59 | " ld 6,%O0+56(%R0)" |
| 60 | : : "Q" (*fpregs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | if (!MACHINE_HAS_IEEE) |
| 62 | return; |
| 63 | asm volatile( |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 64 | " lfpc %0\n" |
| 65 | " ld 1,%O0+16(%R0)\n" |
| 66 | " ld 3,%O0+32(%R0)\n" |
| 67 | " ld 5,%O0+48(%R0)\n" |
| 68 | " ld 7,%O0+64(%R0)\n" |
| 69 | " ld 8,%O0+72(%R0)\n" |
| 70 | " ld 9,%O0+80(%R0)\n" |
| 71 | " ld 10,%O0+88(%R0)\n" |
| 72 | " ld 11,%O0+96(%R0)\n" |
| 73 | " ld 12,%O0+104(%R0)\n" |
| 74 | " ld 13,%O0+112(%R0)\n" |
| 75 | " ld 14,%O0+120(%R0)\n" |
| 76 | " ld 15,%O0+128(%R0)\n" |
| 77 | : : "Q" (*fpregs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | static inline void save_access_regs(unsigned int *acrs) |
| 81 | { |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 82 | asm volatile("stam 0,15,%0" : "=Q" (*acrs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static inline void restore_access_regs(unsigned int *acrs) |
| 86 | { |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 87 | asm volatile("lam 0,15,%0" : : "Q" (*acrs)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Heiko Carstens | fdb6d07 | 2010-10-25 16:10:18 +0200 | [diff] [blame] | 90 | #define switch_to(prev,next,last) do { \ |
Heiko Carstens | fdb6d07 | 2010-10-25 16:10:18 +0200 | [diff] [blame] | 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]); \ |
Martin Schwidefsky | 5e9a269 | 2011-01-05 12:48:10 +0100 | [diff] [blame] | 98 | update_per_regs(next); \ |
Heiko Carstens | fdb6d07 | 2010-10-25 16:10:18 +0200 | [diff] [blame] | 99 | } \ |
| 100 | prev = __switch_to(prev,next); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } while (0) |
| 102 | |
Martin Schwidefsky | aa5e97c | 2008-12-31 15:11:39 +0100 | [diff] [blame] | 103 | extern void account_vtime(struct task_struct *, struct task_struct *); |
Martin Schwidefsky | 1f1c12a | 2006-01-14 13:21:03 -0800 | [diff] [blame] | 104 | extern void account_tick_vtime(struct task_struct *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Heiko Carstens | 29b08d2 | 2006-12-04 15:40:40 +0100 | [diff] [blame] | 106 | #ifdef CONFIG_PFAULT |
Heiko Carstens | 29b08d2 | 2006-12-04 15:40:40 +0100 | [diff] [blame] | 107 | extern int pfault_init(void); |
| 108 | extern void pfault_fini(void); |
| 109 | #else /* CONFIG_PFAULT */ |
Heiko Carstens | 29b08d2 | 2006-12-04 15:40:40 +0100 | [diff] [blame] | 110 | #define pfault_init() ({-1;}) |
| 111 | #define pfault_fini() do { } while (0) |
| 112 | #endif /* CONFIG_PFAULT */ |
| 113 | |
Martin Schwidefsky | 45e576b | 2008-05-07 09:22:59 +0200 | [diff] [blame] | 114 | extern void cmma_init(void); |
Michael Holzheu | 92fe313 | 2010-03-24 11:49:50 +0100 | [diff] [blame] | 115 | extern int memcpy_real(void *, void *, size_t); |
Martin Schwidefsky | 45e576b | 2008-05-07 09:22:59 +0200 | [diff] [blame] | 116 | |
Heiko Carstens | 5ee24d95 | 2005-06-30 02:58:48 -0700 | [diff] [blame] | 117 | #define finish_arch_switch(prev) do { \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | set_fs(current->thread.mm_segment); \ |
Martin Schwidefsky | aa5e97c | 2008-12-31 15:11:39 +0100 | [diff] [blame] | 119 | account_vtime(prev, current); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } while (0) |
| 121 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 122 | #define nop() asm volatile("nop") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | /* |
| 125 | * Force strict CPU ordering. |
| 126 | * And yes, this is required on UP too when we're talking |
| 127 | * to devices. |
| 128 | * |
| 129 | * This is very similar to the ppc eieio/sync instruction in that is |
| 130 | * does a checkpoint syncronisation & makes sure that |
| 131 | * all memory ops have completed wrt other CPU's ( see 7-15 POP DJB ). |
| 132 | */ |
| 133 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 134 | #define eieio() asm volatile("bcr 15,0" : : : "memory") |
| 135 | #define SYNC_OTHER_CORES(x) eieio() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | #define mb() eieio() |
| 137 | #define rmb() eieio() |
| 138 | #define wmb() eieio() |
| 139 | #define read_barrier_depends() do { } while(0) |
| 140 | #define smp_mb() mb() |
| 141 | #define smp_rmb() rmb() |
| 142 | #define smp_wmb() wmb() |
| 143 | #define smp_read_barrier_depends() read_barrier_depends() |
| 144 | #define smp_mb__before_clear_bit() smp_mb() |
| 145 | #define smp_mb__after_clear_bit() smp_mb() |
| 146 | |
| 147 | |
| 148 | #define set_mb(var, value) do { var = value; mb(); } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | #ifdef __s390x__ |
| 151 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 152 | #define __ctl_load(array, low, high) ({ \ |
| 153 | typedef struct { char _[sizeof(array)]; } addrtype; \ |
| 154 | asm volatile( \ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 155 | " lctlg %1,%2,%0\n" \ |
| 156 | : : "Q" (*(addrtype *)(&array)), \ |
| 157 | "i" (low), "i" (high)); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | }) |
| 159 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 160 | #define __ctl_store(array, low, high) ({ \ |
| 161 | typedef struct { char _[sizeof(array)]; } addrtype; \ |
| 162 | asm volatile( \ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 163 | " stctg %1,%2,%0\n" \ |
| 164 | : "=Q" (*(addrtype *)(&array)) \ |
| 165 | : "i" (low), "i" (high)); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | }) |
| 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | #else /* __s390x__ */ |
| 169 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 170 | #define __ctl_load(array, low, high) ({ \ |
| 171 | typedef struct { char _[sizeof(array)]; } addrtype; \ |
| 172 | asm volatile( \ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 173 | " lctl %1,%2,%0\n" \ |
| 174 | : : "Q" (*(addrtype *)(&array)), \ |
| 175 | "i" (low), "i" (high)); \ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 176 | }) |
| 177 | |
| 178 | #define __ctl_store(array, low, high) ({ \ |
| 179 | typedef struct { char _[sizeof(array)]; } addrtype; \ |
| 180 | asm volatile( \ |
Martin Schwidefsky | 987bcda | 2010-02-26 22:37:31 +0100 | [diff] [blame] | 181 | " stctl %1,%2,%0\n" \ |
| 182 | : "=Q" (*(addrtype *)(&array)) \ |
| 183 | : "i" (low), "i" (high)); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | }) |
| 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | #endif /* __s390x__ */ |
| 187 | |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 188 | #define __ctl_set_bit(cr, bit) ({ \ |
| 189 | unsigned long __dummy; \ |
| 190 | __ctl_store(__dummy, cr, cr); \ |
| 191 | __dummy |= 1UL << (bit); \ |
| 192 | __ctl_load(__dummy, cr, cr); \ |
| 193 | }) |
| 194 | |
| 195 | #define __ctl_clear_bit(cr, bit) ({ \ |
| 196 | unsigned long __dummy; \ |
| 197 | __ctl_store(__dummy, cr, cr); \ |
| 198 | __dummy &= ~(1UL << (bit)); \ |
| 199 | __ctl_load(__dummy, cr, cr); \ |
| 200 | }) |
| 201 | |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 202 | /* |
| 203 | * Use to set psw mask except for the first byte which |
| 204 | * won't be changed by this function. |
| 205 | */ |
| 206 | static inline void |
| 207 | __set_psw_mask(unsigned long mask) |
| 208 | { |
David Howells | df9ee29 | 2010-10-07 14:08:55 +0100 | [diff] [blame] | 209 | __load_psw_mask(mask | (arch_local_save_flags() & ~(-1UL >> 8))); |
Heiko Carstens | 77fa224 | 2005-06-25 14:55:30 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 212 | #define local_mcck_enable() __set_psw_mask(psw_kernel_bits) |
| 213 | #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] | 214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | #ifdef CONFIG_SMP |
| 216 | |
| 217 | extern void smp_ctl_set_bit(int cr, int bit); |
| 218 | extern void smp_ctl_clear_bit(int cr, int bit); |
| 219 | #define ctl_set_bit(cr, bit) smp_ctl_set_bit(cr, bit) |
| 220 | #define ctl_clear_bit(cr, bit) smp_ctl_clear_bit(cr, bit) |
| 221 | |
| 222 | #else |
| 223 | |
| 224 | #define ctl_set_bit(cr, bit) __ctl_set_bit(cr, bit) |
| 225 | #define ctl_clear_bit(cr, bit) __ctl_clear_bit(cr, bit) |
| 226 | |
| 227 | #endif /* CONFIG_SMP */ |
| 228 | |
Martin Schwidefsky | 14375bc | 2010-10-25 16:10:51 +0200 | [diff] [blame] | 229 | #define MAX_FACILITY_BIT (256*8) /* stfle_fac_list has 256 bytes */ |
Heiko Carstens | 484875b | 2008-04-30 13:38:43 +0200 | [diff] [blame] | 230 | |
Martin Schwidefsky | 14375bc | 2010-10-25 16:10:51 +0200 | [diff] [blame] | 231 | /* |
| 232 | * The test_facility function uses the bit odering where the MSB is bit 0. |
| 233 | * That makes it easier to query facility bits with the bit number as |
| 234 | * documented in the Principles of Operation. |
| 235 | */ |
| 236 | static inline int test_facility(unsigned long nr) |
Heiko Carstens | 320c04c | 2008-12-25 13:38:40 +0100 | [diff] [blame] | 237 | { |
Martin Schwidefsky | 14375bc | 2010-10-25 16:10:51 +0200 | [diff] [blame] | 238 | unsigned char *ptr; |
Heiko Carstens | 320c04c | 2008-12-25 13:38:40 +0100 | [diff] [blame] | 239 | |
Martin Schwidefsky | 14375bc | 2010-10-25 16:10:51 +0200 | [diff] [blame] | 240 | if (nr >= MAX_FACILITY_BIT) |
| 241 | return 0; |
| 242 | ptr = (unsigned char *) &S390_lowcore.stfle_fac_list + (nr >> 3); |
| 243 | return (*ptr & (0x80 >> (nr & 7))) != 0; |
Heiko Carstens | 320c04c | 2008-12-25 13:38:40 +0100 | [diff] [blame] | 244 | } |
| 245 | |
Heiko Carstens | 2e5061e | 2008-04-30 13:38:45 +0200 | [diff] [blame] | 246 | static inline unsigned short stap(void) |
| 247 | { |
| 248 | unsigned short cpu_address; |
| 249 | |
| 250 | asm volatile("stap %0" : "=m" (cpu_address)); |
| 251 | return cpu_address; |
| 252 | } |
| 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | extern void (*_machine_restart)(char *command); |
| 255 | extern void (*_machine_halt)(void); |
| 256 | extern void (*_machine_power_off)(void); |
| 257 | |
Heiko Carstens | 9887a1f | 2011-01-12 09:55:28 +0100 | [diff] [blame] | 258 | extern unsigned long arch_align_stack(unsigned long sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Hans-Joachim Picht | 155af2f | 2009-06-16 10:30:52 +0200 | [diff] [blame] | 260 | static inline int tprot(unsigned long addr) |
| 261 | { |
| 262 | int rc = -EFAULT; |
| 263 | |
| 264 | asm volatile( |
| 265 | " tprot 0(%1),0\n" |
| 266 | "0: ipm %0\n" |
| 267 | " srl %0,28\n" |
| 268 | "1:\n" |
| 269 | EX_TABLE(0b,1b) |
| 270 | : "+d" (rc) : "a" (addr) : "cc"); |
| 271 | return rc; |
| 272 | } |
| 273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | #endif /* __KERNEL__ */ |
| 275 | |
| 276 | #endif |