blob: 212dca66fcac28f7a38fb994149997c58be6e0c5 [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
7#include <linux/config.h>
8#include <linux/kernel.h>
9
10#include <asm/atomic.h>
11#include <asm/hw_irq.h>
12
13/*
14 * Memory barrier.
15 * The sync instruction guarantees that all memory accesses initiated
16 * by this processor have been performed (with respect to all other
17 * mechanisms that access memory). The eieio instruction is a barrier
18 * providing an ordering (separately) for (a) cacheable stores and (b)
19 * loads and stores to non-cacheable memory (e.g. I/O devices).
20 *
21 * mb() prevents loads and stores being reordered across this point.
22 * rmb() prevents loads being reordered across this point.
23 * wmb() prevents stores being reordered across this point.
24 * read_barrier_depends() prevents data-dependent loads being reordered
25 * across this point (nop on PPC).
26 *
27 * We can use the eieio instruction for wmb, but since it doesn't
28 * give any ordering guarantees about loads, we have to use the
29 * stronger but slower sync instruction for mb and rmb.
30 */
31#define mb() __asm__ __volatile__ ("sync" : : : "memory")
32#define rmb() __asm__ __volatile__ ("sync" : : : "memory")
33#define wmb() __asm__ __volatile__ ("eieio" : : : "memory")
34#define read_barrier_depends() do { } while(0)
35
36#define set_mb(var, value) do { var = value; mb(); } while (0)
37#define set_wmb(var, value) do { var = value; wmb(); } while (0)
38
39#ifdef CONFIG_SMP
40#define smp_mb() mb()
41#define smp_rmb() rmb()
42#define smp_wmb() wmb()
43#define smp_read_barrier_depends() read_barrier_depends()
44#else
45#define smp_mb() barrier()
46#define smp_rmb() barrier()
47#define smp_wmb() barrier()
48#define smp_read_barrier_depends() do { } while(0)
49#endif /* CONFIG_SMP */
50
51#ifdef __KERNEL__
52struct task_struct;
53struct pt_regs;
54
55extern void print_backtrace(unsigned long *);
56extern void show_regs(struct pt_regs * regs);
57extern void flush_instruction_cache(void);
58extern void hard_reset_now(void);
59extern void poweroff_now(void);
60#ifdef CONFIG_6xx
61extern long _get_L2CR(void);
62extern long _get_L3CR(void);
63extern void _set_L2CR(unsigned long);
64extern void _set_L3CR(unsigned long);
65#else
66#define _get_L2CR() 0L
67#define _get_L3CR() 0L
68#define _set_L2CR(val) do { } while(0)
69#define _set_L3CR(val) do { } while(0)
70#endif
71extern void via_cuda_init(void);
72extern void pmac_nvram_init(void);
Olaf Hering35e95e62005-10-28 17:46:19 -070073extern void chrp_nvram_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074extern void read_rtc_time(void);
75extern void pmac_find_display(void);
76extern void giveup_fpu(struct task_struct *);
77extern void enable_kernel_fp(void);
Paul Mackerras7ac59c62005-10-17 20:12:39 +100078extern void flush_fp_to_thread(struct task_struct *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079extern void enable_kernel_altivec(void);
80extern void giveup_altivec(struct task_struct *);
81extern void load_up_altivec(struct task_struct *);
Paul Mackerrasfd582ec2005-10-11 22:08:12 +100082extern int emulate_altivec(struct pt_regs *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083extern void giveup_spe(struct task_struct *);
84extern void load_up_spe(struct task_struct *);
85extern int fix_alignment(struct pt_regs *);
David Gibson25c8a782005-10-27 16:27:25 +100086extern void cvt_fd(float *from, double *to, struct thread_struct *thread);
87extern void cvt_df(double *from, float *to, struct thread_struct *thread);
Paul Mackerras7ac59c62005-10-17 20:12:39 +100088
89#ifdef CONFIG_ALTIVEC
90extern void flush_altivec_to_thread(struct task_struct *);
91#else
92static inline void flush_altivec_to_thread(struct task_struct *t)
93{
94}
95#endif
96
97#ifdef CONFIG_SPE
98extern void flush_spe_to_thread(struct task_struct *);
99#else
100static inline void flush_spe_to_thread(struct task_struct *t)
101{
102}
103#endif
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105extern int call_rtas(const char *, int, int, unsigned long *, ...);
106extern void cacheable_memzero(void *p, unsigned int nb);
Eugene Surovegine8834802005-09-03 15:55:54 -0700107extern void *cacheable_memcpy(void *, const void *, unsigned int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long);
109extern void bad_page_fault(struct pt_regs *, unsigned long, int);
Stephen Rothwelldc1c1ca2005-10-01 18:43:42 +1000110extern int die(const char *, struct pt_regs *, long);
Paul Mackerrasbb0bb3b2005-09-10 21:13:11 +1000111extern void _exception(int, struct pt_regs *, int, unsigned long);
Paul Mackerrasfd582ec2005-10-11 22:08:12 +1000112void _nmask_and_or_msr(unsigned long nmask, unsigned long or_val);
113
Kumar Gala39cdc4b2005-09-03 15:55:39 -0700114#ifdef CONFIG_BOOKE_WDT
115extern u32 booke_wdt_enabled;
116extern u32 booke_wdt_period;
117#endif /* CONFIG_BOOKE_WDT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119struct device_node;
120extern void note_scsi_host(struct device_node *, void *);
121
122extern struct task_struct *__switch_to(struct task_struct *,
123 struct task_struct *);
124#define switch_to(prev, next, last) ((last) = __switch_to((prev), (next)))
125
Ingo Molnar4dc7a0b2006-01-12 01:05:27 -0800126/*
127 * On SMP systems, when the scheduler does migration-cost autodetection,
128 * it needs a way to flush as much of the CPU's caches as possible.
129 *
130 * TODO: fill this in!
131 */
132static inline void sched_cacheflush(void)
133{
134}
135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136struct thread_struct;
137extern struct task_struct *_switch(struct thread_struct *prev,
138 struct thread_struct *next);
139
140extern unsigned int rtas_data;
141
142static __inline__ unsigned long
143xchg_u32(volatile void *p, unsigned long val)
144{
145 unsigned long prev;
146
147 __asm__ __volatile__ ("\n\
1481: lwarx %0,0,%2 \n"
149 PPC405_ERR77(0,%2)
150" stwcx. %3,0,%2 \n\
151 bne- 1b"
152 : "=&r" (prev), "=m" (*(volatile unsigned long *)p)
153 : "r" (p), "r" (val), "m" (*(volatile unsigned long *)p)
154 : "cc", "memory");
155
156 return prev;
157}
158
159/*
160 * This function doesn't exist, so you'll get a linker error
161 * if something tries to do an invalid xchg().
162 */
163extern void __xchg_called_with_bad_pointer(void);
164
165#define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
166#define tas(ptr) (xchg((ptr),1))
167
168static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
169{
170 switch (size) {
171 case 4:
172 return (unsigned long) xchg_u32(ptr, x);
173#if 0 /* xchg_u64 doesn't exist on 32-bit PPC */
174 case 8:
175 return (unsigned long) xchg_u64(ptr, x);
176#endif /* 0 */
177 }
178 __xchg_called_with_bad_pointer();
179 return x;
180
181
182}
183
184extern inline void * xchg_ptr(void * m, void * val)
185{
186 return (void *) xchg_u32(m, (unsigned long) val);
187}
188
189
190#define __HAVE_ARCH_CMPXCHG 1
191
192static __inline__ unsigned long
193__cmpxchg_u32(volatile unsigned int *p, unsigned int old, unsigned int new)
194{
195 unsigned int prev;
196
197 __asm__ __volatile__ ("\n\
1981: lwarx %0,0,%2 \n\
199 cmpw 0,%0,%3 \n\
200 bne 2f \n"
201 PPC405_ERR77(0,%2)
202" stwcx. %4,0,%2 \n\
203 bne- 1b\n"
204#ifdef CONFIG_SMP
205" sync\n"
206#endif /* CONFIG_SMP */
207"2:"
208 : "=&r" (prev), "=m" (*p)
209 : "r" (p), "r" (old), "r" (new), "m" (*p)
210 : "cc", "memory");
211
212 return prev;
213}
214
215/* This function doesn't exist, so you'll get a linker error
216 if something tries to do an invalid cmpxchg(). */
217extern void __cmpxchg_called_with_bad_pointer(void);
218
219static __inline__ unsigned long
220__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
221{
222 switch (size) {
223 case 4:
224 return __cmpxchg_u32(ptr, old, new);
225#if 0 /* we don't have __cmpxchg_u64 on 32-bit PPC */
226 case 8:
227 return __cmpxchg_u64(ptr, old, new);
228#endif /* 0 */
229 }
230 __cmpxchg_called_with_bad_pointer();
231 return old;
232}
233
234#define cmpxchg(ptr,o,n) \
235 ({ \
236 __typeof__(*(ptr)) _o_ = (o); \
237 __typeof__(*(ptr)) _n_ = (n); \
238 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
239 (unsigned long)_n_, sizeof(*(ptr))); \
240 })
241
242#define arch_align_stack(x) (x)
243
244#endif /* __KERNEL__ */
245#endif /* __PPC_SYSTEM_H */