Linux 2.6.18-rc2
[deliverable/linux.git] / include / asm-s390 / system.h
CommitLineData
1da177e4
LT
1/*
2 * include/asm-s390/system.h
3 *
4 * S390 version
5 * Copyright (C) 1999 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
7 *
8 * Derived from "include/asm-i386/system.h"
9 */
10
11#ifndef __ASM_SYSTEM_H
12#define __ASM_SYSTEM_H
13
1da177e4
LT
14#include <linux/kernel.h>
15#include <asm/types.h>
16#include <asm/ptrace.h>
17#include <asm/setup.h>
77fa2245 18#include <asm/processor.h>
1da177e4
LT
19
20#ifdef __KERNEL__
21
22struct task_struct;
23
24extern struct task_struct *__switch_to(void *, void *);
25
26#ifdef __s390x__
27#define __FLAG_SHIFT 56
28#else /* ! __s390x__ */
29#define __FLAG_SHIFT 24
30#endif /* ! __s390x__ */
31
32static inline void save_fp_regs(s390_fp_regs *fpregs)
33{
34 asm volatile (
35 " std 0,8(%1)\n"
36 " std 2,24(%1)\n"
37 " std 4,40(%1)\n"
38 " std 6,56(%1)"
39 : "=m" (*fpregs) : "a" (fpregs), "m" (*fpregs) : "memory" );
40 if (!MACHINE_HAS_IEEE)
41 return;
42 asm volatile(
43 " stfpc 0(%1)\n"
44 " std 1,16(%1)\n"
45 " std 3,32(%1)\n"
46 " std 5,48(%1)\n"
47 " std 7,64(%1)\n"
48 " std 8,72(%1)\n"
49 " std 9,80(%1)\n"
50 " std 10,88(%1)\n"
51 " std 11,96(%1)\n"
52 " std 12,104(%1)\n"
53 " std 13,112(%1)\n"
54 " std 14,120(%1)\n"
55 " std 15,128(%1)\n"
56 : "=m" (*fpregs) : "a" (fpregs), "m" (*fpregs) : "memory" );
57}
58
59static inline void restore_fp_regs(s390_fp_regs *fpregs)
60{
61 asm volatile (
62 " ld 0,8(%0)\n"
63 " ld 2,24(%0)\n"
64 " ld 4,40(%0)\n"
65 " ld 6,56(%0)"
66 : : "a" (fpregs), "m" (*fpregs) );
67 if (!MACHINE_HAS_IEEE)
68 return;
69 asm volatile(
70 " lfpc 0(%0)\n"
71 " ld 1,16(%0)\n"
72 " ld 3,32(%0)\n"
73 " ld 5,48(%0)\n"
74 " ld 7,64(%0)\n"
75 " ld 8,72(%0)\n"
76 " ld 9,80(%0)\n"
77 " ld 10,88(%0)\n"
78 " ld 11,96(%0)\n"
79 " ld 12,104(%0)\n"
80 " ld 13,112(%0)\n"
81 " ld 14,120(%0)\n"
82 " ld 15,128(%0)\n"
83 : : "a" (fpregs), "m" (*fpregs) );
84}
85
86static inline void save_access_regs(unsigned int *acrs)
87{
88 asm volatile ("stam 0,15,0(%0)" : : "a" (acrs) : "memory" );
89}
90
91static inline void restore_access_regs(unsigned int *acrs)
92{
93 asm volatile ("lam 0,15,0(%0)" : : "a" (acrs) );
94}
95
96#define switch_to(prev,next,last) do { \
97 if (prev == next) \
98 break; \
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); \
104} while (0)
105
4dc7a0bb
IM
106/*
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.
109 *
110 * TODO: fill this in!
111 */
112static inline void sched_cacheflush(void)
113{
114}
115
1da177e4 116#ifdef CONFIG_VIRT_CPU_ACCOUNTING
1f1c12af
MS
117extern void account_vtime(struct task_struct *);
118extern void account_tick_vtime(struct task_struct *);
1da177e4 119extern void account_system_vtime(struct task_struct *);
5c833890
JB
120#else
121#define account_vtime(x) do { /* empty */ } while (0)
4866cde0 122#endif
1da177e4 123
5ee24d95 124#define finish_arch_switch(prev) do { \
1da177e4 125 set_fs(current->thread.mm_segment); \
1f1c12af 126 account_vtime(prev); \
1da177e4
LT
127} while (0)
128
1da177e4
LT
129#define nop() __asm__ __volatile__ ("nop")
130
131#define xchg(ptr,x) \
132 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(void *)(ptr),sizeof(*(ptr))))
133
134static inline unsigned long __xchg(unsigned long x, void * ptr, int size)
135{
136 unsigned long addr, old;
137 int shift;
138
139 switch (size) {
140 case 1:
141 addr = (unsigned long) ptr;
142 shift = (3 ^ (addr & 3)) << 3;
143 addr ^= addr & 3;
144 asm volatile(
145 " l %0,0(%4)\n"
146 "0: lr 0,%0\n"
147 " nr 0,%3\n"
148 " or 0,%2\n"
149 " cs %0,0,0(%4)\n"
150 " jl 0b\n"
151 : "=&d" (old), "=m" (*(int *) addr)
152 : "d" (x << shift), "d" (~(255 << shift)), "a" (addr),
153 "m" (*(int *) addr) : "memory", "cc", "0" );
154 x = old >> shift;
155 break;
156 case 2:
157 addr = (unsigned long) ptr;
158 shift = (2 ^ (addr & 2)) << 3;
159 addr ^= addr & 2;
160 asm volatile(
161 " l %0,0(%4)\n"
162 "0: lr 0,%0\n"
163 " nr 0,%3\n"
164 " or 0,%2\n"
165 " cs %0,0,0(%4)\n"
166 " jl 0b\n"
167 : "=&d" (old), "=m" (*(int *) addr)
168 : "d" (x << shift), "d" (~(65535 << shift)), "a" (addr),
169 "m" (*(int *) addr) : "memory", "cc", "0" );
170 x = old >> shift;
171 break;
172 case 4:
173 asm volatile (
174 " l %0,0(%3)\n"
175 "0: cs %0,%2,0(%3)\n"
176 " jl 0b\n"
177 : "=&d" (old), "=m" (*(int *) ptr)
178 : "d" (x), "a" (ptr), "m" (*(int *) ptr)
179 : "memory", "cc" );
180 x = old;
181 break;
182#ifdef __s390x__
183 case 8:
184 asm volatile (
185 " lg %0,0(%3)\n"
186 "0: csg %0,%2,0(%3)\n"
187 " jl 0b\n"
188 : "=&d" (old), "=m" (*(long *) ptr)
189 : "d" (x), "a" (ptr), "m" (*(long *) ptr)
190 : "memory", "cc" );
191 x = old;
192 break;
193#endif /* __s390x__ */
194 }
195 return x;
196}
197
198/*
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.
202 */
203
204#define __HAVE_ARCH_CMPXCHG 1
205
206#define cmpxchg(ptr,o,n)\
207 ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
208 (unsigned long)(n),sizeof(*(ptr))))
209
210static inline unsigned long
211__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
212{
213 unsigned long addr, prev, tmp;
214 int shift;
215
216 switch (size) {
217 case 1:
218 addr = (unsigned long) ptr;
219 shift = (3 ^ (addr & 3)) << 3;
220 addr ^= addr & 3;
221 asm volatile(
222 " l %0,0(%4)\n"
223 "0: nr %0,%5\n"
224 " lr %1,%0\n"
225 " or %0,%2\n"
226 " or %1,%3\n"
227 " cs %0,%1,0(%4)\n"
228 " jnl 1f\n"
229 " xr %1,%0\n"
230 " nr %1,%5\n"
231 " jnz 0b\n"
232 "1:"
233 : "=&d" (prev), "=&d" (tmp)
234 : "d" (old << shift), "d" (new << shift), "a" (ptr),
235 "d" (~(255 << shift))
236 : "memory", "cc" );
237 return prev >> shift;
238 case 2:
239 addr = (unsigned long) ptr;
240 shift = (2 ^ (addr & 2)) << 3;
241 addr ^= addr & 2;
242 asm volatile(
243 " l %0,0(%4)\n"
244 "0: nr %0,%5\n"
245 " lr %1,%0\n"
246 " or %0,%2\n"
247 " or %1,%3\n"
248 " cs %0,%1,0(%4)\n"
249 " jnl 1f\n"
250 " xr %1,%0\n"
251 " nr %1,%5\n"
252 " jnz 0b\n"
253 "1:"
254 : "=&d" (prev), "=&d" (tmp)
255 : "d" (old << shift), "d" (new << shift), "a" (ptr),
256 "d" (~(65535 << shift))
257 : "memory", "cc" );
258 return prev >> shift;
259 case 4:
260 asm volatile (
261 " cs %0,%2,0(%3)\n"
262 : "=&d" (prev) : "0" (old), "d" (new), "a" (ptr)
263 : "memory", "cc" );
264 return prev;
265#ifdef __s390x__
266 case 8:
267 asm volatile (
268 " csg %0,%2,0(%3)\n"
269 : "=&d" (prev) : "0" (old), "d" (new), "a" (ptr)
270 : "memory", "cc" );
271 return prev;
272#endif /* __s390x__ */
273 }
274 return old;
275}
276
277/*
278 * Force strict CPU ordering.
279 * And yes, this is required on UP too when we're talking
280 * to devices.
281 *
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 ).
285 */
286
287#define eieio() __asm__ __volatile__ ( "bcr 15,0" : : : "memory" )
288# define SYNC_OTHER_CORES(x) eieio()
289#define mb() 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()
299
300
301#define set_mb(var, value) do { var = value; mb(); } while (0)
1da177e4 302
1da177e4
LT
303#ifdef __s390x__
304
1da177e4
LT
305#define __ctl_load(array, low, high) ({ \
306 typedef struct { char _[sizeof(array)]; } addrtype; \
307 __asm__ __volatile__ ( \
308 " bras 1,0f\n" \
309 " lctlg 0,0,0(%0)\n" \
310 "0: ex %1,0(1)" \
311 : : "a" (&array), "a" (((low)<<4)+(high)), \
312 "m" (*(addrtype *)(array)) : "1" ); \
313 })
314
315#define __ctl_store(array, low, high) ({ \
316 typedef struct { char _[sizeof(array)]; } addrtype; \
317 __asm__ __volatile__ ( \
318 " bras 1,0f\n" \
319 " stctg 0,0,0(%1)\n" \
320 "0: ex %2,0(1)" \
321 : "=m" (*(addrtype *)(array)) \
322 : "a" (&array), "a" (((low)<<4)+(high)) : "1" ); \
323 })
324
325#define __ctl_set_bit(cr, bit) ({ \
326 __u8 __dummy[24]; \
327 __asm__ __volatile__ ( \
328 " bras 1,0f\n" /* skip indirect insns */ \
329 " stctg 0,0,0(%1)\n" \
330 " lctlg 0,0,0(%1)\n" \
331 "0: ex %2,0(1)\n" /* execute stctl */ \
332 " lg 0,0(%1)\n" \
333 " ogr 0,%3\n" /* set the bit */ \
334 " stg 0,0(%1)\n" \
335 "1: ex %2,6(1)" /* execute lctl */ \
336 : "=m" (__dummy) \
337 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
338 "a" (cr*17), "a" (1L<<(bit)) \
339 : "cc", "0", "1" ); \
340 })
341
342#define __ctl_clear_bit(cr, bit) ({ \
343 __u8 __dummy[16]; \
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 */ \
349 " lg 0,0(%1)\n" \
350 " ngr 0,%3\n" /* set the bit */ \
351 " stg 0,0(%1)\n" \
352 "1: ex %2,6(1)" /* execute lctl */ \
353 : "=m" (__dummy) \
354 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
355 "a" (cr*17), "a" (~(1L<<(bit))) \
356 : "cc", "0", "1" ); \
357 })
358
359#else /* __s390x__ */
360
1da177e4
LT
361#define __ctl_load(array, low, high) ({ \
362 typedef struct { char _[sizeof(array)]; } addrtype; \
363 __asm__ __volatile__ ( \
364 " bras 1,0f\n" \
365 " lctl 0,0,0(%0)\n" \
366 "0: ex %1,0(1)" \
367 : : "a" (&array), "a" (((low)<<4)+(high)), \
368 "m" (*(addrtype *)(array)) : "1" ); \
369 })
370
371#define __ctl_store(array, low, high) ({ \
372 typedef struct { char _[sizeof(array)]; } addrtype; \
373 __asm__ __volatile__ ( \
374 " bras 1,0f\n" \
375 " stctl 0,0,0(%1)\n" \
376 "0: ex %2,0(1)" \
377 : "=m" (*(addrtype *)(array)) \
378 : "a" (&array), "a" (((low)<<4)+(high)): "1" ); \
379 })
380
381#define __ctl_set_bit(cr, bit) ({ \
382 __u8 __dummy[16]; \
383 __asm__ __volatile__ ( \
384 " bras 1,0f\n" /* skip indirect insns */ \
385 " stctl 0,0,0(%1)\n" \
386 " lctl 0,0,0(%1)\n" \
387 "0: ex %2,0(1)\n" /* execute stctl */ \
388 " l 0,0(%1)\n" \
389 " or 0,%3\n" /* set the bit */ \
390 " st 0,0(%1)\n" \
391 "1: ex %2,4(1)" /* execute lctl */ \
392 : "=m" (__dummy) \
393 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
394 "a" (cr*17), "a" (1<<(bit)) \
395 : "cc", "0", "1" ); \
396 })
397
398#define __ctl_clear_bit(cr, bit) ({ \
399 __u8 __dummy[16]; \
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 */ \
405 " l 0,0(%1)\n" \
406 " nr 0,%3\n" /* set the bit */ \
407 " st 0,0(%1)\n" \
408 "1: ex %2,4(1)" /* execute lctl */ \
409 : "=m" (__dummy) \
410 : "a" ((((unsigned long) &__dummy) + 7) & ~7UL), \
411 "a" (cr*17), "a" (~(1<<(bit))) \
412 : "cc", "0", "1" ); \
413 })
414#endif /* __s390x__ */
415
1f194a4c 416#include <linux/irqflags.h>
1da177e4 417
77fa2245
HC
418/*
419 * Use to set psw mask except for the first byte which
420 * won't be changed by this function.
421 */
422static inline void
423__set_psw_mask(unsigned long mask)
424{
425 local_save_flags(mask);
426 __load_psw_mask(mask);
427}
428
429#define local_mcck_enable() __set_psw_mask(PSW_KERNEL_BITS)
430#define local_mcck_disable() __set_psw_mask(PSW_KERNEL_BITS & ~PSW_MASK_MCHECK)
431
1da177e4
LT
432#ifdef CONFIG_SMP
433
434extern void smp_ctl_set_bit(int cr, int bit);
435extern void smp_ctl_clear_bit(int cr, int bit);
436#define ctl_set_bit(cr, bit) smp_ctl_set_bit(cr, bit)
437#define ctl_clear_bit(cr, bit) smp_ctl_clear_bit(cr, bit)
438
439#else
440
441#define ctl_set_bit(cr, bit) __ctl_set_bit(cr, bit)
442#define ctl_clear_bit(cr, bit) __ctl_clear_bit(cr, bit)
443
444#endif /* CONFIG_SMP */
445
446extern void (*_machine_restart)(char *command);
447extern void (*_machine_halt)(void);
448extern void (*_machine_power_off)(void);
449
450#define arch_align_stack(x) (x)
451
452#endif /* __KERNEL__ */
453
454#endif
This page took 0.151523 seconds and 5 git commands to generate.