1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Broadcom BM2835 V4L2 driver
5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
7 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
8 * Dave Stevenson <dsteve@broadcom.com>
9 * Simon Mellor <simellor@broadcom.com>
10 * Luke Diamand <luked@broadcom.com>
12 * MMAL interface to VCHIQ message passing
18 #include "mmal-msg-format.h"
20 #define MAX_PORT_COUNT 4
22 /* Maximum size of the format extradata. */
23 #define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
25 struct vchiq_mmal_instance;
27 enum vchiq_mmal_es_type {
28 MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
29 MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
30 MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
31 MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
32 MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
35 struct vchiq_mmal_port_buffer {
36 unsigned int num; /* number of buffers */
37 u32 size; /* size of buffers */
38 u32 alignment; /* alignment of buffers */
41 struct vchiq_mmal_port;
43 typedef void (*vchiq_mmal_buffer_cb)(
44 struct vchiq_mmal_instance *instance,
45 struct vchiq_mmal_port *port,
46 int status, struct mmal_buffer *buffer,
47 unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
49 struct vchiq_mmal_port {
52 u32 type; /* port type, cached to use on port info set */
53 u32 index; /* port index, cached to use on port info set */
55 /* component port belongs to, allows simple deref */
56 struct vchiq_mmal_component *component;
58 struct vchiq_mmal_port *connected; /* port conencted to */
61 struct vchiq_mmal_port_buffer minimum_buffer;
62 struct vchiq_mmal_port_buffer recommended_buffer;
63 struct vchiq_mmal_port_buffer current_buffer;
66 struct mmal_es_format_local format;
67 /* elementary stream format */
68 union mmal_es_specific_format es;
70 /* data buffers to fill */
71 struct list_head buffers;
72 /* lock to serialise adding and removing buffers from list */
75 /* Count of buffers the VPU has yet to return */
76 atomic_t buffers_with_vpu;
77 /* callback on buffer completion */
78 vchiq_mmal_buffer_cb buffer_cb;
79 /* callback context */
83 struct vchiq_mmal_component {
85 u32 handle; /* VideoCore handle for component */
86 u32 inputs; /* Number of input ports */
87 u32 outputs; /* Number of output ports */
88 u32 clocks; /* Number of clock ports */
89 struct vchiq_mmal_port control; /* control port */
90 struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
91 struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
92 struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
95 int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
96 int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
98 /* Initialise a mmal component and its ports
101 int vchiq_mmal_component_init(
102 struct vchiq_mmal_instance *instance,
104 struct vchiq_mmal_component **component_out);
106 int vchiq_mmal_component_finalise(
107 struct vchiq_mmal_instance *instance,
108 struct vchiq_mmal_component *component);
110 int vchiq_mmal_component_enable(
111 struct vchiq_mmal_instance *instance,
112 struct vchiq_mmal_component *component);
114 int vchiq_mmal_component_disable(
115 struct vchiq_mmal_instance *instance,
116 struct vchiq_mmal_component *component);
118 /* enable a mmal port
120 * enables a port and if a buffer callback provided enque buffer
121 * headers as appropriate for the port.
123 int vchiq_mmal_port_enable(
124 struct vchiq_mmal_instance *instance,
125 struct vchiq_mmal_port *port,
126 vchiq_mmal_buffer_cb buffer_cb);
130 * disable a port will dequeue any pending buffers
132 int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
133 struct vchiq_mmal_port *port);
135 int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
136 struct vchiq_mmal_port *port,
141 int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
142 struct vchiq_mmal_port *port,
147 int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
148 struct vchiq_mmal_port *port);
150 int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
151 struct vchiq_mmal_port *src,
152 struct vchiq_mmal_port *dst);
154 int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
158 int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
159 struct vchiq_mmal_port *port,
160 struct mmal_buffer *buf);
162 int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance,
163 struct mmal_buffer *buf);
164 int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf);
165 #endif /* MMAL_VCHIQ_H */