1 #ifndef __PPC64_SYSTEM_H
2 #define __PPC64_SYSTEM_H
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
11 #include <linux/config.h>
12 #include <linux/compiler.h>
14 #include <asm/processor.h>
15 #include <asm/hw_irq.h>
16 #include <asm/memory.h>
20 * The sync instruction guarantees that all memory accesses initiated
21 * by this processor have been performed (with respect to all other
22 * mechanisms that access memory). The eieio instruction is a barrier
23 * providing an ordering (separately) for (a) cacheable stores and (b)
24 * loads and stores to non-cacheable memory (e.g. I/O devices).
26 * mb() prevents loads and stores being reordered across this point.
27 * rmb() prevents loads being reordered across this point.
28 * wmb() prevents stores being reordered across this point.
29 * read_barrier_depends() prevents data-dependent loads being reordered
30 * across this point (nop on PPC).
32 * We can use the eieio instruction for wmb, but since it doesn't
33 * give any ordering guarantees about loads, we have to use the
34 * stronger but slower sync instruction for mb and rmb.
36 #define mb() __asm__ __volatile__ ("sync" : : : "memory")
37 #define rmb() __asm__ __volatile__ ("lwsync" : : : "memory")
38 #define wmb() __asm__ __volatile__ ("eieio" : : : "memory")
39 #define read_barrier_depends() do { } while(0)
41 #define set_mb(var, value) do { var = value; mb(); } while (0)
42 #define set_wmb(var, value) do { var = value; wmb(); } while (0)
46 #define smp_rmb() rmb()
47 #define smp_wmb() wmb()
48 #define smp_read_barrier_depends() read_barrier_depends()
50 #define smp_mb() __asm__ __volatile__("": : :"memory")
51 #define smp_rmb() __asm__ __volatile__("": : :"memory")
52 #define smp_wmb() __asm__ __volatile__("": : :"memory")
53 #define smp_read_barrier_depends() do { } while(0)
54 #endif /* CONFIG_SMP */
60 #ifdef CONFIG_DEBUGGER
62 extern int (*__debugger)(struct pt_regs *regs);
63 extern int (*__debugger_bpt)(struct pt_regs *regs);
64 extern int (*__debugger_sstep)(struct pt_regs *regs);
65 extern int (*__debugger_iabr_match)(struct pt_regs *regs);
66 extern int (*__debugger_dabr_match)(struct pt_regs *regs);
67 extern int (*__debugger_fault_handler)(struct pt_regs *regs);
69 #define DEBUGGER_BOILERPLATE(__NAME) \
70 static inline int __NAME(struct pt_regs *regs) \
72 if (unlikely(__ ## __NAME)) \
73 return __ ## __NAME(regs); \
77 DEBUGGER_BOILERPLATE(debugger)
78 DEBUGGER_BOILERPLATE(debugger_bpt)
79 DEBUGGER_BOILERPLATE(debugger_sstep)
80 DEBUGGER_BOILERPLATE(debugger_iabr_match)
81 DEBUGGER_BOILERPLATE(debugger_dabr_match)
82 DEBUGGER_BOILERPLATE(debugger_fault_handler)
85 extern void xmon_init(void);
89 static inline int debugger(struct pt_regs *regs) { return 0; }
90 static inline int debugger_bpt(struct pt_regs *regs) { return 0; }
91 static inline int debugger_sstep(struct pt_regs *regs) { return 0; }
92 static inline int debugger_iabr_match(struct pt_regs *regs) { return 0; }
93 static inline int debugger_dabr_match(struct pt_regs *regs) { return 0; }
94 static inline int debugger_fault_handler(struct pt_regs *regs) { return 0; }
97 extern int fix_alignment(struct pt_regs *regs);
98 extern void bad_page_fault(struct pt_regs *regs, unsigned long address,
100 extern void show_regs(struct pt_regs * regs);
101 extern int die(const char *str, struct pt_regs *regs, long err);
103 extern void flush_instruction_cache(void);
104 extern int _get_PVR(void);
105 extern void giveup_fpu(struct task_struct *);
106 extern void disable_kernel_fp(void);
107 extern void enable_kernel_fp(void);
108 extern void giveup_altivec(struct task_struct *);
109 extern void disable_kernel_altivec(void);
110 extern void enable_kernel_altivec(void);
111 extern void cvt_fd(float *from, double *to, unsigned long *fpscr);
112 extern void cvt_df(double *from, float *to, unsigned long *fpscr);
115 extern struct task_struct *__switch_to(struct task_struct *,
116 struct task_struct *);
117 #define switch_to(prev, next, last) ((last) = __switch_to((prev), (next)))
119 struct thread_struct;
120 extern struct task_struct * _switch(struct thread_struct *prev,
121 struct thread_struct *next);
123 static inline int __is_processor(unsigned long pv)
126 asm("mfspr %0, 0x11F" : "=r" (pvr));
127 return(PVR_VER(pvr) == pv);
133 * Changes the memory location '*ptr' to be val and returns
134 * the previous value stored there.
136 * Inline asm pulled from arch/ppc/kernel/misc.S so ppc64
137 * is more like most of the other architectures.
139 static __inline__ unsigned long
140 __xchg_u32(volatile int *m, unsigned long val)
144 __asm__ __volatile__(
146 "1: lwarx %0,0,%3 # __xchg_u32\n\
150 : "=&r" (dummy), "=m" (*m)
157 static __inline__ unsigned long
158 __xchg_u64(volatile long *m, unsigned long val)
162 __asm__ __volatile__(
164 "1: ldarx %0,0,%3 # __xchg_u64\n\
168 : "=&r" (dummy), "=m" (*m)
176 * This function doesn't exist, so you'll get a linker error
177 * if something tries to do an invalid xchg().
179 extern void __xchg_called_with_bad_pointer(void);
181 static __inline__ unsigned long
182 __xchg(volatile void *ptr, unsigned long x, int size)
186 return __xchg_u32(ptr, x);
188 return __xchg_u64(ptr, x);
190 __xchg_called_with_bad_pointer();
194 #define xchg(ptr,x) \
196 __typeof__(*(ptr)) _x_ = (x); \
197 (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
200 #define tas(ptr) (xchg((ptr),1))
202 #define __HAVE_ARCH_CMPXCHG 1
204 static __inline__ unsigned long
205 __cmpxchg_u32(volatile int *p, int old, int new)
209 __asm__ __volatile__ (
211 "1: lwarx %0,0,%2 # __cmpxchg_u32\n\
219 : "=&r" (prev), "=m" (*p)
220 : "r" (p), "r" (old), "r" (new), "m" (*p)
226 static __inline__ unsigned long
227 __cmpxchg_u64(volatile long *p, unsigned long old, unsigned long new)
231 __asm__ __volatile__ (
233 "1: ldarx %0,0,%2 # __cmpxchg_u64\n\
241 : "=&r" (prev), "=m" (*p)
242 : "r" (p), "r" (old), "r" (new), "m" (*p)
248 /* This function doesn't exist, so you'll get a linker error
249 if something tries to do an invalid cmpxchg(). */
250 extern void __cmpxchg_called_with_bad_pointer(void);
252 static __inline__ unsigned long
253 __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
257 return __cmpxchg_u32(ptr, old, new);
259 return __cmpxchg_u64(ptr, old, new);
261 __cmpxchg_called_with_bad_pointer();
265 #define cmpxchg(ptr,o,n) \
267 __typeof__(*(ptr)) _o_ = (o); \
268 __typeof__(*(ptr)) _n_ = (n); \
269 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
270 (unsigned long)_n_, sizeof(*(ptr))); \
273 #endif /* __KERNEL__ */