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-msg-format.h"
21 #define MAX_PORT_COUNT 4
23 /* Maximum size of the format extradata. */
24 #define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
26 struct vchiq_mmal_instance;
28 enum vchiq_mmal_es_type {
29 MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
30 MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
31 MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
32 MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
33 MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
36 struct vchiq_mmal_port_buffer {
37 unsigned int num; /* number of buffers */
38 u32 size; /* size of buffers */
39 u32 alignment; /* alignment of buffers */
42 struct vchiq_mmal_port;
44 typedef void (*vchiq_mmal_buffer_cb)(
45 struct vchiq_mmal_instance *instance,
46 struct vchiq_mmal_port *port,
47 int status, struct mmal_buffer *buffer,
48 unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
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 conencted 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 {
86 u32 handle; /* VideoCore handle for component */
87 u32 inputs; /* Number of input ports */
88 u32 outputs; /* Number of output ports */
89 u32 clocks; /* Number of clock ports */
90 struct vchiq_mmal_port control; /* control port */
91 struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
92 struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
93 struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
96 int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
97 int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
99 /* Initialise a mmal component and its ports
102 int vchiq_mmal_component_init(
103 struct vchiq_mmal_instance *instance,
105 struct vchiq_mmal_component **component_out);
107 int vchiq_mmal_component_finalise(
108 struct vchiq_mmal_instance *instance,
109 struct vchiq_mmal_component *component);
111 int vchiq_mmal_component_enable(
112 struct vchiq_mmal_instance *instance,
113 struct vchiq_mmal_component *component);
115 int vchiq_mmal_component_disable(
116 struct vchiq_mmal_instance *instance,
117 struct vchiq_mmal_component *component);
119 /* enable a mmal port
121 * enables a port and if a buffer callback provided enque buffer
122 * headers as appropriate for the port.
124 int vchiq_mmal_port_enable(
125 struct vchiq_mmal_instance *instance,
126 struct vchiq_mmal_port *port,
127 vchiq_mmal_buffer_cb buffer_cb);
131 * disable a port will dequeue any pending buffers
133 int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
134 struct vchiq_mmal_port *port);
136 int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
137 struct vchiq_mmal_port *port,
142 int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
143 struct vchiq_mmal_port *port,
148 int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
149 struct vchiq_mmal_port *port);
151 int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
152 struct vchiq_mmal_port *src,
153 struct vchiq_mmal_port *dst);
155 int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
159 int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
160 struct vchiq_mmal_port *port,
161 struct mmal_buffer *buf);
163 int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance,
164 struct mmal_buffer *buf);
165 int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf);
166 #endif /* MMAL_VCHIQ_H */