11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * lppaca.h
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 2001  Mike Corrigan IBM Corporation
41da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This program is free software; you can redistribute it and/or modify
61da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * it under the terms of the GNU General Public License as published by
71da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * the Free Software Foundation; either version 2 of the License, or
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * (at your option) any later version.
91da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * This program is distributed in the hope that it will be useful,
111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * but WITHOUT ANY WARRANTY; without even the implied warranty of
121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * GNU General Public License for more details.
141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * You should have received a copy of the GNU General Public License
161da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * along with this program; if not, write to the Free Software
171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
181da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
198882a4da1c932c9f311c9f739e6719adea3e25d9David Gibson#ifndef _ASM_POWERPC_LPPACA_H
208882a4da1c932c9f311c9f739e6719adea3e25d9David Gibson#define _ASM_POWERPC_LPPACA_H
2188ced0314938814e1772b4d0d7ab20c52e4472b6Arnd Bergmann#ifdef __KERNEL__
221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
2359c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard/*
2459c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard * These definitions relate to hypervisors that only exist when using
25944916858a430a0627e483657d4cfa2cd2dfb4f7Benjamin Herrenschmidt * a server type processor
26944916858a430a0627e483657d4cfa2cd2dfb4f7Benjamin Herrenschmidt */
27944916858a430a0627e483657d4cfa2cd2dfb4f7Benjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3S
28944916858a430a0627e483657d4cfa2cd2dfb4f7Benjamin Herrenschmidt
2959c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard/*
3059c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard * This control block contains the data that is shared between the
3159c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard * hypervisor and the OS.
3259c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard */
332f6093c84730b4bad65bcd0f2f904a5769b1dfc5Michael Neuling#include <linux/cache.h>
34f2f6dad6ca3b06ae35a2e7b63f38158242c01531Benjamin Herrenschmidt#include <linux/threads.h>
351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/types.h>
362f6093c84730b4bad65bcd0f2f904a5769b1dfc5Michael Neuling#include <asm/mmu.h>
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
38f2f6dad6ca3b06ae35a2e7b63f38158242c01531Benjamin Herrenschmidt/*
39f2f6dad6ca3b06ae35a2e7b63f38158242c01531Benjamin Herrenschmidt * We only have to have statically allocated lppaca structs on
40f2f6dad6ca3b06ae35a2e7b63f38158242c01531Benjamin Herrenschmidt * legacy iSeries, which supports at most 64 cpus.
41f2f6dad6ca3b06ae35a2e7b63f38158242c01531Benjamin Herrenschmidt */
42f2f6dad6ca3b06ae35a2e7b63f38158242c01531Benjamin Herrenschmidt#define NR_LPPACAS	1
43f2f6dad6ca3b06ae35a2e7b63f38158242c01531Benjamin Herrenschmidt
4459c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard/*
4559c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard * The Hypervisor barfs if the lppaca crosses a page boundary.  A 1k
4659c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard * alignment is sufficient to prevent this
4759c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard */
48c6b3feaf5774508ab5a955a81e45ffefa3b12eaaBryan O'Sullivanstruct lppaca {
4959c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	/* cacheline 1 contains read-only data */
5059c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard
51c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be32	desc;			/* Eye catcher 0xD397D781 */
52c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be16	size;			/* Size of this struct */
53f13c13a005127b5dc5daaca190277a062d946e63Anton Blanchard	u8	reserved1[3];
54f13c13a005127b5dc5daaca190277a062d946e63Anton Blanchard	u8	__old_status;		/* Old status, including shared proc */
5559c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	reserved3[14];
56c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	volatile __be32 dyn_hw_node_id;	/* Dynamic hardware node id */
57c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	volatile __be32 dyn_hw_proc_id;	/* Dynamic hardware proc id */
5859c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	reserved4[56];
5959c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	volatile u8 vphn_assoc_counts[8]; /* Virtual processor home node */
6059c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard					  /* associativity change counters */
6159c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	reserved5[32];
6259c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard
6359c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	/* cacheline 2 contains local read-write data */
6459c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard
6559c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	reserved6[48];
6659c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	cede_latency_hint;
676e0b8bc965d25a8e0701eaca3fca5941b4f4b2b2Michael Ellerman	u8	ebb_regs_in_use;
686e0b8bc965d25a8e0701eaca3fca5941b4f4b2b2Michael Ellerman	u8	reserved7[6];
6959c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	dtl_enable_mask;	/* Dispatch Trace Log mask */
7059c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	donate_dedicated_cpu;	/* Donate dedicated CPU cycles */
7159c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	fpregs_in_use;
7259c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	pmcregs_in_use;
7359c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	reserved8[28];
74c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be64	wait_state_cycles;	/* Wait cycles for this proc */
7559c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	reserved9[28];
76c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be16	slb_count;		/* # of SLBs to maintain */
7759c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	idle;			/* Indicate OS is idle */
7859c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	vmxregs_in_use;
7959c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard
8059c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	/* cacheline 3 is shared with other processors */
8159c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard
8259c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	/*
8359c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	 * This is the yield_count.  An "odd" value (low bit on) means that
8459c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	 * the processor is yielded (either because of an OS yield or a
8559c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	 * hypervisor preempt).  An even value implies that the processor is
8659c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	 * currently executing.
87733187e29576041ceccf3b82092ca900fc929170Anton Blanchard	 * NOTE: Even dedicated processor partitions can yield so this
88733187e29576041ceccf3b82092ca900fc929170Anton Blanchard	 * field cannot be used to determine if we are shared or dedicated.
8959c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	 */
90c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	volatile __be32 yield_count;
91c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	volatile __be32 dispersion_count; /* dispatch changed physical cpu */
92c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	volatile __be64 cmo_faults;	/* CMO page fault count */
93c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	volatile __be64 cmo_fault_time;	/* CMO page fault time */
9459c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	reserved10[104];
9559c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard
9659c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	/* cacheline 4-5 */
9759c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard
98c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be32	page_ins;		/* CMO Hint - # page ins by OS */
9959c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	reserved11[148];
100c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	volatile __be64 dtl_idx;		/* Dispatch Trace Log head index */
10159c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	u8	reserved12[96];
102c6b3feaf5774508ab5a955a81e45ffefa3b12eaaBryan O'Sullivan} __attribute__((__aligned__(0x400)));
1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
1043356bb9f7ba378a6e2709f9df95f4ea52111f4dfDavid Gibsonextern struct lppaca lppaca[];
1053356bb9f7ba378a6e2709f9df95f4ea52111f4dfDavid Gibson
10693c22703efa72c7527dbd586d1951c1f4a85fd70Paul Mackerras#define lppaca_of(cpu)	(*paca[cpu].lppaca_ptr)
1078154c5d22d91cd16bd9985b0638c8957e4688d0ePaul Mackerras
1082f6093c84730b4bad65bcd0f2f904a5769b1dfc5Michael Neuling/*
109733187e29576041ceccf3b82092ca900fc929170Anton Blanchard * We are using a non architected field to determine if a partition is
110733187e29576041ceccf3b82092ca900fc929170Anton Blanchard * shared or dedicated. This currently works on both KVM and PHYP, but
111733187e29576041ceccf3b82092ca900fc929170Anton Blanchard * we will have to transition to something better.
112f13c13a005127b5dc5daaca190277a062d946e63Anton Blanchard */
113f13c13a005127b5dc5daaca190277a062d946e63Anton Blanchard#define LPPACA_OLD_SHARED_PROC		2
114f13c13a005127b5dc5daaca190277a062d946e63Anton Blanchard
115f13c13a005127b5dc5daaca190277a062d946e63Anton Blanchardstatic inline bool lppaca_shared_proc(struct lppaca *l)
116f13c13a005127b5dc5daaca190277a062d946e63Anton Blanchard{
117733187e29576041ceccf3b82092ca900fc929170Anton Blanchard	return !!(l->__old_status & LPPACA_OLD_SHARED_PROC);
118f13c13a005127b5dc5daaca190277a062d946e63Anton Blanchard}
119f13c13a005127b5dc5daaca190277a062d946e63Anton Blanchard
120f13c13a005127b5dc5daaca190277a062d946e63Anton Blanchard/*
1212f6093c84730b4bad65bcd0f2f904a5769b1dfc5Michael Neuling * SLB shadow buffer structure as defined in the PAPR.  The save_area
1222f6093c84730b4bad65bcd0f2f904a5769b1dfc5Michael Neuling * contains adjacent ESID and VSID pairs for each shadowed SLB.  The
1232f6093c84730b4bad65bcd0f2f904a5769b1dfc5Michael Neuling * ESID is stored in the lower 64bits, then the VSID.
1242f6093c84730b4bad65bcd0f2f904a5769b1dfc5Michael Neuling */
1252f6093c84730b4bad65bcd0f2f904a5769b1dfc5Michael Neulingstruct slb_shadow {
126c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be32	persistent;		/* Number of persistent SLBs */
127c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be32	buffer_length;		/* Total shadow buffer length */
128c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be64	reserved;
1292f6093c84730b4bad65bcd0f2f904a5769b1dfc5Michael Neuling	struct	{
130c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard		__be64     esid;
131c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard		__be64	vsid;
13259c19cb2f6a7928a2fd3afd22bfe988e025b41d8Anton Blanchard	} save_area[SLB_NUM_BOLTED];
1332f6093c84730b4bad65bcd0f2f904a5769b1dfc5Michael Neuling} ____cacheline_aligned;
1342f6093c84730b4bad65bcd0f2f904a5769b1dfc5Michael Neuling
135cf9efce0ce3136fa076f53e53154e98455229514Paul Mackerras/*
136cf9efce0ce3136fa076f53e53154e98455229514Paul Mackerras * Layout of entries in the hypervisor's dispatch trace log buffer.
137cf9efce0ce3136fa076f53e53154e98455229514Paul Mackerras */
138cf9efce0ce3136fa076f53e53154e98455229514Paul Mackerrasstruct dtl_entry {
139cf9efce0ce3136fa076f53e53154e98455229514Paul Mackerras	u8	dispatch_reason;
140cf9efce0ce3136fa076f53e53154e98455229514Paul Mackerras	u8	preempt_reason;
141c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be16	processor_id;
142c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be32	enqueue_to_dispatch_time;
143c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be32	ready_to_enqueue_time;
144c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be32	waiting_to_ready_time;
145c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be64	timebase;
146c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be64	fault_addr;
147c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be64	srr0;
148c72cd555e828b710bce8c3635254dbb483397142Anton Blanchard	__be64	srr1;
149cf9efce0ce3136fa076f53e53154e98455229514Paul Mackerras};
150cf9efce0ce3136fa076f53e53154e98455229514Paul Mackerras
151cf9efce0ce3136fa076f53e53154e98455229514Paul Mackerras#define DISPATCH_LOG_BYTES	4096	/* bytes per cpu */
152cf9efce0ce3136fa076f53e53154e98455229514Paul Mackerras#define N_DISPATCH_LOG		(DISPATCH_LOG_BYTES / sizeof(struct dtl_entry))
153cf9efce0ce3136fa076f53e53154e98455229514Paul Mackerras
154af442a1baa6d00117cc7e7377ce7e6a545268684Nishanth Aravamudanextern struct kmem_cache *dtl_cache;
155af442a1baa6d00117cc7e7377ce7e6a545268684Nishanth Aravamudan
156872e439a45ed4a4bd499bc55cb0dffa74027f749Paul Mackerras/*
157abf917cd91cbb73952758f9741e2fa65002a48eeFrederic Weisbecker * When CONFIG_VIRT_CPU_ACCOUNTING_NATIVE = y, the cpu accounting code controls
158872e439a45ed4a4bd499bc55cb0dffa74027f749Paul Mackerras * reading from the dispatch trace log.  If other code wants to consume
159872e439a45ed4a4bd499bc55cb0dffa74027f749Paul Mackerras * DTL entries, it can set this pointer to a function that will get
160872e439a45ed4a4bd499bc55cb0dffa74027f749Paul Mackerras * called once for each DTL entry that gets processed.
161872e439a45ed4a4bd499bc55cb0dffa74027f749Paul Mackerras */
162872e439a45ed4a4bd499bc55cb0dffa74027f749Paul Mackerrasextern void (*dtl_consumer)(struct dtl_entry *entry, u64 index);
163872e439a45ed4a4bd499bc55cb0dffa74027f749Paul Mackerras
164944916858a430a0627e483657d4cfa2cd2dfb4f7Benjamin Herrenschmidt#endif /* CONFIG_PPC_BOOK3S */
16588ced0314938814e1772b4d0d7ab20c52e4472b6Arnd Bergmann#endif /* __KERNEL__ */
1668882a4da1c932c9f311c9f739e6719adea3e25d9David Gibson#endif /* _ASM_POWERPC_LPPACA_H */
167