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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  linux/arch/arm/kernel/smp.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 2002 ARM Limited, All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/sched/mm.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 <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/profile.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/nmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/percpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/clockchips.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/cpufreq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/irq_work.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/kernel_stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <asm/bugs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <asm/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <asm/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <asm/cputype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <asm/exception.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <asm/idmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <asm/topology.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <asm/mmu_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <asm/procinfo.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <asm/tlbflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <asm/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <asm/smp_plat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <asm/virt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include <asm/mach/arch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #include <asm/mpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define CREATE_TRACE_POINTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #include <trace/events/ipi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) EXPORT_TRACEPOINT_SYMBOL_GPL(ipi_raise);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) EXPORT_TRACEPOINT_SYMBOL_GPL(ipi_entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) EXPORT_TRACEPOINT_SYMBOL_GPL(ipi_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  * as from 2.5, kernels no longer have an init_tasks structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)  * so we need some other way of telling a new secondary core
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)  * where to place its SVC stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) struct secondary_data secondary_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) enum ipi_msg_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	IPI_WAKEUP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	IPI_TIMER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	IPI_RESCHEDULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	IPI_CALL_FUNC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	IPI_CPU_STOP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	IPI_IRQ_WORK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	IPI_COMPLETION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	NR_IPI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	 * CPU_BACKTRACE is special and not included in NR_IPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	 * or tracable with trace_ipi_*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	IPI_CPU_BACKTRACE = NR_IPI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	 * SGI8-15 can be reserved by secure firmware, and thus may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	 * not be usable by the kernel. Please keep the above limited
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	 * to at most 8 entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	MAX_IPI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static int ipi_irq_base __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static int nr_ipi __read_mostly = NR_IPI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static struct irq_desc *ipi_desc[MAX_IPI] __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static void ipi_setup(int cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static DECLARE_COMPLETION(cpu_running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static struct smp_operations smp_ops __ro_after_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) void __init smp_set_ops(const struct smp_operations *ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		smp_ops = *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static unsigned long get_arch_pgd(pgd_t *pgd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #ifdef CONFIG_ARM_LPAE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	return __phys_to_pfn(virt_to_phys(pgd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	return virt_to_phys(pgd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #if defined(CONFIG_BIG_LITTLE) && defined(CONFIG_HARDEN_BRANCH_PREDICTOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int secondary_biglittle_prepare(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (!cpu_vtable[cpu])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		cpu_vtable[cpu] = kzalloc(sizeof(*cpu_vtable[cpu]), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	return cpu_vtable[cpu] ? 0 : -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static void secondary_biglittle_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	init_proc_vtable(lookup_processor(read_cpuid_id())->proc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static int secondary_biglittle_prepare(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static void secondary_biglittle_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int __cpu_up(unsigned int cpu, struct task_struct *idle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	if (!smp_ops.smp_boot_secondary)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	ret = secondary_biglittle_prepare(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	 * We need to tell the secondary core where to find
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	 * its stack and the page tables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	secondary_data.stack = task_stack_page(idle) + THREAD_START_SP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #ifdef CONFIG_ARM_MPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	secondary_data.mpu_rgn_info = &mpu_rgn_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) #ifdef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	secondary_data.pgdir = virt_to_phys(idmap_pgd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	secondary_data.swapper_pg_dir = get_arch_pgd(swapper_pg_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	sync_cache_w(&secondary_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	 * Now bring the CPU into our world.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	ret = smp_ops.smp_boot_secondary(cpu, idle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	if (ret == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 		 * CPU was successfully started, wait for it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		 * to come online or time out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		wait_for_completion_timeout(&cpu_running,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 						 msecs_to_jiffies(1000));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		if (!cpu_online(cpu)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			pr_crit("CPU%u: failed to come online\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		pr_err("CPU%u: failed to boot: %d\n", cpu, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	memset(&secondary_data, 0, sizeof(secondary_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* platform specific SMP operations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) void __init smp_init_cpus(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (smp_ops.smp_init_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		smp_ops.smp_init_cpus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) int platform_can_secondary_boot(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	return !!smp_ops.smp_boot_secondary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) int platform_can_cpu_hotplug(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) #ifdef CONFIG_HOTPLUG_CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (smp_ops.cpu_kill)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) #ifdef CONFIG_HOTPLUG_CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static int platform_cpu_kill(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (smp_ops.cpu_kill)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		return smp_ops.cpu_kill(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static int platform_cpu_disable(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	if (smp_ops.cpu_disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		return smp_ops.cpu_disable(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) int platform_can_hotplug_cpu(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	/* cpu_die must be specified to support hotplug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	if (!smp_ops.cpu_die)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (smp_ops.cpu_can_disable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		return smp_ops.cpu_can_disable(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	 * By default, allow disabling all CPUs except the first one,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	 * since this is special on a lot of platforms, e.g. because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	 * of clock tick interrupts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	return cpu != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static void ipi_teardown(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	if (WARN_ON_ONCE(!ipi_irq_base))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	for (i = 0; i < nr_ipi; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		disable_percpu_irq(ipi_irq_base + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  * __cpu_disable runs on the processor to be shutdown.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) int __cpu_disable(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	unsigned int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	ret = platform_cpu_disable(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #ifdef CONFIG_GENERIC_ARCH_TOPOLOGY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	remove_cpu_topology(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	 * Take this CPU offline.  Once we clear this, we can't return,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	 * and we must not schedule until we're ready to give up the cpu.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	set_cpu_online(cpu, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	ipi_teardown(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	 * OK - migrate IRQs away from this CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	irq_migrate_all_off_this_cpu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	 * Flush user cache and TLB mappings, and then remove this CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	 * from the vm mask set of all processes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	 * Caches are flushed to the Level of Unification Inner Shareable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	 * to write-back dirty lines to unified caches shared by all CPUs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	flush_cache_louis();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	local_flush_tlb_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)  * called on the thread which is asking for a CPU to be shutdown -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)  * waits until shutdown has completed, or it is timed out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) void __cpu_die(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (!cpu_wait_death(cpu, 5)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		pr_err("CPU%u: cpu didn't die\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	pr_debug("CPU%u: shutdown\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	clear_tasks_mm_cpumask(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	 * platform_cpu_kill() is generally expected to do the powering off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	 * and/or cutting of clocks to the dying CPU.  Optionally, this may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	 * be done by the CPU which is dying in preference to supporting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	 * this call, but that means there is _no_ synchronisation between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	 * the requesting CPU and the dying CPU actually losing power.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	if (!platform_cpu_kill(cpu))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		pr_err("CPU%u: unable to kill\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)  * Called from the idle thread for the CPU which has been shutdown.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)  * Note that we disable IRQs here, but do not re-enable them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)  * before returning to the caller. This is also the behaviour
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)  * of the other hotplug-cpu capable cores, so presumably coming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)  * out of idle fixes this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) void arch_cpu_idle_dead(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	unsigned int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	idle_task_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	 * Flush the data out of the L1 cache for this CPU.  This must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	 * before the completion to ensure that data is safely written out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	 * before platform_cpu_kill() gets called - which may disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	 * *this* CPU and power down its cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	flush_cache_louis();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	 * Tell __cpu_die() that this CPU is now safe to dispose of.  Once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	 * this returns, power and/or clocks can be removed at any point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	 * from this CPU and its cache by platform_cpu_kill().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	(void)cpu_report_death();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	 * Ensure that the cache lines associated with that completion are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	 * written out.  This covers the case where _this_ CPU is doing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	 * powering down, to ensure that the completion is visible to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	 * CPU waiting for this one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	flush_cache_louis();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	 * The actual CPU shutdown procedure is at least platform (if not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	 * CPU) specific.  This may remove power, or it may simply spin.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	 * Platforms are generally expected *NOT* to return from this call,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	 * although there are some which do because they have no way to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	 * power down the CPU.  These platforms are the _only_ reason we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 	 * have a return path which uses the fragment of assembly below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	 * The return path should not be used for platforms which can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	 * power off the CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	if (smp_ops.cpu_die)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 		smp_ops.cpu_die(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	pr_warn("CPU%u: smp_ops.cpu_die() returned, trying to resuscitate\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 		cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 	 * Do not return to the idle loop - jump back to the secondary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	 * cpu initialisation.  There's some initialisation which needs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	 * to be repeated to undo the effects of taking the CPU offline.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	__asm__("mov	sp, %0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	"	mov	fp, #0\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	"	b	secondary_start_kernel"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 		: "r" (task_stack_page(current) + THREAD_SIZE - 8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) #endif /* CONFIG_HOTPLUG_CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)  * Called by both boot and secondaries to move global data into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)  * per-processor storage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) static void smp_store_cpu_info(unsigned int cpuid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	struct cpuinfo_arm *cpu_info = &per_cpu(cpu_data, cpuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	cpu_info->loops_per_jiffy = loops_per_jiffy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	cpu_info->cpuid = read_cpuid_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	store_cpu_topology(cpuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	check_cpu_icache_size(cpuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)  * This is the secondary CPU boot entry.  We're using this CPUs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)  * idle thread stack, but a set of temporary page tables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) asmlinkage void secondary_start_kernel(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	struct mm_struct *mm = &init_mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	unsigned int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	secondary_biglittle_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	 * The identity mapping is uncached (strongly ordered), so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	 * switch away from it before attempting any exclusive accesses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	cpu_switch_mm(mm->pgd, mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	local_flush_bp_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	enter_lazy_tlb(mm, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	local_flush_tlb_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	 * All kernel threads share the same mm context; grab a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	 * reference and switch to it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	mmgrab(mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	current->active_mm = mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	cpumask_set_cpu(cpu, mm_cpumask(mm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	cpu_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) #ifndef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	setup_vectors_base();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	pr_debug("CPU%u: Booted secondary processor\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	trace_hardirqs_off();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	 * Give the platform a chance to do its own initialisation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	if (smp_ops.smp_secondary_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		smp_ops.smp_secondary_init(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	notify_cpu_starting(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	ipi_setup(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	calibrate_delay();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	smp_store_cpu_info(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	 * OK, now it's safe to let the boot CPU continue.  Wait for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	 * the CPU migration code to notice that the CPU is online
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	 * before we continue - which happens after __cpu_up returns.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	set_cpu_online(cpu, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	check_other_bugs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	complete(&cpu_running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 	local_fiq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	local_abt_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	 * OK, it's off to the idle thread for us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) void __init smp_cpus_done(unsigned int max_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 	int cpu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	unsigned long bogosum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 	for_each_online_cpu(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 		bogosum += per_cpu(cpu_data, cpu).loops_per_jiffy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	printk(KERN_INFO "SMP: Total of %d processors activated "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	       "(%lu.%02lu BogoMIPS).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 	       num_online_cpus(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	       bogosum / (500000/HZ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 	       (bogosum / (5000/HZ)) % 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 	hyp_mode_check();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) void __init smp_prepare_boot_cpu(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 	set_my_cpu_offset(per_cpu_offset(smp_processor_id()));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) void __init smp_prepare_cpus(unsigned int max_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	unsigned int ncores = num_possible_cpus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) 	init_cpu_topology();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	smp_store_cpu_info(smp_processor_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	 * are we trying to boot more cores than exist?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	if (max_cpus > ncores)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		max_cpus = ncores;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	if (ncores > 1 && max_cpus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		 * Initialise the present map, which describes the set of CPUs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		 * actually populated at the present time. A platform should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 		 * re-initialize the map in the platforms smp_prepare_cpus()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		 * if present != possible (e.g. physical hotplug).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		init_cpu_present(cpu_possible_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 		 * Initialise the SCU if there are more than one CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 		 * and let them know where to start.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		if (smp_ops.smp_prepare_cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 			smp_ops.smp_prepare_cpus(max_cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) static const char *ipi_types[NR_IPI] __tracepoint_string = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) #define S(x,s)	[x] = s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	S(IPI_WAKEUP, "CPU wakeup interrupts"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	S(IPI_TIMER, "Timer broadcast interrupts"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	S(IPI_RESCHEDULE, "Rescheduling interrupts"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	S(IPI_CALL_FUNC, "Function call interrupts"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	S(IPI_CPU_STOP, "CPU stop interrupts"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	S(IPI_IRQ_WORK, "IRQ work interrupts"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	S(IPI_COMPLETION, "completion interrupts"),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) static void smp_cross_call(const struct cpumask *target, unsigned int ipinr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) void show_ipi_list(struct seq_file *p, int prec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	unsigned int cpu, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	for (i = 0; i < NR_IPI; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		unsigned int irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 		if (!ipi_desc[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		irq = irq_desc_get_irq(ipi_desc[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 		seq_printf(p, "%*s%u: ", prec - 1, "IPI", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 		for_each_online_cpu(cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 			seq_printf(p, "%10u ", kstat_irqs_cpu(irq, cpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		seq_printf(p, " %s\n", ipi_types[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) void arch_send_call_function_ipi_mask(const struct cpumask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	smp_cross_call(mask, IPI_CALL_FUNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) void arch_send_wakeup_ipi_mask(const struct cpumask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	smp_cross_call(mask, IPI_WAKEUP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) void arch_send_call_function_single_ipi(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	smp_cross_call(cpumask_of(cpu), IPI_CALL_FUNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) #ifdef CONFIG_IRQ_WORK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) void arch_irq_work_raise(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 	if (arch_irq_work_has_interrupt())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		smp_cross_call(cpumask_of(smp_processor_id()), IPI_IRQ_WORK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) void tick_broadcast(const struct cpumask *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	smp_cross_call(mask, IPI_TIMER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) static DEFINE_RAW_SPINLOCK(stop_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)  * ipi_cpu_stop - handle IPI from smp_send_stop()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) static void ipi_cpu_stop(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	if (system_state <= SYSTEM_RUNNING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 		raw_spin_lock(&stop_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 		pr_crit("CPU%u: stopping\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		dump_stack();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 		raw_spin_unlock(&stop_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	set_cpu_online(cpu, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	local_fiq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 		cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		wfe();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) static DEFINE_PER_CPU(struct completion *, cpu_completion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) int register_ipi_completion(struct completion *completion, int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	per_cpu(cpu_completion, cpu) = completion;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	return IPI_COMPLETION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) static void ipi_complete(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	complete(per_cpu(cpu_completion, cpu));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)  * Main handler for inter-processor interrupts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) asmlinkage void __exception_irq_entry do_IPI(int ipinr, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	handle_IPI(ipinr, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) static void do_handle_IPI(int ipinr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	unsigned int cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	if ((unsigned)ipinr < NR_IPI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 		trace_ipi_entry_rcuidle(ipi_types[ipinr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	switch (ipinr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	case IPI_WAKEUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	case IPI_TIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 		tick_receive_broadcast();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	case IPI_RESCHEDULE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 		scheduler_ipi();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	case IPI_CALL_FUNC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 		generic_smp_call_function_interrupt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	case IPI_CPU_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		ipi_cpu_stop(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) #ifdef CONFIG_IRQ_WORK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	case IPI_IRQ_WORK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 		irq_work_run();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	case IPI_COMPLETION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 		ipi_complete(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	case IPI_CPU_BACKTRACE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 		printk_nmi_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) 		nmi_cpu_backtrace(get_irq_regs());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 		printk_nmi_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 		pr_crit("CPU%u: Unknown IPI message 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 		        cpu, ipinr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	if ((unsigned)ipinr < NR_IPI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 		trace_ipi_exit_rcuidle(ipi_types[ipinr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) /* Legacy version, should go away once all irqchips have been converted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) void handle_IPI(int ipinr, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 	struct pt_regs *old_regs = set_irq_regs(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 	irq_enter();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 	do_handle_IPI(ipinr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 	irq_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 	set_irq_regs(old_regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) static irqreturn_t ipi_handler(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	do_handle_IPI(irq - ipi_irq_base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) static void smp_cross_call(const struct cpumask *target, unsigned int ipinr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 	trace_ipi_raise_rcuidle(target, ipi_types[ipinr]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 	__ipi_send_mask(ipi_desc[ipinr], target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) static void ipi_setup(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) 	if (WARN_ON_ONCE(!ipi_irq_base))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	for (i = 0; i < nr_ipi; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) 		enable_percpu_irq(ipi_irq_base + i, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) void __init set_smp_ipi_range(int ipi_base, int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) 	WARN_ON(n < MAX_IPI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	nr_ipi = min(n, MAX_IPI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	for (i = 0; i < nr_ipi; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 		int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 		err = request_percpu_irq(ipi_base + i, ipi_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 					 "IPI", &irq_stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 		WARN_ON(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 		ipi_desc[i] = irq_to_desc(ipi_base + i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) 		irq_set_status_flags(ipi_base + i, IRQ_HIDDEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) 		/* The recheduling IPI is special... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 		if (i == IPI_RESCHEDULE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 			__irq_modify_status(ipi_base + i, 0, IRQ_RAW, ~0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	ipi_irq_base = ipi_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	/* Setup the boot CPU immediately */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	ipi_setup(smp_processor_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) void smp_send_reschedule(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) void smp_send_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 	unsigned long timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) 	struct cpumask mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 	cpumask_copy(&mask, cpu_online_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 	cpumask_clear_cpu(smp_processor_id(), &mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 	if (!cpumask_empty(&mask))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) 		smp_cross_call(&mask, IPI_CPU_STOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 	/* Wait up to one second for other CPUs to stop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	timeout = USEC_PER_SEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 	while (num_online_cpus() > 1 && timeout--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) 		udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 	if (num_online_cpus() > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 		pr_warn("SMP: failed to stop secondary CPUs\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) /* In case panic() and panic() called at the same time on CPU1 and CPU2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)  * and CPU 1 calls panic_smp_self_stop() before crash_smp_send_stop()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)  * CPU1 can't receive the ipi irqs from CPU2, CPU1 will be always online,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)  * kdump fails. So split out the panic_smp_self_stop() and add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)  * set_cpu_online(smp_processor_id(), false).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) void panic_smp_self_stop(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) 	pr_debug("CPU %u will stop doing anything useful since another CPU has paniced\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	         smp_processor_id());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 	set_cpu_online(smp_processor_id(), false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 	while (1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 		cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)  * not supported here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) int setup_profiling_timer(unsigned int multiplier)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 	return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) #ifdef CONFIG_CPU_FREQ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) static DEFINE_PER_CPU(unsigned long, l_p_j_ref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) static DEFINE_PER_CPU(unsigned long, l_p_j_ref_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) static unsigned long global_l_p_j_ref;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) static unsigned long global_l_p_j_ref_freq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) static int cpufreq_callback(struct notifier_block *nb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) 					unsigned long val, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) 	struct cpufreq_freqs *freq = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) 	struct cpumask *cpus = freq->policy->cpus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) 	int cpu, first = cpumask_first(cpus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) 	unsigned int lpj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) 	if (freq->flags & CPUFREQ_CONST_LOOPS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) 		return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) 	if (!per_cpu(l_p_j_ref, first)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) 		for_each_cpu(cpu, cpus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) 			per_cpu(l_p_j_ref, cpu) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) 				per_cpu(cpu_data, cpu).loops_per_jiffy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) 			per_cpu(l_p_j_ref_freq, cpu) = freq->old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) 		if (!global_l_p_j_ref) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) 			global_l_p_j_ref = loops_per_jiffy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) 			global_l_p_j_ref_freq = freq->old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) 	if ((val == CPUFREQ_PRECHANGE  && freq->old < freq->new) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) 	    (val == CPUFREQ_POSTCHANGE && freq->old > freq->new)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) 		loops_per_jiffy = cpufreq_scale(global_l_p_j_ref,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) 						global_l_p_j_ref_freq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) 						freq->new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) 		lpj = cpufreq_scale(per_cpu(l_p_j_ref, first),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) 				    per_cpu(l_p_j_ref_freq, first), freq->new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) 		for_each_cpu(cpu, cpus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) 			per_cpu(cpu_data, cpu).loops_per_jiffy = lpj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) 	return NOTIFY_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) static struct notifier_block cpufreq_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) 	.notifier_call  = cpufreq_callback,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) static int __init register_cpufreq_notifier(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) 	return cpufreq_register_notifier(&cpufreq_notifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) 						CPUFREQ_TRANSITION_NOTIFIER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) core_initcall(register_cpufreq_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) static void raise_nmi(cpumask_t *mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) 	__ipi_send_mask(ipi_desc[IPI_CPU_BACKTRACE], mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) void arch_trigger_cpumask_backtrace(const cpumask_t *mask, bool exclude_self)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) 	nmi_trigger_cpumask_backtrace(mask, exclude_self, raise_nmi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) }