sun4m_smp.c 6.2 KB
Newer Older
1 2
/*
 *  sun4m SMP support.
L
Linus Torvalds 已提交
3 4 5 6
 *
 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
 */

7
#include <linux/clockchips.h>
L
Linus Torvalds 已提交
8 9
#include <linux/interrupt.h>
#include <linux/profile.h>
10
#include <linux/delay.h>
11
#include <linux/sched.h>
R
Robert Reif 已提交
12
#include <linux/cpu.h>
13

L
Linus Torvalds 已提交
14
#include <asm/cacheflush.h>
15
#include <asm/switch_to.h>
L
Linus Torvalds 已提交
16
#include <asm/tlbflush.h>
17
#include <asm/timer.h>
18
#include <asm/oplib.h>
L
Linus Torvalds 已提交
19

20
#include "irq.h"
21
#include "kernel.h"
22

23 24 25
#define IRQ_IPI_SINGLE		12
#define IRQ_IPI_MASK		13
#define IRQ_IPI_RESCHED		14
L
Linus Torvalds 已提交
26 27
#define IRQ_CROSS_CALL		15

28 29
static inline unsigned long
swap_ulong(volatile unsigned long *ptr, unsigned long val)
L
Linus Torvalds 已提交
30 31 32 33 34 35 36
{
	__asm__ __volatile__("swap [%1], %0\n\t" :
			     "=&r" (val), "=&r" (ptr) :
			     "0" (val), "1" (ptr));
	return val;
}

37
void __cpuinit smp4m_callin(void)
L
Linus Torvalds 已提交
38 39 40
{
	int cpuid = hard_smp_processor_id();

41 42
	local_ops->cache_all();
	local_ops->tlb_all();
L
Linus Torvalds 已提交
43

44 45
	notify_cpu_starting(cpuid);

46
	register_percpu_ce(cpuid);
L
Linus Torvalds 已提交
47 48 49 50

	calibrate_delay();
	smp_store_cpu_info(cpuid);

51 52
	local_ops->cache_all();
	local_ops->tlb_all();
L
Linus Torvalds 已提交
53 54 55 56 57 58 59 60

	/*
	 * Unblock the master CPU _only_ when the scheduler state
	 * of all secondary CPUs will be up-to-date, so after
	 * the SMP initialization the master will be just allowed
	 * to call the scheduler code.
	 */
	/* Allow master to continue. */
61
	swap_ulong(&cpu_callin_map[cpuid], 1);
L
Linus Torvalds 已提交
62

63
	/* XXX: What's up with all the flushes? */
64 65
	local_ops->cache_all();
	local_ops->tlb_all();
66

L
Linus Torvalds 已提交
67 68 69 70 71 72 73 74 75
	/* Fix idle thread fields. */
	__asm__ __volatile__("ld [%0], %%g6\n\t"
			     : : "r" (&current_set[cpuid])
			     : "memory" /* paranoid */);

	/* Attach to the address space of init_task. */
	atomic_inc(&init_mm.mm_count);
	current->active_mm = &init_mm;

76
	while (!cpumask_test_cpu(cpuid, &smp_commenced_mask))
77
		mb();
L
Linus Torvalds 已提交
78 79

	local_irq_enable();
80

81
	set_cpu_online(cpuid, true);
L
Linus Torvalds 已提交
82 83 84 85 86 87 88
}

/*
 *	Cycle through the processors asking the PROM to start each one.
 */
void __init smp4m_boot_cpus(void)
{
89
	sun4m_unmask_profile_irq();
90
	local_ops->cache_all();
91
}
L
Linus Torvalds 已提交
92

93
int __cpuinit smp4m_boot_one_cpu(int i)
94 95 96 97 98
{
	unsigned long *entry = &sun4m_cpu_startup;
	struct task_struct *p;
	int timeout;
	int cpu_node;
L
Linus Torvalds 已提交
99

100 101 102 103 104 105
	cpu_find_by_mid(i, &cpu_node);

	/* Cook up an idler for this guy. */
	p = fork_idle(i);
	current_set[i] = task_thread_info(p);
	/* See trampoline.S for details... */
106
	entry += ((i - 1) * 3);
L
Linus Torvalds 已提交
107

108 109 110 111 112 113 114 115
	/*
	 * Initialize the contexts table
	 * Since the call to prom_startcpu() trashes the structure,
	 * we need to re-initialize it for each cpu
	 */
	smp_penguin_ctable.which_io = 0;
	smp_penguin_ctable.phys_addr = (unsigned int) srmmu_ctx_table_phys;
	smp_penguin_ctable.reg_size = 0;
L
Linus Torvalds 已提交
116

117
	/* whirrr, whirrr, whirrrrrrrrr... */
118
	printk(KERN_INFO "Starting CPU %d at %p\n", i, entry);
119
	local_ops->cache_all();
120
	prom_startcpu(cpu_node, &smp_penguin_ctable, 0, (char *)entry);
121 122

	/* wheee... it's going... */
123 124
	for (timeout = 0; timeout < 10000; timeout++) {
		if (cpu_callin_map[i])
125 126
			break;
		udelay(200);
L
Linus Torvalds 已提交
127 128
	}

129
	if (!(cpu_callin_map[i])) {
130
		printk(KERN_ERR "Processor %d is stuck.\n", i);
131 132
		return -ENODEV;
	}
L
Linus Torvalds 已提交
133

134
	local_ops->cache_all();
135 136 137 138 139 140 141 142 143 144 145
	return 0;
}

