platsmp.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * arch/arm/mach-sti/platsmp.c
  3. *
  4. * Copyright (C) 2013 STMicroelectronics (R&D) Limited.
  5. * http://www.st.com
  6. *
  7. * Cloned from linux/arch/arm/mach-vexpress/platsmp.c
  8. *
  9. * Copyright (C) 2002 ARM Ltd.
  10. * All Rights Reserved
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. */
  16. #include <linux/init.h>
  17. #include <linux/errno.h>
  18. #include <linux/delay.h>
  19. #include <linux/smp.h>
  20. #include <linux/io.h>
  21. #include <linux/of.h>
  22. #include <linux/of_address.h>
  23. #include <linux/memblock.h>
  24. #include <asm/cacheflush.h>
  25. #include <asm/smp_plat.h>
  26. #include <asm/smp_scu.h>
  27. #include "smp.h"
  28. static void write_pen_release(int val)
  29. {
  30. pen_release = val;
  31. smp_wmb();
  32. sync_cache_w(&pen_release);
  33. }
  34. static DEFINE_SPINLOCK(boot_lock);
  35. static void sti_secondary_init(unsigned int cpu)
  36. {
  37. /*
  38. * let the primary processor know we're out of the
  39. * pen, then head off into the C entry point
  40. */
  41. write_pen_release(-1);
  42. /*
  43. * Synchronise with the boot thread.
  44. */
  45. spin_lock(&boot_lock);
  46. spin_unlock(&boot_lock);
  47. }
  48. static int sti_boot_secondary(unsigned int cpu, struct task_struct *idle)
  49. {
  50. unsigned long timeout;
  51. /*
  52. * set synchronisation state between this boot processor
  53. * and the secondary one
  54. */
  55. spin_lock(&boot_lock);
  56. /*
  57. * The secondary processor is waiting to be released from
  58. * the holding pen - release it, then wait for it to flag
  59. * that it has been released by resetting pen_release.
  60. *
  61. * Note that "pen_release" is the hardware CPU ID, whereas
  62. * "cpu" is Linux's internal ID.
  63. */
  64. write_pen_release(cpu_logical_map(cpu));
  65. /*
  66. * Send the secondary CPU a soft interrupt, thereby causing
  67. * it to jump to the secondary entrypoint.
  68. */
  69. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  70. timeout = jiffies + (1 * HZ);
  71. while (time_before(jiffies, timeout)) {
  72. smp_rmb();
  73. if (pen_release == -1)
  74. break;
  75. udelay(10);
  76. }
  77. /*
  78. * now the secondary core is starting up let it run its
  79. * calibrations, then wait for it to finish
  80. */
  81. spin_unlock(&boot_lock);
  82. return pen_release != -1 ? -ENOSYS : 0;
  83. }
  84. static void __init sti_smp_prepare_cpus(unsigned int max_cpus)
  85. {
  86. struct device_node *np;
  87. void __iomem *scu_base;
  88. u32 __iomem *cpu_strt_ptr;
  89. u32 release_phys;
  90. int cpu;
  91. unsigned long entry_pa = virt_to_phys(sti_secondary_startup);
  92. np = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-scu");
  93. if (np) {
  94. scu_base = of_iomap(np, 0);
  95. scu_enable(scu_base);
  96. of_node_put(np);
  97. }
  98. if (max_cpus <= 1)
  99. return;
  100. for_each_possible_cpu(cpu) {
  101. np = of_get_cpu_node(cpu, NULL);
  102. if (!np)
  103. continue;
  104. if (of_property_read_u32(np, "cpu-release-addr",
  105. &release_phys)) {
  106. pr_err("CPU %d: missing or invalid cpu-release-addr "
  107. "property\n", cpu);
  108. continue;
  109. }
  110. /*
  111. * holding pen is usually configured in SBC DMEM but can also be
  112. * in RAM.
  113. */
  114. if (!memblock_is_memory(release_phys))
  115. cpu_strt_ptr =
  116. ioremap(release_phys, sizeof(release_phys));
  117. else
  118. cpu_strt_ptr =
  119. (u32 __iomem *)phys_to_virt(release_phys);
  120. __raw_writel(entry_pa, cpu_strt_ptr);
  121. /*
  122. * wmb so that data is actually written
  123. * before cache flush is done
  124. */
  125. smp_wmb();
  126. sync_cache_w(cpu_strt_ptr);
  127. if (!memblock_is_memory(release_phys))
  128. iounmap(cpu_strt_ptr);
  129. }
  130. }
  131. const struct smp_operations sti_smp_ops __initconst = {
  132. .smp_prepare_cpus = sti_smp_prepare_cpus,
  133. .smp_secondary_init = sti_secondary_init,
  134. .smp_boot_secondary = sti_boot_secondary,
  135. };