18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * lppaca.h
48c2ecf20Sopenharmony_ci * Copyright (C) 2001  Mike Corrigan IBM Corporation
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_LPPACA_H
78c2ecf20Sopenharmony_ci#define _ASM_POWERPC_LPPACA_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci/*
108c2ecf20Sopenharmony_ci * The below VPHN macros are outside the __KERNEL__ check since these are
118c2ecf20Sopenharmony_ci * used for compiling the vphn selftest in userspace
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/* The H_HOME_NODE_ASSOCIATIVITY h_call returns 6 64-bit registers. */
158c2ecf20Sopenharmony_ci#define VPHN_REGISTER_COUNT 6
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/*
188c2ecf20Sopenharmony_ci * 6 64-bit registers unpacked into up to 24 be32 associativity values. To
198c2ecf20Sopenharmony_ci * form the complete property we have to add the length in the first cell.
208c2ecf20Sopenharmony_ci */
218c2ecf20Sopenharmony_ci#define VPHN_ASSOC_BUFSIZE (VPHN_REGISTER_COUNT*sizeof(u64)/sizeof(u16) + 1)
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci/*
248c2ecf20Sopenharmony_ci * The H_HOME_NODE_ASSOCIATIVITY hcall takes two values for flags:
258c2ecf20Sopenharmony_ci * 1 for retrieving associativity information for a guest cpu
268c2ecf20Sopenharmony_ci * 2 for retrieving associativity information for a host/hypervisor cpu
278c2ecf20Sopenharmony_ci */
288c2ecf20Sopenharmony_ci#define VPHN_FLAG_VCPU	1
298c2ecf20Sopenharmony_ci#define VPHN_FLAG_PCPU	2
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#ifdef __KERNEL__
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci/*
348c2ecf20Sopenharmony_ci * These definitions relate to hypervisors that only exist when using
358c2ecf20Sopenharmony_ci * a server type processor
368c2ecf20Sopenharmony_ci */
378c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/*
408c2ecf20Sopenharmony_ci * This control block contains the data that is shared between the
418c2ecf20Sopenharmony_ci * hypervisor and the OS.
428c2ecf20Sopenharmony_ci */
438c2ecf20Sopenharmony_ci#include <linux/cache.h>
448c2ecf20Sopenharmony_ci#include <linux/threads.h>
458c2ecf20Sopenharmony_ci#include <asm/types.h>
468c2ecf20Sopenharmony_ci#include <asm/mmu.h>
478c2ecf20Sopenharmony_ci#include <asm/firmware.h>
488c2ecf20Sopenharmony_ci#include <asm/paca.h>
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/*
518c2ecf20Sopenharmony_ci * The lppaca is the "virtual processor area" registered with the hypervisor,
528c2ecf20Sopenharmony_ci * H_REGISTER_VPA etc.
538c2ecf20Sopenharmony_ci *
548c2ecf20Sopenharmony_ci * According to PAPR, the structure is 640 bytes long, must be L1 cache line
558c2ecf20Sopenharmony_ci * aligned, and must not cross a 4kB boundary. Its size field must be at
568c2ecf20Sopenharmony_ci * least 640 bytes (but may be more).
578c2ecf20Sopenharmony_ci *
588c2ecf20Sopenharmony_ci * Pre-v4.14 KVM hypervisors reject the VPA if its size field is smaller than
598c2ecf20Sopenharmony_ci * 1kB, so we dynamically allocate 1kB and advertise size as 1kB, but keep
608c2ecf20Sopenharmony_ci * this structure as the canonical 640 byte size.
618c2ecf20Sopenharmony_ci */
628c2ecf20Sopenharmony_cistruct lppaca {
638c2ecf20Sopenharmony_ci	/* cacheline 1 contains read-only data */
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	__be32	desc;			/* Eye catcher 0xD397D781 */
668c2ecf20Sopenharmony_ci	__be16	size;			/* Size of this struct */
678c2ecf20Sopenharmony_ci	u8	reserved1[3];
688c2ecf20Sopenharmony_ci	u8	__old_status;		/* Old status, including shared proc */
698c2ecf20Sopenharmony_ci	u8	reserved3[14];
708c2ecf20Sopenharmony_ci	volatile __be32 dyn_hw_node_id;	/* Dynamic hardware node id */
718c2ecf20Sopenharmony_ci	volatile __be32 dyn_hw_proc_id;	/* Dynamic hardware proc id */
728c2ecf20Sopenharmony_ci	u8	reserved4[56];
738c2ecf20Sopenharmony_ci	volatile u8 vphn_assoc_counts[8]; /* Virtual processor home node */
748c2ecf20Sopenharmony_ci					  /* associativity change counters */
758c2ecf20Sopenharmony_ci	u8	reserved5[32];
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	/* cacheline 2 contains local read-write data */
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	u8	reserved6[48];
808c2ecf20Sopenharmony_ci	u8	cede_latency_hint;
818c2ecf20Sopenharmony_ci	u8	ebb_regs_in_use;
828c2ecf20Sopenharmony_ci	u8	reserved7[6];
838c2ecf20Sopenharmony_ci	u8	dtl_enable_mask;	/* Dispatch Trace Log mask */
848c2ecf20Sopenharmony_ci	u8	donate_dedicated_cpu;	/* Donate dedicated CPU cycles */
858c2ecf20Sopenharmony_ci	u8	fpregs_in_use;
868c2ecf20Sopenharmony_ci	u8	pmcregs_in_use;
878c2ecf20Sopenharmony_ci	u8	reserved8[28];
888c2ecf20Sopenharmony_ci	__be64	wait_state_cycles;	/* Wait cycles for this proc */
898c2ecf20Sopenharmony_ci	u8	reserved9[28];
908c2ecf20Sopenharmony_ci	__be16	slb_count;		/* # of SLBs to maintain */
918c2ecf20Sopenharmony_ci	u8	idle;			/* Indicate OS is idle */
928c2ecf20Sopenharmony_ci	u8	vmxregs_in_use;
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	/* cacheline 3 is shared with other processors */
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci	/*
978c2ecf20Sopenharmony_ci	 * This is the yield_count.  An "odd" value (low bit on) means that
988c2ecf20Sopenharmony_ci	 * the processor is yielded (either because of an OS yield or a
998c2ecf20Sopenharmony_ci	 * hypervisor preempt).  An even value implies that the processor is
1008c2ecf20Sopenharmony_ci	 * currently executing.
1018c2ecf20Sopenharmony_ci	 * NOTE: Even dedicated processor partitions can yield so this
1028c2ecf20Sopenharmony_ci	 * field cannot be used to determine if we are shared or dedicated.
1038c2ecf20Sopenharmony_ci	 */
1048c2ecf20Sopenharmony_ci	volatile __be32 yield_count;
1058c2ecf20Sopenharmony_ci	volatile __be32 dispersion_count; /* dispatch changed physical cpu */
1068c2ecf20Sopenharmony_ci	volatile __be64 cmo_faults;	/* CMO page fault count */
1078c2ecf20Sopenharmony_ci	volatile __be64 cmo_fault_time;	/* CMO page fault time */
1088c2ecf20Sopenharmony_ci	u8	reserved10[104];
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	/* cacheline 4-5 */
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci	__be32	page_ins;		/* CMO Hint - # page ins by OS */
1138c2ecf20Sopenharmony_ci	u8	reserved11[148];
1148c2ecf20Sopenharmony_ci	volatile __be64 dtl_idx;	/* Dispatch Trace Log head index */
1158c2ecf20Sopenharmony_ci	u8	reserved12[96];
1168c2ecf20Sopenharmony_ci} ____cacheline_aligned;
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci#define lppaca_of(cpu)	(*paca_ptrs[cpu]->lppaca_ptr)
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci/*
1218c2ecf20Sopenharmony_ci * We are using a non architected field to determine if a partition is
1228c2ecf20Sopenharmony_ci * shared or dedicated. This currently works on both KVM and PHYP, but
1238c2ecf20Sopenharmony_ci * we will have to transition to something better.
1248c2ecf20Sopenharmony_ci */
1258c2ecf20Sopenharmony_ci#define LPPACA_OLD_SHARED_PROC		2
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_PSERIES
1288c2ecf20Sopenharmony_ci/*
1298c2ecf20Sopenharmony_ci * All CPUs should have the same shared proc value, so directly access the PACA
1308c2ecf20Sopenharmony_ci * to avoid false positives from DEBUG_PREEMPT.
1318c2ecf20Sopenharmony_ci */
1328c2ecf20Sopenharmony_cistatic inline bool lppaca_shared_proc(void)
1338c2ecf20Sopenharmony_ci{
1348c2ecf20Sopenharmony_ci	struct lppaca *l = local_paca->lppaca_ptr;
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	if (!firmware_has_feature(FW_FEATURE_SPLPAR))
1378c2ecf20Sopenharmony_ci		return false;
1388c2ecf20Sopenharmony_ci	return !!(l->__old_status & LPPACA_OLD_SHARED_PROC);
1398c2ecf20Sopenharmony_ci}
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci#define get_lppaca()	(get_paca()->lppaca_ptr)
1428c2ecf20Sopenharmony_ci#endif
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci/*
1458c2ecf20Sopenharmony_ci * SLB shadow buffer structure as defined in the PAPR.  The save_area
1468c2ecf20Sopenharmony_ci * contains adjacent ESID and VSID pairs for each shadowed SLB.  The
1478c2ecf20Sopenharmony_ci * ESID is stored in the lower 64bits, then the VSID.
1488c2ecf20Sopenharmony_ci */
1498c2ecf20Sopenharmony_cistruct slb_shadow {
1508c2ecf20Sopenharmony_ci	__be32	persistent;		/* Number of persistent SLBs */
1518c2ecf20Sopenharmony_ci	__be32	buffer_length;		/* Total shadow buffer length */
1528c2ecf20Sopenharmony_ci	__be64	reserved;
1538c2ecf20Sopenharmony_ci	struct	{
1548c2ecf20Sopenharmony_ci		__be64     esid;
1558c2ecf20Sopenharmony_ci		__be64	vsid;
1568c2ecf20Sopenharmony_ci	} save_area[SLB_NUM_BOLTED];
1578c2ecf20Sopenharmony_ci} ____cacheline_aligned;
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ciextern long hcall_vphn(unsigned long cpu, u64 flags, __be32 *associativity);
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci#endif /* CONFIG_PPC_BOOK3S */
1628c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
1638c2ecf20Sopenharmony_ci#endif /* _ASM_POWERPC_LPPACA_H */
164