void __init smp4m_smp_done(void)
{
	int i, first;
	int *prev;

	/* setup cpu list for irq rotation */
	first = 0;
	prev = &first;
146 147 148
	for_each_online_cpu(i) {
		*prev = i;
		prev = &cpu_data(i).next;
L
Linus Torvalds 已提交
149
	}
150
	*prev = first;
151
	local_ops->cache_all();
L
Linus Torvalds 已提交
152 153 154 155

	/* Ok, they are spinning and ready to go. */
}

156
static void sun4m_send_ipi(int cpu, int level)
157
{
158
	sbus_writel(SUN4M_SOFT_INT(level), &sun4m_irq_percpu[cpu]->set);
159 160
}

161
static void sun4m_ipi_resched(int cpu)
162
{
163
	sun4m_send_ipi(cpu, IRQ_IPI_RESCHED);
164 165
}

166
static void sun4m_ipi_single(int cpu)
167
{
168
	sun4m_send_ipi(cpu, IRQ_IPI_SINGLE);
169 170
}

171
static void sun4m_ipi_mask_one(int cpu)
172
{
173
	sun4m_send_ipi(cpu, IRQ_IPI_MASK);
174 175
}

L
Linus Torvalds 已提交
176 177 178 179 180 181 182
static struct smp_funcall {
	smpfunc_t func;
	unsigned long arg1;
	unsigned long arg2;
	unsigned long arg3;
	unsigned long arg4;
	unsigned long arg5;
183 184
	unsigned long processors_in[SUN4M_NCPUS];  /* Set when ipi entered. */
	unsigned long processors_out[SUN4M_NCPUS]; /* Set when ipi exited. */
L
Linus Torvalds 已提交
185 186 187 188 189
} ccall_info;

static DEFINE_SPINLOCK(cross_call_lock);

/* Cross calls must be serialized, at least currently. */
190
static void sun4m_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
A
Adrian Bunk 已提交
191
			     unsigned long arg2, unsigned long arg3,
192
			     unsigned long arg4)
L
Linus Torvalds 已提交
193
{
194
		register int ncpus = SUN4M_NCPUS;
L
Linus Torvalds 已提交
195 196 197 198 199 200 201 202 203 204
		unsigned long flags;

		spin_lock_irqsave(&cross_call_lock, flags);

		/* Init function glue. */
		ccall_info.func = func;
		ccall_info.arg1 = arg1;
		ccall_info.arg2 = arg2;
		ccall_info.arg3 = arg3;
		ccall_info.arg4 = arg4;
205
		ccall_info.arg5 = 0;
L
Linus Torvalds 已提交
206 207 208 209 210

		/* Init receive/complete mapping, plus fire the IPI's off. */
		{
			register int i;

211 212
			cpumask_clear_cpu(smp_processor_id(), &mask);
			cpumask_and(&mask, cpu_online_mask, &mask);
213
			for (i = 0; i < ncpus; i++) {
214
				if (cpumask_test_cpu(i, &mask)) {
L
Linus Torvalds 已提交
215 216
					ccall_info.processors_in[i] = 0;
					ccall_info.processors_out[i] = 0;
217
					sun4m_send_ipi(i, IRQ_CROSS_CALL);
L
Linus Torvalds 已提交
218 219 220 221 222 223 224 225 226 227 228 229
				} else {
					ccall_info.processors_in[i] = 1;
					ccall_info.processors_out[i] = 1;
				}
			}
		}

		{
			register int i;

			i = 0;
			do {
230
				if (!cpumask_test_cpu(i, &mask))
231
					continue;
232
				while (!ccall_info.processors_in[i])
L
Linus Torvalds 已提交
233
					barrier();
234
			} while (++i < ncpus);
L
Linus Torvalds 已提交
235 236 237

			i = 0;
			do {
238
				if (!cpumask_test_cpu(i, &mask))
239
					continue;
240
				while (!ccall_info.processors_out[i])
L
Linus Torvalds 已提交
241
					barrier();
242
			} while (++i < ncpus);
L
Linus Torvalds 已提交
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
		}
		spin_unlock_irqrestore(&cross_call_lock, flags);
}

/* Running cross calls. */
void smp4m_cross_call_irq(void)
{
	int i = smp_processor_id();

	ccall_info.processors_in[i] = 1;
	ccall_info.func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3,
			ccall_info.arg4, ccall_info.arg5);
	ccall_info.processors_out[i] = 1;
}

void smp4m_percpu_timer_interrupt(struct pt_regs *regs)
{
A
Al Viro 已提交
260
	struct pt_regs *old_regs;
261
	struct clock_event_device *ce;
L
Linus Torvalds 已提交
262 263
	int cpu = smp_processor_id();

A
Al Viro 已提交
264 265
	old_regs = set_irq_regs(regs);

266
	ce = &per_cpu(sparc32_clockevent, cpu);
L
Linus Torvalds 已提交
267

268 269 270 271
	if (ce->mode & CLOCK_EVT_MODE_PERIODIC)
		sun4m_clear_profile_irq(cpu);
	else
		load_profile_irq(cpu, 0); /* Is this needless? */
L
Linus Torvalds 已提交
272

273 274 275
	irq_enter();
	ce->event_handler(ce);
	irq_exit();
L
Linus Torvalds 已提交
276

A
Al Viro 已提交
277
	set_irq_regs(old_regs);
L
Linus Torvalds 已提交
278 279
}

280 281 282 283 284 285 286
static const struct sparc32_ipi_ops sun4m_ipi_ops = {
	.cross_call = sun4m_cross_call,
	.resched    = sun4m_ipi_resched,
	.single     = sun4m_ipi_single,
	.mask_one   = sun4m_ipi_mask_one,
};

L
Linus Torvalds 已提交
287 288
void __init sun4m_init_smp(void)
{
289
	sparc32_ipi_ops = &sun4m_ipi_ops;
L
Linus Torvalds 已提交
290
}