summaryrefslogtreecommitdiff
path: root/drivers/amvdec_ports/aml_vcodec_util.c (plain)
blob: 0026c6a2ad40801c0d46a7e195970422ee17f446
1/*
2* Copyright (C) 2017 Amlogic, Inc. All rights reserved.
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful, but WITHOUT
10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12* more details.
13*
14* You should have received a copy of the GNU General Public License along
15* with this program; if not, write to the Free Software Foundation, Inc.,
16* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17*
18* Description:
19*/
20#include <linux/module.h>
21
22#include "aml_vcodec_drv.h"
23#include "aml_vcodec_util.h"
24//#include "aml_vpu.h"
25
26/* For encoder, this will enable logs in venc/*/
27bool aml_vcodec_dbg;
28EXPORT_SYMBOL(aml_vcodec_dbg);
29
30/* The log level of v4l2 encoder or decoder driver.
31 * That is, files under aml-vcodec/.
32 */
33int aml_v4l2_dbg_level;
34EXPORT_SYMBOL(aml_v4l2_dbg_level);
35
36void __iomem *aml_vcodec_get_reg_addr(struct aml_vcodec_ctx *data,
37 unsigned int reg_idx)
38{
39 struct aml_vcodec_ctx *ctx = (struct aml_vcodec_ctx *)data;
40
41 if (!data || reg_idx >= NUM_MAX_VCODEC_REG_BASE) {
42 aml_v4l2_err("Invalid arguments, reg_idx=%d", reg_idx);
43 return NULL;
44 }
45 return ctx->dev->reg_base[reg_idx];
46}
47EXPORT_SYMBOL(aml_vcodec_get_reg_addr);
48
49int aml_vcodec_mem_alloc(struct aml_vcodec_ctx *data,
50 struct aml_vcodec_mem *mem)
51{
52 unsigned long size = mem->size;
53 struct aml_vcodec_ctx *ctx = (struct aml_vcodec_ctx *)data;
54 struct device *dev = &ctx->dev->plat_dev->dev;
55
56 //mem->va = dma_alloc_coherent(dev, size, &mem->dma_addr, GFP_KERNEL);
57 mem->va = codec_mm_dma_alloc_coherent(dev_name(dev), size,
58 &mem->dma_addr, GFP_KERNEL, 0);
59 if (!mem->va) {
60 aml_v4l2_err("%s dma_alloc size=%ld failed!", dev_name(dev),
61 size);
62 return -ENOMEM;
63 }
64
65 memset(mem->va, 0, size);
66
67 aml_v4l2_debug(4, "[%d] - va = %p", ctx->id, mem->va);
68 aml_v4l2_debug(4, "[%d] - dma = 0x%lx", ctx->id,
69 (unsigned long)mem->dma_addr);
70 aml_v4l2_debug(4, "[%d] size = 0x%lx", ctx->id, size);
71
72 return 0;
73}
74EXPORT_SYMBOL(aml_vcodec_mem_alloc);
75
76void aml_vcodec_mem_free(struct aml_vcodec_ctx *data,
77 struct aml_vcodec_mem *mem)
78{
79 unsigned long size = mem->size;
80 struct aml_vcodec_ctx *ctx = (struct aml_vcodec_ctx *)data;
81 struct device *dev = &ctx->dev->plat_dev->dev;
82
83 if (!mem->va) {
84 aml_v4l2_err("%s dma_free size=%ld failed!", dev_name(dev),
85 size);
86 return;
87 }
88
89 aml_v4l2_debug(4, "[%d] - va = %p", ctx->id, mem->va);
90 aml_v4l2_debug(4, "[%d] - dma = 0x%lx", ctx->id,
91 (unsigned long)mem->dma_addr);
92 aml_v4l2_debug(4, "[%d] size = 0x%lx", ctx->id, size);
93
94 dma_free_coherent(dev, size, mem->va, mem->dma_addr);
95 mem->va = NULL;
96 mem->dma_addr = 0;
97 mem->size = 0;
98}
99EXPORT_SYMBOL(aml_vcodec_mem_free);
100
101void aml_vcodec_set_curr_ctx(struct aml_vcodec_dev *dev,
102 struct aml_vcodec_ctx *ctx)
103{
104 unsigned long flags;
105
106 spin_lock_irqsave(&dev->irqlock, flags);
107 dev->curr_ctx = ctx;
108 spin_unlock_irqrestore(&dev->irqlock, flags);
109}
110EXPORT_SYMBOL(aml_vcodec_set_curr_ctx);
111
112struct aml_vcodec_ctx *aml_vcodec_get_curr_ctx(struct aml_vcodec_dev *dev)
113{
114 unsigned long flags;
115 struct aml_vcodec_ctx *ctx;
116
117 spin_lock_irqsave(&dev->irqlock, flags);
118 ctx = dev->curr_ctx;
119 spin_unlock_irqrestore(&dev->irqlock, flags);
120 return ctx;
121}
122EXPORT_SYMBOL(aml_vcodec_get_curr_ctx);
123