[PATCH] ppc64: xics cleanup
[pandora-kernel.git] / arch / ppc64 / kernel / idle.c
1 /*
2  * Idle daemon for PowerPC.  Idle daemon will handle any action
3  * that needs to be taken when the system becomes idle.
4  *
5  * Originally Written by Cort Dougan (cort@cs.nmt.edu)
6  *
7  * iSeries supported added by Mike Corrigan <mikejc@us.ibm.com>
8  *
9  * Additional shared processor, SMT, and firmware support
10  *    Copyright (c) 2003 Dave Engebretsen <engebret@us.ibm.com>
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version
15  * 2 of the License, or (at your option) any later version.
16  */
17
18 #include <linux/config.h>
19 #include <linux/sched.h>
20 #include <linux/kernel.h>
21 #include <linux/smp.h>
22 #include <linux/cpu.h>
23 #include <linux/sysctl.h>
24
25 #include <asm/system.h>
26 #include <asm/processor.h>
27 #include <asm/cputable.h>
28 #include <asm/time.h>
29 #include <asm/systemcfg.h>
30 #include <asm/machdep.h>
31
32 extern void power4_idle(void);
33
34 int default_idle(void)
35 {
36         long oldval;
37         unsigned int cpu = smp_processor_id();
38
39         while (1) {
40                 oldval = test_and_clear_thread_flag(TIF_NEED_RESCHED);
41
42                 if (!oldval) {
43                         set_thread_flag(TIF_POLLING_NRFLAG);
44
45                         while (!need_resched() && !cpu_is_offline(cpu)) {
46                                 ppc64_runlatch_off();
47
48                                 /*
49                                  * Go into low thread priority and possibly
50                                  * low power mode.
51                                  */
52                                 HMT_low();
53                                 HMT_very_low();
54                         }
55
56                         HMT_medium();
57                         clear_thread_flag(TIF_POLLING_NRFLAG);
58                 } else {
59                         set_need_resched();
60                 }
61
62                 ppc64_runlatch_on();
63                 schedule();
64                 if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING)
65                         cpu_die();
66         }
67
68         return 0;
69 }
70
71 int native_idle(void)
72 {
73         while (1) {
74                 ppc64_runlatch_off();
75
76                 if (!need_resched())
77                         power4_idle();
78
79                 if (need_resched()) {
80                         ppc64_runlatch_on();
81                         schedule();
82                 }
83
84                 if (cpu_is_offline(smp_processor_id()) &&
85                     system_state == SYSTEM_RUNNING)
86                         cpu_die();
87         }
88
89         return 0;
90 }
91
92 void cpu_idle(void)
93 {
94         BUG_ON(NULL == ppc_md.idle_loop);
95         ppc_md.idle_loop();
96 }
97
98 int powersave_nap;
99
100 #ifdef CONFIG_SYSCTL
101 /*
102  * Register the sysctl to set/clear powersave_nap.
103  */
104 static ctl_table powersave_nap_ctl_table[]={
105         {
106                 .ctl_name       = KERN_PPC_POWERSAVE_NAP,
107                 .procname       = "powersave-nap",
108                 .data           = &powersave_nap,
109                 .maxlen         = sizeof(int),
110                 .mode           = 0644,
111                 .proc_handler   = &proc_dointvec,
112         },
113         { 0, },
114 };
115 static ctl_table powersave_nap_sysctl_root[] = {
116         { 1, "kernel", NULL, 0, 0755, powersave_nap_ctl_table, },
117         { 0,},
118 };
119
120 static int __init
121 register_powersave_nap_sysctl(void)
122 {
123         register_sysctl_table(powersave_nap_sysctl_root, 0);
124
125         return 0;
126 }
127 __initcall(register_powersave_nap_sysctl);
128 #endif