Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Marc Gonzalez | 222de7b | 2016-06-29 14:21:42 +0200 | [diff] [blame] | 2 | #include <linux/delay.h> |
Marc Gonzalez | d6bd057 | 2016-01-06 10:27:43 +0100 | [diff] [blame] | 3 | #include <linux/init.h> |
| 4 | #include <linux/smp.h> |
| 5 | #include "smc.h" |
| 6 | |
| 7 | static int tango_boot_secondary(unsigned int cpu, struct task_struct *idle) |
| 8 | { |
Florian Fainelli | 64fc2a9 | 2017-01-15 03:59:29 +0100 | [diff] [blame] | 9 | tango_set_aux_boot_addr(__pa_symbol(secondary_startup)); |
Marc Gonzalez | d6bd057 | 2016-01-06 10:27:43 +0100 | [diff] [blame] | 10 | tango_start_aux_core(cpu); |
| 11 | return 0; |
| 12 | } |
| 13 | |
Marc Gonzalez | 222de7b | 2016-06-29 14:21:42 +0200 | [diff] [blame] | 14 | #ifdef CONFIG_HOTPLUG_CPU |
| 15 | /* |
| 16 | * cpu_kill() and cpu_die() run concurrently on different cores. |
| 17 | * Firmware will only "kill" a core once it has properly "died". |
| 18 | * Try a few times to kill a core before giving up, and sleep |
| 19 | * between tries to give that core enough time to die. |
| 20 | */ |
| 21 | static int tango_cpu_kill(unsigned int cpu) |
| 22 | { |
| 23 | int i, err; |
| 24 | |
| 25 | for (i = 0; i < 10; ++i) { |
| 26 | msleep(10); |
| 27 | err = tango_aux_core_kill(cpu); |
| 28 | if (!err) |
| 29 | return true; |
| 30 | } |
| 31 | |
| 32 | return false; |
| 33 | } |
| 34 | |
| 35 | static void tango_cpu_die(unsigned int cpu) |
| 36 | { |
| 37 | while (tango_aux_core_die(cpu) < 0) |
| 38 | cpu_relax(); |
| 39 | |
| 40 | panic("cpu %d failed to die\n", cpu); |
| 41 | } |
Marc Gonzalez | 222de7b | 2016-06-29 14:21:42 +0200 | [diff] [blame] | 42 | #endif |
| 43 | |
Masahiro Yamada | c38ac80 | 2016-01-25 20:33:42 +0900 | [diff] [blame] | 44 | static const struct smp_operations tango_smp_ops __initconst = { |
Marc Gonzalez | d6bd057 | 2016-01-06 10:27:43 +0100 | [diff] [blame] | 45 | .smp_boot_secondary = tango_boot_secondary, |
Arnd Bergmann | 8264dde5 | 2016-07-06 22:04:42 +0200 | [diff] [blame] | 46 | #ifdef CONFIG_HOTPLUG_CPU |
Marc Gonzalez | 222de7b | 2016-06-29 14:21:42 +0200 | [diff] [blame] | 47 | .cpu_kill = tango_cpu_kill, |
| 48 | .cpu_die = tango_cpu_die, |
Arnd Bergmann | 8264dde5 | 2016-07-06 22:04:42 +0200 | [diff] [blame] | 49 | #endif |
Marc Gonzalez | d6bd057 | 2016-01-06 10:27:43 +0100 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | CPU_METHOD_OF_DECLARE(tango4_smp, "sigma,tango4-smp", &tango_smp_ops); |