chrp_smp.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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
  35. smp_chrp_probe(void)
  36. {
  37. if (smp_chrp_cpu_nr > 1)
  38. openpic_request_IPIs();
  39. return smp_chrp_cpu_nr;
  40. }
  41. static void __devinit
  42. smp_chrp_kick_cpu(int nr)
  43. {
  44. *(unsigned long *)KERNELBASE = nr;
  45. asm volatile("dcbf 0,%0"::"r"(KERNELBASE):"memory");
  46. }
  47. static void __devinit
  48. smp_chrp_setup_cpu(int cpu_nr)
  49. {
  50. if (OpenPIC_Addr)
  51. do_openpic_setup_cpu();
  52. }
  53. static DEFINE_SPINLOCK(timebase_lock);
  54. static unsigned int timebase_upper = 0, timebase_lower = 0;
  55. void __devinit
  56. smp_chrp_give_timebase(void)
  57. {
  58. spin_lock(&timebase_lock);
  59. call_rtas("freeze-time-base", 0, 1, NULL);
  60. timebase_upper = get_tbu();
  61. timebase_lower = get_tbl();
  62. spin_unlock(&timebase_lock);
  63. while (timebase_upper || timebase_lower)
  64. barrier();
  65. call_rtas("thaw-time-base", 0, 1, NULL);
  66. }
  67. void __devinit
  68. smp_chrp_take_timebase(void)
  69. {
  70. while (!(timebase_upper || timebase_lower))
  71. barrier();
  72. spin_lock(&timebase_lock);
  73. set_tb(timebase_upper, timebase_lower);
  74. timebase_upper = 0;
  75. timebase_lower = 0;
  76. spin_unlock(&timebase_lock);
  77. printk("CPU %i taken timebase\n", smp_processor_id());
  78. }
  79. /* CHRP with openpic */
  80. struct smp_ops_t chrp_smp_ops = {
  81. .message_pass = smp_openpic_message_pass,
  82. .probe = smp_chrp_probe,
  83. .kick_cpu = smp_chrp_kick_cpu,
  84. .setup_cpu = smp_chrp_setup_cpu,
  85. .give_timebase = smp_chrp_give_timebase,
  86. .take_timebase = smp_chrp_take_timebase,
  87. };