1e4a884ccSGautham R. Shenoy /* SPDX-License-Identifier: GPL-2.0-or-later */ 2e4a884ccSGautham R. Shenoy #ifndef _ASM_POWERPC_IDLE_H 3e4a884ccSGautham R. Shenoy #define _ASM_POWERPC_IDLE_H 4e4a884ccSGautham R. Shenoy #include <asm/runlatch.h> 5e4a884ccSGautham R. Shenoy #include <asm/paca.h> 6e4a884ccSGautham R. Shenoy 7e4a884ccSGautham R. Shenoy #ifdef CONFIG_PPC_PSERIES 8dc8afce5SGautham R. Shenoy DECLARE_PER_CPU(u64, idle_spurr_cycles); 9c4019198SGautham R. Shenoy DECLARE_PER_CPU(u64, idle_entry_purr_snap); 10dc8afce5SGautham R. Shenoy DECLARE_PER_CPU(u64, idle_entry_spurr_snap); 11c4019198SGautham R. Shenoy 12c4019198SGautham R. Shenoy static inline void snapshot_purr_idle_entry(void) 13c4019198SGautham R. Shenoy { 14c4019198SGautham R. Shenoy *this_cpu_ptr(&idle_entry_purr_snap) = mfspr(SPRN_PURR); 15c4019198SGautham R. Shenoy } 16c4019198SGautham R. Shenoy 17dc8afce5SGautham R. Shenoy static inline void snapshot_spurr_idle_entry(void) 18dc8afce5SGautham R. Shenoy { 19dc8afce5SGautham R. Shenoy *this_cpu_ptr(&idle_entry_spurr_snap) = mfspr(SPRN_SPURR); 20dc8afce5SGautham R. Shenoy } 21dc8afce5SGautham R. Shenoy 22c4019198SGautham R. Shenoy static inline void update_idle_purr_accounting(void) 23c4019198SGautham R. Shenoy { 24c4019198SGautham R. Shenoy u64 wait_cycles; 25c4019198SGautham R. Shenoy u64 in_purr = *this_cpu_ptr(&idle_entry_purr_snap); 26c4019198SGautham R. Shenoy 27c4019198SGautham R. Shenoy wait_cycles = be64_to_cpu(get_lppaca()->wait_state_cycles); 28c4019198SGautham R. Shenoy wait_cycles += mfspr(SPRN_PURR) - in_purr; 29c4019198SGautham R. Shenoy get_lppaca()->wait_state_cycles = cpu_to_be64(wait_cycles); 30c4019198SGautham R. Shenoy } 31c4019198SGautham R. Shenoy 32dc8afce5SGautham R. Shenoy static inline void update_idle_spurr_accounting(void) 33dc8afce5SGautham R. Shenoy { 34dc8afce5SGautham R. Shenoy u64 *idle_spurr_cycles_ptr = this_cpu_ptr(&idle_spurr_cycles); 35dc8afce5SGautham R. Shenoy u64 in_spurr = *this_cpu_ptr(&idle_entry_spurr_snap); 36dc8afce5SGautham R. Shenoy 37dc8afce5SGautham R. Shenoy *idle_spurr_cycles_ptr += mfspr(SPRN_SPURR) - in_spurr; 38dc8afce5SGautham R. Shenoy } 39dc8afce5SGautham R. Shenoy 40c4019198SGautham R. Shenoy static inline void pseries_idle_prolog(void) 41e4a884ccSGautham R. Shenoy { 42e4a884ccSGautham R. Shenoy ppc64_runlatch_off(); 43c4019198SGautham R. Shenoy snapshot_purr_idle_entry(); 44dc8afce5SGautham R. Shenoy snapshot_spurr_idle_entry(); 45e4a884ccSGautham R. Shenoy /* 46e4a884ccSGautham R. Shenoy * Indicate to the HV that we are idle. Now would be 47e4a884ccSGautham R. Shenoy * a good time to find other work to dispatch. 48e4a884ccSGautham R. Shenoy */ 49e4a884ccSGautham R. Shenoy get_lppaca()->idle = 1; 50e4a884ccSGautham R. Shenoy } 51e4a884ccSGautham R. Shenoy 52c4019198SGautham R. Shenoy static inline void pseries_idle_epilog(void) 53e4a884ccSGautham R. Shenoy { 54c4019198SGautham R. Shenoy update_idle_purr_accounting(); 55dc8afce5SGautham R. Shenoy update_idle_spurr_accounting(); 56e4a884ccSGautham R. Shenoy get_lppaca()->idle = 0; 57e4a884ccSGautham R. Shenoy ppc64_runlatch_on(); 58e4a884ccSGautham R. Shenoy } 59c4019198SGautham R. Shenoy 60e4a884ccSGautham R. Shenoy #endif /* CONFIG_PPC_PSERIES */ 61e4a884ccSGautham R. Shenoy #endif 62