blob: f7a832e3a1d1d44f0568a5f7336eb587092d85a0 [file] [log] [blame]
Atish Patraf1e58582020-03-17 18:11:44 -07001// 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>
Pingfan Liuf40fe312022-01-23 20:13:52 +080015#include <asm/numa.h>
Atish Patraf1e58582020-03-17 18:11:44 -070016#include <asm/sbi.h>
17
Atish Patraf1e58582020-03-17 18:11:44 -070018bool cpu_has_hotplug(unsigned int cpu)
19{
20 if (cpu_ops[cpu]->cpu_stop)
21 return true;
22
23 return false;
24}
25
26/*
27 * __cpu_disable runs on the processor to be shutdown.
28 */
29int __cpu_disable(void)
30{
31 int ret = 0;
32 unsigned int cpu = smp_processor_id();
33
34 if (!cpu_ops[cpu] || !cpu_ops[cpu]->cpu_stop)
35 return -EOPNOTSUPP;
36
37 if (cpu_ops[cpu]->cpu_disable)
38 ret = cpu_ops[cpu]->cpu_disable(cpu);
39
40 if (ret)
41 return ret;
42
43 remove_cpu_topology(cpu);
Pingfan Liuf40fe312022-01-23 20:13:52 +080044 numa_remove_cpu(cpu);
Atish Patraf1e58582020-03-17 18:11:44 -070045 set_cpu_online(cpu, false);
46 irq_migrate_all_off_this_cpu();
47
48 return ret;
49}
50
51/*
52 * Called on the thread which is asking for a CPU to be shutdown.
53 */
54void __cpu_die(unsigned int cpu)
55{
56 int ret = 0;
57
58 if (!cpu_wait_death(cpu, 5)) {
59 pr_err("CPU %u: didn't die\n", cpu);
60 return;
61 }
62 pr_notice("CPU%u: off\n", cpu);
63
64 /* Verify from the firmware if the cpu is really stopped*/
65 if (cpu_ops[cpu]->cpu_is_stopped)
66 ret = cpu_ops[cpu]->cpu_is_stopped(cpu);
67 if (ret)
68 pr_warn("CPU%d may not have stopped: %d\n", cpu, ret);
69}
70
71/*
72 * Called from the idle thread for the CPU which has been shutdown.
73 */
Jisheng Zhang7f3de1a2021-11-29 00:07:37 +080074void arch_cpu_idle_dead(void)
Atish Patraf1e58582020-03-17 18:11:44 -070075{
76 idle_task_exit();
77
78 (void)cpu_report_death();
79
80 cpu_ops[smp_processor_id()]->cpu_stop();
81 /* It should never reach here */
82 BUG();
83}