at v5.3 109 lines 2.9 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2/* 3* Copyright (c) 2016 MediaTek Inc. 4* Author: PC Chen <pc.chen@mediatek.com> 5* Tiffany Lin <tiffany.lin@mediatek.com> 6*/ 7 8#include <linux/module.h> 9 10#include "mtk_vcodec_drv.h" 11#include "mtk_vcodec_util.h" 12#include "mtk_vpu.h" 13 14/* For encoder, this will enable logs in venc/*/ 15bool mtk_vcodec_dbg; 16EXPORT_SYMBOL(mtk_vcodec_dbg); 17 18/* The log level of v4l2 encoder or decoder driver. 19 * That is, files under mtk-vcodec/. 20 */ 21int mtk_v4l2_dbg_level; 22EXPORT_SYMBOL(mtk_v4l2_dbg_level); 23 24void __iomem *mtk_vcodec_get_reg_addr(struct mtk_vcodec_ctx *data, 25 unsigned int reg_idx) 26{ 27 struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)data; 28 29 if (!data || reg_idx >= NUM_MAX_VCODEC_REG_BASE) { 30 mtk_v4l2_err("Invalid arguments, reg_idx=%d", reg_idx); 31 return NULL; 32 } 33 return ctx->dev->reg_base[reg_idx]; 34} 35EXPORT_SYMBOL(mtk_vcodec_get_reg_addr); 36 37int mtk_vcodec_mem_alloc(struct mtk_vcodec_ctx *data, 38 struct mtk_vcodec_mem *mem) 39{ 40 unsigned long size = mem->size; 41 struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)data; 42 struct device *dev = &ctx->dev->plat_dev->dev; 43 44 mem->va = dma_alloc_coherent(dev, size, &mem->dma_addr, GFP_KERNEL); 45 if (!mem->va) { 46 mtk_v4l2_err("%s dma_alloc size=%ld failed!", dev_name(dev), 47 size); 48 return -ENOMEM; 49 } 50 51 mtk_v4l2_debug(3, "[%d] - va = %p", ctx->id, mem->va); 52 mtk_v4l2_debug(3, "[%d] - dma = 0x%lx", ctx->id, 53 (unsigned long)mem->dma_addr); 54 mtk_v4l2_debug(3, "[%d] size = 0x%lx", ctx->id, size); 55 56 return 0; 57} 58EXPORT_SYMBOL(mtk_vcodec_mem_alloc); 59 60void mtk_vcodec_mem_free(struct mtk_vcodec_ctx *data, 61 struct mtk_vcodec_mem *mem) 62{ 63 unsigned long size = mem->size; 64 struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)data; 65 struct device *dev = &ctx->dev->plat_dev->dev; 66 67 if (!mem->va) { 68 mtk_v4l2_err("%s dma_free size=%ld failed!", dev_name(dev), 69 size); 70 return; 71 } 72 73 mtk_v4l2_debug(3, "[%d] - va = %p", ctx->id, mem->va); 74 mtk_v4l2_debug(3, "[%d] - dma = 0x%lx", ctx->id, 75 (unsigned long)mem->dma_addr); 76 mtk_v4l2_debug(3, "[%d] size = 0x%lx", ctx->id, size); 77 78 dma_free_coherent(dev, size, mem->va, mem->dma_addr); 79 mem->va = NULL; 80 mem->dma_addr = 0; 81 mem->size = 0; 82} 83EXPORT_SYMBOL(mtk_vcodec_mem_free); 84 85void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *dev, 86 struct mtk_vcodec_ctx *ctx) 87{ 88 unsigned long flags; 89 90 spin_lock_irqsave(&dev->irqlock, flags); 91 dev->curr_ctx = ctx; 92 spin_unlock_irqrestore(&dev->irqlock, flags); 93} 94EXPORT_SYMBOL(mtk_vcodec_set_curr_ctx); 95 96struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *dev) 97{ 98 unsigned long flags; 99 struct mtk_vcodec_ctx *ctx; 100 101 spin_lock_irqsave(&dev->irqlock, flags); 102 ctx = dev->curr_ctx; 103 spin_unlock_irqrestore(&dev->irqlock, flags); 104 return ctx; 105} 106EXPORT_SYMBOL(mtk_vcodec_get_curr_ctx); 107 108MODULE_LICENSE("GPL v2"); 109MODULE_DESCRIPTION("Mediatek video codec driver");