platsmp.c 6.1 KB

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