mpic_msgr.h 3.5 KB

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