smp_32.c 10.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/* smp.c: Sparc SMP support.
 *
 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
 * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
 * Copyright (C) 2004 Keith M Wesolowski (wesolows@foobazco.org)
 */

#include <asm/head.h>

#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/threads.h>
#include <linux/smp.h>
#include <linux/interrupt.h>
#include <linux/kernel_stat.h>
#include <linux/init.h>
#include <linux/spinlock.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/seq_file.h>
#include <linux/cache.h>
#include <linux/delay.h>

#include <asm/ptrace.h>
#include <asm/atomic.h>

#include <asm/irq.h>
#include <asm/page.h>
#include <asm/pgalloc.h>
#include <asm/pgtable.h>
#include <asm/oplib.h>
#include <asm/cacheflush.h>
#include <asm/tlbflush.h>
#include <asm/cpudata.h>
K
Konrad Eisele 已提交
35
#include <asm/leon.h>
L
Linus Torvalds 已提交
36

37 38
#include "irq.h"

A
Al Viro 已提交
39
volatile unsigned long cpu_callin_map[NR_CPUS] __cpuinitdata = {0,};
L
Linus Torvalds 已提交
40

41
cpumask_t smp_commenced_mask = CPU_MASK_NONE;
L
Linus Torvalds 已提交
42 43 44 45 46 47 48 49 50

/* The only guaranteed locking primitive available on all Sparc
 * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
 * places the current byte at the effective address into dest_reg and
 * places 0xff there afterwards.  Pretty lame locking primitive
 * compared to the Alpha and the Intel no?  Most Sparcs have 'swap'
 * instruction which is much better...
 */

51
void __cpuinit smp_store_cpu_info(int id)
L
Linus Torvalds 已提交
52 53
{
	int cpu_node;
S
Sam Ravnborg 已提交
54
	int mid;
L
Linus Torvalds 已提交
55 56 57 58 59 60 61

	cpu_data(id).udelay_val = loops_per_jiffy;

	cpu_find_by_mid(id, &cpu_node);
	cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
						     "clock-frequency", 0);
	cpu_data(id).prom_node = cpu_node;
S
Sam Ravnborg 已提交
62
	mid = cpu_get_hwmid(cpu_node);
63

S
Sam Ravnborg 已提交
64 65 66 67 68
	if (mid < 0) {
		printk(KERN_NOTICE "No MID found for CPU%d at node 0x%08d", id, cpu_node);
		mid = 0;
	}
	cpu_data(id).mid = mid;
L
Linus Torvalds 已提交
69 70 71 72
}

void __init smp_cpus_done(unsigned int max_cpus)
{
73
	extern void smp4m_smp_done(void);
74
	extern void smp4d_smp_done(void);
75
	unsigned long bogosum = 0;
76
	int cpu, num = 0;
77

78 79 80 81
	for_each_online_cpu(cpu) {
		num++;
		bogosum += cpu_data(cpu).udelay_val;
	}
82 83 84 85 86

	printk("Total of %d processors activated (%lu.%02lu BogoMIPS).\n",
		num, bogosum/(500000/HZ),
		(bogosum/(5000/HZ))%100);

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
	switch(sparc_cpu_model) {
	case sun4:
		printk("SUN4\n");
		BUG();
		break;
	case sun4c:
		printk("SUN4C\n");
		BUG();
		break;
	case sun4m:
		smp4m_smp_done();
		break;
	case sun4d:
		smp4d_smp_done();
		break;
K
Konrad Eisele 已提交
102 103 104
	case sparc_leon:
		leon_smp_done();
		break;
105 106 107 108 109 110 111 112 113 114 115 116 117
	case sun4e:
		printk("SUN4E\n");
		BUG();
		break;
	case sun4u:
		printk("SUN4U\n");
		BUG();
		break;
	default:
		printk("UNKNOWN!\n");
		BUG();
		break;
	};
L
Linus Torvalds 已提交
118 119 120 121 122 123 124 125
}

void cpu_panic(void)
{
	printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
	panic("SMP bolixed\n");
}

