Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * linux/arch/arm/mach-vexpress/mcpm_platsmp.c
0004  *
0005  * Created by:  Nicolas Pitre, November 2012
0006  * Copyright:   (C) 2012-2013  Linaro Limited
0007  *
0008  * Code to handle secondary CPU bringup and hotplug for the cluster power API.
0009  */
0010 
0011 #include <linux/init.h>
0012 #include <linux/smp.h>
0013 #include <linux/spinlock.h>
0014 
0015 #include <asm/mcpm.h>
0016 #include <asm/smp.h>
0017 #include <asm/smp_plat.h>
0018 
0019 static void cpu_to_pcpu(unsigned int cpu,
0020             unsigned int *pcpu, unsigned int *pcluster)
0021 {
0022     unsigned int mpidr;
0023 
0024     mpidr = cpu_logical_map(cpu);
0025     *pcpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
0026     *pcluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
0027 }
0028 
0029 static int mcpm_boot_secondary(unsigned int cpu, struct task_struct *idle)
0030 {
0031     unsigned int pcpu, pcluster, ret;
0032     extern void secondary_startup(void);
0033 
0034     cpu_to_pcpu(cpu, &pcpu, &pcluster);
0035 
0036     pr_debug("%s: logical CPU %d is physical CPU %d cluster %d\n",
0037          __func__, cpu, pcpu, pcluster);
0038 
0039     mcpm_set_entry_vector(pcpu, pcluster, NULL);
0040     ret = mcpm_cpu_power_up(pcpu, pcluster);
0041     if (ret)
0042         return ret;
0043     mcpm_set_entry_vector(pcpu, pcluster, secondary_startup);
0044     arch_send_wakeup_ipi_mask(cpumask_of(cpu));
0045     dsb_sev();
0046     return 0;
0047 }
0048 
0049 static void mcpm_secondary_init(unsigned int cpu)
0050 {
0051     mcpm_cpu_powered_up();
0052 }
0053 
0054 #ifdef CONFIG_HOTPLUG_CPU
0055 
0056 static int mcpm_cpu_kill(unsigned int cpu)
0057 {
0058     unsigned int pcpu, pcluster;
0059 
0060     cpu_to_pcpu(cpu, &pcpu, &pcluster);
0061 
0062     return !mcpm_wait_for_cpu_powerdown(pcpu, pcluster);
0063 }
0064 
0065 static bool mcpm_cpu_can_disable(unsigned int cpu)
0066 {
0067     /* We assume all CPUs may be shut down. */
0068     return true;
0069 }
0070 
0071 static void mcpm_cpu_die(unsigned int cpu)
0072 {
0073     unsigned int mpidr, pcpu, pcluster;
0074     mpidr = read_cpuid_mpidr();
0075     pcpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
0076     pcluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
0077     mcpm_set_entry_vector(pcpu, pcluster, NULL);
0078     mcpm_cpu_power_down();
0079 }
0080 
0081 #endif
0082 
0083 static const struct smp_operations mcpm_smp_ops __initconst = {
0084     .smp_boot_secondary = mcpm_boot_secondary,
0085     .smp_secondary_init = mcpm_secondary_init,
0086 #ifdef CONFIG_HOTPLUG_CPU
0087     .cpu_kill       = mcpm_cpu_kill,
0088     .cpu_can_disable    = mcpm_cpu_can_disable,
0089     .cpu_die        = mcpm_cpu_die,
0090 #endif
0091 };
0092 
0093 void __init mcpm_smp_set_ops(void)
0094 {
0095     smp_set_ops(&mcpm_smp_ops);
0096 }