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