2008-11-19 08:35:56 -07:00
|
|
|
/*
|
|
|
|
* Author: Andy Fleming <afleming@freescale.com>
|
|
|
|
* Kumar Gala <galak@kernel.crashing.org>
|
|
|
|
*
|
|
|
|
* Copyright 2006-2008 Freescale Semiconductor Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/stddef.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/of.h>
|
2010-07-21 15:14:53 -06:00
|
|
|
#include <linux/kexec.h>
|
2008-11-19 08:35:56 -07:00
|
|
|
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/mpic.h>
|
|
|
|
#include <asm/cacheflush.h>
|
2009-02-11 21:50:42 -07:00
|
|
|
#include <asm/dbell.h>
|
2008-11-19 08:35:56 -07:00
|
|
|
|
|
|
|
#include <sysdev/fsl_soc.h>
|
2010-07-21 15:14:53 -06:00
|
|
|
#include <sysdev/mpic.h>
|
2008-11-19 08:35:56 -07:00
|
|
|
|
|
|
|
extern void __early_start(void);
|
|
|
|
|
|
|
|
#define BOOT_ENTRY_ADDR_UPPER 0
|
|
|
|
#define BOOT_ENTRY_ADDR_LOWER 1
|
|
|
|
#define BOOT_ENTRY_R3_UPPER 2
|
|
|
|
#define BOOT_ENTRY_R3_LOWER 3
|
|
|
|
#define BOOT_ENTRY_RESV 4
|
|
|
|
#define BOOT_ENTRY_PIR 5
|
|
|
|
#define BOOT_ENTRY_R6_UPPER 6
|
|
|
|
#define BOOT_ENTRY_R6_LOWER 7
|
|
|
|
#define NUM_BOOT_ENTRY 8
|
|
|
|
#define SIZE_BOOT_ENTRY (NUM_BOOT_ENTRY * sizeof(u32))
|
|
|
|
|
|
|
|
static void __init
|
|
|
|
smp_85xx_kick_cpu(int nr)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
const u64 *cpu_rel_addr;
|
|
|
|
__iomem u32 *bptr_vaddr;
|
|
|
|
struct device_node *np;
|
|
|
|
int n = 0;
|
2009-12-18 15:50:37 -07:00
|
|
|
int ioremappable;
|
2008-11-19 08:35:56 -07:00
|
|
|
|
|
|
|
WARN_ON (nr < 0 || nr >= NR_CPUS);
|
|
|
|
|
|
|
|
pr_debug("smp_85xx_kick_cpu: kick CPU #%d\n", nr);
|
|
|
|
|
|
|
|
np = of_get_cpu_node(nr, NULL);
|
|
|
|
cpu_rel_addr = of_get_property(np, "cpu-release-addr", NULL);
|
|
|
|
|
|
|
|
if (cpu_rel_addr == NULL) {
|
|
|
|
printk(KERN_ERR "No cpu-release-addr for cpu %d\n", nr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-18 15:50:37 -07:00
|
|
|
/*
|
|
|
|
* A secondary core could be in a spinloop in the bootpage
|
|
|
|
* (0xfffff000), somewhere in highmem, or somewhere in lowmem.
|
|
|
|
* The bootpage and highmem can be accessed via ioremap(), but
|
|
|
|
* we need to directly access the spinloop if its in lowmem.
|
|
|
|
*/
|
|
|
|
ioremappable = *cpu_rel_addr > virt_to_phys(high_memory);
|
|
|
|
|
2008-11-19 08:35:56 -07:00
|
|
|
/* Map the spin table */
|
2009-12-18 15:50:37 -07:00
|
|
|
if (ioremappable)
|
|
|
|
bptr_vaddr = ioremap(*cpu_rel_addr, SIZE_BOOT_ENTRY);
|
|
|
|
else
|
|
|
|
bptr_vaddr = phys_to_virt(*cpu_rel_addr);
|
2008-11-19 08:35:56 -07:00
|
|
|
|
2009-06-19 02:30:42 -06:00
|
|
|
local_irq_save(flags);
|
|
|
|
|
2008-11-19 08:35:56 -07:00
|
|
|
out_be32(bptr_vaddr + BOOT_ENTRY_PIR, nr);
|
2010-10-08 09:37:31 -06:00
|
|
|
#ifdef CONFIG_PPC32
|
2008-11-19 08:35:56 -07:00
|
|
|
out_be32(bptr_vaddr + BOOT_ENTRY_ADDR_LOWER, __pa(__early_start));
|
|
|
|
|
2009-12-18 15:50:37 -07:00
|
|
|
if (!ioremappable)
|
|
|
|
flush_dcache_range((ulong)bptr_vaddr,
|
|
|
|
(ulong)(bptr_vaddr + SIZE_BOOT_ENTRY));
|
|
|
|
|
2008-11-19 08:35:56 -07:00
|
|
|
/* Wait a bit for the CPU to ack. */
|
|
|
|
while ((__secondary_hold_acknowledge != nr) && (++n < 1000))
|
|
|
|
mdelay(1);
|
2010-10-08 09:37:31 -06:00
|
|
|
#else
|
|
|
|
out_be64((u64 *)(bptr_vaddr + BOOT_ENTRY_ADDR_UPPER),
|
|
|
|
__pa((u64)*((unsigned long long *) generic_secondary_smp_init)));
|
|
|
|
|
|
|
|
smp_generic_kick_cpu(nr);
|
|
|
|
#endif
|
2008-11-19 08:35:56 -07:00
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
2009-12-18 15:50:37 -07:00
|
|
|
if (ioremappable)
|
|
|
|
iounmap(bptr_vaddr);
|
2009-06-19 02:30:42 -06:00
|
|
|
|
2008-11-19 08:35:56 -07:00
|
|
|
pr_debug("waited %d msecs for CPU #%d.\n", n, nr);
|
|
|
|
}
|
|
|
|
|
2009-02-11 21:50:42 -07:00
|
|
|
static void __init
|
|
|
|
smp_85xx_setup_cpu(int cpu_nr)
|
|
|
|
{
|
|
|
|
mpic_setup_this_cpu();
|
2010-07-08 23:29:53 -06:00
|
|
|
if (cpu_has_feature(CPU_FTR_DBELL))
|
|
|
|
doorbell_setup_this_cpu();
|
2009-02-11 21:50:42 -07:00
|
|
|
}
|
|
|
|
|
2008-11-19 08:35:56 -07:00
|
|
|
struct smp_ops_t smp_85xx_ops = {
|
|
|
|
.kick_cpu = smp_85xx_kick_cpu,
|
2010-07-21 15:14:53 -06:00
|
|
|
#ifdef CONFIG_KEXEC
|
|
|
|
.give_timebase = smp_generic_give_timebase,
|
|
|
|
.take_timebase = smp_generic_take_timebase,
|
|
|
|
#endif
|
2008-11-19 08:35:56 -07:00
|
|
|
};
|
|
|
|
|
2010-07-21 15:14:53 -06:00
|
|
|
#ifdef CONFIG_KEXEC
|
|
|
|
static int kexec_down_cpus = 0;
|
|
|
|
|
|
|
|
void mpc85xx_smp_kexec_cpu_down(int crash_shutdown, int secondary)
|
|
|
|
{
|
|
|
|
/* When crashing, this gets called on all CPU's we only
|
|
|
|
* take down the non-boot cpus */
|
|
|
|
if (smp_processor_id() != boot_cpuid)
|
|
|
|
{
|
|
|
|
local_irq_disable();
|
|
|
|
kexec_down_cpus++;
|
|
|
|
|
|
|
|
while (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mpc85xx_smp_kexec_down(void *arg)
|
|
|
|
{
|
|
|
|
if (ppc_md.kexec_cpu_down)
|
|
|
|
ppc_md.kexec_cpu_down(0,1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mpc85xx_smp_machine_kexec(struct kimage *image)
|
|
|
|
{
|
|
|
|
int timeout = 2000;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
set_cpus_allowed(current, cpumask_of_cpu(boot_cpuid));
|
|
|
|
|
|
|
|
smp_call_function(mpc85xx_smp_kexec_down, NULL, 0);
|
|
|
|
|
|
|
|
while ( (kexec_down_cpus != (num_online_cpus() - 1)) &&
|
|
|
|
( timeout > 0 ) )
|
|
|
|
{
|
|
|
|
timeout--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !timeout )
|
|
|
|
printk(KERN_ERR "Unable to bring down secondary cpu(s)");
|
|
|
|
|
|
|
|
for (i = 0; i < num_present_cpus(); i++)
|
|
|
|
{
|
|
|
|
if ( i == smp_processor_id() ) continue;
|
|
|
|
mpic_reset_core(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
default_machine_kexec(image);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_KEXEC */
|
|
|
|
|
2009-02-11 21:50:42 -07:00
|
|
|
void __init mpc85xx_smp_init(void)
|
|
|
|
{
|
|
|
|
struct device_node *np;
|
|
|
|
|
|
|
|
np = of_find_node_by_type(NULL, "open-pic");
|
|
|
|
if (np) {
|
|
|
|
smp_85xx_ops.probe = smp_mpic_probe;
|
|
|
|
smp_85xx_ops.setup_cpu = smp_85xx_setup_cpu;
|
|
|
|
smp_85xx_ops.message_pass = smp_mpic_message_pass;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cpu_has_feature(CPU_FTR_DBELL))
|
2010-07-08 23:29:53 -06:00
|
|
|
smp_85xx_ops.message_pass = doorbell_message_pass;
|
2009-02-11 21:50:42 -07:00
|
|
|
|
|
|
|
BUG_ON(!smp_85xx_ops.message_pass);
|
|
|
|
|
2008-11-19 08:35:56 -07:00
|
|
|
smp_ops = &smp_85xx_ops;
|
2010-07-21 15:14:53 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_KEXEC
|
|
|
|
ppc_md.kexec_cpu_down = mpc85xx_smp_kexec_cpu_down;
|
|
|
|
ppc_md.machine_kexec = mpc85xx_smp_machine_kexec;
|
|
|
|
#endif
|
2008-11-19 08:35:56 -07:00
|
|
|
}
|