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
6 commit 326a6edcb2ada56375bd7d3fc24c83f58e8da7f3 upstream.
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
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>
17 .../bcm2835-audio/bcm2835-vchiq.c | 170 ++++++------------
18 1 file changed, 58 insertions(+), 112 deletions(-)
20 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
21 +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c
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
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");
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
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)
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,
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
68 struct bcm2835_audio_instance *instance;
72 - LOG_DBG("%s: start", __func__);
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);
78 - return ERR_PTR(-EINVAL);
80 /* Allocate memory for this instance */
81 instance = kzalloc(sizeof(*instance), GFP_KERNEL);
83 return ERR_PTR(-ENOMEM);
85 - instance->num_connections = num_connections;
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],
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
104 - LOG_DBG("%s: about to open %i\n", __func__, i);
105 - status = vchi_service_open(vchi_instance, ¶ms,
106 - &instance->vchi_handle[i]);
107 + params.callback_param = instance,
109 - LOG_DBG("%s: opened %i: %p=%d\n", __func__, i, instance->vchi_handle[i], status);
111 - LOG_ERR("%s: failed to open VCHI service connection (status=%d)\n",
114 - goto err_close_services;
116 - /* Finished with the service for now */
117 - vchi_service_release(instance->vchi_handle[i]);
120 - LOG_DBG("%s: okay\n", __func__);
122 + status = vchi_service_open(vchi_instance, ¶ms,
123 + &instance->vchi_handle);
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]);
131 + LOG_ERR("%s: failed to open VCHI service connection (status=%d)\n",
134 + return ERR_PTR(-EPERM);
138 - LOG_ERR("%s: error\n", __func__);
139 + /* Finished with the service for now */
140 + vchi_service_release(instance->vchi_handle);
142 - return ERR_PTR(ret);
146 static int vc_vchi_audio_deinit(struct bcm2835_audio_instance *instance)
151 - LOG_ERR("%s: invalid handle %p\n", __func__, instance);
157 - LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
158 mutex_lock(&instance->vchi_mutex);
160 /* Close all VCHI service connections */
161 - for (i = 0; i < instance->num_connections; i++) {
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);
168 - status = vchi_service_close(instance->vchi_handle[i]);
170 - LOG_DBG("%s: failed to close VCHI service connection (status=%d)\n",
173 + status = vchi_service_close(instance->vchi_handle);
175 + LOG_DBG("%s: failed to close VCHI service connection (status=%d)\n",
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;
184 - LOG_INFO("%s: start\n", __func__);
187 - LOG_ERR("%s: VCHI instance already open (%p)\n",
188 - __func__, instance);
189 - instance->alsa_stream = alsa_stream;
190 - alsa_stream->instance = instance;
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);
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;
205 - LOG_DBG(" success !\n");
210 @@ -431,12 +377,12 @@ int bcm2835_audio_open(struct bcm2835_al
211 LOG_DBG(" instance (%p)\n", instance);
213 mutex_lock(&instance->vchi_mutex);
214 - vchi_service_use(instance->vchi_handle[0]);
215 + vchi_service_use(instance->vchi_handle);
217 m.type = VC_AUDIO_MSG_TYPE_OPEN;
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,
225 @@ -450,7 +396,7 @@ int bcm2835_audio_open(struct bcm2835_al
229 - vchi_service_release(instance->vchi_handle[0]);
230 + vchi_service_release(instance->vchi_handle);
231 mutex_unlock(&instance->vchi_mutex);
234 @@ -472,7 +418,7 @@ int bcm2835_audio_set_ctls(struct bcm283
235 chip->dest, chip->volume);
237 mutex_lock(&instance->vchi_mutex);
238 - vchi_service_use(instance->vchi_handle[0]);
239 + vchi_service_use(instance->vchi_handle);
241 instance->result = -1;
243 @@ -487,7 +433,7 @@ int bcm2835_audio_set_ctls(struct bcm283
244 init_completion(&instance->msg_avail_comp);
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,
252 @@ -511,7 +457,7 @@ int bcm2835_audio_set_ctls(struct bcm283
256 - vchi_service_release(instance->vchi_handle[0]);
257 + vchi_service_release(instance->vchi_handle);
258 mutex_unlock(&instance->vchi_mutex);
261 @@ -537,7 +483,7 @@ int bcm2835_audio_set_params(struct bcm2
264 mutex_lock(&instance->vchi_mutex);
265 - vchi_service_use(instance->vchi_handle[0]);
266 + vchi_service_use(instance->vchi_handle);
268 instance->result = -1;
270 @@ -550,7 +496,7 @@ int bcm2835_audio_set_params(struct bcm2
271 init_completion(&instance->msg_avail_comp);
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,
279 @@ -574,7 +520,7 @@ int bcm2835_audio_set_params(struct bcm2
283 - vchi_service_release(instance->vchi_handle[0]);
284 + vchi_service_release(instance->vchi_handle);
285 mutex_unlock(&instance->vchi_mutex);
288 @@ -588,12 +534,12 @@ static int bcm2835_audio_start_worker(st
291 mutex_lock(&instance->vchi_mutex);
292 - vchi_service_use(instance->vchi_handle[0]);
293 + vchi_service_use(instance->vchi_handle);
295 m.type = VC_AUDIO_MSG_TYPE_START;
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,
303 @@ -607,7 +553,7 @@ static int bcm2835_audio_start_worker(st
307 - vchi_service_release(instance->vchi_handle[0]);
308 + vchi_service_release(instance->vchi_handle);
309 mutex_unlock(&instance->vchi_mutex);
312 @@ -620,13 +566,13 @@ static int bcm2835_audio_stop_worker(str
315 mutex_lock(&instance->vchi_mutex);
316 - vchi_service_use(instance->vchi_handle[0]);
317 + vchi_service_use(instance->vchi_handle);
319 m.type = VC_AUDIO_MSG_TYPE_STOP;
320 m.u.stop.draining = alsa_stream->draining;
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,
328 @@ -640,7 +586,7 @@ static int bcm2835_audio_stop_worker(str
332 - vchi_service_release(instance->vchi_handle[0]);
333 + vchi_service_release(instance->vchi_handle);
334 mutex_unlock(&instance->vchi_mutex);
337 @@ -655,7 +601,7 @@ int bcm2835_audio_close(struct bcm2835_a
338 my_workqueue_quit(alsa_stream);
340 mutex_lock(&instance->vchi_mutex);
341 - vchi_service_use(instance->vchi_handle[0]);
342 + vchi_service_use(instance->vchi_handle);
344 m.type = VC_AUDIO_MSG_TYPE_CLOSE;
346 @@ -663,7 +609,7 @@ int bcm2835_audio_close(struct bcm2835_a
347 init_completion(&instance->msg_avail_comp);
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,
355 @@ -687,7 +633,7 @@ int bcm2835_audio_close(struct bcm2835_a
359 - vchi_service_release(instance->vchi_handle[0]);
360 + vchi_service_release(instance->vchi_handle);
361 mutex_unlock(&instance->vchi_mutex);
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);
367 mutex_lock(&instance->vchi_mutex);
368 - vchi_service_use(instance->vchi_handle[0]);
369 + vchi_service_use(instance->vchi_handle);
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);
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;
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,
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,
393 0 * VCHI_FLAGS_BLOCK_UNTIL_QUEUED
395 @@ -746,7 +692,7 @@ static int bcm2835_audio_write_worker(st
397 int bytes = min_t(int, m.u.write.max_packet, count);
399 - status = bcm2835_vchi_msg_queue(instance->vchi_handle[0],
400 + status = bcm2835_vchi_msg_queue(instance->vchi_handle,
402 src = (char *)src + bytes;
404 @@ -763,7 +709,7 @@ static int bcm2835_audio_write_worker(st
408 - vchi_service_release(instance->vchi_handle[0]);
409 + vchi_service_release(instance->vchi_handle);
410 mutex_unlock(&instance->vchi_mutex);