summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/pmgr/pmgr.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/pmgr/pmgr.c')
-rw-r--r--drivers/gpu/nvgpu/pmgr/pmgr.c184
1 files changed, 184 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/pmgr/pmgr.c b/drivers/gpu/nvgpu/pmgr/pmgr.c
new file mode 100644
index 00000000..2a9f9673
--- /dev/null
+++ b/drivers/gpu/nvgpu/pmgr/pmgr.c
@@ -0,0 +1,184 @@
1/*
2 * Copyright (c) 2016-2017, 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 "gk20a/gk20a.h"
24#include "pwrdev.h"
25#include "pmgrpmu.h"
26
27#ifdef CONFIG_DEBUG_FS
28#include <linux/debugfs.h>
29#include "common/linux/os_linux.h"
30#endif
31
32int pmgr_pwr_devices_get_power(struct gk20a *g, u32 *val)
33{
34 struct nv_pmu_pmgr_pwr_devices_query_payload payload;
35 int status;
36
37 status = pmgr_pmu_pwr_devices_query_blocking(g, 1, &payload);
38 if (status)
39 nvgpu_err(g, "pmgr_pwr_devices_get_current_power failed %x",
40 status);
41
42 *val = payload.devices[0].powerm_w;
43
44 return status;
45}
46
47int pmgr_pwr_devices_get_current(struct gk20a *g, u32 *val)
48{
49 struct nv_pmu_pmgr_pwr_devices_query_payload payload;
50 int status;
51
52 status = pmgr_pmu_pwr_devices_query_blocking(g, 1, &payload);
53 if (status)
54 nvgpu_err(g, "pmgr_pwr_devices_get_current failed %x",
55 status);
56
57 *val = payload.devices[0].currentm_a;
58
59 return status;
60}
61
62int pmgr_pwr_devices_get_voltage(struct gk20a *g, u32 *val)
63{
64 struct nv_pmu_pmgr_pwr_devices_query_payload payload;
65 int status;
66
67 status = pmgr_pmu_pwr_devices_query_blocking(g, 1, &payload);
68 if (status)
69 nvgpu_err(g, "pmgr_pwr_devices_get_current_voltage failed %x",
70 status);
71
72 *val = payload.devices[0].voltageu_v;
73
74 return status;
75}
76
77#ifdef CONFIG_DEBUG_FS
78static int pmgr_pwr_devices_get_power_u64(void *data, u64 *p)
79{
80 struct gk20a *g = (struct gk20a *)data;
81 int err;
82 u32 val;
83
84 err = pmgr_pwr_devices_get_power(g, &val);
85 *p = val;
86
87 return err;
88}
89
90static int pmgr_pwr_devices_get_current_u64(void *data, u64 *p)
91{
92 struct gk20a *g = (struct gk20a *)data;
93 int err;
94 u32 val;
95
96 err = pmgr_pwr_devices_get_current(g, &val);
97 *p = val;
98
99 return err;
100}
101
102static int pmgr_pwr_devices_get_voltage_u64(void *data, u64 *p)
103{
104 struct gk20a *g = (struct gk20a *)data;
105 int err;
106 u32 val;
107
108 err = pmgr_pwr_devices_get_voltage(g, &val);
109 *p = val;
110
111 return err;
112}
113
114DEFINE_SIMPLE_ATTRIBUTE(
115 pmgr_power_ctrl_fops, pmgr_pwr_devices_get_power_u64, NULL, "%llu\n");
116
117DEFINE_SIMPLE_ATTRIBUTE(
118 pmgr_current_ctrl_fops, pmgr_pwr_devices_get_current_u64, NULL, "%llu\n");
119
120DEFINE_SIMPLE_ATTRIBUTE(
121 pmgr_voltage_ctrl_fops, pmgr_pwr_devices_get_voltage_u64, NULL, "%llu\n");
122
123static void pmgr_debugfs_init(struct gk20a *g)
124{
125 struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g);
126 struct dentry *dbgentry;
127
128 dbgentry = debugfs_create_file(
129 "power", S_IRUGO, l->debugfs, g, &pmgr_power_ctrl_fops);
130 if (!dbgentry)
131 nvgpu_err(g, "debugfs entry create failed for power");
132
133 dbgentry = debugfs_create_file(
134 "current", S_IRUGO, l->debugfs, g, &pmgr_current_ctrl_fops);
135 if (!dbgentry)
136 nvgpu_err(g, "debugfs entry create failed for current");
137
138 dbgentry = debugfs_create_file(
139 "voltage", S_IRUGO, l->debugfs, g, &pmgr_voltage_ctrl_fops);
140 if (!dbgentry)
141 nvgpu_err(g, "debugfs entry create failed for voltage");
142}
143#endif
144
145u32 pmgr_domain_sw_setup(struct gk20a *g)
146{
147 u32 status;
148
149 status = pmgr_device_sw_setup(g);
150 if (status) {
151 nvgpu_err(g,
152 "error creating boardobjgrp for pmgr devices, status - 0x%x",
153 status);
154 goto exit;
155 }
156
157 status = pmgr_monitor_sw_setup(g);
158 if (status) {
159 nvgpu_err(g,
160 "error creating boardobjgrp for pmgr monitor, status - 0x%x",
161 status);
162 goto exit;
163 }
164
165 status = pmgr_policy_sw_setup(g);
166 if (status) {
167 nvgpu_err(g,
168 "error creating boardobjgrp for pmgr policy, status - 0x%x",
169 status);
170 goto exit;
171 }
172
173#ifdef CONFIG_DEBUG_FS
174 pmgr_debugfs_init(g);
175#endif
176
177exit:
178 return status;
179}
180
181u32 pmgr_domain_pmu_setup(struct gk20a *g)
182{
183 return pmgr_send_pmgr_tables_to_pmu(g);
184}