2 * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
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
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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
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.
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>
41 #include <asm/mmu_context.h>
43 #include <asm/netlogic/interrupt.h>
44 #include <asm/netlogic/mips-extns.h>
45 #include <asm/netlogic/haldefs.h>
46 #include <asm/netlogic/common.h>
48 #include <asm/netlogic/xlr/iomap.h>
49 #include <asm/netlogic/xlr/pic.h>
51 void nlm_send_ipi_single(int logical_cpu
, unsigned int action
)
53 int cpu
= cpu_logical_map(logical_cpu
);
55 if (action
& SMP_CALL_FUNCTION
)
56 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);
61 void nlm_send_ipi_mask(const struct cpumask
*mask
, unsigned int action
)
65 for_each_cpu(cpu
, mask
) {
66 nlm_send_ipi_single(cpu
, action
);
70 /* IRQ_IPI_SMP_FUNCTION Handler */
71 void nlm_smp_function_ipi_handler(unsigned int irq
, struct irq_desc
*desc
)
73 smp_call_function_interrupt();
74 write_c0_eirr(1ull << irq
);
77 /* IRQ_IPI_SMP_RESCHEDULE handler */
78 void nlm_smp_resched_ipi_handler(unsigned int irq
, struct irq_desc
*desc
)
81 write_c0_eirr(1ull << irq
);
85 * Called before going into mips code, early cpu init
87 void nlm_early_init_secondary(int cpu
)
89 write_c0_ebase((uint32_t)nlm_common_ebase
);
97 * Code to run on secondary just after probing the CPU
99 static void __cpuinit
nlm_init_secondary(void)
104 void nlm_smp_finish(void)
107 nlm_common_msgring_cpu_init();
112 void nlm_cpus_done(void)
117 * Boot all other cpus in the system, initialize them, and bring them into
120 int nlm_cpu_unblock
[NR_CPUS
];
121 int nlm_cpu_ready
[NR_CPUS
];
122 unsigned long nlm_next_gp
;
123 unsigned long nlm_next_sp
;
124 cpumask_t phys_cpu_present_map
;
126 void nlm_boot_secondary(int logical_cpu
, struct task_struct
*idle
)
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
);
137 nlm_cpu_unblock
[cpu
] = 1;
140 void __init
nlm_smp_setup(void)
142 unsigned int boot_cpu
;
145 boot_cpu
= hard_smp_processor_id();
146 cpus_clear(phys_cpu_present_map
);
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
);
154 for (i
= 0; i
< NR_CPUS
; i
++) {
156 * nlm_cpu_ready array is not set for the boot_cpu,
157 * it is only set for ASPs (see smpboot.S)
159 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
);
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]);
172 pr_info("Detected %i Slave CPU(s)\n", num_cpus
);
175 void nlm_prepare_cpus(unsigned int max_cpus
)
179 struct 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
,