xref: /linux/arch/arm/mach-axxia/platsmp.c (revision 64fc2a947a9873700929ec0ef02b4654a04e0476)
11d22924eSAnders Berg /*
21d22924eSAnders Berg  * linux/arch/arm/mach-axxia/platsmp.c
31d22924eSAnders Berg  *
41d22924eSAnders Berg  * Copyright (C) 2012 LSI Corporation
51d22924eSAnders Berg  *
61d22924eSAnders Berg  * This program is free software; you can redistribute it and/or modify
71d22924eSAnders Berg  * it under the terms of the GNU General Public License version 2 as
81d22924eSAnders Berg  * published by the Free Software Foundation.
91d22924eSAnders Berg  */
101d22924eSAnders Berg 
111d22924eSAnders Berg #include <linux/init.h>
121d22924eSAnders Berg #include <linux/io.h>
131d22924eSAnders Berg #include <linux/smp.h>
141d22924eSAnders Berg #include <linux/of.h>
151d22924eSAnders Berg #include <linux/of_address.h>
161d22924eSAnders Berg #include <asm/cacheflush.h>
171d22924eSAnders Berg 
181d22924eSAnders Berg /* Syscon register offsets for releasing cores from reset */
191d22924eSAnders Berg #define SC_CRIT_WRITE_KEY	0x1000
201d22924eSAnders Berg #define SC_RST_CPU_HOLD		0x1010
211d22924eSAnders Berg 
221d22924eSAnders Berg /*
231d22924eSAnders Berg  * Write the kernel entry point for secondary CPUs to the specified address
241d22924eSAnders Berg  */
251d22924eSAnders Berg static void write_release_addr(u32 release_phys)
261d22924eSAnders Berg {
271d22924eSAnders Berg 	u32 *virt = (u32 *) phys_to_virt(release_phys);
28*64fc2a94SFlorian Fainelli 	writel_relaxed(__pa_symbol(secondary_startup), virt);
291d22924eSAnders Berg 	/* Make sure this store is visible to other CPUs */
301d22924eSAnders Berg 	smp_wmb();
311d22924eSAnders Berg 	__cpuc_flush_dcache_area(virt, sizeof(u32));
321d22924eSAnders Berg }
331d22924eSAnders Berg 
341d22924eSAnders Berg static int axxia_boot_secondary(unsigned int cpu, struct task_struct *idle)
351d22924eSAnders Berg {
361d22924eSAnders Berg 	struct device_node *syscon_np;
371d22924eSAnders Berg 	void __iomem *syscon;
381d22924eSAnders Berg 	u32 tmp;
391d22924eSAnders Berg 
401d22924eSAnders Berg 	syscon_np = of_find_compatible_node(NULL, NULL, "lsi,axxia-syscon");
411d22924eSAnders Berg 	if (!syscon_np)
421d22924eSAnders Berg 		return -ENOENT;
431d22924eSAnders Berg 
441d22924eSAnders Berg 	syscon = of_iomap(syscon_np, 0);
451d22924eSAnders Berg 	if (!syscon)
461d22924eSAnders Berg 		return -ENOMEM;
471d22924eSAnders Berg 
481d22924eSAnders Berg 	tmp = readl(syscon + SC_RST_CPU_HOLD);
491d22924eSAnders Berg 	writel(0xab, syscon + SC_CRIT_WRITE_KEY);
501d22924eSAnders Berg 	tmp &= ~(1 << cpu);
511d22924eSAnders Berg 	writel(tmp, syscon + SC_RST_CPU_HOLD);
521d22924eSAnders Berg 
531d22924eSAnders Berg 	return 0;
541d22924eSAnders Berg }
551d22924eSAnders Berg 
561d22924eSAnders Berg static void __init axxia_smp_prepare_cpus(unsigned int max_cpus)
571d22924eSAnders Berg {
581d22924eSAnders Berg 	int cpu_count = 0;
591d22924eSAnders Berg 	int cpu;
601d22924eSAnders Berg 
611d22924eSAnders Berg 	/*
621d22924eSAnders Berg 	 * Initialise the present map, which describes the set of CPUs actually
631d22924eSAnders Berg 	 * populated at the present time.
641d22924eSAnders Berg 	 */
651d22924eSAnders Berg 	for_each_possible_cpu(cpu) {
661d22924eSAnders Berg 		struct device_node *np;
671d22924eSAnders Berg 		u32 release_phys;
681d22924eSAnders Berg 
691d22924eSAnders Berg 		np = of_get_cpu_node(cpu, NULL);
701d22924eSAnders Berg 		if (!np)
711d22924eSAnders Berg 			continue;
721d22924eSAnders Berg 		if (of_property_read_u32(np, "cpu-release-addr", &release_phys))
731d22924eSAnders Berg 			continue;
741d22924eSAnders Berg 
751d22924eSAnders Berg 		if (cpu_count < max_cpus) {
761d22924eSAnders Berg 			set_cpu_present(cpu, true);
771d22924eSAnders Berg 			cpu_count++;
781d22924eSAnders Berg 		}
791d22924eSAnders Berg 
801d22924eSAnders Berg 		if (release_phys != 0)
811d22924eSAnders Berg 			write_release_addr(release_phys);
821d22924eSAnders Berg 	}
831d22924eSAnders Berg }
841d22924eSAnders Berg 
8575305275SMasahiro Yamada static const struct smp_operations axxia_smp_ops __initconst = {
861d22924eSAnders Berg 	.smp_prepare_cpus	= axxia_smp_prepare_cpus,
871d22924eSAnders Berg 	.smp_boot_secondary	= axxia_boot_secondary,
881d22924eSAnders Berg };
891d22924eSAnders Berg CPU_METHOD_OF_DECLARE(axxia_smp, "lsi,syscon-release", &axxia_smp_ops);
90