mpic_msgr.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2011-2012, Meador Inge, Mentor Graphics Corporation.
  4. */
  5. #ifndef _ASM_MPIC_MSGR_H
  6. #define _ASM_MPIC_MSGR_H
  7. #include <linux/types.h>
  8. #include <linux/spinlock.h>
  9. #include <asm/smp.h>
  10. #include <asm/io.h>
  11. struct mpic_msgr {
  12. u32 __iomem *base;
  13. u32 __iomem *mer;
  14. int irq;
  15. unsigned char in_use;
  16. raw_spinlock_t lock;
  17. int num;
  18. };
  19. /* Get a message register
  20. *
  21. * @reg_num: the MPIC message register to get
  22. *
  23. * A pointer to the message register is returned. If
  24. * the message register asked for is already in use, then
  25. * EBUSY is returned. If the number given is not associated
  26. * with an actual message register, then ENODEV is returned.
  27. * Successfully getting the register marks it as in use.
  28. */
  29. extern struct mpic_msgr *mpic_msgr_get(unsigned int reg_num);
  30. /* Relinquish a message register
  31. *
  32. * @msgr: the message register to return
  33. *
  34. * Disables the given message register and marks it as free.
  35. * After this call has completed successully the message
  36. * register is available to be acquired by a call to
  37. * mpic_msgr_get.
  38. */
  39. extern void mpic_msgr_put(struct mpic_msgr *msgr);
  40. /* Enable a message register
  41. *
  42. * @msgr: the message register to enable
  43. *
  44. * The given message register is enabled for sending
  45. * messages.
  46. */
  47. extern void mpic_msgr_enable(struct mpic_msgr *msgr);
  48. /* Disable a message register
  49. *
  50. * @msgr: the message register to disable
  51. *
  52. * The given message register is disabled for sending
  53. * messages.
  54. */
  55. extern void mpic_msgr_disable(struct mpic_msgr *msgr);
  56. /* Write a message to a message register
  57. *
  58. * @msgr: the message register to write to
  59. * @message: the message to write
  60. *
  61. * The given 32-bit message is written to the given message
  62. * register. Writing to an enabled message registers fires
  63. * an interrupt.
  64. */
  65. static inline void mpic_msgr_write(struct mpic_msgr *msgr, u32 message)
  66. {
  67. out_be32(msgr->base, message);
  68. }
  69. /* Read a message from a message register
  70. *
  71. * @msgr: the message register to read from
  72. *
  73. * Returns the 32-bit value currently in the given message register.
  74. * Upon reading the register any interrupts for that register are
  75. * cleared.
  76. */
  77. static inline u32 mpic_msgr_read(struct mpic_msgr *msgr)
  78. {
  79. return in_be32(msgr->base);
  80. }
  81. /* Clear a message register
  82. *
  83. * @msgr: the message register to clear
  84. *
  85. * Clears any interrupts associated with the given message register.
  86. */
  87. static inline void mpic_msgr_clear(struct mpic_msgr *msgr)
  88. {
  89. (void) mpic_msgr_read(msgr);
  90. }
  91. /* Set the destination CPU for the message register
  92. *
  93. * @msgr: the message register whose destination is to be set
  94. * @cpu_num: the Linux CPU number to bind the message register to
  95. *
  96. * Note that the CPU number given is the CPU number used by the kernel
  97. * and *not* the actual hardware CPU number.
  98. */
  99. static inline void mpic_msgr_set_destination(struct mpic_msgr *msgr,
  100. u32 cpu_num)
  101. {
  102. out_be32(msgr->base, 1 << get_hard_smp_processor_id(cpu_num));
  103. }
  104. /* Get the IRQ number for the message register
  105. * @msgr: the message register whose IRQ is to be returned
  106. *
  107. * Returns the IRQ number associated with the given message register.
  108. * 0 is returned if this message register is not capable of receiving
  109. * interrupts. What message register can and cannot receive interrupts is
  110. * specified in the device tree for the system.
  111. */
  112. static inline int mpic_msgr_get_irq(struct mpic_msgr *msgr)
  113. {
  114. return msgr->irq;
  115. }
  116. #endif