dbell.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Author: Kumar Gala <galak@kernel.crashing.org>
  3. *
  4. * Copyright 2009 Freescale Semiconductor Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <linux/stddef.h>
  12. #include <linux/kernel.h>
  13. #include <linux/smp.h>
  14. #include <linux/threads.h>
  15. #include <linux/hardirq.h>
  16. #include <asm/dbell.h>
  17. #include <asm/irq_regs.h>
  18. #include <asm/kvm_ppc.h>
  19. #ifdef CONFIG_SMP
  20. /*
  21. * Doorbells must only be used if CPU_FTR_DBELL is available.
  22. * msgsnd is used in HV, and msgsndp is used in !HV.
  23. *
  24. * These should be used by platform code that is aware of restrictions.
  25. * Other arch code should use ->cause_ipi.
  26. *
  27. * doorbell_global_ipi() sends a dbell to any target CPU.
  28. * Must be used only by architectures that address msgsnd target
  29. * by PIR/get_hard_smp_processor_id.
  30. */
  31. void doorbell_global_ipi(int cpu)
  32. {
  33. u32 tag = get_hard_smp_processor_id(cpu);
  34. kvmppc_set_host_ipi(cpu);
  35. /* Order previous accesses vs. msgsnd, which is treated as a store */
  36. ppc_msgsnd_sync();
  37. ppc_msgsnd(PPC_DBELL_MSGTYPE, 0, tag);
  38. }
  39. /*
  40. * doorbell_core_ipi() sends a dbell to a target CPU in the same core.
  41. * Must be used only by architectures that address msgsnd target
  42. * by TIR/cpu_thread_in_core.
  43. */
  44. void doorbell_core_ipi(int cpu)
  45. {
  46. u32 tag = cpu_thread_in_core(cpu);
  47. kvmppc_set_host_ipi(cpu);
  48. /* Order previous accesses vs. msgsnd, which is treated as a store */
  49. ppc_msgsnd_sync();
  50. ppc_msgsnd(PPC_DBELL_MSGTYPE, 0, tag);
  51. }
  52. /*
  53. * Attempt to cause a core doorbell if destination is on the same core.
  54. * Returns 1 on success, 0 on failure.
  55. */
  56. int doorbell_try_core_ipi(int cpu)
  57. {
  58. int this_cpu = get_cpu();
  59. int ret = 0;
  60. if (cpumask_test_cpu(cpu, cpu_sibling_mask(this_cpu))) {
  61. doorbell_core_ipi(cpu);
  62. ret = 1;
  63. }
  64. put_cpu();
  65. return ret;
  66. }
  67. void doorbell_exception(struct pt_regs *regs)
  68. {
  69. struct pt_regs *old_regs = set_irq_regs(regs);
  70. irq_enter();
  71. ppc_msgsync();
  72. may_hard_irq_enable();
  73. kvmppc_clear_host_ipi(smp_processor_id());
  74. __this_cpu_inc(irq_stat.doorbell_irqs);
  75. smp_ipi_demux_relaxed(); /* already performed the barrier */
  76. irq_exit();
  77. set_irq_regs(old_regs);
  78. }
  79. #else /* CONFIG_SMP */
  80. void doorbell_exception(struct pt_regs *regs)
  81. {
  82. printk(KERN_WARNING "Received doorbell on non-smp system\n");
  83. }
  84. #endif /* CONFIG_SMP */