blob: 93034651c87ea37517cc1db519ab4e097eee45d8 [file] [log] [blame]
Marc Zyngierd329de32013-01-02 15:24:22 +00001/*
2 * Spin Table SMP initialisation
3 *
4 * Copyright (C) 2013 ARM Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
Mark Rutland652af892013-10-24 20:30:16 +010019#include <linux/delay.h>
Marc Zyngierd329de32013-01-02 15:24:22 +000020#include <linux/init.h>
21#include <linux/of.h>
22#include <linux/smp.h>
Mark Rutland113954c2014-07-30 11:59:02 +010023#include <linux/types.h>
Laura Abbottf8fee94e2017-01-10 13:35:49 -080024#include <linux/mm.h>
Marc Zyngierd329de32013-01-02 15:24:22 +000025
26#include <asm/cacheflush.h>
Mark Rutlandcd1aebf2013-10-24 20:30:15 +010027#include <asm/cpu_ops.h>
Mark Rutland652af892013-10-24 20:30:16 +010028#include <asm/cputype.h>
Paul Walmsley59c68322015-01-05 17:38:42 -070029#include <asm/io.h>
Mark Rutland652af892013-10-24 20:30:16 +010030#include <asm/smp_plat.h>
31
32extern void secondary_holding_pen(void);
James Morseb6113032016-08-24 18:27:29 +010033volatile unsigned long __section(".mmuoff.data.read")
34secondary_holding_pen_release = INVALID_HWID;
Marc Zyngierd329de32013-01-02 15:24:22 +000035
36static phys_addr_t cpu_release_addr[NR_CPUS];
Mark Rutland652af892013-10-24 20:30:16 +010037
38/*
39 * Write secondary_holding_pen_release in a way that is guaranteed to be
40 * visible to all observers, irrespective of whether they're taking part
41 * in coherency or not. This is necessary for the hotplug code to work
42 * reliably.
43 */
44static void write_pen_release(u64 val)
45{
46 void *start = (void *)&secondary_holding_pen_release;
47 unsigned long size = sizeof(secondary_holding_pen_release);
48
49 secondary_holding_pen_release = val;
50 __flush_dcache_area(start, size);
51}
52
Marc Zyngierd329de32013-01-02 15:24:22 +000053
Lorenzo Pieralisi819a8822015-05-13 14:12:46 +010054static int smp_spin_table_cpu_init(unsigned int cpu)
Marc Zyngierd329de32013-01-02 15:24:22 +000055{
Lorenzo Pieralisi819a8822015-05-13 14:12:46 +010056 struct device_node *dn;
Masahiro Yamada2fee7d52016-04-20 10:23:31 +090057 int ret;
Lorenzo Pieralisi819a8822015-05-13 14:12:46 +010058
59 dn = of_get_cpu_node(cpu, NULL);
60 if (!dn)
61 return -ENODEV;
62
Marc Zyngierd329de32013-01-02 15:24:22 +000063 /*
64 * Determine the address from which the CPU is polling.
65 */
Masahiro Yamada2fee7d52016-04-20 10:23:31 +090066 ret = of_property_read_u64(dn, "cpu-release-addr",
67 &cpu_release_addr[cpu]);
68 if (ret)
Marc Zyngierd329de32013-01-02 15:24:22 +000069 pr_err("CPU %d: missing or invalid cpu-release-addr property\n",
70 cpu);
71
Masahiro Yamada2fee7d52016-04-20 10:23:31 +090072 of_node_put(dn);
Marc Zyngierd329de32013-01-02 15:24:22 +000073
Masahiro Yamada2fee7d52016-04-20 10:23:31 +090074 return ret;
Marc Zyngierd329de32013-01-02 15:24:22 +000075}
76
Mark Rutlandcd1aebf2013-10-24 20:30:15 +010077static int smp_spin_table_cpu_prepare(unsigned int cpu)
Marc Zyngierd329de32013-01-02 15:24:22 +000078{
Mark Rutland113954c2014-07-30 11:59:02 +010079 __le64 __iomem *release_addr;
Marc Zyngierd329de32013-01-02 15:24:22 +000080
81 if (!cpu_release_addr[cpu])
82 return -ENODEV;
83
Mark Rutland113954c2014-07-30 11:59:02 +010084 /*
85 * The cpu-release-addr may or may not be inside the linear mapping.
86 * As ioremap_cache will either give us a new mapping or reuse the
87 * existing linear mapping, we can use it to cover both cases. In
88 * either case the memory will be MT_NORMAL.
89 */
90 release_addr = ioremap_cache(cpu_release_addr[cpu],
91 sizeof(*release_addr));
92 if (!release_addr)
93 return -ENOMEM;
Matthew Leach710be9a2013-10-11 14:52:18 +010094
95 /*
96 * We write the release address as LE regardless of the native
97 * endianess of the kernel. Therefore, any boot-loaders that
98 * read this address need to convert this address to the
99 * boot-loader's endianess before jumping. This is mandated by
100 * the boot protocol.
101 */
Laura Abbottf8fee94e2017-01-10 13:35:49 -0800102 writeq_relaxed(__pa_symbol(secondary_holding_pen), release_addr);
Mark Rutland113954c2014-07-30 11:59:02 +0100103 __flush_dcache_area((__force void *)release_addr,
104 sizeof(*release_addr));
Marc Zyngierd329de32013-01-02 15:24:22 +0000105
106 /*
107 * Send an event to wake up the secondary CPU.
108 */
109 sev();
110
Mark Rutland113954c2014-07-30 11:59:02 +0100111 iounmap(release_addr);
112
Marc Zyngierd329de32013-01-02 15:24:22 +0000113 return 0;
114}
115
Mark Rutland652af892013-10-24 20:30:16 +0100116static int smp_spin_table_cpu_boot(unsigned int cpu)
117{
Mark Rutland652af892013-10-24 20:30:16 +0100118 /*
119 * Update the pen release flag.
120 */
121 write_pen_release(cpu_logical_map(cpu));
122
123 /*
124 * Send an event, causing the secondaries to read pen_release.
125 */
126 sev();
127
Catalin Marinas64001112014-04-04 11:49:05 +0100128 return 0;
Mark Rutland652af892013-10-24 20:30:16 +0100129}
130
Mark Rutlandcd1aebf2013-10-24 20:30:15 +0100131const struct cpu_operations smp_spin_table_ops = {
Marc Zyngierd329de32013-01-02 15:24:22 +0000132 .name = "spin-table",
Mark Rutlandcd1aebf2013-10-24 20:30:15 +0100133 .cpu_init = smp_spin_table_cpu_init,
134 .cpu_prepare = smp_spin_table_cpu_prepare,
Mark Rutland652af892013-10-24 20:30:16 +0100135 .cpu_boot = smp_spin_table_cpu_boot,
Marc Zyngierd329de32013-01-02 15:24:22 +0000136};