system.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
  3. */
  4. #ifndef __PPC_SYSTEM_H
  5. #define __PPC_SYSTEM_H
  6. #include <linux/kernel.h>
  7. #include <asm/hw_irq.h>
  8. /*
  9. * Memory barrier.
  10. * The sync instruction guarantees that all memory accesses initiated
  11. * by this processor have been performed (with respect to all other
  12. * mechanisms that access memory). The eieio instruction is a barrier
  13. * providing an ordering (separately) for (a) cacheable stores and (b)
  14. * loads and stores to non-cacheable memory (e.g. I/O devices).
  15. *
  16. * mb() prevents loads and stores being reordered across this point.
  17. * rmb() prevents loads being reordered across this point.
  18. * wmb() prevents stores being reordered across this point.
  19. * read_barrier_depends() prevents data-dependent loads being reordered
  20. * across this point (nop on PPC).
  21. *
  22. * We can use the eieio instruction for wmb, but since it doesn't
  23. * give any ordering guarantees about loads, we have to use the
  24. * stronger but slower sync instruction for mb and rmb.
  25. */
  26. #define mb() __asm__ __volatile__ ("sync" : : : "memory")
  27. #define rmb() __asm__ __volatile__ ("sync" : : : "memory")
  28. #define wmb() __asm__ __volatile__ ("eieio" : : : "memory")
  29. #define read_barrier_depends() do { } while(0)
  30. #define set_mb(var, value) do { var = value; mb(); } while (0)
  31. #define AT_VECTOR_SIZE_ARCH 6 /* entries in ARCH_DLINFO */
  32. #ifdef CONFIG_SMP
  33. #define smp_mb() mb()
  34. #define smp_rmb() rmb()
  35. #define smp_wmb() __asm__ __volatile__ ("eieio" : : : "memory")
  36. #define smp_read_barrier_depends() read_barrier_depends()
  37. #else
  38. #define smp_mb() barrier()
  39. #define smp_rmb() barrier()
  40. #define smp_wmb() barrier()
  41. #define smp_read_barrier_depends() do { } while(0)
  42. #endif /* CONFIG_SMP */
  43. #ifdef __KERNEL__
  44. struct task_struct;
  45. struct pt_regs;
  46. extern void print_backtrace(unsigned long *);
  47. extern void show_regs(struct pt_regs * regs);
  48. extern void flush_instruction_cache(void);
  49. extern void hard_reset_now(void);
  50. extern void poweroff_now(void);
  51. extern int set_dabr(unsigned long dabr);
  52. #ifdef CONFIG_6xx
  53. extern long _get_L2CR(void);
  54. extern long _get_L3CR(void);
  55. extern void _set_L2CR(unsigned long);
  56. extern void _set_L3CR(unsigned long);
  57. #else
  58. #define _get_L2CR() 0L
  59. #define _get_L3CR() 0L
  60. #define _set_L2CR(val) do { } while(0)
  61. #define _set_L3CR(val) do { } while(0)
  62. #endif
  63. extern void via_cuda_init(void);
  64. extern void pmac_nvram_init(void);
  65. extern void chrp_nvram_init(void);
  66. extern void read_rtc_time(void);
  67. extern void pmac_find_display(void);
  68. extern void giveup_fpu(struct task_struct *);
  69. extern void disable_kernel_fp(void);
  70. extern void enable_kernel_fp(void);
  71. extern void flush_fp_to_thread(struct task_struct *);
  72. extern void enable_kernel_altivec(void);
  73. extern void giveup_altivec(struct task_struct *);
  74. extern void load_up_altivec(struct task_struct *);
  75. extern int emulate_altivec(struct pt_regs *);
  76. extern void giveup_spe(struct task_struct *);
  77. extern void load_up_spe(struct task_struct *);
  78. extern int fix_alignment(struct pt_regs *);
  79. extern void cvt_fd(float *from, double *to, struct thread_struct *thread);
  80. extern void cvt_df(double *from, float *to, struct thread_struct *thread);
  81. #ifndef CONFIG_SMP
  82. extern void discard_lazy_cpu_state(void);
  83. #else
  84. static inline void discard_lazy_cpu_state(void)
  85. {
  86. }
  87. #endif
  88. #ifdef CONFIG_ALTIVEC
  89. extern void flush_altivec_to_thread(struct task_struct *);
  90. #else
  91. static inline void flush_altivec_to_thread(struct task_struct *t)
  92. {
  93. }
  94. #endif
  95. #ifdef CONFIG_SPE
  96. extern void flush_spe_to_thread(struct task_struct *);
  97. #else
  98. static inline void flush_spe_to_thread(struct task_struct *t)
  99. {
  100. }
  101. #endif
  102. extern int call_rtas(const char *, int, int, unsigned long *, ...);
  103. extern void cacheable_memzero(void *p, unsigned int nb);
  104. extern void *cacheable_memcpy(void *, const void *, unsigned int);
  105. extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long);
  106. extern void bad_page_fault(struct pt_regs *, unsigned long, int);
  107. extern int die(const char *, struct pt_regs *, long);
  108. extern void _exception(int, struct pt_regs *, int, unsigned long);
  109. void _nmask_and_or_msr(unsigned long nmask, unsigned long or_val);
  110. #ifdef CONFIG_BOOKE_WDT
  111. extern u32 booke_wdt_enabled;
  112. extern u32 booke_wdt_period;
  113. #endif /* CONFIG_BOOKE_WDT */
  114. struct device_node;
  115. extern void note_scsi_host(struct device_node *, void *);
  116. extern struct task_struct *__switch_to(struct task_struct *,
  117. struct task_struct *);
  118. #define switch_to(prev, next, last) ((last) = __switch_to((prev), (next)))
  119. struct thread_struct;
  120. extern struct task_struct *_switch(struct thread_struct *prev,
  121. struct thread_struct *next);
  122. extern unsigned int rtas_data;
  123. static __inline__ unsigned long
  124. xchg_u32(volatile void *p, unsigned long val)
  125. {
  126. unsigned long prev;
  127. __asm__ __volatile__ ("\n\
  128. 1: lwarx %0,0,%2 \n"
  129. PPC405_ERR77(0,%2)
  130. " stwcx. %3,0,%2 \n\
  131. bne- 1b"
  132. : "=&r" (prev), "=m" (*(volatile unsigned long *)p)
  133. : "r" (p), "r" (val), "m" (*(volatile unsigned long *)p)
  134. : "cc", "memory");
  135. return prev;
  136. }
  137. /*
  138. * This function doesn't exist, so you'll get a linker error
  139. * if something tries to do an invalid xchg().
  140. */
  141. extern void __xchg_called_with_bad_pointer(void);
  142. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  143. static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
  144. {
  145. switch (size) {
  146. case 4:
  147. return (unsigned long) xchg_u32(ptr, x);
  148. #if 0 /* xchg_u64 doesn't exist on 32-bit PPC */
  149. case 8:
  150. return (unsigned long) xchg_u64(ptr, x);
  151. #endif /* 0 */
  152. }
  153. __xchg_called_with_bad_pointer();
  154. return x;
  155. }
  156. extern inline void * xchg_ptr(void * m, void * val)
  157. {
  158. return (void *) xchg_u32(m, (unsigned long) val);
  159. }
  160. #define __HAVE_ARCH_CMPXCHG 1
  161. static __inline__ unsigned long
  162. __cmpxchg_u32(volatile unsigned int *p, unsigned int old, unsigned int new)
  163. {
  164. unsigned int prev;
  165. __asm__ __volatile__ ("\n\
  166. 1: lwarx %0,0,%2 \n\
  167. cmpw 0,%0,%3 \n\
  168. bne 2f \n"
  169. PPC405_ERR77(0,%2)
  170. " stwcx. %4,0,%2 \n\
  171. bne- 1b\n"
  172. #ifdef CONFIG_SMP
  173. " sync\n"
  174. #endif /* CONFIG_SMP */
  175. "2:"
  176. : "=&r" (prev), "=m" (*p)
  177. : "r" (p), "r" (old), "r" (new), "m" (*p)
  178. : "cc", "memory");
  179. return prev;
  180. }
  181. static inline unsigned long
  182. __cmpxchg_u32_local(volatile unsigned int *p, unsigned int old,
  183. unsigned int new)
  184. {
  185. unsigned int prev;
  186. __asm__ __volatile__ ("\n\
  187. 1: lwarx %0,0,%2 \n\
  188. cmpw 0,%0,%3 \n\
  189. bne 2f \n"
  190. PPC405_ERR77(0,%2)
  191. " stwcx. %4,0,%2 \n\
  192. bne- 1b\n"
  193. "2:"
  194. : "=&r" (prev), "=m" (*p)
  195. : "r" (p), "r" (old), "r" (new), "m" (*p)
  196. : "cc", "memory");
  197. return prev;
  198. }
  199. /* This function doesn't exist, so you'll get a linker error
  200. if something tries to do an invalid cmpxchg(). */
  201. extern void __cmpxchg_called_with_bad_pointer(void);
  202. static __inline__ unsigned long
  203. __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new,
  204. unsigned int size)
  205. {
  206. switch (size) {
  207. case 4:
  208. return __cmpxchg_u32(ptr, old, new);
  209. #if 0 /* we don't have __cmpxchg_u64 on 32-bit PPC */
  210. case 8:
  211. return __cmpxchg_u64(ptr, old, new);
  212. #endif /* 0 */
  213. }
  214. __cmpxchg_called_with_bad_pointer();
  215. return old;
  216. }
  217. #define cmpxchg(ptr, o, n) \
  218. ({ \
  219. __typeof__(*(ptr)) _o_ = (o); \
  220. __typeof__(*(ptr)) _n_ = (n); \
  221. (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
  222. (unsigned long)_n_, sizeof(*(ptr))); \
  223. })
  224. #include <asm-generic/cmpxchg-local.h>
  225. static inline unsigned long __cmpxchg_local(volatile void *ptr,
  226. unsigned long old,
  227. unsigned long new, int size)
  228. {
  229. switch (size) {
  230. case 4:
  231. return __cmpxchg_u32_local(ptr, old, new);
  232. default:
  233. return __cmpxchg_local_generic(ptr, old, new, size);
  234. }
  235. return old;
  236. }
  237. /*
  238. * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
  239. * them available.
  240. */
  241. #define cmpxchg_local(ptr, o, n) \
  242. ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \
  243. (unsigned long)(n), sizeof(*(ptr))))
  244. #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
  245. #define arch_align_stack(x) (x)
  246. #endif /* __KERNEL__ */
  247. #endif /* __PPC_SYSTEM_H */