blob: ff69c2df298b6b2ce69f742c7f5b6dbcf179f821 [file] [log] [blame]
Gregory CLEMENT45f59842012-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 CLEMENT45f59842012-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
Ezequiel Garcia994c8c92013-07-26 10:17:54 -030033#define AXP_BOOTROM_BASE 0xfff00000
34#define AXP_BOOTROM_SIZE 0x100000
35
Sudeep KarkadaNageshaf6cec7c2013-07-03 16:01:42 +010036static 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
Gregory CLEMENT45f59842012-11-14 22:51:08 +010049void __init set_secondary_cpus_clock(void)
50{
Sudeep KarkadaNageshaf6cec7c2013-07-03 16:01:42 +010051 int thiscpu, cpu;
Gregory CLEMENT45f59842012-11-14 22:51:08 +010052 unsigned long rate;
Sudeep KarkadaNageshaf6cec7c2013-07-03 16:01:42 +010053 struct clk *cpu_clk;
Gregory CLEMENT45f59842012-11-14 22:51:08 +010054
55 thiscpu = smp_processor_id();
Sudeep KarkadaNageshaf6cec7c2013-07-03 16:01:42 +010056 cpu_clk = get_cpu_clk(thiscpu);
57 if (!cpu_clk)
Gregory CLEMENT45f59842012-11-14 22:51:08 +010058 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 KarkadaNageshaf6cec7c2013-07-03 16:01:42 +010063 for_each_possible_cpu(cpu) {
64 if (cpu == thiscpu)
65 continue;
66 cpu_clk = get_cpu_clk(cpu);
67 if (!cpu_clk)
Gregory CLEMENT45f59842012-11-14 22:51:08 +010068 return;
Sudeep KarkadaNageshaf6cec7c2013-07-03 16:01:42 +010069 clk_set_rate(cpu_clk, rate);
Gregory CLEMENT45f59842012-11-14 22:51:08 +010070 }
71}
72
Paul Gortmaker8bd26e32013-06-17 15:43:14 -040073static void armada_xp_secondary_init(unsigned int cpu)
Gregory CLEMENT45f59842012-11-14 22:51:08 +010074{
75 armada_xp_mpic_smp_cpu_init();
76}
77
Paul Gortmaker8bd26e32013-06-17 15:43:14 -040078static int armada_xp_boot_secondary(unsigned int cpu, struct task_struct *idle)
Gregory CLEMENT45f59842012-11-14 22:51:08 +010079{
80 pr_info("Booting CPU %d\n", cpu);
81
82 armada_xp_boot_cpu(cpu, armada_xp_secondary_startup);
83
84 return 0;
85}
86
87static void __init armada_xp_smp_init_cpus(void)
88{
Sudeep KarkadaNageshaa7160b72013-07-23 12:32:42 +010089 unsigned int ncores = num_possible_cpus();
Thomas Petazzonib21dcaf2013-06-05 09:04:54 +020090
Thomas Petazzonib21dcaf2013-06-05 09:04:54 +020091 if (ncores == 0 || ncores > ARMADA_XP_MAX_CPUS)
92 panic("Invalid number of CPUs in DT\n");
Gregory CLEMENT45f59842012-11-14 22:51:08 +010093
Gregory CLEMENT45f59842012-11-14 22:51:08 +010094 set_smp_cross_call(armada_mpic_send_doorbell);
95}
96
97void __init armada_xp_smp_prepare_cpus(unsigned int max_cpus)
98{
Ezequiel Garcia994c8c92013-07-26 10:17:54 -030099 struct device_node *node;
100 struct resource res;
101 int err;
102
Gregory CLEMENT45f59842012-11-14 22:51:08 +0100103 set_secondary_cpus_clock();
104 flush_cache_all();
105 set_cpu_coherent(cpu_logical_map(smp_processor_id()), 0);
Ezequiel Garcia994c8c92013-07-26 10:17:54 -0300106
107 /*
108 * In order to boot the secondary CPUs we need to ensure
109 * the bootROM is mapped at the correct address.
110 */
111 node = of_find_compatible_node(NULL, NULL, "marvell,bootrom");
112 if (!node)
113 panic("Cannot find 'marvell,bootrom' compatible node");
114
115 err = of_address_to_resource(node, 0, &res);
116 if (err < 0)
117 panic("Cannot get 'bootrom' node address");
118
119 if (res.start != AXP_BOOTROM_BASE ||
120 resource_size(&res) != AXP_BOOTROM_SIZE)
121 panic("The address for the BootROM is incorrect");
Gregory CLEMENT45f59842012-11-14 22:51:08 +0100122}
123
124struct smp_operations armada_xp_smp_ops __initdata = {
125 .smp_init_cpus = armada_xp_smp_init_cpus,
126 .smp_prepare_cpus = armada_xp_smp_prepare_cpus,
127 .smp_secondary_init = armada_xp_secondary_init,
128 .smp_boot_secondary = armada_xp_boot_secondary,
129#ifdef CONFIG_HOTPLUG_CPU
130 .cpu_die = armada_xp_cpu_die,
131#endif
132};