Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Symmetric Multi Processing (SMP) support for Armada XP |
| 3 | * |
| 4 | * Copyright (C) 2012 Marvell |
| 5 | * |
| 6 | * Lior Amsalem <alior@marvell.com> |
| 7 | * Yehuda Yitschak <yehuday@marvell.com> |
| 8 | * Gregory CLEMENT <gregory.clement@free-electrons.com> |
| 9 | * Thomas Petazzoni <thomas.petazzoni@free-electrons.com> |
| 10 | * |
| 11 | * This file is licensed under the terms of the GNU General Public |
| 12 | * License version 2. This program is licensed "as is" without any |
| 13 | * warranty of any kind, whether express or implied. |
| 14 | * |
| 15 | * The Armada XP SoC has 4 ARMv7 PJ4B CPUs running in full HW coherency |
| 16 | * This file implements the routines for preparing the SMP infrastructure |
| 17 | * and waking up the secondary CPUs |
| 18 | */ |
| 19 | |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/smp.h> |
| 22 | #include <linux/clk.h> |
| 23 | #include <linux/of.h> |
Ezequiel Garcia | 994c8c9 | 2013-07-26 10:17:54 -0300 | [diff] [blame] | 24 | #include <linux/of_address.h> |
Thomas Petazzoni | 87e1bed | 2013-03-21 17:59:15 +0100 | [diff] [blame] | 25 | #include <linux/mbus.h> |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 26 | #include <asm/cacheflush.h> |
| 27 | #include <asm/smp_plat.h> |
| 28 | #include "common.h" |
| 29 | #include "armada-370-xp.h" |
| 30 | #include "pmsu.h" |
| 31 | #include "coherency.h" |
| 32 | |
Ezequiel Garcia | 994c8c9 | 2013-07-26 10:17:54 -0300 | [diff] [blame] | 33 | #define AXP_BOOTROM_BASE 0xfff00000 |
| 34 | #define AXP_BOOTROM_SIZE 0x100000 |
| 35 | |
Sudeep KarkadaNagesha | f6cec7c | 2013-07-03 16:01:42 +0100 | [diff] [blame] | 36 | static struct clk *__init get_cpu_clk(int cpu) |
| 37 | { |
| 38 | struct clk *cpu_clk; |
| 39 | struct device_node *np = of_get_cpu_node(cpu, NULL); |
| 40 | |
| 41 | if (WARN(!np, "missing cpu node\n")) |
| 42 | return NULL; |
| 43 | cpu_clk = of_clk_get(np, 0); |
| 44 | if (WARN_ON(IS_ERR(cpu_clk))) |
| 45 | return NULL; |
| 46 | return cpu_clk; |
| 47 | } |
| 48 | |
Jisheng Zhang | b12634e | 2013-11-07 17:02:38 +0800 | [diff] [blame] | 49 | static void __init set_secondary_cpus_clock(void) |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 50 | { |
Sudeep KarkadaNagesha | f6cec7c | 2013-07-03 16:01:42 +0100 | [diff] [blame] | 51 | int thiscpu, cpu; |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 52 | unsigned long rate; |
Sudeep KarkadaNagesha | f6cec7c | 2013-07-03 16:01:42 +0100 | [diff] [blame] | 53 | struct clk *cpu_clk; |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 54 | |
| 55 | thiscpu = smp_processor_id(); |
Sudeep KarkadaNagesha | f6cec7c | 2013-07-03 16:01:42 +0100 | [diff] [blame] | 56 | cpu_clk = get_cpu_clk(thiscpu); |
| 57 | if (!cpu_clk) |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 58 | return; |
| 59 | clk_prepare_enable(cpu_clk); |
| 60 | rate = clk_get_rate(cpu_clk); |
| 61 | |
| 62 | /* set all the other CPU clk to the same rate than the boot CPU */ |
Sudeep KarkadaNagesha | f6cec7c | 2013-07-03 16:01:42 +0100 | [diff] [blame] | 63 | for_each_possible_cpu(cpu) { |
| 64 | if (cpu == thiscpu) |
| 65 | continue; |
| 66 | cpu_clk = get_cpu_clk(cpu); |
| 67 | if (!cpu_clk) |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 68 | return; |
Sudeep KarkadaNagesha | f6cec7c | 2013-07-03 16:01:42 +0100 | [diff] [blame] | 69 | clk_set_rate(cpu_clk, rate); |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
Paul Gortmaker | 8bd26e3 | 2013-06-17 15:43:14 -0400 | [diff] [blame] | 73 | static int armada_xp_boot_secondary(unsigned int cpu, struct task_struct *idle) |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 74 | { |
Thomas Petazzoni | 05ad690 | 2014-04-14 15:53:58 +0200 | [diff] [blame] | 75 | int ret, hw_cpu; |
| 76 | |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 77 | pr_info("Booting CPU %d\n", cpu); |
| 78 | |
Thomas Petazzoni | 05ad690 | 2014-04-14 15:53:58 +0200 | [diff] [blame] | 79 | hw_cpu = cpu_logical_map(cpu); |
| 80 | mvebu_pmsu_set_cpu_boot_addr(hw_cpu, armada_xp_secondary_startup); |
Thomas Petazzoni | 2633777 | 2014-05-30 22:18:17 +0200 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * This is needed to wake up CPUs in the offline state after |
| 84 | * using CPU hotplug. |
| 85 | */ |
| 86 | arch_send_wakeup_ipi_mask(cpumask_of(cpu)); |
| 87 | |
| 88 | /* |
| 89 | * This is needed to take secondary CPUs out of reset on the |
| 90 | * initial boot. |
| 91 | */ |
Thomas Petazzoni | 05ad690 | 2014-04-14 15:53:58 +0200 | [diff] [blame] | 92 | ret = mvebu_cpu_reset_deassert(hw_cpu); |
| 93 | if (ret) { |
| 94 | pr_warn("unable to boot CPU: %d\n", ret); |
| 95 | return ret; |
| 96 | } |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
Thomas Petazzoni | 2633777 | 2014-05-30 22:18:17 +0200 | [diff] [blame] | 101 | /* |
| 102 | * When a CPU is brought back online, either through CPU hotplug, or |
| 103 | * because of the boot of a kexec'ed kernel, the PMSU configuration |
| 104 | * for this CPU might be in the deep idle state, preventing this CPU |
| 105 | * from receiving interrupts. Here, we therefore take out the current |
| 106 | * CPU from this state, which was entered by armada_xp_cpu_die() |
| 107 | * below. |
| 108 | */ |
| 109 | static void armada_xp_secondary_init(unsigned int cpu) |
| 110 | { |
Gregory CLEMENT | 898ef3e | 2014-07-23 15:00:42 +0200 | [diff] [blame^] | 111 | mvebu_v7_pmsu_idle_exit(); |
Thomas Petazzoni | 2633777 | 2014-05-30 22:18:17 +0200 | [diff] [blame] | 112 | } |
| 113 | |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 114 | static void __init armada_xp_smp_init_cpus(void) |
| 115 | { |
Sudeep KarkadaNagesha | a7160b7 | 2013-07-23 12:32:42 +0100 | [diff] [blame] | 116 | unsigned int ncores = num_possible_cpus(); |
Thomas Petazzoni | b21dcaf | 2013-06-05 09:04:54 +0200 | [diff] [blame] | 117 | |
Thomas Petazzoni | b21dcaf | 2013-06-05 09:04:54 +0200 | [diff] [blame] | 118 | if (ncores == 0 || ncores > ARMADA_XP_MAX_CPUS) |
| 119 | panic("Invalid number of CPUs in DT\n"); |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 120 | } |
| 121 | |
Jisheng Zhang | b12634e | 2013-11-07 17:02:38 +0800 | [diff] [blame] | 122 | static void __init armada_xp_smp_prepare_cpus(unsigned int max_cpus) |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 123 | { |
Ezequiel Garcia | 994c8c9 | 2013-07-26 10:17:54 -0300 | [diff] [blame] | 124 | struct device_node *node; |
| 125 | struct resource res; |
| 126 | int err; |
| 127 | |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 128 | set_secondary_cpus_clock(); |
| 129 | flush_cache_all(); |
Gregory CLEMENT | 952f4ca | 2014-04-14 17:10:07 +0200 | [diff] [blame] | 130 | set_cpu_coherent(); |
Ezequiel Garcia | 994c8c9 | 2013-07-26 10:17:54 -0300 | [diff] [blame] | 131 | |
| 132 | /* |
| 133 | * In order to boot the secondary CPUs we need to ensure |
| 134 | * the bootROM is mapped at the correct address. |
| 135 | */ |
| 136 | node = of_find_compatible_node(NULL, NULL, "marvell,bootrom"); |
| 137 | if (!node) |
| 138 | panic("Cannot find 'marvell,bootrom' compatible node"); |
| 139 | |
| 140 | err = of_address_to_resource(node, 0, &res); |
| 141 | if (err < 0) |
| 142 | panic("Cannot get 'bootrom' node address"); |
| 143 | |
| 144 | if (res.start != AXP_BOOTROM_BASE || |
| 145 | resource_size(&res) != AXP_BOOTROM_SIZE) |
| 146 | panic("The address for the BootROM is incorrect"); |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Thomas Petazzoni | 2633777 | 2014-05-30 22:18:17 +0200 | [diff] [blame] | 149 | #ifdef CONFIG_HOTPLUG_CPU |
| 150 | static void armada_xp_cpu_die(unsigned int cpu) |
| 151 | { |
| 152 | /* |
| 153 | * CPU hotplug is implemented by putting offline CPUs into the |
| 154 | * deep idle sleep state. |
| 155 | */ |
| 156 | armada_370_xp_pmsu_idle_enter(true); |
| 157 | } |
| 158 | |
| 159 | /* |
| 160 | * We need a dummy function, so that platform_can_cpu_hotplug() knows |
| 161 | * we support CPU hotplug. However, the function does not need to do |
| 162 | * anything, because CPUs going offline can enter the deep idle state |
| 163 | * by themselves, without any help from a still alive CPU. |
| 164 | */ |
| 165 | static int armada_xp_cpu_kill(unsigned int cpu) |
| 166 | { |
| 167 | return 1; |
| 168 | } |
| 169 | #endif |
| 170 | |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 171 | struct smp_operations armada_xp_smp_ops __initdata = { |
| 172 | .smp_init_cpus = armada_xp_smp_init_cpus, |
| 173 | .smp_prepare_cpus = armada_xp_smp_prepare_cpus, |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 174 | .smp_boot_secondary = armada_xp_boot_secondary, |
Thomas Petazzoni | 2633777 | 2014-05-30 22:18:17 +0200 | [diff] [blame] | 175 | .smp_secondary_init = armada_xp_secondary_init, |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 176 | #ifdef CONFIG_HOTPLUG_CPU |
| 177 | .cpu_die = armada_xp_cpu_die, |
Thomas Petazzoni | 2633777 | 2014-05-30 22:18:17 +0200 | [diff] [blame] | 178 | .cpu_kill = armada_xp_cpu_kill, |
Gregory CLEMENT | 45f5984 | 2012-11-14 22:51:08 +0100 | [diff] [blame] | 179 | #endif |
| 180 | }; |
Thomas Petazzoni | 2c9b224 | 2014-04-14 15:53:59 +0200 | [diff] [blame] | 181 | |
| 182 | CPU_METHOD_OF_DECLARE(armada_xp_smp, "marvell,armada-xp-smp", |
| 183 | &armada_xp_smp_ops); |