From 06ceff1240902c7f4cdb01dcbc9c988fc5fd9495 Mon Sep 17 00:00:00 2001 From: Vinod G Date: Mon, 18 Jun 2018 12:04:13 -0700 Subject: gpu: nvgpu: PG refcount check moved to a wrapper function. Moved PG refcount checking to a wrapper function, this function manages the refcount and decides whether to call dbg_set_powergate function. Instead of checking the dbg_s->is_pg_disabled variable, code is checking g->dbg_powergating_disabled_refcount variable to know if powergate is disabled or not. Updating hwpm ctxsw mode without disabling powergate will result in priv errors. Bug 200410871 Bug 2109765 Change-Id: I33c9022cb04cd39249c78e72584dfe6afb7212d0 Signed-off-by: Vinod G Reviewed-on: https://git-master.nvidia.com/r/1753550 Reviewed-by: svc-mobile-coverity Reviewed-by: Richard Zhao GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/os/linux/ioctl_dbg.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'drivers/gpu/nvgpu/os/linux/ioctl_dbg.c') diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_dbg.c b/drivers/gpu/nvgpu/os/linux/ioctl_dbg.c index 31e7e2cb..76ff25c0 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_dbg.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_dbg.c @@ -181,7 +181,9 @@ int gk20a_dbg_gpu_dev_release(struct inode *inode, struct file *filp) * calling powergate/timeout enable ioctl */ nvgpu_mutex_acquire(&g->dbg_sessions_lock); - g->ops.dbg_session_ops.dbg_set_powergate(dbg_s, false); + if (dbg_s->is_pg_disabled) { + nvgpu_set_powergate_locked(dbg_s, false); + } nvgpu_dbg_timeout_enable(dbg_s, NVGPU_DBG_GPU_IOCTL_TIMEOUT_ENABLE); /* If this session owned the perf buffer, release it */ @@ -867,9 +869,10 @@ static int nvgpu_ioctl_channel_reg_ops(struct dbg_session_gk20a *dbg_s, /* In the virtual case, the server will handle * disabling/enabling powergating when processing reg ops */ - powergate_err = g->ops.dbg_session_ops.dbg_set_powergate(dbg_s, - true); - is_pg_disabled = true; + powergate_err = nvgpu_set_powergate_locked(dbg_s, true); + if (!powergate_err) { + is_pg_disabled = true; + } } if (!powergate_err) { @@ -938,9 +941,8 @@ static int nvgpu_ioctl_channel_reg_ops(struct dbg_session_gk20a *dbg_s, /* enable powergate, if previously disabled */ if (is_pg_disabled) { - powergate_err = - g->ops.dbg_session_ops.dbg_set_powergate(dbg_s, - false); + powergate_err = nvgpu_set_powergate_locked(dbg_s, + false); } } @@ -964,14 +966,16 @@ static int nvgpu_ioctl_powergate_gk20a(struct dbg_session_gk20a *dbg_s, g->name, args->mode); nvgpu_mutex_acquire(&g->dbg_sessions_lock); - if (args->mode == NVGPU_DBG_GPU_POWERGATE_MODE_DISABLE) { - err = g->ops.dbg_session_ops.dbg_set_powergate(dbg_s, true); - } else if (args->mode == NVGPU_DBG_GPU_POWERGATE_MODE_ENABLE) { - err = g->ops.dbg_session_ops.dbg_set_powergate(dbg_s, false); - } else { + if ((args->mode != NVGPU_DBG_GPU_POWERGATE_MODE_DISABLE) && + (args->mode != NVGPU_DBG_GPU_POWERGATE_MODE_ENABLE)) { nvgpu_err(g, "invalid powergate mode"); err = -EINVAL; + goto pg_err_end; } + + err = nvgpu_set_powergate_locked(dbg_s, + args->mode == NVGPU_DBG_GPU_POWERGATE_MODE_DISABLE); +pg_err_end: nvgpu_mutex_release(&g->dbg_sessions_lock); return err; } @@ -1053,7 +1057,7 @@ static int nvgpu_dbg_gpu_ioctl_hwpm_ctxsw_mode(struct dbg_session_gk20a *dbg_s, err = -EINVAL; goto clean_up; } - if (!dbg_s->is_pg_disabled) { + if (g->dbg_powergating_disabled_refcount == 0) { nvgpu_err(g, "powergate is not disabled"); err = -ENOSYS; goto clean_up; -- cgit v1.2.2