arm64: dts: Revert "specify console via command line"
[linux/fpc-iii.git] / arch / sh / kernel / smp.c
blob372acdc9033eb35da2b5a610cc6221f53208e573
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * arch/sh/kernel/smp.c
5 * SMP support for the SuperH processors.
7 * Copyright (C) 2002 - 2010 Paul Mundt
8 * Copyright (C) 2006 - 2007 Akio Idehara
9 */
10 #include <linux/err.h>
11 #include <linux/cache.h>
12 #include <linux/cpumask.h>
13 #include <linux/delay.h>
14 #include <linux/init.h>
15 #include <linux/spinlock.h>
16 #include <linux/mm.h>
17 #include <linux/module.h>
18 #include <linux/cpu.h>
19 #include <linux/interrupt.h>
20 #include <linux/sched/mm.h>
21 #include <linux/sched/hotplug.h>
22 #include <linux/atomic.h>
23 #include <linux/clockchips.h>
24 #include <asm/processor.h>
25 #include <asm/mmu_context.h>
26 #include <asm/smp.h>
27 #include <asm/cacheflush.h>
28 #include <asm/sections.h>
29 #include <asm/setup.h>
31 int __cpu_number_map[NR_CPUS]; /* Map physical to logical */
32 int __cpu_logical_map[NR_CPUS]; /* Map logical to physical */
34 struct plat_smp_ops *mp_ops = NULL;
36 /* State of each CPU */
37 DEFINE_PER_CPU(int, cpu_state) = { 0 };
39 void register_smp_ops(struct plat_smp_ops *ops)
41 if (mp_ops)
42 printk(KERN_WARNING "Overriding previously set SMP ops\n");
44 mp_ops = ops;
47 static inline void smp_store_cpu_info(unsigned int cpu)
49 struct sh_cpuinfo *c = cpu_data + cpu;
51 memcpy(c, &boot_cpu_data, sizeof(struct sh_cpuinfo));
53 c->loops_per_jiffy = loops_per_jiffy;
56 void __init smp_prepare_cpus(unsigned int max_cpus)
58 unsigned int cpu = smp_processor_id();
60 init_new_context(current, &init_mm);
61 current_thread_info()->cpu = cpu;
62 mp_ops->prepare_cpus(max_cpus);
64 #ifndef CONFIG_HOTPLUG_CPU
65 init_cpu_present(cpu_possible_mask);
66 #endif
69 void __init smp_prepare_boot_cpu(void)
71 unsigned int cpu = smp_processor_id();
73 __cpu_number_map[0] = cpu;
74 __cpu_logical_map[0] = cpu;
76 set_cpu_online(cpu, true);
77 set_cpu_possible(cpu, true);
79 per_cpu(cpu_state, cpu) = CPU_ONLINE;
82 #ifdef CONFIG_HOTPLUG_CPU
83 void native_cpu_die(unsigned int cpu)
85 unsigned int i;
87 for (i = 0; i < 10; i++) {
88 smp_rmb();
89 if (per_cpu(cpu_state, cpu) == CPU_DEAD) {
90 if (system_state == SYSTEM_RUNNING)
91 pr_info("CPU %u is now offline\n", cpu);
93 return;
96 msleep(100);
99 pr_err("CPU %u didn't die...\n", cpu);
102 int native_cpu_disable(unsigned int cpu)
104 return cpu == 0 ? -EPERM : 0;
107 void play_dead_common(void)
109 idle_task_exit();
110 irq_ctx_exit(raw_smp_processor_id());
111 mb();
113 __this_cpu_write(cpu_state, CPU_DEAD);
114 local_irq_disable();
117 void native_play_dead(void)
119 play_dead_common();
122 int __cpu_disable(void)
124 unsigned int cpu = smp_processor_id();
125 int ret;
127 ret = mp_ops->cpu_disable(cpu);
128 if (ret)
129 return ret;
132 * Take this CPU offline. Once we clear this, we can't return,
133 * and we must not schedule until we're ready to give up the cpu.
135 set_cpu_online(cpu, false);
138 * OK - migrate IRQs away from this CPU
140 migrate_irqs();
143 * Flush user cache and TLB mappings, and then remove this CPU
144 * from the vm mask set of all processes.
146 flush_cache_all();
147 #ifdef CONFIG_MMU
148 local_flush_tlb_all();
149 #endif
151 clear_tasks_mm_cpumask(cpu);
153 return 0;
155 #else /* ... !CONFIG_HOTPLUG_CPU */
156 int native_cpu_disable(unsigned int cpu)
158 return -ENOSYS;
161 void native_cpu_die(unsigned int cpu)
163 /* We said "no" in __cpu_disable */
164 BUG();
167 void native_play_dead(void)
169 BUG();
171 #endif
173 asmlinkage void start_secondary(void)
175 unsigned int cpu = smp_processor_id();
176 struct mm_struct *mm = &init_mm;
178 enable_mmu();
179 mmgrab(mm);
180 mmget(mm);
181 current->active_mm = mm;
182 #ifdef CONFIG_MMU
183 enter_lazy_tlb(mm, current);
184 local_flush_tlb_all();
185 #endif
187 per_cpu_trap_init();
189 preempt_disable();
191 notify_cpu_starting(cpu);
193 local_irq_enable();
195 calibrate_delay();
197 smp_store_cpu_info(cpu);
199 set_cpu_online(cpu, true);
200 per_cpu(cpu_state, cpu) = CPU_ONLINE;
202 cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
205 extern struct {
206 unsigned long sp;
207 unsigned long bss_start;
208 unsigned long bss_end;
209 void *start_kernel_fn;
210 void *cpu_init_fn;
211 void *thread_info;
212 } stack_start;
214 int __cpu_up(unsigned int cpu, struct task_struct *tsk)
216 unsigned long timeout;
218 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
220 /* Fill in data in head.S for secondary cpus */
221 stack_start.sp = tsk->thread.sp;
222 stack_start.thread_info = tsk->stack;
223 stack_start.bss_start = 0; /* don't clear bss for secondary cpus */
224 stack_start.start_kernel_fn = start_secondary;
226 flush_icache_range((unsigned long)&stack_start,
227 (unsigned long)&stack_start + sizeof(stack_start));
228 wmb();
230 mp_ops->start_cpu(cpu, (unsigned long)_stext);
232 timeout = jiffies + HZ;
233 while (time_before(jiffies, timeout)) {
234 if (cpu_online(cpu))
235 break;
237 udelay(10);
238 barrier();
241 if (cpu_online(cpu))
242 return 0;
244 return -ENOENT;
247 void __init smp_cpus_done(unsigned int max_cpus)
249 unsigned long bogosum = 0;
250 int cpu;
252 for_each_online_cpu(cpu)
253 bogosum += cpu_data[cpu].loops_per_jiffy;
255 printk(KERN_INFO "SMP: Total of %d processors activated "
256 "(%lu.%02lu BogoMIPS).\n", num_online_cpus(),
257 bogosum / (500000/HZ),
258 (bogosum / (5000/HZ)) % 100);
261 void smp_send_reschedule(int cpu)
263 mp_ops->send_ipi(cpu, SMP_MSG_RESCHEDULE);
266 void smp_send_stop(void)
268 smp_call_function(stop_this_cpu, 0, 0);
271 void arch_send_call_function_ipi_mask(const struct cpumask *mask)
273 int cpu;
275 for_each_cpu(cpu, mask)
276 mp_ops->send_ipi(cpu, SMP_MSG_FUNCTION);
279 void arch_send_call_function_single_ipi(int cpu)
281 mp_ops->send_ipi(cpu, SMP_MSG_FUNCTION_SINGLE);
284 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
285 void tick_broadcast(const struct cpumask *mask)
287 int cpu;
289 for_each_cpu(cpu, mask)
290 mp_ops->send_ipi(cpu, SMP_MSG_TIMER);
293 static void ipi_timer(void)
295 irq_enter();
296 tick_receive_broadcast();
297 irq_exit();
299 #endif
301 void smp_message_recv(unsigned int msg)
303 switch (msg) {
304 case SMP_MSG_FUNCTION:
305 generic_smp_call_function_interrupt();
306 break;
307 case SMP_MSG_RESCHEDULE:
308 scheduler_ipi();
309 break;
310 case SMP_MSG_FUNCTION_SINGLE:
311 generic_smp_call_function_single_interrupt();
312 break;
313 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
314 case SMP_MSG_TIMER:
315 ipi_timer();
316 break;
317 #endif
318 default:
319 printk(KERN_WARNING "SMP %d: %s(): unknown IPI %d\n",
320 smp_processor_id(), __func__, msg);
321 break;
325 /* Not really SMP stuff ... */
326 int setup_profiling_timer(unsigned int multiplier)
328 return 0;
331 #ifdef CONFIG_MMU
333 static void flush_tlb_all_ipi(void *info)
335 local_flush_tlb_all();
338 void flush_tlb_all(void)
340 on_each_cpu(flush_tlb_all_ipi, 0, 1);
343 static void flush_tlb_mm_ipi(void *mm)
345 local_flush_tlb_mm((struct mm_struct *)mm);
349 * The following tlb flush calls are invoked when old translations are
350 * being torn down, or pte attributes are changing. For single threaded
351 * address spaces, a new context is obtained on the current cpu, and tlb
352 * context on other cpus are invalidated to force a new context allocation
353 * at switch_mm time, should the mm ever be used on other cpus. For
354 * multithreaded address spaces, intercpu interrupts have to be sent.
355 * Another case where intercpu interrupts are required is when the target
356 * mm might be active on another cpu (eg debuggers doing the flushes on
357 * behalf of debugees, kswapd stealing pages from another process etc).
358 * Kanoj 07/00.
360 void flush_tlb_mm(struct mm_struct *mm)
362 preempt_disable();
364 if ((atomic_read(&mm->mm_users) != 1) || (current->mm != mm)) {
365 smp_call_function(flush_tlb_mm_ipi, (void *)mm, 1);
366 } else {
367 int i;
368 for_each_online_cpu(i)
369 if (smp_processor_id() != i)
370 cpu_context(i, mm) = 0;
372 local_flush_tlb_mm(mm);
374 preempt_enable();
377 struct flush_tlb_data {
378 struct vm_area_struct *vma;
379 unsigned long addr1;
380 unsigned long addr2;
383 static void flush_tlb_range_ipi(void *info)
385 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
387 local_flush_tlb_range(fd->vma, fd->addr1, fd->addr2);
390 void flush_tlb_range(struct vm_area_struct *vma,
391 unsigned long start, unsigned long end)
393 struct mm_struct *mm = vma->vm_mm;
395 preempt_disable();
396 if ((atomic_read(&mm->mm_users) != 1) || (current->mm != mm)) {
397 struct flush_tlb_data fd;
399 fd.vma = vma;
400 fd.addr1 = start;
401 fd.addr2 = end;
402 smp_call_function(flush_tlb_range_ipi, (void *)&fd, 1);
403 } else {
404 int i;
405 for_each_online_cpu(i)
406 if (smp_processor_id() != i)
407 cpu_context(i, mm) = 0;
409 local_flush_tlb_range(vma, start, end);
410 preempt_enable();
413 static void flush_tlb_kernel_range_ipi(void *info)
415 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
417 local_flush_tlb_kernel_range(fd->addr1, fd->addr2);
420 void flush_tlb_kernel_range(unsigned long start, unsigned long end)
422 struct flush_tlb_data fd;
424 fd.addr1 = start;
425 fd.addr2 = end;
426 on_each_cpu(flush_tlb_kernel_range_ipi, (void *)&fd, 1);
429 static void flush_tlb_page_ipi(void *info)
431 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
433 local_flush_tlb_page(fd->vma, fd->addr1);
436 void flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
438 preempt_disable();
439 if ((atomic_read(&vma->vm_mm->mm_users) != 1) ||
440 (current->mm != vma->vm_mm)) {
441 struct flush_tlb_data fd;
443 fd.vma = vma;
444 fd.addr1 = page;
445 smp_call_function(flush_tlb_page_ipi, (void *)&fd, 1);
446 } else {
447 int i;
448 for_each_online_cpu(i)
449 if (smp_processor_id() != i)
450 cpu_context(i, vma->vm_mm) = 0;
452 local_flush_tlb_page(vma, page);
453 preempt_enable();
456 static void flush_tlb_one_ipi(void *info)
458 struct flush_tlb_data *fd = (struct flush_tlb_data *)info;
459 local_flush_tlb_one(fd->addr1, fd->addr2);
462 void flush_tlb_one(unsigned long asid, unsigned long vaddr)
464 struct flush_tlb_data fd;
466 fd.addr1 = asid;
467 fd.addr2 = vaddr;
469 smp_call_function(flush_tlb_one_ipi, (void *)&fd, 1);
470 local_flush_tlb_one(asid, vaddr);
473 #endif