Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/*
2* Copyright (c) 2016 MediaTek Inc.
3* Author: PC Chen <pc.chen@mediatek.com>
4* Tiffany Lin <tiffany.lin@mediatek.com>
5*
6* This program is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License version 2 as
8* published by the Free Software Foundation.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*/
15
16#include <linux/module.h>
17
18#include "mtk_vcodec_drv.h"
19#include "mtk_vcodec_util.h"
20#include "mtk_vpu.h"
21
22/* For encoder, this will enable logs in venc/*/
23bool mtk_vcodec_dbg;
24EXPORT_SYMBOL(mtk_vcodec_dbg);
25
26/* The log level of v4l2 encoder or decoder driver.
27 * That is, files under mtk-vcodec/.
28 */
29int mtk_v4l2_dbg_level;
30EXPORT_SYMBOL(mtk_v4l2_dbg_level);
31
32void __iomem *mtk_vcodec_get_reg_addr(struct mtk_vcodec_ctx *data,
33 unsigned int reg_idx)
34{
35 struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)data;
36
37 if (!data || reg_idx >= NUM_MAX_VCODEC_REG_BASE) {
38 mtk_v4l2_err("Invalid arguments, reg_idx=%d", reg_idx);
39 return NULL;
40 }
41 return ctx->dev->reg_base[reg_idx];
42}
43EXPORT_SYMBOL(mtk_vcodec_get_reg_addr);
44
45int mtk_vcodec_mem_alloc(struct mtk_vcodec_ctx *data,
46 struct mtk_vcodec_mem *mem)
47{
48 unsigned long size = mem->size;
49 struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)data;
50 struct device *dev = &ctx->dev->plat_dev->dev;
51
52 mem->va = dma_alloc_coherent(dev, size, &mem->dma_addr, GFP_KERNEL);
53
54 if (!mem->va) {
55 mtk_v4l2_err("%s dma_alloc size=%ld failed!", dev_name(dev),
56 size);
57 return -ENOMEM;
58 }
59
60 memset(mem->va, 0, size);
61
62 mtk_v4l2_debug(3, "[%d] - va = %p", ctx->id, mem->va);
63 mtk_v4l2_debug(3, "[%d] - dma = 0x%lx", ctx->id,
64 (unsigned long)mem->dma_addr);
65 mtk_v4l2_debug(3, "[%d] size = 0x%lx", ctx->id, size);
66
67 return 0;
68}
69EXPORT_SYMBOL(mtk_vcodec_mem_alloc);
70
71void mtk_vcodec_mem_free(struct mtk_vcodec_ctx *data,
72 struct mtk_vcodec_mem *mem)
73{
74 unsigned long size = mem->size;
75 struct mtk_vcodec_ctx *ctx = (struct mtk_vcodec_ctx *)data;
76 struct device *dev = &ctx->dev->plat_dev->dev;
77
78 if (!mem->va) {
79 mtk_v4l2_err("%s dma_free size=%ld failed!", dev_name(dev),
80 size);
81 return;
82 }
83
84 dma_free_coherent(dev, size, mem->va, mem->dma_addr);
85 mem->va = NULL;
86 mem->dma_addr = 0;
87 mem->size = 0;
88
89 mtk_v4l2_debug(3, "[%d] - va = %p", ctx->id, mem->va);
90 mtk_v4l2_debug(3, "[%d] - dma = 0x%lx", ctx->id,
91 (unsigned long)mem->dma_addr);
92 mtk_v4l2_debug(3, "[%d] size = 0x%lx", ctx->id, size);
93}
94EXPORT_SYMBOL(mtk_vcodec_mem_free);