platsmp.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * arch/arm/mach-sti/platsmp.c
  3. *
  4. * Copyright (C) 2013 STMicroelectronics (R&D) Limited.
  5. * http://www.st.com
  6. *
  7. * Cloned from linux/arch/arm/mach-vexpress/platsmp.c
  8. *
  9. * Copyright (C) 2002 ARM Ltd.
  10. * All Rights Reserved
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. */
  16. #include <linux/init.h>
  17. #include <linux/errno.h>
  18. #include <linux/delay.h>
  19. #include <linux/smp.h>
  20. #include <linux/io.h>
  21. #include <linux/of.h>
  22. #include <linux/of_address.h>
  23. #include <asm/cacheflush.h>
  24. #include <asm/smp_plat.h>
  25. #include <asm/smp_scu.h>
  26. #include "smp.h"
  27. static void write_pen_release(int val)
  28. {
  29. pen_release = val;
  30. smp_wmb();
  31. sync_cache_w(&pen_release);
  32. }
  33. static DEFINE_SPINLOCK(boot_lock);
  34. static void sti_secondary_init(unsigned int cpu)
  35. {
  36. trace_hardirqs_off();
  37. /*
  38. * let the primary processor know we're out of the
  39. * pen, then head off into the C entry point
  40. */
  41. write_pen_release(-1);
  42. /*
  43. * Synchronise with the boot thread.
  44. */
  45. spin_lock(&boot_lock);
  46. spin_unlock(&boot_lock);
  47. }
  48. static int sti_boot_secondary(unsigned int cpu, struct task_struct *idle)
  49. {
  50. unsigned long timeout;
  51. /*
  52. * set synchronisation state between this boot processor
  53. * and the secondary one
  54. */
  55. spin_lock(&boot_lock);
  56. /*
  57. * The secondary processor is waiting to be released from
  58. * the holding pen - release it, then wait for it to flag
  59. * that it has been released by resetting pen_release.
  60. *
  61. * Note that "pen_release" is the hardware CPU ID, whereas
  62. * "cpu" is Linux's internal ID.
  63. */
  64. write_pen_release(cpu_logical_map(cpu));
  65. /*
  66. * Send the secondary CPU a soft interrupt, thereby causing
  67. * it to jump to the secondary entrypoint.
  68. */
  69. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  70. timeout = jiffies + (1 * HZ);
  71. while (time_before(jiffies, timeout)) {
  72. smp_rmb();
  73. if (pen_release == -1)
  74. break;
  75. udelay(10);
  76. }
  77. /*
  78. * now the secondary core is starting up let it run its
  79. * calibrations, then wait for it to finish
  80. */
  81. spin_unlock(&boot_lock);
  82. return pen_release != -1 ? -ENOSYS : 0;
  83. }
  84. static void __init sti_smp_prepare_cpus(unsigned int max_cpus)
  85. {
  86. void __iomem *scu_base = NULL;
  87. struct device_node *np = of_find_compatible_node(
  88. NULL, NULL, "arm,cortex-a9-scu");
  89. if (np) {
  90. scu_base = of_iomap(np, 0);
  91. scu_enable(scu_base);
  92. of_node_put(np);
  93. }
  94. }
  95. struct smp_operations __initdata sti_smp_ops = {
  96. .smp_prepare_cpus = sti_smp_prepare_cpus,
  97. .smp_secondary_init = sti_secondary_init,
  98. .smp_boot_secondary = sti_boot_secondary,
  99. };