0042-ARM-mediatek-add-smp-bringup-code.patch 4.8 KB

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