1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Broadcom BM2835 V4L2 driver
5 * Copyright © 2013 Raspberry Pi (Trading) Ltd.
7 * Authors: Vincent Sanders @ Collabora
8 * Dave Stevenson @ Broadcom
9 * (now dave.stevenson@raspberrypi.org)
10 * Simon Mellor @ Broadcom
11 * Luke Diamand @ Broadcom
13 * MMAL interface to VCHIQ message passing
19 #include "mmal-common.h"
20 #include "mmal-msg-format.h"
22 #define MAX_PORT_COUNT 4
24 /* Maximum size of the format extradata. */
25 #define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
27 struct vchiq_mmal_instance;
29 enum vchiq_mmal_es_type {
30 MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
31 MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
32 MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
33 MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
34 MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
37 struct vchiq_mmal_port_buffer {
38 unsigned int num; /* number of buffers */
39 u32 size; /* size of buffers */
40 u32 alignment; /* alignment of buffers */
43 struct vchiq_mmal_port;
45 typedef void (*vchiq_mmal_buffer_cb)(
46 struct vchiq_mmal_instance *instance,
47 struct vchiq_mmal_port *port,
48 int status, struct mmal_buffer *buffer);
50 struct vchiq_mmal_port {
54 u32 type; /* port type, cached to use on port info set */
55 u32 index; /* port index, cached to use on port info set */
57 /* component port belongs to, allows simple deref */
58 struct vchiq_mmal_component *component;
60 struct vchiq_mmal_port *connected; /* port connected to */
63 struct vchiq_mmal_port_buffer minimum_buffer;
64 struct vchiq_mmal_port_buffer recommended_buffer;
65 struct vchiq_mmal_port_buffer current_buffer;
68 struct mmal_es_format_local format;
69 /* elementary stream format */
70 union mmal_es_specific_format es;
72 /* data buffers to fill */
73 struct list_head buffers;
74 /* lock to serialise adding and removing buffers from list */
77 /* Count of buffers the VPU has yet to return */
78 atomic_t buffers_with_vpu;
79 /* callback on buffer completion */
80 vchiq_mmal_buffer_cb buffer_cb;
81 /* callback context */
84 /* ensure serialised use of the one event context structure */
85 struct mutex event_context_mutex;
86 struct mmal_msg_context *event_context;
89 struct vchiq_mmal_component {
92 u32 handle; /* VideoCore handle for component */
93 u32 inputs; /* Number of input ports */
94 u32 outputs; /* Number of output ports */
95 u32 clocks; /* Number of clock ports */
96 struct vchiq_mmal_port control; /* control port */
97 struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
98 struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
99 struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
100 u32 client_component; /* Used to ref back to client struct */
103 int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
104 int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
106 /* Initialise a mmal component and its ports
109 int vchiq_mmal_component_init(
110 struct vchiq_mmal_instance *instance,
112 struct vchiq_mmal_component **component_out);
114 int vchiq_mmal_component_finalise(
115 struct vchiq_mmal_instance *instance,
116 struct vchiq_mmal_component *component);
118 int vchiq_mmal_component_enable(
119 struct vchiq_mmal_instance *instance,
120 struct vchiq_mmal_component *component);
122 int vchiq_mmal_component_disable(
123 struct vchiq_mmal_instance *instance,
124 struct vchiq_mmal_component *component);
126 /* enable a mmal port
128 * enables a port and if a buffer callback provided enque buffer
129 * headers as appropriate for the port.
131 int vchiq_mmal_port_enable(
132 struct vchiq_mmal_instance *instance,
133 struct vchiq_mmal_port *port,
134 vchiq_mmal_buffer_cb buffer_cb);
138 * disable a port will dequeue any pending buffers
140 int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
141 struct vchiq_mmal_port *port);
143 int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
144 struct vchiq_mmal_port *port,
149 int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
150 struct vchiq_mmal_port *port,
155 int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
156 struct vchiq_mmal_port *port);
158 int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
159 struct vchiq_mmal_port *src,
160 struct vchiq_mmal_port *dst);
162 int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
166 int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
167 struct vchiq_mmal_port *port,
168 struct mmal_buffer *buf);
170 int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance,
171 struct mmal_buffer *buf);
172 int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf);
173 #endif /* MMAL_VCHIQ_H */