Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu> |
| 3 | */ |
Stephen Rothwell | bbeb3f4 | 2005-09-27 13:51:59 +1000 | [diff] [blame] | 4 | #ifndef _ASM_POWERPC_SYSTEM_H |
| 5 | #define _ASM_POWERPC_SYSTEM_H |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 6 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 7 | #include <linux/kernel.h> |
Paul Mackerras | 14b3ca4 | 2008-04-20 17:57:10 +1000 | [diff] [blame] | 8 | #include <linux/irqflags.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 9 | |
| 10 | #include <asm/hw_irq.h> |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 11 | |
| 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 Fleming | e0da0da | 2006-10-27 14:31:07 -0500 | [diff] [blame] | 28 | * rmb(), though. Note that rmb() actually uses a sync on 32-bit |
| 29 | * architectures. |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 30 | * |
| 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 Piggin | 74f0609 | 2008-05-22 00:12:31 +1000 | [diff] [blame] | 33 | * 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 Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 35 | */ |
| 36 | #define mb() __asm__ __volatile__ ("sync" : : : "memory") |
Nick Piggin | 598056d | 2008-05-22 00:10:56 +1000 | [diff] [blame] | 37 | #define rmb() __asm__ __volatile__ ("sync" : : : "memory") |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 38 | #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 Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 42 | |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 43 | #ifdef __KERNEL__ |
Olaf Hering | 4f9a58d | 2007-10-16 23:30:12 -0700 | [diff] [blame] | 44 | #define AT_VECTOR_SIZE_ARCH 6 /* entries in ARCH_DLINFO */ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 45 | #ifdef CONFIG_SMP |
Nick Piggin | 74f0609 | 2008-05-22 00:12:31 +1000 | [diff] [blame] | 46 | |
| 47 | #ifdef __SUBARCH_HAS_LWSYNC |
| 48 | # define SMPWMB lwsync |
| 49 | #else |
| 50 | # define SMPWMB eieio |
| 51 | #endif |
| 52 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 53 | #define smp_mb() mb() |
| 54 | #define smp_rmb() rmb() |
Nick Piggin | 74f0609 | 2008-05-22 00:12:31 +1000 | [diff] [blame] | 55 | #define smp_wmb() __asm__ __volatile__ (__stringify(SMPWMB) : : :"memory") |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 56 | #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 Lynch | 5db9fa9 | 2006-08-22 20:36:05 -0500 | [diff] [blame] | 64 | /* |
| 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 Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 73 | struct task_struct; |
| 74 | struct pt_regs; |
| 75 | |
Olof Johansson | 7dbb922 | 2008-01-31 14:34:47 +1100 | [diff] [blame] | 76 | #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 77 | |
| 78 | extern int (*__debugger)(struct pt_regs *regs); |
| 79 | extern int (*__debugger_ipi)(struct pt_regs *regs); |
| 80 | extern int (*__debugger_bpt)(struct pt_regs *regs); |
| 81 | extern int (*__debugger_sstep)(struct pt_regs *regs); |
| 82 | extern int (*__debugger_iabr_match)(struct pt_regs *regs); |
| 83 | extern int (*__debugger_dabr_match)(struct pt_regs *regs); |
| 84 | extern int (*__debugger_fault_handler)(struct pt_regs *regs); |
| 85 | |
| 86 | #define DEBUGGER_BOILERPLATE(__NAME) \ |
| 87 | static inline int __NAME(struct pt_regs *regs) \ |
| 88 | { \ |
| 89 | if (unlikely(__ ## __NAME)) \ |
| 90 | return __ ## __NAME(regs); \ |
| 91 | return 0; \ |
| 92 | } |
| 93 | |
| 94 | DEBUGGER_BOILERPLATE(debugger) |
| 95 | DEBUGGER_BOILERPLATE(debugger_ipi) |
| 96 | DEBUGGER_BOILERPLATE(debugger_bpt) |
| 97 | DEBUGGER_BOILERPLATE(debugger_sstep) |
| 98 | DEBUGGER_BOILERPLATE(debugger_iabr_match) |
| 99 | DEBUGGER_BOILERPLATE(debugger_dabr_match) |
| 100 | DEBUGGER_BOILERPLATE(debugger_fault_handler) |
| 101 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 102 | #else |
| 103 | static inline int debugger(struct pt_regs *regs) { return 0; } |
| 104 | static inline int debugger_ipi(struct pt_regs *regs) { return 0; } |
| 105 | static inline int debugger_bpt(struct pt_regs *regs) { return 0; } |
| 106 | static inline int debugger_sstep(struct pt_regs *regs) { return 0; } |
| 107 | static inline int debugger_iabr_match(struct pt_regs *regs) { return 0; } |
| 108 | static inline int debugger_dabr_match(struct pt_regs *regs) { return 0; } |
| 109 | static inline int debugger_fault_handler(struct pt_regs *regs) { return 0; } |
| 110 | #endif |
| 111 | |
| 112 | extern int set_dabr(unsigned long dabr); |
Luis Machado | d6a61bf | 2008-07-24 02:10:41 +1000 | [diff] [blame] | 113 | extern void do_dabr(struct pt_regs *regs, unsigned long address, |
| 114 | unsigned long error_code); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 115 | extern void print_backtrace(unsigned long *); |
| 116 | extern void show_regs(struct pt_regs * regs); |
| 117 | extern void flush_instruction_cache(void); |
| 118 | extern void hard_reset_now(void); |
| 119 | extern void poweroff_now(void); |
| 120 | |
| 121 | #ifdef CONFIG_6xx |
| 122 | extern long _get_L2CR(void); |
| 123 | extern long _get_L3CR(void); |
| 124 | extern void _set_L2CR(unsigned long); |
| 125 | extern void _set_L3CR(unsigned long); |
| 126 | #else |
| 127 | #define _get_L2CR() 0L |
| 128 | #define _get_L3CR() 0L |
| 129 | #define _set_L2CR(val) do { } while(0) |
| 130 | #define _set_L3CR(val) do { } while(0) |
| 131 | #endif |
| 132 | |
| 133 | extern void via_cuda_init(void); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 134 | extern void read_rtc_time(void); |
| 135 | extern void pmac_find_display(void); |
| 136 | extern void giveup_fpu(struct task_struct *); |
Stephen Rothwell | cabb558 | 2005-09-30 16:16:52 +1000 | [diff] [blame] | 137 | extern void disable_kernel_fp(void); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 138 | extern void enable_kernel_fp(void); |
| 139 | extern void flush_fp_to_thread(struct task_struct *); |
| 140 | extern void enable_kernel_altivec(void); |
| 141 | extern void giveup_altivec(struct task_struct *); |
| 142 | extern void load_up_altivec(struct task_struct *); |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 143 | extern int emulate_altivec(struct pt_regs *); |
Michael Neuling | 7c29217 | 2008-07-11 16:29:12 +1000 | [diff] [blame] | 144 | extern void __giveup_vsx(struct task_struct *); |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 145 | extern void giveup_vsx(struct task_struct *); |
Johannes Berg | d169d14 | 2007-04-28 08:00:03 +1000 | [diff] [blame] | 146 | extern void enable_kernel_spe(void); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 147 | extern void giveup_spe(struct task_struct *); |
| 148 | extern void load_up_spe(struct task_struct *); |
| 149 | extern int fix_alignment(struct pt_regs *); |
David Gibson | 25c8a78 | 2005-10-27 16:27:25 +1000 | [diff] [blame] | 150 | extern void cvt_fd(float *from, double *to, struct thread_struct *thread); |
| 151 | extern void cvt_df(double *from, float *to, struct thread_struct *thread); |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 152 | |
Paul Mackerras | 5388fb1 | 2006-01-11 22:11:39 +1100 | [diff] [blame] | 153 | #ifndef CONFIG_SMP |
| 154 | extern void discard_lazy_cpu_state(void); |
| 155 | #else |
| 156 | static inline void discard_lazy_cpu_state(void) |
| 157 | { |
| 158 | } |
| 159 | #endif |
| 160 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 161 | #ifdef CONFIG_ALTIVEC |
| 162 | extern void flush_altivec_to_thread(struct task_struct *); |
| 163 | #else |
| 164 | static inline void flush_altivec_to_thread(struct task_struct *t) |
| 165 | { |
| 166 | } |
| 167 | #endif |
| 168 | |
Michael Neuling | ce48b21 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 169 | #ifdef CONFIG_VSX |
| 170 | extern void flush_vsx_to_thread(struct task_struct *); |
| 171 | #else |
| 172 | static inline void flush_vsx_to_thread(struct task_struct *t) |
| 173 | { |
| 174 | } |
| 175 | #endif |
| 176 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 177 | #ifdef CONFIG_SPE |
| 178 | extern void flush_spe_to_thread(struct task_struct *); |
| 179 | #else |
| 180 | static inline void flush_spe_to_thread(struct task_struct *t) |
| 181 | { |
| 182 | } |
| 183 | #endif |
| 184 | |
| 185 | extern int call_rtas(const char *, int, int, unsigned long *, ...); |
| 186 | extern void cacheable_memzero(void *p, unsigned int nb); |
| 187 | extern void *cacheable_memcpy(void *, const void *, unsigned int); |
| 188 | extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long); |
| 189 | extern void bad_page_fault(struct pt_regs *, unsigned long, int); |
| 190 | extern int die(const char *, struct pt_regs *, long); |
| 191 | extern void _exception(int, struct pt_regs *, int, unsigned long); |
Jon Loeliger | 1d59483 | 2008-01-23 12:42:07 -0600 | [diff] [blame] | 192 | extern void _nmask_and_or_msr(unsigned long nmask, unsigned long or_val); |
| 193 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 194 | #ifdef CONFIG_BOOKE_WDT |
| 195 | extern u32 booke_wdt_enabled; |
| 196 | extern u32 booke_wdt_period; |
| 197 | #endif /* CONFIG_BOOKE_WDT */ |
| 198 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 199 | struct device_node; |
| 200 | extern void note_scsi_host(struct device_node *, void *); |
| 201 | |
| 202 | extern struct task_struct *__switch_to(struct task_struct *, |
| 203 | struct task_struct *); |
| 204 | #define switch_to(prev, next, last) ((last) = __switch_to((prev), (next))) |
| 205 | |
| 206 | struct thread_struct; |
| 207 | extern struct task_struct *_switch(struct thread_struct *prev, |
| 208 | struct thread_struct *next); |
| 209 | |
| 210 | extern unsigned int rtas_data; |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 211 | extern int mem_init_done; /* set on boot once kmalloc can be called */ |
Michael Ellerman | 5f25f065 | 2008-05-08 14:27:07 +1000 | [diff] [blame] | 212 | extern int init_bootmem_done; /* set on !NUMA once bootmem is available */ |
Paul Mackerras | cf00a8d | 2005-10-31 13:07:02 +1100 | [diff] [blame] | 213 | extern unsigned long memory_limit; |
Paul Mackerras | 49b0985 | 2005-11-10 15:53:40 +1100 | [diff] [blame] | 214 | extern unsigned long klimit; |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 215 | |
Stephen Rothwell | 7b2c3c5 | 2007-09-17 14:08:06 +1000 | [diff] [blame] | 216 | extern void *alloc_maybe_bootmem(size_t size, gfp_t mask); |
Stephen Rothwell | 5669c3c | 2007-10-02 13:37:53 +1000 | [diff] [blame] | 217 | extern void *zalloc_maybe_bootmem(size_t size, gfp_t mask); |
Stephen Rothwell | 7b2c3c5 | 2007-09-17 14:08:06 +1000 | [diff] [blame] | 218 | |
Paul Mackerras | 17a6392 | 2005-10-20 21:10:09 +1000 | [diff] [blame] | 219 | extern int powersave_nap; /* set if nap mode can be used in idle loop */ |
| 220 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 221 | /* |
| 222 | * Atomic exchange |
| 223 | * |
| 224 | * Changes the memory location '*ptr' to be val and returns |
| 225 | * the previous value stored there. |
| 226 | */ |
Paul Mackerras | dd18434f | 2008-04-28 14:44:08 +1000 | [diff] [blame] | 227 | static __always_inline unsigned long |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 228 | __xchg_u32(volatile void *p, unsigned long val) |
| 229 | { |
| 230 | unsigned long prev; |
| 231 | |
| 232 | __asm__ __volatile__( |
Anton Blanchard | 144b9c1 | 2006-01-13 15:37:17 +1100 | [diff] [blame] | 233 | LWSYNC_ON_SMP |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 234 | "1: lwarx %0,0,%2 \n" |
| 235 | PPC405_ERR77(0,%2) |
| 236 | " stwcx. %3,0,%2 \n\ |
| 237 | bne- 1b" |
| 238 | ISYNC_ON_SMP |
Linus Torvalds | e2a3d40 | 2006-07-08 15:00:28 -0700 | [diff] [blame] | 239 | : "=&r" (prev), "+m" (*(volatile unsigned int *)p) |
| 240 | : "r" (p), "r" (val) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 241 | : "cc", "memory"); |
| 242 | |
| 243 | return prev; |
| 244 | } |
| 245 | |
Mathieu Desnoyers | f46e477 | 2007-05-08 00:34:27 -0700 | [diff] [blame] | 246 | /* |
| 247 | * Atomic exchange |
| 248 | * |
| 249 | * Changes the memory location '*ptr' to be val and returns |
| 250 | * the previous value stored there. |
| 251 | */ |
Paul Mackerras | dd18434f | 2008-04-28 14:44:08 +1000 | [diff] [blame] | 252 | static __always_inline unsigned long |
Mathieu Desnoyers | f46e477 | 2007-05-08 00:34:27 -0700 | [diff] [blame] | 253 | __xchg_u32_local(volatile void *p, unsigned long val) |
| 254 | { |
| 255 | unsigned long prev; |
| 256 | |
| 257 | __asm__ __volatile__( |
| 258 | "1: lwarx %0,0,%2 \n" |
| 259 | PPC405_ERR77(0,%2) |
| 260 | " stwcx. %3,0,%2 \n\ |
| 261 | bne- 1b" |
| 262 | : "=&r" (prev), "+m" (*(volatile unsigned int *)p) |
| 263 | : "r" (p), "r" (val) |
| 264 | : "cc", "memory"); |
| 265 | |
| 266 | return prev; |
| 267 | } |
| 268 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 269 | #ifdef CONFIG_PPC64 |
Paul Mackerras | dd18434f | 2008-04-28 14:44:08 +1000 | [diff] [blame] | 270 | static __always_inline unsigned long |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 271 | __xchg_u64(volatile void *p, unsigned long val) |
| 272 | { |
| 273 | unsigned long prev; |
| 274 | |
| 275 | __asm__ __volatile__( |
Anton Blanchard | 144b9c1 | 2006-01-13 15:37:17 +1100 | [diff] [blame] | 276 | LWSYNC_ON_SMP |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 277 | "1: ldarx %0,0,%2 \n" |
| 278 | PPC405_ERR77(0,%2) |
| 279 | " stdcx. %3,0,%2 \n\ |
| 280 | bne- 1b" |
| 281 | ISYNC_ON_SMP |
Linus Torvalds | e2a3d40 | 2006-07-08 15:00:28 -0700 | [diff] [blame] | 282 | : "=&r" (prev), "+m" (*(volatile unsigned long *)p) |
| 283 | : "r" (p), "r" (val) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 284 | : "cc", "memory"); |
| 285 | |
| 286 | return prev; |
| 287 | } |
Mathieu Desnoyers | f46e477 | 2007-05-08 00:34:27 -0700 | [diff] [blame] | 288 | |
Paul Mackerras | dd18434f | 2008-04-28 14:44:08 +1000 | [diff] [blame] | 289 | static __always_inline unsigned long |
Mathieu Desnoyers | f46e477 | 2007-05-08 00:34:27 -0700 | [diff] [blame] | 290 | __xchg_u64_local(volatile void *p, unsigned long val) |
| 291 | { |
| 292 | unsigned long prev; |
| 293 | |
| 294 | __asm__ __volatile__( |
| 295 | "1: ldarx %0,0,%2 \n" |
| 296 | PPC405_ERR77(0,%2) |
| 297 | " stdcx. %3,0,%2 \n\ |
| 298 | bne- 1b" |
| 299 | : "=&r" (prev), "+m" (*(volatile unsigned long *)p) |
| 300 | : "r" (p), "r" (val) |
| 301 | : "cc", "memory"); |
| 302 | |
| 303 | return prev; |
| 304 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 305 | #endif |
| 306 | |
| 307 | /* |
| 308 | * This function doesn't exist, so you'll get a linker error |
| 309 | * if something tries to do an invalid xchg(). |
| 310 | */ |
| 311 | extern void __xchg_called_with_bad_pointer(void); |
| 312 | |
Paul Mackerras | dd18434f | 2008-04-28 14:44:08 +1000 | [diff] [blame] | 313 | static __always_inline unsigned long |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 314 | __xchg(volatile void *ptr, unsigned long x, unsigned int size) |
| 315 | { |
| 316 | switch (size) { |
| 317 | case 4: |
| 318 | return __xchg_u32(ptr, x); |
| 319 | #ifdef CONFIG_PPC64 |
| 320 | case 8: |
| 321 | return __xchg_u64(ptr, x); |
| 322 | #endif |
| 323 | } |
| 324 | __xchg_called_with_bad_pointer(); |
| 325 | return x; |
| 326 | } |
| 327 | |
Paul Mackerras | dd18434f | 2008-04-28 14:44:08 +1000 | [diff] [blame] | 328 | static __always_inline unsigned long |
Mathieu Desnoyers | f46e477 | 2007-05-08 00:34:27 -0700 | [diff] [blame] | 329 | __xchg_local(volatile void *ptr, unsigned long x, unsigned int size) |
| 330 | { |
| 331 | switch (size) { |
| 332 | case 4: |
| 333 | return __xchg_u32_local(ptr, x); |
| 334 | #ifdef CONFIG_PPC64 |
| 335 | case 8: |
| 336 | return __xchg_u64_local(ptr, x); |
| 337 | #endif |
| 338 | } |
| 339 | __xchg_called_with_bad_pointer(); |
| 340 | return x; |
| 341 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 342 | #define xchg(ptr,x) \ |
| 343 | ({ \ |
| 344 | __typeof__(*(ptr)) _x_ = (x); \ |
| 345 | (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \ |
| 346 | }) |
| 347 | |
Mathieu Desnoyers | f46e477 | 2007-05-08 00:34:27 -0700 | [diff] [blame] | 348 | #define xchg_local(ptr,x) \ |
| 349 | ({ \ |
| 350 | __typeof__(*(ptr)) _x_ = (x); \ |
| 351 | (__typeof__(*(ptr))) __xchg_local((ptr), \ |
| 352 | (unsigned long)_x_, sizeof(*(ptr))); \ |
| 353 | }) |
| 354 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 355 | /* |
| 356 | * Compare and exchange - if *p == old, set it to new, |
| 357 | * and return the old value of *p. |
| 358 | */ |
| 359 | #define __HAVE_ARCH_CMPXCHG 1 |
| 360 | |
Paul Mackerras | dd18434f | 2008-04-28 14:44:08 +1000 | [diff] [blame] | 361 | static __always_inline unsigned long |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 362 | __cmpxchg_u32(volatile unsigned int *p, unsigned long old, unsigned long new) |
| 363 | { |
| 364 | unsigned int prev; |
| 365 | |
| 366 | __asm__ __volatile__ ( |
Anton Blanchard | 144b9c1 | 2006-01-13 15:37:17 +1100 | [diff] [blame] | 367 | LWSYNC_ON_SMP |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 368 | "1: lwarx %0,0,%2 # __cmpxchg_u32\n\ |
| 369 | cmpw 0,%0,%3\n\ |
| 370 | bne- 2f\n" |
| 371 | PPC405_ERR77(0,%2) |
| 372 | " stwcx. %4,0,%2\n\ |
| 373 | bne- 1b" |
| 374 | ISYNC_ON_SMP |
| 375 | "\n\ |
| 376 | 2:" |
Linus Torvalds | e2a3d40 | 2006-07-08 15:00:28 -0700 | [diff] [blame] | 377 | : "=&r" (prev), "+m" (*p) |
| 378 | : "r" (p), "r" (old), "r" (new) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 379 | : "cc", "memory"); |
| 380 | |
| 381 | return prev; |
| 382 | } |
| 383 | |
Paul Mackerras | dd18434f | 2008-04-28 14:44:08 +1000 | [diff] [blame] | 384 | static __always_inline unsigned long |
Mathieu Desnoyers | f46e477 | 2007-05-08 00:34:27 -0700 | [diff] [blame] | 385 | __cmpxchg_u32_local(volatile unsigned int *p, unsigned long old, |
| 386 | unsigned long new) |
| 387 | { |
| 388 | unsigned int prev; |
| 389 | |
| 390 | __asm__ __volatile__ ( |
| 391 | "1: lwarx %0,0,%2 # __cmpxchg_u32\n\ |
| 392 | cmpw 0,%0,%3\n\ |
| 393 | bne- 2f\n" |
| 394 | PPC405_ERR77(0,%2) |
| 395 | " stwcx. %4,0,%2\n\ |
| 396 | bne- 1b" |
| 397 | "\n\ |
| 398 | 2:" |
| 399 | : "=&r" (prev), "+m" (*p) |
| 400 | : "r" (p), "r" (old), "r" (new) |
| 401 | : "cc", "memory"); |
| 402 | |
| 403 | return prev; |
| 404 | } |
| 405 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 406 | #ifdef CONFIG_PPC64 |
Paul Mackerras | dd18434f | 2008-04-28 14:44:08 +1000 | [diff] [blame] | 407 | static __always_inline unsigned long |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 408 | __cmpxchg_u64(volatile unsigned long *p, unsigned long old, unsigned long new) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 409 | { |
| 410 | unsigned long prev; |
| 411 | |
| 412 | __asm__ __volatile__ ( |
Anton Blanchard | 144b9c1 | 2006-01-13 15:37:17 +1100 | [diff] [blame] | 413 | LWSYNC_ON_SMP |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 414 | "1: ldarx %0,0,%2 # __cmpxchg_u64\n\ |
| 415 | cmpd 0,%0,%3\n\ |
| 416 | bne- 2f\n\ |
| 417 | stdcx. %4,0,%2\n\ |
| 418 | bne- 1b" |
| 419 | ISYNC_ON_SMP |
| 420 | "\n\ |
| 421 | 2:" |
Linus Torvalds | e2a3d40 | 2006-07-08 15:00:28 -0700 | [diff] [blame] | 422 | : "=&r" (prev), "+m" (*p) |
| 423 | : "r" (p), "r" (old), "r" (new) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 424 | : "cc", "memory"); |
| 425 | |
| 426 | return prev; |
| 427 | } |
Mathieu Desnoyers | f46e477 | 2007-05-08 00:34:27 -0700 | [diff] [blame] | 428 | |
Paul Mackerras | dd18434f | 2008-04-28 14:44:08 +1000 | [diff] [blame] | 429 | static __always_inline unsigned long |
Mathieu Desnoyers | f46e477 | 2007-05-08 00:34:27 -0700 | [diff] [blame] | 430 | __cmpxchg_u64_local(volatile unsigned long *p, unsigned long old, |
| 431 | unsigned long new) |
| 432 | { |
| 433 | unsigned long prev; |
| 434 | |
| 435 | __asm__ __volatile__ ( |
| 436 | "1: ldarx %0,0,%2 # __cmpxchg_u64\n\ |
| 437 | cmpd 0,%0,%3\n\ |
| 438 | bne- 2f\n\ |
| 439 | stdcx. %4,0,%2\n\ |
| 440 | bne- 1b" |
| 441 | "\n\ |
| 442 | 2:" |
| 443 | : "=&r" (prev), "+m" (*p) |
| 444 | : "r" (p), "r" (old), "r" (new) |
| 445 | : "cc", "memory"); |
| 446 | |
| 447 | return prev; |
| 448 | } |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 449 | #endif |
| 450 | |
| 451 | /* This function doesn't exist, so you'll get a linker error |
| 452 | if something tries to do an invalid cmpxchg(). */ |
| 453 | extern void __cmpxchg_called_with_bad_pointer(void); |
| 454 | |
Paul Mackerras | dd18434f | 2008-04-28 14:44:08 +1000 | [diff] [blame] | 455 | static __always_inline unsigned long |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 456 | __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, |
| 457 | unsigned int size) |
| 458 | { |
| 459 | switch (size) { |
| 460 | case 4: |
| 461 | return __cmpxchg_u32(ptr, old, new); |
| 462 | #ifdef CONFIG_PPC64 |
| 463 | case 8: |
| 464 | return __cmpxchg_u64(ptr, old, new); |
| 465 | #endif |
| 466 | } |
| 467 | __cmpxchg_called_with_bad_pointer(); |
| 468 | return old; |
| 469 | } |
| 470 | |
Paul Mackerras | dd18434f | 2008-04-28 14:44:08 +1000 | [diff] [blame] | 471 | static __always_inline unsigned long |
Mathieu Desnoyers | f46e477 | 2007-05-08 00:34:27 -0700 | [diff] [blame] | 472 | __cmpxchg_local(volatile void *ptr, unsigned long old, unsigned long new, |
| 473 | unsigned int size) |
| 474 | { |
| 475 | switch (size) { |
| 476 | case 4: |
| 477 | return __cmpxchg_u32_local(ptr, old, new); |
| 478 | #ifdef CONFIG_PPC64 |
| 479 | case 8: |
| 480 | return __cmpxchg_u64_local(ptr, old, new); |
| 481 | #endif |
| 482 | } |
| 483 | __cmpxchg_called_with_bad_pointer(); |
| 484 | return old; |
| 485 | } |
| 486 | |
Mathieu Desnoyers | f9c4650 | 2008-02-07 00:16:10 -0800 | [diff] [blame] | 487 | #define cmpxchg(ptr, o, n) \ |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 488 | ({ \ |
| 489 | __typeof__(*(ptr)) _o_ = (o); \ |
| 490 | __typeof__(*(ptr)) _n_ = (n); \ |
| 491 | (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \ |
| 492 | (unsigned long)_n_, sizeof(*(ptr))); \ |
| 493 | }) |
| 494 | |
Mathieu Desnoyers | f46e477 | 2007-05-08 00:34:27 -0700 | [diff] [blame] | 495 | |
Mathieu Desnoyers | f9c4650 | 2008-02-07 00:16:10 -0800 | [diff] [blame] | 496 | #define cmpxchg_local(ptr, o, n) \ |
Mathieu Desnoyers | f46e477 | 2007-05-08 00:34:27 -0700 | [diff] [blame] | 497 | ({ \ |
| 498 | __typeof__(*(ptr)) _o_ = (o); \ |
| 499 | __typeof__(*(ptr)) _n_ = (n); \ |
| 500 | (__typeof__(*(ptr))) __cmpxchg_local((ptr), (unsigned long)_o_, \ |
| 501 | (unsigned long)_n_, sizeof(*(ptr))); \ |
| 502 | }) |
| 503 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 504 | #ifdef CONFIG_PPC64 |
| 505 | /* |
| 506 | * We handle most unaligned accesses in hardware. On the other hand |
| 507 | * unaligned DMA can be very expensive on some ppc64 IO chips (it does |
| 508 | * powers of 2 writes until it reaches sufficient alignment). |
| 509 | * |
| 510 | * Based on this we disable the IP header alignment in network drivers. |
Anton Blanchard | 025be81 | 2006-03-31 02:27:06 -0800 | [diff] [blame] | 511 | * We also modify NET_SKB_PAD to be a cacheline in size, thus maintaining |
| 512 | * cacheline alignment of buffers. |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 513 | */ |
Anton Blanchard | 025be81 | 2006-03-31 02:27:06 -0800 | [diff] [blame] | 514 | #define NET_IP_ALIGN 0 |
| 515 | #define NET_SKB_PAD L1_CACHE_BYTES |
Mathieu Desnoyers | f9c4650 | 2008-02-07 00:16:10 -0800 | [diff] [blame] | 516 | |
| 517 | #define cmpxchg64(ptr, o, n) \ |
| 518 | ({ \ |
| 519 | BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ |
| 520 | cmpxchg((ptr), (o), (n)); \ |
| 521 | }) |
| 522 | #define cmpxchg64_local(ptr, o, n) \ |
| 523 | ({ \ |
| 524 | BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ |
| 525 | cmpxchg_local((ptr), (o), (n)); \ |
| 526 | }) |
| 527 | #else |
| 528 | #include <asm-generic/cmpxchg-local.h> |
| 529 | #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n)) |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 530 | #endif |
| 531 | |
| 532 | #define arch_align_stack(x) (x) |
| 533 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 534 | /* Used in very early kernel initialization. */ |
Stephen Rothwell | cabb558 | 2005-09-30 16:16:52 +1000 | [diff] [blame] | 535 | extern unsigned long reloc_offset(void); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 536 | extern unsigned long add_reloc_offset(unsigned long); |
| 537 | extern void reloc_got2(unsigned long); |
| 538 | |
| 539 | #define PTRRELOC(x) ((typeof(x)) add_reloc_offset((unsigned long)(x))) |
Stephen Rothwell | cabb558 | 2005-09-30 16:16:52 +1000 | [diff] [blame] | 540 | |
Paul Mackerras | c6622f6 | 2006-02-24 10:06:59 +1100 | [diff] [blame] | 541 | #ifdef CONFIG_VIRT_CPU_ACCOUNTING |
| 542 | extern void account_system_vtime(struct task_struct *); |
| 543 | #endif |
| 544 | |
Michael Ellerman | 94a3807 | 2007-06-20 10:54:19 +1000 | [diff] [blame] | 545 | extern struct dentry *powerpc_debugfs_root; |
| 546 | |
Paul Mackerras | 14cf11a | 2005-09-26 16:04:21 +1000 | [diff] [blame] | 547 | #endif /* __KERNEL__ */ |
Stephen Rothwell | bbeb3f4 | 2005-09-27 13:51:59 +1000 | [diff] [blame] | 548 | #endif /* _ASM_POWERPC_SYSTEM_H */ |