A
Al Viro 已提交
126
struct linux_prom_registers smp_penguin_ctable __cpuinitdata = { 0 };
L
Linus Torvalds 已提交
127 128 129

void smp_send_reschedule(int cpu)
{
130 131 132 133 134 135
	/*
	 * CPU model dependent way of implementing IPI generation targeting
	 * a single CPU. The trap handler needs only to do trap entry/return
	 * to call schedule.
	 */
	BTFIXUP_CALL(smp_ipi_resched)(cpu);
L
Linus Torvalds 已提交
136 137 138 139 140 141
}

void smp_send_stop(void)
{
}

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
void arch_send_call_function_single_ipi(int cpu)
{
	/* trigger one IPI single call on one CPU */
	BTFIXUP_CALL(smp_ipi_single)(cpu);
}

void arch_send_call_function_ipi_mask(const struct cpumask *mask)
{
	int cpu;

	/* trigger IPI mask call on each CPU */
	for_each_cpu(cpu, mask)
		BTFIXUP_CALL(smp_ipi_mask_one)(cpu);
}

void smp_resched_interrupt(void)
{
159 160
	irq_enter();
	scheduler_ipi();
161
	local_cpu_data().irq_resched_count++;
162 163
	irq_exit();
	/* re-schedule routine called by interrupt return code. */
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
}

void smp_call_function_single_interrupt(void)
{
	irq_enter();
	generic_smp_call_function_single_interrupt();
	local_cpu_data().irq_call_count++;
	irq_exit();
}

void smp_call_function_interrupt(void)
{
	irq_enter();
	generic_smp_call_function_interrupt();
	local_cpu_data().irq_call_count++;
	irq_exit();
}

L
Linus Torvalds 已提交
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
void smp_flush_cache_all(void)
{
	xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all));
	local_flush_cache_all();
}

void smp_flush_tlb_all(void)
{
	xc0((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_all));
	local_flush_tlb_all();
}

void smp_flush_cache_mm(struct mm_struct *mm)
{
	if(mm->context != NO_CONTEXT) {
197 198 199 200
		cpumask_t cpu_mask;
		cpumask_copy(&cpu_mask, mm_cpumask(mm));
		cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
		if (!cpumask_empty(&cpu_mask))
L
Linus Torvalds 已提交
201 202 203 204 205 206 207 208
			xc1((smpfunc_t) BTFIXUP_CALL(local_flush_cache_mm), (unsigned long) mm);
		local_flush_cache_mm(mm);
	}
}

void smp_flush_tlb_mm(struct mm_struct *mm)
{
	if(mm->context != NO_CONTEXT) {
209 210 211 212
		cpumask_t cpu_mask;
		cpumask_copy(&cpu_mask, mm_cpumask(mm));
		cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
		if (!cpumask_empty(&cpu_mask)) {
L
Linus Torvalds 已提交
213 214
			xc1((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_mm), (unsigned long) mm);
			if(atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
215 216
				cpumask_copy(mm_cpumask(mm),
					     cpumask_of(smp_processor_id()));
L
Linus Torvalds 已提交
217 218 219 220 221 222 223 224 225 226 227
		}
		local_flush_tlb_mm(mm);
	}
}

void smp_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
			   unsigned long end)
{
	struct mm_struct *mm = vma->vm_mm;

	if (mm->context != NO_CONTEXT) {
228 229 230 231
		cpumask_t cpu_mask;
		cpumask_copy(&cpu_mask, mm_cpumask(mm));
		cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
		if (!cpumask_empty(&cpu_mask))
L
Linus Torvalds 已提交
232 233 234 235 236 237 238 239 240 241 242
			xc3((smpfunc_t) BTFIXUP_CALL(local_flush_cache_range), (unsigned long) vma, start, end);
		local_flush_cache_range(vma, start, end);
	}
}

