blob: 4f93c67e63de34293dadc0baeb23fe944b27888c [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>
Marc Zyngierd329de32013-01-02 15:24:22 +000024
25#include <asm/cacheflush.h>
Mark Rutlandcd1aebf2013-10-24 20:30:15 +010026#include <asm/cpu_ops.h>
Mark Rutland652af892013-10-24 20:30:16 +010027#include <asm/cputype.h>
28#include <asm/smp_plat.h>
29
30extern void secondary_holding_pen(void);
31volatile unsigned long secondary_holding_pen_release = INVALID_HWID;
Marc Zyngierd329de32013-01-02 15:24:22 +000032
33static phys_addr_t cpu_release_addr[NR_CPUS];
Mark Rutland652af892013-10-24 20:30:16 +010034
35/*
36 * Write secondary_holding_pen_release in a way that is guaranteed to be
37 * visible to all observers, irrespective of whether they're taking part
38 * in coherency or not. This is necessary for the hotplug code to work
39 * reliably.
40 */
41static void write_pen_release(u64 val)
42{
43 void *start = (void *)&secondary_holding_pen_release;
44 unsigned long size = sizeof(secondary_holding_pen_release);
45
46 secondary_holding_pen_release = val;
47 __flush_dcache_area(start, size);
48}
49
Marc Zyngierd329de32013-01-02 15:24:22 +000050
Mark Rutlandcd1aebf2013-10-24 20:30:15 +010051static int smp_spin_table_cpu_init(struct device_node *dn, unsigned int cpu)
Marc Zyngierd329de32013-01-02 15:24:22 +000052{
53 /*
54 * Determine the address from which the CPU is polling.
55 */
56 if (of_property_read_u64(dn, "cpu-release-addr",
57 &cpu_release_addr[cpu])) {
58 pr_err("CPU %d: missing or invalid cpu-release-addr property\n",
59 cpu);
60
61 return -1;
62 }
63
64 return 0;
65}
66
Mark Rutlandcd1aebf2013-10-24 20:30:15 +010067static int smp_spin_table_cpu_prepare(unsigned int cpu)
Marc Zyngierd329de32013-01-02 15:24:22 +000068{
Mark Rutland113954c2014-07-30 11:59:02 +010069 __le64 __iomem *release_addr;
Marc Zyngierd329de32013-01-02 15:24:22 +000070
71 if (!cpu_release_addr[cpu])
72 return -ENODEV;
73
Mark Rutland113954c2014-07-30 11:59:02 +010074 /*
75 * The cpu-release-addr may or may not be inside the linear mapping.
76 * As ioremap_cache will either give us a new mapping or reuse the
77 * existing linear mapping, we can use it to cover both cases. In
78 * either case the memory will be MT_NORMAL.
79 */
80 release_addr = ioremap_cache(cpu_release_addr[cpu],
81 sizeof(*release_addr));
82 if (!release_addr)
83 return -ENOMEM;
Matthew Leach710be9a2013-10-11 14:52:18 +010084
85 /*
86 * We write the release address as LE regardless of the native
87 * endianess of the kernel. Therefore, any boot-loaders that
88 * read this address need to convert this address to the
89 * boot-loader's endianess before jumping. This is mandated by
90 * the boot protocol.
91 */
Mark Rutland113954c2014-07-30 11:59:02 +010092 writeq_relaxed(__pa(secondary_holding_pen), release_addr);
93 __flush_dcache_area((__force void *)release_addr,
94 sizeof(*release_addr));
Marc Zyngierd329de32013-01-02 15:24:22 +000095
96 /*
97 * Send an event to wake up the secondary CPU.
98 */
99 sev();
100
Mark Rutland113954c2014-07-30 11:59:02 +0100101 iounmap(release_addr);
102
Marc Zyngierd329de32013-01-02 15:24:22 +0000103 return 0;
104}
105
Mark Rutland652af892013-10-24 20:30:16 +0100106static int smp_spin_table_cpu_boot(unsigned int cpu)
107{
Mark Rutland652af892013-10-24 20:30:16 +0100108 /*
109 * Update the pen release flag.
110 */
111 write_pen_release(cpu_logical_map(cpu));
112
113 /*
114 * Send an event, causing the secondaries to read pen_release.
115 */
116 sev();
117
Catalin Marinas64001112014-04-04 11:49:05 +0100118 return 0;
Mark Rutland652af892013-10-24 20:30:16 +0100119}
120
Mark Rutlandcd1aebf2013-10-24 20:30:15 +0100121const struct cpu_operations smp_spin_table_ops = {
Marc Zyngierd329de32013-01-02 15:24:22 +0000122 .name = "spin-table",
Mark Rutlandcd1aebf2013-10-24 20:30:15 +0100123 .cpu_init = smp_spin_table_cpu_init,
124 .cpu_prepare = smp_spin_table_cpu_prepare,
Mark Rutland652af892013-10-24 20:30:16 +0100125 .cpu_boot = smp_spin_table_cpu_boot,
Marc Zyngierd329de32013-01-02 15:24:22 +0000126};