Browse Source

Merge remote-tracking branch 'remotes/origin/video-kernel-waipio.lnx.1.0' into origin/video-kernel.lnx.1.0

Praveen Chavan 3 years ago
parent
commit
b0542cb78c

+ 7 - 2
driver/platform/waipio/src/msm_vidc_waipio.c

@@ -149,8 +149,13 @@ static struct msm_platform_inst_capability instance_data_waipio[] = {
 		0, 0,
 		CAP_FLAG_ROOT,
 		{0},
-		{PROFILE, MIN_FRAME_QP, MAX_FRAME_QP, I_FRAME_QP, P_FRAME_QP,
-			B_FRAME_QP, META_ROI_INFO, BLUR_TYPES, MIN_QUALITY}},
+		{/* Do not change order of META_ROI_INFO, MIN_QUALITY, BLUR_TYPES
+		 * Since parent -> children relationship for these cap_ids is
+		 * as follows:
+		 * META_ROI_INFO -> MIN_QUALITY -> BLUR_TYPES
+		 */
+		PROFILE, MIN_FRAME_QP, MAX_FRAME_QP, I_FRAME_QP, P_FRAME_QP,
+			B_FRAME_QP, META_ROI_INFO, MIN_QUALITY, BLUR_TYPES}},
 
 	{PIX_FMTS, DEC, HEVC|HEIC,
 		MSM_VIDC_FMT_NV12,

+ 24 - 2
driver/variant/iris2/src/msm_vidc_iris2.c

@@ -213,6 +213,7 @@ static int __prepare_enable_clock_iris2(struct msm_vidc_core *core,
 	int rc = 0;
 	struct clock_info *cl;
 	bool found;
+	u64 rate = 0;
 
 	if (!core || !clk_name) {
 		d_vpr_e("%s: invalid params\n", __func__);
@@ -233,8 +234,16 @@ static int __prepare_enable_clock_iris2(struct msm_vidc_core *core,
 		 * them.  Since we don't really have a load at this point, scale
 		 * it to the lowest frequency possible
 		 */
-		if (cl->has_scaling)
-			__set_clk_rate(core, cl, clk_round_rate(cl->clk, 0));
+		if (cl->has_scaling) {
+			rate = clk_round_rate(cl->clk, 0);
+			/**
+			 * source clock is already multipled with scaling ratio and __set_clk_rate
+			 * attempts to multiply again. So divide scaling ratio before calling
+			 * __set_clk_rate.
+			 */
+			rate = rate / MSM_VIDC_CLOCK_SOURCE_SCALING_RATIO;
+			__set_clk_rate(core, cl, rate);
+		}
 
 		rc = clk_prepare_enable(cl->clk);
 		if (rc) {
@@ -586,6 +595,13 @@ static int __power_off_iris2_controller(struct msm_vidc_core *core)
 		rc = 0;
 	}
 
+	/* Turn off MVP MVS0 SRC clock */
+	rc = __disable_unprepare_clock_iris2(core, "video_cc_mvs0_clk_src");
+	if (rc) {
+		d_vpr_e("%s: disable unprepare video_cc_mvs0_clk_src failed\n", __func__);
+		rc = 0;
+	}
+
 	return rc;
 }
 
@@ -639,8 +655,14 @@ static int __power_on_iris2_controller(struct msm_vidc_core *core)
 	if (rc)
 		goto fail_clk_controller;
 
+	rc = __prepare_enable_clock_iris2(core, "video_cc_mvs0_clk_src");
+	if (rc)
+		goto fail_clk_src;
+
 	return 0;
 
+fail_clk_src:
+	__disable_unprepare_clock_iris2(core, "core_clk");
 fail_clk_controller:
 	__disable_unprepare_clock_iris2(core, "gcc_video_axi0");
 fail_clk_axi:

+ 10 - 0
driver/variant/iris2/src/msm_vidc_power_iris2.c

@@ -165,6 +165,10 @@ u64 msm_vidc_calc_freq_iris2(struct msm_vidc_inst *inst, u32 data_size)
 
 		vsp_cycles += mbs_per_second * base_cycles;
 
+		/* Add 25 percent extra for 960fps use case */
+		if (fps >= MAXIMUM_FPS)
+			vsp_cycles += div_u64(vpp_cycles * 25, 100);
+
 		if (inst->codec == MSM_VIDC_VP9 &&
 				inst->capabilities->cap[STAGE].value ==
 					MSM_VIDC_STAGE_2 &&
@@ -367,6 +371,12 @@ static u64 __calculate_decoder(struct vidc_bus_vote_data *d)
 	llc.total = llc.dpb_read + llc.line_buffer_read +
 			llc.line_buffer_write + ddr.total;
 
+	/* Add 25 percent extra for 960fps use case */
+	if (fps >= MAXIMUM_FPS) {
+		ddr.total += div_u64(ddr.total * 25, 100);
+		llc.total += div_u64(llc.total * 25, 100);
+	}
+
 	/* Dump all the variables for easier debugging */
 	if (msm_vidc_debug & VIDC_BUS) {
 		struct dump dump[] = {

+ 2 - 0
driver/vidc/inc/msm_vidc_debug.h

@@ -34,6 +34,8 @@ extern unsigned int msm_vidc_debug;
 extern bool msm_vidc_lossless_encode;
 extern bool msm_vidc_syscache_disable;
 extern int msm_vidc_clock_voting;
+extern int msm_vidc_ddr_bw;
+extern int msm_vidc_llc_bw;
 extern bool msm_vidc_fw_dump;
 extern unsigned int msm_vidc_enable_bugon;
 

+ 298 - 0
driver/vidc/inc/msm_vidc_events.h

@@ -0,0 +1,298 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2012-2021, The Linux Foundation. All rights reserved.
+ */
+
+#if !defined(_TRACE_MSM_VIDC_H) || defined(TRACE_HEADER_MULTI_READ)
+#define _TRACE_MSM_VIDC_H
+
+#undef TRACE_SYSTEM
+#define TRACE_SYSTEM msm_vidc_events
+#undef TRACE_INCLUDE_PATH
+#define TRACE_INCLUDE_PATH .
+#undef TRACE_INCLUDE_FILE
+#define TRACE_INCLUDE_FILE msm_vidc_events
+
+#include <linux/tracepoint.h>
+#include "msm_vidc_inst.h"
+
+DECLARE_EVENT_CLASS(msm_v4l2_vidc_inst,
+
+	TP_PROTO(char *dummy, struct msm_vidc_inst *inst),
+
+	TP_ARGS(dummy, inst),
+
+	TP_STRUCT__entry(
+		__field(char *, dummy)
+		__field(const char *, debug_str)
+	),
+
+	TP_fast_assign(
+		__entry->dummy = dummy;
+		__entry->debug_str = inst ? inst->debug_str : (u8 *)"";
+	),
+
+	TP_printk("%s: %s\n", __entry->dummy, __entry->debug_str)
+);
+
+DEFINE_EVENT(msm_v4l2_vidc_inst, msm_v4l2_vidc_open,
+
+	TP_PROTO(char *dummy, struct msm_vidc_inst *inst),
+
+	TP_ARGS(dummy, inst)
+);
+
+DEFINE_EVENT(msm_v4l2_vidc_inst, msm_v4l2_vidc_close,
+
+	TP_PROTO(char *dummy, struct msm_vidc_inst *inst),
+
+	TP_ARGS(dummy, inst)
+);
+
+DECLARE_EVENT_CLASS(msm_v4l2_vidc_fw_load,
+
+	TP_PROTO(char *dummy),
+
+	TP_ARGS(dummy),
+
+	TP_STRUCT__entry(
+		__field(char *, dummy)
+	),
+
+	TP_fast_assign(
+		__entry->dummy = dummy;
+	),
+
+	TP_printk("%s\n", __entry->dummy)
+);
+
+DEFINE_EVENT(msm_v4l2_vidc_fw_load, msm_v4l2_vidc_fw_load,
+
+	TP_PROTO(char *dummy),
+
+	TP_ARGS(dummy)
+);
+
+DECLARE_EVENT_CLASS(msm_vidc_driver,
+
+	TP_PROTO(struct msm_vidc_inst *inst, const char *func,
+		const char *old_state, const char *new_state),
+
+	TP_ARGS(inst, func, old_state, new_state),
+
+	TP_STRUCT__entry(
+		__field(const char *, debug_str)
+		__field(const char *, func)
+		__field(const char *, old_state)
+		__field(const char *, new_state)
+	),
+
+	TP_fast_assign(
+		__entry->debug_str = inst ? inst->debug_str : (u8 *)"";
+		__entry->func = func;
+		__entry->old_state = old_state;
+		__entry->new_state = new_state;
+	),
+
+	TP_printk("%s: %s: state changed to %s from %s\n",
+		__entry->debug_str,
+		__entry->func,
+		__entry->new_state,
+		__entry->old_state)
+);
+
+DEFINE_EVENT(msm_vidc_driver, msm_vidc_common_state_change,
+
+	TP_PROTO(struct msm_vidc_inst *inst, const char *func,
+		const char *old_state, const char *new_state),
+
+	TP_ARGS(inst, func, old_state, new_state)
+);
+
+DECLARE_EVENT_CLASS(venus_hfi_var,
+
+	TP_PROTO(u32 cp_start, u32 cp_size,
+		u32 cp_nonpixel_start, u32 cp_nonpixel_size),
+
+	TP_ARGS(cp_start, cp_size, cp_nonpixel_start, cp_nonpixel_size),
+
+	TP_STRUCT__entry(
+		__field(u32, cp_start)
+		__field(u32, cp_size)
+		__field(u32, cp_nonpixel_start)
+		__field(u32, cp_nonpixel_size)
+	),
+
+	TP_fast_assign(
+		__entry->cp_start = cp_start;
+		__entry->cp_size = cp_size;
+		__entry->cp_nonpixel_start = cp_nonpixel_start;
+		__entry->cp_nonpixel_size = cp_nonpixel_size;
+	),
+
+	TP_printk(
+		"TZBSP_MEM_PROTECT_VIDEO_VAR done, cp_start : 0x%x, cp_size : 0x%x, cp_nonpixel_start : 0x%x, cp_nonpixel_size : 0x%x\n",
+		__entry->cp_start,
+		__entry->cp_size,
+		__entry->cp_nonpixel_start,
+		__entry->cp_nonpixel_size)
+);
+
+DEFINE_EVENT(venus_hfi_var, venus_hfi_var_done,
+
+	TP_PROTO(u32 cp_start, u32 cp_size,
+		u32 cp_nonpixel_start, u32 cp_nonpixel_size),
+
+	TP_ARGS(cp_start, cp_size, cp_nonpixel_start, cp_nonpixel_size)
+);
+
+DECLARE_EVENT_CLASS(msm_v4l2_vidc_buffer_events,
+
+	TP_PROTO(struct msm_vidc_inst *inst, const char *str, const char *buf_type,
+			struct msm_vidc_buffer *vbuf, unsigned long inode, long ref_count),
+
+	TP_ARGS(inst, str, buf_type, vbuf, inode, ref_count),
+
+	TP_STRUCT__entry(
+		__field(u8 *, debug_str)
+		__field(const char *, str)
+		__field(const char *, buf_type)
+		__field(u32, index)
+		__field(int, fd)
+		__field(u32, data_offset)
+		__field(u64, device_addr)
+		__field(unsigned long, inode)
+		__field(long, ref_count)
+		__field(u32, buffer_size)
+		__field(u32, data_size)
+		__field(u32, flags)
+		__field(u64, timestamp)
+		__field(int, attr)
+		__field(u64, etb)
+		__field(u64, ebd)
+		__field(u64, ftb)
+		__field(u64, fbd)
+	),
+
+	TP_fast_assign(
+		__entry->debug_str = inst ? inst->debug_str : (u8 *)"";
+		__entry->str = str;
+		__entry->buf_type = buf_type;
+		__entry->index = vbuf ? vbuf->index : -1;
+		__entry->fd = vbuf ? vbuf->fd : 0;
+		__entry->data_offset = vbuf ? vbuf->data_offset : 0;
+		__entry->device_addr = vbuf ? vbuf->device_addr : 0;
+		__entry->inode = inode;
+		__entry->ref_count = ref_count;
+		__entry->buffer_size = vbuf ? vbuf->buffer_size : 0;
+		__entry->data_size = vbuf ? vbuf->data_size : 0;
+		__entry->flags = vbuf ? vbuf->flags : 0;
+		__entry->timestamp = vbuf ? vbuf->timestamp : 0;
+		__entry->attr = vbuf ? vbuf->attr : 0;
+		__entry->etb = inst ? inst->debug_count.etb : 0;
+		__entry->ebd = inst ? inst->debug_count.ebd : 0;
+		__entry->ftb = inst ? inst->debug_count.ftb : 0;
+		__entry->fbd = inst ? inst->debug_count.fbd : 0;
+	),
+
+	TP_printk(
+		"%s: %s: %s: idx %2d fd %3d off %d daddr %#llx inode %8lu ref %2ld size %8d filled %8d flags %#x ts %8lld attr %#x counts(etb ebd ftb fbd) %4llu %4llu %4llu %4llu\n",
+		__entry->debug_str, __entry->str, __entry->buf_type, __entry->index, __entry->fd,
+		__entry->data_offset, __entry->device_addr, __entry->inode, __entry->ref_count,
+		__entry->buffer_size, __entry->data_size, __entry->flags, __entry->timestamp,
+		__entry->attr, __entry->etb, __entry->ebd, __entry->ftb, __entry->fbd)
+);
+
+DEFINE_EVENT(msm_v4l2_vidc_buffer_events, msm_v4l2_vidc_buffer_event_log,
+
+	TP_PROTO(struct msm_vidc_inst *inst, const char *str, const char *buf_type,
+		struct msm_vidc_buffer *vbuf, unsigned long inode, long ref_count),
+
+	TP_ARGS(inst, str, buf_type, vbuf, inode, ref_count)
+);
+
+DECLARE_EVENT_CLASS(msm_vidc_perf,
+
+	TP_PROTO(struct msm_vidc_inst *inst, u64 clk_freq, u64 bw_ddr, u64 bw_llcc),
+
+	TP_ARGS(inst, clk_freq, bw_ddr, bw_llcc),
+
+	TP_STRUCT__entry(
+		__field(u8 *, debug_str)
+		__field(u64, curr_freq)
+		__field(u32, ddr_bw)
+		__field(u32, sys_cache_bw)
+		__field(u32, dcvs_flags)
+		__field(u64, clk_freq)
+		__field(u64, bw_ddr)
+		__field(u64, bw_llcc)
+	),
+
+	TP_fast_assign(
+		__entry->debug_str = inst ? inst->debug_str : (u8 *)"";
+		__entry->curr_freq = inst ? inst->power.curr_freq : 0;
+		__entry->ddr_bw = inst ? inst->power.ddr_bw : 0;
+		__entry->sys_cache_bw = inst ? inst->power.sys_cache_bw : 0;
+		__entry->dcvs_flags = inst ? inst->power.dcvs_flags : 0;
+		__entry->clk_freq = clk_freq;
+		__entry->bw_ddr = bw_ddr;
+		__entry->bw_llcc = bw_llcc;
+	),
+
+	TP_printk("%s: power: inst: clk %lld ddr %d llcc %d dcvs flags %#x, core: clk %lld ddr %lld llcc %lld\n",
+		__entry->debug_str, __entry->curr_freq, __entry->ddr_bw, __entry->sys_cache_bw,
+		__entry->dcvs_flags, __entry->clk_freq, __entry->bw_ddr, __entry->bw_llcc)
+);
+
+DEFINE_EVENT(msm_vidc_perf, msm_vidc_perf_power_scale,
+
+	TP_PROTO(struct msm_vidc_inst *inst, u64 clk_freq, u64 bw_ddr, u64 bw_llcc),
+
+	TP_ARGS(inst, clk_freq, bw_ddr, bw_llcc)
+);
+
+DECLARE_EVENT_CLASS(msm_vidc_buffer_dma_ops,
+
+	TP_PROTO(const char *buffer_op, void *dmabuf, u8 size, void *kvaddr,
+			const char *buf_name, u8 secure, u32 region),
+
+	TP_ARGS(buffer_op, dmabuf, size, kvaddr, buf_name, secure, region),
+
+	TP_STRUCT__entry(
+		__field(const char *, buffer_op)
+		__field(void *, dmabuf)
+		__field(u8, size)
+		__field(void *, kvaddr)
+		__field(const char *, buf_name)
+		__field(u8, secure)
+		__field(u32, region)
+	),
+
+	TP_fast_assign(
+		__entry->buffer_op = buffer_op;
+		__entry->dmabuf = dmabuf;
+		__entry->size = size;
+		__entry->kvaddr = kvaddr;
+		__entry->buf_name = buf_name;
+		__entry->secure = secure;
+		__entry->region = region;
+	),
+
+	TP_printk(
+		"%s: dmabuf %pK, size %d, kvaddr %pK, buffer_type %s, secure %d, region %d\n",
+		__entry->buffer_op, __entry->dmabuf, __entry->size, __entry->kvaddr,
+		__entry->buf_name, __entry->secure, __entry->region)
+);
+
+DEFINE_EVENT(msm_vidc_buffer_dma_ops, msm_vidc_dma_buffer,
+
+	TP_PROTO(const char *buffer_op, void *dmabuf, u8 size, void *kvaddr,
+			const char *buf_name, u8 secure, u32 region),
+
+	TP_ARGS(buffer_op, dmabuf, size, kvaddr, buf_name, secure, region)
+);
+
+#endif
+
+/* This part must be outside protection */
+#include <trace/define_trace.h>

+ 3 - 0
driver/vidc/inc/msm_vidc_power.h

@@ -13,6 +13,9 @@
 
 #define COMPRESSION_RATIO_MAX 5
 
+/* TODO: Move to dtsi OR use source clock instead of branch clock.*/
+#define MSM_VIDC_CLOCK_SOURCE_SCALING_RATIO 3
+
 enum vidc_bus_type {
 	PERF,
 	DDR,

+ 8 - 0
driver/vidc/src/msm_vidc_control.c

@@ -469,6 +469,14 @@ static int msm_vidc_adjust_dynamic_property(struct msm_vidc_inst *inst,
 			goto exit;
 	}
 
+	if (capability->cap[cap_id].value == prev_value && cap_id == GOP_SIZE) {
+		/*
+		 * Ignore setting same GOP size value to firmware to avoid
+		 * unnecessary generation of IDR frame.
+		 */
+		goto exit;
+	}
+
 	/* add cap_id to firmware list always */
 	rc = msm_vidc_add_capid_to_list(inst, cap_id, FW_LIST);
 	if (rc)

+ 13 - 1
driver/vidc/src/msm_vidc_debug.c

@@ -2,7 +2,7 @@
 /*
  * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  */
-
+#define CREATE_TRACE_POINTS
 #include "msm_vidc_debug.h"
 #include "msm_vidc_driver.h"
 #include "msm_vidc_dt.h"
@@ -10,6 +10,7 @@
 #include "msm_vidc_core.h"
 #include "msm_vidc_inst.h"
 #include "msm_vidc_internal.h"
+#include "msm_vidc_events.h"
 
 extern struct msm_vidc_core *g_core;
 
@@ -84,6 +85,8 @@ bool msm_vidc_syscache_disable = !true;
 EXPORT_SYMBOL(msm_vidc_syscache_disable);
 
 int msm_vidc_clock_voting = !1;
+int msm_vidc_ddr_bw = !1;
+int msm_vidc_llc_bw = !1;
 
 bool msm_vidc_fw_dump = !true;
 EXPORT_SYMBOL(msm_vidc_fw_dump);
@@ -125,6 +128,11 @@ void msm_vidc_show_stats(void *inst)
 	int x;
 	struct msm_vidc_inst *i = (struct msm_vidc_inst *) inst;
 
+	if (!i) {
+		d_vpr_e("%s: invalid params\n", __func__);
+		return;
+	}
+
 	for (x = 0; x < MAX_PROFILING_POINTS; x++) {
 		if (i->debug.pdata[x].name[0]) {
 			if (i->debug.samples) {
@@ -300,6 +308,10 @@ struct dentry* msm_vidc_debugfs_init_drv()
 
 	debugfs_create_u32("core_clock_voting", 0644, dir,
 			&msm_vidc_clock_voting);
+	debugfs_create_u32("ddr_bw_kbps", 0644, dir,
+			&msm_vidc_ddr_bw);
+	debugfs_create_u32("llc_bw_kbps", 0644, dir,
+			&msm_vidc_llc_bw);
 	debugfs_create_bool("disable_video_syscache", 0644, dir,
 			&msm_vidc_syscache_disable);
 	debugfs_create_bool("lossless_encoding", 0644, dir,

+ 20 - 2
driver/vidc/src/msm_vidc_driver.c

@@ -22,6 +22,8 @@
 #include "venus_hfi.h"
 #include "venus_hfi_response.h"
 #include "hfi_packet.h"
+#include "msm_vidc_events.h"
+
 extern struct msm_vidc_core *g_core;
 
 #define is_odd(val) ((val) % 2 == 1)
@@ -371,7 +373,7 @@ void print_vidc_buffer(u32 tag, const char *tag_str, const char *str, struct msm
 {
 	struct dma_buf *dbuf;
 
-	if (!(tag & msm_vidc_debug) || !inst || !vbuf || !tag_str || !str)
+	if (!inst || !vbuf || !tag_str || !str)
 		return;
 
 	dbuf = (struct dma_buf *)vbuf->dmabuf;
@@ -384,6 +386,11 @@ void print_vidc_buffer(u32 tag, const char *tag_str, const char *str, struct msm
 		(dbuf ? file_count(dbuf->file) : -1), vbuf->buffer_size, vbuf->data_size,
 		vbuf->flags, vbuf->timestamp, vbuf->attr, inst->debug_count.etb,
 		inst->debug_count.ebd, inst->debug_count.ftb, inst->debug_count.fbd);
+
+	trace_msm_v4l2_vidc_buffer_event_log(inst, str, buf_name(vbuf->type), vbuf,
+		(dbuf ? file_inode(dbuf->file)->i_ino : -1), (dbuf ? file_count(dbuf->file) : -1));
+
+
 }
 
 void print_vb2_buffer(const char *str, struct msm_vidc_inst *inst,
@@ -1194,6 +1201,9 @@ int msm_vidc_change_inst_state(struct msm_vidc_inst *inst,
 		i_vpr_h(inst, "%s: state changed to %s from %s\n",
 		   func, state_name(request_state), state_name(inst->state));
 
+	trace_msm_vidc_common_state_change(inst, func, state_name(inst->state),
+			state_name(request_state));
+
 	inst->state = request_state;
 
 	return 0;
@@ -2209,7 +2219,7 @@ static int msm_vidc_insert_sort(struct list_head *head,
 		prev = node;
 	}
 
-	if (!is_inserted)
+	if (!is_inserted && prev)
 		list_add(&entry->list, &prev->list);
 
 	return 0;
@@ -2619,6 +2629,7 @@ void msm_vidc_allow_dcvs(struct msm_vidc_inst *inst)
 {
 	bool allow = false;
 	struct msm_vidc_core *core;
+	u32 fps;
 
 	if (!inst || !inst->core) {
 		d_vpr_e("%s: Invalid args: %pK\n", __func__, inst);
@@ -2674,6 +2685,13 @@ void msm_vidc_allow_dcvs(struct msm_vidc_inst *inst)
 		goto exit;
 	}
 
+	fps =  msm_vidc_get_fps(inst);
+	if (is_decode_session(inst) && fps >= MAXIMUM_FPS) {
+		allow = false;
+		i_vpr_h(inst, "%s: unsupported fps %d\n", __func__, fps);
+		goto exit;
+	}
+
 exit:
 	i_vpr_hp(inst, "%s: dcvs: %s\n", __func__, allow ? "enabled" : "disabled");
 

+ 7 - 0
driver/vidc/src/msm_vidc_memory.c

@@ -16,6 +16,7 @@
 #include "msm_vidc_driver.h"
 #include "msm_vidc_dt.h"
 #include "msm_vidc_core.h"
+#include "msm_vidc_events.h"
 
 struct msm_vidc_buf_region_name {
 	enum msm_vidc_buffer_region region;
@@ -388,6 +389,9 @@ int msm_vidc_memory_alloc(struct msm_vidc_core *core, struct msm_vidc_alloc *mem
 		"%s: dmabuf %pK, size %d, kvaddr %pK, buffer_type %s, secure %d, region %d\n",
 		__func__, mem->dmabuf, mem->size, mem->kvaddr, buf_name(mem->type),
 		mem->secure, mem->region);
+	trace_msm_vidc_dma_buffer("ALLOC", mem->dmabuf, mem->size, mem->kvaddr,
+		buf_name(mem->type), mem->secure, mem->region);
+
 	return 0;
 
 error:
@@ -409,6 +413,9 @@ int msm_vidc_memory_free(struct msm_vidc_core *core, struct msm_vidc_alloc *mem)
 		__func__, mem->dmabuf, mem->size, mem->kvaddr, buf_name(mem->type),
 		mem->secure, mem->region);
 
+	trace_msm_vidc_dma_buffer("FREE", mem->dmabuf, mem->size, mem->kvaddr,
+		buf_name(mem->type), mem->secure, mem->region);
+
 	if (mem->kvaddr) {
 		dma_buf_vunmap(mem->dmabuf, mem->kvaddr);
 		mem->kvaddr = NULL;

+ 15 - 14
driver/vidc/src/msm_vidc_power.c

@@ -13,6 +13,7 @@
 #include "msm_vidc_platform.h"
 #include "msm_vidc_buffer.h"
 #include "venus_hfi.h"
+#include "msm_vidc_events.h"
 
 /* Q16 Format */
 #define MSM_VIDC_MIN_UBWC_COMPLEXITY_FACTOR (1 << 16)
@@ -20,9 +21,6 @@
 #define MSM_VIDC_MIN_UBWC_COMPRESSION_RATIO (1 << 16)
 #define MSM_VIDC_MAX_UBWC_COMPRESSION_RATIO (5 << 16)
 
-/* TODO: Move to dtsi OR use source clock instead of branch clock.*/
-#define MSM_VIDC_CLOCK_SOURCE_SCALING_RATIO 3
-
 u64 msm_vidc_max_freq(struct msm_vidc_inst *inst)
 {
 	struct msm_vidc_core* core;
@@ -166,6 +164,16 @@ static int msm_vidc_set_buses(struct msm_vidc_inst* inst)
 	}
 	mutex_unlock(&core->lock);
 
+	if (msm_vidc_ddr_bw) {
+		d_vpr_l("msm_vidc_ddr_bw %d\n", msm_vidc_ddr_bw);
+		total_bw_ddr = msm_vidc_ddr_bw;
+	}
+
+	if (msm_vidc_llc_bw) {
+		d_vpr_l("msm_vidc_llc_bw %d\n", msm_vidc_llc_bw);
+		total_bw_llcc = msm_vidc_llc_bw;
+	}
+
 	rc = venus_hfi_scale_buses(inst, total_bw_ddr, total_bw_llcc);
 	if (rc)
 		return rc;
@@ -196,8 +204,6 @@ int msm_vidc_scale_buses(struct msm_vidc_inst *inst)
 	vote_data->power_mode = VIDC_POWER_NORMAL;
 	if (inst->power.buffer_counter < DCVS_WINDOW || is_image_session(inst))
 		vote_data->power_mode = VIDC_POWER_TURBO;
-	if (msm_vidc_clock_voting)
-		vote_data->power_mode = VIDC_POWER_TURBO;
 
 	if (vote_data->power_mode == VIDC_POWER_TURBO)
 		goto set_buses;
@@ -364,15 +370,6 @@ int msm_vidc_set_clocks(struct msm_vidc_inst* inst)
 		__func__, rate, freq, increment, decrement);
 	mutex_unlock(&core->lock);
 
-	/*
-	 * This conversion is necessary since we are scaling clock values based on
-	 * the branch clock. However, mmrm driver expects source clock to be registered
-	 * and used for scaling.
-	 * TODO: Remove this scaling if using source clock instead of branch clock.
-	 */
-	rate = rate * MSM_VIDC_CLOCK_SOURCE_SCALING_RATIO;
-	i_vpr_l(inst, "%s: scaled clock rate %lu\n", __func__, rate);
-
 	rc = venus_hfi_scale_clocks(inst, rate);
 	if (rc)
 		return rc;
@@ -524,6 +521,10 @@ int msm_vidc_scale_power(struct msm_vidc_inst *inst, bool scale_buses)
 		inst->power.sys_cache_bw, inst->power.dcvs_flags,
 		core->power.clk_freq, core->power.bw_ddr,
 		core->power.bw_llcc);
+
+	trace_msm_vidc_perf_power_scale(inst, core->power.clk_freq,
+		core->power.bw_ddr, core->power.bw_llcc);
+
 	return 0;
 }
 

+ 6 - 0
driver/vidc/src/msm_vidc_v4l2.c

@@ -10,6 +10,7 @@
 #include "msm_vidc_debug.h"
 #include "msm_vidc_driver.h"
 #include "msm_vidc.h"
+#include "msm_vidc_events.h"
 
 extern struct msm_vidc_core *g_core;
 
@@ -36,14 +37,17 @@ int msm_v4l2_open(struct file *filp)
 	struct msm_vidc_core *core = video_drvdata(filp);
 	struct msm_vidc_inst *inst;
 
+	trace_msm_v4l2_vidc_open("START", NULL);
 	inst = msm_vidc_open(core, vid_dev->type);
 	if (!inst) {
 		d_vpr_e("Failed to create instance, type = %d\n",
 			vid_dev->type);
+		trace_msm_v4l2_vidc_open("END", NULL);
 		return -ENOMEM;
 	}
 	clear_bit(V4L2_FL_USES_V4L2_FH, &vdev->flags);
 	filp->private_data = &(inst->event_handler);
+	trace_msm_v4l2_vidc_open("END", inst);
 	return 0;
 }
 
@@ -53,9 +57,11 @@ int msm_v4l2_close(struct file *filp)
 	struct msm_vidc_inst *inst;
 
 	inst = get_vidc_inst(filp, NULL);
+	trace_msm_v4l2_vidc_close("START", inst);
 
 	rc = msm_vidc_close(inst);
 	filp->private_data = NULL;
+	trace_msm_v4l2_vidc_close("END", NULL);
 	return rc;
 }
 

+ 28 - 4
driver/vidc/src/venus_hfi.c

@@ -25,6 +25,7 @@
 #include "msm_vidc_debug.h"
 #include "hfi_packet.h"
 #include "venus_hfi_response.h"
+#include "msm_vidc_events.h"
 
 #define MIN_PAYLOAD_SIZE 3
 
@@ -382,7 +383,7 @@ static void __schedule_power_collapse_work(struct msm_vidc_core *core)
 
 	if (!mod_delayed_work(core->pm_workq, &core->pm_work,
 			msecs_to_jiffies(core->capabilities[SW_PC_DELAY].value))) {
-		d_vpr_e("power collapse already scheduled\n");
+		d_vpr_h("power collapse already scheduled\n");
 	} else {
 		d_vpr_l("power collapse scheduled for %d ms\n",
 			core->capabilities[SW_PC_DELAY].value);
@@ -667,6 +668,14 @@ int __set_clk_rate(struct msm_vidc_core *core,
 	}
 	client = cl->mmrm_client;
 
+	/*
+	 * This conversion is necessary since we are scaling clock values based on
+	 * the branch clock. However, mmrm driver expects source clock to be registered
+	 * and used for scaling.
+	 * TODO: Remove this scaling if using source clock instead of branch clock.
+	 */
+	rate = rate * MSM_VIDC_CLOCK_SOURCE_SCALING_RATIO;
+
 	/* bail early if requested clk rate is not changed */
 	if (rate == cl->prev)
 		return 0;
@@ -1303,6 +1312,10 @@ static int __protect_cp_mem(struct msm_vidc_core *core)
 	if (rc)
 		d_vpr_e("Failed to protect memory(%d)\n", rc);
 
+	trace_venus_hfi_var_done(
+		memprot.cp_start, memprot.cp_size,
+		memprot.cp_nonpixel_start, memprot.cp_nonpixel_size);
+
 	return rc;
 }
 #if 0 // TODO
@@ -1604,6 +1617,7 @@ int __prepare_enable_clks(struct msm_vidc_core *core)
 {
 	struct clock_info *cl = NULL;
 	int rc = 0, c = 0;
+	u64 rate = 0;
 
 	if (!core) {
 		d_vpr_e("%s: invalid params\n", __func__);
@@ -1621,9 +1635,16 @@ int __prepare_enable_clks(struct msm_vidc_core *core)
 		 * them.  Since we don't really have a load at this point, scale
 		 * it to the lowest frequency possible
 		 */
-		if (cl->has_scaling)
-			__set_clk_rate(core, cl,
-					clk_round_rate(cl->clk, 0));
+		if (cl->has_scaling) {
+			rate = clk_round_rate(cl->clk, 0);
+			/**
+			 * source clock is already multipled with scaling ratio and __set_clk_rate
+			 * attempts to multiply again. So divide scaling ratio before calling
+			 * __set_clk_rate.
+			 */
+			rate = rate / MSM_VIDC_CLOCK_SOURCE_SCALING_RATIO;
+			__set_clk_rate(core, cl, rate);
+		}
 
 		rc = clk_prepare_enable(cl->clk);
 		if (rc) {
@@ -2614,6 +2635,7 @@ int __load_fw(struct msm_vidc_core *core)
 	core->handoff_done = false;
 	core->hw_power_control = false;
 
+	trace_msm_v4l2_vidc_fw_load("START");
 	rc = __init_resources(core);
 	if (rc) {
 		d_vpr_e("%s: Failed to init resources: %d\n", __func__, rc);
@@ -2651,6 +2673,7 @@ int __load_fw(struct msm_vidc_core *core)
 	* present.
 	*/
 	__hand_off_regulators(core);
+	trace_msm_v4l2_vidc_fw_load("END");
 
 	return rc;
 fail_protect_mem:
@@ -2662,6 +2685,7 @@ fail_load_fw:
 fail_venus_power_on:
 	__deinit_resources(core);
 fail_init_res:
+	trace_msm_v4l2_vidc_fw_load("END");
 	return rc;
 }
 

+ 6 - 3
driver/vidc/src/venus_hfi_response.c

@@ -1411,20 +1411,23 @@ static int handle_session_property(struct msm_vidc_inst *inst,
 		}
 		break;
 	case HFI_PROP_QUALITY_MODE:
-		if (inst->capabilities->cap[QUALITY_MODE].value !=  payload_ptr[0])
+		if (payload_ptr &&
+			inst->capabilities->cap[QUALITY_MODE].value !=  payload_ptr[0])
 			i_vpr_e(inst,
 				"%s: fw quality mode(%d) not matching the capability value(%d)\n",
 				__func__,  payload_ptr[0],
 				inst->capabilities->cap[QUALITY_MODE].value);
 		break;
 	case HFI_PROP_STAGE:
-		if (inst->capabilities->cap[STAGE].value !=  payload_ptr[0])
+		if (payload_ptr &&
+			inst->capabilities->cap[STAGE].value !=  payload_ptr[0])
 			i_vpr_e(inst,
 				"%s: fw stage mode(%d) not matching the capability value(%d)\n",
 				__func__,  payload_ptr[0], inst->capabilities->cap[STAGE].value);
 		break;
 	case HFI_PROP_PIPE:
-		if (inst->capabilities->cap[PIPE].value !=  payload_ptr[0])
+		if (payload_ptr &&
+			inst->capabilities->cap[PIPE].value !=  payload_ptr[0])
 			i_vpr_e(inst,
 				"%s: fw pipe mode(%d) not matching the capability value(%d)\n",
 				__func__,  payload_ptr[0], inst->capabilities->cap[PIPE].value);

+ 1 - 1
video_kernel_board.mk

@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 # Build video kernel driver
-ifneq ($(TARGET_USES_QMAA),true)
+ifneq ($(TARGET_KERNEL_DLKM_DISABLE),true)
 ifneq ($(TARGET_BOARD_AUTO),true)
 ifeq ($(call is-board-platform-in-list,$(TARGET_BOARD_PLATFORM)),true)
 BOARD_VENDOR_KERNEL_MODULES += $(KERNEL_MODULES_OUT)/msm_video.ko