Files
android/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h
T
threeeye bc1d038eac REVVL 6 Pro kernel bring-up: full working tree snapshot (2026-09-12)
Squashed backup commit (no shallow-clone history issues) of
xiaomi-mt6833-dev/kernel_xiaomi_mt6833 (lineage-23.2 branch, upstream
commit 9eece662e) plus all fixes applied to get everpal_defconfig building
clean against a modern (GCC 15.2.0) toolchain -- see the previous commit
message on the lineage-23.2 branch (also in this repo history is not
available here since this is a squashed snapshot; full incremental history
lives in the local DL380 checkout and the upstream GitHub remote).

Upstream: https://github.com/xiaomi-mt6833-dev/kernel_xiaomi_mt6833 (lineage-23.2)
2026-09-12 13:36:46 +00:00

171 lines
5.3 KiB
C

/*
* 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.
*/
#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 */
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) \
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...) \
pr_info("[MTK_VCODEC][ERROR][%d]: %s() " fmt "\n", \
((struct mtk_vcodec_ctx *)h->ctx)->id, __func__, ##args)
#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)
#define mtk_vcodec_perf_log(fmt, args...)
#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);
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);
#endif /* _MTK_VCODEC_UTIL_H_ */