void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
			 unsigned long end)
{
	struct mm_struct *mm = vma->vm_mm;

	if (mm->context != NO_CONTEXT) {
243 244 245 246
		cpumask_t cpu_mask;
		cpumask_copy(&cpu_mask, mm_cpumask(mm));
		cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
		if (!cpumask_empty(&cpu_mask))
L
Linus Torvalds 已提交
247 248 249 250 251 252 253 254 255 256
			xc3((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_range), (unsigned long) vma, start, end);
		local_flush_tlb_range(vma, start, end);
	}
}

void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
{
	struct mm_struct *mm = vma->vm_mm;

	if(mm->context != NO_CONTEXT) {
257 258 259 260
		cpumask_t cpu_mask;
		cpumask_copy(&cpu_mask, mm_cpumask(mm));
		cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
		if (!cpumask_empty(&cpu_mask))
L
Linus Torvalds 已提交
261 262 263 264 265 266 267 268 269 270
			xc2((smpfunc_t) BTFIXUP_CALL(local_flush_cache_page), (unsigned long) vma, page);
		local_flush_cache_page(vma, page);
	}
}

void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
{
	struct mm_struct *mm = vma->vm_mm;

	if(mm->context != NO_CONTEXT) {
271 272 273 274
		cpumask_t cpu_mask;
		cpumask_copy(&cpu_mask, mm_cpumask(mm));
		cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
		if (!cpumask_empty(&cpu_mask))
L
Linus Torvalds 已提交
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
			xc2((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_page), (unsigned long) vma, page);
		local_flush_tlb_page(vma, page);
	}
}

void smp_flush_page_to_ram(unsigned long page)
{
	/* Current theory is that those who call this are the one's
	 * who have just dirtied their cache with the pages contents
	 * in kernel space, therefore we only run this on local cpu.
	 *
	 * XXX This experiment failed, research further... -DaveM
	 */
#if 1
	xc1((smpfunc_t) BTFIXUP_CALL(local_flush_page_to_ram), page);
#endif
	local_flush_page_to_ram(page);
}

void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
{
296 297 298 299
	cpumask_t cpu_mask;
	cpumask_copy(&cpu_mask, mm_cpumask(mm));
	cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
	if (!cpumask_empty(&cpu_mask))
L
Linus Torvalds 已提交
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
		xc2((smpfunc_t) BTFIXUP_CALL(local_flush_sig_insns), (unsigned long) mm, insn_addr);
	local_flush_sig_insns(mm, insn_addr);
}

extern unsigned int lvl14_resolution;

/* /proc/profile writes can call this, don't __init it please. */
static DEFINE_SPINLOCK(prof_setup_lock);

int setup_profiling_timer(unsigned int multiplier)
{
	int i;
	unsigned long flags;

	/* Prevent level14 ticker IRQ flooding. */
	if((!multiplier) || (lvl14_resolution / multiplier) < 500)
		return -EINVAL;

	spin_lock_irqsave(&prof_setup_lock, flags);
319
	for_each_possible_cpu(i) {
320
		load_profile_irq(i, lvl14_resolution / multiplier);
L
Linus Torvalds 已提交
321 322 323 324 325 326 327
		prof_multiplier(i) = multiplier;
	}
	spin_unlock_irqrestore(&prof_setup_lock, flags);

	return 0;
}

328
void __init smp_prepare_cpus(unsigned int max_cpus)
L
Linus Torvalds 已提交
329
{
330 331
	extern void __init smp4m_boot_cpus(void);
	extern void __init smp4d_boot_cpus(void);
B
Bob Breuer 已提交
332
	int i, cpuid, extra;
333 334 335 336 337

	printk("Entering SMP Mode...\n");

	extra = 0;
	for (i = 0; !cpu_find_by_instance(i, NULL, &cpuid); i++) {
B
Bob Breuer 已提交
338
		if (cpuid >= NR_CPUS)
339 340
			extra++;
	}
B
Bob Breuer 已提交
341 342
	/* i = number of cpus */
	if (extra && max_cpus > i - extra)
343 344 345 346
		printk("Warning: NR_CPUS is too low to start all cpus\n");

	smp_store_cpu_info(boot_cpu_id);

347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
	switch(sparc_cpu_model) {
	case sun4:
		printk("SUN4\n");
		BUG();
		break;
	case sun4c:
		printk("SUN4C\n");
		BUG();
		break;
	case sun4m:
		smp4m_boot_cpus();
		break;
	case sun4d:
		smp4d_boot_cpus();
		break;
K
Konrad Eisele 已提交
362 363 364
	case sparc_leon:
		leon_boot_cpus();
		break;
365 366 367 368 369 370 371 372 373 374 375 376 377
	case sun4e:
		printk("SUN4E\n");
		BUG();
		break;
	case sun4u:
		printk("SUN4U\n");
		BUG();
		break;
	default:
		printk("UNKNOWN!\n");
		BUG();
		break;
	};
L
Linus Torvalds 已提交
378 379
}

