paca.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * This control block defines the PACA which defines the processor
  4. * specific data for each logical processor on the system.
  5. * There are some pointers defined that are utilized by PLIC.
  6. *
  7. * C 2001 PPC 64 Team, IBM Corp
  8. */
  9. #ifndef _ASM_POWERPC_PACA_H
  10. #define _ASM_POWERPC_PACA_H
  11. #ifdef __KERNEL__
  12. #ifdef CONFIG_PPC64
  13. #include <linux/cache.h>
  14. #include <linux/string.h>
  15. #include <asm/types.h>
  16. #include <asm/mmu.h>
  17. #include <asm/page.h>
  18. #ifdef CONFIG_PPC_BOOK3E_64
  19. #include <asm/exception-64e.h>
  20. #else
  21. #include <asm/exception-64s.h>
  22. #endif
  23. #ifdef CONFIG_KVM_BOOK3S_64_HANDLER
  24. #include <asm/kvm_book3s_asm.h>
  25. #endif
  26. #include <asm/accounting.h>
  27. #include <asm/hmi.h>
  28. #include <asm/cpuidle.h>
  29. #include <asm/atomic.h>
  30. #include <asm/mce.h>
  31. #include <asm-generic/mmiowb_types.h>
  32. register struct paca_struct *local_paca asm("r13");
  33. #if defined(CONFIG_DEBUG_PREEMPT) && defined(CONFIG_SMP)
  34. extern unsigned int debug_smp_processor_id(void); /* from linux/smp.h */
  35. /*
  36. * Add standard checks that preemption cannot occur when using get_paca():
  37. * otherwise the paca_struct it points to may be the wrong one just after.
  38. */
  39. #define get_paca() ((void) debug_smp_processor_id(), local_paca)
  40. #else
  41. #define get_paca() local_paca
  42. #endif
  43. #define get_slb_shadow() (get_paca()->slb_shadow_ptr)
  44. struct task_struct;
  45. struct rtas_args;
  46. struct lppaca;
  47. /*
  48. * Defines the layout of the paca.
  49. *
  50. * This structure is not directly accessed by firmware or the service
  51. * processor.
  52. */
  53. struct paca_struct {
  54. #ifdef CONFIG_PPC_PSERIES
  55. /*
  56. * Because hw_cpu_id, unlike other paca fields, is accessed
  57. * routinely from other CPUs (from the IRQ code), we stick to
  58. * read-only (after boot) fields in the first cacheline to
  59. * avoid cacheline bouncing.
  60. */
  61. struct lppaca *lppaca_ptr; /* Pointer to LpPaca for PLIC */
  62. #endif /* CONFIG_PPC_PSERIES */
  63. /*
  64. * MAGIC: the spinlock functions in arch/powerpc/lib/locks.c
  65. * load lock_token and paca_index with a single lwz
  66. * instruction. They must travel together and be properly
  67. * aligned.
  68. */
  69. #ifdef __BIG_ENDIAN__
  70. u16 lock_token; /* Constant 0x8000, used in locks */
  71. u16 paca_index; /* Logical processor number */
  72. #else
  73. u16 paca_index; /* Logical processor number */
  74. u16 lock_token; /* Constant 0x8000, used in locks */
  75. #endif
  76. u64 kernel_toc; /* Kernel TOC address */
  77. u64 kernelbase; /* Base address of kernel */
  78. u64 kernel_msr; /* MSR while running in kernel */
  79. void *emergency_sp; /* pointer to emergency stack */
  80. u64 data_offset; /* per cpu data offset */
  81. s16 hw_cpu_id; /* Physical processor number */
  82. u8 cpu_start; /* At startup, processor spins until */
  83. /* this becomes non-zero. */
  84. u8 kexec_state; /* set when kexec down has irqs off */
  85. #ifdef CONFIG_PPC_BOOK3S_64
  86. #ifdef CONFIG_PPC_64S_HASH_MMU
  87. struct slb_shadow *slb_shadow_ptr;
  88. #endif
  89. struct dtl_entry *dispatch_log;
  90. struct dtl_entry *dispatch_log_end;
  91. #endif
  92. u64 dscr_default; /* per-CPU default DSCR */
  93. #ifdef CONFIG_PPC_BOOK3S_64
  94. /*
  95. * Now, starting in cacheline 2, the exception save areas
  96. */
  97. /* used for most interrupts/exceptions */
  98. u64 exgen[EX_SIZE] __attribute__((aligned(0x80)));
  99. #ifdef CONFIG_PPC_64S_HASH_MMU
  100. /* SLB related definitions */
  101. u16 vmalloc_sllp;
  102. u8 slb_cache_ptr;
  103. u8 stab_rr; /* stab/slb round-robin counter */
  104. #ifdef CONFIG_DEBUG_VM
  105. u8 in_kernel_slb_handler;
  106. #endif
  107. u32 slb_used_bitmap; /* Bitmaps for first 32 SLB entries. */
  108. u32 slb_kern_bitmap;
  109. u32 slb_cache[SLB_CACHE_ENTRIES];
  110. #endif
  111. #endif /* CONFIG_PPC_BOOK3S_64 */
  112. #ifdef CONFIG_PPC_BOOK3E_64
  113. u64 exgen[8] __aligned(0x40);
  114. /* Keep pgd in the same cacheline as the start of extlb */
  115. pgd_t *pgd __aligned(0x40); /* Current PGD */
  116. pgd_t *kernel_pgd; /* Kernel PGD */
  117. /* Shared by all threads of a core -- points to tcd of first thread */
  118. struct tlb_core_data *tcd_ptr;
  119. /*
  120. * We can have up to 3 levels of reentrancy in the TLB miss handler,
  121. * in each of four exception levels (normal, crit, mcheck, debug).
  122. */
  123. u64 extlb[12][EX_TLB_SIZE / sizeof(u64)];
  124. u64 exmc[8]; /* used for machine checks */
  125. u64 excrit[8]; /* used for crit interrupts */
  126. u64 exdbg[8]; /* used for debug interrupts */
  127. /* Kernel stack pointers for use by special exceptions */
  128. void *mc_kstack;
  129. void *crit_kstack;
  130. void *dbg_kstack;
  131. struct tlb_core_data tcd;
  132. #endif /* CONFIG_PPC_BOOK3E_64 */
  133. #ifdef CONFIG_PPC_64S_HASH_MMU
  134. unsigned char mm_ctx_low_slices_psize[BITS_PER_LONG / BITS_PER_BYTE];
  135. unsigned char mm_ctx_high_slices_psize[SLICE_ARRAY_SIZE];
  136. #endif
  137. /*
  138. * then miscellaneous read-write fields
  139. */
  140. struct task_struct *__current; /* Pointer to current */
  141. u64 kstack; /* Saved Kernel stack addr */
  142. u64 saved_r1; /* r1 save for RTAS calls or PM or EE=0 */
  143. u64 saved_msr; /* MSR saved here by enter_rtas */
  144. #ifdef CONFIG_PPC64
  145. u64 exit_save_r1; /* Syscall/interrupt R1 save */
  146. #endif
  147. #ifdef CONFIG_PPC_BOOK3E_64
  148. u16 trap_save; /* Used when bad stack is encountered */
  149. #endif
  150. #ifdef CONFIG_PPC_BOOK3S_64
  151. u8 hsrr_valid; /* HSRRs set for HRFID */
  152. u8 srr_valid; /* SRRs set for RFID */
  153. #endif
  154. u8 irq_soft_mask; /* mask for irq soft masking */
  155. u8 irq_happened; /* irq happened while soft-disabled */
  156. u8 irq_work_pending; /* IRQ_WORK interrupt while soft-disable */
  157. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  158. u8 pmcregs_in_use; /* pseries puts this in lppaca */
  159. #endif
  160. u64 sprg_vdso; /* Saved user-visible sprg */
  161. #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
  162. u64 tm_scratch; /* TM scratch area for reclaim */
  163. #endif
  164. #ifdef CONFIG_PPC_POWERNV
  165. /* PowerNV idle fields */
  166. /* PNV_CORE_IDLE_* bits, all siblings work on thread 0 paca */
  167. unsigned long idle_state;
  168. union {
  169. /* P7/P8 specific fields */
  170. struct {
  171. /* PNV_THREAD_RUNNING/NAP/SLEEP */
  172. u8 thread_idle_state;
  173. /* Mask to denote subcore sibling threads */
  174. u8 subcore_sibling_mask;
  175. };
  176. /* P9 specific fields */
  177. struct {
  178. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  179. /* The PSSCR value that the kernel requested before going to stop */
  180. u64 requested_psscr;
  181. /* Flag to request this thread not to stop */
  182. atomic_t dont_stop;
  183. #endif
  184. };
  185. };
  186. #endif
  187. #ifdef CONFIG_PPC_BOOK3S_64
  188. /* Non-maskable exceptions that are not performance critical */
  189. u64 exnmi[EX_SIZE]; /* used for system reset (nmi) */
  190. u64 exmc[EX_SIZE]; /* used for machine checks */
  191. #endif
  192. #ifdef CONFIG_PPC_BOOK3S_64
  193. /* Exclusive stacks for system reset and machine check exception. */
  194. void *nmi_emergency_sp;
  195. void *mc_emergency_sp;
  196. u16 in_nmi; /* In nmi handler */
  197. /*
  198. * Flag to check whether we are in machine check early handler
  199. * and already using emergency stack.
  200. */
  201. u16 in_mce;
  202. u8 hmi_event_available; /* HMI event is available */
  203. u8 hmi_p9_special_emu; /* HMI P9 special emulation */
  204. u32 hmi_irqs; /* HMI irq stat */
  205. #endif
  206. u8 ftrace_enabled; /* Hard disable ftrace */
  207. /* Stuff for accurate time accounting */
  208. struct cpu_accounting_data accounting;
  209. u64 dtl_ridx; /* read index in dispatch log */
  210. struct dtl_entry *dtl_curr; /* pointer corresponding to dtl_ridx */
  211. #ifdef CONFIG_KVM_BOOK3S_HANDLER
  212. #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE
  213. /* We use this to store guest state in */
  214. struct kvmppc_book3s_shadow_vcpu shadow_vcpu;
  215. #endif
  216. struct kvmppc_host_state kvm_hstate;
  217. #ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE
  218. /*
  219. * Bitmap for sibling subcore status. See kvm/book3s_hv_ras.c for
  220. * more details
  221. */
  222. struct sibling_subcore_state *sibling_subcore_state;
  223. #endif
  224. #endif
  225. #ifdef CONFIG_PPC_BOOK3S_64
  226. /*
  227. * rfi fallback flush must be in its own cacheline to prevent
  228. * other paca data leaking into the L1d
  229. */
  230. u64 exrfi[EX_SIZE] __aligned(0x80);
  231. void *rfi_flush_fallback_area;
  232. u64 l1d_flush_size;
  233. #endif
  234. #ifdef CONFIG_PPC_PSERIES
  235. u8 *mce_data_buf; /* buffer to hold per cpu rtas errlog */
  236. #endif /* CONFIG_PPC_PSERIES */
  237. #ifdef CONFIG_PPC_BOOK3S_64
  238. #ifdef CONFIG_PPC_64S_HASH_MMU
  239. /* Capture SLB related old contents in MCE handler. */
  240. struct slb_entry *mce_faulty_slbs;
  241. u16 slb_save_cache_ptr;
  242. #endif
  243. #endif /* CONFIG_PPC_BOOK3S_64 */
  244. #ifdef CONFIG_STACKPROTECTOR
  245. unsigned long canary;
  246. #endif
  247. #ifdef CONFIG_MMIOWB
  248. struct mmiowb_state mmiowb_state;
  249. #endif
  250. #ifdef CONFIG_PPC_BOOK3S_64
  251. struct mce_info *mce_info;
  252. u8 mce_pending_irq_work;
  253. #endif /* CONFIG_PPC_BOOK3S_64 */
  254. } ____cacheline_aligned;
  255. extern void copy_mm_to_paca(struct mm_struct *mm);
  256. extern struct paca_struct **paca_ptrs;
  257. extern void initialise_paca(struct paca_struct *new_paca, int cpu);
  258. extern void setup_paca(struct paca_struct *new_paca);
  259. extern void allocate_paca_ptrs(void);
  260. extern void allocate_paca(int cpu);
  261. extern void free_unused_pacas(void);
  262. #else /* CONFIG_PPC64 */
  263. static inline void allocate_paca(int cpu) { }
  264. static inline void free_unused_pacas(void) { }
  265. #endif /* CONFIG_PPC64 */
  266. #endif /* __KERNEL__ */
  267. #endif /* _ASM_POWERPC_PACA_H */