platsmp.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * linux/arch/arm/mach-realview/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/smp.h>
  16. #include <asm/cacheflush.h>
  17. #include <asm/hardware/arm_scu.h>
  18. #include <asm/hardware.h>
  19. #include <asm/io.h>
  20. #include <asm/mach-types.h>
  21. extern void realview_secondary_startup(void);
  22. /*
  23. * control for which core is the next to come out of the secondary
  24. * boot "holding pen"
  25. */
  26. volatile int __cpuinitdata pen_release = -1;
  27. static unsigned int __init get_core_count(void)
  28. {
  29. unsigned int ncores;
  30. if (machine_is_realview_eb() && core_tile_eb11mp()) {
  31. ncores = __raw_readl(__io_address(REALVIEW_EB11MP_SCU_BASE) + SCU_CONFIG);
  32. ncores = (ncores & 0x03) + 1;
  33. } else
  34. ncores = 1;
  35. return ncores;
  36. }
  37. static DEFINE_SPINLOCK(boot_lock);
  38. void __cpuinit platform_secondary_init(unsigned int cpu)
  39. {
  40. /*
  41. * the primary core may have used a "cross call" soft interrupt
  42. * to get this processor out of WFI in the BootMonitor - make
  43. * sure that we are no longer being sent this soft interrupt
  44. */
  45. smp_cross_call_done(cpumask_of_cpu(cpu));
  46. /*
  47. * if any interrupts are already enabled for the primary
  48. * core (e.g. timer irq), then they will not have been enabled
  49. * for us: do so
  50. */
  51. gic_cpu_init(0, __io_address(REALVIEW_EB11MP_GIC_CPU_BASE));
  52. /*
  53. * let the primary processor know we're out of the
  54. * pen, then head off into the C entry point
  55. */
  56. pen_release = -1;
  57. smp_wmb();
  58. /*
  59. * Synchronise with the boot thread.
  60. */
  61. spin_lock(&boot_lock);
  62. spin_unlock(&boot_lock);
  63. }
  64. int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
  65. {
  66. unsigned long timeout;
  67. /*
  68. * set synchronisation state between this boot processor
  69. * and the secondary one
  70. */
  71. spin_lock(&boot_lock);
  72. /*
  73. * The secondary processor is waiting to be released from
  74. * the holding pen - release it, then wait for it to flag
  75. * that it has been released by resetting pen_release.
  76. *
  77. * Note that "pen_release" is the hardware CPU ID, whereas
  78. * "cpu" is Linux's internal ID.
  79. */
  80. pen_release = cpu;
  81. flush_cache_all();
  82. /*
  83. * XXX
  84. *
  85. * This is a later addition to the booting protocol: the
  86. * bootMonitor now puts secondary cores into WFI, so
  87. * poke_milo() no longer gets the cores moving; we need
  88. * to send a soft interrupt to wake the secondary core.
  89. * Use smp_cross_call() for this, since there's little
  90. * point duplicating the code here
  91. */
  92. smp_cross_call(cpumask_of_cpu(cpu));
  93. timeout = jiffies + (1 * HZ);
  94. while (time_before(jiffies, timeout)) {
  95. smp_rmb();
  96. if (pen_release == -1)
  97. break;
  98. udelay(10);
  99. }
  100. /*
  101. * now the secondary core is starting up let it run its
  102. * calibrations, then wait for it to finish
  103. */
  104. spin_unlock(&boot_lock);
  105. return pen_release != -1 ? -ENOSYS : 0;
  106. }
  107. static void __init poke_milo(void)
  108. {
  109. extern void secondary_startup(void);
  110. /* nobody is to be released from the pen yet */
  111. pen_release = -1;
  112. /*
  113. * write the address of secondary startup into the system-wide
  114. * flags register, then clear the bottom two bits, which is what
  115. * BootMonitor is waiting for
  116. */
  117. #if 1
  118. #define REALVIEW_SYS_FLAGSS_OFFSET 0x30
  119. __raw_writel(virt_to_phys(realview_secondary_startup),
  120. __io_address(REALVIEW_SYS_BASE) +
  121. REALVIEW_SYS_FLAGSS_OFFSET);
  122. #define REALVIEW_SYS_FLAGSC_OFFSET 0x34
  123. __raw_writel(3,
  124. __io_address(REALVIEW_SYS_BASE) +
  125. REALVIEW_SYS_FLAGSC_OFFSET);
  126. #endif
  127. mb();
  128. }
  129. /*
  130. * Initialise the CPU possible map early - this describes the CPUs
  131. * which may be present or become present in the system.
  132. */
  133. void __init smp_init_cpus(void)
  134. {
  135. unsigned int i, ncores = get_core_count();
  136. for (i = 0; i < ncores; i++)
  137. cpu_set(i, cpu_possible_map);
  138. }
  139. void __init smp_prepare_cpus(unsigned int max_cpus)
  140. {
  141. unsigned int ncores = get_core_count();
  142. unsigned int cpu = smp_processor_id();
  143. int i;
  144. /* sanity check */
  145. if (ncores == 0) {
  146. printk(KERN_ERR
  147. "Realview: strange CM count of 0? Default to 1\n");
  148. ncores = 1;
  149. }
  150. if (ncores > NR_CPUS) {
  151. printk(KERN_WARNING
  152. "Realview: no. of cores (%d) greater than configured "
  153. "maximum of %d - clipping\n",
  154. ncores, NR_CPUS);
  155. ncores = NR_CPUS;
  156. }
  157. smp_store_cpu_info(cpu);
  158. /*
  159. * are we trying to boot more cores than exist?
  160. */
  161. if (max_cpus > ncores)
  162. max_cpus = ncores;
  163. #ifdef CONFIG_LOCAL_TIMERS
  164. /*
  165. * Enable the local timer for primary CPU. If the device is
  166. * dummy (!CONFIG_LOCAL_TIMERS), it was already registers in
  167. * realview_timer_init
  168. */
  169. if (machine_is_realview_eb() && core_tile_eb11mp())
  170. local_timer_setup(cpu);
  171. #endif
  172. /*
  173. * Initialise the present map, which describes the set of CPUs
  174. * actually populated at the present time.
  175. */
  176. for (i = 0; i < max_cpus; i++)
  177. cpu_set(i, cpu_present_map);
  178. /*
  179. * Do we need any more CPUs? If so, then let them know where
  180. * to start. Note that, on modern versions of MILO, the "poke"
  181. * doesn't actually do anything until each individual core is
  182. * sent a soft interrupt to get it out of WFI
  183. */
  184. if (max_cpus > 1)
  185. poke_milo();
  186. }