platsmp.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * linux/arch/arm/mach-cintegrator/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/kernel.h>
  13. #include <linux/sched.h>
  14. #include <linux/errno.h>
  15. #include <linux/mm.h>
  16. #include <asm/atomic.h>
  17. #include <asm/cacheflush.h>
  18. #include <asm/delay.h>
  19. #include <asm/mmu_context.h>
  20. #include <asm/ptrace.h>
  21. #include <asm/smp.h>
  22. extern void integrator_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. unsigned long __cpuinitdata phys_pen_release = 0;
  29. static DEFINE_SPINLOCK(boot_lock);
  30. void __cpuinit platform_secondary_init(unsigned int cpu)
  31. {
  32. /*
  33. * the primary core may have used a "cross call" soft interrupt
  34. * to get this processor out of WFI in the BootMonitor - make
  35. * sure that we are no longer being sent this soft interrupt
  36. */
  37. smp_cross_call_done(cpumask_of_cpu(cpu));
  38. /*
  39. * if any interrupts are already enabled for the primary
  40. * core (e.g. timer irq), then they will not have been enabled
  41. * for us: do so
  42. */
  43. secondary_scan_irqs();
  44. /*
  45. * let the primary processor know we're out of the
  46. * pen, then head off into the C entry point
  47. */
  48. pen_release = -1;
  49. /*
  50. * Synchronise with the boot thread.
  51. */
  52. spin_lock(&boot_lock);
  53. spin_unlock(&boot_lock);
  54. }
  55. int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
  56. {
  57. unsigned long timeout;
  58. /*
  59. * set synchronisation state between this boot processor
  60. * and the secondary one
  61. */
  62. spin_lock(&boot_lock);
  63. /*
  64. * The secondary processor is waiting to be released from
  65. * the holding pen - release it, then wait for it to flag
  66. * that it has been released by resetting pen_release.
  67. *
  68. * Note that "pen_release" is the hardware CPU ID, whereas
  69. * "cpu" is Linux's internal ID.
  70. */
  71. pen_release = cpu;
  72. flush_cache_all();
  73. /*
  74. * XXX
  75. *
  76. * This is a later addition to the booting protocol: the
  77. * bootMonitor now puts secondary cores into WFI, so
  78. * poke_milo() no longer gets the cores moving; we need
  79. * to send a soft interrupt to wake the secondary core.
  80. * Use smp_cross_call() for this, since there's little
  81. * point duplicating the code here
  82. */
  83. smp_cross_call(cpumask_of_cpu(cpu));
  84. timeout = jiffies + (1 * HZ);
  85. while (time_before(jiffies, timeout)) {
  86. if (pen_release == -1)
  87. break;
  88. udelay(10);
  89. }
  90. /*
  91. * now the secondary core is starting up let it run its
  92. * calibrations, then wait for it to finish
  93. */
  94. spin_unlock(&boot_lock);
  95. return pen_release != -1 ? -ENOSYS : 0;
  96. }
  97. static void __init poke_milo(void)
  98. {
  99. extern void secondary_startup(void);
  100. /* nobody is to be released from the pen yet */
  101. pen_release = -1;
  102. phys_pen_release = virt_to_phys(&pen_release);
  103. /*
  104. * write the address of secondary startup into the system-wide
  105. * flags register, then clear the bottom two bits, which is what
  106. * BootMonitor is waiting for
  107. */
  108. #if 1
  109. #define CINTEGRATOR_HDR_FLAGSS_OFFSET 0x30
  110. __raw_writel(virt_to_phys(integrator_secondary_startup),
  111. (IO_ADDRESS(INTEGRATOR_HDR_BASE) +
  112. CINTEGRATOR_HDR_FLAGSS_OFFSET));
  113. #define CINTEGRATOR_HDR_FLAGSC_OFFSET 0x34
  114. __raw_writel(3,
  115. (IO_ADDRESS(INTEGRATOR_HDR_BASE) +
  116. CINTEGRATOR_HDR_FLAGSC_OFFSET));
  117. #endif
  118. mb();
  119. }
  120. /*
  121. * Initialise the CPU possible map early - this describes the CPUs
  122. * which may be present or become present in the system.
  123. */
  124. void __init smp_init_cpus(void)
  125. {
  126. unsigned int i, ncores = get_core_count();
  127. for (i = 0; i < ncores; i++)
  128. cpu_set(i, cpu_possible_map);
  129. }
  130. void __init smp_prepare_cpus(unsigned int max_cpus)
  131. {
  132. unsigned int ncores = get_core_count();
  133. unsigned int cpu = smp_processor_id();
  134. int i;
  135. /* sanity check */
  136. if (ncores == 0) {
  137. printk(KERN_ERR
  138. "Integrator/CP: strange CM count of 0? Default to 1\n");
  139. ncores = 1;
  140. }
  141. if (ncores > NR_CPUS) {
  142. printk(KERN_WARNING
  143. "Integrator/CP: no. of cores (%d) greater than configured "
  144. "maximum of %d - clipping\n",
  145. ncores, NR_CPUS);
  146. ncores = NR_CPUS;
  147. }
  148. /*
  149. * start with some more config for the Boot CPU, now that
  150. * the world is a bit more alive (which was not the case
  151. * when smp_prepare_boot_cpu() was called)
  152. */
  153. smp_store_cpu_info(cpu);
  154. /*
  155. * are we trying to boot more cores than exist?
  156. */
  157. if (max_cpus > ncores)
  158. max_cpus = ncores;
  159. /*
  160. * Initialise the present map, which describes the set of CPUs
  161. * actually populated at the present time.
  162. */
  163. for (i = 0; i < max_cpus; i++)
  164. cpu_set(i, cpu_present_map);
  165. /*
  166. * Do we need any more CPUs? If so, then let them know where
  167. * to start. Note that, on modern versions of MILO, the "poke"
  168. * doesn't actually do anything until each individual core is
  169. * sent a soft interrupt to get it out of WFI
  170. */
  171. if (max_cpus > 1)
  172. poke_milo();
  173. }