blob: 3b32c834d14cfa141894df3313fe2f8260a82145 [file] [log] [blame]
Jayachandran C5c64250672011-05-07 01:36:40 +05301/*
2 * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
3 * reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the NetLogic
9 * license below:
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * THIS SOFTWARE IS PROVIDED BY NETLOGIC ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL NETLOGIC OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include <linux/kernel.h>
36#include <linux/delay.h>
37#include <linux/init.h>
38#include <linux/smp.h>
39#include <linux/irq.h>
40
41#include <asm/mmu_context.h>
42
43#include <asm/netlogic/interrupt.h>
44#include <asm/netlogic/mips-extns.h>
Jayachandran C0c965402011-11-11 17:08:29 +053045#include <asm/netlogic/haldefs.h>
46#include <asm/netlogic/common.h>
Jayachandran C5c64250672011-05-07 01:36:40 +053047
48#include <asm/netlogic/xlr/iomap.h>
49#include <asm/netlogic/xlr/pic.h>
Jayachandran C5c64250672011-05-07 01:36:40 +053050
Jayachandran C0c965402011-11-11 17:08:29 +053051void nlm_send_ipi_single(int logical_cpu, unsigned int action)
Jayachandran C5c64250672011-05-07 01:36:40 +053052{
53 int cpu = cpu_logical_map(logical_cpu);
Jayachandran C5c64250672011-05-07 01:36:40 +053054
55 if (action & SMP_CALL_FUNCTION)
Jayachandran C0c965402011-11-11 17:08:29 +053056 nlm_pic_send_ipi(nlm_pic_base, cpu, IRQ_IPI_SMP_FUNCTION, 0);
57 if (action & SMP_RESCHEDULE_YOURSELF)
58 nlm_pic_send_ipi(nlm_pic_base, cpu, IRQ_IPI_SMP_RESCHEDULE, 0);
Jayachandran C5c64250672011-05-07 01:36:40 +053059}
60
61void nlm_send_ipi_mask(const struct cpumask *mask, unsigned int action)
62{
63 int cpu;
64
65 for_each_cpu(cpu, mask) {
Jayachandran C0c965402011-11-11 17:08:29 +053066 nlm_send_ipi_single(cpu, action);
Jayachandran C5c64250672011-05-07 01:36:40 +053067 }
68}
69
70/* IRQ_IPI_SMP_FUNCTION Handler */
71void nlm_smp_function_ipi_handler(unsigned int irq, struct irq_desc *desc)
72{
73 smp_call_function_interrupt();
Jayachandran C0c965402011-11-11 17:08:29 +053074 write_c0_eirr(1ull << irq);
Jayachandran C5c64250672011-05-07 01:36:40 +053075}
76
77/* IRQ_IPI_SMP_RESCHEDULE handler */
78void nlm_smp_resched_ipi_handler(unsigned int irq, struct irq_desc *desc)
79{
Jayachandran C39263ee2011-06-07 03:14:12 +053080 scheduler_ipi();
Jayachandran C0c965402011-11-11 17:08:29 +053081 write_c0_eirr(1ull << irq);
Jayachandran C5c64250672011-05-07 01:36:40 +053082}
83
84/*
85 * Called before going into mips code, early cpu init
86 */
Jayachandran C0c965402011-11-11 17:08:29 +053087void nlm_early_init_secondary(int cpu)
Jayachandran C5c64250672011-05-07 01:36:40 +053088{
89 write_c0_ebase((uint32_t)nlm_common_ebase);
Jayachandran C0c965402011-11-11 17:08:29 +053090#ifdef NLM_XLP
91 if (cpu % 4 == 0)
92 xlp_mmu_init();
93#endif
Jayachandran C5c64250672011-05-07 01:36:40 +053094}
95
96/*
97 * Code to run on secondary just after probing the CPU
98 */
99static void __cpuinit nlm_init_secondary(void)
100{
101 nlm_smp_irq_init();
102}
103
104void nlm_smp_finish(void)
105{
106#ifdef notyet
107 nlm_common_msgring_cpu_init();
108#endif
Jayachandran C39263ee2011-06-07 03:14:12 +0530109 local_irq_enable();
Jayachandran C5c64250672011-05-07 01:36:40 +0530110}
111
112void nlm_cpus_done(void)
113{
114}
115
116/*
117 * Boot all other cpus in the system, initialize them, and bring them into
118 * the boot function
119 */
120int nlm_cpu_unblock[NR_CPUS];
121int nlm_cpu_ready[NR_CPUS];
122unsigned long nlm_next_gp;
123unsigned long nlm_next_sp;
124cpumask_t phys_cpu_present_map;
125
126void nlm_boot_secondary(int logical_cpu, struct task_struct *idle)
127{
128 unsigned long gp = (unsigned long)task_thread_info(idle);
129 unsigned long sp = (unsigned long)__KSTK_TOS(idle);
130 int cpu = cpu_logical_map(logical_cpu);
131
132 nlm_next_sp = sp;
133 nlm_next_gp = gp;
134
135 /* barrier */
136 __sync();
137 nlm_cpu_unblock[cpu] = 1;
138}
139
140void __init nlm_smp_setup(void)
141{
142 unsigned int boot_cpu;
143 int num_cpus, i;
144
145 boot_cpu = hard_smp_processor_id();
146 cpus_clear(phys_cpu_present_map);
147
148 cpu_set(boot_cpu, phys_cpu_present_map);
149 __cpu_number_map[boot_cpu] = 0;
150 __cpu_logical_map[0] = boot_cpu;
151 cpu_set(0, cpu_possible_map);
152
153 num_cpus = 1;
154 for (i = 0; i < NR_CPUS; i++) {
Hillf Dantonb2788962011-09-24 02:29:54 +0200155 /*
Jayachandran C0c965402011-11-11 17:08:29 +0530156 * nlm_cpu_ready array is not set for the boot_cpu,
157 * it is only set for ASPs (see smpboot.S)
Hillf Dantonb2788962011-09-24 02:29:54 +0200158 */
Jayachandran C5c64250672011-05-07 01:36:40 +0530159 if (nlm_cpu_ready[i]) {
160 cpu_set(i, phys_cpu_present_map);
161 __cpu_number_map[i] = num_cpus;
162 __cpu_logical_map[num_cpus] = i;
163 cpu_set(num_cpus, cpu_possible_map);
164 ++num_cpus;
165 }
166 }
167
168 pr_info("Phys CPU present map: %lx, possible map %lx\n",
169 (unsigned long)phys_cpu_present_map.bits[0],
170 (unsigned long)cpu_possible_map.bits[0]);
171
172 pr_info("Detected %i Slave CPU(s)\n", num_cpus);
173}
174
175void nlm_prepare_cpus(unsigned int max_cpus)
176{
177}
178
179struct plat_smp_ops nlm_smp_ops = {
180 .send_ipi_single = nlm_send_ipi_single,
181 .send_ipi_mask = nlm_send_ipi_mask,
182 .init_secondary = nlm_init_secondary,
183 .smp_finish = nlm_smp_finish,
184 .cpus_done = nlm_cpus_done,
185 .boot_secondary = nlm_boot_secondary,
186 .smp_setup = nlm_smp_setup,
187 .prepare_cpus = nlm_prepare_cpus,
188};