blob: 145b70f6d22ba33125459e55093310fc51abd5b4 [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 *
26 * We have to use the sync instructions for mb(), since lwsync doesn't
27 * order loads with respect to previous stores. Lwsync is fine for
Andy Fleminge0da0da2006-10-27 14:31:07 -050028 * rmb(), though. Note that rmb() actually uses a sync on 32-bit
29 * architectures.
Paul Mackerras14cf11a2005-09-26 16:04:21 +100030 *
31 * For wmb(), we use sync since wmb is used in drivers to order
32 * stores to system memory with respect to writes to the device.
Nick Piggin74f06092008-05-22 00:12:31 +100033 * However, smp_wmb() can be a lighter-weight lwsync or eieio barrier
34 * on SMP since it is only used to order updates to system memory.
Paul Mackerras14cf11a2005-09-26 16:04:21 +100035 */
36#define mb() __asm__ __volatile__ ("sync" : : : "memory")
Nick Piggin598056d2008-05-22 00:10:56 +100037#define rmb() __asm__ __volatile__ ("sync" : : : "memory")
Paul Mackerras14cf11a2005-09-26 16:04:21 +100038#define wmb() __asm__ __volatile__ ("sync" : : : "memory")
39#define read_barrier_depends() do { } while(0)
40
41#define set_mb(var, value) do { var = value; mb(); } while (0)
Paul Mackerras14cf11a2005-09-26 16:04:21 +100042
Arnd Bergmann88ced032005-12-16 22:43:46 +010043#ifdef __KERNEL__
Olaf Hering4f9a58d2007-10-16 23:30:12 -070044#define AT_VECTOR_SIZE_ARCH 6 /* entries in ARCH_DLINFO */
Paul Mackerras14cf11a2005-09-26 16:04:21 +100045#ifdef CONFIG_SMP
Nick Piggin74f06092008-05-22 00:12:31 +100046
47#ifdef __SUBARCH_HAS_LWSYNC
48# define SMPWMB lwsync
49#else
50# define SMPWMB eieio
51#endif
52
Paul Mackerras14cf11a2005-09-26 16:04:21 +100053#define smp_mb() mb()
54#define smp_rmb() rmb()
Nick Piggin74f06092008-05-22 00:12:31 +100055#define smp_wmb() __asm__ __volatile__ (__stringify(SMPWMB) : : :"memory")
Paul Mackerras14cf11a2005-09-26 16:04:21 +100056#define smp_read_barrier_depends() read_barrier_depends()
57#else
58#define smp_mb() barrier()
59#define smp_rmb() barrier()
60#define smp_wmb() barrier()
61#define smp_read_barrier_depends() do { } while(0)
62#endif /* CONFIG_SMP */
63
Nathan Lynch5db9fa92006-08-22 20:36:05 -050064/*
65 * This is a barrier which prevents following instructions from being
66 * started until the value of the argument x is known. For example, if
67 * x is a variable loaded from memory, this prevents following
68 * instructions from being executed until the load has been performed.
69 */
70#define data_barrier(x) \
71 asm volatile("twi 0,%0,0; isync" : : "r" (x) : "memory");
72
Paul Mackerras14cf11a2005-09-26 16:04:21 +100073struct task_struct;
74struct pt_regs;
75
Olof Johansson7dbb9222008-01-31 14:34:47 +110076#if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
Paul Mackerras14cf11a2005-09-26 16:04:21 +100077
78extern int (*__debugger)(struct pt_regs *regs);
79extern int (*__debugger_ipi)(struct pt_regs *regs);
80extern int (*__debugger_bpt)(struct pt_regs *regs);
81extern int (*__debugger_sstep)(struct pt_regs *regs);
82extern int (*__debugger_iabr_match)(struct pt_regs *regs);
83extern int (*__debugger_dabr_match)(struct pt_regs *regs);
84extern int (*__debugger_fault_handler)(struct pt_regs *regs);
85
86#define DEBUGGER_BOILERPLATE(__NAME) \
87static inline int __NAME(struct pt_regs *regs) \
88{ \
89 if (unlikely(__ ## __NAME)) \
90 return __ ## __NAME(regs); \
91 return 0; \
92}
93
94DEBUGGER_BOILERPLATE(debugger)
95DEBUGGER_BOILERPLATE(debugger_ipi)
96DEBUGGER_BOILERPLATE(debugger_bpt)
97DEBUGGER_BOILERPLATE(debugger_sstep)
98DEBUGGER_BOILERPLATE(debugger_iabr_match)
99DEBUGGER_BOILERPLATE(debugger_dabr_match)
100DEBUGGER_BOILERPLATE(debugger_fault_handler)
101
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000102#else
103static inline int debugger(struct pt_regs *regs) { return 0; }
104static inline int debugger_ipi(struct pt_regs *regs) { return 0; }
105static inline int debugger_bpt(struct pt_regs *regs) { return 0; }
106static inline int debugger_sstep(struct pt_regs *regs) { return 0; }
107static inline int debugger_iabr_match(struct pt_regs *regs) { return 0; }
108static inline int debugger_dabr_match(struct pt_regs *regs) { return 0; }
109static inline int debugger_fault_handler(struct pt_regs *regs) { return 0; }
110#endif
111
112extern int set_dabr(unsigned long dabr);
113extern void print_backtrace(unsigned long *);
114extern void show_regs(struct pt_regs * regs);
115extern void flush_instruction_cache(void);
116extern void hard_reset_now(void);
117extern void poweroff_now(void);
118
119#ifdef CONFIG_6xx
120extern long _get_L2CR(void);
121extern long _get_L3CR(void);
122extern void _set_L2CR(unsigned long);
123extern void _set_L3CR(unsigned long);
124#else
125#define _get_L2CR() 0L
126#define _get_L3CR() 0L
127#define _set_L2CR(val) do { } while(0)
128#define _set_L3CR(val) do { } while(0)
129#endif
130
131extern void via_cuda_init(void);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000132extern void read_rtc_time(void);
133extern void pmac_find_display(void);
134extern void giveup_fpu(struct task_struct *);
Stephen Rothwellcabb5582005-09-30 16:16:52 +1000135extern void disable_kernel_fp(void);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000136extern void enable_kernel_fp(void);
137extern void flush_fp_to_thread(struct task_struct *);
138extern void enable_kernel_altivec(void);
139extern void giveup_altivec(struct task_struct *);
140extern void load_up_altivec(struct task_struct *);
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000141extern int emulate_altivec(struct pt_regs *);
Johannes Bergd169d142007-04-28 08:00:03 +1000142extern void enable_kernel_spe(void);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000143extern void giveup_spe(struct task_struct *);
144extern void load_up_spe(struct task_struct *);
145extern int fix_alignment(struct pt_regs *);
David Gibson25c8a782005-10-27 16:27:25 +1000146extern void cvt_fd(float *from, double *to, struct thread_struct *thread);
147extern void cvt_df(double *from, float *to, struct thread_struct *thread);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000148
Paul Mackerras5388fb12006-01-11 22:11:39 +1100149#ifndef CONFIG_SMP
150extern void discard_lazy_cpu_state(void);
151#else
152static inline void discard_lazy_cpu_state(void)
153{
154}
155#endif
156
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000157#ifdef CONFIG_ALTIVEC
158extern void flush_altivec_to_thread(struct task_struct *);
159#else
160static inline void flush_altivec_to_thread(struct task_struct *t)
161{
162}
163#endif
164
165#ifdef CONFIG_SPE
166extern void flush_spe_to_thread(struct task_struct *);
167#else
168static inline void flush_spe_to_thread(struct task_struct *t)
169{
170}
171#endif
172
173extern int call_rtas(const char *, int, int, unsigned long *, ...);
174extern void cacheable_memzero(void *p, unsigned int nb);
175extern void *cacheable_memcpy(void *, const void *, unsigned int);
176extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long);
177extern void bad_page_fault(struct pt_regs *, unsigned long, int);
178extern int die(const char *, struct pt_regs *, long);
179extern void _exception(int, struct pt_regs *, int, unsigned long);
Jon Loeliger1d594832008-01-23 12:42:07 -0600180extern void _nmask_and_or_msr(unsigned long nmask, unsigned long or_val);
181
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000182#ifdef CONFIG_BOOKE_WDT
183extern u32 booke_wdt_enabled;
184extern u32 booke_wdt_period;
185#endif /* CONFIG_BOOKE_WDT */
186
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000187struct device_node;
188extern void note_scsi_host(struct device_node *, void *);
189
190extern struct task_struct *__switch_to(struct task_struct *,
191 struct task_struct *);
192#define switch_to(prev, next, last) ((last) = __switch_to((prev), (next)))
193
194struct thread_struct;
195extern struct task_struct *_switch(struct thread_struct *prev,
196 struct thread_struct *next);
197
198extern unsigned int rtas_data;
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000199extern int mem_init_done; /* set on boot once kmalloc can be called */
Michael Ellerman5f25f0652008-05-08 14:27:07 +1000200extern int init_bootmem_done; /* set on !NUMA once bootmem is available */
Paul Mackerrascf00a8d2005-10-31 13:07:02 +1100201extern unsigned long memory_limit;
Paul Mackerras49b09852005-11-10 15:53:40 +1100202extern unsigned long klimit;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000203
Stephen Rothwell7b2c3c52007-09-17 14:08:06 +1000204extern void *alloc_maybe_bootmem(size_t size, gfp_t mask);
Stephen Rothwell5669c3c2007-10-02 13:37:53 +1000205extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask);
Stephen Rothwell7b2c3c52007-09-17 14:08:06 +1000206
Paul Mackerras17a63922005-10-20 21:10:09 +1000207extern int powersave_nap; /* set if nap mode can be used in idle loop */
208
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000209/*
210 * Atomic exchange
211 *
212 * Changes the memory location '*ptr' to be val and returns
213 * the previous value stored there.
214 */
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000215static __always_inline unsigned long
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000216__xchg_u32(volatile void *p, unsigned long val)
217{
218 unsigned long prev;
219
220 __asm__ __volatile__(
Anton Blanchard144b9c132006-01-13 15:37:17 +1100221 LWSYNC_ON_SMP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000222"1: lwarx %0,0,%2 \n"
223 PPC405_ERR77(0,%2)
224" stwcx. %3,0,%2 \n\
225 bne- 1b"
226 ISYNC_ON_SMP
Linus Torvaldse2a3d402006-07-08 15:00:28 -0700227 : "=&r" (prev), "+m" (*(volatile unsigned int *)p)
228 : "r" (p), "r" (val)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000229 : "cc", "memory");
230
231 return prev;
232}
233
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700234/*
235 * Atomic exchange
236 *
237 * Changes the memory location '*ptr' to be val and returns
238 * the previous value stored there.
239 */
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000240static __always_inline unsigned long
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700241__xchg_u32_local(volatile void *p, unsigned long val)
242{
243 unsigned long prev;
244
245 __asm__ __volatile__(
246"1: lwarx %0,0,%2 \n"
247 PPC405_ERR77(0,%2)
248" stwcx. %3,0,%2 \n\
249 bne- 1b"
250 : "=&r" (prev), "+m" (*(volatile unsigned int *)p)
251 : "r" (p), "r" (val)
252 : "cc", "memory");
253
254 return prev;
255}
256
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000257#ifdef CONFIG_PPC64
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000258static __always_inline unsigned long
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000259__xchg_u64(volatile void *p, unsigned long val)
260{
261 unsigned long prev;
262
263 __asm__ __volatile__(
Anton Blanchard144b9c132006-01-13 15:37:17 +1100264 LWSYNC_ON_SMP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000265"1: ldarx %0,0,%2 \n"
266 PPC405_ERR77(0,%2)
267" stdcx. %3,0,%2 \n\
268 bne- 1b"
269 ISYNC_ON_SMP
Linus Torvaldse2a3d402006-07-08 15:00:28 -0700270 : "=&r" (prev), "+m" (*(volatile unsigned long *)p)
271 : "r" (p), "r" (val)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000272 : "cc", "memory");
273
274 return prev;
275}
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700276
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000277static __always_inline unsigned long
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700278__xchg_u64_local(volatile void *p, unsigned long val)
279{
280 unsigned long prev;
281
282 __asm__ __volatile__(
283"1: ldarx %0,0,%2 \n"
284 PPC405_ERR77(0,%2)
285" stdcx. %3,0,%2 \n\
286 bne- 1b"
287 : "=&r" (prev), "+m" (*(volatile unsigned long *)p)
288 : "r" (p), "r" (val)
289 : "cc", "memory");
290
291 return prev;
292}
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000293#endif
294
295/*
296 * This function doesn't exist, so you'll get a linker error
297 * if something tries to do an invalid xchg().
298 */
299extern void __xchg_called_with_bad_pointer(void);
300
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000301static __always_inline unsigned long
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000302__xchg(volatile void *ptr, unsigned long x, unsigned int size)
303{
304 switch (size) {
305 case 4:
306 return __xchg_u32(ptr, x);
307#ifdef CONFIG_PPC64
308 case 8:
309 return __xchg_u64(ptr, x);
310#endif
311 }
312 __xchg_called_with_bad_pointer();
313 return x;
314}
315
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000316static __always_inline unsigned long
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700317__xchg_local(volatile void *ptr, unsigned long x, unsigned int size)
318{
319 switch (size) {
320 case 4:
321 return __xchg_u32_local(ptr, x);
322#ifdef CONFIG_PPC64
323 case 8:
324 return __xchg_u64_local(ptr, x);
325#endif
326 }
327 __xchg_called_with_bad_pointer();
328 return x;
329}
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000330#define xchg(ptr,x) \
331 ({ \
332 __typeof__(*(ptr)) _x_ = (x); \
333 (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
334 })
335
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700336#define xchg_local(ptr,x) \
337 ({ \
338 __typeof__(*(ptr)) _x_ = (x); \
339 (__typeof__(*(ptr))) __xchg_local((ptr), \
340 (unsigned long)_x_, sizeof(*(ptr))); \
341 })
342
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000343/*
344 * Compare and exchange - if *p == old, set it to new,
345 * and return the old value of *p.
346 */
347#define __HAVE_ARCH_CMPXCHG 1
348
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000349static __always_inline unsigned long
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000350__cmpxchg_u32(volatile unsigned int *p, unsigned long old, unsigned long new)
351{
352 unsigned int prev;
353
354 __asm__ __volatile__ (
Anton Blanchard144b9c132006-01-13 15:37:17 +1100355 LWSYNC_ON_SMP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000356"1: lwarx %0,0,%2 # __cmpxchg_u32\n\
357 cmpw 0,%0,%3\n\
358 bne- 2f\n"
359 PPC405_ERR77(0,%2)
360" stwcx. %4,0,%2\n\
361 bne- 1b"
362 ISYNC_ON_SMP
363 "\n\
3642:"
Linus Torvaldse2a3d402006-07-08 15:00:28 -0700365 : "=&r" (prev), "+m" (*p)
366 : "r" (p), "r" (old), "r" (new)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000367 : "cc", "memory");
368
369 return prev;
370}
371
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000372static __always_inline unsigned long
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700373__cmpxchg_u32_local(volatile unsigned int *p, unsigned long old,
374 unsigned long new)
375{
376 unsigned int prev;
377
378 __asm__ __volatile__ (
379"1: lwarx %0,0,%2 # __cmpxchg_u32\n\
380 cmpw 0,%0,%3\n\
381 bne- 2f\n"
382 PPC405_ERR77(0,%2)
383" stwcx. %4,0,%2\n\
384 bne- 1b"
385 "\n\
3862:"
387 : "=&r" (prev), "+m" (*p)
388 : "r" (p), "r" (old), "r" (new)
389 : "cc", "memory");
390
391 return prev;
392}
393
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000394#ifdef CONFIG_PPC64
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000395static __always_inline unsigned long
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100396__cmpxchg_u64(volatile unsigned long *p, unsigned long old, unsigned long new)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000397{
398 unsigned long prev;
399
400 __asm__ __volatile__ (
Anton Blanchard144b9c132006-01-13 15:37:17 +1100401 LWSYNC_ON_SMP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000402"1: ldarx %0,0,%2 # __cmpxchg_u64\n\
403 cmpd 0,%0,%3\n\
404 bne- 2f\n\
405 stdcx. %4,0,%2\n\
406 bne- 1b"
407 ISYNC_ON_SMP
408 "\n\
4092:"
Linus Torvaldse2a3d402006-07-08 15:00:28 -0700410 : "=&r" (prev), "+m" (*p)
411 : "r" (p), "r" (old), "r" (new)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000412 : "cc", "memory");
413
414 return prev;
415}
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700416
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000417static __always_inline unsigned long
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700418__cmpxchg_u64_local(volatile unsigned long *p, unsigned long old,
419 unsigned long new)
420{
421 unsigned long prev;
422
423 __asm__ __volatile__ (
424"1: ldarx %0,0,%2 # __cmpxchg_u64\n\
425 cmpd 0,%0,%3\n\
426 bne- 2f\n\
427 stdcx. %4,0,%2\n\
428 bne- 1b"
429 "\n\
4302:"
431 : "=&r" (prev), "+m" (*p)
432 : "r" (p), "r" (old), "r" (new)
433 : "cc", "memory");
434
435 return prev;
436}
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000437#endif
438
439/* This function doesn't exist, so you'll get a linker error
440 if something tries to do an invalid cmpxchg(). */
441extern void __cmpxchg_called_with_bad_pointer(void);
442
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000443static __always_inline unsigned long
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000444__cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
445 unsigned int size)
446{
447 switch (size) {
448 case 4:
449 return __cmpxchg_u32(ptr, old, new);
450#ifdef CONFIG_PPC64
451 case 8:
452 return __cmpxchg_u64(ptr, old, new);
453#endif
454 }
455 __cmpxchg_called_with_bad_pointer();
456 return old;
457}
458
Paul Mackerrasdd18434f2008-04-28 14:44:08 +1000459static __always_inline unsigned long
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700460__cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new,
461 unsigned int size)
462{
463 switch (size) {
464 case 4:
465 return __cmpxchg_u32_local(ptr, old, new);
466#ifdef CONFIG_PPC64
467 case 8:
468 return __cmpxchg_u64_local(ptr, old, new);
469#endif
470 }
471 __cmpxchg_called_with_bad_pointer();
472 return old;
473}
474
Mathieu Desnoyersf9c46502008-02-07 00:16:10 -0800475#define cmpxchg(ptr, o, n) \
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000476 ({ \
477 __typeof__(*(ptr)) _o_ = (o); \
478 __typeof__(*(ptr)) _n_ = (n); \
479 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
480 (unsigned long)_n_, sizeof(*(ptr))); \
481 })
482
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700483
Mathieu Desnoyersf9c46502008-02-07 00:16:10 -0800484#define cmpxchg_local(ptr, o, n) \
Mathieu Desnoyersf46e4772007-05-08 00:34:27 -0700485 ({ \
486 __typeof__(*(ptr)) _o_ = (o); \
487 __typeof__(*(ptr)) _n_ = (n); \
488 (__typeof__(*(ptr))) __cmpxchg_local((ptr), (unsigned long)_o_, \
489 (unsigned long)_n_, sizeof(*(ptr))); \
490 })
491
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000492#ifdef CONFIG_PPC64
493/*
494 * We handle most unaligned accesses in hardware. On the other hand
495 * unaligned DMA can be very expensive on some ppc64 IO chips (it does
496 * powers of 2 writes until it reaches sufficient alignment).
497 *
498 * Based on this we disable the IP header alignment in network drivers.
Anton Blanchard025be812006-03-31 02:27:06 -0800499 * We also modify NET_SKB_PAD to be a cacheline in size, thus maintaining
500 * cacheline alignment of buffers.
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000501 */
Anton Blanchard025be812006-03-31 02:27:06 -0800502#define NET_IP_ALIGN 0
503#define NET_SKB_PAD L1_CACHE_BYTES
Mathieu Desnoyersf9c46502008-02-07 00:16:10 -0800504
505#define cmpxchg64(ptr, o, n) \
506 ({ \
507 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
508 cmpxchg((ptr), (o), (n)); \
509 })
510#define cmpxchg64_local(ptr, o, n) \
511 ({ \
512 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
513 cmpxchg_local((ptr), (o), (n)); \
514 })
515#else
516#include <asm-generic/cmpxchg-local.h>
517#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000518#endif
519
520#define arch_align_stack(x) (x)
521
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000522/* Used in very early kernel initialization. */
Stephen Rothwellcabb5582005-09-30 16:16:52 +1000523extern unsigned long reloc_offset(void);
Paul Mackerras9b6b5632005-10-06 12:06:20 +1000524extern unsigned long add_reloc_offset(unsigned long);
525extern void reloc_got2(unsigned long);
526
527#define PTRRELOC(x) ((typeof(x)) add_reloc_offset((unsigned long)(x)))
Stephen Rothwellcabb5582005-09-30 16:16:52 +1000528
Michael Ellermanc87ef112005-11-03 17:57:53 +1100529static inline void create_instruction(unsigned long addr, unsigned int instr)
530{
531 unsigned int *p;
532 p = (unsigned int *)addr;
533 *p = instr;
534 asm ("dcbst 0, %0; sync; icbi 0,%0; sync; isync" : : "r" (p));
535}
536
537/* Flags for create_branch:
538 * "b" == create_branch(addr, target, 0);
539 * "ba" == create_branch(addr, target, BRANCH_ABSOLUTE);
540 * "bl" == create_branch(addr, target, BRANCH_SET_LINK);
541 * "bla" == create_branch(addr, target, BRANCH_ABSOLUTE | BRANCH_SET_LINK);
542 */
543#define BRANCH_SET_LINK 0x1
544#define BRANCH_ABSOLUTE 0x2
545
546static inline void create_branch(unsigned long addr,
547 unsigned long target, int flags)
548{
549 unsigned int instruction;
550
551 if (! (flags & BRANCH_ABSOLUTE))
552 target = target - addr;
553
554 /* Mask out the flags and target, so they don't step on each other. */
555 instruction = 0x48000000 | (flags & 0x3) | (target & 0x03FFFFFC);
556
557 create_instruction(addr, instruction);
558}
559
560static inline void create_function_call(unsigned long addr, void * func)
561{
562 unsigned long func_addr;
563
564#ifdef CONFIG_PPC64
565 /*
566 * On PPC64 the function pointer actually points to the function's
567 * descriptor. The first entry in the descriptor is the address
568 * of the function text.
569 */
570 func_addr = *(unsigned long *)func;
571#else
572 func_addr = (unsigned long)func;
573#endif
574 create_branch(addr, func_addr, BRANCH_SET_LINK);
575}
576
Paul Mackerrasc6622f62006-02-24 10:06:59 +1100577#ifdef CONFIG_VIRT_CPU_ACCOUNTING
578extern void account_system_vtime(struct task_struct *);
579#endif
580
Michael Ellerman94a38072007-06-20 10:54:19 +1000581extern struct dentry *powerpc_debugfs_root;
582
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000583#endif /* __KERNEL__ */
Stephen Rothwellbbeb3f42005-09-27 13:51:59 +1000584#endif /* _ASM_POWERPC_SYSTEM_H */