Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Nicolas Pitre | 9ff221b | 2012-11-19 16:02:17 -0500 | [diff] [blame] | 2 | /* |
| 3 | * linux/arch/arm/mach-vexpress/mcpm_platsmp.c |
| 4 | * |
| 5 | * Created by: Nicolas Pitre, November 2012 |
| 6 | * Copyright: (C) 2012-2013 Linaro Limited |
| 7 | * |
Nicolas Pitre | 9ff221b | 2012-11-19 16:02:17 -0500 | [diff] [blame] | 8 | * Code to handle secondary CPU bringup and hotplug for the cluster power API. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/smp.h> |
| 13 | #include <linux/spinlock.h> |
| 14 | |
Nicolas Pitre | 9ff221b | 2012-11-19 16:02:17 -0500 | [diff] [blame] | 15 | #include <asm/mcpm.h> |
| 16 | #include <asm/smp.h> |
| 17 | #include <asm/smp_plat.h> |
| 18 | |
Dave Martin | 1e56609 | 2013-10-01 19:57:28 +0100 | [diff] [blame] | 19 | static void cpu_to_pcpu(unsigned int cpu, |
| 20 | unsigned int *pcpu, unsigned int *pcluster) |
Nicolas Pitre | 9ff221b | 2012-11-19 16:02:17 -0500 | [diff] [blame] | 21 | { |
Dave Martin | 1e56609 | 2013-10-01 19:57:28 +0100 | [diff] [blame] | 22 | unsigned int mpidr; |
Nicolas Pitre | 9ff221b | 2012-11-19 16:02:17 -0500 | [diff] [blame] | 23 | |
| 24 | mpidr = cpu_logical_map(cpu); |
Dave Martin | 1e56609 | 2013-10-01 19:57:28 +0100 | [diff] [blame] | 25 | *pcpu = MPIDR_AFFINITY_LEVEL(mpidr, 0); |
| 26 | *pcluster = MPIDR_AFFINITY_LEVEL(mpidr, 1); |
| 27 | } |
| 28 | |
| 29 | static int mcpm_boot_secondary(unsigned int cpu, struct task_struct *idle) |
| 30 | { |
| 31 | unsigned int pcpu, pcluster, ret; |
| 32 | extern void secondary_startup(void); |
| 33 | |
| 34 | cpu_to_pcpu(cpu, &pcpu, &pcluster); |
| 35 | |
Nicolas Pitre | 9ff221b | 2012-11-19 16:02:17 -0500 | [diff] [blame] | 36 | pr_debug("%s: logical CPU %d is physical CPU %d cluster %d\n", |
| 37 | __func__, cpu, pcpu, pcluster); |
| 38 | |
| 39 | mcpm_set_entry_vector(pcpu, pcluster, NULL); |
| 40 | ret = mcpm_cpu_power_up(pcpu, pcluster); |
| 41 | if (ret) |
| 42 | return ret; |
| 43 | mcpm_set_entry_vector(pcpu, pcluster, secondary_startup); |
| 44 | arch_send_wakeup_ipi_mask(cpumask_of(cpu)); |
| 45 | dsb_sev(); |
| 46 | return 0; |
| 47 | } |
| 48 | |
Paul Gortmaker | 8bd26e3 | 2013-06-17 15:43:14 -0400 | [diff] [blame] | 49 | static void mcpm_secondary_init(unsigned int cpu) |
Nicolas Pitre | 9ff221b | 2012-11-19 16:02:17 -0500 | [diff] [blame] | 50 | { |
| 51 | mcpm_cpu_powered_up(); |
Nicolas Pitre | 9ff221b | 2012-11-19 16:02:17 -0500 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | #ifdef CONFIG_HOTPLUG_CPU |
| 55 | |
Dave Martin | 0de0d64 | 2013-10-01 19:58:17 +0100 | [diff] [blame] | 56 | static int mcpm_cpu_kill(unsigned int cpu) |
| 57 | { |
| 58 | unsigned int pcpu, pcluster; |
| 59 | |
| 60 | cpu_to_pcpu(cpu, &pcpu, &pcluster); |
| 61 | |
Dave Martin | 166aaf3 | 2014-04-17 16:58:39 +0100 | [diff] [blame] | 62 | return !mcpm_wait_for_cpu_powerdown(pcpu, pcluster); |
Dave Martin | 0de0d64 | 2013-10-01 19:58:17 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Stephen Boyd | 787047e | 2015-07-29 00:34:48 +0100 | [diff] [blame] | 65 | static bool mcpm_cpu_can_disable(unsigned int cpu) |
Nicolas Pitre | 9ff221b | 2012-11-19 16:02:17 -0500 | [diff] [blame] | 66 | { |
Stephen Boyd | 787047e | 2015-07-29 00:34:48 +0100 | [diff] [blame] | 67 | /* We assume all CPUs may be shut down. */ |
| 68 | return true; |
Nicolas Pitre | 9ff221b | 2012-11-19 16:02:17 -0500 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static void mcpm_cpu_die(unsigned int cpu) |
| 72 | { |
| 73 | unsigned int mpidr, pcpu, pcluster; |
| 74 | mpidr = read_cpuid_mpidr(); |
| 75 | pcpu = MPIDR_AFFINITY_LEVEL(mpidr, 0); |
| 76 | pcluster = MPIDR_AFFINITY_LEVEL(mpidr, 1); |
| 77 | mcpm_set_entry_vector(pcpu, pcluster, NULL); |
| 78 | mcpm_cpu_power_down(); |
| 79 | } |
| 80 | |
| 81 | #endif |
| 82 | |
Masahiro Yamada | 7530527 | 2015-11-15 10:39:53 +0900 | [diff] [blame] | 83 | static const struct smp_operations mcpm_smp_ops __initconst = { |
Nicolas Pitre | 9ff221b | 2012-11-19 16:02:17 -0500 | [diff] [blame] | 84 | .smp_boot_secondary = mcpm_boot_secondary, |
| 85 | .smp_secondary_init = mcpm_secondary_init, |
| 86 | #ifdef CONFIG_HOTPLUG_CPU |
Dave Martin | 0de0d64 | 2013-10-01 19:58:17 +0100 | [diff] [blame] | 87 | .cpu_kill = mcpm_cpu_kill, |
Stephen Boyd | 787047e | 2015-07-29 00:34:48 +0100 | [diff] [blame] | 88 | .cpu_can_disable = mcpm_cpu_can_disable, |
Nicolas Pitre | 9ff221b | 2012-11-19 16:02:17 -0500 | [diff] [blame] | 89 | .cpu_die = mcpm_cpu_die, |
| 90 | #endif |
| 91 | }; |
Nicolas Pitre | a7eb7c6 | 2013-04-09 01:29:17 -0400 | [diff] [blame] | 92 | |
| 93 | void __init mcpm_smp_set_ops(void) |
| 94 | { |
| 95 | smp_set_ops(&mcpm_smp_ops); |
| 96 | } |