mmal-msg.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Broadcom BCM2835 V4L2 driver
  4. *
  5. * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  6. *
  7. * Authors: Vincent Sanders @ Collabora
  8. * Dave Stevenson @ Broadcom
  9. * (now dave.stevenson@raspberrypi.org)
  10. * Simon Mellor @ Broadcom
  11. * Luke Diamand @ Broadcom
  12. */
  13. /*
  14. * all the data structures which serialise the MMAL protocol. note
  15. * these are directly mapped onto the received message data.
  16. *
  17. * BEWARE: They seem to *assume* pointers are u32 and that there is no
  18. * structure padding!
  19. *
  20. * NOTE: this implementation uses kernel types to ensure sizes. Rather
  21. * than assigning values to enums to force their size the
  22. * implementation uses fixed size types and not the enums (though the
  23. * comments have the actual enum type
  24. */
  25. #ifndef MMAL_MSG_H
  26. #define MMAL_MSG_H
  27. #define VC_MMAL_VER 15
  28. #define VC_MMAL_MIN_VER 10
  29. /* max total message size is 512 bytes */
  30. #define MMAL_MSG_MAX_SIZE 512
  31. /* with six 32bit header elements max payload is therefore 488 bytes */
  32. #define MMAL_MSG_MAX_PAYLOAD 488
  33. #include "mmal-msg-common.h"
  34. #include "mmal-msg-format.h"
  35. #include "mmal-msg-port.h"
  36. #include "mmal-vchiq.h"
  37. enum mmal_msg_type {
  38. MMAL_MSG_TYPE_QUIT = 1,
  39. MMAL_MSG_TYPE_SERVICE_CLOSED,
  40. MMAL_MSG_TYPE_GET_VERSION,
  41. MMAL_MSG_TYPE_COMPONENT_CREATE,
  42. MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
  43. MMAL_MSG_TYPE_COMPONENT_ENABLE,
  44. MMAL_MSG_TYPE_COMPONENT_DISABLE,
  45. MMAL_MSG_TYPE_PORT_INFO_GET,
  46. MMAL_MSG_TYPE_PORT_INFO_SET,
  47. MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
  48. MMAL_MSG_TYPE_BUFFER_FROM_HOST,
  49. MMAL_MSG_TYPE_BUFFER_TO_HOST,
  50. MMAL_MSG_TYPE_GET_STATS,
  51. MMAL_MSG_TYPE_PORT_PARAMETER_SET,
  52. MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
  53. MMAL_MSG_TYPE_EVENT_TO_HOST,
  54. MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
  55. MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
  56. MMAL_MSG_TYPE_CONSUME_MEM,
  57. MMAL_MSG_TYPE_LMK, /* 20 */
  58. MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
  59. MMAL_MSG_TYPE_DRM_GET_LHS32,
  60. MMAL_MSG_TYPE_DRM_GET_TIME,
  61. MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
  62. MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
  63. MMAL_MSG_TYPE_HOST_LOG,
  64. MMAL_MSG_TYPE_MSG_LAST
  65. };
  66. /* port action request messages differ depending on the action type */
  67. enum mmal_msg_port_action_type {
  68. MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unknown action */
  69. MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
  70. MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
  71. MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
  72. MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
  73. MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
  74. MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
  75. };
  76. struct mmal_msg_header {
  77. u32 magic;
  78. u32 type; /* enum mmal_msg_type */
  79. /* Opaque handle to the control service */
  80. u32 control_service;
  81. u32 context; /* a u32 per message context */
  82. u32 status; /* The status of the vchiq operation */
  83. u32 padding;
  84. };
  85. /* Send from VC to host to report version */
  86. struct mmal_msg_version {
  87. u32 flags;
  88. u32 major;
  89. u32 minor;
  90. u32 minimum;
  91. };
  92. /* request to VC to create component */
  93. struct mmal_msg_component_create {
  94. u32 client_component; /* component context */
  95. char name[128];
  96. u32 pid; /* For debug */
  97. };
  98. /* reply from VC to component creation request */
  99. struct mmal_msg_component_create_reply {
  100. u32 status; /* enum mmal_msg_status - how does this differ to
  101. * the one in the header?
  102. */
  103. u32 component_handle; /* VideoCore handle for component */
  104. u32 input_num; /* Number of input ports */
  105. u32 output_num; /* Number of output ports */
  106. u32 clock_num; /* Number of clock ports */
  107. };
  108. /* request to VC to destroy a component */
  109. struct mmal_msg_component_destroy {
  110. u32 component_handle;
  111. };
  112. struct mmal_msg_component_destroy_reply {
  113. u32 status; /* The component destruction status */
  114. };
  115. /* request and reply to VC to enable a component */
  116. struct mmal_msg_component_enable {
  117. u32 component_handle;
  118. };
  119. struct mmal_msg_component_enable_reply {
  120. u32 status; /* The component enable status */
  121. };
  122. /* request and reply to VC to disable a component */
  123. struct mmal_msg_component_disable {
  124. u32 component_handle;
  125. };
  126. struct mmal_msg_component_disable_reply {
  127. u32 status; /* The component disable status */
  128. };
  129. /* request to VC to get port information */
  130. struct mmal_msg_port_info_get {
  131. u32 component_handle; /* component handle port is associated with */
  132. u32 port_type; /* enum mmal_msg_port_type */
  133. u32 index; /* port index to query */
  134. };
  135. /* reply from VC to get port info request */
  136. struct mmal_msg_port_info_get_reply {
  137. u32 status; /* enum mmal_msg_status */
  138. u32 component_handle; /* component handle port is associated with */
  139. u32 port_type; /* enum mmal_msg_port_type */
  140. u32 port_index; /* port indexed in query */
  141. s32 found; /* unused */
  142. u32 port_handle; /* Handle to use for this port */
  143. struct mmal_port port;
  144. struct mmal_es_format format; /* elementary stream format */
  145. union mmal_es_specific_format es; /* es type specific data */
  146. u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
  147. };
  148. /* request to VC to set port information */
  149. struct mmal_msg_port_info_set {
  150. u32 component_handle;
  151. u32 port_type; /* enum mmal_msg_port_type */
  152. u32 port_index; /* port indexed in query */
  153. struct mmal_port port;
  154. struct mmal_es_format format;
  155. union mmal_es_specific_format es;
  156. u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  157. };
  158. /* reply from VC to port info set request */
  159. struct mmal_msg_port_info_set_reply {
  160. u32 status;
  161. u32 component_handle; /* component handle port is associated with */
  162. u32 port_type; /* enum mmal_msg_port_type */
  163. u32 index; /* port indexed in query */
  164. s32 found; /* unused */
  165. u32 port_handle; /* Handle to use for this port */
  166. struct mmal_port port;
  167. struct mmal_es_format format;
  168. union mmal_es_specific_format es;
  169. u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  170. };
  171. /* port action requests that take a mmal_port as a parameter */
  172. struct mmal_msg_port_action_port {
  173. u32 component_handle;
  174. u32 port_handle;
  175. u32 action; /* enum mmal_msg_port_action_type */
  176. struct mmal_port port;
  177. };
  178. /* port action requests that take handles as a parameter */
  179. struct mmal_msg_port_action_handle {
  180. u32 component_handle;
  181. u32 port_handle;
  182. u32 action; /* enum mmal_msg_port_action_type */
  183. u32 connect_component_handle;
  184. u32 connect_port_handle;
  185. };
  186. struct mmal_msg_port_action_reply {
  187. u32 status; /* The port action operation status */
  188. };
  189. /* MMAL buffer transfer */
  190. /* Size of space reserved in a buffer message for short messages. */
  191. #define MMAL_VC_SHORT_DATA 128
  192. /* Signals that the current payload is the end of the stream of data */
  193. #define MMAL_BUFFER_HEADER_FLAG_EOS BIT(0)
  194. /* Signals that the start of the current payload starts a frame */
  195. #define MMAL_BUFFER_HEADER_FLAG_FRAME_START BIT(1)
  196. /* Signals that the end of the current payload ends a frame */
  197. #define MMAL_BUFFER_HEADER_FLAG_FRAME_END BIT(2)
  198. /* Signals that the current payload contains only complete frames (>1) */
  199. #define MMAL_BUFFER_HEADER_FLAG_FRAME \
  200. (MMAL_BUFFER_HEADER_FLAG_FRAME_START | \
  201. MMAL_BUFFER_HEADER_FLAG_FRAME_END)
  202. /* Signals that the current payload is a keyframe (i.e. self decodable) */
  203. #define MMAL_BUFFER_HEADER_FLAG_KEYFRAME BIT(3)
  204. /*
  205. * Signals a discontinuity in the stream of data (e.g. after a seek).
  206. * Can be used for instance by a decoder to reset its state
  207. */
  208. #define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY BIT(4)
  209. /*
  210. * Signals a buffer containing some kind of config data for the component
  211. * (e.g. codec config data)
  212. */
  213. #define MMAL_BUFFER_HEADER_FLAG_CONFIG BIT(5)
  214. /* Signals an encrypted payload */
  215. #define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED BIT(6)
  216. /* Signals a buffer containing side information */
  217. #define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO BIT(7)
  218. /*
  219. * Signals a buffer which is the snapshot/postview image from a stills
  220. * capture
  221. */
  222. #define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT BIT(8)
  223. /* Signals a buffer which contains data known to be corrupted */
  224. #define MMAL_BUFFER_HEADER_FLAG_CORRUPTED BIT(9)
  225. /* Signals that a buffer failed to be transmitted */
  226. #define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED BIT(10)
  227. struct mmal_driver_buffer {
  228. u32 magic;
  229. u32 component_handle;
  230. u32 port_handle;
  231. u32 client_context;
  232. };
  233. /* buffer header */
  234. struct mmal_buffer_header {
  235. u32 next; /* next header */
  236. u32 priv; /* framework private data */
  237. u32 cmd;
  238. u32 data;
  239. u32 alloc_size;
  240. u32 length;
  241. u32 offset;
  242. u32 flags;
  243. s64 pts;
  244. s64 dts;
  245. u32 type;
  246. u32 user_data;
  247. };
  248. struct mmal_buffer_header_type_specific {
  249. union {
  250. struct {
  251. u32 planes;
  252. u32 offset[4];
  253. u32 pitch[4];
  254. u32 flags;
  255. } video;
  256. } u;
  257. };
  258. struct mmal_msg_buffer_from_host {
  259. /*
  260. *The front 32 bytes of the buffer header are copied
  261. * back to us in the reply to allow for context. This
  262. * area is used to store two mmal_driver_buffer structures to
  263. * allow for multiple concurrent service users.
  264. */
  265. /* control data */
  266. struct mmal_driver_buffer drvbuf;
  267. /* referenced control data for passthrough buffer management */
  268. struct mmal_driver_buffer drvbuf_ref;
  269. struct mmal_buffer_header buffer_header; /* buffer header itself */
  270. struct mmal_buffer_header_type_specific buffer_header_type_specific;
  271. s32 is_zero_copy;
  272. s32 has_reference;
  273. /* allows short data to be xfered in control message */
  274. u32 payload_in_message;
  275. u8 short_data[MMAL_VC_SHORT_DATA];
  276. };
  277. /* port parameter setting */
  278. #define MMAL_WORKER_PORT_PARAMETER_SPACE 96
  279. struct mmal_msg_port_parameter_set {
  280. u32 component_handle; /* component */
  281. u32 port_handle; /* port */
  282. u32 id; /* Parameter ID */
  283. u32 size; /* Parameter size */
  284. u32 value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  285. };
  286. struct mmal_msg_port_parameter_set_reply {
  287. u32 status; /* enum mmal_msg_status todo: how does this
  288. * differ to the one in the header?
  289. */
  290. };
  291. /* port parameter getting */
  292. struct mmal_msg_port_parameter_get {
  293. u32 component_handle; /* component */
  294. u32 port_handle; /* port */
  295. u32 id; /* Parameter ID */
  296. u32 size; /* Parameter size */
  297. };
  298. struct mmal_msg_port_parameter_get_reply {
  299. u32 status; /* Status of mmal_port_parameter_get call */
  300. u32 id; /* Parameter ID */
  301. u32 size; /* Parameter size */
  302. u32 value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  303. };
  304. /* event messages */
  305. #define MMAL_WORKER_EVENT_SPACE 256
  306. struct mmal_msg_event_to_host {
  307. u32 client_component; /* component context */
  308. u32 port_type;
  309. u32 port_num;
  310. u32 cmd;
  311. u32 length;
  312. u8 data[MMAL_WORKER_EVENT_SPACE];
  313. u32 delayed_buffer;
  314. };
  315. /* all mmal messages are serialised through this structure */
  316. struct mmal_msg {
  317. /* header */
  318. struct mmal_msg_header h;
  319. /* payload */
  320. union {
  321. struct mmal_msg_version version;
  322. struct mmal_msg_component_create component_create;
  323. struct mmal_msg_component_create_reply component_create_reply;
  324. struct mmal_msg_component_destroy component_destroy;
  325. struct mmal_msg_component_destroy_reply component_destroy_reply;
  326. struct mmal_msg_component_enable component_enable;
  327. struct mmal_msg_component_enable_reply component_enable_reply;
  328. struct mmal_msg_component_disable component_disable;
  329. struct mmal_msg_component_disable_reply component_disable_reply;
  330. struct mmal_msg_port_info_get port_info_get;
  331. struct mmal_msg_port_info_get_reply port_info_get_reply;
  332. struct mmal_msg_port_info_set port_info_set;
  333. struct mmal_msg_port_info_set_reply port_info_set_reply;
  334. struct mmal_msg_port_action_port port_action_port;
  335. struct mmal_msg_port_action_handle port_action_handle;
  336. struct mmal_msg_port_action_reply port_action_reply;
  337. struct mmal_msg_buffer_from_host buffer_from_host;
  338. struct mmal_msg_port_parameter_set port_parameter_set;
  339. struct mmal_msg_port_parameter_set_reply
  340. port_parameter_set_reply;
  341. struct mmal_msg_port_parameter_get
  342. port_parameter_get;
  343. struct mmal_msg_port_parameter_get_reply
  344. port_parameter_get_reply;
  345. struct mmal_msg_event_to_host event_to_host;
  346. u8 payload[MMAL_MSG_MAX_PAYLOAD];
  347. } u;
  348. };
  349. #endif