From 61ae0b7642cc8e65b0cef40163faccbbcdfe6435 Mon Sep 17 00:00:00 2001 From: Antony Clince Alex Date: Thu, 28 Apr 2022 02:28:43 +0000 Subject: [PATCH] gpu: nvgpu: fix emulate mode enable The emulate mode support is determined after chip detect and is flagged by using NVGPU_SUPPORT_EMULATE_MODE flag. The present logic prevents user from configuring the emulate mode sysfs knobs if this flag is not set, however the emulate mode usecase requires the user to configure the syfs knob prior to power-on, hence defer emulate mode check to a later stage after chip detect. Bug 3621460 Change-Id: If522527542fa8d7e95ccbcff43b74adbb9e976e6 Signed-off-by: Antony Clince Alex Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2703953 Reviewed-by: svcacv Reviewed-by: svc-mobile-coverity Reviewed-by: svc-mobile-cert Reviewed-by: Mayur Poojary Reviewed-by: Mahantesh Kumbar Reviewed-by: Ankur Kishore GVS: Gerrit_Virtual_Submit Tested-by: David Li --- drivers/gpu/nvgpu/common/acr/acr_sw_ga10b.c | 6 +++++- drivers/gpu/nvgpu/hal/gr/init/gr_init_ga10b.c | 4 +++- drivers/gpu/nvgpu/os/linux/sysfs.c | 4 ---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/nvgpu/common/acr/acr_sw_ga10b.c b/drivers/gpu/nvgpu/common/acr/acr_sw_ga10b.c index fdafb0b98..b800ce274 100644 --- a/drivers/gpu/nvgpu/common/acr/acr_sw_ga10b.c +++ b/drivers/gpu/nvgpu/common/acr/acr_sw_ga10b.c @@ -21,6 +21,7 @@ */ #include #include +#include #include #include #include @@ -166,9 +167,12 @@ static int ga10b_acr_patch_wpr_info_to_ucode(struct gk20a *g, */ acr_sysmem_desc->wpr_offset = WPR_OFFSET; - if (g->emulate_mode < EMULATE_MODE_MAX_CONFIG) { + if (nvgpu_is_enabled(g, NVGPU_SUPPORT_EMULATE_MODE) && + (g->emulate_mode < EMULATE_MODE_MAX_CONFIG)) { acr_sysmem_desc->gpu_mode &= (~EMULATE_MODE_MASK); acr_sysmem_desc->gpu_mode |= g->emulate_mode; + } else { + acr_sysmem_desc->gpu_mode &= (~EMULATE_MODE_MASK); } if (nvgpu_is_enabled(g, NVGPU_SUPPORT_MIG)) { diff --git a/drivers/gpu/nvgpu/hal/gr/init/gr_init_ga10b.c b/drivers/gpu/nvgpu/hal/gr/init/gr_init_ga10b.c index cda88969c..885914e72 100644 --- a/drivers/gpu/nvgpu/hal/gr/init/gr_init_ga10b.c +++ b/drivers/gpu/nvgpu/hal/gr/init/gr_init_ga10b.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "gr_init_ga10b.h" @@ -65,7 +66,8 @@ u32 ga10b_gr_init_get_ctx_betacb_size(struct gk20a *g) void ga10b_gr_init_commit_rops_crop_override(struct gk20a *g, struct nvgpu_gr_ctx *gr_ctx, bool patch) { - if (g->emulate_mode) { + if (nvgpu_is_enabled(g, NVGPU_SUPPORT_EMULATE_MODE) && + (g->emulate_mode > 0U)) { u32 data = 0U; data = nvgpu_readl(g, gr_pri_gpcs_rops_crop_debug1_r()); data = set_field(data, diff --git a/drivers/gpu/nvgpu/os/linux/sysfs.c b/drivers/gpu/nvgpu/os/linux/sysfs.c index f9c5ea317..b7e87d79e 100644 --- a/drivers/gpu/nvgpu/os/linux/sysfs.c +++ b/drivers/gpu/nvgpu/os/linux/sysfs.c @@ -1327,10 +1327,6 @@ static ssize_t emulate_mode_store(struct device *dev, if (kstrtoul(buf, 10, &val) < 0) return -EINVAL; - if (!nvgpu_is_enabled(g, NVGPU_SUPPORT_EMULATE_MODE)) { - nvgpu_err(g, "Emulate mode not supported"); - return -EINVAL; - } if (nvgpu_is_powered_on(g)) { nvgpu_err(g, "GPU is powered on already, emulate mode " "cannot be enabled");