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