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