PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

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

http://github.com/torvalds/linux
C Header | 240 lines | 120 code | 52 blank | 68 comment | 1 complexity | 10df640031ea7d9c91501546652ca980 MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-1.0, GPL-2.0
  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 "vchi_cfg.h"
  6. #include "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 callback;
  39. void *callback_param;
  40. };
  41. // Opaque handle for a VCHI instance
  42. struct vchi_instance_handle;
  43. // Opaque handle for a server or client
  44. struct vchi_service_handle;
  45. /******************************************************************************
  46. * Global funcs - implementation is specific to which side you are on
  47. * (local / remote)
  48. *****************************************************************************/
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. // Routine used to initialise the vchi on both local + remote connections
  53. extern int32_t vchi_initialise(struct vchi_instance_handle **instance_handle);
  54. extern int32_t vchi_exit(void);
  55. extern int32_t vchi_connect(struct vchi_instance_handle *instance_handle);
  56. //When this is called, ensure that all services have no data pending.
  57. //Bulk transfers can remain 'queued'
  58. extern int32_t vchi_disconnect(struct vchi_instance_handle *instance_handle);
  59. // helper functions
  60. extern void *vchi_allocate_buffer(struct vchi_service_handle *handle, uint32_t *length);
  61. extern void vchi_free_buffer(struct vchi_service_handle *handle, void *address);
  62. extern uint32_t vchi_current_time(struct vchi_instance_handle *instance_handle);
  63. /******************************************************************************
  64. * Global service API
  65. *****************************************************************************/
  66. // Routine to destroy a service
  67. extern int32_t vchi_service_destroy(const struct vchi_service_handle *handle);
  68. // Routine to open a named service
  69. extern int32_t vchi_service_open(struct vchi_instance_handle *instance_handle,
  70. struct service_creation *setup,
  71. struct vchi_service_handle **handle);
  72. extern int32_t vchi_get_peer_version(const struct vchi_service_handle *handle,
  73. short *peer_version);
  74. // Routine to close a named service
  75. extern int32_t vchi_service_close(const struct vchi_service_handle *handle);
  76. // Routine to increment ref count on a named service
  77. extern int32_t vchi_service_use(const struct vchi_service_handle *handle);
  78. // Routine to decrement ref count on a named service
  79. extern int32_t vchi_service_release(const struct vchi_service_handle *handle);
  80. // Routine to set a control option for a named service
  81. extern int32_t vchi_service_set_option(const struct vchi_service_handle *handle,
  82. enum vchi_service_option option,
  83. int value);
  84. /* Routine to send a message from kernel memory across a service */
  85. extern int
  86. vchi_queue_kernel_message(struct vchi_service_handle *handle,
  87. void *data,
  88. unsigned int size);
  89. /* Routine to send a message from user memory across a service */
  90. extern int
  91. vchi_queue_user_message(struct vchi_service_handle *handle,
  92. void __user *data,
  93. unsigned int size);
  94. // Routine to receive a msg from a service
  95. // Dequeue is equivalent to hold, copy into client buffer, release
  96. extern int32_t vchi_msg_dequeue(struct vchi_service_handle *handle,
  97. void *data,
  98. uint32_t max_data_size_to_read,
  99. uint32_t *actual_msg_size,
  100. enum vchi_flags flags);
  101. // Routine to look at a message in place.
  102. // The message is not dequeued, so a subsequent call to peek or dequeue
  103. // will return the same message.
  104. extern int32_t vchi_msg_peek(struct vchi_service_handle *handle,
  105. void **data,
  106. uint32_t *msg_size,
  107. enum vchi_flags flags);
  108. // Routine to remove a message after it has been read in place with peek
  109. // The first message on the queue is dequeued.
  110. extern int32_t vchi_msg_remove(struct vchi_service_handle *handle);
  111. // Routine to look at a message in place.
  112. // The message is dequeued, so the caller is left holding it; the descriptor is
  113. // filled in and must be released when the user has finished with the message.
  114. extern int32_t vchi_msg_hold(struct vchi_service_handle *handle,
  115. void **data, // } may be NULL, as info can be
  116. uint32_t *msg_size, // } obtained from HELD_MSG_T
  117. enum vchi_flags flags,
  118. struct vchi_held_msg *message_descriptor);
  119. // Initialise an iterator to look through messages in place
  120. extern int32_t vchi_msg_look_ahead(struct vchi_service_handle *handle,
  121. struct vchi_msg_iter *iter,
  122. enum vchi_flags flags);
  123. /*******************************************************************************
  124. * Global service support API - operations on held messages
  125. * and message iterators
  126. ******************************************************************************/
  127. // Routine to get the address of a held message
  128. extern void *vchi_held_msg_ptr(const struct vchi_held_msg *message);
  129. // Routine to get the size of a held message
  130. extern int32_t vchi_held_msg_size(const struct vchi_held_msg *message);
  131. // Routine to get the transmit timestamp as written into the header by the peer
  132. extern uint32_t vchi_held_msg_tx_timestamp(const struct vchi_held_msg *message);
  133. // Routine to get the reception timestamp, written as we parsed the header
  134. extern uint32_t vchi_held_msg_rx_timestamp(const struct vchi_held_msg *message);
  135. // Routine to release a held message after it has been processed
  136. extern int32_t vchi_held_msg_release(struct vchi_held_msg *message);
  137. // Indicates whether the iterator has a next message.
  138. extern int32_t vchi_msg_iter_has_next(const struct vchi_msg_iter *iter);
  139. // Return the pointer and length for the next message and advance the iterator.
  140. extern int32_t vchi_msg_iter_next(struct vchi_msg_iter *iter,
  141. void **data,
  142. uint32_t *msg_size);
  143. // Remove the last message returned by vchi_msg_iter_next.
  144. // Can only be called once after each call to vchi_msg_iter_next.
  145. extern int32_t vchi_msg_iter_remove(struct vchi_msg_iter *iter);
  146. // Hold the last message returned by vchi_msg_iter_next.
  147. // Can only be called once after each call to vchi_msg_iter_next.
  148. extern int32_t vchi_msg_iter_hold(struct vchi_msg_iter *iter,
  149. struct vchi_held_msg *message);
  150. // Return information for the next message, and hold it, advancing the iterator.
  151. extern int32_t vchi_msg_iter_hold_next(struct vchi_msg_iter *iter,
  152. void **data, // } may be NULL
  153. uint32_t *msg_size, // }
  154. struct vchi_held_msg *message);
  155. /******************************************************************************
  156. * Global bulk API
  157. *****************************************************************************/
  158. // Routine to prepare interface for a transfer from the other side
  159. extern int32_t vchi_bulk_queue_receive(struct vchi_service_handle *handle,
  160. void *data_dst,
  161. uint32_t data_size,
  162. enum vchi_flags flags,
  163. void *transfer_handle);
  164. // Prepare interface for a transfer from the other side into relocatable memory.
  165. int32_t vchi_bulk_queue_receive_reloc(const struct vchi_service_handle *handle,
  166. uint32_t offset,
  167. uint32_t data_size,
  168. const enum vchi_flags flags,
  169. void * const bulk_handle);
  170. // Routine to queue up data ready for transfer to the other (once they have signalled they are ready)
  171. extern int32_t vchi_bulk_queue_transmit(struct vchi_service_handle *handle,
  172. const void *data_src,
  173. uint32_t data_size,
  174. enum vchi_flags flags,
  175. void *transfer_handle);
  176. /******************************************************************************
  177. * Configuration plumbing
  178. *****************************************************************************/
  179. #ifdef __cplusplus
  180. }
  181. #endif
  182. extern int32_t vchi_bulk_queue_transmit_reloc(struct vchi_service_handle *handle,
  183. uint32_t offset,
  184. uint32_t data_size,
  185. enum vchi_flags flags,
  186. void *transfer_handle);
  187. #endif /* VCHI_H_ */
  188. /****************************** End of file **********************************/