Path: blob/master/arch/powerpc/platforms/85xx/smp.c
10820 views
/*1* Author: Andy Fleming <[email protected]>2* Kumar Gala <[email protected]>3*4* Copyright 2006-2008 Freescale Semiconductor Inc.5*6* This program is free software; you can redistribute it and/or modify it7* under the terms of the GNU General Public License as published by the8* Free Software Foundation; either version 2 of the License, or (at your9* option) any later version.10*/1112#include <linux/stddef.h>13#include <linux/kernel.h>14#include <linux/init.h>15#include <linux/delay.h>16#include <linux/of.h>17#include <linux/kexec.h>18#include <linux/highmem.h>1920#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>2627#include <sysdev/fsl_soc.h>28#include <sysdev/mpic.h>2930extern void __early_start(void);3132#define BOOT_ENTRY_ADDR_UPPER 033#define BOOT_ENTRY_ADDR_LOWER 134#define BOOT_ENTRY_R3_UPPER 235#define BOOT_ENTRY_R3_LOWER 336#define BOOT_ENTRY_RESV 437#define BOOT_ENTRY_PIR 538#define BOOT_ENTRY_R6_UPPER 639#define BOOT_ENTRY_R6_LOWER 740#define NUM_BOOT_ENTRY 841#define SIZE_BOOT_ENTRY (NUM_BOOT_ENTRY * sizeof(u32))4243static int __init44smp_85xx_kick_cpu(int nr)45{46unsigned long flags;47const u64 *cpu_rel_addr;48__iomem u32 *bptr_vaddr;49struct device_node *np;50int n = 0;51int ioremappable;5253WARN_ON (nr < 0 || nr >= NR_CPUS);5455pr_debug("smp_85xx_kick_cpu: kick CPU #%d\n", nr);5657np = of_get_cpu_node(nr, NULL);58cpu_rel_addr = of_get_property(np, "cpu-release-addr", NULL);5960if (cpu_rel_addr == NULL) {61printk(KERN_ERR "No cpu-release-addr for cpu %d\n", nr);62return -ENOENT;63}6465/*66* A secondary core could be in a spinloop in the bootpage67* (0xfffff000), somewhere in highmem, or somewhere in lowmem.68* The bootpage and highmem can be accessed via ioremap(), but69* we need to directly access the spinloop if its in lowmem.70*/71ioremappable = *cpu_rel_addr > virt_to_phys(high_memory);7273/* Map the spin table */74if (ioremappable)75bptr_vaddr = ioremap(*cpu_rel_addr, SIZE_BOOT_ENTRY);76else77bptr_vaddr = phys_to_virt(*cpu_rel_addr);7879local_irq_save(flags);8081out_be32(bptr_vaddr + BOOT_ENTRY_PIR, nr);82#ifdef CONFIG_PPC3283out_be32(bptr_vaddr + BOOT_ENTRY_ADDR_LOWER, __pa(__early_start));8485if (!ioremappable)86flush_dcache_range((ulong)bptr_vaddr,87(ulong)(bptr_vaddr + SIZE_BOOT_ENTRY));8889/* Wait a bit for the CPU to ack. */90while ((__secondary_hold_acknowledge != nr) && (++n < 1000))91mdelay(1);92#else93smp_generic_kick_cpu(nr);9495out_be64((u64 *)(bptr_vaddr + BOOT_ENTRY_ADDR_UPPER),96__pa((u64)*((unsigned long long *) generic_secondary_smp_init)));9798if (!ioremappable)99flush_dcache_range((ulong)bptr_vaddr,100(ulong)(bptr_vaddr + SIZE_BOOT_ENTRY));101#endif102103local_irq_restore(flags);104105if (ioremappable)106iounmap(bptr_vaddr);107108pr_debug("waited %d msecs for CPU #%d.\n", n, nr);109110return 0;111}112113static void __init114smp_85xx_setup_cpu(int cpu_nr)115{116mpic_setup_this_cpu();117if (cpu_has_feature(CPU_FTR_DBELL))118doorbell_setup_this_cpu();119}120121struct smp_ops_t smp_85xx_ops = {122.kick_cpu = smp_85xx_kick_cpu,123#ifdef CONFIG_KEXEC124.give_timebase = smp_generic_give_timebase,125.take_timebase = smp_generic_take_timebase,126#endif127};128129#ifdef CONFIG_KEXEC130atomic_t kexec_down_cpus = ATOMIC_INIT(0);131132void mpc85xx_smp_kexec_cpu_down(int crash_shutdown, int secondary)133{134local_irq_disable();135136if (secondary) {137atomic_inc(&kexec_down_cpus);138/* loop forever */139while (1);140}141}142143static void mpc85xx_smp_kexec_down(void *arg)144{145if (ppc_md.kexec_cpu_down)146ppc_md.kexec_cpu_down(0,1);147}148149static void map_and_flush(unsigned long paddr)150{151struct page *page = pfn_to_page(paddr >> PAGE_SHIFT);152unsigned long kaddr = (unsigned long)kmap(page);153154flush_dcache_range(kaddr, kaddr + PAGE_SIZE);155kunmap(page);156}157158/**159* Before we reset the other cores, we need to flush relevant cache160* out to memory so we don't get anything corrupted, some of these flushes161* are performed out of an overabundance of caution as interrupts are not162* disabled yet and we can switch cores163*/164static void mpc85xx_smp_flush_dcache_kexec(struct kimage *image)165{166kimage_entry_t *ptr, entry;167unsigned long paddr;168int i;169170if (image->type == KEXEC_TYPE_DEFAULT) {171/* normal kexec images are stored in temporary pages */172for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE);173ptr = (entry & IND_INDIRECTION) ?174phys_to_virt(entry & PAGE_MASK) : ptr + 1) {175if (!(entry & IND_DESTINATION)) {176map_and_flush(entry);177}178}179/* flush out last IND_DONE page */180map_and_flush(entry);181} else {182/* crash type kexec images are copied to the crash region */183for (i = 0; i < image->nr_segments; i++) {184struct kexec_segment *seg = &image->segment[i];185for (paddr = seg->mem; paddr < seg->mem + seg->memsz;186paddr += PAGE_SIZE) {187map_and_flush(paddr);188}189}190}191192/* also flush the kimage struct to be passed in as well */193flush_dcache_range((unsigned long)image,194(unsigned long)image + sizeof(*image));195}196197static void mpc85xx_smp_machine_kexec(struct kimage *image)198{199int timeout = INT_MAX;200int i, num_cpus = num_present_cpus();201202mpc85xx_smp_flush_dcache_kexec(image);203204if (image->type == KEXEC_TYPE_DEFAULT)205smp_call_function(mpc85xx_smp_kexec_down, NULL, 0);206207while ( (atomic_read(&kexec_down_cpus) != (num_cpus - 1)) &&208( timeout > 0 ) )209{210timeout--;211}212213if ( !timeout )214printk(KERN_ERR "Unable to bring down secondary cpu(s)");215216for (i = 0; i < num_cpus; i++)217{218if ( i == smp_processor_id() ) continue;219mpic_reset_core(i);220}221222default_machine_kexec(image);223}224#endif /* CONFIG_KEXEC */225226void __init mpc85xx_smp_init(void)227{228struct device_node *np;229230np = of_find_node_by_type(NULL, "open-pic");231if (np) {232smp_85xx_ops.probe = smp_mpic_probe;233smp_85xx_ops.setup_cpu = smp_85xx_setup_cpu;234smp_85xx_ops.message_pass = smp_mpic_message_pass;235}236237if (cpu_has_feature(CPU_FTR_DBELL)) {238smp_85xx_ops.message_pass = smp_muxed_ipi_message_pass;239smp_85xx_ops.cause_ipi = doorbell_cause_ipi;240}241242BUG_ON(!smp_85xx_ops.message_pass);243244smp_ops = &smp_85xx_ops;245246#ifdef CONFIG_KEXEC247ppc_md.kexec_cpu_down = mpc85xx_smp_kexec_cpu_down;248ppc_md.machine_kexec = mpc85xx_smp_machine_kexec;249#endif250}251252253