platsmp.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 <asm/cacheflush.h>
  24. #include <asm/smp_plat.h>
  25. #include "common.h"
  26. #include "armada-370-xp.h"
  27. #include "pmsu.h"
  28. #include "coherency.h"
  29. void __init set_secondary_cpus_clock(void)
  30. {
  31. int thiscpu;
  32. unsigned long rate;
  33. struct clk *cpu_clk = NULL;
  34. struct device_node *np = NULL;
  35. thiscpu = smp_processor_id();
  36. for_each_node_by_type(np, "cpu") {
  37. int err;
  38. int cpu;
  39. err = of_property_read_u32(np, "reg", &cpu);
  40. if (WARN_ON(err))
  41. return;
  42. if (cpu == thiscpu) {
  43. cpu_clk = of_clk_get(np, 0);
  44. break;
  45. }
  46. }
  47. if (WARN_ON(IS_ERR(cpu_clk)))
  48. return;
  49. clk_prepare_enable(cpu_clk);
  50. rate = clk_get_rate(cpu_clk);
  51. /* set all the other CPU clk to the same rate than the boot CPU */
  52. for_each_node_by_type(np, "cpu") {
  53. int err;
  54. int cpu;
  55. err = of_property_read_u32(np, "reg", &cpu);
  56. if (WARN_ON(err))
  57. return;
  58. if (cpu != thiscpu) {
  59. cpu_clk = of_clk_get(np, 0);
  60. clk_set_rate(cpu_clk, rate);
  61. }
  62. }
  63. }
  64. static void __cpuinit armada_xp_secondary_init(unsigned int cpu)
  65. {
  66. armada_xp_mpic_smp_cpu_init();
  67. }
  68. static int __cpuinit armada_xp_boot_secondary(unsigned int cpu,
  69. struct task_struct *idle)
  70. {
  71. pr_info("Booting CPU %d\n", cpu);
  72. armada_xp_boot_cpu(cpu, armada_xp_secondary_startup);
  73. return 0;
  74. }
  75. static void __init armada_xp_smp_init_cpus(void)
  76. {
  77. unsigned int i, ncores;
  78. ncores = coherency_get_cpu_count();
  79. /* Limit possible CPUs to defconfig */
  80. if (ncores > nr_cpu_ids) {
  81. pr_warn("SMP: %d CPUs physically present. Only %d configured.",
  82. ncores, nr_cpu_ids);
  83. pr_warn("Clipping CPU count to %d\n", nr_cpu_ids);
  84. ncores = nr_cpu_ids;
  85. }
  86. for (i = 0; i < ncores; i++)
  87. set_cpu_possible(i, true);
  88. set_smp_cross_call(armada_mpic_send_doorbell);
  89. }
  90. void __init armada_xp_smp_prepare_cpus(unsigned int max_cpus)
  91. {
  92. set_secondary_cpus_clock();
  93. flush_cache_all();
  94. set_cpu_coherent(cpu_logical_map(smp_processor_id()), 0);
  95. }
  96. struct smp_operations armada_xp_smp_ops __initdata = {
  97. .smp_init_cpus = armada_xp_smp_init_cpus,
  98. .smp_prepare_cpus = armada_xp_smp_prepare_cpus,
  99. .smp_secondary_init = armada_xp_secondary_init,
  100. .smp_boot_secondary = armada_xp_boot_secondary,
  101. #ifdef CONFIG_HOTPLUG_CPU
  102. .cpu_die = armada_xp_cpu_die,
  103. #endif
  104. };