platsmp.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Symmetric Multi Processing (SMP) support for Armada XP
  4. *
  5. * Copyright (C) 2012 Marvell
  6. *
  7. * Lior Amsalem <[email protected]>
  8. * Yehuda Yitschak <[email protected]>
  9. * Gregory CLEMENT <[email protected]>
  10. * Thomas Petazzoni <[email protected]>
  11. *
  12. * The Armada XP SoC has 4 ARMv7 PJ4B CPUs running in full HW coherency
  13. * This file implements the routines for preparing the SMP infrastructure
  14. * and waking up the secondary CPUs
  15. */
  16. #include <linux/init.h>
  17. #include <linux/smp.h>
  18. #include <linux/clk.h>
  19. #include <linux/of.h>
  20. #include <linux/of_address.h>
  21. #include <linux/mbus.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/smp_plat.h>
  24. #include "common.h"
  25. #include "armada-370-xp.h"
  26. #include "pmsu.h"
  27. #include "coherency.h"
  28. #define ARMADA_XP_MAX_CPUS 4
  29. #define AXP_BOOTROM_BASE 0xfff00000
  30. #define AXP_BOOTROM_SIZE 0x100000
  31. static struct clk *boot_cpu_clk;
  32. static struct clk *get_cpu_clk(int cpu)
  33. {
  34. struct clk *cpu_clk;
  35. struct device_node *np = of_get_cpu_node(cpu, NULL);
  36. if (WARN(!np, "missing cpu node\n"))
  37. return NULL;
  38. cpu_clk = of_clk_get(np, 0);
  39. if (WARN_ON(IS_ERR(cpu_clk)))
  40. return NULL;
  41. return cpu_clk;
  42. }
  43. static int armada_xp_boot_secondary(unsigned int cpu, struct task_struct *idle)
  44. {
  45. int ret, hw_cpu;
  46. pr_info("Booting CPU %d\n", cpu);
  47. hw_cpu = cpu_logical_map(cpu);
  48. mvebu_pmsu_set_cpu_boot_addr(hw_cpu, armada_xp_secondary_startup);
  49. /*
  50. * This is needed to wake up CPUs in the offline state after
  51. * using CPU hotplug.
  52. */
  53. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  54. /*
  55. * This is needed to take secondary CPUs out of reset on the
  56. * initial boot.
  57. */
  58. ret = mvebu_cpu_reset_deassert(hw_cpu);
  59. if (ret) {
  60. pr_warn("unable to boot CPU: %d\n", ret);
  61. return ret;
  62. }
  63. return 0;
  64. }
  65. /*
  66. * When a CPU is brought back online, either through CPU hotplug, or
  67. * because of the boot of a kexec'ed kernel, the PMSU configuration
  68. * for this CPU might be in the deep idle state, preventing this CPU
  69. * from receiving interrupts. Here, we therefore take out the current
  70. * CPU from this state, which was entered by armada_xp_cpu_die()
  71. * below.
  72. */
  73. static void armada_xp_secondary_init(unsigned int cpu)
  74. {
  75. mvebu_v7_pmsu_idle_exit();
  76. }
  77. static void __init armada_xp_smp_init_cpus(void)
  78. {
  79. unsigned int ncores = num_possible_cpus();
  80. if (ncores == 0 || ncores > ARMADA_XP_MAX_CPUS)
  81. panic("Invalid number of CPUs in DT\n");
  82. }
  83. static int armada_xp_sync_secondary_clk(unsigned int cpu)
  84. {
  85. struct clk *cpu_clk = get_cpu_clk(cpu);
  86. if (!cpu_clk || !boot_cpu_clk)
  87. return 0;
  88. clk_prepare_enable(cpu_clk);
  89. clk_set_rate(cpu_clk, clk_get_rate(boot_cpu_clk));
  90. return 0;
  91. }
  92. static void __init armada_xp_smp_prepare_cpus(unsigned int max_cpus)
  93. {
  94. struct device_node *node;
  95. struct resource res;
  96. int err;
  97. flush_cache_all();
  98. set_cpu_coherent();
  99. boot_cpu_clk = get_cpu_clk(smp_processor_id());
  100. if (boot_cpu_clk) {
  101. clk_prepare_enable(boot_cpu_clk);
  102. cpuhp_setup_state_nocalls(CPUHP_AP_ARM_MVEBU_SYNC_CLOCKS,
  103. "arm/mvebu/sync_clocks:online",
  104. armada_xp_sync_secondary_clk, NULL);
  105. }
  106. /*
  107. * In order to boot the secondary CPUs we need to ensure
  108. * the bootROM is mapped at the correct address.
  109. */
  110. node = of_find_compatible_node(NULL, NULL, "marvell,bootrom");
  111. if (!node)
  112. panic("Cannot find 'marvell,bootrom' compatible node");
  113. err = of_address_to_resource(node, 0, &res);
  114. of_node_put(node);
  115. if (err < 0)
  116. panic("Cannot get 'bootrom' node address");
  117. if (res.start != AXP_BOOTROM_BASE ||
  118. resource_size(&res) != AXP_BOOTROM_SIZE)
  119. panic("The address for the BootROM is incorrect");
  120. }
  121. #ifdef CONFIG_HOTPLUG_CPU
  122. static void armada_xp_cpu_die(unsigned int cpu)
  123. {
  124. /*
  125. * CPU hotplug is implemented by putting offline CPUs into the
  126. * deep idle sleep state.
  127. */
  128. armada_370_xp_pmsu_idle_enter(true);
  129. }
  130. /*
  131. * We need a dummy function, so that platform_can_cpu_hotplug() knows
  132. * we support CPU hotplug. However, the function does not need to do
  133. * anything, because CPUs going offline can enter the deep idle state
  134. * by themselves, without any help from a still alive CPU.
  135. */
  136. static int armada_xp_cpu_kill(unsigned int cpu)
  137. {
  138. return 1;
  139. }
  140. #endif
  141. const struct smp_operations armada_xp_smp_ops __initconst = {
  142. .smp_init_cpus = armada_xp_smp_init_cpus,
  143. .smp_prepare_cpus = armada_xp_smp_prepare_cpus,
  144. .smp_boot_secondary = armada_xp_boot_secondary,
  145. .smp_secondary_init = armada_xp_secondary_init,
  146. #ifdef CONFIG_HOTPLUG_CPU
  147. .cpu_die = armada_xp_cpu_die,
  148. .cpu_kill = armada_xp_cpu_kill,
  149. #endif
  150. };
  151. CPU_METHOD_OF_DECLARE(armada_xp_smp, "marvell,armada-xp-smp",
  152. &armada_xp_smp_ops);
  153. #define MV98DX3236_CPU_RESUME_CTRL_REG 0x08
  154. #define MV98DX3236_CPU_RESUME_ADDR_REG 0x04
  155. static const struct of_device_id of_mv98dx3236_resume_table[] = {
  156. {
  157. .compatible = "marvell,98dx3336-resume-ctrl",
  158. },
  159. { /* end of list */ },
  160. };
  161. static int mv98dx3236_resume_set_cpu_boot_addr(int hw_cpu, void *boot_addr)
  162. {
  163. struct device_node *np;
  164. void __iomem *base;
  165. WARN_ON(hw_cpu != 1);
  166. np = of_find_matching_node(NULL, of_mv98dx3236_resume_table);
  167. if (!np)
  168. return -ENODEV;
  169. base = of_io_request_and_map(np, 0, of_node_full_name(np));
  170. of_node_put(np);
  171. if (IS_ERR(base))
  172. return PTR_ERR(base);
  173. writel(0, base + MV98DX3236_CPU_RESUME_CTRL_REG);
  174. writel(__pa_symbol(boot_addr), base + MV98DX3236_CPU_RESUME_ADDR_REG);
  175. iounmap(base);
  176. return 0;
  177. }
  178. static int mv98dx3236_boot_secondary(unsigned int cpu, struct task_struct *idle)
  179. {
  180. int ret, hw_cpu;
  181. hw_cpu = cpu_logical_map(cpu);
  182. mv98dx3236_resume_set_cpu_boot_addr(hw_cpu,
  183. armada_xp_secondary_startup);
  184. /*
  185. * This is needed to wake up CPUs in the offline state after
  186. * using CPU hotplug.
  187. */
  188. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  189. /*
  190. * This is needed to take secondary CPUs out of reset on the
  191. * initial boot.
  192. */
  193. ret = mvebu_cpu_reset_deassert(hw_cpu);
  194. if (ret) {
  195. pr_warn("unable to boot CPU: %d\n", ret);
  196. return ret;
  197. }
  198. return 0;
  199. }
  200. static const struct smp_operations mv98dx3236_smp_ops __initconst = {
  201. .smp_init_cpus = armada_xp_smp_init_cpus,
  202. .smp_prepare_cpus = armada_xp_smp_prepare_cpus,
  203. .smp_boot_secondary = mv98dx3236_boot_secondary,
  204. .smp_secondary_init = armada_xp_secondary_init,
  205. #ifdef CONFIG_HOTPLUG_CPU
  206. .cpu_die = armada_xp_cpu_die,
  207. .cpu_kill = armada_xp_cpu_kill,
  208. #endif
  209. };
  210. CPU_METHOD_OF_DECLARE(mv98dx3236_smp, "marvell,98dx3236-smp",
  211. &mv98dx3236_smp_ops);