hcall_msgq.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2021, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __GH_HCALL_MSGQ_H
  6. #define __GH_HCALL_MSGQ_H
  7. #include <linux/err.h>
  8. #include <linux/types.h>
  9. #include <linux/gunyah/hcall_common.h>
  10. #include <linux/gunyah/gh_common.h>
  11. #include <asm/gunyah/hcall.h>
  12. static inline int gh_hcall_msgq_bind_send(gh_capid_t msgq_capid,
  13. gh_capid_t vic_capid,
  14. gh_virq_handle_t virq_info)
  15. {
  16. struct gh_hcall_resp _resp = {0};
  17. return _gh_hcall(0x6017,
  18. (struct gh_hcall_args){ msgq_capid, vic_capid,
  19. virq_info },
  20. &_resp);
  21. }
  22. static inline int gh_hcall_msgq_bind_recv(gh_capid_t msgq_capid,
  23. gh_capid_t vic_capid,
  24. gh_virq_handle_t virq_info)
  25. {
  26. struct gh_hcall_resp _resp = {0};
  27. return _gh_hcall(0x6018,
  28. (struct gh_hcall_args){ msgq_capid, vic_capid,
  29. virq_info },
  30. &_resp);
  31. }
  32. static inline int gh_hcall_msgq_unbind_send(gh_capid_t msgq_capid)
  33. {
  34. struct gh_hcall_resp _resp = {0};
  35. return _gh_hcall(0x6019, (struct gh_hcall_args){ msgq_capid }, &_resp);
  36. }
  37. static inline int gh_hcall_msgq_unbind_recv(gh_capid_t msgq_capid)
  38. {
  39. struct gh_hcall_resp _resp = {0};
  40. return _gh_hcall(0x601A, (struct gh_hcall_args){ msgq_capid }, &_resp);
  41. }
  42. struct gh_hcall_msgq_send_resp {
  43. bool not_full;
  44. };
  45. static inline int gh_hcall_msgq_send(gh_capid_t msgq_capid, size_t size,
  46. void *data, u64 send_flags,
  47. struct gh_hcall_msgq_send_resp *resp)
  48. {
  49. int ret;
  50. struct gh_hcall_resp _resp = {0};
  51. ret = _gh_hcall(0x601B,
  52. (struct gh_hcall_args){ msgq_capid, size, (unsigned long)data,
  53. send_flags },
  54. &_resp);
  55. if (!ret && resp)
  56. resp->not_full = _resp.resp1;
  57. return ret;
  58. }
  59. struct gh_hcall_msgq_recv_resp {
  60. size_t recv_size;
  61. bool not_empty;
  62. };
  63. static inline int gh_hcall_msgq_recv(gh_capid_t msgq_capid, void *buffer,
  64. size_t max_size,
  65. struct gh_hcall_msgq_recv_resp *resp)
  66. {
  67. int ret;
  68. struct gh_hcall_resp _resp = {0};
  69. ret = _gh_hcall(0x601C,
  70. (struct gh_hcall_args){ msgq_capid, (unsigned long)buffer,
  71. max_size },
  72. &_resp);
  73. if (!ret && resp) {
  74. resp->recv_size = _resp.resp1;
  75. resp->not_empty = _resp.resp2;
  76. }
  77. return ret;
  78. }
  79. static inline int gh_hcall_msgq_flush(gh_capid_t msgq_capid)
  80. {
  81. struct gh_hcall_resp _resp = {0};
  82. return _gh_hcall(0x601D, (struct gh_hcall_args){ msgq_capid }, &_resp);
  83. }
  84. static inline int gh_hcall_msgq_configure_send(gh_capid_t msgq_capid,
  85. long not_full_threshold,
  86. long not_full_delay)
  87. {
  88. struct gh_hcall_resp _resp = {0};
  89. return _gh_hcall(0x601F,
  90. (struct gh_hcall_args){ msgq_capid, not_full_threshold,
  91. not_full_delay, -1 },
  92. &_resp);
  93. }
  94. static inline int gh_hcall_msgq_configure_recv(gh_capid_t msgq_capid,
  95. long not_empty_threshold,
  96. long not_empty_delay)
  97. {
  98. struct gh_hcall_resp _resp = {0};
  99. return _gh_hcall(0x6020,
  100. (struct gh_hcall_args){ msgq_capid, not_empty_threshold,
  101. not_empty_delay, -1 },
  102. &_resp);
  103. }
  104. #endif