blob: 50b3c2e0306f9565151f58d26f86c8c115db242d [file] [log] [blame]
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +05301/*
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 Murthy0d948732014-02-26 05:39:06 +053014#include <linux/clockchips.h>
Preeti U Murthy08888392014-02-26 05:39:20 +053015#include <linux/of.h>
Preeti U Murthy92c83ff52015-02-18 06:34:17 +010016#include <linux/slab.h>
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +053017
18#include <asm/machdep.h>
19#include <asm/firmware.h>
Shreyas B. Prabhu8eb8ac82014-12-10 00:26:51 +053020#include <asm/opal.h>
Nicolas Pitre591ac0c2014-02-17 10:59:29 -050021#include <asm/runlatch.h>
Gautham R. Shenoy09206b62017-01-25 14:06:28 +053022#include <asm/cpuidle.h>
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +053023
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +053024/*
25 * Expose only those Hardware idle states via the cpuidle framework
26 * that have latency value below POWERNV_THRESHOLD_LATENCY_NS.
27 */
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +053028#define POWERNV_THRESHOLD_LATENCY_NS 200000
29
Andrew Donnellaned613902016-11-22 16:08:06 +110030static struct cpuidle_driver powernv_idle_driver = {
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +053031 .name = "powernv_idle",
32 .owner = THIS_MODULE,
33};
34
35static int max_idle_state;
36static struct cpuidle_state *cpuidle_state_table;
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +053037
Gautham R. Shenoy09206b62017-01-25 14:06:28 +053038struct stop_psscr_table {
39 u64 val;
40 u64 mask;
41};
42
43static struct stop_psscr_table stop_psscr_table[CPUIDLE_STATE_MAX];
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +053044
Shilpasri G Bhat78eaa102015-06-18 16:53:11 +053045static u64 snooze_timeout;
46static bool snooze_timeout_en;
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +053047
48static int snooze_loop(struct cpuidle_device *dev,
49 struct cpuidle_driver *drv,
50 int index)
51{
Shilpasri G Bhat78eaa102015-06-18 16:53:11 +053052 u64 snooze_exit_time;
53
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +053054 set_thread_flag(TIF_POLLING_NRFLAG);
55
Nicholas Piggin3fc5ee922017-06-14 23:02:39 +100056 local_irq_enable();
57
Shilpasri G Bhat78eaa102015-06-18 16:53:11 +053058 snooze_exit_time = get_tb() + snooze_timeout;
Nicolas Pitre591ac0c2014-02-17 10:59:29 -050059 ppc64_runlatch_off();
Anton Blanchard26eb48a2017-04-04 07:54:13 +100060 HMT_very_low();
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +053061 while (!need_resched()) {
Anton Blanchard0baa91c2017-04-04 07:54:14 +100062 if (likely(snooze_timeout_en) && get_tb() > snooze_exit_time)
Shilpasri G Bhat78eaa102015-06-18 16:53:11 +053063 break;
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +053064 }
65
66 HMT_medium();
Nicolas Pitre591ac0c2014-02-17 10:59:29 -050067 ppc64_runlatch_on();
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +053068 clear_thread_flag(TIF_POLLING_NRFLAG);
69 smp_mb();
Nicholas Piggin3fc5ee922017-06-14 23:02:39 +100070
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +053071 return index;
72}
73
74static int nap_loop(struct cpuidle_device *dev,
75 struct cpuidle_driver *drv,
76 int index)
77{
Nicholas Piggin2201f992017-06-13 23:05:45 +100078 power7_idle_type(PNV_THREAD_NAP);
79
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +053080 return index;
81}
82
preeticc5a2f72015-06-24 01:48:01 -050083/* Register for fastsleep only in oneshot mode of broadcast */
84#ifdef CONFIG_TICK_ONESHOT
Preeti U Murthy0d948732014-02-26 05:39:06 +053085static int fastsleep_loop(struct cpuidle_device *dev,
86 struct cpuidle_driver *drv,
87 int index)
88{
89 unsigned long old_lpcr = mfspr(SPRN_LPCR);
90 unsigned long new_lpcr;
91
92 if (unlikely(system_state < SYSTEM_RUNNING))
93 return index;
94
95 new_lpcr = old_lpcr;
Michael Neuling9b6a68d2014-06-11 15:59:27 +100096 /* Do not exit powersave upon decrementer as we've setup the timer
97 * offload.
Preeti U Murthy0d948732014-02-26 05:39:06 +053098 */
Michael Neuling9b6a68d2014-06-11 15:59:27 +100099 new_lpcr &= ~LPCR_PECE1;
Preeti U Murthy0d948732014-02-26 05:39:06 +0530100
101 mtspr(SPRN_LPCR, new_lpcr);
Nicholas Piggin2201f992017-06-13 23:05:45 +1000102
103 power7_idle_type(PNV_THREAD_SLEEP);
Preeti U Murthy0d948732014-02-26 05:39:06 +0530104
105 mtspr(SPRN_LPCR, old_lpcr);
106
107 return index;
108}
preeticc5a2f72015-06-24 01:48:01 -0500109#endif
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530110
111static int stop_loop(struct cpuidle_device *dev,
112 struct cpuidle_driver *drv,
113 int index)
114{
Nicholas Piggin2201f992017-06-13 23:05:45 +1000115 power9_idle_type(stop_psscr_table[index].val,
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530116 stop_psscr_table[index].mask);
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530117 return index;
118}
119
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530120/*
121 * States for dedicated partition case.
122 */
Shreyas B. Prabhu169f3fa2016-07-08 11:50:50 +0530123static struct cpuidle_state powernv_states[CPUIDLE_STATE_MAX] = {
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530124 { /* Snooze */
125 .name = "snooze",
126 .desc = "snooze",
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530127 .exit_latency = 0,
128 .target_residency = 0,
Shreyas B. Prabhu957efce2016-07-08 11:50:51 +0530129 .enter = snooze_loop },
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530130};
131
Sebastian Andrzej Siewior10fcca92016-08-24 11:12:59 +0200132static int powernv_cpuidle_cpu_online(unsigned int cpu)
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530133{
Sebastian Andrzej Siewior10fcca92016-08-24 11:12:59 +0200134 struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu);
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530135
136 if (dev && cpuidle_get_driver()) {
Sebastian Andrzej Siewior10fcca92016-08-24 11:12:59 +0200137 cpuidle_pause_and_lock();
138 cpuidle_enable_device(dev);
139 cpuidle_resume_and_unlock();
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530140 }
Sebastian Andrzej Siewior10fcca92016-08-24 11:12:59 +0200141 return 0;
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530142}
143
Sebastian Andrzej Siewior10fcca92016-08-24 11:12:59 +0200144static int powernv_cpuidle_cpu_dead(unsigned int cpu)
145{
146 struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu);
147
148 if (dev && cpuidle_get_driver()) {
149 cpuidle_pause_and_lock();
150 cpuidle_disable_device(dev);
151 cpuidle_resume_and_unlock();
152 }
153 return 0;
154}
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530155
156/*
157 * powernv_cpuidle_driver_init()
158 */
159static int powernv_cpuidle_driver_init(void)
160{
161 int idle_state;
162 struct cpuidle_driver *drv = &powernv_idle_driver;
163
164 drv->state_count = 0;
165
166 for (idle_state = 0; idle_state < max_idle_state; ++idle_state) {
167 /* Is the state not enabled? */
168 if (cpuidle_state_table[idle_state].enter == NULL)
169 continue;
170
171 drv->states[drv->state_count] = /* structure copy */
172 cpuidle_state_table[idle_state];
173
174 drv->state_count += 1;
175 }
176
Vaidyanathan Srinivasan293d2642017-03-23 20:52:46 +0530177 /*
178 * On the PowerNV platform cpu_present may be less than cpu_possible in
179 * cases when firmware detects the CPU, but it is not available to the
180 * OS. If CONFIG_HOTPLUG_CPU=n, then such CPUs are not hotplugable at
181 * run time and hence cpu_devices are not created for those CPUs by the
182 * generic topology_init().
183 *
184 * drv->cpumask defaults to cpu_possible_mask in
185 * __cpuidle_driver_init(). This breaks cpuidle on PowerNV where
186 * cpu_devices are not created for CPUs in cpu_possible_mask that
187 * cannot be hot-added later at run time.
188 *
189 * Trying cpuidle_register_device() on a CPU without a cpu_device is
190 * incorrect, so pass a correct CPU mask to the generic cpuidle driver.
191 */
192
193 drv->cpumask = (struct cpumask *)cpu_present_mask;
194
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530195 return 0;
196}
197
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530198static inline void add_powernv_state(int index, const char *name,
199 unsigned int flags,
200 int (*idle_fn)(struct cpuidle_device *,
201 struct cpuidle_driver *,
202 int),
203 unsigned int target_residency,
204 unsigned int exit_latency,
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530205 u64 psscr_val, u64 psscr_mask)
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530206{
207 strlcpy(powernv_states[index].name, name, CPUIDLE_NAME_LEN);
208 strlcpy(powernv_states[index].desc, name, CPUIDLE_NAME_LEN);
209 powernv_states[index].flags = flags;
210 powernv_states[index].target_residency = target_residency;
211 powernv_states[index].exit_latency = exit_latency;
212 powernv_states[index].enter = idle_fn;
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530213 stop_psscr_table[index].val = psscr_val;
214 stop_psscr_table[index].mask = psscr_mask;
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530215}
216
Gautham R. Shenoyecad4502017-03-15 13:45:53 +0530217/*
218 * Returns 0 if prop1_len == prop2_len. Else returns -1
219 */
220static inline int validate_dt_prop_sizes(const char *prop1, int prop1_len,
221 const char *prop2, int prop2_len)
222{
223 if (prop1_len == prop2_len)
224 return 0;
225
226 pr_warn("cpuidle-powernv: array sizes don't match for %s and %s\n",
227 prop1, prop2);
228 return -1;
229}
230
Preeti U Murthy08888392014-02-26 05:39:20 +0530231static int powernv_add_idle_states(void)
232{
233 struct device_node *power_mgt;
Preeti U Murthy08888392014-02-26 05:39:20 +0530234 int nr_idle_states = 1; /* Snooze */
Gautham R. Shenoyecad4502017-03-15 13:45:53 +0530235 int dt_idle_states, count;
Shreyas B. Prabhu957efce2016-07-08 11:50:51 +0530236 u32 latency_ns[CPUIDLE_STATE_MAX];
237 u32 residency_ns[CPUIDLE_STATE_MAX];
238 u32 flags[CPUIDLE_STATE_MAX];
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530239 u64 psscr_val[CPUIDLE_STATE_MAX];
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530240 u64 psscr_mask[CPUIDLE_STATE_MAX];
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530241 const char *names[CPUIDLE_STATE_MAX];
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530242 u32 has_stop_states = 0;
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100243 int i, rc;
Preeti U Murthy08888392014-02-26 05:39:20 +0530244
245 /* Currently we have snooze statically defined */
246
247 power_mgt = of_find_node_by_path("/ibm,opal/power-mgt");
248 if (!power_mgt) {
249 pr_warn("opal: PowerMgmt Node not found\n");
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100250 goto out;
Preeti U Murthy08888392014-02-26 05:39:20 +0530251 }
252
Preeti U Murthy70734a72015-02-18 23:24:53 -0600253 /* Read values of any property to determine the num of idle states */
254 dt_idle_states = of_property_count_u32_elems(power_mgt, "ibm,cpu-idle-state-flags");
255 if (dt_idle_states < 0) {
256 pr_warn("cpuidle-powernv: no idle states found in the DT\n");
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100257 goto out;
Preeti U. Murthy74aa51b2014-10-14 13:23:00 +0530258 }
259
Gautham R. Shenoyecad4502017-03-15 13:45:53 +0530260 count = of_property_count_u32_elems(power_mgt,
261 "ibm,cpu-idle-state-latencies-ns");
262
263 if (validate_dt_prop_sizes("ibm,cpu-idle-state-flags", dt_idle_states,
264 "ibm,cpu-idle-state-latencies-ns",
265 count) != 0)
266 goto out;
267
268 count = of_property_count_strings(power_mgt,
269 "ibm,cpu-idle-state-names");
270 if (validate_dt_prop_sizes("ibm,cpu-idle-state-flags", dt_idle_states,
271 "ibm,cpu-idle-state-names",
272 count) != 0)
273 goto out;
274
Shreyas B. Prabhu957efce2016-07-08 11:50:51 +0530275 /*
276 * Since snooze is used as first idle state, max idle states allowed is
277 * CPUIDLE_STATE_MAX -1
278 */
279 if (dt_idle_states > CPUIDLE_STATE_MAX - 1) {
280 pr_warn("cpuidle-powernv: discovered idle states more than allowed");
281 dt_idle_states = CPUIDLE_STATE_MAX - 1;
282 }
283
Preeti U Murthy70734a72015-02-18 23:24:53 -0600284 if (of_property_read_u32_array(power_mgt,
285 "ibm,cpu-idle-state-flags", flags, dt_idle_states)) {
286 pr_warn("cpuidle-powernv : missing ibm,cpu-idle-state-flags in DT\n");
Shreyas B. Prabhu957efce2016-07-08 11:50:51 +0530287 goto out;
Preeti U Murthy70734a72015-02-18 23:24:53 -0600288 }
Preeti U Murthy08888392014-02-26 05:39:20 +0530289
Shreyas B. Prabhu957efce2016-07-08 11:50:51 +0530290 if (of_property_read_u32_array(power_mgt,
291 "ibm,cpu-idle-state-latencies-ns", latency_ns,
292 dt_idle_states)) {
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100293 pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-latencies-ns in DT\n");
Shreyas B. Prabhu957efce2016-07-08 11:50:51 +0530294 goto out;
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100295 }
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530296 if (of_property_read_string_array(power_mgt,
297 "ibm,cpu-idle-state-names", names, dt_idle_states) < 0) {
298 pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-names in DT\n");
299 goto out;
300 }
301
302 /*
303 * If the idle states use stop instruction, probe for psscr values
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530304 * and psscr mask which are necessary to specify required stop level.
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530305 */
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530306 has_stop_states = (flags[0] &
307 (OPAL_PM_STOP_INST_FAST | OPAL_PM_STOP_INST_DEEP));
308 if (has_stop_states) {
Gautham R. Shenoyecad4502017-03-15 13:45:53 +0530309 count = of_property_count_u64_elems(power_mgt,
310 "ibm,cpu-idle-state-psscr");
311 if (validate_dt_prop_sizes("ibm,cpu-idle-state-flags",
312 dt_idle_states,
313 "ibm,cpu-idle-state-psscr",
314 count) != 0)
315 goto out;
316
317 count = of_property_count_u64_elems(power_mgt,
318 "ibm,cpu-idle-state-psscr-mask");
319 if (validate_dt_prop_sizes("ibm,cpu-idle-state-flags",
320 dt_idle_states,
321 "ibm,cpu-idle-state-psscr-mask",
322 count) != 0)
323 goto out;
324
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530325 if (of_property_read_u64_array(power_mgt,
326 "ibm,cpu-idle-state-psscr", psscr_val, dt_idle_states)) {
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530327 pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-psscr in DT\n");
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530328 goto out;
329 }
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100330
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530331 if (of_property_read_u64_array(power_mgt,
332 "ibm,cpu-idle-state-psscr-mask",
333 psscr_mask, dt_idle_states)) {
334 pr_warn("cpuidle-powernv:Missing ibm,cpu-idle-state-psscr-mask in DT\n");
335 goto out;
336 }
337 }
338
Gautham R. Shenoyecad4502017-03-15 13:45:53 +0530339 count = of_property_count_u32_elems(power_mgt,
340 "ibm,cpu-idle-state-residency-ns");
341
342 if (count < 0) {
343 rc = count;
344 } else if (validate_dt_prop_sizes("ibm,cpu-idle-state-flags",
345 dt_idle_states,
346 "ibm,cpu-idle-state-residency-ns",
347 count) != 0) {
348 goto out;
349 } else {
350 rc = of_property_read_u32_array(power_mgt,
351 "ibm,cpu-idle-state-residency-ns",
352 residency_ns, dt_idle_states);
353 }
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100354
Preeti U Murthy08888392014-02-26 05:39:20 +0530355 for (i = 0; i < dt_idle_states; i++) {
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530356 unsigned int exit_latency, target_residency;
Gautham R. Shenoyf9122ee2017-05-16 14:19:48 +0530357 bool stops_timebase = false;
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530358 /*
359 * If an idle state has exit latency beyond
360 * POWERNV_THRESHOLD_LATENCY_NS then don't use it
361 * in cpu-idle.
362 */
363 if (latency_ns[i] > POWERNV_THRESHOLD_LATENCY_NS)
364 continue;
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530365 /*
366 * Firmware passes residency and latency values in ns.
367 * cpuidle expects it in us.
368 */
369 exit_latency = latency_ns[i] / 1000;
370 if (!rc)
371 target_residency = residency_ns[i] / 1000;
372 else
373 target_residency = 0;
Preeti U Murthy08888392014-02-26 05:39:20 +0530374
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530375 if (has_stop_states) {
376 int err = validate_psscr_val_mask(&psscr_val[i],
377 &psscr_mask[i],
378 flags[i]);
379 if (err) {
380 report_invalid_psscr_val(psscr_val[i], err);
381 continue;
382 }
383 }
384
Gautham R. Shenoyf9122ee2017-05-16 14:19:48 +0530385 if (flags[i] & OPAL_PM_TIMEBASE_STOP)
386 stops_timebase = true;
387
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100388 /*
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530389 * For nap and fastsleep, use default target_residency
390 * values if f/w does not expose it.
Preeti U. Murthy74aa51b2014-10-14 13:23:00 +0530391 */
Preeti U Murthy70734a72015-02-18 23:24:53 -0600392 if (flags[i] & OPAL_PM_NAP_ENABLED) {
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530393 if (!rc)
394 target_residency = 100;
Preeti U Murthy08888392014-02-26 05:39:20 +0530395 /* Add NAP state */
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530396 add_powernv_state(nr_idle_states, "Nap",
397 CPUIDLE_FLAG_NONE, nap_loop,
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530398 target_residency, exit_latency, 0, 0);
Gautham R. Shenoyf9122ee2017-05-16 14:19:48 +0530399 } else if (has_stop_states && !stops_timebase) {
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530400 add_powernv_state(nr_idle_states, names[i],
401 CPUIDLE_FLAG_NONE, stop_loop,
402 target_residency, exit_latency,
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530403 psscr_val[i], psscr_mask[i]);
preeticc5a2f72015-06-24 01:48:01 -0500404 }
405
406 /*
407 * All cpuidle states with CPUIDLE_FLAG_TIMER_STOP set must come
408 * within this config dependency check.
409 */
410#ifdef CONFIG_TICK_ONESHOT
Gautham R. Shenoyf9122ee2017-05-16 14:19:48 +0530411 else if (flags[i] & OPAL_PM_SLEEP_ENABLED ||
412 flags[i] & OPAL_PM_SLEEP_ENABLED_ER1) {
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530413 if (!rc)
414 target_residency = 300000;
Preeti U Murthy08888392014-02-26 05:39:20 +0530415 /* Add FASTSLEEP state */
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530416 add_powernv_state(nr_idle_states, "FastSleep",
417 CPUIDLE_FLAG_TIMER_STOP,
418 fastsleep_loop,
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530419 target_residency, exit_latency, 0, 0);
Gautham R. Shenoyf9122ee2017-05-16 14:19:48 +0530420 } else if (has_stop_states && stops_timebase) {
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530421 add_powernv_state(nr_idle_states, names[i],
422 CPUIDLE_FLAG_TIMER_STOP, stop_loop,
423 target_residency, exit_latency,
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530424 psscr_val[i], psscr_mask[i]);
Preeti U Murthy08888392014-02-26 05:39:20 +0530425 }
preeticc5a2f72015-06-24 01:48:01 -0500426#endif
Gautham R. Shenoyf9122ee2017-05-16 14:19:48 +0530427 else
428 continue;
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100429 nr_idle_states++;
Preeti U Murthy08888392014-02-26 05:39:20 +0530430 }
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100431out:
Preeti U Murthy08888392014-02-26 05:39:20 +0530432 return nr_idle_states;
433}
434
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530435/*
436 * powernv_idle_probe()
437 * Choose state table for shared versus dedicated partition
438 */
439static int powernv_idle_probe(void)
440{
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530441 if (cpuidle_disable != IDLE_NO_OVERRIDE)
442 return -ENODEV;
443
Stewart Smithe4d54f72015-12-09 17:18:20 +1100444 if (firmware_has_feature(FW_FEATURE_OPAL)) {
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530445 cpuidle_state_table = powernv_states;
Preeti U Murthy08888392014-02-26 05:39:20 +0530446 /* Device tree can indicate more idle states */
447 max_idle_state = powernv_add_idle_states();
Shilpasri G Bhat78eaa102015-06-18 16:53:11 +0530448 if (max_idle_state > 1) {
449 snooze_timeout_en = true;
450 snooze_timeout = powernv_states[1].target_residency *
451 tb_ticks_per_usec;
452 }
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530453 } else
454 return -ENODEV;
455
456 return 0;
457}
458
459static int __init powernv_processor_idle_init(void)
460{
461 int retval;
462
463 retval = powernv_idle_probe();
464 if (retval)
465 return retval;
466
467 powernv_cpuidle_driver_init();
468 retval = cpuidle_register(&powernv_idle_driver, NULL);
469 if (retval) {
470 printk(KERN_DEBUG "Registration of powernv driver failed.\n");
471 return retval;
472 }
473
Sebastian Andrzej Siewior10fcca92016-08-24 11:12:59 +0200474 retval = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
475 "cpuidle/powernv:online",
476 powernv_cpuidle_cpu_online, NULL);
477 WARN_ON(retval < 0);
478 retval = cpuhp_setup_state_nocalls(CPUHP_CPUIDLE_DEAD,
479 "cpuidle/powernv:dead", NULL,
480 powernv_cpuidle_cpu_dead);
481 WARN_ON(retval < 0);
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530482 printk(KERN_DEBUG "powernv_idle_driver registered\n");
483 return 0;
484}
485
486device_initcall(powernv_processor_idle_init);