processor.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. #ifndef _ASM_POWERPC_PROCESSOR_H
  2. #define _ASM_POWERPC_PROCESSOR_H
  3. /*
  4. * Copyright (C) 2001 PPC 64 Team, IBM Corp
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #include <asm/reg.h>
  12. #ifdef CONFIG_VSX
  13. #define TS_FPRWIDTH 2
  14. #else
  15. #define TS_FPRWIDTH 1
  16. #endif
  17. #ifndef __ASSEMBLY__
  18. #include <linux/compiler.h>
  19. #include <asm/ptrace.h>
  20. #include <asm/types.h>
  21. /* We do _not_ want to define new machine types at all, those must die
  22. * in favor of using the device-tree
  23. * -- BenH.
  24. */
  25. /* PREP sub-platform types see residual.h for these */
  26. #define _PREP_Motorola 0x01 /* motorola prep */
  27. #define _PREP_Firm 0x02 /* firmworks prep */
  28. #define _PREP_IBM 0x00 /* ibm prep */
  29. #define _PREP_Bull 0x03 /* bull prep */
  30. /* CHRP sub-platform types. These are arbitrary */
  31. #define _CHRP_Motorola 0x04 /* motorola chrp, the cobra */
  32. #define _CHRP_IBM 0x05 /* IBM chrp, the longtrail and longtrail 2 */
  33. #define _CHRP_Pegasos 0x06 /* Genesi/bplan's Pegasos and Pegasos2 */
  34. #define _CHRP_briq 0x07 /* TotalImpact's briQ */
  35. #if defined(__KERNEL__) && defined(CONFIG_PPC32)
  36. extern int _chrp_type;
  37. #ifdef CONFIG_PPC_PREP
  38. /* what kind of prep workstation we are */
  39. extern int _prep_type;
  40. #endif /* CONFIG_PPC_PREP */
  41. #endif /* defined(__KERNEL__) && defined(CONFIG_PPC32) */
  42. /*
  43. * Default implementation of macro that returns current
  44. * instruction pointer ("program counter").
  45. */
  46. #define current_text_addr() ({ __label__ _l; _l: &&_l;})
  47. /* Macros for adjusting thread priority (hardware multi-threading) */
  48. #define HMT_very_low() asm volatile("or 31,31,31 # very low priority")
  49. #define HMT_low() asm volatile("or 1,1,1 # low priority")
  50. #define HMT_medium_low() asm volatile("or 6,6,6 # medium low priority")
  51. #define HMT_medium() asm volatile("or 2,2,2 # medium priority")
  52. #define HMT_medium_high() asm volatile("or 5,5,5 # medium high priority")
  53. #define HMT_high() asm volatile("or 3,3,3 # high priority")
  54. #ifdef __KERNEL__
  55. struct task_struct;
  56. void start_thread(struct pt_regs *regs, unsigned long fdptr, unsigned long sp);
  57. void release_thread(struct task_struct *);
  58. /* Prepare to copy thread state - unlazy all lazy status */
  59. extern void prepare_to_copy(struct task_struct *tsk);
  60. /* Create a new kernel thread. */
  61. extern long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
  62. /* Lazy FPU handling on uni-processor */
  63. extern struct task_struct *last_task_used_math;
  64. extern struct task_struct *last_task_used_altivec;
  65. extern struct task_struct *last_task_used_vsx;
  66. extern struct task_struct *last_task_used_spe;
  67. #ifdef CONFIG_PPC32
  68. #if CONFIG_TASK_SIZE > CONFIG_KERNEL_START
  69. #error User TASK_SIZE overlaps with KERNEL_START address
  70. #endif
  71. #define TASK_SIZE (CONFIG_TASK_SIZE)
  72. /* This decides where the kernel will search for a free chunk of vm
  73. * space during mmap's.
  74. */
  75. #define TASK_UNMAPPED_BASE (TASK_SIZE / 8 * 3)
  76. #endif
  77. #ifdef CONFIG_PPC64
  78. /* 64-bit user address space is 44-bits (16TB user VM) */
  79. #define TASK_SIZE_USER64 (0x0000100000000000UL)
  80. /*
  81. * 32-bit user address space is 4GB - 1 page
  82. * (this 1 page is needed so referencing of 0xFFFFFFFF generates EFAULT
  83. */
  84. #define TASK_SIZE_USER32 (0x0000000100000000UL - (1*PAGE_SIZE))
  85. #define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
  86. TASK_SIZE_USER32 : TASK_SIZE_USER64)
  87. #define TASK_SIZE TASK_SIZE_OF(current)
  88. /* This decides where the kernel will search for a free chunk of vm
  89. * space during mmap's.
  90. */
  91. #define TASK_UNMAPPED_BASE_USER32 (PAGE_ALIGN(TASK_SIZE_USER32 / 4))
  92. #define TASK_UNMAPPED_BASE_USER64 (PAGE_ALIGN(TASK_SIZE_USER64 / 4))
  93. #define TASK_UNMAPPED_BASE ((test_thread_flag(TIF_32BIT)) ? \
  94. TASK_UNMAPPED_BASE_USER32 : TASK_UNMAPPED_BASE_USER64 )
  95. #endif
  96. #ifdef __KERNEL__
  97. #ifdef __powerpc64__
  98. #define STACK_TOP_USER64 TASK_SIZE_USER64
  99. #define STACK_TOP_USER32 TASK_SIZE_USER32
  100. #define STACK_TOP (test_thread_flag(TIF_32BIT) ? \
  101. STACK_TOP_USER32 : STACK_TOP_USER64)
  102. #define STACK_TOP_MAX STACK_TOP_USER64
  103. #else /* __powerpc64__ */
  104. #define STACK_TOP TASK_SIZE
  105. #define STACK_TOP_MAX STACK_TOP
  106. #endif /* __powerpc64__ */
  107. #endif /* __KERNEL__ */
  108. typedef struct {
  109. unsigned long seg;
  110. } mm_segment_t;
  111. #define TS_FPROFFSET 0
  112. #define TS_VSRLOWOFFSET 1
  113. #define TS_FPR(i) fpr[i][TS_FPROFFSET]
  114. struct thread_struct {
  115. unsigned long ksp; /* Kernel stack pointer */
  116. unsigned long ksp_limit; /* if ksp <= ksp_limit stack overflow */
  117. #ifdef CONFIG_PPC64
  118. unsigned long ksp_vsid;
  119. #endif
  120. struct pt_regs *regs; /* Pointer to saved register state */
  121. mm_segment_t fs; /* for get_fs() validation */
  122. #ifdef CONFIG_PPC32
  123. void *pgdir; /* root of page-table tree */
  124. #endif
  125. #if defined(CONFIG_4xx) || defined (CONFIG_BOOKE)
  126. unsigned long dbcr0; /* debug control register values */
  127. unsigned long dbcr1;
  128. #endif
  129. /* FP and VSX 0-31 register set */
  130. double fpr[32][TS_FPRWIDTH];
  131. struct {
  132. unsigned int pad;
  133. unsigned int val; /* Floating point status */
  134. } fpscr;
  135. int fpexc_mode; /* floating-point exception mode */
  136. unsigned int align_ctl; /* alignment handling control */
  137. #ifdef CONFIG_PPC64
  138. unsigned long start_tb; /* Start purr when proc switched in */
  139. unsigned long accum_tb; /* Total accumilated purr for process */
  140. #endif
  141. unsigned long dabr; /* Data address breakpoint register */
  142. #ifdef CONFIG_ALTIVEC
  143. /* Complete AltiVec register set */
  144. vector128 vr[32] __attribute__((aligned(16)));
  145. /* AltiVec status */
  146. vector128 vscr __attribute__((aligned(16)));
  147. unsigned long vrsave;
  148. int used_vr; /* set if process has used altivec */
  149. #endif /* CONFIG_ALTIVEC */
  150. #ifdef CONFIG_VSX
  151. /* VSR status */
  152. int used_vsr; /* set if process has used altivec */
  153. #endif /* CONFIG_VSX */
  154. #ifdef CONFIG_SPE
  155. unsigned long evr[32]; /* upper 32-bits of SPE regs */
  156. u64 acc; /* Accumulator */
  157. unsigned long spefscr; /* SPE & eFP status */
  158. int used_spe; /* set if process has used spe */
  159. #endif /* CONFIG_SPE */
  160. };
  161. #define ARCH_MIN_TASKALIGN 16
  162. #define INIT_SP (sizeof(init_stack) + (unsigned long) &init_stack)
  163. #define INIT_SP_LIMIT \
  164. (_ALIGN_UP(sizeof(init_thread_info), 16) + (unsigned long) &init_stack)
  165. #ifdef CONFIG_SPE
  166. #define SPEFSCR_INIT .spefscr = SPEFSCR_FINVE | SPEFSCR_FDBZE | SPEFSCR_FUNFE | SPEFSCR_FOVFE,
  167. #else
  168. #define SPEFSCR_INIT
  169. #endif
  170. #ifdef CONFIG_PPC32
  171. #define INIT_THREAD { \
  172. .ksp = INIT_SP, \
  173. .ksp_limit = INIT_SP_LIMIT, \
  174. .fs = KERNEL_DS, \
  175. .pgdir = swapper_pg_dir, \
  176. .fpexc_mode = MSR_FE0 | MSR_FE1, \
  177. SPEFSCR_INIT \
  178. }
  179. #else
  180. #define INIT_THREAD { \
  181. .ksp = INIT_SP, \
  182. .ksp_limit = INIT_SP_LIMIT, \
  183. .regs = (struct pt_regs *)INIT_SP - 1, /* XXX bogus, I think */ \
  184. .fs = KERNEL_DS, \
  185. .fpr = {{0}}, \
  186. .fpscr = { .val = 0, }, \
  187. .fpexc_mode = 0, \
  188. }
  189. #endif
  190. /*
  191. * Return saved PC of a blocked thread. For now, this is the "user" PC
  192. */
  193. #define thread_saved_pc(tsk) \
  194. ((tsk)->thread.regs? (tsk)->thread.regs->nip: 0)
  195. #define task_pt_regs(tsk) ((struct pt_regs *)(tsk)->thread.regs)
  196. unsigned long get_wchan(struct task_struct *p);
  197. #define KSTK_EIP(tsk) ((tsk)->thread.regs? (tsk)->thread.regs->nip: 0)
  198. #define KSTK_ESP(tsk) ((tsk)->thread.regs? (tsk)->thread.regs->gpr[1]: 0)
  199. /* Get/set floating-point exception mode */
  200. #define GET_FPEXC_CTL(tsk, adr) get_fpexc_mode((tsk), (adr))
  201. #define SET_FPEXC_CTL(tsk, val) set_fpexc_mode((tsk), (val))
  202. extern int get_fpexc_mode(struct task_struct *tsk, unsigned long adr);
  203. extern int set_fpexc_mode(struct task_struct *tsk, unsigned int val);
  204. #define GET_ENDIAN(tsk, adr) get_endian((tsk), (adr))
  205. #define SET_ENDIAN(tsk, val) set_endian((tsk), (val))
  206. extern int get_endian(struct task_struct *tsk, unsigned long adr);
  207. extern int set_endian(struct task_struct *tsk, unsigned int val);
  208. #define GET_UNALIGN_CTL(tsk, adr) get_unalign_ctl((tsk), (adr))
  209. #define SET_UNALIGN_CTL(tsk, val) set_unalign_ctl((tsk), (val))
  210. extern int get_unalign_ctl(struct task_struct *tsk, unsigned long adr);
  211. extern int set_unalign_ctl(struct task_struct *tsk, unsigned int val);
  212. static inline unsigned int __unpack_fe01(unsigned long msr_bits)
  213. {
  214. return ((msr_bits & MSR_FE0) >> 10) | ((msr_bits & MSR_FE1) >> 8);
  215. }
  216. static inline unsigned long __pack_fe01(unsigned int fpmode)
  217. {
  218. return ((fpmode << 10) & MSR_FE0) | ((fpmode << 8) & MSR_FE1);
  219. }
  220. #ifdef CONFIG_PPC64
  221. #define cpu_relax() do { HMT_low(); HMT_medium(); barrier(); } while (0)
  222. #else
  223. #define cpu_relax() barrier()
  224. #endif
  225. /* Check that a certain kernel stack pointer is valid in task_struct p */
  226. int validate_sp(unsigned long sp, struct task_struct *p,
  227. unsigned long nbytes);
  228. /*
  229. * Prefetch macros.
  230. */
  231. #define ARCH_HAS_PREFETCH
  232. #define ARCH_HAS_PREFETCHW
  233. #define ARCH_HAS_SPINLOCK_PREFETCH
  234. static inline void prefetch(const void *x)
  235. {
  236. if (unlikely(!x))
  237. return;
  238. __asm__ __volatile__ ("dcbt 0,%0" : : "r" (x));
  239. }
  240. static inline void prefetchw(const void *x)
  241. {
  242. if (unlikely(!x))
  243. return;
  244. __asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x));
  245. }
  246. #define spin_lock_prefetch(x) prefetchw(x)
  247. #ifdef CONFIG_PPC64
  248. #define HAVE_ARCH_PICK_MMAP_LAYOUT
  249. #endif
  250. #endif /* __KERNEL__ */
  251. #endif /* __ASSEMBLY__ */
  252. #endif /* _ASM_POWERPC_PROCESSOR_H */