kvm tools, setup: Create private directory
[linux-2.6/next.git] / arch / mips / netlogic / xlr / smp.c
blobb495a7f1433b5f74054dd80e7b22f0d8dee7263f
1 /*
2 * Copyright 2003-2011 NetLogic Microsystems, Inc. (NetLogic). All rights
3 * reserved.
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:
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
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>
46 #include <asm/netlogic/xlr/iomap.h>
47 #include <asm/netlogic/xlr/pic.h>
48 #include <asm/netlogic/xlr/xlr.h>
50 void core_send_ipi(int logical_cpu, unsigned int action)
52 int cpu = cpu_logical_map(logical_cpu);
53 u32 tid = cpu & 0x3;
54 u32 pid = (cpu >> 2) & 0x07;
55 u32 ipi = (tid << 16) | (pid << 20);
57 if (action & SMP_CALL_FUNCTION)
58 ipi |= IRQ_IPI_SMP_FUNCTION;
59 else if (action & SMP_RESCHEDULE_YOURSELF)
60 ipi |= IRQ_IPI_SMP_RESCHEDULE;
61 else
62 return;
64 pic_send_ipi(ipi);
67 void nlm_send_ipi_single(int cpu, unsigned int action)
69 core_send_ipi(cpu, action);
72 void nlm_send_ipi_mask(const struct cpumask *mask, unsigned int action)
74 int cpu;
76 for_each_cpu(cpu, mask) {
77 core_send_ipi(cpu, action);
81 /* IRQ_IPI_SMP_FUNCTION Handler */
82 void nlm_smp_function_ipi_handler(unsigned int irq, struct irq_desc *desc)
84 smp_call_function_interrupt();
87 /* IRQ_IPI_SMP_RESCHEDULE handler */
88 void nlm_smp_resched_ipi_handler(unsigned int irq, struct irq_desc *desc)
90 set_need_resched();
93 void nlm_common_ipi_handler(int irq, struct pt_regs *regs)
95 if (irq == IRQ_IPI_SMP_FUNCTION) {
96 smp_call_function_interrupt();
97 } else {
98 /* Announce that we are for reschduling */
99 set_need_resched();
104 * Called before going into mips code, early cpu init
106 void nlm_early_init_secondary(void)
108 write_c0_ebase((uint32_t)nlm_common_ebase);
109 /* TLB partition here later */
113 * Code to run on secondary just after probing the CPU
115 static void __cpuinit nlm_init_secondary(void)
117 nlm_smp_irq_init();
120 void nlm_smp_finish(void)
122 #ifdef notyet
123 nlm_common_msgring_cpu_init();
124 #endif
127 void nlm_cpus_done(void)
132 * Boot all other cpus in the system, initialize them, and bring them into
133 * the boot function
135 int nlm_cpu_unblock[NR_CPUS];
136 int nlm_cpu_ready[NR_CPUS];
137 unsigned long nlm_next_gp;
138 unsigned long nlm_next_sp;
139 cpumask_t phys_cpu_present_map;
141 void nlm_boot_secondary(int logical_cpu, struct task_struct *idle)
143 unsigned long gp = (unsigned long)task_thread_info(idle);
144 unsigned long sp = (unsigned long)__KSTK_TOS(idle);
145 int cpu = cpu_logical_map(logical_cpu);
147 nlm_next_sp = sp;
148 nlm_next_gp = gp;
150 /* barrier */
151 __sync();
152 nlm_cpu_unblock[cpu] = 1;
155 void __init nlm_smp_setup(void)
157 unsigned int boot_cpu;
158 int num_cpus, i;
160 boot_cpu = hard_smp_processor_id();
161 cpus_clear(phys_cpu_present_map);
163 cpu_set(boot_cpu, phys_cpu_present_map);
164 __cpu_number_map[boot_cpu] = 0;
165 __cpu_logical_map[0] = boot_cpu;
166 cpu_set(0, cpu_possible_map);
168 num_cpus = 1;
169 for (i = 0; i < NR_CPUS; i++) {
170 if (nlm_cpu_ready[i]) {
171 cpu_set(i, phys_cpu_present_map);
172 __cpu_number_map[i] = num_cpus;
173 __cpu_logical_map[num_cpus] = i;
174 cpu_set(num_cpus, cpu_possible_map);
175 ++num_cpus;
179 pr_info("Phys CPU present map: %lx, possible map %lx\n",
180 (unsigned long)phys_cpu_present_map.bits[0],
181 (unsigned long)cpu_possible_map.bits[0]);
183 pr_info("Detected %i Slave CPU(s)\n", num_cpus);
186 void nlm_prepare_cpus(unsigned int max_cpus)
190 struct plat_smp_ops nlm_smp_ops = {
191 .send_ipi_single = nlm_send_ipi_single,
192 .send_ipi_mask = nlm_send_ipi_mask,
193 .init_secondary = nlm_init_secondary,
194 .smp_finish = nlm_smp_finish,
195 .cpus_done = nlm_cpus_done,
196 .boot_secondary = nlm_boot_secondary,
197 .smp_setup = nlm_smp_setup,
198 .prepare_cpus = nlm_prepare_cpus,
201 unsigned long secondary_entry_point;
203 int nlm_wakeup_secondary_cpus(u32 wakeup_mask)
205 unsigned int tid, pid, ipi, i, boot_cpu;
206 void *reset_vec;
208 secondary_entry_point = (unsigned long)prom_pre_boot_secondary_cpus;
209 reset_vec = (void *)CKSEG1ADDR(0x1fc00000);
210 memcpy(reset_vec, nlm_boot_smp_nmi, 0x80);
211 boot_cpu = hard_smp_processor_id();
213 for (i = 0; i < NR_CPUS; i++) {
214 if (i == boot_cpu)
215 continue;
216 if (wakeup_mask & (1u << i)) {
217 tid = i & 0x3;
218 pid = (i >> 2) & 0x7;
219 ipi = (tid << 16) | (pid << 20) | (1 << 8);
220 pic_send_ipi(ipi);
224 return 0;