platsmp.c 5.6 KB

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