rpmsg_rpc.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Remote Processor Procedure Call Driver
  3. *
  4. * Copyright (C) 2012-2017 Texas Instruments Incorporated - http://www.ti.com/
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in
  14. * the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name Texas Instruments nor the names of its
  17. * contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #ifndef _UAPI_LINUX_RPMSG_RPC_H_
  33. #define _UAPI_LINUX_RPMSG_RPC_H_
  34. #include <linux/ioctl.h>
  35. /**
  36. * struct rppc_buf_fds - rppc buffer registration/deregistration
  37. * @num: number of file descriptors
  38. * @fds: pointer to the array holding the file descriptors
  39. */
  40. struct rppc_buf_fds {
  41. uint32_t num;
  42. int32_t *fds;
  43. };
  44. /*
  45. * ioctl definitions
  46. */
  47. #define RPPC_IOC_MAGIC 'r'
  48. #define RPPC_IOC_CREATE _IOW(RPPC_IOC_MAGIC, 1, char *)
  49. #define RPPC_IOC_BUFREGISTER _IOW(RPPC_IOC_MAGIC, 2, struct rppc_buf_fds)
  50. #define RPPC_IOC_BUFUNREGISTER _IOW(RPPC_IOC_MAGIC, 3, struct rppc_buf_fds)
  51. #define RPPC_IOC_MAXNR (4)
  52. #define RPPC_MAX_PARAMETERS (10)
  53. #define RPPC_MAX_TRANSLATIONS (1024)
  54. #define RPPC_MAX_INST_NAMELEN (48)
  55. /**
  56. * enum rppc_param_type - RPC function parameter type
  57. * @RPPC_PARAM_TYPE_UNKNOWN: unrecognized parameter
  58. * @RPPC_PARAM_TYPE_ATOMIC: an atomic data type, 1 byte to architecture limit
  59. * sized bytes
  60. * @RPPC_PARAM_TYPE_PTR: a pointer to shared memory. The fd field in the
  61. * structures rppc_param and rppc_param_translation must
  62. * contain the file descriptor of the associated dma_buf
  63. * @RPPC_PARAM_TYPE_STRUCT: (unsupported) a structure type. Will be architecture
  64. * width aligned in memory
  65. *
  66. * These enum values are used to identify the parameter type for every
  67. * parameter argument of the remote function.
  68. */
  69. enum rppc_param_type {
  70. RPPC_PARAM_TYPE_UNKNOWN = 0,
  71. RPPC_PARAM_TYPE_ATOMIC,
  72. RPPC_PARAM_TYPE_PTR,
  73. RPPC_PARAM_TYPE_STRUCT,
  74. };
  75. /**
  76. * struct rppc_param_translation - pointer translation helper structure
  77. * @index: index of the parameter where the translation needs to be done in.
  78. * used for computing the primary offset and mapping into kernel
  79. * the page from the buffer referred to in the corresponding parameter
  80. * @offset: offset from the primary base pointer to the pointer to translate.
  81. * This is the secondary offset, and used either for mentioning the
  82. * offset from an structure array element base, or within a single
  83. * structure which itself is at an offset in an allocated buffer
  84. * @base: the base user virtual address of the pointer to translate (used to
  85. * calculate translated pointer offset)
  86. * @fd: dma_buf file descriptor of the allocated buffer pointer within which
  87. * the translated pointer is present
  88. */
  89. struct rppc_param_translation {
  90. uint32_t index;
  91. ptrdiff_t offset;
  92. size_t base;
  93. int32_t fd;
  94. };
  95. /**
  96. * struct rppc_param - descriptor structure for each parameter
  97. * @type: type of the parameter, as dictated by enum rppc_param_type
  98. * @size: size of the data (for atomic types) or size of the containing
  99. * structure in which translations are performed
  100. * @data: either the parameter value itself (for atomic type) or
  101. * the actual user space pointer address to the data (for pointer type)
  102. * @base: the base user space pointer address of the original allocated buffer,
  103. * providing a reference if data has the pointer that is at an offset
  104. * from the original pointer
  105. * @fd: file descriptor of the exported allocation (will be used to
  106. * import the associated dma_buf within the driver).
  107. */
  108. struct rppc_param {
  109. uint32_t type;
  110. size_t size;
  111. size_t data;
  112. size_t base;
  113. int32_t fd;
  114. };
  115. /**
  116. * struct rppc_function - descriptor structure for the remote function
  117. * @fxn_id: index of the function to invoke on the opened rppc device
  118. * @num_params: number of parameters filled in the params field
  119. * @params: array of parameter descriptor structures
  120. * @num_translations: number of in-place translations to be performed within
  121. * the arguments.
  122. * @translations: an open array of the translation descriptor structures, whose
  123. * length is given in @num_translations. Used for translating
  124. * the pointers within the function data.
  125. *
  126. * This is the primary descriptor structure passed down from the userspace,
  127. * describing the function, its parameter arguments and the needed translations.
  128. */
  129. struct rppc_function {
  130. uint32_t fxn_id;
  131. uint32_t num_params;
  132. struct rppc_param params[RPPC_MAX_PARAMETERS];
  133. uint32_t num_translations;
  134. struct rppc_param_translation translations[0];
  135. };
  136. /**
  137. * struct rppc_function_return - function return status descriptor structure
  138. * @fxn_id: index of the function invoked on the opened rppc device
  139. * @status: return value of the executed function
  140. */
  141. struct rppc_function_return {
  142. uint32_t fxn_id;
  143. uint32_t status;
  144. };
  145. /**
  146. * struct rppc_create_instance - rppc channel connector helper
  147. * @name: Name of the rppc server device to establish a connection with
  148. */
  149. struct rppc_create_instance {
  150. char name[RPPC_MAX_INST_NAMELEN];
  151. };
  152. /*
  153. * helper macros for manipulating the function index in the marshalled packet
  154. */
  155. #define RPPC_DESC_EXEC_SYNC (0x0100)
  156. #define RPPC_DESC_TYPE_MASK (0x0F00)
  157. /*
  158. * helper macros for manipulating the function index in the marshalled packet.
  159. * The remote functions are offset by one relative to the client
  160. * XXX: Remove the relative offset
  161. */
  162. #define RPPC_SET_FXN_IDX(idx) (((idx) + 1) | 0x80000000)
  163. #define RPPC_FXN_MASK(idx) (((idx) - 1) & 0x7FFFFFFF)
  164. /**
  165. * struct rppc_packet - the actual marshalled packet
  166. * @desc: type of function execution, currently only synchronous function
  167. * invocations are supported
  168. * @msg_id: an incremental message index identifier
  169. * @flags: a combination of job id and pool id of the worker threads
  170. * of the server
  171. * @fxn_id: id of the function to execute
  172. * @result: result of the remotely executed function
  173. * @data_size: size of the payload packet
  174. * @data: variable payload, containing the marshalled function data.
  175. *
  176. * This is actually a condensed structure of the Remote Command Messaging
  177. * (RCM) structure. The initial fields of the structure are used by the
  178. * remote-side server to schedule the execution of the function. The actual
  179. * variable payload data starts from the .data field. This marshalled packet
  180. * is the payload for a rpmsg message.
  181. *
  182. * XXX: remove or mask unneeded fields, some fields can be stripped down
  183. */
  184. struct rppc_packet {
  185. uint16_t desc;
  186. uint16_t msg_id;
  187. uint32_t flags;
  188. uint32_t fxn_id;
  189. int32_t result;
  190. uint32_t data_size;
  191. uint8_t data[0];
  192. } __packed;
  193. #endif /* _UAPI_LINUX_RPMSG_RPC_H_ */