media: count buffer size for allocate coherent memory. [2/2]
authorNanxin Qin <nanxin.qin@amlogic.com>
Mon, 2 Nov 2020 08:35:27 +0000 (16:35 +0800)
committerHui Zhang <hui.zhang@amlogic.com>
Tue, 8 Dec 2020 09:12:26 +0000 (01:12 -0800)
PD#SWPL-36112

Problem:
CtsMediaTestCases process crash when codec_mm_reserved

Solution:
count buffer size for allocate coherent memory

Verify:
ah212

Change-Id: Ic74cda41faf9d8d6fb50aa6ed4911dfce744a283
Signed-off-by: Nanxin Qin <nanxin.qin@amlogic.com>
drivers/amvdec_ports/aml_vcodec_util.c
drivers/frame_provider/decoder/utils/vdec_input.c
drivers/frame_provider/decoder/utils/vdec_input.h
drivers/frame_provider/decoder/utils/vdec_power_ctrl.c

index 03180abd8f81cb4e023e75500a1eccd0fab2ce6d..509a42aa7e32f8d0612d3d8a5625ee295ae3cc6a 100644 (file)
@@ -43,9 +43,9 @@ int aml_vcodec_mem_alloc(struct aml_vcodec_ctx *data,
        struct aml_vcodec_ctx *ctx = (struct aml_vcodec_ctx *)data;
        struct device *dev = &ctx->dev->plat_dev->dev;
 
-       //mem->vaddr = dma_alloc_coherent(dev, size, &mem->dma_addr, GFP_KERNEL);
-       mem->vaddr = codec_mm_dma_alloc_coherent(dev_name(dev), size,
-                       &mem->dma_addr, GFP_KERNEL, 0);
+       mem->vaddr = dma_alloc_coherent(dev, size, &mem->dma_addr, GFP_KERNEL);
+       //mem->vaddr = codec_mm_dma_alloc_coherent(dev_name(dev), size,
+       //              &mem->dma_addr, GFP_KERNEL, 0);
        if (!mem->vaddr) {
                v4l_dbg(ctx, V4L_DEBUG_CODEC_ERROR,
                        "%s dma_alloc size=%ld failed!\n", dev_name(dev),
index bfe22bbbaf7fa63d68862aafdc74a05df4278b5b..1a9d301b267df097291d822c54fd0cb0b28ff949 100644 (file)
@@ -223,10 +223,18 @@ static void vframe_block_add_chunk(struct vframe_block_list_s *block,
        block->input->sequence++;
 }
 
+static bool is_coherent_buff = 1;
+
 static void vframe_block_free_block(struct vframe_block_list_s *block)
 {
-       if (block->addr) {
-               codec_mm_free_for_dma(MEM_NAME, block->addr);
+       if (is_coherent_buff) {
+               if (block->mem_handle) {
+                       codec_mm_dma_free_coherent(block->mem_handle);
+               }
+       } else {
+               if (block->addr) {
+                       codec_mm_free_for_dma(MEM_NAME, block->addr);
+               }
        }
        /*
        *pr_err("free block %d, size=%d\n", block->id, block->size);
@@ -258,20 +266,25 @@ static int vframe_block_init_alloc_storage(struct vdec_input_s *input,
                block->priv = priv;
        } else {
                alloc_size = PAGE_ALIGN(alloc_size);
-               block->addr = codec_mm_alloc_for_dma_ex(
-                       MEM_NAME,
-                       alloc_size/PAGE_SIZE,
-                       VFRAME_BLOCK_PAGEALIGN,
-                       CODEC_MM_FLAGS_DMA_CPU | CODEC_MM_FLAGS_FOR_VDECODER,
-                       input->id,
-                       block->id);
+               if (is_coherent_buff) {
+                       block->start_virt = codec_mm_dma_alloc_coherent(&block->mem_handle, &block->addr, alloc_size, MEM_NAME);
+               } else {
+                       block->addr = codec_mm_alloc_for_dma_ex(
+                               MEM_NAME,
+                               alloc_size/PAGE_SIZE,
+                               VFRAME_BLOCK_PAGEALIGN,
+                               CODEC_MM_FLAGS_DMA_CPU | CODEC_MM_FLAGS_FOR_VDECODER,
+                               input->id,
+                               block->id);
+               }
 
                if (!block->addr) {
                        pr_err("Input block allocation failed\n");
                        return -ENOMEM;
                }
 
-               block->start_virt = (void *)codec_mm_phys_to_virt(block->addr);
+               if (!is_coherent_buff)
+                       block->start_virt = (void *)codec_mm_phys_to_virt(block->addr);
                if (block->start_virt)
                        block->is_mapped = true;
                block->start = block->addr;
@@ -525,10 +538,9 @@ int vdec_input_set_buffer(struct vdec_input_s *input, u32 start, u32 size)
                input->swap_page_phys = codec_mm_alloc_for_dma("SWAP",
                        1, 0, CODEC_MM_FLAGS_TVP);
        else {
-               input->swap_page = dma_alloc_coherent(v4l_get_dev_from_codec_mm(),
-                               PAGE_SIZE,
-                               &input->swap_page_phys, GFP_KERNEL);
-
+               input->swap_page = codec_mm_dma_alloc_coherent(&input->mem_handle,
+                               (ulong *)&input->swap_page_phys,
+                               PAGE_SIZE, MEM_NAME);
                if (input->swap_page == NULL)
                        return -ENOMEM;
        }
@@ -1156,11 +1168,8 @@ void vdec_input_release(struct vdec_input_s *input)
                if (input->swap_page_phys)
                        codec_mm_free_for_dma("SWAP", input->swap_page_phys);
        } else {
-               if (input->swap_page) {
-                       dma_free_coherent(v4l_get_dev_from_codec_mm(),
-                               PAGE_SIZE, input->swap_page,
-                               input->swap_page_phys);
-               }
+               if (input->swap_page)
+                       codec_mm_dma_free_coherent(input->mem_handle);
        }
        input->swap_page = NULL;
        input->swap_page_phys = 0;
index c5d8b66aca79a3f34661297856e75558b63b7e79..8a6a7bf498a1157b36cc18fcc222bf95ef8b2812 100644 (file)
@@ -39,7 +39,7 @@ struct vframe_block_list_s {
        int chunk_count;
        int is_out_buf;
        u32 handle;
-
+       ulong mem_handle;
        /* free callback */
        chunk_free free;
        void* priv;
@@ -89,6 +89,7 @@ struct vdec_input_s {
        bool swap_valid;
        bool swap_needed;
        bool eos;
+       ulong mem_handle;
        void *swap_page;
        dma_addr_t swap_page_phys;
        u64 total_wr_count;
index 12b81a0f7a452ae50e8110e7911d62d31d5fb551..9057a8053a43f1d3e12678525d3ee288ebf15bdb 100644 (file)
@@ -256,7 +256,8 @@ static void pm_vdec_legacy_power_off(struct device *dev, int id);
 static void pm_vdec_legacy_power_on(struct device *dev, int id)
 {
        void *decomp_addr = NULL;
-       dma_addr_t decomp_dma_addr;
+       ulong decomp_dma_addr;
+       ulong mem_handle;
        u32 decomp_addr_aligned = 0;
        int hevc_loop = 0;
        int sleep_val, iso_val;
@@ -268,9 +269,8 @@ static void pm_vdec_legacy_power_on(struct device *dev, int id)
 
        if (hevc_workaround_needed() &&
                (id == VDEC_HEVC)) {
-               decomp_addr = codec_mm_dma_alloc_coherent("vdec_prealloc",
-                       SZ_64K + SZ_4K, &decomp_dma_addr, GFP_KERNEL, 0);
-
+               decomp_addr = codec_mm_dma_alloc_coherent(&mem_handle,
+                       &decomp_dma_addr, SZ_64K + SZ_4K, "vdec_prealloc");
                if (decomp_addr) {
                        decomp_addr_aligned = ALIGN(decomp_dma_addr, SZ_64K);
                        memset((u8 *)decomp_addr +
@@ -487,8 +487,7 @@ static void pm_vdec_legacy_power_on(struct device *dev, int id)
        }
 
        if (decomp_addr)
-               codec_mm_dma_free_coherent("vdec_prealloc",
-                       SZ_64K + SZ_4K, decomp_addr, decomp_dma_addr, 0);
+               codec_mm_dma_free_coherent(mem_handle);
 }
 
 static void pm_vdec_legacy_power_off(struct device *dev, int id)