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>
24 extern struct task_struct *__switch_to(void *, void *);
27 #define __FLAG_SHIFT 56
28 #else /* ! __s390x__ */
29 #define __FLAG_SHIFT 24
30 #endif /* ! __s390x__ */
32 static inline void save_fp_regs(s390_fp_regs *fpregs)
39 : "=m" (*fpregs) : "a" (fpregs), "m" (*fpregs) : "memory" );
40 if (!MACHINE_HAS_IEEE)
56 : "=m" (*fpregs) : "a" (fpregs), "m" (*fpregs) : "memory" );
59 static inline void restore_fp_regs(s390_fp_regs *fpregs)
66 : : "a" (fpregs), "m" (*fpregs) );
67 if (!MACHINE_HAS_IEEE)
83 : : "a" (fpregs), "m" (*fpregs) );
86 static inline void save_access_regs(unsigned int *acrs)
88 asm volatile ("stam 0,15,0(%0)" : : "a" (acrs) : "memory" );
91 static inline void restore_access_regs(unsigned int *acrs)
93 asm volatile ("lam 0,15,0(%0)" : : "a" (acrs) );
96 #define switch_to(prev,next,last) do { \
99 save_fp_regs(&prev->thread.fp_regs); \
100 restore_fp_regs(&next->thread.fp_regs); \
101 save_access_regs(&prev->thread.acrs[0]); \
102 restore_access_regs(&next->thread.acrs[0]); \
103 prev = __switch_to(prev,next); \
106 #define prepare_arch_switch(rq, next) do { } while(0)
107 #define task_running(rq, p) ((rq)->curr == (p))
109 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
110 extern void account_user_vtime(struct task_struct *);
111 extern void account_system_vtime(struct task_struct *);
113 #define finish_arch_switch(rq, prev) do { \
114 set_fs(current->thread.mm_segment); \
115 spin_unlock(&(rq)->lock); \
116 account_system_vtime(prev); \
117 local_irq_enable(); \
122 #define finish_arch_switch(rq, prev) do { \
123 set_fs(current->thread.mm_segment); \
124 spin_unlock_irq(&(rq)->lock); \
129 #define nop() __asm__ __volatile__ ("nop")
131 #define xchg(ptr,x) \
132 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(void *)(ptr),sizeof(*(ptr))))
134 static inline unsigned long __xchg(unsigned long x, void * ptr, int size)
136 unsigned long addr, old;
141 addr = (unsigned long) ptr;
142 shift = (3 ^ (addr & 3)) << 3;
151 : "=&d" (old), "=m" (*(int *) addr)
152 : "d" (x << shift), "d" (~(255 << shift)), "a" (addr),
153 "m" (*(int *) addr) : "memory", "cc", "0" );
157 addr = (unsigned long) ptr;
158 shift = (2 ^ (addr & 2)) << 3;
167 : "=&d" (old), "=m" (*(int *) addr)
168 : "d" (x << shift), "d" (~(65535 << shift)), "a" (addr),
169 "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)
186 "0: csg %0,%2,0(%3)\n"
188 : "=&d" (old), "=m" (*(long *) ptr)
189 : "d" (x), "a" (ptr), "m" (*(long *) ptr)
193 #endif /* __s390x__ */
199 * Atomic compare and exchange. Compare OLD with MEM, if identical,
200 * store NEW in MEM. Return the initial value in MEM. Success is
201 * indicated by comparing RETURN with OLD.
204 #define __HAVE_ARCH_CMPXCHG 1
206 #define cmpxchg(ptr,o,n)\
207 ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
208 (unsigned long)(n),sizeof(*(ptr))))
210 static inline unsigned long
211 __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
213 unsigned long addr, prev, tmp;
218 addr = (unsigned long) ptr;
219 shift = (3 ^ (addr & 3)) << 3;
233 : "=&d" (prev), "=&d" (tmp)
234 : "d" (old << shift), "d" (new << shift), "a" (ptr),
235 "d" (~(255 << shift))
237 return prev >> shift;
239 addr = (unsigned long) ptr;
240 shift = (2 ^ (addr & 2)) << 3;
254 : "=&d" (prev), "=&d" (tmp)
255 : "d" (old << shift), "d" (new << shift), "a" (ptr),
256 "d" (~(65535 << shift))
258 return prev >> shift;
262 : "=&d" (prev) : "0" (old), "d" (new), "a" (ptr)
269 : "=&d" (prev) : "0" (old), "d" (new), "a" (ptr)
272 #endif /* __s390x__ */
278 * Force strict CPU ordering.
279 * And yes, this is required on UP too when we're talking
282 * This is very similar to the ppc eieio/sync instruction in that is
283 * does a checkpoint syncronisation & makes sure that
284 * all memory ops have completed wrt other CPU's ( see 7-15 POP DJB ).
287 #define eieio() __asm__ __volatile__ ( "bcr 15,0" : : : "memory" )
288 # define SYNC_OTHER_CORES(x) eieio()
290 #define rmb() eieio()
291 #define wmb() eieio()
292 #define read_barrier_depends() do { } while(0)
293 #define smp_mb() mb()
294 #define smp_rmb() rmb()
295 #define smp_wmb() wmb()
296 #define smp_read_barrier_depends() read_barrier_depends()
297 #define smp_mb__before_clear_bit() smp_mb()
298 #define smp_mb__after_clear_bit() smp_mb()
301 #define set_mb(var, value) do { var = value; mb(); } while (0)
302 #define set_wmb(var, value) do { var = value; wmb(); } while (0)
304 /* interrupt control.. */
305 #define local_irq_enable() ({ \
306 unsigned long __dummy; \
307 __asm__ __volatile__ ( \
309 : "=m" (__dummy) : "a" (&__dummy) : "memory" ); \
312 #define local_irq_disable() ({ \
313 unsigned long __flags; \
314 __asm__ __volatile__ ( \
315 "stnsm 0(%1),0xfc" : "=m" (__flags) : "a" (&__flags) ); \
319 #define local_save_flags(x) \
320 __asm__ __volatile__("stosm 0(%1),0" : "=m" (x) : "a" (&x), "m" (x) )
322 #define local_irq_restore(x) \
323 __asm__ __volatile__("ssm 0(%0)" : : "a" (&x), "m" (x) : "memory")
325 #define irqs_disabled() \
327 unsigned long flags; \
328 local_save_flags(flags); \
329 !((flags >> __FLAG_SHIFT) & 3); \
334 #define __load_psw(psw) \
335 __asm__ __volatile__("lpswe 0(%0)" : : "a" (&psw), "m" (psw) : "cc" );
337 #define __ctl_load(array, low, high) ({ \
338 typedef struct { char _[sizeof(array)]; } addrtype; \
339 __asm__ __volatile__ ( \
341 " lctlg 0,0,0(%0)\n" \
343 : : "a" (&array), "a" (((low)<<4)+(high)), \
344 "m" (*(addrtype *)(array)) : "1" ); \
347 #define __ctl_store(array, low, high) ({ \
348 typedef struct { char _[sizeof(array)]; } addrtype; \
349 __asm__ __volatile__ ( \
351 " stctg 0,0,0(%1)\n" \
353 : "=m" (*(addrtype *)(array)) \
354 : "a" (&array), "a" (((low)<<4)+(high)) : "1" ); \
357 #define __ctl_set_bit(cr, bit) ({ \
359 __asm__ __volatile__ ( \
360 " bras 1,0f\n" /* skip indirect insns */ \
361 " stctg 0,0,0(%1)\n" \
362 " lctlg 0,0,0(%1)\n" \
363 "0: ex %2,0(1)\n" /* execute stctl */ \
365 " ogr 0,%3\n" /* set the bit */ \
367 "1: ex %2,6(1)" /* execute lctl */ \
369 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
370 "a" (cr*17), "a" (1L<<(bit)) \
371 : "cc", "0", "1" ); \
374 #define __ctl_clear_bit(cr, bit) ({ \
376 __asm__ __volatile__ ( \
377 " bras 1,0f\n" /* skip indirect insns */ \
378 " stctg 0,0,0(%1)\n" \
379 " lctlg 0,0,0(%1)\n" \
380 "0: ex %2,0(1)\n" /* execute stctl */ \
382 " ngr 0,%3\n" /* set the bit */ \
384 "1: ex %2,6(1)" /* execute lctl */ \
386 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
387 "a" (cr*17), "a" (~(1L<<(bit))) \
388 : "cc", "0", "1" ); \
391 #else /* __s390x__ */
393 #define __load_psw(psw) \
394 __asm__ __volatile__("lpsw 0(%0)" : : "a" (&psw) : "cc" );
396 #define __ctl_load(array, low, high) ({ \
397 typedef struct { char _[sizeof(array)]; } addrtype; \
398 __asm__ __volatile__ ( \
400 " lctl 0,0,0(%0)\n" \
402 : : "a" (&array), "a" (((low)<<4)+(high)), \
403 "m" (*(addrtype *)(array)) : "1" ); \
406 #define __ctl_store(array, low, high) ({ \
407 typedef struct { char _[sizeof(array)]; } addrtype; \
408 __asm__ __volatile__ ( \
410 " stctl 0,0,0(%1)\n" \
412 : "=m" (*(addrtype *)(array)) \
413 : "a" (&array), "a" (((low)<<4)+(high)): "1" ); \
416 #define __ctl_set_bit(cr, bit) ({ \
418 __asm__ __volatile__ ( \
419 " bras 1,0f\n" /* skip indirect insns */ \
420 " stctl 0,0,0(%1)\n" \
421 " lctl 0,0,0(%1)\n" \
422 "0: ex %2,0(1)\n" /* execute stctl */ \
424 " or 0,%3\n" /* set the bit */ \
426 "1: ex %2,4(1)" /* execute lctl */ \
428 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
429 "a" (cr*17), "a" (1<<(bit)) \
430 : "cc", "0", "1" ); \
433 #define __ctl_clear_bit(cr, bit) ({ \
435 __asm__ __volatile__ ( \
436 " bras 1,0f\n" /* skip indirect insns */ \
437 " stctl 0,0,0(%1)\n" \
438 " lctl 0,0,0(%1)\n" \
439 "0: ex %2,0(1)\n" /* execute stctl */ \
441 " nr 0,%3\n" /* set the bit */ \
443 "1: ex %2,4(1)" /* execute lctl */ \
445 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
446 "a" (cr*17), "a" (~(1<<(bit))) \
447 : "cc", "0", "1" ); \
449 #endif /* __s390x__ */
451 /* For spinlocks etc */
452 #define local_irq_save(x) ((x) = local_irq_disable())
456 extern void smp_ctl_set_bit(int cr, int bit);
457 extern void smp_ctl_clear_bit(int cr, int bit);
458 #define ctl_set_bit(cr, bit) smp_ctl_set_bit(cr, bit)
459 #define ctl_clear_bit(cr, bit) smp_ctl_clear_bit(cr, bit)
463 #define ctl_set_bit(cr, bit) __ctl_set_bit(cr, bit)
464 #define ctl_clear_bit(cr, bit) __ctl_clear_bit(cr, bit)
466 #endif /* CONFIG_SMP */
468 extern void (*_machine_restart)(char *command);
469 extern void (*_machine_halt)(void);
470 extern void (*_machine_power_off)(void);
472 #define arch_align_stack(x) (x)
474 #endif /* __KERNEL__ */