1b8b572e1SStephen Rothwell /* 2b8b572e1SStephen Rothwell * lppaca.h 3b8b572e1SStephen Rothwell * Copyright (C) 2001 Mike Corrigan IBM Corporation 4b8b572e1SStephen Rothwell * 5b8b572e1SStephen Rothwell * This program is free software; you can redistribute it and/or modify 6b8b572e1SStephen Rothwell * it under the terms of the GNU General Public License as published by 7b8b572e1SStephen Rothwell * the Free Software Foundation; either version 2 of the License, or 8b8b572e1SStephen Rothwell * (at your option) any later version. 9b8b572e1SStephen Rothwell * 10b8b572e1SStephen Rothwell * This program is distributed in the hope that it will be useful, 11b8b572e1SStephen Rothwell * but WITHOUT ANY WARRANTY; without even the implied warranty of 12b8b572e1SStephen Rothwell * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13b8b572e1SStephen Rothwell * GNU General Public License for more details. 14b8b572e1SStephen Rothwell * 15b8b572e1SStephen Rothwell * You should have received a copy of the GNU General Public License 16b8b572e1SStephen Rothwell * along with this program; if not, write to the Free Software 17b8b572e1SStephen Rothwell * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18b8b572e1SStephen Rothwell */ 19b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_LPPACA_H 20b8b572e1SStephen Rothwell #define _ASM_POWERPC_LPPACA_H 21b8b572e1SStephen Rothwell #ifdef __KERNEL__ 22b8b572e1SStephen Rothwell 2359c19cb2SAnton Blanchard /* 2459c19cb2SAnton Blanchard * These definitions relate to hypervisors that only exist when using 2594491685SBenjamin Herrenschmidt * a server type processor 2694491685SBenjamin Herrenschmidt */ 2794491685SBenjamin Herrenschmidt #ifdef CONFIG_PPC_BOOK3S 2894491685SBenjamin Herrenschmidt 2959c19cb2SAnton Blanchard /* 3059c19cb2SAnton Blanchard * This control block contains the data that is shared between the 3159c19cb2SAnton Blanchard * hypervisor and the OS. 3259c19cb2SAnton Blanchard */ 33b8b572e1SStephen Rothwell #include <linux/cache.h> 34f2f6dad6SBenjamin Herrenschmidt #include <linux/threads.h> 35b8b572e1SStephen Rothwell #include <asm/types.h> 36b8b572e1SStephen Rothwell #include <asm/mmu.h> 37*a6201da3SAneesh Kumar K.V #include <asm/firmware.h> 38b8b572e1SStephen Rothwell 39f2f6dad6SBenjamin Herrenschmidt /* 40499dcd41SNicholas Piggin * The lppaca is the "virtual processor area" registered with the hypervisor, 41499dcd41SNicholas Piggin * H_REGISTER_VPA etc. 42499dcd41SNicholas Piggin * 43499dcd41SNicholas Piggin * According to PAPR, the structure is 640 bytes long, must be L1 cache line 44499dcd41SNicholas Piggin * aligned, and must not cross a 4kB boundary. Its size field must be at 45499dcd41SNicholas Piggin * least 640 bytes (but may be more). 46499dcd41SNicholas Piggin * 47499dcd41SNicholas Piggin * Pre-v4.14 KVM hypervisors reject the VPA if its size field is smaller than 48499dcd41SNicholas Piggin * 1kB, so we dynamically allocate 1kB and advertise size as 1kB, but keep 49499dcd41SNicholas Piggin * this structure as the canonical 640 byte size. 5059c19cb2SAnton Blanchard */ 51b8b572e1SStephen Rothwell struct lppaca { 5259c19cb2SAnton Blanchard /* cacheline 1 contains read-only data */ 53b8b572e1SStephen Rothwell 54c72cd555SAnton Blanchard __be32 desc; /* Eye catcher 0xD397D781 */ 55c72cd555SAnton Blanchard __be16 size; /* Size of this struct */ 56f13c13a0SAnton Blanchard u8 reserved1[3]; 57f13c13a0SAnton Blanchard u8 __old_status; /* Old status, including shared proc */ 5859c19cb2SAnton Blanchard u8 reserved3[14]; 59c72cd555SAnton Blanchard volatile __be32 dyn_hw_node_id; /* Dynamic hardware node id */ 60c72cd555SAnton Blanchard volatile __be32 dyn_hw_proc_id; /* Dynamic hardware proc id */ 6159c19cb2SAnton Blanchard u8 reserved4[56]; 6259c19cb2SAnton Blanchard volatile u8 vphn_assoc_counts[8]; /* Virtual processor home node */ 6359c19cb2SAnton Blanchard /* associativity change counters */ 6459c19cb2SAnton Blanchard u8 reserved5[32]; 65b8b572e1SStephen Rothwell 6659c19cb2SAnton Blanchard /* cacheline 2 contains local read-write data */ 67b8b572e1SStephen Rothwell 6859c19cb2SAnton Blanchard u8 reserved6[48]; 6959c19cb2SAnton Blanchard u8 cede_latency_hint; 706e0b8bc9SMichael Ellerman u8 ebb_regs_in_use; 716e0b8bc9SMichael Ellerman u8 reserved7[6]; 7259c19cb2SAnton Blanchard u8 dtl_enable_mask; /* Dispatch Trace Log mask */ 7359c19cb2SAnton Blanchard u8 donate_dedicated_cpu; /* Donate dedicated CPU cycles */ 7459c19cb2SAnton Blanchard u8 fpregs_in_use; 7559c19cb2SAnton Blanchard u8 pmcregs_in_use; 7659c19cb2SAnton Blanchard u8 reserved8[28]; 77c72cd555SAnton Blanchard __be64 wait_state_cycles; /* Wait cycles for this proc */ 7859c19cb2SAnton Blanchard u8 reserved9[28]; 79c72cd555SAnton Blanchard __be16 slb_count; /* # of SLBs to maintain */ 8059c19cb2SAnton Blanchard u8 idle; /* Indicate OS is idle */ 8159c19cb2SAnton Blanchard u8 vmxregs_in_use; 82b8b572e1SStephen Rothwell 8359c19cb2SAnton Blanchard /* cacheline 3 is shared with other processors */ 8459c19cb2SAnton Blanchard 8559c19cb2SAnton Blanchard /* 8659c19cb2SAnton Blanchard * This is the yield_count. An "odd" value (low bit on) means that 8759c19cb2SAnton Blanchard * the processor is yielded (either because of an OS yield or a 8859c19cb2SAnton Blanchard * hypervisor preempt). An even value implies that the processor is 8959c19cb2SAnton Blanchard * currently executing. 90733187e2SAnton Blanchard * NOTE: Even dedicated processor partitions can yield so this 91733187e2SAnton Blanchard * field cannot be used to determine if we are shared or dedicated. 9259c19cb2SAnton Blanchard */ 93c72cd555SAnton Blanchard volatile __be32 yield_count; 94c72cd555SAnton Blanchard volatile __be32 dispersion_count; /* dispatch changed physical cpu */ 95c72cd555SAnton Blanchard volatile __be64 cmo_faults; /* CMO page fault count */ 96c72cd555SAnton Blanchard volatile __be64 cmo_fault_time; /* CMO page fault time */ 9759c19cb2SAnton Blanchard u8 reserved10[104]; 9859c19cb2SAnton Blanchard 9959c19cb2SAnton Blanchard /* cacheline 4-5 */ 10059c19cb2SAnton Blanchard 101c72cd555SAnton Blanchard __be32 page_ins; /* CMO Hint - # page ins by OS */ 10259c19cb2SAnton Blanchard u8 reserved11[148]; 103c72cd555SAnton Blanchard volatile __be64 dtl_idx; /* Dispatch Trace Log head index */ 10459c19cb2SAnton Blanchard u8 reserved12[96]; 105499dcd41SNicholas Piggin } ____cacheline_aligned; 106b8b572e1SStephen Rothwell 107d2e60075SNicholas Piggin #define lppaca_of(cpu) (*paca_ptrs[cpu]->lppaca_ptr) 1088154c5d2SPaul Mackerras 109b8b572e1SStephen Rothwell /* 110733187e2SAnton Blanchard * We are using a non architected field to determine if a partition is 111733187e2SAnton Blanchard * shared or dedicated. This currently works on both KVM and PHYP, but 112733187e2SAnton Blanchard * we will have to transition to something better. 113f13c13a0SAnton Blanchard */ 114f13c13a0SAnton Blanchard #define LPPACA_OLD_SHARED_PROC 2 115f13c13a0SAnton Blanchard 116f13c13a0SAnton Blanchard static inline bool lppaca_shared_proc(struct lppaca *l) 117f13c13a0SAnton Blanchard { 118*a6201da3SAneesh Kumar K.V if (!firmware_has_feature(FW_FEATURE_SPLPAR)) 119*a6201da3SAneesh Kumar K.V return false; 120733187e2SAnton Blanchard return !!(l->__old_status & LPPACA_OLD_SHARED_PROC); 121f13c13a0SAnton Blanchard } 122f13c13a0SAnton Blanchard 123f13c13a0SAnton Blanchard /* 124b8b572e1SStephen Rothwell * SLB shadow buffer structure as defined in the PAPR. The save_area 125b8b572e1SStephen Rothwell * contains adjacent ESID and VSID pairs for each shadowed SLB. The 126b8b572e1SStephen Rothwell * ESID is stored in the lower 64bits, then the VSID. 127b8b572e1SStephen Rothwell */ 128b8b572e1SStephen Rothwell struct slb_shadow { 129c72cd555SAnton Blanchard __be32 persistent; /* Number of persistent SLBs */ 130c72cd555SAnton Blanchard __be32 buffer_length; /* Total shadow buffer length */ 131c72cd555SAnton Blanchard __be64 reserved; 132b8b572e1SStephen Rothwell struct { 133c72cd555SAnton Blanchard __be64 esid; 134c72cd555SAnton Blanchard __be64 vsid; 13559c19cb2SAnton Blanchard } save_area[SLB_NUM_BOLTED]; 136b8b572e1SStephen Rothwell } ____cacheline_aligned; 137b8b572e1SStephen Rothwell 138cf9efce0SPaul Mackerras /* 139cf9efce0SPaul Mackerras * Layout of entries in the hypervisor's dispatch trace log buffer. 140cf9efce0SPaul Mackerras */ 141cf9efce0SPaul Mackerras struct dtl_entry { 142cf9efce0SPaul Mackerras u8 dispatch_reason; 143cf9efce0SPaul Mackerras u8 preempt_reason; 144c72cd555SAnton Blanchard __be16 processor_id; 145c72cd555SAnton Blanchard __be32 enqueue_to_dispatch_time; 146c72cd555SAnton Blanchard __be32 ready_to_enqueue_time; 147c72cd555SAnton Blanchard __be32 waiting_to_ready_time; 148c72cd555SAnton Blanchard __be64 timebase; 149c72cd555SAnton Blanchard __be64 fault_addr; 150c72cd555SAnton Blanchard __be64 srr0; 151c72cd555SAnton Blanchard __be64 srr1; 152cf9efce0SPaul Mackerras }; 153cf9efce0SPaul Mackerras 154cf9efce0SPaul Mackerras #define DISPATCH_LOG_BYTES 4096 /* bytes per cpu */ 155cf9efce0SPaul Mackerras #define N_DISPATCH_LOG (DISPATCH_LOG_BYTES / sizeof(struct dtl_entry)) 156cf9efce0SPaul Mackerras 157af442a1bSNishanth Aravamudan extern struct kmem_cache *dtl_cache; 158af442a1bSNishanth Aravamudan 159872e439aSPaul Mackerras /* 160abf917cdSFrederic Weisbecker * When CONFIG_VIRT_CPU_ACCOUNTING_NATIVE = y, the cpu accounting code controls 161872e439aSPaul Mackerras * reading from the dispatch trace log. If other code wants to consume 162872e439aSPaul Mackerras * DTL entries, it can set this pointer to a function that will get 163872e439aSPaul Mackerras * called once for each DTL entry that gets processed. 164872e439aSPaul Mackerras */ 165872e439aSPaul Mackerras extern void (*dtl_consumer)(struct dtl_entry *entry, u64 index); 166872e439aSPaul Mackerras 16794491685SBenjamin Herrenschmidt #endif /* CONFIG_PPC_BOOK3S */ 168b8b572e1SStephen Rothwell #endif /* __KERNEL__ */ 169b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_LPPACA_H */ 170