1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * arch/arm/mach-mediatek/platsmp.c
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (c) 2014 Mediatek Inc.
6*4882a593Smuzhiyun * Author: Shunli Wang <shunli.wang@mediatek.com>
7*4882a593Smuzhiyun * Yingjoe Chen <yingjoe.chen@mediatek.com>
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun #include <linux/io.h>
10*4882a593Smuzhiyun #include <linux/memblock.h>
11*4882a593Smuzhiyun #include <linux/of.h>
12*4882a593Smuzhiyun #include <linux/of_address.h>
13*4882a593Smuzhiyun #include <linux/string.h>
14*4882a593Smuzhiyun #include <linux/threads.h>
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun #define MTK_MAX_CPU 8
17*4882a593Smuzhiyun #define MTK_SMP_REG_SIZE 0x1000
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun struct mtk_smp_boot_info {
20*4882a593Smuzhiyun unsigned long smp_base;
21*4882a593Smuzhiyun unsigned int jump_reg;
22*4882a593Smuzhiyun unsigned int core_keys[MTK_MAX_CPU - 1];
23*4882a593Smuzhiyun unsigned int core_regs[MTK_MAX_CPU - 1];
24*4882a593Smuzhiyun };
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun static const struct mtk_smp_boot_info mtk_mt8135_tz_boot = {
27*4882a593Smuzhiyun 0x80002000, 0x3fc,
28*4882a593Smuzhiyun { 0x534c4131, 0x4c415332, 0x41534c33 },
29*4882a593Smuzhiyun { 0x3f8, 0x3f8, 0x3f8 },
30*4882a593Smuzhiyun };
31*4882a593Smuzhiyun
32*4882a593Smuzhiyun static const struct mtk_smp_boot_info mtk_mt6589_boot = {
33*4882a593Smuzhiyun 0x10002000, 0x34,
34*4882a593Smuzhiyun { 0x534c4131, 0x4c415332, 0x41534c33 },
35*4882a593Smuzhiyun { 0x38, 0x3c, 0x40 },
36*4882a593Smuzhiyun };
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun static const struct mtk_smp_boot_info mtk_mt7623_boot = {
39*4882a593Smuzhiyun 0x10202000, 0x34,
40*4882a593Smuzhiyun { 0x534c4131, 0x4c415332, 0x41534c33 },
41*4882a593Smuzhiyun { 0x38, 0x3c, 0x40 },
42*4882a593Smuzhiyun };
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun static const struct of_device_id mtk_tz_smp_boot_infos[] __initconst = {
45*4882a593Smuzhiyun { .compatible = "mediatek,mt8135", .data = &mtk_mt8135_tz_boot },
46*4882a593Smuzhiyun { .compatible = "mediatek,mt8127", .data = &mtk_mt8135_tz_boot },
47*4882a593Smuzhiyun { .compatible = "mediatek,mt2701", .data = &mtk_mt8135_tz_boot },
48*4882a593Smuzhiyun {},
49*4882a593Smuzhiyun };
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun static const struct of_device_id mtk_smp_boot_infos[] __initconst = {
52*4882a593Smuzhiyun { .compatible = "mediatek,mt6589", .data = &mtk_mt6589_boot },
53*4882a593Smuzhiyun { .compatible = "mediatek,mt7623", .data = &mtk_mt7623_boot },
54*4882a593Smuzhiyun { .compatible = "mediatek,mt7629", .data = &mtk_mt7623_boot },
55*4882a593Smuzhiyun {},
56*4882a593Smuzhiyun };
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun static void __iomem *mtk_smp_base;
59*4882a593Smuzhiyun static const struct mtk_smp_boot_info *mtk_smp_info;
60*4882a593Smuzhiyun
mtk_boot_secondary(unsigned int cpu,struct task_struct * idle)61*4882a593Smuzhiyun static int mtk_boot_secondary(unsigned int cpu, struct task_struct *idle)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun if (!mtk_smp_base)
64*4882a593Smuzhiyun return -EINVAL;
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun if (!mtk_smp_info->core_keys[cpu-1])
67*4882a593Smuzhiyun return -EINVAL;
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun writel_relaxed(mtk_smp_info->core_keys[cpu-1],
70*4882a593Smuzhiyun mtk_smp_base + mtk_smp_info->core_regs[cpu-1]);
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun arch_send_wakeup_ipi_mask(cpumask_of(cpu));
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun return 0;
75*4882a593Smuzhiyun }
76*4882a593Smuzhiyun
__mtk_smp_prepare_cpus(unsigned int max_cpus,int trustzone)77*4882a593Smuzhiyun static void __init __mtk_smp_prepare_cpus(unsigned int max_cpus, int trustzone)
78*4882a593Smuzhiyun {
79*4882a593Smuzhiyun int i, num;
80*4882a593Smuzhiyun const struct of_device_id *infos;
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun if (trustzone) {
83*4882a593Smuzhiyun num = ARRAY_SIZE(mtk_tz_smp_boot_infos);
84*4882a593Smuzhiyun infos = mtk_tz_smp_boot_infos;
85*4882a593Smuzhiyun } else {
86*4882a593Smuzhiyun num = ARRAY_SIZE(mtk_smp_boot_infos);
87*4882a593Smuzhiyun infos = mtk_smp_boot_infos;
88*4882a593Smuzhiyun }
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun /* Find smp boot info for this SoC */
91*4882a593Smuzhiyun for (i = 0; i < num; i++) {
92*4882a593Smuzhiyun if (of_machine_is_compatible(infos[i].compatible)) {
93*4882a593Smuzhiyun mtk_smp_info = infos[i].data;
94*4882a593Smuzhiyun break;
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun }
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun if (!mtk_smp_info) {
99*4882a593Smuzhiyun pr_err("%s: Device is not supported\n", __func__);
100*4882a593Smuzhiyun return;
101*4882a593Smuzhiyun }
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun if (trustzone) {
104*4882a593Smuzhiyun /* smp_base(trustzone-bootinfo) is reserved by device tree */
105*4882a593Smuzhiyun mtk_smp_base = phys_to_virt(mtk_smp_info->smp_base);
106*4882a593Smuzhiyun } else {
107*4882a593Smuzhiyun mtk_smp_base = ioremap(mtk_smp_info->smp_base, MTK_SMP_REG_SIZE);
108*4882a593Smuzhiyun if (!mtk_smp_base) {
109*4882a593Smuzhiyun pr_err("%s: Can't remap %lx\n", __func__,
110*4882a593Smuzhiyun mtk_smp_info->smp_base);
111*4882a593Smuzhiyun return;
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun }
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun /*
116*4882a593Smuzhiyun * write the address of slave startup address into the system-wide
117*4882a593Smuzhiyun * jump register
118*4882a593Smuzhiyun */
119*4882a593Smuzhiyun writel_relaxed(__pa_symbol(secondary_startup_arm),
120*4882a593Smuzhiyun mtk_smp_base + mtk_smp_info->jump_reg);
121*4882a593Smuzhiyun }
122*4882a593Smuzhiyun
mtk_tz_smp_prepare_cpus(unsigned int max_cpus)123*4882a593Smuzhiyun static void __init mtk_tz_smp_prepare_cpus(unsigned int max_cpus)
124*4882a593Smuzhiyun {
125*4882a593Smuzhiyun __mtk_smp_prepare_cpus(max_cpus, 1);
126*4882a593Smuzhiyun }
127*4882a593Smuzhiyun
mtk_smp_prepare_cpus(unsigned int max_cpus)128*4882a593Smuzhiyun static void __init mtk_smp_prepare_cpus(unsigned int max_cpus)
129*4882a593Smuzhiyun {
130*4882a593Smuzhiyun __mtk_smp_prepare_cpus(max_cpus, 0);
131*4882a593Smuzhiyun }
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun static const struct smp_operations mt81xx_tz_smp_ops __initconst = {
134*4882a593Smuzhiyun .smp_prepare_cpus = mtk_tz_smp_prepare_cpus,
135*4882a593Smuzhiyun .smp_boot_secondary = mtk_boot_secondary,
136*4882a593Smuzhiyun };
137*4882a593Smuzhiyun CPU_METHOD_OF_DECLARE(mt81xx_tz_smp, "mediatek,mt81xx-tz-smp", &mt81xx_tz_smp_ops);
138*4882a593Smuzhiyun
139*4882a593Smuzhiyun static const struct smp_operations mt6589_smp_ops __initconst = {
140*4882a593Smuzhiyun .smp_prepare_cpus = mtk_smp_prepare_cpus,
141*4882a593Smuzhiyun .smp_boot_secondary = mtk_boot_secondary,
142*4882a593Smuzhiyun };
143*4882a593Smuzhiyun CPU_METHOD_OF_DECLARE(mt6589_smp, "mediatek,mt6589-smp", &mt6589_smp_ops);
144