platsmp.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * linux/arch/arm/plat-versatile/platsmp.c
  3. *
  4. * Copyright (C) 2002 ARM Ltd.
  5. * All Rights Reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/errno.h>
  13. #include <linux/delay.h>
  14. #include <linux/device.h>
  15. #include <linux/jiffies.h>
  16. #include <linux/smp.h>
  17. #include <asm/cacheflush.h>
  18. #include <asm/smp_plat.h>
  19. #include <plat/platsmp.h>
  20. /*
  21. * Write pen_release in a way that is guaranteed to be visible to all
  22. * observers, irrespective of whether they're taking part in coherency
  23. * or not. This is necessary for the hotplug code to work reliably.
  24. */
  25. static void write_pen_release(int val)
  26. {
  27. pen_release = val;
  28. smp_wmb();
  29. sync_cache_w(&pen_release);
  30. }
  31. static DEFINE_SPINLOCK(boot_lock);
  32. void versatile_secondary_init(unsigned int cpu)
  33. {
  34. /*
  35. * let the primary processor know we're out of the
  36. * pen, then head off into the C entry point
  37. */
  38. write_pen_release(-1);
  39. /*
  40. * Synchronise with the boot thread.
  41. */
  42. spin_lock(&boot_lock);
  43. spin_unlock(&boot_lock);
  44. }
  45. int versatile_boot_secondary(unsigned int cpu, struct task_struct *idle)
  46. {
  47. unsigned long timeout;
  48. /*
  49. * Set synchronisation state between this boot processor
  50. * and the secondary one
  51. */
  52. spin_lock(&boot_lock);
  53. /*
  54. * This is really belt and braces; we hold unintended secondary
  55. * CPUs in the holding pen until we're ready for them. However,
  56. * since we haven't sent them a soft interrupt, they shouldn't
  57. * be there.
  58. */
  59. write_pen_release(cpu_logical_map(cpu));
  60. /*
  61. * Send the secondary CPU a soft interrupt, thereby causing
  62. * the boot monitor to read the system wide flags register,
  63. * and branch to the address found there.
  64. */
  65. arch_send_wakeup_ipi_mask(cpumask_of(cpu));
  66. timeout = jiffies + (1 * HZ);
  67. while (time_before(jiffies, timeout)) {
  68. smp_rmb();
  69. if (pen_release == -1)
  70. break;
  71. udelay(10);
  72. }
  73. /*
  74. * now the secondary core is starting up let it run its
  75. * calibrations, then wait for it to finish
  76. */
  77. spin_unlock(&boot_lock);
  78. return pen_release != -1 ? -ENOSYS : 0;
  79. }