xref: /openbmc/linux/arch/arm/common/mcpm_platsmp.c (revision d2912cb1)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
29ff221baSNicolas Pitre /*
39ff221baSNicolas Pitre  * linux/arch/arm/mach-vexpress/mcpm_platsmp.c
49ff221baSNicolas Pitre  *
59ff221baSNicolas Pitre  * Created by:  Nicolas Pitre, November 2012
69ff221baSNicolas Pitre  * Copyright:   (C) 2012-2013  Linaro Limited
79ff221baSNicolas Pitre  *
89ff221baSNicolas Pitre  * Code to handle secondary CPU bringup and hotplug for the cluster power API.
99ff221baSNicolas Pitre  */
109ff221baSNicolas Pitre 
119ff221baSNicolas Pitre #include <linux/init.h>
129ff221baSNicolas Pitre #include <linux/smp.h>
139ff221baSNicolas Pitre #include <linux/spinlock.h>
149ff221baSNicolas Pitre 
159ff221baSNicolas Pitre #include <asm/mcpm.h>
169ff221baSNicolas Pitre #include <asm/smp.h>
179ff221baSNicolas Pitre #include <asm/smp_plat.h>
189ff221baSNicolas Pitre 
cpu_to_pcpu(unsigned int cpu,unsigned int * pcpu,unsigned int * pcluster)191e566099SDave Martin static void cpu_to_pcpu(unsigned int cpu,
201e566099SDave Martin 			unsigned int *pcpu, unsigned int *pcluster)
219ff221baSNicolas Pitre {
221e566099SDave Martin 	unsigned int mpidr;
239ff221baSNicolas Pitre 
249ff221baSNicolas Pitre 	mpidr = cpu_logical_map(cpu);
251e566099SDave Martin 	*pcpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
261e566099SDave Martin 	*pcluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
271e566099SDave Martin }
281e566099SDave Martin 
mcpm_boot_secondary(unsigned int cpu,struct task_struct * idle)291e566099SDave Martin static int mcpm_boot_secondary(unsigned int cpu, struct task_struct *idle)
301e566099SDave Martin {
311e566099SDave Martin 	unsigned int pcpu, pcluster, ret;
321e566099SDave Martin 	extern void secondary_startup(void);
331e566099SDave Martin 
341e566099SDave Martin 	cpu_to_pcpu(cpu, &pcpu, &pcluster);
351e566099SDave Martin 
369ff221baSNicolas Pitre 	pr_debug("%s: logical CPU %d is physical CPU %d cluster %d\n",
379ff221baSNicolas Pitre 		 __func__, cpu, pcpu, pcluster);
389ff221baSNicolas Pitre 
399ff221baSNicolas Pitre 	mcpm_set_entry_vector(pcpu, pcluster, NULL);
409ff221baSNicolas Pitre 	ret = mcpm_cpu_power_up(pcpu, pcluster);
419ff221baSNicolas Pitre 	if (ret)
429ff221baSNicolas Pitre 		return ret;
439ff221baSNicolas Pitre 	mcpm_set_entry_vector(pcpu, pcluster, secondary_startup);
449ff221baSNicolas Pitre 	arch_send_wakeup_ipi_mask(cpumask_of(cpu));
459ff221baSNicolas Pitre 	dsb_sev();
469ff221baSNicolas Pitre 	return 0;
479ff221baSNicolas Pitre }
489ff221baSNicolas Pitre 
mcpm_secondary_init(unsigned int cpu)498bd26e3aSPaul Gortmaker static void mcpm_secondary_init(unsigned int cpu)
509ff221baSNicolas Pitre {
519ff221baSNicolas Pitre 	mcpm_cpu_powered_up();
529ff221baSNicolas Pitre }
539ff221baSNicolas Pitre 
549ff221baSNicolas Pitre #ifdef CONFIG_HOTPLUG_CPU
559ff221baSNicolas Pitre 
mcpm_cpu_kill(unsigned int cpu)560de0d646SDave Martin static int mcpm_cpu_kill(unsigned int cpu)
570de0d646SDave Martin {
580de0d646SDave Martin 	unsigned int pcpu, pcluster;
590de0d646SDave Martin 
600de0d646SDave Martin 	cpu_to_pcpu(cpu, &pcpu, &pcluster);
610de0d646SDave Martin 
62166aaf39SDave Martin 	return !mcpm_wait_for_cpu_powerdown(pcpu, pcluster);
630de0d646SDave Martin }
640de0d646SDave Martin 
mcpm_cpu_can_disable(unsigned int cpu)65787047eeSStephen Boyd static bool mcpm_cpu_can_disable(unsigned int cpu)
669ff221baSNicolas Pitre {
67787047eeSStephen Boyd 	/* We assume all CPUs may be shut down. */
68787047eeSStephen Boyd 	return true;
699ff221baSNicolas Pitre }
709ff221baSNicolas Pitre 
mcpm_cpu_die(unsigned int cpu)719ff221baSNicolas Pitre static void mcpm_cpu_die(unsigned int cpu)
729ff221baSNicolas Pitre {
739ff221baSNicolas Pitre 	unsigned int mpidr, pcpu, pcluster;
749ff221baSNicolas Pitre 	mpidr = read_cpuid_mpidr();
759ff221baSNicolas Pitre 	pcpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
769ff221baSNicolas Pitre 	pcluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
779ff221baSNicolas Pitre 	mcpm_set_entry_vector(pcpu, pcluster, NULL);
789ff221baSNicolas Pitre 	mcpm_cpu_power_down();
799ff221baSNicolas Pitre }
809ff221baSNicolas Pitre 
819ff221baSNicolas Pitre #endif
829ff221baSNicolas Pitre 
8375305275SMasahiro Yamada static const struct smp_operations mcpm_smp_ops __initconst = {
849ff221baSNicolas Pitre 	.smp_boot_secondary	= mcpm_boot_secondary,
859ff221baSNicolas Pitre 	.smp_secondary_init	= mcpm_secondary_init,
869ff221baSNicolas Pitre #ifdef CONFIG_HOTPLUG_CPU
870de0d646SDave Martin 	.cpu_kill		= mcpm_cpu_kill,
88787047eeSStephen Boyd 	.cpu_can_disable	= mcpm_cpu_can_disable,
899ff221baSNicolas Pitre 	.cpu_die		= mcpm_cpu_die,
909ff221baSNicolas Pitre #endif
919ff221baSNicolas Pitre };
92a7eb7c6fSNicolas Pitre 
mcpm_smp_set_ops(void)93a7eb7c6fSNicolas Pitre void __init mcpm_smp_set_ops(void)
94a7eb7c6fSNicolas Pitre {
95a7eb7c6fSNicolas Pitre 	smp_set_ops(&mcpm_smp_ops);
96a7eb7c6fSNicolas Pitre }
97