2016-05-03 07:11:24 -03:00
/*
* Copyright ( c ) 2016 MediaTek Inc .
* Author : PC Chen < pc . chen @ mediatek . com >
* Tiffany Lin < tiffany . lin @ mediatek . com >
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*/
# include <linux/module.h>
# include "mtk_vcodec_drv.h"
# include "mtk_vcodec_util.h"
# include "mtk_vpu.h"
/* For encoder, this will enable logs in venc/*/
bool mtk_vcodec_dbg ;
EXPORT_SYMBOL ( mtk_vcodec_dbg ) ;
/* The log level of v4l2 encoder or decoder driver.
* That is , files under mtk - vcodec / .
*/
int mtk_v4l2_dbg_level ;
EXPORT_SYMBOL ( mtk_v4l2_dbg_level ) ;
void __iomem * mtk_vcodec_get_reg_addr ( struct mtk_vcodec_ctx * data ,
unsigned int reg_idx )
{
struct mtk_vcodec_ctx * ctx = ( struct mtk_vcodec_ctx * ) data ;
if ( ! data | | reg_idx > = NUM_MAX_VCODEC_REG_BASE ) {
mtk_v4l2_err ( " Invalid arguments, reg_idx=%d " , reg_idx ) ;
return NULL ;
}
return ctx - > dev - > reg_base [ reg_idx ] ;
}
EXPORT_SYMBOL ( mtk_vcodec_get_reg_addr ) ;
int mtk_vcodec_mem_alloc ( struct mtk_vcodec_ctx * data ,
struct mtk_vcodec_mem * mem )
{
unsigned long size = mem - > size ;
struct mtk_vcodec_ctx * ctx = ( struct mtk_vcodec_ctx * ) data ;
struct device * dev = & ctx - > dev - > plat_dev - > dev ;
cross-tree: phase out dma_zalloc_coherent()
We already need to zero out memory for dma_alloc_coherent(), as such
using dma_zalloc_coherent() is superflous. Phase it out.
This change was generated with the following Coccinelle SmPL patch:
@ replace_dma_zalloc_coherent @
expression dev, size, data, handle, flags;
@@
-dma_zalloc_coherent(dev, size, handle, flags)
+dma_alloc_coherent(dev, size, handle, flags)
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
[hch: re-ran the script on the latest tree]
Signed-off-by: Christoph Hellwig <hch@lst.de>
2019-01-04 09:23:09 +01:00
mem - > va = dma_alloc_coherent ( dev , size , & mem - > dma_addr , GFP_KERNEL ) ;
2016-05-03 07:11:24 -03:00
if ( ! mem - > va ) {
mtk_v4l2_err ( " %s dma_alloc size=%ld failed! " , dev_name ( dev ) ,
size ) ;
return - ENOMEM ;
}
mtk_v4l2_debug ( 3 , " [%d] - va = %p " , ctx - > id , mem - > va ) ;
mtk_v4l2_debug ( 3 , " [%d] - dma = 0x%lx " , ctx - > id ,
( unsigned long ) mem - > dma_addr ) ;
mtk_v4l2_debug ( 3 , " [%d] size = 0x%lx " , ctx - > id , size ) ;
return 0 ;
}
EXPORT_SYMBOL ( mtk_vcodec_mem_alloc ) ;
void mtk_vcodec_mem_free ( struct mtk_vcodec_ctx * data ,
struct mtk_vcodec_mem * mem )
{
unsigned long size = mem - > size ;
struct mtk_vcodec_ctx * ctx = ( struct mtk_vcodec_ctx * ) data ;
struct device * dev = & ctx - > dev - > plat_dev - > dev ;
if ( ! mem - > va ) {
mtk_v4l2_err ( " %s dma_free size=%ld failed! " , dev_name ( dev ) ,
size ) ;
return ;
}
mtk_v4l2_debug ( 3 , " [%d] - va = %p " , ctx - > id , mem - > va ) ;
mtk_v4l2_debug ( 3 , " [%d] - dma = 0x%lx " , ctx - > id ,
( unsigned long ) mem - > dma_addr ) ;
mtk_v4l2_debug ( 3 , " [%d] size = 0x%lx " , ctx - > id , size ) ;
2016-09-02 09:19:54 -03:00
dma_free_coherent ( dev , size , mem - > va , mem - > dma_addr ) ;
mem - > va = NULL ;
mem - > dma_addr = 0 ;
mem - > size = 0 ;
2016-05-03 07:11:24 -03:00
}
EXPORT_SYMBOL ( mtk_vcodec_mem_free ) ;
2016-09-02 09:19:54 -03:00
void mtk_vcodec_set_curr_ctx ( struct mtk_vcodec_dev * dev ,
struct mtk_vcodec_ctx * ctx )
{
unsigned long flags ;
spin_lock_irqsave ( & dev - > irqlock , flags ) ;
dev - > curr_ctx = ctx ;
spin_unlock_irqrestore ( & dev - > irqlock , flags ) ;
}
EXPORT_SYMBOL ( mtk_vcodec_set_curr_ctx ) ;
struct mtk_vcodec_ctx * mtk_vcodec_get_curr_ctx ( struct mtk_vcodec_dev * dev )
{
unsigned long flags ;
struct mtk_vcodec_ctx * ctx ;
spin_lock_irqsave ( & dev - > irqlock , flags ) ;
ctx = dev - > curr_ctx ;
spin_unlock_irqrestore ( & dev - > irqlock , flags ) ;
return ctx ;
}
EXPORT_SYMBOL ( mtk_vcodec_get_curr_ctx ) ;
2017-11-20 02:47:54 -05:00
MODULE_LICENSE ( " GPL v2 " ) ;
MODULE_DESCRIPTION ( " Mediatek video codec driver " ) ;