processor.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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 <linux/cache.h>
  20. #include <asm/ptrace.h>
  21. #include <asm/types.h>
  22. /* We do _not_ want to define new machine types at all, those must die
  23. * in favor of using the device-tree
  24. * -- BenH.
  25. */
  26. /* PREP sub-platform types see residual.h for these */
  27. #define _PREP_Motorola 0x01 /* motorola prep */
  28. #define _PREP_Firm 0x02 /* firmworks prep */
  29. #define _PREP_IBM 0x00 /* ibm prep */
  30. #define _PREP_Bull 0x03 /* bull prep */
  31. /* CHRP sub-platform types. These are arbitrary */
  32. #define _CHRP_Motorola 0x04 /* motorola chrp, the cobra */
  33. #define _CHRP_IBM 0x05 /* IBM chrp, the longtrail and longtrail 2 */
  34. #define _CHRP_Pegasos 0x06 /* Genesi/bplan's Pegasos and Pegasos2 */
  35. #define _CHRP_briq 0x07 /* TotalImpact's briQ */
  36. #if defined(__KERNEL__) && defined(CONFIG_PPC32)
  37. extern int _chrp_type;
  38. #ifdef CONFIG_PPC_PREP
  39. /* what kind of prep workstation we are */
  40. extern int _prep_type;
  41. #endif /* CONFIG_PPC_PREP */
  42. #endif /* defined(__KERNEL__) && defined(CONFIG_PPC32) */
  43. /*
  44. * Default implementation of macro that returns current
  45. * instruction pointer ("program counter").
  46. */
  47. #define current_text_addr() ({ __label__ _l; _l: &&_l;})
  48. /* Macros for adjusting thread priority (hardware multi-threading) */
  49. #define HMT_very_low() asm volatile("or 31,31,31 # very low priority")
  50. #define HMT_low() asm volatile("or 1,1,1 # low priority")
  51. #define HMT_medium_low() asm volatile("or 6,6,6 # medium low priority")
  52. #define HMT_medium() asm volatile("or 2,2,2 # medium priority")
  53. #define HMT_medium_high() asm volatile("or 5,5,5 # medium high priority")
  54. #define HMT_high() asm volatile("or 3,3,3 # high priority")
  55. #ifdef __KERNEL__
  56. struct task_struct;
  57. void start_thread(struct pt_regs *regs, unsigned long fdptr, unsigned long sp);
  58. void release_thread(struct task_struct *);
  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_vsx;
  63. extern struct task_struct *last_task_used_spe;
  64. #ifdef CONFIG_PPC32
  65. #if CONFIG_TASK_SIZE > CONFIG_KERNEL_START
  66. #error User TASK_SIZE overlaps with KERNEL_START address
  67. #endif
  68. #define TASK_SIZE (CONFIG_TASK_SIZE)
  69. /* This decides where the kernel will search for a free chunk of vm
  70. * space during mmap's.
  71. */
  72. #define TASK_UNMAPPED_BASE (TASK_SIZE / 8 * 3)
  73. #endif
  74. #ifdef CONFIG_PPC64
  75. /* 64-bit user address space is 46-bits (64TB user VM) */
  76. #define TASK_SIZE_USER64 (0x0000400000000000UL)
  77. /*
  78. * 32-bit user address space is 4GB - 1 page
  79. * (this 1 page is needed so referencing of 0xFFFFFFFF generates EFAULT
  80. */
  81. #define TASK_SIZE_USER32 (0x0000000100000000UL - (1*PAGE_SIZE))
  82. #define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
  83. TASK_SIZE_USER32 : TASK_SIZE_USER64)
  84. #define TASK_SIZE TASK_SIZE_OF(current)
  85. /* This decides where the kernel will search for a free chunk of vm
  86. * space during mmap's.
  87. */
  88. #define TASK_UNMAPPED_BASE_USER32 (PAGE_ALIGN(TASK_SIZE_USER32 / 4))
  89. #define TASK_UNMAPPED_BASE_USER64 (PAGE_ALIGN(TASK_SIZE_USER64 / 4))
  90. #define TASK_UNMAPPED_BASE ((is_32bit_task()) ? \
  91. TASK_UNMAPPED_BASE_USER32 : TASK_UNMAPPED_BASE_USER64 )
  92. #endif
  93. #ifdef __powerpc64__
  94. #define STACK_TOP_USER64 TASK_SIZE_USER64
  95. #define STACK_TOP_USER32 TASK_SIZE_USER32
  96. #define STACK_TOP (is_32bit_task() ? \
  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. typedef struct {
  104. unsigned long seg;
  105. } mm_segment_t;
  106. #define TS_FPROFFSET 0
  107. #define TS_VSRLOWOFFSET 1
  108. #define TS_FPR(i) fpr[i][TS_FPROFFSET]
  109. struct thread_struct {
  110. unsigned long ksp; /* Kernel stack pointer */
  111. unsigned long ksp_limit; /* if ksp <= ksp_limit stack overflow */
  112. #ifdef CONFIG_PPC64
  113. unsigned long ksp_vsid;
  114. #endif
  115. struct pt_regs *regs; /* Pointer to saved register state */
  116. mm_segment_t fs; /* for get_fs() validation */
  117. #ifdef CONFIG_BOOKE
  118. /* BookE base exception scratch space; align on cacheline */
  119. unsigned long normsave[8] ____cacheline_aligned;
  120. #endif
  121. #ifdef CONFIG_PPC32
  122. void *pgdir; /* root of page-table tree */
  123. #endif
  124. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  125. /*
  126. * The following help to manage the use of Debug Control Registers
  127. * om the BookE platforms.
  128. */
  129. unsigned long dbcr0;
  130. unsigned long dbcr1;
  131. #ifdef CONFIG_BOOKE
  132. unsigned long dbcr2;
  133. #endif
  134. /*
  135. * The stored value of the DBSR register will be the value at the
  136. * last debug interrupt. This register can only be read from the
  137. * user (will never be written to) and has value while helping to
  138. * describe the reason for the last debug trap. Torez
  139. */
  140. unsigned long dbsr;
  141. /*
  142. * The following will contain addresses used by debug applications
  143. * to help trace and trap on particular address locations.
  144. * The bits in the Debug Control Registers above help define which
  145. * of the following registers will contain valid data and/or addresses.
  146. */
  147. unsigned long iac1;
  148. unsigned long iac2;
  149. #if CONFIG_PPC_ADV_DEBUG_IACS > 2
  150. unsigned long iac3;
  151. unsigned long iac4;
  152. #endif
  153. unsigned long dac1;
  154. unsigned long dac2;
  155. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  156. unsigned long dvc1;
  157. unsigned long dvc2;
  158. #endif
  159. #endif
  160. /* FP and VSX 0-31 register set */
  161. double fpr[32][TS_FPRWIDTH];
  162. struct {
  163. unsigned int pad;
  164. unsigned int val; /* Floating point status */
  165. } fpscr;
  166. int fpexc_mode; /* floating-point exception mode */
  167. unsigned int align_ctl; /* alignment handling control */
  168. #ifdef CONFIG_PPC64
  169. unsigned long start_tb; /* Start purr when proc switched in */
  170. unsigned long accum_tb; /* Total accumilated purr for process */
  171. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  172. struct perf_event *ptrace_bps[HBP_NUM];
  173. /*
  174. * Helps identify source of single-step exception and subsequent
  175. * hw-breakpoint enablement
  176. */
  177. struct perf_event *last_hit_ubp;
  178. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  179. #endif
  180. unsigned long dabr; /* Data address breakpoint register */
  181. unsigned long dabrx; /* ... extension */
  182. unsigned long trap_nr; /* last trap # on this thread */
  183. #ifdef CONFIG_ALTIVEC
  184. /* Complete AltiVec register set */
  185. vector128 vr[32] __attribute__((aligned(16)));
  186. /* AltiVec status */
  187. vector128 vscr __attribute__((aligned(16)));
  188. unsigned long vrsave;
  189. int used_vr; /* set if process has used altivec */
  190. #endif /* CONFIG_ALTIVEC */
  191. #ifdef CONFIG_VSX
  192. /* VSR status */
  193. int used_vsr; /* set if process has used altivec */
  194. #endif /* CONFIG_VSX */
  195. #ifdef CONFIG_SPE
  196. unsigned long evr[32]; /* upper 32-bits of SPE regs */
  197. u64 acc; /* Accumulator */
  198. unsigned long spefscr; /* SPE & eFP status */
  199. int used_spe; /* set if process has used spe */
  200. #endif /* CONFIG_SPE */
  201. #ifdef CONFIG_KVM_BOOK3S_32_HANDLER
  202. void* kvm_shadow_vcpu; /* KVM internal data */
  203. #endif /* CONFIG_KVM_BOOK3S_32_HANDLER */
  204. #if defined(CONFIG_KVM) && defined(CONFIG_BOOKE)
  205. struct kvm_vcpu *kvm_vcpu;
  206. #endif
  207. #ifdef CONFIG_PPC64
  208. unsigned long dscr;
  209. int dscr_inherit;
  210. #endif
  211. };
  212. #define ARCH_MIN_TASKALIGN 16
  213. #define INIT_SP (sizeof(init_stack) + (unsigned long) &init_stack)
  214. #define INIT_SP_LIMIT \
  215. (_ALIGN_UP(sizeof(init_thread_info), 16) + (unsigned long) &init_stack)
  216. #ifdef CONFIG_SPE
  217. #define SPEFSCR_INIT .spefscr = SPEFSCR_FINVE | SPEFSCR_FDBZE | SPEFSCR_FUNFE | SPEFSCR_FOVFE,
  218. #else
  219. #define SPEFSCR_INIT
  220. #endif
  221. #ifdef CONFIG_PPC32
  222. #define INIT_THREAD { \
  223. .ksp = INIT_SP, \
  224. .ksp_limit = INIT_SP_LIMIT, \
  225. .fs = KERNEL_DS, \
  226. .pgdir = swapper_pg_dir, \
  227. .fpexc_mode = MSR_FE0 | MSR_FE1, \
  228. SPEFSCR_INIT \
  229. }
  230. #else
  231. #define INIT_THREAD { \
  232. .ksp = INIT_SP, \
  233. .ksp_limit = INIT_SP_LIMIT, \
  234. .regs = (struct pt_regs *)INIT_SP - 1, /* XXX bogus, I think */ \
  235. .fs = KERNEL_DS, \
  236. .fpr = {{0}}, \
  237. .fpscr = { .val = 0, }, \
  238. .fpexc_mode = 0, \
  239. }
  240. #endif
  241. /*
  242. * Return saved PC of a blocked thread. For now, this is the "user" PC
  243. */
  244. #define thread_saved_pc(tsk) \
  245. ((tsk)->thread.regs? (tsk)->thread.regs->nip: 0)
  246. #define task_pt_regs(tsk) ((struct pt_regs *)(tsk)->thread.regs)
  247. unsigned long get_wchan(struct task_struct *p);
  248. #define KSTK_EIP(tsk) ((tsk)->thread.regs? (tsk)->thread.regs->nip: 0)
  249. #define KSTK_ESP(tsk) ((tsk)->thread.regs? (tsk)->thread.regs->gpr[1]: 0)
  250. /* Get/set floating-point exception mode */
  251. #define GET_FPEXC_CTL(tsk, adr) get_fpexc_mode((tsk), (adr))
  252. #define SET_FPEXC_CTL(tsk, val) set_fpexc_mode((tsk), (val))
  253. extern int get_fpexc_mode(struct task_struct *tsk, unsigned long adr);
  254. extern int set_fpexc_mode(struct task_struct *tsk, unsigned int val);
  255. #define GET_ENDIAN(tsk, adr) get_endian((tsk), (adr))
  256. #define SET_ENDIAN(tsk, val) set_endian((tsk), (val))
  257. extern int get_endian(struct task_struct *tsk, unsigned long adr);
  258. extern int set_endian(struct task_struct *tsk, unsigned int val);
  259. #define GET_UNALIGN_CTL(tsk, adr) get_unalign_ctl((tsk), (adr))
  260. #define SET_UNALIGN_CTL(tsk, val) set_unalign_ctl((tsk), (val))
  261. extern int get_unalign_ctl(struct task_struct *tsk, unsigned long adr);
  262. extern int set_unalign_ctl(struct task_struct *tsk, unsigned int val);
  263. static inline unsigned int __unpack_fe01(unsigned long msr_bits)
  264. {
  265. return ((msr_bits & MSR_FE0) >> 10) | ((msr_bits & MSR_FE1) >> 8);
  266. }
  267. static inline unsigned long __pack_fe01(unsigned int fpmode)
  268. {
  269. return ((fpmode << 10) & MSR_FE0) | ((fpmode << 8) & MSR_FE1);
  270. }
  271. #ifdef CONFIG_PPC64
  272. #define cpu_relax() do { HMT_low(); HMT_medium(); barrier(); } while (0)
  273. #else
  274. #define cpu_relax() barrier()
  275. #endif
  276. /* Check that a certain kernel stack pointer is valid in task_struct p */
  277. int validate_sp(unsigned long sp, struct task_struct *p,
  278. unsigned long nbytes);
  279. /*
  280. * Prefetch macros.
  281. */
  282. #define ARCH_HAS_PREFETCH
  283. #define ARCH_HAS_PREFETCHW
  284. #define ARCH_HAS_SPINLOCK_PREFETCH
  285. static inline void prefetch(const void *x)
  286. {
  287. if (unlikely(!x))
  288. return;
  289. __asm__ __volatile__ ("dcbt 0,%0" : : "r" (x));
  290. }
  291. static inline void prefetchw(const void *x)
  292. {
  293. if (unlikely(!x))
  294. return;
  295. __asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x));
  296. }
  297. #define spin_lock_prefetch(x) prefetchw(x)
  298. #ifdef CONFIG_PPC64
  299. #define HAVE_ARCH_PICK_MMAP_LAYOUT
  300. #endif
  301. #ifdef CONFIG_PPC64
  302. static inline unsigned long get_clean_sp(struct pt_regs *regs, int is_32)
  303. {
  304. unsigned long sp;
  305. if (is_32)
  306. sp = regs->gpr[1] & 0x0ffffffffUL;
  307. else
  308. sp = regs->gpr[1];
  309. return sp;
  310. }
  311. #else
  312. static inline unsigned long get_clean_sp(struct pt_regs *regs, int is_32)
  313. {
  314. return regs->gpr[1];
  315. }
  316. #endif
  317. extern unsigned long cpuidle_disable;
  318. enum idle_boot_override {IDLE_NO_OVERRIDE = 0, IDLE_POWERSAVE_OFF};
  319. extern int powersave_nap; /* set if nap mode can be used in idle loop */
  320. extern void power7_nap(void);
  321. #ifdef CONFIG_PSERIES_IDLE
  322. extern void update_smt_snooze_delay(int snooze);
  323. #else
  324. static inline void update_smt_snooze_delay(int snooze) {}
  325. #endif
  326. extern void flush_instruction_cache(void);
  327. extern void hard_reset_now(void);
  328. extern void poweroff_now(void);
  329. extern int fix_alignment(struct pt_regs *);
  330. extern void cvt_fd(float *from, double *to);
  331. extern void cvt_df(double *from, float *to);
  332. extern void _nmask_and_or_msr(unsigned long nmask, unsigned long or_val);
  333. #ifdef CONFIG_PPC64
  334. /*
  335. * We handle most unaligned accesses in hardware. On the other hand
  336. * unaligned DMA can be very expensive on some ppc64 IO chips (it does
  337. * powers of 2 writes until it reaches sufficient alignment).
  338. *
  339. * Based on this we disable the IP header alignment in network drivers.
  340. */
  341. #define NET_IP_ALIGN 0
  342. #endif
  343. #endif /* __KERNEL__ */
  344. #endif /* __ASSEMBLY__ */
  345. #endif /* _ASM_POWERPC_PROCESSOR_H */