blob: 52586f9956bbf9a4ccc0b53bd79c178e975bc341 [file] [log] [blame]
Shreyas B. Prabhu7cba1602014-12-10 00:26:52 +05301#ifndef _ASM_POWERPC_CPUIDLE_H
2#define _ASM_POWERPC_CPUIDLE_H
3
4#ifdef CONFIG_PPC_POWERNV
Nicholas Piggin0d7720a2017-04-19 23:05:50 +10005/* Thread state used in powernv idle state management */
Shreyas B. Prabhu7cba1602014-12-10 00:26:52 +05306#define PNV_THREAD_RUNNING 0
7#define PNV_THREAD_NAP 1
8#define PNV_THREAD_SLEEP 2
9#define PNV_THREAD_WINKLE 3
Nicholas Piggin0d7720a2017-04-19 23:05:50 +100010
11/*
12 * Core state used in powernv idle for POWER8.
13 *
14 * The lock bit synchronizes updates to the state, as well as parts of the
15 * sleep/wake code (see kernel/idle_book3s.S).
16 *
17 * Bottom 8 bits track the idle state of each thread. Bit is cleared before
18 * the thread executes an idle instruction (nap/sleep/winkle).
19 *
20 * Then there is winkle tracking. A core does not lose complete state
21 * until every thread is in winkle. So the winkle count field counts the
22 * number of threads in winkle (small window of false positives is okay
23 * around the sleep/wake, so long as there are no false negatives).
24 *
25 * When the winkle count reaches 8 (the COUNT_ALL_BIT becomes set), then
26 * the THREAD_WINKLE_BITS are set, which indicate which threads have not
27 * yet woken from the winkle state.
28 */
29#define PNV_CORE_IDLE_LOCK_BIT 0x10000000
30
31#define PNV_CORE_IDLE_WINKLE_COUNT 0x00010000
32#define PNV_CORE_IDLE_WINKLE_COUNT_ALL_BIT 0x00080000
33#define PNV_CORE_IDLE_WINKLE_COUNT_BITS 0x000F0000
34#define PNV_CORE_IDLE_THREAD_WINKLE_BITS_SHIFT 8
35#define PNV_CORE_IDLE_THREAD_WINKLE_BITS 0x0000FF00
36
37#define PNV_CORE_IDLE_THREAD_BITS 0x000000FF
Shreyas B. Prabhu7cba1602014-12-10 00:26:52 +053038
Gautham R. Shenoy09206b62017-01-25 14:06:28 +053039/*
40 * ============================ NOTE =================================
41 * The older firmware populates only the RL field in the psscr_val and
42 * sets the psscr_mask to 0xf. On such a firmware, the kernel sets the
43 * remaining PSSCR fields to default values as follows:
44 *
45 * - ESL and EC bits are to 1. So wakeup from any stop state will be
46 * at vector 0x100.
47 *
48 * - MTL and PSLL are set to the maximum allowed value as per the ISA,
49 * i.e. 15.
50 *
51 * - The Transition Rate, TR is set to the Maximum value 3.
52 */
53#define PSSCR_HV_DEFAULT_VAL (PSSCR_ESL | PSSCR_EC | \
54 PSSCR_PSLL_MASK | PSSCR_TR_MASK | \
55 PSSCR_MTL_MASK)
56
57#define PSSCR_HV_DEFAULT_MASK (PSSCR_ESL | PSSCR_EC | \
58 PSSCR_PSLL_MASK | PSSCR_TR_MASK | \
59 PSSCR_MTL_MASK | PSSCR_RL_MASK)
60#define PSSCR_EC_SHIFT 20
61#define PSSCR_ESL_SHIFT 21
62#define GET_PSSCR_EC(x) (((x) & PSSCR_EC) >> PSSCR_EC_SHIFT)
63#define GET_PSSCR_ESL(x) (((x) & PSSCR_ESL) >> PSSCR_ESL_SHIFT)
64#define GET_PSSCR_RL(x) ((x) & PSSCR_RL_MASK)
65
66#define ERR_EC_ESL_MISMATCH -1
67#define ERR_DEEP_STATE_ESL_MISMATCH -2
68
Shreyas B. Prabhu7cba1602014-12-10 00:26:52 +053069#ifndef __ASSEMBLY__
70extern u32 pnv_fastsleep_workaround_at_entry[];
71extern u32 pnv_fastsleep_workaround_at_exit[];
Shreyas B. Prabhubcef83a2016-07-08 11:50:49 +053072
73extern u64 pnv_first_deep_stop_state;
Gautham R. Shenoy09206b62017-01-25 14:06:28 +053074
Gautham R. Shenoya7cd88d2017-03-22 20:34:14 +053075unsigned long pnv_cpu_offline(unsigned int cpu);
Gautham R. Shenoy09206b62017-01-25 14:06:28 +053076int validate_psscr_val_mask(u64 *psscr_val, u64 *psscr_mask, u32 flags);
77static inline void report_invalid_psscr_val(u64 psscr_val, int err)
78{
79 switch (err) {
80 case ERR_EC_ESL_MISMATCH:
81 pr_warn("Invalid psscr 0x%016llx : ESL,EC bits unequal",
82 psscr_val);
83 break;
84 case ERR_DEEP_STATE_ESL_MISMATCH:
85 pr_warn("Invalid psscr 0x%016llx : ESL cleared for deep stop-state",
86 psscr_val);
87 }
88}
Shreyas B. Prabhu7cba1602014-12-10 00:26:52 +053089#endif
90
91#endif
92
Mahesh Salgaonkar98d88212016-08-05 17:34:04 +053093/* Idle state entry routines */
94#ifdef CONFIG_PPC_P7_NAP
Gautham R. Shenoy823b7bd2017-01-25 14:06:25 +053095#define IDLE_STATE_ENTER_SEQ(IDLE_INST) \
Mahesh Salgaonkar98d88212016-08-05 17:34:04 +053096 /* Magic NAP/SLEEP/WINKLE mode enter sequence */ \
97 std r0,0(r1); \
98 ptesync; \
99 ld r0,0(r1); \
Gautham R. Shenoy424f8ac2017-02-27 11:10:07 +0530100236: cmpd cr0,r0,r0; \
101 bne 236b; \
Mahesh Salgaonkar98d88212016-08-05 17:34:04 +0530102 IDLE_INST; \
Gautham R. Shenoy823b7bd2017-01-25 14:06:25 +0530103
104#define IDLE_STATE_ENTER_SEQ_NORET(IDLE_INST) \
105 IDLE_STATE_ENTER_SEQ(IDLE_INST) \
Mahesh Salgaonkar98d88212016-08-05 17:34:04 +0530106 b .
107#endif /* CONFIG_PPC_P7_NAP */
108
Shreyas B. Prabhu7cba1602014-12-10 00:26:52 +0530109#endif