dbell.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright 2009 Freescale Semiconductor, Inc.
  4. *
  5. * provides masks and opcode images for use by code generation, emulation
  6. * and for instructions that older assemblers might not know about
  7. */
  8. #ifndef _ASM_POWERPC_DBELL_H
  9. #define _ASM_POWERPC_DBELL_H
  10. #include <linux/smp.h>
  11. #include <linux/threads.h>
  12. #include <asm/cputhreads.h>
  13. #include <asm/ppc-opcode.h>
  14. #include <asm/feature-fixups.h>
  15. #include <asm/kvm_ppc.h>
  16. #define PPC_DBELL_MSG_BRDCAST (0x04000000)
  17. #define PPC_DBELL_TYPE(x) (((x) & 0xf) << (63-36))
  18. #define PPC_DBELL_TYPE_MASK PPC_DBELL_TYPE(0xf)
  19. #define PPC_DBELL_LPID(x) ((x) << (63 - 49))
  20. #define PPC_DBELL_PIR_MASK 0x3fff
  21. enum ppc_dbell {
  22. PPC_DBELL = 0, /* doorbell */
  23. PPC_DBELL_CRIT = 1, /* critical doorbell */
  24. PPC_G_DBELL = 2, /* guest doorbell */
  25. PPC_G_DBELL_CRIT = 3, /* guest critical doorbell */
  26. PPC_G_DBELL_MC = 4, /* guest mcheck doorbell */
  27. PPC_DBELL_SERVER = 5, /* doorbell on server */
  28. };
  29. #ifdef CONFIG_PPC_BOOK3S
  30. #define PPC_DBELL_MSGTYPE PPC_DBELL_SERVER
  31. static inline void _ppc_msgsnd(u32 msg)
  32. {
  33. __asm__ __volatile__ (ASM_FTR_IFSET(PPC_MSGSND(%1), PPC_MSGSNDP(%1), %0)
  34. : : "i" (CPU_FTR_HVMODE), "r" (msg));
  35. }
  36. /* sync before sending message */
  37. static inline void ppc_msgsnd_sync(void)
  38. {
  39. __asm__ __volatile__ ("sync" : : : "memory");
  40. }
  41. /* sync after taking message interrupt */
  42. static inline void ppc_msgsync(void)
  43. {
  44. /* sync is not required when taking messages from the same core */
  45. __asm__ __volatile__ (ASM_FTR_IFSET(PPC_MSGSYNC " ; lwsync", "", %0)
  46. : : "i" (CPU_FTR_HVMODE|CPU_FTR_ARCH_300));
  47. }
  48. static inline void _ppc_msgclr(u32 msg)
  49. {
  50. __asm__ __volatile__ (ASM_FTR_IFSET(PPC_MSGCLR(%1), PPC_MSGCLRP(%1), %0)
  51. : : "i" (CPU_FTR_HVMODE), "r" (msg));
  52. }
  53. static inline void ppc_msgclr(enum ppc_dbell type)
  54. {
  55. u32 msg = PPC_DBELL_TYPE(type);
  56. _ppc_msgclr(msg);
  57. }
  58. #else /* CONFIG_PPC_BOOK3S */
  59. #define PPC_DBELL_MSGTYPE PPC_DBELL
  60. static inline void _ppc_msgsnd(u32 msg)
  61. {
  62. __asm__ __volatile__ (PPC_MSGSND(%0) : : "r" (msg));
  63. }
  64. /* sync before sending message */
  65. static inline void ppc_msgsnd_sync(void)
  66. {
  67. __asm__ __volatile__ ("sync" : : : "memory");
  68. }
  69. /* sync after taking message interrupt */
  70. static inline void ppc_msgsync(void)
  71. {
  72. }
  73. #endif /* CONFIG_PPC_BOOK3S */
  74. extern void doorbell_exception(struct pt_regs *regs);
  75. static inline void ppc_msgsnd(enum ppc_dbell type, u32 flags, u32 tag)
  76. {
  77. u32 msg = PPC_DBELL_TYPE(type) | (flags & PPC_DBELL_MSG_BRDCAST) |
  78. (tag & 0x07ffffff);
  79. _ppc_msgsnd(msg);
  80. }
  81. #ifdef CONFIG_SMP
  82. /*
  83. * Doorbells must only be used if CPU_FTR_DBELL is available.
  84. * msgsnd is used in HV, and msgsndp is used in !HV.
  85. *
  86. * These should be used by platform code that is aware of restrictions.
  87. * Other arch code should use ->cause_ipi.
  88. *
  89. * doorbell_global_ipi() sends a dbell to any target CPU.
  90. * Must be used only by architectures that address msgsnd target
  91. * by PIR/get_hard_smp_processor_id.
  92. */
  93. static inline void doorbell_global_ipi(int cpu)
  94. {
  95. u32 tag = get_hard_smp_processor_id(cpu);
  96. kvmppc_set_host_ipi(cpu);
  97. /* Order previous accesses vs. msgsnd, which is treated as a store */
  98. ppc_msgsnd_sync();
  99. ppc_msgsnd(PPC_DBELL_MSGTYPE, 0, tag);
  100. }
  101. /*
  102. * doorbell_core_ipi() sends a dbell to a target CPU in the same core.
  103. * Must be used only by architectures that address msgsnd target
  104. * by TIR/cpu_thread_in_core.
  105. */
  106. static inline void doorbell_core_ipi(int cpu)
  107. {
  108. u32 tag = cpu_thread_in_core(cpu);
  109. kvmppc_set_host_ipi(cpu);
  110. /* Order previous accesses vs. msgsnd, which is treated as a store */
  111. ppc_msgsnd_sync();
  112. ppc_msgsnd(PPC_DBELL_MSGTYPE, 0, tag);
  113. }
  114. /*
  115. * Attempt to cause a core doorbell if destination is on the same core.
  116. * Returns 1 on success, 0 on failure.
  117. */
  118. static inline int doorbell_try_core_ipi(int cpu)
  119. {
  120. int this_cpu = get_cpu();
  121. int ret = 0;
  122. if (cpumask_test_cpu(cpu, cpu_sibling_mask(this_cpu))) {
  123. doorbell_core_ipi(cpu);
  124. ret = 1;
  125. }
  126. put_cpu();
  127. return ret;
  128. }
  129. #endif /* CONFIG_SMP */
  130. #endif /* _ASM_POWERPC_DBELL_H */