David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is subject to the terms and conditions of the GNU General Public |
| 3 | * License. See the file "COPYING" in the main directory of this archive |
| 4 | * for more details. |
| 5 | * |
David Daney | edfcbb8 | 2010-07-23 10:57:49 -0700 | [diff] [blame] | 6 | * Copyright (C) 2004-2008, 2009, 2010 Cavium Networks |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 7 | */ |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 8 | #include <linux/cpu.h> |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 9 | #include <linux/delay.h> |
| 10 | #include <linux/smp.h> |
| 11 | #include <linux/interrupt.h> |
| 12 | #include <linux/kernel_stat.h> |
| 13 | #include <linux/sched.h> |
Ingo Molnar | ef8bd77 | 2017-02-08 18:51:36 +0100 | [diff] [blame] | 14 | #include <linux/sched/hotplug.h> |
Arnd Bergmann | fc69910 | 2017-03-08 08:29:31 +0100 | [diff] [blame] | 15 | #include <linux/sched/task_stack.h> |
Paul Gortmaker | 26dd3e4 | 2017-01-28 21:05:57 -0500 | [diff] [blame] | 16 | #include <linux/init.h> |
| 17 | #include <linux/export.h> |
Dengcheng Zhu | 62cac48 | 2018-09-11 14:49:21 -0700 | [diff] [blame] | 18 | #include <linux/kexec.h> |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 19 | |
| 20 | #include <asm/mmu_context.h> |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 21 | #include <asm/time.h> |
David Howells | b81947c | 2012-03-28 18:30:02 +0100 | [diff] [blame] | 22 | #include <asm/setup.h> |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 23 | |
| 24 | #include <asm/octeon/octeon.h> |
| 25 | |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 26 | #include "octeon_boot.h" |
| 27 | |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 28 | volatile unsigned long octeon_processor_boot = 0xff; |
| 29 | volatile unsigned long octeon_processor_sp; |
| 30 | volatile unsigned long octeon_processor_gp; |
Steven J. Hill | 3ff72be | 2016-12-13 14:25:37 -0600 | [diff] [blame] | 31 | #ifdef CONFIG_RELOCATABLE |
| 32 | volatile unsigned long octeon_processor_relocated_kernel_entry; |
| 33 | #endif /* CONFIG_RELOCATABLE */ |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 34 | |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 35 | #ifdef CONFIG_HOTPLUG_CPU |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 36 | uint64_t octeon_bootloader_entry_addr; |
| 37 | EXPORT_SYMBOL(octeon_bootloader_entry_addr); |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 38 | #endif |
| 39 | |
Steven J. Hill | 3ff72be | 2016-12-13 14:25:37 -0600 | [diff] [blame] | 40 | extern void kernel_entry(unsigned long arg1, ...); |
| 41 | |
David Daney | c6d2b22 | 2016-02-09 11:00:12 -0800 | [diff] [blame] | 42 | static void octeon_icache_flush(void) |
| 43 | { |
| 44 | asm volatile ("synci 0($0)\n"); |
| 45 | } |
| 46 | |
| 47 | static void (*octeon_message_functions[8])(void) = { |
| 48 | scheduler_ipi, |
| 49 | generic_smp_call_function_interrupt, |
| 50 | octeon_icache_flush, |
| 51 | }; |
| 52 | |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 53 | static irqreturn_t mailbox_interrupt(int irq, void *dev_id) |
| 54 | { |
David Daney | c6d2b22 | 2016-02-09 11:00:12 -0800 | [diff] [blame] | 55 | u64 mbox_clrx = CVMX_CIU_MBOX_CLRX(cvmx_get_core_num()); |
| 56 | u64 action; |
| 57 | int i; |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 58 | |
David Daney | c6d2b22 | 2016-02-09 11:00:12 -0800 | [diff] [blame] | 59 | /* |
| 60 | * Make sure the function array initialization remains |
| 61 | * correct. |
| 62 | */ |
| 63 | BUILD_BUG_ON(SMP_RESCHEDULE_YOURSELF != (1 << 0)); |
| 64 | BUILD_BUG_ON(SMP_CALL_FUNCTION != (1 << 1)); |
| 65 | BUILD_BUG_ON(SMP_ICACHE_FLUSH != (1 << 2)); |
| 66 | |
| 67 | /* |
| 68 | * Load the mailbox register to figure out what we're supposed |
| 69 | * to do. |
| 70 | */ |
| 71 | action = cvmx_read_csr(mbox_clrx); |
| 72 | |
| 73 | if (OCTEON_IS_MODEL(OCTEON_CN68XX)) |
| 74 | action &= 0xff; |
| 75 | else |
| 76 | action &= 0xffff; |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 77 | |
| 78 | /* Clear the mailbox to clear the interrupt */ |
David Daney | c6d2b22 | 2016-02-09 11:00:12 -0800 | [diff] [blame] | 79 | cvmx_write_csr(mbox_clrx, action); |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 80 | |
David Daney | c6d2b22 | 2016-02-09 11:00:12 -0800 | [diff] [blame] | 81 | for (i = 0; i < ARRAY_SIZE(octeon_message_functions) && action;) { |
| 82 | if (action & 1) { |
| 83 | void (*fn)(void) = octeon_message_functions[i]; |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 84 | |
David Daney | c6d2b22 | 2016-02-09 11:00:12 -0800 | [diff] [blame] | 85 | if (fn) |
| 86 | fn(); |
| 87 | } |
| 88 | action >>= 1; |
| 89 | i++; |
| 90 | } |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 91 | return IRQ_HANDLED; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Cause the function described by call_data to be executed on the passed |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 96 | * cpu. When the function has finished, increment the finished field of |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 97 | * call_data. |
| 98 | */ |
| 99 | void octeon_send_ipi_single(int cpu, unsigned int action) |
| 100 | { |
| 101 | int coreid = cpu_logical_map(cpu); |
| 102 | /* |
| 103 | pr_info("SMP: Mailbox send cpu=%d, coreid=%d, action=%u\n", cpu, |
| 104 | coreid, action); |
| 105 | */ |
| 106 | cvmx_write_csr(CVMX_CIU_MBOX_SETX(coreid), action); |
| 107 | } |
| 108 | |
David Daney | 067f329 | 2009-10-01 16:47:38 -0700 | [diff] [blame] | 109 | static inline void octeon_send_ipi_mask(const struct cpumask *mask, |
| 110 | unsigned int action) |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 111 | { |
| 112 | unsigned int i; |
| 113 | |
Rusty Russell | 8dd9289 | 2015-03-05 10:49:17 +1030 | [diff] [blame] | 114 | for_each_cpu(i, mask) |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 115 | octeon_send_ipi_single(i, action); |
| 116 | } |
| 117 | |
| 118 | /** |
Rusty Russell | 5f054e3 | 2012-03-29 15:38:31 +1030 | [diff] [blame] | 119 | * Detect available CPUs, populate cpu_possible_mask |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 120 | */ |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 121 | static void octeon_smp_hotplug_setup(void) |
| 122 | { |
| 123 | #ifdef CONFIG_HOTPLUG_CPU |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 124 | struct linux_app_boot_info *labi; |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 125 | |
Aaro Koskinen | 5ca0e37 | 2014-06-28 00:59:51 +0300 | [diff] [blame] | 126 | if (!setup_max_cpus) |
| 127 | return; |
| 128 | |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 129 | labi = (struct linux_app_boot_info *)PHYS_TO_XKSEG_CACHED(LABI_ADDR_IN_BOOTLOADER); |
Aaro Koskinen | eac44d9 | 2014-06-28 00:59:52 +0300 | [diff] [blame] | 130 | if (labi->labi_signature != LABI_SIGNATURE) { |
| 131 | pr_info("The bootloader on this board does not support HOTPLUG_CPU."); |
| 132 | return; |
| 133 | } |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 134 | |
| 135 | octeon_bootloader_entry_addr = labi->InitTLBStart_addr; |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 136 | #endif |
| 137 | } |
| 138 | |
Yang Shi | 0e8c1a3 | 2016-02-19 17:04:07 -0800 | [diff] [blame] | 139 | static void __init octeon_smp_setup(void) |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 140 | { |
| 141 | const int coreid = cvmx_get_core_num(); |
| 142 | int cpus; |
| 143 | int id; |
David Daney | 7d52ab1 | 2016-02-01 17:46:54 -0800 | [diff] [blame] | 144 | struct cvmx_sysinfo *sysinfo = cvmx_sysinfo_get(); |
| 145 | |
David Daney | edfcbb8 | 2010-07-23 10:57:49 -0700 | [diff] [blame] | 146 | #ifdef CONFIG_HOTPLUG_CPU |
David Daney | c6d2b22 | 2016-02-09 11:00:12 -0800 | [diff] [blame] | 147 | int core_mask = octeon_get_boot_coremask(); |
David Daney | edfcbb8 | 2010-07-23 10:57:49 -0700 | [diff] [blame] | 148 | unsigned int num_cores = cvmx_octeon_num_cores(); |
| 149 | #endif |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 150 | |
David Daney | edfcbb8 | 2010-07-23 10:57:49 -0700 | [diff] [blame] | 151 | /* The present CPUs are initially just the boot cpu (CPU 0). */ |
| 152 | for (id = 0; id < NR_CPUS; id++) { |
| 153 | set_cpu_possible(id, id == 0); |
| 154 | set_cpu_present(id, id == 0); |
| 155 | } |
| 156 | |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 157 | __cpu_number_map[coreid] = 0; |
| 158 | __cpu_logical_map[0] = coreid; |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 159 | |
David Daney | edfcbb8 | 2010-07-23 10:57:49 -0700 | [diff] [blame] | 160 | /* The present CPUs get the lowest CPU numbers. */ |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 161 | cpus = 1; |
David Daney | edfcbb8 | 2010-07-23 10:57:49 -0700 | [diff] [blame] | 162 | for (id = 0; id < NR_CPUS; id++) { |
David Daney | 7d52ab1 | 2016-02-01 17:46:54 -0800 | [diff] [blame] | 163 | if ((id != coreid) && cvmx_coremask_is_core_set(&sysinfo->core_mask, id)) { |
David Daney | edfcbb8 | 2010-07-23 10:57:49 -0700 | [diff] [blame] | 164 | set_cpu_possible(cpus, true); |
| 165 | set_cpu_present(cpus, true); |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 166 | __cpu_number_map[id] = cpus; |
| 167 | __cpu_logical_map[cpus] = id; |
| 168 | cpus++; |
| 169 | } |
| 170 | } |
David Daney | edfcbb8 | 2010-07-23 10:57:49 -0700 | [diff] [blame] | 171 | |
| 172 | #ifdef CONFIG_HOTPLUG_CPU |
| 173 | /* |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 174 | * The possible CPUs are all those present on the chip. We |
| 175 | * will assign CPU numbers for possible cores as well. Cores |
David Daney | edfcbb8 | 2010-07-23 10:57:49 -0700 | [diff] [blame] | 176 | * are always consecutively numberd from 0. |
| 177 | */ |
Aaro Koskinen | eac44d9 | 2014-06-28 00:59:52 +0300 | [diff] [blame] | 178 | for (id = 0; setup_max_cpus && octeon_bootloader_entry_addr && |
| 179 | id < num_cores && id < NR_CPUS; id++) { |
David Daney | edfcbb8 | 2010-07-23 10:57:49 -0700 | [diff] [blame] | 180 | if (!(core_mask & (1 << id))) { |
| 181 | set_cpu_possible(cpus, true); |
| 182 | __cpu_number_map[id] = cpus; |
| 183 | __cpu_logical_map[cpus] = id; |
| 184 | cpus++; |
| 185 | } |
| 186 | } |
| 187 | #endif |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 188 | |
| 189 | octeon_smp_hotplug_setup(); |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 190 | } |
| 191 | |
Steven J. Hill | 3ff72be | 2016-12-13 14:25:37 -0600 | [diff] [blame] | 192 | |
| 193 | #ifdef CONFIG_RELOCATABLE |
| 194 | int plat_post_relocation(long offset) |
| 195 | { |
| 196 | unsigned long entry = (unsigned long)kernel_entry; |
| 197 | |
| 198 | /* Send secondaries into relocated kernel */ |
| 199 | octeon_processor_relocated_kernel_entry = entry + offset; |
| 200 | |
| 201 | return 0; |
| 202 | } |
| 203 | #endif /* CONFIG_RELOCATABLE */ |
| 204 | |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 205 | /** |
| 206 | * Firmware CPU startup hook |
| 207 | * |
| 208 | */ |
Paul Burton | d595d42 | 2017-08-12 19:49:40 -0700 | [diff] [blame] | 209 | static int octeon_boot_secondary(int cpu, struct task_struct *idle) |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 210 | { |
| 211 | int count; |
| 212 | |
| 213 | pr_info("SMP: Booting CPU%02d (CoreId %2d)...\n", cpu, |
| 214 | cpu_logical_map(cpu)); |
| 215 | |
| 216 | octeon_processor_sp = __KSTK_TOS(idle); |
| 217 | octeon_processor_gp = (unsigned long)(task_thread_info(idle)); |
| 218 | octeon_processor_boot = cpu_logical_map(cpu); |
| 219 | mb(); |
| 220 | |
| 221 | count = 10000; |
| 222 | while (octeon_processor_sp && count) { |
| 223 | /* Waiting for processor to get the SP and GP */ |
| 224 | udelay(1); |
| 225 | count--; |
| 226 | } |
Paul Burton | d595d42 | 2017-08-12 19:49:40 -0700 | [diff] [blame] | 227 | if (count == 0) { |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 228 | pr_err("Secondary boot timeout\n"); |
Paul Burton | d595d42 | 2017-08-12 19:49:40 -0700 | [diff] [blame] | 229 | return -ETIMEDOUT; |
| 230 | } |
| 231 | |
| 232 | return 0; |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | /** |
| 236 | * After we've done initial boot, this function is called to allow the |
| 237 | * board code to clean up state, if needed |
| 238 | */ |
Paul Gortmaker | 078a55f | 2013-06-18 13:38:59 +0000 | [diff] [blame] | 239 | static void octeon_init_secondary(void) |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 240 | { |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 241 | unsigned int sr; |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 242 | |
David Daney | 0c32638 | 2011-03-25 12:38:51 -0700 | [diff] [blame] | 243 | sr = set_c0_status(ST0_BEV); |
| 244 | write_c0_ebase((u32)ebase); |
| 245 | write_c0_status(sr); |
| 246 | |
| 247 | octeon_check_cpu_bist(); |
| 248 | octeon_init_cvmcount(); |
| 249 | |
| 250 | octeon_irq_setup_secondary(); |
David Daney | 0c32638 | 2011-03-25 12:38:51 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | /** |
| 254 | * Callout to firmware before smp_init |
| 255 | * |
| 256 | */ |
Yang Shi | 0e8c1a3 | 2016-02-19 17:04:07 -0800 | [diff] [blame] | 257 | static void __init octeon_prepare_cpus(unsigned int max_cpus) |
David Daney | 0c32638 | 2011-03-25 12:38:51 -0700 | [diff] [blame] | 258 | { |
David Daney | e650ce0 | 2011-02-17 14:47:52 -0800 | [diff] [blame] | 259 | /* |
| 260 | * Only the low order mailbox bits are used for IPIs, leave |
| 261 | * the other bits alone. |
| 262 | */ |
| 263 | cvmx_write_csr(CVMX_CIU_MBOX_CLRX(cvmx_get_core_num()), 0xffff); |
Venkat Subbiah | e63fb7a | 2011-10-03 13:31:10 -0700 | [diff] [blame] | 264 | if (request_irq(OCTEON_IRQ_MBOX0, mailbox_interrupt, |
| 265 | IRQF_PERCPU | IRQF_NO_THREAD, "SMP-IPI", |
| 266 | mailbox_interrupt)) { |
Ralf Baechle | ab75dc0 | 2011-11-17 15:07:31 +0000 | [diff] [blame] | 267 | panic("Cannot request_irq(OCTEON_IRQ_MBOX0)"); |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 268 | } |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Last chance for the board code to finish SMP initialization before |
| 273 | * the CPU is "online". |
| 274 | */ |
| 275 | static void octeon_smp_finish(void) |
| 276 | { |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 277 | octeon_user_io_init(); |
| 278 | |
| 279 | /* to generate the first CPU timer interrupt */ |
| 280 | write_c0_compare(read_c0_count() + mips_hpt_frequency / HZ); |
Yong Zhang | 1bcfecc | 2012-07-19 09:13:53 +0200 | [diff] [blame] | 281 | local_irq_enable(); |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 282 | } |
| 283 | |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 284 | #ifdef CONFIG_HOTPLUG_CPU |
| 285 | |
| 286 | /* State of each CPU. */ |
Aaro Koskinen | 51807f6 | 2018-11-22 00:37:32 +0200 | [diff] [blame] | 287 | static DEFINE_PER_CPU(int, cpu_state); |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 288 | |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 289 | static int octeon_cpu_disable(void) |
| 290 | { |
| 291 | unsigned int cpu = smp_processor_id(); |
| 292 | |
| 293 | if (cpu == 0) |
| 294 | return -EBUSY; |
| 295 | |
Aaro Koskinen | eac44d9 | 2014-06-28 00:59:52 +0300 | [diff] [blame] | 296 | if (!octeon_bootloader_entry_addr) |
| 297 | return -ENOTSUPP; |
| 298 | |
Rusty Russell | 0b5f9c0 | 2012-03-29 15:38:30 +1030 | [diff] [blame] | 299 | set_cpu_online(cpu, false); |
James Hogan | 826e99b | 2016-07-13 14:12:45 +0100 | [diff] [blame] | 300 | calculate_cpu_foreign_map(); |
Ralf Baechle | 17efb59 | 2013-09-03 18:19:28 +0200 | [diff] [blame] | 301 | octeon_fixup_irqs(); |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 302 | |
Ralf Baechle | 9329c15 | 2016-01-27 18:07:00 +0100 | [diff] [blame] | 303 | __flush_cache_all(); |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 304 | local_flush_tlb_all(); |
| 305 | |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 306 | return 0; |
| 307 | } |
| 308 | |
| 309 | static void octeon_cpu_die(unsigned int cpu) |
| 310 | { |
| 311 | int coreid = cpu_logical_map(cpu); |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 312 | uint32_t mask, new_mask; |
| 313 | const struct cvmx_bootmem_named_block_desc *block_desc; |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 314 | |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 315 | while (per_cpu(cpu_state, cpu) != CPU_DEAD) |
| 316 | cpu_relax(); |
| 317 | |
| 318 | /* |
| 319 | * This is a bit complicated strategics of getting/settig available |
| 320 | * cores mask, copied from bootloader |
| 321 | */ |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 322 | |
| 323 | mask = 1 << coreid; |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 324 | /* LINUX_APP_BOOT_BLOCK is initialized in bootoct binary */ |
| 325 | block_desc = cvmx_bootmem_find_named_block(LINUX_APP_BOOT_BLOCK_NAME); |
| 326 | |
| 327 | if (!block_desc) { |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 328 | struct linux_app_boot_info *labi; |
| 329 | |
| 330 | labi = (struct linux_app_boot_info *)PHYS_TO_XKSEG_CACHED(LABI_ADDR_IN_BOOTLOADER); |
| 331 | |
| 332 | labi->avail_coremask |= mask; |
| 333 | new_mask = labi->avail_coremask; |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 334 | } else { /* alternative, already initialized */ |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 335 | uint32_t *p = (uint32_t *)PHYS_TO_XKSEG_CACHED(block_desc->base_addr + |
| 336 | AVAIL_COREMASK_OFFSET_IN_LINUX_APP_BOOT_BLOCK); |
| 337 | *p |= mask; |
| 338 | new_mask = *p; |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 339 | } |
| 340 | |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 341 | pr_info("Reset core %d. Available Coremask = 0x%x \n", coreid, new_mask); |
| 342 | mb(); |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 343 | cvmx_write_csr(CVMX_CIU_PP_RST, 1 << coreid); |
| 344 | cvmx_write_csr(CVMX_CIU_PP_RST, 0); |
| 345 | } |
| 346 | |
| 347 | void play_dead(void) |
| 348 | { |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 349 | int cpu = cpu_number_map(cvmx_get_core_num()); |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 350 | |
| 351 | idle_task_exit(); |
| 352 | octeon_processor_boot = 0xff; |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 353 | per_cpu(cpu_state, cpu) = CPU_DEAD; |
| 354 | |
| 355 | mb(); |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 356 | |
| 357 | while (1) /* core will be reset here */ |
| 358 | ; |
| 359 | } |
| 360 | |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 361 | static void start_after_reset(void) |
| 362 | { |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 363 | kernel_entry(0, 0, 0); /* set a2 = 0 for secondary core */ |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 364 | } |
| 365 | |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 366 | static int octeon_update_boot_vector(unsigned int cpu) |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 367 | { |
| 368 | |
| 369 | int coreid = cpu_logical_map(cpu); |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 370 | uint32_t avail_coremask; |
| 371 | const struct cvmx_bootmem_named_block_desc *block_desc; |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 372 | struct boot_init_vector *boot_vect = |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 373 | (struct boot_init_vector *)PHYS_TO_XKSEG_CACHED(BOOTLOADER_BOOT_VECTOR); |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 374 | |
| 375 | block_desc = cvmx_bootmem_find_named_block(LINUX_APP_BOOT_BLOCK_NAME); |
| 376 | |
| 377 | if (!block_desc) { |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 378 | struct linux_app_boot_info *labi; |
| 379 | |
| 380 | labi = (struct linux_app_boot_info *)PHYS_TO_XKSEG_CACHED(LABI_ADDR_IN_BOOTLOADER); |
| 381 | |
| 382 | avail_coremask = labi->avail_coremask; |
| 383 | labi->avail_coremask &= ~(1 << coreid); |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 384 | } else { /* alternative, already initialized */ |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 385 | avail_coremask = *(uint32_t *)PHYS_TO_XKSEG_CACHED( |
| 386 | block_desc->base_addr + AVAIL_COREMASK_OFFSET_IN_LINUX_APP_BOOT_BLOCK); |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | if (!(avail_coremask & (1 << coreid))) { |
Adam Buchbinder | 92a76f6 | 2016-02-25 00:44:58 -0800 | [diff] [blame] | 390 | /* core not available, assume, that caught by simple-executive */ |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 391 | cvmx_write_csr(CVMX_CIU_PP_RST, 1 << coreid); |
| 392 | cvmx_write_csr(CVMX_CIU_PP_RST, 0); |
| 393 | } |
| 394 | |
| 395 | boot_vect[coreid].app_start_func_addr = |
| 396 | (uint32_t) (unsigned long) start_after_reset; |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 397 | boot_vect[coreid].code_addr = octeon_bootloader_entry_addr; |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 398 | |
David Daney | babba4f | 2010-07-23 10:57:51 -0700 | [diff] [blame] | 399 | mb(); |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 400 | |
| 401 | cvmx_write_csr(CVMX_CIU_NMI, (1 << coreid) & avail_coremask); |
| 402 | |
| 403 | return 0; |
| 404 | } |
| 405 | |
Paul Gortmaker | 078a55f | 2013-06-18 13:38:59 +0000 | [diff] [blame] | 406 | static int register_cavium_notifier(void) |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 407 | { |
Sebastian Andrzej Siewior | dd6d7c6 | 2016-09-06 19:04:51 +0200 | [diff] [blame] | 408 | return cpuhp_setup_state_nocalls(CPUHP_MIPS_SOC_PREPARE, |
| 409 | "mips/cavium:prepare", |
| 410 | octeon_update_boot_vector, NULL); |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 411 | } |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 412 | late_initcall(register_cavium_notifier); |
| 413 | |
Ralf Baechle | 7034228 | 2013-01-22 12:59:30 +0100 | [diff] [blame] | 414 | #endif /* CONFIG_HOTPLUG_CPU */ |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 415 | |
Aaro Koskinen | 51807f6 | 2018-11-22 00:37:32 +0200 | [diff] [blame] | 416 | static const struct plat_smp_ops octeon_smp_ops = { |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 417 | .send_ipi_single = octeon_send_ipi_single, |
| 418 | .send_ipi_mask = octeon_send_ipi_mask, |
| 419 | .init_secondary = octeon_init_secondary, |
| 420 | .smp_finish = octeon_smp_finish, |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 421 | .boot_secondary = octeon_boot_secondary, |
| 422 | .smp_setup = octeon_smp_setup, |
| 423 | .prepare_cpus = octeon_prepare_cpus, |
Ralf Baechle | 773cb77 | 2009-06-23 10:36:38 +0100 | [diff] [blame] | 424 | #ifdef CONFIG_HOTPLUG_CPU |
| 425 | .cpu_disable = octeon_cpu_disable, |
| 426 | .cpu_die = octeon_cpu_die, |
| 427 | #endif |
Dengcheng Zhu | 62cac48 | 2018-09-11 14:49:21 -0700 | [diff] [blame] | 428 | #ifdef CONFIG_KEXEC |
| 429 | .kexec_nonboot_cpu = kexec_nonboot_cpu_jump, |
| 430 | #endif |
David Daney | 5b3b168 | 2009-01-08 16:46:40 -0800 | [diff] [blame] | 431 | }; |
David Daney | c6d2b22 | 2016-02-09 11:00:12 -0800 | [diff] [blame] | 432 | |
| 433 | static irqreturn_t octeon_78xx_reched_interrupt(int irq, void *dev_id) |
| 434 | { |
| 435 | scheduler_ipi(); |
| 436 | return IRQ_HANDLED; |
| 437 | } |
| 438 | |
| 439 | static irqreturn_t octeon_78xx_call_function_interrupt(int irq, void *dev_id) |
| 440 | { |
| 441 | generic_smp_call_function_interrupt(); |
| 442 | return IRQ_HANDLED; |
| 443 | } |
| 444 | |
| 445 | static irqreturn_t octeon_78xx_icache_flush_interrupt(int irq, void *dev_id) |
| 446 | { |
| 447 | octeon_icache_flush(); |
| 448 | return IRQ_HANDLED; |
| 449 | } |
| 450 | |
| 451 | /* |
| 452 | * Callout to firmware before smp_init |
| 453 | */ |
| 454 | static void octeon_78xx_prepare_cpus(unsigned int max_cpus) |
| 455 | { |
| 456 | if (request_irq(OCTEON_IRQ_MBOX0 + 0, |
| 457 | octeon_78xx_reched_interrupt, |
| 458 | IRQF_PERCPU | IRQF_NO_THREAD, "Scheduler", |
| 459 | octeon_78xx_reched_interrupt)) { |
| 460 | panic("Cannot request_irq for SchedulerIPI"); |
| 461 | } |
| 462 | if (request_irq(OCTEON_IRQ_MBOX0 + 1, |
| 463 | octeon_78xx_call_function_interrupt, |
| 464 | IRQF_PERCPU | IRQF_NO_THREAD, "SMP-Call", |
| 465 | octeon_78xx_call_function_interrupt)) { |
| 466 | panic("Cannot request_irq for SMP-Call"); |
| 467 | } |
| 468 | if (request_irq(OCTEON_IRQ_MBOX0 + 2, |
| 469 | octeon_78xx_icache_flush_interrupt, |
| 470 | IRQF_PERCPU | IRQF_NO_THREAD, "ICache-Flush", |
| 471 | octeon_78xx_icache_flush_interrupt)) { |
| 472 | panic("Cannot request_irq for ICache-Flush"); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | static void octeon_78xx_send_ipi_single(int cpu, unsigned int action) |
| 477 | { |
| 478 | int i; |
| 479 | |
| 480 | for (i = 0; i < 8; i++) { |
| 481 | if (action & 1) |
| 482 | octeon_ciu3_mbox_send(cpu, i); |
| 483 | action >>= 1; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | static void octeon_78xx_send_ipi_mask(const struct cpumask *mask, |
| 488 | unsigned int action) |
| 489 | { |
| 490 | unsigned int cpu; |
| 491 | |
| 492 | for_each_cpu(cpu, mask) |
| 493 | octeon_78xx_send_ipi_single(cpu, action); |
| 494 | } |
| 495 | |
Matt Redfearn | ff2c825 | 2017-07-19 09:21:03 +0100 | [diff] [blame] | 496 | static const struct plat_smp_ops octeon_78xx_smp_ops = { |
David Daney | c6d2b22 | 2016-02-09 11:00:12 -0800 | [diff] [blame] | 497 | .send_ipi_single = octeon_78xx_send_ipi_single, |
| 498 | .send_ipi_mask = octeon_78xx_send_ipi_mask, |
| 499 | .init_secondary = octeon_init_secondary, |
| 500 | .smp_finish = octeon_smp_finish, |
| 501 | .boot_secondary = octeon_boot_secondary, |
| 502 | .smp_setup = octeon_smp_setup, |
| 503 | .prepare_cpus = octeon_78xx_prepare_cpus, |
| 504 | #ifdef CONFIG_HOTPLUG_CPU |
| 505 | .cpu_disable = octeon_cpu_disable, |
| 506 | .cpu_die = octeon_cpu_die, |
| 507 | #endif |
Dengcheng Zhu | 62cac48 | 2018-09-11 14:49:21 -0700 | [diff] [blame] | 508 | #ifdef CONFIG_KEXEC |
| 509 | .kexec_nonboot_cpu = kexec_nonboot_cpu_jump, |
| 510 | #endif |
David Daney | c6d2b22 | 2016-02-09 11:00:12 -0800 | [diff] [blame] | 511 | }; |
| 512 | |
| 513 | void __init octeon_setup_smp(void) |
| 514 | { |
Matt Redfearn | ff2c825 | 2017-07-19 09:21:03 +0100 | [diff] [blame] | 515 | const struct plat_smp_ops *ops; |
David Daney | c6d2b22 | 2016-02-09 11:00:12 -0800 | [diff] [blame] | 516 | |
| 517 | if (octeon_has_feature(OCTEON_FEATURE_CIU3)) |
| 518 | ops = &octeon_78xx_smp_ops; |
| 519 | else |
| 520 | ops = &octeon_smp_ops; |
| 521 | |
| 522 | register_smp_ops(ops); |
| 523 | } |