system.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*
  2. * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
  3. */
  4. #ifndef _ASM_POWERPC_SYSTEM_H
  5. #define _ASM_POWERPC_SYSTEM_H
  6. #include <linux/config.h>
  7. #include <linux/kernel.h>
  8. #include <asm/hw_irq.h>
  9. #include <asm/ppc_asm.h>
  10. #include <asm/atomic.h>
  11. /*
  12. * Memory barrier.
  13. * The sync instruction guarantees that all memory accesses initiated
  14. * by this processor have been performed (with respect to all other
  15. * mechanisms that access memory). The eieio instruction is a barrier
  16. * providing an ordering (separately) for (a) cacheable stores and (b)
  17. * loads and stores to non-cacheable memory (e.g. I/O devices).
  18. *
  19. * mb() prevents loads and stores being reordered across this point.
  20. * rmb() prevents loads being reordered across this point.
  21. * wmb() prevents stores being reordered across this point.
  22. * read_barrier_depends() prevents data-dependent loads being reordered
  23. * across this point (nop on PPC).
  24. *
  25. * We have to use the sync instructions for mb(), since lwsync doesn't
  26. * order loads with respect to previous stores. Lwsync is fine for
  27. * rmb(), though. Note that lwsync is interpreted as sync by
  28. * 32-bit and older 64-bit CPUs.
  29. *
  30. * For wmb(), we use sync since wmb is used in drivers to order
  31. * stores to system memory with respect to writes to the device.
  32. * However, smp_wmb() can be a lighter-weight eieio barrier on
  33. * SMP since it is only used to order updates to system memory.
  34. */
  35. #define mb() __asm__ __volatile__ ("sync" : : : "memory")
  36. #define rmb() __asm__ __volatile__ ("lwsync" : : : "memory")
  37. #define wmb() __asm__ __volatile__ ("sync" : : : "memory")
  38. #define read_barrier_depends() do { } while(0)
  39. #define set_mb(var, value) do { var = value; mb(); } while (0)
  40. #define set_wmb(var, value) do { var = value; wmb(); } while (0)
  41. #ifdef CONFIG_SMP
  42. #define smp_mb() mb()
  43. #define smp_rmb() rmb()
  44. #define smp_wmb() __asm__ __volatile__ ("eieio" : : : "memory")
  45. #define smp_read_barrier_depends() read_barrier_depends()
  46. #else
  47. #define smp_mb() barrier()
  48. #define smp_rmb() barrier()
  49. #define smp_wmb() barrier()
  50. #define smp_read_barrier_depends() do { } while(0)
  51. #endif /* CONFIG_SMP */
  52. #ifdef __KERNEL__
  53. struct task_struct;
  54. struct pt_regs;
  55. #ifdef CONFIG_DEBUGGER
  56. extern int (*__debugger)(struct pt_regs *regs);
  57. extern int (*__debugger_ipi)(struct pt_regs *regs);
  58. extern int (*__debugger_bpt)(struct pt_regs *regs);
  59. extern int (*__debugger_sstep)(struct pt_regs *regs);
  60. extern int (*__debugger_iabr_match)(struct pt_regs *regs);
  61. extern int (*__debugger_dabr_match)(struct pt_regs *regs);
  62. extern int (*__debugger_fault_handler)(struct pt_regs *regs);
  63. #define DEBUGGER_BOILERPLATE(__NAME) \
  64. static inline int __NAME(struct pt_regs *regs) \
  65. { \
  66. if (unlikely(__ ## __NAME)) \
  67. return __ ## __NAME(regs); \
  68. return 0; \
  69. }
  70. DEBUGGER_BOILERPLATE(debugger)
  71. DEBUGGER_BOILERPLATE(debugger_ipi)
  72. DEBUGGER_BOILERPLATE(debugger_bpt)
  73. DEBUGGER_BOILERPLATE(debugger_sstep)
  74. DEBUGGER_BOILERPLATE(debugger_iabr_match)
  75. DEBUGGER_BOILERPLATE(debugger_dabr_match)
  76. DEBUGGER_BOILERPLATE(debugger_fault_handler)
  77. #ifdef CONFIG_XMON
  78. extern void xmon_init(int enable);
  79. #endif
  80. #else
  81. static inline int debugger(struct pt_regs *regs) { return 0; }
  82. static inline int debugger_ipi(struct pt_regs *regs) { return 0; }
  83. static inline int debugger_bpt(struct pt_regs *regs) { return 0; }
  84. static inline int debugger_sstep(struct pt_regs *regs) { return 0; }
  85. static inline int debugger_iabr_match(struct pt_regs *regs) { return 0; }
  86. static inline int debugger_dabr_match(struct pt_regs *regs) { return 0; }
  87. static inline int debugger_fault_handler(struct pt_regs *regs) { return 0; }
  88. #endif
  89. extern int set_dabr(unsigned long dabr);
  90. extern void print_backtrace(unsigned long *);
  91. extern void show_regs(struct pt_regs * regs);
  92. extern void flush_instruction_cache(void);
  93. extern void hard_reset_now(void);
  94. extern void poweroff_now(void);
  95. #ifdef CONFIG_6xx
  96. extern long _get_L2CR(void);
  97. extern long _get_L3CR(void);
  98. extern void _set_L2CR(unsigned long);
  99. extern void _set_L3CR(unsigned long);
  100. #else
  101. #define _get_L2CR() 0L
  102. #define _get_L3CR() 0L
  103. #define _set_L2CR(val) do { } while(0)
  104. #define _set_L3CR(val) do { } while(0)
  105. #endif
  106. extern void via_cuda_init(void);
  107. extern void read_rtc_time(void);
  108. extern void pmac_find_display(void);
  109. extern void giveup_fpu(struct task_struct *);
  110. extern void disable_kernel_fp(void);
  111. extern void enable_kernel_fp(void);
  112. extern void flush_fp_to_thread(struct task_struct *);
  113. extern void enable_kernel_altivec(void);
  114. extern void giveup_altivec(struct task_struct *);
  115. extern void load_up_altivec(struct task_struct *);
  116. extern int emulate_altivec(struct pt_regs *);
  117. extern void giveup_spe(struct task_struct *);
  118. extern void load_up_spe(struct task_struct *);
  119. extern int fix_alignment(struct pt_regs *);
  120. extern void cvt_fd(float *from, double *to, unsigned long *fpscr);
  121. extern void cvt_df(double *from, float *to, unsigned long *fpscr);
  122. #ifdef CONFIG_ALTIVEC
  123. extern void flush_altivec_to_thread(struct task_struct *);
  124. #else
  125. static inline void flush_altivec_to_thread(struct task_struct *t)
  126. {
  127. }
  128. #endif
  129. #ifdef CONFIG_SPE
  130. extern void flush_spe_to_thread(struct task_struct *);
  131. #else
  132. static inline void flush_spe_to_thread(struct task_struct *t)
  133. {
  134. }
  135. #endif
  136. extern int call_rtas(const char *, int, int, unsigned long *, ...);
  137. extern void cacheable_memzero(void *p, unsigned int nb);
  138. extern void *cacheable_memcpy(void *, const void *, unsigned int);
  139. extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long);
  140. extern void bad_page_fault(struct pt_regs *, unsigned long, int);
  141. extern int die(const char *, struct pt_regs *, long);
  142. extern void _exception(int, struct pt_regs *, int, unsigned long);
  143. #ifdef CONFIG_BOOKE_WDT
  144. extern u32 booke_wdt_enabled;
  145. extern u32 booke_wdt_period;
  146. #endif /* CONFIG_BOOKE_WDT */
  147. /* EBCDIC -> ASCII conversion for [0-9A-Z] on iSeries */
  148. extern unsigned char e2a(unsigned char);
  149. struct device_node;
  150. extern void note_scsi_host(struct device_node *, void *);
  151. extern struct task_struct *__switch_to(struct task_struct *,
  152. struct task_struct *);
  153. #define switch_to(prev, next, last) ((last) = __switch_to((prev), (next)))
  154. struct thread_struct;
  155. extern struct task_struct *_switch(struct thread_struct *prev,
  156. struct thread_struct *next);
  157. extern unsigned int rtas_data;
  158. extern int mem_init_done; /* set on boot once kmalloc can be called */
  159. /*
  160. * Atomic exchange
  161. *
  162. * Changes the memory location '*ptr' to be val and returns
  163. * the previous value stored there.
  164. */
  165. static __inline__ unsigned long
  166. __xchg_u32(volatile void *p, unsigned long val)
  167. {
  168. unsigned long prev;
  169. __asm__ __volatile__(
  170. EIEIO_ON_SMP
  171. "1: lwarx %0,0,%2 \n"
  172. PPC405_ERR77(0,%2)
  173. " stwcx. %3,0,%2 \n\
  174. bne- 1b"
  175. ISYNC_ON_SMP
  176. : "=&r" (prev), "=m" (*(volatile unsigned int *)p)
  177. : "r" (p), "r" (val), "m" (*(volatile unsigned int *)p)
  178. : "cc", "memory");
  179. return prev;
  180. }
  181. #ifdef CONFIG_PPC64
  182. static __inline__ unsigned long
  183. __xchg_u64(volatile void *p, unsigned long val)
  184. {
  185. unsigned long prev;
  186. __asm__ __volatile__(
  187. EIEIO_ON_SMP
  188. "1: ldarx %0,0,%2 \n"
  189. PPC405_ERR77(0,%2)
  190. " stdcx. %3,0,%2 \n\
  191. bne- 1b"
  192. ISYNC_ON_SMP
  193. : "=&r" (prev), "=m" (*(volatile unsigned long *)p)
  194. : "r" (p), "r" (val), "m" (*(volatile unsigned long *)p)
  195. : "cc", "memory");
  196. return prev;
  197. }
  198. #endif
  199. /*
  200. * This function doesn't exist, so you'll get a linker error
  201. * if something tries to do an invalid xchg().
  202. */
  203. extern void __xchg_called_with_bad_pointer(void);
  204. static __inline__ unsigned long
  205. __xchg(volatile void *ptr, unsigned long x, unsigned int size)
  206. {
  207. switch (size) {
  208. case 4:
  209. return __xchg_u32(ptr, x);
  210. #ifdef CONFIG_PPC64
  211. case 8:
  212. return __xchg_u64(ptr, x);
  213. #endif
  214. }
  215. __xchg_called_with_bad_pointer();
  216. return x;
  217. }
  218. #define xchg(ptr,x) \
  219. ({ \
  220. __typeof__(*(ptr)) _x_ = (x); \
  221. (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
  222. })
  223. #define tas(ptr) (xchg((ptr),1))
  224. /*
  225. * Compare and exchange - if *p == old, set it to new,
  226. * and return the old value of *p.
  227. */
  228. #define __HAVE_ARCH_CMPXCHG 1
  229. static __inline__ unsigned long
  230. __cmpxchg_u32(volatile unsigned int *p, unsigned long old, unsigned long new)
  231. {
  232. unsigned int prev;
  233. __asm__ __volatile__ (
  234. EIEIO_ON_SMP
  235. "1: lwarx %0,0,%2 # __cmpxchg_u32\n\
  236. cmpw 0,%0,%3\n\
  237. bne- 2f\n"
  238. PPC405_ERR77(0,%2)
  239. " stwcx. %4,0,%2\n\
  240. bne- 1b"
  241. ISYNC_ON_SMP
  242. "\n\
  243. 2:"
  244. : "=&r" (prev), "=m" (*p)
  245. : "r" (p), "r" (old), "r" (new), "m" (*p)
  246. : "cc", "memory");
  247. return prev;
  248. }
  249. #ifdef CONFIG_PPC64
  250. static __inline__ unsigned long
  251. __cmpxchg_u64(volatile long *p, unsigned long old, unsigned long new)
  252. {
  253. unsigned long prev;
  254. __asm__ __volatile__ (
  255. EIEIO_ON_SMP
  256. "1: ldarx %0,0,%2 # __cmpxchg_u64\n\
  257. cmpd 0,%0,%3\n\
  258. bne- 2f\n\
  259. stdcx. %4,0,%2\n\
  260. bne- 1b"
  261. ISYNC_ON_SMP
  262. "\n\
  263. 2:"
  264. : "=&r" (prev), "=m" (*p)
  265. : "r" (p), "r" (old), "r" (new), "m" (*p)
  266. : "cc", "memory");
  267. return prev;
  268. }
  269. #endif
  270. /* This function doesn't exist, so you'll get a linker error
  271. if something tries to do an invalid cmpxchg(). */
  272. extern void __cmpxchg_called_with_bad_pointer(void);
  273. static __inline__ unsigned long
  274. __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
  275. unsigned int size)
  276. {
  277. switch (size) {
  278. case 4:
  279. return __cmpxchg_u32(ptr, old, new);
  280. #ifdef CONFIG_PPC64
  281. case 8:
  282. return __cmpxchg_u64(ptr, old, new);
  283. #endif
  284. }
  285. __cmpxchg_called_with_bad_pointer();
  286. return old;
  287. }
  288. #define cmpxchg(ptr,o,n) \
  289. ({ \
  290. __typeof__(*(ptr)) _o_ = (o); \
  291. __typeof__(*(ptr)) _n_ = (n); \
  292. (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
  293. (unsigned long)_n_, sizeof(*(ptr))); \
  294. })
  295. #ifdef CONFIG_PPC64
  296. /*
  297. * We handle most unaligned accesses in hardware. On the other hand
  298. * unaligned DMA can be very expensive on some ppc64 IO chips (it does
  299. * powers of 2 writes until it reaches sufficient alignment).
  300. *
  301. * Based on this we disable the IP header alignment in network drivers.
  302. */
  303. #define NET_IP_ALIGN 0
  304. #endif
  305. #define arch_align_stack(x) (x)
  306. /* Used in very early kernel initialization. */
  307. extern unsigned long reloc_offset(void);
  308. extern unsigned long add_reloc_offset(unsigned long);
  309. extern void reloc_got2(unsigned long);
  310. #define PTRRELOC(x) ((typeof(x)) add_reloc_offset((unsigned long)(x)))
  311. #endif /* __KERNEL__ */
  312. #endif /* _ASM_POWERPC_SYSTEM_H */