1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Broadcom BM2835 V4L2 driver
5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
7 * Authors: Vincent Sanders @ Collabora
8 * Dave Stevenson @ Broadcom
9 * (now dave.stevenson@raspberrypi.org)
10 * Simon Mellor @ Broadcom
11 * Luke Diamand @ Broadcom
15 * all the data structures which serialise the MMAL protocol. note
16 * these are directly mapped onto the recived message data.
18 * BEWARE: They seem to *assume* pointers are u32 and that there is no
21 * NOTE: this implementation uses kernel types to ensure sizes. Rather
22 * than assigning values to enums to force their size the
23 * implementation uses fixed size types and not the enums (though the
24 * comments have the actual enum type
29 #define VC_MMAL_VER 15
30 #define VC_MMAL_MIN_VER 10
31 #define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
33 /* max total message size is 512 bytes */
34 #define MMAL_MSG_MAX_SIZE 512
35 /* with six 32bit header elements max payload is therefore 488 bytes */
36 #define MMAL_MSG_MAX_PAYLOAD 488
38 #include "mmal-msg-common.h"
39 #include "mmal-msg-format.h"
40 #include "mmal-msg-port.h"
43 MMAL_MSG_TYPE_QUIT = 1,
44 MMAL_MSG_TYPE_SERVICE_CLOSED,
45 MMAL_MSG_TYPE_GET_VERSION,
46 MMAL_MSG_TYPE_COMPONENT_CREATE,
47 MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
48 MMAL_MSG_TYPE_COMPONENT_ENABLE,
49 MMAL_MSG_TYPE_COMPONENT_DISABLE,
50 MMAL_MSG_TYPE_PORT_INFO_GET,
51 MMAL_MSG_TYPE_PORT_INFO_SET,
52 MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
53 MMAL_MSG_TYPE_BUFFER_FROM_HOST,
54 MMAL_MSG_TYPE_BUFFER_TO_HOST,
55 MMAL_MSG_TYPE_GET_STATS,
56 MMAL_MSG_TYPE_PORT_PARAMETER_SET,
57 MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
58 MMAL_MSG_TYPE_EVENT_TO_HOST,
59 MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
60 MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
61 MMAL_MSG_TYPE_CONSUME_MEM,
62 MMAL_MSG_TYPE_LMK, /* 20 */
63 MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
64 MMAL_MSG_TYPE_DRM_GET_LHS32,
65 MMAL_MSG_TYPE_DRM_GET_TIME,
66 MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
67 MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
68 MMAL_MSG_TYPE_HOST_LOG,
69 MMAL_MSG_TYPE_MSG_LAST
72 /* port action request messages differ depending on the action type */
73 enum mmal_msg_port_action_type {
74 MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unknown action */
75 MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
76 MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
77 MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
78 MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
79 MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
80 MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
83 struct mmal_msg_header {
85 u32 type; /* enum mmal_msg_type */
87 /* Opaque handle to the control service */
90 u32 context; /* a u32 per message context */
91 u32 status; /* The status of the vchiq operation */
95 /* Send from VC to host to report version */
96 struct mmal_msg_version {
103 /* request to VC to create component */
104 struct mmal_msg_component_create {
105 u32 client_component; /* component context */
107 u32 pid; /* For debug */
110 /* reply from VC to component creation request */
111 struct mmal_msg_component_create_reply {
112 u32 status; /* enum mmal_msg_status - how does this differ to
113 * the one in the header?
115 u32 component_handle; /* VideoCore handle for component */
116 u32 input_num; /* Number of input ports */
117 u32 output_num; /* Number of output ports */
118 u32 clock_num; /* Number of clock ports */
121 /* request to VC to destroy a component */
122 struct mmal_msg_component_destroy {
123 u32 component_handle;
126 struct mmal_msg_component_destroy_reply {
127 u32 status; /* The component destruction status */
130 /* request and reply to VC to enable a component */
131 struct mmal_msg_component_enable {
132 u32 component_handle;
135 struct mmal_msg_component_enable_reply {
136 u32 status; /* The component enable status */
139 /* request and reply to VC to disable a component */
140 struct mmal_msg_component_disable {
141 u32 component_handle;
144 struct mmal_msg_component_disable_reply {
145 u32 status; /* The component disable status */
148 /* request to VC to get port information */
149 struct mmal_msg_port_info_get {
150 u32 component_handle; /* component handle port is associated with */
151 u32 port_type; /* enum mmal_msg_port_type */
152 u32 index; /* port index to query */
155 /* reply from VC to get port info request */
156 struct mmal_msg_port_info_get_reply {
157 u32 status; /* enum mmal_msg_status */
158 u32 component_handle; /* component handle port is associated with */
159 u32 port_type; /* enum mmal_msg_port_type */
160 u32 port_index; /* port indexed in query */
161 s32 found; /* unused */
162 u32 port_handle; /* Handle to use for this port */
163 struct mmal_port port;
164 struct mmal_es_format format; /* elementary stream format */
165 union mmal_es_specific_format es; /* es type specific data */
166 u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
169 /* request to VC to set port information */
170 struct mmal_msg_port_info_set {
171 u32 component_handle;
172 u32 port_type; /* enum mmal_msg_port_type */
173 u32 port_index; /* port indexed in query */
174 struct mmal_port port;
175 struct mmal_es_format format;
176 union mmal_es_specific_format es;
177 u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
180 /* reply from VC to port info set request */
181 struct mmal_msg_port_info_set_reply {
183 u32 component_handle; /* component handle port is associated with */
184 u32 port_type; /* enum mmal_msg_port_type */
185 u32 index; /* port indexed in query */
186 s32 found; /* unused */
187 u32 port_handle; /* Handle to use for this port */
188 struct mmal_port port;
189 struct mmal_es_format format;
190 union mmal_es_specific_format es;
191 u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
194 /* port action requests that take a mmal_port as a parameter */
195 struct mmal_msg_port_action_port {
196 u32 component_handle;
198 u32 action; /* enum mmal_msg_port_action_type */
199 struct mmal_port port;
202 /* port action requests that take handles as a parameter */
203 struct mmal_msg_port_action_handle {
204 u32 component_handle;
206 u32 action; /* enum mmal_msg_port_action_type */
207 u32 connect_component_handle;
208 u32 connect_port_handle;
211 struct mmal_msg_port_action_reply {
212 u32 status; /* The port action operation status */
215 /* MMAL buffer transfer */
217 /* Size of space reserved in a buffer message for short messages. */
218 #define MMAL_VC_SHORT_DATA 128
220 /* Signals that the current payload is the end of the stream of data */
221 #define MMAL_BUFFER_HEADER_FLAG_EOS BIT(0)
222 /* Signals that the start of the current payload starts a frame */
223 #define MMAL_BUFFER_HEADER_FLAG_FRAME_START BIT(1)
224 /* Signals that the end of the current payload ends a frame */
225 #define MMAL_BUFFER_HEADER_FLAG_FRAME_END BIT(2)
226 /* Signals that the current payload contains only complete frames (>1) */
227 #define MMAL_BUFFER_HEADER_FLAG_FRAME \
228 (MMAL_BUFFER_HEADER_FLAG_FRAME_START | \
229 MMAL_BUFFER_HEADER_FLAG_FRAME_END)
230 /* Signals that the current payload is a keyframe (i.e. self decodable) */
231 #define MMAL_BUFFER_HEADER_FLAG_KEYFRAME BIT(3)
233 * Signals a discontinuity in the stream of data (e.g. after a seek).
234 * Can be used for instance by a decoder to reset its state
236 #define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY BIT(4)
238 * Signals a buffer containing some kind of config data for the component
239 * (e.g. codec config data)
241 #define MMAL_BUFFER_HEADER_FLAG_CONFIG BIT(5)
242 /* Signals an encrypted payload */
243 #define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED BIT(6)
244 /* Signals a buffer containing side information */
245 #define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO BIT(7)
247 * Signals a buffer which is the snapshot/postview image from a stills
250 #define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT BIT(8)
251 /* Signals a buffer which contains data known to be corrupted */
252 #define MMAL_BUFFER_HEADER_FLAG_CORRUPTED BIT(9)
253 /* Signals that a buffer failed to be transmitted */
254 #define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED BIT(10)
256 struct mmal_driver_buffer {
258 u32 component_handle;
264 struct mmal_buffer_header {
265 u32 next; /* next header */
266 u32 priv; /* framework private data */
279 struct mmal_buffer_header_type_specific {
290 struct mmal_msg_buffer_from_host {
292 *The front 32 bytes of the buffer header are copied
293 * back to us in the reply to allow for context. This
294 * area is used to store two mmal_driver_buffer structures to
295 * allow for multiple concurrent service users.
298 struct mmal_driver_buffer drvbuf;
300 /* referenced control data for passthrough buffer management */
301 struct mmal_driver_buffer drvbuf_ref;
302 struct mmal_buffer_header buffer_header; /* buffer header itself */
303 struct mmal_buffer_header_type_specific buffer_header_type_specific;
307 /* allows short data to be xfered in control message */
308 u32 payload_in_message;
309 u8 short_data[MMAL_VC_SHORT_DATA];
312 /* port parameter setting */
314 #define MMAL_WORKER_PORT_PARAMETER_SPACE 96
316 struct mmal_msg_port_parameter_set {
317 u32 component_handle; /* component */
318 u32 port_handle; /* port */
319 u32 id; /* Parameter ID */
320 u32 size; /* Parameter size */
321 u32 value[MMAL_WORKER_PORT_PARAMETER_SPACE];
324 struct mmal_msg_port_parameter_set_reply {
325 u32 status; /* enum mmal_msg_status todo: how does this
326 * differ to the one in the header?
330 /* port parameter getting */
332 struct mmal_msg_port_parameter_get {
333 u32 component_handle; /* component */
334 u32 port_handle; /* port */
335 u32 id; /* Parameter ID */
336 u32 size; /* Parameter size */
339 struct mmal_msg_port_parameter_get_reply {
340 u32 status; /* Status of mmal_port_parameter_get call */
341 u32 id; /* Parameter ID */
342 u32 size; /* Parameter size */
343 u32 value[MMAL_WORKER_PORT_PARAMETER_SPACE];
347 #define MMAL_WORKER_EVENT_SPACE 256
349 struct mmal_msg_event_to_host {
350 u32 client_component; /* component context */
357 u8 data[MMAL_WORKER_EVENT_SPACE];
361 /* all mmal messages are serialised through this structure */
364 struct mmal_msg_header h;
367 struct mmal_msg_version version;
369 struct mmal_msg_component_create component_create;
370 struct mmal_msg_component_create_reply component_create_reply;
372 struct mmal_msg_component_destroy component_destroy;
373 struct mmal_msg_component_destroy_reply component_destroy_reply;
375 struct mmal_msg_component_enable component_enable;
376 struct mmal_msg_component_enable_reply component_enable_reply;
378 struct mmal_msg_component_disable component_disable;
379 struct mmal_msg_component_disable_reply component_disable_reply;
381 struct mmal_msg_port_info_get port_info_get;
382 struct mmal_msg_port_info_get_reply port_info_get_reply;
384 struct mmal_msg_port_info_set port_info_set;
385 struct mmal_msg_port_info_set_reply port_info_set_reply;
387 struct mmal_msg_port_action_port port_action_port;
388 struct mmal_msg_port_action_handle port_action_handle;
389 struct mmal_msg_port_action_reply port_action_reply;
391 struct mmal_msg_buffer_from_host buffer_from_host;
393 struct mmal_msg_port_parameter_set port_parameter_set;
394 struct mmal_msg_port_parameter_set_reply
395 port_parameter_set_reply;
396 struct mmal_msg_port_parameter_get
398 struct mmal_msg_port_parameter_get_reply
399 port_parameter_get_reply;
401 struct mmal_msg_event_to_host event_to_host;
403 u8 payload[MMAL_MSG_MAX_PAYLOAD];