blob: f9597b701028a107d6acc11ce481fcaddc5e0411 [file] [log] [blame]
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +01001/*
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 Garcia994c8c92013-07-26 10:17:54 -030024#include <linux/of_address.h>
Thomas Petazzoni87e1bed2013-03-21 17:59:15 +010025#include <linux/mbus.h>
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +010026#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
Gregory CLEMENT316fbbc2014-10-30 12:39:41 +010033#define ARMADA_XP_MAX_CPUS 4
34
Ezequiel Garcia994c8c92013-07-26 10:17:54 -030035#define AXP_BOOTROM_BASE 0xfff00000
36#define AXP_BOOTROM_SIZE 0x100000
37
Thomas Petazzonib9b1de02014-11-21 17:00:10 +010038static struct clk *get_cpu_clk(int cpu)
Sudeep KarkadaNageshaf6cec7c2013-07-03 16:01:42 +010039{
40 struct clk *cpu_clk;
41 struct device_node *np = of_get_cpu_node(cpu, NULL);
42
43 if (WARN(!np, "missing cpu node\n"))
44 return NULL;
45 cpu_clk = of_clk_get(np, 0);
46 if (WARN_ON(IS_ERR(cpu_clk)))
47 return NULL;
48 return cpu_clk;
49}
50
Thomas Petazzonib9b1de02014-11-21 17:00:10 +010051static void set_secondary_cpu_clock(unsigned int cpu)
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +010052{
Thomas Petazzonib9b1de02014-11-21 17:00:10 +010053 int thiscpu;
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +010054 unsigned long rate;
Sudeep KarkadaNageshaf6cec7c2013-07-03 16:01:42 +010055 struct clk *cpu_clk;
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +010056
Thomas Petazzonib9b1de02014-11-21 17:00:10 +010057 thiscpu = get_cpu();
58
Sudeep KarkadaNageshaf6cec7c2013-07-03 16:01:42 +010059 cpu_clk = get_cpu_clk(thiscpu);
60 if (!cpu_clk)
Thomas Petazzonib9b1de02014-11-21 17:00:10 +010061 goto out;
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +010062 clk_prepare_enable(cpu_clk);
63 rate = clk_get_rate(cpu_clk);
64
Thomas Petazzonib9b1de02014-11-21 17:00:10 +010065 cpu_clk = get_cpu_clk(cpu);
66 if (!cpu_clk)
67 goto out;
68 clk_set_rate(cpu_clk, rate);
69 clk_prepare_enable(cpu_clk);
70
71out:
72 put_cpu();
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +010073}
74
Paul Gortmaker8bd26e32013-06-17 15:43:14 -040075static int armada_xp_boot_secondary(unsigned int cpu, struct task_struct *idle)
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +010076{
Thomas Petazzoni05ad6902014-04-14 15:53:58 +020077 int ret, hw_cpu;
78
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +010079 pr_info("Booting CPU %d\n", cpu);
80
Thomas Petazzoni05ad6902014-04-14 15:53:58 +020081 hw_cpu = cpu_logical_map(cpu);
Thomas Petazzonib9b1de02014-11-21 17:00:10 +010082 set_secondary_cpu_clock(hw_cpu);
Thomas Petazzoni05ad6902014-04-14 15:53:58 +020083 mvebu_pmsu_set_cpu_boot_addr(hw_cpu, armada_xp_secondary_startup);
Thomas Petazzoni26337772014-05-30 22:18:17 +020084
85 /*
86 * This is needed to wake up CPUs in the offline state after
87 * using CPU hotplug.
88 */
89 arch_send_wakeup_ipi_mask(cpumask_of(cpu));
90
91 /*
92 * This is needed to take secondary CPUs out of reset on the
93 * initial boot.
94 */
Thomas Petazzoni05ad6902014-04-14 15:53:58 +020095 ret = mvebu_cpu_reset_deassert(hw_cpu);
96 if (ret) {
97 pr_warn("unable to boot CPU: %d\n", ret);
98 return ret;
99 }
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +0100100
101 return 0;
102}
103
Thomas Petazzoni26337772014-05-30 22:18:17 +0200104/*
105 * When a CPU is brought back online, either through CPU hotplug, or
106 * because of the boot of a kexec'ed kernel, the PMSU configuration
107 * for this CPU might be in the deep idle state, preventing this CPU
108 * from receiving interrupts. Here, we therefore take out the current
109 * CPU from this state, which was entered by armada_xp_cpu_die()
110 * below.
111 */
112static void armada_xp_secondary_init(unsigned int cpu)
113{
Gregory CLEMENT898ef3e2014-07-23 15:00:42 +0200114 mvebu_v7_pmsu_idle_exit();
Thomas Petazzoni26337772014-05-30 22:18:17 +0200115}
116
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +0100117static void __init armada_xp_smp_init_cpus(void)
118{
Sudeep KarkadaNageshaa7160b72013-07-23 12:32:42 +0100119 unsigned int ncores = num_possible_cpus();
Thomas Petazzonib21dcaf2013-06-05 09:04:54 +0200120
Thomas Petazzonib21dcaf2013-06-05 09:04:54 +0200121 if (ncores == 0 || ncores > ARMADA_XP_MAX_CPUS)
122 panic("Invalid number of CPUs in DT\n");
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +0100123}
124
Jisheng Zhangb12634e2013-11-07 17:02:38 +0800125static void __init armada_xp_smp_prepare_cpus(unsigned int max_cpus)
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +0100126{
Ezequiel Garcia994c8c92013-07-26 10:17:54 -0300127 struct device_node *node;
128 struct resource res;
129 int err;
130
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +0100131 flush_cache_all();
Gregory CLEMENT952f4ca2014-04-14 17:10:07 +0200132 set_cpu_coherent();
Ezequiel Garcia994c8c92013-07-26 10:17:54 -0300133
134 /*
135 * In order to boot the secondary CPUs we need to ensure
136 * the bootROM is mapped at the correct address.
137 */
138 node = of_find_compatible_node(NULL, NULL, "marvell,bootrom");
139 if (!node)
140 panic("Cannot find 'marvell,bootrom' compatible node");
141
142 err = of_address_to_resource(node, 0, &res);
143 if (err < 0)
144 panic("Cannot get 'bootrom' node address");
145
146 if (res.start != AXP_BOOTROM_BASE ||
147 resource_size(&res) != AXP_BOOTROM_SIZE)
148 panic("The address for the BootROM is incorrect");
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +0100149}
150
Thomas Petazzoni26337772014-05-30 22:18:17 +0200151#ifdef CONFIG_HOTPLUG_CPU
152static void armada_xp_cpu_die(unsigned int cpu)
153{
154 /*
155 * CPU hotplug is implemented by putting offline CPUs into the
156 * deep idle sleep state.
157 */
158 armada_370_xp_pmsu_idle_enter(true);
159}
160
161/*
162 * We need a dummy function, so that platform_can_cpu_hotplug() knows
163 * we support CPU hotplug. However, the function does not need to do
164 * anything, because CPUs going offline can enter the deep idle state
165 * by themselves, without any help from a still alive CPU.
166 */
167static int armada_xp_cpu_kill(unsigned int cpu)
168{
169 return 1;
170}
171#endif
172
Masahiro Yamada75305272015-11-15 10:39:53 +0900173const struct smp_operations armada_xp_smp_ops __initconst = {
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +0100174 .smp_init_cpus = armada_xp_smp_init_cpus,
175 .smp_prepare_cpus = armada_xp_smp_prepare_cpus,
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +0100176 .smp_boot_secondary = armada_xp_boot_secondary,
Thomas Petazzoni26337772014-05-30 22:18:17 +0200177 .smp_secondary_init = armada_xp_secondary_init,
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +0100178#ifdef CONFIG_HOTPLUG_CPU
179 .cpu_die = armada_xp_cpu_die,
Thomas Petazzoni26337772014-05-30 22:18:17 +0200180 .cpu_kill = armada_xp_cpu_kill,
Gregory CLEMENT45f5984a2012-11-14 22:51:08 +0100181#endif
182};
Thomas Petazzoni2c9b2242014-04-14 15:53:59 +0200183
184CPU_METHOD_OF_DECLARE(armada_xp_smp, "marvell,armada-xp-smp",
185 &armada_xp_smp_ops);