blob: fba29c876b62ab843d06e308ef2590c9f3999f85 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Idle daemon for PowerPC. Idle daemon will handle any action
3 * that needs to be taken when the system becomes idle.
4 *
5 * Written by Cort Dougan (cort@cs.nmt.edu). Subsequently hacked
6 * on by Tom Rini, Armin Kuster, Paul Mackerras and others.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
12 */
13#include <linux/config.h>
14#include <linux/errno.h>
15#include <linux/sched.h>
16#include <linux/kernel.h>
17#include <linux/mm.h>
18#include <linux/smp.h>
19#include <linux/smp_lock.h>
20#include <linux/stddef.h>
21#include <linux/unistd.h>
22#include <linux/ptrace.h>
23#include <linux/slab.h>
24#include <linux/sysctl.h>
Paul Mackerras31139972005-09-10 21:13:13 +100025#include <linux/cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27#include <asm/pgtable.h>
28#include <asm/uaccess.h>
29#include <asm/system.h>
30#include <asm/io.h>
31#include <asm/mmu.h>
32#include <asm/cache.h>
33#include <asm/cputable.h>
34#include <asm/machdep.h>
35
36void default_idle(void)
37{
38 void (*powersave)(void);
Paul Mackerras31139972005-09-10 21:13:13 +100039 int cpu = smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41 powersave = ppc_md.power_save;
42
43 if (!need_resched()) {
44 if (powersave != NULL)
45 powersave();
46#ifdef CONFIG_SMP
47 else {
48 set_thread_flag(TIF_POLLING_NRFLAG);
Paul Mackerras31139972005-09-10 21:13:13 +100049 while (!need_resched() && !cpu_is_offline(cpu))
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 barrier();
51 clear_thread_flag(TIF_POLLING_NRFLAG);
52 }
53#endif
54 }
55 if (need_resched())
56 schedule();
Paul Mackerras31139972005-09-10 21:13:13 +100057 if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
58 cpu_die();
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
61/*
62 * The body of the idle task.
63 */
64void cpu_idle(void)
65{
66 for (;;)
67 if (ppc_md.idle != NULL)
68 ppc_md.idle();
69 else
70 default_idle();
71}
72
73#if defined(CONFIG_SYSCTL) && defined(CONFIG_6xx)
74/*
75 * Register the sysctl to set/clear powersave_nap.
76 */
77extern unsigned long powersave_nap;
78
79static ctl_table powersave_nap_ctl_table[]={
80 {
81 .ctl_name = KERN_PPC_POWERSAVE_NAP,
82 .procname = "powersave-nap",
83 .data = &powersave_nap,
84 .maxlen = sizeof(int),
85 .mode = 0644,
86 .proc_handler = &proc_dointvec,
87 },
88 { 0, },
89};
90static ctl_table powersave_nap_sysctl_root[] = {
91 { 1, "kernel", NULL, 0, 0755, powersave_nap_ctl_table, },
92 { 0,},
93};
94
95static int __init
96register_powersave_nap_sysctl(void)
97{
98 register_sysctl_table(powersave_nap_sysctl_root, 0);
99
100 return 0;
101}
102
103__initcall(register_powersave_nap_sysctl);
104#endif