hab_pipe.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2019, 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef HAB_PIPE_H
  7. #define HAB_PIPE_H
  8. struct hab_shared_buf {
  9. uint32_t rd_count; /* volatile cannot be used here */
  10. uint32_t wr_count; /* volatile cannot be used here */
  11. uint32_t size;
  12. unsigned char data[]; /* volatile cannot be used here */
  13. };
  14. /* debug only */
  15. struct dbg_item {
  16. uint32_t rd_cnt;
  17. uint32_t wr_cnt;
  18. void *va; /* local for read or write */
  19. uint32_t index; /* local */
  20. uint32_t sz; /* size in */
  21. uint32_t ret; /* actual bytes read */
  22. };
  23. #define DBG_ITEM_SIZE 20
  24. struct dbg_items {
  25. struct dbg_item it[DBG_ITEM_SIZE];
  26. int idx;
  27. };
  28. struct hab_pipe_endpoint {
  29. struct {
  30. uint32_t wr_count;
  31. uint32_t index;
  32. struct hab_shared_buf *legacy_sh_buf;
  33. } tx_info;
  34. struct {
  35. uint32_t index;
  36. struct hab_shared_buf *legacy_sh_buf;
  37. } rx_info;
  38. };
  39. struct hab_pipe {
  40. struct hab_pipe_endpoint top;
  41. struct hab_pipe_endpoint bottom;
  42. /* Legacy debugging metadata, replaced by dbg_itms from qvm_channel */
  43. struct hab_shared_buf *legacy_buf_a; /* top TX, bottom RX */
  44. struct hab_shared_buf *legacy_buf_b; /* top RX, bottom TX */
  45. size_t legacy_total_size;
  46. unsigned char buf_base[];
  47. };
  48. size_t hab_pipe_calc_required_bytes(const uint32_t shared_buf_size);
  49. struct hab_pipe_endpoint *hab_pipe_init(struct hab_pipe *pipe,
  50. struct hab_shared_buf **tx_buf_p,
  51. struct hab_shared_buf **rx_buf_p,
  52. struct dbg_items **itms,
  53. const uint32_t shared_buf_size, int top);
  54. uint32_t hab_pipe_write(struct hab_pipe_endpoint *ep,
  55. struct hab_shared_buf *sh_buf,
  56. const uint32_t buf_size,
  57. unsigned char *p, uint32_t num_bytes);
  58. void hab_pipe_write_commit(struct hab_pipe_endpoint *ep,
  59. struct hab_shared_buf *sh_buf);
  60. uint32_t hab_pipe_read(struct hab_pipe_endpoint *ep,
  61. struct hab_shared_buf *sh_buf,
  62. const uint32_t buf_size,
  63. unsigned char *p, uint32_t size, uint32_t clear);
  64. /* debug only */
  65. void hab_pipe_rxinfo(struct hab_pipe_endpoint *ep,
  66. struct hab_shared_buf *sh_buf,
  67. uint32_t *rd_cnt,
  68. uint32_t *wr_cnt, uint32_t *idx);
  69. #endif /* HAB_PIPE_H */