blob: 76f5824cdb002e22844999bd18e05471a7b0305c [file] [log] [blame]
Thomas Gleixner41173ab2019-05-28 09:57:11 -07001// SPDX-License-Identifier: GPL-2.0-only
Ralf Baechle39b8d522008-04-28 17:14:26 +01002/*
Ralf Baechle39b8d522008-04-28 17:14:26 +01003 *
4 * Copyright (C) 2007 MIPS Technologies, Inc.
5 * Chris Dearman (chris@mips.com)
6 */
7
8#undef DEBUG
9
10#include <linux/kernel.h>
Jason A. Donenfeldf677b772017-10-23 19:20:56 +020011#include <linux/sched/task_stack.h>
Ralf Baechle631330f2009-06-19 14:05:26 +010012#include <linux/smp.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010013#include <linux/cpumask.h>
14#include <linux/interrupt.h>
15#include <linux/compiler.h>
16
Arun Sharma600634972011-07-26 16:09:06 -070017#include <linux/atomic.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010018#include <asm/cacheflush.h>
19#include <asm/cpu.h>
20#include <asm/processor.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010021#include <asm/hardirq.h>
22#include <asm/mmu_context.h>
23#include <asm/smp.h>
24#include <asm/time.h>
25#include <asm/mipsregs.h>
26#include <asm/mipsmtregs.h>
27#include <asm/mips_mt.h>
Tim Anderson03650702009-06-17 16:22:53 -070028#include <asm/amon.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010029
Ralf Baechle39b8d522008-04-28 17:14:26 +010030static void cmp_init_secondary(void)
31{
Paul Burtonf0cff5c2014-03-24 10:19:28 +000032 struct cpuinfo_mips *c __maybe_unused = &current_cpu_data;
Ralf Baechle39b8d522008-04-28 17:14:26 +010033
34 /* Assume GIC is present */
James Hoganc3f134f2015-01-16 11:10:46 +000035 change_c0_status(ST0_IM, STATUSF_IP2 | STATUSF_IP3 | STATUSF_IP4 |
36 STATUSF_IP5 | STATUSF_IP6 | STATUSF_IP7);
Ralf Baechle39b8d522008-04-28 17:14:26 +010037
38 /* Enable per-cpu interrupts: platform specific */
39
Ralf Baechleb6336482014-05-23 16:29:44 +020040#ifdef CONFIG_MIPS_MT_SMP
Leonid Yegoshin670bac32013-09-11 14:17:47 -050041 if (cpu_has_mipsmt)
James Hogan7e7bf0e2017-11-01 23:20:23 +000042 cpu_set_vpe_id(c, (read_c0_tcbind() >> TCBIND_CURVPE_SHIFT) &
43 TCBIND_CURVPE);
Ralf Baechle39b8d522008-04-28 17:14:26 +010044#endif
Ralf Baechle39b8d522008-04-28 17:14:26 +010045}
46
47static void cmp_smp_finish(void)
48{
49 pr_debug("SMPCMP: CPU%d: %s\n", smp_processor_id(), __func__);
50
51 /* CDFIXME: remove this? */
52 write_c0_compare(read_c0_count() + (8 * mips_hpt_frequency / HZ));
53
54#ifdef CONFIG_MIPS_MT_FPAFF
55 /* If we have an FPU, enroll ourselves in the FPU-full mask */
56 if (cpu_has_fpu)
Rusty Russell8dd92892015-03-05 10:49:17 +103057 cpumask_set_cpu(smp_processor_id(), &mt_fpu_cpumask);
Ralf Baechle39b8d522008-04-28 17:14:26 +010058#endif /* CONFIG_MIPS_MT_FPAFF */
59
60 local_irq_enable();
61}
62
Ralf Baechle39b8d522008-04-28 17:14:26 +010063/*
64 * Setup the PC, SP, and GP of a secondary processor and start it running
65 * smp_bootstrap is the place to resume from
66 * __KSTK_TOS(idle) is apparently the stack pointer
67 * (unsigned long)idle->thread_info the gp
68 */
Paul Burtond595d422017-08-12 19:49:40 -070069static int cmp_boot_secondary(int cpu, struct task_struct *idle)
Ralf Baechle39b8d522008-04-28 17:14:26 +010070{
71 struct thread_info *gp = task_thread_info(idle);
72 unsigned long sp = __KSTK_TOS(idle);
73 unsigned long pc = (unsigned long)&smp_bootstrap;
74 unsigned long a0 = 0;
75
76 pr_debug("SMPCMP: CPU%d: %s cpu %d\n", smp_processor_id(),
77 __func__, cpu);
78
79#if 0
80 /* Needed? */
81 flush_icache_range((unsigned long)gp,
82 (unsigned long)(gp + sizeof(struct thread_info)));
83#endif
84
Tim Anderson03650702009-06-17 16:22:53 -070085 amon_cpu_start(cpu, pc, sp, (unsigned long)gp, a0);
Paul Burtond595d422017-08-12 19:49:40 -070086 return 0;
Ralf Baechle39b8d522008-04-28 17:14:26 +010087}
88
89/*
90 * Common setup before any secondaries are started
91 */
92void __init cmp_smp_setup(void)
93{
94 int i;
95 int ncpu = 0;
96
97 pr_debug("SMPCMP: CPU%d: %s\n", smp_processor_id(), __func__);
98
99#ifdef CONFIG_MIPS_MT_FPAFF
100 /* If we have an FPU, enroll ourselves in the FPU-full mask */
101 if (cpu_has_fpu)
Rusty Russell8dd92892015-03-05 10:49:17 +1030102 cpumask_set_cpu(0, &mt_fpu_cpumask);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100103#endif /* CONFIG_MIPS_MT_FPAFF */
104
105 for (i = 1; i < NR_CPUS; i++) {
106 if (amon_cpu_avail(i)) {
Rusty Russell4037ac62009-09-24 09:34:47 -0600107 set_cpu_possible(i, true);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100108 __cpu_number_map[i] = ++ncpu;
Ralf Baechle70342282013-01-22 12:59:30 +0100109 __cpu_logical_map[ncpu] = i;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100110 }
111 }
112
113 if (cpu_has_mipsmt) {
Leonid Yegoshin670bac32013-09-11 14:17:47 -0500114 unsigned int nvpe = 1;
115#ifdef CONFIG_MIPS_MT_SMP
116 unsigned int mvpconf0 = read_c0_mvpconf0();
117
118 nvpe = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
Leonid Yegoshin670bac32013-09-11 14:17:47 -0500119#endif
Ralf Baechle39b8d522008-04-28 17:14:26 +0100120 smp_num_siblings = nvpe;
121 }
122 pr_info("Detected %i available secondary CPU(s)\n", ncpu);
123}
124
125void __init cmp_prepare_cpus(unsigned int max_cpus)
126{
127 pr_debug("SMPCMP: CPU%d: %s max_cpus=%d\n",
128 smp_processor_id(), __func__, max_cpus);
129
Markos Chandras40149882013-09-19 18:00:29 +0100130#ifdef CONFIG_MIPS_MT
Ralf Baechle39b8d522008-04-28 17:14:26 +0100131 /*
132 * FIXME: some of these options are per-system, some per-core and
133 * some per-cpu
134 */
135 mips_mt_set_cpuoptions();
Markos Chandras40149882013-09-19 18:00:29 +0100136#endif
137
Ralf Baechle39b8d522008-04-28 17:14:26 +0100138}
139
Matt Redfearnff2c8252017-07-19 09:21:03 +0100140const struct plat_smp_ops cmp_smp_ops = {
Qais Yousefbb11cff2015-12-08 13:20:28 +0000141 .send_ipi_single = mips_smp_send_ipi_single,
142 .send_ipi_mask = mips_smp_send_ipi_mask,
Ralf Baechle39b8d522008-04-28 17:14:26 +0100143 .init_secondary = cmp_init_secondary,
144 .smp_finish = cmp_smp_finish,
Ralf Baechle39b8d522008-04-28 17:14:26 +0100145 .boot_secondary = cmp_boot_secondary,
146 .smp_setup = cmp_smp_setup,
147 .prepare_cpus = cmp_prepare_cpus,
148};