Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 1 | /* |
| 2 | * cpuidle-powernv - idle state cpuidle driver. |
| 3 | * Adapted from drivers/cpuidle/cpuidle-pseries |
| 4 | * |
| 5 | */ |
| 6 | |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/init.h> |
| 10 | #include <linux/moduleparam.h> |
| 11 | #include <linux/cpuidle.h> |
| 12 | #include <linux/cpu.h> |
| 13 | #include <linux/notifier.h> |
Preeti U Murthy | 0d94873 | 2014-02-26 05:39:06 +0530 | [diff] [blame] | 14 | #include <linux/clockchips.h> |
Preeti U Murthy | 0888839 | 2014-02-26 05:39:20 +0530 | [diff] [blame] | 15 | #include <linux/of.h> |
Preeti U Murthy | 92c83ff5 | 2015-02-18 06:34:17 +0100 | [diff] [blame] | 16 | #include <linux/slab.h> |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 17 | |
| 18 | #include <asm/machdep.h> |
| 19 | #include <asm/firmware.h> |
Shreyas B. Prabhu | 8eb8ac8 | 2014-12-10 00:26:51 +0530 | [diff] [blame] | 20 | #include <asm/opal.h> |
Nicolas Pitre | 591ac0c | 2014-02-17 10:59:29 -0500 | [diff] [blame] | 21 | #include <asm/runlatch.h> |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 22 | |
Gautham R. Shenoy | 9e9fc6f | 2017-01-25 14:06:27 +0530 | [diff] [blame^] | 23 | /* |
| 24 | * Expose only those Hardware idle states via the cpuidle framework |
| 25 | * that have latency value below POWERNV_THRESHOLD_LATENCY_NS. |
| 26 | */ |
Shreyas B. Prabhu | 3005c59 | 2016-07-08 11:50:52 +0530 | [diff] [blame] | 27 | #define POWERNV_THRESHOLD_LATENCY_NS 200000 |
| 28 | |
Andrew Donnellan | ed61390 | 2016-11-22 16:08:06 +1100 | [diff] [blame] | 29 | static struct cpuidle_driver powernv_idle_driver = { |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 30 | .name = "powernv_idle", |
| 31 | .owner = THIS_MODULE, |
| 32 | }; |
| 33 | |
| 34 | static int max_idle_state; |
| 35 | static struct cpuidle_state *cpuidle_state_table; |
Shreyas B. Prabhu | 3005c59 | 2016-07-08 11:50:52 +0530 | [diff] [blame] | 36 | |
| 37 | static u64 stop_psscr_table[CPUIDLE_STATE_MAX]; |
| 38 | |
Shilpasri G Bhat | 78eaa10 | 2015-06-18 16:53:11 +0530 | [diff] [blame] | 39 | static u64 snooze_timeout; |
| 40 | static bool snooze_timeout_en; |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 41 | |
| 42 | static int snooze_loop(struct cpuidle_device *dev, |
| 43 | struct cpuidle_driver *drv, |
| 44 | int index) |
| 45 | { |
Shilpasri G Bhat | 78eaa10 | 2015-06-18 16:53:11 +0530 | [diff] [blame] | 46 | u64 snooze_exit_time; |
| 47 | |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 48 | local_irq_enable(); |
| 49 | set_thread_flag(TIF_POLLING_NRFLAG); |
| 50 | |
Shilpasri G Bhat | 78eaa10 | 2015-06-18 16:53:11 +0530 | [diff] [blame] | 51 | snooze_exit_time = get_tb() + snooze_timeout; |
Nicolas Pitre | 591ac0c | 2014-02-17 10:59:29 -0500 | [diff] [blame] | 52 | ppc64_runlatch_off(); |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 53 | while (!need_resched()) { |
| 54 | HMT_low(); |
| 55 | HMT_very_low(); |
Shilpasri G Bhat | 78eaa10 | 2015-06-18 16:53:11 +0530 | [diff] [blame] | 56 | if (snooze_timeout_en && get_tb() > snooze_exit_time) |
| 57 | break; |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | HMT_medium(); |
Nicolas Pitre | 591ac0c | 2014-02-17 10:59:29 -0500 | [diff] [blame] | 61 | ppc64_runlatch_on(); |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 62 | clear_thread_flag(TIF_POLLING_NRFLAG); |
| 63 | smp_mb(); |
| 64 | return index; |
| 65 | } |
| 66 | |
| 67 | static int nap_loop(struct cpuidle_device *dev, |
| 68 | struct cpuidle_driver *drv, |
| 69 | int index) |
| 70 | { |
Nicolas Pitre | 591ac0c | 2014-02-17 10:59:29 -0500 | [diff] [blame] | 71 | ppc64_runlatch_off(); |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 72 | power7_idle(); |
Nicolas Pitre | 591ac0c | 2014-02-17 10:59:29 -0500 | [diff] [blame] | 73 | ppc64_runlatch_on(); |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 74 | return index; |
| 75 | } |
| 76 | |
preeti | cc5a2f7 | 2015-06-24 01:48:01 -0500 | [diff] [blame] | 77 | /* Register for fastsleep only in oneshot mode of broadcast */ |
| 78 | #ifdef CONFIG_TICK_ONESHOT |
Preeti U Murthy | 0d94873 | 2014-02-26 05:39:06 +0530 | [diff] [blame] | 79 | static int fastsleep_loop(struct cpuidle_device *dev, |
| 80 | struct cpuidle_driver *drv, |
| 81 | int index) |
| 82 | { |
| 83 | unsigned long old_lpcr = mfspr(SPRN_LPCR); |
| 84 | unsigned long new_lpcr; |
| 85 | |
| 86 | if (unlikely(system_state < SYSTEM_RUNNING)) |
| 87 | return index; |
| 88 | |
| 89 | new_lpcr = old_lpcr; |
Michael Neuling | 9b6a68d | 2014-06-11 15:59:27 +1000 | [diff] [blame] | 90 | /* Do not exit powersave upon decrementer as we've setup the timer |
| 91 | * offload. |
Preeti U Murthy | 0d94873 | 2014-02-26 05:39:06 +0530 | [diff] [blame] | 92 | */ |
Michael Neuling | 9b6a68d | 2014-06-11 15:59:27 +1000 | [diff] [blame] | 93 | new_lpcr &= ~LPCR_PECE1; |
Preeti U Murthy | 0d94873 | 2014-02-26 05:39:06 +0530 | [diff] [blame] | 94 | |
| 95 | mtspr(SPRN_LPCR, new_lpcr); |
| 96 | power7_sleep(); |
| 97 | |
| 98 | mtspr(SPRN_LPCR, old_lpcr); |
| 99 | |
| 100 | return index; |
| 101 | } |
preeti | cc5a2f7 | 2015-06-24 01:48:01 -0500 | [diff] [blame] | 102 | #endif |
Shreyas B. Prabhu | 3005c59 | 2016-07-08 11:50:52 +0530 | [diff] [blame] | 103 | |
| 104 | static int stop_loop(struct cpuidle_device *dev, |
| 105 | struct cpuidle_driver *drv, |
| 106 | int index) |
| 107 | { |
| 108 | ppc64_runlatch_off(); |
| 109 | power9_idle_stop(stop_psscr_table[index]); |
| 110 | ppc64_runlatch_on(); |
| 111 | return index; |
| 112 | } |
| 113 | |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 114 | /* |
| 115 | * States for dedicated partition case. |
| 116 | */ |
Shreyas B. Prabhu | 169f3fa | 2016-07-08 11:50:50 +0530 | [diff] [blame] | 117 | static struct cpuidle_state powernv_states[CPUIDLE_STATE_MAX] = { |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 118 | { /* Snooze */ |
| 119 | .name = "snooze", |
| 120 | .desc = "snooze", |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 121 | .exit_latency = 0, |
| 122 | .target_residency = 0, |
Shreyas B. Prabhu | 957efce | 2016-07-08 11:50:51 +0530 | [diff] [blame] | 123 | .enter = snooze_loop }, |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 124 | }; |
| 125 | |
Sebastian Andrzej Siewior | 10fcca9 | 2016-08-24 11:12:59 +0200 | [diff] [blame] | 126 | static int powernv_cpuidle_cpu_online(unsigned int cpu) |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 127 | { |
Sebastian Andrzej Siewior | 10fcca9 | 2016-08-24 11:12:59 +0200 | [diff] [blame] | 128 | struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu); |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 129 | |
| 130 | if (dev && cpuidle_get_driver()) { |
Sebastian Andrzej Siewior | 10fcca9 | 2016-08-24 11:12:59 +0200 | [diff] [blame] | 131 | cpuidle_pause_and_lock(); |
| 132 | cpuidle_enable_device(dev); |
| 133 | cpuidle_resume_and_unlock(); |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 134 | } |
Sebastian Andrzej Siewior | 10fcca9 | 2016-08-24 11:12:59 +0200 | [diff] [blame] | 135 | return 0; |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 136 | } |
| 137 | |
Sebastian Andrzej Siewior | 10fcca9 | 2016-08-24 11:12:59 +0200 | [diff] [blame] | 138 | static int powernv_cpuidle_cpu_dead(unsigned int cpu) |
| 139 | { |
| 140 | struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu); |
| 141 | |
| 142 | if (dev && cpuidle_get_driver()) { |
| 143 | cpuidle_pause_and_lock(); |
| 144 | cpuidle_disable_device(dev); |
| 145 | cpuidle_resume_and_unlock(); |
| 146 | } |
| 147 | return 0; |
| 148 | } |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 149 | |
| 150 | /* |
| 151 | * powernv_cpuidle_driver_init() |
| 152 | */ |
| 153 | static int powernv_cpuidle_driver_init(void) |
| 154 | { |
| 155 | int idle_state; |
| 156 | struct cpuidle_driver *drv = &powernv_idle_driver; |
| 157 | |
| 158 | drv->state_count = 0; |
| 159 | |
| 160 | for (idle_state = 0; idle_state < max_idle_state; ++idle_state) { |
| 161 | /* Is the state not enabled? */ |
| 162 | if (cpuidle_state_table[idle_state].enter == NULL) |
| 163 | continue; |
| 164 | |
| 165 | drv->states[drv->state_count] = /* structure copy */ |
| 166 | cpuidle_state_table[idle_state]; |
| 167 | |
| 168 | drv->state_count += 1; |
| 169 | } |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
Gautham R. Shenoy | 9e9fc6f | 2017-01-25 14:06:27 +0530 | [diff] [blame^] | 174 | static inline void add_powernv_state(int index, const char *name, |
| 175 | unsigned int flags, |
| 176 | int (*idle_fn)(struct cpuidle_device *, |
| 177 | struct cpuidle_driver *, |
| 178 | int), |
| 179 | unsigned int target_residency, |
| 180 | unsigned int exit_latency, |
| 181 | u64 psscr_val) |
| 182 | { |
| 183 | strlcpy(powernv_states[index].name, name, CPUIDLE_NAME_LEN); |
| 184 | strlcpy(powernv_states[index].desc, name, CPUIDLE_NAME_LEN); |
| 185 | powernv_states[index].flags = flags; |
| 186 | powernv_states[index].target_residency = target_residency; |
| 187 | powernv_states[index].exit_latency = exit_latency; |
| 188 | powernv_states[index].enter = idle_fn; |
| 189 | stop_psscr_table[index] = psscr_val; |
| 190 | } |
| 191 | |
Preeti U Murthy | 0888839 | 2014-02-26 05:39:20 +0530 | [diff] [blame] | 192 | static int powernv_add_idle_states(void) |
| 193 | { |
| 194 | struct device_node *power_mgt; |
Preeti U Murthy | 0888839 | 2014-02-26 05:39:20 +0530 | [diff] [blame] | 195 | int nr_idle_states = 1; /* Snooze */ |
| 196 | int dt_idle_states; |
Shreyas B. Prabhu | 957efce | 2016-07-08 11:50:51 +0530 | [diff] [blame] | 197 | u32 latency_ns[CPUIDLE_STATE_MAX]; |
| 198 | u32 residency_ns[CPUIDLE_STATE_MAX]; |
| 199 | u32 flags[CPUIDLE_STATE_MAX]; |
Shreyas B. Prabhu | 3005c59 | 2016-07-08 11:50:52 +0530 | [diff] [blame] | 200 | u64 psscr_val[CPUIDLE_STATE_MAX]; |
| 201 | const char *names[CPUIDLE_STATE_MAX]; |
Preeti U Murthy | 92c83ff5 | 2015-02-18 06:34:17 +0100 | [diff] [blame] | 202 | int i, rc; |
Preeti U Murthy | 0888839 | 2014-02-26 05:39:20 +0530 | [diff] [blame] | 203 | |
| 204 | /* Currently we have snooze statically defined */ |
| 205 | |
| 206 | power_mgt = of_find_node_by_path("/ibm,opal/power-mgt"); |
| 207 | if (!power_mgt) { |
| 208 | pr_warn("opal: PowerMgmt Node not found\n"); |
Preeti U Murthy | 92c83ff5 | 2015-02-18 06:34:17 +0100 | [diff] [blame] | 209 | goto out; |
Preeti U Murthy | 0888839 | 2014-02-26 05:39:20 +0530 | [diff] [blame] | 210 | } |
| 211 | |
Preeti U Murthy | 70734a7 | 2015-02-18 23:24:53 -0600 | [diff] [blame] | 212 | /* Read values of any property to determine the num of idle states */ |
| 213 | dt_idle_states = of_property_count_u32_elems(power_mgt, "ibm,cpu-idle-state-flags"); |
| 214 | if (dt_idle_states < 0) { |
| 215 | pr_warn("cpuidle-powernv: no idle states found in the DT\n"); |
Preeti U Murthy | 92c83ff5 | 2015-02-18 06:34:17 +0100 | [diff] [blame] | 216 | goto out; |
Preeti U. Murthy | 74aa51b | 2014-10-14 13:23:00 +0530 | [diff] [blame] | 217 | } |
| 218 | |
Shreyas B. Prabhu | 957efce | 2016-07-08 11:50:51 +0530 | [diff] [blame] | 219 | /* |
| 220 | * Since snooze is used as first idle state, max idle states allowed is |
| 221 | * CPUIDLE_STATE_MAX -1 |
| 222 | */ |
| 223 | if (dt_idle_states > CPUIDLE_STATE_MAX - 1) { |
| 224 | pr_warn("cpuidle-powernv: discovered idle states more than allowed"); |
| 225 | dt_idle_states = CPUIDLE_STATE_MAX - 1; |
| 226 | } |
| 227 | |
Preeti U Murthy | 70734a7 | 2015-02-18 23:24:53 -0600 | [diff] [blame] | 228 | if (of_property_read_u32_array(power_mgt, |
| 229 | "ibm,cpu-idle-state-flags", flags, dt_idle_states)) { |
| 230 | pr_warn("cpuidle-powernv : missing ibm,cpu-idle-state-flags in DT\n"); |
Shreyas B. Prabhu | 957efce | 2016-07-08 11:50:51 +0530 | [diff] [blame] | 231 | goto out; |
Preeti U Murthy | 70734a7 | 2015-02-18 23:24:53 -0600 | [diff] [blame] | 232 | } |
Preeti U Murthy | 0888839 | 2014-02-26 05:39:20 +0530 | [diff] [blame] | 233 | |
Shreyas B. Prabhu | 957efce | 2016-07-08 11:50:51 +0530 | [diff] [blame] | 234 | if (of_property_read_u32_array(power_mgt, |
| 235 | "ibm,cpu-idle-state-latencies-ns", latency_ns, |
| 236 | dt_idle_states)) { |
Preeti U Murthy | 92c83ff5 | 2015-02-18 06:34:17 +0100 | [diff] [blame] | 237 | pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-latencies-ns in DT\n"); |
Shreyas B. Prabhu | 957efce | 2016-07-08 11:50:51 +0530 | [diff] [blame] | 238 | goto out; |
Preeti U Murthy | 92c83ff5 | 2015-02-18 06:34:17 +0100 | [diff] [blame] | 239 | } |
Shreyas B. Prabhu | 3005c59 | 2016-07-08 11:50:52 +0530 | [diff] [blame] | 240 | if (of_property_read_string_array(power_mgt, |
| 241 | "ibm,cpu-idle-state-names", names, dt_idle_states) < 0) { |
| 242 | pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-names in DT\n"); |
| 243 | goto out; |
| 244 | } |
| 245 | |
| 246 | /* |
| 247 | * If the idle states use stop instruction, probe for psscr values |
| 248 | * which are necessary to specify required stop level. |
| 249 | */ |
| 250 | if (flags[0] & (OPAL_PM_STOP_INST_FAST | OPAL_PM_STOP_INST_DEEP)) |
| 251 | if (of_property_read_u64_array(power_mgt, |
| 252 | "ibm,cpu-idle-state-psscr", psscr_val, dt_idle_states)) { |
| 253 | pr_warn("cpuidle-powernv: missing ibm,cpu-idle-states-psscr in DT\n"); |
| 254 | goto out; |
| 255 | } |
Preeti U Murthy | 92c83ff5 | 2015-02-18 06:34:17 +0100 | [diff] [blame] | 256 | |
Preeti U Murthy | 92c83ff5 | 2015-02-18 06:34:17 +0100 | [diff] [blame] | 257 | rc = of_property_read_u32_array(power_mgt, |
| 258 | "ibm,cpu-idle-state-residency-ns", residency_ns, dt_idle_states); |
| 259 | |
Preeti U Murthy | 0888839 | 2014-02-26 05:39:20 +0530 | [diff] [blame] | 260 | for (i = 0; i < dt_idle_states; i++) { |
Gautham R. Shenoy | 9e9fc6f | 2017-01-25 14:06:27 +0530 | [diff] [blame^] | 261 | unsigned int exit_latency, target_residency; |
Shreyas B. Prabhu | 3005c59 | 2016-07-08 11:50:52 +0530 | [diff] [blame] | 262 | /* |
| 263 | * If an idle state has exit latency beyond |
| 264 | * POWERNV_THRESHOLD_LATENCY_NS then don't use it |
| 265 | * in cpu-idle. |
| 266 | */ |
| 267 | if (latency_ns[i] > POWERNV_THRESHOLD_LATENCY_NS) |
| 268 | continue; |
Gautham R. Shenoy | 9e9fc6f | 2017-01-25 14:06:27 +0530 | [diff] [blame^] | 269 | /* |
| 270 | * Firmware passes residency and latency values in ns. |
| 271 | * cpuidle expects it in us. |
| 272 | */ |
| 273 | exit_latency = latency_ns[i] / 1000; |
| 274 | if (!rc) |
| 275 | target_residency = residency_ns[i] / 1000; |
| 276 | else |
| 277 | target_residency = 0; |
Preeti U Murthy | 0888839 | 2014-02-26 05:39:20 +0530 | [diff] [blame] | 278 | |
Preeti U Murthy | 92c83ff5 | 2015-02-18 06:34:17 +0100 | [diff] [blame] | 279 | /* |
Gautham R. Shenoy | 9e9fc6f | 2017-01-25 14:06:27 +0530 | [diff] [blame^] | 280 | * For nap and fastsleep, use default target_residency |
| 281 | * values if f/w does not expose it. |
Preeti U. Murthy | 74aa51b | 2014-10-14 13:23:00 +0530 | [diff] [blame] | 282 | */ |
Preeti U Murthy | 70734a7 | 2015-02-18 23:24:53 -0600 | [diff] [blame] | 283 | if (flags[i] & OPAL_PM_NAP_ENABLED) { |
Gautham R. Shenoy | 9e9fc6f | 2017-01-25 14:06:27 +0530 | [diff] [blame^] | 284 | if (!rc) |
| 285 | target_residency = 100; |
Preeti U Murthy | 0888839 | 2014-02-26 05:39:20 +0530 | [diff] [blame] | 286 | /* Add NAP state */ |
Gautham R. Shenoy | 9e9fc6f | 2017-01-25 14:06:27 +0530 | [diff] [blame^] | 287 | add_powernv_state(nr_idle_states, "Nap", |
| 288 | CPUIDLE_FLAG_NONE, nap_loop, |
| 289 | target_residency, exit_latency, 0); |
Shreyas B. Prabhu | 3005c59 | 2016-07-08 11:50:52 +0530 | [diff] [blame] | 290 | } else if ((flags[i] & OPAL_PM_STOP_INST_FAST) && |
| 291 | !(flags[i] & OPAL_PM_TIMEBASE_STOP)) { |
Gautham R. Shenoy | 9e9fc6f | 2017-01-25 14:06:27 +0530 | [diff] [blame^] | 292 | add_powernv_state(nr_idle_states, names[i], |
| 293 | CPUIDLE_FLAG_NONE, stop_loop, |
| 294 | target_residency, exit_latency, |
| 295 | psscr_val[i]); |
preeti | cc5a2f7 | 2015-06-24 01:48:01 -0500 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | /* |
| 299 | * All cpuidle states with CPUIDLE_FLAG_TIMER_STOP set must come |
| 300 | * within this config dependency check. |
| 301 | */ |
| 302 | #ifdef CONFIG_TICK_ONESHOT |
| 303 | if (flags[i] & OPAL_PM_SLEEP_ENABLED || |
Preeti U Murthy | 70734a7 | 2015-02-18 23:24:53 -0600 | [diff] [blame] | 304 | flags[i] & OPAL_PM_SLEEP_ENABLED_ER1) { |
Gautham R. Shenoy | 9e9fc6f | 2017-01-25 14:06:27 +0530 | [diff] [blame^] | 305 | if (!rc) |
| 306 | target_residency = 300000; |
Preeti U Murthy | 0888839 | 2014-02-26 05:39:20 +0530 | [diff] [blame] | 307 | /* Add FASTSLEEP state */ |
Gautham R. Shenoy | 9e9fc6f | 2017-01-25 14:06:27 +0530 | [diff] [blame^] | 308 | add_powernv_state(nr_idle_states, "FastSleep", |
| 309 | CPUIDLE_FLAG_TIMER_STOP, |
| 310 | fastsleep_loop, |
| 311 | target_residency, exit_latency, 0); |
Shreyas B. Prabhu | 3005c59 | 2016-07-08 11:50:52 +0530 | [diff] [blame] | 312 | } else if ((flags[i] & OPAL_PM_STOP_INST_DEEP) && |
| 313 | (flags[i] & OPAL_PM_TIMEBASE_STOP)) { |
Gautham R. Shenoy | 9e9fc6f | 2017-01-25 14:06:27 +0530 | [diff] [blame^] | 314 | add_powernv_state(nr_idle_states, names[i], |
| 315 | CPUIDLE_FLAG_TIMER_STOP, stop_loop, |
| 316 | target_residency, exit_latency, |
| 317 | psscr_val[i]); |
Preeti U Murthy | 0888839 | 2014-02-26 05:39:20 +0530 | [diff] [blame] | 318 | } |
preeti | cc5a2f7 | 2015-06-24 01:48:01 -0500 | [diff] [blame] | 319 | #endif |
Preeti U Murthy | 92c83ff5 | 2015-02-18 06:34:17 +0100 | [diff] [blame] | 320 | nr_idle_states++; |
Preeti U Murthy | 0888839 | 2014-02-26 05:39:20 +0530 | [diff] [blame] | 321 | } |
Preeti U Murthy | 92c83ff5 | 2015-02-18 06:34:17 +0100 | [diff] [blame] | 322 | out: |
Preeti U Murthy | 0888839 | 2014-02-26 05:39:20 +0530 | [diff] [blame] | 323 | return nr_idle_states; |
| 324 | } |
| 325 | |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 326 | /* |
| 327 | * powernv_idle_probe() |
| 328 | * Choose state table for shared versus dedicated partition |
| 329 | */ |
| 330 | static int powernv_idle_probe(void) |
| 331 | { |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 332 | if (cpuidle_disable != IDLE_NO_OVERRIDE) |
| 333 | return -ENODEV; |
| 334 | |
Stewart Smith | e4d54f7 | 2015-12-09 17:18:20 +1100 | [diff] [blame] | 335 | if (firmware_has_feature(FW_FEATURE_OPAL)) { |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 336 | cpuidle_state_table = powernv_states; |
Preeti U Murthy | 0888839 | 2014-02-26 05:39:20 +0530 | [diff] [blame] | 337 | /* Device tree can indicate more idle states */ |
| 338 | max_idle_state = powernv_add_idle_states(); |
Shilpasri G Bhat | 78eaa10 | 2015-06-18 16:53:11 +0530 | [diff] [blame] | 339 | if (max_idle_state > 1) { |
| 340 | snooze_timeout_en = true; |
| 341 | snooze_timeout = powernv_states[1].target_residency * |
| 342 | tb_ticks_per_usec; |
| 343 | } |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 344 | } else |
| 345 | return -ENODEV; |
| 346 | |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | static int __init powernv_processor_idle_init(void) |
| 351 | { |
| 352 | int retval; |
| 353 | |
| 354 | retval = powernv_idle_probe(); |
| 355 | if (retval) |
| 356 | return retval; |
| 357 | |
| 358 | powernv_cpuidle_driver_init(); |
| 359 | retval = cpuidle_register(&powernv_idle_driver, NULL); |
| 360 | if (retval) { |
| 361 | printk(KERN_DEBUG "Registration of powernv driver failed.\n"); |
| 362 | return retval; |
| 363 | } |
| 364 | |
Sebastian Andrzej Siewior | 10fcca9 | 2016-08-24 11:12:59 +0200 | [diff] [blame] | 365 | retval = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, |
| 366 | "cpuidle/powernv:online", |
| 367 | powernv_cpuidle_cpu_online, NULL); |
| 368 | WARN_ON(retval < 0); |
| 369 | retval = cpuhp_setup_state_nocalls(CPUHP_CPUIDLE_DEAD, |
| 370 | "cpuidle/powernv:dead", NULL, |
| 371 | powernv_cpuidle_cpu_dead); |
| 372 | WARN_ON(retval < 0); |
Deepthi Dharwar | 2c2e6ec | 2014-01-14 16:32:40 +0530 | [diff] [blame] | 373 | printk(KERN_DEBUG "powernv_idle_driver registered\n"); |
| 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | device_initcall(powernv_processor_idle_init); |