smp.c 4.2 KB

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