processor.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef _ASM_POWERPC_PROCESSOR_H
  3. #define _ASM_POWERPC_PROCESSOR_H
  4. /*
  5. * Copyright (C) 2001 PPC 64 Team, IBM Corp
  6. */
  7. #include <vdso/processor.h>
  8. #include <asm/reg.h>
  9. #ifdef CONFIG_VSX
  10. #define TS_FPRWIDTH 2
  11. #ifdef __BIG_ENDIAN__
  12. #define TS_FPROFFSET 0
  13. #define TS_VSRLOWOFFSET 1
  14. #else
  15. #define TS_FPROFFSET 1
  16. #define TS_VSRLOWOFFSET 0
  17. #endif
  18. #else
  19. #define TS_FPRWIDTH 1
  20. #define TS_FPROFFSET 0
  21. #endif
  22. #ifdef CONFIG_PPC64
  23. /* Default SMT priority is set to 3. Use 11- 13bits to save priority. */
  24. #define PPR_PRIORITY 3
  25. #ifdef __ASSEMBLY__
  26. #define DEFAULT_PPR (PPR_PRIORITY << 50)
  27. #else
  28. #define DEFAULT_PPR ((u64)PPR_PRIORITY << 50)
  29. #endif /* __ASSEMBLY__ */
  30. #endif /* CONFIG_PPC64 */
  31. #ifndef __ASSEMBLY__
  32. #include <linux/types.h>
  33. #include <linux/thread_info.h>
  34. #include <asm/ptrace.h>
  35. #include <asm/hw_breakpoint.h>
  36. /* We do _not_ want to define new machine types at all, those must die
  37. * in favor of using the device-tree
  38. * -- BenH.
  39. */
  40. /* PREP sub-platform types. Unused */
  41. #define _PREP_Motorola 0x01 /* motorola prep */
  42. #define _PREP_Firm 0x02 /* firmworks prep */
  43. #define _PREP_IBM 0x00 /* ibm prep */
  44. #define _PREP_Bull 0x03 /* bull prep */
  45. /* CHRP sub-platform types. These are arbitrary */
  46. #define _CHRP_Motorola 0x04 /* motorola chrp, the cobra */
  47. #define _CHRP_IBM 0x05 /* IBM chrp, the longtrail and longtrail 2 */
  48. #define _CHRP_Pegasos 0x06 /* Genesi/bplan's Pegasos and Pegasos2 */
  49. #define _CHRP_briq 0x07 /* TotalImpact's briQ */
  50. #if defined(__KERNEL__) && defined(CONFIG_PPC32)
  51. extern int _chrp_type;
  52. #endif /* defined(__KERNEL__) && defined(CONFIG_PPC32) */
  53. #ifdef __KERNEL__
  54. #ifdef CONFIG_PPC64
  55. #include <asm/task_size_64.h>
  56. #else
  57. #include <asm/task_size_32.h>
  58. #endif
  59. struct task_struct;
  60. void start_thread(struct pt_regs *regs, unsigned long fdptr, unsigned long sp);
  61. #define TS_FPR(i) fp_state.fpr[i][TS_FPROFFSET]
  62. #define TS_CKFPR(i) ckfp_state.fpr[i][TS_FPROFFSET]
  63. /* FP and VSX 0-31 register set */
  64. struct thread_fp_state {
  65. u64 fpr[32][TS_FPRWIDTH] __attribute__((aligned(16)));
  66. u64 fpscr; /* Floating point status */
  67. };
  68. /* Complete AltiVec register set including VSCR */
  69. struct thread_vr_state {
  70. vector128 vr[32] __attribute__((aligned(16)));
  71. vector128 vscr __attribute__((aligned(16)));
  72. };
  73. struct debug_reg {
  74. #ifdef CONFIG_PPC_ADV_DEBUG_REGS
  75. /*
  76. * The following help to manage the use of Debug Control Registers
  77. * om the BookE platforms.
  78. */
  79. uint32_t dbcr0;
  80. uint32_t dbcr1;
  81. #ifdef CONFIG_BOOKE
  82. uint32_t dbcr2;
  83. #endif
  84. /*
  85. * The stored value of the DBSR register will be the value at the
  86. * last debug interrupt. This register can only be read from the
  87. * user (will never be written to) and has value while helping to
  88. * describe the reason for the last debug trap. Torez
  89. */
  90. uint32_t dbsr;
  91. /*
  92. * The following will contain addresses used by debug applications
  93. * to help trace and trap on particular address locations.
  94. * The bits in the Debug Control Registers above help define which
  95. * of the following registers will contain valid data and/or addresses.
  96. */
  97. unsigned long iac1;
  98. unsigned long iac2;
  99. #if CONFIG_PPC_ADV_DEBUG_IACS > 2
  100. unsigned long iac3;
  101. unsigned long iac4;
  102. #endif
  103. unsigned long dac1;
  104. unsigned long dac2;
  105. #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
  106. unsigned long dvc1;
  107. unsigned long dvc2;
  108. #endif
  109. #endif
  110. };
  111. struct thread_struct {
  112. unsigned long ksp; /* Kernel stack pointer */
  113. #ifdef CONFIG_PPC64
  114. unsigned long ksp_vsid;
  115. #endif
  116. struct pt_regs *regs; /* Pointer to saved register state */
  117. #ifdef CONFIG_BOOKE
  118. /* BookE base exception scratch space; align on cacheline */
  119. unsigned long normsave[8] ____cacheline_aligned;
  120. #endif
  121. #ifdef CONFIG_PPC32
  122. void *pgdir; /* root of page-table tree */
  123. #ifdef CONFIG_PPC_RTAS
  124. unsigned long rtas_sp; /* stack pointer for when in RTAS */
  125. #endif
  126. #if defined(CONFIG_PPC_BOOK3S_32) && defined(CONFIG_PPC_KUAP)
  127. unsigned long kuap; /* opened segments for user access */
  128. #endif
  129. unsigned long srr0;
  130. unsigned long srr1;
  131. unsigned long dar;
  132. unsigned long dsisr;
  133. #ifdef CONFIG_PPC_BOOK3S_32
  134. unsigned long r0, r3, r4, r5, r6, r8, r9, r11;
  135. unsigned long lr, ctr;
  136. unsigned long sr0;
  137. #endif
  138. #endif /* CONFIG_PPC32 */
  139. #if defined(CONFIG_BOOKE_OR_40x) && defined(CONFIG_PPC_KUAP)
  140. unsigned long pid; /* value written in PID reg. at interrupt exit */
  141. #endif
  142. /* Debug Registers */
  143. struct debug_reg debug;
  144. #ifdef CONFIG_PPC_FPU_REGS
  145. struct thread_fp_state fp_state;
  146. struct thread_fp_state *fp_save_area;
  147. #endif
  148. int fpexc_mode; /* floating-point exception mode */
  149. unsigned int align_ctl; /* alignment handling control */
  150. #ifdef CONFIG_HAVE_HW_BREAKPOINT
  151. struct perf_event *ptrace_bps[HBP_NUM_MAX];
  152. /*
  153. * Helps identify source of single-step exception and subsequent
  154. * hw-breakpoint enablement
  155. */
  156. struct perf_event *last_hit_ubp[HBP_NUM_MAX];
  157. #endif /* CONFIG_HAVE_HW_BREAKPOINT */
  158. struct arch_hw_breakpoint hw_brk[HBP_NUM_MAX]; /* hardware breakpoint info */
  159. unsigned long trap_nr; /* last trap # on this thread */
  160. u8 load_slb; /* Ages out SLB preload cache entries */
  161. u8 load_fp;
  162. #ifdef CONFIG_ALTIVEC
  163. u8 load_vec;
  164. struct thread_vr_state vr_state;
  165. struct thread_vr_state *vr_save_area;
  166. unsigned long vrsave;
  167. int used_vr; /* set if process has used altivec */
  168. #endif /* CONFIG_ALTIVEC */
  169. #ifdef CONFIG_VSX
  170. /* VSR status */
  171. int used_vsr; /* set if process has used VSX */
  172. #endif /* CONFIG_VSX */
  173. #ifdef CONFIG_SPE
  174. struct_group(spe,
  175. unsigned long evr[32]; /* upper 32-bits of SPE regs */
  176. u64 acc; /* Accumulator */
  177. );
  178. unsigned long spefscr; /* SPE & eFP status */
  179. unsigned long spefscr_last; /* SPEFSCR value on last prctl
  180. call or trap return */
  181. int used_spe; /* set if process has used spe */
  182. #endif /* CONFIG_SPE */
  183. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  184. u8 load_tm;
  185. u64 tm_tfhar; /* Transaction fail handler addr */
  186. u64 tm_texasr; /* Transaction exception & summary */
  187. u64 tm_tfiar; /* Transaction fail instr address reg */
  188. struct pt_regs ckpt_regs; /* Checkpointed registers */
  189. unsigned long tm_tar;
  190. unsigned long tm_ppr;
  191. unsigned long tm_dscr;
  192. unsigned long tm_amr;
  193. /*
  194. * Checkpointed FP and VSX 0-31 register set.
  195. *
  196. * When a transaction is active/signalled/scheduled etc., *regs is the
  197. * most recent set of/speculated GPRs with ckpt_regs being the older
  198. * checkpointed regs to which we roll back if transaction aborts.
  199. *
  200. * These are analogous to how ckpt_regs and pt_regs work
  201. */
  202. struct thread_fp_state ckfp_state; /* Checkpointed FP state */
  203. struct thread_vr_state ckvr_state; /* Checkpointed VR state */
  204. unsigned long ckvrsave; /* Checkpointed VRSAVE */
  205. #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
  206. #ifdef CONFIG_KVM_BOOK3S_32_HANDLER
  207. void* kvm_shadow_vcpu; /* KVM internal data */
  208. #endif /* CONFIG_KVM_BOOK3S_32_HANDLER */
  209. #if defined(CONFIG_KVM) && defined(CONFIG_BOOKE)
  210. struct kvm_vcpu *kvm_vcpu;
  211. #endif
  212. #ifdef CONFIG_PPC64
  213. unsigned long dscr;
  214. unsigned long fscr;
  215. /*
  216. * This member element dscr_inherit indicates that the process
  217. * has explicitly attempted and changed the DSCR register value
  218. * for itself. Hence kernel wont use the default CPU DSCR value
  219. * contained in the PACA structure anymore during process context
  220. * switch. Once this variable is set, this behaviour will also be
  221. * inherited to all the children of this process from that point
  222. * onwards.
  223. */
  224. int dscr_inherit;
  225. unsigned long tidr;
  226. #endif
  227. #ifdef CONFIG_PPC_BOOK3S_64
  228. unsigned long tar;
  229. unsigned long ebbrr;
  230. unsigned long ebbhr;
  231. unsigned long bescr;
  232. unsigned long siar;
  233. unsigned long sdar;
  234. unsigned long sier;
  235. unsigned long mmcr2;
  236. unsigned mmcr0;
  237. unsigned used_ebb;
  238. unsigned long mmcr3;
  239. unsigned long sier2;
  240. unsigned long sier3;
  241. #endif
  242. };
  243. #define ARCH_MIN_TASKALIGN 16
  244. #define INIT_SP (sizeof(init_stack) + (unsigned long) &init_stack)
  245. #define INIT_SP_LIMIT ((unsigned long)&init_stack)
  246. #ifdef CONFIG_SPE
  247. #define SPEFSCR_INIT \
  248. .spefscr = SPEFSCR_FINVE | SPEFSCR_FDBZE | SPEFSCR_FUNFE | SPEFSCR_FOVFE, \
  249. .spefscr_last = SPEFSCR_FINVE | SPEFSCR_FDBZE | SPEFSCR_FUNFE | SPEFSCR_FOVFE,
  250. #else
  251. #define SPEFSCR_INIT
  252. #endif
  253. #ifdef CONFIG_PPC_BOOK3S_32
  254. #define SR0_INIT .sr0 = IS_ENABLED(CONFIG_PPC_KUEP) ? SR_NX : 0,
  255. #else
  256. #define SR0_INIT
  257. #endif
  258. #if defined(CONFIG_PPC_BOOK3S_32) && defined(CONFIG_PPC_KUAP)
  259. #define INIT_THREAD { \
  260. .ksp = INIT_SP, \
  261. .pgdir = swapper_pg_dir, \
  262. .kuap = ~0UL, /* KUAP_NONE */ \
  263. .fpexc_mode = MSR_FE0 | MSR_FE1, \
  264. SPEFSCR_INIT \
  265. SR0_INIT \
  266. }
  267. #elif defined(CONFIG_PPC32)
  268. #define INIT_THREAD { \
  269. .ksp = INIT_SP, \
  270. .pgdir = swapper_pg_dir, \
  271. .fpexc_mode = MSR_FE0 | MSR_FE1, \
  272. SPEFSCR_INIT \
  273. SR0_INIT \
  274. }
  275. #else
  276. #define INIT_THREAD { \
  277. .ksp = INIT_SP, \
  278. .fpexc_mode = 0, \
  279. }
  280. #endif
  281. #define task_pt_regs(tsk) ((tsk)->thread.regs)
  282. unsigned long __get_wchan(struct task_struct *p);
  283. #define KSTK_EIP(tsk) ((tsk)->thread.regs? (tsk)->thread.regs->nip: 0)
  284. #define KSTK_ESP(tsk) ((tsk)->thread.regs? (tsk)->thread.regs->gpr[1]: 0)
  285. /* Get/set floating-point exception mode */
  286. #define GET_FPEXC_CTL(tsk, adr) get_fpexc_mode((tsk), (adr))
  287. #define SET_FPEXC_CTL(tsk, val) set_fpexc_mode((tsk), (val))
  288. extern int get_fpexc_mode(struct task_struct *tsk, unsigned long adr);
  289. extern int set_fpexc_mode(struct task_struct *tsk, unsigned int val);
  290. #define GET_ENDIAN(tsk, adr) get_endian((tsk), (adr))
  291. #define SET_ENDIAN(tsk, val) set_endian((tsk), (val))
  292. extern int get_endian(struct task_struct *tsk, unsigned long adr);
  293. extern int set_endian(struct task_struct *tsk, unsigned int val);
  294. #define GET_UNALIGN_CTL(tsk, adr) get_unalign_ctl((tsk), (adr))
  295. #define SET_UNALIGN_CTL(tsk, val) set_unalign_ctl((tsk), (val))
  296. extern int get_unalign_ctl(struct task_struct *tsk, unsigned long adr);
  297. extern int set_unalign_ctl(struct task_struct *tsk, unsigned int val);
  298. extern void load_fp_state(struct thread_fp_state *fp);
  299. extern void store_fp_state(struct thread_fp_state *fp);
  300. extern void load_vr_state(struct thread_vr_state *vr);
  301. extern void store_vr_state(struct thread_vr_state *vr);
  302. static inline unsigned int __unpack_fe01(unsigned long msr_bits)
  303. {
  304. return ((msr_bits & MSR_FE0) >> 10) | ((msr_bits & MSR_FE1) >> 8);
  305. }
  306. static inline unsigned long __pack_fe01(unsigned int fpmode)
  307. {
  308. return ((fpmode << 10) & MSR_FE0) | ((fpmode << 8) & MSR_FE1);
  309. }
  310. #ifdef CONFIG_PPC64
  311. #define spin_begin() \
  312. asm volatile(ASM_FTR_IFCLR( \
  313. "or 1,1,1", /* HMT_LOW */ \
  314. "nop", /* v3.1 uses pause_short in cpu_relax instead */ \
  315. %0) :: "i" (CPU_FTR_ARCH_31) : "memory")
  316. #define spin_cpu_relax() \
  317. asm volatile(ASM_FTR_IFCLR( \
  318. "nop", /* Before v3.1 use priority nops in spin_begin/end */ \
  319. PPC_WAIT(2, 0), /* aka pause_short */ \
  320. %0) :: "i" (CPU_FTR_ARCH_31) : "memory")
  321. #define spin_end() \
  322. asm volatile(ASM_FTR_IFCLR( \
  323. "or 2,2,2", /* HMT_MEDIUM */ \
  324. "nop", \
  325. %0) :: "i" (CPU_FTR_ARCH_31) : "memory")
  326. #endif
  327. /* Check that a certain kernel stack pointer is valid in task_struct p */
  328. int validate_sp(unsigned long sp, struct task_struct *p,
  329. unsigned long nbytes);
  330. /*
  331. * Prefetch macros.
  332. */
  333. #define ARCH_HAS_PREFETCH
  334. #define ARCH_HAS_PREFETCHW
  335. #define ARCH_HAS_SPINLOCK_PREFETCH
  336. static inline void prefetch(const void *x)
  337. {
  338. if (unlikely(!x))
  339. return;
  340. __asm__ __volatile__ ("dcbt 0,%0" : : "r" (x));
  341. }
  342. static inline void prefetchw(const void *x)
  343. {
  344. if (unlikely(!x))
  345. return;
  346. __asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x));
  347. }
  348. #define spin_lock_prefetch(x) prefetchw(x)
  349. /* asm stubs */
  350. extern unsigned long isa300_idle_stop_noloss(unsigned long psscr_val);
  351. extern unsigned long isa300_idle_stop_mayloss(unsigned long psscr_val);
  352. extern unsigned long isa206_idle_insn_mayloss(unsigned long type);
  353. #ifdef CONFIG_PPC_970_NAP
  354. extern void power4_idle_nap(void);
  355. void power4_idle_nap_return(void);
  356. #endif
  357. extern unsigned long cpuidle_disable;
  358. enum idle_boot_override {IDLE_NO_OVERRIDE = 0, IDLE_POWERSAVE_OFF};
  359. extern int powersave_nap; /* set if nap mode can be used in idle loop */
  360. extern void power7_idle_type(unsigned long type);
  361. extern void arch300_idle_type(unsigned long stop_psscr_val,
  362. unsigned long stop_psscr_mask);
  363. void pnv_power9_force_smt4_catch(void);
  364. void pnv_power9_force_smt4_release(void);
  365. extern int fix_alignment(struct pt_regs *);
  366. #ifdef CONFIG_PPC64
  367. /*
  368. * We handle most unaligned accesses in hardware. On the other hand
  369. * unaligned DMA can be very expensive on some ppc64 IO chips (it does
  370. * powers of 2 writes until it reaches sufficient alignment).
  371. *
  372. * Based on this we disable the IP header alignment in network drivers.
  373. */
  374. #define NET_IP_ALIGN 0
  375. #endif
  376. int do_mathemu(struct pt_regs *regs);
  377. int do_spe_mathemu(struct pt_regs *regs);
  378. int speround_handler(struct pt_regs *regs);
  379. /* VMX copying */
  380. int enter_vmx_usercopy(void);
  381. int exit_vmx_usercopy(void);
  382. int enter_vmx_ops(void);
  383. void *exit_vmx_ops(void *dest);
  384. #endif /* __KERNEL__ */
  385. #endif /* __ASSEMBLY__ */
  386. #endif /* _ASM_POWERPC_PROCESSOR_H */