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

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