xref: /openbmc/linux/arch/arm/mach-mediatek/platsmp.c (revision 1802d0be)
11802d0beSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
20cda0700SYingjoe Chen /*
30cda0700SYingjoe Chen  * arch/arm/mach-mediatek/platsmp.c
40cda0700SYingjoe Chen  *
50cda0700SYingjoe Chen  * Copyright (c) 2014 Mediatek Inc.
60cda0700SYingjoe Chen  * Author: Shunli Wang <shunli.wang@mediatek.com>
70cda0700SYingjoe Chen  *         Yingjoe Chen <yingjoe.chen@mediatek.com>
80cda0700SYingjoe Chen  */
90cda0700SYingjoe Chen #include <linux/io.h>
100cda0700SYingjoe Chen #include <linux/memblock.h>
110cda0700SYingjoe Chen #include <linux/of.h>
120cda0700SYingjoe Chen #include <linux/of_address.h>
130cda0700SYingjoe Chen #include <linux/string.h>
140cda0700SYingjoe Chen #include <linux/threads.h>
150cda0700SYingjoe Chen 
160cda0700SYingjoe Chen #define MTK_MAX_CPU		8
170cda0700SYingjoe Chen #define MTK_SMP_REG_SIZE	0x1000
180cda0700SYingjoe Chen 
190cda0700SYingjoe Chen struct mtk_smp_boot_info {
200cda0700SYingjoe Chen 	unsigned long smp_base;
210cda0700SYingjoe Chen 	unsigned int jump_reg;
220cda0700SYingjoe Chen 	unsigned int core_keys[MTK_MAX_CPU - 1];
230cda0700SYingjoe Chen 	unsigned int core_regs[MTK_MAX_CPU - 1];
240cda0700SYingjoe Chen };
250cda0700SYingjoe Chen 
260cda0700SYingjoe Chen static const struct mtk_smp_boot_info mtk_mt8135_tz_boot = {
270cda0700SYingjoe Chen 	0x80002000, 0x3fc,
280cda0700SYingjoe Chen 	{ 0x534c4131, 0x4c415332, 0x41534c33 },
290cda0700SYingjoe Chen 	{ 0x3f8, 0x3f8, 0x3f8 },
300cda0700SYingjoe Chen };
310cda0700SYingjoe Chen 
320cda0700SYingjoe Chen static const struct mtk_smp_boot_info mtk_mt6589_boot = {
330cda0700SYingjoe Chen 	0x10002000, 0x34,
340cda0700SYingjoe Chen 	{ 0x534c4131, 0x4c415332, 0x41534c33 },
350cda0700SYingjoe Chen 	{ 0x38, 0x3c, 0x40 },
360cda0700SYingjoe Chen };
370cda0700SYingjoe Chen 
38fd63892fSJohn Crispin static const struct mtk_smp_boot_info mtk_mt7623_boot = {
39fd63892fSJohn Crispin 	0x10202000, 0x34,
40fd63892fSJohn Crispin 	{ 0x534c4131, 0x4c415332, 0x41534c33 },
41fd63892fSJohn Crispin 	{ 0x38, 0x3c, 0x40 },
42fd63892fSJohn Crispin };
43fd63892fSJohn Crispin 
440cda0700SYingjoe Chen static const struct of_device_id mtk_tz_smp_boot_infos[] __initconst = {
450cda0700SYingjoe Chen 	{ .compatible   = "mediatek,mt8135", .data = &mtk_mt8135_tz_boot },
460cda0700SYingjoe Chen 	{ .compatible   = "mediatek,mt8127", .data = &mtk_mt8135_tz_boot },
475b0fb1eaSLouis Yu 	{ .compatible   = "mediatek,mt2701", .data = &mtk_mt8135_tz_boot },
488b1cfd74SThomas Meyer 	{},
490cda0700SYingjoe Chen };
500cda0700SYingjoe Chen 
510cda0700SYingjoe Chen static const struct of_device_id mtk_smp_boot_infos[] __initconst = {
520cda0700SYingjoe Chen 	{ .compatible   = "mediatek,mt6589", .data = &mtk_mt6589_boot },
53fd63892fSJohn Crispin 	{ .compatible   = "mediatek,mt7623", .data = &mtk_mt7623_boot },
54a43379ddSRyder Lee 	{ .compatible   = "mediatek,mt7629", .data = &mtk_mt7623_boot },
558b1cfd74SThomas Meyer 	{},
560cda0700SYingjoe Chen };
570cda0700SYingjoe Chen 
580cda0700SYingjoe Chen static void __iomem *mtk_smp_base;
590cda0700SYingjoe Chen static const struct mtk_smp_boot_info *mtk_smp_info;
600cda0700SYingjoe Chen 
mtk_boot_secondary(unsigned int cpu,struct task_struct * idle)610cda0700SYingjoe Chen static int mtk_boot_secondary(unsigned int cpu, struct task_struct *idle)
620cda0700SYingjoe Chen {
630cda0700SYingjoe Chen 	if (!mtk_smp_base)
640cda0700SYingjoe Chen 		return -EINVAL;
650cda0700SYingjoe Chen 
660cda0700SYingjoe Chen 	if (!mtk_smp_info->core_keys[cpu-1])
670cda0700SYingjoe Chen 		return -EINVAL;
680cda0700SYingjoe Chen 
690cda0700SYingjoe Chen 	writel_relaxed(mtk_smp_info->core_keys[cpu-1],
700cda0700SYingjoe Chen 		mtk_smp_base + mtk_smp_info->core_regs[cpu-1]);
710cda0700SYingjoe Chen 
720cda0700SYingjoe Chen 	arch_send_wakeup_ipi_mask(cpumask_of(cpu));
730cda0700SYingjoe Chen 
740cda0700SYingjoe Chen 	return 0;
750cda0700SYingjoe Chen }
760cda0700SYingjoe Chen 
__mtk_smp_prepare_cpus(unsigned int max_cpus,int trustzone)770cda0700SYingjoe Chen static void __init __mtk_smp_prepare_cpus(unsigned int max_cpus, int trustzone)
780cda0700SYingjoe Chen {
790cda0700SYingjoe Chen 	int i, num;
800cda0700SYingjoe Chen 	const struct of_device_id *infos;
810cda0700SYingjoe Chen 
820cda0700SYingjoe Chen 	if (trustzone) {
830cda0700SYingjoe Chen 		num = ARRAY_SIZE(mtk_tz_smp_boot_infos);
840cda0700SYingjoe Chen 		infos = mtk_tz_smp_boot_infos;
850cda0700SYingjoe Chen 	} else {
860cda0700SYingjoe Chen 		num = ARRAY_SIZE(mtk_smp_boot_infos);
870cda0700SYingjoe Chen 		infos = mtk_smp_boot_infos;
880cda0700SYingjoe Chen 	}
890cda0700SYingjoe Chen 
900cda0700SYingjoe Chen 	/* Find smp boot info for this SoC */
910cda0700SYingjoe Chen 	for (i = 0; i < num; i++) {
920cda0700SYingjoe Chen 		if (of_machine_is_compatible(infos[i].compatible)) {
930cda0700SYingjoe Chen 			mtk_smp_info = infos[i].data;
940cda0700SYingjoe Chen 			break;
950cda0700SYingjoe Chen 		}
960cda0700SYingjoe Chen 	}
970cda0700SYingjoe Chen 
980cda0700SYingjoe Chen 	if (!mtk_smp_info) {
990cda0700SYingjoe Chen 		pr_err("%s: Device is not supported\n", __func__);
1000cda0700SYingjoe Chen 		return;
1010cda0700SYingjoe Chen 	}
1020cda0700SYingjoe Chen 
1030cda0700SYingjoe Chen 	if (trustzone) {
1040cda0700SYingjoe Chen 		/* smp_base(trustzone-bootinfo) is reserved by device tree */
1050cda0700SYingjoe Chen 		mtk_smp_base = phys_to_virt(mtk_smp_info->smp_base);
1060cda0700SYingjoe Chen 	} else {
1070cda0700SYingjoe Chen 		mtk_smp_base = ioremap(mtk_smp_info->smp_base, MTK_SMP_REG_SIZE);
1080cda0700SYingjoe Chen 		if (!mtk_smp_base) {
1090cda0700SYingjoe Chen 			pr_err("%s: Can't remap %lx\n", __func__,
1100cda0700SYingjoe Chen 				mtk_smp_info->smp_base);
1110cda0700SYingjoe Chen 			return;
1120cda0700SYingjoe Chen 		}
1130cda0700SYingjoe Chen 	}
1140cda0700SYingjoe Chen 
1150cda0700SYingjoe Chen 	/*
1160cda0700SYingjoe Chen 	 * write the address of slave startup address into the system-wide
1170cda0700SYingjoe Chen 	 * jump register
1180cda0700SYingjoe Chen 	 */
11964fc2a94SFlorian Fainelli 	writel_relaxed(__pa_symbol(secondary_startup_arm),
1200cda0700SYingjoe Chen 			mtk_smp_base + mtk_smp_info->jump_reg);
1210cda0700SYingjoe Chen }
1220cda0700SYingjoe Chen 
mtk_tz_smp_prepare_cpus(unsigned int max_cpus)1230cda0700SYingjoe Chen static void __init mtk_tz_smp_prepare_cpus(unsigned int max_cpus)
1240cda0700SYingjoe Chen {
1250cda0700SYingjoe Chen 	__mtk_smp_prepare_cpus(max_cpus, 1);
1260cda0700SYingjoe Chen }
1270cda0700SYingjoe Chen 
mtk_smp_prepare_cpus(unsigned int max_cpus)1280cda0700SYingjoe Chen static void __init mtk_smp_prepare_cpus(unsigned int max_cpus)
1290cda0700SYingjoe Chen {
1300cda0700SYingjoe Chen 	__mtk_smp_prepare_cpus(max_cpus, 0);
1310cda0700SYingjoe Chen }
1320cda0700SYingjoe Chen 
13375305275SMasahiro Yamada static const struct smp_operations mt81xx_tz_smp_ops __initconst = {
1340cda0700SYingjoe Chen 	.smp_prepare_cpus = mtk_tz_smp_prepare_cpus,
1350cda0700SYingjoe Chen 	.smp_boot_secondary = mtk_boot_secondary,
1360cda0700SYingjoe Chen };
1370cda0700SYingjoe Chen CPU_METHOD_OF_DECLARE(mt81xx_tz_smp, "mediatek,mt81xx-tz-smp", &mt81xx_tz_smp_ops);
1380cda0700SYingjoe Chen 
13975305275SMasahiro Yamada static const struct smp_operations mt6589_smp_ops __initconst = {
1400cda0700SYingjoe Chen 	.smp_prepare_cpus = mtk_smp_prepare_cpus,
1410cda0700SYingjoe Chen 	.smp_boot_secondary = mtk_boot_secondary,
1420cda0700SYingjoe Chen };
1430cda0700SYingjoe Chen CPU_METHOD_OF_DECLARE(mt6589_smp, "mediatek,mt6589-smp", &mt6589_smp_ops);
144