1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Copyright (C) 2020 Western Digital Corporation or its affiliates. 4 */ 5 6 #include <linux/kernel.h> 7 #include <linux/mm.h> 8 #include <linux/sched.h> 9 #include <linux/err.h> 10 #include <linux/irq.h> 11 #include <linux/cpu.h> 12 #include <linux/sched/hotplug.h> 13 #include <asm/irq.h> 14 #include <asm/cpu_ops.h> 15 #include <asm/numa.h> 16 #include <asm/sbi.h> 17 18 void cpu_stop(void); arch_cpu_idle_dead(void)19void arch_cpu_idle_dead(void) 20 { 21 cpu_stop(); 22 } 23 cpu_has_hotplug(unsigned int cpu)24bool cpu_has_hotplug(unsigned int cpu) 25 { 26 if (cpu_ops[cpu]->cpu_stop) 27 return true; 28 29 return false; 30 } 31 32 /* 33 * __cpu_disable runs on the processor to be shutdown. 34 */ __cpu_disable(void)35int __cpu_disable(void) 36 { 37 int ret = 0; 38 unsigned int cpu = smp_processor_id(); 39 40 if (!cpu_ops[cpu] || !cpu_ops[cpu]->cpu_stop) 41 return -EOPNOTSUPP; 42 43 if (cpu_ops[cpu]->cpu_disable) 44 ret = cpu_ops[cpu]->cpu_disable(cpu); 45 46 if (ret) 47 return ret; 48 49 remove_cpu_topology(cpu); 50 numa_remove_cpu(cpu); 51 set_cpu_online(cpu, false); 52 irq_migrate_all_off_this_cpu(); 53 54 return ret; 55 } 56 57 /* 58 * Called on the thread which is asking for a CPU to be shutdown. 59 */ __cpu_die(unsigned int cpu)60void __cpu_die(unsigned int cpu) 61 { 62 int ret = 0; 63 64 if (!cpu_wait_death(cpu, 5)) { 65 pr_err("CPU %u: didn't die\n", cpu); 66 return; 67 } 68 pr_notice("CPU%u: off\n", cpu); 69 70 /* Verify from the firmware if the cpu is really stopped*/ 71 if (cpu_ops[cpu]->cpu_is_stopped) 72 ret = cpu_ops[cpu]->cpu_is_stopped(cpu); 73 if (ret) 74 pr_warn("CPU%d may not have stopped: %d\n", cpu, ret); 75 } 76 77 /* 78 * Called from the idle thread for the CPU which has been shutdown. 79 */ cpu_stop(void)80void cpu_stop(void) 81 { 82 idle_task_exit(); 83 84 (void)cpu_report_death(); 85 86 cpu_ops[smp_processor_id()]->cpu_stop(); 87 /* It should never reach here */ 88 BUG(); 89 } 90