2020-03-17 18:11:44 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Western Digital Corporation or its affiliates.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/irq.h>
|
2023-05-12 14:07:40 -07:00
|
|
|
#include <linux/cpuhotplug.h>
|
2020-03-17 18:11:44 -07:00
|
|
|
#include <linux/cpu.h>
|
|
|
|
#include <linux/sched/hotplug.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
#include <asm/cpu_ops.h>
|
2022-01-23 05:13:52 -07:00
|
|
|
#include <asm/numa.h>
|
2023-03-27 20:52:19 -07:00
|
|
|
#include <asm/smp.h>
|
2020-03-17 18:11:44 -07:00
|
|
|
|
|
|
|
bool cpu_has_hotplug(unsigned int cpu)
|
|
|
|
{
|
2023-11-21 16:47:26 -07:00
|
|
|
if (cpu_ops->cpu_stop)
|
2020-03-17 18:11:44 -07:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* __cpu_disable runs on the processor to be shutdown.
|
|
|
|
*/
|
|
|
|
int __cpu_disable(void)
|
|
|
|
{
|
|
|
|
unsigned int cpu = smp_processor_id();
|
|
|
|
|
2023-11-21 16:47:26 -07:00
|
|
|
if (!cpu_ops->cpu_stop)
|
2020-03-17 18:11:44 -07:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
remove_cpu_topology(cpu);
|
2022-01-23 05:13:52 -07:00
|
|
|
numa_remove_cpu(cpu);
|
2020-03-17 18:11:44 -07:00
|
|
|
set_cpu_online(cpu, false);
|
2023-03-27 20:52:19 -07:00
|
|
|
riscv_ipi_disable();
|
2020-03-17 18:11:44 -07:00
|
|
|
irq_migrate_all_off_this_cpu();
|
|
|
|
|
2023-11-21 16:47:25 -07:00
|
|
|
return 0;
|
2020-03-17 18:11:44 -07:00
|
|
|
}
|
|
|
|
|
2023-05-12 14:07:40 -07:00
|
|
|
#ifdef CONFIG_HOTPLUG_CPU
|
2020-03-17 18:11:44 -07:00
|
|
|
/*
|
2023-05-12 14:07:40 -07:00
|
|
|
* Called on the thread which is asking for a CPU to be shutdown, if the
|
|
|
|
* CPU reported dead to the hotplug core.
|
2020-03-17 18:11:44 -07:00
|
|
|
*/
|
2023-05-12 14:07:40 -07:00
|
|
|
void arch_cpuhp_cleanup_dead_cpu(unsigned int cpu)
|
2020-03-17 18:11:44 -07:00
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
pr_notice("CPU%u: off\n", cpu);
|
|
|
|
|
|
|
|
/* Verify from the firmware if the cpu is really stopped*/
|
2023-11-21 16:47:26 -07:00
|
|
|
if (cpu_ops->cpu_is_stopped)
|
|
|
|
ret = cpu_ops->cpu_is_stopped(cpu);
|
2020-03-17 18:11:44 -07:00
|
|
|
if (ret)
|
2024-10-16 20:20:10 -07:00
|
|
|
pr_warn("CPU%u may not have stopped: %d\n", cpu, ret);
|
2020-03-17 18:11:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called from the idle thread for the CPU which has been shutdown.
|
|
|
|
*/
|
2023-02-14 00:05:58 -07:00
|
|
|
void __noreturn arch_cpu_idle_dead(void)
|
2020-03-17 18:11:44 -07:00
|
|
|
{
|
|
|
|
idle_task_exit();
|
|
|
|
|
2023-05-12 14:07:40 -07:00
|
|
|
cpuhp_ap_report_dead();
|
2020-03-17 18:11:44 -07:00
|
|
|
|
2023-11-21 16:47:26 -07:00
|
|
|
cpu_ops->cpu_stop();
|
2020-03-17 18:11:44 -07:00
|
|
|
/* It should never reach here */
|
|
|
|
BUG();
|
|
|
|
}
|
2023-05-12 14:07:40 -07:00
|
|
|
#endif
|