blob: 2a4be19a92c43275343fb5ed808667c92117bb92 [file] [log] [blame]
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001/*
2 * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
3 */
Stephen Rothwellbbeb3f42005-09-27 13:51:59 +10004#ifndef _ASM_POWERPC_SYSTEM_H
5#define _ASM_POWERPC_SYSTEM_H
Paul Mackerras14cf11a2005-09-26 16:04:21 +10006
Paul Mackerras14cf11a2005-09-26 16:04:21 +10007#include <linux/kernel.h>
Paul Mackerras14b3ca42008-04-20 17:57:10 +10008#include <linux/irqflags.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +10009
10#include <asm/hw_irq.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100011
12/*
13 * Memory barrier.
14 * The sync instruction guarantees that all memory accesses initiated
15 * by this processor have been performed (with respect to all other
16 * mechanisms that access memory). The eieio instruction is a barrier
17 * providing an ordering (separately) for (a) cacheable stores and (b)
18 * loads and stores to non-cacheable memory (e.g. I/O devices).
19 *
20 * mb() prevents loads and stores being reordered across this point.
21 * rmb() prevents loads being reordered across this point.
22 * wmb() prevents stores being reordered across this point.
23 * read_barrier_depends() prevents data-dependent loads being reordered
24 * across this point (nop on PPC).
25 *
Nick Piggin957ab072008-11-11 17:51:18 +000026 * *mb() variants without smp_ prefix must order all types of memory
27 * operations with one another. sync is the only instruction sufficient
28 * to do this.
Paul Mackerras14cf11a2005-09-26 16:04:21 +100029 *
Nick Piggin957ab072008-11-11 17:51:18 +000030 * For the smp_ barriers, ordering is for cacheable memory operations
31 * only. We have to use the sync instruction for smp_mb(), since lwsync
32 * doesn't order loads with respect to previous stores. Lwsync can be
33 * used for smp_rmb() and smp_wmb().
34 *
35 * However, on CPUs that don't support lwsync, lwsync actually maps to a
36 * heavy-weight sync, so smp_wmb() can be a lighter-weight eieio.
Paul Mackerras14cf11a2005-09-26 16:04:21 +100037 */
38#define mb() __asm__ __volatile__ ("sync" : : : "memory")
Nick Piggin598056d2008-05-22 00:10:56 +100039#define rmb() __asm__ __volatile__ ("sync" : : : "memory")
Paul Mackerras14cf11a2005-09-26 16:04:21 +100040#define wmb() __asm__ __volatile__ ("sync" : : : "memory")
41#define read_barrier_depends() do { } while(0)
42
43#define set_mb(var, value) do { var = value; mb(); } while (0)
Paul Mackerras14cf11a2005-09-26 16:04:21 +100044
Arnd Bergmann88ced032005-12-16 22:43:46 +010045#ifdef __KERNEL__
Olaf Hering4f9a58d2007-10-16 23:30:12 -070046#define AT_VECTOR_SIZE_ARCH 6 /* entries in ARCH_DLINFO */
Paul Mackerras14cf11a2005-09-26 16:04:21 +100047#ifdef CONFIG_SMP
Nick Piggin74f06092008-05-22 00:12:31 +100048
49#ifdef __SUBARCH_HAS_LWSYNC
Nick Piggin46d075be2008-11-11 17:50:48 +000050# define SMPWMB LWSYNC
Nick Piggin74f06092008-05-22 00:12:31 +100051#else
52# define SMPWMB eieio
53#endif
54
Paul Mackerras14cf11a2005-09-26 16:04:21 +100055#define smp_mb() mb()
Nick Piggin957ab072008-11-11 17:51:18 +000056#define smp_rmb() __asm__ __volatile__ (stringify_in_c(LWSYNC) : : :"memory")
Nick Piggin46d075be2008-11-11 17:50:48 +000057#define smp_wmb() __asm__ __volatile__ (stringify_in_c(SMPWMB) : : :"memory")
Paul Mackerras14cf11a2005-09-26 16:04:21 +100058#define smp_read_barrier_depends() read_barrier_depends()
59#else
60#define smp_mb() barrier()
61#define smp_rmb() barrier()
62#define smp_wmb() barrier()
63#define smp_read_barrier_depends() do { } while(0)
64#endif /* CONFIG_SMP */
65
Nathan Lynch5db9fa92006-08-22 20:36:05 -050066/*
67 * This is a barrier which prevents following instructions from being
68 * started until the value of the argument x is known. For example, if
69 * x is a variable loaded from memory, this prevents following
70 * instructions from being executed until the load has been performed.
71 */
72#define data_barrier(x) \
73 asm volatile("twi 0,%0,0; isync" : : "r" (x) : "memory");
74
Paul Mackerras14cf11a2005-09-26 16:04:21 +100075struct task_struct;
76struct pt_regs;
77
Olof Johansson7dbb9222008-01-31 14:34:47 +110078#if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
Paul Mackerras14cf11a2005-09-26 16:04:21 +100079
80extern int (*__debugger)(struct pt_regs *regs);
81extern int (*__debugger_ipi)(struct pt_regs *regs);
82extern int (*__debugger_bpt)(struct pt_regs *regs);
83extern int (*__debugger_sstep)(struct pt_regs *regs);
84extern int (*__debugger_iabr_match)(struct pt_regs *regs);
85extern int (*__debugger_dabr_match)(struct pt_regs *regs);
86extern int (*__debugger_fault_handler)(struct pt_regs *regs);
87
88#define DEBUGGER_BOILERPLATE(__NAME) \
89static inline int __NAME(struct pt_regs *regs) \
90{ \
91 if (unlikely(__ ## __NAME)) \
92 return __ ## __NAME(regs); \
93 return 0; \
94}
95
96DEBUGGER_BOILERPLATE(debugger)
97DEBUGGER_BOILERPLATE(debugger_ipi)
98DEBUGGER_BOILERPLATE(debugger_bpt)
99DEBUGGER_BOILERPLATE(debugger_sstep)
100DEBUGGER_BOILERPLATE(debugger_iabr_match)
101DEBUGGER_BOILERPLATE(debugger_dabr_match)
102DEBUGGER_BOILERPLATE(debugger_fault_handler)
103
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000104#else
105static inline int debugger(struct pt_regs *regs) { return 0; }
106static inline int debugger_ipi(struct pt_regs *regs) { return 0; }
107static inline int debugger_bpt(struct pt_regs *regs) { return 0; }
108static inline int debugger_sstep(struct pt_regs *regs) { return 0; }
109static inline int debugger_iabr_match(struct pt_regs *regs) { return 0; }
110static inline int debugger_dabr_match(struct pt_regs *regs) { return 0; }
111static inline int debugger_fault_handler(struct pt_regs *regs) { return 0; }
112#endif
113
114extern int set_dabr(unsigned long dabr);
Luis Machadod6a61bf2008-07-24 02:10:41 +1000115extern void do_dabr(struct pt_regs *regs, unsigned long address,
116 unsigned long error_code);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000117extern void print_backtrace(unsigned long *);
118extern void show_regs(struct pt_regs * regs);
119extern void flush_instruction_cache(void);
120extern void hard_reset_now(void);
121extern void poweroff_now(void);
122
123#ifdef CONFIG_6xx
124extern long _get_L2CR(void);
125extern long _get_L3CR(void);
126extern void _set_L2CR(unsigned long);
127extern void _set_L3CR(unsigned long);
128#else
129#define _get_L2CR() 0L
130#define _get_L3CR() 0L
131#define _set_L2CR(val) do { } while(0)
132#define _set_L3CR(val) do { } while(0)
133#endif
134
135extern void via_cuda_init(void);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000136extern void read_rtc_time(void);
137extern void pmac_find_display(void);
138extern void giveup_fpu(struct task_struct *);
Stephen Rothwellcabb5582005-09-30 16:16:52 +1000139extern void disable_kernel_fp(void);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000140extern void enable_kernel_fp(void);
141extern void flush_fp_to_thread(struct task_struct *);
142extern void enable_kernel_altivec(void);
143extern void giveup_altivec(struct task_struct *);
144extern void load_up_altivec(struct task_struct *);
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000145extern int emulate_altivec(struct pt_regs *);
Michael Neuling7c292172008-07-11 16:29:12 +1000146extern void __giveup_vsx(struct task_struct *);
Michael Neulingce48b212008-06-25 14:07:18 +1000147extern void giveup_vsx(struct task_struct *);
Johannes Bergd169d142007-04-28 08:00:03 +1000148extern void enable_kernel_spe(void);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000149extern void giveup_spe(struct task_struct *);
150extern void load_up_spe(struct task_struct *);
151extern int fix_alignment(struct pt_regs *);
David Gibson25c8a782005-10-27 16:27:25 +1000152extern void cvt_fd(float *from, double *to, struct thread_struct *thread);
153extern void cvt_df(double *from, float *to, struct thread_struct *thread);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000154
Paul Mackerras5388fb12006-01-11 22:11:39 +1100155#ifndef CONFIG_SMP
156extern void discard_lazy_cpu_state(void);
157#else
158static inline void discard_lazy_cpu_state(void)
159{
160}
161#endif
162
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000163#ifdef CONFIG_ALTIVEC
164extern void flush_altivec_to_thread(struct task_struct *);
165#else
166static inline void flush_altivec_to_thread(struct task_struct *t)
167{
168}
169#endif
170
Michael Neulingce48b212008-06-25 14:07:18 +1000171#ifdef CONFIG_VSX
172extern void flush_vsx_to_thread(struct task_struct *);
173#else
174static inline void flush_vsx_to_thread(struct task_struct *t)
175{
176}
177#endif
178
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000179#ifdef CONFIG_SPE
180extern void flush_spe_to_thread(struct task_struct *);
181#else
182static inline void flush_spe_to_thread(struct task_struct *t)
183{
184}
185#endif
186
187extern int call_rtas(const char *, int, int, unsigned long *, ...);
188extern void cacheable_memzero(void *p, unsigned int nb);
189extern void *cacheable_memcpy(void *, const void *, unsigned int);
190extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long);
191extern void bad_page_fault(struct pt_regs *, unsigned long, int);
192extern int die(const char *, struct pt_regs *, long);
193extern void _exception(int, struct pt_regs *, int, unsigned long);
Jon Loeliger1d594832008-01-23 12:42:07 -0600194extern void _nmask_and_or_msr(unsigned long nmask, unsigned long or_val);
195
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000196#ifdef CONFIG_BOOKE_WDT
197extern u32 booke_wdt_enabled;
198extern u32 booke_wdt_period;
199#endif /* CONFIG_BOOKE_WDT */
200
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000201struct device_node;
202extern void note_scsi_host(struct device_node *, void *);
203
204extern struct task_struct *__switch_to(struct task_struct *,
205 struct task_struct *);
206#define switch_to(prev, next, last) ((last) = __switch_to((prev), (next)))
207
208struct thread_struct;
209extern struct task_struct *_switch(struct thread_struct *prev,
210 struct thread_struct *next);
211
212extern unsigned int rtas_data;
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000213extern int mem_init_done; /* set on boot once kmalloc can be called */
Michael Ellerman5f25f062008-05-08 14:27:07 +1000214extern int init_bootmem_done; /* set on !NUMA once bootmem is available */
Paul Mackerrascf00a8d2005-10-31 13:07:02 +1100215extern unsigned long memory_limit;
Paul Mackerras49b09852005-11-10 15:53:40 +1100216extern unsigned long klimit;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000217
Stephen Rothwell7b2c3c52007-09-17 14:08:06 +1000218extern void *alloc_maybe_bootmem(size_t size, gfp_t mask);
Stephen Rothwell5669c3c2007-10-02 13:37:53 +1000219extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask);
Stephen Rothwell7b2c3c52007-09-17 14:08:06 +1000220
Paul Mackerras17a63922005-10-20 21:10:09 +1000221extern int powersave_nap; /* set if nap mode can be used in idle loop */
222
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000223/*
224 * Atomic exchange
225 *
226 * Changes the memory location '*ptr' to be val and returns
227 * the previous value stored there.
228 */
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000229static __always_inline unsigned long
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000230__xchg_u32(volatile void *p, unsigned long val)
231{
232 unsigned long prev;
233
234 __asm__ __volatile__(
Anton Blanchard144b9c12006-01-13 15:37:17 +1100235 LWSYNC_ON_SMP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000236"1: lwarx %0,0,%2 \n"
237 PPC405_ERR77(0,%2)
238" stwcx. %3,0,%2 \n\
239 bne- 1b"
240 ISYNC_ON_SMP
Linus Torvaldse2a3d402006-07-08 15:00:28 -0700241 : "=&r" (prev), "+m" (*(volatile unsigned int *)p)
242 : "r" (p), "r" (val)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000243 : "cc", "memory");
244
245 return prev;
246}
247
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700248/*
249 * Atomic exchange
250 *
251 * Changes the memory location '*ptr' to be val and returns
252 * the previous value stored there.
253 */
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000254static __always_inline unsigned long
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700255__xchg_u32_local(volatile void *p, unsigned long val)
256{
257 unsigned long prev;
258
259 __asm__ __volatile__(
260"1: lwarx %0,0,%2 \n"
261 PPC405_ERR77(0,%2)
262" stwcx. %3,0,%2 \n\
263 bne- 1b"
264 : "=&r" (prev), "+m" (*(volatile unsigned int *)p)
265 : "r" (p), "r" (val)
266 : "cc", "memory");
267
268 return prev;
269}
270
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000271#ifdef CONFIG_PPC64
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000272static __always_inline unsigned long
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000273__xchg_u64(volatile void *p, unsigned long val)
274{
275 unsigned long prev;
276
277 __asm__ __volatile__(
Anton Blanchard144b9c12006-01-13 15:37:17 +1100278 LWSYNC_ON_SMP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000279"1: ldarx %0,0,%2 \n"
280 PPC405_ERR77(0,%2)
281" stdcx. %3,0,%2 \n\
282 bne- 1b"
283 ISYNC_ON_SMP
Linus Torvaldse2a3d402006-07-08 15:00:28 -0700284 : "=&r" (prev), "+m" (*(volatile unsigned long *)p)
285 : "r" (p), "r" (val)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000286 : "cc", "memory");
287
288 return prev;
289}
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700290
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000291static __always_inline unsigned long
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700292__xchg_u64_local(volatile void *p, unsigned long val)
293{
294 unsigned long prev;
295
296 __asm__ __volatile__(
297"1: ldarx %0,0,%2 \n"
298 PPC405_ERR77(0,%2)
299" stdcx. %3,0,%2 \n\
300 bne- 1b"
301 : "=&r" (prev), "+m" (*(volatile unsigned long *)p)
302 : "r" (p), "r" (val)
303 : "cc", "memory");
304
305 return prev;
306}
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000307#endif
308
309/*
310 * This function doesn't exist, so you'll get a linker error
311 * if something tries to do an invalid xchg().
312 */
313extern void __xchg_called_with_bad_pointer(void);
314
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000315static __always_inline unsigned long
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000316__xchg(volatile void *ptr, unsigned long x, unsigned int size)
317{
318 switch (size) {
319 case 4:
320 return __xchg_u32(ptr, x);
321#ifdef CONFIG_PPC64
322 case 8:
323 return __xchg_u64(ptr, x);
324#endif
325 }
326 __xchg_called_with_bad_pointer();
327 return x;
328}
329
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000330static __always_inline unsigned long
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700331__xchg_local(volatile void *ptr, unsigned long x, unsigned int size)
332{
333 switch (size) {
334 case 4:
335 return __xchg_u32_local(ptr, x);
336#ifdef CONFIG_PPC64
337 case 8:
338 return __xchg_u64_local(ptr, x);
339#endif
340 }
341 __xchg_called_with_bad_pointer();
342 return x;
343}
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000344#define xchg(ptr,x) \
345 ({ \
346 __typeof__(*(ptr)) _x_ = (x); \
347 (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
348 })
349
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700350#define xchg_local(ptr,x) \
351 ({ \
352 __typeof__(*(ptr)) _x_ = (x); \
353 (__typeof__(*(ptr))) __xchg_local((ptr), \
354 (unsigned long)_x_, sizeof(*(ptr))); \
355 })
356
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000357/*
358 * Compare and exchange - if *p == old, set it to new,
359 * and return the old value of *p.
360 */
361#define __HAVE_ARCH_CMPXCHG 1
362
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000363static __always_inline unsigned long
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000364__cmpxchg_u32(volatile unsigned int *p, unsigned long old, unsigned long new)
365{
366 unsigned int prev;
367
368 __asm__ __volatile__ (
Anton Blanchard144b9c12006-01-13 15:37:17 +1100369 LWSYNC_ON_SMP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000370"1: lwarx %0,0,%2 # __cmpxchg_u32\n\
371 cmpw 0,%0,%3\n\
372 bne- 2f\n"
373 PPC405_ERR77(0,%2)
374" stwcx. %4,0,%2\n\
375 bne- 1b"
376 ISYNC_ON_SMP
377 "\n\
3782:"
Linus Torvaldse2a3d402006-07-08 15:00:28 -0700379 : "=&r" (prev), "+m" (*p)
380 : "r" (p), "r" (old), "r" (new)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000381 : "cc", "memory");
382
383 return prev;
384}
385
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000386static __always_inline unsigned long
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700387__cmpxchg_u32_local(volatile unsigned int *p, unsigned long old,
388 unsigned long new)
389{
390 unsigned int prev;
391
392 __asm__ __volatile__ (
393"1: lwarx %0,0,%2 # __cmpxchg_u32\n\
394 cmpw 0,%0,%3\n\
395 bne- 2f\n"
396 PPC405_ERR77(0,%2)
397" stwcx. %4,0,%2\n\
398 bne- 1b"
399 "\n\
4002:"
401 : "=&r" (prev), "+m" (*p)
402 : "r" (p), "r" (old), "r" (new)
403 : "cc", "memory");
404
405 return prev;
406}
407
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000408#ifdef CONFIG_PPC64
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000409static __always_inline unsigned long
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100410__cmpxchg_u64(volatile unsigned long *p, unsigned long old, unsigned long new)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000411{
412 unsigned long prev;
413
414 __asm__ __volatile__ (
Anton Blanchard144b9c12006-01-13 15:37:17 +1100415 LWSYNC_ON_SMP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000416"1: ldarx %0,0,%2 # __cmpxchg_u64\n\
417 cmpd 0,%0,%3\n\
418 bne- 2f\n\
419 stdcx. %4,0,%2\n\
420 bne- 1b"
421 ISYNC_ON_SMP
422 "\n\
4232:"
Linus Torvaldse2a3d402006-07-08 15:00:28 -0700424 : "=&r" (prev), "+m" (*p)
425 : "r" (p), "r" (old), "r" (new)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000426 : "cc", "memory");
427
428 return prev;
429}
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700430
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000431static __always_inline unsigned long
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700432__cmpxchg_u64_local(volatile unsigned long *p, unsigned long old,
433 unsigned long new)
434{
435 unsigned long prev;
436
437 __asm__ __volatile__ (
438"1: ldarx %0,0,%2 # __cmpxchg_u64\n\
439 cmpd 0,%0,%3\n\
440 bne- 2f\n\
441 stdcx. %4,0,%2\n\
442 bne- 1b"
443 "\n\
4442:"
445 : "=&r" (prev), "+m" (*p)
446 : "r" (p), "r" (old), "r" (new)
447 : "cc", "memory");
448
449 return prev;
450}
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000451#endif
452
453/* This function doesn't exist, so you'll get a linker error
454 if something tries to do an invalid cmpxchg(). */
455extern void __cmpxchg_called_with_bad_pointer(void);
456
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000457static __always_inline unsigned long
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000458__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
459 unsigned int size)
460{
461 switch (size) {
462 case 4:
463 return __cmpxchg_u32(ptr, old, new);
464#ifdef CONFIG_PPC64
465 case 8:
466 return __cmpxchg_u64(ptr, old, new);
467#endif
468 }
469 __cmpxchg_called_with_bad_pointer();
470 return old;
471}
472
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000473static __always_inline unsigned long
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700474__cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
475 unsigned int size)
476{
477 switch (size) {
478 case 4:
479 return __cmpxchg_u32_local(ptr, old, new);
480#ifdef CONFIG_PPC64
481 case 8:
482 return __cmpxchg_u64_local(ptr, old, new);
483#endif
484 }
485 __cmpxchg_called_with_bad_pointer();
486 return old;
487}
488
Mathieu Desnoyersf9c46502008-02-07 00:16:10 -0800489#define cmpxchg(ptr, o, n) \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000490 ({ \
491 __typeof__(*(ptr)) _o_ = (o); \
492 __typeof__(*(ptr)) _n_ = (n); \
493 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
494 (unsigned long)_n_, sizeof(*(ptr))); \
495 })
496
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700497
Mathieu Desnoyersf9c46502008-02-07 00:16:10 -0800498#define cmpxchg_local(ptr, o, n) \
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700499 ({ \
500 __typeof__(*(ptr)) _o_ = (o); \
501 __typeof__(*(ptr)) _n_ = (n); \
502 (__typeof__(*(ptr))) __cmpxchg_local((ptr), (unsigned long)_o_, \
503 (unsigned long)_n_, sizeof(*(ptr))); \
504 })
505
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000506#ifdef CONFIG_PPC64
507/*
508 * We handle most unaligned accesses in hardware. On the other hand
509 * unaligned DMA can be very expensive on some ppc64 IO chips (it does
510 * powers of 2 writes until it reaches sufficient alignment).
511 *
512 * Based on this we disable the IP header alignment in network drivers.
Anton Blanchard025be812006-03-31 02:27:06 -0800513 * We also modify NET_SKB_PAD to be a cacheline in size, thus maintaining
514 * cacheline alignment of buffers.
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000515 */
Anton Blanchard025be812006-03-31 02:27:06 -0800516#define NET_IP_ALIGN 0
517#define NET_SKB_PAD L1_CACHE_BYTES
Mathieu Desnoyersf9c46502008-02-07 00:16:10 -0800518
519#define cmpxchg64(ptr, o, n) \
520 ({ \
521 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
522 cmpxchg((ptr), (o), (n)); \
523 })
524#define cmpxchg64_local(ptr, o, n) \
525 ({ \
526 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
527 cmpxchg_local((ptr), (o), (n)); \
528 })
529#else
530#include <asm-generic/cmpxchg-local.h>
531#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000532#endif
533
534#define arch_align_stack(x) (x)
535
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000536/* Used in very early kernel initialization. */
Stephen Rothwellcabb5582005-09-30 16:16:52 +1000537extern unsigned long reloc_offset(void);
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000538extern unsigned long add_reloc_offset(unsigned long);
539extern void reloc_got2(unsigned long);
540
541#define PTRRELOC(x) ((typeof(x)) add_reloc_offset((unsigned long)(x)))
Stephen Rothwellcabb5582005-09-30 16:16:52 +1000542
Paul Mackerrasc6622f62006-02-24 10:06:59 +1100543#ifdef CONFIG_VIRT_CPU_ACCOUNTING
544extern void account_system_vtime(struct task_struct *);
545#endif
546
Michael Ellerman94a38072007-06-20 10:54:19 +1000547extern struct dentry *powerpc_debugfs_root;
548
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000549#endif /* __KERNEL__ */
Stephen Rothwellbbeb3f42005-09-27 13:51:59 +1000550#endif /* _ASM_POWERPC_SYSTEM_H */