Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * 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 Mackerras | 3113997 | 2005-09-10 21:13:13 +1000 | [diff] [blame] | 25 | #include <linux/cpu.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 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> |
Paul Mackerras | 05f62a5 | 2005-10-06 13:29:24 +1000 | [diff] [blame] | 35 | #include <asm/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | void default_idle(void) |
| 38 | { |
| 39 | void (*powersave)(void); |
| 40 | |
| 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); |
Otavio Salvador | e13ac21 | 2006-01-06 00:11:26 -0800 | [diff] [blame] | 49 | while (!need_resched() && |
| 50 | !cpu_is_offline(smp_processor_id())) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | barrier(); |
| 52 | clear_thread_flag(TIF_POLLING_NRFLAG); |
| 53 | } |
| 54 | #endif |
| 55 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /* |
| 59 | * The body of the idle task. |
| 60 | */ |
| 61 | void cpu_idle(void) |
| 62 | { |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 63 | int cpu = smp_processor_id(); |
| 64 | |
| 65 | for (;;) { |
Andrew Morton | e4d76e1 | 2005-11-09 15:45:30 -0800 | [diff] [blame] | 66 | while (!need_resched()) { |
Nick Piggin | 64c7c8f | 2005-11-08 21:39:04 -0800 | [diff] [blame] | 67 | if (ppc_md.idle != NULL) |
| 68 | ppc_md.idle(); |
| 69 | else |
| 70 | default_idle(); |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Nick Piggin | 64c7c8f | 2005-11-08 21:39:04 -0800 | [diff] [blame] | 73 | if (cpu_is_offline(cpu) && system_state == SYSTEM_RUNNING) |
| 74 | cpu_die(); |
| 75 | preempt_enable_no_resched(); |
| 76 | schedule(); |
| 77 | preempt_disable(); |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 78 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | #if defined(CONFIG_SYSCTL) && defined(CONFIG_6xx) |
| 82 | /* |
| 83 | * Register the sysctl to set/clear powersave_nap. |
| 84 | */ |
Paul Mackerras | 17a6392 | 2005-10-20 21:10:09 +1000 | [diff] [blame] | 85 | extern int powersave_nap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
| 87 | static ctl_table powersave_nap_ctl_table[]={ |
| 88 | { |
| 89 | .ctl_name = KERN_PPC_POWERSAVE_NAP, |
| 90 | .procname = "powersave-nap", |
| 91 | .data = &powersave_nap, |
| 92 | .maxlen = sizeof(int), |
| 93 | .mode = 0644, |
| 94 | .proc_handler = &proc_dointvec, |
| 95 | }, |
| 96 | { 0, }, |
| 97 | }; |
| 98 | static ctl_table powersave_nap_sysctl_root[] = { |
| 99 | { 1, "kernel", NULL, 0, 0755, powersave_nap_ctl_table, }, |
| 100 | { 0,}, |
| 101 | }; |
| 102 | |
| 103 | static int __init |
| 104 | register_powersave_nap_sysctl(void) |
| 105 | { |
| 106 | register_sysctl_table(powersave_nap_sysctl_root, 0); |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
| 111 | __initcall(register_powersave_nap_sysctl); |
| 112 | #endif |