162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * This control block defines the PACA which defines the processor 462306a36Sopenharmony_ci * specific data for each logical processor on the system. 562306a36Sopenharmony_ci * There are some pointers defined that are utilized by PLIC. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * C 2001 PPC 64 Team, IBM Corp 862306a36Sopenharmony_ci */ 962306a36Sopenharmony_ci#ifndef _ASM_POWERPC_PACA_H 1062306a36Sopenharmony_ci#define _ASM_POWERPC_PACA_H 1162306a36Sopenharmony_ci#ifdef __KERNEL__ 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#ifdef CONFIG_PPC64 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include <linux/cache.h> 1662306a36Sopenharmony_ci#include <linux/string.h> 1762306a36Sopenharmony_ci#include <asm/types.h> 1862306a36Sopenharmony_ci#include <asm/mmu.h> 1962306a36Sopenharmony_ci#include <asm/page.h> 2062306a36Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3E_64 2162306a36Sopenharmony_ci#include <asm/exception-64e.h> 2262306a36Sopenharmony_ci#else 2362306a36Sopenharmony_ci#include <asm/exception-64s.h> 2462306a36Sopenharmony_ci#endif 2562306a36Sopenharmony_ci#ifdef CONFIG_KVM_BOOK3S_64_HANDLER 2662306a36Sopenharmony_ci#include <asm/kvm_book3s_asm.h> 2762306a36Sopenharmony_ci#endif 2862306a36Sopenharmony_ci#include <asm/accounting.h> 2962306a36Sopenharmony_ci#include <asm/hmi.h> 3062306a36Sopenharmony_ci#include <asm/cpuidle.h> 3162306a36Sopenharmony_ci#include <asm/atomic.h> 3262306a36Sopenharmony_ci#include <asm/mce.h> 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#include <asm-generic/mmiowb_types.h> 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ciregister struct paca_struct *local_paca asm("r13"); 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#if defined(CONFIG_DEBUG_PREEMPT) && defined(CONFIG_SMP) 3962306a36Sopenharmony_ciextern unsigned int debug_smp_processor_id(void); /* from linux/smp.h */ 4062306a36Sopenharmony_ci/* 4162306a36Sopenharmony_ci * Add standard checks that preemption cannot occur when using get_paca(): 4262306a36Sopenharmony_ci * otherwise the paca_struct it points to may be the wrong one just after. 4362306a36Sopenharmony_ci */ 4462306a36Sopenharmony_ci#define get_paca() ((void) debug_smp_processor_id(), local_paca) 4562306a36Sopenharmony_ci#else 4662306a36Sopenharmony_ci#define get_paca() local_paca 4762306a36Sopenharmony_ci#endif 4862306a36Sopenharmony_ci 4962306a36Sopenharmony_ci#define get_slb_shadow() (get_paca()->slb_shadow_ptr) 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_cistruct task_struct; 5262306a36Sopenharmony_cistruct rtas_args; 5362306a36Sopenharmony_cistruct lppaca; 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci/* 5662306a36Sopenharmony_ci * Defines the layout of the paca. 5762306a36Sopenharmony_ci * 5862306a36Sopenharmony_ci * This structure is not directly accessed by firmware or the service 5962306a36Sopenharmony_ci * processor. 6062306a36Sopenharmony_ci */ 6162306a36Sopenharmony_cistruct paca_struct { 6262306a36Sopenharmony_ci#ifdef CONFIG_PPC_PSERIES 6362306a36Sopenharmony_ci /* 6462306a36Sopenharmony_ci * Because hw_cpu_id, unlike other paca fields, is accessed 6562306a36Sopenharmony_ci * routinely from other CPUs (from the IRQ code), we stick to 6662306a36Sopenharmony_ci * read-only (after boot) fields in the first cacheline to 6762306a36Sopenharmony_ci * avoid cacheline bouncing. 6862306a36Sopenharmony_ci */ 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci struct lppaca *lppaca_ptr; /* Pointer to LpPaca for PLIC */ 7162306a36Sopenharmony_ci#endif /* CONFIG_PPC_PSERIES */ 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci /* 7462306a36Sopenharmony_ci * MAGIC: the spinlock functions in arch/powerpc/lib/locks.c 7562306a36Sopenharmony_ci * load lock_token and paca_index with a single lwz 7662306a36Sopenharmony_ci * instruction. They must travel together and be properly 7762306a36Sopenharmony_ci * aligned. 7862306a36Sopenharmony_ci */ 7962306a36Sopenharmony_ci#ifdef __BIG_ENDIAN__ 8062306a36Sopenharmony_ci u16 lock_token; /* Constant 0x8000, used in locks */ 8162306a36Sopenharmony_ci u16 paca_index; /* Logical processor number */ 8262306a36Sopenharmony_ci#else 8362306a36Sopenharmony_ci u16 paca_index; /* Logical processor number */ 8462306a36Sopenharmony_ci u16 lock_token; /* Constant 0x8000, used in locks */ 8562306a36Sopenharmony_ci#endif 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci#ifndef CONFIG_PPC_KERNEL_PCREL 8862306a36Sopenharmony_ci u64 kernel_toc; /* Kernel TOC address */ 8962306a36Sopenharmony_ci#endif 9062306a36Sopenharmony_ci u64 kernelbase; /* Base address of kernel */ 9162306a36Sopenharmony_ci u64 kernel_msr; /* MSR while running in kernel */ 9262306a36Sopenharmony_ci void *emergency_sp; /* pointer to emergency stack */ 9362306a36Sopenharmony_ci u64 data_offset; /* per cpu data offset */ 9462306a36Sopenharmony_ci s16 hw_cpu_id; /* Physical processor number */ 9562306a36Sopenharmony_ci u8 cpu_start; /* At startup, processor spins until */ 9662306a36Sopenharmony_ci /* this becomes non-zero. */ 9762306a36Sopenharmony_ci u8 kexec_state; /* set when kexec down has irqs off */ 9862306a36Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64 9962306a36Sopenharmony_ci#ifdef CONFIG_PPC_64S_HASH_MMU 10062306a36Sopenharmony_ci struct slb_shadow *slb_shadow_ptr; 10162306a36Sopenharmony_ci#endif 10262306a36Sopenharmony_ci struct dtl_entry *dispatch_log; 10362306a36Sopenharmony_ci struct dtl_entry *dispatch_log_end; 10462306a36Sopenharmony_ci#endif 10562306a36Sopenharmony_ci u64 dscr_default; /* per-CPU default DSCR */ 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64 10862306a36Sopenharmony_ci /* 10962306a36Sopenharmony_ci * Now, starting in cacheline 2, the exception save areas 11062306a36Sopenharmony_ci */ 11162306a36Sopenharmony_ci /* used for most interrupts/exceptions */ 11262306a36Sopenharmony_ci u64 exgen[EX_SIZE] __attribute__((aligned(0x80))); 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci#ifdef CONFIG_PPC_64S_HASH_MMU 11562306a36Sopenharmony_ci /* SLB related definitions */ 11662306a36Sopenharmony_ci u16 vmalloc_sllp; 11762306a36Sopenharmony_ci u8 slb_cache_ptr; 11862306a36Sopenharmony_ci u8 stab_rr; /* stab/slb round-robin counter */ 11962306a36Sopenharmony_ci#ifdef CONFIG_DEBUG_VM 12062306a36Sopenharmony_ci u8 in_kernel_slb_handler; 12162306a36Sopenharmony_ci#endif 12262306a36Sopenharmony_ci u32 slb_used_bitmap; /* Bitmaps for first 32 SLB entries. */ 12362306a36Sopenharmony_ci u32 slb_kern_bitmap; 12462306a36Sopenharmony_ci u32 slb_cache[SLB_CACHE_ENTRIES]; 12562306a36Sopenharmony_ci#endif 12662306a36Sopenharmony_ci#endif /* CONFIG_PPC_BOOK3S_64 */ 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3E_64 12962306a36Sopenharmony_ci u64 exgen[8] __aligned(0x40); 13062306a36Sopenharmony_ci /* Keep pgd in the same cacheline as the start of extlb */ 13162306a36Sopenharmony_ci pgd_t *pgd __aligned(0x40); /* Current PGD */ 13262306a36Sopenharmony_ci pgd_t *kernel_pgd; /* Kernel PGD */ 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci /* Shared by all threads of a core -- points to tcd of first thread */ 13562306a36Sopenharmony_ci struct tlb_core_data *tcd_ptr; 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci /* 13862306a36Sopenharmony_ci * We can have up to 3 levels of reentrancy in the TLB miss handler, 13962306a36Sopenharmony_ci * in each of four exception levels (normal, crit, mcheck, debug). 14062306a36Sopenharmony_ci */ 14162306a36Sopenharmony_ci u64 extlb[12][EX_TLB_SIZE / sizeof(u64)]; 14262306a36Sopenharmony_ci u64 exmc[8]; /* used for machine checks */ 14362306a36Sopenharmony_ci u64 excrit[8]; /* used for crit interrupts */ 14462306a36Sopenharmony_ci u64 exdbg[8]; /* used for debug interrupts */ 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci /* Kernel stack pointers for use by special exceptions */ 14762306a36Sopenharmony_ci void *mc_kstack; 14862306a36Sopenharmony_ci void *crit_kstack; 14962306a36Sopenharmony_ci void *dbg_kstack; 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci struct tlb_core_data tcd; 15262306a36Sopenharmony_ci#endif /* CONFIG_PPC_BOOK3E_64 */ 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ci#ifdef CONFIG_PPC_64S_HASH_MMU 15562306a36Sopenharmony_ci unsigned char mm_ctx_low_slices_psize[BITS_PER_LONG / BITS_PER_BYTE]; 15662306a36Sopenharmony_ci unsigned char mm_ctx_high_slices_psize[SLICE_ARRAY_SIZE]; 15762306a36Sopenharmony_ci#endif 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_ci /* 16062306a36Sopenharmony_ci * then miscellaneous read-write fields 16162306a36Sopenharmony_ci */ 16262306a36Sopenharmony_ci struct task_struct *__current; /* Pointer to current */ 16362306a36Sopenharmony_ci u64 kstack; /* Saved Kernel stack addr */ 16462306a36Sopenharmony_ci u64 saved_r1; /* r1 save for RTAS calls or PM or EE=0 */ 16562306a36Sopenharmony_ci u64 saved_msr; /* MSR saved here by enter_rtas */ 16662306a36Sopenharmony_ci#ifdef CONFIG_PPC64 16762306a36Sopenharmony_ci u64 exit_save_r1; /* Syscall/interrupt R1 save */ 16862306a36Sopenharmony_ci#endif 16962306a36Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3E_64 17062306a36Sopenharmony_ci u16 trap_save; /* Used when bad stack is encountered */ 17162306a36Sopenharmony_ci#endif 17262306a36Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64 17362306a36Sopenharmony_ci u8 hsrr_valid; /* HSRRs set for HRFID */ 17462306a36Sopenharmony_ci u8 srr_valid; /* SRRs set for RFID */ 17562306a36Sopenharmony_ci#endif 17662306a36Sopenharmony_ci u8 irq_soft_mask; /* mask for irq soft masking */ 17762306a36Sopenharmony_ci u8 irq_happened; /* irq happened while soft-disabled */ 17862306a36Sopenharmony_ci u8 irq_work_pending; /* IRQ_WORK interrupt while soft-disable */ 17962306a36Sopenharmony_ci#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 18062306a36Sopenharmony_ci u8 pmcregs_in_use; /* pseries puts this in lppaca */ 18162306a36Sopenharmony_ci#endif 18262306a36Sopenharmony_ci u64 sprg_vdso; /* Saved user-visible sprg */ 18362306a36Sopenharmony_ci#ifdef CONFIG_PPC_TRANSACTIONAL_MEM 18462306a36Sopenharmony_ci u64 tm_scratch; /* TM scratch area for reclaim */ 18562306a36Sopenharmony_ci#endif 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ci#ifdef CONFIG_PPC_POWERNV 18862306a36Sopenharmony_ci /* PowerNV idle fields */ 18962306a36Sopenharmony_ci /* PNV_CORE_IDLE_* bits, all siblings work on thread 0 paca */ 19062306a36Sopenharmony_ci unsigned long idle_lock; /* A value of 1 means acquired */ 19162306a36Sopenharmony_ci unsigned long idle_state; 19262306a36Sopenharmony_ci union { 19362306a36Sopenharmony_ci /* P7/P8 specific fields */ 19462306a36Sopenharmony_ci struct { 19562306a36Sopenharmony_ci /* PNV_THREAD_RUNNING/NAP/SLEEP */ 19662306a36Sopenharmony_ci u8 thread_idle_state; 19762306a36Sopenharmony_ci /* Mask to denote subcore sibling threads */ 19862306a36Sopenharmony_ci u8 subcore_sibling_mask; 19962306a36Sopenharmony_ci }; 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_ci /* P9 specific fields */ 20262306a36Sopenharmony_ci struct { 20362306a36Sopenharmony_ci#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 20462306a36Sopenharmony_ci /* The PSSCR value that the kernel requested before going to stop */ 20562306a36Sopenharmony_ci u64 requested_psscr; 20662306a36Sopenharmony_ci /* Flag to request this thread not to stop */ 20762306a36Sopenharmony_ci atomic_t dont_stop; 20862306a36Sopenharmony_ci#endif 20962306a36Sopenharmony_ci }; 21062306a36Sopenharmony_ci }; 21162306a36Sopenharmony_ci#endif 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64 21462306a36Sopenharmony_ci /* Non-maskable exceptions that are not performance critical */ 21562306a36Sopenharmony_ci u64 exnmi[EX_SIZE]; /* used for system reset (nmi) */ 21662306a36Sopenharmony_ci u64 exmc[EX_SIZE]; /* used for machine checks */ 21762306a36Sopenharmony_ci#endif 21862306a36Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64 21962306a36Sopenharmony_ci /* Exclusive stacks for system reset and machine check exception. */ 22062306a36Sopenharmony_ci void *nmi_emergency_sp; 22162306a36Sopenharmony_ci void *mc_emergency_sp; 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci u16 in_nmi; /* In nmi handler */ 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci /* 22662306a36Sopenharmony_ci * Flag to check whether we are in machine check early handler 22762306a36Sopenharmony_ci * and already using emergency stack. 22862306a36Sopenharmony_ci */ 22962306a36Sopenharmony_ci u16 in_mce; 23062306a36Sopenharmony_ci u8 hmi_event_available; /* HMI event is available */ 23162306a36Sopenharmony_ci u8 hmi_p9_special_emu; /* HMI P9 special emulation */ 23262306a36Sopenharmony_ci u32 hmi_irqs; /* HMI irq stat */ 23362306a36Sopenharmony_ci#endif 23462306a36Sopenharmony_ci u8 ftrace_enabled; /* Hard disable ftrace */ 23562306a36Sopenharmony_ci 23662306a36Sopenharmony_ci /* Stuff for accurate time accounting */ 23762306a36Sopenharmony_ci struct cpu_accounting_data accounting; 23862306a36Sopenharmony_ci u64 dtl_ridx; /* read index in dispatch log */ 23962306a36Sopenharmony_ci struct dtl_entry *dtl_curr; /* pointer corresponding to dtl_ridx */ 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_ci#ifdef CONFIG_KVM_BOOK3S_HANDLER 24262306a36Sopenharmony_ci#ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE 24362306a36Sopenharmony_ci /* We use this to store guest state in */ 24462306a36Sopenharmony_ci struct kvmppc_book3s_shadow_vcpu shadow_vcpu; 24562306a36Sopenharmony_ci#endif 24662306a36Sopenharmony_ci struct kvmppc_host_state kvm_hstate; 24762306a36Sopenharmony_ci#ifdef CONFIG_KVM_BOOK3S_HV_POSSIBLE 24862306a36Sopenharmony_ci /* 24962306a36Sopenharmony_ci * Bitmap for sibling subcore status. See kvm/book3s_hv_ras.c for 25062306a36Sopenharmony_ci * more details 25162306a36Sopenharmony_ci */ 25262306a36Sopenharmony_ci struct sibling_subcore_state *sibling_subcore_state; 25362306a36Sopenharmony_ci#endif 25462306a36Sopenharmony_ci#endif 25562306a36Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64 25662306a36Sopenharmony_ci /* 25762306a36Sopenharmony_ci * rfi fallback flush must be in its own cacheline to prevent 25862306a36Sopenharmony_ci * other paca data leaking into the L1d 25962306a36Sopenharmony_ci */ 26062306a36Sopenharmony_ci u64 exrfi[EX_SIZE] __aligned(0x80); 26162306a36Sopenharmony_ci void *rfi_flush_fallback_area; 26262306a36Sopenharmony_ci u64 l1d_flush_size; 26362306a36Sopenharmony_ci#endif 26462306a36Sopenharmony_ci#ifdef CONFIG_PPC_PSERIES 26562306a36Sopenharmony_ci u8 *mce_data_buf; /* buffer to hold per cpu rtas errlog */ 26662306a36Sopenharmony_ci#endif /* CONFIG_PPC_PSERIES */ 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64 26962306a36Sopenharmony_ci#ifdef CONFIG_PPC_64S_HASH_MMU 27062306a36Sopenharmony_ci /* Capture SLB related old contents in MCE handler. */ 27162306a36Sopenharmony_ci struct slb_entry *mce_faulty_slbs; 27262306a36Sopenharmony_ci u16 slb_save_cache_ptr; 27362306a36Sopenharmony_ci#endif 27462306a36Sopenharmony_ci#endif /* CONFIG_PPC_BOOK3S_64 */ 27562306a36Sopenharmony_ci#ifdef CONFIG_STACKPROTECTOR 27662306a36Sopenharmony_ci unsigned long canary; 27762306a36Sopenharmony_ci#endif 27862306a36Sopenharmony_ci#ifdef CONFIG_MMIOWB 27962306a36Sopenharmony_ci struct mmiowb_state mmiowb_state; 28062306a36Sopenharmony_ci#endif 28162306a36Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64 28262306a36Sopenharmony_ci struct mce_info *mce_info; 28362306a36Sopenharmony_ci u8 mce_pending_irq_work; 28462306a36Sopenharmony_ci#endif /* CONFIG_PPC_BOOK3S_64 */ 28562306a36Sopenharmony_ci} ____cacheline_aligned; 28662306a36Sopenharmony_ci 28762306a36Sopenharmony_ciextern void copy_mm_to_paca(struct mm_struct *mm); 28862306a36Sopenharmony_ciextern struct paca_struct **paca_ptrs; 28962306a36Sopenharmony_ciextern void initialise_paca(struct paca_struct *new_paca, int cpu); 29062306a36Sopenharmony_ciextern void setup_paca(struct paca_struct *new_paca); 29162306a36Sopenharmony_ciextern void allocate_paca_ptrs(void); 29262306a36Sopenharmony_ciextern void allocate_paca(int cpu); 29362306a36Sopenharmony_ciextern void free_unused_pacas(void); 29462306a36Sopenharmony_ci 29562306a36Sopenharmony_ci#else /* CONFIG_PPC64 */ 29662306a36Sopenharmony_ci 29762306a36Sopenharmony_cistatic inline void allocate_paca(int cpu) { } 29862306a36Sopenharmony_cistatic inline void free_unused_pacas(void) { } 29962306a36Sopenharmony_ci 30062306a36Sopenharmony_ci#endif /* CONFIG_PPC64 */ 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ci#endif /* __KERNEL__ */ 30362306a36Sopenharmony_ci#endif /* _ASM_POWERPC_PACA_H */ 304