xref: /openbmc/linux/arch/arm/common/mcpm_platsmp.c (revision 9ff221ba)
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 <linux/irqchip/arm-gic.h>
199ff221baSNicolas Pitre 
209ff221baSNicolas Pitre #include <asm/mcpm.h>
219ff221baSNicolas Pitre #include <asm/smp.h>
229ff221baSNicolas Pitre #include <asm/smp_plat.h>
239ff221baSNicolas Pitre 
249ff221baSNicolas Pitre static void __init simple_smp_init_cpus(void)
259ff221baSNicolas Pitre {
269ff221baSNicolas Pitre }
279ff221baSNicolas Pitre 
289ff221baSNicolas Pitre static int __cpuinit mcpm_boot_secondary(unsigned int cpu, struct task_struct *idle)
299ff221baSNicolas Pitre {
309ff221baSNicolas Pitre 	unsigned int mpidr, pcpu, pcluster, ret;
319ff221baSNicolas Pitre 	extern void secondary_startup(void);
329ff221baSNicolas Pitre 
339ff221baSNicolas Pitre 	mpidr = cpu_logical_map(cpu);
349ff221baSNicolas Pitre 	pcpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
359ff221baSNicolas Pitre 	pcluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
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 
499ff221baSNicolas Pitre static void __cpuinit mcpm_secondary_init(unsigned int cpu)
509ff221baSNicolas Pitre {
519ff221baSNicolas Pitre 	mcpm_cpu_powered_up();
529ff221baSNicolas Pitre 	gic_secondary_init(0);
539ff221baSNicolas Pitre }
549ff221baSNicolas Pitre 
559ff221baSNicolas Pitre #ifdef CONFIG_HOTPLUG_CPU
569ff221baSNicolas Pitre 
579ff221baSNicolas Pitre static int mcpm_cpu_disable(unsigned int cpu)
589ff221baSNicolas Pitre {
599ff221baSNicolas Pitre 	/*
609ff221baSNicolas Pitre 	 * We assume all CPUs may be shut down.
619ff221baSNicolas Pitre 	 * This would be the hook to use for eventual Secure
629ff221baSNicolas Pitre 	 * OS migration requests as described in the PSCI spec.
639ff221baSNicolas Pitre 	 */
649ff221baSNicolas Pitre 	return 0;
659ff221baSNicolas Pitre }
669ff221baSNicolas Pitre 
679ff221baSNicolas Pitre static void mcpm_cpu_die(unsigned int cpu)
689ff221baSNicolas Pitre {
699ff221baSNicolas Pitre 	unsigned int mpidr, pcpu, pcluster;
709ff221baSNicolas Pitre 	mpidr = read_cpuid_mpidr();
719ff221baSNicolas Pitre 	pcpu = MPIDR_AFFINITY_LEVEL(mpidr, 0);
729ff221baSNicolas Pitre 	pcluster = MPIDR_AFFINITY_LEVEL(mpidr, 1);
739ff221baSNicolas Pitre 	mcpm_set_entry_vector(pcpu, pcluster, NULL);
749ff221baSNicolas Pitre 	mcpm_cpu_power_down();
759ff221baSNicolas Pitre }
769ff221baSNicolas Pitre 
779ff221baSNicolas Pitre #endif
789ff221baSNicolas Pitre 
799ff221baSNicolas Pitre struct smp_operations __initdata mcpm_smp_ops = {
809ff221baSNicolas Pitre 	.smp_init_cpus		= simple_smp_init_cpus,
819ff221baSNicolas Pitre 	.smp_boot_secondary	= mcpm_boot_secondary,
829ff221baSNicolas Pitre 	.smp_secondary_init	= mcpm_secondary_init,
839ff221baSNicolas Pitre #ifdef CONFIG_HOTPLUG_CPU
849ff221baSNicolas Pitre 	.cpu_disable		= mcpm_cpu_disable,
859ff221baSNicolas Pitre 	.cpu_die		= mcpm_cpu_die,
869ff221baSNicolas Pitre #endif
879ff221baSNicolas Pitre };
88