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 {
53 u32 type; /* port type, cached to use on port info set */
54 u32 index; /* port index, cached to use on port info set */
56 /* component port belongs to, allows simple deref */
57 struct vchiq_mmal_component *component;
59 struct vchiq_mmal_port *connected; /* port connected to */
62 struct vchiq_mmal_port_buffer minimum_buffer;
63 struct vchiq_mmal_port_buffer recommended_buffer;
64 struct vchiq_mmal_port_buffer current_buffer;
67 struct mmal_es_format_local format;
68 /* elementary stream format */
69 union mmal_es_specific_format es;
71 /* data buffers to fill */
72 struct list_head buffers;
73 /* lock to serialise adding and removing buffers from list */
76 /* Count of buffers the VPU has yet to return */
77 atomic_t buffers_with_vpu;
78 /* callback on buffer completion */
79 vchiq_mmal_buffer_cb buffer_cb;
80 /* callback context */
84 struct vchiq_mmal_component {
87 u32 handle; /* VideoCore handle for component */
88 u32 inputs; /* Number of input ports */
89 u32 outputs; /* Number of output ports */
90 u32 clocks; /* Number of clock ports */
91 struct vchiq_mmal_port control; /* control port */
92 struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
93 struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
94 struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
95 u32 client_component; /* Used to ref back to client struct */
98 int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
99 int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
101 /* Initialise a mmal component and its ports
104 int vchiq_mmal_component_init(
105 struct vchiq_mmal_instance *instance,
107 struct vchiq_mmal_component **component_out);
109 int vchiq_mmal_component_finalise(
110 struct vchiq_mmal_instance *instance,
111 struct vchiq_mmal_component *component);
113 int vchiq_mmal_component_enable(
114 struct vchiq_mmal_instance *instance,
115 struct vchiq_mmal_component *component);
117 int vchiq_mmal_component_disable(
118 struct vchiq_mmal_instance *instance,
119 struct vchiq_mmal_component *component);
121 /* enable a mmal port
123 * enables a port and if a buffer callback provided enque buffer
124 * headers as appropriate for the port.
126 int vchiq_mmal_port_enable(
127 struct vchiq_mmal_instance *instance,
128 struct vchiq_mmal_port *port,
129 vchiq_mmal_buffer_cb buffer_cb);
133 * disable a port will dequeue any pending buffers
135 int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
136 struct vchiq_mmal_port *port);
138 int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
139 struct vchiq_mmal_port *port,
144 int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
145 struct vchiq_mmal_port *port,
150 int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
151 struct vchiq_mmal_port *port);
153 int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
154 struct vchiq_mmal_port *src,
155 struct vchiq_mmal_port *dst);
157 int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
161 int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
162 struct vchiq_mmal_port *port,
163 struct mmal_buffer *buf);
165 int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance,
166 struct mmal_buffer *buf);
167 int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf);
168 #endif /* MMAL_VCHIQ_H */