Thomas Gleixner | caab277 | 2019-06-03 07:44:50 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Spin Table SMP initialisation |
| 4 | * |
| 5 | * Copyright (C) 2013 ARM Ltd. |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Mark Rutland | 652af89 | 2013-10-24 20:30:16 +0100 | [diff] [blame] | 8 | #include <linux/delay.h> |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 9 | #include <linux/init.h> |
| 10 | #include <linux/of.h> |
| 11 | #include <linux/smp.h> |
Mark Rutland | 113954c | 2014-07-30 11:59:02 +0100 | [diff] [blame] | 12 | #include <linux/types.h> |
Laura Abbott | 2077be6 | 2017-01-10 13:35:49 -0800 | [diff] [blame] | 13 | #include <linux/mm.h> |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 14 | |
| 15 | #include <asm/cacheflush.h> |
Mark Rutland | cd1aebf | 2013-10-24 20:30:15 +0100 | [diff] [blame] | 16 | #include <asm/cpu_ops.h> |
Mark Rutland | 652af89 | 2013-10-24 20:30:16 +0100 | [diff] [blame] | 17 | #include <asm/cputype.h> |
Paul Walmsley | 59c6832 | 2015-01-05 17:38:42 -0700 | [diff] [blame] | 18 | #include <asm/io.h> |
Mark Rutland | 652af89 | 2013-10-24 20:30:16 +0100 | [diff] [blame] | 19 | #include <asm/smp_plat.h> |
| 20 | |
| 21 | extern void secondary_holding_pen(void); |
Nick Desaulniers | 80d8381 | 2019-08-12 14:50:45 -0700 | [diff] [blame] | 22 | volatile unsigned long __section(.mmuoff.data.read) |
James Morse | b611303 | 2016-08-24 18:27:29 +0100 | [diff] [blame] | 23 | secondary_holding_pen_release = INVALID_HWID; |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 24 | |
| 25 | static phys_addr_t cpu_release_addr[NR_CPUS]; |
Mark Rutland | 652af89 | 2013-10-24 20:30:16 +0100 | [diff] [blame] | 26 | |
| 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 | */ |
| 33 | static 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 Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 42 | |
Lorenzo Pieralisi | 819a882 | 2015-05-13 14:12:46 +0100 | [diff] [blame] | 43 | static int smp_spin_table_cpu_init(unsigned int cpu) |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 44 | { |
Lorenzo Pieralisi | 819a882 | 2015-05-13 14:12:46 +0100 | [diff] [blame] | 45 | struct device_node *dn; |
Masahiro Yamada | 2fee7d5 | 2016-04-20 10:23:31 +0900 | [diff] [blame] | 46 | int ret; |
Lorenzo Pieralisi | 819a882 | 2015-05-13 14:12:46 +0100 | [diff] [blame] | 47 | |
| 48 | dn = of_get_cpu_node(cpu, NULL); |
| 49 | if (!dn) |
| 50 | return -ENODEV; |
| 51 | |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 52 | /* |
| 53 | * Determine the address from which the CPU is polling. |
| 54 | */ |
Masahiro Yamada | 2fee7d5 | 2016-04-20 10:23:31 +0900 | [diff] [blame] | 55 | ret = of_property_read_u64(dn, "cpu-release-addr", |
| 56 | &cpu_release_addr[cpu]); |
| 57 | if (ret) |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 58 | pr_err("CPU %d: missing or invalid cpu-release-addr property\n", |
| 59 | cpu); |
| 60 | |
Masahiro Yamada | 2fee7d5 | 2016-04-20 10:23:31 +0900 | [diff] [blame] | 61 | of_node_put(dn); |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 62 | |
Masahiro Yamada | 2fee7d5 | 2016-04-20 10:23:31 +0900 | [diff] [blame] | 63 | return ret; |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Mark Rutland | cd1aebf | 2013-10-24 20:30:15 +0100 | [diff] [blame] | 66 | static int smp_spin_table_cpu_prepare(unsigned int cpu) |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 67 | { |
Mark Rutland | 113954c | 2014-07-30 11:59:02 +0100 | [diff] [blame] | 68 | __le64 __iomem *release_addr; |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 69 | |
| 70 | if (!cpu_release_addr[cpu]) |
| 71 | return -ENODEV; |
| 72 | |
Mark Rutland | 113954c | 2014-07-30 11:59:02 +0100 | [diff] [blame] | 73 | /* |
| 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 Leach | 710be9a | 2013-10-11 14:52:18 +0100 | [diff] [blame] | 83 | |
| 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 Abbott | 2077be6 | 2017-01-10 13:35:49 -0800 | [diff] [blame] | 91 | writeq_relaxed(__pa_symbol(secondary_holding_pen), release_addr); |
Mark Rutland | 113954c | 2014-07-30 11:59:02 +0100 | [diff] [blame] | 92 | __flush_dcache_area((__force void *)release_addr, |
| 93 | sizeof(*release_addr)); |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * Send an event to wake up the secondary CPU. |
| 97 | */ |
| 98 | sev(); |
| 99 | |
Mark Rutland | 113954c | 2014-07-30 11:59:02 +0100 | [diff] [blame] | 100 | iounmap(release_addr); |
| 101 | |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | |
Mark Rutland | 652af89 | 2013-10-24 20:30:16 +0100 | [diff] [blame] | 105 | static int smp_spin_table_cpu_boot(unsigned int cpu) |
| 106 | { |
Mark Rutland | 652af89 | 2013-10-24 20:30:16 +0100 | [diff] [blame] | 107 | /* |
| 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 Marinas | 6400111 | 2014-04-04 11:49:05 +0100 | [diff] [blame] | 117 | return 0; |
Mark Rutland | 652af89 | 2013-10-24 20:30:16 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Mark Rutland | cd1aebf | 2013-10-24 20:30:15 +0100 | [diff] [blame] | 120 | const struct cpu_operations smp_spin_table_ops = { |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 121 | .name = "spin-table", |
Mark Rutland | cd1aebf | 2013-10-24 20:30:15 +0100 | [diff] [blame] | 122 | .cpu_init = smp_spin_table_cpu_init, |
| 123 | .cpu_prepare = smp_spin_table_cpu_prepare, |
Mark Rutland | 652af89 | 2013-10-24 20:30:16 +0100 | [diff] [blame] | 124 | .cpu_boot = smp_spin_table_cpu_boot, |
Marc Zyngier | d329de3 | 2013-01-02 15:24:22 +0000 | [diff] [blame] | 125 | }; |