spi: spi-fsl-qspi: Fix return value check of devm_ioremap() in probe
[linux/fpc-iii.git] / arch / riscv / kernel / smpboot.c
blob4e9922790f6eac76ef641feae8d5b07f8adccf52
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * SMP initialisation and IPI support
4 * Based on arch/arm64/kernel/smp.c
6 * Copyright (C) 2012 ARM Ltd.
7 * Copyright (C) 2015 Regents of the University of California
8 * Copyright (C) 2017 SiFive
9 */
11 #include <linux/arch_topology.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15 #include <linux/mm.h>
16 #include <linux/sched.h>
17 #include <linux/kernel_stat.h>
18 #include <linux/notifier.h>
19 #include <linux/cpu.h>
20 #include <linux/percpu.h>
21 #include <linux/delay.h>
22 #include <linux/err.h>
23 #include <linux/irq.h>
24 #include <linux/of.h>
25 #include <linux/sched/task_stack.h>
26 #include <linux/sched/mm.h>
27 #include <asm/clint.h>
28 #include <asm/cpu_ops.h>
29 #include <asm/irq.h>
30 #include <asm/mmu_context.h>
31 #include <asm/tlbflush.h>
32 #include <asm/sections.h>
33 #include <asm/sbi.h>
34 #include <asm/smp.h>
36 #include "head.h"
38 static DECLARE_COMPLETION(cpu_running);
40 void __init smp_prepare_boot_cpu(void)
42 init_cpu_topology();
45 void __init smp_prepare_cpus(unsigned int max_cpus)
47 int cpuid;
48 int ret;
50 /* This covers non-smp usecase mandated by "nosmp" option */
51 if (max_cpus == 0)
52 return;
54 for_each_possible_cpu(cpuid) {
55 if (cpuid == smp_processor_id())
56 continue;
57 if (cpu_ops[cpuid]->cpu_prepare) {
58 ret = cpu_ops[cpuid]->cpu_prepare(cpuid);
59 if (ret)
60 continue;
62 set_cpu_present(cpuid, true);
66 void __init setup_smp(void)
68 struct device_node *dn;
69 int hart;
70 bool found_boot_cpu = false;
71 int cpuid = 1;
73 cpu_set_ops(0);
75 for_each_of_cpu_node(dn) {
76 hart = riscv_of_processor_hartid(dn);
77 if (hart < 0)
78 continue;
80 if (hart == cpuid_to_hartid_map(0)) {
81 BUG_ON(found_boot_cpu);
82 found_boot_cpu = 1;
83 continue;
85 if (cpuid >= NR_CPUS) {
86 pr_warn("Invalid cpuid [%d] for hartid [%d]\n",
87 cpuid, hart);
88 break;
91 cpuid_to_hartid_map(cpuid) = hart;
92 cpuid++;
95 BUG_ON(!found_boot_cpu);
97 if (cpuid > nr_cpu_ids)
98 pr_warn("Total number of cpus [%d] is greater than nr_cpus option value [%d]\n",
99 cpuid, nr_cpu_ids);
101 for (cpuid = 1; cpuid < nr_cpu_ids; cpuid++) {
102 if (cpuid_to_hartid_map(cpuid) != INVALID_HARTID) {
103 cpu_set_ops(cpuid);
104 set_cpu_possible(cpuid, true);
109 int start_secondary_cpu(int cpu, struct task_struct *tidle)
111 if (cpu_ops[cpu]->cpu_start)
112 return cpu_ops[cpu]->cpu_start(cpu, tidle);
114 return -EOPNOTSUPP;
117 int __cpu_up(unsigned int cpu, struct task_struct *tidle)
119 int ret = 0;
120 tidle->thread_info.cpu = cpu;
122 ret = start_secondary_cpu(cpu, tidle);
123 if (!ret) {
124 lockdep_assert_held(&cpu_running);
125 wait_for_completion_timeout(&cpu_running,
126 msecs_to_jiffies(1000));
128 if (!cpu_online(cpu)) {
129 pr_crit("CPU%u: failed to come online\n", cpu);
130 ret = -EIO;
132 } else {
133 pr_crit("CPU%u: failed to start\n", cpu);
136 return ret;
139 void __init smp_cpus_done(unsigned int max_cpus)
144 * C entry point for a secondary processor.
146 asmlinkage __visible void smp_callin(void)
148 struct mm_struct *mm = &init_mm;
150 if (!IS_ENABLED(CONFIG_RISCV_SBI))
151 clint_clear_ipi(cpuid_to_hartid_map(smp_processor_id()));
153 /* All kernel threads share the same mm context. */
154 mmgrab(mm);
155 current->active_mm = mm;
157 trap_init();
158 notify_cpu_starting(smp_processor_id());
159 update_siblings_masks(smp_processor_id());
160 set_cpu_online(smp_processor_id(), 1);
162 * Remote TLB flushes are ignored while the CPU is offline, so emit
163 * a local TLB flush right now just in case.
165 local_flush_tlb_all();
166 complete(&cpu_running);
168 * Disable preemption before enabling interrupts, so we don't try to
169 * schedule a CPU that hasn't actually started yet.
171 preempt_disable();
172 local_irq_enable();
173 cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);