mbox-db5500.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) ST-Ericsson SA 2010
  3. * Author: Stefan Nilsson <stefan.xk.nilsson@stericsson.com> for ST-Ericsson.
  4. * Author: Martin Persson <martin.persson@stericsson.com> for ST-Ericsson.
  5. * License terms: GNU General Public License (GPL), version 2.
  6. */
  7. #ifndef __INC_STE_MBOX_H
  8. #define __INC_STE_MBOX_H
  9. #define MBOX_BUF_SIZE 16
  10. #define MBOX_NAME_SIZE 8
  11. /**
  12. * mbox_recv_cb_t - Definition of the mailbox callback.
  13. * @mbox_msg: The mailbox message.
  14. * @priv: The clients private data as specified in the call to mbox_setup.
  15. *
  16. * This function will be called upon reception of new mailbox messages.
  17. */
  18. typedef void mbox_recv_cb_t (u32 mbox_msg, void *priv);
  19. /**
  20. * struct mbox - Mailbox instance struct
  21. * @list: Linked list head.
  22. * @pdev: Pointer to device struct.
  23. * @cb: Callback function. Will be called
  24. * when new data is received.
  25. * @client_data: Clients private data. Will be sent back
  26. * in the callback function.
  27. * @virtbase_peer: Virtual address for outgoing mailbox.
  28. * @virtbase_local: Virtual address for incoming mailbox.
  29. * @buffer: Then internal queue for outgoing messages.
  30. * @name: Name of this mailbox.
  31. * @buffer_available: Completion variable to achieve "blocking send".
  32. * This variable will be signaled when there is
  33. * internal buffer space available.
  34. * @client_blocked: To keep track if any client is currently
  35. * blocked.
  36. * @lock: Spinlock to protect this mailbox instance.
  37. * @write_index: Index in internal buffer to write to.
  38. * @read_index: Index in internal buffer to read from.
  39. * @allocated: Indicates whether this particular mailbox
  40. * id has been allocated by someone.
  41. */
  42. struct mbox {
  43. struct list_head list;
  44. struct platform_device *pdev;
  45. mbox_recv_cb_t *cb;
  46. void *client_data;
  47. void __iomem *virtbase_peer;
  48. void __iomem *virtbase_local;
  49. u32 buffer[MBOX_BUF_SIZE];
  50. char name[MBOX_NAME_SIZE];
  51. struct completion buffer_available;
  52. u8 client_blocked;
  53. spinlock_t lock;
  54. u8 write_index;
  55. u8 read_index;
  56. bool allocated;
  57. };
  58. /**
  59. * mbox_setup - Set up a mailbox and return its instance.
  60. * @mbox_id: The ID number of the mailbox. 0 or 1 for modem CPU,
  61. * 2 for modem DSP.
  62. * @mbox_cb: Pointer to the callback function to be called when a new message
  63. * is received.
  64. * @priv: Client user data which will be returned in the callback.
  65. *
  66. * Returns a mailbox instance to be specified in subsequent calls to mbox_send.
  67. */
  68. struct mbox *mbox_setup(u8 mbox_id, mbox_recv_cb_t *mbox_cb, void *priv);
  69. /**
  70. * mbox_send - Send a mailbox message.
  71. * @mbox: Mailbox instance (returned by mbox_setup)
  72. * @mbox_msg: The mailbox message to send.
  73. * @block: Specifies whether this call will block until send is possible,
  74. * or return an error if the mailbox buffer is full.
  75. *
  76. * Returns 0 on success or a negative error code on error. -ENOMEM indicates
  77. * that the internal buffer is full and you have to try again later (or
  78. * specify "block" in order to block until send is possible).
  79. */
  80. int mbox_send(struct mbox *mbox, u32 mbox_msg, bool block);
  81. #endif /*INC_STE_MBOX_H*/