mpic_msgr.h 3.5 KB

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