platsmp.c 6.5 KB

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