1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | /* |
3 | * Broadcom BCM2835 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 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 | bool enabled; |
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 connected 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 | bool in_use; |
86 | bool enabled; |
87 | u32 handle; /* VideoCore handle for component */ |
88 | u32 inputs; /* Number of input ports */ |
89 | u32 outputs; /* Number of output ports */ |
90 | u32 clocks; /* Number of clock ports */ |
91 | struct vchiq_mmal_port control; /* control port */ |
92 | struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */ |
93 | struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */ |
94 | struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */ |
95 | u32 client_component; /* Used to ref back to client struct */ |
96 | }; |
97 | |
98 | int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance); |
99 | int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance); |
100 | |
101 | /* Initialise a mmal component and its ports |
102 | * |
103 | */ |
104 | int vchiq_mmal_component_init( |
105 | struct vchiq_mmal_instance *instance, |
106 | const char *name, |
107 | struct vchiq_mmal_component **component_out); |
108 | |
109 | int vchiq_mmal_component_finalise( |
110 | struct vchiq_mmal_instance *instance, |
111 | struct vchiq_mmal_component *component); |
112 | |
113 | int vchiq_mmal_component_enable( |
114 | struct vchiq_mmal_instance *instance, |
115 | struct vchiq_mmal_component *component); |
116 | |
117 | int vchiq_mmal_component_disable( |
118 | struct vchiq_mmal_instance *instance, |
119 | struct vchiq_mmal_component *component); |
120 | |
121 | /* enable a mmal port |
122 | * |
123 | * enables a port and if a buffer callback provided enque buffer |
124 | * headers as appropriate for the port. |
125 | */ |
126 | int vchiq_mmal_port_enable( |
127 | struct vchiq_mmal_instance *instance, |
128 | struct vchiq_mmal_port *port, |
129 | vchiq_mmal_buffer_cb buffer_cb); |
130 | |
131 | /* disable a port |
132 | * |
133 | * disable a port will dequeue any pending buffers |
134 | */ |
135 | int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance, |
136 | struct vchiq_mmal_port *port); |
137 | |
138 | int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance, |
139 | struct vchiq_mmal_port *port, |
140 | u32 parameter, |
141 | void *value, |
142 | u32 value_size); |
143 | |
144 | int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance, |
145 | struct vchiq_mmal_port *port, |
146 | u32 parameter, |
147 | void *value, |
148 | u32 *value_size); |
149 | |
150 | int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance, |
151 | struct vchiq_mmal_port *port); |
152 | |
153 | int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance, |
154 | struct vchiq_mmal_port *src, |
155 | struct vchiq_mmal_port *dst); |
156 | |
157 | int vchiq_mmal_version(struct vchiq_mmal_instance *instance, |
158 | u32 *major_out, |
159 | u32 *minor_out); |
160 | |
161 | int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance, |
162 | struct vchiq_mmal_port *port, |
163 | struct mmal_buffer *buf); |
164 | |
165 | int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance, |
166 | struct mmal_buffer *buf); |
167 | int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf); |
168 | #endif /* MMAL_VCHIQ_H */ |
169 | |