smp_spin_table.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Spin Table SMP initialisation
  3. *
  4. * Copyright (C) 2013 ARM Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <linux/delay.h>
  19. #include <linux/init.h>
  20. #include <linux/of.h>
  21. #include <linux/smp.h>
  22. #include <asm/cacheflush.h>
  23. #include <asm/cpu_ops.h>
  24. #include <asm/cputype.h>
  25. #include <asm/smp_plat.h>
  26. extern void secondary_holding_pen(void);
  27. volatile unsigned long secondary_holding_pen_release = INVALID_HWID;
  28. static phys_addr_t cpu_release_addr[NR_CPUS];
  29. static DEFINE_RAW_SPINLOCK(boot_lock);
  30. /*
  31. * Write secondary_holding_pen_release in a way that is guaranteed to be
  32. * visible to all observers, irrespective of whether they're taking part
  33. * in coherency or not. This is necessary for the hotplug code to work
  34. * reliably.
  35. */
  36. static void write_pen_release(u64 val)
  37. {
  38. void *start = (void *)&secondary_holding_pen_release;
  39. unsigned long size = sizeof(secondary_holding_pen_release);
  40. secondary_holding_pen_release = val;
  41. __flush_dcache_area(start, size);
  42. }
  43. static int smp_spin_table_cpu_init(struct device_node *dn, unsigned int cpu)
  44. {
  45. /*
  46. * Determine the address from which the CPU is polling.
  47. */
  48. if (of_property_read_u64(dn, "cpu-release-addr",
  49. &cpu_release_addr[cpu])) {
  50. pr_err("CPU %d: missing or invalid cpu-release-addr property\n",
  51. cpu);
  52. return -1;
  53. }
  54. return 0;
  55. }
  56. static int smp_spin_table_cpu_prepare(unsigned int cpu)
  57. {
  58. void **release_addr;
  59. if (!cpu_release_addr[cpu])
  60. return -ENODEV;
  61. release_addr = __va(cpu_release_addr[cpu]);
  62. /*
  63. * We write the release address as LE regardless of the native
  64. * endianess of the kernel. Therefore, any boot-loaders that
  65. * read this address need to convert this address to the
  66. * boot-loader's endianess before jumping. This is mandated by
  67. * the boot protocol.
  68. */
  69. release_addr[0] = (void *) cpu_to_le64(__pa(secondary_holding_pen));
  70. __flush_dcache_area(release_addr, sizeof(release_addr[0]));
  71. /*
  72. * Send an event to wake up the secondary CPU.
  73. */
  74. sev();
  75. return 0;
  76. }
  77. static int smp_spin_table_cpu_boot(unsigned int cpu)
  78. {
  79. unsigned long timeout;
  80. /*
  81. * Set synchronisation state between this boot processor
  82. * and the secondary one
  83. */
  84. raw_spin_lock(&boot_lock);
  85. /*
  86. * Update the pen release flag.
  87. */
  88. write_pen_release(cpu_logical_map(cpu));
  89. /*
  90. * Send an event, causing the secondaries to read pen_release.
  91. */
  92. sev();
  93. timeout = jiffies + (1 * HZ);
  94. while (time_before(jiffies, timeout)) {
  95. if (secondary_holding_pen_release == INVALID_HWID)
  96. break;
  97. udelay(10);
  98. }
  99. /*
  100. * Now the secondary core is starting up let it run its
  101. * calibrations, then wait for it to finish
  102. */
  103. raw_spin_unlock(&boot_lock);
  104. return secondary_holding_pen_release != INVALID_HWID ? -ENOSYS : 0;
  105. }
  106. void smp_spin_table_cpu_postboot(void)
  107. {
  108. /*
  109. * Let the primary processor know we're out of the pen.
  110. */
  111. write_pen_release(INVALID_HWID);
  112. /*
  113. * Synchronise with the boot thread.
  114. */
  115. raw_spin_lock(&boot_lock);
  116. raw_spin_unlock(&boot_lock);
  117. }
  118. const struct cpu_operations smp_spin_table_ops = {
  119. .name = "spin-table",
  120. .cpu_init = smp_spin_table_cpu_init,
  121. .cpu_prepare = smp_spin_table_cpu_prepare,
  122. .cpu_boot = smp_spin_table_cpu_boot,
  123. .cpu_postboot = smp_spin_table_cpu_postboot,
  124. };