diff options
author | Pradeep Venkatasubbarao | 2014-03-24 02:48:35 -0500 |
---|---|---|
committer | Pradeep Venkatasubbarao | 2014-03-25 23:04:42 -0500 |
commit | 1010fffb26ff3ee6e775b2f28d9016a88f26669a (patch) | |
tree | 68295d13b5bde5999fbe42cac00fdc95c7804171 /libdce.c | |
parent | 0ab31239d479f6954ba56977cfd358b373b3f9ed (diff) | |
download | hardware-ti-libdce-1010fffb26ff3ee6e775b2f28d9016a88f26669a.tar.gz hardware-ti-libdce-1010fffb26ff3ee6e775b2f28d9016a88f26669a.tar.xz hardware-ti-libdce-1010fffb26ff3ee6e775b2f28d9016a88f26669a.zip |
[LINUX] Manage Tiler Pinning for dce DRM buffers
Applications using dce_alloc/dce_free calls to manage memory,
leaked memory because on non-closure of the created dmabuf fds.
Additionally, all memory allocated from Tiler/DMM via DRM need to be
explictly pinned to tiler using dce_buf_lock/dce_buf_unlock calls.
Hence in the earlier implementation, every call to dce_alloc/free
had to be followed by a lock/unlock call to pin/unpin it to tiler.
In order, to insulate the applications from the internal details of
DRM memory management and for ease of use of alloc and free calls,
dce_alloc now takes care of creating the dmabuf and pinning it to tiler
while dce_free takes care of tiler unpinning and closure of dmabuf fd.
Applications can continue to use dce_alloc and dce_free calls as before
thus maintiaining backward compatibility.
On the other hand, since the same interfaces are used for multiple remote
core targets, like IPU and DSP, MemHeader struture is upgraded to hold the
core for which the block of memory belongs to, to keep track of the core.
Hence all applications/Remote cores using this version of libdce should
recompile with the new MemHeader for proper functioning.
Dependent IPUMM patch: https://gerrit.ext.ti.com/gerrit/omap/#/c/12994/
Change-Id: If09a1039b5b16f3cc5ff0e9c6c598932d8a2ce3e
Signed-off-by: Pradeep Venkatasubbarao <pradeepv@ti.com>
Signed-off-by: Amarinder Bindra <a-bindra@ti.com>
Signed-off-by: Karthik Ramanan <a0393906@ti.com>
Diffstat (limited to 'libdce.c')
-rw-r--r-- | libdce.c | 39 |
1 files changed, 23 insertions, 16 deletions
@@ -140,11 +140,15 @@ static int __inline getCoreIndexFromEngine(Engine_Handle engine) | |||
140 | } | 140 | } |
141 | 141 | ||
142 | /***************** FUNCTIONS ********************************************/ | 142 | /***************** FUNCTIONS ********************************************/ |
143 | /* Interface for QNX for parameter buffer allocation */ | 143 | /* Interface for QNX/Linux for parameter buffer allocation */ |
144 | /* These interfaces are implemented to maintain Backward Compatability */ | 144 | /* These interfaces are implemented to maintain Backward Compatability */ |
145 | void *dce_alloc(int sz) | 145 | void *dce_alloc(int sz) |
146 | { | 146 | { |
147 | return (memplugin_alloc(sz, 1, MEM_TILER_1D, 0, 0)); | 147 | /* |
148 | Beware: The last argument is a bit field. As of now only core ID | ||
149 | is considered to be there in the last 4 bits of the word | ||
150 | */ | ||
151 | return (memplugin_alloc(sz, 1, MEM_TILER_1D, 0, IPU)); | ||
148 | } | 152 | } |
149 | 153 | ||
150 | void dce_free(void *ptr) | 154 | void dce_free(void *ptr) |
@@ -243,11 +247,11 @@ Engine_Handle Engine_open(String name, Engine_Attrs *attrs, Engine_Error *ec) | |||
243 | INFO(">> Engine_open Params::name = %s size = %d\n", name, strlen(name)); | 247 | INFO(">> Engine_open Params::name = %s size = %d\n", name, strlen(name)); |
244 | /* Allocate Shared memory for the engine_open rpc msg structure*/ | 248 | /* Allocate Shared memory for the engine_open rpc msg structure*/ |
245 | /* Tiler Memory preferred in QNX */ | 249 | /* Tiler Memory preferred in QNX */ |
246 | engine_open_msg = memplugin_alloc(sizeof(dce_engine_open), 1, DEFAULT_REGION, 0, 0); | 250 | engine_open_msg = memplugin_alloc(sizeof(dce_engine_open), 1, DEFAULT_REGION, 0, coreIdx); |
247 | _ASSERT_AND_EXECUTE(engine_open_msg != NULL, DCE_EOUT_OF_MEMORY, engine_handle = NULL); | 251 | _ASSERT_AND_EXECUTE(engine_open_msg != NULL, DCE_EOUT_OF_MEMORY, engine_handle = NULL); |
248 | 252 | ||
249 | if( attrs ) { | 253 | if( attrs ) { |
250 | engine_attrs = memplugin_alloc(sizeof(Engine_Attrs), 1, DEFAULT_REGION, 0, 0); | 254 | engine_attrs = memplugin_alloc(sizeof(Engine_Attrs), 1, DEFAULT_REGION, 0, coreIdx); |
251 | _ASSERT_AND_EXECUTE(engine_attrs != NULL, DCE_EOUT_OF_MEMORY, engine_handle = NULL); | 255 | _ASSERT_AND_EXECUTE(engine_attrs != NULL, DCE_EOUT_OF_MEMORY, engine_handle = NULL); |
252 | *engine_attrs = *attrs; | 256 | *engine_attrs = *attrs; |
253 | } | 257 | } |
@@ -352,8 +356,11 @@ static void *create(Engine_Handle engine, String name, void *params, dce_codec_t | |||
352 | _ASSERT(engine != NULL, DCE_EINVALID_INPUT); | 356 | _ASSERT(engine != NULL, DCE_EINVALID_INPUT); |
353 | _ASSERT(params != NULL, DCE_EINVALID_INPUT); | 357 | _ASSERT(params != NULL, DCE_EINVALID_INPUT); |
354 | 358 | ||
359 | coreIdx = getCoreIndexFromCodec(codec_id); | ||
360 | _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); | ||
361 | |||
355 | /* Allocate shared memory for translating codec name to IPU */ | 362 | /* Allocate shared memory for translating codec name to IPU */ |
356 | codec_name = memplugin_alloc(MAX_NAME_LENGTH * sizeof(char), 1, DEFAULT_REGION, 0, 0); | 363 | codec_name = memplugin_alloc(MAX_NAME_LENGTH * sizeof(char), 1, DEFAULT_REGION, 0, coreIdx); |
357 | _ASSERT_AND_EXECUTE(codec_name != NULL, DCE_EOUT_OF_MEMORY, codec_handle = NULL); | 364 | _ASSERT_AND_EXECUTE(codec_name != NULL, DCE_EOUT_OF_MEMORY, codec_handle = NULL); |
358 | 365 | ||
359 | strncpy(codec_name, name, strlen(name)); | 366 | strncpy(codec_name, name, strlen(name)); |
@@ -367,9 +374,6 @@ static void *create(Engine_Handle engine, String name, void *params, dce_codec_t | |||
367 | Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[3]), GetSz(params), P2H(params), | 374 | Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[3]), GetSz(params), P2H(params), |
368 | sizeof(MemHeader), memplugin_share(params)); | 375 | sizeof(MemHeader), memplugin_share(params)); |
369 | /* Invoke the Remote function through MmRpc */ | 376 | /* Invoke the Remote function through MmRpc */ |
370 | coreIdx = getCoreIndexFromCodec(codec_id); | ||
371 | _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); | ||
372 | |||
373 | eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, (int32_t *)(&codec_handle)); | 377 | eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, (int32_t *)(&codec_handle)); |
374 | 378 | ||
375 | /* In case of Error, the Application will get a NULL Codec Handle */ | 379 | /* In case of Error, the Application will get a NULL Codec Handle */ |
@@ -412,6 +416,9 @@ static XDAS_Int32 control(void *codec, int id, void *dynParams, void *status, dc | |||
412 | _ASSERT(dynParams != NULL, DCE_EINVALID_INPUT); | 416 | _ASSERT(dynParams != NULL, DCE_EINVALID_INPUT); |
413 | _ASSERT(status != NULL, DCE_EINVALID_INPUT); | 417 | _ASSERT(status != NULL, DCE_EINVALID_INPUT); |
414 | 418 | ||
419 | coreIdx = getCoreIndexFromCodec(codec_id); | ||
420 | _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); | ||
421 | |||
415 | /* Marshall function arguments into the send buffer */ | 422 | /* Marshall function arguments into the send buffer */ |
416 | Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_CODEC_CONTROL, 5, 0, NULL); | 423 | Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_CODEC_CONTROL, 5, 0, NULL); |
417 | Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[0]), sizeof(int32_t), codec_id); | 424 | Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[0]), sizeof(int32_t), codec_id); |
@@ -423,8 +430,6 @@ static XDAS_Int32 control(void *codec, int id, void *dynParams, void *status, dc | |||
423 | sizeof(MemHeader), memplugin_share(status)); | 430 | sizeof(MemHeader), memplugin_share(status)); |
424 | 431 | ||
425 | /* Invoke the Remote function through MmRpc */ | 432 | /* Invoke the Remote function through MmRpc */ |
426 | coreIdx = getCoreIndexFromCodec(codec_id); | ||
427 | _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); | ||
428 | eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet); | 433 | eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet); |
429 | _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL); | 434 | _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL); |
430 | 435 | ||
@@ -469,6 +474,9 @@ static XDAS_Int32 get_version(void *codec, void *dynParams, void *status, dce_co | |||
469 | _ASSERT(dynParams != NULL, DCE_EINVALID_INPUT); | 474 | _ASSERT(dynParams != NULL, DCE_EINVALID_INPUT); |
470 | _ASSERT(status != NULL, DCE_EINVALID_INPUT); | 475 | _ASSERT(status != NULL, DCE_EINVALID_INPUT); |
471 | 476 | ||
477 | coreIdx = getCoreIndexFromCodec(codec_id); | ||
478 | _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); | ||
479 | |||
472 | if( codec_id == OMAP_DCE_VIDDEC3 ) { | 480 | if( codec_id == OMAP_DCE_VIDDEC3 ) { |
473 | version_buf = (void * *)(&(((IVIDDEC3_Status *)status)->data.buf)); | 481 | version_buf = (void * *)(&(((IVIDDEC3_Status *)status)->data.buf)); |
474 | } else if( codec_id == OMAP_DCE_VIDENC2 ) { | 482 | } else if( codec_id == OMAP_DCE_VIDENC2 ) { |
@@ -493,8 +501,6 @@ static XDAS_Int32 get_version(void *codec, void *dynParams, void *status, dce_co | |||
493 | (size_t)P2H(*version_buf), memplugin_share(*version_buf)); | 501 | (size_t)P2H(*version_buf), memplugin_share(*version_buf)); |
494 | 502 | ||
495 | /* Invoke the Remote function through MmRpc */ | 503 | /* Invoke the Remote function through MmRpc */ |
496 | coreIdx = getCoreIndexFromCodec(codec_id); | ||
497 | _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); | ||
498 | eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet); | 504 | eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet); |
499 | _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL); | 505 | _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL); |
500 | 506 | ||
@@ -559,6 +565,9 @@ static XDAS_Int32 process(void *codec, void *inBufs, void *outBufs, | |||
559 | _ASSERT(inArgs != NULL, DCE_EINVALID_INPUT); | 565 | _ASSERT(inArgs != NULL, DCE_EINVALID_INPUT); |
560 | _ASSERT(outArgs != NULL, DCE_EINVALID_INPUT); | 566 | _ASSERT(outArgs != NULL, DCE_EINVALID_INPUT); |
561 | 567 | ||
568 | coreIdx = getCoreIndexFromCodec(codec_id); | ||
569 | _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); | ||
570 | |||
562 | if( codec_id == OMAP_DCE_VIDDEC3 ) { | 571 | if( codec_id == OMAP_DCE_VIDDEC3 ) { |
563 | numInBufs = ((XDM2_BufDesc *)inBufs)->numBufs; | 572 | numInBufs = ((XDM2_BufDesc *)inBufs)->numBufs; |
564 | numOutBufs = ((XDM2_BufDesc *)outBufs)->numBufs; | 573 | numOutBufs = ((XDM2_BufDesc *)outBufs)->numBufs; |
@@ -686,8 +695,6 @@ static XDAS_Int32 process(void *codec, void *inBufs, void *outBufs, | |||
686 | } | 695 | } |
687 | 696 | ||
688 | /* Invoke the Remote function through MmRpc */ | 697 | /* Invoke the Remote function through MmRpc */ |
689 | coreIdx = getCoreIndexFromCodec(codec_id); | ||
690 | _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); | ||
691 | eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet); | 698 | eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet); |
692 | _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL); | 699 | _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL); |
693 | 700 | ||
@@ -735,6 +742,8 @@ static void delete(void *codec, dce_codec_type codec_id) | |||
735 | pthread_mutex_lock(&ipc_mutex); | 742 | pthread_mutex_lock(&ipc_mutex); |
736 | 743 | ||
737 | _ASSERT(codec != NULL, DCE_EINVALID_INPUT); | 744 | _ASSERT(codec != NULL, DCE_EINVALID_INPUT); |
745 | coreIdx = getCoreIndexFromCodec(codec_id); | ||
746 | _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); | ||
738 | 747 | ||
739 | /* Marshall function arguments into the send buffer */ | 748 | /* Marshall function arguments into the send buffer */ |
740 | Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_CODEC_DELETE, 2, 0, NULL); | 749 | Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_CODEC_DELETE, 2, 0, NULL); |
@@ -742,8 +751,6 @@ static void delete(void *codec, dce_codec_type codec_id) | |||
742 | Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[1]), sizeof(int32_t), (int32_t)codec); | 751 | Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[1]), sizeof(int32_t), (int32_t)codec); |
743 | 752 | ||
744 | /* Invoke the Remote function through MmRpc */ | 753 | /* Invoke the Remote function through MmRpc */ |
745 | coreIdx = getCoreIndexFromCodec(codec_id); | ||
746 | _ASSERT(coreIdx != INVALID_CORE, DCE_EINVALID_INPUT); | ||
747 | eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet); | 754 | eError = MmRpc_call(MmRpcHandle[coreIdx], &fxnCtx, &fxnRet); |
748 | _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL); | 755 | _ASSERT(eError == DCE_EOK, DCE_EIPC_CALL_FAIL); |
749 | 756 | ||