rpmsg_rpc.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */
  2. /*
  3. * Remote Processor Procedure Call Driver
  4. *
  5. * Copyright (C) 2012-2019 Texas Instruments Incorporated - http://www.ti.com/
  6. */
  7. #ifndef _UAPI_LINUX_RPMSG_RPC_H_
  8. #define _UAPI_LINUX_RPMSG_RPC_H_
  9. #include <linux/ioctl.h>
  10. /**
  11. * struct rppc_buf_fds - rppc buffer registration/deregistration
  12. * @num: number of file descriptors
  13. * @fds: pointer to the array holding the file descriptors
  14. */
  15. struct rppc_buf_fds {
  16. uint32_t num;
  17. int32_t *fds;
  18. };
  19. /*
  20. * ioctl definitions
  21. */
  22. #define RPPC_IOC_MAGIC 'r'
  23. #define RPPC_IOC_CREATE _IOW(RPPC_IOC_MAGIC, 1, char *)
  24. #define RPPC_IOC_BUFREGISTER _IOW(RPPC_IOC_MAGIC, 2, struct rppc_buf_fds)
  25. #define RPPC_IOC_BUFUNREGISTER _IOW(RPPC_IOC_MAGIC, 3, struct rppc_buf_fds)
  26. #define RPPC_IOC_MAXNR (4)
  27. #define RPPC_MAX_PARAMETERS (10)
  28. #define RPPC_MAX_TRANSLATIONS (1024)
  29. #define RPPC_MAX_INST_NAMELEN (48)
  30. /**
  31. * enum rppc_param_type - RPC function parameter type
  32. * @RPPC_PARAM_TYPE_UNKNOWN: unrecognized parameter
  33. * @RPPC_PARAM_TYPE_ATOMIC: an atomic data type, 1 byte to architecture limit
  34. * sized bytes
  35. * @RPPC_PARAM_TYPE_PTR: a pointer to shared memory. The fd field in the
  36. * structures rppc_param and rppc_param_translation must
  37. * contain the file descriptor of the associated dma_buf
  38. * @RPPC_PARAM_TYPE_STRUCT: (unsupported) a structure type. Will be architecture
  39. * width aligned in memory
  40. *
  41. * These enum values are used to identify the parameter type for every
  42. * parameter argument of the remote function.
  43. */
  44. enum rppc_param_type {
  45. RPPC_PARAM_TYPE_UNKNOWN = 0,
  46. RPPC_PARAM_TYPE_ATOMIC,
  47. RPPC_PARAM_TYPE_PTR,
  48. RPPC_PARAM_TYPE_STRUCT,
  49. };
  50. /**
  51. * struct rppc_param_translation - pointer translation helper structure
  52. * @index: index of the parameter where the translation needs to be done in.
  53. * used for computing the primary offset and mapping into kernel
  54. * the page from the buffer referred to in the corresponding parameter
  55. * @offset: offset from the primary base pointer to the pointer to translate.
  56. * This is the secondary offset, and used either for mentioning the
  57. * offset from an structure array element base, or within a single
  58. * structure which itself is at an offset in an allocated buffer
  59. * @base: the base user virtual address of the pointer to translate (used to
  60. * calculate translated pointer offset)
  61. * @fd: dma_buf file descriptor of the allocated buffer pointer within which
  62. * the translated pointer is present
  63. */
  64. struct rppc_param_translation {
  65. uint32_t index;
  66. ptrdiff_t offset;
  67. size_t base;
  68. int32_t fd;
  69. };
  70. /**
  71. * struct rppc_param - descriptor structure for each parameter
  72. * @type: type of the parameter, as dictated by enum rppc_param_type
  73. * @size: size of the data (for atomic types) or size of the containing
  74. * structure in which translations are performed
  75. * @data: either the parameter value itself (for atomic type) or
  76. * the actual user space pointer address to the data (for pointer type)
  77. * @base: the base user space pointer address of the original allocated buffer,
  78. * providing a reference if data has the pointer that is at an offset
  79. * from the original pointer
  80. * @fd: file descriptor of the exported allocation (will be used to
  81. * import the associated dma_buf within the driver).
  82. */
  83. struct rppc_param {
  84. uint32_t type;
  85. size_t size;
  86. size_t data;
  87. size_t base;
  88. int32_t fd;
  89. };
  90. /**
  91. * struct rppc_function - descriptor structure for the remote function
  92. * @fxn_id: index of the function to invoke on the opened rppc device
  93. * @num_params: number of parameters filled in the params field
  94. * @params: array of parameter descriptor structures
  95. * @num_translations: number of in-place translations to be performed within
  96. * the arguments.
  97. * @translations: an open array of the translation descriptor structures, whose
  98. * length is given in @num_translations. Used for translating
  99. * the pointers within the function data.
  100. *
  101. * This is the primary descriptor structure passed down from the userspace,
  102. * describing the function, its parameter arguments and the needed translations.
  103. */
  104. struct rppc_function {
  105. uint32_t fxn_id;
  106. uint32_t num_params;
  107. struct rppc_param params[RPPC_MAX_PARAMETERS];
  108. uint32_t num_translations;
  109. struct rppc_param_translation translations[0];
  110. };
  111. /**
  112. * struct rppc_function_return - function return status descriptor structure
  113. * @fxn_id: index of the function invoked on the opened rppc device
  114. * @status: return value of the executed function
  115. */
  116. struct rppc_function_return {
  117. uint32_t fxn_id;
  118. uint32_t status;
  119. };
  120. /**
  121. * struct rppc_create_instance - rppc channel connector helper
  122. * @name: Name of the rppc server device to establish a connection with
  123. */
  124. struct rppc_create_instance {
  125. char name[RPPC_MAX_INST_NAMELEN];
  126. };
  127. /*
  128. * helper macros for manipulating the function index in the marshalled packet
  129. */
  130. #define RPPC_DESC_EXEC_SYNC (0x0100)
  131. #define RPPC_DESC_TYPE_MASK (0x0F00)
  132. /*
  133. * helper macros for manipulating the function index in the marshalled packet.
  134. * The remote functions are offset by one relative to the client
  135. * XXX: Remove the relative offset
  136. */
  137. #define RPPC_SET_FXN_IDX(idx) (((idx) + 1) | 0x80000000)
  138. #define RPPC_FXN_MASK(idx) (((idx) - 1) & 0x7FFFFFFF)
  139. /**
  140. * struct rppc_packet - the actual marshalled packet
  141. * @desc: type of function execution, currently only synchronous function
  142. * invocations are supported
  143. * @msg_id: an incremental message index identifier
  144. * @flags: a combination of job id and pool id of the worker threads
  145. * of the server
  146. * @fxn_id: id of the function to execute
  147. * @result: result of the remotely executed function
  148. * @data_size: size of the payload packet
  149. * @data: variable payload, containing the marshalled function data.
  150. *
  151. * This is actually a condensed structure of the Remote Command Messaging
  152. * (RCM) structure. The initial fields of the structure are used by the
  153. * remote-side server to schedule the execution of the function. The actual
  154. * variable payload data starts from the .data field. This marshalled packet
  155. * is the payload for a rpmsg message.
  156. *
  157. * XXX: remove or mask unneeded fields, some fields can be stripped down
  158. */
  159. struct rppc_packet {
  160. uint16_t desc;
  161. uint16_t msg_id;
  162. uint32_t flags;
  163. uint32_t fxn_id;
  164. int32_t result;
  165. uint32_t data_size;
  166. uint8_t data[0];
  167. } __packed;
  168. #endif /* _UAPI_LINUX_RPMSG_RPC_H_ */