mpic_msgr.h 3.5 KB

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