mt-smp.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /*
  2. * Copyright (c) 2015 MediaTek Inc.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/smp.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/jiffies.h>
  18. #include <linux/delay.h>
  19. #include <asm/fiq_glue.h>
  20. #include <mt-plat/sync_write.h>
  21. #include <mach/mt_spm_mtcmos.h>
  22. #include <mach/mt_secure_api.h>
  23. #include "mt-smp.h"
  24. #include "smp.h"
  25. #include "hotplug.h"
  26. #define SLAVE1_MAGIC_REG (SRAMROM_BASE+0x38)
  27. #define SLAVE2_MAGIC_REG (SRAMROM_BASE+0x38)
  28. #define SLAVE3_MAGIC_REG (SRAMROM_BASE+0x38)
  29. #define SLAVE4_MAGIC_REG (SRAMROM_BASE+0x3C)
  30. #define SLAVE5_MAGIC_REG (SRAMROM_BASE+0x3C)
  31. #define SLAVE6_MAGIC_REG (SRAMROM_BASE+0x3C)
  32. #define SLAVE7_MAGIC_REG (SRAMROM_BASE+0x3C)
  33. #define SLAVE1_MAGIC_NUM 0x534C4131
  34. #define SLAVE2_MAGIC_NUM 0x4C415332
  35. #define SLAVE3_MAGIC_NUM 0x41534C33
  36. #define SLAVE4_MAGIC_NUM 0x534C4134
  37. #define SLAVE5_MAGIC_NUM 0x4C415335
  38. #define SLAVE6_MAGIC_NUM 0x41534C36
  39. #define SLAVE7_MAGIC_NUM 0x534C4137
  40. #define SLAVE_JUMP_REG (SRAMROM_BASE+0x34)
  41. static DEFINE_SPINLOCK(boot_lock);
  42. /*
  43. * Write pen_release in a way that is guaranteed to be visible to all
  44. * observers, irrespective of whether they're taking part in coherency
  45. * or not. This is necessary for the hotplug code to work reliably.
  46. */
  47. static void __cpuinit write_pen_release(int val)
  48. {
  49. pen_release = val;
  50. /* Make sure this is visible to other CPUs */
  51. smp_wmb();
  52. /* sync_cache_w(&pen_release); */
  53. __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
  54. outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
  55. }
  56. void __cpuinit mt_smp_secondary_init(unsigned int cpu)
  57. {
  58. pr_debug("Slave cpu init\n");
  59. HOTPLUG_INFO("platform_secondary_init, cpu: %d\n", cpu);
  60. #ifndef CONFIG_MTK_GIC
  61. mt_gic_secondary_init();
  62. #endif
  63. /*
  64. * let the primary processor know we're out of the
  65. * pen, then head off into the C entry point
  66. */
  67. write_pen_release(-1);
  68. #if !defined(CONFIG_ARM_PSCI)
  69. fiq_glue_resume();
  70. #endif
  71. /*
  72. * Synchronise with the boot thread.
  73. */
  74. spin_lock(&boot_lock);
  75. spin_unlock(&boot_lock);
  76. }
  77. #define MT6735_INFRACFG_AO 0x10001000
  78. static void __init smp_set_boot_addr(void)
  79. {
  80. static void __iomem *infracfg_ao_base;
  81. infracfg_ao_base = ioremap(MT6735_INFRACFG_AO, 0x1000);
  82. if (!infracfg_ao_base)
  83. pr_err("%s: Unable to map I/O memory\n", __func__);
  84. /* Write the address of slave startup into boot address
  85. register for bootrom power down mode */
  86. writel_relaxed(virt_to_phys(mt_secondary_startup),
  87. infracfg_ao_base + 0x800);
  88. iounmap(infracfg_ao_base);
  89. }
  90. int __cpuinit mt_smp_boot_secondary(unsigned int cpu, struct task_struct *idle)
  91. {
  92. unsigned long timeout;
  93. atomic_inc(&hotplug_cpu_count);
  94. /*
  95. * Set synchronisation state between this boot processor
  96. * and the secondary one
  97. */
  98. spin_lock(&boot_lock);
  99. HOTPLUG_INFO("mt_smp_boot_secondary, cpu: %d\n", cpu);
  100. /*
  101. * The secondary processor is waiting to be released from
  102. * the holding pen - release it, then wait for it to flag
  103. * that it has been released by resetting pen_release.
  104. *
  105. * Note that "pen_release" is the hardware CPU ID, whereas
  106. * "cpu" is Linux's internal ID.
  107. */
  108. /*
  109. * This is really belt and braces; we hold unintended secondary
  110. * CPUs in the holding pen until we're ready for them. However,
  111. * since we haven't sent them a soft interrupt, they shouldn't
  112. * be there.
  113. */
  114. write_pen_release(cpu);
  115. switch (cpu) {
  116. case 1:
  117. #ifdef CONFIG_MTK_FPGA
  118. mt_reg_sync_writel(SLAVE1_MAGIC_NUM, SLAVE1_MAGIC_REG);
  119. HOTPLUG_INFO("SLAVE1_MAGIC_NUM:%x\n", SLAVE1_MAGIC_NUM);
  120. #endif
  121. spm_mtcmos_ctrl_cpu1(STA_POWER_ON, 1);
  122. break;
  123. case 2:
  124. #ifdef CONFIG_MTK_FPGA
  125. mt_reg_sync_writel(SLAVE2_MAGIC_NUM, SLAVE2_MAGIC_REG);
  126. HOTPLUG_INFO("SLAVE2_MAGIC_NUM:%x\n", SLAVE2_MAGIC_NUM);
  127. #endif
  128. spm_mtcmos_ctrl_cpu2(STA_POWER_ON, 1);
  129. break;
  130. case 3:
  131. #ifdef CONFIG_MTK_FPGA
  132. mt_reg_sync_writel(SLAVE3_MAGIC_NUM, SLAVE3_MAGIC_REG);
  133. HOTPLUG_INFO("SLAVE3_MAGIC_NUM:%x\n", SLAVE3_MAGIC_NUM);
  134. #endif
  135. spm_mtcmos_ctrl_cpu3(STA_POWER_ON, 1);
  136. break;
  137. #ifdef CONFIG_ARCH_MT6753
  138. case 4:
  139. #ifdef CONFIG_MTK_FPGA
  140. mt_reg_sync_writel(SLAVE4_MAGIC_NUM, SLAVE4_MAGIC_REG);
  141. HOTPLUG_INFO("SLAVE4_MAGIC_NUM:%x\n", SLAVE4_MAGIC_NUM);
  142. #endif
  143. spm_mtcmos_ctrl_cpu4(STA_POWER_ON, 1);
  144. break;
  145. case 5:
  146. if ((cpu_online(4) == 0) && (cpu_online(6) == 0) &&
  147. (cpu_online(7) == 0)) {
  148. HOTPLUG_INFO("up CPU%d fail, CPU4 first\n", cpu);
  149. spin_unlock(&boot_lock);
  150. atomic_dec(&hotplug_cpu_count);
  151. return -ENOSYS;
  152. }
  153. #ifdef CONFIG_MTK_FPGA
  154. mt_reg_sync_writel(SLAVE5_MAGIC_NUM, SLAVE5_MAGIC_REG);
  155. HOTPLUG_INFO("SLAVE5_MAGIC_NUM:%x\n", SLAVE5_MAGIC_NUM);
  156. #endif
  157. spm_mtcmos_ctrl_cpu5(STA_POWER_ON, 1);
  158. break;
  159. case 6:
  160. if ((cpu_online(4) == 0) && (cpu_online(5) == 0) &&
  161. (cpu_online(7) == 0)) {
  162. HOTPLUG_INFO("up CPU%d fail, CPU4 first\n", cpu);
  163. spin_unlock(&boot_lock);
  164. atomic_dec(&hotplug_cpu_count);
  165. return -ENOSYS;
  166. }
  167. #ifdef CONFIG_MTK_FPGA
  168. mt_reg_sync_writel(SLAVE6_MAGIC_NUM, SLAVE6_MAGIC_REG);
  169. HOTPLUG_INFO("SLAVE6_MAGIC_NUM:%x\n", SLAVE6_MAGIC_NUM);
  170. #endif
  171. spm_mtcmos_ctrl_cpu6(STA_POWER_ON, 1);
  172. break;
  173. case 7:
  174. if ((cpu_online(4) == 0) && (cpu_online(5) == 0) &&
  175. (cpu_online(6) == 0)) {
  176. HOTPLUG_INFO("up CPU%d fail, CPU4 first\n", cpu);
  177. spin_unlock(&boot_lock);
  178. atomic_dec(&hotplug_cpu_count);
  179. return -ENOSYS;
  180. }
  181. #ifdef CONFIG_MTK_FPGA
  182. mt_reg_sync_writel(SLAVE7_MAGIC_NUM, SLAVE7_MAGIC_REG);
  183. HOTPLUG_INFO("SLAVE7_MAGIC_NUM:%x\n", SLAVE7_MAGIC_NUM);
  184. #endif
  185. spm_mtcmos_ctrl_cpu7(STA_POWER_ON, 1);
  186. break;
  187. #endif /* CONFIG_ARCH_MT6753 */
  188. default:
  189. break;
  190. }
  191. /*
  192. * Now the secondary core is starting up let it run its
  193. * calibrations, then wait for it to finish
  194. */
  195. spin_unlock(&boot_lock);
  196. timeout = jiffies + (1 * HZ);
  197. while (time_before(jiffies, timeout)) {
  198. /* */
  199. smp_rmb();
  200. if (pen_release == -1)
  201. break;
  202. udelay(10);
  203. }
  204. if (pen_release != -1) {
  205. on_each_cpu((smp_call_func_t) dump_stack, NULL, 0);
  206. atomic_dec(&hotplug_cpu_count);
  207. return -ENOSYS;
  208. }
  209. return 0;
  210. }
  211. void __init mt_smp_init_cpus(void)
  212. {
  213. /* Enable CA7 snoop function */
  214. #if defined(CONFIG_ARM_PSCI) || defined(CONFIG_MTK_PSCI)
  215. mcusys_smc_write_phy(virt_to_phys((void *)MP0_AXI_CONFIG),
  216. readl((void *)MP0_AXI_CONFIG) & ~ACINACTM);
  217. #else
  218. mcusys_smc_write(MP0_AXI_CONFIG, readl(MP0_AXI_CONFIG) & ~ACINACTM);
  219. #endif
  220. /* Enable snoop requests and DVM message requests */
  221. REG_WRITE((void *)CCI400_SI4_SNOOP_CONTROL,
  222. readl((void *)CCI400_SI4_SNOOP_CONTROL) | (SNOOP_REQ |
  223. DVM_MSG_REQ));
  224. while (readl((void *)CCI400_STATUS) & CHANGE_PENDING)
  225. ;
  226. pr_emerg("@@@### num_possible_cpus(): %u ###@@@\n",
  227. num_possible_cpus());
  228. pr_emerg("@@@### num_present_cpus(): %u ###@@@\n", num_present_cpus());
  229. #ifndef CONFIG_MTK_GIC
  230. irq_total_secondary_cpus = num_possible_cpus() - 1;
  231. #endif
  232. }
  233. void __init mt_smp_prepare_cpus(unsigned int max_cpus)
  234. {
  235. #if !defined(CONFIG_ARM_PSCI)
  236. #ifdef CONFIG_MTK_FPGA
  237. /* write the address of slave startup into the system-wide
  238. flags register */
  239. mt_reg_sync_writel(virt_to_phys(mt_secondary_startup), SLAVE_JUMP_REG);
  240. #endif
  241. /* Set all cpus into AArch32 */
  242. mcusys_smc_write(MP0_MISC_CONFIG3,
  243. readl(MP0_MISC_CONFIG3) & 0xFFFF0FFF);
  244. mcusys_smc_write(MP1_MISC_CONFIG3,
  245. readl(MP1_MISC_CONFIG3) & 0xFFFF0FFF);
  246. /* enable bootrom power down mode */
  247. REG_WRITE(BOOTROM_SEC_CTRL, readl(BOOTROM_SEC_CTRL) | SW_ROM_PD);
  248. /* write the address of slave startup into boot address register
  249. for bootrom power down mode */
  250. mt_reg_sync_writel(virt_to_phys(mt_secondary_startup),
  251. BOOTROM_BOOT_ADDR);
  252. #endif
  253. /* set boot address */
  254. smp_set_boot_addr();
  255. /* initial spm_mtcmos memory map */
  256. spm_mtcmos_cpu_init();
  257. }
  258. struct smp_operations __initdata mt_smp_ops = {
  259. .smp_init_cpus = mt_smp_init_cpus,
  260. .smp_prepare_cpus = mt_smp_prepare_cpus,
  261. .smp_secondary_init = mt_smp_secondary_init,
  262. .smp_boot_secondary = mt_smp_boot_secondary,
  263. #ifdef CONFIG_HOTPLUG_CPU
  264. .cpu_kill = mt_cpu_kill,
  265. .cpu_die = mt_cpu_die,
  266. .cpu_disable = mt_cpu_disable,
  267. #endif
  268. };