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 | /* |
15 | * all the data structures which serialise the MMAL protocol. note |
16 | * these are directly mapped onto the recived message data. |
17 | * |
18 | * BEWARE: They seem to *assume* pointers are u32 and that there is no |
19 | * structure padding! |
20 | * |
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 |
25 | */ |
26 | #ifndef MMAL_MSG_H |
27 | #define MMAL_MSG_H |
28 | |
29 | #define VC_MMAL_VER 15 |
30 | #define VC_MMAL_MIN_VER 10 |
31 | |
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 |
36 | |
37 | #include "mmal-msg-common.h" |
38 | #include "mmal-msg-format.h" |
39 | #include "mmal-msg-port.h" |
40 | #include "mmal-vchiq.h" |
41 | |
42 | enum mmal_msg_type { |
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 |
70 | }; |
71 | |
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*/ |
81 | }; |
82 | |
83 | struct { |
84 | u32 ; |
85 | u32 ; /* enum mmal_msg_type */ |
86 | |
87 | /* Opaque handle to the control service */ |
88 | u32 ; |
89 | |
90 | u32 ; /* a u32 per message context */ |
91 | u32 ; /* The status of the vchiq operation */ |
92 | u32 ; |
93 | }; |
94 | |
95 | /* Send from VC to host to report version */ |
96 | struct mmal_msg_version { |
97 | u32 flags; |
98 | u32 major; |
99 | u32 minor; |
100 | u32 minimum; |
101 | }; |
102 | |
103 | /* request to VC to create component */ |
104 | struct mmal_msg_component_create { |
105 | u32 client_component; /* component context */ |
106 | char name[128]; |
107 | u32 pid; /* For debug */ |
108 | }; |
109 | |
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? |
114 | */ |
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 */ |
119 | }; |
120 | |
121 | /* request to VC to destroy a component */ |
122 | struct mmal_msg_component_destroy { |
123 | u32 component_handle; |
124 | }; |
125 | |
126 | struct mmal_msg_component_destroy_reply { |
127 | u32 status; /* The component destruction status */ |
128 | }; |
129 | |
130 | /* request and reply to VC to enable a component */ |
131 | struct mmal_msg_component_enable { |
132 | u32 component_handle; |
133 | }; |
134 | |
135 | struct mmal_msg_component_enable_reply { |
136 | u32 status; /* The component enable status */ |
137 | }; |
138 | |
139 | /* request and reply to VC to disable a component */ |
140 | struct mmal_msg_component_disable { |
141 | u32 component_handle; |
142 | }; |
143 | |
144 | struct mmal_msg_component_disable_reply { |
145 | u32 status; /* The component disable status */ |
146 | }; |
147 | |
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 */ |
153 | }; |
154 | |
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 [MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */ |
167 | }; |
168 | |
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 [MMAL_FORMAT_EXTRADATA_MAX_SIZE]; |
178 | }; |
179 | |
180 | /* reply from VC to port info set request */ |
181 | struct mmal_msg_port_info_set_reply { |
182 | u32 status; |
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 [MMAL_FORMAT_EXTRADATA_MAX_SIZE]; |
192 | }; |
193 | |
194 | /* port action requests that take a mmal_port as a parameter */ |
195 | struct mmal_msg_port_action_port { |
196 | u32 component_handle; |
197 | u32 port_handle; |
198 | u32 action; /* enum mmal_msg_port_action_type */ |
199 | struct mmal_port port; |
200 | }; |
201 | |
202 | /* port action requests that take handles as a parameter */ |
203 | struct mmal_msg_port_action_handle { |
204 | u32 component_handle; |
205 | u32 port_handle; |
206 | u32 action; /* enum mmal_msg_port_action_type */ |
207 | u32 connect_component_handle; |
208 | u32 connect_port_handle; |
209 | }; |
210 | |
211 | struct mmal_msg_port_action_reply { |
212 | u32 status; /* The port action operation status */ |
213 | }; |
214 | |
215 | /* MMAL buffer transfer */ |
216 | |
217 | /* Size of space reserved in a buffer message for short messages. */ |
218 | #define MMAL_VC_SHORT_DATA 128 |
219 | |
220 | /* Signals that the current payload is the end of the stream of data */ |
221 | #define BIT(0) |
222 | /* Signals that the start of the current payload starts a frame */ |
223 | #define BIT(1) |
224 | /* Signals that the end of the current payload ends a frame */ |
225 | #define BIT(2) |
226 | /* Signals that the current payload contains only complete frames (>1) */ |
227 | #define \ |
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 BIT(3) |
232 | /* |
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 |
235 | */ |
236 | #define BIT(4) |
237 | /* |
238 | * Signals a buffer containing some kind of config data for the component |
239 | * (e.g. codec config data) |
240 | */ |
241 | #define BIT(5) |
242 | /* Signals an encrypted payload */ |
243 | #define BIT(6) |
244 | /* Signals a buffer containing side information */ |
245 | #define BIT(7) |
246 | /* |
247 | * Signals a buffer which is the snapshot/postview image from a stills |
248 | * capture |
249 | */ |
250 | #define BIT(8) |
251 | /* Signals a buffer which contains data known to be corrupted */ |
252 | #define BIT(9) |
253 | /* Signals that a buffer failed to be transmitted */ |
254 | #define BIT(10) |
255 | |
256 | struct mmal_driver_buffer { |
257 | u32 magic; |
258 | u32 component_handle; |
259 | u32 port_handle; |
260 | u32 client_context; |
261 | }; |
262 | |
263 | /* buffer header */ |
264 | struct { |
265 | u32 ; /* next header */ |
266 | u32 ; /* framework private data */ |
267 | u32 ; |
268 | u32 ; |
269 | u32 ; |
270 | u32 ; |
271 | u32 ; |
272 | u32 ; |
273 | s64 ; |
274 | s64 ; |
275 | u32 ; |
276 | u32 ; |
277 | }; |
278 | |
279 | struct { |
280 | union { |
281 | struct { |
282 | u32 ; |
283 | u32 [4]; |
284 | u32 [4]; |
285 | u32 ; |
286 | } ; |
287 | } ; |
288 | }; |
289 | |
290 | struct mmal_msg_buffer_from_host { |
291 | /* |
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. |
296 | */ |
297 | /* control data */ |
298 | struct mmal_driver_buffer drvbuf; |
299 | |
300 | /* referenced control data for passthrough buffer management */ |
301 | struct mmal_driver_buffer drvbuf_ref; |
302 | struct mmal_buffer_header ; /* buffer header itself */ |
303 | struct mmal_buffer_header_type_specific ; |
304 | s32 is_zero_copy; |
305 | s32 has_reference; |
306 | |
307 | /* allows short data to be xfered in control message */ |
308 | u32 payload_in_message; |
309 | u8 short_data[MMAL_VC_SHORT_DATA]; |
310 | }; |
311 | |
312 | /* port parameter setting */ |
313 | |
314 | #define MMAL_WORKER_PORT_PARAMETER_SPACE 96 |
315 | |
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]; |
322 | }; |
323 | |
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? |
327 | */ |
328 | }; |
329 | |
330 | /* port parameter getting */ |
331 | |
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 */ |
337 | }; |
338 | |
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]; |
344 | }; |
345 | |
346 | /* event messages */ |
347 | #define MMAL_WORKER_EVENT_SPACE 256 |
348 | |
349 | struct mmal_msg_event_to_host { |
350 | u32 client_component; /* component context */ |
351 | |
352 | u32 port_type; |
353 | u32 port_num; |
354 | |
355 | u32 cmd; |
356 | u32 length; |
357 | u8 data[MMAL_WORKER_EVENT_SPACE]; |
358 | u32 delayed_buffer; |
359 | }; |
360 | |
361 | /* all mmal messages are serialised through this structure */ |
362 | struct mmal_msg { |
363 | /* header */ |
364 | struct mmal_msg_header h; |
365 | /* payload */ |
366 | union { |
367 | struct mmal_msg_version version; |
368 | |
369 | struct mmal_msg_component_create component_create; |
370 | struct mmal_msg_component_create_reply component_create_reply; |
371 | |
372 | struct mmal_msg_component_destroy component_destroy; |
373 | struct mmal_msg_component_destroy_reply component_destroy_reply; |
374 | |
375 | struct mmal_msg_component_enable component_enable; |
376 | struct mmal_msg_component_enable_reply component_enable_reply; |
377 | |
378 | struct mmal_msg_component_disable component_disable; |
379 | struct mmal_msg_component_disable_reply component_disable_reply; |
380 | |
381 | struct mmal_msg_port_info_get port_info_get; |
382 | struct mmal_msg_port_info_get_reply port_info_get_reply; |
383 | |
384 | struct mmal_msg_port_info_set port_info_set; |
385 | struct mmal_msg_port_info_set_reply port_info_set_reply; |
386 | |
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; |
390 | |
391 | struct mmal_msg_buffer_from_host buffer_from_host; |
392 | |
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 |
397 | port_parameter_get; |
398 | struct mmal_msg_port_parameter_get_reply |
399 | port_parameter_get_reply; |
400 | |
401 | struct mmal_msg_event_to_host event_to_host; |
402 | |
403 | u8 payload[MMAL_MSG_MAX_PAYLOAD]; |
404 | } u; |
405 | }; |
406 | #endif |
407 | |