xref: /openbmc/linux/arch/arm/mach-mediatek/platsmp.c (revision 8b1cfd74)
10cda0700SYingjoe Chen /*
20cda0700SYingjoe Chen  * arch/arm/mach-mediatek/platsmp.c
30cda0700SYingjoe Chen  *
40cda0700SYingjoe Chen  * Copyright (c) 2014 Mediatek Inc.
50cda0700SYingjoe Chen  * Author: Shunli Wang <shunli.wang@mediatek.com>
60cda0700SYingjoe Chen  *         Yingjoe Chen <yingjoe.chen@mediatek.com>
70cda0700SYingjoe Chen  *
80cda0700SYingjoe Chen  * This program is free software; you can redistribute it and/or modify
90cda0700SYingjoe Chen  * it under the terms of the GNU General Public License version 2 as
100cda0700SYingjoe Chen  * published by the Free Software Foundation.
110cda0700SYingjoe Chen  *
120cda0700SYingjoe Chen  * This program is distributed in the hope that it will be useful,
130cda0700SYingjoe Chen  * but WITHOUT ANY WARRANTY; without even the implied warranty of
140cda0700SYingjoe Chen  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
150cda0700SYingjoe Chen  * GNU General Public License for more details.
160cda0700SYingjoe Chen  *
170cda0700SYingjoe Chen  */
180cda0700SYingjoe Chen #include <linux/io.h>
190cda0700SYingjoe Chen #include <linux/memblock.h>
200cda0700SYingjoe Chen #include <linux/of.h>
210cda0700SYingjoe Chen #include <linux/of_address.h>
220cda0700SYingjoe Chen #include <linux/string.h>
230cda0700SYingjoe Chen #include <linux/threads.h>
240cda0700SYingjoe Chen 
250cda0700SYingjoe Chen #define MTK_MAX_CPU		8
260cda0700SYingjoe Chen #define MTK_SMP_REG_SIZE	0x1000
270cda0700SYingjoe Chen 
280cda0700SYingjoe Chen struct mtk_smp_boot_info {
290cda0700SYingjoe Chen 	unsigned long smp_base;
300cda0700SYingjoe Chen 	unsigned int jump_reg;
310cda0700SYingjoe Chen 	unsigned int core_keys[MTK_MAX_CPU - 1];
320cda0700SYingjoe Chen 	unsigned int core_regs[MTK_MAX_CPU - 1];
330cda0700SYingjoe Chen };
340cda0700SYingjoe Chen 
350cda0700SYingjoe Chen static const struct mtk_smp_boot_info mtk_mt8135_tz_boot = {
360cda0700SYingjoe Chen 	0x80002000, 0x3fc,
370cda0700SYingjoe Chen 	{ 0x534c4131, 0x4c415332, 0x41534c33 },
380cda0700SYingjoe Chen 	{ 0x3f8, 0x3f8, 0x3f8 },
390cda0700SYingjoe Chen };
400cda0700SYingjoe Chen 
410cda0700SYingjoe Chen static const struct mtk_smp_boot_info mtk_mt6589_boot = {
420cda0700SYingjoe Chen 	0x10002000, 0x34,
430cda0700SYingjoe Chen 	{ 0x534c4131, 0x4c415332, 0x41534c33 },
440cda0700SYingjoe Chen 	{ 0x38, 0x3c, 0x40 },
450cda0700SYingjoe Chen };
460cda0700SYingjoe Chen 
47fd63892fSJohn Crispin static const struct mtk_smp_boot_info mtk_mt7623_boot = {
48fd63892fSJohn Crispin 	0x10202000, 0x34,
49fd63892fSJohn Crispin 	{ 0x534c4131, 0x4c415332, 0x41534c33 },
50fd63892fSJohn Crispin 	{ 0x38, 0x3c, 0x40 },
51fd63892fSJohn Crispin };
52fd63892fSJohn Crispin 
530cda0700SYingjoe Chen static const struct of_device_id mtk_tz_smp_boot_infos[] __initconst = {
540cda0700SYingjoe Chen 	{ .compatible   = "mediatek,mt8135", .data = &mtk_mt8135_tz_boot },
550cda0700SYingjoe Chen 	{ .compatible   = "mediatek,mt8127", .data = &mtk_mt8135_tz_boot },
565b0fb1eaSLouis Yu 	{ .compatible   = "mediatek,mt2701", .data = &mtk_mt8135_tz_boot },
578b1cfd74SThomas Meyer 	{},
580cda0700SYingjoe Chen };
590cda0700SYingjoe Chen 
600cda0700SYingjoe Chen static const struct of_device_id mtk_smp_boot_infos[] __initconst = {
610cda0700SYingjoe Chen 	{ .compatible   = "mediatek,mt6589", .data = &mtk_mt6589_boot },
62fd63892fSJohn Crispin 	{ .compatible   = "mediatek,mt7623", .data = &mtk_mt7623_boot },
633b99ab7dSSean Wang 	{ .compatible   = "mediatek,mt7623a", .data = &mtk_mt7623_boot },
648b1cfd74SThomas Meyer 	{},
650cda0700SYingjoe Chen };
660cda0700SYingjoe Chen 
670cda0700SYingjoe Chen static void __iomem *mtk_smp_base;
680cda0700SYingjoe Chen static const struct mtk_smp_boot_info *mtk_smp_info;
690cda0700SYingjoe Chen 
700cda0700SYingjoe Chen static int mtk_boot_secondary(unsigned int cpu, struct task_struct *idle)
710cda0700SYingjoe Chen {
720cda0700SYingjoe Chen 	if (!mtk_smp_base)
730cda0700SYingjoe Chen 		return -EINVAL;
740cda0700SYingjoe Chen 
750cda0700SYingjoe Chen 	if (!mtk_smp_info->core_keys[cpu-1])
760cda0700SYingjoe Chen 		return -EINVAL;
770cda0700SYingjoe Chen 
780cda0700SYingjoe Chen 	writel_relaxed(mtk_smp_info->core_keys[cpu-1],
790cda0700SYingjoe Chen 		mtk_smp_base + mtk_smp_info->core_regs[cpu-1]);
800cda0700SYingjoe Chen 
810cda0700SYingjoe Chen 	arch_send_wakeup_ipi_mask(cpumask_of(cpu));
820cda0700SYingjoe Chen 
830cda0700SYingjoe Chen 	return 0;
840cda0700SYingjoe Chen }
850cda0700SYingjoe Chen 
860cda0700SYingjoe Chen static void __init __mtk_smp_prepare_cpus(unsigned int max_cpus, int trustzone)
870cda0700SYingjoe Chen {
880cda0700SYingjoe Chen 	int i, num;
890cda0700SYingjoe Chen 	const struct of_device_id *infos;
900cda0700SYingjoe Chen 
910cda0700SYingjoe Chen 	if (trustzone) {
920cda0700SYingjoe Chen 		num = ARRAY_SIZE(mtk_tz_smp_boot_infos);
930cda0700SYingjoe Chen 		infos = mtk_tz_smp_boot_infos;
940cda0700SYingjoe Chen 	} else {
950cda0700SYingjoe Chen 		num = ARRAY_SIZE(mtk_smp_boot_infos);
960cda0700SYingjoe Chen 		infos = mtk_smp_boot_infos;
970cda0700SYingjoe Chen 	}
980cda0700SYingjoe Chen 
990cda0700SYingjoe Chen 	/* Find smp boot info for this SoC */
1000cda0700SYingjoe Chen 	for (i = 0; i < num; i++) {
1010cda0700SYingjoe Chen 		if (of_machine_is_compatible(infos[i].compatible)) {
1020cda0700SYingjoe Chen 			mtk_smp_info = infos[i].data;
1030cda0700SYingjoe Chen 			break;
1040cda0700SYingjoe Chen 		}
1050cda0700SYingjoe Chen 	}
1060cda0700SYingjoe Chen 
1070cda0700SYingjoe Chen 	if (!mtk_smp_info) {
1080cda0700SYingjoe Chen 		pr_err("%s: Device is not supported\n", __func__);
1090cda0700SYingjoe Chen 		return;
1100cda0700SYingjoe Chen 	}
1110cda0700SYingjoe Chen 
1120cda0700SYingjoe Chen 	if (trustzone) {
1130cda0700SYingjoe Chen 		/* smp_base(trustzone-bootinfo) is reserved by device tree */
1140cda0700SYingjoe Chen 		mtk_smp_base = phys_to_virt(mtk_smp_info->smp_base);
1150cda0700SYingjoe Chen 	} else {
1160cda0700SYingjoe Chen 		mtk_smp_base = ioremap(mtk_smp_info->smp_base, MTK_SMP_REG_SIZE);
1170cda0700SYingjoe Chen 		if (!mtk_smp_base) {
1180cda0700SYingjoe Chen 			pr_err("%s: Can't remap %lx\n", __func__,
1190cda0700SYingjoe Chen 				mtk_smp_info->smp_base);
1200cda0700SYingjoe Chen 			return;
1210cda0700SYingjoe Chen 		}
1220cda0700SYingjoe Chen 	}
1230cda0700SYingjoe Chen 
1240cda0700SYingjoe Chen 	/*
1250cda0700SYingjoe Chen 	 * write the address of slave startup address into the system-wide
1260cda0700SYingjoe Chen 	 * jump register
1270cda0700SYingjoe Chen 	 */
12864fc2a94SFlorian Fainelli 	writel_relaxed(__pa_symbol(secondary_startup_arm),
1290cda0700SYingjoe Chen 			mtk_smp_base + mtk_smp_info->jump_reg);
1300cda0700SYingjoe Chen }
1310cda0700SYingjoe Chen 
1320cda0700SYingjoe Chen static void __init mtk_tz_smp_prepare_cpus(unsigned int max_cpus)
1330cda0700SYingjoe Chen {
1340cda0700SYingjoe Chen 	__mtk_smp_prepare_cpus(max_cpus, 1);
1350cda0700SYingjoe Chen }
1360cda0700SYingjoe Chen 
1370cda0700SYingjoe Chen static void __init mtk_smp_prepare_cpus(unsigned int max_cpus)
1380cda0700SYingjoe Chen {
1390cda0700SYingjoe Chen 	__mtk_smp_prepare_cpus(max_cpus, 0);
1400cda0700SYingjoe Chen }
1410cda0700SYingjoe Chen 
14275305275SMasahiro Yamada static const struct smp_operations mt81xx_tz_smp_ops __initconst = {
1430cda0700SYingjoe Chen 	.smp_prepare_cpus = mtk_tz_smp_prepare_cpus,
1440cda0700SYingjoe Chen 	.smp_boot_secondary = mtk_boot_secondary,
1450cda0700SYingjoe Chen };
1460cda0700SYingjoe Chen CPU_METHOD_OF_DECLARE(mt81xx_tz_smp, "mediatek,mt81xx-tz-smp", &mt81xx_tz_smp_ops);
1470cda0700SYingjoe Chen 
14875305275SMasahiro Yamada static const struct smp_operations mt6589_smp_ops __initconst = {
1490cda0700SYingjoe Chen 	.smp_prepare_cpus = mtk_smp_prepare_cpus,
1500cda0700SYingjoe Chen 	.smp_boot_secondary = mtk_boot_secondary,
1510cda0700SYingjoe Chen };
1520cda0700SYingjoe Chen CPU_METHOD_OF_DECLARE(mt6589_smp, "mediatek,mt6589-smp", &mt6589_smp_ops);
153