processor.h 14 KB

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