xref: /OK3568_Linux_fs/kernel/arch/powerpc/include/asm/lppaca.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * lppaca.h
4*4882a593Smuzhiyun  * Copyright (C) 2001  Mike Corrigan IBM Corporation
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun #ifndef _ASM_POWERPC_LPPACA_H
7*4882a593Smuzhiyun #define _ASM_POWERPC_LPPACA_H
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun /*
10*4882a593Smuzhiyun  * The below VPHN macros are outside the __KERNEL__ check since these are
11*4882a593Smuzhiyun  * used for compiling the vphn selftest in userspace
12*4882a593Smuzhiyun  */
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun /* The H_HOME_NODE_ASSOCIATIVITY h_call returns 6 64-bit registers. */
15*4882a593Smuzhiyun #define VPHN_REGISTER_COUNT 6
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /*
18*4882a593Smuzhiyun  * 6 64-bit registers unpacked into up to 24 be32 associativity values. To
19*4882a593Smuzhiyun  * form the complete property we have to add the length in the first cell.
20*4882a593Smuzhiyun  */
21*4882a593Smuzhiyun #define VPHN_ASSOC_BUFSIZE (VPHN_REGISTER_COUNT*sizeof(u64)/sizeof(u16) + 1)
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun /*
24*4882a593Smuzhiyun  * The H_HOME_NODE_ASSOCIATIVITY hcall takes two values for flags:
25*4882a593Smuzhiyun  * 1 for retrieving associativity information for a guest cpu
26*4882a593Smuzhiyun  * 2 for retrieving associativity information for a host/hypervisor cpu
27*4882a593Smuzhiyun  */
28*4882a593Smuzhiyun #define VPHN_FLAG_VCPU	1
29*4882a593Smuzhiyun #define VPHN_FLAG_PCPU	2
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #ifdef __KERNEL__
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun /*
34*4882a593Smuzhiyun  * These definitions relate to hypervisors that only exist when using
35*4882a593Smuzhiyun  * a server type processor
36*4882a593Smuzhiyun  */
37*4882a593Smuzhiyun #ifdef CONFIG_PPC_BOOK3S
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /*
40*4882a593Smuzhiyun  * This control block contains the data that is shared between the
41*4882a593Smuzhiyun  * hypervisor and the OS.
42*4882a593Smuzhiyun  */
43*4882a593Smuzhiyun #include <linux/cache.h>
44*4882a593Smuzhiyun #include <linux/threads.h>
45*4882a593Smuzhiyun #include <asm/types.h>
46*4882a593Smuzhiyun #include <asm/mmu.h>
47*4882a593Smuzhiyun #include <asm/firmware.h>
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun /*
50*4882a593Smuzhiyun  * The lppaca is the "virtual processor area" registered with the hypervisor,
51*4882a593Smuzhiyun  * H_REGISTER_VPA etc.
52*4882a593Smuzhiyun  *
53*4882a593Smuzhiyun  * According to PAPR, the structure is 640 bytes long, must be L1 cache line
54*4882a593Smuzhiyun  * aligned, and must not cross a 4kB boundary. Its size field must be at
55*4882a593Smuzhiyun  * least 640 bytes (but may be more).
56*4882a593Smuzhiyun  *
57*4882a593Smuzhiyun  * Pre-v4.14 KVM hypervisors reject the VPA if its size field is smaller than
58*4882a593Smuzhiyun  * 1kB, so we dynamically allocate 1kB and advertise size as 1kB, but keep
59*4882a593Smuzhiyun  * this structure as the canonical 640 byte size.
60*4882a593Smuzhiyun  */
61*4882a593Smuzhiyun struct lppaca {
62*4882a593Smuzhiyun 	/* cacheline 1 contains read-only data */
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun 	__be32	desc;			/* Eye catcher 0xD397D781 */
65*4882a593Smuzhiyun 	__be16	size;			/* Size of this struct */
66*4882a593Smuzhiyun 	u8	reserved1[3];
67*4882a593Smuzhiyun 	u8	__old_status;		/* Old status, including shared proc */
68*4882a593Smuzhiyun 	u8	reserved3[14];
69*4882a593Smuzhiyun 	volatile __be32 dyn_hw_node_id;	/* Dynamic hardware node id */
70*4882a593Smuzhiyun 	volatile __be32 dyn_hw_proc_id;	/* Dynamic hardware proc id */
71*4882a593Smuzhiyun 	u8	reserved4[56];
72*4882a593Smuzhiyun 	volatile u8 vphn_assoc_counts[8]; /* Virtual processor home node */
73*4882a593Smuzhiyun 					  /* associativity change counters */
74*4882a593Smuzhiyun 	u8	reserved5[32];
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun 	/* cacheline 2 contains local read-write data */
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun 	u8	reserved6[48];
79*4882a593Smuzhiyun 	u8	cede_latency_hint;
80*4882a593Smuzhiyun 	u8	ebb_regs_in_use;
81*4882a593Smuzhiyun 	u8	reserved7[6];
82*4882a593Smuzhiyun 	u8	dtl_enable_mask;	/* Dispatch Trace Log mask */
83*4882a593Smuzhiyun 	u8	donate_dedicated_cpu;	/* Donate dedicated CPU cycles */
84*4882a593Smuzhiyun 	u8	fpregs_in_use;
85*4882a593Smuzhiyun 	u8	pmcregs_in_use;
86*4882a593Smuzhiyun 	u8	reserved8[28];
87*4882a593Smuzhiyun 	__be64	wait_state_cycles;	/* Wait cycles for this proc */
88*4882a593Smuzhiyun 	u8	reserved9[28];
89*4882a593Smuzhiyun 	__be16	slb_count;		/* # of SLBs to maintain */
90*4882a593Smuzhiyun 	u8	idle;			/* Indicate OS is idle */
91*4882a593Smuzhiyun 	u8	vmxregs_in_use;
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun 	/* cacheline 3 is shared with other processors */
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun 	/*
96*4882a593Smuzhiyun 	 * This is the yield_count.  An "odd" value (low bit on) means that
97*4882a593Smuzhiyun 	 * the processor is yielded (either because of an OS yield or a
98*4882a593Smuzhiyun 	 * hypervisor preempt).  An even value implies that the processor is
99*4882a593Smuzhiyun 	 * currently executing.
100*4882a593Smuzhiyun 	 * NOTE: Even dedicated processor partitions can yield so this
101*4882a593Smuzhiyun 	 * field cannot be used to determine if we are shared or dedicated.
102*4882a593Smuzhiyun 	 */
103*4882a593Smuzhiyun 	volatile __be32 yield_count;
104*4882a593Smuzhiyun 	volatile __be32 dispersion_count; /* dispatch changed physical cpu */
105*4882a593Smuzhiyun 	volatile __be64 cmo_faults;	/* CMO page fault count */
106*4882a593Smuzhiyun 	volatile __be64 cmo_fault_time;	/* CMO page fault time */
107*4882a593Smuzhiyun 	u8	reserved10[104];
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun 	/* cacheline 4-5 */
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun 	__be32	page_ins;		/* CMO Hint - # page ins by OS */
112*4882a593Smuzhiyun 	u8	reserved11[148];
113*4882a593Smuzhiyun 	volatile __be64 dtl_idx;	/* Dispatch Trace Log head index */
114*4882a593Smuzhiyun 	u8	reserved12[96];
115*4882a593Smuzhiyun } ____cacheline_aligned;
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun #define lppaca_of(cpu)	(*paca_ptrs[cpu]->lppaca_ptr)
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun /*
120*4882a593Smuzhiyun  * We are using a non architected field to determine if a partition is
121*4882a593Smuzhiyun  * shared or dedicated. This currently works on both KVM and PHYP, but
122*4882a593Smuzhiyun  * we will have to transition to something better.
123*4882a593Smuzhiyun  */
124*4882a593Smuzhiyun #define LPPACA_OLD_SHARED_PROC		2
125*4882a593Smuzhiyun 
lppaca_shared_proc(struct lppaca * l)126*4882a593Smuzhiyun static inline bool lppaca_shared_proc(struct lppaca *l)
127*4882a593Smuzhiyun {
128*4882a593Smuzhiyun 	if (!firmware_has_feature(FW_FEATURE_SPLPAR))
129*4882a593Smuzhiyun 		return false;
130*4882a593Smuzhiyun 	return !!(l->__old_status & LPPACA_OLD_SHARED_PROC);
131*4882a593Smuzhiyun }
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun /*
134*4882a593Smuzhiyun  * SLB shadow buffer structure as defined in the PAPR.  The save_area
135*4882a593Smuzhiyun  * contains adjacent ESID and VSID pairs for each shadowed SLB.  The
136*4882a593Smuzhiyun  * ESID is stored in the lower 64bits, then the VSID.
137*4882a593Smuzhiyun  */
138*4882a593Smuzhiyun struct slb_shadow {
139*4882a593Smuzhiyun 	__be32	persistent;		/* Number of persistent SLBs */
140*4882a593Smuzhiyun 	__be32	buffer_length;		/* Total shadow buffer length */
141*4882a593Smuzhiyun 	__be64	reserved;
142*4882a593Smuzhiyun 	struct	{
143*4882a593Smuzhiyun 		__be64     esid;
144*4882a593Smuzhiyun 		__be64	vsid;
145*4882a593Smuzhiyun 	} save_area[SLB_NUM_BOLTED];
146*4882a593Smuzhiyun } ____cacheline_aligned;
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun extern long hcall_vphn(unsigned long cpu, u64 flags, __be32 *associativity);
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun #endif /* CONFIG_PPC_BOOK3S */
151*4882a593Smuzhiyun #endif /* __KERNEL__ */
152*4882a593Smuzhiyun #endif /* _ASM_POWERPC_LPPACA_H */
153