summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu
diff options
context:
space:
mode:
authorDivya Singhatwaria <dsinghatwari@nvidia.com>2019-07-23 01:13:35 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2019-08-02 15:57:24 -0400
commitae175e45edc5807131dfb1b63d3e4795e96a3f86 (patch)
treec209caf5a5804f250be83e4a68295daa64d6cfb5 /drivers/gpu/nvgpu
parent47f6bc0c2e85d0a8ff943b88c81108ca1bfc588e (diff)
gpu: nvgpu: Use TPC_PG_MASK to powergate the TPC
- In GV11B, read fuse_status_opt_tpc_gpc register to read which TPCs are floorswept. - The driver will also read sysfs node: tpc_pg_mask - Based on these two values "can_tpc_powergate" will be set to true or false and mask will be used to write to fuse_ctrl_opt_tpc_gpc register to powergate the TPC. - can_tpc_powergate = true indicates that the mask value sent from userspace is valid and can be used to power gate the desired TPC - can_tpc_powergate = false indicates that the mask value sent from userspace is not valid and cannot be used to power gate the desired TPC. Bug 200532639 Change-Id: Ib0806e4c96305a13b3574e8063ad8e16770aa7cd Signed-off-by: Divya Singhatwaria <dsinghatwari@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/2159219 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu')
-rw-r--r--drivers/gpu/nvgpu/Makefile1
-rw-r--r--drivers/gpu/nvgpu/Makefile.sources1
-rw-r--r--drivers/gpu/nvgpu/gk20a/gk20a.c22
-rw-r--r--drivers/gpu/nvgpu/gm20b/hal_gm20b.c5
-rw-r--r--drivers/gpu/nvgpu/gp106/hal_gp106.c4
-rw-r--r--drivers/gpu/nvgpu/gv100/hal_gv100.c4
-rw-r--r--drivers/gpu/nvgpu/gv11b/hal_gv11b.c5
-rw-r--r--drivers/gpu/nvgpu/gv11b/tpc_gv11b.c70
-rw-r--r--drivers/gpu/nvgpu/gv11b/tpc_gv11b.h32
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/gk20a.h6
-rw-r--r--drivers/gpu/nvgpu/os/linux/module.c3
-rw-r--r--drivers/gpu/nvgpu/os/linux/platform_gk20a.h4
-rw-r--r--drivers/gpu/nvgpu/os/linux/platform_gv11b_tegra.c25
-rw-r--r--drivers/gpu/nvgpu/os/linux/sysfs.c28
14 files changed, 177 insertions, 33 deletions
diff --git a/drivers/gpu/nvgpu/Makefile b/drivers/gpu/nvgpu/Makefile
index 827d7df5..bec1809b 100644
--- a/drivers/gpu/nvgpu/Makefile
+++ b/drivers/gpu/nvgpu/Makefile
@@ -330,6 +330,7 @@ nvgpu-y += \
330 gv11b/subctx_gv11b.o \ 330 gv11b/subctx_gv11b.o \
331 gv11b/regops_gv11b.o \ 331 gv11b/regops_gv11b.o \
332 gv11b/ecc_gv11b.o \ 332 gv11b/ecc_gv11b.o \
333 gv11b/tpc_gv11b.o \
333 gv100/mm_gv100.o \ 334 gv100/mm_gv100.o \
334 gv100/gr_ctx_gv100.o \ 335 gv100/gr_ctx_gv100.o \
335 gv100/bios_gv100.o \ 336 gv100/bios_gv100.o \
diff --git a/drivers/gpu/nvgpu/Makefile.sources b/drivers/gpu/nvgpu/Makefile.sources
index 183da6a5..03bc8bcd 100644
--- a/drivers/gpu/nvgpu/Makefile.sources
+++ b/drivers/gpu/nvgpu/Makefile.sources
@@ -197,6 +197,7 @@ srcs := os/posix/nvgpu.c \
197 gv11b/subctx_gv11b.c \ 197 gv11b/subctx_gv11b.c \
198 gv11b/regops_gv11b.c \ 198 gv11b/regops_gv11b.c \
199 gv11b/ecc_gv11b.c \ 199 gv11b/ecc_gv11b.c \
200 gv11b/tpc_gv11b.c \
200 gp106/hal_gp106.c \ 201 gp106/hal_gp106.c \
201 gp106/flcn_gp106.c \ 202 gp106/flcn_gp106.c \
202 gp106/pmu_gp106.c \ 203 gp106/pmu_gp106.c \
diff --git a/drivers/gpu/nvgpu/gk20a/gk20a.c b/drivers/gpu/nvgpu/gk20a/gk20a.c
index 7ae1febc..347658b2 100644
--- a/drivers/gpu/nvgpu/gk20a/gk20a.c
+++ b/drivers/gpu/nvgpu/gk20a/gk20a.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * GK20A Graphics 2 * GK20A Graphics
3 * 3 *
4 * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved. 4 * Copyright (c) 2011-2019, NVIDIA CORPORATION. All rights reserved.
5 * 5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a 6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"), 7 * copy of this software and associated documentation files (the "Software"),
@@ -126,6 +126,8 @@ int gk20a_finalize_poweron(struct gk20a *g)
126 u32 nr_pages; 126 u32 nr_pages;
127#endif 127#endif
128 128
129 u32 fuse_status;
130
129 nvgpu_log_fn(g, " "); 131 nvgpu_log_fn(g, " ");
130 132
131 if (g->power_on) { 133 if (g->power_on) {
@@ -264,14 +266,20 @@ int gk20a_finalize_poweron(struct gk20a *g)
264 g->ops.mc.intr_enable(g); 266 g->ops.mc.intr_enable(g);
265 267
266 /* 268 /*
267 * Overwrite can_tpc_powergate to false if the chip is ES fused and 269 * Power gate the chip as per the TPC PG mask
268 * already optimized with some TPCs already floorswept 270 * and the fuse_status register.
269 * via fuse. We will not support TPC-PG in those cases. 271 * If TPC PG mask is invalid halt the GPU poweron.
270 */ 272 */
273 g->can_tpc_powergate = false;
274 fuse_status = g->ops.fuse.fuse_status_opt_tpc_gpc(g, 0);
275
276 if (g->ops.tpc.tpc_powergate) {
277 err = g->ops.tpc.tpc_powergate(g, fuse_status);
278 }
271 279
272 if (g->ops.fuse.fuse_status_opt_tpc_gpc(g, 0) != 0x0) { 280 if (err) {
273 g->can_tpc_powergate = false; 281 nvgpu_err(g, "failed to power ON GPU");
274 g->tpc_pg_mask = 0x0; 282 goto done;
275 } 283 }
276 284
277 nvgpu_mutex_acquire(&g->tpc_pg_lock); 285 nvgpu_mutex_acquire(&g->tpc_pg_lock);
diff --git a/drivers/gpu/nvgpu/gm20b/hal_gm20b.c b/drivers/gpu/nvgpu/gm20b/hal_gm20b.c
index 24d13d43..113f6520 100644
--- a/drivers/gpu/nvgpu/gm20b/hal_gm20b.c
+++ b/drivers/gpu/nvgpu/gm20b/hal_gm20b.c
@@ -687,6 +687,9 @@ static const struct gpu_ops gm20b_ops = {
687 .acr = { 687 .acr = {
688 .acr_sw_init = nvgpu_gm20b_acr_sw_init, 688 .acr_sw_init = nvgpu_gm20b_acr_sw_init,
689 }, 689 },
690 .tpc = {
691 .tpc_powergate = NULL,
692 },
690 .chip_init_gpu_characteristics = gk20a_init_gpu_characteristics, 693 .chip_init_gpu_characteristics = gk20a_init_gpu_characteristics,
691 .get_litter_value = gm20b_get_litter_value, 694 .get_litter_value = gm20b_get_litter_value,
692}; 695};
@@ -737,6 +740,8 @@ int gm20b_init_hal(struct gk20a *g)
737 740
738 gops->fuse = gm20b_ops.fuse; 741 gops->fuse = gm20b_ops.fuse;
739 742
743 gops->tpc = gm20b_ops.tpc;
744
740 gops->acr = gm20b_ops.acr; 745 gops->acr = gm20b_ops.acr;
741 746
742 /* Lone functions */ 747 /* Lone functions */
diff --git a/drivers/gpu/nvgpu/gp106/hal_gp106.c b/drivers/gpu/nvgpu/gp106/hal_gp106.c
index 86a133d5..d033a516 100644
--- a/drivers/gpu/nvgpu/gp106/hal_gp106.c
+++ b/drivers/gpu/nvgpu/gp106/hal_gp106.c
@@ -815,6 +815,9 @@ static const struct gpu_ops gp106_ops = {
815 .acr = { 815 .acr = {
816 .acr_sw_init = nvgpu_gp106_acr_sw_init, 816 .acr_sw_init = nvgpu_gp106_acr_sw_init,
817 }, 817 },
818 .tpc = {
819 .tpc_powergate = NULL,
820 },
818 .get_litter_value = gp106_get_litter_value, 821 .get_litter_value = gp106_get_litter_value,
819 .chip_init_gpu_characteristics = gp106_init_gpu_characteristics, 822 .chip_init_gpu_characteristics = gp106_init_gpu_characteristics,
820}; 823};
@@ -870,6 +873,7 @@ int gp106_init_hal(struct gk20a *g)
870 gops->falcon = gp106_ops.falcon; 873 gops->falcon = gp106_ops.falcon;
871 gops->priv_ring = gp106_ops.priv_ring; 874 gops->priv_ring = gp106_ops.priv_ring;
872 gops->fuse = gp106_ops.fuse; 875 gops->fuse = gp106_ops.fuse;
876 gops->tpc = gp106_ops.tpc;
873 gops->acr = gp106_ops.acr; 877 gops->acr = gp106_ops.acr;
874 878
875 /* Lone functions */ 879 /* Lone functions */
diff --git a/drivers/gpu/nvgpu/gv100/hal_gv100.c b/drivers/gpu/nvgpu/gv100/hal_gv100.c
index 457ae64c..6fd777c0 100644
--- a/drivers/gpu/nvgpu/gv100/hal_gv100.c
+++ b/drivers/gpu/nvgpu/gv100/hal_gv100.c
@@ -971,6 +971,9 @@ static const struct gpu_ops gv100_ops = {
971 .acr = { 971 .acr = {
972 .acr_sw_init = nvgpu_gp106_acr_sw_init, 972 .acr_sw_init = nvgpu_gp106_acr_sw_init,
973 }, 973 },
974 .tpc = {
975 .tpc_powergate = NULL,
976 },
974 .chip_init_gpu_characteristics = gv100_init_gpu_characteristics, 977 .chip_init_gpu_characteristics = gv100_init_gpu_characteristics,
975 .get_litter_value = gv100_get_litter_value, 978 .get_litter_value = gv100_get_litter_value,
976}; 979};
@@ -1008,6 +1011,7 @@ int gv100_init_hal(struct gk20a *g)
1008 gops->falcon = gv100_ops.falcon; 1011 gops->falcon = gv100_ops.falcon;
1009 gops->priv_ring = gv100_ops.priv_ring; 1012 gops->priv_ring = gv100_ops.priv_ring;
1010 gops->fuse = gv100_ops.fuse; 1013 gops->fuse = gv100_ops.fuse;
1014 gops->tpc = gv100_ops.tpc;
1011 gops->nvlink = gv100_ops.nvlink; 1015 gops->nvlink = gv100_ops.nvlink;
1012 gops->top = gv100_ops.top; 1016 gops->top = gv100_ops.top;
1013 gops->acr = gv100_ops.acr; 1017 gops->acr = gv100_ops.acr;
diff --git a/drivers/gpu/nvgpu/gv11b/hal_gv11b.c b/drivers/gpu/nvgpu/gv11b/hal_gv11b.c
index 6b4eeb88..2225e380 100644
--- a/drivers/gpu/nvgpu/gv11b/hal_gv11b.c
+++ b/drivers/gpu/nvgpu/gv11b/hal_gv11b.c
@@ -88,6 +88,7 @@
88#include "regops_gv11b.h" 88#include "regops_gv11b.h"
89#include "subctx_gv11b.h" 89#include "subctx_gv11b.h"
90#include "ecc_gv11b.h" 90#include "ecc_gv11b.h"
91#include "tpc_gv11b.h"
91 92
92#include <nvgpu/ptimer.h> 93#include <nvgpu/ptimer.h>
93#include <nvgpu/debug.h> 94#include <nvgpu/debug.h>
@@ -859,6 +860,9 @@ static const struct gpu_ops gv11b_ops = {
859 .acr = { 860 .acr = {
860 .acr_sw_init = nvgpu_gv11b_acr_sw_init, 861 .acr_sw_init = nvgpu_gv11b_acr_sw_init,
861 }, 862 },
863 .tpc = {
864 .tpc_powergate = gv11b_tpc_powergate,
865 },
862 .chip_init_gpu_characteristics = gv11b_init_gpu_characteristics, 866 .chip_init_gpu_characteristics = gv11b_init_gpu_characteristics,
863 .get_litter_value = gv11b_get_litter_value, 867 .get_litter_value = gv11b_get_litter_value,
864}; 868};
@@ -893,6 +897,7 @@ int gv11b_init_hal(struct gk20a *g)
893 gops->falcon = gv11b_ops.falcon; 897 gops->falcon = gv11b_ops.falcon;
894 gops->priv_ring = gv11b_ops.priv_ring; 898 gops->priv_ring = gv11b_ops.priv_ring;
895 gops->fuse = gv11b_ops.fuse; 899 gops->fuse = gv11b_ops.fuse;
900 gops->tpc = gv11b_ops.tpc;
896 gops->clk_arb = gv11b_ops.clk_arb; 901 gops->clk_arb = gv11b_ops.clk_arb;
897 gops->acr = gv11b_ops.acr; 902 gops->acr = gv11b_ops.acr;
898 903
diff --git a/drivers/gpu/nvgpu/gv11b/tpc_gv11b.c b/drivers/gpu/nvgpu/gv11b/tpc_gv11b.c
new file mode 100644
index 00000000..3177870c
--- /dev/null
+++ b/drivers/gpu/nvgpu/gv11b/tpc_gv11b.c
@@ -0,0 +1,70 @@
1/*
2 * GV11B TPC
3 *
4 * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24#include <nvgpu/gk20a.h>
25#include "tpc_gv11b.h"
26
27int gv11b_tpc_powergate(struct gk20a *g, u32 fuse_status)
28{
29 int err = 0;
30
31 if (fuse_status == 0x0) {
32 g->can_tpc_powergate = true;
33
34 } else {
35 /* if hardware has already floorswept any TPC
36 * (fuse_status != 0x0) and if TPC PG mask
37 * sent from userspace is 0x0 GPU will be powered on
38 * with the default fuse_status setting. It cannot
39 * un-floorsweep any TPC
40 * thus, set g->tpc_pg_mask to fuse_status value
41 */
42 if (g->tpc_pg_mask == 0x0) {
43 g->can_tpc_powergate = true;
44 g->tpc_pg_mask = fuse_status;
45
46 } else if (fuse_status == g->tpc_pg_mask) {
47 g->can_tpc_powergate = true;
48
49 } else if ((fuse_status & g->tpc_pg_mask) ==
50 fuse_status) {
51 g->can_tpc_powergate = true;
52
53 } else {
54 /* If userspace sends a TPC PG mask such that
55 * it tries to un-floorsweep any TPC which is
56 * already powergated from hardware, then
57 * such mask is invalid.
58 * In this case set tpc pg mask to 0x0
59 * Return -EINVAL here and halt GPU poweron.
60 */
61 nvgpu_err(g, "Invalid TPC_PG mask: 0x%x",
62 g->tpc_pg_mask);
63 g->can_tpc_powergate = false;
64 g->tpc_pg_mask = 0x0;
65 err = -EINVAL;
66 }
67 }
68
69 return err;
70}
diff --git a/drivers/gpu/nvgpu/gv11b/tpc_gv11b.h b/drivers/gpu/nvgpu/gv11b/tpc_gv11b.h
new file mode 100644
index 00000000..e860c22d
--- /dev/null
+++ b/drivers/gpu/nvgpu/gv11b/tpc_gv11b.h
@@ -0,0 +1,32 @@
1/*
2 * GV11B TPC
3 *
4 * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef NVGPU_TPC_GV11B_H
26#define NVGPU_TPC_GV11B_H
27
28struct gk20a;
29
30int gv11b_tpc_powergate(struct gk20a *g, u32 fuse_status);
31
32#endif /* NVGPU_TPC_GV11B_H */
diff --git a/drivers/gpu/nvgpu/include/nvgpu/gk20a.h b/drivers/gpu/nvgpu/include/nvgpu/gk20a.h
index 7ed4c714..c9002f47 100644
--- a/drivers/gpu/nvgpu/include/nvgpu/gk20a.h
+++ b/drivers/gpu/nvgpu/include/nvgpu/gk20a.h
@@ -149,7 +149,7 @@ enum gk20a_cbc_op {
149 149
150#define nvgpu_get_litter_value(g, v) (g)->ops.get_litter_value((g), v) 150#define nvgpu_get_litter_value(g, v) (g)->ops.get_litter_value((g), v)
151 151
152#define MAX_TPC_PG_CONFIGS 3 152#define MAX_TPC_PG_CONFIGS 9
153 153
154enum nvgpu_unit; 154enum nvgpu_unit;
155 155
@@ -1348,6 +1348,9 @@ struct gpu_ops {
1348 struct { 1348 struct {
1349 void (*acr_sw_init)(struct gk20a *g, struct nvgpu_acr *acr); 1349 void (*acr_sw_init)(struct gk20a *g, struct nvgpu_acr *acr);
1350 } acr; 1350 } acr;
1351 struct {
1352 int (*tpc_powergate)(struct gk20a *g, u32 fuse_status);
1353 } tpc;
1351 void (*semaphore_wakeup)(struct gk20a *g, bool post_events); 1354 void (*semaphore_wakeup)(struct gk20a *g, bool post_events);
1352}; 1355};
1353 1356
@@ -1615,6 +1618,7 @@ struct gk20a {
1615 u32 tpc_fs_mask_user; 1618 u32 tpc_fs_mask_user;
1616 1619
1617 u32 tpc_pg_mask; 1620 u32 tpc_pg_mask;
1621 u32 tpc_count;
1618 bool can_tpc_powergate; 1622 bool can_tpc_powergate;
1619 1623
1620 u32 valid_tpc_mask[MAX_TPC_PG_CONFIGS]; 1624 u32 valid_tpc_mask[MAX_TPC_PG_CONFIGS];
diff --git a/drivers/gpu/nvgpu/os/linux/module.c b/drivers/gpu/nvgpu/os/linux/module.c
index 964fc651..a81d837b 100644
--- a/drivers/gpu/nvgpu/os/linux/module.c
+++ b/drivers/gpu/nvgpu/os/linux/module.c
@@ -1200,7 +1200,8 @@ static int nvgpu_read_fuse_overrides(struct gk20a *g)
1200 break; 1200 break;
1201 case GV11B_FUSE_OPT_TPC_DISABLE: 1201 case GV11B_FUSE_OPT_TPC_DISABLE:
1202 if (platform->set_tpc_pg_mask != NULL) 1202 if (platform->set_tpc_pg_mask != NULL)
1203 platform->set_tpc_pg_mask(dev_from_gk20a(g), value); 1203 platform->set_tpc_pg_mask(dev_from_gk20a(g),
1204 value);
1204 break; 1205 break;
1205 default: 1206 default:
1206 nvgpu_err(g, "ignore unknown fuse override %08x", fuse); 1207 nvgpu_err(g, "ignore unknown fuse override %08x", fuse);
diff --git a/drivers/gpu/nvgpu/os/linux/platform_gk20a.h b/drivers/gpu/nvgpu/os/linux/platform_gk20a.h
index 2ddadd2e..adec8607 100644
--- a/drivers/gpu/nvgpu/os/linux/platform_gk20a.h
+++ b/drivers/gpu/nvgpu/os/linux/platform_gk20a.h
@@ -196,8 +196,8 @@ struct gk20a_platform {
196 /* Pre callback is called before frequency change */ 196 /* Pre callback is called before frequency change */
197 void (*prescale)(struct device *dev); 197 void (*prescale)(struct device *dev);
198 198
199 /* Set TPC_PG during probe */ 199 /* Set TPC_PG_MASK during probe */
200 void (*set_tpc_pg_mask)(struct device *dev, u32 tpc_mask); 200 void (*set_tpc_pg_mask)(struct device *dev, u32 tpc_pg_mask);
201 201
202 /* Devfreq governor name. If scaling is enabled, we request 202 /* Devfreq governor name. If scaling is enabled, we request
203 * this governor to be used in scaling */ 203 * this governor to be used in scaling */
diff --git a/drivers/gpu/nvgpu/os/linux/platform_gv11b_tegra.c b/drivers/gpu/nvgpu/os/linux/platform_gv11b_tegra.c
index 4a94c1cd..ac1958a2 100644
--- a/drivers/gpu/nvgpu/os/linux/platform_gv11b_tegra.c
+++ b/drivers/gpu/nvgpu/os/linux/platform_gv11b_tegra.c
@@ -218,26 +218,29 @@ static int gv11b_tegra_suspend(struct device *dev)
218 return 0; 218 return 0;
219} 219}
220 220
221static bool is_tpc_mask_valid(struct gk20a_platform *platform, u32 tpc_mask) 221static bool is_tpc_mask_valid(struct gk20a_platform *platform, u32 tpc_pg_mask)
222{ 222{
223 u32 i; 223 u32 i;
224 bool valid = false; 224 bool valid = false;
225 225
226 for (i = 0; i < MAX_TPC_PG_CONFIGS; i++) { 226 for (i = 0; i < MAX_TPC_PG_CONFIGS; i++) {
227 if (tpc_mask == platform->valid_tpc_mask[i]) 227 if (tpc_pg_mask == platform->valid_tpc_mask[i]) {
228 valid = true; 228 valid = true;
229 break;
230 }
229 } 231 }
230 return valid; 232 return valid;
231} 233}
232 234
233static void gv11b_tegra_set_tpc_pg_mask(struct device *dev, u32 tpc_mask) 235static void gv11b_tegra_set_tpc_pg_mask(struct device *dev, u32 tpc_pg_mask)
234{ 236{
235 struct gk20a_platform *platform = gk20a_get_platform(dev); 237 struct gk20a_platform *platform = gk20a_get_platform(dev);
236 struct gk20a *g = get_gk20a(dev); 238 struct gk20a *g = get_gk20a(dev);
237 239
238 if (is_tpc_mask_valid(platform, tpc_mask)) { 240 if (is_tpc_mask_valid(platform, tpc_pg_mask)) {
239 g->tpc_pg_mask = tpc_mask; 241 g->tpc_pg_mask = tpc_pg_mask;
240 } 242 }
243
241} 244}
242 245
243struct gk20a_platform gv11b_tegra_platform = { 246struct gk20a_platform gv11b_tegra_platform = {
@@ -257,9 +260,15 @@ struct gk20a_platform gv11b_tegra_platform = {
257 .can_tpc_powergate = true, 260 .can_tpc_powergate = true,
258 .valid_tpc_mask[0] = 0x0, 261 .valid_tpc_mask[0] = 0x0,
259 .valid_tpc_mask[1] = 0x1, 262 .valid_tpc_mask[1] = 0x1,
260 .valid_tpc_mask[2] = 0x5, 263 .valid_tpc_mask[2] = 0x2,
261 264 .valid_tpc_mask[3] = 0x4,
262 .set_tpc_pg_mask = gv11b_tegra_set_tpc_pg_mask, 265 .valid_tpc_mask[4] = 0x8,
266 .valid_tpc_mask[5] = 0x5,
267 .valid_tpc_mask[6] = 0x6,
268 .valid_tpc_mask[7] = 0x9,
269 .valid_tpc_mask[8] = 0xa,
270
271 .set_tpc_pg_mask = gv11b_tegra_set_tpc_pg_mask,
263 272
264 .can_slcg = true, 273 .can_slcg = true,
265 .can_blcg = true, 274 .can_blcg = true,
diff --git a/drivers/gpu/nvgpu/os/linux/sysfs.c b/drivers/gpu/nvgpu/os/linux/sysfs.c
index 759c12e8..2ab29649 100644
--- a/drivers/gpu/nvgpu/os/linux/sysfs.c
+++ b/drivers/gpu/nvgpu/os/linux/sysfs.c
@@ -788,26 +788,28 @@ static ssize_t force_idle_read(struct device *dev,
788static DEVICE_ATTR(force_idle, ROOTRW, force_idle_read, force_idle_store); 788static DEVICE_ATTR(force_idle, ROOTRW, force_idle_read, force_idle_store);
789#endif 789#endif
790 790
791static ssize_t tpc_pg_mask_read(struct device *dev,
792 struct device_attribute *attr, char *buf)
793{
794 struct gk20a *g = get_gk20a(dev);
795
796 return snprintf(buf, PAGE_SIZE, "%d\n", g->tpc_pg_mask);
797}
798
799static bool is_tpc_mask_valid(struct gk20a *g, u32 tpc_mask) 791static bool is_tpc_mask_valid(struct gk20a *g, u32 tpc_mask)
800{ 792{
801 u32 i; 793 u32 i;
802 bool valid = false; 794 bool valid = false;
803 795
804 for (i = 0; i < MAX_TPC_PG_CONFIGS; i++) { 796 for (i = 0; i < MAX_TPC_PG_CONFIGS; i++) {
805 if (tpc_mask == g->valid_tpc_mask[i]) 797 if (tpc_mask == g->valid_tpc_mask[i]) {
806 valid = true; 798 valid = true;
799 break;
800 }
807 } 801 }
808 return valid; 802 return valid;
809} 803}
810 804
805static ssize_t tpc_pg_mask_read(struct device *dev,
806 struct device_attribute *attr, char *buf)
807{
808 struct gk20a *g = get_gk20a(dev);
809
810 return snprintf(buf, PAGE_SIZE, "%d\n", g->tpc_pg_mask);
811}
812
811static ssize_t tpc_pg_mask_store(struct device *dev, 813static ssize_t tpc_pg_mask_store(struct device *dev,
812 struct device_attribute *attr, const char *buf, size_t count) 814 struct device_attribute *attr, const char *buf, size_t count)
813{ 815{
@@ -817,11 +819,6 @@ static ssize_t tpc_pg_mask_store(struct device *dev,
817 819
818 nvgpu_mutex_acquire(&g->tpc_pg_lock); 820 nvgpu_mutex_acquire(&g->tpc_pg_lock);
819 821
820 if (!g->can_tpc_powergate) {
821 nvgpu_info(g, "TPC-PG not enabled for the platform");
822 goto exit;
823 }
824
825 if (kstrtoul(buf, 10, &val) < 0) { 822 if (kstrtoul(buf, 10, &val) < 0) {
826 nvgpu_err(g, "invalid value"); 823 nvgpu_err(g, "invalid value");
827 nvgpu_mutex_release(&g->tpc_pg_lock); 824 nvgpu_mutex_release(&g->tpc_pg_lock);
@@ -839,6 +836,9 @@ static ssize_t tpc_pg_mask_store(struct device *dev,
839 return -ENODEV; 836 return -ENODEV;
840 } 837 }
841 838
839 /* checking that the value from userspace is within
840 * the possible valid TPC configurations.
841 */
842 if (is_tpc_mask_valid(g, (u32)val)) { 842 if (is_tpc_mask_valid(g, (u32)val)) {
843 g->tpc_pg_mask = val; 843 g->tpc_pg_mask = val;
844 } else { 844 } else {