fix a kmap leak in virtio_console
[linux/fpc-iii.git] / drivers / cpuidle / cpuidle-powernv.c
blob78fd174c57e86dfb4608a12f4af44d334ab1da7c
1 /*
2 * cpuidle-powernv - idle state cpuidle driver.
3 * Adapted from drivers/cpuidle/cpuidle-pseries
5 */
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>
15 #include <asm/machdep.h>
16 #include <asm/firmware.h>
18 struct cpuidle_driver powernv_idle_driver = {
19 .name = "powernv_idle",
20 .owner = THIS_MODULE,
23 static int max_idle_state;
24 static struct cpuidle_state *cpuidle_state_table;
26 static int snooze_loop(struct cpuidle_device *dev,
27 struct cpuidle_driver *drv,
28 int index)
30 local_irq_enable();
31 set_thread_flag(TIF_POLLING_NRFLAG);
33 while (!need_resched()) {
34 HMT_low();
35 HMT_very_low();
38 HMT_medium();
39 clear_thread_flag(TIF_POLLING_NRFLAG);
40 smp_mb();
41 return index;
44 static int nap_loop(struct cpuidle_device *dev,
45 struct cpuidle_driver *drv,
46 int index)
48 power7_idle();
49 return index;
53 * States for dedicated partition case.
55 static struct cpuidle_state powernv_states[] = {
56 { /* Snooze */
57 .name = "snooze",
58 .desc = "snooze",
59 .flags = CPUIDLE_FLAG_TIME_VALID,
60 .exit_latency = 0,
61 .target_residency = 0,
62 .enter = &snooze_loop },
63 { /* NAP */
64 .name = "NAP",
65 .desc = "NAP",
66 .flags = CPUIDLE_FLAG_TIME_VALID,
67 .exit_latency = 10,
68 .target_residency = 100,
69 .enter = &nap_loop },
72 static int powernv_cpuidle_add_cpu_notifier(struct notifier_block *n,
73 unsigned long action, void *hcpu)
75 int hotcpu = (unsigned long)hcpu;
76 struct cpuidle_device *dev =
77 per_cpu(cpuidle_devices, hotcpu);
79 if (dev && cpuidle_get_driver()) {
80 switch (action) {
81 case CPU_ONLINE:
82 case CPU_ONLINE_FROZEN:
83 cpuidle_pause_and_lock();
84 cpuidle_enable_device(dev);
85 cpuidle_resume_and_unlock();
86 break;
88 case CPU_DEAD:
89 case CPU_DEAD_FROZEN:
90 cpuidle_pause_and_lock();
91 cpuidle_disable_device(dev);
92 cpuidle_resume_and_unlock();
93 break;
95 default:
96 return NOTIFY_DONE;
99 return NOTIFY_OK;
102 static struct notifier_block setup_hotplug_notifier = {
103 .notifier_call = powernv_cpuidle_add_cpu_notifier,
107 * powernv_cpuidle_driver_init()
109 static int powernv_cpuidle_driver_init(void)
111 int idle_state;
112 struct cpuidle_driver *drv = &powernv_idle_driver;
114 drv->state_count = 0;
116 for (idle_state = 0; idle_state < max_idle_state; ++idle_state) {
117 /* Is the state not enabled? */
118 if (cpuidle_state_table[idle_state].enter == NULL)
119 continue;
121 drv->states[drv->state_count] = /* structure copy */
122 cpuidle_state_table[idle_state];
124 drv->state_count += 1;
127 return 0;
131 * powernv_idle_probe()
132 * Choose state table for shared versus dedicated partition
134 static int powernv_idle_probe(void)
137 if (cpuidle_disable != IDLE_NO_OVERRIDE)
138 return -ENODEV;
140 if (firmware_has_feature(FW_FEATURE_OPALv3)) {
141 cpuidle_state_table = powernv_states;
142 max_idle_state = ARRAY_SIZE(powernv_states);
143 } else
144 return -ENODEV;
146 return 0;
149 static int __init powernv_processor_idle_init(void)
151 int retval;
153 retval = powernv_idle_probe();
154 if (retval)
155 return retval;
157 powernv_cpuidle_driver_init();
158 retval = cpuidle_register(&powernv_idle_driver, NULL);
159 if (retval) {
160 printk(KERN_DEBUG "Registration of powernv driver failed.\n");
161 return retval;
164 register_cpu_notifier(&setup_hotplug_notifier);
165 printk(KERN_DEBUG "powernv_idle_driver registered\n");
166 return 0;
169 device_initcall(powernv_processor_idle_init);