processor.h 16 KB

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