mailbox.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Mailbox internal functions
  3. *
  4. * Copyright (C) 2006 Nokia Corporation
  5. * Written by: Hiroshi DOYU <Hiroshi.DOYU@nokia.com>
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #ifndef __ARCH_ARM_PLAT_MAILBOX_H
  12. #define __ARCH_ARM_PLAT_MAILBOX_H
  13. /*
  14. * Mailbox sequence bit API
  15. */
  16. #if defined(CONFIG_ARCH_OMAP1)
  17. # define MBOX_USE_SEQ_BIT
  18. #elif defined(CONFIG_ARCH_OMAP2)
  19. # define MBOX_USE_SEQ_BIT
  20. #endif
  21. #ifdef MBOX_USE_SEQ_BIT
  22. /* seq_rcv should be initialized with any value other than
  23. * 0 and 1 << 31, to allow either value for the first
  24. * message. */
  25. static inline void mbox_seq_init(struct omap_mbox *mbox)
  26. {
  27. /* any value other than 0 and 1 << 31 */
  28. mbox->seq_rcv = 0xffffffff;
  29. }
  30. static inline void mbox_seq_toggle(struct omap_mbox *mbox, mbox_msg_t * msg)
  31. {
  32. /* add seq_snd to msg */
  33. *msg = (*msg & 0x7fffffff) | mbox->seq_snd;
  34. /* flip seq_snd */
  35. mbox->seq_snd ^= 1 << 31;
  36. }
  37. static inline int mbox_seq_test(struct omap_mbox *mbox, mbox_msg_t msg)
  38. {
  39. mbox_msg_t seq = msg & (1 << 31);
  40. if (seq == mbox->seq_rcv)
  41. return -1;
  42. mbox->seq_rcv = seq;
  43. return 0;
  44. }
  45. #else
  46. static inline void mbox_seq_init(struct omap_mbox *mbox)
  47. {
  48. }
  49. static inline void mbox_seq_toggle(struct omap_mbox *mbox, mbox_msg_t * msg)
  50. {
  51. }
  52. static inline int mbox_seq_test(struct omap_mbox *mbox, mbox_msg_t msg)
  53. {
  54. return 0;
  55. }
  56. #endif
  57. /* Mailbox FIFO handle functions */
  58. static inline mbox_msg_t mbox_fifo_read(struct omap_mbox *mbox)
  59. {
  60. return mbox->ops->fifo_read(mbox);
  61. }
  62. static inline void mbox_fifo_write(struct omap_mbox *mbox, mbox_msg_t msg)
  63. {
  64. mbox->ops->fifo_write(mbox, msg);
  65. }
  66. static inline int mbox_fifo_empty(struct omap_mbox *mbox)
  67. {
  68. return mbox->ops->fifo_empty(mbox);
  69. }
  70. static inline int mbox_fifo_full(struct omap_mbox *mbox)
  71. {
  72. return mbox->ops->fifo_full(mbox);
  73. }
  74. /* Mailbox IRQ handle functions */
  75. static inline void enable_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
  76. {
  77. mbox->ops->enable_irq(mbox, irq);
  78. }
  79. static inline void disable_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
  80. {
  81. mbox->ops->disable_irq(mbox, irq);
  82. }
  83. static inline void ack_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
  84. {
  85. if (mbox->ops->ack_irq)
  86. mbox->ops->ack_irq(mbox, irq);
  87. }
  88. static inline int is_mbox_irq(struct omap_mbox *mbox, omap_mbox_irq_t irq)
  89. {
  90. return mbox->ops->is_irq(mbox, irq);
  91. }
  92. #endif /* __ARCH_ARM_PLAT_MAILBOX_H */