smp.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 <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. cpumask_t cpu_online_map;
  39. static atomic_t cpus_booted = ATOMIC_INIT(0);
  40. /* These are defined by the board-specific code. */
  41. /*
  42. * Cause the function described by call_data to be executed on the passed
  43. * cpu. When the function has finished, increment the finished field of
  44. * call_data.
  45. */
  46. void __smp_send_ipi(unsigned int cpu, unsigned int action);
  47. /*
  48. * Find the number of available processors
  49. */
  50. unsigned int __smp_probe_cpus(void);
  51. /*
  52. * Start a particular processor
  53. */
  54. void __smp_slave_init(unsigned int cpu);
  55. /*
  56. * Run specified function on a particular processor.
  57. */
  58. void __smp_call_function(unsigned int cpu);
  59. static inline void __init smp_store_cpu_info(unsigned int cpu)
  60. {
  61. cpu_data[cpu].loops_per_jiffy = loops_per_jiffy;
  62. }
  63. void __init smp_prepare_cpus(unsigned int max_cpus)
  64. {
  65. unsigned int cpu = smp_processor_id();
  66. int i;
  67. atomic_set(&cpus_booted, 1);
  68. smp_store_cpu_info(cpu);
  69. for (i = 0; i < __smp_probe_cpus(); i++)
  70. cpu_set(i, cpu_possible_map);
  71. }
  72. void __devinit smp_prepare_boot_cpu(void)
  73. {
  74. unsigned int cpu = smp_processor_id();
  75. cpu_set(cpu, cpu_online_map);
  76. cpu_set(cpu, cpu_possible_map);
  77. }
  78. int __cpu_up(unsigned int cpu)
  79. {
  80. struct task_struct *tsk;
  81. tsk = fork_idle(cpu);
  82. if (IS_ERR(tsk))
  83. panic("Failed forking idle task for cpu %d\n", cpu);
  84. tsk->thread_info->cpu = cpu;
  85. cpu_set(cpu, cpu_online_map);
  86. return 0;
  87. }
  88. int start_secondary(void *unused)
  89. {
  90. unsigned int cpu = smp_processor_id();
  91. atomic_inc(&init_mm.mm_count);
  92. current->active_mm = &init_mm;
  93. smp_store_cpu_info(cpu);
  94. __smp_slave_init(cpu);
  95. per_cpu_trap_init();
  96. atomic_inc(&cpus_booted);
  97. cpu_idle();
  98. return 0;
  99. }
  100. void __init smp_cpus_done(unsigned int max_cpus)
  101. {
  102. smp_mb();
  103. }
  104. void smp_send_reschedule(int cpu)
  105. {
  106. __smp_send_ipi(cpu, SMP_MSG_RESCHEDULE);
  107. }
  108. static void stop_this_cpu(void *unused)
  109. {
  110. cpu_clear(smp_processor_id(), cpu_online_map);
  111. local_irq_disable();
  112. for (;;)
  113. cpu_relax();
  114. }
  115. void smp_send_stop(void)
  116. {
  117. smp_call_function(stop_this_cpu, 0, 1, 0);
  118. }
  119. struct smp_fn_call_struct smp_fn_call = {
  120. .lock = SPIN_LOCK_UNLOCKED,
  121. .finished = ATOMIC_INIT(0),
  122. };
  123. /*
  124. * The caller of this wants the passed function to run on every cpu. If wait
  125. * is set, wait until all cpus have finished the function before returning.
  126. * The lock is here to protect the call structure.
  127. * You must not call this function with disabled interrupts or from a
  128. * hardware interrupt handler or from a bottom half handler.
  129. */
  130. int smp_call_function(void (*func)(void *info), void *info, int retry, int wait)
  131. {
  132. unsigned int nr_cpus = atomic_read(&cpus_booted);
  133. int i;
  134. if (nr_cpus < 2)
  135. return 0;
  136. /* Can deadlock when called with interrupts disabled */
  137. WARN_ON(irqs_disabled());
  138. spin_lock(&smp_fn_call.lock);
  139. atomic_set(&smp_fn_call.finished, 0);
  140. smp_fn_call.fn = func;
  141. smp_fn_call.data = info;
  142. for (i = 0; i < nr_cpus; i++)
  143. if (i != smp_processor_id())
  144. __smp_call_function(i);
  145. if (wait)
  146. while (atomic_read(&smp_fn_call.finished) != (nr_cpus - 1));
  147. spin_unlock(&smp_fn_call.lock);
  148. return 0;
  149. }
  150. /* Not really SMP stuff ... */
  151. int setup_profiling_timer(unsigned int multiplier)
  152. {
  153. return 0;
  154. }