chrp_smp.c 2.1 KB

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