Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Freescale Semiconductor, Inc. |
| 3 | * Copyright 2011 Linaro Ltd. |
| 4 | * |
| 5 | * The code contained herein is licensed under the GNU General Public |
| 6 | * License. You may obtain a copy of the GNU General Public License |
| 7 | * Version 2 or later at the following locations: |
| 8 | * |
| 9 | * http://www.opensource.org/licenses/gpl-license.html |
| 10 | * http://www.gnu.org/copyleft/gpl.html |
| 11 | */ |
| 12 | |
| 13 | #include <linux/init.h> |
Jingchang Lu | 4e3fea4 | 2014-10-31 17:01:13 +0800 | [diff] [blame] | 14 | #include <linux/of_address.h> |
| 15 | #include <linux/of.h> |
Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 16 | #include <linux/smp.h> |
Jingchang Lu | 4e3fea4 | 2014-10-31 17:01:13 +0800 | [diff] [blame] | 17 | |
Shawn Guo | 087bb28 | 2013-04-16 22:11:19 +0800 | [diff] [blame] | 18 | #include <asm/cacheflush.h> |
Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 19 | #include <asm/page.h> |
| 20 | #include <asm/smp_scu.h> |
Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 21 | #include <asm/mach/map.h> |
Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 22 | |
Shawn Guo | e337247 | 2012-09-13 21:01:00 +0800 | [diff] [blame] | 23 | #include "common.h" |
Shawn Guo | 50f2de6 | 2012-09-14 14:14:45 +0800 | [diff] [blame] | 24 | #include "hardware.h" |
Shawn Guo | e337247 | 2012-09-13 21:01:00 +0800 | [diff] [blame] | 25 | |
Shawn Guo | 087bb28 | 2013-04-16 22:11:19 +0800 | [diff] [blame] | 26 | u32 g_diag_reg; |
Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 27 | static void __iomem *scu_base; |
| 28 | |
| 29 | static struct map_desc scu_io_desc __initdata = { |
| 30 | /* .virtual and .pfn are run-time assigned */ |
| 31 | .length = SZ_4K, |
| 32 | .type = MT_DEVICE, |
| 33 | }; |
| 34 | |
| 35 | void __init imx_scu_map_io(void) |
| 36 | { |
| 37 | unsigned long base; |
| 38 | |
| 39 | /* Get SCU base */ |
| 40 | asm("mrc p15, 4, %0, c15, c0, 0" : "=r" (base)); |
| 41 | |
| 42 | scu_io_desc.virtual = IMX_IO_P2V(base); |
| 43 | scu_io_desc.pfn = __phys_to_pfn(base); |
| 44 | iotable_init(&scu_io_desc, 1); |
| 45 | |
| 46 | scu_base = IMX_IO_ADDRESS(base); |
| 47 | } |
| 48 | |
Paul Gortmaker | 8bd26e3 | 2013-06-17 15:43:14 -0400 | [diff] [blame] | 49 | static int imx_boot_secondary(unsigned int cpu, struct task_struct *idle) |
Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 50 | { |
| 51 | imx_set_cpu_jump(cpu, v7_secondary_startup); |
| 52 | imx_enable_cpu(cpu, true); |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | /* |
| 57 | * Initialise the CPU possible map early - this describes the CPUs |
| 58 | * which may be present or become present in the system. |
| 59 | */ |
Marc Zyngier | e4f2d97 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 60 | static void __init imx_smp_init_cpus(void) |
Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 61 | { |
| 62 | int i, ncores; |
| 63 | |
| 64 | ncores = scu_get_core_count(scu_base); |
| 65 | |
Shawn Guo | dc13ba2 | 2013-04-02 16:37:21 +0800 | [diff] [blame] | 66 | for (i = ncores; i < NR_CPUS; i++) |
| 67 | set_cpu_possible(i, false); |
Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void imx_smp_prepare(void) |
| 71 | { |
| 72 | scu_enable(scu_base); |
| 73 | } |
| 74 | |
Marc Zyngier | e4f2d97 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 75 | static void __init imx_smp_prepare_cpus(unsigned int max_cpus) |
Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 76 | { |
| 77 | imx_smp_prepare(); |
Shawn Guo | 087bb28 | 2013-04-16 22:11:19 +0800 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * The diagnostic register holds the errata bits. Mostly bootloader |
| 81 | * does not bring up secondary cores, so that when errata bits are set |
| 82 | * in bootloader, they are set only for boot cpu. But on a SMP |
| 83 | * configuration, it should be equally done on every single core. |
| 84 | * Read the register from boot cpu here, and will replicate it into |
| 85 | * secondary cores when booting them. |
| 86 | */ |
| 87 | asm("mrc p15, 0, %0, c15, c0, 1" : "=r" (g_diag_reg) : : "cc"); |
Nicolas Pitre | f45913f | 2013-12-05 14:26:16 -0500 | [diff] [blame] | 88 | sync_cache_w(&g_diag_reg); |
Shawn Guo | 69c31b7 | 2011-09-06 14:59:40 +0800 | [diff] [blame] | 89 | } |
Marc Zyngier | e4f2d97 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 90 | |
Masahiro Yamada | 7530527 | 2015-11-15 10:39:53 +0900 | [diff] [blame] | 91 | const struct smp_operations imx_smp_ops __initconst = { |
Marc Zyngier | e4f2d97 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 92 | .smp_init_cpus = imx_smp_init_cpus, |
| 93 | .smp_prepare_cpus = imx_smp_prepare_cpus, |
Marc Zyngier | e4f2d97 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 94 | .smp_boot_secondary = imx_boot_secondary, |
| 95 | #ifdef CONFIG_HOTPLUG_CPU |
| 96 | .cpu_die = imx_cpu_die, |
Shawn Guo | 8375766 | 2013-01-14 14:08:50 +0800 | [diff] [blame] | 97 | .cpu_kill = imx_cpu_kill, |
Marc Zyngier | e4f2d97 | 2011-09-08 13:15:22 +0100 | [diff] [blame] | 98 | #endif |
| 99 | }; |
Jingchang Lu | 4e3fea4 | 2014-10-31 17:01:13 +0800 | [diff] [blame] | 100 | |
| 101 | #define DCFG_CCSR_SCRATCHRW1 0x200 |
| 102 | |
| 103 | static int ls1021a_boot_secondary(unsigned int cpu, struct task_struct *idle) |
| 104 | { |
| 105 | arch_send_wakeup_ipi_mask(cpumask_of(cpu)); |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static void __init ls1021a_smp_prepare_cpus(unsigned int max_cpus) |
| 111 | { |
| 112 | struct device_node *np; |
| 113 | void __iomem *dcfg_base; |
| 114 | unsigned long paddr; |
| 115 | |
| 116 | np = of_find_compatible_node(NULL, NULL, "fsl,ls1021a-dcfg"); |
| 117 | dcfg_base = of_iomap(np, 0); |
| 118 | BUG_ON(!dcfg_base); |
| 119 | |
Florian Fainelli | 64fc2a9 | 2017-01-15 03:59:29 +0100 | [diff] [blame] | 120 | paddr = __pa_symbol(secondary_startup); |
Jingchang Lu | 4e3fea4 | 2014-10-31 17:01:13 +0800 | [diff] [blame] | 121 | writel_relaxed(cpu_to_be32(paddr), dcfg_base + DCFG_CCSR_SCRATCHRW1); |
| 122 | |
| 123 | iounmap(dcfg_base); |
| 124 | } |
| 125 | |
Masahiro Yamada | 7530527 | 2015-11-15 10:39:53 +0900 | [diff] [blame] | 126 | const struct smp_operations ls1021a_smp_ops __initconst = { |
Jingchang Lu | 4e3fea4 | 2014-10-31 17:01:13 +0800 | [diff] [blame] | 127 | .smp_prepare_cpus = ls1021a_smp_prepare_cpus, |
| 128 | .smp_boot_secondary = ls1021a_boot_secondary, |
| 129 | }; |