18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * This control block defines the PACA which defines the processor 48c2ecf20Sopenharmony_ci * specific data for each logical processor on the system. 58c2ecf20Sopenharmony_ci * There are some pointers defined that are utilized by PLIC. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * C 2001 PPC 64 Team, IBM Corp 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_PACA_H 108c2ecf20Sopenharmony_ci#define _ASM_POWERPC_PACA_H 118c2ecf20Sopenharmony_ci#ifdef __KERNEL__ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC64 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#include <linux/string.h> 168c2ecf20Sopenharmony_ci#include <asm/types.h> 178c2ecf20Sopenharmony_ci#include <asm/mmu.h> 188c2ecf20Sopenharmony_ci#include <asm/page.h> 198c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3E 208c2ecf20Sopenharmony_ci#include <asm/exception-64e.h> 218c2ecf20Sopenharmony_ci#else 228c2ecf20Sopenharmony_ci#include <asm/exception-64s.h> 238c2ecf20Sopenharmony_ci#endif 248c2ecf20Sopenharmony_ci#ifdef CONFIG_KVM_BOOK3S_64_HANDLER 258c2ecf20Sopenharmony_ci#include <asm/kvm_book3s_asm.h> 268c2ecf20Sopenharmony_ci#endif 278c2ecf20Sopenharmony_ci#include <asm/accounting.h> 288c2ecf20Sopenharmony_ci#include <asm/hmi.h> 298c2ecf20Sopenharmony_ci#include <asm/cpuidle.h> 308c2ecf20Sopenharmony_ci#include <asm/atomic.h> 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#include <asm-generic/mmiowb_types.h> 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ciregister struct paca_struct *local_paca asm("r13"); 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#if defined(CONFIG_DEBUG_PREEMPT) && defined(CONFIG_SMP) 378c2ecf20Sopenharmony_ciextern unsigned int debug_smp_processor_id(void); /* from linux/smp.h */ 388c2ecf20Sopenharmony_ci/* 398c2ecf20Sopenharmony_ci * Add standard checks that preemption cannot occur when using get_paca(): 408c2ecf20Sopenharmony_ci * otherwise the paca_struct it points to may be the wrong one just after. 418c2ecf20Sopenharmony_ci */ 428c2ecf20Sopenharmony_ci#define get_paca() ((void) debug_smp_processor_id(), local_paca) 438c2ecf20Sopenharmony_ci#else 448c2ecf20Sopenharmony_ci#define get_paca() local_paca 458c2ecf20Sopenharmony_ci#endif 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci#define get_slb_shadow() (get_paca()->slb_shadow_ptr) 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_cistruct task_struct; 508c2ecf20Sopenharmony_cistruct rtas_args; 518c2ecf20Sopenharmony_cistruct lppaca; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci/* 548c2ecf20Sopenharmony_ci * Defines the layout of the paca. 558c2ecf20Sopenharmony_ci * 568c2ecf20Sopenharmony_ci * This structure is not directly accessed by firmware or the service 578c2ecf20Sopenharmony_ci * processor. 588c2ecf20Sopenharmony_ci */ 598c2ecf20Sopenharmony_cistruct paca_struct { 608c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_PSERIES 618c2ecf20Sopenharmony_ci /* 628c2ecf20Sopenharmony_ci * Because hw_cpu_id, unlike other paca fields, is accessed 638c2ecf20Sopenharmony_ci * routinely from other CPUs (from the IRQ code), we stick to 648c2ecf20Sopenharmony_ci * read-only (after boot) fields in the first cacheline to 658c2ecf20Sopenharmony_ci * avoid cacheline bouncing. 668c2ecf20Sopenharmony_ci */ 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci struct lppaca *lppaca_ptr; /* Pointer to LpPaca for PLIC */ 698c2ecf20Sopenharmony_ci#endif /* CONFIG_PPC_PSERIES */ 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci /* 728c2ecf20Sopenharmony_ci * MAGIC: the spinlock functions in arch/powerpc/lib/locks.c 738c2ecf20Sopenharmony_ci * load lock_token and paca_index with a single lwz 748c2ecf20Sopenharmony_ci * instruction. They must travel together and be properly 758c2ecf20Sopenharmony_ci * aligned. 768c2ecf20Sopenharmony_ci */ 778c2ecf20Sopenharmony_ci#ifdef __BIG_ENDIAN__ 788c2ecf20Sopenharmony_ci u16 lock_token; /* Constant 0x8000, used in locks */ 798c2ecf20Sopenharmony_ci u16 paca_index; /* Logical processor number */ 808c2ecf20Sopenharmony_ci#else 818c2ecf20Sopenharmony_ci u16 paca_index; /* Logical processor number */ 828c2ecf20Sopenharmony_ci u16 lock_token; /* Constant 0x8000, used in locks */ 838c2ecf20Sopenharmony_ci#endif 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci u64 kernel_toc; /* Kernel TOC address */ 868c2ecf20Sopenharmony_ci u64 kernelbase; /* Base address of kernel */ 878c2ecf20Sopenharmony_ci u64 kernel_msr; /* MSR while running in kernel */ 888c2ecf20Sopenharmony_ci void *emergency_sp; /* pointer to emergency stack */ 898c2ecf20Sopenharmony_ci u64 data_offset; /* per cpu data offset */ 908c2ecf20Sopenharmony_ci s16 hw_cpu_id; /* Physical processor number */ 918c2ecf20Sopenharmony_ci u8 cpu_start; /* At startup, processor spins until */ 928c2ecf20Sopenharmony_ci /* this becomes non-zero. */ 938c2ecf20Sopenharmony_ci u8 kexec_state; /* set when kexec down has irqs off */ 948c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64 958c2ecf20Sopenharmony_ci struct slb_shadow *slb_shadow_ptr; 968c2ecf20Sopenharmony_ci struct dtl_entry *dispatch_log; 978c2ecf20Sopenharmony_ci struct dtl_entry *dispatch_log_end; 988c2ecf20Sopenharmony_ci#endif 998c2ecf20Sopenharmony_ci u64 dscr_default; /* per-CPU default DSCR */ 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64 1028c2ecf20Sopenharmony_ci /* 1038c2ecf20Sopenharmony_ci * Now, starting in cacheline 2, the exception save areas 1048c2ecf20Sopenharmony_ci */ 1058c2ecf20Sopenharmony_ci /* used for most interrupts/exceptions */ 1068c2ecf20Sopenharmony_ci u64 exgen[EX_SIZE] __attribute__((aligned(0x80))); 1078c2ecf20Sopenharmony_ci u64 exslb[EX_SIZE]; /* used for SLB/segment table misses 1088c2ecf20Sopenharmony_ci * on the linear mapping */ 1098c2ecf20Sopenharmony_ci /* SLB related definitions */ 1108c2ecf20Sopenharmony_ci u16 vmalloc_sllp; 1118c2ecf20Sopenharmony_ci u8 slb_cache_ptr; 1128c2ecf20Sopenharmony_ci u8 stab_rr; /* stab/slb round-robin counter */ 1138c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_VM 1148c2ecf20Sopenharmony_ci u8 in_kernel_slb_handler; 1158c2ecf20Sopenharmony_ci#endif 1168c2ecf20Sopenharmony_ci u32 slb_used_bitmap; /* Bitmaps for first 32 SLB entries. */ 1178c2ecf20Sopenharmony_ci u32 slb_kern_bitmap; 1188c2ecf20Sopenharmony_ci u32 slb_cache[SLB_CACHE_ENTRIES]; 1198c2ecf20Sopenharmony_ci#endif /* CONFIG_PPC_BOOK3S_64 */ 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3E 1228c2ecf20Sopenharmony_ci u64 exgen[8] __aligned(0x40); 1238c2ecf20Sopenharmony_ci /* Keep pgd in the same cacheline as the start of extlb */ 1248c2ecf20Sopenharmony_ci pgd_t *pgd __aligned(0x40); /* Current PGD */ 1258c2ecf20Sopenharmony_ci pgd_t *kernel_pgd; /* Kernel PGD */ 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci /* Shared by all threads of a core -- points to tcd of first thread */ 1288c2ecf20Sopenharmony_ci struct tlb_core_data *tcd_ptr; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci /* 1318c2ecf20Sopenharmony_ci * We can have up to 3 levels of reentrancy in the TLB miss handler, 1328c2ecf20Sopenharmony_ci * in each of four exception levels (normal, crit, mcheck, debug). 1338c2ecf20Sopenharmony_ci */ 1348c2ecf20Sopenharmony_ci u64 extlb[12][EX_TLB_SIZE / sizeof(u64)]; 1358c2ecf20Sopenharmony_ci u64 exmc[8]; /* used for machine checks */ 1368c2ecf20Sopenharmony_ci u64 excrit[8]; /* used for crit interrupts */ 1378c2ecf20Sopenharmony_ci u64 exdbg[8]; /* used for debug interrupts */ 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci /* Kernel stack pointers for use by special exceptions */ 1408c2ecf20Sopenharmony_ci void *mc_kstack; 1418c2ecf20Sopenharmony_ci void *crit_kstack; 1428c2ecf20Sopenharmony_ci void *dbg_kstack; 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci struct tlb_core_data tcd; 1458c2ecf20Sopenharmony_ci#endif /* CONFIG_PPC_BOOK3E */ 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S 1488c2ecf20Sopenharmony_ci mm_context_id_t mm_ctx_id; 1498c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_MM_SLICES 1508c2ecf20Sopenharmony_ci unsigned char mm_ctx_low_slices_psize[BITS_PER_LONG / BITS_PER_BYTE]; 1518c2ecf20Sopenharmony_ci unsigned char mm_ctx_high_slices_psize[SLICE_ARRAY_SIZE]; 1528c2ecf20Sopenharmony_ci unsigned long mm_ctx_slb_addr_limit; 1538c2ecf20Sopenharmony_ci#else 1548c2ecf20Sopenharmony_ci u16 mm_ctx_user_psize; 1558c2ecf20Sopenharmony_ci u16 mm_ctx_sllp; 1568c2ecf20Sopenharmony_ci#endif 1578c2ecf20Sopenharmony_ci#endif 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci /* 1608c2ecf20Sopenharmony_ci * then miscellaneous read-write fields 1618c2ecf20Sopenharmony_ci */ 1628c2ecf20Sopenharmony_ci struct task_struct *__current; /* Pointer to current */ 1638c2ecf20Sopenharmony_ci u64 kstack; /* Saved Kernel stack addr */ 1648c2ecf20Sopenharmony_ci u64 saved_r1; /* r1 save for RTAS calls or PM or EE=0 */ 1658c2ecf20Sopenharmony_ci u64 saved_msr; /* MSR saved here by enter_rtas */ 1668c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3E 1678c2ecf20Sopenharmony_ci u16 trap_save; /* Used when bad stack is encountered */ 1688c2ecf20Sopenharmony_ci#endif 1698c2ecf20Sopenharmony_ci u8 irq_soft_mask; /* mask for irq soft masking */ 1708c2ecf20Sopenharmony_ci u8 irq_happened; /* irq happened while soft-disabled */ 1718c2ecf20Sopenharmony_ci u8 irq_work_pending; /* IRQ_WORK interrupt while soft-disable */ 1728c2ecf20Sopenharmony_ci#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 1738c2ecf20Sopenharmony_ci u8 pmcregs_in_use; /* pseries puts this in lppaca */ 1748c2ecf20Sopenharmony_ci#endif 1758c2ecf20Sopenharmony_ci u64 sprg_vdso; /* Saved user-visible sprg */ 1768c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_TRANSACTIONAL_MEM 1778c2ecf20Sopenharmony_ci u64 tm_scratch; /* TM scratch area for reclaim */ 1788c2ecf20Sopenharmony_ci#endif 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_POWERNV 1818c2ecf20Sopenharmony_ci /* PowerNV idle fields */ 1828c2ecf20Sopenharmony_ci /* PNV_CORE_IDLE_* bits, all siblings work on thread 0 paca */ 1838c2ecf20Sopenharmony_ci unsigned long idle_state; 1848c2ecf20Sopenharmony_ci union { 1858c2ecf20Sopenharmony_ci /* P7/P8 specific fields */ 1868c2ecf20Sopenharmony_ci struct { 1878c2ecf20Sopenharmony_ci /* PNV_THREAD_RUNNING/NAP/SLEEP */ 1888c2ecf20Sopenharmony_ci u8 thread_idle_state; 1898c2ecf20Sopenharmony_ci /* Mask to denote subcore sibling threads */ 1908c2ecf20Sopenharmony_ci u8 subcore_sibling_mask; 1918c2ecf20Sopenharmony_ci }; 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci /* P9 specific fields */ 1948c2ecf20Sopenharmony_ci struct { 1958c2ecf20Sopenharmony_ci#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 1968c2ecf20Sopenharmony_ci /* The PSSCR value that the kernel requested before going to stop */ 1978c2ecf20Sopenharmony_ci u64 requested_psscr; 1988c2ecf20Sopenharmony_ci /* Flag to request this thread not to stop */ 1998c2ecf20Sopenharmony_ci atomic_t dont_stop; 2008c2ecf20Sopenharmony_ci#endif 2018c2ecf20Sopenharmony_ci }; 2028c2ecf20Sopenharmony_ci }; 2038c2ecf20Sopenharmony_ci#endif 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64 2068c2ecf20Sopenharmony_ci /* Non-maskable exceptions that are not performance critical */ 2078c2ecf20Sopenharmony_ci u64 exnmi[EX_SIZE]; /* used for system reset (nmi) */ 2088c2ecf20Sopenharmony_ci u64 exmc[EX_SIZE]; /* used for machine checks */ 2098c2ecf20Sopenharmony_ci#endif 2108c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64 2118c2ecf20Sopenharmony_ci /* Exclusive stacks for system reset and machine check exception. */ 2128c2ecf20Sopenharmony_ci void *nmi_emergency_sp; 2138c2ecf20Sopenharmony_ci void *mc_emergency_sp; 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci u16 in_nmi; /* In nmi handler */ 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci /* 2188c2ecf20Sopenharmony_ci * Flag to check whether we are in machine check early handler 2198c2ecf20Sopenharmony_ci * and already using emergency stack. 2208c2ecf20Sopenharmony_ci */ 2218c2ecf20Sopenharmony_ci u16 in_mce; 2228c2ecf20Sopenharmony_ci u8 hmi_event_available; /* HMI event is available */ 2238c2ecf20Sopenharmony_ci u8 hmi_p9_special_emu; /* HMI P9 special emulation */ 2248c2ecf20Sopenharmony_ci u32 hmi_irqs; /* HMI irq stat */ 2258c2ecf20Sopenharmony_ci#endif 2268c2ecf20Sopenharmony_ci u8 ftrace_enabled; /* Hard disable ftrace */ 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci /* Stuff for accurate time accounting */ 2298c2ecf20Sopenharmony_ci struct cpu_accounting_data accounting; 2308c2ecf20Sopenharmony_ci u64 dtl_ridx; /* read index in dispatch log */ 2318c2ecf20Sopenharmony_ci struct dtl_entry *dtl_curr; /* pointer corresponding to dtl_ridx */ 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci#ifdef CONFIG_KVM_BOOK3S_HANDLER 2348c2ecf20Sopenharmony_ci#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 2358c2ecf20Sopenharmony_ci /* We use this to store guest state in */ 2368c2ecf20Sopenharmony_ci struct kvmppc_book3s_shadow_vcpu shadow_vcpu; 2378c2ecf20Sopenharmony_ci#endif 2388c2ecf20Sopenharmony_ci struct kvmppc_host_state kvm_hstate; 2398c2ecf20Sopenharmony_ci#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 2408c2ecf20Sopenharmony_ci /* 2418c2ecf20Sopenharmony_ci * Bitmap for sibling subcore status. See kvm/book3s_hv_ras.c for 2428c2ecf20Sopenharmony_ci * more details 2438c2ecf20Sopenharmony_ci */ 2448c2ecf20Sopenharmony_ci struct sibling_subcore_state *sibling_subcore_state; 2458c2ecf20Sopenharmony_ci#endif 2468c2ecf20Sopenharmony_ci#endif 2478c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64 2488c2ecf20Sopenharmony_ci /* 2498c2ecf20Sopenharmony_ci * rfi fallback flush must be in its own cacheline to prevent 2508c2ecf20Sopenharmony_ci * other paca data leaking into the L1d 2518c2ecf20Sopenharmony_ci */ 2528c2ecf20Sopenharmony_ci u64 exrfi[EX_SIZE] __aligned(0x80); 2538c2ecf20Sopenharmony_ci void *rfi_flush_fallback_area; 2548c2ecf20Sopenharmony_ci u64 l1d_flush_size; 2558c2ecf20Sopenharmony_ci#endif 2568c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_PSERIES 2578c2ecf20Sopenharmony_ci struct rtas_args *rtas_args_reentrant; 2588c2ecf20Sopenharmony_ci u8 *mce_data_buf; /* buffer to hold per cpu rtas errlog */ 2598c2ecf20Sopenharmony_ci#endif /* CONFIG_PPC_PSERIES */ 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64 2628c2ecf20Sopenharmony_ci /* Capture SLB related old contents in MCE handler. */ 2638c2ecf20Sopenharmony_ci struct slb_entry *mce_faulty_slbs; 2648c2ecf20Sopenharmony_ci u16 slb_save_cache_ptr; 2658c2ecf20Sopenharmony_ci#endif /* CONFIG_PPC_BOOK3S_64 */ 2668c2ecf20Sopenharmony_ci#ifdef CONFIG_STACKPROTECTOR 2678c2ecf20Sopenharmony_ci unsigned long canary; 2688c2ecf20Sopenharmony_ci#endif 2698c2ecf20Sopenharmony_ci#ifdef CONFIG_MMIOWB 2708c2ecf20Sopenharmony_ci struct mmiowb_state mmiowb_state; 2718c2ecf20Sopenharmony_ci#endif 2728c2ecf20Sopenharmony_ci} ____cacheline_aligned; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ciextern void copy_mm_to_paca(struct mm_struct *mm); 2758c2ecf20Sopenharmony_ciextern struct paca_struct **paca_ptrs; 2768c2ecf20Sopenharmony_ciextern void initialise_paca(struct paca_struct *new_paca, int cpu); 2778c2ecf20Sopenharmony_ciextern void setup_paca(struct paca_struct *new_paca); 2788c2ecf20Sopenharmony_ciextern void allocate_paca_ptrs(void); 2798c2ecf20Sopenharmony_ciextern void allocate_paca(int cpu); 2808c2ecf20Sopenharmony_ciextern void free_unused_pacas(void); 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci#else /* CONFIG_PPC64 */ 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_cistatic inline void allocate_paca_ptrs(void) { }; 2858c2ecf20Sopenharmony_cistatic inline void allocate_paca(int cpu) { }; 2868c2ecf20Sopenharmony_cistatic inline void free_unused_pacas(void) { }; 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ci#endif /* CONFIG_PPC64 */ 2898c2ecf20Sopenharmony_ci 2908c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */ 2918c2ecf20Sopenharmony_ci#endif /* _ASM_POWERPC_PACA_H */ 292