xref: /linux/arch/powerpc/include/asm/lppaca.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2b8b572e1SStephen Rothwell /*
3b8b572e1SStephen Rothwell  * lppaca.h
4b8b572e1SStephen Rothwell  * Copyright (C) 2001  Mike Corrigan IBM Corporation
5b8b572e1SStephen Rothwell  */
6b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_LPPACA_H
7b8b572e1SStephen Rothwell #define _ASM_POWERPC_LPPACA_H
85a1ea477SNaveen N. Rao 
9b8b572e1SStephen Rothwell #ifdef __KERNEL__
10b8b572e1SStephen Rothwell 
1159c19cb2SAnton Blanchard /*
1259c19cb2SAnton Blanchard  * These definitions relate to hypervisors that only exist when using
1394491685SBenjamin Herrenschmidt  * a server type processor
1494491685SBenjamin Herrenschmidt  */
1594491685SBenjamin Herrenschmidt #ifdef CONFIG_PPC_BOOK3S
1694491685SBenjamin Herrenschmidt 
1759c19cb2SAnton Blanchard /*
1859c19cb2SAnton Blanchard  * This control block contains the data that is shared between the
1959c19cb2SAnton Blanchard  * hypervisor and the OS.
2059c19cb2SAnton Blanchard  */
21b8b572e1SStephen Rothwell #include <linux/cache.h>
22f2f6dad6SBenjamin Herrenschmidt #include <linux/threads.h>
23b8b572e1SStephen Rothwell #include <asm/types.h>
24b8b572e1SStephen Rothwell #include <asm/mmu.h>
25a6201da3SAneesh Kumar K.V #include <asm/firmware.h>
26eac030b2SRussell Currey #include <asm/paca.h>
27b8b572e1SStephen Rothwell 
28f2f6dad6SBenjamin Herrenschmidt /*
29499dcd41SNicholas Piggin  * The lppaca is the "virtual processor area" registered with the hypervisor,
30499dcd41SNicholas Piggin  * H_REGISTER_VPA etc.
31499dcd41SNicholas Piggin  *
32499dcd41SNicholas Piggin  * According to PAPR, the structure is 640 bytes long, must be L1 cache line
33499dcd41SNicholas Piggin  * aligned, and must not cross a 4kB boundary. Its size field must be at
34499dcd41SNicholas Piggin  * least 640 bytes (but may be more).
35499dcd41SNicholas Piggin  *
36499dcd41SNicholas Piggin  * Pre-v4.14 KVM hypervisors reject the VPA if its size field is smaller than
37499dcd41SNicholas Piggin  * 1kB, so we dynamically allocate 1kB and advertise size as 1kB, but keep
38499dcd41SNicholas Piggin  * this structure as the canonical 640 byte size.
3959c19cb2SAnton Blanchard  */
40b8b572e1SStephen Rothwell struct lppaca {
4159c19cb2SAnton Blanchard 	/* cacheline 1 contains read-only data */
42b8b572e1SStephen Rothwell 
43c72cd555SAnton Blanchard 	__be32	desc;			/* Eye catcher 0xD397D781 */
44c72cd555SAnton Blanchard 	__be16	size;			/* Size of this struct */
45f13c13a0SAnton Blanchard 	u8	reserved1[3];
46f13c13a0SAnton Blanchard 	u8	__old_status;		/* Old status, including shared proc */
4759c19cb2SAnton Blanchard 	u8	reserved3[14];
48c72cd555SAnton Blanchard 	volatile __be32 dyn_hw_node_id;	/* Dynamic hardware node id */
49c72cd555SAnton Blanchard 	volatile __be32 dyn_hw_proc_id;	/* Dynamic hardware proc id */
5059c19cb2SAnton Blanchard 	u8	reserved4[56];
5159c19cb2SAnton Blanchard 	volatile u8 vphn_assoc_counts[8]; /* Virtual processor home node */
5259c19cb2SAnton Blanchard 					  /* associativity change counters */
5359c19cb2SAnton Blanchard 	u8	reserved5[32];
54b8b572e1SStephen Rothwell 
5559c19cb2SAnton Blanchard 	/* cacheline 2 contains local read-write data */
56b8b572e1SStephen Rothwell 
5759c19cb2SAnton Blanchard 	u8	reserved6[48];
5859c19cb2SAnton Blanchard 	u8	cede_latency_hint;
596e0b8bc9SMichael Ellerman 	u8	ebb_regs_in_use;
606e0b8bc9SMichael Ellerman 	u8	reserved7[6];
6159c19cb2SAnton Blanchard 	u8	dtl_enable_mask;	/* Dispatch Trace Log mask */
6259c19cb2SAnton Blanchard 	u8	donate_dedicated_cpu;	/* Donate dedicated CPU cycles */
6359c19cb2SAnton Blanchard 	u8	fpregs_in_use;
6459c19cb2SAnton Blanchard 	u8	pmcregs_in_use;
65*e1f288d2SGautam Menghani 	u8	l2_counters_enable;  /* Enable usage of counters for KVM guest */
66*e1f288d2SGautam Menghani 	u8	reserved8[27];
67c72cd555SAnton Blanchard 	__be64	wait_state_cycles;	/* Wait cycles for this proc */
6859c19cb2SAnton Blanchard 	u8	reserved9[28];
69c72cd555SAnton Blanchard 	__be16	slb_count;		/* # of SLBs to maintain */
7059c19cb2SAnton Blanchard 	u8	idle;			/* Indicate OS is idle */
7159c19cb2SAnton Blanchard 	u8	vmxregs_in_use;
72b8b572e1SStephen Rothwell 
7359c19cb2SAnton Blanchard 	/* cacheline 3 is shared with other processors */
7459c19cb2SAnton Blanchard 
7559c19cb2SAnton Blanchard 	/*
7659c19cb2SAnton Blanchard 	 * This is the yield_count.  An "odd" value (low bit on) means that
7759c19cb2SAnton Blanchard 	 * the processor is yielded (either because of an OS yield or a
7859c19cb2SAnton Blanchard 	 * hypervisor preempt).  An even value implies that the processor is
7959c19cb2SAnton Blanchard 	 * currently executing.
80733187e2SAnton Blanchard 	 * NOTE: Even dedicated processor partitions can yield so this
81733187e2SAnton Blanchard 	 * field cannot be used to determine if we are shared or dedicated.
8259c19cb2SAnton Blanchard 	 */
83c72cd555SAnton Blanchard 	volatile __be32 yield_count;
84c72cd555SAnton Blanchard 	volatile __be32 dispersion_count; /* dispatch changed physical cpu */
85c72cd555SAnton Blanchard 	volatile __be64 cmo_faults;	/* CMO page fault count */
86c72cd555SAnton Blanchard 	volatile __be64 cmo_fault_time;	/* CMO page fault time */
87a8933c8dSNicholas Piggin 	u8	reserved10[64];		/* [S]PURR expropriated/donated */
88a8933c8dSNicholas Piggin 	volatile __be64 enqueue_dispatch_tb; /* Total TB enqueue->dispatch */
89a8933c8dSNicholas Piggin 	volatile __be64 ready_enqueue_tb; /* Total TB ready->enqueue */
90a8933c8dSNicholas Piggin 	volatile __be64 wait_ready_tb;	/* Total TB wait->ready */
91a8933c8dSNicholas Piggin 	u8	reserved11[16];
9259c19cb2SAnton Blanchard 
9359c19cb2SAnton Blanchard 	/* cacheline 4-5 */
9459c19cb2SAnton Blanchard 
95c72cd555SAnton Blanchard 	__be32	page_ins;		/* CMO Hint - # page ins by OS */
96*e1f288d2SGautam Menghani 	u8	reserved12[28];
97*e1f288d2SGautam Menghani 	volatile __be64 l1_to_l2_cs_tb;
98*e1f288d2SGautam Menghani 	volatile __be64 l2_to_l1_cs_tb;
99*e1f288d2SGautam Menghani 	volatile __be64 l2_runtime_tb;
100a8933c8dSNicholas Piggin 	u8 reserved13[96];
101*e1f288d2SGautam Menghani 	volatile __be64 dtl_idx;	/* Dispatch Trace Log head index */
102*e1f288d2SGautam Menghani 	u8	reserved14[96];
103499dcd41SNicholas Piggin } ____cacheline_aligned;
104b8b572e1SStephen Rothwell 
105d2e60075SNicholas Piggin #define lppaca_of(cpu)	(*paca_ptrs[cpu]->lppaca_ptr)
1068154c5d2SPaul Mackerras 
107b8b572e1SStephen Rothwell /*
108733187e2SAnton Blanchard  * We are using a non architected field to determine if a partition is
109733187e2SAnton Blanchard  * shared or dedicated. This currently works on both KVM and PHYP, but
110733187e2SAnton Blanchard  * we will have to transition to something better.
111f13c13a0SAnton Blanchard  */
112f13c13a0SAnton Blanchard #define LPPACA_OLD_SHARED_PROC		2
113f13c13a0SAnton Blanchard 
114eac030b2SRussell Currey #ifdef CONFIG_PPC_PSERIES
115eac030b2SRussell Currey /*
116eac030b2SRussell Currey  * All CPUs should have the same shared proc value, so directly access the PACA
117eac030b2SRussell Currey  * to avoid false positives from DEBUG_PREEMPT.
118eac030b2SRussell Currey  */
lppaca_shared_proc(void)119eac030b2SRussell Currey static inline bool lppaca_shared_proc(void)
120f13c13a0SAnton Blanchard {
121eac030b2SRussell Currey 	struct lppaca *l = local_paca->lppaca_ptr;
122eac030b2SRussell Currey 
123a6201da3SAneesh Kumar K.V 	if (!firmware_has_feature(FW_FEATURE_SPLPAR))
124a6201da3SAneesh Kumar K.V 		return false;
125733187e2SAnton Blanchard 	return !!(l->__old_status & LPPACA_OLD_SHARED_PROC);
126f13c13a0SAnton Blanchard }
127f13c13a0SAnton Blanchard 
1281aa00066SMichael Ellerman #define get_lppaca()	(get_paca()->lppaca_ptr)
1291aa00066SMichael Ellerman #endif
1301aa00066SMichael Ellerman 
131f13c13a0SAnton Blanchard /*
132b8b572e1SStephen Rothwell  * SLB shadow buffer structure as defined in the PAPR.  The save_area
133b8b572e1SStephen Rothwell  * contains adjacent ESID and VSID pairs for each shadowed SLB.  The
134b8b572e1SStephen Rothwell  * ESID is stored in the lower 64bits, then the VSID.
135b8b572e1SStephen Rothwell  */
136b8b572e1SStephen Rothwell struct slb_shadow {
137c72cd555SAnton Blanchard 	__be32	persistent;		/* Number of persistent SLBs */
138c72cd555SAnton Blanchard 	__be32	buffer_length;		/* Total shadow buffer length */
139c72cd555SAnton Blanchard 	__be64	reserved;
140b8b572e1SStephen Rothwell 	struct	{
141c72cd555SAnton Blanchard 		__be64     esid;
142c72cd555SAnton Blanchard 		__be64	vsid;
14359c19cb2SAnton Blanchard 	} save_area[SLB_NUM_BOLTED];
144b8b572e1SStephen Rothwell } ____cacheline_aligned;
145b8b572e1SStephen Rothwell 
14694491685SBenjamin Herrenschmidt #endif /* CONFIG_PPC_BOOK3S */
147b8b572e1SStephen Rothwell #endif /* __KERNEL__ */
148b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_LPPACA_H */
149