summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/common/power_features/pg/pg.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/common/power_features/pg/pg.c')
-rw-r--r--drivers/gpu/nvgpu/common/power_features/pg/pg.c106
1 files changed, 106 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/common/power_features/pg/pg.c b/drivers/gpu/nvgpu/common/power_features/pg/pg.c
new file mode 100644
index 00000000..fa31f4e3
--- /dev/null
+++ b/drivers/gpu/nvgpu/common/power_features/pg/pg.c
@@ -0,0 +1,106 @@
1/*
2 * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23#include <nvgpu/gk20a.h>
24#include <nvgpu/pmu.h>
25#include <nvgpu/power_features/pg.h>
26
27bool nvgpu_pg_elpg_is_enabled(struct gk20a *g)
28{
29 bool elpg_enabled;
30
31 nvgpu_log_fn(g, " ");
32
33 nvgpu_mutex_acquire(&g->cg_pg_lock);
34 elpg_enabled = g->elpg_enabled;
35 nvgpu_mutex_release(&g->cg_pg_lock);
36 return elpg_enabled;
37}
38
39int nvgpu_pg_elpg_enable(struct gk20a *g)
40{
41 int err = 0;
42
43 nvgpu_log_fn(g, " ");
44
45 if (!g->can_elpg) {
46 return 0;
47 }
48
49 nvgpu_mutex_acquire(&g->cg_pg_lock);
50 if (g->elpg_enabled) {
51 err = nvgpu_pmu_pg_global_enable(g, true);
52 }
53 nvgpu_mutex_release(&g->cg_pg_lock);
54 return err;
55}
56
57int nvgpu_pg_elpg_disable(struct gk20a *g)
58{
59 int err = 0;
60
61 nvgpu_log_fn(g, " ");
62
63 if (!g->can_elpg) {
64 return 0;
65 }
66
67 nvgpu_mutex_acquire(&g->cg_pg_lock);
68 if (g->elpg_enabled) {
69 err = nvgpu_pmu_pg_global_enable(g, false);
70 }
71 nvgpu_mutex_release(&g->cg_pg_lock);
72 return err;
73}
74
75int nvgpu_pg_elpg_set_elpg_enabled(struct gk20a *g, bool enable)
76{
77 int err = 0;
78 bool change_mode = false;
79
80 nvgpu_log_fn(g, " ");
81
82 if (!g->can_elpg) {
83 return 0;
84 }
85
86 nvgpu_mutex_acquire(&g->cg_pg_lock);
87 if (enable) {
88 if (!g->elpg_enabled) {
89 change_mode = true;
90 g->elpg_enabled = true;
91 }
92 } else {
93 if (g->elpg_enabled) {
94 change_mode = true;
95 g->elpg_enabled = false;
96 }
97 }
98 if (!change_mode) {
99 goto done;
100 }
101
102 err = nvgpu_pmu_pg_global_enable(g, enable);
103done:
104 nvgpu_mutex_release(&g->cg_pg_lock);
105 return err;
106}