PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/staging/vc04_services/interface/vchi/vchi.h

https://gitlab.com/freesoftware/linux
C Header | 238 lines | 120 code | 52 blank | 66 comment | 1 complexity | 412edbaf3f6e75c11e584aacd23cc2f0 MD5 | raw file
  1. /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
  2. /* Copyright (c) 2010-2012 Broadcom. All rights reserved. */
  3. #ifndef VCHI_H_
  4. #define VCHI_H_
  5. #include "interface/vchi/vchi_cfg.h"
  6. #include "interface/vchi/vchi_common.h"
  7. /******************************************************************************
  8. Global defs
  9. *****************************************************************************/
  10. #define VCHI_BULK_ROUND_UP(x) ((((unsigned long)(x))+VCHI_BULK_ALIGN-1) & ~(VCHI_BULK_ALIGN-1))
  11. #define VCHI_BULK_ROUND_DOWN(x) (((unsigned long)(x)) & ~(VCHI_BULK_ALIGN-1))
  12. #define VCHI_BULK_ALIGN_NBYTES(x) (VCHI_BULK_ALIGNED(x) ? 0 : (VCHI_BULK_ALIGN - ((unsigned long)(x) & (VCHI_BULK_ALIGN-1))))
  13. #ifdef USE_VCHIQ_ARM
  14. #define VCHI_BULK_ALIGNED(x) 1
  15. #else
  16. #define VCHI_BULK_ALIGNED(x) (((unsigned long)(x) & (VCHI_BULK_ALIGN-1)) == 0)
  17. #endif
  18. struct vchi_version {
  19. uint32_t version;
  20. uint32_t version_min;
  21. };
  22. #define VCHI_VERSION(v_) { v_, v_ }
  23. #define VCHI_VERSION_EX(v_, m_) { v_, m_ }
  24. // Macros to manipulate 'FOURCC' values
  25. #define MAKE_FOURCC(x) ((int32_t)((x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3]))
  26. // Opaque service information
  27. struct opaque_vchi_service_t;
  28. // Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold,
  29. // vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only.
  30. struct vchi_held_msg {
  31. struct opaque_vchi_service_t *service;
  32. void *message;
  33. };
  34. // structure used to provide the information needed to open a server or a client
  35. struct service_creation {
  36. struct vchi_version version;
  37. int32_t service_id;
  38. VCHI_CALLBACK_T callback;
  39. void *callback_param;
  40. };
  41. // Opaque handle for a VCHI instance
  42. typedef struct opaque_vchi_instance_handle_t *VCHI_INSTANCE_T;
  43. // Opaque handle for a server or client
  44. typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T;
  45. /******************************************************************************
  46. Global funcs - implementation is specific to which side you are on (local / remote)
  47. *****************************************************************************/
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. // Routine used to initialise the vchi on both local + remote connections
  52. extern int32_t vchi_initialise(VCHI_INSTANCE_T *instance_handle);
  53. extern int32_t vchi_exit(void);
  54. extern int32_t vchi_connect(VCHI_INSTANCE_T instance_handle);
  55. //When this is called, ensure that all services have no data pending.
  56. //Bulk transfers can remain 'queued'
  57. extern int32_t vchi_disconnect(VCHI_INSTANCE_T instance_handle);
  58. // helper functions
  59. extern void *vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length);
  60. extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address);
  61. extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);
  62. /******************************************************************************
  63. Global service API
  64. *****************************************************************************/
  65. // Routine to destroy a service
  66. extern int32_t vchi_service_destroy(const VCHI_SERVICE_HANDLE_T handle);
  67. // Routine to open a named service
  68. extern int32_t vchi_service_open(VCHI_INSTANCE_T instance_handle,
  69. struct service_creation *setup,
  70. VCHI_SERVICE_HANDLE_T *handle);
  71. extern int32_t vchi_get_peer_version(const VCHI_SERVICE_HANDLE_T handle,
  72. short *peer_version);
  73. // Routine to close a named service
  74. extern int32_t vchi_service_close(const VCHI_SERVICE_HANDLE_T handle);
  75. // Routine to increment ref count on a named service
  76. extern int32_t vchi_service_use(const VCHI_SERVICE_HANDLE_T handle);
  77. // Routine to decrement ref count on a named service
  78. extern int32_t vchi_service_release(const VCHI_SERVICE_HANDLE_T handle);
  79. // Routine to set a control option for a named service
  80. extern int32_t vchi_service_set_option(const VCHI_SERVICE_HANDLE_T handle,
  81. VCHI_SERVICE_OPTION_T option,
  82. int value);
  83. /* Routine to send a message from kernel memory across a service */
  84. extern int
  85. vchi_queue_kernel_message(VCHI_SERVICE_HANDLE_T handle,
  86. void *data,
  87. unsigned int size);
  88. /* Routine to send a message from user memory across a service */
  89. extern int
  90. vchi_queue_user_message(VCHI_SERVICE_HANDLE_T handle,
  91. void __user *data,
  92. unsigned int size);
  93. // Routine to receive a msg from a service
  94. // Dequeue is equivalent to hold, copy into client buffer, release
  95. extern int32_t vchi_msg_dequeue(VCHI_SERVICE_HANDLE_T handle,
  96. void *data,
  97. uint32_t max_data_size_to_read,
  98. uint32_t *actual_msg_size,
  99. VCHI_FLAGS_T flags);
  100. // Routine to look at a message in place.
  101. // The message is not dequeued, so a subsequent call to peek or dequeue
  102. // will return the same message.
  103. extern int32_t vchi_msg_peek(VCHI_SERVICE_HANDLE_T handle,
  104. void **data,
  105. uint32_t *msg_size,
  106. VCHI_FLAGS_T flags);
  107. // Routine to remove a message after it has been read in place with peek
  108. // The first message on the queue is dequeued.
  109. extern int32_t vchi_msg_remove(VCHI_SERVICE_HANDLE_T handle);
  110. // Routine to look at a message in place.
  111. // The message is dequeued, so the caller is left holding it; the descriptor is
  112. // filled in and must be released when the user has finished with the message.
  113. extern int32_t vchi_msg_hold(VCHI_SERVICE_HANDLE_T handle,
  114. void **data, // } may be NULL, as info can be
  115. uint32_t *msg_size, // } obtained from HELD_MSG_T
  116. VCHI_FLAGS_T flags,
  117. struct vchi_held_msg *message_descriptor);
  118. // Initialise an iterator to look through messages in place
  119. extern int32_t vchi_msg_look_ahead(VCHI_SERVICE_HANDLE_T handle,
  120. struct vchi_msg_iter *iter,
  121. VCHI_FLAGS_T flags);
  122. /******************************************************************************
  123. Global service support API - operations on held messages and message iterators
  124. *****************************************************************************/
  125. // Routine to get the address of a held message
  126. extern void *vchi_held_msg_ptr(const struct vchi_held_msg *message);
  127. // Routine to get the size of a held message
  128. extern int32_t vchi_held_msg_size(const struct vchi_held_msg *message);
  129. // Routine to get the transmit timestamp as written into the header by the peer
  130. extern uint32_t vchi_held_msg_tx_timestamp(const struct vchi_held_msg *message);
  131. // Routine to get the reception timestamp, written as we parsed the header
  132. extern uint32_t vchi_held_msg_rx_timestamp(const struct vchi_held_msg *message);
  133. // Routine to release a held message after it has been processed
  134. extern int32_t vchi_held_msg_release(struct vchi_held_msg *message);
  135. // Indicates whether the iterator has a next message.
  136. extern int32_t vchi_msg_iter_has_next(const struct vchi_msg_iter *iter);
  137. // Return the pointer and length for the next message and advance the iterator.
  138. extern int32_t vchi_msg_iter_next(struct vchi_msg_iter *iter,
  139. void **data,
  140. uint32_t *msg_size);
  141. // Remove the last message returned by vchi_msg_iter_next.
  142. // Can only be called once after each call to vchi_msg_iter_next.
  143. extern int32_t vchi_msg_iter_remove(struct vchi_msg_iter *iter);
  144. // Hold the last message returned by vchi_msg_iter_next.
  145. // Can only be called once after each call to vchi_msg_iter_next.
  146. extern int32_t vchi_msg_iter_hold(struct vchi_msg_iter *iter,
  147. struct vchi_held_msg *message);
  148. // Return information for the next message, and hold it, advancing the iterator.
  149. extern int32_t vchi_msg_iter_hold_next(struct vchi_msg_iter *iter,
  150. void **data, // } may be NULL
  151. uint32_t *msg_size, // }
  152. struct vchi_held_msg *message);
  153. /******************************************************************************
  154. Global bulk API
  155. *****************************************************************************/
  156. // Routine to prepare interface for a transfer from the other side
  157. extern int32_t vchi_bulk_queue_receive(VCHI_SERVICE_HANDLE_T handle,
  158. void *data_dst,
  159. uint32_t data_size,
  160. VCHI_FLAGS_T flags,
  161. void *transfer_handle);
  162. // Prepare interface for a transfer from the other side into relocatable memory.
  163. int32_t vchi_bulk_queue_receive_reloc(const VCHI_SERVICE_HANDLE_T handle,
  164. uint32_t offset,
  165. uint32_t data_size,
  166. const VCHI_FLAGS_T flags,
  167. void * const bulk_handle);
  168. // Routine to queue up data ready for transfer to the other (once they have signalled they are ready)
  169. extern int32_t vchi_bulk_queue_transmit(VCHI_SERVICE_HANDLE_T handle,
  170. const void *data_src,
  171. uint32_t data_size,
  172. VCHI_FLAGS_T flags,
  173. void *transfer_handle);
  174. /******************************************************************************
  175. Configuration plumbing
  176. *****************************************************************************/
  177. #ifdef __cplusplus
  178. }
  179. #endif
  180. extern int32_t vchi_bulk_queue_transmit_reloc(VCHI_SERVICE_HANDLE_T handle,
  181. uint32_t offset,
  182. uint32_t data_size,
  183. VCHI_FLAGS_T flags,
  184. void *transfer_handle);
  185. #endif /* VCHI_H_ */
  186. /****************************** End of file **********************************/