2 * Broadcom BM2835 V4L2 driver
4 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11 * Dave Stevenson <dsteve@broadcom.com>
12 * Simon Mellor <simellor@broadcom.com>
13 * Luke Diamand <luked@broadcom.com>
16 /* all the data structures which serialise the MMAL protocol. note
17 * these are directly mapped onto the recived message data.
19 * BEWARE: They seem to *assume* pointers are u32 and that there is no
22 * NOTE: this implementation uses kernel types to ensure sizes. Rather
23 * than assigning values to enums to force their size the
24 * implementation uses fixed size types and not the enums (though the
25 * comments have the actual enum type
28 #define VC_MMAL_VER 15
29 #define VC_MMAL_MIN_VER 10
30 #define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
32 /* max total message size is 512 bytes */
33 #define MMAL_MSG_MAX_SIZE 512
34 /* with six 32bit header elements max payload is therefore 488 bytes */
35 #define MMAL_MSG_MAX_PAYLOAD 488
37 #include "mmal-msg-common.h"
38 #include "mmal-msg-format.h"
39 #include "mmal-msg-port.h"
42 MMAL_MSG_TYPE_QUIT = 1,
43 MMAL_MSG_TYPE_SERVICE_CLOSED,
44 MMAL_MSG_TYPE_GET_VERSION,
45 MMAL_MSG_TYPE_COMPONENT_CREATE,
46 MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
47 MMAL_MSG_TYPE_COMPONENT_ENABLE,
48 MMAL_MSG_TYPE_COMPONENT_DISABLE,
49 MMAL_MSG_TYPE_PORT_INFO_GET,
50 MMAL_MSG_TYPE_PORT_INFO_SET,
51 MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
52 MMAL_MSG_TYPE_BUFFER_FROM_HOST,
53 MMAL_MSG_TYPE_BUFFER_TO_HOST,
54 MMAL_MSG_TYPE_GET_STATS,
55 MMAL_MSG_TYPE_PORT_PARAMETER_SET,
56 MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
57 MMAL_MSG_TYPE_EVENT_TO_HOST,
58 MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
59 MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
60 MMAL_MSG_TYPE_CONSUME_MEM,
61 MMAL_MSG_TYPE_LMK, /* 20 */
62 MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
63 MMAL_MSG_TYPE_DRM_GET_LHS32,
64 MMAL_MSG_TYPE_DRM_GET_TIME,
65 MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
66 MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
67 MMAL_MSG_TYPE_HOST_LOG,
68 MMAL_MSG_TYPE_MSG_LAST
71 /* port action request messages differ depending on the action type */
72 enum mmal_msg_port_action_type {
73 MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
74 MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
75 MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
76 MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
77 MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
78 MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
79 MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
82 struct mmal_msg_header {
84 u32 type; /** enum mmal_msg_type */
86 /* Opaque handle to the control service */
89 u32 context; /** a u32 per message context */
90 u32 status; /** The status of the vchiq operation */
94 /* Send from VC to host to report version */
95 struct mmal_msg_version {
102 /* request to VC to create component */
103 struct mmal_msg_component_create {
104 u32 client_component; /* component context */
106 u32 pid; /* For debug */
109 /* reply from VC to component creation request */
110 struct mmal_msg_component_create_reply {
111 u32 status; /* enum mmal_msg_status - how does this differ to
112 * the one in the header?
114 u32 component_handle; /* VideoCore handle for component */
115 u32 input_num; /* Number of input ports */
116 u32 output_num; /* Number of output ports */
117 u32 clock_num; /* Number of clock ports */
120 /* request to VC to destroy a component */
121 struct mmal_msg_component_destroy {
122 u32 component_handle;
125 struct mmal_msg_component_destroy_reply {
126 u32 status; /** The component destruction status */
129 /* request and reply to VC to enable a component */
130 struct mmal_msg_component_enable {
131 u32 component_handle;
134 struct mmal_msg_component_enable_reply {
135 u32 status; /** The component enable status */
138 /* request and reply to VC to disable a component */
139 struct mmal_msg_component_disable {
140 u32 component_handle;
143 struct mmal_msg_component_disable_reply {
144 u32 status; /** The component disable status */
147 /* request to VC to get port information */
148 struct mmal_msg_port_info_get {
149 u32 component_handle; /* component handle port is associated with */
150 u32 port_type; /* enum mmal_msg_port_type */
151 u32 index; /* port index to query */
154 /* reply from VC to get port info request */
155 struct mmal_msg_port_info_get_reply {
156 u32 status; /** enum mmal_msg_status */
157 u32 component_handle; /* component handle port is associated with */
158 u32 port_type; /* enum mmal_msg_port_type */
159 u32 port_index; /* port indexed in query */
160 s32 found; /* unused */
161 u32 port_handle; /**< Handle to use for this port */
162 struct mmal_port port;
163 struct mmal_es_format format; /* elementary stream format */
164 union mmal_es_specific_format es; /* es type specific data */
165 u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
168 /* request to VC to set port information */
169 struct mmal_msg_port_info_set {
170 u32 component_handle;
171 u32 port_type; /* enum mmal_msg_port_type */
172 u32 port_index; /* port indexed in query */
173 struct mmal_port port;
174 struct mmal_es_format format;
175 union mmal_es_specific_format es;
176 u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
179 /* reply from VC to port info set request */
180 struct mmal_msg_port_info_set_reply {
182 u32 component_handle; /* component handle port is associated with */
183 u32 port_type; /* enum mmal_msg_port_type */
184 u32 index; /* port indexed in query */
185 s32 found; /* unused */
186 u32 port_handle; /**< Handle to use for this port */
187 struct mmal_port port;
188 struct mmal_es_format format;
189 union mmal_es_specific_format es;
190 u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
193 /* port action requests that take a mmal_port as a parameter */
194 struct mmal_msg_port_action_port {
195 u32 component_handle;
197 u32 action; /* enum mmal_msg_port_action_type */
198 struct mmal_port port;
201 /* port action requests that take handles as a parameter */
202 struct mmal_msg_port_action_handle {
203 u32 component_handle;
205 u32 action; /* enum mmal_msg_port_action_type */
206 u32 connect_component_handle;
207 u32 connect_port_handle;
210 struct mmal_msg_port_action_reply {
211 u32 status; /** The port action operation status */
214 /* MMAL buffer transfer */
216 /** Size of space reserved in a buffer message for short messages. */
217 #define MMAL_VC_SHORT_DATA 128
219 /** Signals that the current payload is the end of the stream of data */
220 #define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
221 /** Signals that the start of the current payload starts a frame */
222 #define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
223 /** Signals that the end of the current payload ends a frame */
224 #define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
225 /** Signals that the current payload contains only complete frames (>1) */
226 #define MMAL_BUFFER_HEADER_FLAG_FRAME \
227 (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
228 /** Signals that the current payload is a keyframe (i.e. self decodable) */
229 #define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
230 /** Signals a discontinuity in the stream of data (e.g. after a seek).
231 * Can be used for instance by a decoder to reset its state
233 #define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
234 /** Signals a buffer containing some kind of config data for the component
235 * (e.g. codec config data)
237 #define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
238 /** Signals an encrypted payload */
239 #define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
240 /** Signals a buffer containing side information */
241 #define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
242 /** Signals a buffer which is the snapshot/postview image from a stills
245 #define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
246 /** Signals a buffer which contains data known to be corrupted */
247 #define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
248 /** Signals that a buffer failed to be transmitted */
249 #define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
251 struct mmal_driver_buffer {
253 u32 component_handle;
259 struct mmal_buffer_header {
260 u32 next; /* next header */
261 u32 priv; /* framework private data */
274 struct mmal_buffer_header_type_specific {
285 struct mmal_msg_buffer_from_host {
286 /* The front 32 bytes of the buffer header are copied
287 * back to us in the reply to allow for context. This
288 * area is used to store two mmal_driver_buffer structures to
289 * allow for multiple concurrent service users.
292 struct mmal_driver_buffer drvbuf;
294 /* referenced control data for passthrough buffer management */
295 struct mmal_driver_buffer drvbuf_ref;
296 struct mmal_buffer_header buffer_header; /* buffer header itself */
297 struct mmal_buffer_header_type_specific buffer_header_type_specific;
301 /** allows short data to be xfered in control message */
302 u32 payload_in_message;
303 u8 short_data[MMAL_VC_SHORT_DATA];
306 /* port parameter setting */
308 #define MMAL_WORKER_PORT_PARAMETER_SPACE 96
310 struct mmal_msg_port_parameter_set {
311 u32 component_handle; /* component */
312 u32 port_handle; /* port */
313 u32 id; /* Parameter ID */
314 u32 size; /* Parameter size */
315 uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
318 struct mmal_msg_port_parameter_set_reply {
319 u32 status; /* enum mmal_msg_status todo: how does this
320 * differ to the one in the header?
324 /* port parameter getting */
326 struct mmal_msg_port_parameter_get {
327 u32 component_handle; /* component */
328 u32 port_handle; /* port */
329 u32 id; /* Parameter ID */
330 u32 size; /* Parameter size */
333 struct mmal_msg_port_parameter_get_reply {
334 u32 status; /* Status of mmal_port_parameter_get call */
335 u32 id; /* Parameter ID */
336 u32 size; /* Parameter size */
337 uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
341 #define MMAL_WORKER_EVENT_SPACE 256
343 struct mmal_msg_event_to_host {
344 u32 client_component; /* component context */
351 u8 data[MMAL_WORKER_EVENT_SPACE];
355 /* all mmal messages are serialised through this structure */
358 struct mmal_msg_header h;
361 struct mmal_msg_version version;
363 struct mmal_msg_component_create component_create;
364 struct mmal_msg_component_create_reply component_create_reply;
366 struct mmal_msg_component_destroy component_destroy;
367 struct mmal_msg_component_destroy_reply component_destroy_reply;
369 struct mmal_msg_component_enable component_enable;
370 struct mmal_msg_component_enable_reply component_enable_reply;
372 struct mmal_msg_component_disable component_disable;
373 struct mmal_msg_component_disable_reply component_disable_reply;
375 struct mmal_msg_port_info_get port_info_get;
376 struct mmal_msg_port_info_get_reply port_info_get_reply;
378 struct mmal_msg_port_info_set port_info_set;
379 struct mmal_msg_port_info_set_reply port_info_set_reply;
381 struct mmal_msg_port_action_port port_action_port;
382 struct mmal_msg_port_action_handle port_action_handle;
383 struct mmal_msg_port_action_reply port_action_reply;
385 struct mmal_msg_buffer_from_host buffer_from_host;
387 struct mmal_msg_port_parameter_set port_parameter_set;
388 struct mmal_msg_port_parameter_set_reply
389 port_parameter_set_reply;
390 struct mmal_msg_port_parameter_get
392 struct mmal_msg_port_parameter_get_reply
393 port_parameter_get_reply;
395 struct mmal_msg_event_to_host event_to_host;
397 u8 payload[MMAL_MSG_MAX_PAYLOAD];