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