blob: 228a6527082dc2184a754b17b472d3b8ee4ba8ee [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Sam Ravnborgaba20a82011-01-28 22:08:20 +00002/*
3 * sun4m SMP support.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
5 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
6 */
7
Tkhai Kirill62f08282012-04-04 21:49:26 +02008#include <linux/clockchips.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/profile.h>
Adrian Bunk6c81c322008-02-06 01:37:51 -080011#include <linux/delay.h>
Ingo Molnar68e21be22017-02-01 19:08:20 +010012#include <linux/sched/mm.h>
Robert Reif4245e592008-10-12 20:52:26 -070013#include <linux/cpu.h>
Adrian Bunk6c81c322008-02-06 01:37:51 -080014
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <asm/cacheflush.h>
Sam Ravnborgbde4d8b2012-03-30 15:53:50 +020016#include <asm/switch_to.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/tlbflush.h>
Tkhai Kirill62f08282012-04-04 21:49:26 +020018#include <asm/timer.h>
David S. Miller5d83d662012-05-13 20:49:31 -070019#include <asm/oplib.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Al Viro32231a62007-07-21 19:18:57 -070021#include "irq.h"
Sam Ravnborgaba20a82011-01-28 22:08:20 +000022#include "kernel.h"
Al Viro32231a62007-07-21 19:18:57 -070023
Daniel Hellstromecbc42b2011-05-02 00:08:53 +000024#define IRQ_IPI_SINGLE 12
25#define IRQ_IPI_MASK 13
26#define IRQ_IPI_RESCHED 14
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#define IRQ_CROSS_CALL 15
28
Wu Fengguang1a8a27c2009-01-07 18:09:10 -080029static inline unsigned long
30swap_ulong(volatile unsigned long *ptr, unsigned long val)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
32 __asm__ __volatile__("swap [%1], %0\n\t" :
33 "=&r" (val), "=&r" (ptr) :
34 "0" (val), "1" (ptr));
35 return val;
36}
37
Paul Gortmaker2066aad2013-06-17 15:43:14 -040038void sun4m_cpu_pre_starting(void *arg)
Sam Ravnborgf9fd3482013-02-15 15:52:06 +010039{
40}
41
Paul Gortmaker2066aad2013-06-17 15:43:14 -040042void sun4m_cpu_pre_online(void *arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070043{
44 int cpuid = hard_smp_processor_id();
45
Sam Ravnborgf9fd3482013-02-15 15:52:06 +010046 /* Allow master to continue. The master will then give us the
47 * go-ahead by setting the smp_commenced_mask and will wait without
48 * timeouts until our setup is completed fully (signified by
49 * our bit being set in the cpu_online_mask).
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 */
Wu Fengguang1a8a27c2009-01-07 18:09:10 -080051 swap_ulong(&cpu_callin_map[cpuid], 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Bob Breuera54123e2006-03-23 22:36:19 -080053 /* XXX: What's up with all the flushes? */
David S. Miller5d83d662012-05-13 20:49:31 -070054 local_ops->cache_all();
55 local_ops->tlb_all();
Sam Ravnborgaba20a82011-01-28 22:08:20 +000056
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 /* Fix idle thread fields. */
58 __asm__ __volatile__("ld [%0], %%g6\n\t"
59 : : "r" (&current_set[cpuid])
60 : "memory" /* paranoid */);
61
62 /* Attach to the address space of init_task. */
Vegard Nossumf1f10072017-02-27 14:30:07 -080063 mmgrab(&init_mm);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 current->active_mm = &init_mm;
65
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -070066 while (!cpumask_test_cpu(cpuid, &smp_commenced_mask))
Bob Breuera54123e2006-03-23 22:36:19 -080067 mb();
Linus Torvalds1da177e2005-04-16 15:20:36 -070068}
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070/*
71 * Cycle through the processors asking the PROM to start each one.
72 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070073void __init smp4m_boot_cpus(void)
74{
Tkhai Kirill62f08282012-04-04 21:49:26 +020075 sun4m_unmask_profile_irq();
David S. Miller5d83d662012-05-13 20:49:31 -070076 local_ops->cache_all();
Bob Breuera54123e2006-03-23 22:36:19 -080077}
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Paul Gortmaker2066aad2013-06-17 15:43:14 -040079int smp4m_boot_one_cpu(int i, struct task_struct *idle)
Bob Breuera54123e2006-03-23 22:36:19 -080080{
Bob Breuera54123e2006-03-23 22:36:19 -080081 unsigned long *entry = &sun4m_cpu_startup;
Bob Breuera54123e2006-03-23 22:36:19 -080082 int timeout;
83 int cpu_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Bob Breuera54123e2006-03-23 22:36:19 -080085 cpu_find_by_mid(i, &cpu_node);
Thomas Gleixnerf0a2bc72012-04-20 13:05:56 +000086 current_set[i] = task_thread_info(idle);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Bob Breuera54123e2006-03-23 22:36:19 -080088 /* See trampoline.S for details... */
Sam Ravnborgaba20a82011-01-28 22:08:20 +000089 entry += ((i - 1) * 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Bob Breuera54123e2006-03-23 22:36:19 -080091 /*
92 * Initialize the contexts table
93 * Since the call to prom_startcpu() trashes the structure,
94 * we need to re-initialize it for each cpu
95 */
96 smp_penguin_ctable.which_io = 0;
97 smp_penguin_ctable.phys_addr = (unsigned int) srmmu_ctx_table_phys;
98 smp_penguin_ctable.reg_size = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Bob Breuera54123e2006-03-23 22:36:19 -0800100 /* whirrr, whirrr, whirrrrrrrrr... */
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000101 printk(KERN_INFO "Starting CPU %d at %p\n", i, entry);
David S. Miller5d83d662012-05-13 20:49:31 -0700102 local_ops->cache_all();
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000103 prom_startcpu(cpu_node, &smp_penguin_ctable, 0, (char *)entry);
Bob Breuera54123e2006-03-23 22:36:19 -0800104
105 /* wheee... it's going... */
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000106 for (timeout = 0; timeout < 10000; timeout++) {
107 if (cpu_callin_map[i])
Bob Breuera54123e2006-03-23 22:36:19 -0800108 break;
109 udelay(200);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 }
111
Bob Breuera54123e2006-03-23 22:36:19 -0800112 if (!(cpu_callin_map[i])) {
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000113 printk(KERN_ERR "Processor %d is stuck.\n", i);
Bob Breuera54123e2006-03-23 22:36:19 -0800114 return -ENODEV;
115 }
116
David S. Miller5d83d662012-05-13 20:49:31 -0700117 local_ops->cache_all();
Bob Breuera54123e2006-03-23 22:36:19 -0800118 return 0;
119}
120
121void __init smp4m_smp_done(void)
122{
123 int i, first;
124 int *prev;
125
126 /* setup cpu list for irq rotation */
127 first = 0;
128 prev = &first;
Rusty Russellec7c14b2009-03-16 14:40:24 +1030129 for_each_online_cpu(i) {
130 *prev = i;
131 prev = &cpu_data(i).next;
Bob Breuera54123e2006-03-23 22:36:19 -0800132 }
133 *prev = first;
David S. Miller5d83d662012-05-13 20:49:31 -0700134 local_ops->cache_all();
Bob Breuera54123e2006-03-23 22:36:19 -0800135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 /* Ok, they are spinning and ready to go. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137}
138
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200139static void sun4m_send_ipi(int cpu, int level)
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000140{
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200141 sbus_writel(SUN4M_SOFT_INT(level), &sun4m_irq_percpu[cpu]->set);
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000142}
143
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200144static void sun4m_ipi_resched(int cpu)
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000145{
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200146 sun4m_send_ipi(cpu, IRQ_IPI_RESCHED);
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000147}
148
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200149static void sun4m_ipi_single(int cpu)
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000150{
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200151 sun4m_send_ipi(cpu, IRQ_IPI_SINGLE);
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000152}
153
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200154static void sun4m_ipi_mask_one(int cpu)
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000155{
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200156 sun4m_send_ipi(cpu, IRQ_IPI_MASK);
Daniel Hellstromecbc42b2011-05-02 00:08:53 +0000157}
158
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159static struct smp_funcall {
160 smpfunc_t func;
161 unsigned long arg1;
162 unsigned long arg2;
163 unsigned long arg3;
164 unsigned long arg4;
165 unsigned long arg5;
Bob Breuera54123e2006-03-23 22:36:19 -0800166 unsigned long processors_in[SUN4M_NCPUS]; /* Set when ipi entered. */
167 unsigned long processors_out[SUN4M_NCPUS]; /* Set when ipi exited. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168} ccall_info;
169
170static DEFINE_SPINLOCK(cross_call_lock);
171
172/* Cross calls must be serialized, at least currently. */
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200173static void sun4m_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
Adrian Bunkc61c65c2008-06-05 11:40:58 -0700174 unsigned long arg2, unsigned long arg3,
David S. Miller66e4f8c2008-08-27 20:03:22 -0700175 unsigned long arg4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
Bob Breuera54123e2006-03-23 22:36:19 -0800177 register int ncpus = SUN4M_NCPUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 unsigned long flags;
179
180 spin_lock_irqsave(&cross_call_lock, flags);
181
182 /* Init function glue. */
183 ccall_info.func = func;
184 ccall_info.arg1 = arg1;
185 ccall_info.arg2 = arg2;
186 ccall_info.arg3 = arg3;
187 ccall_info.arg4 = arg4;
David S. Miller66e4f8c2008-08-27 20:03:22 -0700188 ccall_info.arg5 = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190 /* Init receive/complete mapping, plus fire the IPI's off. */
191 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 register int i;
193
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700194 cpumask_clear_cpu(smp_processor_id(), &mask);
195 cpumask_and(&mask, cpu_online_mask, &mask);
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000196 for (i = 0; i < ncpus; i++) {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700197 if (cpumask_test_cpu(i, &mask)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 ccall_info.processors_in[i] = 0;
199 ccall_info.processors_out[i] = 0;
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200200 sun4m_send_ipi(i, IRQ_CROSS_CALL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 } else {
202 ccall_info.processors_in[i] = 1;
203 ccall_info.processors_out[i] = 1;
204 }
205 }
206 }
207
208 {
209 register int i;
210
211 i = 0;
212 do {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700213 if (!cpumask_test_cpu(i, &mask))
David S. Miller66e4f8c2008-08-27 20:03:22 -0700214 continue;
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000215 while (!ccall_info.processors_in[i])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 barrier();
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000217 } while (++i < ncpus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 i = 0;
220 do {
KOSAKI Motohirofb1fece2011-05-16 13:38:07 -0700221 if (!cpumask_test_cpu(i, &mask))
David S. Miller66e4f8c2008-08-27 20:03:22 -0700222 continue;
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000223 while (!ccall_info.processors_out[i])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 barrier();
Sam Ravnborgaba20a82011-01-28 22:08:20 +0000225 } while (++i < ncpus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 spin_unlock_irqrestore(&cross_call_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228}
229
230/* Running cross calls. */
231void smp4m_cross_call_irq(void)
232{
233 int i = smp_processor_id();
234
235 ccall_info.processors_in[i] = 1;
236 ccall_info.func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3,
237 ccall_info.arg4, ccall_info.arg5);
238 ccall_info.processors_out[i] = 1;
239}
240
241void smp4m_percpu_timer_interrupt(struct pt_regs *regs)
242{
Al Viro0d844382006-10-08 14:30:44 +0100243 struct pt_regs *old_regs;
Tkhai Kirill62f08282012-04-04 21:49:26 +0200244 struct clock_event_device *ce;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 int cpu = smp_processor_id();
246
Al Viro0d844382006-10-08 14:30:44 +0100247 old_regs = set_irq_regs(regs);
248
Tkhai Kirill62f08282012-04-04 21:49:26 +0200249 ce = &per_cpu(sparc32_clockevent, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
Viresh Kumarff4aea42015-07-16 16:56:29 +0530251 if (clockevent_state_periodic(ce))
Tkhai Kirill62f08282012-04-04 21:49:26 +0200252 sun4m_clear_profile_irq(cpu);
253 else
Sam Ravnborg08c93882012-05-14 17:30:35 +0200254 sparc_config.load_profile_irq(cpu, 0); /* Is this needless? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Tkhai Kirill62f08282012-04-04 21:49:26 +0200256 irq_enter();
257 ce->event_handler(ce);
258 irq_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Al Viro0d844382006-10-08 14:30:44 +0100260 set_irq_regs(old_regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261}
262
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200263static const struct sparc32_ipi_ops sun4m_ipi_ops = {
264 .cross_call = sun4m_cross_call,
265 .resched = sun4m_ipi_resched,
266 .single = sun4m_ipi_single,
267 .mask_one = sun4m_ipi_mask_one,
268};
269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270void __init sun4m_init_smp(void)
271{
Sam Ravnborg4ba22b12012-05-14 15:14:36 +0200272 sparc32_ipi_ops = &sun4m_ipi_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273}