1 // SPDX-License-Identifier: GPL-2.0-only
3 * arch/arm/mach-mediatek/platsmp.c
5 * Copyright (c) 2014 Mediatek Inc.
6 * Author: Shunli Wang <shunli.wang@mediatek.com>
7 * Yingjoe Chen <yingjoe.chen@mediatek.com>
10 #include <linux/memblock.h>
12 #include <linux/of_address.h>
13 #include <linux/string.h>
14 #include <linux/threads.h>
17 #define MTK_SMP_REG_SIZE 0x1000
19 struct mtk_smp_boot_info
{
20 unsigned long smp_base
;
21 unsigned int jump_reg
;
22 unsigned int core_keys
[MTK_MAX_CPU
- 1];
23 unsigned int core_regs
[MTK_MAX_CPU
- 1];
26 static const struct mtk_smp_boot_info mtk_mt8135_tz_boot
= {
28 { 0x534c4131, 0x4c415332, 0x41534c33 },
29 { 0x3f8, 0x3f8, 0x3f8 },
32 static const struct mtk_smp_boot_info mtk_mt6589_boot
= {
34 { 0x534c4131, 0x4c415332, 0x41534c33 },
38 static const struct mtk_smp_boot_info mtk_mt7623_boot
= {
40 { 0x534c4131, 0x4c415332, 0x41534c33 },
44 static const struct of_device_id mtk_tz_smp_boot_infos
[] __initconst
= {
45 { .compatible
= "mediatek,mt8135", .data
= &mtk_mt8135_tz_boot
},
46 { .compatible
= "mediatek,mt8127", .data
= &mtk_mt8135_tz_boot
},
47 { .compatible
= "mediatek,mt2701", .data
= &mtk_mt8135_tz_boot
},
51 static const struct of_device_id mtk_smp_boot_infos
[] __initconst
= {
52 { .compatible
= "mediatek,mt6589", .data
= &mtk_mt6589_boot
},
53 { .compatible
= "mediatek,mt7623", .data
= &mtk_mt7623_boot
},
54 { .compatible
= "mediatek,mt7629", .data
= &mtk_mt7623_boot
},
58 static void __iomem
*mtk_smp_base
;
59 static const struct mtk_smp_boot_info
*mtk_smp_info
;
61 static int mtk_boot_secondary(unsigned int cpu
, struct task_struct
*idle
)
66 if (!mtk_smp_info
->core_keys
[cpu
-1])
69 writel_relaxed(mtk_smp_info
->core_keys
[cpu
-1],
70 mtk_smp_base
+ mtk_smp_info
->core_regs
[cpu
-1]);
72 arch_send_wakeup_ipi_mask(cpumask_of(cpu
));
77 static void __init
__mtk_smp_prepare_cpus(unsigned int max_cpus
, int trustzone
)
80 const struct of_device_id
*infos
;
83 num
= ARRAY_SIZE(mtk_tz_smp_boot_infos
);
84 infos
= mtk_tz_smp_boot_infos
;
86 num
= ARRAY_SIZE(mtk_smp_boot_infos
);
87 infos
= mtk_smp_boot_infos
;
90 /* Find smp boot info for this SoC */
91 for (i
= 0; i
< num
; i
++) {
92 if (of_machine_is_compatible(infos
[i
].compatible
)) {
93 mtk_smp_info
= infos
[i
].data
;
99 pr_err("%s: Device is not supported\n", __func__
);
104 /* smp_base(trustzone-bootinfo) is reserved by device tree */
105 mtk_smp_base
= phys_to_virt(mtk_smp_info
->smp_base
);
107 mtk_smp_base
= ioremap(mtk_smp_info
->smp_base
, MTK_SMP_REG_SIZE
);
109 pr_err("%s: Can't remap %lx\n", __func__
,
110 mtk_smp_info
->smp_base
);
116 * write the address of slave startup address into the system-wide
119 writel_relaxed(__pa_symbol(secondary_startup_arm
),
120 mtk_smp_base
+ mtk_smp_info
->jump_reg
);
123 static void __init
mtk_tz_smp_prepare_cpus(unsigned int max_cpus
)
125 __mtk_smp_prepare_cpus(max_cpus
, 1);
128 static void __init
mtk_smp_prepare_cpus(unsigned int max_cpus
)
130 __mtk_smp_prepare_cpus(max_cpus
, 0);
133 static const struct smp_operations mt81xx_tz_smp_ops __initconst
= {
134 .smp_prepare_cpus
= mtk_tz_smp_prepare_cpus
,
135 .smp_boot_secondary
= mtk_boot_secondary
,
137 CPU_METHOD_OF_DECLARE(mt81xx_tz_smp
, "mediatek,mt81xx-tz-smp", &mt81xx_tz_smp_ops
);
139 static const struct smp_operations mt6589_smp_ops __initconst
= {
140 .smp_prepare_cpus
= mtk_smp_prepare_cpus
,
141 .smp_boot_secondary
= mtk_boot_secondary
,
143 CPU_METHOD_OF_DECLARE(mt6589_smp
, "mediatek,mt6589-smp", &mt6589_smp_ops
);