processor.h 16 KB

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