system.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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/config.h>
  7. #include <linux/kernel.h>
  8. #include <asm/atomic.h>
  9. #include <asm/hw_irq.h>
  10. /*
  11. * Memory barrier.
  12. * The sync instruction guarantees that all memory accesses initiated
  13. * by this processor have been performed (with respect to all other
  14. * mechanisms that access memory). The eieio instruction is a barrier
  15. * providing an ordering (separately) for (a) cacheable stores and (b)
  16. * loads and stores to non-cacheable memory (e.g. I/O devices).
  17. *
  18. * mb() prevents loads and stores being reordered across this point.
  19. * rmb() prevents loads being reordered across this point.
  20. * wmb() prevents stores being reordered across this point.
  21. * read_barrier_depends() prevents data-dependent loads being reordered
  22. * across this point (nop on PPC).
  23. *
  24. * We can use the eieio instruction for wmb, but since it doesn't
  25. * give any ordering guarantees about loads, we have to use the
  26. * stronger but slower sync instruction for mb and rmb.
  27. */
  28. #define mb() __asm__ __volatile__ ("sync" : : : "memory")
  29. #define rmb() __asm__ __volatile__ ("sync" : : : "memory")
  30. #define wmb() __asm__ __volatile__ ("eieio" : : : "memory")
  31. #define read_barrier_depends() do { } while(0)
  32. #define set_mb(var, value) do { var = value; mb(); } while (0)
  33. #define set_wmb(var, value) do { var = value; wmb(); } while (0)
  34. #ifdef CONFIG_SMP
  35. #define smp_mb() mb()
  36. #define smp_rmb() rmb()
  37. #define smp_wmb() wmb()
  38. #define smp_read_barrier_depends() read_barrier_depends()
  39. #else
  40. #define smp_mb() barrier()
  41. #define smp_rmb() barrier()
  42. #define smp_wmb() barrier()
  43. #define smp_read_barrier_depends() do { } while(0)
  44. #endif /* CONFIG_SMP */
  45. #ifdef __KERNEL__
  46. struct task_struct;
  47. struct pt_regs;
  48. extern void print_backtrace(unsigned long *);
  49. extern void show_regs(struct pt_regs * regs);
  50. extern void flush_instruction_cache(void);
  51. extern void hard_reset_now(void);
  52. extern void poweroff_now(void);
  53. #ifdef CONFIG_6xx
  54. extern long _get_L2CR(void);
  55. extern long _get_L3CR(void);
  56. extern void _set_L2CR(unsigned long);
  57. extern void _set_L3CR(unsigned long);
  58. #else
  59. #define _get_L2CR() 0L
  60. #define _get_L3CR() 0L
  61. #define _set_L2CR(val) do { } while(0)
  62. #define _set_L3CR(val) do { } while(0)
  63. #endif
  64. extern void via_cuda_init(void);
  65. extern void pmac_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 enable_kernel_fp(void);
  70. extern void enable_kernel_altivec(void);
  71. extern void giveup_altivec(struct task_struct *);
  72. extern void load_up_altivec(struct task_struct *);
  73. extern void giveup_spe(struct task_struct *);
  74. extern void load_up_spe(struct task_struct *);
  75. extern int fix_alignment(struct pt_regs *);
  76. extern void cvt_fd(float *from, double *to, unsigned long *fpscr);
  77. extern void cvt_df(double *from, float *to, unsigned long *fpscr);
  78. extern int call_rtas(const char *, int, int, unsigned long *, ...);
  79. extern void cacheable_memzero(void *p, unsigned int nb);
  80. extern int do_page_fault(struct pt_regs *, unsigned long, unsigned long);
  81. extern void bad_page_fault(struct pt_regs *, unsigned long, int);
  82. extern void die(const char *, struct pt_regs *, long);
  83. struct device_node;
  84. extern void note_scsi_host(struct device_node *, void *);
  85. extern struct task_struct *__switch_to(struct task_struct *,
  86. struct task_struct *);
  87. #define switch_to(prev, next, last) ((last) = __switch_to((prev), (next)))
  88. struct thread_struct;
  89. extern struct task_struct *_switch(struct thread_struct *prev,
  90. struct thread_struct *next);
  91. extern unsigned int rtas_data;
  92. static __inline__ unsigned long
  93. xchg_u32(volatile void *p, unsigned long val)
  94. {
  95. unsigned long prev;
  96. __asm__ __volatile__ ("\n\
  97. 1: lwarx %0,0,%2 \n"
  98. PPC405_ERR77(0,%2)
  99. " stwcx. %3,0,%2 \n\
  100. bne- 1b"
  101. : "=&r" (prev), "=m" (*(volatile unsigned long *)p)
  102. : "r" (p), "r" (val), "m" (*(volatile unsigned long *)p)
  103. : "cc", "memory");
  104. return prev;
  105. }
  106. /*
  107. * This function doesn't exist, so you'll get a linker error
  108. * if something tries to do an invalid xchg().
  109. */
  110. extern void __xchg_called_with_bad_pointer(void);
  111. #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
  112. #define tas(ptr) (xchg((ptr),1))
  113. static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size)
  114. {
  115. switch (size) {
  116. case 4:
  117. return (unsigned long) xchg_u32(ptr, x);
  118. #if 0 /* xchg_u64 doesn't exist on 32-bit PPC */
  119. case 8:
  120. return (unsigned long) xchg_u64(ptr, x);
  121. #endif /* 0 */
  122. }
  123. __xchg_called_with_bad_pointer();
  124. return x;
  125. }
  126. extern inline void * xchg_ptr(void * m, void * val)
  127. {
  128. return (void *) xchg_u32(m, (unsigned long) val);
  129. }
  130. #define __HAVE_ARCH_CMPXCHG 1
  131. static __inline__ unsigned long
  132. __cmpxchg_u32(volatile unsigned int *p, unsigned int old, unsigned int new)
  133. {
  134. unsigned int prev;
  135. __asm__ __volatile__ ("\n\
  136. 1: lwarx %0,0,%2 \n\
  137. cmpw 0,%0,%3 \n\
  138. bne 2f \n"
  139. PPC405_ERR77(0,%2)
  140. " stwcx. %4,0,%2 \n\
  141. bne- 1b\n"
  142. #ifdef CONFIG_SMP
  143. " sync\n"
  144. #endif /* CONFIG_SMP */
  145. "2:"
  146. : "=&r" (prev), "=m" (*p)
  147. : "r" (p), "r" (old), "r" (new), "m" (*p)
  148. : "cc", "memory");
  149. return prev;
  150. }
  151. /* This function doesn't exist, so you'll get a linker error
  152. if something tries to do an invalid cmpxchg(). */
  153. extern void __cmpxchg_called_with_bad_pointer(void);
  154. static __inline__ unsigned long
  155. __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
  156. {
  157. switch (size) {
  158. case 4:
  159. return __cmpxchg_u32(ptr, old, new);
  160. #if 0 /* we don't have __cmpxchg_u64 on 32-bit PPC */
  161. case 8:
  162. return __cmpxchg_u64(ptr, old, new);
  163. #endif /* 0 */
  164. }
  165. __cmpxchg_called_with_bad_pointer();
  166. return old;
  167. }
  168. #define cmpxchg(ptr,o,n) \
  169. ({ \
  170. __typeof__(*(ptr)) _o_ = (o); \
  171. __typeof__(*(ptr)) _n_ = (n); \
  172. (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
  173. (unsigned long)_n_, sizeof(*(ptr))); \
  174. })
  175. #define arch_align_stack(x) (x)
  176. #endif /* __KERNEL__ */
  177. #endif /* __PPC_SYSTEM_H */