B
Bob Breuer 已提交
380 381 382 383 384 385 386 387 388 389 390
/* Set this up early so that things like the scheduler can init
 * properly.  We use the same cpu mask for both the present and
 * possible cpu map.
 */
void __init smp_setup_cpu_possible_map(void)
{
	int instance, mid;

	instance = 0;
	while (!cpu_find_by_instance(instance, NULL, &mid)) {
		if (mid < NR_CPUS) {
391 392
			set_cpu_possible(mid, true);
			set_cpu_present(mid, true);
B
Bob Breuer 已提交
393 394 395 396 397
		}
		instance++;
	}
}

398
void __init smp_prepare_boot_cpu(void)
L
Linus Torvalds 已提交
399
{
400 401 402 403 404 405 406 407 408 409
	int cpuid = hard_smp_processor_id();

	if (cpuid >= NR_CPUS) {
		prom_printf("Serious problem, boot cpu id >= NR_CPUS\n");
		prom_halt();
	}
	if (cpuid != 0)
		printk("boot cpu id != 0, this could work but is untested\n");

	current_thread_info()->cpu = cpuid;
410 411
	set_cpu_online(cpuid, true);
	set_cpu_possible(cpuid, true);
L
Linus Torvalds 已提交
412 413
}

414
int __cpuinit __cpu_up(unsigned int cpu)
L
Linus Torvalds 已提交
415
{
416 417
	extern int __cpuinit smp4m_boot_one_cpu(int);
	extern int __cpuinit smp4d_boot_one_cpu(int);
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
	int ret=0;

	switch(sparc_cpu_model) {
	case sun4:
		printk("SUN4\n");
		BUG();
		break;
	case sun4c:
		printk("SUN4C\n");
		BUG();
		break;
	case sun4m:
		ret = smp4m_boot_one_cpu(cpu);
		break;
	case sun4d:
		ret = smp4d_boot_one_cpu(cpu);
		break;
K
Konrad Eisele 已提交
435 436 437
	case sparc_leon:
		ret = leon_boot_one_cpu(cpu);
		break;
438 439 440 441 442 443 444 445 446 447 448 449 450
	case sun4e:
		printk("SUN4E\n");
		BUG();
		break;
	case sun4u:
		printk("SUN4U\n");
		BUG();
		break;
	default:
		printk("UNKNOWN!\n");
		BUG();
		break;
	};
451 452

	if (!ret) {
453
		cpumask_set_cpu(cpu, &smp_commenced_mask);
454 455 456 457
		while (!cpu_online(cpu))
			mb();
	}
	return ret;
L
Linus Torvalds 已提交
458 459 460 461 462 463
}

void smp_bogo(struct seq_file *m)
{
	int i;
	
464 465 466 467 468 469
	for_each_online_cpu(i) {
		seq_printf(m,
			   "Cpu%dBogo\t: %lu.%02lu\n",
			   i,
			   cpu_data(i).udelay_val/(500000/HZ),
			   (cpu_data(i).udelay_val/(5000/HZ))%100);
L
Linus Torvalds 已提交
470 471 472 473 474 475 476 477
	}
}

void smp_info(struct seq_file *m)
{
	int i;

	seq_printf(m, "State:\n");
478 479
	for_each_online_cpu(i)
		seq_printf(m, "CPU%d\t\t: online\n", i);
L
Linus Torvalds 已提交
480
}