smp.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /* smp.c: Sparc SMP support.
  2. *
  3. * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
  4. * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  5. * Copyright (C) 2004 Keith M Wesolowski (wesolows@foobazco.org)
  6. */
  7. #include <asm/head.h>
  8. #include <linux/kernel.h>
  9. #include <linux/sched.h>
  10. #include <linux/threads.h>
  11. #include <linux/smp.h>
  12. #include <linux/smp_lock.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/kernel_stat.h>
  15. #include <linux/init.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/mm.h>
  18. #include <linux/fs.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/cache.h>
  21. #include <linux/delay.h>
  22. #include <asm/ptrace.h>
  23. #include <asm/atomic.h>
  24. #include <asm/irq.h>
  25. #include <asm/page.h>
  26. #include <asm/pgalloc.h>
  27. #include <asm/pgtable.h>
  28. #include <asm/oplib.h>
  29. #include <asm/cacheflush.h>
  30. #include <asm/tlbflush.h>
  31. #include <asm/cpudata.h>
  32. volatile int smp_processors_ready = 0;
  33. int smp_num_cpus = 1;
  34. volatile unsigned long cpu_callin_map[NR_CPUS] __initdata = {0,};
  35. unsigned char boot_cpu_id = 0;
  36. unsigned char boot_cpu_id4 = 0; /* boot_cpu_id << 2 */
  37. int smp_activated = 0;
  38. volatile int __cpu_number_map[NR_CPUS];
  39. volatile int __cpu_logical_map[NR_CPUS];
  40. cpumask_t cpu_online_map = CPU_MASK_NONE;
  41. cpumask_t phys_cpu_present_map = CPU_MASK_NONE;
  42. /* The only guaranteed locking primitive available on all Sparc
  43. * processors is 'ldstub [%reg + immediate], %dest_reg' which atomically
  44. * places the current byte at the effective address into dest_reg and
  45. * places 0xff there afterwards. Pretty lame locking primitive
  46. * compared to the Alpha and the Intel no? Most Sparcs have 'swap'
  47. * instruction which is much better...
  48. */
  49. /* Used to make bitops atomic */
  50. unsigned char bitops_spinlock = 0;
  51. volatile unsigned long ipi_count;
  52. volatile int smp_process_available=0;
  53. volatile int smp_commenced = 0;
  54. void __init smp_store_cpu_info(int id)
  55. {
  56. int cpu_node;
  57. cpu_data(id).udelay_val = loops_per_jiffy;
  58. cpu_find_by_mid(id, &cpu_node);
  59. cpu_data(id).clock_tick = prom_getintdefault(cpu_node,
  60. "clock-frequency", 0);
  61. cpu_data(id).prom_node = cpu_node;
  62. cpu_data(id).mid = cpu_get_hwmid(cpu_node);
  63. if (cpu_data(id).mid < 0)
  64. panic("No MID found for CPU%d at node 0x%08d", id, cpu_node);
  65. }
  66. void __init smp_cpus_done(unsigned int max_cpus)
  67. {
  68. }
  69. void cpu_panic(void)
  70. {
  71. printk("CPU[%d]: Returns from cpu_idle!\n", smp_processor_id());
  72. panic("SMP bolixed\n");
  73. }
  74. struct linux_prom_registers smp_penguin_ctable __initdata = { 0 };
  75. void __init smp_boot_cpus(void)
  76. {
  77. extern void smp4m_boot_cpus(void);
  78. extern void smp4d_boot_cpus(void);
  79. if (sparc_cpu_model == sun4m)
  80. smp4m_boot_cpus();
  81. else
  82. smp4d_boot_cpus();
  83. }
  84. void smp_send_reschedule(int cpu)
  85. {
  86. /* See sparc64 */
  87. }
  88. void smp_send_stop(void)
  89. {
  90. }
  91. void smp_flush_cache_all(void)
  92. {
  93. xc0((smpfunc_t) BTFIXUP_CALL(local_flush_cache_all));
  94. local_flush_cache_all();
  95. }
  96. void smp_flush_tlb_all(void)
  97. {
  98. xc0((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_all));
  99. local_flush_tlb_all();
  100. }
  101. void smp_flush_cache_mm(struct mm_struct *mm)
  102. {
  103. if(mm->context != NO_CONTEXT) {
  104. cpumask_t cpu_mask = mm->cpu_vm_mask;
  105. cpu_clear(smp_processor_id(), cpu_mask);
  106. if (!cpus_empty(cpu_mask))
  107. xc1((smpfunc_t) BTFIXUP_CALL(local_flush_cache_mm), (unsigned long) mm);
  108. local_flush_cache_mm(mm);
  109. }
  110. }
  111. void smp_flush_tlb_mm(struct mm_struct *mm)
  112. {
  113. if(mm->context != NO_CONTEXT) {
  114. cpumask_t cpu_mask = mm->cpu_vm_mask;
  115. cpu_clear(smp_processor_id(), cpu_mask);
  116. if (!cpus_empty(cpu_mask)) {
  117. xc1((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_mm), (unsigned long) mm);
  118. if(atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
  119. mm->cpu_vm_mask = cpumask_of_cpu(smp_processor_id());
  120. }
  121. local_flush_tlb_mm(mm);
  122. }
  123. }
  124. void smp_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
  125. unsigned long end)
  126. {
  127. struct mm_struct *mm = vma->vm_mm;
  128. if (mm->context != NO_CONTEXT) {
  129. cpumask_t cpu_mask = mm->cpu_vm_mask;
  130. cpu_clear(smp_processor_id(), cpu_mask);
  131. if (!cpus_empty(cpu_mask))
  132. xc3((smpfunc_t) BTFIXUP_CALL(local_flush_cache_range), (unsigned long) vma, start, end);
  133. local_flush_cache_range(vma, start, end);
  134. }
  135. }
  136. void smp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
  137. unsigned long end)
  138. {
  139. struct mm_struct *mm = vma->vm_mm;
  140. if (mm->context != NO_CONTEXT) {
  141. cpumask_t cpu_mask = mm->cpu_vm_mask;
  142. cpu_clear(smp_processor_id(), cpu_mask);
  143. if (!cpus_empty(cpu_mask))
  144. xc3((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_range), (unsigned long) vma, start, end);
  145. local_flush_tlb_range(vma, start, end);
  146. }
  147. }
  148. void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
  149. {
  150. struct mm_struct *mm = vma->vm_mm;
  151. if(mm->context != NO_CONTEXT) {
  152. cpumask_t cpu_mask = mm->cpu_vm_mask;
  153. cpu_clear(smp_processor_id(), cpu_mask);
  154. if (!cpus_empty(cpu_mask))
  155. xc2((smpfunc_t) BTFIXUP_CALL(local_flush_cache_page), (unsigned long) vma, page);
  156. local_flush_cache_page(vma, page);
  157. }
  158. }
  159. void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
  160. {
  161. struct mm_struct *mm = vma->vm_mm;
  162. if(mm->context != NO_CONTEXT) {
  163. cpumask_t cpu_mask = mm->cpu_vm_mask;
  164. cpu_clear(smp_processor_id(), cpu_mask);
  165. if (!cpus_empty(cpu_mask))
  166. xc2((smpfunc_t) BTFIXUP_CALL(local_flush_tlb_page), (unsigned long) vma, page);
  167. local_flush_tlb_page(vma, page);
  168. }
  169. }
  170. void smp_reschedule_irq(void)
  171. {
  172. set_need_resched();
  173. }
  174. void smp_flush_page_to_ram(unsigned long page)
  175. {
  176. /* Current theory is that those who call this are the one's
  177. * who have just dirtied their cache with the pages contents
  178. * in kernel space, therefore we only run this on local cpu.
  179. *
  180. * XXX This experiment failed, research further... -DaveM
  181. */
  182. #if 1
  183. xc1((smpfunc_t) BTFIXUP_CALL(local_flush_page_to_ram), page);
  184. #endif
  185. local_flush_page_to_ram(page);
  186. }
  187. void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
  188. {
  189. cpumask_t cpu_mask = mm->cpu_vm_mask;
  190. cpu_clear(smp_processor_id(), cpu_mask);
  191. if (!cpus_empty(cpu_mask))
  192. xc2((smpfunc_t) BTFIXUP_CALL(local_flush_sig_insns), (unsigned long) mm, insn_addr);
  193. local_flush_sig_insns(mm, insn_addr);
  194. }
  195. extern unsigned int lvl14_resolution;
  196. /* /proc/profile writes can call this, don't __init it please. */
  197. static DEFINE_SPINLOCK(prof_setup_lock);
  198. int setup_profiling_timer(unsigned int multiplier)
  199. {
  200. int i;
  201. unsigned long flags;
  202. /* Prevent level14 ticker IRQ flooding. */
  203. if((!multiplier) || (lvl14_resolution / multiplier) < 500)
  204. return -EINVAL;
  205. spin_lock_irqsave(&prof_setup_lock, flags);
  206. for(i = 0; i < NR_CPUS; i++) {
  207. if (cpu_possible(i))
  208. load_profile_irq(i, lvl14_resolution / multiplier);
  209. prof_multiplier(i) = multiplier;
  210. }
  211. spin_unlock_irqrestore(&prof_setup_lock, flags);
  212. return 0;
  213. }
  214. void __init smp_prepare_cpus(unsigned int maxcpus)
  215. {
  216. }
  217. void __devinit smp_prepare_boot_cpu(void)
  218. {
  219. current_thread_info()->cpu = hard_smp_processor_id();
  220. cpu_set(smp_processor_id(), cpu_online_map);
  221. cpu_set(smp_processor_id(), phys_cpu_present_map);
  222. }
  223. int __devinit __cpu_up(unsigned int cpu)
  224. {
  225. panic("smp doesn't work\n");
  226. }
  227. void smp_bogo(struct seq_file *m)
  228. {
  229. int i;
  230. for (i = 0; i < NR_CPUS; i++) {
  231. if (cpu_online(i))
  232. seq_printf(m,
  233. "Cpu%dBogo\t: %lu.%02lu\n",
  234. i,
  235. cpu_data(i).udelay_val/(500000/HZ),
  236. (cpu_data(i).udelay_val/(5000/HZ))%100);
  237. }
  238. }
  239. void smp_info(struct seq_file *m)
  240. {
  241. int i;
  242. seq_printf(m, "State:\n");
  243. for (i = 0; i < NR_CPUS; i++) {
  244. if (cpu_online(i))
  245. seq_printf(m, "CPU%d\t\t: online\n", i);
  246. }
  247. }