]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/libdce2.git/commitdiff
[GLP] Enable DMA Buf Handle
authorSaurabh Bipin Chandra <a0131926@ti.com>
Sun, 4 Aug 2013 09:55:14 +0000 (15:25 +0530)
committerSaurabh Bipin Chandra <a0131926@ti.com>
Fri, 30 Aug 2013 05:58:22 +0000 (11:28 +0530)
This patch converts all MmRpc_Pointer_Param call
to MmRpc_OffsetPointer_Param to take care of MemHeader.

This is not needed from a QNX perspective but is needed
from a Linux perspective. There should no added latency is QNX
due to this change as the rpmsg_rpc kernel path is still the same.

This patch invokes memplugin_share() for the buffers allocated
through DCE to get the corresponding DMA Buf Handles for GLP.
For QNX, the return value is expected to be 0.

For linux, the patch adds the logic for Single vs Multiplanar buffers.

For linux, the memplugin_share() logic is modified to store and
retireve the same dma_buf_fd rather than getting a dup() each time.

These changes makes the following assumptions:
1. All the parameter buffers are allocated through
   DCE/MemPlugin.
2. The CLient passes Virtual pointers, rather than
   DMA Buf Handles to libdce for parameter buffers.
3. For IO Buffers, the client passes DMA Buf Handles
   and are not allocated using DCE/MemPlugin.

This patch assumes MmRpc is exposing translation[i].base.

Change-Id: I7d13f4a4d69fbe8b6dd0317e2a860f0df2061ef9
Signed-off-by: Sunita Nadampalli <sunitan@ti.com>
Signed-off-by: Saurabh Bipin Chandra <a0131926@ti.com>
libdce.c
memplugin.h
memplugin_linux.c

index 11ee333933342787f0523a95ab3c33fe32f94620..f83aeb5df0d93977b584f1bb68b33ebbe234e937 100644 (file)
--- a/libdce.c
+++ b/libdce.c
@@ -111,12 +111,21 @@ static inline void Fill_MmRpc_fxnCtx(MmRpc_FxnCtx *fxnCtx, int fxn_id, int num_p
     fxnCtx->xltAry = xltAry;
 }
 
-static inline void Fill_MmRpc_fxnCtx_Ptr_Params(MmRpc_Param *mmrpc_params, int size, void *addr, void *handle)
+static inline void Fill_MmRpc_fxnCtx_OffPtr_Params(MmRpc_Param *mmrpc_params, int size, void *base, int offset, size_t handle)
+{
+    mmrpc_params->type = MmRpc_ParamType_OffPtr;
+    mmrpc_params->param.offPtr.size = (size_t)size;
+    mmrpc_params->param.offPtr.base = (size_t)base;
+    mmrpc_params->param.offPtr.offset = (size_t)offset;
+    mmrpc_params->param.offPtr.handle = handle;
+}
+
+static inline void Fill_MmRpc_fxnCtx_Ptr_Params(MmRpc_Param *mmrpc_params, int size, void *addr, size_t handle)
 {
     mmrpc_params->type = MmRpc_ParamType_Ptr;
     mmrpc_params->param.ptr.size = size;
     mmrpc_params->param.ptr.addr = (size_t)addr;
-    mmrpc_params->param.ptr.handle = (size_t)handle;
+    mmrpc_params->param.ptr.handle = handle;
 }
 
 static inline void Fill_MmRpc_fxnCtx_Scalar_Params(MmRpc_Param *mmrpc_params, int size, int data)
@@ -126,13 +135,14 @@ static inline void Fill_MmRpc_fxnCtx_Scalar_Params(MmRpc_Param *mmrpc_params, in
     mmrpc_params->param.scalar.data = (size_t)data;
 }
 
-static inline void Fill_MmRpc_fxnCtx_Xlt_Array(MmRpc_Xlt *mmrpc_xlt, int index, int32_t base, int32_t addr, void *handle)
+static inline void Fill_MmRpc_fxnCtx_Xlt_Array(MmRpc_Xlt *mmrpc_xlt, int index, int32_t base, int32_t addr, size_t handle)
 {
     /* index : index of params filled in FxnCtx                                                                                        */
     /* offset : calculated from address of index                                                                                      */
     mmrpc_xlt->index = index;
     mmrpc_xlt->offset = MmRpc_OFFSET(base, addr);
-    mmrpc_xlt->handle = (size_t)handle;
+    mmrpc_xlt->base = handle;
+    mmrpc_xlt->handle = handle;
 }
 
 /************************ FUNCTIONS **************************/
