12874c5fdSThomas 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; 40b793a010SRandy Dunlap return 1; 41302eca18Sarnd@arndb.de } 42302eca18Sarnd@arndb.de __setup("powersave=off", powersave_off); 43302eca18Sarnd@arndb.de 44799fef06SThomas Gleixner void arch_cpu_idle(void) 45799fef06SThomas Gleixner { 46a0652fc9SPaul Mackerras ppc64_runlatch_off(); 47a0652fc9SPaul Mackerras 48a0652fc9SPaul Mackerras if (ppc_md.power_save) { 49a0652fc9SPaul Mackerras ppc_md.power_save(); 50799fef06SThomas Gleixner /* 51799fef06SThomas Gleixner * Some power_save functions return with 527230c564SBenjamin Herrenschmidt * interrupts enabled, some don't. 537230c564SBenjamin Herrenschmidt */ 5489b30987SPeter Zijlstra if (!irqs_disabled()) 5589b30987SPeter Zijlstra raw_local_irq_disable(); 56a0652fc9SPaul Mackerras } else { 57a0652fc9SPaul Mackerras /* 58a0652fc9SPaul Mackerras * Go into low thread priority and possibly 59a0652fc9SPaul Mackerras * low power mode. 60a0652fc9SPaul Mackerras */ 61a0652fc9SPaul Mackerras HMT_low(); 62a0652fc9SPaul Mackerras HMT_very_low(); 63a0652fc9SPaul Mackerras } 64a0652fc9SPaul Mackerras 65a0652fc9SPaul Mackerras HMT_medium(); 66a0652fc9SPaul Mackerras ppc64_runlatch_on(); 67a0652fc9SPaul Mackerras } 68a0652fc9SPaul Mackerras 69a0652fc9SPaul Mackerras int powersave_nap; 70a0652fc9SPaul Mackerras 71ed0bc98fSNicholas Piggin #ifdef CONFIG_PPC_970_NAP 72ed0bc98fSNicholas Piggin void power4_idle(void) 73ed0bc98fSNicholas Piggin { 74ed0bc98fSNicholas Piggin if (!cpu_has_feature(CPU_FTR_CAN_NAP)) 75ed0bc98fSNicholas Piggin return; 76ed0bc98fSNicholas Piggin 77ed0bc98fSNicholas Piggin if (!powersave_nap) 78ed0bc98fSNicholas Piggin return; 79ed0bc98fSNicholas Piggin 80ed0bc98fSNicholas Piggin if (!prep_irq_for_idle()) 81ed0bc98fSNicholas Piggin return; 82ed0bc98fSNicholas Piggin 83ed0bc98fSNicholas Piggin if (cpu_has_feature(CPU_FTR_ALTIVEC)) 84d51f86cfSAlexey Kardashevskiy asm volatile(PPC_DSSALL " ; sync" ::: "memory"); 85ed0bc98fSNicholas Piggin 86ed0bc98fSNicholas Piggin power4_idle_nap(); 87ed0bc98fSNicholas Piggin 88ed0bc98fSNicholas Piggin /* 89ed0bc98fSNicholas Piggin * power4_idle_nap returns with interrupts enabled (soft and hard). 90ed0bc98fSNicholas Piggin * to our caller with interrupts enabled (soft and hard). Our caller 91ed0bc98fSNicholas Piggin * can cope with either interrupts disabled or enabled upon return. 92ed0bc98fSNicholas Piggin */ 93ed0bc98fSNicholas Piggin } 94ed0bc98fSNicholas Piggin #endif 95ed0bc98fSNicholas Piggin 96a0652fc9SPaul Mackerras #ifdef CONFIG_SYSCTL 97a0652fc9SPaul Mackerras /* 98a0652fc9SPaul Mackerras * Register the sysctl to set/clear powersave_nap. 99a0652fc9SPaul Mackerras */ 100cc293bf7SJoe Perches static struct ctl_table powersave_nap_ctl_table[] = { 101a0652fc9SPaul Mackerras { 102a0652fc9SPaul Mackerras .procname = "powersave-nap", 103a0652fc9SPaul Mackerras .data = &powersave_nap, 104a0652fc9SPaul Mackerras .maxlen = sizeof(int), 105a0652fc9SPaul Mackerras .mode = 0644, 1066d456111SEric W. Biederman .proc_handler = proc_dointvec, 107a0652fc9SPaul Mackerras }, 108f5f10678SEric W. Biederman {} 109a0652fc9SPaul Mackerras }; 110a0652fc9SPaul Mackerras 111a0652fc9SPaul Mackerras static int __init 112a0652fc9SPaul Mackerras register_powersave_nap_sysctl(void) 113a0652fc9SPaul Mackerras { 114*bfedee5dSLuis Chamberlain register_sysctl("kernel", powersave_nap_ctl_table); 115a0652fc9SPaul Mackerras 116a0652fc9SPaul Mackerras return 0; 117a0652fc9SPaul Mackerras } 118a0652fc9SPaul Mackerras __initcall(register_powersave_nap_sysctl); 119a0652fc9SPaul Mackerras #endif 120