Linux-libre 5.3.12-gnu
[librecmc/linux-libre.git] / drivers / staging / vc04_services / bcm2835-camera / mmal-vchiq.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Broadcom BM2835 V4L2 driver
4  *
5  * Copyright © 2013 Raspberry Pi (Trading) Ltd.
6  *
7  * Authors: Vincent Sanders @ Collabora
8  *          Dave Stevenson @ Broadcom
9  *              (now dave.stevenson@raspberrypi.org)
10  *          Simon Mellor @ Broadcom
11  *          Luke Diamand @ Broadcom
12  *
13  * MMAL interface to VCHIQ message passing
14  */
15
16 #ifndef MMAL_VCHIQ_H
17 #define MMAL_VCHIQ_H
18
19 #include "mmal-msg-format.h"
20
21 #define MAX_PORT_COUNT 4
22
23 /* Maximum size of the format extradata. */
24 #define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
25
26 struct vchiq_mmal_instance;
27
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 */
34 };
35
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 */
40 };
41
42 struct vchiq_mmal_port;
43
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);
49
50 struct vchiq_mmal_port {
51         u32 enabled:1;
52         u32 handle;
53         u32 type; /* port type, cached to use on port info set */
54         u32 index; /* port index, cached to use on port info set */
55
56         /* component port belongs to, allows simple deref */
57         struct vchiq_mmal_component *component;
58
59         struct vchiq_mmal_port *connected; /* port conencted to */
60
61         /* buffer info */
62         struct vchiq_mmal_port_buffer minimum_buffer;
63         struct vchiq_mmal_port_buffer recommended_buffer;
64         struct vchiq_mmal_port_buffer current_buffer;
65
66         /* stream format */
67         struct mmal_es_format_local format;
68         /* elementary stream format */
69         union mmal_es_specific_format es;
70
71         /* data buffers to fill */
72         struct list_head buffers;
73         /* lock to serialise adding and removing buffers from list */
74         spinlock_t slock;
75
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 */
81         void *cb_ctx;
82 };
83
84 struct vchiq_mmal_component {
85         u32 enabled:1;
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 */
94 };
95
96 int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
97 int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
98
99 /* Initialise a mmal component and its ports
100  *
101  */
102 int vchiq_mmal_component_init(
103                 struct vchiq_mmal_instance *instance,
104                 const char *name,
105                 struct vchiq_mmal_component **component_out);
106
107 int vchiq_mmal_component_finalise(
108                 struct vchiq_mmal_instance *instance,
109                 struct vchiq_mmal_component *component);
110
111 int vchiq_mmal_component_enable(
112                 struct vchiq_mmal_instance *instance,
113                 struct vchiq_mmal_component *component);
114
115 int vchiq_mmal_component_disable(
116                 struct vchiq_mmal_instance *instance,
117                 struct vchiq_mmal_component *component);
118
119 /* enable a mmal port
120  *
121  * enables a port and if a buffer callback provided enque buffer
122  * headers as appropriate for the port.
123  */
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);
128
129 /* disable a port
130  *
131  * disable a port will dequeue any pending buffers
132  */
133 int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
134                             struct vchiq_mmal_port *port);
135
136 int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
137                                   struct vchiq_mmal_port *port,
138                                   u32 parameter,
139                                   void *value,
140                                   u32 value_size);
141
142 int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
143                                   struct vchiq_mmal_port *port,
144                                   u32 parameter,
145                                   void *value,
146                                   u32 *value_size);
147
148 int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
149                                struct vchiq_mmal_port *port);
150
151 int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
152                                    struct vchiq_mmal_port *src,
153                                    struct vchiq_mmal_port *dst);
154
155 int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
156                        u32 *major_out,
157                        u32 *minor_out);
158
159 int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
160                              struct vchiq_mmal_port *port,
161                              struct mmal_buffer *buf);
162
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 */