xref: /openbmc/linux/arch/powerpc/include/asm/cpuidle.h (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
27cba160aSShreyas B. Prabhu #ifndef _ASM_POWERPC_CPUIDLE_H
37cba160aSShreyas B. Prabhu #define _ASM_POWERPC_CPUIDLE_H
47cba160aSShreyas B. Prabhu 
57cba160aSShreyas B. Prabhu #ifdef CONFIG_PPC_POWERNV
60d7720a2SNicholas Piggin /* Thread state used in powernv idle state management */
77cba160aSShreyas B. Prabhu #define PNV_THREAD_RUNNING              0
87cba160aSShreyas B. Prabhu #define PNV_THREAD_NAP                  1
97cba160aSShreyas B. Prabhu #define PNV_THREAD_SLEEP                2
107cba160aSShreyas B. Prabhu #define PNV_THREAD_WINKLE               3
110d7720a2SNicholas Piggin 
120d7720a2SNicholas Piggin /*
130d7720a2SNicholas Piggin  * Core state used in powernv idle for POWER8.
140d7720a2SNicholas Piggin  *
150d7720a2SNicholas Piggin  * The lock bit synchronizes updates to the state, as well as parts of the
160d7720a2SNicholas Piggin  * sleep/wake code (see kernel/idle_book3s.S).
170d7720a2SNicholas Piggin  *
180d7720a2SNicholas Piggin  * Bottom 8 bits track the idle state of each thread. Bit is cleared before
190d7720a2SNicholas Piggin  * the thread executes an idle instruction (nap/sleep/winkle).
200d7720a2SNicholas Piggin  *
210d7720a2SNicholas Piggin  * Then there is winkle tracking. A core does not lose complete state
220d7720a2SNicholas Piggin  * until every thread is in winkle. So the winkle count field counts the
230d7720a2SNicholas Piggin  * number of threads in winkle (small window of false positives is okay
240d7720a2SNicholas Piggin  * around the sleep/wake, so long as there are no false negatives).
250d7720a2SNicholas Piggin  *
260d7720a2SNicholas Piggin  * When the winkle count reaches 8 (the COUNT_ALL_BIT becomes set), then
270d7720a2SNicholas Piggin  * the THREAD_WINKLE_BITS are set, which indicate which threads have not
280d7720a2SNicholas Piggin  * yet woken from the winkle state.
290d7720a2SNicholas Piggin  */
3010d91611SNicholas Piggin #define NR_PNV_CORE_IDLE_LOCK_BIT		28
3110d91611SNicholas Piggin #define PNV_CORE_IDLE_LOCK_BIT			(1ULL << NR_PNV_CORE_IDLE_LOCK_BIT)
320d7720a2SNicholas Piggin 
3310d91611SNicholas Piggin #define PNV_CORE_IDLE_WINKLE_COUNT_SHIFT	16
340d7720a2SNicholas Piggin #define PNV_CORE_IDLE_WINKLE_COUNT		0x00010000
350d7720a2SNicholas Piggin #define PNV_CORE_IDLE_WINKLE_COUNT_BITS		0x000F0000
360d7720a2SNicholas Piggin #define PNV_CORE_IDLE_THREAD_WINKLE_BITS_SHIFT	8
370d7720a2SNicholas Piggin #define PNV_CORE_IDLE_THREAD_WINKLE_BITS	0x0000FF00
380d7720a2SNicholas Piggin 
39adbcf8d7SNicholas Piggin #define PNV_CORE_IDLE_THREAD_BITS       	0x000000FF
407cba160aSShreyas B. Prabhu 
4109206b60SGautham R. Shenoy /*
4209206b60SGautham R. Shenoy  * ============================ NOTE =================================
4309206b60SGautham R. Shenoy  * The older firmware populates only the RL field in the psscr_val and
4409206b60SGautham R. Shenoy  * sets the psscr_mask to 0xf. On such a firmware, the kernel sets the
4509206b60SGautham R. Shenoy  * remaining PSSCR fields to default values as follows:
4609206b60SGautham R. Shenoy  *
4709206b60SGautham R. Shenoy  * - ESL and EC bits are to 1. So wakeup from any stop state will be
4809206b60SGautham R. Shenoy  *   at vector 0x100.
4909206b60SGautham R. Shenoy  *
5009206b60SGautham R. Shenoy  * - MTL and PSLL are set to the maximum allowed value as per the ISA,
5109206b60SGautham R. Shenoy  *    i.e. 15.
5209206b60SGautham R. Shenoy  *
5309206b60SGautham R. Shenoy  * - The Transition Rate, TR is set to the Maximum value 3.
5409206b60SGautham R. Shenoy  */
5509206b60SGautham R. Shenoy #define PSSCR_HV_DEFAULT_VAL    (PSSCR_ESL | PSSCR_EC |		    \
5609206b60SGautham R. Shenoy 				PSSCR_PSLL_MASK | PSSCR_TR_MASK |   \
5709206b60SGautham R. Shenoy 				PSSCR_MTL_MASK)
5809206b60SGautham R. Shenoy 
5909206b60SGautham R. Shenoy #define PSSCR_HV_DEFAULT_MASK   (PSSCR_ESL | PSSCR_EC |		    \
6009206b60SGautham R. Shenoy 				PSSCR_PSLL_MASK | PSSCR_TR_MASK |   \
6109206b60SGautham R. Shenoy 				PSSCR_MTL_MASK | PSSCR_RL_MASK)
6209206b60SGautham R. Shenoy #define PSSCR_EC_SHIFT    20
6309206b60SGautham R. Shenoy #define PSSCR_ESL_SHIFT   21
6409206b60SGautham R. Shenoy #define GET_PSSCR_EC(x)   (((x) & PSSCR_EC) >> PSSCR_EC_SHIFT)
6509206b60SGautham R. Shenoy #define GET_PSSCR_ESL(x)  (((x) & PSSCR_ESL) >> PSSCR_ESL_SHIFT)
6609206b60SGautham R. Shenoy #define GET_PSSCR_RL(x)   ((x) & PSSCR_RL_MASK)
6709206b60SGautham R. Shenoy 
6809206b60SGautham R. Shenoy #define ERR_EC_ESL_MISMATCH		-1
6909206b60SGautham R. Shenoy #define ERR_DEEP_STATE_ESL_MISMATCH	-2
7009206b60SGautham R. Shenoy 
717cba160aSShreyas B. Prabhu #ifndef __ASSEMBLY__
72e1c1cfedSGautham R. Shenoy 
739c7b185aSAkshay Adiga #define PNV_IDLE_NAME_LEN    16
749c7b185aSAkshay Adiga struct pnv_idle_states_t {
759c7b185aSAkshay Adiga 	char name[PNV_IDLE_NAME_LEN];
769c7b185aSAkshay Adiga 	u32 latency_ns;
779c7b185aSAkshay Adiga 	u32 residency_ns;
789c7b185aSAkshay Adiga 	u64 psscr_val;
799c7b185aSAkshay Adiga 	u64 psscr_mask;
809c7b185aSAkshay Adiga 	u32 flags;
819c7b185aSAkshay Adiga 	bool valid;
829c7b185aSAkshay Adiga };
839c7b185aSAkshay Adiga 
841961acadSAkshay Adiga extern struct pnv_idle_states_t *pnv_idle_states;
851961acadSAkshay Adiga extern int nr_pnv_idle_states;
8609206b60SGautham R. Shenoy 
87a7cd88daSGautham R. Shenoy unsigned long pnv_cpu_offline(unsigned int cpu);
88*e5913db1SNick Child int __init validate_psscr_val_mask(u64 *psscr_val, u64 *psscr_mask, u32 flags);
report_invalid_psscr_val(u64 psscr_val,int err)8909206b60SGautham R. Shenoy static inline void report_invalid_psscr_val(u64 psscr_val, int err)
9009206b60SGautham R. Shenoy {
9109206b60SGautham R. Shenoy 	switch (err) {
9209206b60SGautham R. Shenoy 	case ERR_EC_ESL_MISMATCH:
9309206b60SGautham R. Shenoy 		pr_warn("Invalid psscr 0x%016llx : ESL,EC bits unequal",
9409206b60SGautham R. Shenoy 			psscr_val);
9509206b60SGautham R. Shenoy 		break;
9609206b60SGautham R. Shenoy 	case ERR_DEEP_STATE_ESL_MISMATCH:
9709206b60SGautham R. Shenoy 		pr_warn("Invalid psscr 0x%016llx : ESL cleared for deep stop-state",
9809206b60SGautham R. Shenoy 			psscr_val);
9909206b60SGautham R. Shenoy 	}
10009206b60SGautham R. Shenoy }
1017cba160aSShreyas B. Prabhu #endif
1027cba160aSShreyas B. Prabhu 
1037cba160aSShreyas B. Prabhu #endif
1047cba160aSShreyas B. Prabhu 
1057cba160aSShreyas B. Prabhu #endif
106