1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Broadcom BM2835 V4L2 driver
5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
7 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
8 * Dave Stevenson <dsteve@broadcom.com>
9 * Simon Mellor <simellor@broadcom.com>
10 * Luke Diamand <luked@broadcom.com>
13 /* all the data structures which serialise the MMAL protocol. note
14 * these are directly mapped onto the recived message data.
16 * BEWARE: They seem to *assume* pointers are u32 and that there is no
19 * NOTE: this implementation uses kernel types to ensure sizes. Rather
20 * than assigning values to enums to force their size the
21 * implementation uses fixed size types and not the enums (though the
22 * comments have the actual enum type
25 #define VC_MMAL_VER 15
26 #define VC_MMAL_MIN_VER 10
27 #define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
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
34 #include "mmal-msg-common.h"
35 #include "mmal-msg-format.h"
36 #include "mmal-msg-port.h"
39 MMAL_MSG_TYPE_QUIT = 1,
40 MMAL_MSG_TYPE_SERVICE_CLOSED,
41 MMAL_MSG_TYPE_GET_VERSION,
42 MMAL_MSG_TYPE_COMPONENT_CREATE,
43 MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
44 MMAL_MSG_TYPE_COMPONENT_ENABLE,
45 MMAL_MSG_TYPE_COMPONENT_DISABLE,
46 MMAL_MSG_TYPE_PORT_INFO_GET,
47 MMAL_MSG_TYPE_PORT_INFO_SET,
48 MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
49 MMAL_MSG_TYPE_BUFFER_FROM_HOST,
50 MMAL_MSG_TYPE_BUFFER_TO_HOST,
51 MMAL_MSG_TYPE_GET_STATS,
52 MMAL_MSG_TYPE_PORT_PARAMETER_SET,
53 MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
54 MMAL_MSG_TYPE_EVENT_TO_HOST,
55 MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
56 MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
57 MMAL_MSG_TYPE_CONSUME_MEM,
58 MMAL_MSG_TYPE_LMK, /* 20 */
59 MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
60 MMAL_MSG_TYPE_DRM_GET_LHS32,
61 MMAL_MSG_TYPE_DRM_GET_TIME,
62 MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
63 MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
64 MMAL_MSG_TYPE_HOST_LOG,
65 MMAL_MSG_TYPE_MSG_LAST
68 /* port action request messages differ depending on the action type */
69 enum mmal_msg_port_action_type {
70 MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unknown action */
71 MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
72 MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
73 MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
74 MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
75 MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
76 MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
79 struct mmal_msg_header {
81 u32 type; /** enum mmal_msg_type */
83 /* Opaque handle to the control service */
86 u32 context; /** a u32 per message context */
87 u32 status; /** The status of the vchiq operation */
91 /* Send from VC to host to report version */
92 struct mmal_msg_version {
99 /* request to VC to create component */
100 struct mmal_msg_component_create {
101 u32 client_component; /* component context */
103 u32 pid; /* For debug */
106 /* reply from VC to component creation request */
107 struct mmal_msg_component_create_reply {
108 u32 status; /* enum mmal_msg_status - how does this differ to
109 * the one in the header?
111 u32 component_handle; /* VideoCore handle for component */
112 u32 input_num; /* Number of input ports */
113 u32 output_num; /* Number of output ports */
114 u32 clock_num; /* Number of clock ports */
117 /* request to VC to destroy a component */
118 struct mmal_msg_component_destroy {
119 u32 component_handle;
122 struct mmal_msg_component_destroy_reply {
123 u32 status; /** The component destruction status */
126 /* request and reply to VC to enable a component */
127 struct mmal_msg_component_enable {
128 u32 component_handle;
131 struct mmal_msg_component_enable_reply {
132 u32 status; /** The component enable status */
135 /* request and reply to VC to disable a component */
136 struct mmal_msg_component_disable {
137 u32 component_handle;
140 struct mmal_msg_component_disable_reply {
141 u32 status; /** The component disable status */
144 /* request to VC to get port information */
145 struct mmal_msg_port_info_get {
146 u32 component_handle; /* component handle port is associated with */
147 u32 port_type; /* enum mmal_msg_port_type */
148 u32 index; /* port index to query */
151 /* reply from VC to get port info request */
152 struct mmal_msg_port_info_get_reply {
153 u32 status; /** enum mmal_msg_status */
154 u32 component_handle; /* component handle port is associated with */
155 u32 port_type; /* enum mmal_msg_port_type */
156 u32 port_index; /* port indexed in query */
157 s32 found; /* unused */
158 u32 port_handle; /**< Handle to use for this port */
159 struct mmal_port port;
160 struct mmal_es_format format; /* elementary stream format */
161 union mmal_es_specific_format es; /* es type specific data */
162 u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
165 /* request to VC to set port information */
166 struct mmal_msg_port_info_set {
167 u32 component_handle;
168 u32 port_type; /* enum mmal_msg_port_type */
169 u32 port_index; /* port indexed in query */
170 struct mmal_port port;
171 struct mmal_es_format format;
172 union mmal_es_specific_format es;
173 u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
176 /* reply from VC to port info set request */
177 struct mmal_msg_port_info_set_reply {
179 u32 component_handle; /* component handle port is associated with */
180 u32 port_type; /* enum mmal_msg_port_type */
181 u32 index; /* port indexed in query */
182 s32 found; /* unused */
183 u32 port_handle; /**< Handle to use for this port */
184 struct mmal_port port;
185 struct mmal_es_format format;
186 union mmal_es_specific_format es;
187 u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
190 /* port action requests that take a mmal_port as a parameter */
191 struct mmal_msg_port_action_port {
192 u32 component_handle;
194 u32 action; /* enum mmal_msg_port_action_type */
195 struct mmal_port port;
198 /* port action requests that take handles as a parameter */
199 struct mmal_msg_port_action_handle {
200 u32 component_handle;
202 u32 action; /* enum mmal_msg_port_action_type */
203 u32 connect_component_handle;
204 u32 connect_port_handle;
207 struct mmal_msg_port_action_reply {
208 u32 status; /** The port action operation status */
211 /* MMAL buffer transfer */
213 /** Size of space reserved in a buffer message for short messages. */
214 #define MMAL_VC_SHORT_DATA 128
216 /** Signals that the current payload is the end of the stream of data */
217 #define MMAL_BUFFER_HEADER_FLAG_EOS BIT(0)
218 /** Signals that the start of the current payload starts a frame */
219 #define MMAL_BUFFER_HEADER_FLAG_FRAME_START BIT(1)
220 /** Signals that the end of the current payload ends a frame */
221 #define MMAL_BUFFER_HEADER_FLAG_FRAME_END BIT(2)
222 /** Signals that the current payload contains only complete frames (>1) */
223 #define MMAL_BUFFER_HEADER_FLAG_FRAME \
224 (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
225 /** Signals that the current payload is a keyframe (i.e. self decodable) */
226 #define MMAL_BUFFER_HEADER_FLAG_KEYFRAME BIT(3)
227 /** Signals a discontinuity in the stream of data (e.g. after a seek).
228 * Can be used for instance by a decoder to reset its state
230 #define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY BIT(4)
231 /** Signals a buffer containing some kind of config data for the component
232 * (e.g. codec config data)
234 #define MMAL_BUFFER_HEADER_FLAG_CONFIG BIT(5)
235 /** Signals an encrypted payload */
236 #define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED BIT(6)
237 /** Signals a buffer containing side information */
238 #define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO BIT(7)
239 /** Signals a buffer which is the snapshot/postview image from a stills
242 #define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT BIT(8)
243 /** Signals a buffer which contains data known to be corrupted */
244 #define MMAL_BUFFER_HEADER_FLAG_CORRUPTED BIT(9)
245 /** Signals that a buffer failed to be transmitted */
246 #define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED BIT(10)
248 struct mmal_driver_buffer {
250 u32 component_handle;
256 struct mmal_buffer_header {
257 u32 next; /* next header */
258 u32 priv; /* framework private data */
271 struct mmal_buffer_header_type_specific {
282 struct mmal_msg_buffer_from_host {
283 /* The front 32 bytes of the buffer header are copied
284 * back to us in the reply to allow for context. This
285 * area is used to store two mmal_driver_buffer structures to
286 * allow for multiple concurrent service users.
289 struct mmal_driver_buffer drvbuf;
291 /* referenced control data for passthrough buffer management */
292 struct mmal_driver_buffer drvbuf_ref;
293 struct mmal_buffer_header buffer_header; /* buffer header itself */
294 struct mmal_buffer_header_type_specific buffer_header_type_specific;
298 /** allows short data to be xfered in control message */
299 u32 payload_in_message;
300 u8 short_data[MMAL_VC_SHORT_DATA];
303 /* port parameter setting */
305 #define MMAL_WORKER_PORT_PARAMETER_SPACE 96
307 struct mmal_msg_port_parameter_set {
308 u32 component_handle; /* component */
309 u32 port_handle; /* port */
310 u32 id; /* Parameter ID */
311 u32 size; /* Parameter size */
312 uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
315 struct mmal_msg_port_parameter_set_reply {
316 u32 status; /* enum mmal_msg_status todo: how does this
317 * differ to the one in the header?
321 /* port parameter getting */
323 struct mmal_msg_port_parameter_get {
324 u32 component_handle; /* component */
325 u32 port_handle; /* port */
326 u32 id; /* Parameter ID */
327 u32 size; /* Parameter size */
330 struct mmal_msg_port_parameter_get_reply {
331 u32 status; /* Status of mmal_port_parameter_get call */
332 u32 id; /* Parameter ID */
333 u32 size; /* Parameter size */
334 uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
338 #define MMAL_WORKER_EVENT_SPACE 256
340 struct mmal_msg_event_to_host {
341 u32 client_component; /* component context */
348 u8 data[MMAL_WORKER_EVENT_SPACE];
352 /* all mmal messages are serialised through this structure */
355 struct mmal_msg_header h;
358 struct mmal_msg_version version;
360 struct mmal_msg_component_create component_create;
361 struct mmal_msg_component_create_reply component_create_reply;
363 struct mmal_msg_component_destroy component_destroy;
364 struct mmal_msg_component_destroy_reply component_destroy_reply;
366 struct mmal_msg_component_enable component_enable;
367 struct mmal_msg_component_enable_reply component_enable_reply;
369 struct mmal_msg_component_disable component_disable;
370 struct mmal_msg_component_disable_reply component_disable_reply;
372 struct mmal_msg_port_info_get port_info_get;
373 struct mmal_msg_port_info_get_reply port_info_get_reply;
375 struct mmal_msg_port_info_set port_info_set;
376 struct mmal_msg_port_info_set_reply port_info_set_reply;
378 struct mmal_msg_port_action_port port_action_port;
379 struct mmal_msg_port_action_handle port_action_handle;
380 struct mmal_msg_port_action_reply port_action_reply;
382 struct mmal_msg_buffer_from_host buffer_from_host;
384 struct mmal_msg_port_parameter_set port_parameter_set;
385 struct mmal_msg_port_parameter_set_reply
386 port_parameter_set_reply;
387 struct mmal_msg_port_parameter_get
389 struct mmal_msg_port_parameter_get_reply
390 port_parameter_get_reply;
392 struct mmal_msg_event_to_host event_to_host;
394 u8 payload[MMAL_MSG_MAX_PAYLOAD];