From 3560442234234715bc9411ac31b4dd4bf1cf9f06 Mon Sep 17 00:00:00 2001 From: Govindaraj Rajagopal Date: Mon, 10 Oct 2022 10:57:25 +0530 Subject: [PATCH] video: driver: add resource ops macro support Added call_res_op() macro and used at all possible places to avoid invalid pointer dereference issue. Also added changes to cleanup unused functions. Change-Id: Id77711ad9eaf7b407208567b0fde1f2693588641 Signed-off-by: Govindaraj Rajagopal --- .../platform/common/inc/msm_vidc_platform.h | 1 - .../platform/common/src/msm_vidc_platform.c | 49 ------------------- .../variant/iris2/src/msm_vidc_buffer_iris2.c | 4 +- driver/variant/iris2/src/msm_vidc_iris2.c | 47 ++++++++---------- driver/variant/iris3/src/msm_vidc_iris3.c | 43 +++++++--------- .../variant/iris3/src/msm_vidc_power_iris3.c | 3 -- driver/variant/iris33/src/msm_vidc_iris33.c | 45 ++++++++--------- .../iris33/src/msm_vidc_power_iris33.c | 3 -- driver/vidc/inc/msm_vidc_control.h | 2 - driver/vidc/inc/msm_vidc_power.h | 1 - driver/vidc/inc/resources.h | 4 ++ driver/vidc/src/msm_vdec.c | 2 - driver/vidc/src/msm_venc.c | 9 +--- driver/vidc/src/msm_vidc_driver.c | 2 - driver/vidc/src/msm_vidc_power.c | 16 +----- driver/vidc/src/msm_vidc_probe.c | 4 +- driver/vidc/src/venus_hfi.c | 38 ++++++-------- 17 files changed, 84 insertions(+), 189 deletions(-) diff --git a/driver/platform/common/inc/msm_vidc_platform.h b/driver/platform/common/inc/msm_vidc_platform.h index 66738f520a..2e0a012d14 100644 --- a/driver/platform/common/inc/msm_vidc_platform.h +++ b/driver/platform/common/inc/msm_vidc_platform.h @@ -231,6 +231,5 @@ static inline bool is_mmrm_supported(struct msm_vidc_core *core) int msm_vidc_init_platform(struct platform_device *pdev); int msm_vidc_deinit_platform(struct platform_device *pdev); -int msm_vidc_read_efuse(struct msm_vidc_core *core); #endif // _MSM_VIDC_PLATFORM_H_ diff --git a/driver/platform/common/src/msm_vidc_platform.c b/driver/platform/common/src/msm_vidc_platform.c index 169f61c04c..ea099e87f5 100644 --- a/driver/platform/common/src/msm_vidc_platform.c +++ b/driver/platform/common/src/msm_vidc_platform.c @@ -6,7 +6,6 @@ #include #include -#include #include "msm_vidc_platform.h" #include "msm_vidc_debug.h" @@ -447,51 +446,3 @@ int msm_vidc_init_platform(struct platform_device *pdev) return rc; } - -int msm_vidc_read_efuse(struct msm_vidc_core *core) -{ - int rc = 0; - void __iomem *base; - u32 i = 0, efuse = 0, efuse_data_count = 0; - struct msm_vidc_efuse_data *efuse_data = NULL; - struct msm_vidc_platform_data *platform_data; - - if (!core || !core->platform || !core->pdev) { - d_vpr_e("%s: invalid params\n", __func__); - return -EINVAL; - } - - platform_data = &core->platform->data; - efuse_data = platform_data->efuse_data; - efuse_data_count = platform_data->efuse_data_size; - - if (!efuse_data) - return 0; - - for (i = 0; i < efuse_data_count; i++) { - switch (efuse_data[i].purpose) { - case SKU_VERSION: - base = devm_ioremap(&core->pdev->dev, efuse_data[i].start_address, - efuse_data[i].size); - if (!base) { - d_vpr_e("failed efuse: start %#x, size %d\n", - efuse_data[i].start_address, - efuse_data[i].size); - return -EINVAL; - } - efuse = readl_relaxed(base); - platform_data->sku_version = - (efuse & efuse_data[i].mask) >> - efuse_data[i].shift; - break; - default: - break; - } - if (platform_data->sku_version) { - d_vpr_h("efuse 0x%x, platform version 0x%x\n", - efuse, platform_data->sku_version); - break; - } - } - return rc; -} diff --git a/driver/variant/iris2/src/msm_vidc_buffer_iris2.c b/driver/variant/iris2/src/msm_vidc_buffer_iris2.c index 639f136f39..96e4feaa78 100644 --- a/driver/variant/iris2/src/msm_vidc_buffer_iris2.c +++ b/driver/variant/iris2/src/msm_vidc_buffer_iris2.c @@ -201,9 +201,7 @@ static u32 msm_vidc_decoder_persist_size_iris2(struct msm_vidc_inst *inst) static u32 msm_vidc_decoder_dpb_size_iris2(struct msm_vidc_inst *inst) { - u32 size = 0; - u32 color_fmt; - u32 width, height; + u32 color_fmt, width, height, size = 0; struct v4l2_format *f; if (!inst) { diff --git a/driver/variant/iris2/src/msm_vidc_iris2.c b/driver/variant/iris2/src/msm_vidc_iris2.c index 102b56346c..e365d2c0c4 100644 --- a/driver/variant/iris2/src/msm_vidc_iris2.c +++ b/driver/variant/iris2/src/msm_vidc_iris2.c @@ -249,7 +249,6 @@ static int __setup_ucregion_memory_map_iris2(struct msm_vidc_core *vidc_core) static int __power_off_iris2_hardware(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0, i; u32 value = 0; @@ -322,12 +321,12 @@ static int __power_off_iris2_hardware(struct msm_vidc_core *core) disable_power: /* power down process */ - rc = res_ops->gdsc_off(core, "vcodec"); + rc = call_res_op(core, gdsc_off, core, "vcodec"); if (rc) { d_vpr_e("%s: disable regulator vcodec failed\n", __func__); rc = 0; } - rc = res_ops->clk_disable(core, "vcodec_clk"); + rc = call_res_op(core, clk_disable, core, "vcodec_clk"); if (rc) { d_vpr_e("%s: disable unprepare vcodec_clk failed\n", __func__); rc = 0; @@ -338,7 +337,6 @@ disable_power: static int __power_off_iris2_controller(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; /* @@ -381,27 +379,27 @@ static int __power_off_iris2_controller(struct msm_vidc_core *core) d_vpr_h("%s: debug bridge release failed\n", __func__); /* Turn off MVP MVS0C core clock */ - rc = res_ops->clk_disable(core, "core_clk"); + rc = call_res_op(core, clk_disable, core, "core_clk"); if (rc) { d_vpr_e("%s: disable unprepare core_clk failed\n", __func__); rc = 0; } /* Disable GCC_VIDEO_AXI0_CLK clock */ - rc = res_ops->clk_disable(core, "gcc_video_axi0"); + rc = call_res_op(core, clk_disable, core, "gcc_video_axi0"); if (rc) { d_vpr_e("%s: disable unprepare gcc_video_axi0 failed\n", __func__); rc = 0; } - rc = res_ops->reset_bridge(core); + rc = call_res_op(core, reset_bridge, core); if (rc) { d_vpr_e("%s: reset bridge failed\n", __func__); rc = 0; } /* power down process */ - rc = res_ops->gdsc_off(core, "iris-ctl"); + rc = call_res_op(core, gdsc_off, core, "iris-ctl"); if (rc) { d_vpr_e("%s: disable regulator iris-ctl failed\n", __func__); rc = 0; @@ -412,7 +410,6 @@ static int __power_off_iris2_controller(struct msm_vidc_core *core) static int __power_off_iris2(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; if (!core || !core->capabilities) { @@ -427,7 +424,7 @@ static int __power_off_iris2(struct msm_vidc_core *core) * Reset video_cc_mvs0_clk_src value to resolve MMRM high video * clock projection issue. */ - rc = res_ops->set_clks(core, 0); + rc = call_res_op(core, set_clks, core, 0); if (rc) d_vpr_e("%s: resetting clocks failed\n", __func__); @@ -437,7 +434,8 @@ static int __power_off_iris2(struct msm_vidc_core *core) if (__power_off_iris2_controller(core)) d_vpr_e("%s: failed to power off controller\n", __func__); - if (res_ops->set_bw(core, 0, 0)) + rc = call_res_op(core, set_bw, core, 0, 0); + if (rc) d_vpr_e("%s: failed to unvote buses\n", __func__); if (!(core->intr_status & WRAPPER_INTR_STATUS_A2HWD_BMSK_IRIS2)) @@ -451,60 +449,57 @@ static int __power_off_iris2(struct msm_vidc_core *core) static int __power_on_iris2_controller(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; - rc = res_ops->gdsc_on(core, "iris-ctl"); + rc = call_res_op(core, gdsc_on, core, "iris-ctl"); if (rc) goto fail_regulator; - rc = res_ops->reset_bridge(core); + rc = call_res_op(core, reset_bridge, core); if (rc) goto fail_reset_ahb2axi; - rc = res_ops->clk_enable(core, "gcc_video_axi0"); + rc = call_res_op(core, clk_enable, core, "gcc_video_axi0"); if (rc) goto fail_clk_axi; - rc = res_ops->clk_enable(core, "core_clk"); + rc = call_res_op(core, clk_enable, core, "core_clk"); if (rc) goto fail_clk_controller; return 0; fail_clk_controller: - res_ops->clk_disable(core, "gcc_video_axi0"); + call_res_op(core, clk_disable, core, "gcc_video_axi0"); fail_clk_axi: fail_reset_ahb2axi: - res_ops->gdsc_off(core, "iris-ctl"); + call_res_op(core, gdsc_off, core, "iris-ctl"); fail_regulator: return rc; } static int __power_on_iris2_hardware(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; - rc = res_ops->gdsc_on(core, "vcodec"); + rc = call_res_op(core, gdsc_on, core, "vcodec"); if (rc) goto fail_regulator; - rc = res_ops->clk_enable(core, "vcodec_clk"); + rc = call_res_op(core, clk_enable, core, "vcodec_clk"); if (rc) goto fail_clk_controller; return 0; fail_clk_controller: - res_ops->gdsc_off(core, "vcodec"); + call_res_op(core, gdsc_off, core, "vcodec"); fail_regulator: return rc; } static int __power_on_iris2(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; struct frequency_table *freq_tbl; u32 freq = 0; int rc = 0; @@ -513,7 +508,7 @@ static int __power_on_iris2(struct msm_vidc_core *core) return 0; /* Vote for all hardware resources */ - rc = res_ops->set_bw(core, INT_MAX, INT_MAX); + rc = call_res_op(core, set_bw, core, INT_MAX, INT_MAX); if (rc) { d_vpr_e("%s: failed to vote buses, rc %d\n", __func__, rc); goto fail_vote_buses; @@ -537,7 +532,7 @@ static int __power_on_iris2(struct msm_vidc_core *core) freq = core->power.clk_freq ? core->power.clk_freq : freq_tbl[0].freq; - rc = res_ops->set_clks(core, freq); + rc = call_res_op(core, set_clks, core, freq); if (rc) { d_vpr_e("%s: failed to scale clocks\n", __func__); rc = 0; @@ -560,7 +555,7 @@ static int __power_on_iris2(struct msm_vidc_core *core) fail_power_on_hardware: __power_off_iris2_controller(core); fail_power_on_controller: - res_ops->set_bw(core, 0, 0); + call_res_op(core, set_bw, core, 0, 0); fail_vote_buses: core->power_enabled = false; return rc; diff --git a/driver/variant/iris3/src/msm_vidc_iris3.c b/driver/variant/iris3/src/msm_vidc_iris3.c index eaf023b3c5..01a09c43fa 100644 --- a/driver/variant/iris3/src/msm_vidc_iris3.c +++ b/driver/variant/iris3/src/msm_vidc_iris3.c @@ -269,7 +269,6 @@ static bool is_iris3_hw_power_collapsed(struct msm_vidc_core *core) static int __power_off_iris3_hardware(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0, i; u32 value = 0; bool pwr_collapsed = false; @@ -361,13 +360,13 @@ static int __power_off_iris3_hardware(struct msm_vidc_core *core) disable_power: /* power down process */ - rc = res_ops->gdsc_off(core, "vcodec"); + rc = call_res_op(core, gdsc_off, core, "vcodec"); if (rc) { d_vpr_e("%s: disable regulator vcodec failed\n", __func__); rc = 0; } - rc = res_ops->clk_disable(core, "vcodec_clk"); + rc = call_res_op(core, clk_disable, core, "vcodec_clk"); if (rc) { d_vpr_e("%s: disable unprepare vcodec_clk failed\n", __func__); rc = 0; @@ -378,7 +377,6 @@ disable_power: static int __power_off_iris3_controller(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; /* @@ -439,14 +437,14 @@ static int __power_off_iris3_controller(struct msm_vidc_core *core) return rc; /* Turn off MVP MVS0C core clock */ - rc = res_ops->clk_disable(core, "core_clk"); + rc = call_res_op(core, clk_disable, core, "core_clk"); if (rc) { d_vpr_e("%s: disable unprepare core_clk failed\n", __func__); rc = 0; } /* power down process */ - rc = res_ops->gdsc_off(core, "iris-ctl"); + rc = call_res_op(core, gdsc_off, core, "iris-ctl"); if (rc) { d_vpr_e("%s: disable regulator iris-ctl failed\n", __func__); rc = 0; @@ -457,7 +455,6 @@ static int __power_off_iris3_controller(struct msm_vidc_core *core) static int __power_off_iris3(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; if (!core || !core->capabilities) { @@ -472,7 +469,7 @@ static int __power_off_iris3(struct msm_vidc_core *core) * Reset video_cc_mvs0_clk_src value to resolve MMRM high video * clock projection issue. */ - rc = res_ops->set_clks(core, 0); + rc = call_res_op(core, set_clks, core, 0); if (rc) d_vpr_e("%s: resetting clocks failed\n", __func__); @@ -482,7 +479,8 @@ static int __power_off_iris3(struct msm_vidc_core *core) if (__power_off_iris3_controller(core)) d_vpr_e("%s: failed to power off controller\n", __func__); - if (res_ops->set_bw(core, 0, 0)) + rc = call_res_op(core, set_bw, core, 0, 0); + if (rc) d_vpr_e("%s: failed to unvote buses\n", __func__); if (!(core->intr_status & WRAPPER_INTR_STATUS_A2HWD_BMSK_IRIS3)) @@ -496,60 +494,57 @@ static int __power_off_iris3(struct msm_vidc_core *core) static int __power_on_iris3_controller(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; - rc = res_ops->gdsc_on(core, "iris-ctl"); + rc = call_res_op(core, gdsc_on, core, "iris-ctl"); if (rc) goto fail_regulator; - rc = res_ops->reset_bridge(core); + rc = call_res_op(core, reset_bridge, core); if (rc) goto fail_reset_ahb2axi; - rc = res_ops->clk_enable(core, "gcc_video_axi0"); + rc = call_res_op(core, clk_enable, core, "gcc_video_axi0"); if (rc) goto fail_clk_axi; - rc = res_ops->clk_enable(core, "core_clk"); + rc = call_res_op(core, clk_enable, core, "core_clk"); if (rc) goto fail_clk_controller; return 0; fail_clk_controller: - res_ops->clk_disable(core, "gcc_video_axi0"); + call_res_op(core, clk_disable, core, "gcc_video_axi0"); fail_clk_axi: fail_reset_ahb2axi: - res_ops->gdsc_off(core, "iris-ctl"); + call_res_op(core, gdsc_off, core, "iris-ctl"); fail_regulator: return rc; } static int __power_on_iris3_hardware(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; - rc = res_ops->gdsc_on(core, "vcodec"); + rc = call_res_op(core, gdsc_on, core, "vcodec"); if (rc) goto fail_regulator; - rc = res_ops->clk_enable(core, "vcodec_clk"); + rc = call_res_op(core, clk_enable, core, "vcodec_clk"); if (rc) goto fail_clk_controller; return 0; fail_clk_controller: - res_ops->gdsc_off(core, "vcodec"); + call_res_op(core, gdsc_off, core, "vcodec"); fail_regulator: return rc; } static int __power_on_iris3(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; struct frequency_table *freq_tbl; u32 freq = 0; int rc = 0; @@ -558,7 +553,7 @@ static int __power_on_iris3(struct msm_vidc_core *core) return 0; /* Vote for all hardware resources */ - rc = res_ops->set_bw(core, INT_MAX, INT_MAX); + rc = call_res_op(core, set_bw, core, INT_MAX, INT_MAX); if (rc) { d_vpr_e("%s: failed to vote buses, rc %d\n", __func__, rc); goto fail_vote_buses; @@ -582,7 +577,7 @@ static int __power_on_iris3(struct msm_vidc_core *core) freq = core->power.clk_freq ? core->power.clk_freq : freq_tbl[0].freq; - rc = res_ops->set_clks(core, freq); + rc = call_res_op(core, set_clks, core, freq); if (rc) { d_vpr_e("%s: failed to scale clocks\n", __func__); rc = 0; @@ -602,7 +597,7 @@ static int __power_on_iris3(struct msm_vidc_core *core) fail_power_on_hardware: __power_off_iris3_controller(core); fail_power_on_controller: - res_ops->set_bw(core, 0, 0); + call_res_op(core, set_bw, core, 0, 0); fail_vote_buses: core->power_enabled = false; return rc; diff --git a/driver/variant/iris3/src/msm_vidc_power_iris3.c b/driver/variant/iris3/src/msm_vidc_power_iris3.c index 5e42551ecb..1faa08a4ae 100644 --- a/driver/variant/iris3/src/msm_vidc_power_iris3.c +++ b/driver/variant/iris3/src/msm_vidc_power_iris3.c @@ -265,7 +265,6 @@ static u64 __calculate_decoder(struct vidc_bus_vote_data *d) /* Derived parameters */ int lcu_per_frame, collocated_bytes_per_lcu, tnbr_per_lcu; unsigned long bitrate; - unsigned int num_vpp_pipes; fp_t bins_to_bit_factor, vsp_read_factor, vsp_write_factor, dpb_factor, dpb_write_factor, y_bw_no_ubwc_8bpp; @@ -317,8 +316,6 @@ static u64 __calculate_decoder(struct vidc_bus_vote_data *d) opb_write_compression_factor = opb_compression_enabled ? dpb_write_compression_factor : FP_ONE; - num_vpp_pipes = d->num_vpp_pipes; - if (d->use_sys_cache) { llc_ref_read_l2_cache_enabled = true; if (is_h264_category) diff --git a/driver/variant/iris33/src/msm_vidc_iris33.c b/driver/variant/iris33/src/msm_vidc_iris33.c index 0c01f43b09..70a3b7cb49 100644 --- a/driver/variant/iris33/src/msm_vidc_iris33.c +++ b/driver/variant/iris33/src/msm_vidc_iris33.c @@ -280,7 +280,6 @@ static bool is_iris33_hw_power_collapsed(struct msm_vidc_core *core) static int __power_off_iris33_hardware(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0, i; u32 value = 0; bool pwr_collapsed = false; @@ -368,13 +367,13 @@ static int __power_off_iris33_hardware(struct msm_vidc_core *core) disable_power: /* power down process */ - rc = res_ops->gdsc_off(core, "vcodec"); + rc = call_res_op(core, gdsc_off, core, "vcodec"); if (rc) { d_vpr_e("%s: disable regulator vcodec failed\n", __func__); rc = 0; } - rc = res_ops->clk_disable(core, "vcodec_clk"); + rc = call_res_op(core, clk_disable, core, "vcodec_clk"); if (rc) { d_vpr_e("%s: disable unprepare vcodec_clk failed\n", __func__); rc = 0; @@ -385,7 +384,6 @@ disable_power: static int __power_off_iris33_controller(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; int value = 0; @@ -493,21 +491,21 @@ static int __power_off_iris33_controller(struct msm_vidc_core *core) /* Turn off MVP MVS0C core clock */ - rc = res_ops->clk_disable(core, "core_clk"); + rc = call_res_op(core, clk_disable, core, "core_clk"); if (rc) { d_vpr_e("%s: disable unprepare core_clk failed\n", __func__); rc = 0; } /* power down process */ - rc = res_ops->gdsc_off(core, "iris-ctl"); + rc = call_res_op(core, gdsc_off, core, "iris-ctl"); if (rc) { d_vpr_e("%s: disable regulator iris-ctl failed\n", __func__); rc = 0; } /* Turn off GCC AXI clock */ - rc = res_ops->clk_disable(core, "gcc_video_axi0"); + rc = call_res_op(core, clk_disable, core, "gcc_video_axi0"); if (rc) { d_vpr_e("%s: disable unprepare core_clk failed\n", __func__); rc = 0; @@ -518,7 +516,6 @@ static int __power_off_iris33_controller(struct msm_vidc_core *core) static int __power_off_iris33(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; if (!core || !core->capabilities) { @@ -533,7 +530,7 @@ static int __power_off_iris33(struct msm_vidc_core *core) * Reset video_cc_mvs0_clk_src value to resolve MMRM high video * clock projection issue. */ - rc = res_ops->set_clks(core, 0); + rc = call_res_op(core, set_clks, core, 0); if (rc) d_vpr_e("%s: resetting clocks failed\n", __func__); @@ -543,7 +540,8 @@ static int __power_off_iris33(struct msm_vidc_core *core) if (__power_off_iris33_controller(core)) d_vpr_e("%s: failed to power off controller\n", __func__); - if (res_ops->set_bw(core, 0, 0)) + rc = call_res_op(core, set_bw, core, 0, 0); + if (rc) d_vpr_e("%s: failed to unvote buses\n", __func__); if (!(core->intr_status & WRAPPER_INTR_STATUS_A2HWD_BMSK_IRIS33)) @@ -557,60 +555,57 @@ static int __power_off_iris33(struct msm_vidc_core *core) static int __power_on_iris33_controller(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; - rc = res_ops->gdsc_on(core, "iris-ctl"); + rc = call_res_op(core, gdsc_on, core, "iris-ctl"); if (rc) goto fail_regulator; - rc = res_ops->reset_bridge(core); + rc = call_res_op(core, reset_bridge, core); if (rc) goto fail_reset_ahb2axi; - rc = res_ops->clk_enable(core, "gcc_video_axi0"); + rc = call_res_op(core, clk_enable, core, "gcc_video_axi0"); if (rc) goto fail_clk_axi; - rc = res_ops->clk_enable(core, "core_clk"); + rc = call_res_op(core, clk_enable, core, "core_clk"); if (rc) goto fail_clk_controller; return 0; fail_clk_controller: - res_ops->clk_disable(core, "gcc_video_axi0"); + call_res_op(core, clk_disable, core, "gcc_video_axi0"); fail_clk_axi: fail_reset_ahb2axi: - res_ops->gdsc_off(core, "iris-ctl"); + call_res_op(core, gdsc_off, core, "iris-ctl"); fail_regulator: return rc; } static int __power_on_iris33_hardware(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; - rc = res_ops->gdsc_on(core, "vcodec"); + rc = call_res_op(core, gdsc_on, core, "vcodec"); if (rc) goto fail_regulator; - rc = res_ops->clk_enable(core, "vcodec_clk"); + rc = call_res_op(core, clk_enable, core, "vcodec_clk"); if (rc) goto fail_clk_controller; return 0; fail_clk_controller: - res_ops->gdsc_off(core, "vcodec"); + call_res_op(core, gdsc_off, core, "vcodec"); fail_regulator: return rc; } static int __power_on_iris33(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; struct frequency_table *freq_tbl; u32 freq = 0; int rc = 0; @@ -619,7 +614,7 @@ static int __power_on_iris33(struct msm_vidc_core *core) return 0; /* Vote for all hardware resources */ - rc = res_ops->set_bw(core, INT_MAX, INT_MAX); + rc = call_res_op(core, set_bw, core, INT_MAX, INT_MAX); if (rc) { d_vpr_e("%s: failed to vote buses, rc %d\n", __func__, rc); goto fail_vote_buses; @@ -643,7 +638,7 @@ static int __power_on_iris33(struct msm_vidc_core *core) freq = core->power.clk_freq ? core->power.clk_freq : freq_tbl[0].freq; - rc = res_ops->set_clks(core, freq); + rc = call_res_op(core, set_clks, core, freq); if (rc) { d_vpr_e("%s: failed to scale clocks\n", __func__); rc = 0; @@ -663,7 +658,7 @@ static int __power_on_iris33(struct msm_vidc_core *core) fail_power_on_hardware: __power_off_iris33_controller(core); fail_power_on_controller: - res_ops->set_bw(core, 0, 0); + call_res_op(core, set_bw, core, 0, 0); fail_vote_buses: core->power_enabled = false; return rc; diff --git a/driver/variant/iris33/src/msm_vidc_power_iris33.c b/driver/variant/iris33/src/msm_vidc_power_iris33.c index 1136cfb3f2..e133799772 100644 --- a/driver/variant/iris33/src/msm_vidc_power_iris33.c +++ b/driver/variant/iris33/src/msm_vidc_power_iris33.c @@ -264,7 +264,6 @@ static u64 __calculate_decoder(struct vidc_bus_vote_data *d) /* Derived parameters */ int lcu_per_frame, collocated_bytes_per_lcu, tnbr_per_lcu; unsigned long bitrate; - unsigned int num_vpp_pipes; fp_t bins_to_bit_factor, vsp_read_factor, vsp_write_factor, dpb_factor, dpb_write_factor, y_bw_no_ubwc_8bpp; @@ -316,8 +315,6 @@ static u64 __calculate_decoder(struct vidc_bus_vote_data *d) opb_write_compression_factor = opb_compression_enabled ? dpb_write_compression_factor : FP_ONE; - num_vpp_pipes = d->num_vpp_pipes; - if (d->use_sys_cache) { llc_ref_read_l2_cache_enabled = true; if (is_h264_category) diff --git a/driver/vidc/inc/msm_vidc_control.h b/driver/vidc/inc/msm_vidc_control.h index 48a1809842..277db6da37 100644 --- a/driver/vidc/inc/msm_vidc_control.h +++ b/driver/vidc/inc/msm_vidc_control.h @@ -115,8 +115,6 @@ int msm_vidc_set_preprocess(void *instance, enum msm_vidc_inst_capability_type cap_id); int msm_vidc_set_reserve_duration(void *instance, enum msm_vidc_inst_capability_type cap_id); -int msm_vidc_set_u32_enum(void *instance, - enum msm_vidc_inst_capability_type cap_id); int msm_vidc_set_q16(void *instance, enum msm_vidc_inst_capability_type cap_id); int msm_vidc_v4l2_menu_to_hfi(struct msm_vidc_inst *inst, diff --git a/driver/vidc/inc/msm_vidc_power.h b/driver/vidc/inc/msm_vidc_power.h index 85564205f3..40836092ab 100644 --- a/driver/vidc/inc/msm_vidc_power.h +++ b/driver/vidc/inc/msm_vidc_power.h @@ -251,7 +251,6 @@ static inline int __bpp(enum msm_vidc_colorformat_type f) u64 msm_vidc_max_freq(struct msm_vidc_inst* inst); int msm_vidc_get_inst_load(struct msm_vidc_inst *inst); -int msm_vidc_get_mbps(struct msm_vidc_inst *inst); int msm_vidc_scale_power(struct msm_vidc_inst *inst, bool scale_buses); void msm_vidc_power_data_reset(struct msm_vidc_inst *inst); #endif diff --git a/driver/vidc/inc/resources.h b/driver/vidc/inc/resources.h index 9c2f926a2c..e24ccc0b80 100644 --- a/driver/vidc/inc/resources.h +++ b/driver/vidc/inc/resources.h @@ -197,6 +197,10 @@ struct msm_vidc_resource { int fw_cookie; }; +#define call_res_op(c, op, ...) \ + (((c) && (c)->res_ops && (c)->res_ops->op) ? \ + ((c)->res_ops->op(__VA_ARGS__)) : 0) + struct msm_vidc_resources_ops { int (*init)(struct msm_vidc_core *core); diff --git a/driver/vidc/src/msm_vdec.c b/driver/vidc/src/msm_vdec.c index fbd3282dd9..2d4ee6de2b 100644 --- a/driver/vidc/src/msm_vdec.c +++ b/driver/vidc/src/msm_vdec.c @@ -2186,8 +2186,6 @@ int msm_vdec_try_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f) f->fmt.pix_mp.pixelformat = inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat; f->fmt.pix_mp.width = inst->fmts[OUTPUT_PORT].fmt.pix_mp.width; f->fmt.pix_mp.height = inst->fmts[OUTPUT_PORT].fmt.pix_mp.height; - pix_fmt = v4l2_colorformat_to_driver(inst, - f->fmt.pix_mp.pixelformat, __func__); } if (inst->bufq[INPUT_PORT].vb2q->streaming) { f->fmt.pix_mp.height = inst->fmts[INPUT_PORT].fmt.pix_mp.height; diff --git a/driver/vidc/src/msm_venc.c b/driver/vidc/src/msm_venc.c index 28dc40eafd..73a9213518 100644 --- a/driver/vidc/src/msm_venc.c +++ b/driver/vidc/src/msm_venc.c @@ -591,13 +591,11 @@ static int msm_venc_queue_input_internal_buffers(struct msm_vidc_inst *inst) static int msm_venc_get_output_internal_buffers(struct msm_vidc_inst *inst) { int i, rc = 0; - struct msm_vidc_core *core; - if (!inst || !inst->core) { + if (!inst) { d_vpr_e("%s: invalid params\n", __func__); return -EINVAL; } - core = inst->core; for (i = 0; i < ARRAY_SIZE(msm_venc_output_internal_buffer_type); i++) { rc = msm_vidc_get_internal_buffers(inst, @@ -693,16 +691,14 @@ static int msm_venc_metadata_delivery(struct msm_vidc_inst *inst, enum msm_vidc_port_type port) { int rc = 0; - struct msm_vidc_core *core; u32 payload[32] = {0}; u32 i, count = 0; struct msm_vidc_inst_capability *capability; - if (!inst || !inst->core) { + if (!inst) { d_vpr_e("%s: invalid params\n", __func__); return -EINVAL; } - core = inst->core; i_vpr_h(inst, "%s()\n", __func__); capability = inst->capabilities; @@ -1047,7 +1043,6 @@ int msm_venc_try_fmt(struct msm_vidc_inst *inst, struct v4l2_format *f) f->fmt.pix_mp.width = inst->fmts[OUTPUT_PORT].fmt.pix_mp.width; f->fmt.pix_mp.height = inst->fmts[OUTPUT_PORT].fmt.pix_mp.height; f->fmt.pix_mp.pixelformat = inst->fmts[OUTPUT_PORT].fmt.pix_mp.pixelformat; - pix_fmt = v4l2_codec_to_driver(inst, f->fmt.pix_mp.pixelformat, __func__); } } else if (f->type == INPUT_META_PLANE) { f->fmt.meta.dataformat = inst->fmts[INPUT_META_PORT].fmt.meta.dataformat; diff --git a/driver/vidc/src/msm_vidc_driver.c b/driver/vidc/src/msm_vidc_driver.c index 9fbc863b59..c7b1b84b96 100644 --- a/driver/vidc/src/msm_vidc_driver.c +++ b/driver/vidc/src/msm_vidc_driver.c @@ -6398,14 +6398,12 @@ static int msm_vidc_check_inst_mbpf(struct msm_vidc_inst *inst) u32 msm_vidc_get_max_bitrate(struct msm_vidc_inst* inst) { - struct msm_vidc_inst_capability *capability; u32 max_bitrate = 0x7fffffff; if (!inst || !inst->capabilities) { d_vpr_e("%s: invalid params\n", __func__); return -EINVAL; } - capability = inst->capabilities; if (inst->capabilities->cap[LOWLATENCY_MODE].value) max_bitrate = min(max_bitrate, diff --git a/driver/vidc/src/msm_vidc_power.c b/driver/vidc/src/msm_vidc_power.c index 6a45130c9d..b7a91a3f3f 100644 --- a/driver/vidc/src/msm_vidc_power.c +++ b/driver/vidc/src/msm_vidc_power.c @@ -112,20 +112,8 @@ u64 msm_vidc_max_freq(struct msm_vidc_inst *inst) return freq; } -int msm_vidc_get_mbps(struct msm_vidc_inst *inst) -{ - u32 mbpf, fps, input_rate; - - mbpf = msm_vidc_get_mbs_per_frame(inst); - fps = msm_vidc_get_fps(inst); - input_rate = msm_vidc_get_input_rate(inst); - - return mbpf * max(fps, input_rate); -} - int msm_vidc_get_inst_load(struct msm_vidc_inst *inst) { - int load = 0; u32 mbpf, fps; u32 frame_rate, operating_rate, input_rate, timestamp_rate; @@ -136,7 +124,7 @@ int msm_vidc_get_inst_load(struct msm_vidc_inst *inst) /* return zero load for thumbnail and NRT session */ if (is_thumbnail_session(inst) || !is_realtime_session(inst)) - return load; + return 0; /* calculate load for RT session */ mbpf = msm_vidc_get_mbs_per_frame(inst); @@ -151,7 +139,7 @@ int msm_vidc_get_inst_load(struct msm_vidc_inst *inst) fps = max(fps, timestamp_rate); } - return load = mbpf * fps; + return mbpf * fps; } static int fill_dynamic_stats(struct msm_vidc_inst *inst, diff --git a/driver/vidc/src/msm_vidc_probe.c b/driver/vidc/src/msm_vidc_probe.c index 147e85d3d0..401aa1b226 100644 --- a/driver/vidc/src/msm_vidc_probe.c +++ b/driver/vidc/src/msm_vidc_probe.c @@ -51,7 +51,6 @@ static inline bool is_video_context_bank_device(struct device *dev) static int msm_vidc_init_resources(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops; struct msm_vidc_resource *res = NULL; int rc = 0; @@ -59,7 +58,6 @@ static int msm_vidc_init_resources(struct msm_vidc_core *core) d_vpr_e("%s: invalid params\n", __func__); return -EINVAL; } - res_ops = core->res_ops; res = devm_kzalloc(&core->pdev->dev, sizeof(*res), GFP_KERNEL); if (!res) { @@ -69,7 +67,7 @@ static int msm_vidc_init_resources(struct msm_vidc_core *core) res->core = core; core->resource = res; - rc = res_ops->init(core); + rc = call_res_op(core, init, core); if (rc) { d_vpr_e("%s: Failed to init resources: %d\n", __func__, rc); return rc; diff --git a/driver/vidc/src/venus_hfi.c b/driver/vidc/src/venus_hfi.c index f1e7529f90..e620c9069c 100644 --- a/driver/vidc/src/venus_hfi.c +++ b/driver/vidc/src/venus_hfi.c @@ -444,7 +444,6 @@ static int __release_subcaches(struct msm_vidc_core *core) static int __set_subcaches(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; struct subcache_info *sinfo; struct hfi_buffer buf; @@ -504,7 +503,7 @@ static int __set_subcaches(struct msm_vidc_core *core) return 0; err_fail_set_subacaches: - res_ops->llcc(core, false); + call_res_op(core, llcc, core, false); return rc; } @@ -567,7 +566,6 @@ static int __venus_power_on(struct msm_vidc_core *core) static int __suspend(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; if (!core) { @@ -590,7 +588,7 @@ static int __suspend(struct msm_vidc_core *core) goto err_tzbsp_suspend; } - res_ops->llcc(core, false); + call_res_op(core, llcc, core, false); __venus_power_off(core); d_vpr_h("Venus power off\n"); @@ -602,7 +600,6 @@ err_tzbsp_suspend: static int __resume(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; if (!core) { @@ -642,7 +639,7 @@ static int __resume(struct msm_vidc_core *core) * (s/w triggered) to fast (HW triggered) unless the h/w vote is * present. */ - res_ops->gdsc_hw_ctrl(core); + call_res_op(core, gdsc_hw_ctrl, core); /* Wait for boot completion */ rc = call_venus_op(core, boot_firmware, core); @@ -653,7 +650,7 @@ static int __resume(struct msm_vidc_core *core) __sys_set_debug(core, (msm_vidc_debug & FW_LOGMASK) >> FW_LOGSHIFT); - rc = res_ops->llcc(core, true); + rc = call_res_op(core, llcc, core, true); if (rc) { d_vpr_e("Failed to activate subcache\n"); goto err_reset_core; @@ -663,7 +660,7 @@ static int __resume(struct msm_vidc_core *core) rc = __sys_set_power_control(core, true); if (rc) { d_vpr_e("%s: set power control failed\n", __func__); - res_ops->gdsc_sw_ctrl(core); + call_res_op(core, gdsc_sw_ctrl, core); rc = 0; } @@ -684,7 +681,6 @@ err_venus_power_on: int __load_fw(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; d_vpr_h("%s\n", __func__); @@ -709,7 +705,7 @@ int __load_fw(struct msm_vidc_core *core) * (s/w triggered) to fast (HW triggered) unless the h/w vote is * present. */ - res_ops->gdsc_hw_ctrl(core); + call_res_op(core, gdsc_hw_ctrl, core); trace_msm_v4l2_vidc_fw_load("END"); return rc; @@ -722,13 +718,11 @@ fail_power: void __unload_fw(struct msm_vidc_core *core) { - int rc = 0; - if (!core->resource->fw_cookie) return; cancel_delayed_work(&core->pm_work); - rc = fw_unload(core); + fw_unload(core); __venus_power_off(core); core->cpu_watchdog = false; @@ -891,13 +885,13 @@ static int __sys_image_version(struct msm_vidc_core *core) int venus_hfi_core_init(struct msm_vidc_core *core) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; if (!core) { d_vpr_e("%s: invalid params\n", __func__); return -EINVAL; } + d_vpr_h("%s(): core %pK\n", __func__, core); rc = __strict_check(core, __func__); @@ -916,7 +910,7 @@ int venus_hfi_core_init(struct msm_vidc_core *core) if (rc) goto error; - rc = res_ops->llcc(core, true); + rc = call_res_op(core, llcc, core, true); if (rc) goto error; @@ -939,7 +933,7 @@ int venus_hfi_core_init(struct msm_vidc_core *core) rc = __sys_set_power_control(core, true); if (rc) { d_vpr_e("%s: set power control failed\n", __func__); - res_ops->gdsc_sw_ctrl(core); + call_res_op(core, gdsc_sw_ctrl, core); rc = 0; } @@ -953,13 +947,13 @@ error: int venus_hfi_core_deinit(struct msm_vidc_core *core, bool force) { - const struct msm_vidc_resources_ops *res_ops = core->res_ops; int rc = 0; if (!core) { d_vpr_h("%s(): invalid params\n", __func__); return -EINVAL; } + d_vpr_h("%s(): core %pK\n", __func__, core); rc = __strict_check(core, __func__); if (rc) @@ -970,7 +964,7 @@ int venus_hfi_core_deinit(struct msm_vidc_core *core, bool force) __resume(core); __flush_debug_queue(core, (!force ? core->packet : NULL), core->packet_size); __release_subcaches(core); - res_ops->llcc(core, false); + call_res_op(core, llcc, core, false); __unload_fw(core); /** * coredump need to be called after firmware unload, coredump also @@ -1997,7 +1991,6 @@ unlock: int venus_hfi_scale_clocks(struct msm_vidc_inst* inst, u64 freq) { - const struct msm_vidc_resources_ops *res_ops; int rc = 0; struct msm_vidc_core* core; @@ -2006,7 +1999,6 @@ int venus_hfi_scale_clocks(struct msm_vidc_inst* inst, u64 freq) return -EINVAL; } core = inst->core; - res_ops = core->res_ops; core_lock(core, __func__); rc = __resume(core); @@ -2014,7 +2006,7 @@ int venus_hfi_scale_clocks(struct msm_vidc_inst* inst, u64 freq) i_vpr_e(inst, "%s: Resume from power collapse failed\n", __func__); goto exit; } - rc = res_ops->set_clks(core, freq); + rc = call_res_op(core, set_clks, core, freq); if (rc) goto exit; @@ -2026,7 +2018,6 @@ exit: int venus_hfi_scale_buses(struct msm_vidc_inst *inst, u64 bw_ddr, u64 bw_llcc) { - const struct msm_vidc_resources_ops *res_ops; int rc = 0; struct msm_vidc_core* core; @@ -2035,7 +2026,6 @@ int venus_hfi_scale_buses(struct msm_vidc_inst *inst, u64 bw_ddr, u64 bw_llcc) return -EINVAL; } core = inst->core; - res_ops = core->res_ops; core_lock(core, __func__); rc = __resume(core); @@ -2043,7 +2033,7 @@ int venus_hfi_scale_buses(struct msm_vidc_inst *inst, u64 bw_ddr, u64 bw_llcc) i_vpr_e(inst, "%s: Resume from power collapse failed\n", __func__); goto exit; } - rc = res_ops->set_bw(core, bw_ddr, bw_llcc); + rc = call_res_op(core, set_bw, core, bw_ddr, bw_llcc); if (rc) goto exit;