xref: /linux/arch/powerpc/kernel/idle.c (revision 799fef06123f86ff69cf754f996219e6ad1678f8)
1a0652fc9SPaul Mackerras /*
2a0652fc9SPaul Mackerras  * Idle daemon for PowerPC.  Idle daemon will handle any action
3a0652fc9SPaul Mackerras  * that needs to be taken when the system becomes idle.
4a0652fc9SPaul Mackerras  *
5a0652fc9SPaul Mackerras  * Originally written by Cort Dougan (cort@cs.nmt.edu).
6a0652fc9SPaul Mackerras  * Subsequent 32-bit hacking by Tom Rini, Armin Kuster,
7a0652fc9SPaul Mackerras  * Paul Mackerras and others.
8a0652fc9SPaul Mackerras  *
9a0652fc9SPaul Mackerras  * iSeries supported added by Mike Corrigan <mikejc@us.ibm.com>
10a0652fc9SPaul Mackerras  *
11a0652fc9SPaul Mackerras  * Additional shared processor, SMT, and firmware support
12a0652fc9SPaul Mackerras  *    Copyright (c) 2003 Dave Engebretsen <engebret@us.ibm.com>
13a0652fc9SPaul Mackerras  *
14a0652fc9SPaul Mackerras  * 32-bit and 64-bit versions merged by Paul Mackerras <paulus@samba.org>
15a0652fc9SPaul Mackerras  *
16a0652fc9SPaul Mackerras  * This program is free software; you can redistribute it and/or
17a0652fc9SPaul Mackerras  * modify it under the terms of the GNU General Public License
18a0652fc9SPaul Mackerras  * as published by the Free Software Foundation; either version
19a0652fc9SPaul Mackerras  * 2 of the License, or (at your option) any later version.
20a0652fc9SPaul Mackerras  */
21a0652fc9SPaul Mackerras 
22a0652fc9SPaul Mackerras #include <linux/sched.h>
23a0652fc9SPaul Mackerras #include <linux/kernel.h>
24a0652fc9SPaul Mackerras #include <linux/smp.h>
25a0652fc9SPaul Mackerras #include <linux/cpu.h>
26a0652fc9SPaul Mackerras #include <linux/sysctl.h>
271ad74998STony Breeds #include <linux/tick.h>
28a0652fc9SPaul Mackerras 
29a0652fc9SPaul Mackerras #include <asm/processor.h>
30a0652fc9SPaul Mackerras #include <asm/cputable.h>
31a0652fc9SPaul Mackerras #include <asm/time.h>
32a0652fc9SPaul Mackerras #include <asm/machdep.h>
33ae3a197eSDavid Howells #include <asm/runlatch.h>
34a0652fc9SPaul Mackerras #include <asm/smp.h>
35a0652fc9SPaul Mackerras 
36a0652fc9SPaul Mackerras 
37771dae81SDeepthi Dharwar unsigned long cpuidle_disable = IDLE_NO_OVERRIDE;
38771dae81SDeepthi Dharwar EXPORT_SYMBOL(cpuidle_disable);
39771dae81SDeepthi Dharwar 
40302eca18Sarnd@arndb.de static int __init powersave_off(char *arg)
41302eca18Sarnd@arndb.de {
42302eca18Sarnd@arndb.de 	ppc_md.power_save = NULL;
43771dae81SDeepthi Dharwar 	cpuidle_disable = IDLE_POWERSAVE_OFF;
44302eca18Sarnd@arndb.de 	return 0;
45302eca18Sarnd@arndb.de }
46302eca18Sarnd@arndb.de __setup("powersave=off", powersave_off);
47302eca18Sarnd@arndb.de 
48*799fef06SThomas Gleixner #ifdef CONFIG_HOTPLUG_CPU
49*799fef06SThomas Gleixner void arch_cpu_idle_dead(void)
50a0652fc9SPaul Mackerras {
51*799fef06SThomas Gleixner 	sched_preempt_enable_no_resched();
52*799fef06SThomas Gleixner 	cpu_die();
53*799fef06SThomas Gleixner }
54*799fef06SThomas Gleixner #endif
551268fbc7SFrederic Weisbecker 
56*799fef06SThomas Gleixner void arch_cpu_idle(void)
57*799fef06SThomas Gleixner {
58a0652fc9SPaul Mackerras 	ppc64_runlatch_off();
59a0652fc9SPaul Mackerras 
60a0652fc9SPaul Mackerras 	if (ppc_md.power_save) {
61a0652fc9SPaul Mackerras 		ppc_md.power_save();
62*799fef06SThomas Gleixner 		/*
63*799fef06SThomas Gleixner 		 * Some power_save functions return with
647230c564SBenjamin Herrenschmidt 		 * interrupts enabled, some don't.
657230c564SBenjamin Herrenschmidt 		 */
667230c564SBenjamin Herrenschmidt 		if (irqs_disabled())
67a0652fc9SPaul Mackerras 			local_irq_enable();
68a0652fc9SPaul Mackerras 	} else {
69*799fef06SThomas Gleixner 		local_irq_enable();
70a0652fc9SPaul Mackerras 		/*
71a0652fc9SPaul Mackerras 		 * Go into low thread priority and possibly
72a0652fc9SPaul Mackerras 		 * low power mode.
73a0652fc9SPaul Mackerras 		 */
74a0652fc9SPaul Mackerras 		HMT_low();
75a0652fc9SPaul Mackerras 		HMT_very_low();
76a0652fc9SPaul Mackerras 	}
77a0652fc9SPaul Mackerras 
78a0652fc9SPaul Mackerras 	HMT_medium();
79a0652fc9SPaul Mackerras 	ppc64_runlatch_on();
80a0652fc9SPaul Mackerras }
81a0652fc9SPaul Mackerras 
82a0652fc9SPaul Mackerras int powersave_nap;
83a0652fc9SPaul Mackerras 
84a0652fc9SPaul Mackerras #ifdef CONFIG_SYSCTL
85a0652fc9SPaul Mackerras /*
86a0652fc9SPaul Mackerras  * Register the sysctl to set/clear powersave_nap.
87a0652fc9SPaul Mackerras  */
88a0652fc9SPaul Mackerras static ctl_table powersave_nap_ctl_table[]={
89a0652fc9SPaul Mackerras 	{
90a0652fc9SPaul Mackerras 		.procname	= "powersave-nap",
91a0652fc9SPaul Mackerras 		.data		= &powersave_nap,
92a0652fc9SPaul Mackerras 		.maxlen		= sizeof(int),
93a0652fc9SPaul Mackerras 		.mode		= 0644,
946d456111SEric W. Biederman 		.proc_handler	= proc_dointvec,
95a0652fc9SPaul Mackerras 	},
96f5f10678SEric W. Biederman 	{}
97a0652fc9SPaul Mackerras };
98a0652fc9SPaul Mackerras static ctl_table powersave_nap_sysctl_root[] = {
99f5f10678SEric W. Biederman 	{
100f5f10678SEric W. Biederman 		.procname	= "kernel",
101fb293ae1SAlexey Dobriyan 		.mode		= 0555,
102f5f10678SEric W. Biederman 		.child		= powersave_nap_ctl_table,
103f5f10678SEric W. Biederman 	},
104f5f10678SEric W. Biederman 	{}
105a0652fc9SPaul Mackerras };
106a0652fc9SPaul Mackerras 
107a0652fc9SPaul Mackerras static int __init
108a0652fc9SPaul Mackerras register_powersave_nap_sysctl(void)
109a0652fc9SPaul Mackerras {
1100b4d4147SEric W. Biederman 	register_sysctl_table(powersave_nap_sysctl_root);
111a0652fc9SPaul Mackerras 
112a0652fc9SPaul Mackerras 	return 0;
113a0652fc9SPaul Mackerras }
114a0652fc9SPaul Mackerras __initcall(register_powersave_nap_sysctl);
115a0652fc9SPaul Mackerras #endif
116