adsprpc_shared.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Copyright (c) 2012-2013,2017 The Linux Foundation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 and
  6. * only version 2 as published by the Free Software Foundation.
  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 ADSPRPC_SHARED_H
  15. #define ADSPRPC_SHARED_H
  16. #include <linux/types.h>
  17. #define FASTRPC_IOCTL_INVOKE _IOWR('R', 1, struct fastrpc_ioctl_invoke)
  18. #define FASTRPC_IOCTL_MMAP _IOWR('R', 2, struct fastrpc_ioctl_mmap)
  19. #define FASTRPC_IOCTL_MUNMAP _IOWR('R', 3, struct fastrpc_ioctl_munmap)
  20. #define FASTRPC_IOCTL_INVOKE_FD _IOWR('R', 4, struct fastrpc_ioctl_invoke_fd)
  21. #define FASTRPC_IOCTL_SETMODE _IOWR('R', 5, uint32_t)
  22. #define FASTRPC_SMD_GUID "fastrpcsmd-apps-dsp"
  23. #define DEVICE_NAME "adsprpc-smd"
  24. /* Driver should operate in parallel with the co-processor */
  25. #define FASTRPC_MODE_PARALLEL 0
  26. /* Driver should operate in serial mode with the co-processor */
  27. #define FASTRPC_MODE_SERIAL 1
  28. /* Retrives number of input buffers from the scalars parameter */
  29. #define REMOTE_SCALARS_INBUFS(sc) (((sc) >> 16) & 0x0ff)
  30. /* Retrives number of output buffers from the scalars parameter */
  31. #define REMOTE_SCALARS_OUTBUFS(sc) (((sc) >> 8) & 0x0ff)
  32. /* Retrives number of input handles from the scalars parameter */
  33. #define REMOTE_SCALARS_INHANDLES(sc) (((sc) >> 4) & 0x0f)
  34. /* Retrives number of output handles from the scalars parameter */
  35. #define REMOTE_SCALARS_OUTHANDLES(sc) ((sc) & 0x0f)
  36. #define REMOTE_SCALARS_LENGTH(sc) (REMOTE_SCALARS_INBUFS(sc) +\
  37. REMOTE_SCALARS_OUTBUFS(sc) +\
  38. REMOTE_SCALARS_INHANDLES(sc) +\
  39. REMOTE_SCALARS_OUTHANDLES(sc))
  40. #define REMOTE_SCALARS_MAKEX(attr, method, in, out, oin, oout) \
  41. ((((uint32_t) (attr) & 0x7) << 29) | \
  42. (((uint32_t) (method) & 0x1f) << 24) | \
  43. (((uint32_t) (in) & 0xff) << 16) | \
  44. (((uint32_t) (out) & 0xff) << 8) | \
  45. (((uint32_t) (oin) & 0x0f) << 4) | \
  46. ((uint32_t) (oout) & 0x0f))
  47. #define REMOTE_SCALARS_MAKE(method, in, out) \
  48. REMOTE_SCALARS_MAKEX(0, method, in, out, 0, 0)
  49. #ifndef VERIFY_PRINT_ERROR
  50. #define VERIFY_EPRINTF(format, args) (void)0
  51. #endif
  52. #ifndef VERIFY_PRINT_INFO
  53. #define VERIFY_IPRINTF(args) (void)0
  54. #endif
  55. #ifndef VERIFY
  56. #define __STR__(x) #x ":"
  57. #define __TOSTR__(x) __STR__(x)
  58. #define __FILE_LINE__ __FILE__ ":" __TOSTR__(__LINE__)
  59. #define VERIFY(err, val) \
  60. do {\
  61. VERIFY_IPRINTF(__FILE_LINE__"info: calling: " #val "\n");\
  62. if (0 == (val)) {\
  63. (err) = (err) == 0 ? -1 : (err);\
  64. VERIFY_EPRINTF(__FILE_LINE__"error: %d: " #val "\n", (err));\
  65. } else {\
  66. VERIFY_IPRINTF(__FILE_LINE__"info: passed: " #val "\n");\
  67. } \
  68. } while (0)
  69. #endif
  70. #define remote_arg_t union remote_arg
  71. struct remote_buf {
  72. void *pv; /* buffer pointer */
  73. size_t len; /* length of buffer */
  74. };
  75. union remote_arg {
  76. struct remote_buf buf; /* buffer info */
  77. uint32_t h; /* remote handle */
  78. };
  79. struct fastrpc_ioctl_invoke {
  80. uint32_t handle; /* remote handle */
  81. uint32_t sc; /* scalars describing the data */
  82. remote_arg_t *pra; /* remote arguments list */
  83. };
  84. struct fastrpc_ioctl_invoke_fd {
  85. struct fastrpc_ioctl_invoke inv;
  86. int *fds; /* fd list */
  87. };
  88. struct fastrpc_ioctl_munmap {
  89. uint32_t vaddrout; /* address to unmap */
  90. size_t size; /* size */
  91. };
  92. struct fastrpc_ioctl_mmap {
  93. int fd; /* ion fd */
  94. uint32_t flags; /* flags for dsp to map with */
  95. uint32_t vaddrin; /* optional virtual address */
  96. size_t size; /* size */
  97. uint32_t vaddrout; /* dsps virtual address */
  98. };
  99. struct smq_null_invoke {
  100. struct smq_invoke_ctx *ctx; /* invoke caller context */
  101. uint32_t handle; /* handle to invoke */
  102. uint32_t sc; /* scalars structure describing the data */
  103. };
  104. struct smq_phy_page {
  105. uint32_t addr; /* physical address */
  106. size_t size; /* size of contiguous region */
  107. };
  108. struct smq_invoke_buf {
  109. int num; /* number of contiguous regions */
  110. int pgidx; /* index to start of contiguous region */
  111. };
  112. struct smq_invoke {
  113. struct smq_null_invoke header;
  114. struct smq_phy_page page; /* remote arg and list of pages address */
  115. };
  116. struct smq_msg {
  117. uint32_t pid; /* process group id */
  118. uint32_t tid; /* thread id */
  119. struct smq_invoke invoke;
  120. };
  121. struct smq_invoke_rsp {
  122. struct smq_invoke_ctx *ctx; /* invoke caller context */
  123. int retval; /* invoke return value */
  124. };
  125. static inline struct smq_invoke_buf *smq_invoke_buf_start(remote_arg_t *pra,
  126. uint32_t sc)
  127. {
  128. unsigned int len = REMOTE_SCALARS_LENGTH(sc);
  129. return (struct smq_invoke_buf *)(&pra[len]);
  130. }
  131. static inline struct smq_phy_page *smq_phy_page_start(uint32_t sc,
  132. struct smq_invoke_buf *buf)
  133. {
  134. uint32_t nTotal = REMOTE_SCALARS_INBUFS(sc)+REMOTE_SCALARS_OUTBUFS(sc);
  135. return (struct smq_phy_page *)(&buf[nTotal]);
  136. }
  137. static inline int smq_invoke_buf_size(uint32_t sc, int nPages)
  138. {
  139. struct smq_phy_page *start = smq_phy_page_start(sc, 0);
  140. return (int)(&(start[nPages]));
  141. }
  142. #endif