Jon Loeliger | 4ca4b62 | 2006-06-17 17:52:45 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Author: Xianghua Xiao <x.xiao@freescale.com> |
| 3 | * Zhang Wei <wei.zhang@freescale.com> |
| 4 | * |
| 5 | * Copyright 2006 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 | |
Jon Loeliger | 4ca4b62 | 2006-06-17 17:52:45 -0500 | [diff] [blame] | 13 | #include <linux/stddef.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/delay.h> |
| 17 | |
Michael Ellerman | aaddd3e | 2008-06-24 11:32:21 +1000 | [diff] [blame] | 18 | #include <asm/code-patching.h> |
Jon Loeliger | 4ca4b62 | 2006-06-17 17:52:45 -0500 | [diff] [blame] | 19 | #include <asm/page.h> |
David Gibson | f1a1eb2 | 2007-05-09 15:20:37 +1000 | [diff] [blame] | 20 | #include <asm/pgtable.h> |
Jon Loeliger | 4ca4b62 | 2006-06-17 17:52:45 -0500 | [diff] [blame] | 21 | #include <asm/pci-bridge.h> |
Stephen Rothwell | b8b572e | 2008-08-01 15:20:30 +1000 | [diff] [blame] | 22 | #include <asm/mpic.h> |
Jon Loeliger | 4ca4b62 | 2006-06-17 17:52:45 -0500 | [diff] [blame] | 23 | #include <asm/mpc86xx.h> |
| 24 | #include <asm/cacheflush.h> |
| 25 | |
| 26 | #include <sysdev/fsl_soc.h> |
| 27 | |
| 28 | #include "mpc86xx.h" |
| 29 | |
| 30 | extern void __secondary_start_mpc86xx(void); |
| 31 | extern unsigned long __secondary_hold_acknowledge; |
| 32 | |
| 33 | |
| 34 | static void __init |
| 35 | smp_86xx_release_core(int nr) |
| 36 | { |
Kumar Gala | 9ad494f | 2006-06-28 00:37:45 -0500 | [diff] [blame] | 37 | __be32 __iomem *mcm_vaddr; |
| 38 | unsigned long pcr; |
Jon Loeliger | 4ca4b62 | 2006-06-17 17:52:45 -0500 | [diff] [blame] | 39 | |
| 40 | if (nr < 0 || nr >= NR_CPUS) |
| 41 | return; |
| 42 | |
| 43 | /* |
| 44 | * Startup Core #nr. |
| 45 | */ |
| 46 | mcm_vaddr = ioremap(get_immrbase() + MPC86xx_MCM_OFFSET, |
| 47 | MPC86xx_MCM_SIZE); |
Kumar Gala | 9ad494f | 2006-06-28 00:37:45 -0500 | [diff] [blame] | 48 | pcr = in_be32(mcm_vaddr + (MCM_PORT_CONFIG_OFFSET >> 2)); |
Jon Loeliger | 4ca4b62 | 2006-06-17 17:52:45 -0500 | [diff] [blame] | 49 | pcr |= 1 << (nr + 24); |
Kumar Gala | 9ad494f | 2006-06-28 00:37:45 -0500 | [diff] [blame] | 50 | out_be32(mcm_vaddr + (MCM_PORT_CONFIG_OFFSET >> 2), pcr); |
Jon Loeliger | 4ca4b62 | 2006-06-17 17:52:45 -0500 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | |
| 54 | static void __init |
| 55 | smp_86xx_kick_cpu(int nr) |
| 56 | { |
| 57 | unsigned int save_vector; |
| 58 | unsigned long target, flags; |
| 59 | int n = 0; |
Michael Ellerman | e7a5727 | 2008-06-24 11:32:22 +1000 | [diff] [blame] | 60 | unsigned int *vector = (unsigned int *)(KERNELBASE + 0x100); |
Jon Loeliger | 4ca4b62 | 2006-06-17 17:52:45 -0500 | [diff] [blame] | 61 | |
| 62 | if (nr < 0 || nr >= NR_CPUS) |
| 63 | return; |
| 64 | |
| 65 | pr_debug("smp_86xx_kick_cpu: kick CPU #%d\n", nr); |
| 66 | |
| 67 | local_irq_save(flags); |
Jon Loeliger | 4ca4b62 | 2006-06-17 17:52:45 -0500 | [diff] [blame] | 68 | |
| 69 | /* Save reset vector */ |
| 70 | save_vector = *vector; |
| 71 | |
| 72 | /* Setup fake reset vector to call __secondary_start_mpc86xx. */ |
| 73 | target = (unsigned long) __secondary_start_mpc86xx; |
Michael Ellerman | e7a5727 | 2008-06-24 11:32:22 +1000 | [diff] [blame] | 74 | patch_branch(vector, target, BRANCH_SET_LINK); |
Jon Loeliger | 4ca4b62 | 2006-06-17 17:52:45 -0500 | [diff] [blame] | 75 | |
| 76 | /* Kick that CPU */ |
| 77 | smp_86xx_release_core(nr); |
| 78 | |
| 79 | /* Wait a bit for the CPU to take the exception. */ |
| 80 | while ((__secondary_hold_acknowledge != nr) && (n++, n < 1000)) |
| 81 | mdelay(1); |
| 82 | |
| 83 | /* Restore the exception vector */ |
| 84 | *vector = save_vector; |
| 85 | flush_icache_range((unsigned long) vector, (unsigned long) vector + 4); |
| 86 | |
| 87 | local_irq_restore(flags); |
| 88 | |
| 89 | pr_debug("wait CPU #%d for %d msecs.\n", nr, n); |
| 90 | } |
| 91 | |
| 92 | |
| 93 | static void __init |
| 94 | smp_86xx_setup_cpu(int cpu_nr) |
| 95 | { |
| 96 | mpic_setup_this_cpu(); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | struct smp_ops_t smp_86xx_ops = { |
| 101 | .message_pass = smp_mpic_message_pass, |
| 102 | .probe = smp_mpic_probe, |
| 103 | .kick_cpu = smp_86xx_kick_cpu, |
| 104 | .setup_cpu = smp_86xx_setup_cpu, |
| 105 | .take_timebase = smp_generic_take_timebase, |
| 106 | .give_timebase = smp_generic_give_timebase, |
| 107 | }; |
| 108 | |
| 109 | |
| 110 | void __init |
| 111 | mpc86xx_smp_init(void) |
| 112 | { |
| 113 | smp_ops = &smp_86xx_ops; |
| 114 | } |