2 * include/asm-s390/system.h
5 * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
8 * Derived from "include/asm-i386/system.h"
11 #ifndef __ASM_SYSTEM_H
12 #define __ASM_SYSTEM_H
14 #include <linux/kernel.h>
15 #include <asm/types.h>
16 #include <asm/ptrace.h>
17 #include <asm/setup.h>
18 #include <asm/processor.h>
19 #include <asm/lowcore.h>
25 extern struct task_struct *__switch_to(void *, void *);
27 static inline void save_fp_regs(s390_fp_regs *fpregs)
34 : "=m" (*fpregs) : "a" (fpregs), "m" (*fpregs) : "memory");
35 if (!MACHINE_HAS_IEEE)
51 : "=m" (*fpregs) : "a" (fpregs), "m" (*fpregs) : "memory");
54 static inline void restore_fp_regs(s390_fp_regs *fpregs)
61 : : "a" (fpregs), "m" (*fpregs));
62 if (!MACHINE_HAS_IEEE)
78 : : "a" (fpregs), "m" (*fpregs));
81 static inline void save_access_regs(unsigned int *acrs)
83 asm volatile("stam 0,15,0(%0)" : : "a" (acrs) : "memory");
86 static inline void restore_access_regs(unsigned int *acrs)
88 asm volatile("lam 0,15,0(%0)" : : "a" (acrs));
91 #define switch_to(prev,next,last) do { \
94 save_fp_regs(&prev->thread.fp_regs); \
95 restore_fp_regs(&next->thread.fp_regs); \
96 save_access_regs(&prev->thread.acrs[0]); \
97 restore_access_regs(&next->thread.acrs[0]); \
98 prev = __switch_to(prev,next); \
101 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
102 extern void account_vtime(struct task_struct *);
103 extern void account_tick_vtime(struct task_struct *);
104 extern void account_system_vtime(struct task_struct *);
106 #define account_vtime(x) do { /* empty */ } while (0)
110 extern void pfault_irq_init(void);
111 extern int pfault_init(void);
112 extern void pfault_fini(void);
113 #else /* CONFIG_PFAULT */
114 #define pfault_irq_init() do { } while (0)
115 #define pfault_init() ({-1;})
116 #define pfault_fini() do { } while (0)
117 #endif /* CONFIG_PFAULT */
119 #define finish_arch_switch(prev) do { \
120 set_fs(current->thread.mm_segment); \
121 account_vtime(prev); \
124 #define nop() asm volatile("nop")
126 #define xchg(ptr,x) \
128 __typeof__(*(ptr)) __ret; \
129 __ret = (__typeof__(*(ptr))) \
130 __xchg((unsigned long)(x), (void *)(ptr),sizeof(*(ptr))); \
134 extern void __xchg_called_with_bad_pointer(void);
136 static inline unsigned long __xchg(unsigned long x, void * ptr, int size)
138 unsigned long addr, old;
143 addr = (unsigned long) ptr;
144 shift = (3 ^ (addr & 3)) << 3;
153 : "=&d" (old), "=m" (*(int *) addr)
154 : "d" (x << shift), "d" (~(255 << shift)), "a" (addr),
155 "m" (*(int *) addr) : "memory", "cc", "0");
158 addr = (unsigned long) ptr;
159 shift = (2 ^ (addr & 2)) << 3;
168 : "=&d" (old), "=m" (*(int *) addr)
169 : "d" (x << shift), "d" (~(65535 << shift)), "a" (addr),
170 "m" (*(int *) addr) : "memory", "cc", "0");
175 "0: cs %0,%2,0(%3)\n"
177 : "=&d" (old), "=m" (*(int *) ptr)
178 : "d" (x), "a" (ptr), "m" (*(int *) ptr)
185 "0: csg %0,%2,0(%3)\n"
187 : "=&d" (old), "=m" (*(long *) ptr)
188 : "d" (x), "a" (ptr), "m" (*(long *) ptr)
191 #endif /* __s390x__ */
193 __xchg_called_with_bad_pointer();
198 * Atomic compare and exchange. Compare OLD with MEM, if identical,
199 * store NEW in MEM. Return the initial value in MEM. Success is
200 * indicated by comparing RETURN with OLD.
203 #define __HAVE_ARCH_CMPXCHG 1
205 #define cmpxchg(ptr, o, n) \
206 ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
207 (unsigned long)(n), sizeof(*(ptr))))
209 extern void __cmpxchg_called_with_bad_pointer(void);
211 static inline unsigned long
212 __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
214 unsigned long addr, prev, tmp;
219 addr = (unsigned long) ptr;
220 shift = (3 ^ (addr & 3)) << 3;
234 : "=&d" (prev), "=&d" (tmp)
235 : "d" (old << shift), "d" (new << shift), "a" (ptr),
236 "d" (~(255 << shift))
238 return prev >> shift;
240 addr = (unsigned long) ptr;
241 shift = (2 ^ (addr & 2)) << 3;
255 : "=&d" (prev), "=&d" (tmp)
256 : "d" (old << shift), "d" (new << shift), "a" (ptr),
257 "d" (~(65535 << shift))
259 return prev >> shift;
263 : "=&d" (prev) : "0" (old), "d" (new), "a" (ptr)
270 : "=&d" (prev) : "0" (old), "d" (new), "a" (ptr)
273 #endif /* __s390x__ */
275 __cmpxchg_called_with_bad_pointer();
280 * Force strict CPU ordering.
281 * And yes, this is required on UP too when we're talking
284 * This is very similar to the ppc eieio/sync instruction in that is
285 * does a checkpoint syncronisation & makes sure that
286 * all memory ops have completed wrt other CPU's ( see 7-15 POP DJB ).
289 #define eieio() asm volatile("bcr 15,0" : : : "memory")
290 #define SYNC_OTHER_CORES(x) eieio()
292 #define rmb() eieio()
293 #define wmb() eieio()
294 #define read_barrier_depends() do { } while(0)
295 #define smp_mb() mb()
296 #define smp_rmb() rmb()
297 #define smp_wmb() wmb()
298 #define smp_read_barrier_depends() read_barrier_depends()
299 #define smp_mb__before_clear_bit() smp_mb()
300 #define smp_mb__after_clear_bit() smp_mb()
303 #define set_mb(var, value) do { var = value; mb(); } while (0)
307 #define __ctl_load(array, low, high) ({ \
308 typedef struct { char _[sizeof(array)]; } addrtype; \
310 " lctlg %1,%2,0(%0)\n" \
311 : : "a" (&array), "i" (low), "i" (high), \
312 "m" (*(addrtype *)(array))); \
315 #define __ctl_store(array, low, high) ({ \
316 typedef struct { char _[sizeof(array)]; } addrtype; \
318 " stctg %2,%3,0(%1)\n" \
319 : "=m" (*(addrtype *)(array)) \
320 : "a" (&array), "i" (low), "i" (high)); \
323 #else /* __s390x__ */
325 #define __ctl_load(array, low, high) ({ \
326 typedef struct { char _[sizeof(array)]; } addrtype; \
328 " lctl %1,%2,0(%0)\n" \
329 : : "a" (&array), "i" (low), "i" (high), \
330 "m" (*(addrtype *)(array))); \
333 #define __ctl_store(array, low, high) ({ \
334 typedef struct { char _[sizeof(array)]; } addrtype; \
336 " stctl %2,%3,0(%1)\n" \
337 : "=m" (*(addrtype *)(array)) \
338 : "a" (&array), "i" (low), "i" (high)); \
341 #endif /* __s390x__ */
343 #define __ctl_set_bit(cr, bit) ({ \
344 unsigned long __dummy; \
345 __ctl_store(__dummy, cr, cr); \
346 __dummy |= 1UL << (bit); \
347 __ctl_load(__dummy, cr, cr); \
350 #define __ctl_clear_bit(cr, bit) ({ \
351 unsigned long __dummy; \
352 __ctl_store(__dummy, cr, cr); \
353 __dummy &= ~(1UL << (bit)); \
354 __ctl_load(__dummy, cr, cr); \
357 #include <linux/irqflags.h>
359 #include <asm-generic/cmpxchg-local.h>
361 static inline unsigned long __cmpxchg_local(volatile void *ptr,
363 unsigned long new, int size)
372 return __cmpxchg(ptr, old, new, size);
374 return __cmpxchg_local_generic(ptr, old, new, size);
381 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
384 #define cmpxchg_local(ptr, o, n) \
385 ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \
386 (unsigned long)(n), sizeof(*(ptr))))
388 #define cmpxchg64_local(ptr, o, n) \
390 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
391 cmpxchg_local((ptr), (o), (n)); \
394 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
398 * Use to set psw mask except for the first byte which
399 * won't be changed by this function.
402 __set_psw_mask(unsigned long mask)
404 __load_psw_mask(mask | (__raw_local_irq_stosm(0x00) & ~(-1UL >> 8)));
407 #define local_mcck_enable() __set_psw_mask(psw_kernel_bits)
408 #define local_mcck_disable() __set_psw_mask(psw_kernel_bits & ~PSW_MASK_MCHECK)
410 int stfle(unsigned long long *list, int doublewords);
414 extern void smp_ctl_set_bit(int cr, int bit);
415 extern void smp_ctl_clear_bit(int cr, int bit);
416 #define ctl_set_bit(cr, bit) smp_ctl_set_bit(cr, bit)
417 #define ctl_clear_bit(cr, bit) smp_ctl_clear_bit(cr, bit)
421 #define ctl_set_bit(cr, bit) __ctl_set_bit(cr, bit)
422 #define ctl_clear_bit(cr, bit) __ctl_clear_bit(cr, bit)
424 #endif /* CONFIG_SMP */
426 static inline unsigned int stfl(void)
429 " .insn s,0xb2b10000,0(0)\n" /* stfl */
432 return S390_lowcore.stfl_fac_list;
435 static inline unsigned short stap(void)
437 unsigned short cpu_address;
439 asm volatile("stap %0" : "=m" (cpu_address));
443 extern void (*_machine_restart)(char *command);
444 extern void (*_machine_halt)(void);
445 extern void (*_machine_power_off)(void);
447 #define arch_align_stack(x) (x)
449 #ifdef CONFIG_TRACE_IRQFLAGS
450 extern psw_t sysc_restore_trace_psw;
451 extern psw_t io_restore_trace_psw;
454 #endif /* __KERNEL__ */