1/* 2 * Author: Andy Fleming <afleming@freescale.com> 3 * Kumar Gala <galak@kernel.crashing.org> 4 * 5 * Copyright 2006-2008 Freescale Semiconductor Inc. 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the 9 * Free Software Foundation; either version 2 of the License, or (at your 10 * option) any later version. 11 */ 12 13#include <linux/stddef.h> 14#include <linux/kernel.h> 15#include <linux/init.h> 16#include <linux/delay.h> 17#include <linux/of.h> 18#include <linux/kexec.h> 19 20#include <asm/machdep.h> 21#include <asm/pgtable.h> 22#include <asm/page.h> 23#include <asm/mpic.h> 24#include <asm/cacheflush.h> 25#include <asm/dbell.h> 26 27#include <sysdev/fsl_soc.h> 28#include <sysdev/mpic.h> 29 30extern void __early_start(void); 31 32#define BOOT_ENTRY_ADDR_UPPER 0 33#define BOOT_ENTRY_ADDR_LOWER 1 34#define BOOT_ENTRY_R3_UPPER 2 35#define BOOT_ENTRY_R3_LOWER 3 36#define BOOT_ENTRY_RESV 4 37#define BOOT_ENTRY_PIR 5 38#define BOOT_ENTRY_R6_UPPER 6 39#define BOOT_ENTRY_R6_LOWER 7 40#define NUM_BOOT_ENTRY 8 41#define SIZE_BOOT_ENTRY (NUM_BOOT_ENTRY * sizeof(u32)) 42 43static void __init 44smp_85xx_kick_cpu(int nr) 45{ 46 unsigned long flags; 47 const u64 *cpu_rel_addr; 48 __iomem u32 *bptr_vaddr; 49 struct device_node *np; 50 int n = 0; 51 int ioremappable; 52 53 WARN_ON (nr < 0 || nr >= NR_CPUS); 54 55 pr_debug("smp_85xx_kick_cpu: kick CPU #%d\n", nr); 56 57 np = of_get_cpu_node(nr, NULL); 58 cpu_rel_addr = of_get_property(np, "cpu-release-addr", NULL); 59 60 if (cpu_rel_addr == NULL) { 61 printk(KERN_ERR "No cpu-release-addr for cpu %d\n", nr); 62 return; 63 } 64 65 /* 66 * A secondary core could be in a spinloop in the bootpage 67 * (0xfffff000), somewhere in highmem, or somewhere in lowmem. 68 * The bootpage and highmem can be accessed via ioremap(), but 69 * we need to directly access the spinloop if its in lowmem. 70 */ 71 ioremappable = *cpu_rel_addr > virt_to_phys(high_memory); 72 73 /* Map the spin table */ 74 if (ioremappable) 75 bptr_vaddr = ioremap(*cpu_rel_addr, SIZE_BOOT_ENTRY); 76 else 77 bptr_vaddr = phys_to_virt(*cpu_rel_addr); 78 79 local_irq_save(flags); 80 81 out_be32(bptr_vaddr + BOOT_ENTRY_PIR, nr); 82 out_be32(bptr_vaddr + BOOT_ENTRY_ADDR_LOWER, __pa(__early_start)); 83 84 if (!ioremappable) 85 flush_dcache_range((ulong)bptr_vaddr, 86 (ulong)(bptr_vaddr + SIZE_BOOT_ENTRY)); 87 88 /* Wait a bit for the CPU to ack. */ 89 while ((__secondary_hold_acknowledge != nr) && (++n < 1000)) 90 mdelay(1); 91 92 local_irq_restore(flags); 93 94 if (ioremappable) 95 iounmap(bptr_vaddr); 96 97 pr_debug("waited %d msecs for CPU #%d.\n", n, nr); 98} 99 100static void __init 101smp_85xx_setup_cpu(int cpu_nr) 102{ 103 mpic_setup_this_cpu(); 104 if (cpu_has_feature(CPU_FTR_DBELL)) 105 doorbell_setup_this_cpu(); 106} 107 108struct smp_ops_t smp_85xx_ops = { 109 .kick_cpu = smp_85xx_kick_cpu, 110#ifdef CONFIG_KEXEC 111 .give_timebase = smp_generic_give_timebase, 112 .take_timebase = smp_generic_take_timebase, 113#endif 114}; 115 116#ifdef CONFIG_KEXEC 117static int kexec_down_cpus = 0; 118 119void mpc85xx_smp_kexec_cpu_down(int crash_shutdown, int secondary) 120{ 121 mpic_teardown_this_cpu(1); 122 123 /* When crashing, this gets called on all CPU's we only 124 * take down the non-boot cpus */ 125 if (smp_processor_id() != boot_cpuid) 126 { 127 local_irq_disable(); 128 kexec_down_cpus++; 129 130 while (1); 131 } 132} 133 134static void mpc85xx_smp_kexec_down(void *arg) 135{ 136 if (ppc_md.kexec_cpu_down) 137 ppc_md.kexec_cpu_down(0,1); 138} 139 140static void mpc85xx_smp_machine_kexec(struct kimage *image) 141{ 142 int timeout = 2000; 143 int i; 144 145 set_cpus_allowed(current, cpumask_of_cpu(boot_cpuid)); 146 147 smp_call_function(mpc85xx_smp_kexec_down, NULL, 0); 148 149 while ( (kexec_down_cpus != (num_online_cpus() - 1)) && 150 ( timeout > 0 ) ) 151 { 152 timeout--; 153 } 154 155 if ( !timeout ) 156 printk(KERN_ERR "Unable to bring down secondary cpu(s)"); 157 158 for (i = 0; i < num_present_cpus(); i++) 159 { 160 if ( i == smp_processor_id() ) continue; 161 mpic_reset_core(i); 162 } 163 164 default_machine_kexec(image); 165} 166#endif /* CONFIG_KEXEC */ 167 168void __init mpc85xx_smp_init(void) 169{ 170 struct device_node *np; 171 172 np = of_find_node_by_type(NULL, "open-pic"); 173 if (np) { 174 smp_85xx_ops.probe = smp_mpic_probe; 175 smp_85xx_ops.setup_cpu = smp_85xx_setup_cpu; 176 smp_85xx_ops.message_pass = smp_mpic_message_pass; 177 } 178 179 if (cpu_has_feature(CPU_FTR_DBELL)) 180 smp_85xx_ops.message_pass = doorbell_message_pass; 181 182 BUG_ON(!smp_85xx_ops.message_pass); 183 184 smp_ops = &smp_85xx_ops; 185 186#ifdef CONFIG_KEXEC 187 ppc_md.kexec_cpu_down = mpc85xx_smp_kexec_cpu_down; 188 ppc_md.machine_kexec = mpc85xx_smp_machine_kexec; 189#endif 190} 191