blob: 128af73042881a21e0014bb4db30af741626c824 [file] [log] [blame]
Sam Ravnborgaba20a82011-01-28 22:08:20 +00001/*
2 * sun4m SMP support.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
5 */
6
Tkhai Kirill62f08282012-04-04 21:49:26 +02007#include <linux/clockchips.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/profile.h>
Adrian Bunk6c81c322008-02-06 01:37:51 -080010#include <linux/delay.h>
David S. Miller5d83d662012-05-13 20:49:31 -070011#include <linux/sched.h>
Robert Reif4245e592008-10-12 20:52:26 -070012#include <linux/cpu.h>
Adrian Bunk6c81c322008-02-06 01:37:51 -080013
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/cacheflush.h>
Sam Ravnborgbde4d8b2012-03-30 15:53:50 +020015#include <asm/switch_to.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/tlbflush.h>
Tkhai Kirill62f08282012-04-04 21:49:26 +020017#include <asm/timer.h>
David S. Miller5d83d662012-05-13 20:49:31 -070018#include <asm/oplib.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Al Viro32231a62007-07-21 19:18:57 -070020#include "irq.h"
Sam Ravnborgaba20a82011-01-28 22:08:20 +000021#include "kernel.h"
Al Viro32231a62007-07-21 19:18:57 -070022
Daniel Hellstromecbc42b2011-05-02 00:08:53 +000023#define IRQ_IPI_SINGLE 12
24#define IRQ_IPI_MASK 13
25#define IRQ_IPI_RESCHED 14
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#define IRQ_CROSS_CALL 15
27
Wu Fengguang1a8a27c2009-01-07 18:09:10 -080028static inline unsigned long
29swap_ulong(volatile unsigned long *ptr, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
31 __asm__ __volatile__("swap [%1], %0\n\t" :
32 "=&r" (val), "=&r" (ptr) :
33 "0" (val), "1" (ptr));
34 return val;
35}
36
Bob Breuer92d452f2006-06-20 00:36:10 -070037void __cpuinit smp4m_callin(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
39 int cpuid = hard_smp_processor_id();
40
David S. Miller5d83d662012-05-13 20:49:31 -070041 local_ops->cache_all();
42 local_ops->tlb_all();
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Manfred Spraule545a612008-09-07 16:57:22 +020044 notify_cpu_starting(cpuid);
45
Tkhai Kirill62f08282012-04-04 21:49:26 +020046 register_percpu_ce(cpuid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48 calibrate_delay();
49 smp_store_cpu_info(cpuid);
50
David S. Miller5d83d662012-05-13 20:49:31 -070051 local_ops->cache_all();
52 local_ops->tlb_all();
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 /*
55 * Unblock the master CPU _only_ when the scheduler state
56 * of all secondary CPUs will be up-to-date, so after
57 * the SMP initialization the master will be just allowed
58 * to call the scheduler code.
59 */
60 /* Allow master to continue. */
Wu Fengguang1a8a27c2009-01-07 18:09:10 -080061 swap_ulong(&cpu_callin_map[cpuid], 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Bob Breuera54123e2006-03-23 22:36:19 -080063 /* XXX: What's up with all the flushes? */
David S. Miller5d83d662012-05-13 20:49:31 -070064 local_ops->cache_all();
65 local_ops->tlb_all();
Sam Ravnborgaba20a82011-01-28 22:08:20 +000066
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 /* Fix idle thread fields. */
68 __asm__ __volatile__("ld [%0], %%g6\n\t"
69 : : "r" (&current_set[cpuid])
70 : "memory" /* paranoid */);
71
72 /* Attach to the address space of init_task. */
73 atomic_inc(&init_mm.mm_count);
74 current->active_mm = &init_mm;
75
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -070076 while (!cpumask_test_cpu(cpuid, &smp_commenced_mask))
Bob Breuera54123e2006-03-23 22:36:19 -080077 mb();
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79 local_irq_enable();
Bob Breuera54123e2006-03-23 22:36:19 -080080
Rusty Russellfe739712009-03-16 14:40:22 +103081 set_cpu_online(cpuid, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/*
85 * Cycle through the processors asking the PROM to start each one.
86 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087void __init smp4m_boot_cpus(void)
88{
Tkhai Kirill62f08282012-04-04 21:49:26 +020089 sun4m_unmask_profile_irq();
David S. Miller5d83d662012-05-13 20:49:31 -070090 local_ops->cache_all();
Bob Breuera54123e2006-03-23 22:36:19 -080091}
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Thomas Gleixnerf0a2bc72012-04-20 13:05:56 +000093int __cpuinit smp4m_boot_one_cpu(int i, struct task_struct *idle)
Bob Breuera54123e2006-03-23 22:36:19 -080094{
Bob Breuera54123e2006-03-23 22:36:19 -080095 unsigned long *entry = &sun4m_cpu_startup;
Bob Breuera54123e2006-03-23 22:36:19 -080096 int timeout;
97 int cpu_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Bob Breuera54123e2006-03-23 22:36:19 -080099 cpu_find_by_mid(i, &cpu_node);
Thomas Gleixnerf0a2bc72012-04-20 13:05:56 +0000100 current_set[i] = task_thread_info(idle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Bob Breuera54123e2006-03-23 22:36:19 -0800102 /* See trampoline.S for details... */
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000103 entry += ((i - 1) * 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Bob Breuera54123e2006-03-23 22:36:19 -0800105 /*
106 * Initialize the contexts table
107 * Since the call to prom_startcpu() trashes the structure,
108 * we need to re-initialize it for each cpu
109 */
110 smp_penguin_ctable.which_io = 0;
111 smp_penguin_ctable.phys_addr = (unsigned int) srmmu_ctx_table_phys;
112 smp_penguin_ctable.reg_size = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Bob Breuera54123e2006-03-23 22:36:19 -0800114 /* whirrr, whirrr, whirrrrrrrrr... */
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000115 printk(KERN_INFO "Starting CPU %d at %p\n", i, entry);
David S. Miller5d83d662012-05-13 20:49:31 -0700116 local_ops->cache_all();
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000117 prom_startcpu(cpu_node, &smp_penguin_ctable, 0, (char *)entry);
Bob Breuera54123e2006-03-23 22:36:19 -0800118
119 /* wheee... it's going... */
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000120 for (timeout = 0; timeout < 10000; timeout++) {
121 if (cpu_callin_map[i])
Bob Breuera54123e2006-03-23 22:36:19 -0800122 break;
123 udelay(200);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
125
Bob Breuera54123e2006-03-23 22:36:19 -0800126 if (!(cpu_callin_map[i])) {
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000127 printk(KERN_ERR "Processor %d is stuck.\n", i);
Bob Breuera54123e2006-03-23 22:36:19 -0800128 return -ENODEV;
129 }
130
David S. Miller5d83d662012-05-13 20:49:31 -0700131 local_ops->cache_all();
Bob Breuera54123e2006-03-23 22:36:19 -0800132 return 0;
133}
134
135void __init smp4m_smp_done(void)
136{
137 int i, first;
138 int *prev;
139
140 /* setup cpu list for irq rotation */
141 first = 0;
142 prev = &first;
Rusty Russellec7c14b2009-03-16 14:40:24 +1030143 for_each_online_cpu(i) {
144 *prev = i;
145 prev = &cpu_data(i).next;
Bob Breuera54123e2006-03-23 22:36:19 -0800146 }
147 *prev = first;
David S. Miller5d83d662012-05-13 20:49:31 -0700148 local_ops->cache_all();
Bob Breuera54123e2006-03-23 22:36:19 -0800149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 /* Ok, they are spinning and ready to go. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151}
152
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200153static void sun4m_send_ipi(int cpu, int level)
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000154{
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200155 sbus_writel(SUN4M_SOFT_INT(level), &sun4m_irq_percpu[cpu]->set);
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000156}
157
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200158static void sun4m_ipi_resched(int cpu)
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000159{
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200160 sun4m_send_ipi(cpu, IRQ_IPI_RESCHED);
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000161}
162
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200163static void sun4m_ipi_single(int cpu)
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000164{
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200165 sun4m_send_ipi(cpu, IRQ_IPI_SINGLE);
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000166}
167
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200168static void sun4m_ipi_mask_one(int cpu)
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000169{
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200170 sun4m_send_ipi(cpu, IRQ_IPI_MASK);
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000171}
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173static struct smp_funcall {
174 smpfunc_t func;
175 unsigned long arg1;
176 unsigned long arg2;
177 unsigned long arg3;
178 unsigned long arg4;
179 unsigned long arg5;
Bob Breuera54123e2006-03-23 22:36:19 -0800180 unsigned long processors_in[SUN4M_NCPUS]; /* Set when ipi entered. */
181 unsigned long processors_out[SUN4M_NCPUS]; /* Set when ipi exited. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182} ccall_info;
183
184static DEFINE_SPINLOCK(cross_call_lock);
185
186/* Cross calls must be serialized, at least currently. */
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200187static void sun4m_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
Adrian Bunkc61c65c2008-06-05 11:40:58 -0700188 unsigned long arg2, unsigned long arg3,
David S. Miller66e4f8c2008-08-27 20:03:22 -0700189 unsigned long arg4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
Bob Breuera54123e2006-03-23 22:36:19 -0800191 register int ncpus = SUN4M_NCPUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 unsigned long flags;
193
194 spin_lock_irqsave(&cross_call_lock, flags);
195
196 /* Init function glue. */
197 ccall_info.func = func;
198 ccall_info.arg1 = arg1;
199 ccall_info.arg2 = arg2;
200 ccall_info.arg3 = arg3;
201 ccall_info.arg4 = arg4;
David S. Miller66e4f8c2008-08-27 20:03:22 -0700202 ccall_info.arg5 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 /* Init receive/complete mapping, plus fire the IPI's off. */
205 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 register int i;
207
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700208 cpumask_clear_cpu(smp_processor_id(), &mask);
209 cpumask_and(&mask, cpu_online_mask, &mask);
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000210 for (i = 0; i < ncpus; i++) {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700211 if (cpumask_test_cpu(i, &mask)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 ccall_info.processors_in[i] = 0;
213 ccall_info.processors_out[i] = 0;
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200214 sun4m_send_ipi(i, IRQ_CROSS_CALL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 } else {
216 ccall_info.processors_in[i] = 1;
217 ccall_info.processors_out[i] = 1;
218 }
219 }
220 }
221
222 {
223 register int i;
224
225 i = 0;
226 do {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700227 if (!cpumask_test_cpu(i, &mask))
David S. Miller66e4f8c2008-08-27 20:03:22 -0700228 continue;
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000229 while (!ccall_info.processors_in[i])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 barrier();
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000231 } while (++i < ncpus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233 i = 0;
234 do {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700235 if (!cpumask_test_cpu(i, &mask))
David S. Miller66e4f8c2008-08-27 20:03:22 -0700236 continue;
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000237 while (!ccall_info.processors_out[i])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 barrier();
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000239 } while (++i < ncpus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 spin_unlock_irqrestore(&cross_call_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242}
243
244/* Running cross calls. */
245void smp4m_cross_call_irq(void)
246{
247 int i = smp_processor_id();
248
249 ccall_info.processors_in[i] = 1;
250 ccall_info.func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3,
251 ccall_info.arg4, ccall_info.arg5);
252 ccall_info.processors_out[i] = 1;
253}
254
255void smp4m_percpu_timer_interrupt(struct pt_regs *regs)
256{
Al Viro0d844382006-10-08 14:30:44 +0100257 struct pt_regs *old_regs;
Tkhai Kirill62f08282012-04-04 21:49:26 +0200258 struct clock_event_device *ce;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 int cpu = smp_processor_id();
260
Al Viro0d844382006-10-08 14:30:44 +0100261 old_regs = set_irq_regs(regs);
262
Tkhai Kirill62f08282012-04-04 21:49:26 +0200263 ce = &per_cpu(sparc32_clockevent, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Tkhai Kirill62f08282012-04-04 21:49:26 +0200265 if (ce->mode & CLOCK_EVT_MODE_PERIODIC)
266 sun4m_clear_profile_irq(cpu);
267 else
Sam Ravnborg08c93882012-05-14 17:30:35 +0200268 sparc_config.load_profile_irq(cpu, 0); /* Is this needless? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Tkhai Kirill62f08282012-04-04 21:49:26 +0200270 irq_enter();
271 ce->event_handler(ce);
272 irq_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Al Viro0d844382006-10-08 14:30:44 +0100274 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275}
276
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200277static const struct sparc32_ipi_ops sun4m_ipi_ops = {
278 .cross_call = sun4m_cross_call,
279 .resched = sun4m_ipi_resched,
280 .single = sun4m_ipi_single,
281 .mask_one = sun4m_ipi_mask_one,
282};
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284void __init sun4m_init_smp(void)
285{
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200286 sparc32_ipi_ops = &sun4m_ipi_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287}