trusty_ipc.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (C) 2015 Google, Inc.
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. */
  14. #ifndef __LINUX_TRUSTY_TRUSTY_IPC_H
  15. #define __LINUX_TRUSTY_TRUSTY_IPC_H
  16. struct tipc_chan;
  17. struct tipc_msg_buf {
  18. void *buf_va;
  19. phys_addr_t buf_pa;
  20. size_t buf_sz;
  21. size_t wpos;
  22. size_t rpos;
  23. struct list_head node;
  24. };
  25. enum tipc_chan_event {
  26. TIPC_CHANNEL_CONNECTED = 1,
  27. TIPC_CHANNEL_DISCONNECTED,
  28. TIPC_CHANNEL_SHUTDOWN,
  29. };
  30. struct tipc_chan_ops {
  31. void (*handle_event)(void *cb_arg, int event);
  32. struct tipc_msg_buf *(*handle_msg)(void *cb_arg,
  33. struct tipc_msg_buf *mb);
  34. };
  35. struct tipc_chan *tipc_create_channel(struct device *dev,
  36. const struct tipc_chan_ops *ops,
  37. void *cb_arg);
  38. int tipc_chan_connect(struct tipc_chan *chan, const char *port);
  39. int tipc_chan_queue_msg(struct tipc_chan *chan, struct tipc_msg_buf *mb);
  40. int tipc_chan_shutdown(struct tipc_chan *chan);
  41. void tipc_chan_destroy(struct tipc_chan *chan);
  42. struct tipc_msg_buf *tipc_chan_get_rxbuf(struct tipc_chan *chan);
  43. void tipc_chan_put_rxbuf(struct tipc_chan *chan, struct tipc_msg_buf *mb);
  44. struct tipc_msg_buf *
  45. tipc_chan_get_txbuf_timeout(struct tipc_chan *chan, long timeout);
  46. void tipc_chan_put_txbuf(struct tipc_chan *chan, struct tipc_msg_buf *mb);
  47. static inline size_t mb_avail_space(struct tipc_msg_buf *mb)
  48. {
  49. return mb->buf_sz - mb->wpos;
  50. }
  51. static inline size_t mb_avail_data(struct tipc_msg_buf *mb)
  52. {
  53. return mb->wpos - mb->rpos;
  54. }
  55. static inline void *mb_put_data(struct tipc_msg_buf *mb, size_t len)
  56. {
  57. void *pos = (u8 *)mb->buf_va + mb->wpos;
  58. BUG_ON(mb->wpos + len > mb->buf_sz);
  59. mb->wpos += len;
  60. return pos;
  61. }
  62. static inline void *mb_get_data(struct tipc_msg_buf *mb, size_t len)
  63. {
  64. void *pos = (u8 *)mb->buf_va + mb->rpos;
  65. BUG_ON(mb->rpos + len > mb->wpos);
  66. mb->rpos += len;
  67. return pos;
  68. }
  69. #endif /* __LINUX_TRUSTY_TRUSTY_IPC_H */