1f1e58583SAtish Patra // SPDX-License-Identifier: GPL-2.0 2f1e58583SAtish Patra /* 3f1e58583SAtish Patra * Copyright (C) 2020 Western Digital Corporation or its affiliates. 4f1e58583SAtish Patra */ 5f1e58583SAtish Patra 6f1e58583SAtish Patra #include <linux/kernel.h> 7f1e58583SAtish Patra #include <linux/mm.h> 8f1e58583SAtish Patra #include <linux/sched.h> 9f1e58583SAtish Patra #include <linux/err.h> 10f1e58583SAtish Patra #include <linux/irq.h> 1172b11aa7SThomas Gleixner #include <linux/cpuhotplug.h> 12f1e58583SAtish Patra #include <linux/cpu.h> 13f1e58583SAtish Patra #include <linux/sched/hotplug.h> 14f1e58583SAtish Patra #include <asm/irq.h> 15f1e58583SAtish Patra #include <asm/cpu_ops.h> 16f40fe31cSPingfan Liu #include <asm/numa.h> 17832f15f4SAnup Patel #include <asm/smp.h> 18f1e58583SAtish Patra cpu_has_hotplug(unsigned int cpu)19f1e58583SAtish Patrabool cpu_has_hotplug(unsigned int cpu) 20f1e58583SAtish Patra { 2162ff2622SSamuel Holland if (cpu_ops->cpu_stop) 22f1e58583SAtish Patra return true; 23f1e58583SAtish Patra 24f1e58583SAtish Patra return false; 25f1e58583SAtish Patra } 26f1e58583SAtish Patra 27f1e58583SAtish Patra /* 28f1e58583SAtish Patra * __cpu_disable runs on the processor to be shutdown. 29f1e58583SAtish Patra */ __cpu_disable(void)30f1e58583SAtish Patraint __cpu_disable(void) 31f1e58583SAtish Patra { 32f1e58583SAtish Patra unsigned int cpu = smp_processor_id(); 33f1e58583SAtish Patra 3462ff2622SSamuel Holland if (!cpu_ops->cpu_stop) 35f1e58583SAtish Patra return -EOPNOTSUPP; 36f1e58583SAtish Patra 37f1e58583SAtish Patra remove_cpu_topology(cpu); 38f40fe31cSPingfan Liu numa_remove_cpu(cpu); 39f1e58583SAtish Patra set_cpu_online(cpu, false); 40832f15f4SAnup Patel riscv_ipi_disable(); 41f1e58583SAtish Patra irq_migrate_all_off_this_cpu(); 42f1e58583SAtish Patra 4379093f3eSSamuel Holland return 0; 44f1e58583SAtish Patra } 45f1e58583SAtish Patra 4672b11aa7SThomas Gleixner #ifdef CONFIG_HOTPLUG_CPU 47f1e58583SAtish Patra /* 4872b11aa7SThomas Gleixner * Called on the thread which is asking for a CPU to be shutdown, if the 4972b11aa7SThomas Gleixner * CPU reported dead to the hotplug core. 50f1e58583SAtish Patra */ arch_cpuhp_cleanup_dead_cpu(unsigned int cpu)5172b11aa7SThomas Gleixnervoid arch_cpuhp_cleanup_dead_cpu(unsigned int cpu) 52f1e58583SAtish Patra { 53f1e58583SAtish Patra int ret = 0; 54f1e58583SAtish Patra 55f1e58583SAtish Patra pr_notice("CPU%u: off\n", cpu); 56f1e58583SAtish Patra 57f1e58583SAtish Patra /* Verify from the firmware if the cpu is really stopped*/ 5862ff2622SSamuel Holland if (cpu_ops->cpu_is_stopped) 5962ff2622SSamuel Holland ret = cpu_ops->cpu_is_stopped(cpu); 60f1e58583SAtish Patra if (ret) 61*e0872ab7SWangYuli pr_warn("CPU%u may not have stopped: %d\n", cpu, ret); 62f1e58583SAtish Patra } 63f1e58583SAtish Patra 64f1e58583SAtish Patra /* 65f1e58583SAtish Patra * Called from the idle thread for the CPU which has been shutdown. 66f1e58583SAtish Patra */ arch_cpu_idle_dead(void)67071c44e4SJosh Poimboeufvoid __noreturn arch_cpu_idle_dead(void) 68f1e58583SAtish Patra { 69f1e58583SAtish Patra idle_task_exit(); 70f1e58583SAtish Patra 7172b11aa7SThomas Gleixner cpuhp_ap_report_dead(); 72f1e58583SAtish Patra 7362ff2622SSamuel Holland cpu_ops->cpu_stop(); 74f1e58583SAtish Patra /* It should never reach here */ 75f1e58583SAtish Patra BUG(); 76f1e58583SAtish Patra } 7772b11aa7SThomas Gleixner #endif 78