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); \
108 * On SMP systems, when the scheduler does migration-cost autodetection,
109 * it needs a way to flush as much of the CPU's caches as possible.
111 * TODO: fill this in!
113 static inline void sched_cacheflush(void)
117 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
118 extern void account_vtime(struct task_struct
*);
119 extern void account_tick_vtime(struct task_struct
*);
120 extern void account_system_vtime(struct task_struct
*);
122 #define account_vtime(x) do { /* empty */ } while (0)
125 #define finish_arch_switch(prev) do { \
126 set_fs(current->thread.mm_segment); \
127 account_vtime(prev); \
130 #define nop() __asm__ __volatile__ ("nop")
132 #define xchg(ptr,x) \
133 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(void *)(ptr),sizeof(*(ptr))))
135 static inline unsigned long __xchg(unsigned long x
, void * ptr
, int size
)
137 unsigned long addr
, old
;
142 addr
= (unsigned long) ptr
;
143 shift
= (3 ^ (addr
& 3)) << 3;
152 : "=&d" (old
), "=m" (*(int *) addr
)
153 : "d" (x
<< shift
), "d" (~(255 << shift
)), "a" (addr
),
154 "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" );
176 "0: cs %0,%2,0(%3)\n"
178 : "=&d" (old
), "=m" (*(int *) ptr
)
179 : "d" (x
), "a" (ptr
), "m" (*(int *) ptr
)
187 "0: csg %0,%2,0(%3)\n"
189 : "=&d" (old
), "=m" (*(long *) ptr
)
190 : "d" (x
), "a" (ptr
), "m" (*(long *) ptr
)
194 #endif /* __s390x__ */
200 * Atomic compare and exchange. Compare OLD with MEM, if identical,
201 * store NEW in MEM. Return the initial value in MEM. Success is
202 * indicated by comparing RETURN with OLD.
205 #define __HAVE_ARCH_CMPXCHG 1
207 #define cmpxchg(ptr,o,n)\
208 ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
209 (unsigned long)(n),sizeof(*(ptr))))
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__ */
279 * Force strict CPU ordering.
280 * And yes, this is required on UP too when we're talking
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 ).
288 #define eieio() __asm__ __volatile__ ( "bcr 15,0" : : : "memory" )
289 # define SYNC_OTHER_CORES(x) 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()
302 #define set_mb(var, value) do { var = value; mb(); } while (0)
303 #define set_wmb(var, value) do { var = value; wmb(); } while (0)
305 /* interrupt control.. */
306 #define local_irq_enable() ({ \
307 unsigned long __dummy; \
308 __asm__ __volatile__ ( \
310 : "=m" (__dummy) : "a" (&__dummy) : "memory" ); \
313 #define local_irq_disable() ({ \
314 unsigned long __flags; \
315 __asm__ __volatile__ ( \
316 "stnsm 0(%1),0xfc" : "=m" (__flags) : "a" (&__flags) ); \
320 #define local_save_flags(x) \
321 __asm__ __volatile__("stosm 0(%1),0" : "=m" (x) : "a" (&x), "m" (x) )
323 #define local_irq_restore(x) \
324 __asm__ __volatile__("ssm 0(%0)" : : "a" (&x), "m" (x) : "memory")
326 #define irqs_disabled() \
328 unsigned long flags; \
329 local_save_flags(flags); \
330 !((flags >> __FLAG_SHIFT) & 3); \
335 #define __ctl_load(array, low, high) ({ \
336 typedef struct { char _[sizeof(array)]; } addrtype; \
337 __asm__ __volatile__ ( \
339 " lctlg 0,0,0(%0)\n" \
341 : : "a" (&array), "a" (((low)<<4)+(high)), \
342 "m" (*(addrtype *)(array)) : "1" ); \
345 #define __ctl_store(array, low, high) ({ \
346 typedef struct { char _[sizeof(array)]; } addrtype; \
347 __asm__ __volatile__ ( \
349 " stctg 0,0,0(%1)\n" \
351 : "=m" (*(addrtype *)(array)) \
352 : "a" (&array), "a" (((low)<<4)+(high)) : "1" ); \
355 #define __ctl_set_bit(cr, bit) ({ \
357 __asm__ __volatile__ ( \
358 " bras 1,0f\n" /* skip indirect insns */ \
359 " stctg 0,0,0(%1)\n" \
360 " lctlg 0,0,0(%1)\n" \
361 "0: ex %2,0(1)\n" /* execute stctl */ \
363 " ogr 0,%3\n" /* set the bit */ \
365 "1: ex %2,6(1)" /* execute lctl */ \
367 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
368 "a" (cr*17), "a" (1L<<(bit)) \
369 : "cc", "0", "1" ); \
372 #define __ctl_clear_bit(cr, bit) ({ \
374 __asm__ __volatile__ ( \
375 " bras 1,0f\n" /* skip indirect insns */ \
376 " stctg 0,0,0(%1)\n" \
377 " lctlg 0,0,0(%1)\n" \
378 "0: ex %2,0(1)\n" /* execute stctl */ \
380 " ngr 0,%3\n" /* set the bit */ \
382 "1: ex %2,6(1)" /* execute lctl */ \
384 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
385 "a" (cr*17), "a" (~(1L<<(bit))) \
386 : "cc", "0", "1" ); \
389 #else /* __s390x__ */
391 #define __ctl_load(array, low, high) ({ \
392 typedef struct { char _[sizeof(array)]; } addrtype; \
393 __asm__ __volatile__ ( \
395 " lctl 0,0,0(%0)\n" \
397 : : "a" (&array), "a" (((low)<<4)+(high)), \
398 "m" (*(addrtype *)(array)) : "1" ); \
401 #define __ctl_store(array, low, high) ({ \
402 typedef struct { char _[sizeof(array)]; } addrtype; \
403 __asm__ __volatile__ ( \
405 " stctl 0,0,0(%1)\n" \
407 : "=m" (*(addrtype *)(array)) \
408 : "a" (&array), "a" (((low)<<4)+(high)): "1" ); \
411 #define __ctl_set_bit(cr, bit) ({ \
413 __asm__ __volatile__ ( \
414 " bras 1,0f\n" /* skip indirect insns */ \
415 " stctl 0,0,0(%1)\n" \
416 " lctl 0,0,0(%1)\n" \
417 "0: ex %2,0(1)\n" /* execute stctl */ \
419 " or 0,%3\n" /* set the bit */ \
421 "1: ex %2,4(1)" /* execute lctl */ \
423 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
424 "a" (cr*17), "a" (1<<(bit)) \
425 : "cc", "0", "1" ); \
428 #define __ctl_clear_bit(cr, bit) ({ \
430 __asm__ __volatile__ ( \
431 " bras 1,0f\n" /* skip indirect insns */ \
432 " stctl 0,0,0(%1)\n" \
433 " lctl 0,0,0(%1)\n" \
434 "0: ex %2,0(1)\n" /* execute stctl */ \
436 " nr 0,%3\n" /* set the bit */ \
438 "1: ex %2,4(1)" /* execute lctl */ \
440 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
441 "a" (cr*17), "a" (~(1<<(bit))) \
442 : "cc", "0", "1" ); \
444 #endif /* __s390x__ */
446 /* For spinlocks etc */
447 #define local_irq_save(x) ((x) = local_irq_disable())
450 * Use to set psw mask except for the first byte which
451 * won't be changed by this function.
454 __set_psw_mask(unsigned long mask
)
456 local_save_flags(mask
);
457 __load_psw_mask(mask
);
460 #define local_mcck_enable() __set_psw_mask(PSW_KERNEL_BITS)
461 #define local_mcck_disable() __set_psw_mask(PSW_KERNEL_BITS & ~PSW_MASK_MCHECK)
465 extern void smp_ctl_set_bit(int cr
, int bit
);
466 extern void smp_ctl_clear_bit(int cr
, int bit
);
467 #define ctl_set_bit(cr, bit) smp_ctl_set_bit(cr, bit)
468 #define ctl_clear_bit(cr, bit) smp_ctl_clear_bit(cr, bit)
472 #define ctl_set_bit(cr, bit) __ctl_set_bit(cr, bit)
473 #define ctl_clear_bit(cr, bit) __ctl_clear_bit(cr, bit)
475 #endif /* CONFIG_SMP */
477 extern void (*_machine_restart
)(char *command
);
478 extern void (*_machine_halt
)(void);
479 extern void (*_machine_power_off
)(void);
481 #define arch_align_stack(x) (x)
483 #endif /* __KERNEL__ */