processor.h 15 KB

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