aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPradeep Venkatasubbarao2013-12-19 07:20:33 -0600
committerPradeep Venkatasubbarao2014-01-03 23:25:28 -0600
commit67e0fea9ac091319787abf2899e72f15fed48371 (patch)
treea32772685ce80f13135aa68ce87b1cb7387f3ac1 /libdce.c
parent89aba51d6a81c19c4ee5eeeb3b87ca00c04bc6bc (diff)
downloadrepo-libdce-67e0fea9ac091319787abf2899e72f15fed48371.tar.gz
repo-libdce-67e0fea9ac091319787abf2899e72f15fed48371.tar.xz
repo-libdce-67e0fea9ac091319787abf2899e72f15fed48371.zip
[Fix] Hold mutex during Mmrpc_call
There is a single IPC channel to communicate to IPU2 using Mmrpc calls. Any communication to remote proc ipu2 gets routed through same channel. If mutiple instances use IVAHD/DCE, all the packets get routed through same channel. There is a possibility of corruption if the ipc calls are not serialised. Hence this patch protects the Mmrpc_call function calls with a mutex. Change-Id: I3673ba76e52f03707277893cec07cff06abe8f1f Signed-off-by: Pradeep Venkatasubbarao <pradeepv@ti.com>
Diffstat (limited to 'libdce.c')
-rw-r--r--libdce.c59
1 files changed, 49 insertions, 10 deletions
diff --git a/libdce.c b/libdce.c
index 5cb0ec5..141f3da 100644
--- a/libdce.c
+++ b/libdce.c
@@ -50,7 +50,7 @@
50/* Handle used for Remote Communication */ 50/* Handle used for Remote Communication */
51MmRpc_Handle MmRpcHandle[MAX_REMOTEDEVICES] = { NULL}; 51MmRpc_Handle MmRpcHandle[MAX_REMOTEDEVICES] = { NULL};
52Engine_Handle gEngineHandle[MAX_INSTANCES][MAX_REMOTEDEVICES] = { {NULL, NULL}}; 52Engine_Handle gEngineHandle[MAX_INSTANCES][MAX_REMOTEDEVICES] = { {NULL, NULL}};
53static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; 53static pthread_mutex_t ipc_mutex = PTHREAD_MUTEX_INITIALIZER;
54static int __ClientCount[MAX_REMOTEDEVICES] = {0}; 54static int __ClientCount[MAX_REMOTEDEVICES] = {0};
55int dce_debug = DCE_DEBUG_LEVEL; 55int dce_debug = DCE_DEBUG_LEVEL;
56const String DCE_DEVICE_NAME[MAX_REMOTEDEVICES]= {"rpmsg-dce","rpmsg-dce-dsp"}; 56const String DCE_DEVICE_NAME[MAX_REMOTEDEVICES]= {"rpmsg-dce","rpmsg-dce-dsp"};
@@ -164,7 +164,7 @@ static int dce_ipc_init(int core)
164 164
165 DEBUG(" >> dce_ipc_init\n"); 165 DEBUG(" >> dce_ipc_init\n");
166 166
167 /*First check if maximum clients are already using ipc*/ 167 /*First check if maximum clients are already using ipc*/
168 if(__ClientCount[core] >= MAX_INSTANCES) { 168 if(__ClientCount[core] >= MAX_INSTANCES) {
169 eError = DCE_EXDM_UNSUPPORTED; 169 eError = DCE_EXDM_UNSUPPORTED;
170 return (eError); 170 return (eError);
@@ -193,6 +193,10 @@ EXIT:
193 */ 193 */
194static void dce_ipc_deinit(int core) 194static void dce_ipc_deinit(int core)
195{ 195{
196 if(__ClientCount[core] == 0) {
197 DEBUG("Nothing to be done: a spurious call\n");
198 return;
199 }
196 __ClientCount[core]--; 200 __ClientCount[core]--;
197 if( __ClientCount[core] > 0 ) { 201 if( __ClientCount[core] > 0 ) {
198 goto EXIT; 202 goto EXIT;
@@ -225,9 +229,12 @@ Engine_Handle Engine_open(String name, Engine_Attrs *attrs, Engine_Error *ec)
225 Engine_Handle engine_handle = NULL; 229 Engine_Handle engine_handle = NULL;
226 int coreIdx = INVALID_CORE; 230 int coreIdx = INVALID_CORE;
227 231
232
233 /*Acquire permission to use IPC*/
234 pthread_mutex_lock(&ipc_mutex);
235
228 _ASSERT(name != '\0', DCE_EINVALID_INPUT); 236 _ASSERT(name != '\0', DCE_EINVALID_INPUT);
229 237
230 pthread_mutex_lock(&mutex);
231 coreIdx = getCoreIndexFromName(name); 238 coreIdx = getCoreIndexFromName(name);
232 _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); 239 _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT);
233 /* Initialize IPC. In case of Error Deinitialize them */ 240 /* Initialize IPC. In case of Error Deinitialize them */
@@ -271,7 +278,8 @@ EXIT:
271 if( engine_attrs ) { 278 if( engine_attrs ) {
272 memplugin_free(engine_attrs); 279 memplugin_free(engine_attrs);
273 } 280 }
274 pthread_mutex_unlock(&mutex); 281 /*Relinquish IPC*/
282 pthread_mutex_unlock(&ipc_mutex);
275 283
276 return ((Engine_Handle)engine_handle); 284 return ((Engine_Handle)engine_handle);
277} 285}
@@ -288,7 +296,9 @@ Void Engine_close(Engine_Handle engine)
288 dce_error_status eError = DCE_EOK; 296 dce_error_status eError = DCE_EOK;
289 int32_t coreIdx = INVALID_CORE; 297 int32_t coreIdx = INVALID_CORE;
290 298
291 pthread_mutex_lock(&mutex); 299
300 /*Acquire permission to use IPC*/
301 pthread_mutex_lock(&ipc_mutex);
292 302
293 _ASSERT(engine != NULL, DCE_EINVALID_INPUT); 303 _ASSERT(engine != NULL, DCE_EINVALID_INPUT);
294 304
@@ -306,7 +316,8 @@ Void Engine_close(Engine_Handle engine)
306EXIT: 316EXIT:
307 dce_ipc_deinit(coreIdx); 317 dce_ipc_deinit(coreIdx);
308 318
309 pthread_mutex_unlock(&mutex); 319 /*Relinquish IPC*/
320 pthread_mutex_unlock(&ipc_mutex);
310 321
311 return; 322 return;
312} 323}
@@ -333,6 +344,10 @@ static void *create(Engine_Handle engine, String name, void *params, dce_codec_t
333 char *codec_name = NULL; 344 char *codec_name = NULL;
334 int coreIdx = INVALID_CORE; 345 int coreIdx = INVALID_CORE;
335 346
347
348 /*Acquire permission to use IPC*/
349 pthread_mutex_lock(&ipc_mutex);
350
336 _ASSERT(name != '\0', DCE_EINVALID_INPUT); 351 _ASSERT(name != '\0', DCE_EINVALID_INPUT);
337 _ASSERT(engine != NULL, DCE_EINVALID_INPUT); 352 _ASSERT(engine != NULL, DCE_EINVALID_INPUT);
338 _ASSERT(params != NULL, DCE_EINVALID_INPUT); 353 _ASSERT(params != NULL, DCE_EINVALID_INPUT);
@@ -354,12 +369,16 @@ static void *create(Engine_Handle engine, String name, void *params, dce_codec_t
354 /* Invoke the Remote function through MmRpc */ 369 /* Invoke the Remote function through MmRpc */
355 coreIdx = getCoreIndexFromCodec(codec_id); 370 coreIdx = getCoreIndexFromCodec(codec_id);
356 _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); 371 _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT);
372
357 eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, (int32_t *)(&codec_handle)); 373 eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, (int32_t *)(&codec_handle));
374
358 /* In case of Error, the Application will get a NULL Codec Handle */ 375 /* In case of Error, the Application will get a NULL Codec Handle */
359 _ASSERT_AND_EXECUTE(eError == DCE_EOK, DCE_EIPC_CALL_FAIL, codec_handle = NULL); 376 _ASSERT_AND_EXECUTE(eError == DCE_EOK, DCE_EIPC_CALL_FAIL, codec_handle = NULL);
360 377
361EXIT: 378EXIT:
362 memplugin_free(codec_name); 379 memplugin_free(codec_name);
380 /*Relinquish IPC*/
381 pthread_mutex_unlock(&ipc_mutex);
363 return ((void *)codec_handle); 382 return ((void *)codec_handle);
364} 383}
365 384
@@ -385,6 +404,10 @@ static XDAS_Int32 control(void *codec, int id, void *dynParams, void *status, dc
385 dce_error_status eError = DCE_EOK; 404 dce_error_status eError = DCE_EOK;
386 int coreIdx = INVALID_CORE; 405 int coreIdx = INVALID_CORE;
387 406
407
408 /*Acquire permission to use IPC*/
409 pthread_mutex_lock(&ipc_mutex);
410
388 _ASSERT(codec != NULL, DCE_EINVALID_INPUT); 411 _ASSERT(codec != NULL, DCE_EINVALID_INPUT);
389 _ASSERT(dynParams != NULL, DCE_EINVALID_INPUT); 412 _ASSERT(dynParams != NULL, DCE_EINVALID_INPUT);
390 _ASSERT(status != NULL, DCE_EINVALID_INPUT); 413 _ASSERT(status != NULL, DCE_EINVALID_INPUT);
@@ -403,10 +426,11 @@ static XDAS_Int32 control(void *codec, int id, void *dynParams, void *status, dc
403 coreIdx = getCoreIndexFromCodec(codec_id); 426 coreIdx = getCoreIndexFromCodec(codec_id);
404 _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); 427 _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT);
405 eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet); 428 eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet);
406
407 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL); 429 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
408 430
409EXIT: 431EXIT:
432 /*Relinquish IPC*/
433 pthread_mutex_unlock(&ipc_mutex);
410 return (fxnRet); 434 return (fxnRet);
411 435
412} 436}
@@ -437,6 +461,10 @@ static XDAS_Int32 get_version(void *codec, void *dynParams, void *status, dce_co
437 dce_error_status eError = DCE_EOK; 461 dce_error_status eError = DCE_EOK;
438 int coreIdx = INVALID_CORE; 462 int coreIdx = INVALID_CORE;
439 463
464
465 /*Acquire permission to use IPC*/
466 pthread_mutex_lock(&ipc_mutex);
467
440 _ASSERT(codec != NULL, DCE_EINVALID_INPUT); 468 _ASSERT(codec != NULL, DCE_EINVALID_INPUT);
441 _ASSERT(dynParams != NULL, DCE_EINVALID_INPUT); 469 _ASSERT(dynParams != NULL, DCE_EINVALID_INPUT);
442 _ASSERT(status != NULL, DCE_EINVALID_INPUT); 470 _ASSERT(status != NULL, DCE_EINVALID_INPUT);
@@ -468,10 +496,11 @@ static XDAS_Int32 get_version(void *codec, void *dynParams, void *status, dce_co
468 coreIdx = getCoreIndexFromCodec(codec_id); 496 coreIdx = getCoreIndexFromCodec(codec_id);
469 _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); 497 _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT);
470 eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet); 498 eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet);
471
472 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL); 499 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
473 500
474EXIT: 501EXIT:
502 /*Relinquish IPC*/
503 pthread_mutex_unlock(&ipc_mutex);
475 return (fxnRet); 504 return (fxnRet);
476} 505}
477 506
@@ -520,6 +549,10 @@ static XDAS_Int32 process(void *codec, void *inBufs, void *outBufs,
520 int32_t outbuf_offset[MAX_OUTPUT_BUF]; 549 int32_t outbuf_offset[MAX_OUTPUT_BUF];
521#endif 550#endif
522 551
552
553 /*Acquire permission to use IPC*/
554 pthread_mutex_lock(&ipc_mutex);
555
523 _ASSERT(codec != NULL, DCE_EINVALID_INPUT); 556 _ASSERT(codec != NULL, DCE_EINVALID_INPUT);
524 _ASSERT(inBufs != NULL, DCE_EINVALID_INPUT); 557 _ASSERT(inBufs != NULL, DCE_EINVALID_INPUT);
525 _ASSERT(outBufs != NULL, DCE_EINVALID_INPUT); 558 _ASSERT(outBufs != NULL, DCE_EINVALID_INPUT);
@@ -655,7 +688,6 @@ static XDAS_Int32 process(void *codec, void *inBufs, void *outBufs,
655 /* Invoke the Remote function through MmRpc */ 688 /* Invoke the Remote function through MmRpc */
656 coreIdx = getCoreIndexFromCodec(codec_id); 689 coreIdx = getCoreIndexFromCodec(codec_id);
657 _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); 690 _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT);
658
659 eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet); 691 eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet);
660 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL); 692 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
661 693
@@ -679,6 +711,8 @@ static XDAS_Int32 process(void *codec, void *inBufs, void *outBufs,
679 eError = (dce_error_status)(fxnRet); 711 eError = (dce_error_status)(fxnRet);
680 712
681EXIT: 713EXIT:
714 /*Relinquish IPC*/
715 pthread_mutex_unlock(&ipc_mutex);
682 return (eError); 716 return (eError);
683} 717}
684 718
@@ -696,6 +730,10 @@ static void delete(void *codec, dce_codec_type codec_id)
696 dce_error_status eError = DCE_EOK; 730 dce_error_status eError = DCE_EOK;
697 int coreIdx = INVALID_CORE; 731 int coreIdx = INVALID_CORE;
698 732
733
734 /*Acquire permission to use IPC*/
735 pthread_mutex_lock(&ipc_mutex);
736
699 _ASSERT(codec != NULL, DCE_EINVALID_INPUT); 737 _ASSERT(codec != NULL, DCE_EINVALID_INPUT);
700 738
701 /* Marshall function arguments into the send buffer */ 739 /* Marshall function arguments into the send buffer */
@@ -706,11 +744,12 @@ static void delete(void *codec, dce_codec_type codec_id)
706 /* Invoke the Remote function through MmRpc */ 744 /* Invoke the Remote function through MmRpc */
707 coreIdx = getCoreIndexFromCodec(codec_id); 745 coreIdx = getCoreIndexFromCodec(codec_id);
708 _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); 746 _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT);
709
710 eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet); 747 eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet);
711 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL); 748 _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL);
712 749
713EXIT: 750EXIT:
751 /*Relinquish IPC*/
752 pthread_mutex_unlock(&ipc_mutex);
714 return; 753 return;
715} 754}
716 755