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