processor.h 13 KB

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