1*2874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 2a0652fc9SPaul Mackerras /* 3a0652fc9SPaul Mackerras * Idle daemon for PowerPC. Idle daemon will handle any action 4a0652fc9SPaul Mackerras * that needs to be taken when the system becomes idle. 5a0652fc9SPaul Mackerras * 6a0652fc9SPaul Mackerras * Originally written by Cort Dougan (cort@cs.nmt.edu). 7a0652fc9SPaul Mackerras * Subsequent 32-bit hacking by Tom Rini, Armin Kuster, 8a0652fc9SPaul Mackerras * Paul Mackerras and others. 9a0652fc9SPaul Mackerras * 10a0652fc9SPaul Mackerras * iSeries supported added by Mike Corrigan <mikejc@us.ibm.com> 11a0652fc9SPaul Mackerras * 12a0652fc9SPaul Mackerras * Additional shared processor, SMT, and firmware support 13a0652fc9SPaul Mackerras * Copyright (c) 2003 Dave Engebretsen <engebret@us.ibm.com> 14a0652fc9SPaul Mackerras * 15a0652fc9SPaul Mackerras * 32-bit and 64-bit versions merged by Paul Mackerras <paulus@samba.org> 16a0652fc9SPaul Mackerras */ 17a0652fc9SPaul Mackerras 18a0652fc9SPaul Mackerras #include <linux/sched.h> 19a0652fc9SPaul Mackerras #include <linux/kernel.h> 20a0652fc9SPaul Mackerras #include <linux/smp.h> 21a0652fc9SPaul Mackerras #include <linux/cpu.h> 22a0652fc9SPaul Mackerras #include <linux/sysctl.h> 231ad74998STony Breeds #include <linux/tick.h> 24a0652fc9SPaul Mackerras 25a0652fc9SPaul Mackerras #include <asm/processor.h> 26a0652fc9SPaul Mackerras #include <asm/cputable.h> 27a0652fc9SPaul Mackerras #include <asm/time.h> 28a0652fc9SPaul Mackerras #include <asm/machdep.h> 29ae3a197eSDavid Howells #include <asm/runlatch.h> 30a0652fc9SPaul Mackerras #include <asm/smp.h> 31a0652fc9SPaul Mackerras 32a0652fc9SPaul Mackerras 33771dae81SDeepthi Dharwar unsigned long cpuidle_disable = IDLE_NO_OVERRIDE; 34771dae81SDeepthi Dharwar EXPORT_SYMBOL(cpuidle_disable); 35771dae81SDeepthi Dharwar 36302eca18Sarnd@arndb.de static int __init powersave_off(char *arg) 37302eca18Sarnd@arndb.de { 38302eca18Sarnd@arndb.de ppc_md.power_save = NULL; 39771dae81SDeepthi Dharwar cpuidle_disable = IDLE_POWERSAVE_OFF; 40302eca18Sarnd@arndb.de return 0; 41302eca18Sarnd@arndb.de } 42302eca18Sarnd@arndb.de __setup("powersave=off", powersave_off); 43302eca18Sarnd@arndb.de 44799fef06SThomas Gleixner #ifdef CONFIG_HOTPLUG_CPU 45799fef06SThomas Gleixner void arch_cpu_idle_dead(void) 46a0652fc9SPaul Mackerras { 47799fef06SThomas Gleixner sched_preempt_enable_no_resched(); 48799fef06SThomas Gleixner cpu_die(); 49799fef06SThomas Gleixner } 50799fef06SThomas Gleixner #endif 511268fbc7SFrederic Weisbecker 52799fef06SThomas Gleixner void arch_cpu_idle(void) 53799fef06SThomas Gleixner { 54a0652fc9SPaul Mackerras ppc64_runlatch_off(); 55a0652fc9SPaul Mackerras 56a0652fc9SPaul Mackerras if (ppc_md.power_save) { 57a0652fc9SPaul Mackerras ppc_md.power_save(); 58799fef06SThomas Gleixner /* 59799fef06SThomas Gleixner * Some power_save functions return with 607230c564SBenjamin Herrenschmidt * interrupts enabled, some don't. 617230c564SBenjamin Herrenschmidt */ 627230c564SBenjamin Herrenschmidt if (irqs_disabled()) 63a0652fc9SPaul Mackerras local_irq_enable(); 64a0652fc9SPaul Mackerras } else { 65799fef06SThomas Gleixner local_irq_enable(); 66a0652fc9SPaul Mackerras /* 67a0652fc9SPaul Mackerras * Go into low thread priority and possibly 68a0652fc9SPaul Mackerras * low power mode. 69a0652fc9SPaul Mackerras */ 70a0652fc9SPaul Mackerras HMT_low(); 71a0652fc9SPaul Mackerras HMT_very_low(); 72a0652fc9SPaul Mackerras } 73a0652fc9SPaul Mackerras 74a0652fc9SPaul Mackerras HMT_medium(); 75a0652fc9SPaul Mackerras ppc64_runlatch_on(); 76a0652fc9SPaul Mackerras } 77a0652fc9SPaul Mackerras 78a0652fc9SPaul Mackerras int powersave_nap; 79a0652fc9SPaul Mackerras 80a0652fc9SPaul Mackerras #ifdef CONFIG_SYSCTL 81a0652fc9SPaul Mackerras /* 82a0652fc9SPaul Mackerras * Register the sysctl to set/clear powersave_nap. 83a0652fc9SPaul Mackerras */ 84cc293bf7SJoe Perches static struct ctl_table powersave_nap_ctl_table[] = { 85a0652fc9SPaul Mackerras { 86a0652fc9SPaul Mackerras .procname = "powersave-nap", 87a0652fc9SPaul Mackerras .data = &powersave_nap, 88a0652fc9SPaul Mackerras .maxlen = sizeof(int), 89a0652fc9SPaul Mackerras .mode = 0644, 906d456111SEric W. Biederman .proc_handler = proc_dointvec, 91a0652fc9SPaul Mackerras }, 92f5f10678SEric W. Biederman {} 93a0652fc9SPaul Mackerras }; 94cc293bf7SJoe Perches static struct ctl_table powersave_nap_sysctl_root[] = { 95f5f10678SEric W. Biederman { 96f5f10678SEric W. Biederman .procname = "kernel", 97fb293ae1SAlexey Dobriyan .mode = 0555, 98f5f10678SEric W. Biederman .child = powersave_nap_ctl_table, 99f5f10678SEric W. Biederman }, 100f5f10678SEric W. Biederman {} 101a0652fc9SPaul Mackerras }; 102a0652fc9SPaul Mackerras 103a0652fc9SPaul Mackerras static int __init 104a0652fc9SPaul Mackerras register_powersave_nap_sysctl(void) 105a0652fc9SPaul Mackerras { 1060b4d4147SEric W. Biederman register_sysctl_table(powersave_nap_sysctl_root); 107a0652fc9SPaul Mackerras 108a0652fc9SPaul Mackerras return 0; 109a0652fc9SPaul Mackerras } 110a0652fc9SPaul Mackerras __initcall(register_powersave_nap_sysctl); 111a0652fc9SPaul Mackerras #endif 112