platsmp.c 5.6 KB

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