platsmp.c 3.7 KB

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