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 47fd63892fSJohn Crispin static const struct mtk_smp_boot_info mtk_mt7623_boot = { 48fd63892fSJohn Crispin 0x10202000, 0x34, 49fd63892fSJohn Crispin { 0x534c4131, 0x4c415332, 0x41534c33 }, 50fd63892fSJohn Crispin { 0x38, 0x3c, 0x40 }, 51fd63892fSJohn Crispin }; 52fd63892fSJohn Crispin 530cda0700SYingjoe Chen static const struct of_device_id mtk_tz_smp_boot_infos[] __initconst = { 540cda0700SYingjoe Chen { .compatible = "mediatek,mt8135", .data = &mtk_mt8135_tz_boot }, 550cda0700SYingjoe Chen { .compatible = "mediatek,mt8127", .data = &mtk_mt8135_tz_boot }, 565b0fb1eaSLouis Yu { .compatible = "mediatek,mt2701", .data = &mtk_mt8135_tz_boot }, 570cda0700SYingjoe Chen }; 580cda0700SYingjoe Chen 590cda0700SYingjoe Chen static const struct of_device_id mtk_smp_boot_infos[] __initconst = { 600cda0700SYingjoe Chen { .compatible = "mediatek,mt6589", .data = &mtk_mt6589_boot }, 61fd63892fSJohn Crispin { .compatible = "mediatek,mt7623", .data = &mtk_mt7623_boot }, 620cda0700SYingjoe Chen }; 630cda0700SYingjoe Chen 640cda0700SYingjoe Chen static void __iomem *mtk_smp_base; 650cda0700SYingjoe Chen static const struct mtk_smp_boot_info *mtk_smp_info; 660cda0700SYingjoe Chen 670cda0700SYingjoe Chen static int mtk_boot_secondary(unsigned int cpu, struct task_struct *idle) 680cda0700SYingjoe Chen { 690cda0700SYingjoe Chen if (!mtk_smp_base) 700cda0700SYingjoe Chen return -EINVAL; 710cda0700SYingjoe Chen 720cda0700SYingjoe Chen if (!mtk_smp_info->core_keys[cpu-1]) 730cda0700SYingjoe Chen return -EINVAL; 740cda0700SYingjoe Chen 750cda0700SYingjoe Chen writel_relaxed(mtk_smp_info->core_keys[cpu-1], 760cda0700SYingjoe Chen mtk_smp_base + mtk_smp_info->core_regs[cpu-1]); 770cda0700SYingjoe Chen 780cda0700SYingjoe Chen arch_send_wakeup_ipi_mask(cpumask_of(cpu)); 790cda0700SYingjoe Chen 800cda0700SYingjoe Chen return 0; 810cda0700SYingjoe Chen } 820cda0700SYingjoe Chen 830cda0700SYingjoe Chen static void __init __mtk_smp_prepare_cpus(unsigned int max_cpus, int trustzone) 840cda0700SYingjoe Chen { 850cda0700SYingjoe Chen int i, num; 860cda0700SYingjoe Chen const struct of_device_id *infos; 870cda0700SYingjoe Chen 880cda0700SYingjoe Chen if (trustzone) { 890cda0700SYingjoe Chen num = ARRAY_SIZE(mtk_tz_smp_boot_infos); 900cda0700SYingjoe Chen infos = mtk_tz_smp_boot_infos; 910cda0700SYingjoe Chen } else { 920cda0700SYingjoe Chen num = ARRAY_SIZE(mtk_smp_boot_infos); 930cda0700SYingjoe Chen infos = mtk_smp_boot_infos; 940cda0700SYingjoe Chen } 950cda0700SYingjoe Chen 960cda0700SYingjoe Chen /* Find smp boot info for this SoC */ 970cda0700SYingjoe Chen for (i = 0; i < num; i++) { 980cda0700SYingjoe Chen if (of_machine_is_compatible(infos[i].compatible)) { 990cda0700SYingjoe Chen mtk_smp_info = infos[i].data; 1000cda0700SYingjoe Chen break; 1010cda0700SYingjoe Chen } 1020cda0700SYingjoe Chen } 1030cda0700SYingjoe Chen 1040cda0700SYingjoe Chen if (!mtk_smp_info) { 1050cda0700SYingjoe Chen pr_err("%s: Device is not supported\n", __func__); 1060cda0700SYingjoe Chen return; 1070cda0700SYingjoe Chen } 1080cda0700SYingjoe Chen 1090cda0700SYingjoe Chen if (trustzone) { 1100cda0700SYingjoe Chen /* smp_base(trustzone-bootinfo) is reserved by device tree */ 1110cda0700SYingjoe Chen mtk_smp_base = phys_to_virt(mtk_smp_info->smp_base); 1120cda0700SYingjoe Chen } else { 1130cda0700SYingjoe Chen mtk_smp_base = ioremap(mtk_smp_info->smp_base, MTK_SMP_REG_SIZE); 1140cda0700SYingjoe Chen if (!mtk_smp_base) { 1150cda0700SYingjoe Chen pr_err("%s: Can't remap %lx\n", __func__, 1160cda0700SYingjoe Chen mtk_smp_info->smp_base); 1170cda0700SYingjoe Chen return; 1180cda0700SYingjoe Chen } 1190cda0700SYingjoe Chen } 1200cda0700SYingjoe Chen 1210cda0700SYingjoe Chen /* 1220cda0700SYingjoe Chen * write the address of slave startup address into the system-wide 1230cda0700SYingjoe Chen * jump register 1240cda0700SYingjoe Chen */ 1250cda0700SYingjoe Chen writel_relaxed(virt_to_phys(secondary_startup_arm), 1260cda0700SYingjoe Chen mtk_smp_base + mtk_smp_info->jump_reg); 1270cda0700SYingjoe Chen } 1280cda0700SYingjoe Chen 1290cda0700SYingjoe Chen static void __init mtk_tz_smp_prepare_cpus(unsigned int max_cpus) 1300cda0700SYingjoe Chen { 1310cda0700SYingjoe Chen __mtk_smp_prepare_cpus(max_cpus, 1); 1320cda0700SYingjoe Chen } 1330cda0700SYingjoe Chen 1340cda0700SYingjoe Chen static void __init mtk_smp_prepare_cpus(unsigned int max_cpus) 1350cda0700SYingjoe Chen { 1360cda0700SYingjoe Chen __mtk_smp_prepare_cpus(max_cpus, 0); 1370cda0700SYingjoe Chen } 1380cda0700SYingjoe Chen 13975305275SMasahiro Yamada static const struct smp_operations mt81xx_tz_smp_ops __initconst = { 1400cda0700SYingjoe Chen .smp_prepare_cpus = mtk_tz_smp_prepare_cpus, 1410cda0700SYingjoe Chen .smp_boot_secondary = mtk_boot_secondary, 1420cda0700SYingjoe Chen }; 1430cda0700SYingjoe Chen CPU_METHOD_OF_DECLARE(mt81xx_tz_smp, "mediatek,mt81xx-tz-smp", &mt81xx_tz_smp_ops); 1440cda0700SYingjoe Chen 14575305275SMasahiro Yamada static const struct smp_operations mt6589_smp_ops __initconst = { 1460cda0700SYingjoe Chen .smp_prepare_cpus = mtk_smp_prepare_cpus, 1470cda0700SYingjoe Chen .smp_boot_secondary = mtk_boot_secondary, 1480cda0700SYingjoe Chen }; 1490cda0700SYingjoe Chen CPU_METHOD_OF_DECLARE(mt6589_smp, "mediatek,mt6589-smp", &mt6589_smp_ops); 150