Linux-libre 4.14.145-gnu
[librecmc/linux-libre.git] / drivers / staging / vc04_services / bcm2835-camera / mmal-vchiq.h
1 /*
2  * Broadcom BM2835 V4L2 driver
3  *
4  * Copyright © 2013 Raspberry Pi (Trading) Ltd.
5  *
6  * This file is subject to the terms and conditions of the GNU General Public
7  * License.  See the file COPYING in the main directory of this archive
8  * for more details.
9  *
10  * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
11  *          Dave Stevenson <dsteve@broadcom.com>
12  *          Simon Mellor <simellor@broadcom.com>
13  *          Luke Diamand <luked@broadcom.com>
14  *
15  * MMAL interface to VCHIQ message passing
16  */
17
18 #ifndef MMAL_VCHIQ_H
19 #define MMAL_VCHIQ_H
20
21 #include "mmal-msg-format.h"
22
23 #define MAX_PORT_COUNT 4
24
25 /* Maximum size of the format extradata. */
26 #define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
27
28 struct vchiq_mmal_instance;
29
30 enum vchiq_mmal_es_type {
31         MMAL_ES_TYPE_UNKNOWN,     /**< Unknown elementary stream type */
32         MMAL_ES_TYPE_CONTROL,     /**< Elementary stream of control commands */
33         MMAL_ES_TYPE_AUDIO,       /**< Audio elementary stream */
34         MMAL_ES_TYPE_VIDEO,       /**< Video elementary stream */
35         MMAL_ES_TYPE_SUBPICTURE   /**< Sub-picture elementary stream */
36 };
37
38 /* rectangle, used lots so it gets its own struct */
39 struct vchiq_mmal_rect {
40         s32 x;
41         s32 y;
42         s32 width;
43         s32 height;
44 };
45
46 struct vchiq_mmal_port_buffer {
47         unsigned int num; /* number of buffers */
48         u32 size; /* size of buffers */
49         u32 alignment; /* alignment of buffers */
50 };
51
52 struct vchiq_mmal_port;
53
54 typedef void (*vchiq_mmal_buffer_cb)(
55                 struct vchiq_mmal_instance  *instance,
56                 struct vchiq_mmal_port *port,
57                 int status, struct mmal_buffer *buffer,
58                 unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
59
60 struct vchiq_mmal_port {
61         bool enabled;
62         u32 handle;
63         u32 type; /* port type, cached to use on port info set */
64         u32 index; /* port index, cached to use on port info set */
65
66         /* component port belongs to, allows simple deref */
67         struct vchiq_mmal_component *component;
68
69         struct vchiq_mmal_port *connected; /* port conencted to */
70
71         /* buffer info */
72         struct vchiq_mmal_port_buffer minimum_buffer;
73         struct vchiq_mmal_port_buffer recommended_buffer;
74         struct vchiq_mmal_port_buffer current_buffer;
75
76         /* stream format */
77         struct mmal_es_format_local format;
78         /* elementary stream format */
79         union mmal_es_specific_format es;
80
81         /* data buffers to fill */
82         struct list_head buffers;
83         /* lock to serialise adding and removing buffers from list */
84         spinlock_t slock;
85         /* count of how many buffer header refils have failed because
86          * there was no buffer to satisfy them
87          */
88         int buffer_underflow;
89         /* callback on buffer completion */
90         vchiq_mmal_buffer_cb buffer_cb;
91         /* callback context */
92         void *cb_ctx;
93 };
94
95 struct vchiq_mmal_component {
96         bool enabled;
97         u32 handle;  /* VideoCore handle for component */
98         u32 inputs;  /* Number of input ports */
99         u32 outputs; /* Number of output ports */
100         u32 clocks;  /* Number of clock ports */
101         struct vchiq_mmal_port control; /* control port */
102         struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
103         struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
104         struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
105 };
106
107 int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
108 int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
109
110 /* Initialise a mmal component and its ports
111  *
112  */
113 int vchiq_mmal_component_init(
114                 struct vchiq_mmal_instance *instance,
115                 const char *name,
116                 struct vchiq_mmal_component **component_out);
117
118 int vchiq_mmal_component_finalise(
119                 struct vchiq_mmal_instance *instance,
120                 struct vchiq_mmal_component *component);
121
122 int vchiq_mmal_component_enable(
123                 struct vchiq_mmal_instance *instance,
124                 struct vchiq_mmal_component *component);
125
126 int vchiq_mmal_component_disable(
127                 struct vchiq_mmal_instance *instance,
128                 struct vchiq_mmal_component *component);
129
130 /* enable a mmal port
131  *
132  * enables a port and if a buffer callback provided enque buffer
133  * headers as apropriate for the port.
134  */
135 int vchiq_mmal_port_enable(
136                 struct vchiq_mmal_instance *instance,
137                 struct vchiq_mmal_port *port,
138                 vchiq_mmal_buffer_cb buffer_cb);
139
140 /* disable a port
141  *
142  * disable a port will dequeue any pending buffers
143  */
144 int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
145                            struct vchiq_mmal_port *port);
146
147 int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
148                                   struct vchiq_mmal_port *port,
149                                   u32 parameter,
150                                   void *value,
151                                   u32 value_size);
152
153 int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
154                                   struct vchiq_mmal_port *port,
155                                   u32 parameter,
156                                   void *value,
157                                   u32 *value_size);
158
159 int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
160                                struct vchiq_mmal_port *port);
161
162 int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
163                             struct vchiq_mmal_port *src,
164                             struct vchiq_mmal_port *dst);
165
166 int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
167                        u32 *major_out,
168                        u32 *minor_out);
169
170 int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
171                              struct vchiq_mmal_port *port,
172                              struct mmal_buffer *buf);
173
174 #endif /* MMAL_VCHIQ_H */