blob: f1311a8f310fe9e3c75c28a1d47644c2f1db3465 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
3 */
4#ifndef __PPC_SYSTEM_H
5#define __PPC_SYSTEM_H
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/kernel.h>
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <asm/hw_irq.h>
10
11/*
12 * Memory barrier.
13 * The sync instruction guarantees that all memory accesses initiated
14 * by this processor have been performed (with respect to all other
15 * mechanisms that access memory). The eieio instruction is a barrier
16 * providing an ordering (separately) for (a) cacheable stores and (b)
17 * loads and stores to non-cacheable memory (e.g. I/O devices).
18 *
19 * mb() prevents loads and stores being reordered across this point.
20 * rmb() prevents loads being reordered across this point.
21 * wmb() prevents stores being reordered across this point.
22 * read_barrier_depends() prevents data-dependent loads being reordered
23 * across this point (nop on PPC).
24 *
25 * We can use the eieio instruction for wmb, but since it doesn't
26 * give any ordering guarantees about loads, we have to use the
27 * stronger but slower sync instruction for mb and rmb.
28 */
29#define mb() __asm__ __volatile__ ("sync" : : : "memory")
30#define rmb() __asm__ __volatile__ ("sync" : : : "memory")
31#define wmb() __asm__ __volatile__ ("eieio" : : : "memory")
32#define read_barrier_depends() do { } while(0)
33
34#define set_mb(var, value) do { var = value; mb(); } while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36#ifdef CONFIG_SMP
37#define smp_mb() mb()
38#define smp_rmb() rmb()
Paul Mackerras624cee32006-01-12 21:22:34 +110039#define smp_wmb() __asm__ __volatile__ ("eieio" : : : "memory")
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#define smp_read_barrier_depends() read_barrier_depends()
41#else
42#define smp_mb() barrier()
43#define smp_rmb() barrier()
44#define smp_wmb() barrier()
45#define smp_read_barrier_depends() do { } while(0)
46#endif /* CONFIG_SMP */
47
48#ifdef __KERNEL__
49struct task_struct;
50struct pt_regs;
51
52extern void print_backtrace(unsigned long *);
53extern void show_regs(struct pt_regs * regs);
54extern void flush_instruction_cache(void);
55extern void hard_reset_now(void);
56extern void poweroff_now(void);
57#ifdef CONFIG_6xx
58extern long _get_L2CR(void);
59extern long _get_L3CR(void);
60extern void _set_L2CR(unsigned long);
61extern void _set_L3CR(unsigned long);
62#else
63#define _get_L2CR() 0L
64#define _get_L3CR() 0L
65#define _set_L2CR(val) do { } while(0)
66#define _set_L3CR(val) do { } while(0)
67#endif
68extern void via_cuda_init(void);
69extern void pmac_nvram_init(void);
Olaf Hering35e95e62005-10-28 17:46:19 -070070extern void chrp_nvram_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071extern void read_rtc_time(void);
72extern void pmac_find_display(void);
73extern void giveup_fpu(struct task_struct *);
Paul Mackerras624cee32006-01-12 21:22:34 +110074extern void disable_kernel_fp(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075extern void enable_kernel_fp(void);
Paul Mackerras7ac59c62005-10-17 20:12:39 +100076extern void flush_fp_to_thread(struct task_struct *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077extern void enable_kernel_altivec(void);
78extern void giveup_altivec(struct task_struct *);
79extern void load_up_altivec(struct task_struct *);
Paul Mackerrasfd582ec2005-10-11 22:08:12 +100080extern int emulate_altivec(struct pt_regs *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081extern void giveup_spe(struct task_struct *);
82extern void load_up_spe(struct task_struct *);
83extern int fix_alignment(struct pt_regs *);
David Gibson25c8a782005-10-27 16:27:25 +100084extern void cvt_fd(float *from, double *to, struct thread_struct *thread);
85extern void cvt_df(double *from, float *to, struct thread_struct *thread);
Paul Mackerras7ac59c62005-10-17 20:12:39 +100086
Paul Mackerras624cee32006-01-12 21:22:34 +110087#ifndef CONFIG_SMP
88extern void discard_lazy_cpu_state(void);
89#else
90static inline void discard_lazy_cpu_state(void)
91{
92}
93#endif
94
Paul Mackerras7ac59c62005-10-17 20:12:39 +100095#ifdef CONFIG_ALTIVEC
96extern void flush_altivec_to_thread(struct task_struct *);
97#else
98static inline void flush_altivec_to_thread(struct task_struct *t)
99{
100}
101#endif
102
103#ifdef CONFIG_SPE
104extern void flush_spe_to_thread(struct task_struct *);
105#else
106static inline void flush_spe_to_thread(struct task_struct *t)
107{
108}
109#endif
110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111extern int call_rtas(const char *, int, int, unsigned long *, ...);
112extern void cacheable_memzero(void *p, unsigned int nb);
Eugene Surovegine8834802005-09-03 15:55:54 -0700113extern void *cacheable_memcpy(void *, const void *, unsigned int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long);
115extern void bad_page_fault(struct pt_regs *, unsigned long, int);
Stephen Rothwelldc1c1ca2005-10-01 18:43:42 +1000116extern int die(const char *, struct pt_regs *, long);
Paul Mackerrasbb0bb3b2005-09-10 21:13:11 +1000117extern void _exception(int, struct pt_regs *, int, unsigned long);
Paul Mackerrasfd582ec2005-10-11 22:08:12 +1000118void _nmask_and_or_msr(unsigned long nmask, unsigned long or_val);
119
Kumar Gala39cdc4b2005-09-03 15:55:39 -0700120#ifdef CONFIG_BOOKE_WDT
121extern u32 booke_wdt_enabled;
122extern u32 booke_wdt_period;
123#endif /* CONFIG_BOOKE_WDT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125struct device_node;
126extern void note_scsi_host(struct device_node *, void *);
127
128extern struct task_struct *__switch_to(struct task_struct *,
129 struct task_struct *);
130#define switch_to(prev, next, last) ((last) = __switch_to((prev), (next)))
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132struct thread_struct;
133extern struct task_struct *_switch(struct thread_struct *prev,
134 struct thread_struct *next);
135
136extern unsigned int rtas_data;
137
138static __inline__ unsigned long
139xchg_u32(volatile void *p, unsigned long val)
140{
141 unsigned long prev;
142
143 __asm__ __volatile__ ("\n\
1441: lwarx %0,0,%2 \n"
145 PPC405_ERR77(0,%2)
146" stwcx. %3,0,%2 \n\
147 bne- 1b"
148 : "=&r" (prev), "=m" (*(volatile unsigned long *)p)
149 : "r" (p), "r" (val), "m" (*(volatile unsigned long *)p)
150 : "cc", "memory");
151
152 return prev;
153}
154
155/*
156 * This function doesn't exist, so you'll get a linker error
157 * if something tries to do an invalid xchg().
158 */
159extern void __xchg_called_with_bad_pointer(void);
160
161#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
164{
165 switch (size) {
166 case 4:
167 return (unsigned long) xchg_u32(ptr, x);
168#if 0 /* xchg_u64 doesn't exist on 32-bit PPC */
169 case 8:
170 return (unsigned long) xchg_u64(ptr, x);
171#endif /* 0 */
172 }
173 __xchg_called_with_bad_pointer();
174 return x;
175
176
177}
178
179extern inline void * xchg_ptr(void * m, void * val)
180{
181 return (void *) xchg_u32(m, (unsigned long) val);
182}
183
184
185#define __HAVE_ARCH_CMPXCHG 1
186
187static __inline__ unsigned long
188__cmpxchg_u32(volatile unsigned int *p, unsigned int old, unsigned int new)
189{
190 unsigned int prev;
191
192 __asm__ __volatile__ ("\n\
1931: lwarx %0,0,%2 \n\
194 cmpw 0,%0,%3 \n\
195 bne 2f \n"
196 PPC405_ERR77(0,%2)
197" stwcx. %4,0,%2 \n\
198 bne- 1b\n"
199#ifdef CONFIG_SMP
200" sync\n"
201#endif /* CONFIG_SMP */
202"2:"
203 : "=&r" (prev), "=m" (*p)
204 : "r" (p), "r" (old), "r" (new), "m" (*p)
205 : "cc", "memory");
206
207 return prev;
208}
209
210/* This function doesn't exist, so you'll get a linker error
211 if something tries to do an invalid cmpxchg(). */
212extern void __cmpxchg_called_with_bad_pointer(void);
213
214static __inline__ unsigned long
215__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
216{
217 switch (size) {
218 case 4:
219 return __cmpxchg_u32(ptr, old, new);
220#if 0 /* we don't have __cmpxchg_u64 on 32-bit PPC */
221 case 8:
222 return __cmpxchg_u64(ptr, old, new);
223#endif /* 0 */
224 }
225 __cmpxchg_called_with_bad_pointer();
226 return old;
227}
228
229#define cmpxchg(ptr,o,n) \
230 ({ \
231 __typeof__(*(ptr)) _o_ = (o); \
232 __typeof__(*(ptr)) _n_ = (n); \
233 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
234 (unsigned long)_n_, sizeof(*(ptr))); \
235 })
236
237#define arch_align_stack(x) (x)
238
239#endif /* __KERNEL__ */
240#endif /* __PPC_SYSTEM_H */