^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include "smc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) static int tango_boot_secondary(unsigned int cpu, struct task_struct *idle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) tango_set_aux_boot_addr(__pa_symbol(secondary_startup));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) tango_start_aux_core(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #ifdef CONFIG_HOTPLUG_CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * cpu_kill() and cpu_die() run concurrently on different cores.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Firmware will only "kill" a core once it has properly "died".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Try a few times to kill a core before giving up, and sleep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * between tries to give that core enough time to die.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static int tango_cpu_kill(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) for (i = 0; i < 10; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) msleep(10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) err = tango_aux_core_kill(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static void tango_cpu_die(unsigned int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) while (tango_aux_core_die(cpu) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) cpu_relax();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) panic("cpu %d failed to die\n", cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static const struct smp_operations tango_smp_ops __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .smp_boot_secondary = tango_boot_secondary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #ifdef CONFIG_HOTPLUG_CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) .cpu_kill = tango_cpu_kill,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) .cpu_die = tango_cpu_die,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) CPU_METHOD_OF_DECLARE(tango4_smp, "sigma,tango4-smp", &tango_smp_ops);