system.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:7k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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/kdev_t.h>
  11. #include <asm/page.h>
  12. #include <asm/processor.h>
  13. #include <asm/hw_irq.h>
  14. #include <asm/memory.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.  *
  27.  * We can use the eieio instruction for wmb, but since it doesn't
  28.  * give any ordering guarantees about loads, we have to use the
  29.  * stronger but slower sync instruction for mb and rmb.
  30.  */
  31. #define mb()   __asm__ __volatile__ ("sync" : : : "memory")
  32. #define rmb()  __asm__ __volatile__ ("lwsync" : : : "memory")
  33. #define wmb()  __asm__ __volatile__ ("eieio" : : : "memory")
  34. #define set_mb(var, value) do { var = value; mb(); } while (0)
  35. #define set_wmb(var, value) do { var = value; wmb(); } while (0)
  36. #ifdef CONFIG_SMP
  37. #define smp_mb() mb()
  38. #define smp_rmb() rmb()
  39. #define smp_wmb() wmb()
  40. #else
  41. #define smp_mb() __asm__ __volatile__("": : :"memory")
  42. #define smp_rmb() __asm__ __volatile__("": : :"memory")
  43. #define smp_wmb() __asm__ __volatile__("": : :"memory")
  44. #endif /* CONFIG_SMP */
  45. #ifdef CONFIG_XMON
  46. extern void xmon_irq(int, void *, struct pt_regs *);
  47. extern void xmon(struct pt_regs *excp);
  48. #endif
  49. extern void print_backtrace(unsigned long *);
  50. extern void show_regs(struct pt_regs * regs);
  51. extern void flush_instruction_cache(void);
  52. extern void hard_reset_now(void);
  53. extern void poweroff_now(void);
  54. extern int _get_PVR(void);
  55. extern long _get_L2CR(void);
  56. extern void _set_L2CR(unsigned long);
  57. extern void giveup_fpu(struct task_struct *);
  58. extern void enable_kernel_fp(void);
  59. extern void cvt_fd(float *from, double *to, unsigned long *fpscr);
  60. extern void cvt_df(double *from, float *to, unsigned long *fpscr);
  61. extern int abs(int);
  62. extern void cacheable_memzero(void *p, unsigned int nb);
  63. struct device_node;
  64. struct task_struct;
  65. #define prepare_to_switch() do { } while(0)
  66. #define switch_to(prev,next,last) _switch_to((prev),(next),&(last))
  67. extern void _switch_to(struct task_struct *, struct task_struct *,
  68.        struct task_struct **);
  69. struct thread_struct;
  70. extern struct task_struct *_switch(struct thread_struct *prev,
  71.    struct thread_struct *next);
  72. struct pt_regs;
  73. extern void dump_regs(struct pt_regs *);
  74. #ifndef CONFIG_SMP
  75. #define cli() __cli()
  76. #define sti() __sti()
  77. #define save_flags(flags) __save_flags(flags)
  78. #define restore_flags(flags) __restore_flags(flags)
  79. #define save_and_cli(flags) __save_and_cli(flags)
  80. #else /* CONFIG_SMP */
  81. extern void __global_cli(void);
  82. extern void __global_sti(void);
  83. extern unsigned long __global_save_flags(void);
  84. extern void __global_restore_flags(unsigned long);
  85. #define cli() __global_cli()
  86. #define sti() __global_sti()
  87. #define save_flags(x) ((x)=__global_save_flags())
  88. #define restore_flags(x) __global_restore_flags(x)
  89. #endif /* !CONFIG_SMP */
  90. #define local_irq_disable() __cli()
  91. #define local_irq_enable() __sti()
  92. #define local_irq_save(flags) __save_and_cli(flags)
  93. #define local_irq_restore(flags) __restore_flags(flags)
  94. static __inline__ int __is_processor(unsigned long pv)
  95. {
  96.       unsigned long pvr;
  97.       asm volatile("mfspr %0, 0x11F" : "=r" (pvr)); 
  98.       return(PVR_VER(pvr) == pv);
  99. }
  100. /*
  101.  * Atomic exchange
  102.  *
  103.  * Changes the memory location '*ptr' to be val and returns
  104.  * the previous value stored there.
  105.  *
  106.  * Inline asm pulled from arch/ppc/kernel/misc.S so ppc64
  107.  * is more like most of the other architectures.
  108.  */
  109. static __inline__ unsigned long
  110. __xchg_u32(volatile int *m, unsigned long val)
  111. {
  112. unsigned long dummy;
  113. __asm__ __volatile__(
  114. EIEIO_ON_SMP
  115. "1: lwarx %0,0,%3 # __xchg_u32n
  116. stwcx. %2,0,%3n
  117. 2: bne- 1b"
  118. ISYNC_ON_SMP
  119.   : "=&r" (dummy), "=m" (*m)
  120. : "r" (val), "r" (m)
  121. : "cc", "memory");
  122. return (dummy);
  123. }
  124. static __inline__ unsigned long
  125. __xchg_u64(volatile long *m, unsigned long val)
  126. {
  127. unsigned long dummy;
  128. __asm__ __volatile__(
  129. EIEIO_ON_SMP
  130. "1: ldarx %0,0,%3 # __xchg_u64n
  131. stdcx. %2,0,%3n
  132. 2: bne- 1b"
  133. ISYNC_ON_SMP
  134. : "=&r" (dummy), "=m" (*m)
  135. : "r" (val), "r" (m)
  136. : "cc", "memory");
  137. return (dummy);
  138. }
  139. /*
  140.  * This function doesn't exist, so you'll get a linker error
  141.  * if something tries to do an invalid xchg().
  142.  */
  143. extern void __xchg_called_with_bad_pointer(void);
  144. static __inline__ unsigned long
  145. __xchg(volatile void *ptr, unsigned long x, int size)
  146. {
  147. switch (size) {
  148. case 4:
  149. return __xchg_u32(ptr, x);
  150. case 8:
  151. return __xchg_u64(ptr, x);
  152. }
  153. __xchg_called_with_bad_pointer();
  154. return x;
  155. }
  156. #define xchg(ptr,x)      
  157.   ({      
  158.      __typeof__(*(ptr)) _x_ = (x);      
  159.      (__typeof__(*(ptr))) __xchg((ptr), (unsigned long)_x_, sizeof(*(ptr))); 
  160.   })
  161. #define tas(ptr) (xchg((ptr),1))
  162. #define __HAVE_ARCH_CMPXCHG 1
  163. static __inline__ unsigned long
  164. __cmpxchg_u32(volatile int *p, int old, int new)
  165. {
  166. int prev;
  167. __asm__ __volatile__ (
  168. EIEIO_ON_SMP
  169. "1: lwarx %0,0,%2 # __cmpxchg_u32n
  170. cmpw 0,%0,%3n
  171. bne- 2fn
  172. stwcx. %4,0,%2n
  173. bne- 1b"
  174. ISYNC_ON_SMP
  175. "n
  176. 2:"
  177. : "=&r" (prev), "=m" (*p)
  178. : "r" (p), "r" (old), "r" (new), "m" (*p)
  179. : "cc", "memory");
  180. return prev;
  181. }
  182. static __inline__ unsigned long
  183. __cmpxchg_u64(volatile long *p, unsigned long old, unsigned long new)
  184. {
  185. int prev;
  186. __asm__ __volatile__ (
  187. EIEIO_ON_SMP
  188. "1: ldarx %0,0,%2 # __cmpxchg_u64n
  189. cmpd 0,%0,%3n
  190. bne- 2fn
  191. stdcx. %4,0,%2n
  192. bne- 1b"
  193. ISYNC_ON_SMP
  194. "n
  195. 2:"
  196. : "=&r" (prev), "=m" (*p)
  197. : "r" (p), "r" (old), "r" (new), "m" (*p)
  198. : "cc", "memory");
  199. return prev;
  200. }
  201. /* This function doesn't exist, so you'll get a linker error
  202.    if something tries to do an invalid cmpxchg().  */
  203. extern void __cmpxchg_called_with_bad_pointer(void);
  204. static __inline__ unsigned long
  205. __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
  206. {
  207. switch (size) {
  208. case 4:
  209. return __cmpxchg_u32(ptr, old, new);
  210. case 8:
  211. return __cmpxchg_u64(ptr, old, new);
  212. }
  213. __cmpxchg_called_with_bad_pointer();
  214. return old;
  215. }
  216. #define cmpxchg(ptr,o,n)  
  217.   ({  
  218.      __typeof__(*(ptr)) _o_ = (o);  
  219.      __typeof__(*(ptr)) _n_ = (n);  
  220.      (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,  
  221.     (unsigned long)_n_, sizeof(*(ptr))); 
  222.   })
  223. #endif