10cda0700SYingjoe Chen /* 20cda0700SYingjoe Chen * arch/arm/mach-mediatek/platsmp.c 30cda0700SYingjoe Chen * 40cda0700SYingjoe Chen * Copyright (c) 2014 Mediatek Inc. 50cda0700SYingjoe Chen * Author: Shunli Wang <shunli.wang@mediatek.com> 60cda0700SYingjoe Chen * Yingjoe Chen <yingjoe.chen@mediatek.com> 70cda0700SYingjoe Chen * 80cda0700SYingjoe Chen * This program is free software; you can redistribute it and/or modify 90cda0700SYingjoe Chen * it under the terms of the GNU General Public License version 2 as 100cda0700SYingjoe Chen * published by the Free Software Foundation. 110cda0700SYingjoe Chen * 120cda0700SYingjoe Chen * This program is distributed in the hope that it will be useful, 130cda0700SYingjoe Chen * but WITHOUT ANY WARRANTY; without even the implied warranty of 140cda0700SYingjoe Chen * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 150cda0700SYingjoe Chen * GNU General Public License for more details. 160cda0700SYingjoe Chen * 170cda0700SYingjoe Chen */ 180cda0700SYingjoe Chen #include <linux/io.h> 190cda0700SYingjoe Chen #include <linux/memblock.h> 200cda0700SYingjoe Chen #include <linux/of.h> 210cda0700SYingjoe Chen #include <linux/of_address.h> 220cda0700SYingjoe Chen #include <linux/string.h> 230cda0700SYingjoe Chen #include <linux/threads.h> 240cda0700SYingjoe Chen 250cda0700SYingjoe Chen #define MTK_MAX_CPU 8 260cda0700SYingjoe Chen #define MTK_SMP_REG_SIZE 0x1000 270cda0700SYingjoe Chen 280cda0700SYingjoe Chen struct mtk_smp_boot_info { 290cda0700SYingjoe Chen unsigned long smp_base; 300cda0700SYingjoe Chen unsigned int jump_reg; 310cda0700SYingjoe Chen unsigned int core_keys[MTK_MAX_CPU - 1]; 320cda0700SYingjoe Chen unsigned int core_regs[MTK_MAX_CPU - 1]; 330cda0700SYingjoe Chen }; 340cda0700SYingjoe Chen 350cda0700SYingjoe Chen static const struct mtk_smp_boot_info mtk_mt8135_tz_boot = { 360cda0700SYingjoe Chen 0x80002000, 0x3fc, 370cda0700SYingjoe Chen { 0x534c4131, 0x4c415332, 0x41534c33 }, 380cda0700SYingjoe Chen { 0x3f8, 0x3f8, 0x3f8 }, 390cda0700SYingjoe Chen }; 400cda0700SYingjoe Chen 410cda0700SYingjoe Chen static const struct mtk_smp_boot_info mtk_mt6589_boot = { 420cda0700SYingjoe Chen 0x10002000, 0x34, 430cda0700SYingjoe Chen { 0x534c4131, 0x4c415332, 0x41534c33 }, 440cda0700SYingjoe Chen { 0x38, 0x3c, 0x40 }, 450cda0700SYingjoe Chen }; 460cda0700SYingjoe Chen 470cda0700SYingjoe Chen static const struct of_device_id mtk_tz_smp_boot_infos[] __initconst = { 480cda0700SYingjoe Chen { .compatible = "mediatek,mt8135", .data = &mtk_mt8135_tz_boot }, 490cda0700SYingjoe Chen { .compatible = "mediatek,mt8127", .data = &mtk_mt8135_tz_boot }, 500cda0700SYingjoe Chen }; 510cda0700SYingjoe Chen 520cda0700SYingjoe Chen static const struct of_device_id mtk_smp_boot_infos[] __initconst = { 530cda0700SYingjoe Chen { .compatible = "mediatek,mt6589", .data = &mtk_mt6589_boot }, 540cda0700SYingjoe Chen }; 550cda0700SYingjoe Chen 560cda0700SYingjoe Chen static void __iomem *mtk_smp_base; 570cda0700SYingjoe Chen static const struct mtk_smp_boot_info *mtk_smp_info; 580cda0700SYingjoe Chen 590cda0700SYingjoe Chen static int mtk_boot_secondary(unsigned int cpu, struct task_struct *idle) 600cda0700SYingjoe Chen { 610cda0700SYingjoe Chen if (!mtk_smp_base) 620cda0700SYingjoe Chen return -EINVAL; 630cda0700SYingjoe Chen 640cda0700SYingjoe Chen if (!mtk_smp_info->core_keys[cpu-1]) 650cda0700SYingjoe Chen return -EINVAL; 660cda0700SYingjoe Chen 670cda0700SYingjoe Chen writel_relaxed(mtk_smp_info->core_keys[cpu-1], 680cda0700SYingjoe Chen mtk_smp_base + mtk_smp_info->core_regs[cpu-1]); 690cda0700SYingjoe Chen 700cda0700SYingjoe Chen arch_send_wakeup_ipi_mask(cpumask_of(cpu)); 710cda0700SYingjoe Chen 720cda0700SYingjoe Chen return 0; 730cda0700SYingjoe Chen } 740cda0700SYingjoe Chen 750cda0700SYingjoe Chen static void __init __mtk_smp_prepare_cpus(unsigned int max_cpus, int trustzone) 760cda0700SYingjoe Chen { 770cda0700SYingjoe Chen int i, num; 780cda0700SYingjoe Chen const struct of_device_id *infos; 790cda0700SYingjoe Chen 800cda0700SYingjoe Chen if (trustzone) { 810cda0700SYingjoe Chen num = ARRAY_SIZE(mtk_tz_smp_boot_infos); 820cda0700SYingjoe Chen infos = mtk_tz_smp_boot_infos; 830cda0700SYingjoe Chen } else { 840cda0700SYingjoe Chen num = ARRAY_SIZE(mtk_smp_boot_infos); 850cda0700SYingjoe Chen infos = mtk_smp_boot_infos; 860cda0700SYingjoe Chen } 870cda0700SYingjoe Chen 880cda0700SYingjoe Chen /* Find smp boot info for this SoC */ 890cda0700SYingjoe Chen for (i = 0; i < num; i++) { 900cda0700SYingjoe Chen if (of_machine_is_compatible(infos[i].compatible)) { 910cda0700SYingjoe Chen mtk_smp_info = infos[i].data; 920cda0700SYingjoe Chen break; 930cda0700SYingjoe Chen } 940cda0700SYingjoe Chen } 950cda0700SYingjoe Chen 960cda0700SYingjoe Chen if (!mtk_smp_info) { 970cda0700SYingjoe Chen pr_err("%s: Device is not supported\n", __func__); 980cda0700SYingjoe Chen return; 990cda0700SYingjoe Chen } 1000cda0700SYingjoe Chen 1010cda0700SYingjoe Chen if (trustzone) { 1020cda0700SYingjoe Chen /* smp_base(trustzone-bootinfo) is reserved by device tree */ 1030cda0700SYingjoe Chen mtk_smp_base = phys_to_virt(mtk_smp_info->smp_base); 1040cda0700SYingjoe Chen } else { 1050cda0700SYingjoe Chen mtk_smp_base = ioremap(mtk_smp_info->smp_base, MTK_SMP_REG_SIZE); 1060cda0700SYingjoe Chen if (!mtk_smp_base) { 1070cda0700SYingjoe Chen pr_err("%s: Can't remap %lx\n", __func__, 1080cda0700SYingjoe Chen mtk_smp_info->smp_base); 1090cda0700SYingjoe Chen return; 1100cda0700SYingjoe Chen } 1110cda0700SYingjoe Chen } 1120cda0700SYingjoe Chen 1130cda0700SYingjoe Chen /* 1140cda0700SYingjoe Chen * write the address of slave startup address into the system-wide 1150cda0700SYingjoe Chen * jump register 1160cda0700SYingjoe Chen */ 1170cda0700SYingjoe Chen writel_relaxed(virt_to_phys(secondary_startup_arm), 1180cda0700SYingjoe Chen mtk_smp_base + mtk_smp_info->jump_reg); 1190cda0700SYingjoe Chen } 1200cda0700SYingjoe Chen 1210cda0700SYingjoe Chen static void __init mtk_tz_smp_prepare_cpus(unsigned int max_cpus) 1220cda0700SYingjoe Chen { 1230cda0700SYingjoe Chen __mtk_smp_prepare_cpus(max_cpus, 1); 1240cda0700SYingjoe Chen } 1250cda0700SYingjoe Chen 1260cda0700SYingjoe Chen static void __init mtk_smp_prepare_cpus(unsigned int max_cpus) 1270cda0700SYingjoe Chen { 1280cda0700SYingjoe Chen __mtk_smp_prepare_cpus(max_cpus, 0); 1290cda0700SYingjoe Chen } 1300cda0700SYingjoe Chen 13175305275SMasahiro Yamada static const struct smp_operations mt81xx_tz_smp_ops __initconst = { 1320cda0700SYingjoe Chen .smp_prepare_cpus = mtk_tz_smp_prepare_cpus, 1330cda0700SYingjoe Chen .smp_boot_secondary = mtk_boot_secondary, 1340cda0700SYingjoe Chen }; 1350cda0700SYingjoe Chen CPU_METHOD_OF_DECLARE(mt81xx_tz_smp, "mediatek,mt81xx-tz-smp", &mt81xx_tz_smp_ops); 1360cda0700SYingjoe Chen 13775305275SMasahiro Yamada static const struct smp_operations mt6589_smp_ops __initconst = { 1380cda0700SYingjoe Chen .smp_prepare_cpus = mtk_smp_prepare_cpus, 1390cda0700SYingjoe Chen .smp_boot_secondary = mtk_boot_secondary, 1400cda0700SYingjoe Chen }; 1410cda0700SYingjoe Chen CPU_METHOD_OF_DECLARE(mt6589_smp, "mediatek,mt6589-smp", &mt6589_smp_ops); 142