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