platsmp.c 5.7 KB

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