processor.h 8.1 KB

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