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