eb6538dff3532b8a56139c05e492754afb0e0b99
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-4.19 / 950-0389-staging-bcm2835-audio-Make-single-vchi-handle.patch
1 From 98a1612b199cb3060306c05d1a6d7ca18ef08475 Mon Sep 17 00:00:00 2001
2 From: Takashi Iwai <tiwai@suse.de>
3 Date: Tue, 4 Sep 2018 17:58:47 +0200
4 Subject: [PATCH] staging: bcm2835-audio: Make single vchi handle
5
6 commit 326a6edcb2ada56375bd7d3fc24c83f58e8da7f3 upstream.
7
8 The bcm2835_audio_instance object contains the array of
9 VCHI_SERVICE_HANDLE_T, while the code assumes and uses only the first
10 element explicitly. Let's reduce to a single vchi handle for
11 simplifying the code.
12
13 Signed-off-by: Takashi Iwai <tiwai@suse.de>
14 Tested-by: Stefan Wahren <stefan.wahren@i2se.com>
15 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
16 ---
17 .../bcm2835-audio/bcm2835-vchiq.c | 170 ++++++------------
18 1 file changed, 58 insertions(+), 112 deletions(-)
19
20 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
21 +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
22 @@ -44,8 +44,7 @@
23 #endif
24
25 struct bcm2835_audio_instance {
26 - unsigned int num_connections;
27 - VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
28 + VCHI_SERVICE_HANDLE_T vchi_handle;
29 struct completion msg_avail_comp;
30 struct mutex vchi_mutex;
31 struct bcm2835_alsa_stream *alsa_stream;
32 @@ -202,12 +201,12 @@ static void audio_vchi_callback(void *pa
33 BUG();
34 return;
35 }
36 - if (!instance->vchi_handle[0]) {
37 - LOG_ERR(" .. instance->vchi_handle[0] is null\n");
38 + if (!instance->vchi_handle) {
39 + LOG_ERR(" .. instance->vchi_handle is null\n");
40 BUG();
41 return;
42 }
43 - status = vchi_msg_dequeue(instance->vchi_handle[0],
44 + status = vchi_msg_dequeue(instance->vchi_handle,
45 &m, sizeof(m), &msg_len, VCHI_FLAGS_NONE);
46 if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
47 LOG_DBG(" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
48 @@ -237,102 +236,61 @@ static void audio_vchi_callback(void *pa
49
50 static struct bcm2835_audio_instance *
51 vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
52 - VCHI_CONNECTION_T **vchi_connections,
53 - unsigned int num_connections)
54 + VCHI_CONNECTION_T *vchi_connection)
55 {
56 - unsigned int i;
57 + SERVICE_CREATION_T params = {
58 + .version = VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
59 + .service_id = VC_AUDIO_SERVER_NAME,
60 + .connection = vchi_connection,
61 + .rx_fifo_size = 0,
62 + .tx_fifo_size = 0,
63 + .callback = audio_vchi_callback,
64 + .want_unaligned_bulk_rx = 1, //TODO: remove VCOS_FALSE
65 + .want_unaligned_bulk_tx = 1, //TODO: remove VCOS_FALSE
66 + .want_crc = 0
67 + };
68 struct bcm2835_audio_instance *instance;
69 int status;
70 - int ret;
71 -
72 - LOG_DBG("%s: start", __func__);
73
74 - if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
75 - LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
76 - __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
77 -
78 - return ERR_PTR(-EINVAL);
79 - }
80 /* Allocate memory for this instance */
81 instance = kzalloc(sizeof(*instance), GFP_KERNEL);
82 if (!instance)
83 return ERR_PTR(-ENOMEM);
84
85 - instance->num_connections = num_connections;
86 -
87 /* Create a lock for exclusive, serialized VCHI connection access */
88 mutex_init(&instance->vchi_mutex);
89 /* Open the VCHI service connections */
90 - for (i = 0; i < num_connections; i++) {
91 - SERVICE_CREATION_T params = {
92 - .version = VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
93 - .service_id = VC_AUDIO_SERVER_NAME,
94 - .connection = vchi_connections[i],
95 - .rx_fifo_size = 0,
96 - .tx_fifo_size = 0,
97 - .callback = audio_vchi_callback,
98 - .callback_param = instance,
99 - .want_unaligned_bulk_rx = 1, //TODO: remove VCOS_FALSE
100 - .want_unaligned_bulk_tx = 1, //TODO: remove VCOS_FALSE
101 - .want_crc = 0
102 - };
103 -
104 - LOG_DBG("%s: about to open %i\n", __func__, i);
105 - status = vchi_service_open(vchi_instance, &params,
106 - &instance->vchi_handle[i]);
107 + params.callback_param = instance,
108
109 - LOG_DBG("%s: opened %i: %p=%d\n", __func__, i, instance->vchi_handle[i], status);
110 - if (status) {
111 - LOG_ERR("%s: failed to open VCHI service connection (status=%d)\n",
112 - __func__, status);
113 - ret = -EPERM;
114 - goto err_close_services;
115 - }
116 - /* Finished with the service for now */
117 - vchi_service_release(instance->vchi_handle[i]);
118 - }
119 -
120 - LOG_DBG("%s: okay\n", __func__);
121 - return instance;
122 + status = vchi_service_open(vchi_instance, &params,
123 + &instance->vchi_handle);
124
125 -err_close_services:
126 - for (i = 0; i < instance->num_connections; i++) {
127 - LOG_ERR("%s: closing %i: %p\n", __func__, i, instance->vchi_handle[i]);
128 - if (instance->vchi_handle[i])
129 - vchi_service_close(instance->vchi_handle[i]);
130 + if (status) {
131 + LOG_ERR("%s: failed to open VCHI service connection (status=%d)\n",
132 + __func__, status);
133 + kfree(instance);
134 + return ERR_PTR(-EPERM);
135 }
136
137 - kfree(instance);
138 - LOG_ERR("%s: error\n", __func__);
139 + /* Finished with the service for now */
140 + vchi_service_release(instance->vchi_handle);
141
142 - return ERR_PTR(ret);
143 + return instance;
144 }
145
146 static int vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance)
147 {
148 - unsigned int i;
149 -
150 - if (!instance) {
151 - LOG_ERR("%s: invalid handle %p\n", __func__, instance);
152 -
153 - return -1;
154 - }
155 + int status;
156
157 - LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
158 mutex_lock(&instance->vchi_mutex);
159
160 /* Close all VCHI service connections */
161 - for (i = 0; i < instance->num_connections; i++) {
162 - int status;
163 -
164 - LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]);
165 - vchi_service_use(instance->vchi_handle[i]);
166 + vchi_service_use(instance->vchi_handle);
167
168 - status = vchi_service_close(instance->vchi_handle[i]);
169 - if (status) {
170 - LOG_DBG("%s: failed to close VCHI service connection (status=%d)\n",
171 - __func__, status);
172 - }
173 + status = vchi_service_close(instance->vchi_handle);
174 + if (status) {
175 + LOG_DBG("%s: failed to close VCHI service connection (status=%d)\n",
176 + __func__, status);
177 }
178
179 mutex_unlock(&instance->vchi_mutex);
180 @@ -383,19 +341,9 @@ static int bcm2835_audio_open_connection
181 (struct bcm2835_audio_instance *)alsa_stream->instance;
182 struct bcm2835_vchi_ctx *vhci_ctx = alsa_stream->chip->vchi_ctx;
183
184 - LOG_INFO("%s: start\n", __func__);
185 - BUG_ON(instance);
186 - if (instance) {
187 - LOG_ERR("%s: VCHI instance already open (%p)\n",
188 - __func__, instance);
189 - instance->alsa_stream = alsa_stream;
190 - alsa_stream->instance = instance;
191 - return 0;
192 - }
193 -
194 /* Initialize an instance of the audio service */
195 instance = vc_vchi_audio_init(vhci_ctx->vchi_instance,
196 - &vhci_ctx->vchi_connection, 1);
197 + vhci_ctx->vchi_connection);
198
199 if (IS_ERR(instance)) {
200 LOG_ERR("%s: failed to initialize audio service\n", __func__);
201 @@ -407,8 +355,6 @@ static int bcm2835_audio_open_connection
202 instance->alsa_stream = alsa_stream;
203 alsa_stream->instance = instance;
204
205 - LOG_DBG(" success !\n");
206 -
207 return 0;
208 }
209
210 @@ -431,12 +377,12 @@ int bcm2835_audio_open(struct bcm2835_al
211 LOG_DBG(" instance (%p)\n", instance);
212
213 mutex_lock(&instance->vchi_mutex);
214 - vchi_service_use(instance->vchi_handle[0]);
215 + vchi_service_use(instance->vchi_handle);
216
217 m.type = VC_AUDIO_MSG_TYPE_OPEN;
218
219 /* Send the message to the videocore */
220 - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
221 + status = bcm2835_vchi_msg_queue(instance->vchi_handle,
222 &m, sizeof(m));
223
224 if (status) {
225 @@ -450,7 +396,7 @@ int bcm2835_audio_open(struct bcm2835_al
226 ret = 0;
227
228 unlock:
229 - vchi_service_release(instance->vchi_handle[0]);
230 + vchi_service_release(instance->vchi_handle);
231 mutex_unlock(&instance->vchi_mutex);
232
233 free_wq:
234 @@ -472,7 +418,7 @@ int bcm2835_audio_set_ctls(struct bcm283
235 chip->dest, chip->volume);
236
237 mutex_lock(&instance->vchi_mutex);
238 - vchi_service_use(instance->vchi_handle[0]);
239 + vchi_service_use(instance->vchi_handle);
240
241 instance->result = -1;
242
243 @@ -487,7 +433,7 @@ int bcm2835_audio_set_ctls(struct bcm283
244 init_completion(&instance->msg_avail_comp);
245
246 /* Send the message to the videocore */
247 - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
248 + status = bcm2835_vchi_msg_queue(instance->vchi_handle,
249 &m, sizeof(m));
250
251 if (status) {
252 @@ -511,7 +457,7 @@ int bcm2835_audio_set_ctls(struct bcm283
253 ret = 0;
254
255 unlock:
256 - vchi_service_release(instance->vchi_handle[0]);
257 + vchi_service_release(instance->vchi_handle);
258 mutex_unlock(&instance->vchi_mutex);
259
260 return ret;
261 @@ -537,7 +483,7 @@ int bcm2835_audio_set_params(struct bcm2
262 }
263
264 mutex_lock(&instance->vchi_mutex);
265 - vchi_service_use(instance->vchi_handle[0]);
266 + vchi_service_use(instance->vchi_handle);
267
268 instance->result = -1;
269
270 @@ -550,7 +496,7 @@ int bcm2835_audio_set_params(struct bcm2
271 init_completion(&instance->msg_avail_comp);
272
273 /* Send the message to the videocore */
274 - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
275 + status = bcm2835_vchi_msg_queue(instance->vchi_handle,
276 &m, sizeof(m));
277
278 if (status) {
279 @@ -574,7 +520,7 @@ int bcm2835_audio_set_params(struct bcm2
280 ret = 0;
281
282 unlock:
283 - vchi_service_release(instance->vchi_handle[0]);
284 + vchi_service_release(instance->vchi_handle);
285 mutex_unlock(&instance->vchi_mutex);
286
287 return ret;
288 @@ -588,12 +534,12 @@ static int bcm2835_audio_start_worker(st
289 int ret;
290
291 mutex_lock(&instance->vchi_mutex);
292 - vchi_service_use(instance->vchi_handle[0]);
293 + vchi_service_use(instance->vchi_handle);
294
295 m.type = VC_AUDIO_MSG_TYPE_START;
296
297 /* Send the message to the videocore */
298 - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
299 + status = bcm2835_vchi_msg_queue(instance->vchi_handle,
300 &m, sizeof(m));
301
302 if (status) {
303 @@ -607,7 +553,7 @@ static int bcm2835_audio_start_worker(st
304 ret = 0;
305
306 unlock:
307 - vchi_service_release(instance->vchi_handle[0]);
308 + vchi_service_release(instance->vchi_handle);
309 mutex_unlock(&instance->vchi_mutex);
310 return ret;
311 }
312 @@ -620,13 +566,13 @@ static int bcm2835_audio_stop_worker(str
313 int ret;
314
315 mutex_lock(&instance->vchi_mutex);
316 - vchi_service_use(instance->vchi_handle[0]);
317 + vchi_service_use(instance->vchi_handle);
318
319 m.type = VC_AUDIO_MSG_TYPE_STOP;
320 m.u.stop.draining = alsa_stream->draining;
321
322 /* Send the message to the videocore */
323 - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
324 + status = bcm2835_vchi_msg_queue(instance->vchi_handle,
325 &m, sizeof(m));
326
327 if (status) {
328 @@ -640,7 +586,7 @@ static int bcm2835_audio_stop_worker(str
329 ret = 0;
330
331 unlock:
332 - vchi_service_release(instance->vchi_handle[0]);
333 + vchi_service_release(instance->vchi_handle);
334 mutex_unlock(&instance->vchi_mutex);
335 return ret;
336 }
337 @@ -655,7 +601,7 @@ int bcm2835_audio_close(struct bcm2835_a
338 my_workqueue_quit(alsa_stream);
339
340 mutex_lock(&instance->vchi_mutex);
341 - vchi_service_use(instance->vchi_handle[0]);
342 + vchi_service_use(instance->vchi_handle);
343
344 m.type = VC_AUDIO_MSG_TYPE_CLOSE;
345
346 @@ -663,7 +609,7 @@ int bcm2835_audio_close(struct bcm2835_a
347 init_completion(&instance->msg_avail_comp);
348
349 /* Send the message to the videocore */
350 - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
351 + status = bcm2835_vchi_msg_queue(instance->vchi_handle,
352 &m, sizeof(m));
353
354 if (status) {
355 @@ -687,7 +633,7 @@ int bcm2835_audio_close(struct bcm2835_a
356 ret = 0;
357
358 unlock:
359 - vchi_service_release(instance->vchi_handle[0]);
360 + vchi_service_release(instance->vchi_handle);
361 mutex_unlock(&instance->vchi_mutex);
362
363 /* Stop the audio service */
364 @@ -708,10 +654,10 @@ static int bcm2835_audio_write_worker(st
365 LOG_INFO(" Writing %d bytes from %p\n", count, src);
366
367 mutex_lock(&instance->vchi_mutex);
368 - vchi_service_use(instance->vchi_handle[0]);
369 + vchi_service_use(instance->vchi_handle);
370
371 if (instance->peer_version == 0 &&
372 - vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0)
373 + vchi_get_peer_version(instance->vchi_handle, &instance->peer_version) == 0)
374 LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
375
376 m.type = VC_AUDIO_MSG_TYPE_WRITE;
377 @@ -723,7 +669,7 @@ static int bcm2835_audio_write_worker(st
378 m.u.write.silence = src == NULL;
379
380 /* Send the message to the videocore */
381 - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
382 + status = bcm2835_vchi_msg_queue(instance->vchi_handle,
383 &m, sizeof(m));
384
385 if (status) {
386 @@ -736,7 +682,7 @@ static int bcm2835_audio_write_worker(st
387 if (!m.u.write.silence) {
388 if (!m.u.write.max_packet) {
389 /* Send the message to the videocore */
390 - status = vchi_bulk_queue_transmit(instance->vchi_handle[0],
391 + status = vchi_bulk_queue_transmit(instance->vchi_handle,
392 src, count,
393 0 * VCHI_FLAGS_BLOCK_UNTIL_QUEUED
394 +
395 @@ -746,7 +692,7 @@ static int bcm2835_audio_write_worker(st
396 while (count > 0) {
397 int bytes = min_t(int, m.u.write.max_packet, count);
398
399 - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
400 + status = bcm2835_vchi_msg_queue(instance->vchi_handle,
401 src, bytes);
402 src = (char *)src + bytes;
403 count -= bytes;
404 @@ -763,7 +709,7 @@ static int bcm2835_audio_write_worker(st
405 ret = 0;
406
407 unlock:
408 - vchi_service_release(instance->vchi_handle[0]);
409 + vchi_service_release(instance->vchi_handle);
410 mutex_unlock(&instance->vchi_mutex);
411 return ret;
412 }