platsmp.c 5.7 KB

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