From: Nanxin Qin Date: Mon, 2 Nov 2020 08:35:27 +0000 (+0800) Subject: media: count buffer size for allocate coherent memory. [2/2] X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=36b414c850bc572a95bc93de531c4834cc062365;p=GitHub%2FLineageOS%2FG12%2Fandroid_hardware_amlogic_kernel-modules_media.git media: count buffer size for allocate coherent memory. [2/2] 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 --- diff --git a/drivers/amvdec_ports/aml_vcodec_util.c b/drivers/amvdec_ports/aml_vcodec_util.c index 03180ab..509a42a 100644 --- a/drivers/amvdec_ports/aml_vcodec_util.c +++ b/drivers/amvdec_ports/aml_vcodec_util.c @@ -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), diff --git a/drivers/frame_provider/decoder/utils/vdec_input.c b/drivers/frame_provider/decoder/utils/vdec_input.c index bfe22bb..1a9d301 100644 --- a/drivers/frame_provider/decoder/utils/vdec_input.c +++ b/drivers/frame_provider/decoder/utils/vdec_input.c @@ -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; diff --git a/drivers/frame_provider/decoder/utils/vdec_input.h b/drivers/frame_provider/decoder/utils/vdec_input.h index c5d8b66..8a6a7bf 100644 --- a/drivers/frame_provider/decoder/utils/vdec_input.h +++ b/drivers/frame_provider/decoder/utils/vdec_input.h @@ -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; diff --git a/drivers/frame_provider/decoder/utils/vdec_power_ctrl.c b/drivers/frame_provider/decoder/utils/vdec_power_ctrl.c index 12b81a0..9057a80 100644 --- a/drivers/frame_provider/decoder/utils/vdec_power_ctrl.c +++ b/drivers/frame_provider/decoder/utils/vdec_power_ctrl.c @@ -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)