diff --git a/drivers/gpu/nvgpu/common/linux/debug.c b/drivers/gpu/nvgpu/common/linux/debug.c index ee93a9014..8738f3e75 100644 --- a/drivers/gpu/nvgpu/common/linux/debug.c +++ b/drivers/gpu/nvgpu/common/linux/debug.c @@ -267,9 +267,6 @@ static int gk20a_railgating_debugfs_init(struct gk20a *g) struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); struct dentry *d; - if (!g->can_railgate) - return 0; - d = debugfs_create_file( "railgate_residency", S_IRUGO|S_IWUSR, l->debugfs, g, &railgate_residency_fops); diff --git a/drivers/gpu/nvgpu/common/linux/driver_common.c b/drivers/gpu/nvgpu/common/linux/driver_common.c index 015046dd1..2475912a9 100644 --- a/drivers/gpu/nvgpu/common/linux/driver_common.c +++ b/drivers/gpu/nvgpu/common/linux/driver_common.c @@ -168,8 +168,12 @@ static void nvgpu_init_pm_vars(struct gk20a *g) g->ptimer_src_freq = platform->ptimer_src_freq; g->support_pmu = support_gk20a_pmu(dev_from_gk20a(g)); g->can_railgate = platform->can_railgate_init; - g->railgate_delay = platform->railgate_delay_init; g->ldiv_slowdown_factor = platform->ldiv_slowdown_factor_init; + /* if default delay is not set, set default delay to 500msec */ + if (platform->railgate_delay_init) + g->railgate_delay = platform->railgate_delay_init; + else + g->railgate_delay = NVGPU_DEFAULT_RAILGATE_IDLE_TIMEOUT; __nvgpu_set_enabled(g, NVGPU_PMU_PERFMON, platform->enable_perfmon); /* set default values to aelpg parameters */ diff --git a/drivers/gpu/nvgpu/common/linux/module.c b/drivers/gpu/nvgpu/common/linux/module.c index 86abd36b8..a7289b66c 100644 --- a/drivers/gpu/nvgpu/common/linux/module.c +++ b/drivers/gpu/nvgpu/common/linux/module.c @@ -458,10 +458,10 @@ int __gk20a_do_idle(struct gk20a *g, bool force_reset) * If User disables rail gating, we take one more * extra refcount */ - if (g->user_railgate_disabled) - target_ref_cnt = 2; - else + if (g->can_railgate) target_ref_cnt = 1; + else + target_ref_cnt = 2; nvgpu_mutex_acquire(&platform->railgate_lock); nvgpu_timeout_init(g, &timeout, GK20A_WAIT_FOR_IDLE_MS, @@ -964,7 +964,7 @@ static int gk20a_pm_suspend(struct device *dev) struct gk20a_platform *platform = dev_get_drvdata(dev); struct gk20a *g = get_gk20a(dev); int ret = 0; - int idle_usage_count = g->user_railgate_disabled ? 1 : 0; + int idle_usage_count = 0; if (!g->power_on) { if (!pm_runtime_enabled(dev)) @@ -1020,23 +1020,19 @@ static int gk20a_pm_init(struct device *dev) nvgpu_log_fn(g, " "); - /* Initialise pm runtime */ - if (g->railgate_delay) { + /* + * Initialise pm runtime. For railgate disable + * case, set autosuspend delay to negative which + * will suspend runtime pm + */ + if (g->railgate_delay && g->can_railgate) pm_runtime_set_autosuspend_delay(dev, g->railgate_delay); - pm_runtime_use_autosuspend(dev); - } + else + pm_runtime_set_autosuspend_delay(dev, -1); - if (g->can_railgate) { - pm_runtime_enable(dev); - if (!pm_runtime_enabled(dev)) - gk20a_pm_unrailgate(dev); - else - gk20a_pm_railgate(dev); - } else { - __pm_runtime_disable(dev, false); - gk20a_pm_unrailgate(dev); - } + pm_runtime_use_autosuspend(dev); + pm_runtime_enable(dev); return err; } diff --git a/drivers/gpu/nvgpu/common/linux/sysfs.c b/drivers/gpu/nvgpu/common/linux/sysfs.c index e425e1530..7a887beb0 100644 --- a/drivers/gpu/nvgpu/common/linux/sysfs.c +++ b/drivers/gpu/nvgpu/common/linux/sysfs.c @@ -305,24 +305,23 @@ static ssize_t railgate_enable_store(struct device *dev, unsigned long railgate_enable = 0; /* dev is guaranteed to be valid here. Ok to de-reference */ struct gk20a *g = get_gk20a(dev); - int err = 0; + int err; if (kstrtoul(buf, 10, &railgate_enable) < 0) return -EINVAL; if (railgate_enable && !g->can_railgate) { - /* release extra ref count */ - gk20a_idle(g); g->can_railgate = true; - g->user_railgate_disabled = false; + pm_runtime_set_autosuspend_delay(dev, g->railgate_delay); } else if (railgate_enable == 0 && g->can_railgate) { - /* take extra ref count */ - err = gk20a_busy(g); - if (err) - return err; g->can_railgate = false; - g->user_railgate_disabled = true; + pm_runtime_set_autosuspend_delay(dev, -1); } + /* wake-up system to make rail-gating setting effective */ + err = gk20a_busy(g); + if (err) + return err; + gk20a_idle(g); nvgpu_info(g, "railgate is %s.", g->can_railgate ? "enabled" : "disabled"); diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.c b/drivers/gpu/nvgpu/gk20a/gk20a.c index 9ce2ef53d..b502ef020 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/gk20a.c @@ -370,9 +370,6 @@ int gk20a_wait_for_idle(struct gk20a *g) if (!g) return -ENODEV; - if (g->user_railgate_disabled) - target_usage_count = 1; - while ((nvgpu_atomic_read(&g->usage_count) != target_usage_count) && (wait_length-- >= 0)) nvgpu_msleep(20); diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.h b/drivers/gpu/nvgpu/gk20a/gk20a.h index 07ff28f6a..77e6e7593 100644 --- a/drivers/gpu/nvgpu/gk20a/gk20a.h +++ b/drivers/gpu/nvgpu/gk20a/gk20a.h @@ -1358,7 +1358,6 @@ struct gk20a { u32 ptimer_src_freq; bool can_railgate; - bool user_railgate_disabled; int railgate_delay; u8 ldiv_slowdown_factor; unsigned int aggressive_sync_destroy_thresh; diff --git a/drivers/gpu/nvgpu/include/nvgpu/defaults.h b/drivers/gpu/nvgpu/include/nvgpu/defaults.h index 2d7a42b1e..cae380a74 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/defaults.h +++ b/drivers/gpu/nvgpu/include/nvgpu/defaults.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -28,4 +28,6 @@ */ #define NVGPU_DEFAULT_GR_IDLE_TIMEOUT 3000 +#define NVGPU_DEFAULT_RAILGATE_IDLE_TIMEOUT 500 + #endif