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 8c4019198SGautham R. Shenoy DECLARE_PER_CPU(u64, idle_entry_purr_snap); 9c4019198SGautham R. Shenoy 10c4019198SGautham R. Shenoy static inline void snapshot_purr_idle_entry(void) 11c4019198SGautham R. Shenoy { 12c4019198SGautham R. Shenoy *this_cpu_ptr(&idle_entry_purr_snap) = mfspr(SPRN_PURR); 13c4019198SGautham R. Shenoy } 14c4019198SGautham R. Shenoy 15c4019198SGautham R. Shenoy static inline void update_idle_purr_accounting(void) 16c4019198SGautham R. Shenoy { 17c4019198SGautham R. Shenoy u64 wait_cycles; 18c4019198SGautham R. Shenoy u64 in_purr = *this_cpu_ptr(&idle_entry_purr_snap); 19c4019198SGautham R. Shenoy 20c4019198SGautham R. Shenoy wait_cycles = be64_to_cpu(get_lppaca()->wait_state_cycles); 21c4019198SGautham R. Shenoy wait_cycles += mfspr(SPRN_PURR) - in_purr; 22c4019198SGautham R. Shenoy get_lppaca()->wait_state_cycles = cpu_to_be64(wait_cycles); 23c4019198SGautham R. Shenoy } 24c4019198SGautham R. Shenoy 25c4019198SGautham R. Shenoy static inline void pseries_idle_prolog(void) 26e4a884ccSGautham R. Shenoy { 27e4a884ccSGautham R. Shenoy ppc64_runlatch_off(); 28c4019198SGautham R. Shenoy snapshot_purr_idle_entry(); 29e4a884ccSGautham R. Shenoy /* 30e4a884ccSGautham R. Shenoy * Indicate to the HV that we are idle. Now would be 31e4a884ccSGautham R. Shenoy * a good time to find other work to dispatch. 32e4a884ccSGautham R. Shenoy */ 33e4a884ccSGautham R. Shenoy get_lppaca()->idle = 1; 34e4a884ccSGautham R. Shenoy } 35e4a884ccSGautham R. Shenoy 36c4019198SGautham R. Shenoy static inline void pseries_idle_epilog(void) 37e4a884ccSGautham R. Shenoy { 38c4019198SGautham R. Shenoy update_idle_purr_accounting(); 39e4a884ccSGautham R. Shenoy get_lppaca()->idle = 0; 40e4a884ccSGautham R. Shenoy ppc64_runlatch_on(); 41e4a884ccSGautham R. Shenoy } 42c4019198SGautham R. Shenoy 43e4a884ccSGautham R. Shenoy #endif /* CONFIG_PPC_PSERIES */ 44e4a884ccSGautham R. Shenoy #endif 45