Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Idle daemon for PowerPC. Idle daemon will handle any action |
| 4 | * that needs to be taken when the system becomes idle. |
| 5 | * |
Paul Mackerras | a0652fc | 2006-03-27 15:03:03 +1100 | [diff] [blame] | 6 | * Originally written by Cort Dougan (cort@cs.nmt.edu). |
| 7 | * Subsequent 32-bit hacking by Tom Rini, Armin Kuster, |
| 8 | * Paul Mackerras and others. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * iSeries supported added by Mike Corrigan <mikejc@us.ibm.com> |
| 11 | * |
| 12 | * Additional shared processor, SMT, and firmware support |
| 13 | * Copyright (c) 2003 Dave Engebretsen <engebret@us.ibm.com> |
| 14 | * |
Paul Mackerras | a0652fc | 2006-03-27 15:03:03 +1100 | [diff] [blame] | 15 | * 32-bit and 64-bit versions merged by Paul Mackerras <paulus@samba.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/sched.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/smp.h> |
| 21 | #include <linux/cpu.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/sysctl.h> |
Tony Breeds | 1ad7499 | 2007-09-21 13:26:03 +1000 | [diff] [blame] | 23 | #include <linux/tick.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/cputable.h> |
| 27 | #include <asm/time.h> |
Michael Ellerman | fd899c0 | 2005-07-07 17:56:28 -0700 | [diff] [blame] | 28 | #include <asm/machdep.h> |
David Howells | ae3a197 | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 29 | #include <asm/runlatch.h> |
Paul Mackerras | 2249ca9 | 2005-11-07 13:18:13 +1100 | [diff] [blame] | 30 | #include <asm/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Deepthi Dharwar | 771dae8 | 2011-11-30 02:46:31 +0000 | [diff] [blame] | 33 | unsigned long cpuidle_disable = IDLE_NO_OVERRIDE; |
| 34 | EXPORT_SYMBOL(cpuidle_disable); |
| 35 | |
arnd@arndb.de | 302eca1 | 2006-10-24 18:31:26 +0200 | [diff] [blame] | 36 | static int __init powersave_off(char *arg) |
| 37 | { |
| 38 | ppc_md.power_save = NULL; |
Deepthi Dharwar | 771dae8 | 2011-11-30 02:46:31 +0000 | [diff] [blame] | 39 | cpuidle_disable = IDLE_POWERSAVE_OFF; |
arnd@arndb.de | 302eca1 | 2006-10-24 18:31:26 +0200 | [diff] [blame] | 40 | return 0; |
| 41 | } |
| 42 | __setup("powersave=off", powersave_off); |
| 43 | |
Thomas Gleixner | 799fef0 | 2013-03-21 22:49:56 +0100 | [diff] [blame] | 44 | #ifdef CONFIG_HOTPLUG_CPU |
| 45 | void arch_cpu_idle_dead(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { |
Thomas Gleixner | 799fef0 | 2013-03-21 22:49:56 +0100 | [diff] [blame] | 47 | sched_preempt_enable_no_resched(); |
| 48 | cpu_die(); |
| 49 | } |
| 50 | #endif |
Frederic Weisbecker | 1268fbc | 2011-11-17 18:48:14 +0100 | [diff] [blame] | 51 | |
Thomas Gleixner | 799fef0 | 2013-03-21 22:49:56 +0100 | [diff] [blame] | 52 | void arch_cpu_idle(void) |
| 53 | { |
| 54 | ppc64_runlatch_off(); |
Anton Blanchard | ddafddc | 2006-04-02 19:54:09 +1000 | [diff] [blame] | 55 | |
Thomas Gleixner | 799fef0 | 2013-03-21 22:49:56 +0100 | [diff] [blame] | 56 | if (ppc_md.power_save) { |
| 57 | ppc_md.power_save(); |
| 58 | /* |
| 59 | * Some power_save functions return with |
| 60 | * interrupts enabled, some don't. |
| 61 | */ |
| 62 | if (irqs_disabled()) |
| 63 | local_irq_enable(); |
| 64 | } else { |
| 65 | local_irq_enable(); |
| 66 | /* |
| 67 | * Go into low thread priority and possibly |
| 68 | * low power mode. |
| 69 | */ |
| 70 | HMT_low(); |
| 71 | HMT_very_low(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | } |
Thomas Gleixner | 799fef0 | 2013-03-21 22:49:56 +0100 | [diff] [blame] | 73 | |
| 74 | HMT_medium(); |
| 75 | ppc64_runlatch_on(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | int powersave_nap; |
| 79 | |
| 80 | #ifdef CONFIG_SYSCTL |
| 81 | /* |
| 82 | * Register the sysctl to set/clear powersave_nap. |
| 83 | */ |
Joe Perches | cc293bf | 2013-06-13 19:37:30 -0700 | [diff] [blame] | 84 | static struct ctl_table powersave_nap_ctl_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | .procname = "powersave-nap", |
| 87 | .data = &powersave_nap, |
| 88 | .maxlen = sizeof(int), |
| 89 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 90 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | }, |
Eric W. Biederman | f5f1067 | 2007-02-14 00:33:46 -0800 | [diff] [blame] | 92 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | }; |
Joe Perches | cc293bf | 2013-06-13 19:37:30 -0700 | [diff] [blame] | 94 | static struct ctl_table powersave_nap_sysctl_root[] = { |
Eric W. Biederman | f5f1067 | 2007-02-14 00:33:46 -0800 | [diff] [blame] | 95 | { |
Eric W. Biederman | f5f1067 | 2007-02-14 00:33:46 -0800 | [diff] [blame] | 96 | .procname = "kernel", |
Alexey Dobriyan | fb293ae | 2007-10-28 05:34:53 +1100 | [diff] [blame] | 97 | .mode = 0555, |
Eric W. Biederman | f5f1067 | 2007-02-14 00:33:46 -0800 | [diff] [blame] | 98 | .child = powersave_nap_ctl_table, |
| 99 | }, |
| 100 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | static int __init |
| 104 | register_powersave_nap_sysctl(void) |
| 105 | { |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 106 | register_sysctl_table(powersave_nap_sysctl_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | __initcall(register_powersave_nap_sysctl); |
| 111 | #endif |