Shreyas B. Prabhu | 7cba160 | 2014-12-10 00:26:52 +0530 | [diff] [blame] | 1 | #ifndef _ASM_POWERPC_CPUIDLE_H |
| 2 | #define _ASM_POWERPC_CPUIDLE_H |
| 3 | |
| 4 | #ifdef CONFIG_PPC_POWERNV |
Nicholas Piggin | 0d7720a | 2017-04-19 23:05:50 +1000 | [diff] [blame] | 5 | /* Thread state used in powernv idle state management */ |
Shreyas B. Prabhu | 7cba160 | 2014-12-10 00:26:52 +0530 | [diff] [blame] | 6 | #define PNV_THREAD_RUNNING 0 |
| 7 | #define PNV_THREAD_NAP 1 |
| 8 | #define PNV_THREAD_SLEEP 2 |
| 9 | #define PNV_THREAD_WINKLE 3 |
Nicholas Piggin | 0d7720a | 2017-04-19 23:05:50 +1000 | [diff] [blame] | 10 | |
| 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. Prabhu | 7cba160 | 2014-12-10 00:26:52 +0530 | [diff] [blame] | 38 | |
Gautham R. Shenoy | 09206b6 | 2017-01-25 14:06:28 +0530 | [diff] [blame] | 39 | /* |
| 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. Prabhu | 7cba160 | 2014-12-10 00:26:52 +0530 | [diff] [blame] | 69 | #ifndef __ASSEMBLY__ |
| 70 | extern u32 pnv_fastsleep_workaround_at_entry[]; |
| 71 | extern u32 pnv_fastsleep_workaround_at_exit[]; |
Shreyas B. Prabhu | bcef83a | 2016-07-08 11:50:49 +0530 | [diff] [blame] | 72 | |
| 73 | extern u64 pnv_first_deep_stop_state; |
Gautham R. Shenoy | 09206b6 | 2017-01-25 14:06:28 +0530 | [diff] [blame] | 74 | |
Gautham R. Shenoy | a7cd88d | 2017-03-22 20:34:14 +0530 | [diff] [blame] | 75 | unsigned long pnv_cpu_offline(unsigned int cpu); |
Gautham R. Shenoy | 09206b6 | 2017-01-25 14:06:28 +0530 | [diff] [blame] | 76 | int validate_psscr_val_mask(u64 *psscr_val, u64 *psscr_mask, u32 flags); |
| 77 | static 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. Prabhu | 7cba160 | 2014-12-10 00:26:52 +0530 | [diff] [blame] | 89 | #endif |
| 90 | |
| 91 | #endif |
| 92 | |
Mahesh Salgaonkar | 98d8821 | 2016-08-05 17:34:04 +0530 | [diff] [blame] | 93 | /* Idle state entry routines */ |
| 94 | #ifdef CONFIG_PPC_P7_NAP |
Gautham R. Shenoy | 823b7bd | 2017-01-25 14:06:25 +0530 | [diff] [blame] | 95 | #define IDLE_STATE_ENTER_SEQ(IDLE_INST) \ |
Mahesh Salgaonkar | 98d8821 | 2016-08-05 17:34:04 +0530 | [diff] [blame] | 96 | /* Magic NAP/SLEEP/WINKLE mode enter sequence */ \ |
| 97 | std r0,0(r1); \ |
| 98 | ptesync; \ |
| 99 | ld r0,0(r1); \ |
Gautham R. Shenoy | 424f8ac | 2017-02-27 11:10:07 +0530 | [diff] [blame] | 100 | 236: cmpd cr0,r0,r0; \ |
| 101 | bne 236b; \ |
Mahesh Salgaonkar | 98d8821 | 2016-08-05 17:34:04 +0530 | [diff] [blame] | 102 | IDLE_INST; \ |
Gautham R. Shenoy | 823b7bd | 2017-01-25 14:06:25 +0530 | [diff] [blame] | 103 | |
| 104 | #define IDLE_STATE_ENTER_SEQ_NORET(IDLE_INST) \ |
| 105 | IDLE_STATE_ENTER_SEQ(IDLE_INST) \ |
Mahesh Salgaonkar | 98d8821 | 2016-08-05 17:34:04 +0530 | [diff] [blame] | 106 | b . |
| 107 | #endif /* CONFIG_PPC_P7_NAP */ |
| 108 | |
Shreyas B. Prabhu | 7cba160 | 2014-12-10 00:26:52 +0530 | [diff] [blame] | 109 | #endif |