From 8cb1da8d129e86ec9a32a67047bbef0a00fddfa9 Mon Sep 17 00:00:00 2001 From: Venkata Siva Pavan KumarVenkatapatigari Date: Mon, 4 May 2026 17:44:09 +0530 Subject: [PATCH] video: driver: use global UBWC config on KLM platforms - Use kernel global UBWC config database for kodiak/lemans/monaco - Fall back to existing per-platform UBWC defaults when global data is unavailable. Signed-off-by: Venkata Siva Pavan KumarVenkatapatigari --- .../platform/common/inc/msm_vidc_platform.h | 1 + .../platform/common/src/msm_vidc_platform.c | 4 + driver/platform/common/src/msm_vidc_ubwc.c | 100 ++++++++++++++++++ driver/platform/monaco/src/monaco.c | 1 + msm_video/Kbuild | 1 + video/Kbuild | 1 + 6 files changed, 108 insertions(+) create mode 100644 driver/platform/common/src/msm_vidc_ubwc.c diff --git a/driver/platform/common/inc/msm_vidc_platform.h b/driver/platform/common/inc/msm_vidc_platform.h index b8e5a2d5..d2a41e1c 100644 --- a/driver/platform/common/inc/msm_vidc_platform.h +++ b/driver/platform/common/inc/msm_vidc_platform.h @@ -344,6 +344,7 @@ static inline bool is_mmrm_supported(struct msm_vidc_core *core) } int msm_vidc_init_platform_capabilities(struct msm_vidc_core *core); +int msm_vidc_update_ubwc_config(struct msm_vidc_core *core); enum msm_vidc_hw_version msm_vidc_get_hw_version(void); int msm_vidc_read_efuse(struct msm_vidc_core *core); diff --git a/driver/platform/common/src/msm_vidc_platform.c b/driver/platform/common/src/msm_vidc_platform.c index a3d924a7..81b0498f 100644 --- a/driver/platform/common/src/msm_vidc_platform.c +++ b/driver/platform/common/src/msm_vidc_platform.c @@ -433,6 +433,10 @@ int msm_vidc_init_platform_capabilities(struct msm_vidc_core *core) if (rc) return rc; + rc = msm_vidc_update_ubwc_config(core); + if (rc) + return rc; + rc = msm_vidc_init_vpu(core); return rc; diff --git a/driver/platform/common/src/msm_vidc_ubwc.c b/driver/platform/common/src/msm_vidc_ubwc.c new file mode 100644 index 00000000..10695b50 --- /dev/null +++ b/driver/platform/common/src/msm_vidc_ubwc.c @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. + */ + +#include +#include + +#include "msm_vidc_platform.h" +#include "msm_vidc_debug.h" + +#ifndef MSM_VIDC_HAS_QCOM_UBWC_HEADER +/* + * Downstream driver: enable if kernel provides global UBWC config database + * (include/linux/soc/qcom/ubwc.h with qcom_ubwc_config_get_data()). + */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 17, 0) +#define MSM_VIDC_HAS_QCOM_UBWC_HEADER 1 +#else +#define MSM_VIDC_HAS_QCOM_UBWC_HEADER 0 +#endif +#endif + +#if MSM_VIDC_HAS_QCOM_UBWC_HEADER +#include + +static bool msm_vidc_qcom_ubwc_min_acc_length_64b( + const struct qcom_ubwc_cfg_data *cfg) +{ + return cfg->ubwc_enc_version == UBWC_1_0 && + (cfg->ubwc_dec_version == UBWC_2_0 || + cfg->ubwc_dec_version == UBWC_3_0); +} + +static bool msm_vidc_qcom_ubwc_macrotile_mode( + const struct qcom_ubwc_cfg_data *cfg) +{ + return cfg->macrotile_mode; +} + +static bool msm_vidc_qcom_ubwc_bank_spread( + const struct qcom_ubwc_cfg_data *cfg) +{ + return cfg->ubwc_bank_spread; +} + +static u32 msm_vidc_qcom_ubwc_swizzle( + const struct qcom_ubwc_cfg_data *cfg) +{ + return cfg->ubwc_swizzle; +} + +int msm_vidc_update_ubwc_config(struct msm_vidc_core *core) +{ + const struct qcom_ubwc_cfg_data *ubwc_cfg; + struct msm_vidc_ubwc_config_data *ubwc_config; + u32 swizzle; + + if (!core || !core->platform || !core->platform->data.ubwc_config) + return 0; + + ubwc_cfg = qcom_ubwc_config_get_data(); + if (IS_ERR(ubwc_cfg)) { + long rc = PTR_ERR(ubwc_cfg); + + if (rc == -EINVAL) { + d_vpr_h("%s: no global UBWC config for this platform, using platform defaults\n", + __func__); + return 0; + } + + d_vpr_e("%s: failed to get global UBWC config: %ld\n", + __func__, rc); + return rc; + } + + ubwc_config = core->platform->data.ubwc_config; + swizzle = msm_vidc_qcom_ubwc_swizzle(ubwc_cfg); + + ubwc_config->max_channels = + msm_vidc_qcom_ubwc_macrotile_mode(ubwc_cfg) ? 8 : 4; + ubwc_config->mal_length = + msm_vidc_qcom_ubwc_min_acc_length_64b(ubwc_cfg) ? 64 : 32; + ubwc_config->highest_bank_bit = ubwc_cfg->highest_bank_bit; + ubwc_config->bank_swzl_level = !!(swizzle & UBWC_SWIZZLE_ENABLE_LVL1); + ubwc_config->bank_swz2_level = !!(swizzle & UBWC_SWIZZLE_ENABLE_LVL2); + ubwc_config->bank_swz3_level = !!(swizzle & UBWC_SWIZZLE_ENABLE_LVL3); + ubwc_config->bank_spreading = + msm_vidc_qcom_ubwc_bank_spread(ubwc_cfg); + + d_vpr_h("%s: global UBWC config applied\n", __func__); + + return 0; +} +#else +int msm_vidc_update_ubwc_config(struct msm_vidc_core *core) +{ + return 0; +} +#endif diff --git a/driver/platform/monaco/src/monaco.c b/driver/platform/monaco/src/monaco.c index ed3166fd..f5c8f18b 100644 --- a/driver/platform/monaco/src/monaco.c +++ b/driver/platform/monaco/src/monaco.c @@ -2154,5 +2154,6 @@ int msm_vidc_init_platform_monaco(struct msm_vidc_core *core) if (rc) return rc; + return rc; } diff --git a/msm_video/Kbuild b/msm_video/Kbuild index f2b8867a..75c9a59f 100644 --- a/msm_video/Kbuild +++ b/msm_video/Kbuild @@ -194,6 +194,7 @@ msm_video-objs += $(VIDEO_DRIVER_REL_PATH)/platform/nordau/src/msm_vidc_nordau.o endif msm_video-objs += $(VIDEO_DRIVER_REL_PATH)/platform/common/src/msm_vidc_platform.o \ + $(VIDEO_DRIVER_REL_PATH)/platform/common/src/msm_vidc_ubwc.o \ $(VIDEO_DRIVER_REL_PATH)/platform/common/src/msm_vidc_platform_ext.o \ $(VIDEO_DRIVER_REL_PATH)/variant/common/src/msm_vidc_variant.o \ $(VIDEO_DRIVER_REL_PATH)/vidc/src/msm_vidc_v4l2.o \ diff --git a/video/Kbuild b/video/Kbuild index 1cd1fb9b..7de5e6c3 100644 --- a/video/Kbuild +++ b/video/Kbuild @@ -206,6 +206,7 @@ iris_vpu-objs += $(VIDEO_DRIVER_REL_PATH)/platform/lemans/src/lemans.o \ endif iris_vpu-objs += $(VIDEO_DRIVER_REL_PATH)/platform/common/src/msm_vidc_platform.o \ + $(VIDEO_DRIVER_REL_PATH)/platform/common/src/msm_vidc_ubwc.o \ $(VIDEO_DRIVER_REL_PATH)/variant/common/src/msm_vidc_variant.o \ $(VIDEO_DRIVER_REL_PATH)/vidc/src/msm_vidc_v4l2.o \ $(VIDEO_DRIVER_REL_PATH)/vidc/src/msm_vidc_vb2.o \