summaryrefslogtreecommitdiff
path: root/drivers/amvdec_ports/aml_vcodec_util.c (plain)
blob: 03180abd8f81cb4e023e75500a1eccd0fab2ce6d
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
25void __iomem *aml_vcodec_get_reg_addr(struct aml_vcodec_ctx *data,
26 unsigned int reg_idx)
27{
28 struct aml_vcodec_ctx *ctx = (struct aml_vcodec_ctx *)data;
29
30 if (!data || reg_idx >= NUM_MAX_VCODEC_REG_BASE) {
31 v4l_dbg(ctx, V4L_DEBUG_CODEC_ERROR,
32 "Invalid arguments, reg_idx=%d\n", reg_idx);
33 return NULL;
34 }
35 return ctx->dev->reg_base[reg_idx];
36}
37EXPORT_SYMBOL(aml_vcodec_get_reg_addr);
38
39int aml_vcodec_mem_alloc(struct aml_vcodec_ctx *data,
40 struct aml_vcodec_mem *mem)
41{
42 unsigned long size = mem->size;
43 struct aml_vcodec_ctx *ctx = (struct aml_vcodec_ctx *)data;
44 struct device *dev = &ctx->dev->plat_dev->dev;
45
46 //mem->vaddr = dma_alloc_coherent(dev, size, &mem->dma_addr, GFP_KERNEL);
47 mem->vaddr = codec_mm_dma_alloc_coherent(dev_name(dev), size,
48 &mem->dma_addr, GFP_KERNEL, 0);
49 if (!mem->vaddr) {
50 v4l_dbg(ctx, V4L_DEBUG_CODEC_ERROR,
51 "%s dma_alloc size=%ld failed!\n", dev_name(dev),
52 size);
53 return -ENOMEM;
54 }
55
56 memset(mem->vaddr, 0, size);
57
58 v4l_dbg(ctx, V4L_DEBUG_CODEC_PRINFO, "va: %p\n", mem->vaddr);
59 v4l_dbg(ctx, V4L_DEBUG_CODEC_PRINFO, "dma: 0x%lx\n", (ulong) mem->dma_addr);
60 v4l_dbg(ctx, V4L_DEBUG_CODEC_PRINFO, "size: 0x%lx\n", size);
61
62 return 0;
63}
64EXPORT_SYMBOL(aml_vcodec_mem_alloc);
65
66void aml_vcodec_mem_free(struct aml_vcodec_ctx *data,
67 struct aml_vcodec_mem *mem)
68{
69 unsigned long size = mem->size;
70 struct aml_vcodec_ctx *ctx = (struct aml_vcodec_ctx *)data;
71 struct device *dev = &ctx->dev->plat_dev->dev;
72
73 if (!mem->vaddr) {
74 v4l_dbg(ctx, V4L_DEBUG_CODEC_ERROR,
75 "%s dma_free size=%ld failed!\n", dev_name(dev),
76 size);
77 return;
78 }
79
80 v4l_dbg(ctx, V4L_DEBUG_CODEC_PRINFO, "va: %p\n", mem->vaddr);
81 v4l_dbg(ctx, V4L_DEBUG_CODEC_PRINFO, "dma: 0x%lx\n", (ulong) mem->dma_addr);
82 v4l_dbg(ctx, V4L_DEBUG_CODEC_PRINFO, "size: 0x%lx\n", size);
83
84 dma_free_coherent(dev, size, mem->vaddr, mem->dma_addr);
85 mem->vaddr = NULL;
86 mem->dma_addr = 0;
87 mem->size = 0;
88}
89EXPORT_SYMBOL(aml_vcodec_mem_free);
90
91void aml_vcodec_set_curr_ctx(struct aml_vcodec_dev *dev,
92 struct aml_vcodec_ctx *ctx)
93{
94 unsigned long flags;
95
96 spin_lock_irqsave(&dev->irqlock, flags);
97 dev->curr_ctx = ctx;
98 spin_unlock_irqrestore(&dev->irqlock, flags);
99}
100EXPORT_SYMBOL(aml_vcodec_set_curr_ctx);
101
102struct aml_vcodec_ctx *aml_vcodec_get_curr_ctx(struct aml_vcodec_dev *dev)
103{
104 unsigned long flags;
105 struct aml_vcodec_ctx *ctx;
106
107 spin_lock_irqsave(&dev->irqlock, flags);
108 ctx = dev->curr_ctx;
109 spin_unlock_irqrestore(&dev->irqlock, flags);
110 return ctx;
111}
112EXPORT_SYMBOL(aml_vcodec_get_curr_ctx);
113