aboutsummaryrefslogtreecommitdiffstats
path: root/arch/hexagon
diff options
context:
space:
mode:
authorRichard Kuo <rkuo@codeaurora.org>2011-10-31 19:46:34 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-11-01 10:34:20 -0400
commit43afdf508386342d714f6911c1976f934b520cb0 (patch)
treede4acc7cca0990d28be24fa4f6779ef4e31945e5 /arch/hexagon
parentcf9750bae262dba73a6abaecd2ec3731ba7aef9c (diff)
Hexagon: Add SMP support
Signed-off-by: Richard Kuo <rkuo@codeaurora.org> Signed-off-by: Linas Vepstas <linas@codeaurora.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch/hexagon')
-rw-r--r--arch/hexagon/include/asm/smp.h44
-rw-r--r--arch/hexagon/kernel/smp.c276
-rw-r--r--arch/hexagon/kernel/topology.c52
3 files changed, 372 insertions, 0 deletions
diff --git a/arch/hexagon/include/asm/smp.h b/arch/hexagon/include/asm/smp.h
new file mode 100644
index 000000000000..87c869a6a897
--- /dev/null
+++ b/arch/hexagon/include/asm/smp.h
@@ -0,0 +1,44 @@
1/*
2 * SMP definitions for the Hexagon architecture
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#ifndef __ASM_SMP_H
22#define __ASM_SMP_H
23
24#include <linux/cpumask.h>
25
26#define raw_smp_processor_id() (current_thread_info()->cpu)
27
28enum ipi_message_type {
29 IPI_NOP = 0,
30 IPI_RESCHEDULE = 1,
31 IPI_CALL_FUNC,
32 IPI_CALL_FUNC_SINGLE,
33 IPI_CPU_STOP,
34 IPI_TIMER,
35};
36
37extern void send_ipi(const struct cpumask *cpumask, enum ipi_message_type msg);
38extern void smp_start_cpus(void);
39extern void arch_send_call_function_single_ipi(int cpu);
40extern void arch_send_call_function_ipi_mask(const struct cpumask *mask);
41
42extern void smp_vm_unmask_irq(void *info);
43
44#endif
diff --git a/arch/hexagon/kernel/smp.c b/arch/hexagon/kernel/smp.c
new file mode 100644
index 000000000000..c871a2cffaef
--- /dev/null
+++ b/arch/hexagon/kernel/smp.c
@@ -0,0 +1,276 @@
1/*
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
32#include <asm/system.h> /* xchg */
33#include <asm/time.h> /* timer_interrupt */
34#include <asm/hexagon_vm.h>
35
36#define BASE_IPI_IRQ 26
37
38/*
39 * cpu_possible_map needs to be filled out prior to setup_per_cpu_areas
40 * (which is prior to any of our smp_prepare_cpu crap), in order to set
41 * up the... per_cpu areas.
42 */
43
44struct ipi_data {
45 unsigned long bits;
46};
47
48static DEFINE_PER_CPU(struct ipi_data, ipi_data);
49
50static inline void __handle_ipi(unsigned long *ops, struct ipi_data *ipi,
51 int cpu)
52{
53 unsigned long msg = 0;
54 do {
55 msg = find_next_bit(ops, BITS_PER_LONG, msg+1);
56
57 switch (msg) {
58
59 case IPI_TIMER:
60 ipi_timer();
61 break;
62
63 case IPI_CALL_FUNC:
64 generic_smp_call_function_interrupt();
65 break;
66
67 case IPI_CALL_FUNC_SINGLE:
68 generic_smp_call_function_single_interrupt();
69 break;
70
71 case IPI_CPU_STOP:
72 /*
73 * call vmstop()
74 */
75 __vmstop();
76 break;
77
78 case IPI_RESCHEDULE:
79 scheduler_ipi();
80 break;
81 }
82 } while (msg < BITS_PER_LONG);
83}
84
85/* Used for IPI call from other CPU's to unmask int */
86void smp_vm_unmask_irq(void *info)
87{
88 __vmintop_locen((long) info);
89}
90
91
92/*
93 * This is based on Alpha's IPI stuff.
94 * Supposed to take (int, void*) as args now.
95 * Specifically, first arg is irq, second is the irq_desc.
96 */
97
98irqreturn_t handle_ipi(int irq, void *desc)
99{
100 int cpu = smp_processor_id();
101 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
102 unsigned long ops;
103
104 while ((ops = xchg(&ipi->bits, 0)) != 0)
105 __handle_ipi(&ops, ipi, cpu);
106 return IRQ_HANDLED;
107}
108
109void send_ipi(const struct cpumask *cpumask, enum ipi_message_type msg)
110{
111 unsigned long flags;
112 unsigned long cpu;
113 unsigned long retval;
114
115 local_irq_save(flags);
116
117 for_each_cpu(cpu, cpumask) {
118 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
119
120 set_bit(msg, &ipi->bits);
121 /* Possible barrier here */
122 retval = __vmintop_post(BASE_IPI_IRQ+cpu);
123
124 if (retval != 0) {
125 printk(KERN_ERR "interrupt %ld not configured?\n",
126 BASE_IPI_IRQ+cpu);
127 }
128 }
129
130 local_irq_restore(flags);
131}
132
133static struct irqaction ipi_intdesc = {
134 .handler = handle_ipi,
135 .flags = IRQF_TRIGGER_RISING,
136 .name = "ipi_handler"
137};
138
139void __init smp_prepare_boot_cpu(void)
140{
141}
142
143/*
144 * interrupts should already be disabled from the VM
145 * SP should already be correct; need to set THREADINFO_REG
146 * to point to current thread info
147 */
148
149void __cpuinit start_secondary(void)
150{
151 unsigned int cpu;
152 unsigned long thread_ptr;
153
154 /* Calculate thread_info pointer from stack pointer */
155 __asm__ __volatile__(
156 "%0 = SP;\n"
157 : "=r" (thread_ptr)
158 );
159
160 thread_ptr = thread_ptr & ~(THREAD_SIZE-1);
161
162 __asm__ __volatile__(
163 QUOTED_THREADINFO_REG " = %0;\n"
164 :
165 : "r" (thread_ptr)
166 );
167
168 /* Set the memory struct */
169 atomic_inc(&init_mm.mm_count);
170 current->active_mm = &init_mm;
171
172 cpu = smp_processor_id();
173
174 setup_irq(BASE_IPI_IRQ + cpu, &ipi_intdesc);
175
176 /* Register the clock_event dummy */
177 setup_percpu_clockdev();
178
179 printk(KERN_INFO "%s cpu %d\n", __func__, current_thread_info()->cpu);
180
181 set_cpu_online(cpu, true);
182 while (!cpumask_test_cpu(cpu, cpu_active_mask))
183 cpu_relax();
184 local_irq_enable();
185
186 cpu_idle();
187}
188
189
190/*
191 * called once for each present cpu
192 * apparently starts up the CPU and then
193 * maintains control until "cpu_online(cpu)" is set.
194 */
195
196int __cpuinit __cpu_up(unsigned int cpu)
197{
198 struct task_struct *idle;
199 struct thread_info *thread;
200 void *stack_start;
201
202 /* Create new init task for the CPU */
203 idle = fork_idle(cpu);
204 if (IS_ERR(idle))
205 panic(KERN_ERR "fork_idle failed\n");
206
207 thread = (struct thread_info *)idle->stack;
208 thread->cpu = cpu;
209
210 /* Boot to the head. */
211 stack_start = ((void *) thread) + THREAD_SIZE;
212 __vmstart(start_secondary, stack_start);
213
214 while (!cpu_isset(cpu, cpu_online_map))
215 barrier();
216
217 return 0;
218}
219
220void __init smp_cpus_done(unsigned int max_cpus)
221{
222}
223
224void __init smp_prepare_cpus(unsigned int max_cpus)
225{
226 int i;
227
228 /*
229 * should eventually have some sort of machine
230 * descriptor that has this stuff
231 */
232
233 /* Right now, let's just fake it. */
234 for (i = 0; i < max_cpus; i++)
235 cpu_set(i, cpu_present_map);
236
237 /* Also need to register the interrupts for IPI */
238 if (max_cpus > 1)
239 setup_irq(BASE_IPI_IRQ, &ipi_intdesc);
240}
241
242void smp_send_reschedule(int cpu)
243{
244 send_ipi(cpumask_of(cpu), IPI_RESCHEDULE);
245}
246
247void smp_send_stop(void)
248{
249 struct cpumask targets;
250 cpumask_copy(&targets, cpu_online_mask);
251 cpumask_clear_cpu(smp_processor_id(), &targets);
252 send_ipi(&targets, IPI_CPU_STOP);
253}
254
255void arch_send_call_function_single_ipi(int cpu)
256{
257 send_ipi(cpumask_of(cpu), IPI_CALL_FUNC_SINGLE);
258}
259
260void arch_send_call_function_ipi_mask(const struct cpumask *mask)
261{
262 send_ipi(mask, IPI_CALL_FUNC);
263}
264
265int setup_profiling_timer(unsigned int multiplier)
266{
267 return -EINVAL;
268}
269
270void smp_start_cpus(void)
271{
272 int i;
273
274 for (i = 0; i < NR_CPUS; i++)
275 cpu_set(i, cpu_possible_map);
276}
diff --git a/arch/hexagon/kernel/topology.c b/arch/hexagon/kernel/topology.c
new file mode 100644
index 000000000000..ba4475184432
--- /dev/null
+++ b/arch/hexagon/kernel/topology.c
@@ -0,0 +1,52 @@
1/*
2 * CPU topology 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/cpu.h>
22#include <linux/cpumask.h>
23#include <linux/init.h>
24#include <linux/node.h>
25#include <linux/nodemask.h>
26#include <linux/percpu.h>
27
28/* Swiped from MIPS. */
29
30static DEFINE_PER_CPU(struct cpu, cpu_devices);
31
32static int __init topology_init(void)
33{
34 int i, ret;
35
36 for_each_present_cpu(i) {
37
38 /*
39 * register_cpu takes a per_cpu pointer and
40 * just points it at another per_cpu struct...
41 */
42
43 ret = register_cpu(&per_cpu(cpu_devices, i), i);
44 if (ret)
45 printk(KERN_WARNING "topology_init: register_cpu %d "
46 "failed (%d)\n", i, ret);
47 }
48
49 return 0;
50}
51
52subsys_initcall(topology_init);