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>
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); \
107 * On SMP systems, when the scheduler does migration-cost autodetection,
108 * it needs a way to flush as much of the CPU's caches as possible.
110 * TODO: fill this in!
112 static inline void sched_cacheflush(void)
116 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
117 extern void account_vtime(struct task_struct
*);
118 extern void account_tick_vtime(struct task_struct
*);
119 extern void account_system_vtime(struct task_struct
*);
121 #define account_vtime(x) do { /* empty */ } while (0)
124 #define finish_arch_switch(prev) do { \
125 set_fs(current->thread.mm_segment); \
126 account_vtime(prev); \
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 __ctl_load(array, low, high) ({ \
335 typedef struct { char _[sizeof(array)]; } addrtype; \
336 __asm__ __volatile__ ( \
338 " lctlg 0,0,0(%0)\n" \
340 : : "a" (&array), "a" (((low)<<4)+(high)), \
341 "m" (*(addrtype *)(array)) : "1" ); \
344 #define __ctl_store(array, low, high) ({ \
345 typedef struct { char _[sizeof(array)]; } addrtype; \
346 __asm__ __volatile__ ( \
348 " stctg 0,0,0(%1)\n" \
350 : "=m" (*(addrtype *)(array)) \
351 : "a" (&array), "a" (((low)<<4)+(high)) : "1" ); \
354 #define __ctl_set_bit(cr, bit) ({ \
356 __asm__ __volatile__ ( \
357 " bras 1,0f\n" /* skip indirect insns */ \
358 " stctg 0,0,0(%1)\n" \
359 " lctlg 0,0,0(%1)\n" \
360 "0: ex %2,0(1)\n" /* execute stctl */ \
362 " ogr 0,%3\n" /* set the bit */ \
364 "1: ex %2,6(1)" /* execute lctl */ \
366 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
367 "a" (cr*17), "a" (1L<<(bit)) \
368 : "cc", "0", "1" ); \
371 #define __ctl_clear_bit(cr, bit) ({ \
373 __asm__ __volatile__ ( \
374 " bras 1,0f\n" /* skip indirect insns */ \
375 " stctg 0,0,0(%1)\n" \
376 " lctlg 0,0,0(%1)\n" \
377 "0: ex %2,0(1)\n" /* execute stctl */ \
379 " ngr 0,%3\n" /* set the bit */ \
381 "1: ex %2,6(1)" /* execute lctl */ \
383 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
384 "a" (cr*17), "a" (~(1L<<(bit))) \
385 : "cc", "0", "1" ); \
388 #else /* __s390x__ */
390 #define __ctl_load(array, low, high) ({ \
391 typedef struct { char _[sizeof(array)]; } addrtype; \
392 __asm__ __volatile__ ( \
394 " lctl 0,0,0(%0)\n" \
396 : : "a" (&array), "a" (((low)<<4)+(high)), \
397 "m" (*(addrtype *)(array)) : "1" ); \
400 #define __ctl_store(array, low, high) ({ \
401 typedef struct { char _[sizeof(array)]; } addrtype; \
402 __asm__ __volatile__ ( \
404 " stctl 0,0,0(%1)\n" \
406 : "=m" (*(addrtype *)(array)) \
407 : "a" (&array), "a" (((low)<<4)+(high)): "1" ); \
410 #define __ctl_set_bit(cr, bit) ({ \
412 __asm__ __volatile__ ( \
413 " bras 1,0f\n" /* skip indirect insns */ \
414 " stctl 0,0,0(%1)\n" \
415 " lctl 0,0,0(%1)\n" \
416 "0: ex %2,0(1)\n" /* execute stctl */ \
418 " or 0,%3\n" /* set the bit */ \
420 "1: ex %2,4(1)" /* execute lctl */ \
422 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
423 "a" (cr*17), "a" (1<<(bit)) \
424 : "cc", "0", "1" ); \
427 #define __ctl_clear_bit(cr, bit) ({ \
429 __asm__ __volatile__ ( \
430 " bras 1,0f\n" /* skip indirect insns */ \
431 " stctl 0,0,0(%1)\n" \
432 " lctl 0,0,0(%1)\n" \
433 "0: ex %2,0(1)\n" /* execute stctl */ \
435 " nr 0,%3\n" /* set the bit */ \
437 "1: ex %2,4(1)" /* execute lctl */ \
439 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
440 "a" (cr*17), "a" (~(1<<(bit))) \
441 : "cc", "0", "1" ); \
443 #endif /* __s390x__ */
445 /* For spinlocks etc */
446 #define local_irq_save(x) ((x) = local_irq_disable())
449 * Use to set psw mask except for the first byte which
450 * won't be changed by this function.
453 __set_psw_mask(unsigned long mask
)
455 local_save_flags(mask
);
456 __load_psw_mask(mask
);
459 #define local_mcck_enable() __set_psw_mask(PSW_KERNEL_BITS)
460 #define local_mcck_disable() __set_psw_mask(PSW_KERNEL_BITS & ~PSW_MASK_MCHECK)
464 extern void smp_ctl_set_bit(int cr
, int bit
);
465 extern void smp_ctl_clear_bit(int cr
, int bit
);
466 #define ctl_set_bit(cr, bit) smp_ctl_set_bit(cr, bit)
467 #define ctl_clear_bit(cr, bit) smp_ctl_clear_bit(cr, bit)
471 #define ctl_set_bit(cr, bit) __ctl_set_bit(cr, bit)
472 #define ctl_clear_bit(cr, bit) __ctl_clear_bit(cr, bit)
474 #endif /* CONFIG_SMP */
476 extern void (*_machine_restart
)(char *command
);
477 extern void (*_machine_halt
)(void);
478 extern void (*_machine_power_off
)(void);
480 #define arch_align_stack(x) (x)
482 #endif /* __KERNEL__ */