processor.h 8.6 KB

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