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