processor.h 8.0 KB

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