smp_spin_table.c 3.0 KB

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