xref: /openbmc/linux/arch/arm/common/mcpm_platsmp.c (revision 787047ee)
19ff221baSNicolas Pitre /*
29ff221baSNicolas Pitre  * linux/arch/arm/mach-vexpress/mcpm_platsmp.c
39ff221baSNicolas Pitre  *
49ff221baSNicolas Pitre  * Created by:  Nicolas Pitre, November 2012
59ff221baSNicolas Pitre  * Copyright:   (C) 2012-2013  Linaro Limited
69ff221baSNicolas Pitre  *
79ff221baSNicolas Pitre  * This program is free software; you can redistribute it and/or modify
89ff221baSNicolas Pitre  * it under the terms of the GNU General Public License version 2 as
99ff221baSNicolas Pitre  * published by the Free Software Foundation.
109ff221baSNicolas Pitre  *
119ff221baSNicolas Pitre  * Code to handle secondary CPU bringup and hotplug for the cluster power API.
129ff221baSNicolas Pitre  */
139ff221baSNicolas Pitre 
149ff221baSNicolas Pitre #include <linux/init.h>
159ff221baSNicolas Pitre #include <linux/smp.h>
169ff221baSNicolas Pitre #include <linux/spinlock.h>
179ff221baSNicolas Pitre 
189ff221baSNicolas Pitre #include <asm/mcpm.h>
199ff221baSNicolas Pitre #include <asm/smp.h>
209ff221baSNicolas Pitre #include <asm/smp_plat.h>
219ff221baSNicolas Pitre 
221e566099SDave Martin static void cpu_to_pcpu(unsigned int cpu,
231e566099SDave Martin 			unsigned int *pcpu, unsigned int *pcluster)
249ff221baSNicolas Pitre {
251e566099SDave Martin 	unsigned int mpidr;
269ff221baSNicolas Pitre 
279ff221baSNicolas Pitre 	mpidr = cpu_logical_map(cpu);
281e566099SDave Martin 	*pcpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
291e566099SDave Martin 	*pcluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
301e566099SDave Martin }
311e566099SDave Martin 
321e566099SDave Martin static int mcpm_boot_secondary(unsigned int cpu, struct task_struct *idle)
331e566099SDave Martin {
341e566099SDave Martin 	unsigned int pcpu, pcluster, ret;
351e566099SDave Martin 	extern void secondary_startup(void);
361e566099SDave Martin 
371e566099SDave Martin 	cpu_to_pcpu(cpu, &pcpu, &pcluster);
381e566099SDave Martin 
399ff221baSNicolas Pitre 	pr_debug("%s: logical CPU %d is physical CPU %d cluster %d\n",
409ff221baSNicolas Pitre 		 __func__, cpu, pcpu, pcluster);
419ff221baSNicolas Pitre 
429ff221baSNicolas Pitre 	mcpm_set_entry_vector(pcpu, pcluster, NULL);
439ff221baSNicolas Pitre 	ret = mcpm_cpu_power_up(pcpu, pcluster);
449ff221baSNicolas Pitre 	if (ret)
459ff221baSNicolas Pitre 		return ret;
469ff221baSNicolas Pitre 	mcpm_set_entry_vector(pcpu, pcluster, secondary_startup);
479ff221baSNicolas Pitre 	arch_send_wakeup_ipi_mask(cpumask_of(cpu));
489ff221baSNicolas Pitre 	dsb_sev();
499ff221baSNicolas Pitre 	return 0;
509ff221baSNicolas Pitre }
519ff221baSNicolas Pitre 
528bd26e3aSPaul Gortmaker static void mcpm_secondary_init(unsigned int cpu)
539ff221baSNicolas Pitre {
549ff221baSNicolas Pitre 	mcpm_cpu_powered_up();
559ff221baSNicolas Pitre }
569ff221baSNicolas Pitre 
579ff221baSNicolas Pitre #ifdef CONFIG_HOTPLUG_CPU
589ff221baSNicolas Pitre 
590de0d646SDave Martin static int mcpm_cpu_kill(unsigned int cpu)
600de0d646SDave Martin {
610de0d646SDave Martin 	unsigned int pcpu, pcluster;
620de0d646SDave Martin 
630de0d646SDave Martin 	cpu_to_pcpu(cpu, &pcpu, &pcluster);
640de0d646SDave Martin 
65166aaf39SDave Martin 	return !mcpm_wait_for_cpu_powerdown(pcpu, pcluster);
660de0d646SDave Martin }
670de0d646SDave Martin 
68787047eeSStephen Boyd static bool mcpm_cpu_can_disable(unsigned int cpu)
699ff221baSNicolas Pitre {
70787047eeSStephen Boyd 	/* We assume all CPUs may be shut down. */
71787047eeSStephen Boyd 	return true;
729ff221baSNicolas Pitre }
739ff221baSNicolas Pitre 
749ff221baSNicolas Pitre static void mcpm_cpu_die(unsigned int cpu)
759ff221baSNicolas Pitre {
769ff221baSNicolas Pitre 	unsigned int mpidr, pcpu, pcluster;
779ff221baSNicolas Pitre 	mpidr = read_cpuid_mpidr();
789ff221baSNicolas Pitre 	pcpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
799ff221baSNicolas Pitre 	pcluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
809ff221baSNicolas Pitre 	mcpm_set_entry_vector(pcpu, pcluster, NULL);
819ff221baSNicolas Pitre 	mcpm_cpu_power_down();
829ff221baSNicolas Pitre }
839ff221baSNicolas Pitre 
849ff221baSNicolas Pitre #endif
859ff221baSNicolas Pitre 
86a7eb7c6fSNicolas Pitre static struct smp_operations __initdata mcpm_smp_ops = {
879ff221baSNicolas Pitre 	.smp_boot_secondary	= mcpm_boot_secondary,
889ff221baSNicolas Pitre 	.smp_secondary_init	= mcpm_secondary_init,
899ff221baSNicolas Pitre #ifdef CONFIG_HOTPLUG_CPU
900de0d646SDave Martin 	.cpu_kill		= mcpm_cpu_kill,
91787047eeSStephen Boyd 	.cpu_can_disable	= mcpm_cpu_can_disable,
929ff221baSNicolas Pitre 	.cpu_die		= mcpm_cpu_die,
939ff221baSNicolas Pitre #endif
949ff221baSNicolas Pitre };
95a7eb7c6fSNicolas Pitre 
96a7eb7c6fSNicolas Pitre void __init mcpm_smp_set_ops(void)
97a7eb7c6fSNicolas Pitre {
98a7eb7c6fSNicolas Pitre 	smp_set_ops(&mcpm_smp_ops);
99a7eb7c6fSNicolas Pitre }
100