Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags   |
^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) #ifndef _ASM_POWERPC_IDLE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3) #define _ASM_POWERPC_IDLE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4) #include <asm/runlatch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) #include <asm/paca.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #ifdef CONFIG_PPC_PSERIES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) DECLARE_PER_CPU(u64, idle_spurr_cycles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) DECLARE_PER_CPU(u64, idle_entry_purr_snap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) DECLARE_PER_CPU(u64, idle_entry_spurr_snap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) static inline void snapshot_purr_idle_entry(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 	*this_cpu_ptr(&idle_entry_purr_snap) = mfspr(SPRN_PURR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) static inline void snapshot_spurr_idle_entry(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	*this_cpu_ptr(&idle_entry_spurr_snap) = mfspr(SPRN_SPURR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static inline void update_idle_purr_accounting(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	u64 wait_cycles;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	u64 in_purr = *this_cpu_ptr(&idle_entry_purr_snap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	wait_cycles = be64_to_cpu(get_lppaca()->wait_state_cycles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	wait_cycles += mfspr(SPRN_PURR) - in_purr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 	get_lppaca()->wait_state_cycles = cpu_to_be64(wait_cycles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static inline void update_idle_spurr_accounting(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	u64 *idle_spurr_cycles_ptr = this_cpu_ptr(&idle_spurr_cycles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	u64 in_spurr = *this_cpu_ptr(&idle_entry_spurr_snap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	*idle_spurr_cycles_ptr += mfspr(SPRN_SPURR) - in_spurr;
^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) static inline void pseries_idle_prolog(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	ppc64_runlatch_off();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	snapshot_purr_idle_entry();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	snapshot_spurr_idle_entry();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	 * Indicate to the HV that we are idle. Now would be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	 * a good time to find other work to dispatch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	get_lppaca()->idle = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static inline void pseries_idle_epilog(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	update_idle_purr_accounting();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	update_idle_spurr_accounting();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	get_lppaca()->idle = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	ppc64_runlatch_on();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static inline u64 read_this_idle_purr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	 * If we are reading from an idle context, update the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	 * idle-purr cycles corresponding to the last idle period.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	 * Since the idle context is not yet over, take a fresh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	 * snapshot of the idle-purr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	if (unlikely(get_lppaca()->idle == 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 		update_idle_purr_accounting();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 		snapshot_purr_idle_entry();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	return be64_to_cpu(get_lppaca()->wait_state_cycles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static inline u64 read_this_idle_spurr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	 * If we are reading from an idle context, update the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	 * idle-spurr cycles corresponding to the last idle period.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	 * Since the idle context is not yet over, take a fresh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 	 * snapshot of the idle-spurr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 	if (get_lppaca()->idle == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 		update_idle_spurr_accounting();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 		snapshot_spurr_idle_entry();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) 	return *this_cpu_ptr(&idle_spurr_cycles);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #endif /* CONFIG_PPC_PSERIES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #endif