MIPS: MT: Remove SMTC support
[linux-2.6-block.git] / arch / mips / kernel / smp-cmp.c
1 /*
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>
23 #include <linux/smp.h>
24 #include <linux/cpumask.h>
25 #include <linux/interrupt.h>
26 #include <linux/compiler.h>
27
28 #include <linux/atomic.h>
29 #include <asm/cacheflush.h>
30 #include <asm/cpu.h>
31 #include <asm/processor.h>
32 #include <asm/hardirq.h>
33 #include <asm/mmu_context.h>
34 #include <asm/smp.h>
35 #include <asm/time.h>
36 #include <asm/mipsregs.h>
37 #include <asm/mipsmtregs.h>
38 #include <asm/mips_mt.h>
39 #include <asm/amon.h>
40 #include <asm/gic.h>
41
42 static void cmp_init_secondary(void)
43 {
44         struct cpuinfo_mips *c __maybe_unused = &current_cpu_data;
45
46         /* Assume GIC is present */
47         change_c0_status(ST0_IM, STATUSF_IP3 | STATUSF_IP4 | STATUSF_IP6 |
48                                  STATUSF_IP7);
49
50         /* Enable per-cpu interrupts: platform specific */
51
52 #ifdef CONFIG_MIPS_MT_SMP
53         if (cpu_has_mipsmt)
54                 c->vpe_id = (read_c0_tcbind() >> TCBIND_CURVPE_SHIFT) &
55                         TCBIND_CURVPE;
56 #endif
57 }
58
59 static 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)
69                 cpu_set(smp_processor_id(), mt_fpu_cpumask);
70 #endif /* CONFIG_MIPS_MT_FPAFF */
71
72         local_irq_enable();
73 }
74
75 static void cmp_cpus_done(void)
76 {
77         pr_debug("SMPCMP: CPU%d: %s\n", smp_processor_id(), __func__);
78 }
79
80 /*
81  * Setup the PC, SP, and GP of a secondary processor and start it running
82  * smp_bootstrap is the place to resume from
83  * __KSTK_TOS(idle) is apparently the stack pointer
84  * (unsigned long)idle->thread_info the gp
85  */
86 static void cmp_boot_secondary(int cpu, struct task_struct *idle)
87 {
88         struct thread_info *gp = task_thread_info(idle);
89         unsigned long sp = __KSTK_TOS(idle);
90         unsigned long pc = (unsigned long)&smp_bootstrap;
91         unsigned long a0 = 0;
92
93         pr_debug("SMPCMP: CPU%d: %s cpu %d\n", smp_processor_id(),
94                 __func__, cpu);
95
96 #if 0
97         /* Needed? */
98         flush_icache_range((unsigned long)gp,
99                            (unsigned long)(gp + sizeof(struct thread_info)));
100 #endif
101
102         amon_cpu_start(cpu, pc, sp, (unsigned long)gp, a0);
103 }
104
105 /*
106  * Common setup before any secondaries are started
107  */
108 void __init cmp_smp_setup(void)
109 {
110         int i;
111         int ncpu = 0;
112
113         pr_debug("SMPCMP: CPU%d: %s\n", smp_processor_id(), __func__);
114
115 #ifdef CONFIG_MIPS_MT_FPAFF
116         /* If we have an FPU, enroll ourselves in the FPU-full mask */
117         if (cpu_has_fpu)
118                 cpu_set(0, mt_fpu_cpumask);
119 #endif /* CONFIG_MIPS_MT_FPAFF */
120
121         for (i = 1; i < NR_CPUS; i++) {
122                 if (amon_cpu_avail(i)) {
123                         set_cpu_possible(i, true);
124                         __cpu_number_map[i]     = ++ncpu;
125                         __cpu_logical_map[ncpu] = i;
126                 }
127         }
128
129         if (cpu_has_mipsmt) {
130                 unsigned int nvpe = 1;
131 #ifdef CONFIG_MIPS_MT_SMP
132                 unsigned int mvpconf0 = read_c0_mvpconf0();
133
134                 nvpe = ((mvpconf0 & MVPCONF0_PVPE) >> MVPCONF0_PVPE_SHIFT) + 1;
135 #endif
136                 smp_num_siblings = nvpe;
137         }
138         pr_info("Detected %i available secondary CPU(s)\n", ncpu);
139 }
140
141 void __init cmp_prepare_cpus(unsigned int max_cpus)
142 {
143         pr_debug("SMPCMP: CPU%d: %s max_cpus=%d\n",
144                  smp_processor_id(), __func__, max_cpus);
145
146 #ifdef CONFIG_MIPS_MT
147         /*
148          * FIXME: some of these options are per-system, some per-core and
149          * some per-cpu
150          */
151         mips_mt_set_cpuoptions();
152 #endif
153
154 }
155
156 struct plat_smp_ops cmp_smp_ops = {
157         .send_ipi_single        = gic_send_ipi_single,
158         .send_ipi_mask          = gic_send_ipi_mask,
159         .init_secondary         = cmp_init_secondary,
160         .smp_finish             = cmp_smp_finish,
161         .cpus_done              = cmp_cpus_done,
162         .boot_secondary         = cmp_boot_secondary,
163         .smp_setup              = cmp_smp_setup,
164         .prepare_cpus           = cmp_prepare_cpus,
165 };