smp.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. * arch/sh/kernel/smp.c
  3. *
  4. * SMP support for the SuperH processors.
  5. *
  6. * Copyright (C) 2002, 2003 Paul Mundt
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/config.h>
  14. #include <linux/cache.h>
  15. #include <linux/cpumask.h>
  16. #include <linux/delay.h>
  17. #include <linux/init.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/threads.h>
  21. #include <linux/module.h>
  22. #include <linux/time.h>
  23. #include <linux/timex.h>
  24. #include <linux/sched.h>
  25. #include <linux/module.h>
  26. #include <asm/atomic.h>
  27. #include <asm/processor.h>
  28. #include <asm/system.h>
  29. #include <asm/mmu_context.h>
  30. #include <asm/smp.h>
  31. /*
  32. * This was written with the Sega Saturn (SMP SH-2 7604) in mind,
  33. * but is designed to be usable regardless if there's an MMU
  34. * present or not.
  35. */
  36. struct sh_cpuinfo cpu_data[NR_CPUS];
  37. extern void per_cpu_trap_init(void);
  38. cpumask_t cpu_possible_map;
  39. EXPORT_SYMBOL(cpu_possible_map);
  40. cpumask_t cpu_online_map;
  41. static atomic_t cpus_booted = ATOMIC_INIT(0);
  42. /* These are defined by the board-specific code. */
  43. /*
  44. * Cause the function described by call_data to be executed on the passed
  45. * cpu. When the function has finished, increment the finished field of
  46. * call_data.
  47. */
  48. void __smp_send_ipi(unsigned int cpu, unsigned int action);
  49. /*
  50. * Find the number of available processors
  51. */
  52. unsigned int __smp_probe_cpus(void);
  53. /*
  54. * Start a particular processor
  55. */
  56. void __smp_slave_init(unsigned int cpu);
  57. /*
  58. * Run specified function on a particular processor.
  59. */
  60. void __smp_call_function(unsigned int cpu);
  61. static inline void __init smp_store_cpu_info(unsigned int cpu)
  62. {
  63. cpu_data[cpu].loops_per_jiffy = loops_per_jiffy;
  64. }
  65. void __init smp_prepare_cpus(unsigned int max_cpus)
  66. {
  67. unsigned int cpu = smp_processor_id();
  68. int i;
  69. atomic_set(&cpus_booted, 1);
  70. smp_store_cpu_info(cpu);
  71. for (i = 0; i < __smp_probe_cpus(); i++)
  72. cpu_set(i, cpu_possible_map);
  73. }
  74. void __devinit smp_prepare_boot_cpu(void)
  75. {
  76. unsigned int cpu = smp_processor_id();
  77. cpu_set(cpu, cpu_online_map);
  78. cpu_set(cpu, cpu_possible_map);
  79. }
  80. int __cpu_up(unsigned int cpu)
  81. {
  82. struct task_struct *tsk;
  83. tsk = fork_idle(cpu);
  84. if (IS_ERR(tsk))
  85. panic("Failed forking idle task for cpu %d\n", cpu);
  86. tsk->thread_info->cpu = cpu;
  87. cpu_set(cpu, cpu_online_map);
  88. return 0;
  89. }
  90. int start_secondary(void *unused)
  91. {
  92. unsigned int cpu = smp_processor_id();
  93. atomic_inc(&init_mm.mm_count);
  94. current->active_mm = &init_mm;
  95. smp_store_cpu_info(cpu);
  96. __smp_slave_init(cpu);
  97. per_cpu_trap_init();
  98. atomic_inc(&cpus_booted);
  99. cpu_idle();
  100. return 0;
  101. }
  102. void __init smp_cpus_done(unsigned int max_cpus)
  103. {
  104. smp_mb();
  105. }
  106. void smp_send_reschedule(int cpu)
  107. {
  108. __smp_send_ipi(cpu, SMP_MSG_RESCHEDULE);
  109. }
  110. static void stop_this_cpu(void *unused)
  111. {
  112. cpu_clear(smp_processor_id(), cpu_online_map);
  113. local_irq_disable();
  114. for (;;)
  115. cpu_relax();
  116. }
  117. void smp_send_stop(void)
  118. {
  119. smp_call_function(stop_this_cpu, 0, 1, 0);
  120. }
  121. struct smp_fn_call_struct smp_fn_call = {
  122. .lock = SPIN_LOCK_UNLOCKED,
  123. .finished = ATOMIC_INIT(0),
  124. };
  125. /*
  126. * The caller of this wants the passed function to run on every cpu. If wait
  127. * is set, wait until all cpus have finished the function before returning.
  128. * The lock is here to protect the call structure.
  129. * You must not call this function with disabled interrupts or from a
  130. * hardware interrupt handler or from a bottom half handler.
  131. */
  132. int smp_call_function(void (*func)(void *info), void *info, int retry, int wait)
  133. {
  134. unsigned int nr_cpus = atomic_read(&cpus_booted);
  135. int i;
  136. if (nr_cpus < 2)
  137. return 0;
  138. /* Can deadlock when called with interrupts disabled */
  139. WARN_ON(irqs_disabled());
  140. spin_lock(&smp_fn_call.lock);
  141. atomic_set(&smp_fn_call.finished, 0);
  142. smp_fn_call.fn = func;
  143. smp_fn_call.data = info;
  144. for (i = 0; i < nr_cpus; i++)
  145. if (i != smp_processor_id())
  146. __smp_call_function(i);
  147. if (wait)
  148. while (atomic_read(&smp_fn_call.finished) != (nr_cpus - 1));
  149. spin_unlock(&smp_fn_call.lock);
  150. return 0;
  151. }
  152. /* Not really SMP stuff ... */
  153. int setup_profiling_timer(unsigned int multiplier)
  154. {
  155. return 0;
  156. }