smp_spin_table.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 <linux/types.h>
  23. #include <asm/cacheflush.h>
  24. #include <asm/cpu_ops.h>
  25. #include <asm/cputype.h>
  26. #include <asm/io.h>
  27. #include <asm/smp_plat.h>
  28. extern void secondary_holding_pen(void);
  29. volatile unsigned long __section(".mmuoff.data.read")
  30. secondary_holding_pen_release = INVALID_HWID;
  31. static phys_addr_t cpu_release_addr[NR_CPUS];
  32. /*
  33. * Write secondary_holding_pen_release in a way that is guaranteed to be
  34. * visible to all observers, irrespective of whether they're taking part
  35. * in coherency or not. This is necessary for the hotplug code to work
  36. * reliably.
  37. */
  38. static void write_pen_release(u64 val)
  39. {
  40. void *start = (void *)&secondary_holding_pen_release;
  41. unsigned long size = sizeof(secondary_holding_pen_release);
  42. secondary_holding_pen_release = val;
  43. __flush_dcache_area(start, size);
  44. }
  45. static int smp_spin_table_cpu_init(unsigned int cpu)
  46. {
  47. struct device_node *dn;
  48. int ret;
  49. dn = of_get_cpu_node(cpu, NULL);
  50. if (!dn)
  51. return -ENODEV;
  52. /*
  53. * Determine the address from which the CPU is polling.
  54. */
  55. ret = of_property_read_u64(dn, "cpu-release-addr",
  56. &cpu_release_addr[cpu]);
  57. if (ret)
  58. pr_err("CPU %d: missing or invalid cpu-release-addr property\n",
  59. cpu);
  60. of_node_put(dn);
  61. return ret;
  62. }
  63. static int smp_spin_table_cpu_prepare(unsigned int cpu)
  64. {
  65. __le64 __iomem *release_addr;
  66. if (!cpu_release_addr[cpu])
  67. return -ENODEV;
  68. /*
  69. * The cpu-release-addr may or may not be inside the linear mapping.
  70. * As ioremap_cache will either give us a new mapping or reuse the
  71. * existing linear mapping, we can use it to cover both cases. In
  72. * either case the memory will be MT_NORMAL.
  73. */
  74. release_addr = ioremap_cache(cpu_release_addr[cpu],
  75. sizeof(*release_addr));
  76. if (!release_addr)
  77. return -ENOMEM;
  78. /*
  79. * We write the release address as LE regardless of the native
  80. * endianess of the kernel. Therefore, any boot-loaders that
  81. * read this address need to convert this address to the
  82. * boot-loader's endianess before jumping. This is mandated by
  83. * the boot protocol.
  84. */
  85. writeq_relaxed(__pa(secondary_holding_pen), release_addr);
  86. __flush_dcache_area((__force void *)release_addr,
  87. sizeof(*release_addr));
  88. /*
  89. * Send an event to wake up the secondary CPU.
  90. */
  91. sev();
  92. iounmap(release_addr);
  93. return 0;
  94. }
  95. static int smp_spin_table_cpu_boot(unsigned int cpu)
  96. {
  97. /*
  98. * Update the pen release flag.
  99. */
  100. write_pen_release(cpu_logical_map(cpu));
  101. /*
  102. * Send an event, causing the secondaries to read pen_release.
  103. */
  104. sev();
  105. return 0;
  106. }
  107. const struct cpu_operations smp_spin_table_ops = {
  108. .name = "spin-table",
  109. .cpu_init = smp_spin_table_cpu_init,
  110. .cpu_prepare = smp_spin_table_cpu_prepare,
  111. .cpu_boot = smp_spin_table_cpu_boot,
  112. };