blob: 0672463df20ce6abc3f53b8d2531f1af5fb64e68 [file] [log] [blame]
Richard Kuo43afdf52011-10-31 18:46:34 -05001/*
2 * SMP support for Hexagon
3 *
4 * Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved.
5 *
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.
9 *
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.
14 *
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
18 * 02110-1301, USA.
19 */
20
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>
31
Richard Kuo43afdf52011-10-31 18:46:34 -050032#include <asm/time.h> /* timer_interrupt */
33#include <asm/hexagon_vm.h>
34
35#define BASE_IPI_IRQ 26
36
37/*
Rusty Russell0b5f9c02012-03-29 15:38:30 +103038 * cpu_possible_mask needs to be filled out prior to setup_per_cpu_areas
Richard Kuo43afdf52011-10-31 18:46:34 -050039 * (which is prior to any of our smp_prepare_cpu crap), in order to set
40 * up the... per_cpu areas.
41 */
42
43struct ipi_data {
44 unsigned long bits;
45};
46
47static DEFINE_PER_CPU(struct ipi_data, ipi_data);
48
49static inline void __handle_ipi(unsigned long *ops, struct ipi_data *ipi,
50 int cpu)
51{
52 unsigned long msg = 0;
53 do {
54 msg = find_next_bit(ops, BITS_PER_LONG, msg+1);
55
56 switch (msg) {
57
58 case IPI_TIMER:
59 ipi_timer();
60 break;
61
62 case IPI_CALL_FUNC:
63 generic_smp_call_function_interrupt();
64 break;
65
66 case IPI_CALL_FUNC_SINGLE:
67 generic_smp_call_function_single_interrupt();
68 break;
69
70 case IPI_CPU_STOP:
71 /*
72 * call vmstop()
73 */
74 __vmstop();
75 break;
76
77 case IPI_RESCHEDULE:
78 scheduler_ipi();
79 break;
80 }
81 } while (msg < BITS_PER_LONG);
82}
83
84/* Used for IPI call from other CPU's to unmask int */
85void smp_vm_unmask_irq(void *info)
86{
87 __vmintop_locen((long) info);
88}
89
90
91/*
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.
95 */
96
97irqreturn_t handle_ipi(int irq, void *desc)
98{
99 int cpu = smp_processor_id();
100 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
101 unsigned long ops;
102
103 while ((ops = xchg(&ipi->bits, 0)) != 0)
104 __handle_ipi(&ops, ipi, cpu);
105 return IRQ_HANDLED;
106}
107
108void send_ipi(const struct cpumask *cpumask, enum ipi_message_type msg)
109{
110 unsigned long flags;
111 unsigned long cpu;
112 unsigned long retval;
113
114 local_irq_save(flags);
115
116 for_each_cpu(cpu, cpumask) {
117 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
118
119 set_bit(msg, &ipi->bits);
120 /* Possible barrier here */
121 retval = __vmintop_post(BASE_IPI_IRQ+cpu);
122
123 if (retval != 0) {
124 printk(KERN_ERR "interrupt %ld not configured?\n",
125 BASE_IPI_IRQ+cpu);
126 }
127 }
128
129 local_irq_restore(flags);
130}
131
132static struct irqaction ipi_intdesc = {
133 .handler = handle_ipi,
134 .flags = IRQF_TRIGGER_RISING,
135 .name = "ipi_handler"
136};
137
138void __init smp_prepare_boot_cpu(void)
139{
140}
141
142/*
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
146 */
147
148void __cpuinit start_secondary(void)
149{
150 unsigned int cpu;
151 unsigned long thread_ptr;
152
153 /* Calculate thread_info pointer from stack pointer */
154 __asm__ __volatile__(
155 "%0 = SP;\n"
156 : "=r" (thread_ptr)
157 );
158
159 thread_ptr = thread_ptr & ~(THREAD_SIZE-1);
160
161 __asm__ __volatile__(
162 QUOTED_THREADINFO_REG " = %0;\n"
163 :
164 : "r" (thread_ptr)
165 );
166
167 /* Set the memory struct */
168 atomic_inc(&init_mm.mm_count);
169 current->active_mm = &init_mm;
170
171 cpu = smp_processor_id();
172
173 setup_irq(BASE_IPI_IRQ + cpu, &ipi_intdesc);
174
175 /* Register the clock_event dummy */
176 setup_percpu_clockdev();
177
178 printk(KERN_INFO "%s cpu %d\n", __func__, current_thread_info()->cpu);
179
Srivatsa S. Bhat57f27cc2012-03-22 16:58:25 +0530180 notify_cpu_starting(cpu);
181
182 ipi_call_lock();
Richard Kuo43afdf52011-10-31 18:46:34 -0500183 set_cpu_online(cpu, true);
Srivatsa S. Bhat57f27cc2012-03-22 16:58:25 +0530184 ipi_call_unlock();
185
Richard Kuo43afdf52011-10-31 18:46:34 -0500186 local_irq_enable();
187
188 cpu_idle();
189}
190
191
192/*
193 * called once for each present cpu
194 * apparently starts up the CPU and then
195 * maintains control until "cpu_online(cpu)" is set.
196 */
197
198int __cpuinit __cpu_up(unsigned int cpu)
199{
200 struct task_struct *idle;
201 struct thread_info *thread;
202 void *stack_start;
203
204 /* Create new init task for the CPU */
205 idle = fork_idle(cpu);
206 if (IS_ERR(idle))
207 panic(KERN_ERR "fork_idle failed\n");
208
209 thread = (struct thread_info *)idle->stack;
210 thread->cpu = cpu;
211
212 /* Boot to the head. */
213 stack_start = ((void *) thread) + THREAD_SIZE;
214 __vmstart(start_secondary, stack_start);
215
Rusty Russell0b5f9c02012-03-29 15:38:30 +1030216 while (!cpu_online(cpu))
Richard Kuo43afdf52011-10-31 18:46:34 -0500217 barrier();
218
219 return 0;
220}
221
222void __init smp_cpus_done(unsigned int max_cpus)
223{
224}
225
226void __init smp_prepare_cpus(unsigned int max_cpus)
227{
228 int i;
229
230 /*
231 * should eventually have some sort of machine
232 * descriptor that has this stuff
233 */
234
235 /* Right now, let's just fake it. */
236 for (i = 0; i < max_cpus; i++)
Rusty Russell0b5f9c02012-03-29 15:38:30 +1030237 set_cpu_present(i, true);
Richard Kuo43afdf52011-10-31 18:46:34 -0500238
239 /* Also need to register the interrupts for IPI */
240 if (max_cpus > 1)
241 setup_irq(BASE_IPI_IRQ, &ipi_intdesc);
242}
243
244void smp_send_reschedule(int cpu)
245{
246 send_ipi(cpumask_of(cpu), IPI_RESCHEDULE);
247}
248
249void smp_send_stop(void)
250{
251 struct cpumask targets;
252 cpumask_copy(&targets, cpu_online_mask);
253 cpumask_clear_cpu(smp_processor_id(), &targets);
254 send_ipi(&targets, IPI_CPU_STOP);
255}
256
257void arch_send_call_function_single_ipi(int cpu)
258{
259 send_ipi(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE);
260}
261
262void arch_send_call_function_ipi_mask(const struct cpumask *mask)
263{
264 send_ipi(mask, IPI_CALL_FUNC);
265}
266
267int setup_profiling_timer(unsigned int multiplier)
268{
269 return -EINVAL;
270}
271
272void smp_start_cpus(void)
273{
274 int i;
275
276 for (i = 0; i < NR_CPUS; i++)
Rusty Russell0b5f9c02012-03-29 15:38:30 +1030277 set_cpu_possible(i, true);
Richard Kuo43afdf52011-10-31 18:46:34 -0500278}