platsmp.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * arch/arm/mach-spear13xx/platsmp.c
  3. *
  4. * based upon linux/arch/arm/mach-realview/platsmp.c
  5. *
  6. * Copyright (C) 2012 ST Microelectronics Ltd.
  7. * Shiraz Hashim <shiraz.linux.kernel@gmail.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/delay.h>
  14. #include <linux/jiffies.h>
  15. #include <linux/io.h>
  16. #include <linux/smp.h>
  17. #include <asm/cacheflush.h>
  18. #include <asm/smp_scu.h>
  19. #include <mach/spear.h>
  20. #include "generic.h"
  21. /*
  22. * Write pen_release in a way that is guaranteed to be visible to all
  23. * observers, irrespective of whether they're taking part in coherency
  24. * or not. This is necessary for the hotplug code to work reliably.
  25. */
  26. static void write_pen_release(int val)
  27. {
  28. pen_release = val;
  29. smp_wmb();
  30. sync_cache_w(&pen_release);
  31. }
  32. static DEFINE_SPINLOCK(boot_lock);
  33. static void __iomem *scu_base = IOMEM(VA_SCU_BASE);
  34. static void spear13xx_secondary_init(unsigned int cpu)
  35. {
  36. /*
  37. * let the primary processor know we're out of the
  38. * pen, then head off into the C entry point
  39. */
  40. write_pen_release(-1);
  41. /*
  42. * Synchronise with the boot thread.
  43. */
  44. spin_lock(&boot_lock);
  45. spin_unlock(&boot_lock);
  46. }
  47. static int spear13xx_boot_secondary(unsigned int cpu, struct task_struct *idle)
  48. {
  49. unsigned long timeout;
  50. /*
  51. * set synchronisation state between this boot processor
  52. * and the secondary one
  53. */
  54. spin_lock(&boot_lock);
  55. /*
  56. * The secondary processor is waiting to be released from
  57. * the holding pen - release it, then wait for it to flag
  58. * that it has been released by resetting pen_release.
  59. *
  60. * Note that "pen_release" is the hardware CPU ID, whereas
  61. * "cpu" is Linux's internal ID.
  62. */
  63. write_pen_release(cpu);
  64. timeout = jiffies + (1 * HZ);
  65. while (time_before(jiffies, timeout)) {
  66. smp_rmb();
  67. if (pen_release == -1)
  68. break;
  69. udelay(10);
  70. }
  71. /*
  72. * now the secondary core is starting up let it run its
  73. * calibrations, then wait for it to finish
  74. */
  75. spin_unlock(&boot_lock);
  76. return pen_release != -1 ? -ENOSYS : 0;
  77. }
  78. /*
  79. * Initialise the CPU possible map early - this describes the CPUs
  80. * which may be present or become present in the system.
  81. */
  82. static void __init spear13xx_smp_init_cpus(void)
  83. {
  84. unsigned int i, ncores = scu_get_core_count(scu_base);
  85. if (ncores > nr_cpu_ids) {
  86. pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
  87. ncores, nr_cpu_ids);
  88. ncores = nr_cpu_ids;
  89. }
  90. for (i = 0; i < ncores; i++)
  91. set_cpu_possible(i, true);
  92. }
  93. static void __init spear13xx_smp_prepare_cpus(unsigned int max_cpus)
  94. {
  95. scu_enable(scu_base);
  96. /*
  97. * Write the address of secondary startup into the system-wide location
  98. * (presently it is in SRAM). The BootMonitor waits until it receives a
  99. * soft interrupt, and then the secondary CPU branches to this address.
  100. */
  101. __raw_writel(__pa_symbol(spear13xx_secondary_startup), SYS_LOCATION);
  102. }
  103. const struct smp_operations spear13xx_smp_ops __initconst = {
  104. .smp_init_cpus = spear13xx_smp_init_cpus,
  105. .smp_prepare_cpus = spear13xx_smp_prepare_cpus,
  106. .smp_secondary_init = spear13xx_secondary_init,
  107. .smp_boot_secondary = spear13xx_boot_secondary,
  108. #ifdef CONFIG_HOTPLUG_CPU
  109. .cpu_die = spear13xx_cpu_die,
  110. #endif
  111. };