Merge tag 'v5.15.57' into rpi-5.15.y
[platform/kernel/linux-rpi.git] / drivers / staging / vc04_services / vchiq-mmal / mmal-msg.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Broadcom BM2835 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 mmal_msg_header {
84         u32 magic;
85         u32 type;       /* enum mmal_msg_type */
86
87         /* Opaque handle to the control service */
88         u32 control_service;
89
90         u32 context;    /* a u32 per message context */
91         u32 status;     /* The status of the vchiq operation */
92         u32 padding;
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 extradata[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 extradata[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 extradata[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 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)
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 MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY          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 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)
246 /*
247  * Signals a buffer which is the snapshot/postview image from a stills
248  * capture
249  */
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)
255
256 /* Video buffer header flags
257  * videobufferheaderflags
258  * The following flags describe properties of a video buffer header.
259  * As there is no collision with the MMAL_BUFFER_HEADER_FLAGS_ defines, these
260  * flags will also be present in the MMAL_BUFFER_HEADER_T flags field.
261  */
262 #define MMAL_BUFFER_HEADER_FLAG_FORMAT_SPECIFIC_START_BIT 16
263 #define MMAL_BUFFER_HEADER_FLAG_FORMAT_SPECIFIC_START \
264                         (1 << MMAL_BUFFER_HEADER_FLAG_FORMAT_SPECIFIC_START_BIT)
265 /* Signals an interlaced video frame */
266 #define MMAL_BUFFER_HEADER_VIDEO_FLAG_INTERLACED \
267                         (MMAL_BUFFER_HEADER_FLAG_FORMAT_SPECIFIC_START << 0)
268 /*
269  * Signals that the top field of the current interlaced frame should be
270  * displayed first
271  */
272 #define MMAL_BUFFER_HEADER_VIDEO_FLAG_TOP_FIELD_FIRST \
273                         (MMAL_BUFFER_HEADER_FLAG_FORMAT_SPECIFIC_START << 1)
274
275 struct mmal_driver_buffer {
276         u32 magic;
277         u32 component_handle;
278         u32 port_handle;
279         u32 client_context;
280 };
281
282 /* buffer header */
283 struct mmal_buffer_header {
284         u32 next;       /* next header */
285         u32 priv;       /* framework private data */
286         u32 cmd;
287         u32 data;
288         u32 alloc_size;
289         u32 length;
290         u32 offset;
291         u32 flags;
292         s64 pts;
293         s64 dts;
294         u32 type;
295         u32 user_data;
296 };
297
298 struct mmal_buffer_header_type_specific {
299         union {
300                 struct {
301                 u32 planes;
302                 u32 offset[4];
303                 u32 pitch[4];
304                 u32 flags;
305                 } video;
306         } u;
307 };
308
309 struct mmal_msg_buffer_from_host {
310         /*
311          *The front 32 bytes of the buffer header are copied
312          * back to us in the reply to allow for context. This
313          * area is used to store two mmal_driver_buffer structures to
314          * allow for multiple concurrent service users.
315          */
316         /* control data */
317         struct mmal_driver_buffer drvbuf;
318
319         /* referenced control data for passthrough buffer management */
320         struct mmal_driver_buffer drvbuf_ref;
321         struct mmal_buffer_header buffer_header; /* buffer header itself */
322         struct mmal_buffer_header_type_specific buffer_header_type_specific;
323         s32 is_zero_copy;
324         s32 has_reference;
325
326         /* allows short data to be xfered in control message */
327         u32 payload_in_message;
328         u8 short_data[MMAL_VC_SHORT_DATA];
329 };
330
331 /* port parameter setting */
332
333 #define MMAL_WORKER_PORT_PARAMETER_SPACE      96
334
335 struct mmal_msg_port_parameter_set {
336         u32 component_handle;   /* component */
337         u32 port_handle;        /* port */
338         u32 id;                 /* Parameter ID  */
339         u32 size;               /* Parameter size */
340         u32 value[MMAL_WORKER_PORT_PARAMETER_SPACE];
341 };
342
343 struct mmal_msg_port_parameter_set_reply {
344         u32 status;     /* enum mmal_msg_status todo: how does this
345                          * differ to the one in the header?
346                          */
347 };
348
349 /* port parameter getting */
350
351 struct mmal_msg_port_parameter_get {
352         u32 component_handle;   /* component */
353         u32 port_handle;        /* port */
354         u32 id;                 /* Parameter ID  */
355         u32 size;               /* Parameter size */
356 };
357
358 struct mmal_msg_port_parameter_get_reply {
359         u32 status;             /* Status of mmal_port_parameter_get call */
360         u32 id;                 /* Parameter ID  */
361         u32 size;               /* Parameter size */
362         u32 value[MMAL_WORKER_PORT_PARAMETER_SPACE];
363 };
364
365 /* event messages */
366 #define MMAL_WORKER_EVENT_SPACE 256
367
368 /* Four CC's for events */
369 #define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
370
371 #define MMAL_EVENT_ERROR                MMAL_FOURCC('E', 'R', 'R', 'O')
372 #define MMAL_EVENT_EOS                  MMAL_FOURCC('E', 'E', 'O', 'S')
373 #define MMAL_EVENT_FORMAT_CHANGED       MMAL_FOURCC('E', 'F', 'C', 'H')
374 #define MMAL_EVENT_PARAMETER_CHANGED    MMAL_FOURCC('E', 'P', 'C', 'H')
375
376 /* Structs for each of the event message payloads */
377 struct mmal_msg_event_eos {
378         u32 port_type;  /**< Type of port that received the end of stream */
379         u32 port_index; /**< Index of port that received the end of stream */
380 };
381
382 /** Format changed event data. */
383 struct mmal_msg_event_format_changed {
384         /* Minimum size of buffers the port requires */
385         u32 buffer_size_min;
386         /* Minimum number of buffers the port requires */
387         u32 buffer_num_min;
388         /* Size of buffers the port recommends for optimal performance.
389          * A value of zero means no special recommendation.
390          */
391         u32 buffer_size_recommended;
392         /* Number of buffers the port recommends for optimal
393          * performance. A value of zero means no special recommendation.
394          */
395         u32 buffer_num_recommended;
396
397         u32 es_ptr;
398         struct mmal_es_format format;
399         union mmal_es_specific_format es;
400         u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
401 };
402
403 struct mmal_msg_event_to_host {
404         u32 client_component;   /* component context */
405
406         u32 port_type;
407         u32 port_num;
408
409         u32 cmd;
410         u32 length;
411         u8 data[MMAL_WORKER_EVENT_SPACE];
412         u32 delayed_buffer;
413 };
414
415 /* all mmal messages are serialised through this structure */
416 struct mmal_msg {
417         /* header */
418         struct mmal_msg_header h;
419         /* payload */
420         union {
421                 struct mmal_msg_version version;
422
423                 struct mmal_msg_component_create component_create;
424                 struct mmal_msg_component_create_reply component_create_reply;
425
426                 struct mmal_msg_component_destroy component_destroy;
427                 struct mmal_msg_component_destroy_reply component_destroy_reply;
428
429                 struct mmal_msg_component_enable component_enable;
430                 struct mmal_msg_component_enable_reply component_enable_reply;
431
432                 struct mmal_msg_component_disable component_disable;
433                 struct mmal_msg_component_disable_reply component_disable_reply;
434
435                 struct mmal_msg_port_info_get port_info_get;
436                 struct mmal_msg_port_info_get_reply port_info_get_reply;
437
438                 struct mmal_msg_port_info_set port_info_set;
439                 struct mmal_msg_port_info_set_reply port_info_set_reply;
440
441                 struct mmal_msg_port_action_port port_action_port;
442                 struct mmal_msg_port_action_handle port_action_handle;
443                 struct mmal_msg_port_action_reply port_action_reply;
444
445                 struct mmal_msg_buffer_from_host buffer_from_host;
446
447                 struct mmal_msg_port_parameter_set port_parameter_set;
448                 struct mmal_msg_port_parameter_set_reply
449                         port_parameter_set_reply;
450                 struct mmal_msg_port_parameter_get
451                         port_parameter_get;
452                 struct mmal_msg_port_parameter_get_reply
453                         port_parameter_get_reply;
454
455                 struct mmal_msg_event_to_host event_to_host;
456
457                 u8 payload[MMAL_MSG_MAX_PAYLOAD];
458         } u;
459 };
460 #endif