Merge tag 'sched-urgent-2020-12-27' of git://git.kernel.org/pub/scm/linux/kernel...
[linux/fpc-iii.git] / arch / riscv / kernel / cpu-hotplug.c
blobdf84e0c13db188c13e28eb11f2eaa79d539a5d01
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (C) 2020 Western Digital Corporation or its affiliates.
4 */
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/sbi.h>
17 void cpu_stop(void);
18 void arch_cpu_idle_dead(void)
20 cpu_stop();
23 bool cpu_has_hotplug(unsigned int cpu)
25 if (cpu_ops[cpu]->cpu_stop)
26 return true;
28 return false;
32 * __cpu_disable runs on the processor to be shutdown.
34 int __cpu_disable(void)
36 int ret = 0;
37 unsigned int cpu = smp_processor_id();
39 if (!cpu_ops[cpu] || !cpu_ops[cpu]->cpu_stop)
40 return -EOPNOTSUPP;
42 if (cpu_ops[cpu]->cpu_disable)
43 ret = cpu_ops[cpu]->cpu_disable(cpu);
45 if (ret)
46 return ret;
48 remove_cpu_topology(cpu);
49 set_cpu_online(cpu, false);
50 irq_migrate_all_off_this_cpu();
52 return ret;
56 * Called on the thread which is asking for a CPU to be shutdown.
58 void __cpu_die(unsigned int cpu)
60 int ret = 0;
62 if (!cpu_wait_death(cpu, 5)) {
63 pr_err("CPU %u: didn't die\n", cpu);
64 return;
66 pr_notice("CPU%u: off\n", cpu);
68 /* Verify from the firmware if the cpu is really stopped*/
69 if (cpu_ops[cpu]->cpu_is_stopped)
70 ret = cpu_ops[cpu]->cpu_is_stopped(cpu);
71 if (ret)
72 pr_warn("CPU%d may not have stopped: %d\n", cpu, ret);
76 * Called from the idle thread for the CPU which has been shutdown.
78 void cpu_stop(void)
80 idle_task_exit();
82 (void)cpu_report_death();
84 cpu_ops[smp_processor_id()]->cpu_stop();
85 /* It should never reach here */
86 BUG();