Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 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> |
Matthew McClintock | f933a41 | 2010-07-21 16:14:53 -0500 | [diff] [blame] | 18 | #include <linux/kexec.h> |
Matthew McClintock | 677de42 | 2010-09-16 17:58:26 -0500 | [diff] [blame^] | 19 | #include <linux/highmem.h> |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 20 | |
| 21 | #include <asm/machdep.h> |
| 22 | #include <asm/pgtable.h> |
| 23 | #include <asm/page.h> |
| 24 | #include <asm/mpic.h> |
| 25 | #include <asm/cacheflush.h> |
Kumar Gala | 563fdd4 | 2009-02-11 22:50:42 -0600 | [diff] [blame] | 26 | #include <asm/dbell.h> |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 27 | |
| 28 | #include <sysdev/fsl_soc.h> |
Matthew McClintock | f933a41 | 2010-07-21 16:14:53 -0500 | [diff] [blame] | 29 | #include <sysdev/mpic.h> |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 30 | |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 31 | extern void __early_start(void); |
| 32 | |
| 33 | #define BOOT_ENTRY_ADDR_UPPER 0 |
| 34 | #define BOOT_ENTRY_ADDR_LOWER 1 |
| 35 | #define BOOT_ENTRY_R3_UPPER 2 |
| 36 | #define BOOT_ENTRY_R3_LOWER 3 |
| 37 | #define BOOT_ENTRY_RESV 4 |
| 38 | #define BOOT_ENTRY_PIR 5 |
| 39 | #define BOOT_ENTRY_R6_UPPER 6 |
| 40 | #define BOOT_ENTRY_R6_LOWER 7 |
| 41 | #define NUM_BOOT_ENTRY 8 |
| 42 | #define SIZE_BOOT_ENTRY (NUM_BOOT_ENTRY * sizeof(u32)) |
| 43 | |
| 44 | static void __init |
| 45 | smp_85xx_kick_cpu(int nr) |
| 46 | { |
| 47 | unsigned long flags; |
| 48 | const u64 *cpu_rel_addr; |
| 49 | __iomem u32 *bptr_vaddr; |
| 50 | struct device_node *np; |
| 51 | int n = 0; |
Peter Tyser | d1d47ec | 2009-12-18 16:50:37 -0600 | [diff] [blame] | 52 | int ioremappable; |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 53 | |
| 54 | WARN_ON (nr < 0 || nr >= NR_CPUS); |
| 55 | |
| 56 | pr_debug("smp_85xx_kick_cpu: kick CPU #%d\n", nr); |
| 57 | |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 58 | np = of_get_cpu_node(nr, NULL); |
| 59 | cpu_rel_addr = of_get_property(np, "cpu-release-addr", NULL); |
| 60 | |
| 61 | if (cpu_rel_addr == NULL) { |
| 62 | printk(KERN_ERR "No cpu-release-addr for cpu %d\n", nr); |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 63 | return; |
| 64 | } |
| 65 | |
Peter Tyser | d1d47ec | 2009-12-18 16:50:37 -0600 | [diff] [blame] | 66 | /* |
| 67 | * A secondary core could be in a spinloop in the bootpage |
| 68 | * (0xfffff000), somewhere in highmem, or somewhere in lowmem. |
| 69 | * The bootpage and highmem can be accessed via ioremap(), but |
| 70 | * we need to directly access the spinloop if its in lowmem. |
| 71 | */ |
| 72 | ioremappable = *cpu_rel_addr > virt_to_phys(high_memory); |
| 73 | |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 74 | /* Map the spin table */ |
Peter Tyser | d1d47ec | 2009-12-18 16:50:37 -0600 | [diff] [blame] | 75 | if (ioremappable) |
| 76 | bptr_vaddr = ioremap(*cpu_rel_addr, SIZE_BOOT_ENTRY); |
| 77 | else |
| 78 | bptr_vaddr = phys_to_virt(*cpu_rel_addr); |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 79 | |
Kumar Gala | cb1ffb620 | 2009-06-19 03:30:42 -0500 | [diff] [blame] | 80 | local_irq_save(flags); |
| 81 | |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 82 | out_be32(bptr_vaddr + BOOT_ENTRY_PIR, nr); |
Kumar Gala | 5b8544c | 2010-10-08 10:37:31 -0500 | [diff] [blame] | 83 | #ifdef CONFIG_PPC32 |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 84 | out_be32(bptr_vaddr + BOOT_ENTRY_ADDR_LOWER, __pa(__early_start)); |
| 85 | |
Peter Tyser | d1d47ec | 2009-12-18 16:50:37 -0600 | [diff] [blame] | 86 | if (!ioremappable) |
| 87 | flush_dcache_range((ulong)bptr_vaddr, |
| 88 | (ulong)(bptr_vaddr + SIZE_BOOT_ENTRY)); |
| 89 | |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 90 | /* Wait a bit for the CPU to ack. */ |
| 91 | while ((__secondary_hold_acknowledge != nr) && (++n < 1000)) |
| 92 | mdelay(1); |
Kumar Gala | 5b8544c | 2010-10-08 10:37:31 -0500 | [diff] [blame] | 93 | #else |
| 94 | out_be64((u64 *)(bptr_vaddr + BOOT_ENTRY_ADDR_UPPER), |
| 95 | __pa((u64)*((unsigned long long *) generic_secondary_smp_init))); |
| 96 | |
| 97 | smp_generic_kick_cpu(nr); |
| 98 | #endif |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 99 | |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 100 | local_irq_restore(flags); |
| 101 | |
Peter Tyser | d1d47ec | 2009-12-18 16:50:37 -0600 | [diff] [blame] | 102 | if (ioremappable) |
| 103 | iounmap(bptr_vaddr); |
Kumar Gala | cb1ffb620 | 2009-06-19 03:30:42 -0500 | [diff] [blame] | 104 | |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 105 | pr_debug("waited %d msecs for CPU #%d.\n", n, nr); |
| 106 | } |
| 107 | |
| 108 | static void __init |
Kumar Gala | 563fdd4 | 2009-02-11 22:50:42 -0600 | [diff] [blame] | 109 | smp_85xx_setup_cpu(int cpu_nr) |
| 110 | { |
| 111 | mpic_setup_this_cpu(); |
Benjamin Herrenschmidt | b9f1cd7 | 2010-07-09 15:29:53 +1000 | [diff] [blame] | 112 | if (cpu_has_feature(CPU_FTR_DBELL)) |
| 113 | doorbell_setup_this_cpu(); |
Kumar Gala | 563fdd4 | 2009-02-11 22:50:42 -0600 | [diff] [blame] | 114 | } |
| 115 | |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 116 | struct smp_ops_t smp_85xx_ops = { |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 117 | .kick_cpu = smp_85xx_kick_cpu, |
Matthew McClintock | f933a41 | 2010-07-21 16:14:53 -0500 | [diff] [blame] | 118 | #ifdef CONFIG_KEXEC |
| 119 | .give_timebase = smp_generic_give_timebase, |
| 120 | .take_timebase = smp_generic_take_timebase, |
| 121 | #endif |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 122 | }; |
| 123 | |
Matthew McClintock | f933a41 | 2010-07-21 16:14:53 -0500 | [diff] [blame] | 124 | #ifdef CONFIG_KEXEC |
Matthew McClintock | 5d69296 | 2010-09-16 17:58:25 -0500 | [diff] [blame] | 125 | atomic_t kexec_down_cpus = ATOMIC_INIT(0); |
Matthew McClintock | f933a41 | 2010-07-21 16:14:53 -0500 | [diff] [blame] | 126 | |
| 127 | void mpc85xx_smp_kexec_cpu_down(int crash_shutdown, int secondary) |
| 128 | { |
Matthew McClintock | 5d69296 | 2010-09-16 17:58:25 -0500 | [diff] [blame] | 129 | local_irq_disable(); |
Matthew McClintock | f933a41 | 2010-07-21 16:14:53 -0500 | [diff] [blame] | 130 | |
Matthew McClintock | 5d69296 | 2010-09-16 17:58:25 -0500 | [diff] [blame] | 131 | if (secondary) { |
| 132 | atomic_inc(&kexec_down_cpus); |
| 133 | /* loop forever */ |
Matthew McClintock | f933a41 | 2010-07-21 16:14:53 -0500 | [diff] [blame] | 134 | while (1); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | static void mpc85xx_smp_kexec_down(void *arg) |
| 139 | { |
| 140 | if (ppc_md.kexec_cpu_down) |
| 141 | ppc_md.kexec_cpu_down(0,1); |
| 142 | } |
| 143 | |
Matthew McClintock | 677de42 | 2010-09-16 17:58:26 -0500 | [diff] [blame^] | 144 | static void map_and_flush(unsigned long paddr) |
| 145 | { |
| 146 | struct page *page = pfn_to_page(paddr >> PAGE_SHIFT); |
| 147 | unsigned long kaddr = (unsigned long)kmap(page); |
| 148 | |
| 149 | flush_dcache_range(kaddr, kaddr + PAGE_SIZE); |
| 150 | kunmap(page); |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Before we reset the other cores, we need to flush relevant cache |
| 155 | * out to memory so we don't get anything corrupted, some of these flushes |
| 156 | * are performed out of an overabundance of caution as interrupts are not |
| 157 | * disabled yet and we can switch cores |
| 158 | */ |
| 159 | static void mpc85xx_smp_flush_dcache_kexec(struct kimage *image) |
| 160 | { |
| 161 | kimage_entry_t *ptr, entry; |
| 162 | unsigned long paddr; |
| 163 | int i; |
| 164 | |
| 165 | if (image->type == KEXEC_TYPE_DEFAULT) { |
| 166 | /* normal kexec images are stored in temporary pages */ |
| 167 | for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE); |
| 168 | ptr = (entry & IND_INDIRECTION) ? |
| 169 | phys_to_virt(entry & PAGE_MASK) : ptr + 1) { |
| 170 | if (!(entry & IND_DESTINATION)) { |
| 171 | map_and_flush(entry); |
| 172 | } |
| 173 | } |
| 174 | /* flush out last IND_DONE page */ |
| 175 | map_and_flush(entry); |
| 176 | } else { |
| 177 | /* crash type kexec images are copied to the crash region */ |
| 178 | for (i = 0; i < image->nr_segments; i++) { |
| 179 | struct kexec_segment *seg = &image->segment[i]; |
| 180 | for (paddr = seg->mem; paddr < seg->mem + seg->memsz; |
| 181 | paddr += PAGE_SIZE) { |
| 182 | map_and_flush(paddr); |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /* also flush the kimage struct to be passed in as well */ |
| 188 | flush_dcache_range((unsigned long)image, |
| 189 | (unsigned long)image + sizeof(*image)); |
| 190 | } |
| 191 | |
Matthew McClintock | f933a41 | 2010-07-21 16:14:53 -0500 | [diff] [blame] | 192 | static void mpc85xx_smp_machine_kexec(struct kimage *image) |
| 193 | { |
Matthew McClintock | 5d69296 | 2010-09-16 17:58:25 -0500 | [diff] [blame] | 194 | int timeout = INT_MAX; |
| 195 | int i, num_cpus = num_present_cpus(); |
Matthew McClintock | f933a41 | 2010-07-21 16:14:53 -0500 | [diff] [blame] | 196 | |
Matthew McClintock | 677de42 | 2010-09-16 17:58:26 -0500 | [diff] [blame^] | 197 | mpc85xx_smp_flush_dcache_kexec(image); |
Matthew McClintock | f933a41 | 2010-07-21 16:14:53 -0500 | [diff] [blame] | 198 | |
Matthew McClintock | 5d69296 | 2010-09-16 17:58:25 -0500 | [diff] [blame] | 199 | if (image->type == KEXEC_TYPE_DEFAULT) |
| 200 | smp_call_function(mpc85xx_smp_kexec_down, NULL, 0); |
Matthew McClintock | f933a41 | 2010-07-21 16:14:53 -0500 | [diff] [blame] | 201 | |
Matthew McClintock | 5d69296 | 2010-09-16 17:58:25 -0500 | [diff] [blame] | 202 | while ( (atomic_read(&kexec_down_cpus) != (num_cpus - 1)) && |
Matthew McClintock | f933a41 | 2010-07-21 16:14:53 -0500 | [diff] [blame] | 203 | ( timeout > 0 ) ) |
| 204 | { |
| 205 | timeout--; |
| 206 | } |
| 207 | |
| 208 | if ( !timeout ) |
| 209 | printk(KERN_ERR "Unable to bring down secondary cpu(s)"); |
| 210 | |
Matthew McClintock | 5d69296 | 2010-09-16 17:58:25 -0500 | [diff] [blame] | 211 | for (i = 0; i < num_cpus; i++) |
Matthew McClintock | f933a41 | 2010-07-21 16:14:53 -0500 | [diff] [blame] | 212 | { |
| 213 | if ( i == smp_processor_id() ) continue; |
| 214 | mpic_reset_core(i); |
| 215 | } |
| 216 | |
| 217 | default_machine_kexec(image); |
| 218 | } |
| 219 | #endif /* CONFIG_KEXEC */ |
| 220 | |
Kumar Gala | 563fdd4 | 2009-02-11 22:50:42 -0600 | [diff] [blame] | 221 | void __init mpc85xx_smp_init(void) |
| 222 | { |
| 223 | struct device_node *np; |
| 224 | |
Kumar Gala | 563fdd4 | 2009-02-11 22:50:42 -0600 | [diff] [blame] | 225 | np = of_find_node_by_type(NULL, "open-pic"); |
| 226 | if (np) { |
| 227 | smp_85xx_ops.probe = smp_mpic_probe; |
| 228 | smp_85xx_ops.setup_cpu = smp_85xx_setup_cpu; |
| 229 | smp_85xx_ops.message_pass = smp_mpic_message_pass; |
Kumar Gala | 563fdd4 | 2009-02-11 22:50:42 -0600 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | if (cpu_has_feature(CPU_FTR_DBELL)) |
Benjamin Herrenschmidt | b9f1cd7 | 2010-07-09 15:29:53 +1000 | [diff] [blame] | 233 | smp_85xx_ops.message_pass = doorbell_message_pass; |
Kumar Gala | 563fdd4 | 2009-02-11 22:50:42 -0600 | [diff] [blame] | 234 | |
| 235 | BUG_ON(!smp_85xx_ops.message_pass); |
| 236 | |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 237 | smp_ops = &smp_85xx_ops; |
Matthew McClintock | f933a41 | 2010-07-21 16:14:53 -0500 | [diff] [blame] | 238 | |
| 239 | #ifdef CONFIG_KEXEC |
| 240 | ppc_md.kexec_cpu_down = mpc85xx_smp_kexec_cpu_down; |
| 241 | ppc_md.machine_kexec = mpc85xx_smp_machine_kexec; |
| 242 | #endif |
Kumar Gala | d5b26db | 2008-11-19 09:35:56 -0600 | [diff] [blame] | 243 | } |