2 * arch/arm/mach-mediatek/platsmp.c
4 * Copyright (c) 2014 Mediatek Inc.
5 * Author: Shunli Wang <shunli.wang@mediatek.com>
6 * Yingjoe Chen <yingjoe.chen@mediatek.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
19 #include <linux/memblock.h>
21 #include <linux/of_address.h>
22 #include <linux/string.h>
23 #include <linux/threads.h>
26 #define MTK_SMP_REG_SIZE 0x1000
28 struct mtk_smp_boot_info
{
29 unsigned long smp_base
;
30 unsigned int jump_reg
;
31 unsigned int core_keys
[MTK_MAX_CPU
- 1];
32 unsigned int core_regs
[MTK_MAX_CPU
- 1];
35 static const struct mtk_smp_boot_info mtk_mt8135_tz_boot
= {
37 { 0x534c4131, 0x4c415332, 0x41534c33 },
38 { 0x3f8, 0x3f8, 0x3f8 },
41 static const struct mtk_smp_boot_info mtk_mt6589_boot
= {
43 { 0x534c4131, 0x4c415332, 0x41534c33 },
47 static const struct mtk_smp_boot_info mtk_mt7623_boot
= {
49 { 0x534c4131, 0x4c415332, 0x41534c33 },
53 static const struct of_device_id mtk_tz_smp_boot_infos
[] __initconst
= {
54 { .compatible
= "mediatek,mt8135", .data
= &mtk_mt8135_tz_boot
},
55 { .compatible
= "mediatek,mt8127", .data
= &mtk_mt8135_tz_boot
},
56 { .compatible
= "mediatek,mt2701", .data
= &mtk_mt8135_tz_boot
},
59 static const struct of_device_id mtk_smp_boot_infos
[] __initconst
= {
60 { .compatible
= "mediatek,mt6589", .data
= &mtk_mt6589_boot
},
61 { .compatible
= "mediatek,mt7623", .data
= &mtk_mt7623_boot
},
64 static void __iomem
*mtk_smp_base
;
65 static const struct mtk_smp_boot_info
*mtk_smp_info
;
67 static int mtk_boot_secondary(unsigned int cpu
, struct task_struct
*idle
)
72 if (!mtk_smp_info
->core_keys
[cpu
-1])
75 writel_relaxed(mtk_smp_info
->core_keys
[cpu
-1],
76 mtk_smp_base
+ mtk_smp_info
->core_regs
[cpu
-1]);
78 arch_send_wakeup_ipi_mask(cpumask_of(cpu
));
83 static void __init
__mtk_smp_prepare_cpus(unsigned int max_cpus
, int trustzone
)
86 const struct of_device_id
*infos
;
89 num
= ARRAY_SIZE(mtk_tz_smp_boot_infos
);
90 infos
= mtk_tz_smp_boot_infos
;
92 num
= ARRAY_SIZE(mtk_smp_boot_infos
);
93 infos
= mtk_smp_boot_infos
;
96 /* Find smp boot info for this SoC */
97 for (i
= 0; i
< num
; i
++) {
98 if (of_machine_is_compatible(infos
[i
].compatible
)) {
99 mtk_smp_info
= infos
[i
].data
;
105 pr_err("%s: Device is not supported\n", __func__
);
110 /* smp_base(trustzone-bootinfo) is reserved by device tree */
111 mtk_smp_base
= phys_to_virt(mtk_smp_info
->smp_base
);
113 mtk_smp_base
= ioremap(mtk_smp_info
->smp_base
, MTK_SMP_REG_SIZE
);
115 pr_err("%s: Can't remap %lx\n", __func__
,
116 mtk_smp_info
->smp_base
);
122 * write the address of slave startup address into the system-wide
125 writel_relaxed(virt_to_phys(secondary_startup_arm
),
126 mtk_smp_base
+ mtk_smp_info
->jump_reg
);
129 static void __init
mtk_tz_smp_prepare_cpus(unsigned int max_cpus
)
131 __mtk_smp_prepare_cpus(max_cpus
, 1);
134 static void __init
mtk_smp_prepare_cpus(unsigned int max_cpus
)
136 __mtk_smp_prepare_cpus(max_cpus
, 0);
139 static const struct smp_operations mt81xx_tz_smp_ops __initconst
= {
140 .smp_prepare_cpus
= mtk_tz_smp_prepare_cpus
,
141 .smp_boot_secondary
= mtk_boot_secondary
,
143 CPU_METHOD_OF_DECLARE(mt81xx_tz_smp
, "mediatek,mt81xx-tz-smp", &mt81xx_tz_smp_ops
);
145 static const struct smp_operations mt6589_smp_ops __initconst
= {
146 .smp_prepare_cpus
= mtk_smp_prepare_cpus
,
147 .smp_boot_secondary
= mtk_boot_secondary
,
149 CPU_METHOD_OF_DECLARE(mt6589_smp
, "mediatek,mt6589-smp", &mt6589_smp_ops
);