smp.c 1.9 KB

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