2 * SMP support for Hexagon
4 * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 and
8 * only version 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include <linux/err.h>
22 #include <linux/errno.h>
23 #include <linux/kernel.h>
24 #include <linux/init.h>
25 #include <linux/interrupt.h>
26 #include <linux/module.h>
27 #include <linux/percpu.h>
28 #include <linux/sched.h>
29 #include <linux/smp.h>
30 #include <linux/spinlock.h>
32 #include <asm/time.h> /* timer_interrupt */
33 #include <asm/hexagon_vm.h>
35 #define BASE_IPI_IRQ 26
38 * cpu_possible_map needs to be filled out prior to setup_per_cpu_areas
39 * (which is prior to any of our smp_prepare_cpu crap), in order to set
40 * up the... per_cpu areas.
47 static DEFINE_PER_CPU(struct ipi_data
, ipi_data
);
49 static inline void __handle_ipi(unsigned long *ops
, struct ipi_data
*ipi
,
52 unsigned long msg
= 0;
54 msg
= find_next_bit(ops
, BITS_PER_LONG
, msg
+1);
63 generic_smp_call_function_interrupt();
66 case IPI_CALL_FUNC_SINGLE
:
67 generic_smp_call_function_single_interrupt();
81 } while (msg
< BITS_PER_LONG
);
84 /* Used for IPI call from other CPU's to unmask int */
85 void smp_vm_unmask_irq(void *info
)
87 __vmintop_locen((long) info
);
92 * This is based on Alpha's IPI stuff.
93 * Supposed to take (int, void*) as args now.
94 * Specifically, first arg is irq, second is the irq_desc.
97 irqreturn_t
handle_ipi(int irq
, void *desc
)
99 int cpu
= smp_processor_id();
100 struct ipi_data
*ipi
= &per_cpu(ipi_data
, cpu
);
103 while ((ops
= xchg(&ipi
->bits
, 0)) != 0)
104 __handle_ipi(&ops
, ipi
, cpu
);
108 void send_ipi(const struct cpumask
*cpumask
, enum ipi_message_type msg
)
112 unsigned long retval
;
114 local_irq_save(flags
);
116 for_each_cpu(cpu
, cpumask
) {
117 struct ipi_data
*ipi
= &per_cpu(ipi_data
, cpu
);
119 set_bit(msg
, &ipi
->bits
);
120 /* Possible barrier here */
121 retval
= __vmintop_post(BASE_IPI_IRQ
+cpu
);
124 printk(KERN_ERR
"interrupt %ld not configured?\n",
129 local_irq_restore(flags
);
132 static struct irqaction ipi_intdesc
= {
133 .handler
= handle_ipi
,
134 .flags
= IRQF_TRIGGER_RISING
,
135 .name
= "ipi_handler"
138 void __init
smp_prepare_boot_cpu(void)
143 * interrupts should already be disabled from the VM
144 * SP should already be correct; need to set THREADINFO_REG
145 * to point to current thread info
148 void __cpuinit
start_secondary(void)
151 unsigned long thread_ptr
;
153 /* Calculate thread_info pointer from stack pointer */
154 __asm__
__volatile__(
159 thread_ptr
= thread_ptr
& ~(THREAD_SIZE
-1);
161 __asm__
__volatile__(
162 QUOTED_THREADINFO_REG
" = %0;\n"
167 /* Set the memory struct */
168 atomic_inc(&init_mm
.mm_count
);
169 current
->active_mm
= &init_mm
;
171 cpu
= smp_processor_id();
173 setup_irq(BASE_IPI_IRQ
+ cpu
, &ipi_intdesc
);
175 /* Register the clock_event dummy */
176 setup_percpu_clockdev();
178 printk(KERN_INFO
"%s cpu %d\n", __func__
, current_thread_info()->cpu
);
180 set_cpu_online(cpu
, true);
188 * called once for each present cpu
189 * apparently starts up the CPU and then
190 * maintains control until "cpu_online(cpu)" is set.
193 int __cpuinit
__cpu_up(unsigned int cpu
)
195 struct task_struct
*idle
;
196 struct thread_info
*thread
;
199 /* Create new init task for the CPU */
200 idle
= fork_idle(cpu
);
202 panic(KERN_ERR
"fork_idle failed\n");
204 thread
= (struct thread_info
*)idle
->stack
;
207 /* Boot to the head. */
208 stack_start
= ((void *) thread
) + THREAD_SIZE
;
209 __vmstart(start_secondary
, stack_start
);
211 while (!cpu_isset(cpu
, cpu_online_map
))
217 void __init
smp_cpus_done(unsigned int max_cpus
)
221 void __init
smp_prepare_cpus(unsigned int max_cpus
)
226 * should eventually have some sort of machine
227 * descriptor that has this stuff
230 /* Right now, let's just fake it. */
231 for (i
= 0; i
< max_cpus
; i
++)
232 cpu_set(i
, cpu_present_map
);
234 /* Also need to register the interrupts for IPI */
236 setup_irq(BASE_IPI_IRQ
, &ipi_intdesc
);
239 void smp_send_reschedule(int cpu
)
241 send_ipi(cpumask_of(cpu
), IPI_RESCHEDULE
);
244 void smp_send_stop(void)
246 struct cpumask targets
;
247 cpumask_copy(&targets
, cpu_online_mask
);
248 cpumask_clear_cpu(smp_processor_id(), &targets
);
249 send_ipi(&targets
, IPI_CPU_STOP
);
252 void arch_send_call_function_single_ipi(int cpu
)
254 send_ipi(cpumask_of(cpu
), IPI_CALL_FUNC_SINGLE
);
257 void arch_send_call_function_ipi_mask(const struct cpumask
*mask
)
259 send_ipi(mask
, IPI_CALL_FUNC
);
262 int setup_profiling_timer(unsigned int multiplier
)
267 void smp_start_cpus(void)
271 for (i
= 0; i
< NR_CPUS
; i
++)
272 cpu_set(i
, cpu_possible_map
);