platsmp.c 3.0 KB

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