platsmp.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 AXP_BOOTROM_BASE 0xfff00000
  32. #define AXP_BOOTROM_SIZE 0x100000
  33. void __init set_secondary_cpus_clock(void)
  34. {
  35. int thiscpu;
  36. unsigned long rate;
  37. struct clk *cpu_clk = NULL;
  38. struct device_node *np = NULL;
  39. thiscpu = smp_processor_id();
  40. for_each_node_by_type(np, "cpu") {
  41. int err;
  42. int cpu;
  43. err = of_property_read_u32(np, "reg", &cpu);
  44. if (WARN_ON(err))
  45. return;
  46. if (cpu == thiscpu) {
  47. cpu_clk = of_clk_get(np, 0);
  48. break;
  49. }
  50. }
  51. if (WARN_ON(IS_ERR(cpu_clk)))
  52. return;
  53. clk_prepare_enable(cpu_clk);
  54. rate = clk_get_rate(cpu_clk);
  55. /* set all the other CPU clk to the same rate than the boot CPU */
  56. for_each_node_by_type(np, "cpu") {
  57. int err;
  58. int cpu;
  59. err = of_property_read_u32(np, "reg", &cpu);
  60. if (WARN_ON(err))
  61. return;
  62. if (cpu != thiscpu) {
  63. cpu_clk = of_clk_get(np, 0);
  64. clk_set_rate(cpu_clk, rate);
  65. }
  66. }
  67. }
  68. static void __cpuinit armada_xp_secondary_init(unsigned int cpu)
  69. {
  70. armada_xp_mpic_smp_cpu_init();
  71. }
  72. static int __cpuinit armada_xp_boot_secondary(unsigned int cpu,
  73. struct task_struct *idle)
  74. {
  75. pr_info("Booting CPU %d\n", cpu);
  76. armada_xp_boot_cpu(cpu, armada_xp_secondary_startup);
  77. return 0;
  78. }
  79. static void __init armada_xp_smp_init_cpus(void)
  80. {
  81. struct device_node *np;
  82. unsigned int i, ncores;
  83. np = of_find_node_by_name(NULL, "cpus");
  84. if (!np)
  85. panic("No 'cpus' node found\n");
  86. ncores = of_get_child_count(np);
  87. if (ncores == 0 || ncores > ARMADA_XP_MAX_CPUS)
  88. panic("Invalid number of CPUs in DT\n");
  89. /* Limit possible CPUs to defconfig */
  90. if (ncores > nr_cpu_ids) {
  91. pr_warn("SMP: %d CPUs physically present. Only %d configured.",
  92. ncores, nr_cpu_ids);
  93. pr_warn("Clipping CPU count to %d\n", nr_cpu_ids);
  94. ncores = nr_cpu_ids;
  95. }
  96. for (i = 0; i < ncores; i++)
  97. set_cpu_possible(i, true);
  98. set_smp_cross_call(armada_mpic_send_doorbell);
  99. }
  100. void __init armada_xp_smp_prepare_cpus(unsigned int max_cpus)
  101. {
  102. struct device_node *node;
  103. struct resource res;
  104. int err;
  105. set_secondary_cpus_clock();
  106. flush_cache_all();
  107. set_cpu_coherent(cpu_logical_map(smp_processor_id()), 0);
  108. /*
  109. * In order to boot the secondary CPUs we need to ensure
  110. * the bootROM is mapped at the correct address.
  111. */
  112. node = of_find_compatible_node(NULL, NULL, "marvell,bootrom");
  113. if (!node)
  114. panic("Cannot find 'marvell,bootrom' compatible node");
  115. err = of_address_to_resource(node, 0, &res);
  116. if (err < 0)
  117. panic("Cannot get 'bootrom' node address");
  118. if (res.start != AXP_BOOTROM_BASE ||
  119. resource_size(&res) != AXP_BOOTROM_SIZE)
  120. panic("The address for the BootROM is incorrect");
  121. }
  122. struct smp_operations armada_xp_smp_ops __initdata = {
  123. .smp_init_cpus = armada_xp_smp_init_cpus,
  124. .smp_prepare_cpus = armada_xp_smp_prepare_cpus,
  125. .smp_secondary_init = armada_xp_secondary_init,
  126. .smp_boot_secondary = armada_xp_boot_secondary,
  127. #ifdef CONFIG_HOTPLUG_CPU
  128. .cpu_die = armada_xp_cpu_die,
  129. #endif
  130. };