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)
306 #define __ctl_load(array, low, high) ({ \
307 typedef struct { char _[sizeof(array)]; } addrtype; \
308 __asm__ __volatile__ ( \
310 " lctlg 0,0,0(%0)\n" \
312 : : "a" (&array), "a" (((low)<<4)+(high)), \
313 "m" (*(addrtype *)(array)) : "1" ); \
316 #define __ctl_store(array, low, high) ({ \
317 typedef struct { char _[sizeof(array)]; } addrtype; \
318 __asm__ __volatile__ ( \
320 " stctg 0,0,0(%1)\n" \
322 : "=m" (*(addrtype *)(array)) \
323 : "a" (&array), "a" (((low)<<4)+(high)) : "1" ); \
326 #define __ctl_set_bit(cr, bit) ({ \
328 __asm__ __volatile__ ( \
329 " bras 1,0f\n" /* skip indirect insns */ \
330 " stctg 0,0,0(%1)\n" \
331 " lctlg 0,0,0(%1)\n" \
332 "0: ex %2,0(1)\n" /* execute stctl */ \
334 " ogr 0,%3\n" /* set the bit */ \
336 "1: ex %2,6(1)" /* execute lctl */ \
338 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
339 "a" (cr*17), "a" (1L<<(bit)) \
340 : "cc", "0", "1" ); \
343 #define __ctl_clear_bit(cr, bit) ({ \
345 __asm__ __volatile__ ( \
346 " bras 1,0f\n" /* skip indirect insns */ \
347 " stctg 0,0,0(%1)\n" \
348 " lctlg 0,0,0(%1)\n" \
349 "0: ex %2,0(1)\n" /* execute stctl */ \
351 " ngr 0,%3\n" /* set the bit */ \
353 "1: ex %2,6(1)" /* execute lctl */ \
355 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
356 "a" (cr*17), "a" (~(1L<<(bit))) \
357 : "cc", "0", "1" ); \
360 #else /* __s390x__ */
362 #define __ctl_load(array, low, high) ({ \
363 typedef struct { char _[sizeof(array)]; } addrtype; \
364 __asm__ __volatile__ ( \
366 " lctl 0,0,0(%0)\n" \
368 : : "a" (&array), "a" (((low)<<4)+(high)), \
369 "m" (*(addrtype *)(array)) : "1" ); \
372 #define __ctl_store(array, low, high) ({ \
373 typedef struct { char _[sizeof(array)]; } addrtype; \
374 __asm__ __volatile__ ( \
376 " stctl 0,0,0(%1)\n" \
378 : "=m" (*(addrtype *)(array)) \
379 : "a" (&array), "a" (((low)<<4)+(high)): "1" ); \
382 #define __ctl_set_bit(cr, bit) ({ \
384 __asm__ __volatile__ ( \
385 " bras 1,0f\n" /* skip indirect insns */ \
386 " stctl 0,0,0(%1)\n" \
387 " lctl 0,0,0(%1)\n" \
388 "0: ex %2,0(1)\n" /* execute stctl */ \
390 " or 0,%3\n" /* set the bit */ \
392 "1: ex %2,4(1)" /* execute lctl */ \
394 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
395 "a" (cr*17), "a" (1<<(bit)) \
396 : "cc", "0", "1" ); \
399 #define __ctl_clear_bit(cr, bit) ({ \
401 __asm__ __volatile__ ( \
402 " bras 1,0f\n" /* skip indirect insns */ \
403 " stctl 0,0,0(%1)\n" \
404 " lctl 0,0,0(%1)\n" \
405 "0: ex %2,0(1)\n" /* execute stctl */ \
407 " nr 0,%3\n" /* set the bit */ \
409 "1: ex %2,4(1)" /* execute lctl */ \
411 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
412 "a" (cr*17), "a" (~(1<<(bit))) \
413 : "cc", "0", "1" ); \
415 #endif /* __s390x__ */
417 #include <linux/irqflags.h>
420 * Use to set psw mask except for the first byte which
421 * won't be changed by this function.
424 __set_psw_mask(unsigned long mask)
426 local_save_flags(mask);
427 __load_psw_mask(mask);
430 #define local_mcck_enable() __set_psw_mask(PSW_KERNEL_BITS)
431 #define local_mcck_disable() __set_psw_mask(PSW_KERNEL_BITS & ~PSW_MASK_MCHECK)
435 extern void smp_ctl_set_bit(int cr, int bit);
436 extern void smp_ctl_clear_bit(int cr, int bit);
437 #define ctl_set_bit(cr, bit) smp_ctl_set_bit(cr, bit)
438 #define ctl_clear_bit(cr, bit) smp_ctl_clear_bit(cr, bit)
442 #define ctl_set_bit(cr, bit) __ctl_set_bit(cr, bit)
443 #define ctl_clear_bit(cr, bit) __ctl_clear_bit(cr, bit)
445 #endif /* CONFIG_SMP */
447 extern void (*_machine_restart)(char *command);
448 extern void (*_machine_halt)(void);
449 extern void (*_machine_power_off)(void);
451 #define arch_align_stack(x) (x)
453 #endif /* __KERNEL__ */