Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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