@@ -273,7 +283,8 @@ Engine_Handle Engine_open(String name, Engine_Attrs *attrs, Engine_Error *ec)
 
     /* Marshall function arguments into the send buffer */
     Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_ENGINE_OPEN, 1, 0, NULL);
-    Fill_MmRpc_fxnCtx_Ptr_Params(fxnCtx.params, sizeof(dce_engine_open), engine_open_msg, NULL);
+    Fill_MmRpc_fxnCtx_OffPtr_Params(fxnCtx.params, GetSz(engine_open_msg), (void *)P2H(engine_open_msg),
+                                    sizeof(MemHeader), memplugin_share(engine_open_msg));
 
     /* Invoke the Remote function through MmRpc */
     eError = MmRpc_call(MmRpcHandle, &fxnCtx, (int32_t *)(&engine_handle));
@@ -354,9 +365,10 @@ static void *create(Engine_Handle engine, String name, void *params, dce_codec_t
     Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_CODEC_CREATE, 4, 0, NULL);
     Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[0]), sizeof(int32_t), codec_id);
     Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[1]), sizeof(Engine_Handle), (int32_t)engine);
-    Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[2]), (P2H(codec_name))->size, codec_name, NULL);
-    Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[3]), (P2H(params))->size, params, NULL);
-
+    Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[2]), GetSz(codec_name), P2H(codec_name),
+                                    sizeof(MemHeader), memplugin_share(codec_name));
+    Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[3]), GetSz(params), P2H(params),
+                                    sizeof(MemHeader),  memplugin_share(params));
     /* Invoke the Remote function through MmRpc */
     eError = MmRpc_call(MmRpcHandle, &fxnCtx, (int32_t *)(&codec_handle));
 
@@ -398,8 +410,10 @@ static XDAS_Int32 control(void *codec, int id, void *dynParams, void *status, dc
     Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[0]), sizeof(int32_t), codec_id);
     Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[1]), sizeof(int32_t), (int32_t)codec);
     Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[2]), sizeof(int32_t), (int32_t)id);
-    Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[3]), (P2H(dynParams))->size, dynParams, NULL);
-    Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[4]), (P2H(status))->size, status, NULL);
+    Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[3]), GetSz(dynParams), P2H(dynParams),
+                                    sizeof(MemHeader), memplugin_share(dynParams));
+    Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[4]), GetSz(status), P2H(status),
+                                    sizeof(MemHeader), memplugin_share(status));
 
     /* Invoke the Remote function through MmRpc */
     eError = MmRpc_call(MmRpcHandle, &fxnCtx, &fxnRet);
@@ -451,11 +465,13 @@ static XDAS_Int32 get_version(void *codec, void *dynParams, void *status, dce_co
     Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_CODEC_GET_VERSION, 4, 1, &xltAry);
     Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[0]), sizeof(int32_t), codec_id);
     Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[1]), sizeof(int32_t), (int32_t)codec);
-    Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[2]), (P2H(dynParams))->size, dynParams, NULL);
-    Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[3]), (P2H(status))->size, status, NULL);
+    Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[2]), GetSz(dynParams), P2H(dynParams),
+                                    sizeof(MemHeader), memplugin_share(dynParams));
+    Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[3]), GetSz(status), P2H(status),
+                                    sizeof(MemHeader), memplugin_share(status));
 
     /* Address Translation needed for buffer for version Info */
-    Fill_MmRpc_fxnCtx_Xlt_Array(fxnCtx.xltAry, 3, (int32_t)status, (int32_t)version_buf, NULL);
+    Fill_MmRpc_fxnCtx_Xlt_Array(fxnCtx.xltAry, 3, (int32_t)P2H(status), (int32_t)version_buf, memplugin_share(*version_buf));
 
     /* Invoke the Remote function through MmRpc */
     eError = MmRpc_call(MmRpcHandle, &fxnCtx, &fxnRet);
@@ -475,6 +491,8 @@ typedef enum process_call_params {
     OUTARGS_INDEX
 } process_call_params;
 
