168 lines
5.2 KiB
C
168 lines
5.2 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
/*
|
|
* Copyright (c) 2019 MediaTek Inc.
|
|
*/
|
|
|
|
#ifndef _MTK_VCODEC_UTIL_H_
|
|
#define _MTK_VCODEC_UTIL_H_
|
|
|
|
#include <aee.h>
|
|
#include <linux/types.h>
|
|
#include <linux/dma-direction.h>
|
|
|
|
/* #define FPGA_PWRCLK_API_DISABLE */
|
|
/* #define FPGA_INTERRUPT_API_DISABLE */
|
|
|
|
#define LOG_PARAM_INFO_SIZE 64
|
|
#define LOG_PROPERTY_SIZE 1024
|
|
|
|
struct mtk_vcodec_mem {
|
|
size_t length;
|
|
size_t size;
|
|
size_t data_offset;
|
|
void *va;
|
|
dma_addr_t dma_addr;
|
|
struct dma_buf *dmabuf;
|
|
__u32 flags;
|
|
__u32 index;
|
|
__s64 buf_fd;
|
|
};
|
|
|
|
/**
|
|
* enum flags - decoder different operation types
|
|
* @NO_CAHCE_FLUSH : no need to proceed cache flush
|
|
* @NO_CAHCE_INVALIDATE : no need to proceed cache invalidate
|
|
* @CROP_CHANGED : frame buffer crop changed
|
|
* @REF_FREED : frame buffer is reference freed
|
|
*/
|
|
enum mtk_vcodec_flags {
|
|
NO_CAHCE_CLEAN = 1,
|
|
NO_CAHCE_INVALIDATE = 1 << 1,
|
|
CROP_CHANGED = 1 << 2,
|
|
REF_FREED = 1 << 3
|
|
};
|
|
|
|
struct mtk_vcodec_ctx;
|
|
struct mtk_vcodec_dev;
|
|
|
|
extern int mtk_v4l2_dbg_level;
|
|
extern bool mtk_vcodec_dbg;
|
|
extern bool mtk_vcodec_perf;
|
|
|
|
#define DEBUG 1
|
|
|
|
#if defined(DEBUG)
|
|
|
|
#define mtk_v4l2_debug(level, fmt, args...) \
|
|
do { \
|
|
if ((mtk_v4l2_dbg_level & level) == level) \
|
|
pr_info("[MTK_V4L2] level=%d %s(),%d: " fmt "\n",\
|
|
level, __func__, __LINE__, ##args); \
|
|
} while (0)
|
|
|
|
#define mtk_v4l2_err(fmt, args...) \
|
|
pr_err("[MTK_V4L2][ERROR] %s:%d: " fmt "\n", __func__, __LINE__, \
|
|
##args)
|
|
|
|
|
|
#define mtk_v4l2_debug_enter() mtk_v4l2_debug(8, "+")
|
|
#define mtk_v4l2_debug_leave() mtk_v4l2_debug(8, "-")
|
|
|
|
#define mtk_vcodec_debug(h, fmt, args...) \
|
|
do { \
|
|
if (mtk_vcodec_dbg && h != NULL && h->ctx != NULL) \
|
|
pr_info("[MTK_VCODEC][%d]: %s() " fmt "\n", \
|
|
((struct mtk_vcodec_ctx *)h->ctx)->id, \
|
|
__func__, ##args); \
|
|
} while (0)
|
|
|
|
#define mtk_vcodec_perf_log(fmt, args...) \
|
|
do { \
|
|
if (mtk_vcodec_perf) \
|
|
pr_info("[MTK_PERF] " fmt "\n", ##args); \
|
|
} while (0)
|
|
|
|
|
|
#define mtk_vcodec_err(h, fmt, args...) \
|
|
do { \
|
|
if (h != NULL && h->ctx != NULL) \
|
|
pr_info("[MTK_VCODEC][ERROR][%d]: %s() " fmt "\n", \
|
|
((struct mtk_vcodec_ctx *)h->ctx)->id, __func__, ##args); \
|
|
} while (0)
|
|
|
|
#define mtk_vcodec_debug_enter(h) mtk_vcodec_debug(h, "+")
|
|
#define mtk_vcodec_debug_leave(h) mtk_vcodec_debug(h, "-")
|
|
|
|
#else
|
|
|
|
#define mtk_v4l2_debug(level, fmt, args...)
|
|
#define mtk_v4l2_err(fmt, args...)
|
|
#define mtk_v4l2_debug_enter()
|
|
#define mtk_v4l2_debug_leave()
|
|
|
|
#define mtk_vcodec_debug(h, fmt, args...)
|
|
#define mtk_vcodec_err(h, fmt, args...)
|
|
#define mtk_vcodec_debug_enter(h)
|
|
#define mtk_vcodec_debug_leave(h)
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MTK_AEE_FEATURE
|
|
#define v4l2_aee_print(string, args...) do {\
|
|
char vcu_name[100];\
|
|
int ret;\
|
|
ret = snprintf(vcu_name, 100, "[MTK_V4L2] "string, ##args); \
|
|
if (ret > 0)\
|
|
aee_kernel_warning_api(__FILE__, __LINE__, \
|
|
DB_OPT_MMPROFILE_BUFFER | DB_OPT_NE_JBT_TRACES, \
|
|
vcu_name, "[MTK_V4L2] error:"string, ##args); \
|
|
pr_info("[MTK_V4L2] error:"string, ##args); \
|
|
} while (0)
|
|
#else
|
|
#define v4l2_aee_print(string, args...) do {\
|
|
pr_info("[MTK_V4L2] error:"string, ##args); \
|
|
} while (0)
|
|
|
|
#endif
|
|
|
|
static __attribute__((used)) unsigned int time_ms_s[2][2], time_ms_e[2][2];
|
|
#define time_check_start(is_enc, id) {\
|
|
if (is_enc >= 0 && id >= 0) \
|
|
time_ms_s[is_enc][id] = jiffies_to_msecs(jiffies); \
|
|
}
|
|
#define time_check_end(is_enc, id, timeout_ms) do { \
|
|
if (is_enc < 0 || id < 0) \
|
|
break; \
|
|
time_ms_e[is_enc][id] = jiffies_to_msecs(jiffies); \
|
|
if ((time_ms_e[is_enc][id] - time_ms_s[is_enc][id]) \
|
|
> timeout_ms || \
|
|
mtk_vcodec_perf) \
|
|
pr_info("[V4L2][Info] %s L:%d take %u timeout %u ms", \
|
|
__func__, __LINE__, \
|
|
time_ms_e[is_enc][id] - time_ms_s[is_enc][id], \
|
|
timeout_ms); \
|
|
} while (0)
|
|
|
|
void __iomem *mtk_vcodec_get_dec_reg_addr(struct mtk_vcodec_ctx *data,
|
|
unsigned int reg_idx);
|
|
void __iomem *mtk_vcodec_get_enc_reg_addr(struct mtk_vcodec_ctx *data,
|
|
unsigned int reg_idx);
|
|
int mtk_vcodec_mem_alloc(struct mtk_vcodec_ctx *data,
|
|
struct mtk_vcodec_mem *mem);
|
|
void mtk_vcodec_mem_free(struct mtk_vcodec_ctx *data,
|
|
struct mtk_vcodec_mem *mem);
|
|
void mtk_vcodec_set_curr_ctx(struct mtk_vcodec_dev *dev,
|
|
struct mtk_vcodec_ctx *ctx, unsigned int hw_id);
|
|
struct mtk_vcodec_ctx *mtk_vcodec_get_curr_ctx(struct mtk_vcodec_dev *dev,
|
|
unsigned int hw_id);
|
|
void mtk_vcodec_add_ctx_list(struct mtk_vcodec_ctx *ctx);
|
|
void mtk_vcodec_del_ctx_list(struct mtk_vcodec_ctx *ctx);
|
|
struct vdec_fb *mtk_vcodec_get_fb(struct mtk_vcodec_ctx *ctx);
|
|
int mtk_vdec_put_fb(struct mtk_vcodec_ctx *ctx, int type);
|
|
void mtk_enc_put_buf(struct mtk_vcodec_ctx *ctx);
|
|
void v4l2_m2m_buf_queue_check(struct v4l2_m2m_ctx *m2m_ctx,
|
|
void *vbuf);
|
|
void mtk_vcodec_set_log(struct mtk_vcodec_ctx *ctx, char *val);
|
|
void mtk_vcodec_get_log(struct mtk_vcodec_ctx *ctx, char *val);
|
|
#endif /* _MTK_VCODEC_UTIL_H_ */
|