xref: /openbmc/linux/arch/arm/common/mcpm_platsmp.c (revision 1e566099)
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 
599ff221baSNicolas Pitre static int mcpm_cpu_disable(unsigned int cpu)
609ff221baSNicolas Pitre {
619ff221baSNicolas Pitre 	/*
629ff221baSNicolas Pitre 	 * We assume all CPUs may be shut down.
639ff221baSNicolas Pitre 	 * This would be the hook to use for eventual Secure
649ff221baSNicolas Pitre 	 * OS migration requests as described in the PSCI spec.
659ff221baSNicolas Pitre 	 */
669ff221baSNicolas Pitre 	return 0;
679ff221baSNicolas Pitre }
689ff221baSNicolas Pitre 
699ff221baSNicolas Pitre static void mcpm_cpu_die(unsigned int cpu)
709ff221baSNicolas Pitre {
719ff221baSNicolas Pitre 	unsigned int mpidr, pcpu, pcluster;
729ff221baSNicolas Pitre 	mpidr = read_cpuid_mpidr();
739ff221baSNicolas Pitre 	pcpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
749ff221baSNicolas Pitre 	pcluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
759ff221baSNicolas Pitre 	mcpm_set_entry_vector(pcpu, pcluster, NULL);
769ff221baSNicolas Pitre 	mcpm_cpu_power_down();
779ff221baSNicolas Pitre }
789ff221baSNicolas Pitre 
799ff221baSNicolas Pitre #endif
809ff221baSNicolas Pitre 
81a7eb7c6fSNicolas Pitre static struct smp_operations __initdata mcpm_smp_ops = {
829ff221baSNicolas Pitre 	.smp_boot_secondary	= mcpm_boot_secondary,
839ff221baSNicolas Pitre 	.smp_secondary_init	= mcpm_secondary_init,
849ff221baSNicolas Pitre #ifdef CONFIG_HOTPLUG_CPU
859ff221baSNicolas Pitre 	.cpu_disable		= mcpm_cpu_disable,
869ff221baSNicolas Pitre 	.cpu_die		= mcpm_cpu_die,
879ff221baSNicolas Pitre #endif
889ff221baSNicolas Pitre };
89a7eb7c6fSNicolas Pitre 
90a7eb7c6fSNicolas Pitre void __init mcpm_smp_set_ops(void)
91a7eb7c6fSNicolas Pitre {
92a7eb7c6fSNicolas Pitre 	smp_set_ops(&mcpm_smp_ops);
93a7eb7c6fSNicolas Pitre }
94