2005-10-31 18:08:38 -07:00
|
|
|
/*
|
|
|
|
* SMP support for BPA machines.
|
|
|
|
*
|
|
|
|
* Dave Engebretsen, Peter Bergner, and
|
|
|
|
* Mike Corrigan {engebret|bergner|mikec}@us.ibm.com
|
|
|
|
*
|
|
|
|
* Plus various changes from other IBM teams...
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef DEBUG
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/cache.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/sysdev.h>
|
|
|
|
#include <linux/cpu.h>
|
|
|
|
|
|
|
|
#include <asm/ptrace.h>
|
2011-07-26 17:09:06 -06:00
|
|
|
#include <linux/atomic.h>
|
2005-10-31 18:08:38 -07:00
|
|
|
#include <asm/irq.h>
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/prom.h>
|
|
|
|
#include <asm/smp.h>
|
|
|
|
#include <asm/paca.h>
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
#include <asm/cputable.h>
|
|
|
|
#include <asm/firmware.h>
|
|
|
|
#include <asm/system.h>
|
|
|
|
#include <asm/rtas.h>
|
2007-10-24 23:27:44 -06:00
|
|
|
#include <asm/cputhreads.h>
|
2005-10-31 18:08:38 -07:00
|
|
|
|
|
|
|
#include "interrupt.h"
|
2007-10-29 13:24:19 -06:00
|
|
|
#include <asm/udbg.h>
|
2005-10-31 18:08:38 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define DBG(fmt...) udbg_printf(fmt)
|
|
|
|
#else
|
|
|
|
#define DBG(fmt...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2008-10-20 09:37:03 -06:00
|
|
|
* The Primary thread of each non-boot processor was started from the OF client
|
|
|
|
* interface by prom_hold_cpus and is spinning on secondary_hold_spinloop.
|
2005-10-31 18:08:38 -07:00
|
|
|
*/
|
|
|
|
static cpumask_t of_spin_map;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* smp_startup_cpu() - start the given cpu
|
|
|
|
*
|
|
|
|
* At boot time, there is nothing to do for primary threads which were
|
|
|
|
* started from Open Firmware. For anything else, call RTAS with the
|
|
|
|
* appropriate start location.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 - failure
|
|
|
|
* 1 - success
|
|
|
|
*/
|
|
|
|
static inline int __devinit smp_startup_cpu(unsigned int lcpu)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
unsigned long start_here = __pa((u32)*((unsigned long *)
|
2006-08-10 23:07:08 -06:00
|
|
|
generic_secondary_smp_init));
|
2005-10-31 18:08:38 -07:00
|
|
|
unsigned int pcpu;
|
|
|
|
int start_cpu;
|
|
|
|
|
2011-04-27 23:07:23 -06:00
|
|
|
if (cpumask_test_cpu(lcpu, &of_spin_map))
|
2005-10-31 18:08:38 -07:00
|
|
|
/* Already started by OF and sitting in spin loop */
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
pcpu = get_hard_smp_processor_id(lcpu);
|
|
|
|
|
|
|
|
/* Fixup atomic count: it exited inside IRQ handler. */
|
2006-01-12 02:06:01 -07:00
|
|
|
task_thread_info(paca[lcpu].__current)->preempt_count = 0;
|
2005-10-31 18:08:38 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the RTAS start-cpu token does not exist then presume the
|
|
|
|
* cpu is already spinning.
|
|
|
|
*/
|
|
|
|
start_cpu = rtas_token("start-cpu");
|
|
|
|
if (start_cpu == RTAS_UNKNOWN_SERVICE)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
status = rtas_call(start_cpu, 3, 1, NULL, pcpu, start_here, lcpu);
|
|
|
|
if (status != 0) {
|
|
|
|
printk(KERN_ERR "start-cpu failed: %i\n", status);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init smp_iic_probe(void)
|
|
|
|
{
|
|
|
|
iic_request_IPIs();
|
|
|
|
|
2011-04-27 23:07:23 -06:00
|
|
|
return cpumask_weight(cpu_possible_mask);
|
2005-10-31 18:08:38 -07:00
|
|
|
}
|
|
|
|
|
2008-11-28 02:51:24 -07:00
|
|
|
static void __devinit smp_cell_setup_cpu(int cpu)
|
2005-10-31 18:08:38 -07:00
|
|
|
{
|
|
|
|
if (cpu != boot_cpuid)
|
|
|
|
iic_setup_cpu();
|
2008-11-28 02:51:24 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* change default DABRX to allow user watchpoints
|
|
|
|
*/
|
|
|
|
mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER);
|
2005-10-31 18:08:38 -07:00
|
|
|
}
|
|
|
|
|
2011-04-11 15:46:19 -06:00
|
|
|
static int __devinit smp_cell_kick_cpu(int nr)
|
2005-10-31 18:08:38 -07:00
|
|
|
{
|
|
|
|
BUG_ON(nr < 0 || nr >= NR_CPUS);
|
|
|
|
|
|
|
|
if (!smp_startup_cpu(nr))
|
2011-04-11 15:46:19 -06:00
|
|
|
return -ENOENT;
|
2005-10-31 18:08:38 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The processor is currently spinning, waiting for the
|
|
|
|
* cpu_start field to become non-zero After we set cpu_start,
|
|
|
|
* the processor will continue on to secondary_start
|
|
|
|
*/
|
|
|
|
paca[nr].cpu_start = 1;
|
2011-04-11 15:46:19 -06:00
|
|
|
|
|
|
|
return 0;
|
2005-10-31 18:08:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int smp_cell_cpu_bootable(unsigned int nr)
|
|
|
|
{
|
|
|
|
/* Special case - we inhibit secondary thread startup
|
|
|
|
* during boot if the user requests it. Odd-numbered
|
|
|
|
* cpus are assumed to be secondary threads.
|
|
|
|
*/
|
|
|
|
if (system_state < SYSTEM_RUNNING &&
|
|
|
|
cpu_has_feature(CPU_FTR_SMT) &&
|
2007-10-24 23:27:44 -06:00
|
|
|
!smt_enabled_at_boot && cpu_thread_in_core(nr) != 0)
|
2005-10-31 18:08:38 -07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
static struct smp_ops_t bpa_iic_smp_ops = {
|
2011-05-24 14:34:18 -06:00
|
|
|
.message_pass = iic_message_pass,
|
2005-10-31 18:08:38 -07:00
|
|
|
.probe = smp_iic_probe,
|
|
|
|
.kick_cpu = smp_cell_kick_cpu,
|
2008-11-28 02:51:24 -07:00
|
|
|
.setup_cpu = smp_cell_setup_cpu,
|
2005-10-31 18:08:38 -07:00
|
|
|
.cpu_bootable = smp_cell_cpu_bootable,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* This is called very early */
|
|
|
|
void __init smp_init_cell(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
DBG(" -> smp_init_cell()\n");
|
|
|
|
|
|
|
|
smp_ops = &bpa_iic_smp_ops;
|
|
|
|
|
|
|
|
/* Mark threads which are still spinning in hold loops. */
|
|
|
|
if (cpu_has_feature(CPU_FTR_SMT)) {
|
|
|
|
for_each_present_cpu(i) {
|
2008-10-20 09:37:03 -06:00
|
|
|
if (cpu_thread_in_core(i) == 0)
|
2011-04-27 23:07:23 -06:00
|
|
|
cpumask_set_cpu(i, &of_spin_map);
|
2005-10-31 18:08:38 -07:00
|
|
|
}
|
2011-04-27 23:07:23 -06:00
|
|
|
} else
|
|
|
|
cpumask_copy(&of_spin_map, cpu_present_mask);
|
2005-10-31 18:08:38 -07:00
|
|
|
|
2011-04-27 23:07:23 -06:00
|
|
|
cpumask_clear_cpu(boot_cpuid, &of_spin_map);
|
2005-10-31 18:08:38 -07:00
|
|
|
|
|
|
|
/* Non-lpar has additional take/give timebase */
|
|
|
|
if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) {
|
2009-06-16 10:42:50 -06:00
|
|
|
smp_ops->give_timebase = rtas_give_timebase;
|
|
|
|
smp_ops->take_timebase = rtas_take_timebase;
|
2005-10-31 18:08:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
DBG(" <- smp_init_cell()\n");
|
|
|
|
}
|