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/config.h>
15 #include <linux/kernel.h>
16 #include <asm/types.h>
17 #include <asm/ptrace.h>
18 #include <asm/setup.h>
19 #include <asm/processor.h>
25 extern struct task_struct *__switch_to(void *, void *);
28 #define __FLAG_SHIFT 56
29 #else /* ! __s390x__ */
30 #define __FLAG_SHIFT 24
31 #endif /* ! __s390x__ */
33 static inline void save_fp_regs(s390_fp_regs *fpregs)
40 : "=m" (*fpregs) : "a" (fpregs), "m" (*fpregs) : "memory" );
41 if (!MACHINE_HAS_IEEE)
57 : "=m" (*fpregs) : "a" (fpregs), "m" (*fpregs) : "memory" );
60 static inline void restore_fp_regs(s390_fp_regs *fpregs)
67 : : "a" (fpregs), "m" (*fpregs) );
68 if (!MACHINE_HAS_IEEE)
84 : : "a" (fpregs), "m" (*fpregs) );
87 static inline void save_access_regs(unsigned int *acrs)
89 asm volatile ("stam 0,15,0(%0)" : : "a" (acrs) : "memory" );
92 static inline void restore_access_regs(unsigned int *acrs)
94 asm volatile ("lam 0,15,0(%0)" : : "a" (acrs) );
97 #define switch_to(prev,next,last) do { \
100 save_fp_regs(&prev->thread.fp_regs); \
101 restore_fp_regs(&next->thread.fp_regs); \
102 save_access_regs(&prev->thread.acrs[0]); \
103 restore_access_regs(&next->thread.acrs[0]); \
104 prev = __switch_to(prev,next); \
107 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
108 extern void account_user_vtime(struct task_struct *);
109 extern void account_system_vtime(struct task_struct *);
112 #define finish_arch_switch(prev) do { \
113 set_fs(current->thread.mm_segment); \
114 account_system_vtime(prev); \
117 #define nop() __asm__ __volatile__ ("nop")
119 #define xchg(ptr,x) \
120 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(void *)(ptr),sizeof(*(ptr))))
122 static inline unsigned long __xchg(unsigned long x, void * ptr, int size)
124 unsigned long addr, old;
129 addr = (unsigned long) ptr;
130 shift = (3 ^ (addr & 3)) << 3;
139 : "=&d" (old), "=m" (*(int *) addr)
140 : "d" (x << shift), "d" (~(255 << shift)), "a" (addr),
141 "m" (*(int *) addr) : "memory", "cc", "0" );
145 addr = (unsigned long) ptr;
146 shift = (2 ^ (addr & 2)) << 3;
155 : "=&d" (old), "=m" (*(int *) addr)
156 : "d" (x << shift), "d" (~(65535 << shift)), "a" (addr),
157 "m" (*(int *) addr) : "memory", "cc", "0" );
163 "0: cs %0,%2,0(%3)\n"
165 : "=&d" (old), "=m" (*(int *) ptr)
166 : "d" (x), "a" (ptr), "m" (*(int *) ptr)
174 "0: csg %0,%2,0(%3)\n"
176 : "=&d" (old), "=m" (*(long *) ptr)
177 : "d" (x), "a" (ptr), "m" (*(long *) ptr)
181 #endif /* __s390x__ */
187 * Atomic compare and exchange. Compare OLD with MEM, if identical,
188 * store NEW in MEM. Return the initial value in MEM. Success is
189 * indicated by comparing RETURN with OLD.
192 #define __HAVE_ARCH_CMPXCHG 1
194 #define cmpxchg(ptr,o,n)\
195 ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
196 (unsigned long)(n),sizeof(*(ptr))))
198 static inline unsigned long
199 __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
201 unsigned long addr, prev, tmp;
206 addr = (unsigned long) ptr;
207 shift = (3 ^ (addr & 3)) << 3;
221 : "=&d" (prev), "=&d" (tmp)
222 : "d" (old << shift), "d" (new << shift), "a" (ptr),
223 "d" (~(255 << shift))
225 return prev >> shift;
227 addr = (unsigned long) ptr;
228 shift = (2 ^ (addr & 2)) << 3;
242 : "=&d" (prev), "=&d" (tmp)
243 : "d" (old << shift), "d" (new << shift), "a" (ptr),
244 "d" (~(65535 << shift))
246 return prev >> shift;
250 : "=&d" (prev) : "0" (old), "d" (new), "a" (ptr)
257 : "=&d" (prev) : "0" (old), "d" (new), "a" (ptr)
260 #endif /* __s390x__ */
266 * Force strict CPU ordering.
267 * And yes, this is required on UP too when we're talking
270 * This is very similar to the ppc eieio/sync instruction in that is
271 * does a checkpoint syncronisation & makes sure that
272 * all memory ops have completed wrt other CPU's ( see 7-15 POP DJB ).
275 #define eieio() __asm__ __volatile__ ( "bcr 15,0" : : : "memory" )
276 # define SYNC_OTHER_CORES(x) eieio()
278 #define rmb() eieio()
279 #define wmb() eieio()
280 #define read_barrier_depends() do { } while(0)
281 #define smp_mb() mb()
282 #define smp_rmb() rmb()
283 #define smp_wmb() wmb()
284 #define smp_read_barrier_depends() read_barrier_depends()
285 #define smp_mb__before_clear_bit() smp_mb()
286 #define smp_mb__after_clear_bit() smp_mb()
289 #define set_mb(var, value) do { var = value; mb(); } while (0)
290 #define set_wmb(var, value) do { var = value; wmb(); } while (0)
292 /* interrupt control.. */
293 #define local_irq_enable() ({ \
294 unsigned long __dummy; \
295 __asm__ __volatile__ ( \
297 : "=m" (__dummy) : "a" (&__dummy) : "memory" ); \
300 #define local_irq_disable() ({ \
301 unsigned long __flags; \
302 __asm__ __volatile__ ( \
303 "stnsm 0(%1),0xfc" : "=m" (__flags) : "a" (&__flags) ); \
307 #define local_save_flags(x) \
308 __asm__ __volatile__("stosm 0(%1),0" : "=m" (x) : "a" (&x), "m" (x) )
310 #define local_irq_restore(x) \
311 __asm__ __volatile__("ssm 0(%0)" : : "a" (&x), "m" (x) : "memory")
313 #define irqs_disabled() \
315 unsigned long flags; \
316 local_save_flags(flags); \
317 !((flags >> __FLAG_SHIFT) & 3); \
322 #define __ctl_load(array, low, high) ({ \
323 typedef struct { char _[sizeof(array)]; } addrtype; \
324 __asm__ __volatile__ ( \
326 " lctlg 0,0,0(%0)\n" \
328 : : "a" (&array), "a" (((low)<<4)+(high)), \
329 "m" (*(addrtype *)(array)) : "1" ); \
332 #define __ctl_store(array, low, high) ({ \
333 typedef struct { char _[sizeof(array)]; } addrtype; \
334 __asm__ __volatile__ ( \
336 " stctg 0,0,0(%1)\n" \
338 : "=m" (*(addrtype *)(array)) \
339 : "a" (&array), "a" (((low)<<4)+(high)) : "1" ); \
342 #define __ctl_set_bit(cr, bit) ({ \
344 __asm__ __volatile__ ( \
345 " bras 1,0f\n" /* skip indirect insns */ \
346 " stctg 0,0,0(%1)\n" \
347 " lctlg 0,0,0(%1)\n" \
348 "0: ex %2,0(1)\n" /* execute stctl */ \
350 " ogr 0,%3\n" /* set the bit */ \
352 "1: ex %2,6(1)" /* execute lctl */ \
354 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
355 "a" (cr*17), "a" (1L<<(bit)) \
356 : "cc", "0", "1" ); \
359 #define __ctl_clear_bit(cr, bit) ({ \
361 __asm__ __volatile__ ( \
362 " bras 1,0f\n" /* skip indirect insns */ \
363 " stctg 0,0,0(%1)\n" \
364 " lctlg 0,0,0(%1)\n" \
365 "0: ex %2,0(1)\n" /* execute stctl */ \
367 " ngr 0,%3\n" /* set the bit */ \
369 "1: ex %2,6(1)" /* execute lctl */ \
371 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
372 "a" (cr*17), "a" (~(1L<<(bit))) \
373 : "cc", "0", "1" ); \
376 #else /* __s390x__ */
378 #define __ctl_load(array, low, high) ({ \
379 typedef struct { char _[sizeof(array)]; } addrtype; \
380 __asm__ __volatile__ ( \
382 " lctl 0,0,0(%0)\n" \
384 : : "a" (&array), "a" (((low)<<4)+(high)), \
385 "m" (*(addrtype *)(array)) : "1" ); \
388 #define __ctl_store(array, low, high) ({ \
389 typedef struct { char _[sizeof(array)]; } addrtype; \
390 __asm__ __volatile__ ( \
392 " stctl 0,0,0(%1)\n" \
394 : "=m" (*(addrtype *)(array)) \
395 : "a" (&array), "a" (((low)<<4)+(high)): "1" ); \
398 #define __ctl_set_bit(cr, bit) ({ \
400 __asm__ __volatile__ ( \
401 " bras 1,0f\n" /* skip indirect insns */ \
402 " stctl 0,0,0(%1)\n" \
403 " lctl 0,0,0(%1)\n" \
404 "0: ex %2,0(1)\n" /* execute stctl */ \
406 " or 0,%3\n" /* set the bit */ \
408 "1: ex %2,4(1)" /* execute lctl */ \
410 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
411 "a" (cr*17), "a" (1<<(bit)) \
412 : "cc", "0", "1" ); \
415 #define __ctl_clear_bit(cr, bit) ({ \
417 __asm__ __volatile__ ( \
418 " bras 1,0f\n" /* skip indirect insns */ \
419 " stctl 0,0,0(%1)\n" \
420 " lctl 0,0,0(%1)\n" \
421 "0: ex %2,0(1)\n" /* execute stctl */ \
423 " nr 0,%3\n" /* set the bit */ \
425 "1: ex %2,4(1)" /* execute lctl */ \
427 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
428 "a" (cr*17), "a" (~(1<<(bit))) \
429 : "cc", "0", "1" ); \
431 #endif /* __s390x__ */
433 /* For spinlocks etc */
434 #define local_irq_save(x) ((x) = local_irq_disable())
437 * Use to set psw mask except for the first byte which
438 * won't be changed by this function.
441 __set_psw_mask(unsigned long mask)
443 local_save_flags(mask);
444 __load_psw_mask(mask);
447 #define local_mcck_enable() __set_psw_mask(PSW_KERNEL_BITS)
448 #define local_mcck_disable() __set_psw_mask(PSW_KERNEL_BITS & ~PSW_MASK_MCHECK)
452 extern void smp_ctl_set_bit(int cr, int bit);
453 extern void smp_ctl_clear_bit(int cr, int bit);
454 #define ctl_set_bit(cr, bit) smp_ctl_set_bit(cr, bit)
455 #define ctl_clear_bit(cr, bit) smp_ctl_clear_bit(cr, bit)
459 #define ctl_set_bit(cr, bit) __ctl_set_bit(cr, bit)
460 #define ctl_clear_bit(cr, bit) __ctl_clear_bit(cr, bit)
462 #endif /* CONFIG_SMP */
464 extern void (*_machine_restart)(char *command);
465 extern void (*_machine_halt)(void);
466 extern void (*_machine_power_off)(void);
468 #define arch_align_stack(x) (x)
470 #endif /* __KERNEL__ */