system.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. #ifndef __PPC64_SYSTEM_H
  2. #define __PPC64_SYSTEM_H
  3. /*
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #include <linux/config.h>
  10. #include <linux/compiler.h>
  11. #include <asm/page.h>
  12. #include <asm/processor.h>
  13. #include <asm/hw_irq.h>
  14. #include <asm/synch.h>
  15. /*
  16. * Memory barrier.
  17. * The sync instruction guarantees that all memory accesses initiated
  18. * by this processor have been performed (with respect to all other
  19. * mechanisms that access memory). The eieio instruction is a barrier
  20. * providing an ordering (separately) for (a) cacheable stores and (b)
  21. * loads and stores to non-cacheable memory (e.g. I/O devices).
  22. *
  23. * mb() prevents loads and stores being reordered across this point.
  24. * rmb() prevents loads being reordered across this point.
  25. * wmb() prevents stores being reordered across this point.
  26. * read_barrier_depends() prevents data-dependent loads being reordered
  27. * across this point (nop on PPC).
  28. *
  29. * We have to use the sync instructions for mb(), since lwsync doesn't
  30. * order loads with respect to previous stores. Lwsync is fine for
  31. * rmb(), though.
  32. * For wmb(), we use sync since wmb is used in drivers to order
  33. * stores to system memory with respect to writes to the device.
  34. * However, smp_wmb() can be a lighter-weight eieio barrier on
  35. * SMP since it is only used to order updates to system memory.
  36. */
  37. #define mb() __asm__ __volatile__ ("sync" : : : "memory")
  38. #define rmb() __asm__ __volatile__ ("lwsync" : : : "memory")
  39. #define wmb() __asm__ __volatile__ ("sync" : : : "memory")
  40. #define read_barrier_depends() do { } while(0)
  41. #define set_mb(var, value) do { var = value; smp_mb(); } while (0)
  42. #define set_wmb(var, value) do { var = value; smp_wmb(); } while (0)
  43. #ifdef CONFIG_SMP
  44. #define smp_mb() mb()
  45. #define smp_rmb() rmb()
  46. #define smp_wmb() eieio()
  47. #define smp_read_barrier_depends() read_barrier_depends()
  48. #else
  49. #define smp_mb() __asm__ __volatile__("": : :"memory")
  50. #define smp_rmb() __asm__ __volatile__("": : :"memory")
  51. #define smp_wmb() __asm__ __volatile__("": : :"memory")
  52. #define smp_read_barrier_depends() do { } while(0)
  53. #endif /* CONFIG_SMP */
  54. #ifdef __KERNEL__
  55. struct task_struct;
  56. struct pt_regs;
  57. #ifdef CONFIG_DEBUGGER
  58. extern int (*__debugger)(struct pt_regs *regs);
  59. extern int (*__debugger_ipi)(struct pt_regs *regs);
  60. extern int (*__debugger_bpt)(struct pt_regs *regs);
  61. extern int (*__debugger_sstep)(struct pt_regs *regs);
  62. extern int (*__debugger_iabr_match)(struct pt_regs *regs);
  63. extern int (*__debugger_dabr_match)(struct pt_regs *regs);
  64. extern int (*__debugger_fault_handler)(struct pt_regs *regs);
  65. #define DEBUGGER_BOILERPLATE(__NAME) \
  66. static inline int __NAME(struct pt_regs *regs) \
  67. { \
  68. if (unlikely(__ ## __NAME)) \
  69. return __ ## __NAME(regs); \
  70. return 0; \
  71. }
  72. DEBUGGER_BOILERPLATE(debugger)
  73. DEBUGGER_BOILERPLATE(debugger_ipi)
  74. DEBUGGER_BOILERPLATE(debugger_bpt)
  75. DEBUGGER_BOILERPLATE(debugger_sstep)
  76. DEBUGGER_BOILERPLATE(debugger_iabr_match)
  77. DEBUGGER_BOILERPLATE(debugger_dabr_match)
  78. DEBUGGER_BOILERPLATE(debugger_fault_handler)
  79. #ifdef CONFIG_XMON
  80. extern void xmon_init(int enable);
  81. #endif
  82. #else
  83. static inline int debugger(struct pt_regs *regs) { return 0; }
  84. static inline int debugger_ipi(struct pt_regs *regs) { return 0; }
  85. static inline int debugger_bpt(struct pt_regs *regs) { return 0; }
  86. static inline int debugger_sstep(struct pt_regs *regs) { return 0; }
  87. static inline int debugger_iabr_match(struct pt_regs *regs) { return 0; }
  88. static inline int debugger_dabr_match(struct pt_regs *regs) { return 0; }
  89. static inline int debugger_fault_handler(struct pt_regs *regs) { return 0; }
  90. #endif
  91. extern int set_dabr(unsigned long dabr);
  92. extern void _exception(int signr, struct pt_regs *regs, int code,
  93. unsigned long addr);
  94. extern int fix_alignment(struct pt_regs *regs);
  95. extern void bad_page_fault(struct pt_regs *regs, unsigned long address,
  96. int sig);
  97. extern void show_regs(struct pt_regs * regs);
  98. extern void low_hash_fault(struct pt_regs *regs, unsigned long address);
  99. extern int die(const char *str, struct pt_regs *regs, long err);
  100. extern int _get_PVR(void);
  101. extern void giveup_fpu(struct task_struct *);
  102. extern void disable_kernel_fp(void);
  103. extern void flush_fp_to_thread(struct task_struct *);
  104. extern void enable_kernel_fp(void);
  105. extern void giveup_altivec(struct task_struct *);
  106. extern void disable_kernel_altivec(void);
  107. extern void enable_kernel_altivec(void);
  108. extern int emulate_altivec(struct pt_regs *);
  109. extern void cvt_fd(float *from, double *to, struct thread_struct *thread);
  110. extern void cvt_df(double *from, float *to, struct thread_struct *thread);
  111. #ifdef CONFIG_ALTIVEC
  112. extern void flush_altivec_to_thread(struct task_struct *);
  113. #else
  114. static inline void flush_altivec_to_thread(struct task_struct *t)
  115. {
  116. }
  117. #endif
  118. static inline void flush_spe_to_thread(struct task_struct *t)
  119. {
  120. }
  121. extern int mem_init_done; /* set on boot once kmalloc can be called */
  122. extern unsigned long memory_limit;
  123. /* EBCDIC -> ASCII conversion for [0-9A-Z] on iSeries */
  124. extern unsigned char e2a(unsigned char);
  125. extern struct task_struct *__switch_to(struct task_struct *,
  126. struct task_struct *);
  127. #define switch_to(prev, next, last) ((last) = __switch_to((prev), (next)))
  128. struct thread_struct;
  129. extern struct task_struct * _switch(struct thread_struct *prev,
  130. struct thread_struct *next);
  131. extern int powersave_nap; /* set if nap mode can be used in idle loop */
  132. /*
  133. * Atomic exchange
  134. *
  135. * Changes the memory location '*ptr' to be val and returns
  136. * the previous value stored there.
  137. *
  138. * Inline asm pulled from arch/ppc/kernel/misc.S so ppc64
  139. * is more like most of the other architectures.
  140. */
  141. static __inline__ unsigned long
  142. __xchg_u32(volatile unsigned int *m, unsigned long val)
  143. {
  144. unsigned long dummy;
  145. __asm__ __volatile__(
  146. EIEIO_ON_SMP
  147. "1: lwarx %0,0,%3 # __xchg_u32\n\
  148. stwcx. %2,0,%3\n\
  149. 2: bne- 1b"
  150. ISYNC_ON_SMP
  151. : "=&r" (dummy), "=m" (*m)
  152. : "r" (val), "r" (m)
  153. : "cc", "memory");
  154. return (dummy);
  155. }
  156. static __inline__ unsigned long
  157. __xchg_u64(volatile long *m, unsigned long val)
  158. {
  159. unsigned long dummy;
  160. __asm__ __volatile__(
  161. EIEIO_ON_SMP
  162. "1: ldarx %0,0,%3 # __xchg_u64\n\
  163. stdcx. %2,0,%3\n\
  164. 2: bne- 1b"
  165. ISYNC_ON_SMP
  166. : "=&r" (dummy), "=m" (*m)
  167. : "r" (val), "r" (m)
  168. : "cc", "memory");
  169. return (dummy);
  170. }
  171. /*
  172. * This function doesn't exist, so you'll get a linker error
  173. * if something tries to do an invalid xchg().
  174. */
  175. extern void __xchg_called_with_bad_pointer(void);
  176. static __inline__ unsigned long
  177. __xchg(volatile void *ptr, unsigned long x, unsigned int size)
  178. {
  179. switch (size) {
  180. case 4:
  181. return __xchg_u32(ptr, x);
  182. case 8:
  183. return __xchg_u64(ptr, x);
  184. }
  185. __xchg_called_with_bad_pointer();
  186. return x;
  187. }
  188. #define xchg(ptr,x) \
  189. ({ \
  190. __typeof__(*(ptr)) _x_ = (x); \
  191. (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); \
  192. })
  193. #define tas(ptr) (xchg((ptr),1))
  194. #define __HAVE_ARCH_CMPXCHG 1
  195. static __inline__ unsigned long
  196. __cmpxchg_u32(volatile unsigned int *p, unsigned long old, unsigned long new)
  197. {
  198. unsigned int prev;
  199. __asm__ __volatile__ (
  200. EIEIO_ON_SMP
  201. "1: lwarx %0,0,%2 # __cmpxchg_u32\n\
  202. cmpw 0,%0,%3\n\
  203. bne- 2f\n\
  204. stwcx. %4,0,%2\n\
  205. bne- 1b"
  206. ISYNC_ON_SMP
  207. "\n\
  208. 2:"
  209. : "=&r" (prev), "=m" (*p)
  210. : "r" (p), "r" (old), "r" (new), "m" (*p)
  211. : "cc", "memory");
  212. return prev;
  213. }
  214. static __inline__ unsigned long
  215. __cmpxchg_u64(volatile unsigned long *p, unsigned long old, unsigned long new)
  216. {
  217. unsigned long prev;
  218. __asm__ __volatile__ (
  219. EIEIO_ON_SMP
  220. "1: ldarx %0,0,%2 # __cmpxchg_u64\n\
  221. cmpd 0,%0,%3\n\
  222. bne- 2f\n\
  223. stdcx. %4,0,%2\n\
  224. bne- 1b"
  225. ISYNC_ON_SMP
  226. "\n\
  227. 2:"
  228. : "=&r" (prev), "=m" (*p)
  229. : "r" (p), "r" (old), "r" (new), "m" (*p)
  230. : "cc", "memory");
  231. return prev;
  232. }
  233. /* This function doesn't exist, so you'll get a linker error
  234. if something tries to do an invalid cmpxchg(). */
  235. extern void __cmpxchg_called_with_bad_pointer(void);
  236. static __inline__ unsigned long
  237. __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
  238. unsigned int size)
  239. {
  240. switch (size) {
  241. case 4:
  242. return __cmpxchg_u32(ptr, old, new);
  243. case 8:
  244. return __cmpxchg_u64(ptr, old, new);
  245. }
  246. __cmpxchg_called_with_bad_pointer();
  247. return old;
  248. }
  249. #define cmpxchg(ptr,o,n)\
  250. ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
  251. (unsigned long)(n),sizeof(*(ptr))))
  252. /*
  253. * We handle most unaligned accesses in hardware. On the other hand
  254. * unaligned DMA can be very expensive on some ppc64 IO chips (it does
  255. * powers of 2 writes until it reaches sufficient alignment).
  256. *
  257. * Based on this we disable the IP header alignment in network drivers.
  258. */
  259. #define NET_IP_ALIGN 0
  260. #define arch_align_stack(x) (x)
  261. extern unsigned long reloc_offset(void);
  262. #endif /* __KERNEL__ */
  263. #endif