Browse Source

Codaj12: Optimizing buffer access for zero cpoy and fix dma buffer leak

Signed-off-by: Som Qin <som.qin@starfivetech.com>
Som Qin 9 months ago
parent
commit
17f40b1ac6
3 changed files with 20 additions and 6 deletions
  1. 1 1
      codaj12/jdi/linux/jdi.c
  2. 17 5
      codaj12/sample/helper/jpuhelper.c
  3. 2 0
      codaj12/sample/main_helper.h

+ 1 - 1
codaj12/jdi/linux/jdi.c

@@ -645,7 +645,7 @@ int jdi_allocate_dma_memory(jpu_buffer_t *vb)
     vb->base = (unsigned long)jdb.base;
 
     //map to virtual address
-    jdb.virt_addr = (unsigned long)mmap(NULL, jdb.size, PROT_READ | PROT_WRITE, MAP_SHARED, jdi->jpu_fd, MEM2SYS(jdb.phys_addr));
+    jdb.virt_addr = (unsigned long)mmap(NULL, jdb.size, PROT_READ | PROT_WRITE, MAP_SHARED, jdi->jpu_fd, jdb.phys_addr);
     if (jdb.virt_addr == (unsigned long)MAP_FAILED) {
         memset(vb, 0x00, sizeof(jpu_buffer_t));
         return -1;

+ 17 - 5
codaj12/sample/helper/jpuhelper.c

@@ -1416,7 +1416,7 @@ BOOL AttachOneFrameBuffer(Uint32 instIdx, FrameFormat subsample, CbCrInterLeave
 }
 
 void *AllocateOneFrameBuffer(Uint32 instIdx, FrameFormat subsample, CbCrInterLeave cbcrIntlv, PackedFormat packed,
-                         Uint32 rotation, BOOL scalerOn, Uint32 width, Uint32 height, Uint32 bitDepth, Uint32 *bufferIndex)
+                         Uint32 rotation, BOOL scalerOn, Uint32 width, Uint32 height, Uint32 bitDepth, Uint32 bufferIndex)
 {
     fb_context *fb;
     Uint32  fbLumaStride, fbLumaHeight, fbChromaStride, fbChromaHeight;
@@ -1471,9 +1471,10 @@ void *AllocateOneFrameBuffer(Uint32 instIdx, FrameFormat subsample, CbCrInterLea
         JLOG(ERR, "Fail to allocate frame buffer size=%d\n", fb->vb_base.size);
         return NULL;
     }
+    fb->vb[bufferIndex] = fb->vb_base;
     fb->last_addr = fb->vb_base.phys_addr;
 
-    i = fb->last_num;
+    i = bufferIndex;
     JLOG(INFO, "%s: store on index %d\r\n", __FUNCTION__, i);
     fb->frameBuf[i].Format = subsample;
     fb->frameBuf[i].Index  = i;
@@ -1502,10 +1503,8 @@ void *AllocateOneFrameBuffer(Uint32 instIdx, FrameFormat subsample, CbCrInterLea
     fb->frameBuf[i].strideY = fbLumaStride;
     fb->frameBuf[i].strideC = fbChromaStride;
 
-    *bufferIndex = fb->last_num;
-    fb->last_num += 1;
-
     virt_addr = (void *)fb->vb_base.virt_addr;
+    fb->last_num = bufferIndex + 1;
 
     JLOG(INFO, "%s function OUT, number = %d, return = %p\r\n", __FUNCTION__, fb->last_num, virt_addr);
     return virt_addr;
@@ -1934,6 +1933,19 @@ FRAME_BUF* FindFrameBuffer(int instIdx, PhysicalAddress addrY)
     return NULL;
 }
 
+void FreeOneFrameBuffer(int instIdx, unsigned int bufferIndex)
+{
+    fb_context *fb;
+
+    fb = &s_fb[instIdx];
+
+    if(fb->vb[bufferIndex].base)
+    {
+        jdi_free_dma_memory(&fb->vb[bufferIndex]);
+        fb->vb[bufferIndex].base = 0;
+    }
+}
+
 void FreeFrameBuffer(int instIdx)
 {
     fb_context *fb;

+ 2 - 0
codaj12/sample/main_helper.h

@@ -53,6 +53,7 @@ typedef struct {
 
 typedef struct {
     FRAME_BUF frameBuf[MAX_FRAME];
+    jpu_buffer_t vb[MAX_FRAME];
     jpu_buffer_t vb_base;
     int instIndex;
     int last_num;
@@ -247,6 +248,7 @@ extern BOOL ParseMultiLongOptions(TestMultiConfig* config, const char* argName,
 extern BOOL AllocateFrameBuffer(Uint32 instIdx, FrameFormat subsample, CbCrInterLeave cbcrIntlv, PackedFormat packed,
                                 Uint32 rotation, BOOL scalerOn, Uint32 width, Uint32 height, Uint32 bitDepth, Uint32 num);
 extern void FreeFrameBuffer(int instIdx);
+extern void FreeOneFrameBuffer(int instIdx, unsigned int bufferIndex);
 extern FRAME_BUF *GetFrameBuffer(int instIdx, int index);
 extern int GetFrameBufBase(int instIdx);
 extern int GetFrameBufAllocSize(int instIdx);