+#define LUMA_BUF 0
+#define CHROMA_BUF 1
 /*===============================================================*/
 /** process               : Encode/Decode process.
  *
@@ -495,8 +513,9 @@ static XDAS_Int32 process(void *codec, void *inBufs, void *outBufs,
 {
     MmRpc_FxnCtx        fxnCtx;
     MmRpc_Xlt           xltAry[MAX_TOTAl_BUF];
-    int                 fxnRet, count, total_count, numInBufs = 0, numOutBufs = 0, sz[OUTARGS_INDEX + 1] = { 0 };
+    int                 fxnRet, count, total_count, numInBufs = 0, numOutBufs = 0;
     dce_error_status    eError = DCE_EOK;
+    void             * *data_buf = NULL;
 
     _ASSERT(codec != NULL, DCE_EINVALID_INPUT);
     _ASSERT(inBufs != NULL, DCE_EINVALID_INPUT);
@@ -507,17 +526,9 @@ static XDAS_Int32 process(void *codec, void *inBufs, void *outBufs,
     if( codec_id == OMAP_DCE_VIDDEC3 ) {
         numInBufs = ((XDM2_BufDesc *)inBufs)->numBufs;
         numOutBufs = ((XDM2_BufDesc *)outBufs)->numBufs;
-        sz[INBUFS_INDEX] = sizeof(XDM2_BufDesc);
-        sz[OUTBUFS_INDEX] = sizeof(XDM2_BufDesc);
-        sz[INARGS_INDEX] = sizeof(VIDDEC3_InArgs);
-        sz[OUTARGS_INDEX] = sizeof(VIDDEC3_OutArgs);
     } else if( codec_id == OMAP_DCE_VIDENC2 ) {
         numInBufs = ((IVIDEO2_BufDesc *)inBufs)->numPlanes;
         numOutBufs = ((XDM2_BufDesc *)outBufs)->numBufs;
-        sz[INBUFS_INDEX] = sizeof(IVIDEO2_BufDesc);
-        sz[OUTBUFS_INDEX] = sizeof(XDM2_BufDesc);
-        sz[INARGS_INDEX] = sizeof(VIDENC2_InArgs);
-        sz[OUTARGS_INDEX] = sizeof(VIDENC2_OutArgs);
     }
 
     /* marshall function arguments into the send buffer                       */
@@ -525,24 +536,55 @@ static XDAS_Int32 process(void *codec, void *inBufs, void *outBufs,
     Fill_MmRpc_fxnCtx(&fxnCtx, DCE_RPC_CODEC_PROCESS, 6, numInBufs + numOutBufs, xltAry);
     Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[CODEC_ID_INDEX]), sizeof(int32_t), codec_id);
     Fill_MmRpc_fxnCtx_Scalar_Params(&(fxnCtx.params[CODEC_HANDLE_INDEX]), sizeof(int32_t), (int32_t)codec);
-    Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[INBUFS_INDEX]), sz[INBUFS_INDEX], inBufs, NULL);
-    Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[OUTBUFS_INDEX]), sz[OUTBUFS_INDEX], outBufs, NULL);
-    Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[INARGS_INDEX]), sz[INARGS_INDEX], inArgs, NULL);
-    Fill_MmRpc_fxnCtx_Ptr_Params(&(fxnCtx.params[OUTARGS_INDEX]), sz[OUTARGS_INDEX], outArgs, NULL);
+
+    Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[INBUFS_INDEX]), GetSz(inBufs), P2H(inBufs),
+                                    sizeof(MemHeader), memplugin_share(inBufs));
+    Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[OUTBUFS_INDEX]), GetSz(outBufs), P2H(outBufs),
+                                    sizeof(MemHeader), memplugin_share(outBufs));
+    Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[INARGS_INDEX]), GetSz(inArgs), P2H(inArgs),
+                                    sizeof(MemHeader), memplugin_share(inArgs));
+    Fill_MmRpc_fxnCtx_OffPtr_Params(&(fxnCtx.params[OUTARGS_INDEX]), GetSz(outArgs), P2H(outArgs),
+                                    sizeof(MemHeader), memplugin_share(outArgs));
 
     /* InBufs, OutBufs, InArgs, OutArgs buffer need translation but since they have been */
     /* individually mentioned as fxnCtx Params, they need not be mentioned below again */
     /* Input and Output Buffers have to be mentioned for translation                               */
     for( count = 0, total_count = 0; count < numInBufs; count++, total_count++ ) {
         if( codec_id == OMAP_DCE_VIDDEC3 ) {
-            Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), INBUFS_INDEX, (int32_t)inBufs, (int32_t)&(((XDM2_BufDesc *)inBufs)->descs[count].buf), NULL);
+            data_buf = (void * *)(&(((XDM2_BufDesc *)inBufs)->descs[count].buf));
+            Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), INBUFS_INDEX, (int32_t)P2H(inBufs),
+                                        (int32_t)data_buf, (size_t)*data_buf);
         } else if( codec_id == OMAP_DCE_VIDENC2 ) {
-            Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), INBUFS_INDEX, (int32_t)inBufs, (int32_t)&(((IVIDEO2_BufDesc *)inBufs)->planeDesc[count].buf), NULL);
+            data_buf = (void * *)(&(((IVIDEO2_BufDesc *)inBufs)->planeDesc[count].buf));
+            Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), INBUFS_INDEX, (int32_t)P2H(inBufs),
+                                        (int32_t)data_buf, (size_t)*data_buf);
         }
     }
 
     for( count = 0; count < numOutBufs; count++, total_count++ ) {
-        Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), OUTBUFS_INDEX, (int32_t)outBufs, (int32_t)&(((XDM2_BufDesc *)outBufs)->descs[count].buf), NULL);
+        if(((XDM2_BufDesc *)outBufs)->descs[LUMA_BUF].buf != ((XDM2_BufDesc *)outBufs)->descs[CHROMA_BUF].buf ) {
+            /* MultiPlanar Buffers */
+            data_buf = (void * *)(&(((XDM2_BufDesc *)outBufs)->descs[count].buf));
+            Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), OUTBUFS_INDEX, (int32_t)P2H(outBufs),
+                                        (int32_t)data_buf, (size_t)*data_buf);
+        }
+#if defined(BUILDOS_LINUX)
+        else {
+            /* SinglePlanar Buffers */
+            data_buf = (void * *)(&(((XDM2_BufDesc *)outBufs)->descs[count].buf));
+            Fill_MmRpc_fxnCtx_Xlt_Array(&(fxnCtx.xltAry[total_count]), OUTBUFS_INDEX, (int32_t)P2H(outBufs),
+                                        (int32_t)data_buf, (size_t)*data_buf);
+            if( count == CHROMA_BUF ) {
+                if(((XDM2_BufDesc *)outBufs)->descs[count].memType == XDM_MEMTYPE_RAW ||
+                   ((XDM2_BufDesc *)outBufs)->descs[count].memType == XDM_MEMTYPE_TILEDPAGE ) {
+                    *data_buf += ((XDM2_BufDesc *)outBufs)->descs[LUMA_BUF].bufSize.bytes;
+                } else {
+                    *data_buf += ((XDM2_BufDesc *)outBufs)->descs[LUMA_BUF].bufSize.tileMem.width *
+                                 ((XDM2_BufDesc *)outBufs)->descs[LUMA_BUF].bufSize.tileMem.height;
+                }
+            }
+        }
+#endif
     }
 
     /* Invoke the Remote function through MmRpc */
