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 | void arch_cpu_idle(void) |
| 45 | { |
| 46 | ppc64_runlatch_off(); |
Anton Blanchard | ddafddc | 2006-04-02 19:54:09 +1000 | [diff] [blame] | 47 | |
Thomas Gleixner | 799fef0 | 2013-03-21 22:49:56 +0100 | [diff] [blame] | 48 | if (ppc_md.power_save) { |
| 49 | ppc_md.power_save(); |
| 50 | /* |
| 51 | * Some power_save functions return with |
| 52 | * interrupts enabled, some don't. |
| 53 | */ |
| 54 | if (irqs_disabled()) |
Peter Zijlstra | 58c644b | 2020-11-20 11:50:35 +0100 | [diff] [blame] | 55 | raw_local_irq_enable(); |
Thomas Gleixner | 799fef0 | 2013-03-21 22:49:56 +0100 | [diff] [blame] | 56 | } else { |
Peter Zijlstra | 58c644b | 2020-11-20 11:50:35 +0100 | [diff] [blame] | 57 | raw_local_irq_enable(); |
Thomas Gleixner | 799fef0 | 2013-03-21 22:49:56 +0100 | [diff] [blame] | 58 | /* |
| 59 | * Go into low thread priority and possibly |
| 60 | * low power mode. |
| 61 | */ |
| 62 | HMT_low(); |
| 63 | HMT_very_low(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
Thomas Gleixner | 799fef0 | 2013-03-21 22:49:56 +0100 | [diff] [blame] | 65 | |
| 66 | HMT_medium(); |
| 67 | ppc64_runlatch_on(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | int powersave_nap; |
| 71 | |
Nicholas Piggin | ed0bc98 | 2019-07-11 12:24:03 +1000 | [diff] [blame] | 72 | #ifdef CONFIG_PPC_970_NAP |
| 73 | void power4_idle(void) |
| 74 | { |
| 75 | if (!cpu_has_feature(CPU_FTR_CAN_NAP)) |
| 76 | return; |
| 77 | |
| 78 | if (!powersave_nap) |
| 79 | return; |
| 80 | |
| 81 | if (!prep_irq_for_idle()) |
| 82 | return; |
| 83 | |
| 84 | if (cpu_has_feature(CPU_FTR_ALTIVEC)) |
| 85 | asm volatile("DSSALL ; sync" ::: "memory"); |
| 86 | |
| 87 | power4_idle_nap(); |
| 88 | |
| 89 | /* |
| 90 | * power4_idle_nap returns with interrupts enabled (soft and hard). |
| 91 | * to our caller with interrupts enabled (soft and hard). Our caller |
| 92 | * can cope with either interrupts disabled or enabled upon return. |
| 93 | */ |
| 94 | } |
| 95 | #endif |
| 96 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | #ifdef CONFIG_SYSCTL |
| 98 | /* |
| 99 | * Register the sysctl to set/clear powersave_nap. |
| 100 | */ |
Joe Perches | cc293bf | 2013-06-13 19:37:30 -0700 | [diff] [blame] | 101 | static struct ctl_table powersave_nap_ctl_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | .procname = "powersave-nap", |
| 104 | .data = &powersave_nap, |
| 105 | .maxlen = sizeof(int), |
| 106 | .mode = 0644, |
Eric W. Biederman | 6d45611 | 2009-11-16 03:11:48 -0800 | [diff] [blame] | 107 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | }, |
Eric W. Biederman | f5f1067 | 2007-02-14 00:33:46 -0800 | [diff] [blame] | 109 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | }; |
Joe Perches | cc293bf | 2013-06-13 19:37:30 -0700 | [diff] [blame] | 111 | static struct ctl_table powersave_nap_sysctl_root[] = { |
Eric W. Biederman | f5f1067 | 2007-02-14 00:33:46 -0800 | [diff] [blame] | 112 | { |
Eric W. Biederman | f5f1067 | 2007-02-14 00:33:46 -0800 | [diff] [blame] | 113 | .procname = "kernel", |
Alexey Dobriyan | fb293ae | 2007-10-28 05:34:53 +1100 | [diff] [blame] | 114 | .mode = 0555, |
Eric W. Biederman | f5f1067 | 2007-02-14 00:33:46 -0800 | [diff] [blame] | 115 | .child = powersave_nap_ctl_table, |
| 116 | }, |
| 117 | {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | static int __init |
| 121 | register_powersave_nap_sysctl(void) |
| 122 | { |
Eric W. Biederman | 0b4d414 | 2007-02-14 00:34:09 -0800 | [diff] [blame] | 123 | register_sysctl_table(powersave_nap_sysctl_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | __initcall(register_powersave_nap_sysctl); |
| 128 | #endif |