Merge tag 'v5.15.57' into rpi-5.15.y
[platform/kernel/linux-rpi.git] / drivers / staging / vc04_services / vchiq-mmal / 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-common.h"
20 #include "mmal-msg-format.h"
21
22 #define MAX_PORT_COUNT 4
23
24 /* Maximum size of the format extradata. */
25 #define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
26
27 struct vchiq_mmal_instance;
28
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 */
35 };
36
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 */
41 };
42
43 struct vchiq_mmal_port;
44
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);
49
50 struct vchiq_mmal_port {
51         u32 enabled:1;
52         u32 zero_copy:1;
53         u32 handle;
54         u32 type; /* port type, cached to use on port info set */
55         u32 index; /* port index, cached to use on port info set */
56
57         /* component port belongs to, allows simple deref */
58         struct vchiq_mmal_component *component;
59
60         struct vchiq_mmal_port *connected; /* port connected to */
61
62         /* buffer info */
63         struct vchiq_mmal_port_buffer minimum_buffer;
64         struct vchiq_mmal_port_buffer recommended_buffer;
65         struct vchiq_mmal_port_buffer current_buffer;
66
67         /* stream format */
68         struct mmal_es_format_local format;
69         /* elementary stream format */
70         union mmal_es_specific_format es;
71
72         /* data buffers to fill */
73         struct list_head buffers;
74         /* lock to serialise adding and removing buffers from list */
75         spinlock_t slock;
76
77         /* Count of buffers the VPU has yet to return */
78         atomic_t buffers_with_vpu;
79         /* callback on buffer completion */
80         vchiq_mmal_buffer_cb buffer_cb;
81         /* callback context */
82         void *cb_ctx;
83
84         /* ensure serialised use of the one event context structure */
85         struct mutex event_context_mutex;
86         struct mmal_msg_context *event_context;
87 };
88
89 struct vchiq_mmal_component {
90         u32 in_use:1;
91         u32 enabled:1;
92         u32 handle;  /* VideoCore handle for component */
93         u32 inputs;  /* Number of input ports */
94         u32 outputs; /* Number of output ports */
95         u32 clocks;  /* Number of clock ports */
96         struct vchiq_mmal_port control; /* control port */
97         struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
98         struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
99         struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
100         u32 client_component;   /* Used to ref back to client struct */
101 };
102
103 int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
104 int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
105
106 /* Initialise a mmal component and its ports
107  *
108  */
109 int vchiq_mmal_component_init(
110                 struct vchiq_mmal_instance *instance,
111                 const char *name,
112                 struct vchiq_mmal_component **component_out);
113
114 int vchiq_mmal_component_finalise(
115                 struct vchiq_mmal_instance *instance,
116                 struct vchiq_mmal_component *component);
117
118 int vchiq_mmal_component_enable(
119                 struct vchiq_mmal_instance *instance,
120                 struct vchiq_mmal_component *component);
121
122 int vchiq_mmal_component_disable(
123                 struct vchiq_mmal_instance *instance,
124                 struct vchiq_mmal_component *component);
125
126 /* enable a mmal port
127  *
128  * enables a port and if a buffer callback provided enque buffer
129  * headers as appropriate for the port.
130  */
131 int vchiq_mmal_port_enable(
132                 struct vchiq_mmal_instance *instance,
133                 struct vchiq_mmal_port *port,
134                 vchiq_mmal_buffer_cb buffer_cb);
135
136 /* disable a port
137  *
138  * disable a port will dequeue any pending buffers
139  */
140 int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
141                             struct vchiq_mmal_port *port);
142
143 int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
144                                   struct vchiq_mmal_port *port,
145                                   u32 parameter,
146                                   void *value,
147                                   u32 value_size);
148
149 int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
150                                   struct vchiq_mmal_port *port,
151                                   u32 parameter,
152                                   void *value,
153                                   u32 *value_size);
154
155 int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
156                                struct vchiq_mmal_port *port);
157
158 int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
159                                    struct vchiq_mmal_port *src,
160                                    struct vchiq_mmal_port *dst);
161
162 int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
163                        u32 *major_out,
164                        u32 *minor_out);
165
166 int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
167                              struct vchiq_mmal_port *port,
168                              struct mmal_buffer *buf);
169
170 int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance,
171                           struct mmal_buffer *buf);
172 int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf);
173 #endif /* MMAL_VCHIQ_H */