index 49e0500c0b7ffd21bd631d22cf92307a03416451..bd09a8bb9af69c0c851df423606b313a520d15f5 100644 (file)
@@ -56,6 +56,7 @@
 #define P2H(p) (&(((MemHeader *)(p))[-1]))
 #define H2P(h) ((void *)&(h)[1])
 
+#define GetSz(buf)           ((P2H(buf))->size + sizeof(MemHeader))
 
 /* MemHeader is important because it is necessary to know the           */
 /* size of the parameter buffers on IPU for Cache operations               */
 /* For ex: static params can be VIDDEC3_Params, IVIDDEC3_Params */
 /* or IH264DEC_Params                                                                   */
 typedef struct MemHeader {
-    int   size;
-    void *ptr;
+    uint32_t size;
+    void    *ptr;
+#if defined(BUILDOS_LINUX)
+    int32_t dma_buf_fd;
+#endif
 } MemHeader;
 
 
index bb99d26b49fe0ce1d531c6919e19a5dc2e6b4b94..47f03fc9250f473bb6d15e0af61a82eb61629471 100644 (file)
@@ -45,7 +45,7 @@ extern struct omap_device   *dev;
 void *memplugin_alloc(int sz, int height, mem_type memory_type)
 {
     MemHeader        *h;
-    struct omap_bo   *bo = omap_bo_new(dev, sz + sizeof(MemHeader), OMAP_BO_WC);
+    struct omap_bo   *bo = omap_bo_new(dev, sz + sizeof(MemHeader), OMAP_BO_CACHED);
 
     if( !bo ) {
         return (NULL);
@@ -55,6 +55,7 @@ void *memplugin_alloc(int sz, int height, mem_type memory_type)
     memset(H2P(h), 0, sz);
     h->size = sz;
     h->ptr = (void *)bo;
+    h->dma_buf_fd = 0;
 
     return (H2P(h));
 
@@ -80,7 +81,10 @@ int memplugin_share(void *ptr)
 {
     if( ptr ) {
         MemHeader   *h = P2H(ptr);
-        return (omap_bo_dmabuf((struct omap_bo *)h->ptr));
+        if( !h->dma_buf_fd ) {
+            h->dma_buf_fd = omap_bo_dmabuf((struct omap_bo *)h->ptr);
+        }
+        return (h->dma_buf_fd);
     }
     return (-1);
 }