e81a38a7255ec75c86b359b5417ee1d9987491f5
[openwrt/staging/dedeckeh.git] /
1 From 0243782f98be0fe65ec38e6102e06c02df9fe8ec Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Mon, 24 Sep 2018 16:30:37 +0100
4 Subject: [PATCH 264/782] staging: vc04_services: Split vchiq-mmal into a
5 module
6
7 In preparation for adding a video codec V4L2 module which also
8 wants to use vchiq-mmal functions, split it out into an
9 independent module.
10 The minimum number of changes have been made to achieve this
11 (eg straight moves where possible) so existing checkpatch
12 errors will still be present.
13
14 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
15 ---
16 drivers/staging/vc04_services/Kconfig | 1 +
17 drivers/staging/vc04_services/Makefile | 1 +
18 .../vc04_services/bcm2835-camera/Kconfig | 2 +-
19 .../vc04_services/bcm2835-camera/Makefile | 4 ++--
20 .../staging/vc04_services/vchiq-mmal/Kconfig | 7 ++++++
21 .../staging/vc04_services/vchiq-mmal/Makefile | 8 +++++++
22 .../mmal-common.h | 0
23 .../mmal-encodings.h | 0
24 .../mmal-msg-common.h | 0
25 .../mmal-msg-format.h | 0
26 .../mmal-msg-port.h | 0
27 .../{bcm2835-camera => vchiq-mmal}/mmal-msg.h | 0
28 .../mmal-parameters.h | 0
29 .../mmal-vchiq.c | 22 +++++++++++++++++++
30 .../mmal-vchiq.h | 0
31 15 files changed, 42 insertions(+), 3 deletions(-)
32 create mode 100644 drivers/staging/vc04_services/vchiq-mmal/Kconfig
33 create mode 100644 drivers/staging/vc04_services/vchiq-mmal/Makefile
34 rename drivers/staging/vc04_services/{bcm2835-camera => vchiq-mmal}/mmal-common.h (100%)
35 rename drivers/staging/vc04_services/{bcm2835-camera => vchiq-mmal}/mmal-encodings.h (100%)
36 rename drivers/staging/vc04_services/{bcm2835-camera => vchiq-mmal}/mmal-msg-common.h (100%)
37 rename drivers/staging/vc04_services/{bcm2835-camera => vchiq-mmal}/mmal-msg-format.h (100%)
38 rename drivers/staging/vc04_services/{bcm2835-camera => vchiq-mmal}/mmal-msg-port.h (100%)
39 rename drivers/staging/vc04_services/{bcm2835-camera => vchiq-mmal}/mmal-msg.h (100%)
40 rename drivers/staging/vc04_services/{bcm2835-camera => vchiq-mmal}/mmal-parameters.h (100%)
41 rename drivers/staging/vc04_services/{bcm2835-camera => vchiq-mmal}/mmal-vchiq.c (98%)
42 rename drivers/staging/vc04_services/{bcm2835-camera => vchiq-mmal}/mmal-vchiq.h (100%)
43
44 --- a/drivers/staging/vc04_services/Kconfig
45 +++ b/drivers/staging/vc04_services/Kconfig
46 @@ -21,6 +21,7 @@ config BCM2835_VCHIQ
47 source "drivers/staging/vc04_services/bcm2835-audio/Kconfig"
48
49 source "drivers/staging/vc04_services/bcm2835-camera/Kconfig"
50 +source "drivers/staging/vc04_services/vchiq-mmal/Kconfig"
51
52 endif
53
54 --- a/drivers/staging/vc04_services/Makefile
55 +++ b/drivers/staging/vc04_services/Makefile
56 @@ -12,6 +12,7 @@ vchiq-objs := \
57
58 obj-$(CONFIG_SND_BCM2835) += bcm2835-audio/
59 obj-$(CONFIG_VIDEO_BCM2835) += bcm2835-camera/
60 +obj-$(CONFIG_BCM2835_VCHIQ_MMAL) += vchiq-mmal/
61
62 ccflags-y += -Idrivers/staging/vc04_services -D__VCCOREVER__=0x04000000
63
64 --- a/drivers/staging/vc04_services/bcm2835-camera/Kconfig
65 +++ b/drivers/staging/vc04_services/bcm2835-camera/Kconfig
66 @@ -2,7 +2,7 @@ config VIDEO_BCM2835
67 tristate "BCM2835 Camera"
68 depends on MEDIA_SUPPORT
69 depends on VIDEO_V4L2 && (ARCH_BCM2835 || COMPILE_TEST)
70 - select BCM2835_VCHIQ
71 + select BCM2835_VCHIQ_MMAL
72 select VIDEOBUF2_VMALLOC
73 select BTREE
74 help
75 --- a/drivers/staging/vc04_services/bcm2835-camera/Makefile
76 +++ b/drivers/staging/vc04_services/bcm2835-camera/Makefile
77 @@ -1,11 +1,11 @@
78 # SPDX-License-Identifier: GPL-2.0
79 bcm2835-v4l2-$(CONFIG_VIDEO_BCM2835) := \
80 bcm2835-camera.o \
81 - controls.o \
82 - mmal-vchiq.o
83 + controls.o
84
85 obj-$(CONFIG_VIDEO_BCM2835) += bcm2835-v4l2.o
86
87 ccflags-y += \
88 -Idrivers/staging/vc04_services \
89 + -Idrivers/staging/vc04_services/vchiq-mmal \
90 -D__VCCOREVER__=0x04000000
91 --- /dev/null
92 +++ b/drivers/staging/vc04_services/vchiq-mmal/Kconfig
93 @@ -0,0 +1,7 @@
94 +config BCM2835_VCHIQ_MMAL
95 + tristate "BCM2835 MMAL VCHIQ service"
96 + depends on (ARCH_BCM2835 || COMPILE_TEST)
97 + select BCM2835_VCHIQ
98 + help
99 + Enables the MMAL API over VCHIQ as used for the
100 + majority of the multimedia services on VideoCore.
101 --- /dev/null
102 +++ b/drivers/staging/vc04_services/vchiq-mmal/Makefile
103 @@ -0,0 +1,8 @@
104 +# SPDX-License-Identifier: GPL-2.0
105 +bcm2835-mmal-vchiq-objs := mmal-vchiq.o
106 +
107 +obj-$(CONFIG_BCM2835_VCHIQ_MMAL) += bcm2835-mmal-vchiq.o
108 +
109 +ccflags-y += \
110 + -Idrivers/staging/vc04_services \
111 + -D__VCCOREVER__=0x04000000
112 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.c
113 +++ /dev/null
114 @@ -1,1899 +0,0 @@
115 -// SPDX-License-Identifier: GPL-2.0
116 -/*
117 - * Broadcom BM2835 V4L2 driver
118 - *
119 - * Copyright © 2013 Raspberry Pi (Trading) Ltd.
120 - *
121 - * Authors: Vincent Sanders @ Collabora
122 - * Dave Stevenson @ Broadcom
123 - * (now dave.stevenson@raspberrypi.org)
124 - * Simon Mellor @ Broadcom
125 - * Luke Diamand @ Broadcom
126 - *
127 - * V4L2 driver MMAL vchiq interface code
128 - */
129 -
130 -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
131 -
132 -#include <linux/errno.h>
133 -#include <linux/kernel.h>
134 -#include <linux/mutex.h>
135 -#include <linux/mm.h>
136 -#include <linux/slab.h>
137 -#include <linux/completion.h>
138 -#include <linux/vmalloc.h>
139 -#include <asm/cacheflush.h>
140 -#include <media/videobuf2-vmalloc.h>
141 -
142 -#include "mmal-common.h"
143 -#include "mmal-vchiq.h"
144 -#include "mmal-msg.h"
145 -
146 -#define USE_VCHIQ_ARM
147 -#include "interface/vchi/vchi.h"
148 -
149 -/* maximum number of components supported */
150 -#define VCHIQ_MMAL_MAX_COMPONENTS 4
151 -
152 -/*#define FULL_MSG_DUMP 1*/
153 -
154 -#ifdef DEBUG
155 -static const char *const msg_type_names[] = {
156 - "UNKNOWN",
157 - "QUIT",
158 - "SERVICE_CLOSED",
159 - "GET_VERSION",
160 - "COMPONENT_CREATE",
161 - "COMPONENT_DESTROY",
162 - "COMPONENT_ENABLE",
163 - "COMPONENT_DISABLE",
164 - "PORT_INFO_GET",
165 - "PORT_INFO_SET",
166 - "PORT_ACTION",
167 - "BUFFER_FROM_HOST",
168 - "BUFFER_TO_HOST",
169 - "GET_STATS",
170 - "PORT_PARAMETER_SET",
171 - "PORT_PARAMETER_GET",
172 - "EVENT_TO_HOST",
173 - "GET_CORE_STATS_FOR_PORT",
174 - "OPAQUE_ALLOCATOR",
175 - "CONSUME_MEM",
176 - "LMK",
177 - "OPAQUE_ALLOCATOR_DESC",
178 - "DRM_GET_LHS32",
179 - "DRM_GET_TIME",
180 - "BUFFER_FROM_HOST_ZEROLEN",
181 - "PORT_FLUSH",
182 - "HOST_LOG",
183 -};
184 -#endif
185 -
186 -static const char *const port_action_type_names[] = {
187 - "UNKNOWN",
188 - "ENABLE",
189 - "DISABLE",
190 - "FLUSH",
191 - "CONNECT",
192 - "DISCONNECT",
193 - "SET_REQUIREMENTS",
194 -};
195 -
196 -#if defined(DEBUG)
197 -#if defined(FULL_MSG_DUMP)
198 -#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
199 - do { \
200 - pr_debug(TITLE" type:%s(%d) length:%d\n", \
201 - msg_type_names[(MSG)->h.type], \
202 - (MSG)->h.type, (MSG_LEN)); \
203 - print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
204 - 16, 4, (MSG), \
205 - sizeof(struct mmal_msg_header), 1); \
206 - print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
207 - 16, 4, \
208 - ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
209 - (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
210 - } while (0)
211 -#else
212 -#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
213 - { \
214 - pr_debug(TITLE" type:%s(%d) length:%d\n", \
215 - msg_type_names[(MSG)->h.type], \
216 - (MSG)->h.type, (MSG_LEN)); \
217 - }
218 -#endif
219 -#else
220 -#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
221 -#endif
222 -
223 -struct vchiq_mmal_instance;
224 -
225 -/* normal message context */
226 -struct mmal_msg_context {
227 - struct vchiq_mmal_instance *instance;
228 -
229 - /* Index in the context_map idr so that we can find the
230 - * mmal_msg_context again when servicing the VCHI reply.
231 - */
232 - int handle;
233 -
234 - union {
235 - struct {
236 - /* work struct for buffer_cb callback */
237 - struct work_struct work;
238 - /* work struct for deferred callback */
239 - struct work_struct buffer_to_host_work;
240 - /* mmal instance */
241 - struct vchiq_mmal_instance *instance;
242 - /* mmal port */
243 - struct vchiq_mmal_port *port;
244 - /* actual buffer used to store bulk reply */
245 - struct mmal_buffer *buffer;
246 - /* amount of buffer used */
247 - unsigned long buffer_used;
248 - /* MMAL buffer flags */
249 - u32 mmal_flags;
250 - /* Presentation and Decode timestamps */
251 - s64 pts;
252 - s64 dts;
253 -
254 - int status; /* context status */
255 -
256 - } bulk; /* bulk data */
257 -
258 - struct {
259 - /* message handle to release */
260 - VCHI_HELD_MSG_T msg_handle;
261 - /* pointer to received message */
262 - struct mmal_msg *msg;
263 - /* received message length */
264 - u32 msg_len;
265 - /* completion upon reply */
266 - struct completion cmplt;
267 - } sync; /* synchronous response */
268 - } u;
269 -
270 -};
271 -
272 -struct vchiq_mmal_instance {
273 - VCHI_SERVICE_HANDLE_T handle;
274 -
275 - /* ensure serialised access to service */
276 - struct mutex vchiq_mutex;
277 -
278 - /* vmalloc page to receive scratch bulk xfers into */
279 - void *bulk_scratch;
280 -
281 - struct idr context_map;
282 - /* protect accesses to context_map */
283 - struct mutex context_map_lock;
284 -
285 - /* component to use next */
286 - int component_idx;
287 - struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
288 -
289 - /* ordered workqueue to process all bulk operations */
290 - struct workqueue_struct *bulk_wq;
291 -};
292 -
293 -static struct mmal_msg_context *
294 -get_msg_context(struct vchiq_mmal_instance *instance)
295 -{
296 - struct mmal_msg_context *msg_context;
297 - int handle;
298 -
299 - /* todo: should this be allocated from a pool to avoid kzalloc */
300 - msg_context = kzalloc(sizeof(*msg_context), GFP_KERNEL);
301 -
302 - if (!msg_context)
303 - return ERR_PTR(-ENOMEM);
304 -
305 - /* Create an ID that will be passed along with our message so
306 - * that when we service the VCHI reply, we can look up what
307 - * message is being replied to.
308 - */
309 - mutex_lock(&instance->context_map_lock);
310 - handle = idr_alloc(&instance->context_map, msg_context,
311 - 0, 0, GFP_KERNEL);
312 - mutex_unlock(&instance->context_map_lock);
313 -
314 - if (handle < 0) {
315 - kfree(msg_context);
316 - return ERR_PTR(handle);
317 - }
318 -
319 - msg_context->instance = instance;
320 - msg_context->handle = handle;
321 -
322 - return msg_context;
323 -}
324 -
325 -static struct mmal_msg_context *
326 -lookup_msg_context(struct vchiq_mmal_instance *instance, int handle)
327 -{
328 - return idr_find(&instance->context_map, handle);
329 -}
330 -
331 -static void
332 -release_msg_context(struct mmal_msg_context *msg_context)
333 -{
334 - struct vchiq_mmal_instance *instance = msg_context->instance;
335 -
336 - mutex_lock(&instance->context_map_lock);
337 - idr_remove(&instance->context_map, msg_context->handle);
338 - mutex_unlock(&instance->context_map_lock);
339 - kfree(msg_context);
340 -}
341 -
342 -/* deals with receipt of event to host message */
343 -static void event_to_host_cb(struct vchiq_mmal_instance *instance,
344 - struct mmal_msg *msg, u32 msg_len)
345 -{
346 - pr_debug("unhandled event\n");
347 - pr_debug("component:%u port type:%d num:%d cmd:0x%x length:%d\n",
348 - msg->u.event_to_host.client_component,
349 - msg->u.event_to_host.port_type,
350 - msg->u.event_to_host.port_num,
351 - msg->u.event_to_host.cmd, msg->u.event_to_host.length);
352 -}
353 -
354 -/* workqueue scheduled callback
355 - *
356 - * we do this because it is important we do not call any other vchiq
357 - * sync calls from witin the message delivery thread
358 - */
359 -static void buffer_work_cb(struct work_struct *work)
360 -{
361 - struct mmal_msg_context *msg_context =
362 - container_of(work, struct mmal_msg_context, u.bulk.work);
363 -
364 - atomic_dec(&msg_context->u.bulk.port->buffers_with_vpu);
365 -
366 - msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
367 - msg_context->u.bulk.port,
368 - msg_context->u.bulk.status,
369 - msg_context->u.bulk.buffer,
370 - msg_context->u.bulk.buffer_used,
371 - msg_context->u.bulk.mmal_flags,
372 - msg_context->u.bulk.dts,
373 - msg_context->u.bulk.pts);
374 -}
375 -
376 -/* workqueue scheduled callback to handle receiving buffers
377 - *
378 - * VCHI will allow up to 4 bulk receives to be scheduled before blocking.
379 - * If we block in the service_callback context then we can't process the
380 - * VCHI_CALLBACK_BULK_RECEIVED message that would otherwise allow the blocked
381 - * vchi_bulk_queue_receive() call to complete.
382 - */
383 -static void buffer_to_host_work_cb(struct work_struct *work)
384 -{
385 - struct mmal_msg_context *msg_context =
386 - container_of(work, struct mmal_msg_context,
387 - u.bulk.buffer_to_host_work);
388 - struct vchiq_mmal_instance *instance = msg_context->instance;
389 - unsigned long len = msg_context->u.bulk.buffer_used;
390 - int ret;
391 -
392 - if (!len)
393 - /* Dummy receive to ensure the buffers remain in order */
394 - len = 8;
395 - /* queue the bulk submission */
396 - vchi_service_use(instance->handle);
397 - ret = vchi_bulk_queue_receive(instance->handle,
398 - msg_context->u.bulk.buffer->buffer,
399 - /* Actual receive needs to be a multiple
400 - * of 4 bytes
401 - */
402 - (len + 3) & ~3,
403 - VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
404 - VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
405 - msg_context);
406 -
407 - vchi_service_release(instance->handle);
408 -
409 - if (ret != 0)
410 - pr_err("%s: ctx: %p, vchi_bulk_queue_receive failed %d\n",
411 - __func__, msg_context, ret);
412 -}
413 -
414 -/* enqueue a bulk receive for a given message context */
415 -static int bulk_receive(struct vchiq_mmal_instance *instance,
416 - struct mmal_msg *msg,
417 - struct mmal_msg_context *msg_context)
418 -{
419 - unsigned long rd_len;
420 -
421 - rd_len = msg->u.buffer_from_host.buffer_header.length;
422 -
423 - if (!msg_context->u.bulk.buffer) {
424 - pr_err("bulk.buffer not configured - error in buffer_from_host\n");
425 -
426 - /* todo: this is a serious error, we should never have
427 - * committed a buffer_to_host operation to the mmal
428 - * port without the buffer to back it up (underflow
429 - * handling) and there is no obvious way to deal with
430 - * this - how is the mmal servie going to react when
431 - * we fail to do the xfer and reschedule a buffer when
432 - * it arrives? perhaps a starved flag to indicate a
433 - * waiting bulk receive?
434 - */
435 -
436 - return -EINVAL;
437 - }
438 -
439 - /* ensure we do not overrun the available buffer */
440 - if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
441 - rd_len = msg_context->u.bulk.buffer->buffer_size;
442 - pr_warn("short read as not enough receive buffer space\n");
443 - /* todo: is this the correct response, what happens to
444 - * the rest of the message data?
445 - */
446 - }
447 -
448 - /* store length */
449 - msg_context->u.bulk.buffer_used = rd_len;
450 - msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
451 - msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
452 -
453 - queue_work(msg_context->instance->bulk_wq,
454 - &msg_context->u.bulk.buffer_to_host_work);
455 -
456 - return 0;
457 -}
458 -
459 -/* data in message, memcpy from packet into output buffer */
460 -static int inline_receive(struct vchiq_mmal_instance *instance,
461 - struct mmal_msg *msg,
462 - struct mmal_msg_context *msg_context)
463 -{
464 - memcpy(msg_context->u.bulk.buffer->buffer,
465 - msg->u.buffer_from_host.short_data,
466 - msg->u.buffer_from_host.payload_in_message);
467 -
468 - msg_context->u.bulk.buffer_used =
469 - msg->u.buffer_from_host.payload_in_message;
470 -
471 - return 0;
472 -}
473 -
474 -/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
475 -static int
476 -buffer_from_host(struct vchiq_mmal_instance *instance,
477 - struct vchiq_mmal_port *port, struct mmal_buffer *buf)
478 -{
479 - struct mmal_msg_context *msg_context;
480 - struct mmal_msg m;
481 - int ret;
482 -
483 - if (!port->enabled)
484 - return -EINVAL;
485 -
486 - pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
487 -
488 - /* get context */
489 - if (!buf->msg_context) {
490 - pr_err("%s: msg_context not allocated, buf %p\n", __func__,
491 - buf);
492 - return -EINVAL;
493 - }
494 - msg_context = buf->msg_context;
495 -
496 - /* store bulk message context for when data arrives */
497 - msg_context->u.bulk.instance = instance;
498 - msg_context->u.bulk.port = port;
499 - msg_context->u.bulk.buffer = buf;
500 - msg_context->u.bulk.buffer_used = 0;
501 -
502 - /* initialise work structure ready to schedule callback */
503 - INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
504 - INIT_WORK(&msg_context->u.bulk.buffer_to_host_work,
505 - buffer_to_host_work_cb);
506 -
507 - atomic_inc(&port->buffers_with_vpu);
508 -
509 - /* prep the buffer from host message */
510 - memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
511 -
512 - m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
513 - m.h.magic = MMAL_MAGIC;
514 - m.h.context = msg_context->handle;
515 - m.h.status = 0;
516 -
517 - /* drvbuf is our private data passed back */
518 - m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
519 - m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
520 - m.u.buffer_from_host.drvbuf.port_handle = port->handle;
521 - m.u.buffer_from_host.drvbuf.client_context = msg_context->handle;
522 -
523 - /* buffer header */
524 - m.u.buffer_from_host.buffer_header.cmd = 0;
525 - m.u.buffer_from_host.buffer_header.data =
526 - (u32)(unsigned long)buf->buffer;
527 - m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
528 - m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
529 - m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
530 - m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
531 - m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
532 - m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
533 -
534 - /* clear buffer type sepecific data */
535 - memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
536 - sizeof(m.u.buffer_from_host.buffer_header_type_specific));
537 -
538 - /* no payload in message */
539 - m.u.buffer_from_host.payload_in_message = 0;
540 -
541 - vchi_service_use(instance->handle);
542 -
543 - ret = vchi_queue_kernel_message(instance->handle,
544 - &m,
545 - sizeof(struct mmal_msg_header) +
546 - sizeof(m.u.buffer_from_host));
547 -
548 - vchi_service_release(instance->handle);
549 -
550 - return ret;
551 -}
552 -
553 -/* deals with receipt of buffer to host message */
554 -static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
555 - struct mmal_msg *msg, u32 msg_len)
556 -{
557 - struct mmal_msg_context *msg_context;
558 - u32 handle;
559 -
560 - pr_debug("%s: instance:%p msg:%p msg_len:%d\n",
561 - __func__, instance, msg, msg_len);
562 -
563 - if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
564 - handle = msg->u.buffer_from_host.drvbuf.client_context;
565 - msg_context = lookup_msg_context(instance, handle);
566 -
567 - if (!msg_context) {
568 - pr_err("drvbuf.client_context(%u) is invalid\n",
569 - handle);
570 - return;
571 - }
572 - } else {
573 - pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
574 - return;
575 - }
576 -
577 - msg_context->u.bulk.mmal_flags =
578 - msg->u.buffer_from_host.buffer_header.flags;
579 -
580 - if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
581 - /* message reception had an error */
582 - pr_warn("error %d in reply\n", msg->h.status);
583 -
584 - msg_context->u.bulk.status = msg->h.status;
585 -
586 - } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
587 - /* empty buffer */
588 - if (msg->u.buffer_from_host.buffer_header.flags &
589 - MMAL_BUFFER_HEADER_FLAG_EOS) {
590 - msg_context->u.bulk.status =
591 - bulk_receive(instance, msg, msg_context);
592 - if (msg_context->u.bulk.status == 0)
593 - return; /* successful bulk submission, bulk
594 - * completion will trigger callback
595 - */
596 - } else {
597 - /* do callback with empty buffer - not EOS though */
598 - msg_context->u.bulk.status = 0;
599 - msg_context->u.bulk.buffer_used = 0;
600 - }
601 - } else if (msg->u.buffer_from_host.payload_in_message == 0) {
602 - /* data is not in message, queue a bulk receive */
603 - msg_context->u.bulk.status =
604 - bulk_receive(instance, msg, msg_context);
605 - if (msg_context->u.bulk.status == 0)
606 - return; /* successful bulk submission, bulk
607 - * completion will trigger callback
608 - */
609 -
610 - /* failed to submit buffer, this will end badly */
611 - pr_err("error %d on bulk submission\n",
612 - msg_context->u.bulk.status);
613 -
614 - } else if (msg->u.buffer_from_host.payload_in_message <=
615 - MMAL_VC_SHORT_DATA) {
616 - /* data payload within message */
617 - msg_context->u.bulk.status = inline_receive(instance, msg,
618 - msg_context);
619 - } else {
620 - pr_err("message with invalid short payload\n");
621 -
622 - /* signal error */
623 - msg_context->u.bulk.status = -EINVAL;
624 - msg_context->u.bulk.buffer_used =
625 - msg->u.buffer_from_host.payload_in_message;
626 - }
627 -
628 - /* schedule the port callback */
629 - schedule_work(&msg_context->u.bulk.work);
630 -}
631 -
632 -static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
633 - struct mmal_msg_context *msg_context)
634 -{
635 - msg_context->u.bulk.status = 0;
636 -
637 - /* schedule the port callback */
638 - schedule_work(&msg_context->u.bulk.work);
639 -}
640 -
641 -static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
642 - struct mmal_msg_context *msg_context)
643 -{
644 - pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
645 -
646 - msg_context->u.bulk.status = -EINTR;
647 -
648 - schedule_work(&msg_context->u.bulk.work);
649 -}
650 -
651 -/* incoming event service callback */
652 -static void service_callback(void *param,
653 - const VCHI_CALLBACK_REASON_T reason,
654 - void *bulk_ctx)
655 -{
656 - struct vchiq_mmal_instance *instance = param;
657 - int status;
658 - u32 msg_len;
659 - struct mmal_msg *msg;
660 - VCHI_HELD_MSG_T msg_handle;
661 - struct mmal_msg_context *msg_context;
662 -
663 - if (!instance) {
664 - pr_err("Message callback passed NULL instance\n");
665 - return;
666 - }
667 -
668 - switch (reason) {
669 - case VCHI_CALLBACK_MSG_AVAILABLE:
670 - status = vchi_msg_hold(instance->handle, (void **)&msg,
671 - &msg_len, VCHI_FLAGS_NONE, &msg_handle);
672 - if (status) {
673 - pr_err("Unable to dequeue a message (%d)\n", status);
674 - break;
675 - }
676 -
677 - DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
678 -
679 - /* handling is different for buffer messages */
680 - switch (msg->h.type) {
681 - case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
682 - vchi_held_msg_release(&msg_handle);
683 - break;
684 -
685 - case MMAL_MSG_TYPE_EVENT_TO_HOST:
686 - event_to_host_cb(instance, msg, msg_len);
687 - vchi_held_msg_release(&msg_handle);
688 -
689 - break;
690 -
691 - case MMAL_MSG_TYPE_BUFFER_TO_HOST:
692 - buffer_to_host_cb(instance, msg, msg_len);
693 - vchi_held_msg_release(&msg_handle);
694 - break;
695 -
696 - default:
697 - /* messages dependent on header context to complete */
698 - if (!msg->h.context) {
699 - pr_err("received message context was null!\n");
700 - vchi_held_msg_release(&msg_handle);
701 - break;
702 - }
703 -
704 - msg_context = lookup_msg_context(instance,
705 - msg->h.context);
706 - if (!msg_context) {
707 - pr_err("received invalid message context %u!\n",
708 - msg->h.context);
709 - vchi_held_msg_release(&msg_handle);
710 - break;
711 - }
712 -
713 - /* fill in context values */
714 - msg_context->u.sync.msg_handle = msg_handle;
715 - msg_context->u.sync.msg = msg;
716 - msg_context->u.sync.msg_len = msg_len;
717 -
718 - /* todo: should this check (completion_done()
719 - * == 1) for no one waiting? or do we need a
720 - * flag to tell us the completion has been
721 - * interrupted so we can free the message and
722 - * its context. This probably also solves the
723 - * message arriving after interruption todo
724 - * below
725 - */
726 -
727 - /* complete message so caller knows it happened */
728 - complete(&msg_context->u.sync.cmplt);
729 - break;
730 - }
731 -
732 - break;
733 -
734 - case VCHI_CALLBACK_BULK_RECEIVED:
735 - bulk_receive_cb(instance, bulk_ctx);
736 - break;
737 -
738 - case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
739 - bulk_abort_cb(instance, bulk_ctx);
740 - break;
741 -
742 - case VCHI_CALLBACK_SERVICE_CLOSED:
743 - /* TODO: consider if this requires action if received when
744 - * driver is not explicitly closing the service
745 - */
746 - break;
747 -
748 - default:
749 - pr_err("Received unhandled message reason %d\n", reason);
750 - break;
751 - }
752 -}
753 -
754 -static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
755 - struct mmal_msg *msg,
756 - unsigned int payload_len,
757 - struct mmal_msg **msg_out,
758 - VCHI_HELD_MSG_T *msg_handle_out)
759 -{
760 - struct mmal_msg_context *msg_context;
761 - int ret;
762 - unsigned long timeout;
763 -
764 - /* payload size must not cause message to exceed max size */
765 - if (payload_len >
766 - (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
767 - pr_err("payload length %d exceeds max:%d\n", payload_len,
768 - (int)(MMAL_MSG_MAX_SIZE -
769 - sizeof(struct mmal_msg_header)));
770 - return -EINVAL;
771 - }
772 -
773 - msg_context = get_msg_context(instance);
774 - if (IS_ERR(msg_context))
775 - return PTR_ERR(msg_context);
776 -
777 - init_completion(&msg_context->u.sync.cmplt);
778 -
779 - msg->h.magic = MMAL_MAGIC;
780 - msg->h.context = msg_context->handle;
781 - msg->h.status = 0;
782 -
783 - DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
784 - ">>> sync message");
785 -
786 - vchi_service_use(instance->handle);
787 -
788 - ret = vchi_queue_kernel_message(instance->handle,
789 - msg,
790 - sizeof(struct mmal_msg_header) +
791 - payload_len);
792 -
793 - vchi_service_release(instance->handle);
794 -
795 - if (ret) {
796 - pr_err("error %d queuing message\n", ret);
797 - release_msg_context(msg_context);
798 - return ret;
799 - }
800 -
801 - timeout = wait_for_completion_timeout(&msg_context->u.sync.cmplt,
802 - 3 * HZ);
803 - if (timeout == 0) {
804 - pr_err("timed out waiting for sync completion\n");
805 - ret = -ETIME;
806 - /* todo: what happens if the message arrives after aborting */
807 - release_msg_context(msg_context);
808 - return ret;
809 - }
810 -
811 - *msg_out = msg_context->u.sync.msg;
812 - *msg_handle_out = msg_context->u.sync.msg_handle;
813 - release_msg_context(msg_context);
814 -
815 - return 0;
816 -}
817 -
818 -static void dump_port_info(struct vchiq_mmal_port *port)
819 -{
820 - pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
821 -
822 - pr_debug("buffer minimum num:%d size:%d align:%d\n",
823 - port->minimum_buffer.num,
824 - port->minimum_buffer.size, port->minimum_buffer.alignment);
825 -
826 - pr_debug("buffer recommended num:%d size:%d align:%d\n",
827 - port->recommended_buffer.num,
828 - port->recommended_buffer.size,
829 - port->recommended_buffer.alignment);
830 -
831 - pr_debug("buffer current values num:%d size:%d align:%d\n",
832 - port->current_buffer.num,
833 - port->current_buffer.size, port->current_buffer.alignment);
834 -
835 - pr_debug("elementary stream: type:%d encoding:0x%x variant:0x%x\n",
836 - port->format.type,
837 - port->format.encoding, port->format.encoding_variant);
838 -
839 - pr_debug(" bitrate:%d flags:0x%x\n",
840 - port->format.bitrate, port->format.flags);
841 -
842 - if (port->format.type == MMAL_ES_TYPE_VIDEO) {
843 - pr_debug
844 - ("es video format: width:%d height:%d colourspace:0x%x\n",
845 - port->es.video.width, port->es.video.height,
846 - port->es.video.color_space);
847 -
848 - pr_debug(" : crop xywh %d,%d,%d,%d\n",
849 - port->es.video.crop.x,
850 - port->es.video.crop.y,
851 - port->es.video.crop.width, port->es.video.crop.height);
852 - pr_debug(" : framerate %d/%d aspect %d/%d\n",
853 - port->es.video.frame_rate.num,
854 - port->es.video.frame_rate.den,
855 - port->es.video.par.num, port->es.video.par.den);
856 - }
857 -}
858 -
859 -static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
860 -{
861 - /* todo do readonly fields need setting at all? */
862 - p->type = port->type;
863 - p->index = port->index;
864 - p->index_all = 0;
865 - p->is_enabled = port->enabled;
866 - p->buffer_num_min = port->minimum_buffer.num;
867 - p->buffer_size_min = port->minimum_buffer.size;
868 - p->buffer_alignment_min = port->minimum_buffer.alignment;
869 - p->buffer_num_recommended = port->recommended_buffer.num;
870 - p->buffer_size_recommended = port->recommended_buffer.size;
871 -
872 - /* only three writable fields in a port */
873 - p->buffer_num = port->current_buffer.num;
874 - p->buffer_size = port->current_buffer.size;
875 - p->userdata = (u32)(unsigned long)port;
876 -}
877 -
878 -static int port_info_set(struct vchiq_mmal_instance *instance,
879 - struct vchiq_mmal_port *port)
880 -{
881 - int ret;
882 - struct mmal_msg m;
883 - struct mmal_msg *rmsg;
884 - VCHI_HELD_MSG_T rmsg_handle;
885 -
886 - pr_debug("setting port info port %p\n", port);
887 - if (!port)
888 - return -1;
889 - dump_port_info(port);
890 -
891 - m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
892 -
893 - m.u.port_info_set.component_handle = port->component->handle;
894 - m.u.port_info_set.port_type = port->type;
895 - m.u.port_info_set.port_index = port->index;
896 -
897 - port_to_mmal_msg(port, &m.u.port_info_set.port);
898 -
899 - /* elementary stream format setup */
900 - m.u.port_info_set.format.type = port->format.type;
901 - m.u.port_info_set.format.encoding = port->format.encoding;
902 - m.u.port_info_set.format.encoding_variant =
903 - port->format.encoding_variant;
904 - m.u.port_info_set.format.bitrate = port->format.bitrate;
905 - m.u.port_info_set.format.flags = port->format.flags;
906 -
907 - memcpy(&m.u.port_info_set.es, &port->es,
908 - sizeof(union mmal_es_specific_format));
909 -
910 - m.u.port_info_set.format.extradata_size = port->format.extradata_size;
911 - memcpy(&m.u.port_info_set.extradata, port->format.extradata,
912 - port->format.extradata_size);
913 -
914 - ret = send_synchronous_mmal_msg(instance, &m,
915 - sizeof(m.u.port_info_set),
916 - &rmsg, &rmsg_handle);
917 - if (ret)
918 - return ret;
919 -
920 - if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
921 - /* got an unexpected message type in reply */
922 - ret = -EINVAL;
923 - goto release_msg;
924 - }
925 -
926 - /* return operation status */
927 - ret = -rmsg->u.port_info_get_reply.status;
928 -
929 - pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
930 - port->component->handle, port->handle);
931 -
932 -release_msg:
933 - vchi_held_msg_release(&rmsg_handle);
934 -
935 - return ret;
936 -}
937 -
938 -/* use port info get message to retrieve port information */
939 -static int port_info_get(struct vchiq_mmal_instance *instance,
940 - struct vchiq_mmal_port *port)
941 -{
942 - int ret;
943 - struct mmal_msg m;
944 - struct mmal_msg *rmsg;
945 - VCHI_HELD_MSG_T rmsg_handle;
946 -
947 - /* port info time */
948 - m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
949 - m.u.port_info_get.component_handle = port->component->handle;
950 - m.u.port_info_get.port_type = port->type;
951 - m.u.port_info_get.index = port->index;
952 -
953 - ret = send_synchronous_mmal_msg(instance, &m,
954 - sizeof(m.u.port_info_get),
955 - &rmsg, &rmsg_handle);
956 - if (ret)
957 - return ret;
958 -
959 - if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
960 - /* got an unexpected message type in reply */
961 - ret = -EINVAL;
962 - goto release_msg;
963 - }
964 -
965 - /* return operation status */
966 - ret = -rmsg->u.port_info_get_reply.status;
967 - if (ret != MMAL_MSG_STATUS_SUCCESS)
968 - goto release_msg;
969 -
970 - if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
971 - port->enabled = false;
972 - else
973 - port->enabled = true;
974 -
975 - /* copy the values out of the message */
976 - port->handle = rmsg->u.port_info_get_reply.port_handle;
977 -
978 - /* port type and index cached to use on port info set because
979 - * it does not use a port handle
980 - */
981 - port->type = rmsg->u.port_info_get_reply.port_type;
982 - port->index = rmsg->u.port_info_get_reply.port_index;
983 -
984 - port->minimum_buffer.num =
985 - rmsg->u.port_info_get_reply.port.buffer_num_min;
986 - port->minimum_buffer.size =
987 - rmsg->u.port_info_get_reply.port.buffer_size_min;
988 - port->minimum_buffer.alignment =
989 - rmsg->u.port_info_get_reply.port.buffer_alignment_min;
990 -
991 - port->recommended_buffer.alignment =
992 - rmsg->u.port_info_get_reply.port.buffer_alignment_min;
993 - port->recommended_buffer.num =
994 - rmsg->u.port_info_get_reply.port.buffer_num_recommended;
995 -
996 - port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
997 - port->current_buffer.size =
998 - rmsg->u.port_info_get_reply.port.buffer_size;
999 -
1000 - /* stream format */
1001 - port->format.type = rmsg->u.port_info_get_reply.format.type;
1002 - port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
1003 - port->format.encoding_variant =
1004 - rmsg->u.port_info_get_reply.format.encoding_variant;
1005 - port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
1006 - port->format.flags = rmsg->u.port_info_get_reply.format.flags;
1007 -
1008 - /* elementary stream format */
1009 - memcpy(&port->es,
1010 - &rmsg->u.port_info_get_reply.es,
1011 - sizeof(union mmal_es_specific_format));
1012 - port->format.es = &port->es;
1013 -
1014 - port->format.extradata_size =
1015 - rmsg->u.port_info_get_reply.format.extradata_size;
1016 - memcpy(port->format.extradata,
1017 - rmsg->u.port_info_get_reply.extradata,
1018 - port->format.extradata_size);
1019 -
1020 - pr_debug("received port info\n");
1021 - dump_port_info(port);
1022 -
1023 -release_msg:
1024 -
1025 - pr_debug("%s:result:%d component:0x%x port:%d\n",
1026 - __func__, ret, port->component->handle, port->handle);
1027 -
1028 - vchi_held_msg_release(&rmsg_handle);
1029 -
1030 - return ret;
1031 -}
1032 -
1033 -/* create comonent on vc */
1034 -static int create_component(struct vchiq_mmal_instance *instance,
1035 - struct vchiq_mmal_component *component,
1036 - const char *name)
1037 -{
1038 - int ret;
1039 - struct mmal_msg m;
1040 - struct mmal_msg *rmsg;
1041 - VCHI_HELD_MSG_T rmsg_handle;
1042 -
1043 - /* build component create message */
1044 - m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
1045 - m.u.component_create.client_component = (u32)(unsigned long)component;
1046 - strncpy(m.u.component_create.name, name,
1047 - sizeof(m.u.component_create.name));
1048 -
1049 - ret = send_synchronous_mmal_msg(instance, &m,
1050 - sizeof(m.u.component_create),
1051 - &rmsg, &rmsg_handle);
1052 - if (ret)
1053 - return ret;
1054 -
1055 - if (rmsg->h.type != m.h.type) {
1056 - /* got an unexpected message type in reply */
1057 - ret = -EINVAL;
1058 - goto release_msg;
1059 - }
1060 -
1061 - ret = -rmsg->u.component_create_reply.status;
1062 - if (ret != MMAL_MSG_STATUS_SUCCESS)
1063 - goto release_msg;
1064 -
1065 - /* a valid component response received */
1066 - component->handle = rmsg->u.component_create_reply.component_handle;
1067 - component->inputs = rmsg->u.component_create_reply.input_num;
1068 - component->outputs = rmsg->u.component_create_reply.output_num;
1069 - component->clocks = rmsg->u.component_create_reply.clock_num;
1070 -
1071 - pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
1072 - component->handle,
1073 - component->inputs, component->outputs, component->clocks);
1074 -
1075 -release_msg:
1076 - vchi_held_msg_release(&rmsg_handle);
1077 -
1078 - return ret;
1079 -}
1080 -
1081 -/* destroys a component on vc */
1082 -static int destroy_component(struct vchiq_mmal_instance *instance,
1083 - struct vchiq_mmal_component *component)
1084 -{
1085 - int ret;
1086 - struct mmal_msg m;
1087 - struct mmal_msg *rmsg;
1088 - VCHI_HELD_MSG_T rmsg_handle;
1089 -
1090 - m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
1091 - m.u.component_destroy.component_handle = component->handle;
1092 -
1093 - ret = send_synchronous_mmal_msg(instance, &m,
1094 - sizeof(m.u.component_destroy),
1095 - &rmsg, &rmsg_handle);
1096 - if (ret)
1097 - return ret;
1098 -
1099 - if (rmsg->h.type != m.h.type) {
1100 - /* got an unexpected message type in reply */
1101 - ret = -EINVAL;
1102 - goto release_msg;
1103 - }
1104 -
1105 - ret = -rmsg->u.component_destroy_reply.status;
1106 -
1107 -release_msg:
1108 -
1109 - vchi_held_msg_release(&rmsg_handle);
1110 -
1111 - return ret;
1112 -}
1113 -
1114 -/* enable a component on vc */
1115 -static int enable_component(struct vchiq_mmal_instance *instance,
1116 - struct vchiq_mmal_component *component)
1117 -{
1118 - int ret;
1119 - struct mmal_msg m;
1120 - struct mmal_msg *rmsg;
1121 - VCHI_HELD_MSG_T rmsg_handle;
1122 -
1123 - m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
1124 - m.u.component_enable.component_handle = component->handle;
1125 -
1126 - ret = send_synchronous_mmal_msg(instance, &m,
1127 - sizeof(m.u.component_enable),
1128 - &rmsg, &rmsg_handle);
1129 - if (ret)
1130 - return ret;
1131 -
1132 - if (rmsg->h.type != m.h.type) {
1133 - /* got an unexpected message type in reply */
1134 - ret = -EINVAL;
1135 - goto release_msg;
1136 - }
1137 -
1138 - ret = -rmsg->u.component_enable_reply.status;
1139 -
1140 -release_msg:
1141 - vchi_held_msg_release(&rmsg_handle);
1142 -
1143 - return ret;
1144 -}
1145 -
1146 -/* disable a component on vc */
1147 -static int disable_component(struct vchiq_mmal_instance *instance,
1148 - struct vchiq_mmal_component *component)
1149 -{
1150 - int ret;
1151 - struct mmal_msg m;
1152 - struct mmal_msg *rmsg;
1153 - VCHI_HELD_MSG_T rmsg_handle;
1154 -
1155 - m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
1156 - m.u.component_disable.component_handle = component->handle;
1157 -
1158 - ret = send_synchronous_mmal_msg(instance, &m,
1159 - sizeof(m.u.component_disable),
1160 - &rmsg, &rmsg_handle);
1161 - if (ret)
1162 - return ret;
1163 -
1164 - if (rmsg->h.type != m.h.type) {
1165 - /* got an unexpected message type in reply */
1166 - ret = -EINVAL;
1167 - goto release_msg;
1168 - }
1169 -
1170 - ret = -rmsg->u.component_disable_reply.status;
1171 -
1172 -release_msg:
1173 -
1174 - vchi_held_msg_release(&rmsg_handle);
1175 -
1176 - return ret;
1177 -}
1178 -
1179 -/* get version of mmal implementation */
1180 -static int get_version(struct vchiq_mmal_instance *instance,
1181 - u32 *major_out, u32 *minor_out)
1182 -{
1183 - int ret;
1184 - struct mmal_msg m;
1185 - struct mmal_msg *rmsg;
1186 - VCHI_HELD_MSG_T rmsg_handle;
1187 -
1188 - m.h.type = MMAL_MSG_TYPE_GET_VERSION;
1189 -
1190 - ret = send_synchronous_mmal_msg(instance, &m,
1191 - sizeof(m.u.version),
1192 - &rmsg, &rmsg_handle);
1193 - if (ret)
1194 - return ret;
1195 -
1196 - if (rmsg->h.type != m.h.type) {
1197 - /* got an unexpected message type in reply */
1198 - ret = -EINVAL;
1199 - goto release_msg;
1200 - }
1201 -
1202 - *major_out = rmsg->u.version.major;
1203 - *minor_out = rmsg->u.version.minor;
1204 -
1205 -release_msg:
1206 - vchi_held_msg_release(&rmsg_handle);
1207 -
1208 - return ret;
1209 -}
1210 -
1211 -/* do a port action with a port as a parameter */
1212 -static int port_action_port(struct vchiq_mmal_instance *instance,
1213 - struct vchiq_mmal_port *port,
1214 - enum mmal_msg_port_action_type action_type)
1215 -{
1216 - int ret;
1217 - struct mmal_msg m;
1218 - struct mmal_msg *rmsg;
1219 - VCHI_HELD_MSG_T rmsg_handle;
1220 -
1221 - m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
1222 - m.u.port_action_port.component_handle = port->component->handle;
1223 - m.u.port_action_port.port_handle = port->handle;
1224 - m.u.port_action_port.action = action_type;
1225 -
1226 - port_to_mmal_msg(port, &m.u.port_action_port.port);
1227 -
1228 - ret = send_synchronous_mmal_msg(instance, &m,
1229 - sizeof(m.u.port_action_port),
1230 - &rmsg, &rmsg_handle);
1231 - if (ret)
1232 - return ret;
1233 -
1234 - if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
1235 - /* got an unexpected message type in reply */
1236 - ret = -EINVAL;
1237 - goto release_msg;
1238 - }
1239 -
1240 - ret = -rmsg->u.port_action_reply.status;
1241 -
1242 - pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
1243 - __func__,
1244 - ret, port->component->handle, port->handle,
1245 - port_action_type_names[action_type], action_type);
1246 -
1247 -release_msg:
1248 - vchi_held_msg_release(&rmsg_handle);
1249 -
1250 - return ret;
1251 -}
1252 -
1253 -/* do a port action with handles as parameters */
1254 -static int port_action_handle(struct vchiq_mmal_instance *instance,
1255 - struct vchiq_mmal_port *port,
1256 - enum mmal_msg_port_action_type action_type,
1257 - u32 connect_component_handle,
1258 - u32 connect_port_handle)
1259 -{
1260 - int ret;
1261 - struct mmal_msg m;
1262 - struct mmal_msg *rmsg;
1263 - VCHI_HELD_MSG_T rmsg_handle;
1264 -
1265 - m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
1266 -
1267 - m.u.port_action_handle.component_handle = port->component->handle;
1268 - m.u.port_action_handle.port_handle = port->handle;
1269 - m.u.port_action_handle.action = action_type;
1270 -
1271 - m.u.port_action_handle.connect_component_handle =
1272 - connect_component_handle;
1273 - m.u.port_action_handle.connect_port_handle = connect_port_handle;
1274 -
1275 - ret = send_synchronous_mmal_msg(instance, &m,
1276 - sizeof(m.u.port_action_handle),
1277 - &rmsg, &rmsg_handle);
1278 - if (ret)
1279 - return ret;
1280 -
1281 - if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
1282 - /* got an unexpected message type in reply */
1283 - ret = -EINVAL;
1284 - goto release_msg;
1285 - }
1286 -
1287 - ret = -rmsg->u.port_action_reply.status;
1288 -
1289 - pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d) connect component:0x%x connect port:%d\n",
1290 - __func__,
1291 - ret, port->component->handle, port->handle,
1292 - port_action_type_names[action_type],
1293 - action_type, connect_component_handle, connect_port_handle);
1294 -
1295 -release_msg:
1296 - vchi_held_msg_release(&rmsg_handle);
1297 -
1298 - return ret;
1299 -}
1300 -
1301 -static int port_parameter_set(struct vchiq_mmal_instance *instance,
1302 - struct vchiq_mmal_port *port,
1303 - u32 parameter_id, void *value, u32 value_size)
1304 -{
1305 - int ret;
1306 - struct mmal_msg m;
1307 - struct mmal_msg *rmsg;
1308 - VCHI_HELD_MSG_T rmsg_handle;
1309 -
1310 - m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
1311 -
1312 - m.u.port_parameter_set.component_handle = port->component->handle;
1313 - m.u.port_parameter_set.port_handle = port->handle;
1314 - m.u.port_parameter_set.id = parameter_id;
1315 - m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
1316 - memcpy(&m.u.port_parameter_set.value, value, value_size);
1317 -
1318 - ret = send_synchronous_mmal_msg(instance, &m,
1319 - (4 * sizeof(u32)) + value_size,
1320 - &rmsg, &rmsg_handle);
1321 - if (ret)
1322 - return ret;
1323 -
1324 - if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
1325 - /* got an unexpected message type in reply */
1326 - ret = -EINVAL;
1327 - goto release_msg;
1328 - }
1329 -
1330 - ret = -rmsg->u.port_parameter_set_reply.status;
1331 -
1332 - pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
1333 - __func__,
1334 - ret, port->component->handle, port->handle, parameter_id);
1335 -
1336 -release_msg:
1337 - vchi_held_msg_release(&rmsg_handle);
1338 -
1339 - return ret;
1340 -}
1341 -
1342 -static int port_parameter_get(struct vchiq_mmal_instance *instance,
1343 - struct vchiq_mmal_port *port,
1344 - u32 parameter_id, void *value, u32 *value_size)
1345 -{
1346 - int ret;
1347 - struct mmal_msg m;
1348 - struct mmal_msg *rmsg;
1349 - VCHI_HELD_MSG_T rmsg_handle;
1350 -
1351 - m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
1352 -
1353 - m.u.port_parameter_get.component_handle = port->component->handle;
1354 - m.u.port_parameter_get.port_handle = port->handle;
1355 - m.u.port_parameter_get.id = parameter_id;
1356 - m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
1357 -
1358 - ret = send_synchronous_mmal_msg(instance, &m,
1359 - sizeof(struct
1360 - mmal_msg_port_parameter_get),
1361 - &rmsg, &rmsg_handle);
1362 - if (ret)
1363 - return ret;
1364 -
1365 - if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
1366 - /* got an unexpected message type in reply */
1367 - pr_err("Incorrect reply type %d\n", rmsg->h.type);
1368 - ret = -EINVAL;
1369 - goto release_msg;
1370 - }
1371 -
1372 - ret = -rmsg->u.port_parameter_get_reply.status;
1373 - /* port_parameter_get_reply.size includes the header,
1374 - * whilst *value_size doesn't.
1375 - */
1376 - rmsg->u.port_parameter_get_reply.size -= (2 * sizeof(u32));
1377 -
1378 - if (ret || rmsg->u.port_parameter_get_reply.size > *value_size) {
1379 - /* Copy only as much as we have space for
1380 - * but report true size of parameter
1381 - */
1382 - memcpy(value, &rmsg->u.port_parameter_get_reply.value,
1383 - *value_size);
1384 - *value_size = rmsg->u.port_parameter_get_reply.size;
1385 - } else {
1386 - memcpy(value, &rmsg->u.port_parameter_get_reply.value,
1387 - rmsg->u.port_parameter_get_reply.size);
1388 - }
1389 -
1390 - pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
1391 - ret, port->component->handle, port->handle, parameter_id);
1392 -
1393 -release_msg:
1394 - vchi_held_msg_release(&rmsg_handle);
1395 -
1396 - return ret;
1397 -}
1398 -
1399 -/* disables a port and drains buffers from it */
1400 -static int port_disable(struct vchiq_mmal_instance *instance,
1401 - struct vchiq_mmal_port *port)
1402 -{
1403 - int ret;
1404 - struct list_head *q, *buf_head;
1405 - unsigned long flags = 0;
1406 -
1407 - if (!port->enabled)
1408 - return 0;
1409 -
1410 - port->enabled = false;
1411 -
1412 - ret = port_action_port(instance, port,
1413 - MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
1414 - if (ret == 0) {
1415 - /*
1416 - * Drain all queued buffers on port. This should only
1417 - * apply to buffers that have been queued before the port
1418 - * has been enabled. If the port has been enabled and buffers
1419 - * passed, then the buffers should have been removed from this
1420 - * list, and we should get the relevant callbacks via VCHIQ
1421 - * to release the buffers.
1422 - */
1423 - spin_lock_irqsave(&port->slock, flags);
1424 -
1425 - list_for_each_safe(buf_head, q, &port->buffers) {
1426 - struct mmal_buffer *mmalbuf;
1427 -
1428 - mmalbuf = list_entry(buf_head, struct mmal_buffer,
1429 - list);
1430 - list_del(buf_head);
1431 - if (port->buffer_cb)
1432 - port->buffer_cb(instance,
1433 - port, 0, mmalbuf, 0, 0,
1434 - MMAL_TIME_UNKNOWN,
1435 - MMAL_TIME_UNKNOWN);
1436 - }
1437 -
1438 - spin_unlock_irqrestore(&port->slock, flags);
1439 -
1440 - ret = port_info_get(instance, port);
1441 - }
1442 -
1443 - return ret;
1444 -}
1445 -
1446 -/* enable a port */
1447 -static int port_enable(struct vchiq_mmal_instance *instance,
1448 - struct vchiq_mmal_port *port)
1449 -{
1450 - unsigned int hdr_count;
1451 - struct list_head *q, *buf_head;
1452 - int ret;
1453 -
1454 - if (port->enabled)
1455 - return 0;
1456 -
1457 - ret = port_action_port(instance, port,
1458 - MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
1459 - if (ret)
1460 - goto done;
1461 -
1462 - port->enabled = true;
1463 -
1464 - if (port->buffer_cb) {
1465 - /* send buffer headers to videocore */
1466 - hdr_count = 1;
1467 - list_for_each_safe(buf_head, q, &port->buffers) {
1468 - struct mmal_buffer *mmalbuf;
1469 -
1470 - mmalbuf = list_entry(buf_head, struct mmal_buffer,
1471 - list);
1472 - ret = buffer_from_host(instance, port, mmalbuf);
1473 - if (ret)
1474 - goto done;
1475 -
1476 - list_del(buf_head);
1477 - hdr_count++;
1478 - if (hdr_count > port->current_buffer.num)
1479 - break;
1480 - }
1481 - }
1482 -
1483 - ret = port_info_get(instance, port);
1484 -
1485 -done:
1486 - return ret;
1487 -}
1488 -
1489 -/* ------------------------------------------------------------------
1490 - * Exported API
1491 - *------------------------------------------------------------------
1492 - */
1493 -
1494 -int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
1495 - struct vchiq_mmal_port *port)
1496 -{
1497 - int ret;
1498 -
1499 - if (mutex_lock_interruptible(&instance->vchiq_mutex))
1500 - return -EINTR;
1501 -
1502 - ret = port_info_set(instance, port);
1503 - if (ret)
1504 - goto release_unlock;
1505 -
1506 - /* read what has actually been set */
1507 - ret = port_info_get(instance, port);
1508 -
1509 -release_unlock:
1510 - mutex_unlock(&instance->vchiq_mutex);
1511 -
1512 - return ret;
1513 -}
1514 -
1515 -int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
1516 - struct vchiq_mmal_port *port,
1517 - u32 parameter, void *value, u32 value_size)
1518 -{
1519 - int ret;
1520 -
1521 - if (mutex_lock_interruptible(&instance->vchiq_mutex))
1522 - return -EINTR;
1523 -
1524 - ret = port_parameter_set(instance, port, parameter, value, value_size);
1525 -
1526 - mutex_unlock(&instance->vchiq_mutex);
1527 -
1528 - return ret;
1529 -}
1530 -
1531 -int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
1532 - struct vchiq_mmal_port *port,
1533 - u32 parameter, void *value, u32 *value_size)
1534 -{
1535 - int ret;
1536 -
1537 - if (mutex_lock_interruptible(&instance->vchiq_mutex))
1538 - return -EINTR;
1539 -
1540 - ret = port_parameter_get(instance, port, parameter, value, value_size);
1541 -
1542 - mutex_unlock(&instance->vchiq_mutex);
1543 -
1544 - return ret;
1545 -}
1546 -
1547 -/* enable a port
1548 - *
1549 - * enables a port and queues buffers for satisfying callbacks if we
1550 - * provide a callback handler
1551 - */
1552 -int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
1553 - struct vchiq_mmal_port *port,
1554 - vchiq_mmal_buffer_cb buffer_cb)
1555 -{
1556 - int ret;
1557 -
1558 - if (mutex_lock_interruptible(&instance->vchiq_mutex))
1559 - return -EINTR;
1560 -
1561 - /* already enabled - noop */
1562 - if (port->enabled) {
1563 - ret = 0;
1564 - goto unlock;
1565 - }
1566 -
1567 - port->buffer_cb = buffer_cb;
1568 -
1569 - ret = port_enable(instance, port);
1570 -
1571 -unlock:
1572 - mutex_unlock(&instance->vchiq_mutex);
1573 -
1574 - return ret;
1575 -}
1576 -
1577 -int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
1578 - struct vchiq_mmal_port *port)
1579 -{
1580 - int ret;
1581 -
1582 - if (mutex_lock_interruptible(&instance->vchiq_mutex))
1583 - return -EINTR;
1584 -
1585 - if (!port->enabled) {
1586 - mutex_unlock(&instance->vchiq_mutex);
1587 - return 0;
1588 - }
1589 -
1590 - ret = port_disable(instance, port);
1591 -
1592 - mutex_unlock(&instance->vchiq_mutex);
1593 -
1594 - return ret;
1595 -}
1596 -
1597 -/* ports will be connected in a tunneled manner so data buffers
1598 - * are not handled by client.
1599 - */
1600 -int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
1601 - struct vchiq_mmal_port *src,
1602 - struct vchiq_mmal_port *dst)
1603 -{
1604 - int ret;
1605 -
1606 - if (mutex_lock_interruptible(&instance->vchiq_mutex))
1607 - return -EINTR;
1608 -
1609 - /* disconnect ports if connected */
1610 - if (src->connected) {
1611 - ret = port_disable(instance, src);
1612 - if (ret) {
1613 - pr_err("failed disabling src port(%d)\n", ret);
1614 - goto release_unlock;
1615 - }
1616 -
1617 - /* do not need to disable the destination port as they
1618 - * are connected and it is done automatically
1619 - */
1620 -
1621 - ret = port_action_handle(instance, src,
1622 - MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
1623 - src->connected->component->handle,
1624 - src->connected->handle);
1625 - if (ret < 0) {
1626 - pr_err("failed disconnecting src port\n");
1627 - goto release_unlock;
1628 - }
1629 - src->connected->enabled = false;
1630 - src->connected = NULL;
1631 - }
1632 -
1633 - if (!dst) {
1634 - /* do not make new connection */
1635 - ret = 0;
1636 - pr_debug("not making new connection\n");
1637 - goto release_unlock;
1638 - }
1639 -
1640 - /* copy src port format to dst */
1641 - dst->format.encoding = src->format.encoding;
1642 - dst->es.video.width = src->es.video.width;
1643 - dst->es.video.height = src->es.video.height;
1644 - dst->es.video.crop.x = src->es.video.crop.x;
1645 - dst->es.video.crop.y = src->es.video.crop.y;
1646 - dst->es.video.crop.width = src->es.video.crop.width;
1647 - dst->es.video.crop.height = src->es.video.crop.height;
1648 - dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
1649 - dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
1650 -
1651 - /* set new format */
1652 - ret = port_info_set(instance, dst);
1653 - if (ret) {
1654 - pr_debug("setting port info failed\n");
1655 - goto release_unlock;
1656 - }
1657 -
1658 - /* read what has actually been set */
1659 - ret = port_info_get(instance, dst);
1660 - if (ret) {
1661 - pr_debug("read back port info failed\n");
1662 - goto release_unlock;
1663 - }
1664 -
1665 - /* connect two ports together */
1666 - ret = port_action_handle(instance, src,
1667 - MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
1668 - dst->component->handle, dst->handle);
1669 - if (ret < 0) {
1670 - pr_debug("connecting port %d:%d to %d:%d failed\n",
1671 - src->component->handle, src->handle,
1672 - dst->component->handle, dst->handle);
1673 - goto release_unlock;
1674 - }
1675 - src->connected = dst;
1676 -
1677 -release_unlock:
1678 -
1679 - mutex_unlock(&instance->vchiq_mutex);
1680 -
1681 - return ret;
1682 -}
1683 -
1684 -int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
1685 - struct vchiq_mmal_port *port,
1686 - struct mmal_buffer *buffer)
1687 -{
1688 - unsigned long flags = 0;
1689 - int ret;
1690 -
1691 - ret = buffer_from_host(instance, port, buffer);
1692 - if (ret == -EINVAL) {
1693 - /* Port is disabled. Queue for when it is enabled. */
1694 - spin_lock_irqsave(&port->slock, flags);
1695 - list_add_tail(&buffer->list, &port->buffers);
1696 - spin_unlock_irqrestore(&port->slock, flags);
1697 - }
1698 -
1699 - return 0;
1700 -}
1701 -
1702 -int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance,
1703 - struct mmal_buffer *buf)
1704 -{
1705 - struct mmal_msg_context *msg_context = get_msg_context(instance);
1706 -
1707 - if (IS_ERR(msg_context))
1708 - return (PTR_ERR(msg_context));
1709 -
1710 - buf->msg_context = msg_context;
1711 - return 0;
1712 -}
1713 -
1714 -int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf)
1715 -{
1716 - struct mmal_msg_context *msg_context = buf->msg_context;
1717 -
1718 - if (msg_context)
1719 - release_msg_context(msg_context);
1720 - buf->msg_context = NULL;
1721 -
1722 - return 0;
1723 -}
1724 -
1725 -/* Initialise a mmal component and its ports
1726 - *
1727 - */
1728 -int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
1729 - const char *name,
1730 - struct vchiq_mmal_component **component_out)
1731 -{
1732 - int ret;
1733 - int idx; /* port index */
1734 - struct vchiq_mmal_component *component;
1735 -
1736 - if (mutex_lock_interruptible(&instance->vchiq_mutex))
1737 - return -EINTR;
1738 -
1739 - if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
1740 - ret = -EINVAL; /* todo is this correct error? */
1741 - goto unlock;
1742 - }
1743 -
1744 - component = &instance->component[instance->component_idx];
1745 -
1746 - ret = create_component(instance, component, name);
1747 - if (ret < 0) {
1748 - pr_err("%s: failed to create component %d (Not enough GPU mem?)\n",
1749 - __func__, ret);
1750 - goto unlock;
1751 - }
1752 -
1753 - /* ports info needs gathering */
1754 - component->control.type = MMAL_PORT_TYPE_CONTROL;
1755 - component->control.index = 0;
1756 - component->control.component = component;
1757 - spin_lock_init(&component->control.slock);
1758 - INIT_LIST_HEAD(&component->control.buffers);
1759 - ret = port_info_get(instance, &component->control);
1760 - if (ret < 0)
1761 - goto release_component;
1762 -
1763 - for (idx = 0; idx < component->inputs; idx++) {
1764 - component->input[idx].type = MMAL_PORT_TYPE_INPUT;
1765 - component->input[idx].index = idx;
1766 - component->input[idx].component = component;
1767 - spin_lock_init(&component->input[idx].slock);
1768 - INIT_LIST_HEAD(&component->input[idx].buffers);
1769 - ret = port_info_get(instance, &component->input[idx]);
1770 - if (ret < 0)
1771 - goto release_component;
1772 - }
1773 -
1774 - for (idx = 0; idx < component->outputs; idx++) {
1775 - component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
1776 - component->output[idx].index = idx;
1777 - component->output[idx].component = component;
1778 - spin_lock_init(&component->output[idx].slock);
1779 - INIT_LIST_HEAD(&component->output[idx].buffers);
1780 - ret = port_info_get(instance, &component->output[idx]);
1781 - if (ret < 0)
1782 - goto release_component;
1783 - }
1784 -
1785 - for (idx = 0; idx < component->clocks; idx++) {
1786 - component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
1787 - component->clock[idx].index = idx;
1788 - component->clock[idx].component = component;
1789 - spin_lock_init(&component->clock[idx].slock);
1790 - INIT_LIST_HEAD(&component->clock[idx].buffers);
1791 - ret = port_info_get(instance, &component->clock[idx]);
1792 - if (ret < 0)
1793 - goto release_component;
1794 - }
1795 -
1796 - instance->component_idx++;
1797 -
1798 - *component_out = component;
1799 -
1800 - mutex_unlock(&instance->vchiq_mutex);
1801 -
1802 - return 0;
1803 -
1804 -release_component:
1805 - destroy_component(instance, component);
1806 -unlock:
1807 - mutex_unlock(&instance->vchiq_mutex);
1808 -
1809 - return ret;
1810 -}
1811 -
1812 -/*
1813 - * cause a mmal component to be destroyed
1814 - */
1815 -int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
1816 - struct vchiq_mmal_component *component)
1817 -{
1818 - int ret;
1819 -
1820 - if (mutex_lock_interruptible(&instance->vchiq_mutex))
1821 - return -EINTR;
1822 -
1823 - if (component->enabled)
1824 - ret = disable_component(instance, component);
1825 -
1826 - ret = destroy_component(instance, component);
1827 -
1828 - mutex_unlock(&instance->vchiq_mutex);
1829 -
1830 - return ret;
1831 -}
1832 -
1833 -/*
1834 - * cause a mmal component to be enabled
1835 - */
1836 -int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
1837 - struct vchiq_mmal_component *component)
1838 -{
1839 - int ret;
1840 -
1841 - if (mutex_lock_interruptible(&instance->vchiq_mutex))
1842 - return -EINTR;
1843 -
1844 - if (component->enabled) {
1845 - mutex_unlock(&instance->vchiq_mutex);
1846 - return 0;
1847 - }
1848 -
1849 - ret = enable_component(instance, component);
1850 - if (ret == 0)
1851 - component->enabled = true;
1852 -
1853 - mutex_unlock(&instance->vchiq_mutex);
1854 -
1855 - return ret;
1856 -}
1857 -
1858 -/*
1859 - * cause a mmal component to be enabled
1860 - */
1861 -int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
1862 - struct vchiq_mmal_component *component)
1863 -{
1864 - int ret;
1865 -
1866 - if (mutex_lock_interruptible(&instance->vchiq_mutex))
1867 - return -EINTR;
1868 -
1869 - if (!component->enabled) {
1870 - mutex_unlock(&instance->vchiq_mutex);
1871 - return 0;
1872 - }
1873 -
1874 - ret = disable_component(instance, component);
1875 - if (ret == 0)
1876 - component->enabled = false;
1877 -
1878 - mutex_unlock(&instance->vchiq_mutex);
1879 -
1880 - return ret;
1881 -}
1882 -
1883 -int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
1884 - u32 *major_out, u32 *minor_out)
1885 -{
1886 - int ret;
1887 -
1888 - if (mutex_lock_interruptible(&instance->vchiq_mutex))
1889 - return -EINTR;
1890 -
1891 - ret = get_version(instance, major_out, minor_out);
1892 -
1893 - mutex_unlock(&instance->vchiq_mutex);
1894 -
1895 - return ret;
1896 -}
1897 -
1898 -int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
1899 -{
1900 - int status = 0;
1901 -
1902 - if (!instance)
1903 - return -EINVAL;
1904 -
1905 - if (mutex_lock_interruptible(&instance->vchiq_mutex))
1906 - return -EINTR;
1907 -
1908 - vchi_service_use(instance->handle);
1909 -
1910 - status = vchi_service_close(instance->handle);
1911 - if (status != 0)
1912 - pr_err("mmal-vchiq: VCHIQ close failed\n");
1913 -
1914 - mutex_unlock(&instance->vchiq_mutex);
1915 -
1916 - flush_workqueue(instance->bulk_wq);
1917 - destroy_workqueue(instance->bulk_wq);
1918 -
1919 - vfree(instance->bulk_scratch);
1920 -
1921 - idr_destroy(&instance->context_map);
1922 -
1923 - kfree(instance);
1924 -
1925 - return status;
1926 -}
1927 -
1928 -int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
1929 -{
1930 - int status;
1931 - struct vchiq_mmal_instance *instance;
1932 - static VCHI_CONNECTION_T *vchi_connection;
1933 - static VCHI_INSTANCE_T vchi_instance;
1934 - SERVICE_CREATION_T params = {
1935 - .version = VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
1936 - .service_id = VC_MMAL_SERVER_NAME,
1937 - .connection = vchi_connection,
1938 - .rx_fifo_size = 0,
1939 - .tx_fifo_size = 0,
1940 - .callback = service_callback,
1941 - .callback_param = NULL,
1942 - .want_unaligned_bulk_rx = 1,
1943 - .want_unaligned_bulk_tx = 1,
1944 - .want_crc = 0
1945 - };
1946 -
1947 - /* compile time checks to ensure structure size as they are
1948 - * directly (de)serialised from memory.
1949 - */
1950 -
1951 - /* ensure the header structure has packed to the correct size */
1952 - BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
1953 -
1954 - /* ensure message structure does not exceed maximum length */
1955 - BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
1956 -
1957 - /* mmal port struct is correct size */
1958 - BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
1959 -
1960 - /* create a vchi instance */
1961 - status = vchi_initialise(&vchi_instance);
1962 - if (status) {
1963 - pr_err("Failed to initialise VCHI instance (status=%d)\n",
1964 - status);
1965 - return -EIO;
1966 - }
1967 -
1968 - status = vchi_connect(NULL, 0, vchi_instance);
1969 - if (status) {
1970 - pr_err("Failed to connect VCHI instance (status=%d)\n", status);
1971 - return -EIO;
1972 - }
1973 -
1974 - instance = kzalloc(sizeof(*instance), GFP_KERNEL);
1975 -
1976 - if (!instance)
1977 - return -ENOMEM;
1978 -
1979 - mutex_init(&instance->vchiq_mutex);
1980 -
1981 - instance->bulk_scratch = vmalloc(PAGE_SIZE);
1982 -
1983 - mutex_init(&instance->context_map_lock);
1984 - idr_init_base(&instance->context_map, 1);
1985 -
1986 - params.callback_param = instance;
1987 -
1988 - instance->bulk_wq = alloc_ordered_workqueue("mmal-vchiq",
1989 - WQ_MEM_RECLAIM);
1990 - if (!instance->bulk_wq)
1991 - goto err_free;
1992 -
1993 - status = vchi_service_open(vchi_instance, &params, &instance->handle);
1994 - if (status) {
1995 - pr_err("Failed to open VCHI service connection (status=%d)\n",
1996 - status);
1997 - goto err_close_services;
1998 - }
1999 -
2000 - vchi_service_release(instance->handle);
2001 -
2002 - *out_instance = instance;
2003 -
2004 - return 0;
2005 -
2006 -err_close_services:
2007 - vchi_service_close(instance->handle);
2008 - destroy_workqueue(instance->bulk_wq);
2009 -err_free:
2010 - vfree(instance->bulk_scratch);
2011 - kfree(instance);
2012 - return -ENODEV;
2013 -}
2014 --- /dev/null
2015 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c
2016 @@ -0,0 +1,1921 @@
2017 +// SPDX-License-Identifier: GPL-2.0
2018 +/*
2019 + * Broadcom BM2835 V4L2 driver
2020 + *
2021 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
2022 + *
2023 + * Authors: Vincent Sanders @ Collabora
2024 + * Dave Stevenson @ Broadcom
2025 + * (now dave.stevenson@raspberrypi.org)
2026 + * Simon Mellor @ Broadcom
2027 + * Luke Diamand @ Broadcom
2028 + *
2029 + * V4L2 driver MMAL vchiq interface code
2030 + */
2031 +
2032 +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2033 +
2034 +#include <linux/errno.h>
2035 +#include <linux/kernel.h>
2036 +#include <linux/module.h>
2037 +#include <linux/mutex.h>
2038 +#include <linux/mm.h>
2039 +#include <linux/slab.h>
2040 +#include <linux/completion.h>
2041 +#include <linux/vmalloc.h>
2042 +#include <asm/cacheflush.h>
2043 +#include <media/videobuf2-vmalloc.h>
2044 +
2045 +#include "mmal-common.h"
2046 +#include "mmal-vchiq.h"
2047 +#include "mmal-msg.h"
2048 +
2049 +#define USE_VCHIQ_ARM
2050 +#include "interface/vchi/vchi.h"
2051 +
2052 +MODULE_DESCRIPTION("BCM2835 MMAL VCHIQ interface");
2053 +MODULE_AUTHOR("Dave Stevenson, <dave.stevenson@raspberrypi.org>");
2054 +MODULE_LICENSE("GPL");
2055 +MODULE_VERSION("0.0.1");
2056 +
2057 +/* maximum number of components supported */
2058 +#define VCHIQ_MMAL_MAX_COMPONENTS 4
2059 +
2060 +/*#define FULL_MSG_DUMP 1*/
2061 +
2062 +#ifdef DEBUG
2063 +static const char *const msg_type_names[] = {
2064 + "UNKNOWN",
2065 + "QUIT",
2066 + "SERVICE_CLOSED",
2067 + "GET_VERSION",
2068 + "COMPONENT_CREATE",
2069 + "COMPONENT_DESTROY",
2070 + "COMPONENT_ENABLE",
2071 + "COMPONENT_DISABLE",
2072 + "PORT_INFO_GET",
2073 + "PORT_INFO_SET",
2074 + "PORT_ACTION",
2075 + "BUFFER_FROM_HOST",
2076 + "BUFFER_TO_HOST",
2077 + "GET_STATS",
2078 + "PORT_PARAMETER_SET",
2079 + "PORT_PARAMETER_GET",
2080 + "EVENT_TO_HOST",
2081 + "GET_CORE_STATS_FOR_PORT",
2082 + "OPAQUE_ALLOCATOR",
2083 + "CONSUME_MEM",
2084 + "LMK",
2085 + "OPAQUE_ALLOCATOR_DESC",
2086 + "DRM_GET_LHS32",
2087 + "DRM_GET_TIME",
2088 + "BUFFER_FROM_HOST_ZEROLEN",
2089 + "PORT_FLUSH",
2090 + "HOST_LOG",
2091 +};
2092 +#endif
2093 +
2094 +static const char *const port_action_type_names[] = {
2095 + "UNKNOWN",
2096 + "ENABLE",
2097 + "DISABLE",
2098 + "FLUSH",
2099 + "CONNECT",
2100 + "DISCONNECT",
2101 + "SET_REQUIREMENTS",
2102 +};
2103 +
2104 +#if defined(DEBUG)
2105 +#if defined(FULL_MSG_DUMP)
2106 +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
2107 + do { \
2108 + pr_debug(TITLE" type:%s(%d) length:%d\n", \
2109 + msg_type_names[(MSG)->h.type], \
2110 + (MSG)->h.type, (MSG_LEN)); \
2111 + print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
2112 + 16, 4, (MSG), \
2113 + sizeof(struct mmal_msg_header), 1); \
2114 + print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
2115 + 16, 4, \
2116 + ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
2117 + (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
2118 + } while (0)
2119 +#else
2120 +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
2121 + { \
2122 + pr_debug(TITLE" type:%s(%d) length:%d\n", \
2123 + msg_type_names[(MSG)->h.type], \
2124 + (MSG)->h.type, (MSG_LEN)); \
2125 + }
2126 +#endif
2127 +#else
2128 +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
2129 +#endif
2130 +
2131 +struct vchiq_mmal_instance;
2132 +
2133 +/* normal message context */
2134 +struct mmal_msg_context {
2135 + struct vchiq_mmal_instance *instance;
2136 +
2137 + /* Index in the context_map idr so that we can find the
2138 + * mmal_msg_context again when servicing the VCHI reply.
2139 + */
2140 + int handle;
2141 +
2142 + union {
2143 + struct {
2144 + /* work struct for buffer_cb callback */
2145 + struct work_struct work;
2146 + /* work struct for deferred callback */
2147 + struct work_struct buffer_to_host_work;
2148 + /* mmal instance */
2149 + struct vchiq_mmal_instance *instance;
2150 + /* mmal port */
2151 + struct vchiq_mmal_port *port;
2152 + /* actual buffer used to store bulk reply */
2153 + struct mmal_buffer *buffer;
2154 + /* amount of buffer used */
2155 + unsigned long buffer_used;
2156 + /* MMAL buffer flags */
2157 + u32 mmal_flags;
2158 + /* Presentation and Decode timestamps */
2159 + s64 pts;
2160 + s64 dts;
2161 +
2162 + int status; /* context status */
2163 +
2164 + } bulk; /* bulk data */
2165 +
2166 + struct {
2167 + /* message handle to release */
2168 + VCHI_HELD_MSG_T msg_handle;
2169 + /* pointer to received message */
2170 + struct mmal_msg *msg;
2171 + /* received message length */
2172 + u32 msg_len;
2173 + /* completion upon reply */
2174 + struct completion cmplt;
2175 + } sync; /* synchronous response */
2176 + } u;
2177 +
2178 +};
2179 +
2180 +struct vchiq_mmal_instance {
2181 + VCHI_SERVICE_HANDLE_T handle;
2182 +
2183 + /* ensure serialised access to service */
2184 + struct mutex vchiq_mutex;
2185 +
2186 + /* vmalloc page to receive scratch bulk xfers into */
2187 + void *bulk_scratch;
2188 +
2189 + struct idr context_map;
2190 + /* protect accesses to context_map */
2191 + struct mutex context_map_lock;
2192 +
2193 + /* component to use next */
2194 + int component_idx;
2195 + struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
2196 +
2197 + /* ordered workqueue to process all bulk operations */
2198 + struct workqueue_struct *bulk_wq;
2199 +};
2200 +
2201 +static struct mmal_msg_context *
2202 +get_msg_context(struct vchiq_mmal_instance *instance)
2203 +{
2204 + struct mmal_msg_context *msg_context;
2205 + int handle;
2206 +
2207 + /* todo: should this be allocated from a pool to avoid kzalloc */
2208 + msg_context = kzalloc(sizeof(*msg_context), GFP_KERNEL);
2209 +
2210 + if (!msg_context)
2211 + return ERR_PTR(-ENOMEM);
2212 +
2213 + /* Create an ID that will be passed along with our message so
2214 + * that when we service the VCHI reply, we can look up what
2215 + * message is being replied to.
2216 + */
2217 + mutex_lock(&instance->context_map_lock);
2218 + handle = idr_alloc(&instance->context_map, msg_context,
2219 + 0, 0, GFP_KERNEL);
2220 + mutex_unlock(&instance->context_map_lock);
2221 +
2222 + if (handle < 0) {
2223 + kfree(msg_context);
2224 + return ERR_PTR(handle);
2225 + }
2226 +
2227 + msg_context->instance = instance;
2228 + msg_context->handle = handle;
2229 +
2230 + return msg_context;
2231 +}
2232 +
2233 +static struct mmal_msg_context *
2234 +lookup_msg_context(struct vchiq_mmal_instance *instance, int handle)
2235 +{
2236 + return idr_find(&instance->context_map, handle);
2237 +}
2238 +
2239 +static void
2240 +release_msg_context(struct mmal_msg_context *msg_context)
2241 +{
2242 + struct vchiq_mmal_instance *instance = msg_context->instance;
2243 +
2244 + mutex_lock(&instance->context_map_lock);
2245 + idr_remove(&instance->context_map, msg_context->handle);
2246 + mutex_unlock(&instance->context_map_lock);
2247 + kfree(msg_context);
2248 +}
2249 +
2250 +/* deals with receipt of event to host message */
2251 +static void event_to_host_cb(struct vchiq_mmal_instance *instance,
2252 + struct mmal_msg *msg, u32 msg_len)
2253 +{
2254 + pr_debug("unhandled event\n");
2255 + pr_debug("component:%u port type:%d num:%d cmd:0x%x length:%d\n",
2256 + msg->u.event_to_host.client_component,
2257 + msg->u.event_to_host.port_type,
2258 + msg->u.event_to_host.port_num,
2259 + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
2260 +}
2261 +
2262 +/* workqueue scheduled callback
2263 + *
2264 + * we do this because it is important we do not call any other vchiq
2265 + * sync calls from witin the message delivery thread
2266 + */
2267 +static void buffer_work_cb(struct work_struct *work)
2268 +{
2269 + struct mmal_msg_context *msg_context =
2270 + container_of(work, struct mmal_msg_context, u.bulk.work);
2271 +
2272 + atomic_dec(&msg_context->u.bulk.port->buffers_with_vpu);
2273 +
2274 + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
2275 + msg_context->u.bulk.port,
2276 + msg_context->u.bulk.status,
2277 + msg_context->u.bulk.buffer,
2278 + msg_context->u.bulk.buffer_used,
2279 + msg_context->u.bulk.mmal_flags,
2280 + msg_context->u.bulk.dts,
2281 + msg_context->u.bulk.pts);
2282 +}
2283 +
2284 +/* workqueue scheduled callback to handle receiving buffers
2285 + *
2286 + * VCHI will allow up to 4 bulk receives to be scheduled before blocking.
2287 + * If we block in the service_callback context then we can't process the
2288 + * VCHI_CALLBACK_BULK_RECEIVED message that would otherwise allow the blocked
2289 + * vchi_bulk_queue_receive() call to complete.
2290 + */
2291 +static void buffer_to_host_work_cb(struct work_struct *work)
2292 +{
2293 + struct mmal_msg_context *msg_context =
2294 + container_of(work, struct mmal_msg_context,
2295 + u.bulk.buffer_to_host_work);
2296 + struct vchiq_mmal_instance *instance = msg_context->instance;
2297 + unsigned long len = msg_context->u.bulk.buffer_used;
2298 + int ret;
2299 +
2300 + if (!len)
2301 + /* Dummy receive to ensure the buffers remain in order */
2302 + len = 8;
2303 + /* queue the bulk submission */
2304 + vchi_service_use(instance->handle);
2305 + ret = vchi_bulk_queue_receive(instance->handle,
2306 + msg_context->u.bulk.buffer->buffer,
2307 + /* Actual receive needs to be a multiple
2308 + * of 4 bytes
2309 + */
2310 + (len + 3) & ~3,
2311 + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
2312 + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
2313 + msg_context);
2314 +
2315 + vchi_service_release(instance->handle);
2316 +
2317 + if (ret != 0)
2318 + pr_err("%s: ctx: %p, vchi_bulk_queue_receive failed %d\n",
2319 + __func__, msg_context, ret);
2320 +}
2321 +
2322 +/* enqueue a bulk receive for a given message context */
2323 +static int bulk_receive(struct vchiq_mmal_instance *instance,
2324 + struct mmal_msg *msg,
2325 + struct mmal_msg_context *msg_context)
2326 +{
2327 + unsigned long rd_len;
2328 +
2329 + rd_len = msg->u.buffer_from_host.buffer_header.length;
2330 +
2331 + if (!msg_context->u.bulk.buffer) {
2332 + pr_err("bulk.buffer not configured - error in buffer_from_host\n");
2333 +
2334 + /* todo: this is a serious error, we should never have
2335 + * committed a buffer_to_host operation to the mmal
2336 + * port without the buffer to back it up (underflow
2337 + * handling) and there is no obvious way to deal with
2338 + * this - how is the mmal servie going to react when
2339 + * we fail to do the xfer and reschedule a buffer when
2340 + * it arrives? perhaps a starved flag to indicate a
2341 + * waiting bulk receive?
2342 + */
2343 +
2344 + return -EINVAL;
2345 + }
2346 +
2347 + /* ensure we do not overrun the available buffer */
2348 + if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
2349 + rd_len = msg_context->u.bulk.buffer->buffer_size;
2350 + pr_warn("short read as not enough receive buffer space\n");
2351 + /* todo: is this the correct response, what happens to
2352 + * the rest of the message data?
2353 + */
2354 + }
2355 +
2356 + /* store length */
2357 + msg_context->u.bulk.buffer_used = rd_len;
2358 + msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
2359 + msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
2360 +
2361 + queue_work(msg_context->instance->bulk_wq,
2362 + &msg_context->u.bulk.buffer_to_host_work);
2363 +
2364 + return 0;
2365 +}
2366 +
2367 +/* data in message, memcpy from packet into output buffer */
2368 +static int inline_receive(struct vchiq_mmal_instance *instance,
2369 + struct mmal_msg *msg,
2370 + struct mmal_msg_context *msg_context)
2371 +{
2372 + memcpy(msg_context->u.bulk.buffer->buffer,
2373 + msg->u.buffer_from_host.short_data,
2374 + msg->u.buffer_from_host.payload_in_message);
2375 +
2376 + msg_context->u.bulk.buffer_used =
2377 + msg->u.buffer_from_host.payload_in_message;
2378 +
2379 + return 0;
2380 +}
2381 +
2382 +/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
2383 +static int
2384 +buffer_from_host(struct vchiq_mmal_instance *instance,
2385 + struct vchiq_mmal_port *port, struct mmal_buffer *buf)
2386 +{
2387 + struct mmal_msg_context *msg_context;
2388 + struct mmal_msg m;
2389 + int ret;
2390 +
2391 + if (!port->enabled)
2392 + return -EINVAL;
2393 +
2394 + pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
2395 +
2396 + /* get context */
2397 + if (!buf->msg_context) {
2398 + pr_err("%s: msg_context not allocated, buf %p\n", __func__,
2399 + buf);
2400 + return -EINVAL;
2401 + }
2402 + msg_context = buf->msg_context;
2403 +
2404 + /* store bulk message context for when data arrives */
2405 + msg_context->u.bulk.instance = instance;
2406 + msg_context->u.bulk.port = port;
2407 + msg_context->u.bulk.buffer = buf;
2408 + msg_context->u.bulk.buffer_used = 0;
2409 +
2410 + /* initialise work structure ready to schedule callback */
2411 + INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
2412 + INIT_WORK(&msg_context->u.bulk.buffer_to_host_work,
2413 + buffer_to_host_work_cb);
2414 +
2415 + atomic_inc(&port->buffers_with_vpu);
2416 +
2417 + /* prep the buffer from host message */
2418 + memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
2419 +
2420 + m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
2421 + m.h.magic = MMAL_MAGIC;
2422 + m.h.context = msg_context->handle;
2423 + m.h.status = 0;
2424 +
2425 + /* drvbuf is our private data passed back */
2426 + m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
2427 + m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
2428 + m.u.buffer_from_host.drvbuf.port_handle = port->handle;
2429 + m.u.buffer_from_host.drvbuf.client_context = msg_context->handle;
2430 +
2431 + /* buffer header */
2432 + m.u.buffer_from_host.buffer_header.cmd = 0;
2433 + m.u.buffer_from_host.buffer_header.data =
2434 + (u32)(unsigned long)buf->buffer;
2435 + m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
2436 + m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
2437 + m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
2438 + m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
2439 + m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
2440 + m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
2441 +
2442 + /* clear buffer type sepecific data */
2443 + memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
2444 + sizeof(m.u.buffer_from_host.buffer_header_type_specific));
2445 +
2446 + /* no payload in message */
2447 + m.u.buffer_from_host.payload_in_message = 0;
2448 +
2449 + vchi_service_use(instance->handle);
2450 +
2451 + ret = vchi_queue_kernel_message(instance->handle,
2452 + &m,
2453 + sizeof(struct mmal_msg_header) +
2454 + sizeof(m.u.buffer_from_host));
2455 +
2456 + vchi_service_release(instance->handle);
2457 +
2458 + return ret;
2459 +}
2460 +
2461 +/* deals with receipt of buffer to host message */
2462 +static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
2463 + struct mmal_msg *msg, u32 msg_len)
2464 +{
2465 + struct mmal_msg_context *msg_context;
2466 + u32 handle;
2467 +
2468 + pr_debug("%s: instance:%p msg:%p msg_len:%d\n",
2469 + __func__, instance, msg, msg_len);
2470 +
2471 + if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
2472 + handle = msg->u.buffer_from_host.drvbuf.client_context;
2473 + msg_context = lookup_msg_context(instance, handle);
2474 +
2475 + if (!msg_context) {
2476 + pr_err("drvbuf.client_context(%u) is invalid\n",
2477 + handle);
2478 + return;
2479 + }
2480 + } else {
2481 + pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
2482 + return;
2483 + }
2484 +
2485 + msg_context->u.bulk.mmal_flags =
2486 + msg->u.buffer_from_host.buffer_header.flags;
2487 +
2488 + if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
2489 + /* message reception had an error */
2490 + pr_warn("error %d in reply\n", msg->h.status);
2491 +
2492 + msg_context->u.bulk.status = msg->h.status;
2493 +
2494 + } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
2495 + /* empty buffer */
2496 + if (msg->u.buffer_from_host.buffer_header.flags &
2497 + MMAL_BUFFER_HEADER_FLAG_EOS) {
2498 + msg_context->u.bulk.status =
2499 + bulk_receive(instance, msg, msg_context);
2500 + if (msg_context->u.bulk.status == 0)
2501 + return; /* successful bulk submission, bulk
2502 + * completion will trigger callback
2503 + */
2504 + } else {
2505 + /* do callback with empty buffer - not EOS though */
2506 + msg_context->u.bulk.status = 0;
2507 + msg_context->u.bulk.buffer_used = 0;
2508 + }
2509 + } else if (msg->u.buffer_from_host.payload_in_message == 0) {
2510 + /* data is not in message, queue a bulk receive */
2511 + msg_context->u.bulk.status =
2512 + bulk_receive(instance, msg, msg_context);
2513 + if (msg_context->u.bulk.status == 0)
2514 + return; /* successful bulk submission, bulk
2515 + * completion will trigger callback
2516 + */
2517 +
2518 + /* failed to submit buffer, this will end badly */
2519 + pr_err("error %d on bulk submission\n",
2520 + msg_context->u.bulk.status);
2521 +
2522 + } else if (msg->u.buffer_from_host.payload_in_message <=
2523 + MMAL_VC_SHORT_DATA) {
2524 + /* data payload within message */
2525 + msg_context->u.bulk.status = inline_receive(instance, msg,
2526 + msg_context);
2527 + } else {
2528 + pr_err("message with invalid short payload\n");
2529 +
2530 + /* signal error */
2531 + msg_context->u.bulk.status = -EINVAL;
2532 + msg_context->u.bulk.buffer_used =
2533 + msg->u.buffer_from_host.payload_in_message;
2534 + }
2535 +
2536 + /* schedule the port callback */
2537 + schedule_work(&msg_context->u.bulk.work);
2538 +}
2539 +
2540 +static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
2541 + struct mmal_msg_context *msg_context)
2542 +{
2543 + msg_context->u.bulk.status = 0;
2544 +
2545 + /* schedule the port callback */
2546 + schedule_work(&msg_context->u.bulk.work);
2547 +}
2548 +
2549 +static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
2550 + struct mmal_msg_context *msg_context)
2551 +{
2552 + pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
2553 +
2554 + msg_context->u.bulk.status = -EINTR;
2555 +
2556 + schedule_work(&msg_context->u.bulk.work);
2557 +}
2558 +
2559 +/* incoming event service callback */
2560 +static void service_callback(void *param,
2561 + const VCHI_CALLBACK_REASON_T reason,
2562 + void *bulk_ctx)
2563 +{
2564 + struct vchiq_mmal_instance *instance = param;
2565 + int status;
2566 + u32 msg_len;
2567 + struct mmal_msg *msg;
2568 + VCHI_HELD_MSG_T msg_handle;
2569 + struct mmal_msg_context *msg_context;
2570 +
2571 + if (!instance) {
2572 + pr_err("Message callback passed NULL instance\n");
2573 + return;
2574 + }
2575 +
2576 + switch (reason) {
2577 + case VCHI_CALLBACK_MSG_AVAILABLE:
2578 + status = vchi_msg_hold(instance->handle, (void **)&msg,
2579 + &msg_len, VCHI_FLAGS_NONE, &msg_handle);
2580 + if (status) {
2581 + pr_err("Unable to dequeue a message (%d)\n", status);
2582 + break;
2583 + }
2584 +
2585 + DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
2586 +
2587 + /* handling is different for buffer messages */
2588 + switch (msg->h.type) {
2589 + case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
2590 + vchi_held_msg_release(&msg_handle);
2591 + break;
2592 +
2593 + case MMAL_MSG_TYPE_EVENT_TO_HOST:
2594 + event_to_host_cb(instance, msg, msg_len);
2595 + vchi_held_msg_release(&msg_handle);
2596 +
2597 + break;
2598 +
2599 + case MMAL_MSG_TYPE_BUFFER_TO_HOST:
2600 + buffer_to_host_cb(instance, msg, msg_len);
2601 + vchi_held_msg_release(&msg_handle);
2602 + break;
2603 +
2604 + default:
2605 + /* messages dependent on header context to complete */
2606 + if (!msg->h.context) {
2607 + pr_err("received message context was null!\n");
2608 + vchi_held_msg_release(&msg_handle);
2609 + break;
2610 + }
2611 +
2612 + msg_context = lookup_msg_context(instance,
2613 + msg->h.context);
2614 + if (!msg_context) {
2615 + pr_err("received invalid message context %u!\n",
2616 + msg->h.context);
2617 + vchi_held_msg_release(&msg_handle);
2618 + break;
2619 + }
2620 +
2621 + /* fill in context values */
2622 + msg_context->u.sync.msg_handle = msg_handle;
2623 + msg_context->u.sync.msg = msg;
2624 + msg_context->u.sync.msg_len = msg_len;
2625 +
2626 + /* todo: should this check (completion_done()
2627 + * == 1) for no one waiting? or do we need a
2628 + * flag to tell us the completion has been
2629 + * interrupted so we can free the message and
2630 + * its context. This probably also solves the
2631 + * message arriving after interruption todo
2632 + * below
2633 + */
2634 +
2635 + /* complete message so caller knows it happened */
2636 + complete(&msg_context->u.sync.cmplt);
2637 + break;
2638 + }
2639 +
2640 + break;
2641 +
2642 + case VCHI_CALLBACK_BULK_RECEIVED:
2643 + bulk_receive_cb(instance, bulk_ctx);
2644 + break;
2645 +
2646 + case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
2647 + bulk_abort_cb(instance, bulk_ctx);
2648 + break;
2649 +
2650 + case VCHI_CALLBACK_SERVICE_CLOSED:
2651 + /* TODO: consider if this requires action if received when
2652 + * driver is not explicitly closing the service
2653 + */
2654 + break;
2655 +
2656 + default:
2657 + pr_err("Received unhandled message reason %d\n", reason);
2658 + break;
2659 + }
2660 +}
2661 +
2662 +static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
2663 + struct mmal_msg *msg,
2664 + unsigned int payload_len,
2665 + struct mmal_msg **msg_out,
2666 + VCHI_HELD_MSG_T *msg_handle_out)
2667 +{
2668 + struct mmal_msg_context *msg_context;
2669 + int ret;
2670 + unsigned long timeout;
2671 +
2672 + /* payload size must not cause message to exceed max size */
2673 + if (payload_len >
2674 + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
2675 + pr_err("payload length %d exceeds max:%d\n", payload_len,
2676 + (int)(MMAL_MSG_MAX_SIZE -
2677 + sizeof(struct mmal_msg_header)));
2678 + return -EINVAL;
2679 + }
2680 +
2681 + msg_context = get_msg_context(instance);
2682 + if (IS_ERR(msg_context))
2683 + return PTR_ERR(msg_context);
2684 +
2685 + init_completion(&msg_context->u.sync.cmplt);
2686 +
2687 + msg->h.magic = MMAL_MAGIC;
2688 + msg->h.context = msg_context->handle;
2689 + msg->h.status = 0;
2690 +
2691 + DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
2692 + ">>> sync message");
2693 +
2694 + vchi_service_use(instance->handle);
2695 +
2696 + ret = vchi_queue_kernel_message(instance->handle,
2697 + msg,
2698 + sizeof(struct mmal_msg_header) +
2699 + payload_len);
2700 +
2701 + vchi_service_release(instance->handle);
2702 +
2703 + if (ret) {
2704 + pr_err("error %d queuing message\n", ret);
2705 + release_msg_context(msg_context);
2706 + return ret;
2707 + }
2708 +
2709 + timeout = wait_for_completion_timeout(&msg_context->u.sync.cmplt,
2710 + 3 * HZ);
2711 + if (timeout == 0) {
2712 + pr_err("timed out waiting for sync completion\n");
2713 + ret = -ETIME;
2714 + /* todo: what happens if the message arrives after aborting */
2715 + release_msg_context(msg_context);
2716 + return ret;
2717 + }
2718 +
2719 + *msg_out = msg_context->u.sync.msg;
2720 + *msg_handle_out = msg_context->u.sync.msg_handle;
2721 + release_msg_context(msg_context);
2722 +
2723 + return 0;
2724 +}
2725 +
2726 +static void dump_port_info(struct vchiq_mmal_port *port)
2727 +{
2728 + pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
2729 +
2730 + pr_debug("buffer minimum num:%d size:%d align:%d\n",
2731 + port->minimum_buffer.num,
2732 + port->minimum_buffer.size, port->minimum_buffer.alignment);
2733 +
2734 + pr_debug("buffer recommended num:%d size:%d align:%d\n",
2735 + port->recommended_buffer.num,
2736 + port->recommended_buffer.size,
2737 + port->recommended_buffer.alignment);
2738 +
2739 + pr_debug("buffer current values num:%d size:%d align:%d\n",
2740 + port->current_buffer.num,
2741 + port->current_buffer.size, port->current_buffer.alignment);
2742 +
2743 + pr_debug("elementary stream: type:%d encoding:0x%x variant:0x%x\n",
2744 + port->format.type,
2745 + port->format.encoding, port->format.encoding_variant);
2746 +
2747 + pr_debug(" bitrate:%d flags:0x%x\n",
2748 + port->format.bitrate, port->format.flags);
2749 +
2750 + if (port->format.type == MMAL_ES_TYPE_VIDEO) {
2751 + pr_debug
2752 + ("es video format: width:%d height:%d colourspace:0x%x\n",
2753 + port->es.video.width, port->es.video.height,
2754 + port->es.video.color_space);
2755 +
2756 + pr_debug(" : crop xywh %d,%d,%d,%d\n",
2757 + port->es.video.crop.x,
2758 + port->es.video.crop.y,
2759 + port->es.video.crop.width, port->es.video.crop.height);
2760 + pr_debug(" : framerate %d/%d aspect %d/%d\n",
2761 + port->es.video.frame_rate.num,
2762 + port->es.video.frame_rate.den,
2763 + port->es.video.par.num, port->es.video.par.den);
2764 + }
2765 +}
2766 +
2767 +static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
2768 +{
2769 + /* todo do readonly fields need setting at all? */
2770 + p->type = port->type;
2771 + p->index = port->index;
2772 + p->index_all = 0;
2773 + p->is_enabled = port->enabled;
2774 + p->buffer_num_min = port->minimum_buffer.num;
2775 + p->buffer_size_min = port->minimum_buffer.size;
2776 + p->buffer_alignment_min = port->minimum_buffer.alignment;
2777 + p->buffer_num_recommended = port->recommended_buffer.num;
2778 + p->buffer_size_recommended = port->recommended_buffer.size;
2779 +
2780 + /* only three writable fields in a port */
2781 + p->buffer_num = port->current_buffer.num;
2782 + p->buffer_size = port->current_buffer.size;
2783 + p->userdata = (u32)(unsigned long)port;
2784 +}
2785 +
2786 +static int port_info_set(struct vchiq_mmal_instance *instance,
2787 + struct vchiq_mmal_port *port)
2788 +{
2789 + int ret;
2790 + struct mmal_msg m;
2791 + struct mmal_msg *rmsg;
2792 + VCHI_HELD_MSG_T rmsg_handle;
2793 +
2794 + pr_debug("setting port info port %p\n", port);
2795 + if (!port)
2796 + return -1;
2797 + dump_port_info(port);
2798 +
2799 + m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
2800 +
2801 + m.u.port_info_set.component_handle = port->component->handle;
2802 + m.u.port_info_set.port_type = port->type;
2803 + m.u.port_info_set.port_index = port->index;
2804 +
2805 + port_to_mmal_msg(port, &m.u.port_info_set.port);
2806 +
2807 + /* elementary stream format setup */
2808 + m.u.port_info_set.format.type = port->format.type;
2809 + m.u.port_info_set.format.encoding = port->format.encoding;
2810 + m.u.port_info_set.format.encoding_variant =
2811 + port->format.encoding_variant;
2812 + m.u.port_info_set.format.bitrate = port->format.bitrate;
2813 + m.u.port_info_set.format.flags = port->format.flags;
2814 +
2815 + memcpy(&m.u.port_info_set.es, &port->es,
2816 + sizeof(union mmal_es_specific_format));
2817 +
2818 + m.u.port_info_set.format.extradata_size = port->format.extradata_size;
2819 + memcpy(&m.u.port_info_set.extradata, port->format.extradata,
2820 + port->format.extradata_size);
2821 +
2822 + ret = send_synchronous_mmal_msg(instance, &m,
2823 + sizeof(m.u.port_info_set),
2824 + &rmsg, &rmsg_handle);
2825 + if (ret)
2826 + return ret;
2827 +
2828 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
2829 + /* got an unexpected message type in reply */
2830 + ret = -EINVAL;
2831 + goto release_msg;
2832 + }
2833 +
2834 + /* return operation status */
2835 + ret = -rmsg->u.port_info_get_reply.status;
2836 +
2837 + pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
2838 + port->component->handle, port->handle);
2839 +
2840 +release_msg:
2841 + vchi_held_msg_release(&rmsg_handle);
2842 +
2843 + return ret;
2844 +}
2845 +
2846 +/* use port info get message to retrieve port information */
2847 +static int port_info_get(struct vchiq_mmal_instance *instance,
2848 + struct vchiq_mmal_port *port)
2849 +{
2850 + int ret;
2851 + struct mmal_msg m;
2852 + struct mmal_msg *rmsg;
2853 + VCHI_HELD_MSG_T rmsg_handle;
2854 +
2855 + /* port info time */
2856 + m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
2857 + m.u.port_info_get.component_handle = port->component->handle;
2858 + m.u.port_info_get.port_type = port->type;
2859 + m.u.port_info_get.index = port->index;
2860 +
2861 + ret = send_synchronous_mmal_msg(instance, &m,
2862 + sizeof(m.u.port_info_get),
2863 + &rmsg, &rmsg_handle);
2864 + if (ret)
2865 + return ret;
2866 +
2867 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
2868 + /* got an unexpected message type in reply */
2869 + ret = -EINVAL;
2870 + goto release_msg;
2871 + }
2872 +
2873 + /* return operation status */
2874 + ret = -rmsg->u.port_info_get_reply.status;
2875 + if (ret != MMAL_MSG_STATUS_SUCCESS)
2876 + goto release_msg;
2877 +
2878 + if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
2879 + port->enabled = false;
2880 + else
2881 + port->enabled = true;
2882 +
2883 + /* copy the values out of the message */
2884 + port->handle = rmsg->u.port_info_get_reply.port_handle;
2885 +
2886 + /* port type and index cached to use on port info set because
2887 + * it does not use a port handle
2888 + */
2889 + port->type = rmsg->u.port_info_get_reply.port_type;
2890 + port->index = rmsg->u.port_info_get_reply.port_index;
2891 +
2892 + port->minimum_buffer.num =
2893 + rmsg->u.port_info_get_reply.port.buffer_num_min;
2894 + port->minimum_buffer.size =
2895 + rmsg->u.port_info_get_reply.port.buffer_size_min;
2896 + port->minimum_buffer.alignment =
2897 + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
2898 +
2899 + port->recommended_buffer.alignment =
2900 + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
2901 + port->recommended_buffer.num =
2902 + rmsg->u.port_info_get_reply.port.buffer_num_recommended;
2903 +
2904 + port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
2905 + port->current_buffer.size =
2906 + rmsg->u.port_info_get_reply.port.buffer_size;
2907 +
2908 + /* stream format */
2909 + port->format.type = rmsg->u.port_info_get_reply.format.type;
2910 + port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
2911 + port->format.encoding_variant =
2912 + rmsg->u.port_info_get_reply.format.encoding_variant;
2913 + port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
2914 + port->format.flags = rmsg->u.port_info_get_reply.format.flags;
2915 +
2916 + /* elementary stream format */
2917 + memcpy(&port->es,
2918 + &rmsg->u.port_info_get_reply.es,
2919 + sizeof(union mmal_es_specific_format));
2920 + port->format.es = &port->es;
2921 +
2922 + port->format.extradata_size =
2923 + rmsg->u.port_info_get_reply.format.extradata_size;
2924 + memcpy(port->format.extradata,
2925 + rmsg->u.port_info_get_reply.extradata,
2926 + port->format.extradata_size);
2927 +
2928 + pr_debug("received port info\n");
2929 + dump_port_info(port);
2930 +
2931 +release_msg:
2932 +
2933 + pr_debug("%s:result:%d component:0x%x port:%d\n",
2934 + __func__, ret, port->component->handle, port->handle);
2935 +
2936 + vchi_held_msg_release(&rmsg_handle);
2937 +
2938 + return ret;
2939 +}
2940 +
2941 +/* create comonent on vc */
2942 +static int create_component(struct vchiq_mmal_instance *instance,
2943 + struct vchiq_mmal_component *component,
2944 + const char *name)
2945 +{
2946 + int ret;
2947 + struct mmal_msg m;
2948 + struct mmal_msg *rmsg;
2949 + VCHI_HELD_MSG_T rmsg_handle;
2950 +
2951 + /* build component create message */
2952 + m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
2953 + m.u.component_create.client_component = (u32)(unsigned long)component;
2954 + strncpy(m.u.component_create.name, name,
2955 + sizeof(m.u.component_create.name));
2956 +
2957 + ret = send_synchronous_mmal_msg(instance, &m,
2958 + sizeof(m.u.component_create),
2959 + &rmsg, &rmsg_handle);
2960 + if (ret)
2961 + return ret;
2962 +
2963 + if (rmsg->h.type != m.h.type) {
2964 + /* got an unexpected message type in reply */
2965 + ret = -EINVAL;
2966 + goto release_msg;
2967 + }
2968 +
2969 + ret = -rmsg->u.component_create_reply.status;
2970 + if (ret != MMAL_MSG_STATUS_SUCCESS)
2971 + goto release_msg;
2972 +
2973 + /* a valid component response received */
2974 + component->handle = rmsg->u.component_create_reply.component_handle;
2975 + component->inputs = rmsg->u.component_create_reply.input_num;
2976 + component->outputs = rmsg->u.component_create_reply.output_num;
2977 + component->clocks = rmsg->u.component_create_reply.clock_num;
2978 +
2979 + pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
2980 + component->handle,
2981 + component->inputs, component->outputs, component->clocks);
2982 +
2983 +release_msg:
2984 + vchi_held_msg_release(&rmsg_handle);
2985 +
2986 + return ret;
2987 +}
2988 +
2989 +/* destroys a component on vc */
2990 +static int destroy_component(struct vchiq_mmal_instance *instance,
2991 + struct vchiq_mmal_component *component)
2992 +{
2993 + int ret;
2994 + struct mmal_msg m;
2995 + struct mmal_msg *rmsg;
2996 + VCHI_HELD_MSG_T rmsg_handle;
2997 +
2998 + m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
2999 + m.u.component_destroy.component_handle = component->handle;
3000 +
3001 + ret = send_synchronous_mmal_msg(instance, &m,
3002 + sizeof(m.u.component_destroy),
3003 + &rmsg, &rmsg_handle);
3004 + if (ret)
3005 + return ret;
3006 +
3007 + if (rmsg->h.type != m.h.type) {
3008 + /* got an unexpected message type in reply */
3009 + ret = -EINVAL;
3010 + goto release_msg;
3011 + }
3012 +
3013 + ret = -rmsg->u.component_destroy_reply.status;
3014 +
3015 +release_msg:
3016 +
3017 + vchi_held_msg_release(&rmsg_handle);
3018 +
3019 + return ret;
3020 +}
3021 +
3022 +/* enable a component on vc */
3023 +static int enable_component(struct vchiq_mmal_instance *instance,
3024 + struct vchiq_mmal_component *component)
3025 +{
3026 + int ret;
3027 + struct mmal_msg m;
3028 + struct mmal_msg *rmsg;
3029 + VCHI_HELD_MSG_T rmsg_handle;
3030 +
3031 + m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
3032 + m.u.component_enable.component_handle = component->handle;
3033 +
3034 + ret = send_synchronous_mmal_msg(instance, &m,
3035 + sizeof(m.u.component_enable),
3036 + &rmsg, &rmsg_handle);
3037 + if (ret)
3038 + return ret;
3039 +
3040 + if (rmsg->h.type != m.h.type) {
3041 + /* got an unexpected message type in reply */
3042 + ret = -EINVAL;
3043 + goto release_msg;
3044 + }
3045 +
3046 + ret = -rmsg->u.component_enable_reply.status;
3047 +
3048 +release_msg:
3049 + vchi_held_msg_release(&rmsg_handle);
3050 +
3051 + return ret;
3052 +}
3053 +
3054 +/* disable a component on vc */
3055 +static int disable_component(struct vchiq_mmal_instance *instance,
3056 + struct vchiq_mmal_component *component)
3057 +{
3058 + int ret;
3059 + struct mmal_msg m;
3060 + struct mmal_msg *rmsg;
3061 + VCHI_HELD_MSG_T rmsg_handle;
3062 +
3063 + m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
3064 + m.u.component_disable.component_handle = component->handle;
3065 +
3066 + ret = send_synchronous_mmal_msg(instance, &m,
3067 + sizeof(m.u.component_disable),
3068 + &rmsg, &rmsg_handle);
3069 + if (ret)
3070 + return ret;
3071 +
3072 + if (rmsg->h.type != m.h.type) {
3073 + /* got an unexpected message type in reply */
3074 + ret = -EINVAL;
3075 + goto release_msg;
3076 + }
3077 +
3078 + ret = -rmsg->u.component_disable_reply.status;
3079 +
3080 +release_msg:
3081 +
3082 + vchi_held_msg_release(&rmsg_handle);
3083 +
3084 + return ret;
3085 +}
3086 +
3087 +/* get version of mmal implementation */
3088 +static int get_version(struct vchiq_mmal_instance *instance,
3089 + u32 *major_out, u32 *minor_out)
3090 +{
3091 + int ret;
3092 + struct mmal_msg m;
3093 + struct mmal_msg *rmsg;
3094 + VCHI_HELD_MSG_T rmsg_handle;
3095 +
3096 + m.h.type = MMAL_MSG_TYPE_GET_VERSION;
3097 +
3098 + ret = send_synchronous_mmal_msg(instance, &m,
3099 + sizeof(m.u.version),
3100 + &rmsg, &rmsg_handle);
3101 + if (ret)
3102 + return ret;
3103 +
3104 + if (rmsg->h.type != m.h.type) {
3105 + /* got an unexpected message type in reply */
3106 + ret = -EINVAL;
3107 + goto release_msg;
3108 + }
3109 +
3110 + *major_out = rmsg->u.version.major;
3111 + *minor_out = rmsg->u.version.minor;
3112 +
3113 +release_msg:
3114 + vchi_held_msg_release(&rmsg_handle);
3115 +
3116 + return ret;
3117 +}
3118 +
3119 +/* do a port action with a port as a parameter */
3120 +static int port_action_port(struct vchiq_mmal_instance *instance,
3121 + struct vchiq_mmal_port *port,
3122 + enum mmal_msg_port_action_type action_type)
3123 +{
3124 + int ret;
3125 + struct mmal_msg m;
3126 + struct mmal_msg *rmsg;
3127 + VCHI_HELD_MSG_T rmsg_handle;
3128 +
3129 + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
3130 + m.u.port_action_port.component_handle = port->component->handle;
3131 + m.u.port_action_port.port_handle = port->handle;
3132 + m.u.port_action_port.action = action_type;
3133 +
3134 + port_to_mmal_msg(port, &m.u.port_action_port.port);
3135 +
3136 + ret = send_synchronous_mmal_msg(instance, &m,
3137 + sizeof(m.u.port_action_port),
3138 + &rmsg, &rmsg_handle);
3139 + if (ret)
3140 + return ret;
3141 +
3142 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
3143 + /* got an unexpected message type in reply */
3144 + ret = -EINVAL;
3145 + goto release_msg;
3146 + }
3147 +
3148 + ret = -rmsg->u.port_action_reply.status;
3149 +
3150 + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
3151 + __func__,
3152 + ret, port->component->handle, port->handle,
3153 + port_action_type_names[action_type], action_type);
3154 +
3155 +release_msg:
3156 + vchi_held_msg_release(&rmsg_handle);
3157 +
3158 + return ret;
3159 +}
3160 +
3161 +/* do a port action with handles as parameters */
3162 +static int port_action_handle(struct vchiq_mmal_instance *instance,
3163 + struct vchiq_mmal_port *port,
3164 + enum mmal_msg_port_action_type action_type,
3165 + u32 connect_component_handle,
3166 + u32 connect_port_handle)
3167 +{
3168 + int ret;
3169 + struct mmal_msg m;
3170 + struct mmal_msg *rmsg;
3171 + VCHI_HELD_MSG_T rmsg_handle;
3172 +
3173 + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
3174 +
3175 + m.u.port_action_handle.component_handle = port->component->handle;
3176 + m.u.port_action_handle.port_handle = port->handle;
3177 + m.u.port_action_handle.action = action_type;
3178 +
3179 + m.u.port_action_handle.connect_component_handle =
3180 + connect_component_handle;
3181 + m.u.port_action_handle.connect_port_handle = connect_port_handle;
3182 +
3183 + ret = send_synchronous_mmal_msg(instance, &m,
3184 + sizeof(m.u.port_action_handle),
3185 + &rmsg, &rmsg_handle);
3186 + if (ret)
3187 + return ret;
3188 +
3189 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
3190 + /* got an unexpected message type in reply */
3191 + ret = -EINVAL;
3192 + goto release_msg;
3193 + }
3194 +
3195 + ret = -rmsg->u.port_action_reply.status;
3196 +
3197 + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d) connect component:0x%x connect port:%d\n",
3198 + __func__,
3199 + ret, port->component->handle, port->handle,
3200 + port_action_type_names[action_type],
3201 + action_type, connect_component_handle, connect_port_handle);
3202 +
3203 +release_msg:
3204 + vchi_held_msg_release(&rmsg_handle);
3205 +
3206 + return ret;
3207 +}
3208 +
3209 +static int port_parameter_set(struct vchiq_mmal_instance *instance,
3210 + struct vchiq_mmal_port *port,
3211 + u32 parameter_id, void *value, u32 value_size)
3212 +{
3213 + int ret;
3214 + struct mmal_msg m;
3215 + struct mmal_msg *rmsg;
3216 + VCHI_HELD_MSG_T rmsg_handle;
3217 +
3218 + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
3219 +
3220 + m.u.port_parameter_set.component_handle = port->component->handle;
3221 + m.u.port_parameter_set.port_handle = port->handle;
3222 + m.u.port_parameter_set.id = parameter_id;
3223 + m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
3224 + memcpy(&m.u.port_parameter_set.value, value, value_size);
3225 +
3226 + ret = send_synchronous_mmal_msg(instance, &m,
3227 + (4 * sizeof(u32)) + value_size,
3228 + &rmsg, &rmsg_handle);
3229 + if (ret)
3230 + return ret;
3231 +
3232 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
3233 + /* got an unexpected message type in reply */
3234 + ret = -EINVAL;
3235 + goto release_msg;
3236 + }
3237 +
3238 + ret = -rmsg->u.port_parameter_set_reply.status;
3239 +
3240 + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
3241 + __func__,
3242 + ret, port->component->handle, port->handle, parameter_id);
3243 +
3244 +release_msg:
3245 + vchi_held_msg_release(&rmsg_handle);
3246 +
3247 + return ret;
3248 +}
3249 +
3250 +static int port_parameter_get(struct vchiq_mmal_instance *instance,
3251 + struct vchiq_mmal_port *port,
3252 + u32 parameter_id, void *value, u32 *value_size)
3253 +{
3254 + int ret;
3255 + struct mmal_msg m;
3256 + struct mmal_msg *rmsg;
3257 + VCHI_HELD_MSG_T rmsg_handle;
3258 +
3259 + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
3260 +
3261 + m.u.port_parameter_get.component_handle = port->component->handle;
3262 + m.u.port_parameter_get.port_handle = port->handle;
3263 + m.u.port_parameter_get.id = parameter_id;
3264 + m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
3265 +
3266 + ret = send_synchronous_mmal_msg(instance, &m,
3267 + sizeof(struct
3268 + mmal_msg_port_parameter_get),
3269 + &rmsg, &rmsg_handle);
3270 + if (ret)
3271 + return ret;
3272 +
3273 + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
3274 + /* got an unexpected message type in reply */
3275 + pr_err("Incorrect reply type %d\n", rmsg->h.type);
3276 + ret = -EINVAL;
3277 + goto release_msg;
3278 + }
3279 +
3280 + ret = -rmsg->u.port_parameter_get_reply.status;
3281 + /* port_parameter_get_reply.size includes the header,
3282 + * whilst *value_size doesn't.
3283 + */
3284 + rmsg->u.port_parameter_get_reply.size -= (2 * sizeof(u32));
3285 +
3286 + if (ret || rmsg->u.port_parameter_get_reply.size > *value_size) {
3287 + /* Copy only as much as we have space for
3288 + * but report true size of parameter
3289 + */
3290 + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
3291 + *value_size);
3292 + *value_size = rmsg->u.port_parameter_get_reply.size;
3293 + } else {
3294 + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
3295 + rmsg->u.port_parameter_get_reply.size);
3296 + }
3297 +
3298 + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
3299 + ret, port->component->handle, port->handle, parameter_id);
3300 +
3301 +release_msg:
3302 + vchi_held_msg_release(&rmsg_handle);
3303 +
3304 + return ret;
3305 +}
3306 +
3307 +/* disables a port and drains buffers from it */
3308 +static int port_disable(struct vchiq_mmal_instance *instance,
3309 + struct vchiq_mmal_port *port)
3310 +{
3311 + int ret;
3312 + struct list_head *q, *buf_head;
3313 + unsigned long flags = 0;
3314 +
3315 + if (!port->enabled)
3316 + return 0;
3317 +
3318 + port->enabled = false;
3319 +
3320 + ret = port_action_port(instance, port,
3321 + MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
3322 + if (ret == 0) {
3323 + /*
3324 + * Drain all queued buffers on port. This should only
3325 + * apply to buffers that have been queued before the port
3326 + * has been enabled. If the port has been enabled and buffers
3327 + * passed, then the buffers should have been removed from this
3328 + * list, and we should get the relevant callbacks via VCHIQ
3329 + * to release the buffers.
3330 + */
3331 + spin_lock_irqsave(&port->slock, flags);
3332 +
3333 + list_for_each_safe(buf_head, q, &port->buffers) {
3334 + struct mmal_buffer *mmalbuf;
3335 +
3336 + mmalbuf = list_entry(buf_head, struct mmal_buffer,
3337 + list);
3338 + list_del(buf_head);
3339 + if (port->buffer_cb)
3340 + port->buffer_cb(instance,
3341 + port, 0, mmalbuf, 0, 0,
3342 + MMAL_TIME_UNKNOWN,
3343 + MMAL_TIME_UNKNOWN);
3344 + }
3345 +
3346 + spin_unlock_irqrestore(&port->slock, flags);
3347 +
3348 + ret = port_info_get(instance, port);
3349 + }
3350 +
3351 + return ret;
3352 +}
3353 +
3354 +/* enable a port */
3355 +static int port_enable(struct vchiq_mmal_instance *instance,
3356 + struct vchiq_mmal_port *port)
3357 +{
3358 + unsigned int hdr_count;
3359 + struct list_head *q, *buf_head;
3360 + int ret;
3361 +
3362 + if (port->enabled)
3363 + return 0;
3364 +
3365 + ret = port_action_port(instance, port,
3366 + MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
3367 + if (ret)
3368 + goto done;
3369 +
3370 + port->enabled = true;
3371 +
3372 + if (port->buffer_cb) {
3373 + /* send buffer headers to videocore */
3374 + hdr_count = 1;
3375 + list_for_each_safe(buf_head, q, &port->buffers) {
3376 + struct mmal_buffer *mmalbuf;
3377 +
3378 + mmalbuf = list_entry(buf_head, struct mmal_buffer,
3379 + list);
3380 + ret = buffer_from_host(instance, port, mmalbuf);
3381 + if (ret)
3382 + goto done;
3383 +
3384 + list_del(buf_head);
3385 + hdr_count++;
3386 + if (hdr_count > port->current_buffer.num)
3387 + break;
3388 + }
3389 + }
3390 +
3391 + ret = port_info_get(instance, port);
3392 +
3393 +done:
3394 + return ret;
3395 +}
3396 +
3397 +/* ------------------------------------------------------------------
3398 + * Exported API
3399 + *------------------------------------------------------------------
3400 + */
3401 +
3402 +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
3403 + struct vchiq_mmal_port *port)
3404 +{
3405 + int ret;
3406 +
3407 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
3408 + return -EINTR;
3409 +
3410 + ret = port_info_set(instance, port);
3411 + if (ret)
3412 + goto release_unlock;
3413 +
3414 + /* read what has actually been set */
3415 + ret = port_info_get(instance, port);
3416 +
3417 +release_unlock:
3418 + mutex_unlock(&instance->vchiq_mutex);
3419 +
3420 + return ret;
3421 +}
3422 +EXPORT_SYMBOL_GPL(vchiq_mmal_port_set_format);
3423 +
3424 +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
3425 + struct vchiq_mmal_port *port,
3426 + u32 parameter, void *value, u32 value_size)
3427 +{
3428 + int ret;
3429 +
3430 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
3431 + return -EINTR;
3432 +
3433 + ret = port_parameter_set(instance, port, parameter, value, value_size);
3434 +
3435 + mutex_unlock(&instance->vchiq_mutex);
3436 +
3437 + return ret;
3438 +}
3439 +EXPORT_SYMBOL_GPL(vchiq_mmal_port_parameter_set);
3440 +
3441 +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
3442 + struct vchiq_mmal_port *port,
3443 + u32 parameter, void *value, u32 *value_size)
3444 +{
3445 + int ret;
3446 +
3447 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
3448 + return -EINTR;
3449 +
3450 + ret = port_parameter_get(instance, port, parameter, value, value_size);
3451 +
3452 + mutex_unlock(&instance->vchiq_mutex);
3453 +
3454 + return ret;
3455 +}
3456 +EXPORT_SYMBOL_GPL(vchiq_mmal_port_parameter_get);
3457 +
3458 +/* enable a port
3459 + *
3460 + * enables a port and queues buffers for satisfying callbacks if we
3461 + * provide a callback handler
3462 + */
3463 +int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
3464 + struct vchiq_mmal_port *port,
3465 + vchiq_mmal_buffer_cb buffer_cb)
3466 +{
3467 + int ret;
3468 +
3469 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
3470 + return -EINTR;
3471 +
3472 + /* already enabled - noop */
3473 + if (port->enabled) {
3474 + ret = 0;
3475 + goto unlock;
3476 + }
3477 +
3478 + port->buffer_cb = buffer_cb;
3479 +
3480 + ret = port_enable(instance, port);
3481 +
3482 +unlock:
3483 + mutex_unlock(&instance->vchiq_mutex);
3484 +
3485 + return ret;
3486 +}
3487 +EXPORT_SYMBOL_GPL(vchiq_mmal_port_enable);
3488 +
3489 +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
3490 + struct vchiq_mmal_port *port)
3491 +{
3492 + int ret;
3493 +
3494 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
3495 + return -EINTR;
3496 +
3497 + if (!port->enabled) {
3498 + mutex_unlock(&instance->vchiq_mutex);
3499 + return 0;
3500 + }
3501 +
3502 + ret = port_disable(instance, port);
3503 +
3504 + mutex_unlock(&instance->vchiq_mutex);
3505 +
3506 + return ret;
3507 +}
3508 +EXPORT_SYMBOL_GPL(vchiq_mmal_port_disable);
3509 +
3510 +/* ports will be connected in a tunneled manner so data buffers
3511 + * are not handled by client.
3512 + */
3513 +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
3514 + struct vchiq_mmal_port *src,
3515 + struct vchiq_mmal_port *dst)
3516 +{
3517 + int ret;
3518 +
3519 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
3520 + return -EINTR;
3521 +
3522 + /* disconnect ports if connected */
3523 + if (src->connected) {
3524 + ret = port_disable(instance, src);
3525 + if (ret) {
3526 + pr_err("failed disabling src port(%d)\n", ret);
3527 + goto release_unlock;
3528 + }
3529 +
3530 + /* do not need to disable the destination port as they
3531 + * are connected and it is done automatically
3532 + */
3533 +
3534 + ret = port_action_handle(instance, src,
3535 + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
3536 + src->connected->component->handle,
3537 + src->connected->handle);
3538 + if (ret < 0) {
3539 + pr_err("failed disconnecting src port\n");
3540 + goto release_unlock;
3541 + }
3542 + src->connected->enabled = false;
3543 + src->connected = NULL;
3544 + }
3545 +
3546 + if (!dst) {
3547 + /* do not make new connection */
3548 + ret = 0;
3549 + pr_debug("not making new connection\n");
3550 + goto release_unlock;
3551 + }
3552 +
3553 + /* copy src port format to dst */
3554 + dst->format.encoding = src->format.encoding;
3555 + dst->es.video.width = src->es.video.width;
3556 + dst->es.video.height = src->es.video.height;
3557 + dst->es.video.crop.x = src->es.video.crop.x;
3558 + dst->es.video.crop.y = src->es.video.crop.y;
3559 + dst->es.video.crop.width = src->es.video.crop.width;
3560 + dst->es.video.crop.height = src->es.video.crop.height;
3561 + dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
3562 + dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
3563 +
3564 + /* set new format */
3565 + ret = port_info_set(instance, dst);
3566 + if (ret) {
3567 + pr_debug("setting port info failed\n");
3568 + goto release_unlock;
3569 + }
3570 +
3571 + /* read what has actually been set */
3572 + ret = port_info_get(instance, dst);
3573 + if (ret) {
3574 + pr_debug("read back port info failed\n");
3575 + goto release_unlock;
3576 + }
3577 +
3578 + /* connect two ports together */
3579 + ret = port_action_handle(instance, src,
3580 + MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
3581 + dst->component->handle, dst->handle);
3582 + if (ret < 0) {
3583 + pr_debug("connecting port %d:%d to %d:%d failed\n",
3584 + src->component->handle, src->handle,
3585 + dst->component->handle, dst->handle);
3586 + goto release_unlock;
3587 + }
3588 + src->connected = dst;
3589 +
3590 +release_unlock:
3591 +
3592 + mutex_unlock(&instance->vchiq_mutex);
3593 +
3594 + return ret;
3595 +}
3596 +EXPORT_SYMBOL_GPL(vchiq_mmal_port_connect_tunnel);
3597 +
3598 +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
3599 + struct vchiq_mmal_port *port,
3600 + struct mmal_buffer *buffer)
3601 +{
3602 + unsigned long flags = 0;
3603 + int ret;
3604 +
3605 + ret = buffer_from_host(instance, port, buffer);
3606 + if (ret == -EINVAL) {
3607 + /* Port is disabled. Queue for when it is enabled. */
3608 + spin_lock_irqsave(&port->slock, flags);
3609 + list_add_tail(&buffer->list, &port->buffers);
3610 + spin_unlock_irqrestore(&port->slock, flags);
3611 + }
3612 +
3613 + return 0;
3614 +}
3615 +EXPORT_SYMBOL_GPL(vchiq_mmal_submit_buffer);
3616 +
3617 +int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance,
3618 + struct mmal_buffer *buf)
3619 +{
3620 + struct mmal_msg_context *msg_context = get_msg_context(instance);
3621 +
3622 + if (IS_ERR(msg_context))
3623 + return (PTR_ERR(msg_context));
3624 +
3625 + buf->msg_context = msg_context;
3626 + return 0;
3627 +}
3628 +EXPORT_SYMBOL_GPL(mmal_vchi_buffer_init);
3629 +
3630 +int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf)
3631 +{
3632 + struct mmal_msg_context *msg_context = buf->msg_context;
3633 +
3634 + if (msg_context)
3635 + release_msg_context(msg_context);
3636 + buf->msg_context = NULL;
3637 +
3638 + return 0;
3639 +}
3640 +EXPORT_SYMBOL_GPL(mmal_vchi_buffer_cleanup);
3641 +
3642 +/* Initialise a mmal component and its ports
3643 + *
3644 + */
3645 +int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
3646 + const char *name,
3647 + struct vchiq_mmal_component **component_out)
3648 +{
3649 + int ret;
3650 + int idx; /* port index */
3651 + struct vchiq_mmal_component *component;
3652 +
3653 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
3654 + return -EINTR;
3655 +
3656 + if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
3657 + ret = -EINVAL; /* todo is this correct error? */
3658 + goto unlock;
3659 + }
3660 +
3661 + component = &instance->component[instance->component_idx];
3662 +
3663 + ret = create_component(instance, component, name);
3664 + if (ret < 0) {
3665 + pr_err("%s: failed to create component %d (Not enough GPU mem?)\n",
3666 + __func__, ret);
3667 + goto unlock;
3668 + }
3669 +
3670 + /* ports info needs gathering */
3671 + component->control.type = MMAL_PORT_TYPE_CONTROL;
3672 + component->control.index = 0;
3673 + component->control.component = component;
3674 + spin_lock_init(&component->control.slock);
3675 + INIT_LIST_HEAD(&component->control.buffers);
3676 + ret = port_info_get(instance, &component->control);
3677 + if (ret < 0)
3678 + goto release_component;
3679 +
3680 + for (idx = 0; idx < component->inputs; idx++) {
3681 + component->input[idx].type = MMAL_PORT_TYPE_INPUT;
3682 + component->input[idx].index = idx;
3683 + component->input[idx].component = component;
3684 + spin_lock_init(&component->input[idx].slock);
3685 + INIT_LIST_HEAD(&component->input[idx].buffers);
3686 + ret = port_info_get(instance, &component->input[idx]);
3687 + if (ret < 0)
3688 + goto release_component;
3689 + }
3690 +
3691 + for (idx = 0; idx < component->outputs; idx++) {
3692 + component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
3693 + component->output[idx].index = idx;
3694 + component->output[idx].component = component;
3695 + spin_lock_init(&component->output[idx].slock);
3696 + INIT_LIST_HEAD(&component->output[idx].buffers);
3697 + ret = port_info_get(instance, &component->output[idx]);
3698 + if (ret < 0)
3699 + goto release_component;
3700 + }
3701 +
3702 + for (idx = 0; idx < component->clocks; idx++) {
3703 + component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
3704 + component->clock[idx].index = idx;
3705 + component->clock[idx].component = component;
3706 + spin_lock_init(&component->clock[idx].slock);
3707 + INIT_LIST_HEAD(&component->clock[idx].buffers);
3708 + ret = port_info_get(instance, &component->clock[idx]);
3709 + if (ret < 0)
3710 + goto release_component;
3711 + }
3712 +
3713 + instance->component_idx++;
3714 +
3715 + *component_out = component;
3716 +
3717 + mutex_unlock(&instance->vchiq_mutex);
3718 +
3719 + return 0;
3720 +
3721 +release_component:
3722 + destroy_component(instance, component);
3723 +unlock:
3724 + mutex_unlock(&instance->vchiq_mutex);
3725 +
3726 + return ret;
3727 +}
3728 +EXPORT_SYMBOL_GPL(vchiq_mmal_component_init);
3729 +
3730 +/*
3731 + * cause a mmal component to be destroyed
3732 + */
3733 +int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
3734 + struct vchiq_mmal_component *component)
3735 +{
3736 + int ret;
3737 +
3738 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
3739 + return -EINTR;
3740 +
3741 + if (component->enabled)
3742 + ret = disable_component(instance, component);
3743 +
3744 + ret = destroy_component(instance, component);
3745 +
3746 + mutex_unlock(&instance->vchiq_mutex);
3747 +
3748 + return ret;
3749 +}
3750 +EXPORT_SYMBOL_GPL(vchiq_mmal_component_finalise);
3751 +
3752 +/*
3753 + * cause a mmal component to be enabled
3754 + */
3755 +int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
3756 + struct vchiq_mmal_component *component)
3757 +{
3758 + int ret;
3759 +
3760 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
3761 + return -EINTR;
3762 +
3763 + if (component->enabled) {
3764 + mutex_unlock(&instance->vchiq_mutex);
3765 + return 0;
3766 + }
3767 +
3768 + ret = enable_component(instance, component);
3769 + if (ret == 0)
3770 + component->enabled = true;
3771 +
3772 + mutex_unlock(&instance->vchiq_mutex);
3773 +
3774 + return ret;
3775 +}
3776 +EXPORT_SYMBOL_GPL(vchiq_mmal_component_enable);
3777 +
3778 +/*
3779 + * cause a mmal component to be enabled
3780 + */
3781 +int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
3782 + struct vchiq_mmal_component *component)
3783 +{
3784 + int ret;
3785 +
3786 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
3787 + return -EINTR;
3788 +
3789 + if (!component->enabled) {
3790 + mutex_unlock(&instance->vchiq_mutex);
3791 + return 0;
3792 + }
3793 +
3794 + ret = disable_component(instance, component);
3795 + if (ret == 0)
3796 + component->enabled = false;
3797 +
3798 + mutex_unlock(&instance->vchiq_mutex);
3799 +
3800 + return ret;
3801 +}
3802 +EXPORT_SYMBOL_GPL(vchiq_mmal_component_disable);
3803 +
3804 +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
3805 + u32 *major_out, u32 *minor_out)
3806 +{
3807 + int ret;
3808 +
3809 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
3810 + return -EINTR;
3811 +
3812 + ret = get_version(instance, major_out, minor_out);
3813 +
3814 + mutex_unlock(&instance->vchiq_mutex);
3815 +
3816 + return ret;
3817 +}
3818 +EXPORT_SYMBOL_GPL(vchiq_mmal_version);
3819 +
3820 +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
3821 +{
3822 + int status = 0;
3823 +
3824 + if (!instance)
3825 + return -EINVAL;
3826 +
3827 + if (mutex_lock_interruptible(&instance->vchiq_mutex))
3828 + return -EINTR;
3829 +
3830 + vchi_service_use(instance->handle);
3831 +
3832 + status = vchi_service_close(instance->handle);
3833 + if (status != 0)
3834 + pr_err("mmal-vchiq: VCHIQ close failed\n");
3835 +
3836 + mutex_unlock(&instance->vchiq_mutex);
3837 +
3838 + flush_workqueue(instance->bulk_wq);
3839 + destroy_workqueue(instance->bulk_wq);
3840 +
3841 + vfree(instance->bulk_scratch);
3842 +
3843 + idr_destroy(&instance->context_map);
3844 +
3845 + kfree(instance);
3846 +
3847 + return status;
3848 +}
3849 +EXPORT_SYMBOL_GPL(vchiq_mmal_finalise);
3850 +
3851 +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
3852 +{
3853 + int status;
3854 + struct vchiq_mmal_instance *instance;
3855 + static VCHI_CONNECTION_T *vchi_connection;
3856 + static VCHI_INSTANCE_T vchi_instance;
3857 + SERVICE_CREATION_T params = {
3858 + .version = VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
3859 + .service_id = VC_MMAL_SERVER_NAME,
3860 + .connection = vchi_connection,
3861 + .rx_fifo_size = 0,
3862 + .tx_fifo_size = 0,
3863 + .callback = service_callback,
3864 + .callback_param = NULL,
3865 + .want_unaligned_bulk_rx = 1,
3866 + .want_unaligned_bulk_tx = 1,
3867 + .want_crc = 0
3868 + };
3869 +
3870 + /* compile time checks to ensure structure size as they are
3871 + * directly (de)serialised from memory.
3872 + */
3873 +
3874 + /* ensure the header structure has packed to the correct size */
3875 + BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
3876 +
3877 + /* ensure message structure does not exceed maximum length */
3878 + BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
3879 +
3880 + /* mmal port struct is correct size */
3881 + BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
3882 +
3883 + /* create a vchi instance */
3884 + status = vchi_initialise(&vchi_instance);
3885 + if (status) {
3886 + pr_err("Failed to initialise VCHI instance (status=%d)\n",
3887 + status);
3888 + return -EIO;
3889 + }
3890 +
3891 + status = vchi_connect(NULL, 0, vchi_instance);
3892 + if (status) {
3893 + pr_err("Failed to connect VCHI instance (status=%d)\n", status);
3894 + return -EIO;
3895 + }
3896 +
3897 + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
3898 +
3899 + if (!instance)
3900 + return -ENOMEM;
3901 +
3902 + mutex_init(&instance->vchiq_mutex);
3903 +
3904 + instance->bulk_scratch = vmalloc(PAGE_SIZE);
3905 +
3906 + mutex_init(&instance->context_map_lock);
3907 + idr_init_base(&instance->context_map, 1);
3908 +
3909 + params.callback_param = instance;
3910 +
3911 + instance->bulk_wq = alloc_ordered_workqueue("mmal-vchiq",
3912 + WQ_MEM_RECLAIM);
3913 + if (!instance->bulk_wq)
3914 + goto err_free;
3915 +
3916 + status = vchi_service_open(vchi_instance, &params, &instance->handle);
3917 + if (status) {
3918 + pr_err("Failed to open VCHI service connection (status=%d)\n",
3919 + status);
3920 + goto err_close_services;
3921 + }
3922 +
3923 + vchi_service_release(instance->handle);
3924 +
3925 + *out_instance = instance;
3926 +
3927 + return 0;
3928 +
3929 +err_close_services:
3930 + vchi_service_close(instance->handle);
3931 + destroy_workqueue(instance->bulk_wq);
3932 +err_free:
3933 + vfree(instance->bulk_scratch);
3934 + kfree(instance);
3935 + return -ENODEV;
3936 +}
3937 +EXPORT_SYMBOL_GPL(vchiq_mmal_init);
3938 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-common.h
3939 +++ /dev/null
3940 @@ -1,61 +0,0 @@
3941 -/* SPDX-License-Identifier: GPL-2.0 */
3942 -/*
3943 - * Broadcom BM2835 V4L2 driver
3944 - *
3945 - * Copyright © 2013 Raspberry Pi (Trading) Ltd.
3946 - *
3947 - * Authors: Vincent Sanders @ Collabora
3948 - * Dave Stevenson @ Broadcom
3949 - * (now dave.stevenson@raspberrypi.org)
3950 - * Simon Mellor @ Broadcom
3951 - * Luke Diamand @ Broadcom
3952 - *
3953 - * MMAL structures
3954 - *
3955 - */
3956 -#ifndef MMAL_COMMON_H
3957 -#define MMAL_COMMON_H
3958 -
3959 -#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
3960 -#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
3961 -
3962 -/** Special value signalling that time is not known */
3963 -#define MMAL_TIME_UNKNOWN BIT_ULL(63)
3964 -
3965 -struct mmal_msg_context;
3966 -
3967 -/* mapping between v4l and mmal video modes */
3968 -struct mmal_fmt {
3969 - char *name;
3970 - u32 fourcc; /* v4l2 format id */
3971 - int flags; /* v4l2 flags field */
3972 - u32 mmal;
3973 - int depth;
3974 - u32 mmal_component; /* MMAL component index to be used to encode */
3975 - u32 ybbp; /* depth of first Y plane for planar formats */
3976 - bool remove_padding; /* Does the GPU have to remove padding,
3977 - * or can we do hide padding via bytesperline.
3978 - */
3979 -};
3980 -
3981 -/* buffer for one video frame */
3982 -struct mmal_buffer {
3983 - /* v4l buffer data -- must be first */
3984 - struct vb2_v4l2_buffer vb;
3985 -
3986 - /* list of buffers available */
3987 - struct list_head list;
3988 -
3989 - void *buffer; /* buffer pointer */
3990 - unsigned long buffer_size; /* size of allocated buffer */
3991 -
3992 - struct mmal_msg_context *msg_context;
3993 -};
3994 -
3995 -/* */
3996 -struct mmal_colourfx {
3997 - s32 enable;
3998 - u32 u;
3999 - u32 v;
4000 -};
4001 -#endif
4002 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-encodings.h
4003 +++ /dev/null
4004 @@ -1,124 +0,0 @@
4005 -/* SPDX-License-Identifier: GPL-2.0 */
4006 -/*
4007 - * Broadcom BM2835 V4L2 driver
4008 - *
4009 - * Copyright © 2013 Raspberry Pi (Trading) Ltd.
4010 - *
4011 - * Authors: Vincent Sanders @ Collabora
4012 - * Dave Stevenson @ Broadcom
4013 - * (now dave.stevenson@raspberrypi.org)
4014 - * Simon Mellor @ Broadcom
4015 - * Luke Diamand @ Broadcom
4016 - */
4017 -#ifndef MMAL_ENCODINGS_H
4018 -#define MMAL_ENCODINGS_H
4019 -
4020 -#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
4021 -#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
4022 -#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
4023 -#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
4024 -#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
4025 -#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
4026 -#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
4027 -#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
4028 -#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
4029 -#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
4030 -#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
4031 -#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
4032 -#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
4033 -#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
4034 -#define MMAL_ENCODING_MJPEG MMAL_FOURCC('M', 'J', 'P', 'G')
4035 -
4036 -#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
4037 -#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
4038 -#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
4039 -#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
4040 -#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
4041 -#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
4042 -
4043 -#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
4044 -#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
4045 -#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
4046 -#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
4047 -#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
4048 -#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
4049 -#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
4050 -#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
4051 -#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
4052 -#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
4053 -#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
4054 -#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
4055 -#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
4056 -#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
4057 -#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
4058 -#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
4059 -#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
4060 -#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
4061 -#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
4062 -#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
4063 -#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
4064 -
4065 -/** SAND Video (YUVUV128) format, native format understood by VideoCore.
4066 - * This format is *not* opaque - if requested you will receive full frames
4067 - * of YUV_UV video.
4068 - */
4069 -#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
4070 -
4071 -/** VideoCore opaque image format, image handles are returned to
4072 - * the host but not the actual image data.
4073 - */
4074 -#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
4075 -
4076 -/** An EGL image handle
4077 - */
4078 -#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
4079 -
4080 -/* }@ */
4081 -
4082 -/** \name Pre-defined audio encodings */
4083 -/* @{ */
4084 -#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
4085 -#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
4086 -#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
4087 -#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
4088 -#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
4089 -#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
4090 -
4091 -/* Pre-defined H264 encoding variants */
4092 -
4093 -/** ISO 14496-10 Annex B byte stream format */
4094 -#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
4095 -/** ISO 14496-15 AVC stream format */
4096 -#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
4097 -/** Implicitly delineated NAL units without emulation prevention */
4098 -#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
4099 -
4100 -/** \defgroup MmalColorSpace List of pre-defined video color spaces
4101 - * This defines a list of common color spaces. This list isn't exhaustive and
4102 - * is only provided as a convenience to avoid clients having to use FourCC
4103 - * codes directly. However components are allowed to define and use their own
4104 - * FourCC codes.
4105 - */
4106 -/* @{ */
4107 -
4108 -/** Unknown color space */
4109 -#define MMAL_COLOR_SPACE_UNKNOWN 0
4110 -/** ITU-R BT.601-5 [SDTV] */
4111 -#define MMAL_COLOR_SPACE_ITUR_BT601 MMAL_FOURCC('Y', '6', '0', '1')
4112 -/** ITU-R BT.709-3 [HDTV] */
4113 -#define MMAL_COLOR_SPACE_ITUR_BT709 MMAL_FOURCC('Y', '7', '0', '9')
4114 -/** JPEG JFIF */
4115 -#define MMAL_COLOR_SPACE_JPEG_JFIF MMAL_FOURCC('Y', 'J', 'F', 'I')
4116 -/** Title 47 Code of Federal Regulations (2003) 73.682 (a) (20) */
4117 -#define MMAL_COLOR_SPACE_FCC MMAL_FOURCC('Y', 'F', 'C', 'C')
4118 -/** Society of Motion Picture and Television Engineers 240M (1999) */
4119 -#define MMAL_COLOR_SPACE_SMPTE240M MMAL_FOURCC('Y', '2', '4', '0')
4120 -/** ITU-R BT.470-2 System M */
4121 -#define MMAL_COLOR_SPACE_BT470_2_M MMAL_FOURCC('Y', '_', '_', 'M')
4122 -/** ITU-R BT.470-2 System BG */
4123 -#define MMAL_COLOR_SPACE_BT470_2_BG MMAL_FOURCC('Y', '_', 'B', 'G')
4124 -/** JPEG JFIF, but with 16..255 luma */
4125 -#define MMAL_COLOR_SPACE_JFIF_Y16_255 MMAL_FOURCC('Y', 'Y', '1', '6')
4126 -/* @} MmalColorSpace List */
4127 -
4128 -#endif /* MMAL_ENCODINGS_H */
4129 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-msg-common.h
4130 +++ /dev/null
4131 @@ -1,48 +0,0 @@
4132 -/* SPDX-License-Identifier: GPL-2.0 */
4133 -/*
4134 - * Broadcom BM2835 V4L2 driver
4135 - *
4136 - * Copyright © 2013 Raspberry Pi (Trading) Ltd.
4137 - *
4138 - * Authors: Vincent Sanders @ Collabora
4139 - * Dave Stevenson @ Broadcom
4140 - * (now dave.stevenson@raspberrypi.org)
4141 - * Simon Mellor @ Broadcom
4142 - * Luke Diamand @ Broadcom
4143 - */
4144 -
4145 -#ifndef MMAL_MSG_COMMON_H
4146 -#define MMAL_MSG_COMMON_H
4147 -
4148 -enum mmal_msg_status {
4149 - MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
4150 - MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
4151 - MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
4152 - MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
4153 - MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
4154 - MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
4155 - MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
4156 - MMAL_MSG_STATUS_EIO, /**< I/O error */
4157 - MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
4158 - MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
4159 - MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
4160 - MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
4161 - MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
4162 - MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
4163 - MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
4164 - MMAL_MSG_STATUS_EFAULT, /**< Bad address */
4165 -};
4166 -
4167 -struct mmal_rect {
4168 - s32 x; /**< x coordinate (from left) */
4169 - s32 y; /**< y coordinate (from top) */
4170 - s32 width; /**< width */
4171 - s32 height; /**< height */
4172 -};
4173 -
4174 -struct mmal_rational {
4175 - s32 num; /**< Numerator */
4176 - s32 den; /**< Denominator */
4177 -};
4178 -
4179 -#endif /* MMAL_MSG_COMMON_H */
4180 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-msg-format.h
4181 +++ /dev/null
4182 @@ -1,106 +0,0 @@
4183 -/* SPDX-License-Identifier: GPL-2.0 */
4184 -/*
4185 - * Broadcom BM2835 V4L2 driver
4186 - *
4187 - * Copyright © 2013 Raspberry Pi (Trading) Ltd.
4188 - *
4189 - * Authors: Vincent Sanders @ Collabora
4190 - * Dave Stevenson @ Broadcom
4191 - * (now dave.stevenson@raspberrypi.org)
4192 - * Simon Mellor @ Broadcom
4193 - * Luke Diamand @ Broadcom
4194 - */
4195 -
4196 -#ifndef MMAL_MSG_FORMAT_H
4197 -#define MMAL_MSG_FORMAT_H
4198 -
4199 -#include "mmal-msg-common.h"
4200 -
4201 -/* MMAL_ES_FORMAT_T */
4202 -
4203 -struct mmal_audio_format {
4204 - u32 channels; /* Number of audio channels */
4205 - u32 sample_rate; /* Sample rate */
4206 -
4207 - u32 bits_per_sample; /* Bits per sample */
4208 - u32 block_align; /* Size of a block of data */
4209 -};
4210 -
4211 -struct mmal_video_format {
4212 - u32 width; /* Width of frame in pixels */
4213 - u32 height; /* Height of frame in rows of pixels */
4214 - struct mmal_rect crop; /* Visible region of the frame */
4215 - struct mmal_rational frame_rate; /* Frame rate */
4216 - struct mmal_rational par; /* Pixel aspect ratio */
4217 -
4218 - /*
4219 - * FourCC specifying the color space of the video stream. See the
4220 - * MmalColorSpace "pre-defined color spaces" for some examples.
4221 - */
4222 - u32 color_space;
4223 -};
4224 -
4225 -struct mmal_subpicture_format {
4226 - u32 x_offset;
4227 - u32 y_offset;
4228 -};
4229 -
4230 -union mmal_es_specific_format {
4231 - struct mmal_audio_format audio;
4232 - struct mmal_video_format video;
4233 - struct mmal_subpicture_format subpicture;
4234 -};
4235 -
4236 -/* Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
4237 -struct mmal_es_format_local {
4238 - u32 type; /* enum mmal_es_type */
4239 -
4240 - u32 encoding; /* FourCC specifying encoding of the elementary
4241 - * stream.
4242 - */
4243 - u32 encoding_variant; /* FourCC specifying the specific
4244 - * encoding variant of the elementary
4245 - * stream.
4246 - */
4247 -
4248 - union mmal_es_specific_format *es; /* Type specific
4249 - * information for the
4250 - * elementary stream
4251 - */
4252 -
4253 - u32 bitrate; /* Bitrate in bits per second */
4254 - u32 flags; /* Flags describing properties of the elementary
4255 - * stream.
4256 - */
4257 -
4258 - u32 extradata_size; /* Size of the codec specific data */
4259 - u8 *extradata; /* Codec specific data */
4260 -};
4261 -
4262 -/* Remote definition of an elementary stream format (MMAL_ES_FORMAT_T) */
4263 -struct mmal_es_format {
4264 - u32 type; /* enum mmal_es_type */
4265 -
4266 - u32 encoding; /* FourCC specifying encoding of the elementary
4267 - * stream.
4268 - */
4269 - u32 encoding_variant; /* FourCC specifying the specific
4270 - * encoding variant of the elementary
4271 - * stream.
4272 - */
4273 -
4274 - u32 es; /* Type specific
4275 - * information for the
4276 - * elementary stream
4277 - */
4278 -
4279 - u32 bitrate; /* Bitrate in bits per second */
4280 - u32 flags; /* Flags describing properties of the elementary
4281 - * stream.
4282 - */
4283 -
4284 - u32 extradata_size; /* Size of the codec specific data */
4285 - u32 extradata; /* Codec specific data */
4286 -};
4287 -
4288 -#endif /* MMAL_MSG_FORMAT_H */
4289 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-msg-port.h
4290 +++ /dev/null
4291 @@ -1,109 +0,0 @@
4292 -/* SPDX-License-Identifier: GPL-2.0 */
4293 -/*
4294 - * Broadcom BM2835 V4L2 driver
4295 - *
4296 - * Copyright © 2013 Raspberry Pi (Trading) Ltd.
4297 - *
4298 - * Authors: Vincent Sanders @ Collabora
4299 - * Dave Stevenson @ Broadcom
4300 - * (now dave.stevenson@raspberrypi.org)
4301 - * Simon Mellor @ Broadcom
4302 - * Luke Diamand @ Broadcom
4303 - */
4304 -
4305 -/* MMAL_PORT_TYPE_T */
4306 -enum mmal_port_type {
4307 - MMAL_PORT_TYPE_UNKNOWN = 0, /* Unknown port type */
4308 - MMAL_PORT_TYPE_CONTROL, /* Control port */
4309 - MMAL_PORT_TYPE_INPUT, /* Input port */
4310 - MMAL_PORT_TYPE_OUTPUT, /* Output port */
4311 - MMAL_PORT_TYPE_CLOCK, /* Clock port */
4312 -};
4313 -
4314 -/* The port is pass-through and doesn't need buffer headers allocated */
4315 -#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
4316 -/*
4317 - *The port wants to allocate the buffer payloads.
4318 - * This signals a preference that payload allocation should be done
4319 - * on this port for efficiency reasons.
4320 - */
4321 -#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
4322 -/*
4323 - * The port supports format change events.
4324 - * This applies to input ports and is used to let the client know
4325 - * whether the port supports being reconfigured via a format
4326 - * change event (i.e. without having to disable the port).
4327 - */
4328 -#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
4329 -
4330 -/*
4331 - * mmal port structure (MMAL_PORT_T)
4332 - *
4333 - * most elements are informational only, the pointer values for
4334 - * interogation messages are generally provided as additional
4335 - * structures within the message. When used to set values only the
4336 - * buffer_num, buffer_size and userdata parameters are writable.
4337 - */
4338 -struct mmal_port {
4339 - u32 priv; /* Private member used by the framework */
4340 - u32 name; /* Port name. Used for debugging purposes (RO) */
4341 -
4342 - u32 type; /* Type of the port (RO) enum mmal_port_type */
4343 - u16 index; /* Index of the port in its type list (RO) */
4344 - u16 index_all; /* Index of the port in the list of all ports (RO) */
4345 -
4346 - u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
4347 - u32 format; /* Format of the elementary stream */
4348 -
4349 - u32 buffer_num_min; /* Minimum number of buffers the port
4350 - * requires (RO). This is set by the
4351 - * component.
4352 - */
4353 -
4354 - u32 buffer_size_min; /* Minimum size of buffers the port
4355 - * requires (RO). This is set by the
4356 - * component.
4357 - */
4358 -
4359 - u32 buffer_alignment_min;/* Minimum alignment requirement for
4360 - * the buffers (RO). A value of
4361 - * zero means no special alignment
4362 - * requirements. This is set by the
4363 - * component.
4364 - */
4365 -
4366 - u32 buffer_num_recommended; /* Number of buffers the port
4367 - * recommends for optimal
4368 - * performance (RO). A value of
4369 - * zero means no special
4370 - * recommendation. This is set
4371 - * by the component.
4372 - */
4373 -
4374 - u32 buffer_size_recommended; /* Size of buffers the port
4375 - * recommends for optimal
4376 - * performance (RO). A value of
4377 - * zero means no special
4378 - * recommendation. This is set
4379 - * by the component.
4380 - */
4381 -
4382 - u32 buffer_num; /* Actual number of buffers the port will use.
4383 - * This is set by the client.
4384 - */
4385 -
4386 - u32 buffer_size; /* Actual maximum size of the buffers that
4387 - * will be sent to the port. This is set by
4388 - * the client.
4389 - */
4390 -
4391 - u32 component; /* Component this port belongs to (Read Only) */
4392 -
4393 - u32 userdata; /* Field reserved for use by the client */
4394 -
4395 - u32 capabilities; /* Flags describing the capabilities of a
4396 - * port (RO). Bitwise combination of \ref
4397 - * portcapabilities "Port capabilities"
4398 - * values.
4399 - */
4400 -};
4401 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-msg.h
4402 +++ /dev/null
4403 @@ -1,406 +0,0 @@
4404 -/* SPDX-License-Identifier: GPL-2.0 */
4405 -/*
4406 - * Broadcom BM2835 V4L2 driver
4407 - *
4408 - * Copyright © 2013 Raspberry Pi (Trading) Ltd.
4409 - *
4410 - * Authors: Vincent Sanders @ Collabora
4411 - * Dave Stevenson @ Broadcom
4412 - * (now dave.stevenson@raspberrypi.org)
4413 - * Simon Mellor @ Broadcom
4414 - * Luke Diamand @ Broadcom
4415 - */
4416 -
4417 -/*
4418 - * all the data structures which serialise the MMAL protocol. note
4419 - * these are directly mapped onto the recived message data.
4420 - *
4421 - * BEWARE: They seem to *assume* pointers are u32 and that there is no
4422 - * structure padding!
4423 - *
4424 - * NOTE: this implementation uses kernel types to ensure sizes. Rather
4425 - * than assigning values to enums to force their size the
4426 - * implementation uses fixed size types and not the enums (though the
4427 - * comments have the actual enum type
4428 - */
4429 -#ifndef MMAL_MSG_H
4430 -#define MMAL_MSG_H
4431 -
4432 -#define VC_MMAL_VER 15
4433 -#define VC_MMAL_MIN_VER 10
4434 -#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
4435 -
4436 -/* max total message size is 512 bytes */
4437 -#define MMAL_MSG_MAX_SIZE 512
4438 -/* with six 32bit header elements max payload is therefore 488 bytes */
4439 -#define MMAL_MSG_MAX_PAYLOAD 488
4440 -
4441 -#include "mmal-msg-common.h"
4442 -#include "mmal-msg-format.h"
4443 -#include "mmal-msg-port.h"
4444 -
4445 -enum mmal_msg_type {
4446 - MMAL_MSG_TYPE_QUIT = 1,
4447 - MMAL_MSG_TYPE_SERVICE_CLOSED,
4448 - MMAL_MSG_TYPE_GET_VERSION,
4449 - MMAL_MSG_TYPE_COMPONENT_CREATE,
4450 - MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
4451 - MMAL_MSG_TYPE_COMPONENT_ENABLE,
4452 - MMAL_MSG_TYPE_COMPONENT_DISABLE,
4453 - MMAL_MSG_TYPE_PORT_INFO_GET,
4454 - MMAL_MSG_TYPE_PORT_INFO_SET,
4455 - MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
4456 - MMAL_MSG_TYPE_BUFFER_FROM_HOST,
4457 - MMAL_MSG_TYPE_BUFFER_TO_HOST,
4458 - MMAL_MSG_TYPE_GET_STATS,
4459 - MMAL_MSG_TYPE_PORT_PARAMETER_SET,
4460 - MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
4461 - MMAL_MSG_TYPE_EVENT_TO_HOST,
4462 - MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
4463 - MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
4464 - MMAL_MSG_TYPE_CONSUME_MEM,
4465 - MMAL_MSG_TYPE_LMK, /* 20 */
4466 - MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
4467 - MMAL_MSG_TYPE_DRM_GET_LHS32,
4468 - MMAL_MSG_TYPE_DRM_GET_TIME,
4469 - MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
4470 - MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
4471 - MMAL_MSG_TYPE_HOST_LOG,
4472 - MMAL_MSG_TYPE_MSG_LAST
4473 -};
4474 -
4475 -/* port action request messages differ depending on the action type */
4476 -enum mmal_msg_port_action_type {
4477 - MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unknown action */
4478 - MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
4479 - MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
4480 - MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
4481 - MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
4482 - MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
4483 - MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
4484 -};
4485 -
4486 -struct mmal_msg_header {
4487 - u32 magic;
4488 - u32 type; /* enum mmal_msg_type */
4489 -
4490 - /* Opaque handle to the control service */
4491 - u32 control_service;
4492 -
4493 - u32 context; /* a u32 per message context */
4494 - u32 status; /* The status of the vchiq operation */
4495 - u32 padding;
4496 -};
4497 -
4498 -/* Send from VC to host to report version */
4499 -struct mmal_msg_version {
4500 - u32 flags;
4501 - u32 major;
4502 - u32 minor;
4503 - u32 minimum;
4504 -};
4505 -
4506 -/* request to VC to create component */
4507 -struct mmal_msg_component_create {
4508 - u32 client_component; /* component context */
4509 - char name[128];
4510 - u32 pid; /* For debug */
4511 -};
4512 -
4513 -/* reply from VC to component creation request */
4514 -struct mmal_msg_component_create_reply {
4515 - u32 status; /* enum mmal_msg_status - how does this differ to
4516 - * the one in the header?
4517 - */
4518 - u32 component_handle; /* VideoCore handle for component */
4519 - u32 input_num; /* Number of input ports */
4520 - u32 output_num; /* Number of output ports */
4521 - u32 clock_num; /* Number of clock ports */
4522 -};
4523 -
4524 -/* request to VC to destroy a component */
4525 -struct mmal_msg_component_destroy {
4526 - u32 component_handle;
4527 -};
4528 -
4529 -struct mmal_msg_component_destroy_reply {
4530 - u32 status; /* The component destruction status */
4531 -};
4532 -
4533 -/* request and reply to VC to enable a component */
4534 -struct mmal_msg_component_enable {
4535 - u32 component_handle;
4536 -};
4537 -
4538 -struct mmal_msg_component_enable_reply {
4539 - u32 status; /* The component enable status */
4540 -};
4541 -
4542 -/* request and reply to VC to disable a component */
4543 -struct mmal_msg_component_disable {
4544 - u32 component_handle;
4545 -};
4546 -
4547 -struct mmal_msg_component_disable_reply {
4548 - u32 status; /* The component disable status */
4549 -};
4550 -
4551 -/* request to VC to get port information */
4552 -struct mmal_msg_port_info_get {
4553 - u32 component_handle; /* component handle port is associated with */
4554 - u32 port_type; /* enum mmal_msg_port_type */
4555 - u32 index; /* port index to query */
4556 -};
4557 -
4558 -/* reply from VC to get port info request */
4559 -struct mmal_msg_port_info_get_reply {
4560 - u32 status; /* enum mmal_msg_status */
4561 - u32 component_handle; /* component handle port is associated with */
4562 - u32 port_type; /* enum mmal_msg_port_type */
4563 - u32 port_index; /* port indexed in query */
4564 - s32 found; /* unused */
4565 - u32 port_handle; /* Handle to use for this port */
4566 - struct mmal_port port;
4567 - struct mmal_es_format format; /* elementary stream format */
4568 - union mmal_es_specific_format es; /* es type specific data */
4569 - u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
4570 -};
4571 -
4572 -/* request to VC to set port information */
4573 -struct mmal_msg_port_info_set {
4574 - u32 component_handle;
4575 - u32 port_type; /* enum mmal_msg_port_type */
4576 - u32 port_index; /* port indexed in query */
4577 - struct mmal_port port;
4578 - struct mmal_es_format format;
4579 - union mmal_es_specific_format es;
4580 - u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
4581 -};
4582 -
4583 -/* reply from VC to port info set request */
4584 -struct mmal_msg_port_info_set_reply {
4585 - u32 status;
4586 - u32 component_handle; /* component handle port is associated with */
4587 - u32 port_type; /* enum mmal_msg_port_type */
4588 - u32 index; /* port indexed in query */
4589 - s32 found; /* unused */
4590 - u32 port_handle; /* Handle to use for this port */
4591 - struct mmal_port port;
4592 - struct mmal_es_format format;
4593 - union mmal_es_specific_format es;
4594 - u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
4595 -};
4596 -
4597 -/* port action requests that take a mmal_port as a parameter */
4598 -struct mmal_msg_port_action_port {
4599 - u32 component_handle;
4600 - u32 port_handle;
4601 - u32 action; /* enum mmal_msg_port_action_type */
4602 - struct mmal_port port;
4603 -};
4604 -
4605 -/* port action requests that take handles as a parameter */
4606 -struct mmal_msg_port_action_handle {
4607 - u32 component_handle;
4608 - u32 port_handle;
4609 - u32 action; /* enum mmal_msg_port_action_type */
4610 - u32 connect_component_handle;
4611 - u32 connect_port_handle;
4612 -};
4613 -
4614 -struct mmal_msg_port_action_reply {
4615 - u32 status; /* The port action operation status */
4616 -};
4617 -
4618 -/* MMAL buffer transfer */
4619 -
4620 -/* Size of space reserved in a buffer message for short messages. */
4621 -#define MMAL_VC_SHORT_DATA 128
4622 -
4623 -/* Signals that the current payload is the end of the stream of data */
4624 -#define MMAL_BUFFER_HEADER_FLAG_EOS BIT(0)
4625 -/* Signals that the start of the current payload starts a frame */
4626 -#define MMAL_BUFFER_HEADER_FLAG_FRAME_START BIT(1)
4627 -/* Signals that the end of the current payload ends a frame */
4628 -#define MMAL_BUFFER_HEADER_FLAG_FRAME_END BIT(2)
4629 -/* Signals that the current payload contains only complete frames (>1) */
4630 -#define MMAL_BUFFER_HEADER_FLAG_FRAME \
4631 - (MMAL_BUFFER_HEADER_FLAG_FRAME_START | \
4632 - MMAL_BUFFER_HEADER_FLAG_FRAME_END)
4633 -/* Signals that the current payload is a keyframe (i.e. self decodable) */
4634 -#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME BIT(3)
4635 -/*
4636 - * Signals a discontinuity in the stream of data (e.g. after a seek).
4637 - * Can be used for instance by a decoder to reset its state
4638 - */
4639 -#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY BIT(4)
4640 -/*
4641 - * Signals a buffer containing some kind of config data for the component
4642 - * (e.g. codec config data)
4643 - */
4644 -#define MMAL_BUFFER_HEADER_FLAG_CONFIG BIT(5)
4645 -/* Signals an encrypted payload */
4646 -#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED BIT(6)
4647 -/* Signals a buffer containing side information */
4648 -#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO BIT(7)
4649 -/*
4650 - * Signals a buffer which is the snapshot/postview image from a stills
4651 - * capture
4652 - */
4653 -#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT BIT(8)
4654 -/* Signals a buffer which contains data known to be corrupted */
4655 -#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED BIT(9)
4656 -/* Signals that a buffer failed to be transmitted */
4657 -#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED BIT(10)
4658 -
4659 -struct mmal_driver_buffer {
4660 - u32 magic;
4661 - u32 component_handle;
4662 - u32 port_handle;
4663 - u32 client_context;
4664 -};
4665 -
4666 -/* buffer header */
4667 -struct mmal_buffer_header {
4668 - u32 next; /* next header */
4669 - u32 priv; /* framework private data */
4670 - u32 cmd;
4671 - u32 data;
4672 - u32 alloc_size;
4673 - u32 length;
4674 - u32 offset;
4675 - u32 flags;
4676 - s64 pts;
4677 - s64 dts;
4678 - u32 type;
4679 - u32 user_data;
4680 -};
4681 -
4682 -struct mmal_buffer_header_type_specific {
4683 - union {
4684 - struct {
4685 - u32 planes;
4686 - u32 offset[4];
4687 - u32 pitch[4];
4688 - u32 flags;
4689 - } video;
4690 - } u;
4691 -};
4692 -
4693 -struct mmal_msg_buffer_from_host {
4694 - /*
4695 - *The front 32 bytes of the buffer header are copied
4696 - * back to us in the reply to allow for context. This
4697 - * area is used to store two mmal_driver_buffer structures to
4698 - * allow for multiple concurrent service users.
4699 - */
4700 - /* control data */
4701 - struct mmal_driver_buffer drvbuf;
4702 -
4703 - /* referenced control data for passthrough buffer management */
4704 - struct mmal_driver_buffer drvbuf_ref;
4705 - struct mmal_buffer_header buffer_header; /* buffer header itself */
4706 - struct mmal_buffer_header_type_specific buffer_header_type_specific;
4707 - s32 is_zero_copy;
4708 - s32 has_reference;
4709 -
4710 - /* allows short data to be xfered in control message */
4711 - u32 payload_in_message;
4712 - u8 short_data[MMAL_VC_SHORT_DATA];
4713 -};
4714 -
4715 -/* port parameter setting */
4716 -
4717 -#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
4718 -
4719 -struct mmal_msg_port_parameter_set {
4720 - u32 component_handle; /* component */
4721 - u32 port_handle; /* port */
4722 - u32 id; /* Parameter ID */
4723 - u32 size; /* Parameter size */
4724 - uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
4725 -};
4726 -
4727 -struct mmal_msg_port_parameter_set_reply {
4728 - u32 status; /* enum mmal_msg_status todo: how does this
4729 - * differ to the one in the header?
4730 - */
4731 -};
4732 -
4733 -/* port parameter getting */
4734 -
4735 -struct mmal_msg_port_parameter_get {
4736 - u32 component_handle; /* component */
4737 - u32 port_handle; /* port */
4738 - u32 id; /* Parameter ID */
4739 - u32 size; /* Parameter size */
4740 -};
4741 -
4742 -struct mmal_msg_port_parameter_get_reply {
4743 - u32 status; /* Status of mmal_port_parameter_get call */
4744 - u32 id; /* Parameter ID */
4745 - u32 size; /* Parameter size */
4746 - uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
4747 -};
4748 -
4749 -/* event messages */
4750 -#define MMAL_WORKER_EVENT_SPACE 256
4751 -
4752 -struct mmal_msg_event_to_host {
4753 - u32 client_component; /* component context */
4754 -
4755 - u32 port_type;
4756 - u32 port_num;
4757 -
4758 - u32 cmd;
4759 - u32 length;
4760 - u8 data[MMAL_WORKER_EVENT_SPACE];
4761 - u32 delayed_buffer;
4762 -};
4763 -
4764 -/* all mmal messages are serialised through this structure */
4765 -struct mmal_msg {
4766 - /* header */
4767 - struct mmal_msg_header h;
4768 - /* payload */
4769 - union {
4770 - struct mmal_msg_version version;
4771 -
4772 - struct mmal_msg_component_create component_create;
4773 - struct mmal_msg_component_create_reply component_create_reply;
4774 -
4775 - struct mmal_msg_component_destroy component_destroy;
4776 - struct mmal_msg_component_destroy_reply component_destroy_reply;
4777 -
4778 - struct mmal_msg_component_enable component_enable;
4779 - struct mmal_msg_component_enable_reply component_enable_reply;
4780 -
4781 - struct mmal_msg_component_disable component_disable;
4782 - struct mmal_msg_component_disable_reply component_disable_reply;
4783 -
4784 - struct mmal_msg_port_info_get port_info_get;
4785 - struct mmal_msg_port_info_get_reply port_info_get_reply;
4786 -
4787 - struct mmal_msg_port_info_set port_info_set;
4788 - struct mmal_msg_port_info_set_reply port_info_set_reply;
4789 -
4790 - struct mmal_msg_port_action_port port_action_port;
4791 - struct mmal_msg_port_action_handle port_action_handle;
4792 - struct mmal_msg_port_action_reply port_action_reply;
4793 -
4794 - struct mmal_msg_buffer_from_host buffer_from_host;
4795 -
4796 - struct mmal_msg_port_parameter_set port_parameter_set;
4797 - struct mmal_msg_port_parameter_set_reply
4798 - port_parameter_set_reply;
4799 - struct mmal_msg_port_parameter_get
4800 - port_parameter_get;
4801 - struct mmal_msg_port_parameter_get_reply
4802 - port_parameter_get_reply;
4803 -
4804 - struct mmal_msg_event_to_host event_to_host;
4805 -
4806 - u8 payload[MMAL_MSG_MAX_PAYLOAD];
4807 - } u;
4808 -};
4809 -#endif
4810 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-parameters.h
4811 +++ /dev/null
4812 @@ -1,755 +0,0 @@
4813 -/* SPDX-License-Identifier: GPL-2.0 */
4814 -/*
4815 - * Broadcom BM2835 V4L2 driver
4816 - *
4817 - * Copyright © 2013 Raspberry Pi (Trading) Ltd.
4818 - *
4819 - * Authors: Vincent Sanders @ Collabora
4820 - * Dave Stevenson @ Broadcom
4821 - * (now dave.stevenson@raspberrypi.org)
4822 - * Simon Mellor @ Broadcom
4823 - * Luke Diamand @ Broadcom
4824 - */
4825 -
4826 -/* common parameters */
4827 -
4828 -/** @name Parameter groups
4829 - * Parameters are divided into groups, and then allocated sequentially within
4830 - * a group using an enum.
4831 - * @{
4832 - */
4833 -
4834 -#ifndef MMAL_PARAMETERS_H
4835 -#define MMAL_PARAMETERS_H
4836 -
4837 -/** Common parameter ID group, used with many types of component. */
4838 -#define MMAL_PARAMETER_GROUP_COMMON (0 << 16)
4839 -/** Camera-specific parameter ID group. */
4840 -#define MMAL_PARAMETER_GROUP_CAMERA (1 << 16)
4841 -/** Video-specific parameter ID group. */
4842 -#define MMAL_PARAMETER_GROUP_VIDEO (2 << 16)
4843 -/** Audio-specific parameter ID group. */
4844 -#define MMAL_PARAMETER_GROUP_AUDIO (3 << 16)
4845 -/** Clock-specific parameter ID group. */
4846 -#define MMAL_PARAMETER_GROUP_CLOCK (4 << 16)
4847 -/** Miracast-specific parameter ID group. */
4848 -#define MMAL_PARAMETER_GROUP_MIRACAST (5 << 16)
4849 -
4850 -/* Common parameters */
4851 -enum mmal_parameter_common_type {
4852 - /**< Never a valid parameter ID */
4853 - MMAL_PARAMETER_UNUSED = MMAL_PARAMETER_GROUP_COMMON,
4854 -
4855 - /**< MMAL_PARAMETER_ENCODING_T */
4856 - MMAL_PARAMETER_SUPPORTED_ENCODINGS,
4857 - /**< MMAL_PARAMETER_URI_T */
4858 - MMAL_PARAMETER_URI,
4859 - /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
4860 - MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
4861 - /** MMAL_PARAMETER_BOOLEAN_T */
4862 - MMAL_PARAMETER_ZERO_COPY,
4863 - /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
4864 - MMAL_PARAMETER_BUFFER_REQUIREMENTS,
4865 - /**< MMAL_PARAMETER_STATISTICS_T */
4866 - MMAL_PARAMETER_STATISTICS,
4867 - /**< MMAL_PARAMETER_CORE_STATISTICS_T */
4868 - MMAL_PARAMETER_CORE_STATISTICS,
4869 - /**< MMAL_PARAMETER_MEM_USAGE_T */
4870 - MMAL_PARAMETER_MEM_USAGE,
4871 - /**< MMAL_PARAMETER_UINT32_T */
4872 - MMAL_PARAMETER_BUFFER_FLAG_FILTER,
4873 - /**< MMAL_PARAMETER_SEEK_T */
4874 - MMAL_PARAMETER_SEEK,
4875 - /**< MMAL_PARAMETER_BOOLEAN_T */
4876 - MMAL_PARAMETER_POWERMON_ENABLE,
4877 - /**< MMAL_PARAMETER_LOGGING_T */
4878 - MMAL_PARAMETER_LOGGING,
4879 - /**< MMAL_PARAMETER_UINT64_T */
4880 - MMAL_PARAMETER_SYSTEM_TIME,
4881 - /**< MMAL_PARAMETER_BOOLEAN_T */
4882 - MMAL_PARAMETER_NO_IMAGE_PADDING,
4883 -};
4884 -
4885 -/* camera parameters */
4886 -
4887 -enum mmal_parameter_camera_type {
4888 - /* 0 */
4889 - /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
4890 - MMAL_PARAMETER_THUMBNAIL_CONFIGURATION =
4891 - MMAL_PARAMETER_GROUP_CAMERA,
4892 - /**< Unused? */
4893 - MMAL_PARAMETER_CAPTURE_QUALITY,
4894 - /**< @ref MMAL_PARAMETER_INT32_T */
4895 - MMAL_PARAMETER_ROTATION,
4896 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
4897 - MMAL_PARAMETER_EXIF_DISABLE,
4898 - /**< @ref MMAL_PARAMETER_EXIF_T */
4899 - MMAL_PARAMETER_EXIF,
4900 - /**< @ref MMAL_PARAM_AWBMODE_T */
4901 - MMAL_PARAMETER_AWB_MODE,
4902 - /**< @ref MMAL_PARAMETER_IMAGEFX_T */
4903 - MMAL_PARAMETER_IMAGE_EFFECT,
4904 - /**< @ref MMAL_PARAMETER_COLOURFX_T */
4905 - MMAL_PARAMETER_COLOUR_EFFECT,
4906 - /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
4907 - MMAL_PARAMETER_FLICKER_AVOID,
4908 - /**< @ref MMAL_PARAMETER_FLASH_T */
4909 - MMAL_PARAMETER_FLASH,
4910 - /**< @ref MMAL_PARAMETER_REDEYE_T */
4911 - MMAL_PARAMETER_REDEYE,
4912 - /**< @ref MMAL_PARAMETER_FOCUS_T */
4913 - MMAL_PARAMETER_FOCUS,
4914 - /**< Unused? */
4915 - MMAL_PARAMETER_FOCAL_LENGTHS,
4916 - /**< @ref MMAL_PARAMETER_INT32_T */
4917 - MMAL_PARAMETER_EXPOSURE_COMP,
4918 - /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
4919 - MMAL_PARAMETER_ZOOM,
4920 - /**< @ref MMAL_PARAMETER_MIRROR_T */
4921 - MMAL_PARAMETER_MIRROR,
4922 -
4923 - /* 0x10 */
4924 - /**< @ref MMAL_PARAMETER_UINT32_T */
4925 - MMAL_PARAMETER_CAMERA_NUM,
4926 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
4927 - MMAL_PARAMETER_CAPTURE,
4928 - /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
4929 - MMAL_PARAMETER_EXPOSURE_MODE,
4930 - /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
4931 - MMAL_PARAMETER_EXP_METERING_MODE,
4932 - /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
4933 - MMAL_PARAMETER_FOCUS_STATUS,
4934 - /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
4935 - MMAL_PARAMETER_CAMERA_CONFIG,
4936 - /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
4937 - MMAL_PARAMETER_CAPTURE_STATUS,
4938 - /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
4939 - MMAL_PARAMETER_FACE_TRACK,
4940 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
4941 - MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS,
4942 - /**< @ref MMAL_PARAMETER_UINT32_T */
4943 - MMAL_PARAMETER_JPEG_Q_FACTOR,
4944 - /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
4945 - MMAL_PARAMETER_FRAME_RATE,
4946 - /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
4947 - MMAL_PARAMETER_USE_STC,
4948 - /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
4949 - MMAL_PARAMETER_CAMERA_INFO,
4950 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
4951 - MMAL_PARAMETER_VIDEO_STABILISATION,
4952 - /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
4953 - MMAL_PARAMETER_FACE_TRACK_RESULTS,
4954 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
4955 - MMAL_PARAMETER_ENABLE_RAW_CAPTURE,
4956 -
4957 - /* 0x20 */
4958 - /**< @ref MMAL_PARAMETER_URI_T */
4959 - MMAL_PARAMETER_DPF_FILE,
4960 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
4961 - MMAL_PARAMETER_ENABLE_DPF_FILE,
4962 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
4963 - MMAL_PARAMETER_DPF_FAIL_IS_FATAL,
4964 - /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
4965 - MMAL_PARAMETER_CAPTURE_MODE,
4966 - /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
4967 - MMAL_PARAMETER_FOCUS_REGIONS,
4968 - /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
4969 - MMAL_PARAMETER_INPUT_CROP,
4970 - /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
4971 - MMAL_PARAMETER_SENSOR_INFORMATION,
4972 - /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
4973 - MMAL_PARAMETER_FLASH_SELECT,
4974 - /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
4975 - MMAL_PARAMETER_FIELD_OF_VIEW,
4976 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
4977 - MMAL_PARAMETER_HIGH_DYNAMIC_RANGE,
4978 - /**< @ref MMAL_PARAMETER_DRC_T */
4979 - MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION,
4980 - /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
4981 - MMAL_PARAMETER_ALGORITHM_CONTROL,
4982 - /**< @ref MMAL_PARAMETER_RATIONAL_T */
4983 - MMAL_PARAMETER_SHARPNESS,
4984 - /**< @ref MMAL_PARAMETER_RATIONAL_T */
4985 - MMAL_PARAMETER_CONTRAST,
4986 - /**< @ref MMAL_PARAMETER_RATIONAL_T */
4987 - MMAL_PARAMETER_BRIGHTNESS,
4988 - /**< @ref MMAL_PARAMETER_RATIONAL_T */
4989 - MMAL_PARAMETER_SATURATION,
4990 -
4991 - /* 0x30 */
4992 - /**< @ref MMAL_PARAMETER_UINT32_T */
4993 - MMAL_PARAMETER_ISO,
4994 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
4995 - MMAL_PARAMETER_ANTISHAKE,
4996 - /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
4997 - MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
4998 - /** @ref MMAL_PARAMETER_BOOLEAN_T */
4999 - MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
5000 - /** @ref MMAL_PARAMETER_UINT32_T */
5001 - MMAL_PARAMETER_CAMERA_MIN_ISO,
5002 - /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
5003 - MMAL_PARAMETER_CAMERA_USE_CASE,
5004 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
5005 - MMAL_PARAMETER_CAPTURE_STATS_PASS,
5006 - /** @ref MMAL_PARAMETER_UINT32_T */
5007 - MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
5008 - /** @ref MMAL_PARAMETER_BOOLEAN_T */
5009 - MMAL_PARAMETER_ENABLE_REGISTER_FILE,
5010 - /** @ref MMAL_PARAMETER_BOOLEAN_T */
5011 - MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
5012 - /** @ref MMAL_PARAMETER_CONFIGFILE_T */
5013 - MMAL_PARAMETER_CONFIGFILE_REGISTERS,
5014 - /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
5015 - MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
5016 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
5017 - MMAL_PARAMETER_JPEG_ATTACH_LOG,
5018 - /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
5019 - MMAL_PARAMETER_ZERO_SHUTTER_LAG,
5020 - /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
5021 - MMAL_PARAMETER_FPS_RANGE,
5022 - /**< @ref MMAL_PARAMETER_INT32_T */
5023 - MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP,
5024 -
5025 - /* 0x40 */
5026 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
5027 - MMAL_PARAMETER_SW_SHARPEN_DISABLE,
5028 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
5029 - MMAL_PARAMETER_FLASH_REQUIRED,
5030 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
5031 - MMAL_PARAMETER_SW_SATURATION_DISABLE,
5032 - /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
5033 - MMAL_PARAMETER_SHUTTER_SPEED,
5034 - /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */
5035 - MMAL_PARAMETER_CUSTOM_AWB_GAINS,
5036 -};
5037 -
5038 -struct mmal_parameter_rational {
5039 - s32 num; /**< Numerator */
5040 - s32 den; /**< Denominator */
5041 -};
5042 -
5043 -enum mmal_parameter_camera_config_timestamp_mode {
5044 - MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
5045 - MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
5046 - * for the frame timestamp
5047 - */
5048 - MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
5049 - * but subtract the
5050 - * timestamp of the first
5051 - * frame sent to give a
5052 - * zero based timestamp.
5053 - */
5054 -};
5055 -
5056 -struct mmal_parameter_fps_range {
5057 - /**< Low end of the permitted framerate range */
5058 - struct mmal_parameter_rational fps_low;
5059 - /**< High end of the permitted framerate range */
5060 - struct mmal_parameter_rational fps_high;
5061 -};
5062 -
5063 -/* camera configuration parameter */
5064 -struct mmal_parameter_camera_config {
5065 - /* Parameters for setting up the image pools */
5066 - u32 max_stills_w; /* Max size of stills capture */
5067 - u32 max_stills_h;
5068 - u32 stills_yuv422; /* Allow YUV422 stills capture */
5069 - u32 one_shot_stills; /* Continuous or one shot stills captures. */
5070 -
5071 - u32 max_preview_video_w; /* Max size of the preview or video
5072 - * capture frames
5073 - */
5074 - u32 max_preview_video_h;
5075 - u32 num_preview_video_frames;
5076 -
5077 - /** Sets the height of the circular buffer for stills capture. */
5078 - u32 stills_capture_circular_buffer_height;
5079 -
5080 - /** Allows preview/encode to resume as fast as possible after the stills
5081 - * input frame has been received, and then processes the still frame in
5082 - * the background whilst preview/encode has resumed.
5083 - * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
5084 - */
5085 - u32 fast_preview_resume;
5086 -
5087 - /** Selects algorithm for timestamping frames if
5088 - * there is no clock component connected.
5089 - * enum mmal_parameter_camera_config_timestamp_mode
5090 - */
5091 - s32 use_stc_timestamp;
5092 -};
5093 -
5094 -enum mmal_parameter_exposuremode {
5095 - MMAL_PARAM_EXPOSUREMODE_OFF,
5096 - MMAL_PARAM_EXPOSUREMODE_AUTO,
5097 - MMAL_PARAM_EXPOSUREMODE_NIGHT,
5098 - MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
5099 - MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
5100 - MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
5101 - MMAL_PARAM_EXPOSUREMODE_SPORTS,
5102 - MMAL_PARAM_EXPOSUREMODE_SNOW,
5103 - MMAL_PARAM_EXPOSUREMODE_BEACH,
5104 - MMAL_PARAM_EXPOSUREMODE_VERYLONG,
5105 - MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
5106 - MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
5107 - MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
5108 -};
5109 -
5110 -enum mmal_parameter_exposuremeteringmode {
5111 - MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
5112 - MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
5113 - MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
5114 - MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
5115 -};
5116 -
5117 -enum mmal_parameter_awbmode {
5118 - MMAL_PARAM_AWBMODE_OFF,
5119 - MMAL_PARAM_AWBMODE_AUTO,
5120 - MMAL_PARAM_AWBMODE_SUNLIGHT,
5121 - MMAL_PARAM_AWBMODE_CLOUDY,
5122 - MMAL_PARAM_AWBMODE_SHADE,
5123 - MMAL_PARAM_AWBMODE_TUNGSTEN,
5124 - MMAL_PARAM_AWBMODE_FLUORESCENT,
5125 - MMAL_PARAM_AWBMODE_INCANDESCENT,
5126 - MMAL_PARAM_AWBMODE_FLASH,
5127 - MMAL_PARAM_AWBMODE_HORIZON,
5128 -};
5129 -
5130 -enum mmal_parameter_imagefx {
5131 - MMAL_PARAM_IMAGEFX_NONE,
5132 - MMAL_PARAM_IMAGEFX_NEGATIVE,
5133 - MMAL_PARAM_IMAGEFX_SOLARIZE,
5134 - MMAL_PARAM_IMAGEFX_POSTERIZE,
5135 - MMAL_PARAM_IMAGEFX_WHITEBOARD,
5136 - MMAL_PARAM_IMAGEFX_BLACKBOARD,
5137 - MMAL_PARAM_IMAGEFX_SKETCH,
5138 - MMAL_PARAM_IMAGEFX_DENOISE,
5139 - MMAL_PARAM_IMAGEFX_EMBOSS,
5140 - MMAL_PARAM_IMAGEFX_OILPAINT,
5141 - MMAL_PARAM_IMAGEFX_HATCH,
5142 - MMAL_PARAM_IMAGEFX_GPEN,
5143 - MMAL_PARAM_IMAGEFX_PASTEL,
5144 - MMAL_PARAM_IMAGEFX_WATERCOLOUR,
5145 - MMAL_PARAM_IMAGEFX_FILM,
5146 - MMAL_PARAM_IMAGEFX_BLUR,
5147 - MMAL_PARAM_IMAGEFX_SATURATION,
5148 - MMAL_PARAM_IMAGEFX_COLOURSWAP,
5149 - MMAL_PARAM_IMAGEFX_WASHEDOUT,
5150 - MMAL_PARAM_IMAGEFX_POSTERISE,
5151 - MMAL_PARAM_IMAGEFX_COLOURPOINT,
5152 - MMAL_PARAM_IMAGEFX_COLOURBALANCE,
5153 - MMAL_PARAM_IMAGEFX_CARTOON,
5154 -};
5155 -
5156 -enum MMAL_PARAM_FLICKERAVOID_T {
5157 - MMAL_PARAM_FLICKERAVOID_OFF,
5158 - MMAL_PARAM_FLICKERAVOID_AUTO,
5159 - MMAL_PARAM_FLICKERAVOID_50HZ,
5160 - MMAL_PARAM_FLICKERAVOID_60HZ,
5161 - MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
5162 -};
5163 -
5164 -struct mmal_parameter_awbgains {
5165 - struct mmal_parameter_rational r_gain; /**< Red gain */
5166 - struct mmal_parameter_rational b_gain; /**< Blue gain */
5167 -};
5168 -
5169 -/** Manner of video rate control */
5170 -enum mmal_parameter_rate_control_mode {
5171 - MMAL_VIDEO_RATECONTROL_DEFAULT,
5172 - MMAL_VIDEO_RATECONTROL_VARIABLE,
5173 - MMAL_VIDEO_RATECONTROL_CONSTANT,
5174 - MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
5175 - MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
5176 -};
5177 -
5178 -enum mmal_video_profile {
5179 - MMAL_VIDEO_PROFILE_H263_BASELINE,
5180 - MMAL_VIDEO_PROFILE_H263_H320CODING,
5181 - MMAL_VIDEO_PROFILE_H263_BACKWARDCOMPATIBLE,
5182 - MMAL_VIDEO_PROFILE_H263_ISWV2,
5183 - MMAL_VIDEO_PROFILE_H263_ISWV3,
5184 - MMAL_VIDEO_PROFILE_H263_HIGHCOMPRESSION,
5185 - MMAL_VIDEO_PROFILE_H263_INTERNET,
5186 - MMAL_VIDEO_PROFILE_H263_INTERLACE,
5187 - MMAL_VIDEO_PROFILE_H263_HIGHLATENCY,
5188 - MMAL_VIDEO_PROFILE_MP4V_SIMPLE,
5189 - MMAL_VIDEO_PROFILE_MP4V_SIMPLESCALABLE,
5190 - MMAL_VIDEO_PROFILE_MP4V_CORE,
5191 - MMAL_VIDEO_PROFILE_MP4V_MAIN,
5192 - MMAL_VIDEO_PROFILE_MP4V_NBIT,
5193 - MMAL_VIDEO_PROFILE_MP4V_SCALABLETEXTURE,
5194 - MMAL_VIDEO_PROFILE_MP4V_SIMPLEFACE,
5195 - MMAL_VIDEO_PROFILE_MP4V_SIMPLEFBA,
5196 - MMAL_VIDEO_PROFILE_MP4V_BASICANIMATED,
5197 - MMAL_VIDEO_PROFILE_MP4V_HYBRID,
5198 - MMAL_VIDEO_PROFILE_MP4V_ADVANCEDREALTIME,
5199 - MMAL_VIDEO_PROFILE_MP4V_CORESCALABLE,
5200 - MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCODING,
5201 - MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCORE,
5202 - MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSCALABLE,
5203 - MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSIMPLE,
5204 - MMAL_VIDEO_PROFILE_H264_BASELINE,
5205 - MMAL_VIDEO_PROFILE_H264_MAIN,
5206 - MMAL_VIDEO_PROFILE_H264_EXTENDED,
5207 - MMAL_VIDEO_PROFILE_H264_HIGH,
5208 - MMAL_VIDEO_PROFILE_H264_HIGH10,
5209 - MMAL_VIDEO_PROFILE_H264_HIGH422,
5210 - MMAL_VIDEO_PROFILE_H264_HIGH444,
5211 - MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE,
5212 - MMAL_VIDEO_PROFILE_DUMMY = 0x7FFFFFFF
5213 -};
5214 -
5215 -enum mmal_video_level {
5216 - MMAL_VIDEO_LEVEL_H263_10,
5217 - MMAL_VIDEO_LEVEL_H263_20,
5218 - MMAL_VIDEO_LEVEL_H263_30,
5219 - MMAL_VIDEO_LEVEL_H263_40,
5220 - MMAL_VIDEO_LEVEL_H263_45,
5221 - MMAL_VIDEO_LEVEL_H263_50,
5222 - MMAL_VIDEO_LEVEL_H263_60,
5223 - MMAL_VIDEO_LEVEL_H263_70,
5224 - MMAL_VIDEO_LEVEL_MP4V_0,
5225 - MMAL_VIDEO_LEVEL_MP4V_0b,
5226 - MMAL_VIDEO_LEVEL_MP4V_1,
5227 - MMAL_VIDEO_LEVEL_MP4V_2,
5228 - MMAL_VIDEO_LEVEL_MP4V_3,
5229 - MMAL_VIDEO_LEVEL_MP4V_4,
5230 - MMAL_VIDEO_LEVEL_MP4V_4a,
5231 - MMAL_VIDEO_LEVEL_MP4V_5,
5232 - MMAL_VIDEO_LEVEL_MP4V_6,
5233 - MMAL_VIDEO_LEVEL_H264_1,
5234 - MMAL_VIDEO_LEVEL_H264_1b,
5235 - MMAL_VIDEO_LEVEL_H264_11,
5236 - MMAL_VIDEO_LEVEL_H264_12,
5237 - MMAL_VIDEO_LEVEL_H264_13,
5238 - MMAL_VIDEO_LEVEL_H264_2,
5239 - MMAL_VIDEO_LEVEL_H264_21,
5240 - MMAL_VIDEO_LEVEL_H264_22,
5241 - MMAL_VIDEO_LEVEL_H264_3,
5242 - MMAL_VIDEO_LEVEL_H264_31,
5243 - MMAL_VIDEO_LEVEL_H264_32,
5244 - MMAL_VIDEO_LEVEL_H264_4,
5245 - MMAL_VIDEO_LEVEL_H264_41,
5246 - MMAL_VIDEO_LEVEL_H264_42,
5247 - MMAL_VIDEO_LEVEL_H264_5,
5248 - MMAL_VIDEO_LEVEL_H264_51,
5249 - MMAL_VIDEO_LEVEL_DUMMY = 0x7FFFFFFF
5250 -};
5251 -
5252 -struct mmal_parameter_video_profile {
5253 - enum mmal_video_profile profile;
5254 - enum mmal_video_level level;
5255 -};
5256 -
5257 -/* video parameters */
5258 -
5259 -enum mmal_parameter_video_type {
5260 - /** @ref MMAL_DISPLAYREGION_T */
5261 - MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
5262 -
5263 - /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
5264 - MMAL_PARAMETER_SUPPORTED_PROFILES,
5265 -
5266 - /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
5267 - MMAL_PARAMETER_PROFILE,
5268 -
5269 - /** @ref MMAL_PARAMETER_UINT32_T */
5270 - MMAL_PARAMETER_INTRAPERIOD,
5271 -
5272 - /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
5273 - MMAL_PARAMETER_RATECONTROL,
5274 -
5275 - /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
5276 - MMAL_PARAMETER_NALUNITFORMAT,
5277 -
5278 - /** @ref MMAL_PARAMETER_BOOLEAN_T */
5279 - MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
5280 -
5281 - /** @ref MMAL_PARAMETER_UINT32_T.
5282 - * Setting the value to zero resets to the default (one slice per
5283 - * frame).
5284 - */
5285 - MMAL_PARAMETER_MB_ROWS_PER_SLICE,
5286 -
5287 - /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
5288 - MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
5289 -
5290 - /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
5291 - MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
5292 -
5293 - /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
5294 - MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
5295 -
5296 - /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
5297 - MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
5298 - /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
5299 - MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
5300 -
5301 - /** @ref MMAL_PARAMETER_BOOLEAN_T. */
5302 - MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
5303 -
5304 - /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
5305 - MMAL_PARAMETER_VIDEO_BIT_RATE,
5306 -
5307 - /** @ref MMAL_PARAMETER_FRAME_RATE_T */
5308 - MMAL_PARAMETER_VIDEO_FRAME_RATE,
5309 -
5310 - /** @ref MMAL_PARAMETER_UINT32_T. */
5311 - MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
5312 -
5313 - /** @ref MMAL_PARAMETER_UINT32_T. */
5314 - MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
5315 -
5316 - /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
5317 - MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
5318 -
5319 - MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
5320 - /** @ref MMAL_PARAMETER_UINT32_T.
5321 - * Changing this parameter from the default can reduce frame rate
5322 - * because image buffers need to be re-pitched.
5323 - */
5324 - MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
5325 -
5326 - /** @ref MMAL_PARAMETER_UINT32_T.
5327 - * Changing this parameter from the default can reduce frame rate
5328 - * because image buffers need to be re-pitched.
5329 - */
5330 - MMAL_PARAMETER_VIDEO_ALIGN_VERT,
5331 -
5332 - /** @ref MMAL_PARAMETER_BOOLEAN_T. */
5333 - MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
5334 -
5335 - /** @ref MMAL_PARAMETER_UINT32_T. */
5336 - MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
5337 -
5338 - /**< @ref MMAL_PARAMETER_UINT32_T. */
5339 - MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
5340 -
5341 - /**< @ref MMAL_PARAMETER_UINT32_T. */
5342 - MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
5343 -
5344 - /** @ref MMAL_PARAMETER_UINT32_T */
5345 - MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
5346 -
5347 - /** @ref MMAL_PARAMETER_UINT32_T. */
5348 - MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
5349 -
5350 - /* H264 specific parameters */
5351 -
5352 - /** @ref MMAL_PARAMETER_BOOLEAN_T. */
5353 - MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
5354 -
5355 - /** @ref MMAL_PARAMETER_BOOLEAN_T. */
5356 - MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
5357 -
5358 - /** @ref MMAL_PARAMETER_BOOLEAN_T. */
5359 - MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
5360 -
5361 - /** @ref MMAL_PARAMETER_UINT32_T. */
5362 - MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
5363 -
5364 - /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
5365 - MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
5366 -
5367 - /** @ref MMAL_PARAMETER_BOOLEAN_T */
5368 - MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
5369 -
5370 - /** @ref MMAL_PARAMETER_BOOLEAN_T */
5371 - MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
5372 -
5373 - /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
5374 - MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
5375 -
5376 - /** @ref MMAL_PARAMETER_BOOLEAN_T */
5377 - MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
5378 -
5379 - /** @ref MMAL_PARAMETER_BOOLEAN_T */
5380 - MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
5381 -
5382 - /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
5383 - MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
5384 -
5385 - /** @ref MMAL_PARAMETER_BYTES_T */
5386 - MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
5387 -
5388 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
5389 - MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
5390 -
5391 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
5392 - MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
5393 -
5394 - /**< @ref MMAL_PARAMETER_BOOLEAN_T */
5395 - MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
5396 -};
5397 -
5398 -/** Valid mirror modes */
5399 -enum mmal_parameter_mirror {
5400 - MMAL_PARAM_MIRROR_NONE,
5401 - MMAL_PARAM_MIRROR_VERTICAL,
5402 - MMAL_PARAM_MIRROR_HORIZONTAL,
5403 - MMAL_PARAM_MIRROR_BOTH,
5404 -};
5405 -
5406 -enum mmal_parameter_displaytransform {
5407 - MMAL_DISPLAY_ROT0 = 0,
5408 - MMAL_DISPLAY_MIRROR_ROT0 = 1,
5409 - MMAL_DISPLAY_MIRROR_ROT180 = 2,
5410 - MMAL_DISPLAY_ROT180 = 3,
5411 - MMAL_DISPLAY_MIRROR_ROT90 = 4,
5412 - MMAL_DISPLAY_ROT270 = 5,
5413 - MMAL_DISPLAY_ROT90 = 6,
5414 - MMAL_DISPLAY_MIRROR_ROT270 = 7,
5415 -};
5416 -
5417 -enum mmal_parameter_displaymode {
5418 - MMAL_DISPLAY_MODE_FILL = 0,
5419 - MMAL_DISPLAY_MODE_LETTERBOX = 1,
5420 -};
5421 -
5422 -enum mmal_parameter_displayset {
5423 - MMAL_DISPLAY_SET_NONE = 0,
5424 - MMAL_DISPLAY_SET_NUM = 1,
5425 - MMAL_DISPLAY_SET_FULLSCREEN = 2,
5426 - MMAL_DISPLAY_SET_TRANSFORM = 4,
5427 - MMAL_DISPLAY_SET_DEST_RECT = 8,
5428 - MMAL_DISPLAY_SET_SRC_RECT = 0x10,
5429 - MMAL_DISPLAY_SET_MODE = 0x20,
5430 - MMAL_DISPLAY_SET_PIXEL = 0x40,
5431 - MMAL_DISPLAY_SET_NOASPECT = 0x80,
5432 - MMAL_DISPLAY_SET_LAYER = 0x100,
5433 - MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
5434 - MMAL_DISPLAY_SET_ALPHA = 0x400,
5435 -};
5436 -
5437 -/* rectangle, used lots so it gets its own struct */
5438 -struct vchiq_mmal_rect {
5439 - s32 x;
5440 - s32 y;
5441 - s32 width;
5442 - s32 height;
5443 -};
5444 -
5445 -struct mmal_parameter_displayregion {
5446 - /** Bitfield that indicates which fields are set and should be
5447 - * used. All other fields will maintain their current value.
5448 - * \ref MMAL_DISPLAYSET_T defines the bits that can be
5449 - * combined.
5450 - */
5451 - u32 set;
5452 -
5453 - /** Describes the display output device, with 0 typically
5454 - * being a directly connected LCD display. The actual values
5455 - * will depend on the hardware. Code using hard-wired numbers
5456 - * (e.g. 2) is certain to fail.
5457 - */
5458 -
5459 - u32 display_num;
5460 - /** Indicates that we are using the full device screen area,
5461 - * rather than a window of the display. If zero, then
5462 - * dest_rect is used to specify a region of the display to
5463 - * use.
5464 - */
5465 -
5466 - s32 fullscreen;
5467 - /** Indicates any rotation or flipping used to map frames onto
5468 - * the natural display orientation.
5469 - */
5470 - u32 transform; /* enum mmal_parameter_displaytransform */
5471 -
5472 - /** Where to display the frame within the screen, if
5473 - * fullscreen is zero.
5474 - */
5475 - struct vchiq_mmal_rect dest_rect;
5476 -
5477 - /** Indicates which area of the frame to display. If all
5478 - * values are zero, the whole frame will be used.
5479 - */
5480 - struct vchiq_mmal_rect src_rect;
5481 -
5482 - /** If set to non-zero, indicates that any display scaling
5483 - * should disregard the aspect ratio of the frame region being
5484 - * displayed.
5485 - */
5486 - s32 noaspect;
5487 -
5488 - /** Indicates how the image should be scaled to fit the
5489 - * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
5490 - * that the image should fill the screen by potentially
5491 - * cropping the frames. Setting \code mode \endcode to \code
5492 - * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
5493 - * source region should be displayed and black bars added if
5494 - * necessary.
5495 - */
5496 - u32 mode; /* enum mmal_parameter_displaymode */
5497 -
5498 - /** If non-zero, defines the width of a source pixel relative
5499 - * to \code pixel_y \endcode. If zero, then pixels default to
5500 - * being square.
5501 - */
5502 - u32 pixel_x;
5503 -
5504 - /** If non-zero, defines the height of a source pixel relative
5505 - * to \code pixel_x \endcode. If zero, then pixels default to
5506 - * being square.
5507 - */
5508 - u32 pixel_y;
5509 -
5510 - /** Sets the relative depth of the images, with greater values
5511 - * being in front of smaller values.
5512 - */
5513 - u32 layer;
5514 -
5515 - /** Set to non-zero to ensure copy protection is used on
5516 - * output.
5517 - */
5518 - s32 copyprotect_required;
5519 -
5520 - /** Level of opacity of the layer, where zero is fully
5521 - * transparent and 255 is fully opaque.
5522 - */
5523 - u32 alpha;
5524 -};
5525 -
5526 -#define MMAL_MAX_IMAGEFX_PARAMETERS 5
5527 -
5528 -struct mmal_parameter_imagefx_parameters {
5529 - enum mmal_parameter_imagefx effect;
5530 - u32 num_effect_params;
5531 - u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
5532 -};
5533 -
5534 -#define MMAL_PARAMETER_CAMERA_INFO_MAX_CAMERAS 4
5535 -#define MMAL_PARAMETER_CAMERA_INFO_MAX_FLASHES 2
5536 -#define MMAL_PARAMETER_CAMERA_INFO_MAX_STR_LEN 16
5537 -
5538 -struct mmal_parameter_camera_info_camera_t {
5539 - u32 port_id;
5540 - u32 max_width;
5541 - u32 max_height;
5542 - u32 lens_present;
5543 - u8 camera_name[MMAL_PARAMETER_CAMERA_INFO_MAX_STR_LEN];
5544 -};
5545 -
5546 -enum mmal_parameter_camera_info_flash_type_t {
5547 - /* Make values explicit to ensure they match values in config ini */
5548 - MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_XENON = 0,
5549 - MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_LED = 1,
5550 - MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_OTHER = 2,
5551 - MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_MAX = 0x7FFFFFFF
5552 -};
5553 -
5554 -struct mmal_parameter_camera_info_flash_t {
5555 - enum mmal_parameter_camera_info_flash_type_t flash_type;
5556 -};
5557 -
5558 -struct mmal_parameter_camera_info_t {
5559 - u32 num_cameras;
5560 - u32 num_flashes;
5561 - struct mmal_parameter_camera_info_camera_t
5562 - cameras[MMAL_PARAMETER_CAMERA_INFO_MAX_CAMERAS];
5563 - struct mmal_parameter_camera_info_flash_t
5564 - flashes[MMAL_PARAMETER_CAMERA_INFO_MAX_FLASHES];
5565 -};
5566 -
5567 -#endif
5568 --- a/drivers/staging/vc04_services/bcm2835-camera/mmal-vchiq.h
5569 +++ /dev/null
5570 @@ -1,166 +0,0 @@
5571 -/* SPDX-License-Identifier: GPL-2.0 */
5572 -/*
5573 - * Broadcom BM2835 V4L2 driver
5574 - *
5575 - * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5576 - *
5577 - * Authors: Vincent Sanders @ Collabora
5578 - * Dave Stevenson @ Broadcom
5579 - * (now dave.stevenson@raspberrypi.org)
5580 - * Simon Mellor @ Broadcom
5581 - * Luke Diamand @ Broadcom
5582 - *
5583 - * MMAL interface to VCHIQ message passing
5584 - */
5585 -
5586 -#ifndef MMAL_VCHIQ_H
5587 -#define MMAL_VCHIQ_H
5588 -
5589 -#include "mmal-msg-format.h"
5590 -
5591 -#define MAX_PORT_COUNT 4
5592 -
5593 -/* Maximum size of the format extradata. */
5594 -#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
5595 -
5596 -struct vchiq_mmal_instance;
5597 -
5598 -enum vchiq_mmal_es_type {
5599 - MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
5600 - MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
5601 - MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
5602 - MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
5603 - MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
5604 -};
5605 -
5606 -struct vchiq_mmal_port_buffer {
5607 - unsigned int num; /* number of buffers */
5608 - u32 size; /* size of buffers */
5609 - u32 alignment; /* alignment of buffers */
5610 -};
5611 -
5612 -struct vchiq_mmal_port;
5613 -
5614 -typedef void (*vchiq_mmal_buffer_cb)(
5615 - struct vchiq_mmal_instance *instance,
5616 - struct vchiq_mmal_port *port,
5617 - int status, struct mmal_buffer *buffer,
5618 - unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
5619 -
5620 -struct vchiq_mmal_port {
5621 - bool enabled;
5622 - u32 handle;
5623 - u32 type; /* port type, cached to use on port info set */
5624 - u32 index; /* port index, cached to use on port info set */
5625 -
5626 - /* component port belongs to, allows simple deref */
5627 - struct vchiq_mmal_component *component;
5628 -
5629 - struct vchiq_mmal_port *connected; /* port conencted to */
5630 -
5631 - /* buffer info */
5632 - struct vchiq_mmal_port_buffer minimum_buffer;
5633 - struct vchiq_mmal_port_buffer recommended_buffer;
5634 - struct vchiq_mmal_port_buffer current_buffer;
5635 -
5636 - /* stream format */
5637 - struct mmal_es_format_local format;
5638 - /* elementary stream format */
5639 - union mmal_es_specific_format es;
5640 -
5641 - /* data buffers to fill */
5642 - struct list_head buffers;
5643 - /* lock to serialise adding and removing buffers from list */
5644 - spinlock_t slock;
5645 -
5646 - /* Count of buffers the VPU has yet to return */
5647 - atomic_t buffers_with_vpu;
5648 - /* callback on buffer completion */
5649 - vchiq_mmal_buffer_cb buffer_cb;
5650 - /* callback context */
5651 - void *cb_ctx;
5652 -};
5653 -
5654 -struct vchiq_mmal_component {
5655 - bool enabled;
5656 - u32 handle; /* VideoCore handle for component */
5657 - u32 inputs; /* Number of input ports */
5658 - u32 outputs; /* Number of output ports */
5659 - u32 clocks; /* Number of clock ports */
5660 - struct vchiq_mmal_port control; /* control port */
5661 - struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
5662 - struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
5663 - struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
5664 -};
5665 -
5666 -int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
5667 -int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
5668 -
5669 -/* Initialise a mmal component and its ports
5670 - *
5671 - */
5672 -int vchiq_mmal_component_init(
5673 - struct vchiq_mmal_instance *instance,
5674 - const char *name,
5675 - struct vchiq_mmal_component **component_out);
5676 -
5677 -int vchiq_mmal_component_finalise(
5678 - struct vchiq_mmal_instance *instance,
5679 - struct vchiq_mmal_component *component);
5680 -
5681 -int vchiq_mmal_component_enable(
5682 - struct vchiq_mmal_instance *instance,
5683 - struct vchiq_mmal_component *component);
5684 -
5685 -int vchiq_mmal_component_disable(
5686 - struct vchiq_mmal_instance *instance,
5687 - struct vchiq_mmal_component *component);
5688 -
5689 -/* enable a mmal port
5690 - *
5691 - * enables a port and if a buffer callback provided enque buffer
5692 - * headers as appropriate for the port.
5693 - */
5694 -int vchiq_mmal_port_enable(
5695 - struct vchiq_mmal_instance *instance,
5696 - struct vchiq_mmal_port *port,
5697 - vchiq_mmal_buffer_cb buffer_cb);
5698 -
5699 -/* disable a port
5700 - *
5701 - * disable a port will dequeue any pending buffers
5702 - */
5703 -int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
5704 - struct vchiq_mmal_port *port);
5705 -
5706 -int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
5707 - struct vchiq_mmal_port *port,
5708 - u32 parameter,
5709 - void *value,
5710 - u32 value_size);
5711 -
5712 -int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
5713 - struct vchiq_mmal_port *port,
5714 - u32 parameter,
5715 - void *value,
5716 - u32 *value_size);
5717 -
5718 -int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
5719 - struct vchiq_mmal_port *port);
5720 -
5721 -int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
5722 - struct vchiq_mmal_port *src,
5723 - struct vchiq_mmal_port *dst);
5724 -
5725 -int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
5726 - u32 *major_out,
5727 - u32 *minor_out);
5728 -
5729 -int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
5730 - struct vchiq_mmal_port *port,
5731 - struct mmal_buffer *buf);
5732 -
5733 -int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance,
5734 - struct mmal_buffer *buf);
5735 -int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf);
5736 -#endif /* MMAL_VCHIQ_H */
5737 --- /dev/null
5738 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-common.h
5739 @@ -0,0 +1,61 @@
5740 +/* SPDX-License-Identifier: GPL-2.0 */
5741 +/*
5742 + * Broadcom BM2835 V4L2 driver
5743 + *
5744 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5745 + *
5746 + * Authors: Vincent Sanders @ Collabora
5747 + * Dave Stevenson @ Broadcom
5748 + * (now dave.stevenson@raspberrypi.org)
5749 + * Simon Mellor @ Broadcom
5750 + * Luke Diamand @ Broadcom
5751 + *
5752 + * MMAL structures
5753 + *
5754 + */
5755 +#ifndef MMAL_COMMON_H
5756 +#define MMAL_COMMON_H
5757 +
5758 +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
5759 +#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
5760 +
5761 +/** Special value signalling that time is not known */
5762 +#define MMAL_TIME_UNKNOWN BIT_ULL(63)
5763 +
5764 +struct mmal_msg_context;
5765 +
5766 +/* mapping between v4l and mmal video modes */
5767 +struct mmal_fmt {
5768 + char *name;
5769 + u32 fourcc; /* v4l2 format id */
5770 + int flags; /* v4l2 flags field */
5771 + u32 mmal;
5772 + int depth;
5773 + u32 mmal_component; /* MMAL component index to be used to encode */
5774 + u32 ybbp; /* depth of first Y plane for planar formats */
5775 + bool remove_padding; /* Does the GPU have to remove padding,
5776 + * or can we do hide padding via bytesperline.
5777 + */
5778 +};
5779 +
5780 +/* buffer for one video frame */
5781 +struct mmal_buffer {
5782 + /* v4l buffer data -- must be first */
5783 + struct vb2_v4l2_buffer vb;
5784 +
5785 + /* list of buffers available */
5786 + struct list_head list;
5787 +
5788 + void *buffer; /* buffer pointer */
5789 + unsigned long buffer_size; /* size of allocated buffer */
5790 +
5791 + struct mmal_msg_context *msg_context;
5792 +};
5793 +
5794 +/* */
5795 +struct mmal_colourfx {
5796 + s32 enable;
5797 + u32 u;
5798 + u32 v;
5799 +};
5800 +#endif
5801 --- /dev/null
5802 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-encodings.h
5803 @@ -0,0 +1,124 @@
5804 +/* SPDX-License-Identifier: GPL-2.0 */
5805 +/*
5806 + * Broadcom BM2835 V4L2 driver
5807 + *
5808 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5809 + *
5810 + * Authors: Vincent Sanders @ Collabora
5811 + * Dave Stevenson @ Broadcom
5812 + * (now dave.stevenson@raspberrypi.org)
5813 + * Simon Mellor @ Broadcom
5814 + * Luke Diamand @ Broadcom
5815 + */
5816 +#ifndef MMAL_ENCODINGS_H
5817 +#define MMAL_ENCODINGS_H
5818 +
5819 +#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
5820 +#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
5821 +#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
5822 +#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
5823 +#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
5824 +#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
5825 +#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
5826 +#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
5827 +#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
5828 +#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
5829 +#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
5830 +#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
5831 +#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
5832 +#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
5833 +#define MMAL_ENCODING_MJPEG MMAL_FOURCC('M', 'J', 'P', 'G')
5834 +
5835 +#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
5836 +#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
5837 +#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
5838 +#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
5839 +#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
5840 +#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
5841 +
5842 +#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
5843 +#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
5844 +#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
5845 +#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
5846 +#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
5847 +#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
5848 +#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
5849 +#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
5850 +#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
5851 +#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
5852 +#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
5853 +#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
5854 +#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
5855 +#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
5856 +#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
5857 +#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
5858 +#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
5859 +#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
5860 +#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
5861 +#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
5862 +#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
5863 +
5864 +/** SAND Video (YUVUV128) format, native format understood by VideoCore.
5865 + * This format is *not* opaque - if requested you will receive full frames
5866 + * of YUV_UV video.
5867 + */
5868 +#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
5869 +
5870 +/** VideoCore opaque image format, image handles are returned to
5871 + * the host but not the actual image data.
5872 + */
5873 +#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
5874 +
5875 +/** An EGL image handle
5876 + */
5877 +#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
5878 +
5879 +/* }@ */
5880 +
5881 +/** \name Pre-defined audio encodings */
5882 +/* @{ */
5883 +#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
5884 +#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
5885 +#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
5886 +#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
5887 +#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
5888 +#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
5889 +
5890 +/* Pre-defined H264 encoding variants */
5891 +
5892 +/** ISO 14496-10 Annex B byte stream format */
5893 +#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
5894 +/** ISO 14496-15 AVC stream format */
5895 +#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
5896 +/** Implicitly delineated NAL units without emulation prevention */
5897 +#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
5898 +
5899 +/** \defgroup MmalColorSpace List of pre-defined video color spaces
5900 + * This defines a list of common color spaces. This list isn't exhaustive and
5901 + * is only provided as a convenience to avoid clients having to use FourCC
5902 + * codes directly. However components are allowed to define and use their own
5903 + * FourCC codes.
5904 + */
5905 +/* @{ */
5906 +
5907 +/** Unknown color space */
5908 +#define MMAL_COLOR_SPACE_UNKNOWN 0
5909 +/** ITU-R BT.601-5 [SDTV] */
5910 +#define MMAL_COLOR_SPACE_ITUR_BT601 MMAL_FOURCC('Y', '6', '0', '1')
5911 +/** ITU-R BT.709-3 [HDTV] */
5912 +#define MMAL_COLOR_SPACE_ITUR_BT709 MMAL_FOURCC('Y', '7', '0', '9')
5913 +/** JPEG JFIF */
5914 +#define MMAL_COLOR_SPACE_JPEG_JFIF MMAL_FOURCC('Y', 'J', 'F', 'I')
5915 +/** Title 47 Code of Federal Regulations (2003) 73.682 (a) (20) */
5916 +#define MMAL_COLOR_SPACE_FCC MMAL_FOURCC('Y', 'F', 'C', 'C')
5917 +/** Society of Motion Picture and Television Engineers 240M (1999) */
5918 +#define MMAL_COLOR_SPACE_SMPTE240M MMAL_FOURCC('Y', '2', '4', '0')
5919 +/** ITU-R BT.470-2 System M */
5920 +#define MMAL_COLOR_SPACE_BT470_2_M MMAL_FOURCC('Y', '_', '_', 'M')
5921 +/** ITU-R BT.470-2 System BG */
5922 +#define MMAL_COLOR_SPACE_BT470_2_BG MMAL_FOURCC('Y', '_', 'B', 'G')
5923 +/** JPEG JFIF, but with 16..255 luma */
5924 +#define MMAL_COLOR_SPACE_JFIF_Y16_255 MMAL_FOURCC('Y', 'Y', '1', '6')
5925 +/* @} MmalColorSpace List */
5926 +
5927 +#endif /* MMAL_ENCODINGS_H */
5928 --- /dev/null
5929 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-msg-common.h
5930 @@ -0,0 +1,48 @@
5931 +/* SPDX-License-Identifier: GPL-2.0 */
5932 +/*
5933 + * Broadcom BM2835 V4L2 driver
5934 + *
5935 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5936 + *
5937 + * Authors: Vincent Sanders @ Collabora
5938 + * Dave Stevenson @ Broadcom
5939 + * (now dave.stevenson@raspberrypi.org)
5940 + * Simon Mellor @ Broadcom
5941 + * Luke Diamand @ Broadcom
5942 + */
5943 +
5944 +#ifndef MMAL_MSG_COMMON_H
5945 +#define MMAL_MSG_COMMON_H
5946 +
5947 +enum mmal_msg_status {
5948 + MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
5949 + MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
5950 + MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
5951 + MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
5952 + MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
5953 + MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
5954 + MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
5955 + MMAL_MSG_STATUS_EIO, /**< I/O error */
5956 + MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
5957 + MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
5958 + MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
5959 + MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
5960 + MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
5961 + MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
5962 + MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
5963 + MMAL_MSG_STATUS_EFAULT, /**< Bad address */
5964 +};
5965 +
5966 +struct mmal_rect {
5967 + s32 x; /**< x coordinate (from left) */
5968 + s32 y; /**< y coordinate (from top) */
5969 + s32 width; /**< width */
5970 + s32 height; /**< height */
5971 +};
5972 +
5973 +struct mmal_rational {
5974 + s32 num; /**< Numerator */
5975 + s32 den; /**< Denominator */
5976 +};
5977 +
5978 +#endif /* MMAL_MSG_COMMON_H */
5979 --- /dev/null
5980 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-msg-format.h
5981 @@ -0,0 +1,106 @@
5982 +/* SPDX-License-Identifier: GPL-2.0 */
5983 +/*
5984 + * Broadcom BM2835 V4L2 driver
5985 + *
5986 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5987 + *
5988 + * Authors: Vincent Sanders @ Collabora
5989 + * Dave Stevenson @ Broadcom
5990 + * (now dave.stevenson@raspberrypi.org)
5991 + * Simon Mellor @ Broadcom
5992 + * Luke Diamand @ Broadcom
5993 + */
5994 +
5995 +#ifndef MMAL_MSG_FORMAT_H
5996 +#define MMAL_MSG_FORMAT_H
5997 +
5998 +#include "mmal-msg-common.h"
5999 +
6000 +/* MMAL_ES_FORMAT_T */
6001 +
6002 +struct mmal_audio_format {
6003 + u32 channels; /* Number of audio channels */
6004 + u32 sample_rate; /* Sample rate */
6005 +
6006 + u32 bits_per_sample; /* Bits per sample */
6007 + u32 block_align; /* Size of a block of data */
6008 +};
6009 +
6010 +struct mmal_video_format {
6011 + u32 width; /* Width of frame in pixels */
6012 + u32 height; /* Height of frame in rows of pixels */
6013 + struct mmal_rect crop; /* Visible region of the frame */
6014 + struct mmal_rational frame_rate; /* Frame rate */
6015 + struct mmal_rational par; /* Pixel aspect ratio */
6016 +
6017 + /*
6018 + * FourCC specifying the color space of the video stream. See the
6019 + * MmalColorSpace "pre-defined color spaces" for some examples.
6020 + */
6021 + u32 color_space;
6022 +};
6023 +
6024 +struct mmal_subpicture_format {
6025 + u32 x_offset;
6026 + u32 y_offset;
6027 +};
6028 +
6029 +union mmal_es_specific_format {
6030 + struct mmal_audio_format audio;
6031 + struct mmal_video_format video;
6032 + struct mmal_subpicture_format subpicture;
6033 +};
6034 +
6035 +/* Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
6036 +struct mmal_es_format_local {
6037 + u32 type; /* enum mmal_es_type */
6038 +
6039 + u32 encoding; /* FourCC specifying encoding of the elementary
6040 + * stream.
6041 + */
6042 + u32 encoding_variant; /* FourCC specifying the specific
6043 + * encoding variant of the elementary
6044 + * stream.
6045 + */
6046 +
6047 + union mmal_es_specific_format *es; /* Type specific
6048 + * information for the
6049 + * elementary stream
6050 + */
6051 +
6052 + u32 bitrate; /* Bitrate in bits per second */
6053 + u32 flags; /* Flags describing properties of the elementary
6054 + * stream.
6055 + */
6056 +
6057 + u32 extradata_size; /* Size of the codec specific data */
6058 + u8 *extradata; /* Codec specific data */
6059 +};
6060 +
6061 +/* Remote definition of an elementary stream format (MMAL_ES_FORMAT_T) */
6062 +struct mmal_es_format {
6063 + u32 type; /* enum mmal_es_type */
6064 +
6065 + u32 encoding; /* FourCC specifying encoding of the elementary
6066 + * stream.
6067 + */
6068 + u32 encoding_variant; /* FourCC specifying the specific
6069 + * encoding variant of the elementary
6070 + * stream.
6071 + */
6072 +
6073 + u32 es; /* Type specific
6074 + * information for the
6075 + * elementary stream
6076 + */
6077 +
6078 + u32 bitrate; /* Bitrate in bits per second */
6079 + u32 flags; /* Flags describing properties of the elementary
6080 + * stream.
6081 + */
6082 +
6083 + u32 extradata_size; /* Size of the codec specific data */
6084 + u32 extradata; /* Codec specific data */
6085 +};
6086 +
6087 +#endif /* MMAL_MSG_FORMAT_H */
6088 --- /dev/null
6089 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-msg-port.h
6090 @@ -0,0 +1,109 @@
6091 +/* SPDX-License-Identifier: GPL-2.0 */
6092 +/*
6093 + * Broadcom BM2835 V4L2 driver
6094 + *
6095 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
6096 + *
6097 + * Authors: Vincent Sanders @ Collabora
6098 + * Dave Stevenson @ Broadcom
6099 + * (now dave.stevenson@raspberrypi.org)
6100 + * Simon Mellor @ Broadcom
6101 + * Luke Diamand @ Broadcom
6102 + */
6103 +
6104 +/* MMAL_PORT_TYPE_T */
6105 +enum mmal_port_type {
6106 + MMAL_PORT_TYPE_UNKNOWN = 0, /* Unknown port type */
6107 + MMAL_PORT_TYPE_CONTROL, /* Control port */
6108 + MMAL_PORT_TYPE_INPUT, /* Input port */
6109 + MMAL_PORT_TYPE_OUTPUT, /* Output port */
6110 + MMAL_PORT_TYPE_CLOCK, /* Clock port */
6111 +};
6112 +
6113 +/* The port is pass-through and doesn't need buffer headers allocated */
6114 +#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
6115 +/*
6116 + *The port wants to allocate the buffer payloads.
6117 + * This signals a preference that payload allocation should be done
6118 + * on this port for efficiency reasons.
6119 + */
6120 +#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
6121 +/*
6122 + * The port supports format change events.
6123 + * This applies to input ports and is used to let the client know
6124 + * whether the port supports being reconfigured via a format
6125 + * change event (i.e. without having to disable the port).
6126 + */
6127 +#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
6128 +
6129 +/*
6130 + * mmal port structure (MMAL_PORT_T)
6131 + *
6132 + * most elements are informational only, the pointer values for
6133 + * interogation messages are generally provided as additional
6134 + * structures within the message. When used to set values only the
6135 + * buffer_num, buffer_size and userdata parameters are writable.
6136 + */
6137 +struct mmal_port {
6138 + u32 priv; /* Private member used by the framework */
6139 + u32 name; /* Port name. Used for debugging purposes (RO) */
6140 +
6141 + u32 type; /* Type of the port (RO) enum mmal_port_type */
6142 + u16 index; /* Index of the port in its type list (RO) */
6143 + u16 index_all; /* Index of the port in the list of all ports (RO) */
6144 +
6145 + u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
6146 + u32 format; /* Format of the elementary stream */
6147 +
6148 + u32 buffer_num_min; /* Minimum number of buffers the port
6149 + * requires (RO). This is set by the
6150 + * component.
6151 + */
6152 +
6153 + u32 buffer_size_min; /* Minimum size of buffers the port
6154 + * requires (RO). This is set by the
6155 + * component.
6156 + */
6157 +
6158 + u32 buffer_alignment_min;/* Minimum alignment requirement for
6159 + * the buffers (RO). A value of
6160 + * zero means no special alignment
6161 + * requirements. This is set by the
6162 + * component.
6163 + */
6164 +
6165 + u32 buffer_num_recommended; /* Number of buffers the port
6166 + * recommends for optimal
6167 + * performance (RO). A value of
6168 + * zero means no special
6169 + * recommendation. This is set
6170 + * by the component.
6171 + */
6172 +
6173 + u32 buffer_size_recommended; /* Size of buffers the port
6174 + * recommends for optimal
6175 + * performance (RO). A value of
6176 + * zero means no special
6177 + * recommendation. This is set
6178 + * by the component.
6179 + */
6180 +
6181 + u32 buffer_num; /* Actual number of buffers the port will use.
6182 + * This is set by the client.
6183 + */
6184 +
6185 + u32 buffer_size; /* Actual maximum size of the buffers that
6186 + * will be sent to the port. This is set by
6187 + * the client.
6188 + */
6189 +
6190 + u32 component; /* Component this port belongs to (Read Only) */
6191 +
6192 + u32 userdata; /* Field reserved for use by the client */
6193 +
6194 + u32 capabilities; /* Flags describing the capabilities of a
6195 + * port (RO). Bitwise combination of \ref
6196 + * portcapabilities "Port capabilities"
6197 + * values.
6198 + */
6199 +};
6200 --- /dev/null
6201 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-msg.h
6202 @@ -0,0 +1,406 @@
6203 +/* SPDX-License-Identifier: GPL-2.0 */
6204 +/*
6205 + * Broadcom BM2835 V4L2 driver
6206 + *
6207 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
6208 + *
6209 + * Authors: Vincent Sanders @ Collabora
6210 + * Dave Stevenson @ Broadcom
6211 + * (now dave.stevenson@raspberrypi.org)
6212 + * Simon Mellor @ Broadcom
6213 + * Luke Diamand @ Broadcom
6214 + */
6215 +
6216 +/*
6217 + * all the data structures which serialise the MMAL protocol. note
6218 + * these are directly mapped onto the recived message data.
6219 + *
6220 + * BEWARE: They seem to *assume* pointers are u32 and that there is no
6221 + * structure padding!
6222 + *
6223 + * NOTE: this implementation uses kernel types to ensure sizes. Rather
6224 + * than assigning values to enums to force their size the
6225 + * implementation uses fixed size types and not the enums (though the
6226 + * comments have the actual enum type
6227 + */
6228 +#ifndef MMAL_MSG_H
6229 +#define MMAL_MSG_H
6230 +
6231 +#define VC_MMAL_VER 15
6232 +#define VC_MMAL_MIN_VER 10
6233 +#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
6234 +
6235 +/* max total message size is 512 bytes */
6236 +#define MMAL_MSG_MAX_SIZE 512
6237 +/* with six 32bit header elements max payload is therefore 488 bytes */
6238 +#define MMAL_MSG_MAX_PAYLOAD 488
6239 +
6240 +#include "mmal-msg-common.h"
6241 +#include "mmal-msg-format.h"
6242 +#include "mmal-msg-port.h"
6243 +
6244 +enum mmal_msg_type {
6245 + MMAL_MSG_TYPE_QUIT = 1,
6246 + MMAL_MSG_TYPE_SERVICE_CLOSED,
6247 + MMAL_MSG_TYPE_GET_VERSION,
6248 + MMAL_MSG_TYPE_COMPONENT_CREATE,
6249 + MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
6250 + MMAL_MSG_TYPE_COMPONENT_ENABLE,
6251 + MMAL_MSG_TYPE_COMPONENT_DISABLE,
6252 + MMAL_MSG_TYPE_PORT_INFO_GET,
6253 + MMAL_MSG_TYPE_PORT_INFO_SET,
6254 + MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
6255 + MMAL_MSG_TYPE_BUFFER_FROM_HOST,
6256 + MMAL_MSG_TYPE_BUFFER_TO_HOST,
6257 + MMAL_MSG_TYPE_GET_STATS,
6258 + MMAL_MSG_TYPE_PORT_PARAMETER_SET,
6259 + MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
6260 + MMAL_MSG_TYPE_EVENT_TO_HOST,
6261 + MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
6262 + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
6263 + MMAL_MSG_TYPE_CONSUME_MEM,
6264 + MMAL_MSG_TYPE_LMK, /* 20 */
6265 + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
6266 + MMAL_MSG_TYPE_DRM_GET_LHS32,
6267 + MMAL_MSG_TYPE_DRM_GET_TIME,
6268 + MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
6269 + MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
6270 + MMAL_MSG_TYPE_HOST_LOG,
6271 + MMAL_MSG_TYPE_MSG_LAST
6272 +};
6273 +
6274 +/* port action request messages differ depending on the action type */
6275 +enum mmal_msg_port_action_type {
6276 + MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unknown action */
6277 + MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
6278 + MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
6279 + MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
6280 + MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
6281 + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
6282 + MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
6283 +};
6284 +
6285 +struct mmal_msg_header {
6286 + u32 magic;
6287 + u32 type; /* enum mmal_msg_type */
6288 +
6289 + /* Opaque handle to the control service */
6290 + u32 control_service;
6291 +
6292 + u32 context; /* a u32 per message context */
6293 + u32 status; /* The status of the vchiq operation */
6294 + u32 padding;
6295 +};
6296 +
6297 +/* Send from VC to host to report version */
6298 +struct mmal_msg_version {
6299 + u32 flags;
6300 + u32 major;
6301 + u32 minor;
6302 + u32 minimum;
6303 +};
6304 +
6305 +/* request to VC to create component */
6306 +struct mmal_msg_component_create {
6307 + u32 client_component; /* component context */
6308 + char name[128];
6309 + u32 pid; /* For debug */
6310 +};
6311 +
6312 +/* reply from VC to component creation request */
6313 +struct mmal_msg_component_create_reply {
6314 + u32 status; /* enum mmal_msg_status - how does this differ to
6315 + * the one in the header?
6316 + */
6317 + u32 component_handle; /* VideoCore handle for component */
6318 + u32 input_num; /* Number of input ports */
6319 + u32 output_num; /* Number of output ports */
6320 + u32 clock_num; /* Number of clock ports */
6321 +};
6322 +
6323 +/* request to VC to destroy a component */
6324 +struct mmal_msg_component_destroy {
6325 + u32 component_handle;
6326 +};
6327 +
6328 +struct mmal_msg_component_destroy_reply {
6329 + u32 status; /* The component destruction status */
6330 +};
6331 +
6332 +/* request and reply to VC to enable a component */
6333 +struct mmal_msg_component_enable {
6334 + u32 component_handle;
6335 +};
6336 +
6337 +struct mmal_msg_component_enable_reply {
6338 + u32 status; /* The component enable status */
6339 +};
6340 +
6341 +/* request and reply to VC to disable a component */
6342 +struct mmal_msg_component_disable {
6343 + u32 component_handle;
6344 +};
6345 +
6346 +struct mmal_msg_component_disable_reply {
6347 + u32 status; /* The component disable status */
6348 +};
6349 +
6350 +/* request to VC to get port information */
6351 +struct mmal_msg_port_info_get {
6352 + u32 component_handle; /* component handle port is associated with */
6353 + u32 port_type; /* enum mmal_msg_port_type */
6354 + u32 index; /* port index to query */
6355 +};
6356 +
6357 +/* reply from VC to get port info request */
6358 +struct mmal_msg_port_info_get_reply {
6359 + u32 status; /* enum mmal_msg_status */
6360 + u32 component_handle; /* component handle port is associated with */
6361 + u32 port_type; /* enum mmal_msg_port_type */
6362 + u32 port_index; /* port indexed in query */
6363 + s32 found; /* unused */
6364 + u32 port_handle; /* Handle to use for this port */
6365 + struct mmal_port port;
6366 + struct mmal_es_format format; /* elementary stream format */
6367 + union mmal_es_specific_format es; /* es type specific data */
6368 + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
6369 +};
6370 +
6371 +/* request to VC to set port information */
6372 +struct mmal_msg_port_info_set {
6373 + u32 component_handle;
6374 + u32 port_type; /* enum mmal_msg_port_type */
6375 + u32 port_index; /* port indexed in query */
6376 + struct mmal_port port;
6377 + struct mmal_es_format format;
6378 + union mmal_es_specific_format es;
6379 + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
6380 +};
6381 +
6382 +/* reply from VC to port info set request */
6383 +struct mmal_msg_port_info_set_reply {
6384 + u32 status;
6385 + u32 component_handle; /* component handle port is associated with */
6386 + u32 port_type; /* enum mmal_msg_port_type */
6387 + u32 index; /* port indexed in query */
6388 + s32 found; /* unused */
6389 + u32 port_handle; /* Handle to use for this port */
6390 + struct mmal_port port;
6391 + struct mmal_es_format format;
6392 + union mmal_es_specific_format es;
6393 + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
6394 +};
6395 +
6396 +/* port action requests that take a mmal_port as a parameter */
6397 +struct mmal_msg_port_action_port {
6398 + u32 component_handle;
6399 + u32 port_handle;
6400 + u32 action; /* enum mmal_msg_port_action_type */
6401 + struct mmal_port port;
6402 +};
6403 +
6404 +/* port action requests that take handles as a parameter */
6405 +struct mmal_msg_port_action_handle {
6406 + u32 component_handle;
6407 + u32 port_handle;
6408 + u32 action; /* enum mmal_msg_port_action_type */
6409 + u32 connect_component_handle;
6410 + u32 connect_port_handle;
6411 +};
6412 +
6413 +struct mmal_msg_port_action_reply {
6414 + u32 status; /* The port action operation status */
6415 +};
6416 +
6417 +/* MMAL buffer transfer */
6418 +
6419 +/* Size of space reserved in a buffer message for short messages. */
6420 +#define MMAL_VC_SHORT_DATA 128
6421 +
6422 +/* Signals that the current payload is the end of the stream of data */
6423 +#define MMAL_BUFFER_HEADER_FLAG_EOS BIT(0)
6424 +/* Signals that the start of the current payload starts a frame */
6425 +#define MMAL_BUFFER_HEADER_FLAG_FRAME_START BIT(1)
6426 +/* Signals that the end of the current payload ends a frame */
6427 +#define MMAL_BUFFER_HEADER_FLAG_FRAME_END BIT(2)
6428 +/* Signals that the current payload contains only complete frames (>1) */
6429 +#define MMAL_BUFFER_HEADER_FLAG_FRAME \
6430 + (MMAL_BUFFER_HEADER_FLAG_FRAME_START | \
6431 + MMAL_BUFFER_HEADER_FLAG_FRAME_END)
6432 +/* Signals that the current payload is a keyframe (i.e. self decodable) */
6433 +#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME BIT(3)
6434 +/*
6435 + * Signals a discontinuity in the stream of data (e.g. after a seek).
6436 + * Can be used for instance by a decoder to reset its state
6437 + */
6438 +#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY BIT(4)
6439 +/*
6440 + * Signals a buffer containing some kind of config data for the component
6441 + * (e.g. codec config data)
6442 + */
6443 +#define MMAL_BUFFER_HEADER_FLAG_CONFIG BIT(5)
6444 +/* Signals an encrypted payload */
6445 +#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED BIT(6)
6446 +/* Signals a buffer containing side information */
6447 +#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO BIT(7)
6448 +/*
6449 + * Signals a buffer which is the snapshot/postview image from a stills
6450 + * capture
6451 + */
6452 +#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT BIT(8)
6453 +/* Signals a buffer which contains data known to be corrupted */
6454 +#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED BIT(9)
6455 +/* Signals that a buffer failed to be transmitted */
6456 +#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED BIT(10)
6457 +
6458 +struct mmal_driver_buffer {
6459 + u32 magic;
6460 + u32 component_handle;
6461 + u32 port_handle;
6462 + u32 client_context;
6463 +};
6464 +
6465 +/* buffer header */
6466 +struct mmal_buffer_header {
6467 + u32 next; /* next header */
6468 + u32 priv; /* framework private data */
6469 + u32 cmd;
6470 + u32 data;
6471 + u32 alloc_size;
6472 + u32 length;
6473 + u32 offset;
6474 + u32 flags;
6475 + s64 pts;
6476 + s64 dts;
6477 + u32 type;
6478 + u32 user_data;
6479 +};
6480 +
6481 +struct mmal_buffer_header_type_specific {
6482 + union {
6483 + struct {
6484 + u32 planes;
6485 + u32 offset[4];
6486 + u32 pitch[4];
6487 + u32 flags;
6488 + } video;
6489 + } u;
6490 +};
6491 +
6492 +struct mmal_msg_buffer_from_host {
6493 + /*
6494 + *The front 32 bytes of the buffer header are copied
6495 + * back to us in the reply to allow for context. This
6496 + * area is used to store two mmal_driver_buffer structures to
6497 + * allow for multiple concurrent service users.
6498 + */
6499 + /* control data */
6500 + struct mmal_driver_buffer drvbuf;
6501 +
6502 + /* referenced control data for passthrough buffer management */
6503 + struct mmal_driver_buffer drvbuf_ref;
6504 + struct mmal_buffer_header buffer_header; /* buffer header itself */
6505 + struct mmal_buffer_header_type_specific buffer_header_type_specific;
6506 + s32 is_zero_copy;
6507 + s32 has_reference;
6508 +
6509 + /* allows short data to be xfered in control message */
6510 + u32 payload_in_message;
6511 + u8 short_data[MMAL_VC_SHORT_DATA];
6512 +};
6513 +
6514 +/* port parameter setting */
6515 +
6516 +#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
6517 +
6518 +struct mmal_msg_port_parameter_set {
6519 + u32 component_handle; /* component */
6520 + u32 port_handle; /* port */
6521 + u32 id; /* Parameter ID */
6522 + u32 size; /* Parameter size */
6523 + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
6524 +};
6525 +
6526 +struct mmal_msg_port_parameter_set_reply {
6527 + u32 status; /* enum mmal_msg_status todo: how does this
6528 + * differ to the one in the header?
6529 + */
6530 +};
6531 +
6532 +/* port parameter getting */
6533 +
6534 +struct mmal_msg_port_parameter_get {
6535 + u32 component_handle; /* component */
6536 + u32 port_handle; /* port */
6537 + u32 id; /* Parameter ID */
6538 + u32 size; /* Parameter size */
6539 +};
6540 +
6541 +struct mmal_msg_port_parameter_get_reply {
6542 + u32 status; /* Status of mmal_port_parameter_get call */
6543 + u32 id; /* Parameter ID */
6544 + u32 size; /* Parameter size */
6545 + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
6546 +};
6547 +
6548 +/* event messages */
6549 +#define MMAL_WORKER_EVENT_SPACE 256
6550 +
6551 +struct mmal_msg_event_to_host {
6552 + u32 client_component; /* component context */
6553 +
6554 + u32 port_type;
6555 + u32 port_num;
6556 +
6557 + u32 cmd;
6558 + u32 length;
6559 + u8 data[MMAL_WORKER_EVENT_SPACE];
6560 + u32 delayed_buffer;
6561 +};
6562 +
6563 +/* all mmal messages are serialised through this structure */
6564 +struct mmal_msg {
6565 + /* header */
6566 + struct mmal_msg_header h;
6567 + /* payload */
6568 + union {
6569 + struct mmal_msg_version version;
6570 +
6571 + struct mmal_msg_component_create component_create;
6572 + struct mmal_msg_component_create_reply component_create_reply;
6573 +
6574 + struct mmal_msg_component_destroy component_destroy;
6575 + struct mmal_msg_component_destroy_reply component_destroy_reply;
6576 +
6577 + struct mmal_msg_component_enable component_enable;
6578 + struct mmal_msg_component_enable_reply component_enable_reply;
6579 +
6580 + struct mmal_msg_component_disable component_disable;
6581 + struct mmal_msg_component_disable_reply component_disable_reply;
6582 +
6583 + struct mmal_msg_port_info_get port_info_get;
6584 + struct mmal_msg_port_info_get_reply port_info_get_reply;
6585 +
6586 + struct mmal_msg_port_info_set port_info_set;
6587 + struct mmal_msg_port_info_set_reply port_info_set_reply;
6588 +
6589 + struct mmal_msg_port_action_port port_action_port;
6590 + struct mmal_msg_port_action_handle port_action_handle;
6591 + struct mmal_msg_port_action_reply port_action_reply;
6592 +
6593 + struct mmal_msg_buffer_from_host buffer_from_host;
6594 +
6595 + struct mmal_msg_port_parameter_set port_parameter_set;
6596 + struct mmal_msg_port_parameter_set_reply
6597 + port_parameter_set_reply;
6598 + struct mmal_msg_port_parameter_get
6599 + port_parameter_get;
6600 + struct mmal_msg_port_parameter_get_reply
6601 + port_parameter_get_reply;
6602 +
6603 + struct mmal_msg_event_to_host event_to_host;
6604 +
6605 + u8 payload[MMAL_MSG_MAX_PAYLOAD];
6606 + } u;
6607 +};
6608 +#endif
6609 --- /dev/null
6610 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-parameters.h
6611 @@ -0,0 +1,755 @@
6612 +/* SPDX-License-Identifier: GPL-2.0 */
6613 +/*
6614 + * Broadcom BM2835 V4L2 driver
6615 + *
6616 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
6617 + *
6618 + * Authors: Vincent Sanders @ Collabora
6619 + * Dave Stevenson @ Broadcom
6620 + * (now dave.stevenson@raspberrypi.org)
6621 + * Simon Mellor @ Broadcom
6622 + * Luke Diamand @ Broadcom
6623 + */
6624 +
6625 +/* common parameters */
6626 +
6627 +/** @name Parameter groups
6628 + * Parameters are divided into groups, and then allocated sequentially within
6629 + * a group using an enum.
6630 + * @{
6631 + */
6632 +
6633 +#ifndef MMAL_PARAMETERS_H
6634 +#define MMAL_PARAMETERS_H
6635 +
6636 +/** Common parameter ID group, used with many types of component. */
6637 +#define MMAL_PARAMETER_GROUP_COMMON (0 << 16)
6638 +/** Camera-specific parameter ID group. */
6639 +#define MMAL_PARAMETER_GROUP_CAMERA (1 << 16)
6640 +/** Video-specific parameter ID group. */
6641 +#define MMAL_PARAMETER_GROUP_VIDEO (2 << 16)
6642 +/** Audio-specific parameter ID group. */
6643 +#define MMAL_PARAMETER_GROUP_AUDIO (3 << 16)
6644 +/** Clock-specific parameter ID group. */
6645 +#define MMAL_PARAMETER_GROUP_CLOCK (4 << 16)
6646 +/** Miracast-specific parameter ID group. */
6647 +#define MMAL_PARAMETER_GROUP_MIRACAST (5 << 16)
6648 +
6649 +/* Common parameters */
6650 +enum mmal_parameter_common_type {
6651 + /**< Never a valid parameter ID */
6652 + MMAL_PARAMETER_UNUSED = MMAL_PARAMETER_GROUP_COMMON,
6653 +
6654 + /**< MMAL_PARAMETER_ENCODING_T */
6655 + MMAL_PARAMETER_SUPPORTED_ENCODINGS,
6656 + /**< MMAL_PARAMETER_URI_T */
6657 + MMAL_PARAMETER_URI,
6658 + /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
6659 + MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
6660 + /** MMAL_PARAMETER_BOOLEAN_T */
6661 + MMAL_PARAMETER_ZERO_COPY,
6662 + /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
6663 + MMAL_PARAMETER_BUFFER_REQUIREMENTS,
6664 + /**< MMAL_PARAMETER_STATISTICS_T */
6665 + MMAL_PARAMETER_STATISTICS,
6666 + /**< MMAL_PARAMETER_CORE_STATISTICS_T */
6667 + MMAL_PARAMETER_CORE_STATISTICS,
6668 + /**< MMAL_PARAMETER_MEM_USAGE_T */
6669 + MMAL_PARAMETER_MEM_USAGE,
6670 + /**< MMAL_PARAMETER_UINT32_T */
6671 + MMAL_PARAMETER_BUFFER_FLAG_FILTER,
6672 + /**< MMAL_PARAMETER_SEEK_T */
6673 + MMAL_PARAMETER_SEEK,
6674 + /**< MMAL_PARAMETER_BOOLEAN_T */
6675 + MMAL_PARAMETER_POWERMON_ENABLE,
6676 + /**< MMAL_PARAMETER_LOGGING_T */
6677 + MMAL_PARAMETER_LOGGING,
6678 + /**< MMAL_PARAMETER_UINT64_T */
6679 + MMAL_PARAMETER_SYSTEM_TIME,
6680 + /**< MMAL_PARAMETER_BOOLEAN_T */
6681 + MMAL_PARAMETER_NO_IMAGE_PADDING,
6682 +};
6683 +
6684 +/* camera parameters */
6685 +
6686 +enum mmal_parameter_camera_type {
6687 + /* 0 */
6688 + /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
6689 + MMAL_PARAMETER_THUMBNAIL_CONFIGURATION =
6690 + MMAL_PARAMETER_GROUP_CAMERA,
6691 + /**< Unused? */
6692 + MMAL_PARAMETER_CAPTURE_QUALITY,
6693 + /**< @ref MMAL_PARAMETER_INT32_T */
6694 + MMAL_PARAMETER_ROTATION,
6695 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
6696 + MMAL_PARAMETER_EXIF_DISABLE,
6697 + /**< @ref MMAL_PARAMETER_EXIF_T */
6698 + MMAL_PARAMETER_EXIF,
6699 + /**< @ref MMAL_PARAM_AWBMODE_T */
6700 + MMAL_PARAMETER_AWB_MODE,
6701 + /**< @ref MMAL_PARAMETER_IMAGEFX_T */
6702 + MMAL_PARAMETER_IMAGE_EFFECT,
6703 + /**< @ref MMAL_PARAMETER_COLOURFX_T */
6704 + MMAL_PARAMETER_COLOUR_EFFECT,
6705 + /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
6706 + MMAL_PARAMETER_FLICKER_AVOID,
6707 + /**< @ref MMAL_PARAMETER_FLASH_T */
6708 + MMAL_PARAMETER_FLASH,
6709 + /**< @ref MMAL_PARAMETER_REDEYE_T */
6710 + MMAL_PARAMETER_REDEYE,
6711 + /**< @ref MMAL_PARAMETER_FOCUS_T */
6712 + MMAL_PARAMETER_FOCUS,
6713 + /**< Unused? */
6714 + MMAL_PARAMETER_FOCAL_LENGTHS,
6715 + /**< @ref MMAL_PARAMETER_INT32_T */
6716 + MMAL_PARAMETER_EXPOSURE_COMP,
6717 + /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
6718 + MMAL_PARAMETER_ZOOM,
6719 + /**< @ref MMAL_PARAMETER_MIRROR_T */
6720 + MMAL_PARAMETER_MIRROR,
6721 +
6722 + /* 0x10 */
6723 + /**< @ref MMAL_PARAMETER_UINT32_T */
6724 + MMAL_PARAMETER_CAMERA_NUM,
6725 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
6726 + MMAL_PARAMETER_CAPTURE,
6727 + /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
6728 + MMAL_PARAMETER_EXPOSURE_MODE,
6729 + /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
6730 + MMAL_PARAMETER_EXP_METERING_MODE,
6731 + /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
6732 + MMAL_PARAMETER_FOCUS_STATUS,
6733 + /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
6734 + MMAL_PARAMETER_CAMERA_CONFIG,
6735 + /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
6736 + MMAL_PARAMETER_CAPTURE_STATUS,
6737 + /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
6738 + MMAL_PARAMETER_FACE_TRACK,
6739 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
6740 + MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS,
6741 + /**< @ref MMAL_PARAMETER_UINT32_T */
6742 + MMAL_PARAMETER_JPEG_Q_FACTOR,
6743 + /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
6744 + MMAL_PARAMETER_FRAME_RATE,
6745 + /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
6746 + MMAL_PARAMETER_USE_STC,
6747 + /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
6748 + MMAL_PARAMETER_CAMERA_INFO,
6749 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
6750 + MMAL_PARAMETER_VIDEO_STABILISATION,
6751 + /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
6752 + MMAL_PARAMETER_FACE_TRACK_RESULTS,
6753 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
6754 + MMAL_PARAMETER_ENABLE_RAW_CAPTURE,
6755 +
6756 + /* 0x20 */
6757 + /**< @ref MMAL_PARAMETER_URI_T */
6758 + MMAL_PARAMETER_DPF_FILE,
6759 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
6760 + MMAL_PARAMETER_ENABLE_DPF_FILE,
6761 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
6762 + MMAL_PARAMETER_DPF_FAIL_IS_FATAL,
6763 + /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
6764 + MMAL_PARAMETER_CAPTURE_MODE,
6765 + /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
6766 + MMAL_PARAMETER_FOCUS_REGIONS,
6767 + /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
6768 + MMAL_PARAMETER_INPUT_CROP,
6769 + /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
6770 + MMAL_PARAMETER_SENSOR_INFORMATION,
6771 + /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
6772 + MMAL_PARAMETER_FLASH_SELECT,
6773 + /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
6774 + MMAL_PARAMETER_FIELD_OF_VIEW,
6775 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
6776 + MMAL_PARAMETER_HIGH_DYNAMIC_RANGE,
6777 + /**< @ref MMAL_PARAMETER_DRC_T */
6778 + MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION,
6779 + /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
6780 + MMAL_PARAMETER_ALGORITHM_CONTROL,
6781 + /**< @ref MMAL_PARAMETER_RATIONAL_T */
6782 + MMAL_PARAMETER_SHARPNESS,
6783 + /**< @ref MMAL_PARAMETER_RATIONAL_T */
6784 + MMAL_PARAMETER_CONTRAST,
6785 + /**< @ref MMAL_PARAMETER_RATIONAL_T */
6786 + MMAL_PARAMETER_BRIGHTNESS,
6787 + /**< @ref MMAL_PARAMETER_RATIONAL_T */
6788 + MMAL_PARAMETER_SATURATION,
6789 +
6790 + /* 0x30 */
6791 + /**< @ref MMAL_PARAMETER_UINT32_T */
6792 + MMAL_PARAMETER_ISO,
6793 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
6794 + MMAL_PARAMETER_ANTISHAKE,
6795 + /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
6796 + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
6797 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
6798 + MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
6799 + /** @ref MMAL_PARAMETER_UINT32_T */
6800 + MMAL_PARAMETER_CAMERA_MIN_ISO,
6801 + /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
6802 + MMAL_PARAMETER_CAMERA_USE_CASE,
6803 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
6804 + MMAL_PARAMETER_CAPTURE_STATS_PASS,
6805 + /** @ref MMAL_PARAMETER_UINT32_T */
6806 + MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
6807 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
6808 + MMAL_PARAMETER_ENABLE_REGISTER_FILE,
6809 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
6810 + MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
6811 + /** @ref MMAL_PARAMETER_CONFIGFILE_T */
6812 + MMAL_PARAMETER_CONFIGFILE_REGISTERS,
6813 + /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
6814 + MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
6815 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
6816 + MMAL_PARAMETER_JPEG_ATTACH_LOG,
6817 + /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
6818 + MMAL_PARAMETER_ZERO_SHUTTER_LAG,
6819 + /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
6820 + MMAL_PARAMETER_FPS_RANGE,
6821 + /**< @ref MMAL_PARAMETER_INT32_T */
6822 + MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP,
6823 +
6824 + /* 0x40 */
6825 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
6826 + MMAL_PARAMETER_SW_SHARPEN_DISABLE,
6827 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
6828 + MMAL_PARAMETER_FLASH_REQUIRED,
6829 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
6830 + MMAL_PARAMETER_SW_SATURATION_DISABLE,
6831 + /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
6832 + MMAL_PARAMETER_SHUTTER_SPEED,
6833 + /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */
6834 + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
6835 +};
6836 +
6837 +struct mmal_parameter_rational {
6838 + s32 num; /**< Numerator */
6839 + s32 den; /**< Denominator */
6840 +};
6841 +
6842 +enum mmal_parameter_camera_config_timestamp_mode {
6843 + MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
6844 + MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
6845 + * for the frame timestamp
6846 + */
6847 + MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
6848 + * but subtract the
6849 + * timestamp of the first
6850 + * frame sent to give a
6851 + * zero based timestamp.
6852 + */
6853 +};
6854 +
6855 +struct mmal_parameter_fps_range {
6856 + /**< Low end of the permitted framerate range */
6857 + struct mmal_parameter_rational fps_low;
6858 + /**< High end of the permitted framerate range */
6859 + struct mmal_parameter_rational fps_high;
6860 +};
6861 +
6862 +/* camera configuration parameter */
6863 +struct mmal_parameter_camera_config {
6864 + /* Parameters for setting up the image pools */
6865 + u32 max_stills_w; /* Max size of stills capture */
6866 + u32 max_stills_h;
6867 + u32 stills_yuv422; /* Allow YUV422 stills capture */
6868 + u32 one_shot_stills; /* Continuous or one shot stills captures. */
6869 +
6870 + u32 max_preview_video_w; /* Max size of the preview or video
6871 + * capture frames
6872 + */
6873 + u32 max_preview_video_h;
6874 + u32 num_preview_video_frames;
6875 +
6876 + /** Sets the height of the circular buffer for stills capture. */
6877 + u32 stills_capture_circular_buffer_height;
6878 +
6879 + /** Allows preview/encode to resume as fast as possible after the stills
6880 + * input frame has been received, and then processes the still frame in
6881 + * the background whilst preview/encode has resumed.
6882 + * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
6883 + */
6884 + u32 fast_preview_resume;
6885 +
6886 + /** Selects algorithm for timestamping frames if
6887 + * there is no clock component connected.
6888 + * enum mmal_parameter_camera_config_timestamp_mode
6889 + */
6890 + s32 use_stc_timestamp;
6891 +};
6892 +
6893 +enum mmal_parameter_exposuremode {
6894 + MMAL_PARAM_EXPOSUREMODE_OFF,
6895 + MMAL_PARAM_EXPOSUREMODE_AUTO,
6896 + MMAL_PARAM_EXPOSUREMODE_NIGHT,
6897 + MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
6898 + MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
6899 + MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
6900 + MMAL_PARAM_EXPOSUREMODE_SPORTS,
6901 + MMAL_PARAM_EXPOSUREMODE_SNOW,
6902 + MMAL_PARAM_EXPOSUREMODE_BEACH,
6903 + MMAL_PARAM_EXPOSUREMODE_VERYLONG,
6904 + MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
6905 + MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
6906 + MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
6907 +};
6908 +
6909 +enum mmal_parameter_exposuremeteringmode {
6910 + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
6911 + MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
6912 + MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
6913 + MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
6914 +};
6915 +
6916 +enum mmal_parameter_awbmode {
6917 + MMAL_PARAM_AWBMODE_OFF,
6918 + MMAL_PARAM_AWBMODE_AUTO,
6919 + MMAL_PARAM_AWBMODE_SUNLIGHT,
6920 + MMAL_PARAM_AWBMODE_CLOUDY,
6921 + MMAL_PARAM_AWBMODE_SHADE,
6922 + MMAL_PARAM_AWBMODE_TUNGSTEN,
6923 + MMAL_PARAM_AWBMODE_FLUORESCENT,
6924 + MMAL_PARAM_AWBMODE_INCANDESCENT,
6925 + MMAL_PARAM_AWBMODE_FLASH,
6926 + MMAL_PARAM_AWBMODE_HORIZON,
6927 +};
6928 +
6929 +enum mmal_parameter_imagefx {
6930 + MMAL_PARAM_IMAGEFX_NONE,
6931 + MMAL_PARAM_IMAGEFX_NEGATIVE,
6932 + MMAL_PARAM_IMAGEFX_SOLARIZE,
6933 + MMAL_PARAM_IMAGEFX_POSTERIZE,
6934 + MMAL_PARAM_IMAGEFX_WHITEBOARD,
6935 + MMAL_PARAM_IMAGEFX_BLACKBOARD,
6936 + MMAL_PARAM_IMAGEFX_SKETCH,
6937 + MMAL_PARAM_IMAGEFX_DENOISE,
6938 + MMAL_PARAM_IMAGEFX_EMBOSS,
6939 + MMAL_PARAM_IMAGEFX_OILPAINT,
6940 + MMAL_PARAM_IMAGEFX_HATCH,
6941 + MMAL_PARAM_IMAGEFX_GPEN,
6942 + MMAL_PARAM_IMAGEFX_PASTEL,
6943 + MMAL_PARAM_IMAGEFX_WATERCOLOUR,
6944 + MMAL_PARAM_IMAGEFX_FILM,
6945 + MMAL_PARAM_IMAGEFX_BLUR,
6946 + MMAL_PARAM_IMAGEFX_SATURATION,
6947 + MMAL_PARAM_IMAGEFX_COLOURSWAP,
6948 + MMAL_PARAM_IMAGEFX_WASHEDOUT,
6949 + MMAL_PARAM_IMAGEFX_POSTERISE,
6950 + MMAL_PARAM_IMAGEFX_COLOURPOINT,
6951 + MMAL_PARAM_IMAGEFX_COLOURBALANCE,
6952 + MMAL_PARAM_IMAGEFX_CARTOON,
6953 +};
6954 +
6955 +enum MMAL_PARAM_FLICKERAVOID_T {
6956 + MMAL_PARAM_FLICKERAVOID_OFF,
6957 + MMAL_PARAM_FLICKERAVOID_AUTO,
6958 + MMAL_PARAM_FLICKERAVOID_50HZ,
6959 + MMAL_PARAM_FLICKERAVOID_60HZ,
6960 + MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
6961 +};
6962 +
6963 +struct mmal_parameter_awbgains {
6964 + struct mmal_parameter_rational r_gain; /**< Red gain */
6965 + struct mmal_parameter_rational b_gain; /**< Blue gain */
6966 +};
6967 +
6968 +/** Manner of video rate control */
6969 +enum mmal_parameter_rate_control_mode {
6970 + MMAL_VIDEO_RATECONTROL_DEFAULT,
6971 + MMAL_VIDEO_RATECONTROL_VARIABLE,
6972 + MMAL_VIDEO_RATECONTROL_CONSTANT,
6973 + MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
6974 + MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
6975 +};
6976 +
6977 +enum mmal_video_profile {
6978 + MMAL_VIDEO_PROFILE_H263_BASELINE,
6979 + MMAL_VIDEO_PROFILE_H263_H320CODING,
6980 + MMAL_VIDEO_PROFILE_H263_BACKWARDCOMPATIBLE,
6981 + MMAL_VIDEO_PROFILE_H263_ISWV2,
6982 + MMAL_VIDEO_PROFILE_H263_ISWV3,
6983 + MMAL_VIDEO_PROFILE_H263_HIGHCOMPRESSION,
6984 + MMAL_VIDEO_PROFILE_H263_INTERNET,
6985 + MMAL_VIDEO_PROFILE_H263_INTERLACE,
6986 + MMAL_VIDEO_PROFILE_H263_HIGHLATENCY,
6987 + MMAL_VIDEO_PROFILE_MP4V_SIMPLE,
6988 + MMAL_VIDEO_PROFILE_MP4V_SIMPLESCALABLE,
6989 + MMAL_VIDEO_PROFILE_MP4V_CORE,
6990 + MMAL_VIDEO_PROFILE_MP4V_MAIN,
6991 + MMAL_VIDEO_PROFILE_MP4V_NBIT,
6992 + MMAL_VIDEO_PROFILE_MP4V_SCALABLETEXTURE,
6993 + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFACE,
6994 + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFBA,
6995 + MMAL_VIDEO_PROFILE_MP4V_BASICANIMATED,
6996 + MMAL_VIDEO_PROFILE_MP4V_HYBRID,
6997 + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDREALTIME,
6998 + MMAL_VIDEO_PROFILE_MP4V_CORESCALABLE,
6999 + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCODING,
7000 + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCORE,
7001 + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSCALABLE,
7002 + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSIMPLE,
7003 + MMAL_VIDEO_PROFILE_H264_BASELINE,
7004 + MMAL_VIDEO_PROFILE_H264_MAIN,
7005 + MMAL_VIDEO_PROFILE_H264_EXTENDED,
7006 + MMAL_VIDEO_PROFILE_H264_HIGH,
7007 + MMAL_VIDEO_PROFILE_H264_HIGH10,
7008 + MMAL_VIDEO_PROFILE_H264_HIGH422,
7009 + MMAL_VIDEO_PROFILE_H264_HIGH444,
7010 + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE,
7011 + MMAL_VIDEO_PROFILE_DUMMY = 0x7FFFFFFF
7012 +};
7013 +
7014 +enum mmal_video_level {
7015 + MMAL_VIDEO_LEVEL_H263_10,
7016 + MMAL_VIDEO_LEVEL_H263_20,
7017 + MMAL_VIDEO_LEVEL_H263_30,
7018 + MMAL_VIDEO_LEVEL_H263_40,
7019 + MMAL_VIDEO_LEVEL_H263_45,
7020 + MMAL_VIDEO_LEVEL_H263_50,
7021 + MMAL_VIDEO_LEVEL_H263_60,
7022 + MMAL_VIDEO_LEVEL_H263_70,
7023 + MMAL_VIDEO_LEVEL_MP4V_0,
7024 + MMAL_VIDEO_LEVEL_MP4V_0b,
7025 + MMAL_VIDEO_LEVEL_MP4V_1,
7026 + MMAL_VIDEO_LEVEL_MP4V_2,
7027 + MMAL_VIDEO_LEVEL_MP4V_3,
7028 + MMAL_VIDEO_LEVEL_MP4V_4,
7029 + MMAL_VIDEO_LEVEL_MP4V_4a,
7030 + MMAL_VIDEO_LEVEL_MP4V_5,
7031 + MMAL_VIDEO_LEVEL_MP4V_6,
7032 + MMAL_VIDEO_LEVEL_H264_1,
7033 + MMAL_VIDEO_LEVEL_H264_1b,
7034 + MMAL_VIDEO_LEVEL_H264_11,
7035 + MMAL_VIDEO_LEVEL_H264_12,
7036 + MMAL_VIDEO_LEVEL_H264_13,
7037 + MMAL_VIDEO_LEVEL_H264_2,
7038 + MMAL_VIDEO_LEVEL_H264_21,
7039 + MMAL_VIDEO_LEVEL_H264_22,
7040 + MMAL_VIDEO_LEVEL_H264_3,
7041 + MMAL_VIDEO_LEVEL_H264_31,
7042 + MMAL_VIDEO_LEVEL_H264_32,
7043 + MMAL_VIDEO_LEVEL_H264_4,
7044 + MMAL_VIDEO_LEVEL_H264_41,
7045 + MMAL_VIDEO_LEVEL_H264_42,
7046 + MMAL_VIDEO_LEVEL_H264_5,
7047 + MMAL_VIDEO_LEVEL_H264_51,
7048 + MMAL_VIDEO_LEVEL_DUMMY = 0x7FFFFFFF
7049 +};
7050 +
7051 +struct mmal_parameter_video_profile {
7052 + enum mmal_video_profile profile;
7053 + enum mmal_video_level level;
7054 +};
7055 +
7056 +/* video parameters */
7057 +
7058 +enum mmal_parameter_video_type {
7059 + /** @ref MMAL_DISPLAYREGION_T */
7060 + MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
7061 +
7062 + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
7063 + MMAL_PARAMETER_SUPPORTED_PROFILES,
7064 +
7065 + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
7066 + MMAL_PARAMETER_PROFILE,
7067 +
7068 + /** @ref MMAL_PARAMETER_UINT32_T */
7069 + MMAL_PARAMETER_INTRAPERIOD,
7070 +
7071 + /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
7072 + MMAL_PARAMETER_RATECONTROL,
7073 +
7074 + /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
7075 + MMAL_PARAMETER_NALUNITFORMAT,
7076 +
7077 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
7078 + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
7079 +
7080 + /** @ref MMAL_PARAMETER_UINT32_T.
7081 + * Setting the value to zero resets to the default (one slice per
7082 + * frame).
7083 + */
7084 + MMAL_PARAMETER_MB_ROWS_PER_SLICE,
7085 +
7086 + /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
7087 + MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
7088 +
7089 + /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
7090 + MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
7091 +
7092 + /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
7093 + MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
7094 +
7095 + /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
7096 + MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
7097 + /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
7098 + MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
7099 +
7100 + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
7101 + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
7102 +
7103 + /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
7104 + MMAL_PARAMETER_VIDEO_BIT_RATE,
7105 +
7106 + /** @ref MMAL_PARAMETER_FRAME_RATE_T */
7107 + MMAL_PARAMETER_VIDEO_FRAME_RATE,
7108 +
7109 + /** @ref MMAL_PARAMETER_UINT32_T. */
7110 + MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
7111 +
7112 + /** @ref MMAL_PARAMETER_UINT32_T. */
7113 + MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
7114 +
7115 + /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
7116 + MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
7117 +
7118 + MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
7119 + /** @ref MMAL_PARAMETER_UINT32_T.
7120 + * Changing this parameter from the default can reduce frame rate
7121 + * because image buffers need to be re-pitched.
7122 + */
7123 + MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
7124 +
7125 + /** @ref MMAL_PARAMETER_UINT32_T.
7126 + * Changing this parameter from the default can reduce frame rate
7127 + * because image buffers need to be re-pitched.
7128 + */
7129 + MMAL_PARAMETER_VIDEO_ALIGN_VERT,
7130 +
7131 + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
7132 + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
7133 +
7134 + /** @ref MMAL_PARAMETER_UINT32_T. */
7135 + MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
7136 +
7137 + /**< @ref MMAL_PARAMETER_UINT32_T. */
7138 + MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
7139 +
7140 + /**< @ref MMAL_PARAMETER_UINT32_T. */
7141 + MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
7142 +
7143 + /** @ref MMAL_PARAMETER_UINT32_T */
7144 + MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
7145 +
7146 + /** @ref MMAL_PARAMETER_UINT32_T. */
7147 + MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
7148 +
7149 + /* H264 specific parameters */
7150 +
7151 + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
7152 + MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
7153 +
7154 + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
7155 + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
7156 +
7157 + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
7158 + MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
7159 +
7160 + /** @ref MMAL_PARAMETER_UINT32_T. */
7161 + MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
7162 +
7163 + /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
7164 + MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
7165 +
7166 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
7167 + MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
7168 +
7169 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
7170 + MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
7171 +
7172 + /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
7173 + MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
7174 +
7175 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
7176 + MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
7177 +
7178 + /** @ref MMAL_PARAMETER_BOOLEAN_T */
7179 + MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
7180 +
7181 + /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
7182 + MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
7183 +
7184 + /** @ref MMAL_PARAMETER_BYTES_T */
7185 + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
7186 +
7187 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
7188 + MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
7189 +
7190 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
7191 + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
7192 +
7193 + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
7194 + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
7195 +};
7196 +
7197 +/** Valid mirror modes */
7198 +enum mmal_parameter_mirror {
7199 + MMAL_PARAM_MIRROR_NONE,
7200 + MMAL_PARAM_MIRROR_VERTICAL,
7201 + MMAL_PARAM_MIRROR_HORIZONTAL,
7202 + MMAL_PARAM_MIRROR_BOTH,
7203 +};
7204 +
7205 +enum mmal_parameter_displaytransform {
7206 + MMAL_DISPLAY_ROT0 = 0,
7207 + MMAL_DISPLAY_MIRROR_ROT0 = 1,
7208 + MMAL_DISPLAY_MIRROR_ROT180 = 2,
7209 + MMAL_DISPLAY_ROT180 = 3,
7210 + MMAL_DISPLAY_MIRROR_ROT90 = 4,
7211 + MMAL_DISPLAY_ROT270 = 5,
7212 + MMAL_DISPLAY_ROT90 = 6,
7213 + MMAL_DISPLAY_MIRROR_ROT270 = 7,
7214 +};
7215 +
7216 +enum mmal_parameter_displaymode {
7217 + MMAL_DISPLAY_MODE_FILL = 0,
7218 + MMAL_DISPLAY_MODE_LETTERBOX = 1,
7219 +};
7220 +
7221 +enum mmal_parameter_displayset {
7222 + MMAL_DISPLAY_SET_NONE = 0,
7223 + MMAL_DISPLAY_SET_NUM = 1,
7224 + MMAL_DISPLAY_SET_FULLSCREEN = 2,
7225 + MMAL_DISPLAY_SET_TRANSFORM = 4,
7226 + MMAL_DISPLAY_SET_DEST_RECT = 8,
7227 + MMAL_DISPLAY_SET_SRC_RECT = 0x10,
7228 + MMAL_DISPLAY_SET_MODE = 0x20,
7229 + MMAL_DISPLAY_SET_PIXEL = 0x40,
7230 + MMAL_DISPLAY_SET_NOASPECT = 0x80,
7231 + MMAL_DISPLAY_SET_LAYER = 0x100,
7232 + MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
7233 + MMAL_DISPLAY_SET_ALPHA = 0x400,
7234 +};
7235 +
7236 +/* rectangle, used lots so it gets its own struct */
7237 +struct vchiq_mmal_rect {
7238 + s32 x;
7239 + s32 y;
7240 + s32 width;
7241 + s32 height;
7242 +};
7243 +
7244 +struct mmal_parameter_displayregion {
7245 + /** Bitfield that indicates which fields are set and should be
7246 + * used. All other fields will maintain their current value.
7247 + * \ref MMAL_DISPLAYSET_T defines the bits that can be
7248 + * combined.
7249 + */
7250 + u32 set;
7251 +
7252 + /** Describes the display output device, with 0 typically
7253 + * being a directly connected LCD display. The actual values
7254 + * will depend on the hardware. Code using hard-wired numbers
7255 + * (e.g. 2) is certain to fail.
7256 + */
7257 +
7258 + u32 display_num;
7259 + /** Indicates that we are using the full device screen area,
7260 + * rather than a window of the display. If zero, then
7261 + * dest_rect is used to specify a region of the display to
7262 + * use.
7263 + */
7264 +
7265 + s32 fullscreen;
7266 + /** Indicates any rotation or flipping used to map frames onto
7267 + * the natural display orientation.
7268 + */
7269 + u32 transform; /* enum mmal_parameter_displaytransform */
7270 +
7271 + /** Where to display the frame within the screen, if
7272 + * fullscreen is zero.
7273 + */
7274 + struct vchiq_mmal_rect dest_rect;
7275 +
7276 + /** Indicates which area of the frame to display. If all
7277 + * values are zero, the whole frame will be used.
7278 + */
7279 + struct vchiq_mmal_rect src_rect;
7280 +
7281 + /** If set to non-zero, indicates that any display scaling
7282 + * should disregard the aspect ratio of the frame region being
7283 + * displayed.
7284 + */
7285 + s32 noaspect;
7286 +
7287 + /** Indicates how the image should be scaled to fit the
7288 + * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
7289 + * that the image should fill the screen by potentially
7290 + * cropping the frames. Setting \code mode \endcode to \code
7291 + * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
7292 + * source region should be displayed and black bars added if
7293 + * necessary.
7294 + */
7295 + u32 mode; /* enum mmal_parameter_displaymode */
7296 +
7297 + /** If non-zero, defines the width of a source pixel relative
7298 + * to \code pixel_y \endcode. If zero, then pixels default to
7299 + * being square.
7300 + */
7301 + u32 pixel_x;
7302 +
7303 + /** If non-zero, defines the height of a source pixel relative
7304 + * to \code pixel_x \endcode. If zero, then pixels default to
7305 + * being square.
7306 + */
7307 + u32 pixel_y;
7308 +
7309 + /** Sets the relative depth of the images, with greater values
7310 + * being in front of smaller values.
7311 + */
7312 + u32 layer;
7313 +
7314 + /** Set to non-zero to ensure copy protection is used on
7315 + * output.
7316 + */
7317 + s32 copyprotect_required;
7318 +
7319 + /** Level of opacity of the layer, where zero is fully
7320 + * transparent and 255 is fully opaque.
7321 + */
7322 + u32 alpha;
7323 +};
7324 +
7325 +#define MMAL_MAX_IMAGEFX_PARAMETERS 5
7326 +
7327 +struct mmal_parameter_imagefx_parameters {
7328 + enum mmal_parameter_imagefx effect;
7329 + u32 num_effect_params;
7330 + u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
7331 +};
7332 +
7333 +#define MMAL_PARAMETER_CAMERA_INFO_MAX_CAMERAS 4
7334 +#define MMAL_PARAMETER_CAMERA_INFO_MAX_FLASHES 2
7335 +#define MMAL_PARAMETER_CAMERA_INFO_MAX_STR_LEN 16
7336 +
7337 +struct mmal_parameter_camera_info_camera_t {
7338 + u32 port_id;
7339 + u32 max_width;
7340 + u32 max_height;
7341 + u32 lens_present;
7342 + u8 camera_name[MMAL_PARAMETER_CAMERA_INFO_MAX_STR_LEN];
7343 +};
7344 +
7345 +enum mmal_parameter_camera_info_flash_type_t {
7346 + /* Make values explicit to ensure they match values in config ini */
7347 + MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_XENON = 0,
7348 + MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_LED = 1,
7349 + MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_OTHER = 2,
7350 + MMAL_PARAMETER_CAMERA_INFO_FLASH_TYPE_MAX = 0x7FFFFFFF
7351 +};
7352 +
7353 +struct mmal_parameter_camera_info_flash_t {
7354 + enum mmal_parameter_camera_info_flash_type_t flash_type;
7355 +};
7356 +
7357 +struct mmal_parameter_camera_info_t {
7358 + u32 num_cameras;
7359 + u32 num_flashes;
7360 + struct mmal_parameter_camera_info_camera_t
7361 + cameras[MMAL_PARAMETER_CAMERA_INFO_MAX_CAMERAS];
7362 + struct mmal_parameter_camera_info_flash_t
7363 + flashes[MMAL_PARAMETER_CAMERA_INFO_MAX_FLASHES];
7364 +};
7365 +
7366 +#endif
7367 --- /dev/null
7368 +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.h
7369 @@ -0,0 +1,166 @@
7370 +/* SPDX-License-Identifier: GPL-2.0 */
7371 +/*
7372 + * Broadcom BM2835 V4L2 driver
7373 + *
7374 + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
7375 + *
7376 + * Authors: Vincent Sanders @ Collabora
7377 + * Dave Stevenson @ Broadcom
7378 + * (now dave.stevenson@raspberrypi.org)
7379 + * Simon Mellor @ Broadcom
7380 + * Luke Diamand @ Broadcom
7381 + *
7382 + * MMAL interface to VCHIQ message passing
7383 + */
7384 +
7385 +#ifndef MMAL_VCHIQ_H
7386 +#define MMAL_VCHIQ_H
7387 +
7388 +#include "mmal-msg-format.h"
7389 +
7390 +#define MAX_PORT_COUNT 4
7391 +
7392 +/* Maximum size of the format extradata. */
7393 +#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
7394 +
7395 +struct vchiq_mmal_instance;
7396 +
7397 +enum vchiq_mmal_es_type {
7398 + MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
7399 + MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
7400 + MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
7401 + MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
7402 + MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
7403 +};
7404 +
7405 +struct vchiq_mmal_port_buffer {
7406 + unsigned int num; /* number of buffers */
7407 + u32 size; /* size of buffers */
7408 + u32 alignment; /* alignment of buffers */
7409 +};
7410 +
7411 +struct vchiq_mmal_port;
7412 +
7413 +typedef void (*vchiq_mmal_buffer_cb)(
7414 + struct vchiq_mmal_instance *instance,
7415 + struct vchiq_mmal_port *port,
7416 + int status, struct mmal_buffer *buffer,
7417 + unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
7418 +
7419 +struct vchiq_mmal_port {
7420 + bool enabled;
7421 + u32 handle;
7422 + u32 type; /* port type, cached to use on port info set */
7423 + u32 index; /* port index, cached to use on port info set */
7424 +
7425 + /* component port belongs to, allows simple deref */
7426 + struct vchiq_mmal_component *component;
7427 +
7428 + struct vchiq_mmal_port *connected; /* port conencted to */
7429 +
7430 + /* buffer info */
7431 + struct vchiq_mmal_port_buffer minimum_buffer;
7432 + struct vchiq_mmal_port_buffer recommended_buffer;
7433 + struct vchiq_mmal_port_buffer current_buffer;
7434 +
7435 + /* stream format */
7436 + struct mmal_es_format_local format;
7437 + /* elementary stream format */
7438 + union mmal_es_specific_format es;
7439 +
7440 + /* data buffers to fill */
7441 + struct list_head buffers;
7442 + /* lock to serialise adding and removing buffers from list */
7443 + spinlock_t slock;
7444 +
7445 + /* Count of buffers the VPU has yet to return */
7446 + atomic_t buffers_with_vpu;
7447 + /* callback on buffer completion */
7448 + vchiq_mmal_buffer_cb buffer_cb;
7449 + /* callback context */
7450 + void *cb_ctx;
7451 +};
7452 +
7453 +struct vchiq_mmal_component {
7454 + bool enabled;
7455 + u32 handle; /* VideoCore handle for component */
7456 + u32 inputs; /* Number of input ports */
7457 + u32 outputs; /* Number of output ports */
7458 + u32 clocks; /* Number of clock ports */
7459 + struct vchiq_mmal_port control; /* control port */
7460 + struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
7461 + struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
7462 + struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
7463 +};
7464 +
7465 +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
7466 +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
7467 +
7468 +/* Initialise a mmal component and its ports
7469 + *
7470 + */
7471 +int vchiq_mmal_component_init(
7472 + struct vchiq_mmal_instance *instance,
7473 + const char *name,
7474 + struct vchiq_mmal_component **component_out);
7475 +
7476 +int vchiq_mmal_component_finalise(
7477 + struct vchiq_mmal_instance *instance,
7478 + struct vchiq_mmal_component *component);
7479 +
7480 +int vchiq_mmal_component_enable(
7481 + struct vchiq_mmal_instance *instance,
7482 + struct vchiq_mmal_component *component);
7483 +
7484 +int vchiq_mmal_component_disable(
7485 + struct vchiq_mmal_instance *instance,
7486 + struct vchiq_mmal_component *component);
7487 +
7488 +/* enable a mmal port
7489 + *
7490 + * enables a port and if a buffer callback provided enque buffer
7491 + * headers as appropriate for the port.
7492 + */
7493 +int vchiq_mmal_port_enable(
7494 + struct vchiq_mmal_instance *instance,
7495 + struct vchiq_mmal_port *port,
7496 + vchiq_mmal_buffer_cb buffer_cb);
7497 +
7498 +/* disable a port
7499 + *
7500 + * disable a port will dequeue any pending buffers
7501 + */
7502 +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
7503 + struct vchiq_mmal_port *port);
7504 +
7505 +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
7506 + struct vchiq_mmal_port *port,
7507 + u32 parameter,
7508 + void *value,
7509 + u32 value_size);
7510 +
7511 +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
7512 + struct vchiq_mmal_port *port,
7513 + u32 parameter,
7514 + void *value,
7515 + u32 *value_size);
7516 +
7517 +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
7518 + struct vchiq_mmal_port *port);
7519 +
7520 +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
7521 + struct vchiq_mmal_port *src,
7522 + struct vchiq_mmal_port *dst);
7523 +
7524 +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
7525 + u32 *major_out,
7526 + u32 *minor_out);
7527 +
7528 +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
7529 + struct vchiq_mmal_port *port,
7530 + struct mmal_buffer *buf);
7531 +
7532 +int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance,
7533 + struct mmal_buffer *buf);
7534 +int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf);
7535 +#endif /* MMAL_VCHIQ_H */