GNU Linux-libre 4.19.286-gnu1
[releases.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 <vincent.sanders@collabora.co.uk>
8  *          Dave Stevenson <dsteve@broadcom.com>
9  *          Simon Mellor <simellor@broadcom.com>
10  *          Luke Diamand <luked@broadcom.com>
11  *
12  * MMAL interface to VCHIQ message passing
13  */
14
15 #ifndef MMAL_VCHIQ_H
16 #define MMAL_VCHIQ_H
17
18 #include "mmal-msg-format.h"
19
20 #define MAX_PORT_COUNT 4
21
22 /* Maximum size of the format extradata. */
23 #define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
24
25 struct vchiq_mmal_instance;
26
27 enum vchiq_mmal_es_type {
28         MMAL_ES_TYPE_UNKNOWN,     /**< Unknown elementary stream type */
29         MMAL_ES_TYPE_CONTROL,     /**< Elementary stream of control commands */
30         MMAL_ES_TYPE_AUDIO,       /**< Audio elementary stream */
31         MMAL_ES_TYPE_VIDEO,       /**< Video elementary stream */
32         MMAL_ES_TYPE_SUBPICTURE   /**< Sub-picture elementary stream */
33 };
34
35 struct vchiq_mmal_port_buffer {
36         unsigned int num; /* number of buffers */
37         u32 size; /* size of buffers */
38         u32 alignment; /* alignment of buffers */
39 };
40
41 struct vchiq_mmal_port;
42
43 typedef void (*vchiq_mmal_buffer_cb)(
44                 struct vchiq_mmal_instance  *instance,
45                 struct vchiq_mmal_port *port,
46                 int status, struct mmal_buffer *buffer,
47                 unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
48
49 struct vchiq_mmal_port {
50         bool enabled;
51         u32 handle;
52         u32 type; /* port type, cached to use on port info set */
53         u32 index; /* port index, cached to use on port info set */
54
55         /* component port belongs to, allows simple deref */
56         struct vchiq_mmal_component *component;
57
58         struct vchiq_mmal_port *connected; /* port conencted to */
59
60         /* buffer info */
61         struct vchiq_mmal_port_buffer minimum_buffer;
62         struct vchiq_mmal_port_buffer recommended_buffer;
63         struct vchiq_mmal_port_buffer current_buffer;
64
65         /* stream format */
66         struct mmal_es_format_local format;
67         /* elementary stream format */
68         union mmal_es_specific_format es;
69
70         /* data buffers to fill */
71         struct list_head buffers;
72         /* lock to serialise adding and removing buffers from list */
73         spinlock_t slock;
74
75         /* Count of buffers the VPU has yet to return */
76         atomic_t buffers_with_vpu;
77         /* callback on buffer completion */
78         vchiq_mmal_buffer_cb buffer_cb;
79         /* callback context */
80         void *cb_ctx;
81 };
82
83 struct vchiq_mmal_component {
84         bool enabled;
85         u32 handle;  /* VideoCore handle for component */
86         u32 inputs;  /* Number of input ports */
87         u32 outputs; /* Number of output ports */
88         u32 clocks;  /* Number of clock ports */
89         struct vchiq_mmal_port control; /* control port */
90         struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
91         struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
92         struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
93 };
94
95 int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
96 int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
97
98 /* Initialise a mmal component and its ports
99  *
100  */
101 int vchiq_mmal_component_init(
102                 struct vchiq_mmal_instance *instance,
103                 const char *name,
104                 struct vchiq_mmal_component **component_out);
105
106 int vchiq_mmal_component_finalise(
107                 struct vchiq_mmal_instance *instance,
108                 struct vchiq_mmal_component *component);
109
110 int vchiq_mmal_component_enable(
111                 struct vchiq_mmal_instance *instance,
112                 struct vchiq_mmal_component *component);
113
114 int vchiq_mmal_component_disable(
115                 struct vchiq_mmal_instance *instance,
116                 struct vchiq_mmal_component *component);
117
118 /* enable a mmal port
119  *
120  * enables a port and if a buffer callback provided enque buffer
121  * headers as appropriate for the port.
122  */
123 int vchiq_mmal_port_enable(
124                 struct vchiq_mmal_instance *instance,
125                 struct vchiq_mmal_port *port,
126                 vchiq_mmal_buffer_cb buffer_cb);
127
128 /* disable a port
129  *
130  * disable a port will dequeue any pending buffers
131  */
132 int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
133                            struct vchiq_mmal_port *port);
134
135 int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
136                                   struct vchiq_mmal_port *port,
137                                   u32 parameter,
138                                   void *value,
139                                   u32 value_size);
140
141 int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
142                                   struct vchiq_mmal_port *port,
143                                   u32 parameter,
144                                   void *value,
145                                   u32 *value_size);
146
147 int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
148                                struct vchiq_mmal_port *port);
149
150 int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
151                             struct vchiq_mmal_port *src,
152                             struct vchiq_mmal_port *dst);
153
154 int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
155                        u32 *major_out,
156                        u32 *minor_out);
157
158 int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
159                              struct vchiq_mmal_port *port,
160                              struct mmal_buffer *buf);
161
162 int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance,
163                           struct mmal_buffer *buf);
164 int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf);
165 #endif /* MMAL_VCHIQ_H */