blob: 76923349b4fe16135a97247734a9d803788ae5ca [file] [log] [blame]
Ralf Baechle39b8d522008-04-28 17:14:26 +01001/*
2 * This program is free software; you can distribute it and/or modify it
3 * under the terms of the GNU General Public License (Version 2) as
4 * published by the Free Software Foundation.
5 *
6 * This program is distributed in the hope it will be useful, but WITHOUT
7 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9 * for more details.
10 *
11 * You should have received a copy of the GNU General Public License along
12 * with this program; if not, write to the Free Software Foundation, Inc.,
13 * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
14 *
15 * Copyright (C) 2007 MIPS Technologies, Inc.
16 * Chris Dearman (chris@mips.com)
17 */
18
19#undef DEBUG
20
21#include <linux/kernel.h>
22#include <linux/sched.h>
Ralf Baechle631330f2009-06-19 14:05:26 +010023#include <linux/smp.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010024#include <linux/cpumask.h>
25#include <linux/interrupt.h>
26#include <linux/compiler.h>
Andrew Bresticker4060bbe2014-10-20 12:03:53 -070027#include <linux/irqchip/mips-gic.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010028
Arun Sharma600634972011-07-26 16:09:06 -070029#include <linux/atomic.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010030#include <asm/cacheflush.h>
31#include <asm/cpu.h>
32#include <asm/processor.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010033#include <asm/hardirq.h>
34#include <asm/mmu_context.h>
35#include <asm/smp.h>
36#include <asm/time.h>
37#include <asm/mipsregs.h>
38#include <asm/mipsmtregs.h>
39#include <asm/mips_mt.h>
Tim Anderson03650702009-06-17 16:22:53 -070040#include <asm/amon.h>
Ralf Baechle39b8d522008-04-28 17:14:26 +010041
Ralf Baechle39b8d522008-04-28 17:14:26 +010042static void cmp_init_secondary(void)
43{
Paul Burtonf0cff5c2014-03-24 10:19:28 +000044 struct cpuinfo_mips *c __maybe_unused = &current_cpu_data;
Ralf Baechle39b8d522008-04-28 17:14:26 +010045
46 /* Assume GIC is present */
James Hoganc3f134f2015-01-16 11:10:46 +000047 change_c0_status(ST0_IM, STATUSF_IP2 | STATUSF_IP3 | STATUSF_IP4 |
48 STATUSF_IP5 | STATUSF_IP6 | STATUSF_IP7);
Ralf Baechle39b8d522008-04-28 17:14:26 +010049
50 /* Enable per-cpu interrupts: platform specific */
51
Ralf Baechleb6336482014-05-23 16:29:44 +020052#ifdef CONFIG_MIPS_MT_SMP
Leonid Yegoshin670bac32013-09-11 14:17:47 -050053 if (cpu_has_mipsmt)
54 c->vpe_id = (read_c0_tcbind() >> TCBIND_CURVPE_SHIFT) &
55 TCBIND_CURVPE;
Ralf Baechle39b8d522008-04-28 17:14:26 +010056#endif
Ralf Baechle39b8d522008-04-28 17:14:26 +010057}
58
59static void cmp_smp_finish(void)
60{
61 pr_debug("SMPCMP: CPU%d: %s\n", smp_processor_id(), __func__);
62
63 /* CDFIXME: remove this? */
64 write_c0_compare(read_c0_count() + (8 * mips_hpt_frequency / HZ));
65
66#ifdef CONFIG_MIPS_MT_FPAFF
67 /* If we have an FPU, enroll ourselves in the FPU-full mask */
68 if (cpu_has_fpu)
Rusty Russell8dd92892015-03-05 10:49:17 +103069 cpumask_set_cpu(smp_processor_id(), &mt_fpu_cpumask);
Ralf Baechle39b8d522008-04-28 17:14:26 +010070#endif /* CONFIG_MIPS_MT_FPAFF */
71
72 local_irq_enable();
73}
74
Ralf Baechle39b8d522008-04-28 17:14:26 +010075/*
76 * Setup the PC, SP, and GP of a secondary processor and start it running
77 * smp_bootstrap is the place to resume from
78 * __KSTK_TOS(idle) is apparently the stack pointer
79 * (unsigned long)idle->thread_info the gp
80 */
81static void cmp_boot_secondary(int cpu, struct task_struct *idle)
82{
83 struct thread_info *gp = task_thread_info(idle);
84 unsigned long sp = __KSTK_TOS(idle);
85 unsigned long pc = (unsigned long)&smp_bootstrap;
86 unsigned long a0 = 0;
87
88 pr_debug("SMPCMP: CPU%d: %s cpu %d\n", smp_processor_id(),
89 __func__, cpu);
90
91#if 0
92 /* Needed? */
93 flush_icache_range((unsigned long)gp,
94 (unsigned long)(gp + sizeof(struct thread_info)));
95#endif
96
Tim Anderson03650702009-06-17 16:22:53 -070097 amon_cpu_start(cpu, pc, sp, (unsigned long)gp, a0);
Ralf Baechle39b8d522008-04-28 17:14:26 +010098}
99
100/*
101 * Common setup before any secondaries are started
102 */
103void __init cmp_smp_setup(void)
104{
105 int i;
106 int ncpu = 0;
107
108 pr_debug("SMPCMP: CPU%d: %s\n", smp_processor_id(), __func__);
109
110#ifdef CONFIG_MIPS_MT_FPAFF
111 /* If we have an FPU, enroll ourselves in the FPU-full mask */
112 if (cpu_has_fpu)
Rusty Russell8dd92892015-03-05 10:49:17 +1030113 cpumask_set_cpu(0, &mt_fpu_cpumask);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100114#endif /* CONFIG_MIPS_MT_FPAFF */
115
116 for (i = 1; i < NR_CPUS; i++) {
117 if (amon_cpu_avail(i)) {
Rusty Russell4037ac62009-09-24 09:34:47 -0600118 set_cpu_possible(i, true);
Ralf Baechle39b8d522008-04-28 17:14:26 +0100119 __cpu_number_map[i] = ++ncpu;
Ralf Baechle70342282013-01-22 12:59:30 +0100120 __cpu_logical_map[ncpu] = i;
Ralf Baechle39b8d522008-04-28 17:14:26 +0100121 }
122 }
123
124 if (cpu_has_mipsmt) {
Leonid Yegoshin670bac32013-09-11 14:17:47 -0500125 unsigned int nvpe = 1;
126#ifdef CONFIG_MIPS_MT_SMP
127 unsigned int mvpconf0 = read_c0_mvpconf0();
128
129 nvpe = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
Leonid Yegoshin670bac32013-09-11 14:17:47 -0500130#endif
Ralf Baechle39b8d522008-04-28 17:14:26 +0100131 smp_num_siblings = nvpe;
132 }
133 pr_info("Detected %i available secondary CPU(s)\n", ncpu);
134}
135
136void __init cmp_prepare_cpus(unsigned int max_cpus)
137{
138 pr_debug("SMPCMP: CPU%d: %s max_cpus=%d\n",
139 smp_processor_id(), __func__, max_cpus);
140
Markos Chandras40149882013-09-19 18:00:29 +0100141#ifdef CONFIG_MIPS_MT
Ralf Baechle39b8d522008-04-28 17:14:26 +0100142 /*
143 * FIXME: some of these options are per-system, some per-core and
144 * some per-cpu
145 */
146 mips_mt_set_cpuoptions();
Markos Chandras40149882013-09-19 18:00:29 +0100147#endif
148
Ralf Baechle39b8d522008-04-28 17:14:26 +0100149}
150
151struct plat_smp_ops cmp_smp_ops = {
Qais Yousefbb11cff2015-12-08 13:20:28 +0000152 .send_ipi_single = mips_smp_send_ipi_single,
153 .send_ipi_mask = mips_smp_send_ipi_mask,
Ralf Baechle39b8d522008-04-28 17:14:26 +0100154 .init_secondary = cmp_init_secondary,
155 .smp_finish = cmp_smp_finish,
Ralf Baechle39b8d522008-04-28 17:14:26 +0100156 .boot_secondary = cmp_boot_secondary,
157 .smp_setup = cmp_smp_setup,
158 .prepare_cpus = cmp_prepare_cpus,
159};