blob: 79152676f62b2f6d913b723dfc2eb2fe785b0e4f [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 local_irq_enable();
55 set_thread_flag(TIF_POLLING_NRFLAG);
56
Shilpasri G Bhat78eaa102015-06-18 16:53:11 +053057 snooze_exit_time = get_tb() + snooze_timeout;
Nicolas Pitre591ac0c2014-02-17 10:59:29 -050058 ppc64_runlatch_off();
Anton Blanchard26eb48a2017-04-04 07:54:13 +100059 HMT_very_low();
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +053060 while (!need_resched()) {
Anton Blanchard0baa91c2017-04-04 07:54:14 +100061 if (likely(snooze_timeout_en) && get_tb() > snooze_exit_time)
Shilpasri G Bhat78eaa102015-06-18 16:53:11 +053062 break;
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +053063 }
64
65 HMT_medium();
Nicolas Pitre591ac0c2014-02-17 10:59:29 -050066 ppc64_runlatch_on();
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +053067 clear_thread_flag(TIF_POLLING_NRFLAG);
68 smp_mb();
69 return index;
70}
71
72static int nap_loop(struct cpuidle_device *dev,
73 struct cpuidle_driver *drv,
74 int index)
75{
Nicholas Piggin2201f992017-06-13 23:05:45 +100076 power7_idle_type(PNV_THREAD_NAP);
77
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +053078 return index;
79}
80
preeticc5a2f72015-06-24 01:48:01 -050081/* Register for fastsleep only in oneshot mode of broadcast */
82#ifdef CONFIG_TICK_ONESHOT
Preeti U Murthy0d948732014-02-26 05:39:06 +053083static int fastsleep_loop(struct cpuidle_device *dev,
84 struct cpuidle_driver *drv,
85 int index)
86{
87 unsigned long old_lpcr = mfspr(SPRN_LPCR);
88 unsigned long new_lpcr;
89
90 if (unlikely(system_state < SYSTEM_RUNNING))
91 return index;
92
93 new_lpcr = old_lpcr;
Michael Neuling9b6a68d2014-06-11 15:59:27 +100094 /* Do not exit powersave upon decrementer as we've setup the timer
95 * offload.
Preeti U Murthy0d948732014-02-26 05:39:06 +053096 */
Michael Neuling9b6a68d2014-06-11 15:59:27 +100097 new_lpcr &= ~LPCR_PECE1;
Preeti U Murthy0d948732014-02-26 05:39:06 +053098
99 mtspr(SPRN_LPCR, new_lpcr);
Nicholas Piggin2201f992017-06-13 23:05:45 +1000100
101 power7_idle_type(PNV_THREAD_SLEEP);
Preeti U Murthy0d948732014-02-26 05:39:06 +0530102
103 mtspr(SPRN_LPCR, old_lpcr);
104
105 return index;
106}
preeticc5a2f72015-06-24 01:48:01 -0500107#endif
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530108
109static int stop_loop(struct cpuidle_device *dev,
110 struct cpuidle_driver *drv,
111 int index)
112{
Nicholas Piggin2201f992017-06-13 23:05:45 +1000113 power9_idle_type(stop_psscr_table[index].val,
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530114 stop_psscr_table[index].mask);
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530115 return index;
116}
117
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530118/*
119 * States for dedicated partition case.
120 */
Shreyas B. Prabhu169f3fa2016-07-08 11:50:50 +0530121static struct cpuidle_state powernv_states[CPUIDLE_STATE_MAX] = {
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530122 { /* Snooze */
123 .name = "snooze",
124 .desc = "snooze",
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530125 .exit_latency = 0,
126 .target_residency = 0,
Shreyas B. Prabhu957efce2016-07-08 11:50:51 +0530127 .enter = snooze_loop },
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530128};
129
Sebastian Andrzej Siewior10fcca92016-08-24 11:12:59 +0200130static int powernv_cpuidle_cpu_online(unsigned int cpu)
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530131{
Sebastian Andrzej Siewior10fcca92016-08-24 11:12:59 +0200132 struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu);
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530133
134 if (dev && cpuidle_get_driver()) {
Sebastian Andrzej Siewior10fcca92016-08-24 11:12:59 +0200135 cpuidle_pause_and_lock();
136 cpuidle_enable_device(dev);
137 cpuidle_resume_and_unlock();
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530138 }
Sebastian Andrzej Siewior10fcca92016-08-24 11:12:59 +0200139 return 0;
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530140}
141
Sebastian Andrzej Siewior10fcca92016-08-24 11:12:59 +0200142static int powernv_cpuidle_cpu_dead(unsigned int cpu)
143{
144 struct cpuidle_device *dev = per_cpu(cpuidle_devices, cpu);
145
146 if (dev && cpuidle_get_driver()) {
147 cpuidle_pause_and_lock();
148 cpuidle_disable_device(dev);
149 cpuidle_resume_and_unlock();
150 }
151 return 0;
152}
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530153
154/*
155 * powernv_cpuidle_driver_init()
156 */
157static int powernv_cpuidle_driver_init(void)
158{
159 int idle_state;
160 struct cpuidle_driver *drv = &powernv_idle_driver;
161
162 drv->state_count = 0;
163
164 for (idle_state = 0; idle_state < max_idle_state; ++idle_state) {
165 /* Is the state not enabled? */
166 if (cpuidle_state_table[idle_state].enter == NULL)
167 continue;
168
169 drv->states[drv->state_count] = /* structure copy */
170 cpuidle_state_table[idle_state];
171
172 drv->state_count += 1;
173 }
174
Vaidyanathan Srinivasan293d2642017-03-23 20:52:46 +0530175 /*
176 * On the PowerNV platform cpu_present may be less than cpu_possible in
177 * cases when firmware detects the CPU, but it is not available to the
178 * OS. If CONFIG_HOTPLUG_CPU=n, then such CPUs are not hotplugable at
179 * run time and hence cpu_devices are not created for those CPUs by the
180 * generic topology_init().
181 *
182 * drv->cpumask defaults to cpu_possible_mask in
183 * __cpuidle_driver_init(). This breaks cpuidle on PowerNV where
184 * cpu_devices are not created for CPUs in cpu_possible_mask that
185 * cannot be hot-added later at run time.
186 *
187 * Trying cpuidle_register_device() on a CPU without a cpu_device is
188 * incorrect, so pass a correct CPU mask to the generic cpuidle driver.
189 */
190
191 drv->cpumask = (struct cpumask *)cpu_present_mask;
192
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530193 return 0;
194}
195
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530196static inline void add_powernv_state(int index, const char *name,
197 unsigned int flags,
198 int (*idle_fn)(struct cpuidle_device *,
199 struct cpuidle_driver *,
200 int),
201 unsigned int target_residency,
202 unsigned int exit_latency,
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530203 u64 psscr_val, u64 psscr_mask)
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530204{
205 strlcpy(powernv_states[index].name, name, CPUIDLE_NAME_LEN);
206 strlcpy(powernv_states[index].desc, name, CPUIDLE_NAME_LEN);
207 powernv_states[index].flags = flags;
208 powernv_states[index].target_residency = target_residency;
209 powernv_states[index].exit_latency = exit_latency;
210 powernv_states[index].enter = idle_fn;
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530211 stop_psscr_table[index].val = psscr_val;
212 stop_psscr_table[index].mask = psscr_mask;
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530213}
214
Gautham R. Shenoyecad4502017-03-15 13:45:53 +0530215/*
216 * Returns 0 if prop1_len == prop2_len. Else returns -1
217 */
218static inline int validate_dt_prop_sizes(const char *prop1, int prop1_len,
219 const char *prop2, int prop2_len)
220{
221 if (prop1_len == prop2_len)
222 return 0;
223
224 pr_warn("cpuidle-powernv: array sizes don't match for %s and %s\n",
225 prop1, prop2);
226 return -1;
227}
228
Preeti U Murthy08888392014-02-26 05:39:20 +0530229static int powernv_add_idle_states(void)
230{
231 struct device_node *power_mgt;
Preeti U Murthy08888392014-02-26 05:39:20 +0530232 int nr_idle_states = 1; /* Snooze */
Gautham R. Shenoyecad4502017-03-15 13:45:53 +0530233 int dt_idle_states, count;
Shreyas B. Prabhu957efce2016-07-08 11:50:51 +0530234 u32 latency_ns[CPUIDLE_STATE_MAX];
235 u32 residency_ns[CPUIDLE_STATE_MAX];
236 u32 flags[CPUIDLE_STATE_MAX];
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530237 u64 psscr_val[CPUIDLE_STATE_MAX];
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530238 u64 psscr_mask[CPUIDLE_STATE_MAX];
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530239 const char *names[CPUIDLE_STATE_MAX];
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530240 u32 has_stop_states = 0;
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100241 int i, rc;
Preeti U Murthy08888392014-02-26 05:39:20 +0530242
243 /* Currently we have snooze statically defined */
244
245 power_mgt = of_find_node_by_path("/ibm,opal/power-mgt");
246 if (!power_mgt) {
247 pr_warn("opal: PowerMgmt Node not found\n");
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100248 goto out;
Preeti U Murthy08888392014-02-26 05:39:20 +0530249 }
250
Preeti U Murthy70734a72015-02-18 23:24:53 -0600251 /* Read values of any property to determine the num of idle states */
252 dt_idle_states = of_property_count_u32_elems(power_mgt, "ibm,cpu-idle-state-flags");
253 if (dt_idle_states < 0) {
254 pr_warn("cpuidle-powernv: no idle states found in the DT\n");
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100255 goto out;
Preeti U. Murthy74aa51b2014-10-14 13:23:00 +0530256 }
257
Gautham R. Shenoyecad4502017-03-15 13:45:53 +0530258 count = of_property_count_u32_elems(power_mgt,
259 "ibm,cpu-idle-state-latencies-ns");
260
261 if (validate_dt_prop_sizes("ibm,cpu-idle-state-flags", dt_idle_states,
262 "ibm,cpu-idle-state-latencies-ns",
263 count) != 0)
264 goto out;
265
266 count = of_property_count_strings(power_mgt,
267 "ibm,cpu-idle-state-names");
268 if (validate_dt_prop_sizes("ibm,cpu-idle-state-flags", dt_idle_states,
269 "ibm,cpu-idle-state-names",
270 count) != 0)
271 goto out;
272
Shreyas B. Prabhu957efce2016-07-08 11:50:51 +0530273 /*
274 * Since snooze is used as first idle state, max idle states allowed is
275 * CPUIDLE_STATE_MAX -1
276 */
277 if (dt_idle_states > CPUIDLE_STATE_MAX - 1) {
278 pr_warn("cpuidle-powernv: discovered idle states more than allowed");
279 dt_idle_states = CPUIDLE_STATE_MAX - 1;
280 }
281
Preeti U Murthy70734a72015-02-18 23:24:53 -0600282 if (of_property_read_u32_array(power_mgt,
283 "ibm,cpu-idle-state-flags", flags, dt_idle_states)) {
284 pr_warn("cpuidle-powernv : missing ibm,cpu-idle-state-flags in DT\n");
Shreyas B. Prabhu957efce2016-07-08 11:50:51 +0530285 goto out;
Preeti U Murthy70734a72015-02-18 23:24:53 -0600286 }
Preeti U Murthy08888392014-02-26 05:39:20 +0530287
Shreyas B. Prabhu957efce2016-07-08 11:50:51 +0530288 if (of_property_read_u32_array(power_mgt,
289 "ibm,cpu-idle-state-latencies-ns", latency_ns,
290 dt_idle_states)) {
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100291 pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-latencies-ns in DT\n");
Shreyas B. Prabhu957efce2016-07-08 11:50:51 +0530292 goto out;
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100293 }
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530294 if (of_property_read_string_array(power_mgt,
295 "ibm,cpu-idle-state-names", names, dt_idle_states) < 0) {
296 pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-names in DT\n");
297 goto out;
298 }
299
300 /*
301 * If the idle states use stop instruction, probe for psscr values
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530302 * and psscr mask which are necessary to specify required stop level.
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530303 */
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530304 has_stop_states = (flags[0] &
305 (OPAL_PM_STOP_INST_FAST | OPAL_PM_STOP_INST_DEEP));
306 if (has_stop_states) {
Gautham R. Shenoyecad4502017-03-15 13:45:53 +0530307 count = of_property_count_u64_elems(power_mgt,
308 "ibm,cpu-idle-state-psscr");
309 if (validate_dt_prop_sizes("ibm,cpu-idle-state-flags",
310 dt_idle_states,
311 "ibm,cpu-idle-state-psscr",
312 count) != 0)
313 goto out;
314
315 count = of_property_count_u64_elems(power_mgt,
316 "ibm,cpu-idle-state-psscr-mask");
317 if (validate_dt_prop_sizes("ibm,cpu-idle-state-flags",
318 dt_idle_states,
319 "ibm,cpu-idle-state-psscr-mask",
320 count) != 0)
321 goto out;
322
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530323 if (of_property_read_u64_array(power_mgt,
324 "ibm,cpu-idle-state-psscr", psscr_val, dt_idle_states)) {
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530325 pr_warn("cpuidle-powernv: missing ibm,cpu-idle-state-psscr in DT\n");
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530326 goto out;
327 }
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100328
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530329 if (of_property_read_u64_array(power_mgt,
330 "ibm,cpu-idle-state-psscr-mask",
331 psscr_mask, dt_idle_states)) {
332 pr_warn("cpuidle-powernv:Missing ibm,cpu-idle-state-psscr-mask in DT\n");
333 goto out;
334 }
335 }
336
Gautham R. Shenoyecad4502017-03-15 13:45:53 +0530337 count = of_property_count_u32_elems(power_mgt,
338 "ibm,cpu-idle-state-residency-ns");
339
340 if (count < 0) {
341 rc = count;
342 } else if (validate_dt_prop_sizes("ibm,cpu-idle-state-flags",
343 dt_idle_states,
344 "ibm,cpu-idle-state-residency-ns",
345 count) != 0) {
346 goto out;
347 } else {
348 rc = of_property_read_u32_array(power_mgt,
349 "ibm,cpu-idle-state-residency-ns",
350 residency_ns, dt_idle_states);
351 }
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100352
Preeti U Murthy08888392014-02-26 05:39:20 +0530353 for (i = 0; i < dt_idle_states; i++) {
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530354 unsigned int exit_latency, target_residency;
Gautham R. Shenoyf9122ee2017-05-16 14:19:48 +0530355 bool stops_timebase = false;
Shreyas B. Prabhu3005c592016-07-08 11:50:52 +0530356 /*
357 * If an idle state has exit latency beyond
358 * POWERNV_THRESHOLD_LATENCY_NS then don't use it
359 * in cpu-idle.
360 */
361 if (latency_ns[i] > POWERNV_THRESHOLD_LATENCY_NS)
362 continue;
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530363 /*
364 * Firmware passes residency and latency values in ns.
365 * cpuidle expects it in us.
366 */
367 exit_latency = latency_ns[i] / 1000;
368 if (!rc)
369 target_residency = residency_ns[i] / 1000;
370 else
371 target_residency = 0;
Preeti U Murthy08888392014-02-26 05:39:20 +0530372
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530373 if (has_stop_states) {
374 int err = validate_psscr_val_mask(&psscr_val[i],
375 &psscr_mask[i],
376 flags[i]);
377 if (err) {
378 report_invalid_psscr_val(psscr_val[i], err);
379 continue;
380 }
381 }
382
Gautham R. Shenoyf9122ee2017-05-16 14:19:48 +0530383 if (flags[i] & OPAL_PM_TIMEBASE_STOP)
384 stops_timebase = true;
385
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100386 /*
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530387 * For nap and fastsleep, use default target_residency
388 * values if f/w does not expose it.
Preeti U. Murthy74aa51b2014-10-14 13:23:00 +0530389 */
Preeti U Murthy70734a72015-02-18 23:24:53 -0600390 if (flags[i] & OPAL_PM_NAP_ENABLED) {
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530391 if (!rc)
392 target_residency = 100;
Preeti U Murthy08888392014-02-26 05:39:20 +0530393 /* Add NAP state */
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530394 add_powernv_state(nr_idle_states, "Nap",
395 CPUIDLE_FLAG_NONE, nap_loop,
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530396 target_residency, exit_latency, 0, 0);
Gautham R. Shenoyf9122ee2017-05-16 14:19:48 +0530397 } else if (has_stop_states && !stops_timebase) {
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530398 add_powernv_state(nr_idle_states, names[i],
399 CPUIDLE_FLAG_NONE, stop_loop,
400 target_residency, exit_latency,
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530401 psscr_val[i], psscr_mask[i]);
preeticc5a2f72015-06-24 01:48:01 -0500402 }
403
404 /*
405 * All cpuidle states with CPUIDLE_FLAG_TIMER_STOP set must come
406 * within this config dependency check.
407 */
408#ifdef CONFIG_TICK_ONESHOT
Gautham R. Shenoyf9122ee2017-05-16 14:19:48 +0530409 else if (flags[i] & OPAL_PM_SLEEP_ENABLED ||
410 flags[i] & OPAL_PM_SLEEP_ENABLED_ER1) {
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530411 if (!rc)
412 target_residency = 300000;
Preeti U Murthy08888392014-02-26 05:39:20 +0530413 /* Add FASTSLEEP state */
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530414 add_powernv_state(nr_idle_states, "FastSleep",
415 CPUIDLE_FLAG_TIMER_STOP,
416 fastsleep_loop,
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530417 target_residency, exit_latency, 0, 0);
Gautham R. Shenoyf9122ee2017-05-16 14:19:48 +0530418 } else if (has_stop_states && stops_timebase) {
Gautham R. Shenoy9e9fc6f2017-01-25 14:06:27 +0530419 add_powernv_state(nr_idle_states, names[i],
420 CPUIDLE_FLAG_TIMER_STOP, stop_loop,
421 target_residency, exit_latency,
Gautham R. Shenoy09206b62017-01-25 14:06:28 +0530422 psscr_val[i], psscr_mask[i]);
Preeti U Murthy08888392014-02-26 05:39:20 +0530423 }
preeticc5a2f72015-06-24 01:48:01 -0500424#endif
Gautham R. Shenoyf9122ee2017-05-16 14:19:48 +0530425 else
426 continue;
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100427 nr_idle_states++;
Preeti U Murthy08888392014-02-26 05:39:20 +0530428 }
Preeti U Murthy92c83ff52015-02-18 06:34:17 +0100429out:
Preeti U Murthy08888392014-02-26 05:39:20 +0530430 return nr_idle_states;
431}
432
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530433/*
434 * powernv_idle_probe()
435 * Choose state table for shared versus dedicated partition
436 */
437static int powernv_idle_probe(void)
438{
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530439 if (cpuidle_disable != IDLE_NO_OVERRIDE)
440 return -ENODEV;
441
Stewart Smithe4d54f72015-12-09 17:18:20 +1100442 if (firmware_has_feature(FW_FEATURE_OPAL)) {
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530443 cpuidle_state_table = powernv_states;
Preeti U Murthy08888392014-02-26 05:39:20 +0530444 /* Device tree can indicate more idle states */
445 max_idle_state = powernv_add_idle_states();
Shilpasri G Bhat78eaa102015-06-18 16:53:11 +0530446 if (max_idle_state > 1) {
447 snooze_timeout_en = true;
448 snooze_timeout = powernv_states[1].target_residency *
449 tb_ticks_per_usec;
450 }
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530451 } else
452 return -ENODEV;
453
454 return 0;
455}
456
457static int __init powernv_processor_idle_init(void)
458{
459 int retval;
460
461 retval = powernv_idle_probe();
462 if (retval)
463 return retval;
464
465 powernv_cpuidle_driver_init();
466 retval = cpuidle_register(&powernv_idle_driver, NULL);
467 if (retval) {
468 printk(KERN_DEBUG "Registration of powernv driver failed.\n");
469 return retval;
470 }
471
Sebastian Andrzej Siewior10fcca92016-08-24 11:12:59 +0200472 retval = cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN,
473 "cpuidle/powernv:online",
474 powernv_cpuidle_cpu_online, NULL);
475 WARN_ON(retval < 0);
476 retval = cpuhp_setup_state_nocalls(CPUHP_CPUIDLE_DEAD,
477 "cpuidle/powernv:dead", NULL,
478 powernv_cpuidle_cpu_dead);
479 WARN_ON(retval < 0);
Deepthi Dharwar2c2e6ec2014-01-14 16:32:40 +0530480 printk(KERN_DEBUG "powernv_idle_driver registered\n");
481 return 0;
482}
483
484device_initcall(powernv_processor_idle_init);