From 10b3b5b1d58cbade2c8d973f80291e012efd1ad3 Mon Sep 17 00:00:00 2001 From: Leon Yu Date: Fri, 25 Oct 2019 10:15:57 +0800 Subject: nvgpu: fix railgate_enable_store Writing same value to railgate_enable_store should be treated as nop and made successfully. Doing so is not only an optimization for the operation but also convention that users expect for "settings". This change is primary for fixing a peculiar situation in the driver: root@localhost:/sys/devices/17000000.gp10b# cat railgate_enable 0 root@localhost:/sys/devices/17000000.gp10b# echo 0 > railgate_enable bash: echo: write error: Invalid argument Attempt to disable railgating on a platform where railgating isn't supported shouldn't be treated as 'invalid'. It's disabled after all. Bug 200562094 Change-Id: I3c04934bdbaf337c33d7de9cac6d53c96b4dacae Signed-off-by: Leon Yu Reviewed-on: https://git-master.nvidia.com/r/2225476 Reviewed-by: Vijayakumar Subbu Reviewed-by: Automatic_Commit_Validation_User GVS: Gerrit_Virtual_Submit Reviewed-by: Debarshi Dutta Reviewed-by: Bibek Basu Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/os/linux/sysfs.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/gpu/nvgpu/os/linux/sysfs.c b/drivers/gpu/nvgpu/os/linux/sysfs.c index 84a311de..221ea0ce 100644 --- a/drivers/gpu/nvgpu/os/linux/sysfs.c +++ b/drivers/gpu/nvgpu/os/linux/sysfs.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. + * Copyright (c) 2011-2019, NVIDIA CORPORATION. All rights reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -266,6 +266,13 @@ static ssize_t railgate_enable_store(struct device *dev, if (kstrtoul(buf, 10, &railgate_enable) < 0) return -EINVAL; + /* convert to boolean */ + railgate_enable = !!railgate_enable; + + /* writing same value should be treated as nop and successful */ + if (railgate_enable == enabled) + goto out; + if (!platform->can_railgate_init) { nvgpu_err(g, "Railgating is not supported"); return -EINVAL; @@ -274,7 +281,7 @@ static ssize_t railgate_enable_store(struct device *dev, if (railgate_enable) { __nvgpu_set_enabled(g, NVGPU_CAN_RAILGATE, true); pm_runtime_set_autosuspend_delay(dev, g->railgate_delay); - } else if (railgate_enable == 0 && enabled) { + } else { __nvgpu_set_enabled(g, NVGPU_CAN_RAILGATE, false); pm_runtime_set_autosuspend_delay(dev, -1); } @@ -284,6 +291,7 @@ static ssize_t railgate_enable_store(struct device *dev, return err; gk20a_idle(g); +out: nvgpu_info(g, "railgate is %s.", nvgpu_is_enabled(g, NVGPU_CAN_RAILGATE) ? "enabled" : "disabled"); -- cgit v1.2.2