blob: c8a3fee00c11329910ae63f6fe3ac98e0fd60fdb [file] [log] [blame]
Thomas Gleixnercaab2772019-06-03 07:44:50 +02001// SPDX-License-Identifier: GPL-2.0-only
Marc Zyngierd329de32013-01-02 15:24:22 +00002/*
3 * Spin Table SMP initialisation
4 *
5 * Copyright (C) 2013 ARM Ltd.
Marc Zyngierd329de32013-01-02 15:24:22 +00006 */
7
Mark Rutland652af892013-10-24 20:30:16 +01008#include <linux/delay.h>
Marc Zyngierd329de32013-01-02 15:24:22 +00009#include <linux/init.h>
10#include <linux/of.h>
11#include <linux/smp.h>
Mark Rutland113954c2014-07-30 11:59:02 +010012#include <linux/types.h>
Laura Abbott2077be62017-01-10 13:35:49 -080013#include <linux/mm.h>
Marc Zyngierd329de32013-01-02 15:24:22 +000014
15#include <asm/cacheflush.h>
Mark Rutlandcd1aebf2013-10-24 20:30:15 +010016#include <asm/cpu_ops.h>
Mark Rutland652af892013-10-24 20:30:16 +010017#include <asm/cputype.h>
Paul Walmsley59c68322015-01-05 17:38:42 -070018#include <asm/io.h>
Mark Rutland652af892013-10-24 20:30:16 +010019#include <asm/smp_plat.h>
20
21extern void secondary_holding_pen(void);
Nick Desaulniers80d83812019-08-12 14:50:45 -070022volatile unsigned long __section(.mmuoff.data.read)
James Morseb6113032016-08-24 18:27:29 +010023secondary_holding_pen_release = INVALID_HWID;
Marc Zyngierd329de32013-01-02 15:24:22 +000024
25static phys_addr_t cpu_release_addr[NR_CPUS];
Mark Rutland652af892013-10-24 20:30:16 +010026
27/*
28 * Write secondary_holding_pen_release in a way that is guaranteed to be
29 * visible to all observers, irrespective of whether they're taking part
30 * in coherency or not. This is necessary for the hotplug code to work
31 * reliably.
32 */
33static void write_pen_release(u64 val)
34{
35 void *start = (void *)&secondary_holding_pen_release;
36 unsigned long size = sizeof(secondary_holding_pen_release);
37
38 secondary_holding_pen_release = val;
39 __flush_dcache_area(start, size);
40}
41
Marc Zyngierd329de32013-01-02 15:24:22 +000042
Lorenzo Pieralisi819a8822015-05-13 14:12:46 +010043static int smp_spin_table_cpu_init(unsigned int cpu)
Marc Zyngierd329de32013-01-02 15:24:22 +000044{
Lorenzo Pieralisi819a8822015-05-13 14:12:46 +010045 struct device_node *dn;
Masahiro Yamada2fee7d52016-04-20 10:23:31 +090046 int ret;
Lorenzo Pieralisi819a8822015-05-13 14:12:46 +010047
48 dn = of_get_cpu_node(cpu, NULL);
49 if (!dn)
50 return -ENODEV;
51
Marc Zyngierd329de32013-01-02 15:24:22 +000052 /*
53 * Determine the address from which the CPU is polling.
54 */
Masahiro Yamada2fee7d52016-04-20 10:23:31 +090055 ret = of_property_read_u64(dn, "cpu-release-addr",
56 &cpu_release_addr[cpu]);
57 if (ret)
Marc Zyngierd329de32013-01-02 15:24:22 +000058 pr_err("CPU %d: missing or invalid cpu-release-addr property\n",
59 cpu);
60
Masahiro Yamada2fee7d52016-04-20 10:23:31 +090061 of_node_put(dn);
Marc Zyngierd329de32013-01-02 15:24:22 +000062
Masahiro Yamada2fee7d52016-04-20 10:23:31 +090063 return ret;
Marc Zyngierd329de32013-01-02 15:24:22 +000064}
65
Mark Rutlandcd1aebf2013-10-24 20:30:15 +010066static int smp_spin_table_cpu_prepare(unsigned int cpu)
Marc Zyngierd329de32013-01-02 15:24:22 +000067{
Mark Rutland113954c2014-07-30 11:59:02 +010068 __le64 __iomem *release_addr;
Marc Zyngierd329de32013-01-02 15:24:22 +000069
70 if (!cpu_release_addr[cpu])
71 return -ENODEV;
72
Mark Rutland113954c2014-07-30 11:59:02 +010073 /*
74 * The cpu-release-addr may or may not be inside the linear mapping.
75 * As ioremap_cache will either give us a new mapping or reuse the
76 * existing linear mapping, we can use it to cover both cases. In
77 * either case the memory will be MT_NORMAL.
78 */
79 release_addr = ioremap_cache(cpu_release_addr[cpu],
80 sizeof(*release_addr));
81 if (!release_addr)
82 return -ENOMEM;
Matthew Leach710be9a2013-10-11 14:52:18 +010083
84 /*
85 * We write the release address as LE regardless of the native
86 * endianess of the kernel. Therefore, any boot-loaders that
87 * read this address need to convert this address to the
88 * boot-loader's endianess before jumping. This is mandated by
89 * the boot protocol.
90 */
Laura Abbott2077be62017-01-10 13:35:49 -080091 writeq_relaxed(__pa_symbol(secondary_holding_pen), release_addr);
Mark Rutland113954c2014-07-30 11:59:02 +010092 __flush_dcache_area((__force void *)release_addr,
93 sizeof(*release_addr));
Marc Zyngierd329de32013-01-02 15:24:22 +000094
95 /*
96 * Send an event to wake up the secondary CPU.
97 */
98 sev();
99
Mark Rutland113954c2014-07-30 11:59:02 +0100100 iounmap(release_addr);
101
Marc Zyngierd329de32013-01-02 15:24:22 +0000102 return 0;
103}
104
Mark Rutland652af892013-10-24 20:30:16 +0100105static int smp_spin_table_cpu_boot(unsigned int cpu)
106{
Mark Rutland652af892013-10-24 20:30:16 +0100107 /*
108 * Update the pen release flag.
109 */
110 write_pen_release(cpu_logical_map(cpu));
111
112 /*
113 * Send an event, causing the secondaries to read pen_release.
114 */
115 sev();
116
Catalin Marinas64001112014-04-04 11:49:05 +0100117 return 0;
Mark Rutland652af892013-10-24 20:30:16 +0100118}
119
Mark Rutlandcd1aebf2013-10-24 20:30:15 +0100120const struct cpu_operations smp_spin_table_ops = {
Marc Zyngierd329de32013-01-02 15:24:22 +0000121 .name = "spin-table",
Mark Rutlandcd1aebf2013-10-24 20:30:15 +0100122 .cpu_init = smp_spin_table_cpu_init,
123 .cpu_prepare = smp_spin_table_cpu_prepare,
Mark Rutland652af892013-10-24 20:30:16 +0100124 .cpu_boot = smp_spin_table_cpu_boot,
Marc Zyngierd329de32013-01-02 15:24:22 +0000125};