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