blob: c1960439f7e14193c012e1933df2acd09c24aba8 [file] [log] [blame]
Jayachandran C5c642502011-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 C5c642502011-05-07 01:36:40 +053047
Jayachandran C65040e22011-11-16 00:21:28 +000048#if defined(CONFIG_CPU_XLP)
49#include <asm/netlogic/xlp-hal/iomap.h>
50#include <asm/netlogic/xlp-hal/pic.h>
51#elif defined(CONFIG_CPU_XLR)
Jayachandran C5c642502011-05-07 01:36:40 +053052#include <asm/netlogic/xlr/iomap.h>
53#include <asm/netlogic/xlr/pic.h>
Jayachandran C65040e22011-11-16 00:21:28 +000054#else
55#error "Unknown CPU"
56#endif
Jayachandran C5c642502011-05-07 01:36:40 +053057
Jayachandran C0c965402011-11-11 17:08:29 +053058void nlm_send_ipi_single(int logical_cpu, unsigned int action)
Jayachandran C5c642502011-05-07 01:36:40 +053059{
60 int cpu = cpu_logical_map(logical_cpu);
Jayachandran C5c642502011-05-07 01:36:40 +053061
62 if (action & SMP_CALL_FUNCTION)
Jayachandran C0c965402011-11-11 17:08:29 +053063 nlm_pic_send_ipi(nlm_pic_base, cpu, IRQ_IPI_SMP_FUNCTION, 0);
64 if (action & SMP_RESCHEDULE_YOURSELF)
65 nlm_pic_send_ipi(nlm_pic_base, cpu, IRQ_IPI_SMP_RESCHEDULE, 0);
Jayachandran C5c642502011-05-07 01:36:40 +053066}
67
68void nlm_send_ipi_mask(const struct cpumask *mask, unsigned int action)
69{
70 int cpu;
71
72 for_each_cpu(cpu, mask) {
Jayachandran C0c965402011-11-11 17:08:29 +053073 nlm_send_ipi_single(cpu, action);
Jayachandran C5c642502011-05-07 01:36:40 +053074 }
75}
76
77/* IRQ_IPI_SMP_FUNCTION Handler */
78void nlm_smp_function_ipi_handler(unsigned int irq, struct irq_desc *desc)
79{
Jayachandran C0c965402011-11-11 17:08:29 +053080 write_c0_eirr(1ull << irq);
Jayachandran C65040e22011-11-16 00:21:28 +000081 smp_call_function_interrupt();
Jayachandran C5c642502011-05-07 01:36:40 +053082}
83
84/* IRQ_IPI_SMP_RESCHEDULE handler */
85void nlm_smp_resched_ipi_handler(unsigned int irq, struct irq_desc *desc)
86{
Jayachandran C0c965402011-11-11 17:08:29 +053087 write_c0_eirr(1ull << irq);
Jayachandran C65040e22011-11-16 00:21:28 +000088 scheduler_ipi();
Jayachandran C5c642502011-05-07 01:36:40 +053089}
90
91/*
92 * Called before going into mips code, early cpu init
93 */
Jayachandran C0c965402011-11-11 17:08:29 +053094void nlm_early_init_secondary(int cpu)
Jayachandran C5c642502011-05-07 01:36:40 +053095{
Jayachandran C65040e22011-11-16 00:21:28 +000096 change_c0_config(CONF_CM_CMASK, 0x3);
Jayachandran C5c642502011-05-07 01:36:40 +053097 write_c0_ebase((uint32_t)nlm_common_ebase);
Jayachandran C65040e22011-11-16 00:21:28 +000098#ifdef CONFIG_CPU_XLP
99 if (hard_smp_processor_id() % 4 == 0)
Jayachandran C0c965402011-11-11 17:08:29 +0530100 xlp_mmu_init();
101#endif
Jayachandran C5c642502011-05-07 01:36:40 +0530102}
103
104/*
105 * Code to run on secondary just after probing the CPU
106 */
107static void __cpuinit nlm_init_secondary(void)
108{
109 nlm_smp_irq_init();
110}
111
112void nlm_smp_finish(void)
113{
114#ifdef notyet
115 nlm_common_msgring_cpu_init();
116#endif
Jayachandran C39263ee2011-06-07 03:14:12 +0530117 local_irq_enable();
Jayachandran C5c642502011-05-07 01:36:40 +0530118}
119
120void nlm_cpus_done(void)
121{
122}
123
124/*
125 * Boot all other cpus in the system, initialize them, and bring them into
126 * the boot function
127 */
128int nlm_cpu_unblock[NR_CPUS];
129int nlm_cpu_ready[NR_CPUS];
130unsigned long nlm_next_gp;
131unsigned long nlm_next_sp;
132cpumask_t phys_cpu_present_map;
133
134void nlm_boot_secondary(int logical_cpu, struct task_struct *idle)
135{
136 unsigned long gp = (unsigned long)task_thread_info(idle);
137 unsigned long sp = (unsigned long)__KSTK_TOS(idle);
138 int cpu = cpu_logical_map(logical_cpu);
139
140 nlm_next_sp = sp;
141 nlm_next_gp = gp;
142
143 /* barrier */
144 __sync();
145 nlm_cpu_unblock[cpu] = 1;
146}
147
148void __init nlm_smp_setup(void)
149{
150 unsigned int boot_cpu;
151 int num_cpus, i;
152
153 boot_cpu = hard_smp_processor_id();
154 cpus_clear(phys_cpu_present_map);
155
156 cpu_set(boot_cpu, phys_cpu_present_map);
157 __cpu_number_map[boot_cpu] = 0;
158 __cpu_logical_map[0] = boot_cpu;
159 cpu_set(0, cpu_possible_map);
160
161 num_cpus = 1;
162 for (i = 0; i < NR_CPUS; i++) {
Hillf Dantonb2788962011-09-24 02:29:54 +0200163 /*
Jayachandran C0c965402011-11-11 17:08:29 +0530164 * nlm_cpu_ready array is not set for the boot_cpu,
165 * it is only set for ASPs (see smpboot.S)
Hillf Dantonb2788962011-09-24 02:29:54 +0200166 */
Jayachandran C5c642502011-05-07 01:36:40 +0530167 if (nlm_cpu_ready[i]) {
168 cpu_set(i, phys_cpu_present_map);
169 __cpu_number_map[i] = num_cpus;
170 __cpu_logical_map[num_cpus] = i;
171 cpu_set(num_cpus, cpu_possible_map);
172 ++num_cpus;
173 }
174 }
175
176 pr_info("Phys CPU present map: %lx, possible map %lx\n",
177 (unsigned long)phys_cpu_present_map.bits[0],
178 (unsigned long)cpu_possible_map.bits[0]);
179
180 pr_info("Detected %i Slave CPU(s)\n", num_cpus);
181}
182
183void nlm_prepare_cpus(unsigned int max_cpus)
184{
185}
186
187struct plat_smp_ops nlm_smp_ops = {
188 .send_ipi_single = nlm_send_ipi_single,
189 .send_ipi_mask = nlm_send_ipi_mask,
190 .init_secondary = nlm_init_secondary,
191 .smp_finish = nlm_smp_finish,
192 .cpus_done = nlm_cpus_done,
193 .boot_secondary = nlm_boot_secondary,
194 .smp_setup = nlm_smp_setup,
195 .prepare_cpus = nlm_prepare_cpus,
196};