summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/lpwr/lpwr.c
diff options
context:
space:
mode:
authorMahantesh Kumbar <mkumbar@nvidia.com>2016-11-03 11:46:21 -0400
committerDeepak Nibade <dnibade@nvidia.com>2016-12-27 04:56:53 -0500
commite5824d8014c321fbe2c1e04e12307125dd50a472 (patch)
tree82657cd43c0dcd313b3251f3776e5e80b488fabc /drivers/gpu/nvgpu/lpwr/lpwr.c
parent62d13e613807e9bce3a9d1ef0c61725ef3a885ce (diff)
gpu: nvgpu: MSCG support
- update gp106 pg engine init/list/features HALs to support MS engine - Added defines & interface for lpwr tables read from vbios. - lpwr module which reads idx/gr/ms table from vbios to map rppg/mscg support with respective p-state - lpwr module public functions to control lpwr features enable/disable mscg/rppg & mclk-change request whenever change in mclk-change parameters - lpwr public functions to know rppg/mscg support for requested pstate, - added mutex t prevent PG transition while arbiter executes pstate transition - nvgpu_clk_arb_get_current_pstate() of clk arbiter to get current pstate JIRA DNVGPU-71 Change-Id: Ifcd640cc19ef630be1e2a9ba07ec84023d8202a0 Signed-off-by: Mahantesh Kumbar <mkumbar@nvidia.com> Reviewed-on: http://git-master/r/1247553 (cherry picked from commit 8a441dea2410e1b5196ef24e56a7768b6980e46b) Reviewed-on: http://git-master/r/1270989 Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/lpwr/lpwr.c')
-rw-r--r--drivers/gpu/nvgpu/lpwr/lpwr.c423
1 files changed, 423 insertions, 0 deletions
diff --git a/drivers/gpu/nvgpu/lpwr/lpwr.c b/drivers/gpu/nvgpu/lpwr/lpwr.c
new file mode 100644
index 00000000..4f8d2eec
--- /dev/null
+++ b/drivers/gpu/nvgpu/lpwr/lpwr.c
@@ -0,0 +1,423 @@
1/*
2 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 */
13
14#include "gk20a/gk20a.h"
15#include "gk20a/pmu_gk20a.h"
16#include "gp106/pmu_gp106.h"
17#include "gk20a/pmu_api.h"
18#include "gm206/bios_gm206.h"
19#include "pstate/pstate.h"
20#include "include/bios.h"
21#include "perf/perf.h"
22#include "lpwr.h"
23
24static int get_lpwr_idx_table(struct gk20a *g)
25{
26 u32 *lpwr_idx_table_ptr;
27 u8 *entry_addr;
28 u32 idx;
29 struct nvgpu_lpwr_bios_idx_data *pidx_data =
30 &g->perf_pmu.lpwr.lwpr_bios_data.idx;
31 struct nvgpu_bios_lpwr_idx_table_1x_header header = { 0 };
32 struct nvgpu_bios_lpwr_idx_table_1x_entry entry = { 0 };
33
34 if (g->ops.bios.get_perf_table_ptrs) {
35 lpwr_idx_table_ptr = (u32 *)g->ops.bios.get_perf_table_ptrs(g,
36 g->bios.perf_token, LOWPOWER_TABLE);
37 if (lpwr_idx_table_ptr == NULL)
38 return -EINVAL;
39 } else
40 return -EINVAL;
41
42 memcpy(&header, lpwr_idx_table_ptr,
43 sizeof(struct nvgpu_bios_lpwr_idx_table_1x_header));
44
45 if (header.entry_count >= LPWR_VBIOS_IDX_ENTRY_COUNT_MAX)
46 return -EINVAL;
47
48 pidx_data->base_sampling_period = (u16)header.base_sampling_period;
49
50 /* Parse the LPWR Index Table entries.*/
51 for (idx = 0; idx < header.entry_count; idx++) {
52 entry_addr = (u8 *)lpwr_idx_table_ptr + header.header_size +
53 (idx * header.entry_size);
54
55 memcpy(&entry, entry_addr,
56 sizeof(struct nvgpu_bios_lpwr_idx_table_1x_entry));
57
58 pidx_data->entry[idx].pcie_idx = entry.pcie_idx;
59 pidx_data->entry[idx].gr_idx = entry.gr_idx;
60 pidx_data->entry[idx].ms_idx = entry.ms_idx;
61 pidx_data->entry[idx].di_idx = entry.di_idx;
62 pidx_data->entry[idx].gc6_idx = entry.gc6_idx;
63
64 }
65
66 return 0;
67}
68
69static int get_lpwr_gr_table(struct gk20a *g)
70{
71 u32 *lpwr_gr_table_ptr;
72 u8 *entry_addr;
73 u32 idx;
74 struct nvgpu_lpwr_bios_gr_data *pgr_data =
75 &g->perf_pmu.lpwr.lwpr_bios_data.gr;
76 struct nvgpu_bios_lpwr_gr_table_1x_header header = { 0 };
77 struct nvgpu_bios_lpwr_gr_table_1x_entry entry = { 0 };
78
79 if (g->ops.bios.get_perf_table_ptrs) {
80 lpwr_gr_table_ptr = (u32 *)g->ops.bios.get_perf_table_ptrs(g,
81 g->bios.perf_token, LOWPOWER_GR_TABLE);
82 if (lpwr_gr_table_ptr == NULL)
83 return -EINVAL;
84 } else
85 return -EINVAL;
86
87 memcpy(&header, lpwr_gr_table_ptr,
88 sizeof(struct nvgpu_bios_lpwr_gr_table_1x_header));
89
90 /* Parse the LPWR Index Table entries.*/
91 for (idx = 0; idx < header.entry_count; idx++) {
92 entry_addr = (u8 *)lpwr_gr_table_ptr + header.header_size +
93 (idx * header.entry_size);
94
95 memcpy(&entry, entry_addr,
96 sizeof(struct nvgpu_bios_lpwr_gr_table_1x_entry));
97
98 if (BIOS_GET_FIELD(entry.feautre_mask,
99 NV_VBIOS_LPWR_MS_FEATURE_MASK_MS)) {
100 pgr_data->entry[idx].gr_enabled = true;
101
102 pgr_data->entry[idx].feature_mask =
103 NVGPU_PMU_GR_FEATURE_MASK_ALL;
104
105 if (!BIOS_GET_FIELD(entry.feautre_mask,
106 NV_VBIOS_LPWR_GR_FEATURE_MASK_GR_RPPG))
107 pgr_data->entry[idx].feature_mask &=
108 ~NVGPU_PMU_GR_FEATURE_MASK_RPPG;
109 }
110
111 }
112
113 return 0;
114}
115
116static int get_lpwr_ms_table(struct gk20a *g)
117{
118 u32 *lpwr_ms_table_ptr;
119 u8 *entry_addr;
120 u32 idx;
121 struct nvgpu_lpwr_bios_ms_data *pms_data =
122 &g->perf_pmu.lpwr.lwpr_bios_data.ms;
123 struct nvgpu_bios_lpwr_ms_table_1x_header header = { 0 };
124 struct nvgpu_bios_lpwr_ms_table_1x_entry entry = { 0 };
125
126 if (g->ops.bios.get_perf_table_ptrs) {
127 lpwr_ms_table_ptr = (u32 *)g->ops.bios.get_perf_table_ptrs(g,
128 g->bios.perf_token, LOWPOWER_MS_TABLE);
129 if (lpwr_ms_table_ptr == NULL)
130 return -EINVAL;
131 } else
132 return -EINVAL;
133
134 memcpy(&header, lpwr_ms_table_ptr,
135 sizeof(struct nvgpu_bios_lpwr_ms_table_1x_header));
136
137 if (header.entry_count >= LPWR_VBIOS_MS_ENTRY_COUNT_MAX)
138 return -EINVAL;
139
140 pms_data->default_entry_idx = (u8)header.default_entry_idx;
141
142 pms_data->idle_threshold_us = (u32)(header.idle_threshold_us * 10);
143
144 /* Parse the LPWR MS Table entries.*/
145 for (idx = 0; idx < header.entry_count; idx++) {
146 entry_addr = (u8 *)lpwr_ms_table_ptr + header.header_size +
147 (idx * header.entry_size);
148
149 memcpy(&entry, entry_addr,
150 sizeof(struct nvgpu_bios_lpwr_ms_table_1x_entry));
151
152 if (BIOS_GET_FIELD(entry.feautre_mask,
153 NV_VBIOS_LPWR_MS_FEATURE_MASK_MS)) {
154 pms_data->entry[idx].ms_enabled = true;
155
156 pms_data->entry[idx].feature_mask =
157 NVGPU_PMU_MS_FEATURE_MASK_ALL;
158
159 if (!BIOS_GET_FIELD(entry.feautre_mask,
160 NV_VBIOS_LPWR_MS_FEATURE_MASK_MS_CLOCK_GATING))
161 pms_data->entry[idx].feature_mask &=
162 ~NVGPU_PMU_MS_FEATURE_MASK_CLOCK_GATING;
163
164 if (!BIOS_GET_FIELD(entry.feautre_mask,
165 NV_VBIOS_LPWR_MS_FEATURE_MASK_MS_SWASR))
166 pms_data->entry[idx].feature_mask &=
167 ~NVGPU_PMU_MS_FEATURE_MASK_SW_ASR;
168
169 if (!BIOS_GET_FIELD(entry.feautre_mask,
170 NV_VBIOS_LPWR_MS_FEATURE_MASK_MS_RPPG))
171 pms_data->entry[idx].feature_mask &=
172 ~NVGPU_PMU_MS_FEATURE_MASK_RPPG;
173 }
174
175 pms_data->entry[idx].dynamic_current_logic =
176 entry.dynamic_current_logic;
177
178 pms_data->entry[idx].dynamic_current_sram =
179 entry.dynamic_current_sram;
180 }
181
182 return 0;
183}
184
185u32 nvgpu_lpwr_pg_setup(struct gk20a *g)
186{
187 u32 err = 0;
188
189 gk20a_dbg_fn("");
190
191 err = get_lpwr_gr_table(g);
192 if (err)
193 return err;
194
195 err = get_lpwr_ms_table(g);
196 if (err)
197 return err;
198
199 err = get_lpwr_idx_table(g);
200
201 return err;
202}
203
204static void nvgpu_pmu_handle_param_lpwr_msg(struct gk20a *g,
205 struct pmu_msg *msg, void *param,
206 u32 handle, u32 status)
207{
208 u32 *ack_status = param;
209
210 gk20a_dbg_fn("");
211
212 if (status != 0) {
213 gk20a_err(dev_from_gk20a(g), "LWPR PARAM cmd aborted");
214 return;
215 }
216
217 *ack_status = 1;
218
219 gp106_dbg_pmu("lpwr-param is acknowledged from PMU %x",
220 msg->msg.pg.msg_type);
221}
222
223int nvgpu_lwpr_mclk_change(struct gk20a *g, u32 pstate)
224{
225 struct pmu_cmd cmd;
226 u32 seq, status = 0;
227 u32 payload = NV_PMU_PG_PARAM_MCLK_CHANGE_MS_SWASR_ENABLED;
228 struct clk_set_info *pstate_info;
229 u32 ack_status = 0;
230
231 gk20a_dbg_fn("");
232
233 pstate_info = pstate_get_clk_set_info(g, pstate,
234 clkwhich_mclk);
235 if (!pstate_info)
236 return -EINVAL;
237
238 if (pstate_info->max_mhz >
239 MAX_SWASR_MCLK_FREQ_WITHOUT_WR_TRAINING_MAXWELL_MHZ)
240 payload |=
241 NV_PMU_PG_PARAM_MCLK_CHANGE_GDDR5_WR_TRAINING_ENABLED;
242
243 if (payload != g->perf_pmu.lpwr.mclk_change_cache) {
244 g->perf_pmu.lpwr.mclk_change_cache = payload;
245
246 cmd.hdr.unit_id = PMU_UNIT_PG;
247 cmd.hdr.size = PMU_CMD_HDR_SIZE +
248 sizeof(struct pmu_pg_cmd_mclk_change);
249 cmd.cmd.pg.mclk_change.cmd_type =
250 PMU_PG_CMD_ID_PG_PARAM;
251 cmd.cmd.pg.mclk_change.cmd_id =
252 PMU_PG_PARAM_CMD_MCLK_CHANGE;
253 cmd.cmd.pg.mclk_change.data = payload;
254
255 gp106_dbg_pmu("cmd post MS PMU_PG_PARAM_CMD_MCLK_CHANGE");
256 status = gk20a_pmu_cmd_post(g, &cmd, NULL, NULL,
257 PMU_COMMAND_QUEUE_HPQ,
258 nvgpu_pmu_handle_param_lpwr_msg, &ack_status, &seq, ~0);
259
260 pmu_wait_message_cond(&g->pmu, gk20a_get_gr_idle_timeout(g),
261 &ack_status, 1);
262 if (ack_status == 0) {
263 status = -EINVAL;
264 gk20a_err(dev_from_gk20a(g), "MCLK-CHANGE ACK failed");
265 }
266 }
267
268 return status;
269}
270
271u32 nvgpu_lpwr_post_init(struct gk20a *g)
272{
273 struct pmu_cmd cmd;
274 u32 seq;
275 u32 status = 0;
276 u32 ack_status = 0;
277
278 memset(&cmd, 0, sizeof(struct pmu_cmd));
279 cmd.hdr.unit_id = PMU_UNIT_PG;
280 cmd.hdr.size = PMU_CMD_HDR_SIZE +
281 sizeof(struct pmu_pg_cmd_post_init_param);
282
283 cmd.cmd.pg.post_init.cmd_type =
284 PMU_PG_CMD_ID_PG_PARAM;
285 cmd.cmd.pg.post_init.cmd_id =
286 PMU_PG_PARAM_CMD_POST_INIT;
287
288 gp106_dbg_pmu("cmd post post-init PMU_PG_PARAM_CMD_POST_INIT");
289 status = gk20a_pmu_cmd_post(g, &cmd, NULL, NULL,
290 PMU_COMMAND_QUEUE_LPQ,
291 nvgpu_pmu_handle_param_lpwr_msg, &ack_status, &seq, ~0);
292
293 pmu_wait_message_cond(&g->pmu, gk20a_get_gr_idle_timeout(g),
294 &ack_status, 1);
295 if (ack_status == 0) {
296 status = -EINVAL;
297 gk20a_err(dev_from_gk20a(g), "post-init ack failed");
298 }
299
300 return status;
301}
302
303u32 nvgpu_lpwr_is_mscg_supported(struct gk20a *g, u32 pstate_num)
304{
305 struct nvgpu_lpwr_bios_ms_data *pms_data =
306 &g->perf_pmu.lpwr.lwpr_bios_data.ms;
307 struct nvgpu_lpwr_bios_idx_data *pidx_data =
308 &g->perf_pmu.lpwr.lwpr_bios_data.idx;
309 struct pstate *pstate = pstate_find(g, pstate_num);
310 u32 ms_idx;
311
312 gk20a_dbg_fn("");
313
314 if (!pstate)
315 return 0;
316
317 ms_idx = pidx_data->entry[pstate->lpwr_entry_idx].ms_idx;
318 if (pms_data->entry[ms_idx].ms_enabled)
319 return 1;
320 else
321 return 0;
322}
323
324u32 nvgpu_lpwr_is_rppg_supported(struct gk20a *g, u32 pstate_num)
325{
326 struct nvgpu_lpwr_bios_gr_data *pgr_data =
327 &g->perf_pmu.lpwr.lwpr_bios_data.gr;
328 struct nvgpu_lpwr_bios_idx_data *pidx_data =
329 &g->perf_pmu.lpwr.lwpr_bios_data.idx;
330 struct pstate *pstate = pstate_find(g, pstate_num);
331 u32 idx;
332
333 gk20a_dbg_fn("");
334
335 if (!pstate)
336 return 0;
337
338 idx = pidx_data->entry[pstate->lpwr_entry_idx].gr_idx;
339 if (pgr_data->entry[idx].gr_enabled)
340 return 1;
341 else
342 return 0;
343}
344
345
346int nvgpu_lpwr_enable_pg(struct gk20a *g, bool pstate_lock)
347{
348 struct pmu_gk20a *pmu = &g->pmu;
349 u32 status = 0;
350 u32 is_mscg_supported = 0;
351 u32 is_rppg_supported = 0;
352 u32 present_pstate = 0;
353
354 gk20a_dbg_fn("");
355
356 if (pstate_lock)
357 nvgpu_clk_arb_pstate_change_lock(g, true);
358 mutex_lock(&pmu->pg_mutex);
359
360 present_pstate = nvgpu_clk_arb_get_current_pstate(g);
361
362 is_mscg_supported = nvgpu_lpwr_is_mscg_supported(g,
363 present_pstate);
364 if (is_mscg_supported && g->mscg_enabled) {
365 if (!pmu->mscg_stat)
366 pmu->mscg_stat = PMU_MSCG_ENABLED;
367 }
368
369 is_rppg_supported = nvgpu_lpwr_is_rppg_supported(g,
370 present_pstate);
371 if (is_rppg_supported) {
372 if (support_gk20a_pmu(g->dev) && g->elpg_enabled)
373 status = gk20a_pmu_enable_elpg(g);
374 }
375
376 mutex_unlock(&pmu->pg_mutex);
377 if (pstate_lock)
378 nvgpu_clk_arb_pstate_change_lock(g, false);
379
380 return status;
381}
382
383int nvgpu_lpwr_disable_pg(struct gk20a *g, bool pstate_lock)
384{
385 struct pmu_gk20a *pmu = &g->pmu;
386 int status = 0;
387 u32 is_mscg_supported = 0;
388 u32 is_rppg_supported = 0;
389 u32 present_pstate = 0;
390
391 gk20a_dbg_fn("");
392
393 if (pstate_lock)
394 nvgpu_clk_arb_pstate_change_lock(g, true);
395 mutex_lock(&pmu->pg_mutex);
396
397 present_pstate = nvgpu_clk_arb_get_current_pstate(g);
398
399 is_rppg_supported = nvgpu_lpwr_is_rppg_supported(g,
400 present_pstate);
401 if (is_rppg_supported) {
402 if (support_gk20a_pmu(g->dev) && g->elpg_enabled) {
403 status = gk20a_pmu_disable_elpg(g);
404 if (status)
405 goto exit_unlock;
406 }
407 }
408
409 is_mscg_supported = nvgpu_lpwr_is_mscg_supported(g,
410 present_pstate);
411 if (is_mscg_supported && g->mscg_enabled) {
412 if (pmu->mscg_stat)
413 pmu->mscg_stat = PMU_MSCG_DISABLED;
414 }
415
416exit_unlock:
417 mutex_unlock(&pmu->pg_mutex);
418 if (pstate_lock)
419 nvgpu_clk_arb_pstate_change_lock(g, false);
420
421 gk20a_dbg_fn("done");
422 return status;
423}