processor.h 15 KB

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