Linux 3.16-rc2
[linux/fpc-iii.git] / arch / hexagon / kernel / smp.c
blobff759f26b96aef8cbffbfc9c860aa7f2966ff27b
1 /*
2 * SMP support for Hexagon
4 * Copyright (c) 2010-2012, The Linux Foundation. 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
18 * 02110-1301, USA.
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 #include <linux/cpu.h>
33 #include <asm/time.h> /* timer_interrupt */
34 #include <asm/hexagon_vm.h>
36 #define BASE_IPI_IRQ 26
39 * cpu_possible_mask 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.
44 struct ipi_data {
45 unsigned long bits;
48 static DEFINE_PER_CPU(struct ipi_data, ipi_data);
50 static inline void __handle_ipi(unsigned long *ops, struct ipi_data *ipi,
51 int cpu)
53 unsigned long msg = 0;
54 do {
55 msg = find_next_bit(ops, BITS_PER_LONG, msg+1);
57 switch (msg) {
59 case IPI_TIMER:
60 ipi_timer();
61 break;
63 case IPI_CALL_FUNC:
64 generic_smp_call_function_interrupt();
65 break;
67 case IPI_CPU_STOP:
69 * call vmstop()
71 __vmstop();
72 break;
74 case IPI_RESCHEDULE:
75 scheduler_ipi();
76 break;
78 } while (msg < BITS_PER_LONG);
81 /* Used for IPI call from other CPU's to unmask int */
82 void smp_vm_unmask_irq(void *info)
84 __vmintop_locen((long) info);
89 * This is based on Alpha's IPI stuff.
90 * Supposed to take (int, void*) as args now.
91 * Specifically, first arg is irq, second is the irq_desc.
94 irqreturn_t handle_ipi(int irq, void *desc)
96 int cpu = smp_processor_id();
97 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
98 unsigned long ops;
100 while ((ops = xchg(&ipi->bits, 0)) != 0)
101 __handle_ipi(&ops, ipi, cpu);
102 return IRQ_HANDLED;
105 void send_ipi(const struct cpumask *cpumask, enum ipi_message_type msg)
107 unsigned long flags;
108 unsigned long cpu;
109 unsigned long retval;
111 local_irq_save(flags);
113 for_each_cpu(cpu, cpumask) {
114 struct ipi_data *ipi = &per_cpu(ipi_data, cpu);
116 set_bit(msg, &ipi->bits);
117 /* Possible barrier here */
118 retval = __vmintop_post(BASE_IPI_IRQ+cpu);
120 if (retval != 0) {
121 printk(KERN_ERR "interrupt %ld not configured?\n",
122 BASE_IPI_IRQ+cpu);
126 local_irq_restore(flags);
129 static struct irqaction ipi_intdesc = {
130 .handler = handle_ipi,
131 .flags = IRQF_TRIGGER_RISING,
132 .name = "ipi_handler"
135 void __init smp_prepare_boot_cpu(void)
140 * interrupts should already be disabled from the VM
141 * SP should already be correct; need to set THREADINFO_REG
142 * to point to current thread info
145 void start_secondary(void)
147 unsigned int cpu;
148 unsigned long thread_ptr;
150 /* Calculate thread_info pointer from stack pointer */
151 __asm__ __volatile__(
152 "%0 = SP;\n"
153 : "=r" (thread_ptr)
156 thread_ptr = thread_ptr & ~(THREAD_SIZE-1);
158 __asm__ __volatile__(
159 QUOTED_THREADINFO_REG " = %0;\n"
161 : "r" (thread_ptr)
164 /* Set the memory struct */
165 atomic_inc(&init_mm.mm_count);
166 current->active_mm = &init_mm;
168 cpu = smp_processor_id();
170 setup_irq(BASE_IPI_IRQ + cpu, &ipi_intdesc);
172 /* Register the clock_event dummy */
173 setup_percpu_clockdev();
175 printk(KERN_INFO "%s cpu %d\n", __func__, current_thread_info()->cpu);
177 notify_cpu_starting(cpu);
179 set_cpu_online(cpu, true);
181 local_irq_enable();
183 cpu_startup_entry(CPUHP_ONLINE);
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 __cpu_up(unsigned int cpu, struct task_struct *idle)
195 struct thread_info *thread = (struct thread_info *)idle->stack;
196 void *stack_start;
198 thread->cpu = cpu;
200 /* Boot to the head. */
201 stack_start = ((void *) thread) + THREAD_SIZE;
202 __vmstart(start_secondary, stack_start);
204 while (!cpu_online(cpu))
205 barrier();
207 return 0;
210 void __init smp_cpus_done(unsigned int max_cpus)
214 void __init smp_prepare_cpus(unsigned int max_cpus)
216 int i;
219 * should eventually have some sort of machine
220 * descriptor that has this stuff
223 /* Right now, let's just fake it. */
224 for (i = 0; i < max_cpus; i++)
225 set_cpu_present(i, true);
227 /* Also need to register the interrupts for IPI */
228 if (max_cpus > 1)
229 setup_irq(BASE_IPI_IRQ, &ipi_intdesc);
232 void smp_send_reschedule(int cpu)
234 send_ipi(cpumask_of(cpu), IPI_RESCHEDULE);
237 void smp_send_stop(void)
239 struct cpumask targets;
240 cpumask_copy(&targets, cpu_online_mask);
241 cpumask_clear_cpu(smp_processor_id(), &targets);
242 send_ipi(&targets, IPI_CPU_STOP);
245 void arch_send_call_function_single_ipi(int cpu)
247 send_ipi(cpumask_of(cpu), IPI_CALL_FUNC);
250 void arch_send_call_function_ipi_mask(const struct cpumask *mask)
252 send_ipi(mask, IPI_CALL_FUNC);
255 int setup_profiling_timer(unsigned int multiplier)
257 return -EINVAL;
260 void smp_start_cpus(void)
262 int i;
264 for (i = 0; i < NR_CPUS; i++)
265 set_cpu_possible(i, true);