platsmp.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.hashim@st.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. static DEFINE_SPINLOCK(boot_lock);
  22. static void __iomem *scu_base = IOMEM(VA_SCU_BASE);
  23. static void __cpuinit spear13xx_secondary_init(unsigned int cpu)
  24. {
  25. /*
  26. * let the primary processor know we're out of the
  27. * pen, then head off into the C entry point
  28. */
  29. pen_release = -1;
  30. smp_wmb();
  31. /*
  32. * Synchronise with the boot thread.
  33. */
  34. spin_lock(&boot_lock);
  35. spin_unlock(&boot_lock);
  36. }
  37. static int __cpuinit spear13xx_boot_secondary(unsigned int cpu, struct task_struct *idle)
  38. {
  39. unsigned long timeout;
  40. /*
  41. * set synchronisation state between this boot processor
  42. * and the secondary one
  43. */
  44. spin_lock(&boot_lock);
  45. /*
  46. * The secondary processor is waiting to be released from
  47. * the holding pen - release it, then wait for it to flag
  48. * that it has been released by resetting pen_release.
  49. *
  50. * Note that "pen_release" is the hardware CPU ID, whereas
  51. * "cpu" is Linux's internal ID.
  52. */
  53. pen_release = cpu;
  54. flush_cache_all();
  55. outer_flush_all();
  56. timeout = jiffies + (1 * HZ);
  57. while (time_before(jiffies, timeout)) {
  58. smp_rmb();
  59. if (pen_release == -1)
  60. break;
  61. udelay(10);
  62. }
  63. /*
  64. * now the secondary core is starting up let it run its
  65. * calibrations, then wait for it to finish
  66. */
  67. spin_unlock(&boot_lock);
  68. return pen_release != -1 ? -ENOSYS : 0;
  69. }
  70. /*
  71. * Initialise the CPU possible map early - this describes the CPUs
  72. * which may be present or become present in the system.
  73. */
  74. static void __init spear13xx_smp_init_cpus(void)
  75. {
  76. unsigned int i, ncores = scu_get_core_count(scu_base);
  77. if (ncores > nr_cpu_ids) {
  78. pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
  79. ncores, nr_cpu_ids);
  80. ncores = nr_cpu_ids;
  81. }
  82. for (i = 0; i < ncores; i++)
  83. set_cpu_possible(i, true);
  84. }
  85. static void __init spear13xx_smp_prepare_cpus(unsigned int max_cpus)
  86. {
  87. scu_enable(scu_base);
  88. /*
  89. * Write the address of secondary startup into the system-wide location
  90. * (presently it is in SRAM). The BootMonitor waits until it receives a
  91. * soft interrupt, and then the secondary CPU branches to this address.
  92. */
  93. __raw_writel(virt_to_phys(spear13xx_secondary_startup), SYS_LOCATION);
  94. }
  95. struct smp_operations spear13xx_smp_ops __initdata = {
  96. .smp_init_cpus = spear13xx_smp_init_cpus,
  97. .smp_prepare_cpus = spear13xx_smp_prepare_cpus,
  98. .smp_secondary_init = spear13xx_secondary_init,
  99. .smp_boot_secondary = spear13xx_boot_secondary,
  100. #ifdef CONFIG_HOTPLUG_CPU
  101. .cpu_die = spear13xx_cpu_die,
  102. #endif
  103. };