smp.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/kernel.h>
  11. #include <linux/sched.h>
  12. #include <linux/smp.h>
  13. #include <linux/smp_lock.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/kernel_stat.h>
  16. #include <linux/delay.h>
  17. #include <linux/init.h>
  18. #include <linux/spinlock.h>
  19. #include <asm/ptrace.h>
  20. #include <asm/atomic.h>
  21. #include <asm/irq.h>
  22. #include <asm/page.h>
  23. #include <asm/pgtable.h>
  24. #include <asm/sections.h>
  25. #include <asm/io.h>
  26. #include <asm/prom.h>
  27. #include <asm/smp.h>
  28. #include <asm/residual.h>
  29. #include <asm/time.h>
  30. #include <asm/machdep.h>
  31. #include <asm/smp.h>
  32. #include <asm/mpic.h>
  33. #include <asm/rtas.h>
  34. static void __devinit smp_chrp_kick_cpu(int nr)
  35. {
  36. *(unsigned long *)KERNELBASE = nr;
  37. asm volatile("dcbf 0,%0"::"r"(KERNELBASE):"memory");
  38. }
  39. static void __devinit smp_chrp_setup_cpu(int cpu_nr)
  40. {
  41. mpic_setup_this_cpu();
  42. }
  43. static DEFINE_SPINLOCK(timebase_lock);
  44. static unsigned int timebase_upper = 0, timebase_lower = 0;
  45. void __devinit smp_chrp_give_timebase(void)
  46. {
  47. spin_lock(&timebase_lock);
  48. rtas_call(rtas_token("freeze-time-base"), 0, 1, NULL);
  49. timebase_upper = get_tbu();
  50. timebase_lower = get_tbl();
  51. spin_unlock(&timebase_lock);
  52. while (timebase_upper || timebase_lower)
  53. barrier();
  54. rtas_call(rtas_token("thaw-time-base"), 0, 1, NULL);
  55. }
  56. void __devinit smp_chrp_take_timebase(void)
  57. {
  58. while (!(timebase_upper || timebase_lower))
  59. barrier();
  60. spin_lock(&timebase_lock);
  61. set_tb(timebase_upper, timebase_lower);
  62. timebase_upper = 0;
  63. timebase_lower = 0;
  64. spin_unlock(&timebase_lock);
  65. printk("CPU %i taken timebase\n", smp_processor_id());
  66. }
  67. /* CHRP with openpic */
  68. struct smp_ops_t chrp_smp_ops = {
  69. .message_pass = smp_mpic_message_pass,
  70. .probe = smp_mpic_probe,
  71. .kick_cpu = smp_chrp_kick_cpu,
  72. .setup_cpu = smp_chrp_setup_cpu,
  73. .give_timebase = smp_chrp_give_timebase,
  74. .take_timebase = smp_chrp_take_timebase,
  75. };