blob: 29f8ace10b596949302513f564d1acfc95ef108d [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>
Robert Reif4245e592008-10-12 20:52:26 -070011#include <linux/cpu.h>
Adrian Bunk6c81c322008-02-06 01:37:51 -080012
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/cacheflush.h>
Sam Ravnborgbde4d8b2012-03-30 15:53:50 +020014#include <asm/switch_to.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/tlbflush.h>
Tkhai Kirill62f08282012-04-04 21:49:26 +020016#include <asm/timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Al Viro32231a62007-07-21 19:18:57 -070018#include "irq.h"
Sam Ravnborgaba20a82011-01-28 22:08:20 +000019#include "kernel.h"
Al Viro32231a62007-07-21 19:18:57 -070020
Daniel Hellstromecbc42b2011-05-02 00:08:53 +000021#define IRQ_IPI_SINGLE 12
22#define IRQ_IPI_MASK 13
23#define IRQ_IPI_RESCHED 14
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#define IRQ_CROSS_CALL 15
25
Wu Fengguang1a8a27c2009-01-07 18:09:10 -080026static inline unsigned long
27swap_ulong(volatile unsigned long *ptr, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
29 __asm__ __volatile__("swap [%1], %0\n\t" :
30 "=&r" (val), "=&r" (ptr) :
31 "0" (val), "1" (ptr));
32 return val;
33}
34
Daniel Hellstromecbc42b2011-05-02 00:08:53 +000035static void smp4m_ipi_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
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
41 local_flush_cache_all();
42 local_flush_tlb_all();
43
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
51 local_flush_cache_all();
52 local_flush_tlb_all();
53
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? */
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 local_flush_cache_all();
65 local_flush_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{
Daniel Hellstromecbc42b2011-05-02 00:08:53 +000089 smp4m_ipi_init();
Tkhai Kirill62f08282012-04-04 21:49:26 +020090 sun4m_unmask_profile_irq();
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 local_flush_cache_all();
Bob Breuera54123e2006-03-23 22:36:19 -080092}
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Bob Breuer92d452f2006-06-20 00:36:10 -070094int __cpuinit smp4m_boot_one_cpu(int i)
Bob Breuera54123e2006-03-23 22:36:19 -080095{
Bob Breuera54123e2006-03-23 22:36:19 -080096 unsigned long *entry = &sun4m_cpu_startup;
97 struct task_struct *p;
98 int timeout;
99 int cpu_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Bob Breuera54123e2006-03-23 22:36:19 -0800101 cpu_find_by_mid(i, &cpu_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Bob Breuera54123e2006-03-23 22:36:19 -0800103 /* Cook up an idler for this guy. */
104 p = fork_idle(i);
105 current_set[i] = task_thread_info(p);
106 /* See trampoline.S for details... */
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000107 entry += ((i - 1) * 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
Bob Breuera54123e2006-03-23 22:36:19 -0800109 /*
110 * Initialize the contexts table
111 * Since the call to prom_startcpu() trashes the structure,
112 * we need to re-initialize it for each cpu
113 */
114 smp_penguin_ctable.which_io = 0;
115 smp_penguin_ctable.phys_addr = (unsigned int) srmmu_ctx_table_phys;
116 smp_penguin_ctable.reg_size = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Bob Breuera54123e2006-03-23 22:36:19 -0800118 /* whirrr, whirrr, whirrrrrrrrr... */
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000119 printk(KERN_INFO "Starting CPU %d at %p\n", i, entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 local_flush_cache_all();
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000121 prom_startcpu(cpu_node, &smp_penguin_ctable, 0, (char *)entry);
Bob Breuera54123e2006-03-23 22:36:19 -0800122
123 /* wheee... it's going... */
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000124 for (timeout = 0; timeout < 10000; timeout++) {
125 if (cpu_callin_map[i])
Bob Breuera54123e2006-03-23 22:36:19 -0800126 break;
127 udelay(200);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 }
129
Bob Breuera54123e2006-03-23 22:36:19 -0800130 if (!(cpu_callin_map[i])) {
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000131 printk(KERN_ERR "Processor %d is stuck.\n", i);
Bob Breuera54123e2006-03-23 22:36:19 -0800132 return -ENODEV;
133 }
134
135 local_flush_cache_all();
136 return 0;
137}
138
139void __init smp4m_smp_done(void)
140{
141 int i, first;
142 int *prev;
143
144 /* setup cpu list for irq rotation */
145 first = 0;
146 prev = &first;
Rusty Russellec7c14b2009-03-16 14:40:24 +1030147 for_each_online_cpu(i) {
148 *prev = i;
149 prev = &cpu_data(i).next;
Bob Breuera54123e2006-03-23 22:36:19 -0800150 }
151 *prev = first;
152 local_flush_cache_all();
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 /* Ok, they are spinning and ready to go. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155}
156
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000157
158/* Initialize IPIs on the SUN4M SMP machine */
159static void __init smp4m_ipi_init(void)
160{
161}
162
163static void smp4m_ipi_resched(int cpu)
164{
165 set_cpu_int(cpu, IRQ_IPI_RESCHED);
166}
167
168static void smp4m_ipi_single(int cpu)
169{
170 set_cpu_int(cpu, IRQ_IPI_SINGLE);
171}
172
173static void smp4m_ipi_mask_one(int cpu)
174{
175 set_cpu_int(cpu, IRQ_IPI_MASK);
176}
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178static struct smp_funcall {
179 smpfunc_t func;
180 unsigned long arg1;
181 unsigned long arg2;
182 unsigned long arg3;
183 unsigned long arg4;
184 unsigned long arg5;
Bob Breuera54123e2006-03-23 22:36:19 -0800185 unsigned long processors_in[SUN4M_NCPUS]; /* Set when ipi entered. */
186 unsigned long processors_out[SUN4M_NCPUS]; /* Set when ipi exited. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187} ccall_info;
188
189static DEFINE_SPINLOCK(cross_call_lock);
190
191/* Cross calls must be serialized, at least currently. */
David S. Miller66e4f8c2008-08-27 20:03:22 -0700192static void smp4m_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
Adrian Bunkc61c65c2008-06-05 11:40:58 -0700193 unsigned long arg2, unsigned long arg3,
David S. Miller66e4f8c2008-08-27 20:03:22 -0700194 unsigned long arg4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Bob Breuera54123e2006-03-23 22:36:19 -0800196 register int ncpus = SUN4M_NCPUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 unsigned long flags;
198
199 spin_lock_irqsave(&cross_call_lock, flags);
200
201 /* Init function glue. */
202 ccall_info.func = func;
203 ccall_info.arg1 = arg1;
204 ccall_info.arg2 = arg2;
205 ccall_info.arg3 = arg3;
206 ccall_info.arg4 = arg4;
David S. Miller66e4f8c2008-08-27 20:03:22 -0700207 ccall_info.arg5 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209 /* Init receive/complete mapping, plus fire the IPI's off. */
210 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 register int i;
212
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700213 cpumask_clear_cpu(smp_processor_id(), &mask);
214 cpumask_and(&mask, cpu_online_mask, &mask);
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000215 for (i = 0; i < ncpus; i++) {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700216 if (cpumask_test_cpu(i, &mask)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 ccall_info.processors_in[i] = 0;
218 ccall_info.processors_out[i] = 0;
219 set_cpu_int(i, IRQ_CROSS_CALL);
220 } else {
221 ccall_info.processors_in[i] = 1;
222 ccall_info.processors_out[i] = 1;
223 }
224 }
225 }
226
227 {
228 register int i;
229
230 i = 0;
231 do {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700232 if (!cpumask_test_cpu(i, &mask))
David S. Miller66e4f8c2008-08-27 20:03:22 -0700233 continue;
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000234 while (!ccall_info.processors_in[i])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 barrier();
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000236 } while (++i < ncpus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238 i = 0;
239 do {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700240 if (!cpumask_test_cpu(i, &mask))
David S. Miller66e4f8c2008-08-27 20:03:22 -0700241 continue;
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000242 while (!ccall_info.processors_out[i])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 barrier();
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000244 } while (++i < ncpus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 spin_unlock_irqrestore(&cross_call_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
248
249/* Running cross calls. */
250void smp4m_cross_call_irq(void)
251{
252 int i = smp_processor_id();
253
254 ccall_info.processors_in[i] = 1;
255 ccall_info.func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3,
256 ccall_info.arg4, ccall_info.arg5);
257 ccall_info.processors_out[i] = 1;
258}
259
260void smp4m_percpu_timer_interrupt(struct pt_regs *regs)
261{
Al Viro0d844382006-10-08 14:30:44 +0100262 struct pt_regs *old_regs;
Tkhai Kirill62f08282012-04-04 21:49:26 +0200263 struct clock_event_device *ce;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 int cpu = smp_processor_id();
265
Al Viro0d844382006-10-08 14:30:44 +0100266 old_regs = set_irq_regs(regs);
267
Tkhai Kirill62f08282012-04-04 21:49:26 +0200268 ce = &per_cpu(sparc32_clockevent, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Tkhai Kirill62f08282012-04-04 21:49:26 +0200270 if (ce->mode & CLOCK_EVT_MODE_PERIODIC)
271 sun4m_clear_profile_irq(cpu);
272 else
273 load_profile_irq(cpu, 0); /* Is this needless? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Tkhai Kirill62f08282012-04-04 21:49:26 +0200275 irq_enter();
276 ce->event_handler(ce);
277 irq_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Al Viro0d844382006-10-08 14:30:44 +0100279 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
Adrian Bunkc61c65c2008-06-05 11:40:58 -0700282static void __init smp4m_blackbox_id(unsigned *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
284 int rd = *addr & 0x3e000000;
285 int rs1 = rd >> 11;
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 addr[0] = 0x81580000 | rd; /* rd %tbr, reg */
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000288 addr[1] = 0x8130200c | rd | rs1; /* srl reg, 0xc, reg */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 addr[2] = 0x80082003 | rd | rs1; /* and reg, 3, reg */
290}
291
Adrian Bunkc61c65c2008-06-05 11:40:58 -0700292static void __init smp4m_blackbox_current(unsigned *addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{
294 int rd = *addr & 0x3e000000;
295 int rs1 = rd >> 11;
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 addr[0] = 0x81580000 | rd; /* rd %tbr, reg */
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000298 addr[2] = 0x8130200a | rd | rs1; /* srl reg, 0xa, reg */
David S. Miller4cad6912007-04-30 17:59:50 -0700299 addr[4] = 0x8008200c | rd | rs1; /* and reg, 0xc, reg */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300}
301
302void __init sun4m_init_smp(void)
303{
304 BTFIXUPSET_BLACKBOX(hard_smp_processor_id, smp4m_blackbox_id);
305 BTFIXUPSET_BLACKBOX(load_current, smp4m_blackbox_current);
306 BTFIXUPSET_CALL(smp_cross_call, smp4m_cross_call, BTFIXUPCALL_NORM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 BTFIXUPSET_CALL(__hard_smp_processor_id, __smp4m_processor_id, BTFIXUPCALL_NORM);
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000308 BTFIXUPSET_CALL(smp_ipi_resched, smp4m_ipi_resched, BTFIXUPCALL_NORM);
309 BTFIXUPSET_CALL(smp_ipi_single, smp4m_ipi_single, BTFIXUPCALL_NORM);
310 BTFIXUPSET_CALL(smp_ipi_mask_one, smp4m_ipi_mask_one, BTFIXUPCALL_NORM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311}