2005-11-01 09:08:38 +08: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>
|
2011-12-22 08:26:03 +08:00
|
|
|
#include <linux/device.h>
|
2005-11-01 09:08:38 +08:00
|
|
|
#include <linux/cpu.h>
|
|
|
|
|
|
|
|
#include <asm/ptrace.h>
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2005-11-01 09:08:38 +08: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/rtas.h>
|
2007-10-25 13:27:44 +08:00
|
|
|
#include <asm/cputhreads.h>
|
2014-03-11 08:54:06 +08:00
|
|
|
#include <asm/code-patching.h>
|
2005-11-01 09:08:38 +08:00
|
|
|
|
|
|
|
#include "interrupt.h"
|
2007-10-30 03:24:19 +08:00
|
|
|
#include <asm/udbg.h>
|
2005-11-01 09:08:38 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
#define DBG(fmt...) udbg_printf(fmt)
|
|
|
|
#else
|
|
|
|
#define DBG(fmt...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
2008-10-20 23:37:03 +08: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-11-01 09:08:38 +08: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
|
|
|
|
*/
|
2012-12-22 06:04:10 +08:00
|
|
|
static inline int smp_startup_cpu(unsigned int lcpu)
|
2005-11-01 09:08:38 +08:00
|
|
|
{
|
|
|
|
int status;
|
2014-03-11 08:54:06 +08:00
|
|
|
unsigned long start_here =
|
|
|
|
__pa(ppc_function_entry(generic_secondary_smp_init));
|
2005-11-01 09:08:38 +08:00
|
|
|
unsigned int pcpu;
|
|
|
|
int start_cpu;
|
|
|
|
|
2011-04-28 13:07:23 +08:00
|
|
|
if (cpumask_test_cpu(lcpu, &of_spin_map))
|
2005-11-01 09:08:38 +08: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 17:06:01 +08:00
|
|
|
task_thread_info(paca[lcpu].__current)->preempt_count = 0;
|
2005-11-01 09:08:38 +08: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;
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:04:10 +08:00
|
|
|
static void smp_cell_setup_cpu(int cpu)
|
2005-11-01 09:08:38 +08:00
|
|
|
{
|
|
|
|
if (cpu != boot_cpuid)
|
|
|
|
iic_setup_cpu();
|
2008-11-28 17:51:24 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* change default DABRX to allow user watchpoints
|
|
|
|
*/
|
|
|
|
mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER);
|
2005-11-01 09:08:38 +08:00
|
|
|
}
|
|
|
|
|
2012-12-22 06:04:10 +08:00
|
|
|
static int smp_cell_kick_cpu(int nr)
|
2005-11-01 09:08:38 +08:00
|
|
|
{
|
|
|
|
BUG_ON(nr < 0 || nr >= NR_CPUS);
|
|
|
|
|
|
|
|
if (!smp_startup_cpu(nr))
|
2011-04-12 05:46:19 +08:00
|
|
|
return -ENOENT;
|
2005-11-01 09:08:38 +08: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-12 05:46:19 +08:00
|
|
|
|
|
|
|
return 0;
|
2005-11-01 09:08:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct smp_ops_t bpa_iic_smp_ops = {
|
2011-05-25 04:34:18 +08:00
|
|
|
.message_pass = iic_message_pass,
|
2015-04-04 16:28:50 +08:00
|
|
|
.probe = iic_request_IPIs,
|
2005-11-01 09:08:38 +08:00
|
|
|
.kick_cpu = smp_cell_kick_cpu,
|
2008-11-28 17:51:24 +08:00
|
|
|
.setup_cpu = smp_cell_setup_cpu,
|
2013-08-06 03:58:35 +08:00
|
|
|
.cpu_bootable = smp_generic_cpu_bootable,
|
2005-11-01 09:08:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* 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 23:37:03 +08:00
|
|
|
if (cpu_thread_in_core(i) == 0)
|
2011-04-28 13:07:23 +08:00
|
|
|
cpumask_set_cpu(i, &of_spin_map);
|
2005-11-01 09:08:38 +08:00
|
|
|
}
|
2011-04-28 13:07:23 +08:00
|
|
|
} else
|
|
|
|
cpumask_copy(&of_spin_map, cpu_present_mask);
|
2005-11-01 09:08:38 +08:00
|
|
|
|
2011-04-28 13:07:23 +08:00
|
|
|
cpumask_clear_cpu(boot_cpuid, &of_spin_map);
|
2005-11-01 09:08:38 +08:00
|
|
|
|
|
|
|
/* Non-lpar has additional take/give timebase */
|
|
|
|
if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) {
|
2009-06-17 00:42:50 +08:00
|
|
|
smp_ops->give_timebase = rtas_give_timebase;
|
|
|
|
smp_ops->take_timebase = rtas_take_timebase;
|
2005-11-01 09:08:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DBG(" <- smp_init_cell()\n");
|
|
|
|
}
|