1 From daa2c1f9202f08628d4f91a1cf4dafb44c9bcafe Mon Sep 17 00:00:00 2001
2 From: "Joe.C" <yingjoe.chen@mediatek.com>
3 Date: Fri, 1 May 2015 15:43:28 +0800
4 Subject: [PATCH 42/76] ARM: mediatek: add smp bringup code
6 Add support for booting secondary CPUs on mt6589, mt8127
9 Signed-off-by: Yingjoe Chen <yingjoe.chen@mediatek.com>
11 arch/arm/mach-mediatek/Makefile | 3 +
12 arch/arm/mach-mediatek/platsmp.c | 145 ++++++++++++++++++++++++++++++++++++++
13 2 files changed, 148 insertions(+)
14 create mode 100644 arch/arm/mach-mediatek/platsmp.c
16 --- a/arch/arm/mach-mediatek/Makefile
17 +++ b/arch/arm/mach-mediatek/Makefile
19 +ifeq ($(CONFIG_SMP),y)
20 +obj-$(CONFIG_ARCH_MEDIATEK) += platsmp.o
22 obj-$(CONFIG_ARCH_MEDIATEK) += mediatek.o
24 +++ b/arch/arm/mach-mediatek/platsmp.c
27 + * arch/arm/mach-mediatek/platsmp.c
29 + * Copyright (c) 2014 Mediatek Inc.
30 + * Author: Shunli Wang <shunli.wang@mediatek.com>
31 + * Yingjoe Chen <yingjoe.chen@mediatek.com>
33 + * This program is free software; you can redistribute it and/or modify
34 + * it under the terms of the GNU General Public License version 2 as
35 + * published by the Free Software Foundation.
37 + * This program is distributed in the hope that it will be useful,
38 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 + * GNU General Public License for more details.
43 +#include <linux/io.h>
44 +#include <linux/memblock.h>
45 +#include <linux/of.h>
46 +#include <linux/of_address.h>
47 +#include <linux/string.h>
48 +#include <linux/threads.h>
50 +#define MTK_MAX_CPU 8
51 +#define MTK_SMP_REG_SIZE 0x1000
53 +struct mtk_smp_boot_info {
54 + unsigned long smp_base;
55 + unsigned int jump_reg;
56 + unsigned int boot_reg;
57 + unsigned int core_keys[MTK_MAX_CPU - 1];
58 + unsigned int core_regs[MTK_MAX_CPU - 1];
61 +static const struct mtk_smp_boot_info mtk_mt8135_tz_boot = {
62 + 0x80002000, 1020, 1012,
63 + { 0x534c4131, 0x4c415332, 0x41534c33 },
64 + { 1016, 1016, 1016},
67 +static const struct mtk_smp_boot_info mtk_mt6589_boot = {
68 + 0x10002000, 0x34, 0x30,
69 + { 0x534c4131, 0x4c415332, 0x41534c33 },
70 + { 0x38, 0x3c, 0x40 },
73 +static const struct of_device_id mtk_tz_smp_boot_infos[] __initconst = {
74 + { .compatible = "mediatek,mt8135", .data = &mtk_mt8135_tz_boot },
75 + { .compatible = "mediatek,mt8127", .data = &mtk_mt8135_tz_boot },
78 +static const struct of_device_id mtk_smp_boot_infos[] __initconst = {
79 + { .compatible = "mediatek,mt6589", .data = &mtk_mt6589_boot },
82 +static void __iomem *mtk_smp_base;
83 +static const struct mtk_smp_boot_info *mtk_smp_info;
85 +static int mtk_boot_secondary(unsigned int cpu, struct task_struct *idle)
90 + if (!mtk_smp_info->core_keys[cpu-1])
93 + writel_relaxed(mtk_smp_info->core_keys[cpu-1],
94 + mtk_smp_base + mtk_smp_info->core_regs[cpu-1]);
96 + arch_send_wakeup_ipi_mask(cpumask_of(cpu));
101 +static void __init __mtk_smp_prepare_cpus(unsigned int max_cpus, int trustzone)
104 + const struct of_device_id *infos;
107 + num = ARRAY_SIZE(mtk_tz_smp_boot_infos);
108 + infos = mtk_tz_smp_boot_infos;
110 + num = ARRAY_SIZE(mtk_smp_boot_infos);
111 + infos = mtk_smp_boot_infos;
114 + /* Find smp boot info for this SoC */
115 + for (i = 0; i < num; i++) {
116 + if (of_machine_is_compatible(infos[i].compatible)) {
117 + mtk_smp_info = infos[i].data;
122 + if (!mtk_smp_info) {
123 + pr_err("%s: Device is not supported\n", __func__);
128 + if (memblock_reserve(mtk_smp_info->smp_base, MTK_SMP_REG_SIZE)) {
129 + pr_err("%s: Can't reserve smp memory\n", __func__);
132 + mtk_smp_base = phys_to_virt(mtk_smp_info->smp_base);
134 + mtk_smp_base = ioremap(mtk_smp_info->smp_base, MTK_SMP_REG_SIZE);
135 + if (!mtk_smp_base) {
136 + pr_err("%s: Can't remap %lx\n", __func__,
137 + mtk_smp_info->smp_base);
143 + * write the address of slave startup address into the system-wide
146 + writel_relaxed(virt_to_phys(secondary_startup),
147 + mtk_smp_base + mtk_smp_info->jump_reg);
150 +static void __init mtk_tz_smp_prepare_cpus(unsigned int max_cpus)
152 + __mtk_smp_prepare_cpus(max_cpus, 1);
155 +static void __init mtk_smp_prepare_cpus(unsigned int max_cpus)
157 + __mtk_smp_prepare_cpus(max_cpus, 0);
160 +static struct smp_operations mt81xx_tz_smp_ops __initdata = {
161 + .smp_prepare_cpus = mtk_tz_smp_prepare_cpus,
162 + .smp_boot_secondary = mtk_boot_secondary,
164 +CPU_METHOD_OF_DECLARE(mt81xx_tz_smp, "mediatek,mt81xx-tz-smp", &mt81xx_tz_smp_ops);
166 +static struct smp_operations mt65xx_smp_ops __initdata = {
167 + .smp_prepare_cpus = mtk_smp_prepare_cpus,
168 + .smp_boot_secondary = mtk_boot_secondary,
170 +CPU_METHOD_OF_DECLARE(mt65xx_smp, "mediatek,mt65xx-smp", &mt65xx_smp_ops);