smp.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Smp support for CHRP machines.
  3. *
  4. * Written by Cort Dougan (cort@cs.nmt.edu) borrowing a great
  5. * deal of code from the sparc and intel versions.
  6. *
  7. * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
  8. *
  9. */
  10. #include <linux/config.h>
  11. #include <linux/kernel.h>
  12. #include <linux/sched.h>
  13. #include <linux/smp.h>
  14. #include <linux/smp_lock.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/kernel_stat.h>
  17. #include <linux/delay.h>
  18. #include <linux/init.h>
  19. #include <linux/spinlock.h>
  20. #include <asm/ptrace.h>
  21. #include <asm/atomic.h>
  22. #include <asm/irq.h>
  23. #include <asm/page.h>
  24. #include <asm/pgtable.h>
  25. #include <asm/sections.h>
  26. #include <asm/io.h>
  27. #include <asm/prom.h>
  28. #include <asm/smp.h>
  29. #include <asm/residual.h>
  30. #include <asm/time.h>
  31. #include <asm/open_pic.h>
  32. #include <asm/machdep.h>
  33. extern unsigned long smp_chrp_cpu_nr;
  34. static int __init smp_chrp_probe(void)
  35. {
  36. if (smp_chrp_cpu_nr > 1)
  37. openpic_request_IPIs();
  38. return smp_chrp_cpu_nr;
  39. }
  40. static void __devinit smp_chrp_kick_cpu(int nr)
  41. {
  42. *(unsigned long *)KERNELBASE = nr;
  43. asm volatile("dcbf 0,%0"::"r"(KERNELBASE):"memory");
  44. }
  45. static void __devinit smp_chrp_setup_cpu(int cpu_nr)
  46. {
  47. if (OpenPIC_Addr)
  48. do_openpic_setup_cpu();
  49. }
  50. static DEFINE_SPINLOCK(timebase_lock);
  51. static unsigned int timebase_upper = 0, timebase_lower = 0;
  52. void __devinit smp_chrp_give_timebase(void)
  53. {
  54. spin_lock(&timebase_lock);
  55. rtas_call(rtas_token("freeze-time-base"), 0, 1, NULL);
  56. timebase_upper = get_tbu();
  57. timebase_lower = get_tbl();
  58. spin_unlock(&timebase_lock);
  59. while (timebase_upper || timebase_lower)
  60. barrier();
  61. rtas_call(rtas_token("thaw-time-base"), 0, 1, NULL);
  62. }
  63. void __devinit smp_chrp_take_timebase(void)
  64. {
  65. while (!(timebase_upper || timebase_lower))
  66. barrier();
  67. spin_lock(&timebase_lock);
  68. set_tb(timebase_upper, timebase_lower);
  69. timebase_upper = 0;
  70. timebase_lower = 0;
  71. spin_unlock(&timebase_lock);
  72. printk("CPU %i taken timebase\n", smp_processor_id());
  73. }
  74. /* CHRP with openpic */
  75. struct smp_ops_t chrp_smp_ops = {
  76. .message_pass = smp_openpic_message_pass,
  77. .probe = smp_chrp_probe,
  78. .kick_cpu = smp_chrp_kick_cpu,
  79. .setup_cpu = smp_chrp_setup_cpu,
  80. .give_timebase = smp_chrp_give_timebase,
  81. .take_timebase = smp_chrp_take_timebase,
  82. };