2 * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
4 #ifndef _ASM_POWERPC_SYSTEM_H
5 #define _ASM_POWERPC_SYSTEM_H
7 #include <linux/kernel.h>
8 #include <linux/irqflags.h>
10 #include <asm/hw_irq.h>
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).
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).
26 * *mb() variants without smp_ prefix must order all types of memory
27 * operations with one another. sync is the only instruction sufficient
30 * 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().
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.
38 #define mb() __asm__ __volatile__ ("sync" : : : "memory")
39 #define rmb() __asm__ __volatile__ ("sync" : : : "memory")
40 #define wmb() __asm__ __volatile__ ("sync" : : : "memory")
41 #define read_barrier_depends() do { } while(0)
43 #define set_mb(var, value) do { var = value; mb(); } while (0)
46 #define AT_VECTOR_SIZE_ARCH 6 /* entries in ARCH_DLINFO */
49 #ifdef __SUBARCH_HAS_LWSYNC
50 # define SMPWMB LWSYNC
56 #define smp_rmb() __asm__ __volatile__ (stringify_in_c(LWSYNC) : : :"memory")
57 #define smp_wmb() __asm__ __volatile__ (stringify_in_c(SMPWMB) : : :"memory")
58 #define smp_read_barrier_depends() read_barrier_depends()
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 */
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.
72 #define data_barrier(x) \
73 asm volatile("twi 0,%0,0; isync" : : "r" (x) : "memory");
78 #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
80 extern int (*__debugger
)(struct pt_regs
*regs
);
81 extern int (*__debugger_ipi
)(struct pt_regs
*regs
);
82 extern int (*__debugger_bpt
)(struct pt_regs
*regs
);
83 extern int (*__debugger_sstep
)(struct pt_regs
*regs
);
84 extern int (*__debugger_iabr_match
)(struct pt_regs
*regs
);
85 extern int (*__debugger_dabr_match
)(struct pt_regs
*regs
);
86 extern int (*__debugger_fault_handler
)(struct pt_regs
*regs
);
88 #define DEBUGGER_BOILERPLATE(__NAME) \
89 static inline int __NAME(struct pt_regs *regs) \
91 if (unlikely(__ ## __NAME)) \
92 return __ ## __NAME(regs); \
96 DEBUGGER_BOILERPLATE(debugger
)
97 DEBUGGER_BOILERPLATE(debugger_ipi
)
98 DEBUGGER_BOILERPLATE(debugger_bpt
)
99 DEBUGGER_BOILERPLATE(debugger_sstep
)
100 DEBUGGER_BOILERPLATE(debugger_iabr_match
)
101 DEBUGGER_BOILERPLATE(debugger_dabr_match
)
102 DEBUGGER_BOILERPLATE(debugger_fault_handler
)
105 static inline int debugger(struct pt_regs
*regs
) { return 0; }
106 static inline int debugger_ipi(struct pt_regs
*regs
) { return 0; }
107 static inline int debugger_bpt(struct pt_regs
*regs
) { return 0; }
108 static inline int debugger_sstep(struct pt_regs
*regs
) { return 0; }
109 static inline int debugger_iabr_match(struct pt_regs
*regs
) { return 0; }
110 static inline int debugger_dabr_match(struct pt_regs
*regs
) { return 0; }
111 static inline int debugger_fault_handler(struct pt_regs
*regs
) { return 0; }
114 extern int set_dabr(unsigned long dabr
);
115 extern void do_dabr(struct pt_regs
*regs
, unsigned long address
,
116 unsigned long error_code
);
117 extern void print_backtrace(unsigned long *);
118 extern void show_regs(struct pt_regs
* regs
);
119 extern void flush_instruction_cache(void);
120 extern void hard_reset_now(void);
121 extern void poweroff_now(void);
124 extern long _get_L2CR(void);
125 extern long _get_L3CR(void);
126 extern void _set_L2CR(unsigned long);
127 extern void _set_L3CR(unsigned long);
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)
135 extern void via_cuda_init(void);
136 extern void read_rtc_time(void);
137 extern void pmac_find_display(void);
138 extern void giveup_fpu(struct task_struct
*);
139 extern void disable_kernel_fp(void);
140 extern void enable_kernel_fp(void);
141 extern void flush_fp_to_thread(struct task_struct
*);
142 extern void enable_kernel_altivec(void);
143 extern void giveup_altivec(struct task_struct
*);
144 extern void load_up_altivec(struct task_struct
*);
145 extern int emulate_altivec(struct pt_regs
*);
146 extern void __giveup_vsx(struct task_struct
*);
147 extern void giveup_vsx(struct task_struct
*);
148 extern void enable_kernel_spe(void);
149 extern void giveup_spe(struct task_struct
*);
150 extern void load_up_spe(struct task_struct
*);
151 extern int fix_alignment(struct pt_regs
*);
152 extern void cvt_fd(float *from
, double *to
, struct thread_struct
*thread
);
153 extern void cvt_df(double *from
, float *to
, struct thread_struct
*thread
);
156 extern void discard_lazy_cpu_state(void);
158 static inline void discard_lazy_cpu_state(void)
163 #ifdef CONFIG_ALTIVEC
164 extern void flush_altivec_to_thread(struct task_struct
*);
166 static inline void flush_altivec_to_thread(struct task_struct
*t
)
172 extern void flush_vsx_to_thread(struct task_struct
*);
174 static inline void flush_vsx_to_thread(struct task_struct
*t
)
180 extern void flush_spe_to_thread(struct task_struct
*);
182 static inline void flush_spe_to_thread(struct task_struct
*t
)
187 extern int call_rtas(const char *, int, int, unsigned long *, ...);
188 extern void cacheable_memzero(void *p
, unsigned int nb
);
189 extern void *cacheable_memcpy(void *, const void *, unsigned int);
190 extern int do_page_fault(struct pt_regs
*, unsigned long, unsigned long);
191 extern void bad_page_fault(struct pt_regs
*, unsigned long, int);
192 extern int die(const char *, struct pt_regs
*, long);
193 extern void _exception(int, struct pt_regs
*, int, unsigned long);
194 extern void _nmask_and_or_msr(unsigned long nmask
, unsigned long or_val
);
196 #ifdef CONFIG_BOOKE_WDT
197 extern u32 booke_wdt_enabled
;
198 extern u32 booke_wdt_period
;
199 #endif /* CONFIG_BOOKE_WDT */
202 extern void note_scsi_host(struct device_node
*, void *);
204 extern struct task_struct
*__switch_to(struct task_struct
*,
205 struct task_struct
*);
206 #define switch_to(prev, next, last) ((last) = __switch_to((prev), (next)))
208 struct thread_struct
;
209 extern struct task_struct
*_switch(struct thread_struct
*prev
,
210 struct thread_struct
*next
);
212 extern unsigned int rtas_data
;
213 extern int mem_init_done
; /* set on boot once kmalloc can be called */
214 extern int init_bootmem_done
; /* set on !NUMA once bootmem is available */
215 extern phys_addr_t memory_limit
;
216 extern unsigned long klimit
;
218 extern void *alloc_maybe_bootmem(size_t size
, gfp_t mask
);
219 extern void *zalloc_maybe_bootmem(size_t size
, gfp_t mask
);
221 extern int powersave_nap
; /* set if nap mode can be used in idle loop */
226 * Changes the memory location '*ptr' to be val and returns
227 * the previous value stored there.
229 static __always_inline
unsigned long
230 __xchg_u32(volatile void *p
, unsigned long val
)
234 __asm__
__volatile__(
236 "1: lwarx %0,0,%2 \n"
241 : "=&r" (prev
), "+m" (*(volatile unsigned int *)p
)
251 * Changes the memory location '*ptr' to be val and returns
252 * the previous value stored there.
254 static __always_inline
unsigned long
255 __xchg_u32_local(volatile void *p
, unsigned long val
)
259 __asm__
__volatile__(
260 "1: lwarx %0,0,%2 \n"
264 : "=&r" (prev
), "+m" (*(volatile unsigned int *)p
)
272 static __always_inline
unsigned long
273 __xchg_u64(volatile void *p
, unsigned long val
)
277 __asm__
__volatile__(
279 "1: ldarx %0,0,%2 \n"
284 : "=&r" (prev
), "+m" (*(volatile unsigned long *)p
)
291 static __always_inline
unsigned long
292 __xchg_u64_local(volatile void *p
, unsigned long val
)
296 __asm__
__volatile__(
297 "1: ldarx %0,0,%2 \n"
301 : "=&r" (prev
), "+m" (*(volatile unsigned long *)p
)
310 * This function doesn't exist, so you'll get a linker error
311 * if something tries to do an invalid xchg().
313 extern void __xchg_called_with_bad_pointer(void);
315 static __always_inline
unsigned long
316 __xchg(volatile void *ptr
, unsigned long x
, unsigned int size
)
320 return __xchg_u32(ptr
, x
);
323 return __xchg_u64(ptr
, x
);
326 __xchg_called_with_bad_pointer();
330 static __always_inline
unsigned long
331 __xchg_local(volatile void *ptr
, unsigned long x
, unsigned int size
)
335 return __xchg_u32_local(ptr
, x
);
338 return __xchg_u64_local(ptr
, x
);
341 __xchg_called_with_bad_pointer();
344 #define xchg(ptr,x) \
346 __typeof__(*(ptr)) _x_ = (x); \
347 (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
350 #define xchg_local(ptr,x) \
352 __typeof__(*(ptr)) _x_ = (x); \
353 (__typeof__(*(ptr))) __xchg_local((ptr), \
354 (unsigned long)_x_, sizeof(*(ptr))); \
358 * Compare and exchange - if *p == old, set it to new,
359 * and return the old value of *p.
361 #define __HAVE_ARCH_CMPXCHG 1
363 static __always_inline
unsigned long
364 __cmpxchg_u32(volatile unsigned int *p
, unsigned long old
, unsigned long new)
368 __asm__
__volatile__ (
370 "1: lwarx %0,0,%2 # __cmpxchg_u32\n\
379 : "=&r" (prev
), "+m" (*p
)
380 : "r" (p
), "r" (old
), "r" (new)
386 static __always_inline
unsigned long
387 __cmpxchg_u32_local(volatile unsigned int *p
, unsigned long old
,
392 __asm__
__volatile__ (
393 "1: lwarx %0,0,%2 # __cmpxchg_u32\n\
401 : "=&r" (prev
), "+m" (*p
)
402 : "r" (p
), "r" (old
), "r" (new)
409 static __always_inline
unsigned long
410 __cmpxchg_u64(volatile unsigned long *p
, unsigned long old
, unsigned long new)
414 __asm__
__volatile__ (
416 "1: ldarx %0,0,%2 # __cmpxchg_u64\n\
424 : "=&r" (prev
), "+m" (*p
)
425 : "r" (p
), "r" (old
), "r" (new)
431 static __always_inline
unsigned long
432 __cmpxchg_u64_local(volatile unsigned long *p
, unsigned long old
,
437 __asm__
__volatile__ (
438 "1: ldarx %0,0,%2 # __cmpxchg_u64\n\
445 : "=&r" (prev
), "+m" (*p
)
446 : "r" (p
), "r" (old
), "r" (new)
453 /* This function doesn't exist, so you'll get a linker error
454 if something tries to do an invalid cmpxchg(). */
455 extern void __cmpxchg_called_with_bad_pointer(void);
457 static __always_inline
unsigned long
458 __cmpxchg(volatile void *ptr
, unsigned long old
, unsigned long new,
463 return __cmpxchg_u32(ptr
, old
, new);
466 return __cmpxchg_u64(ptr
, old
, new);
469 __cmpxchg_called_with_bad_pointer();
473 static __always_inline
unsigned long
474 __cmpxchg_local(volatile void *ptr
, unsigned long old
, unsigned long new,
479 return __cmpxchg_u32_local(ptr
, old
, new);
482 return __cmpxchg_u64_local(ptr
, old
, new);
485 __cmpxchg_called_with_bad_pointer();
489 #define cmpxchg(ptr, o, n) \
491 __typeof__(*(ptr)) _o_ = (o); \
492 __typeof__(*(ptr)) _n_ = (n); \
493 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
494 (unsigned long)_n_, sizeof(*(ptr))); \
498 #define cmpxchg_local(ptr, o, n) \
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))); \
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).
512 * Based on this we disable the IP header alignment in network drivers.
513 * We also modify NET_SKB_PAD to be a cacheline in size, thus maintaining
514 * cacheline alignment of buffers.
516 #define NET_IP_ALIGN 0
517 #define NET_SKB_PAD L1_CACHE_BYTES
519 #define cmpxchg64(ptr, o, n) \
521 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
522 cmpxchg((ptr), (o), (n)); \
524 #define cmpxchg64_local(ptr, o, n) \
526 BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
527 cmpxchg_local((ptr), (o), (n)); \
530 #include <asm-generic/cmpxchg-local.h>
531 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
534 extern unsigned long arch_align_stack(unsigned long sp
);
536 /* Used in very early kernel initialization. */
537 extern unsigned long reloc_offset(void);
538 extern unsigned long add_reloc_offset(unsigned long);
539 extern void reloc_got2(unsigned long);
541 #define PTRRELOC(x) ((typeof(x)) add_reloc_offset((unsigned long)(x)))
543 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
544 extern void account_system_vtime(struct task_struct
*);
547 extern struct dentry
*powerpc_debugfs_root
;
549 #endif /* __KERNEL__ */
550 #endif /* _ASM_POWERPC_SYSTEM_H */