xref: /openbmc/linux/arch/arm/common/mcpm_platsmp.c (revision 8bd26e3a)
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 
228bd26e3aSPaul Gortmaker static int mcpm_boot_secondary(unsigned int cpu, struct task_struct *idle)
239ff221baSNicolas Pitre {
249ff221baSNicolas Pitre 	unsigned int mpidr, pcpu, pcluster, ret;
259ff221baSNicolas Pitre 	extern void secondary_startup(void);
269ff221baSNicolas Pitre 
279ff221baSNicolas Pitre 	mpidr = cpu_logical_map(cpu);
289ff221baSNicolas Pitre 	pcpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
299ff221baSNicolas Pitre 	pcluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
309ff221baSNicolas Pitre 	pr_debug("%s: logical CPU %d is physical CPU %d cluster %d\n",
319ff221baSNicolas Pitre 		 __func__, cpu, pcpu, pcluster);
329ff221baSNicolas Pitre 
339ff221baSNicolas Pitre 	mcpm_set_entry_vector(pcpu, pcluster, NULL);
349ff221baSNicolas Pitre 	ret = mcpm_cpu_power_up(pcpu, pcluster);
359ff221baSNicolas Pitre 	if (ret)
369ff221baSNicolas Pitre 		return ret;
379ff221baSNicolas Pitre 	mcpm_set_entry_vector(pcpu, pcluster, secondary_startup);
389ff221baSNicolas Pitre 	arch_send_wakeup_ipi_mask(cpumask_of(cpu));
399ff221baSNicolas Pitre 	dsb_sev();
409ff221baSNicolas Pitre 	return 0;
419ff221baSNicolas Pitre }
429ff221baSNicolas Pitre 
438bd26e3aSPaul Gortmaker static void mcpm_secondary_init(unsigned int cpu)
449ff221baSNicolas Pitre {
459ff221baSNicolas Pitre 	mcpm_cpu_powered_up();
469ff221baSNicolas Pitre }
479ff221baSNicolas Pitre 
489ff221baSNicolas Pitre #ifdef CONFIG_HOTPLUG_CPU
499ff221baSNicolas Pitre 
509ff221baSNicolas Pitre static int mcpm_cpu_disable(unsigned int cpu)
519ff221baSNicolas Pitre {
529ff221baSNicolas Pitre 	/*
539ff221baSNicolas Pitre 	 * We assume all CPUs may be shut down.
549ff221baSNicolas Pitre 	 * This would be the hook to use for eventual Secure
559ff221baSNicolas Pitre 	 * OS migration requests as described in the PSCI spec.
569ff221baSNicolas Pitre 	 */
579ff221baSNicolas Pitre 	return 0;
589ff221baSNicolas Pitre }
599ff221baSNicolas Pitre 
609ff221baSNicolas Pitre static void mcpm_cpu_die(unsigned int cpu)
619ff221baSNicolas Pitre {
629ff221baSNicolas Pitre 	unsigned int mpidr, pcpu, pcluster;
639ff221baSNicolas Pitre 	mpidr = read_cpuid_mpidr();
649ff221baSNicolas Pitre 	pcpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
659ff221baSNicolas Pitre 	pcluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
669ff221baSNicolas Pitre 	mcpm_set_entry_vector(pcpu, pcluster, NULL);
679ff221baSNicolas Pitre 	mcpm_cpu_power_down();
689ff221baSNicolas Pitre }
699ff221baSNicolas Pitre 
709ff221baSNicolas Pitre #endif
719ff221baSNicolas Pitre 
72a7eb7c6fSNicolas Pitre static struct smp_operations __initdata mcpm_smp_ops = {
739ff221baSNicolas Pitre 	.smp_boot_secondary	= mcpm_boot_secondary,
749ff221baSNicolas Pitre 	.smp_secondary_init	= mcpm_secondary_init,
759ff221baSNicolas Pitre #ifdef CONFIG_HOTPLUG_CPU
769ff221baSNicolas Pitre 	.cpu_disable		= mcpm_cpu_disable,
779ff221baSNicolas Pitre 	.cpu_die		= mcpm_cpu_die,
789ff221baSNicolas Pitre #endif
799ff221baSNicolas Pitre };
80a7eb7c6fSNicolas Pitre 
81a7eb7c6fSNicolas Pitre void __init mcpm_smp_set_ops(void)
82a7eb7c6fSNicolas Pitre {
83a7eb7c6fSNicolas Pitre 	smp_set_ops(&mcpm_smp_ops);
84a7eb7c6fSNicolas Pitre }
85