processor.h 8.1 KB

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