xref: /openbmc/linux/drivers/gpu/drm/radeon/kv_dpm.c (revision afb46f79)
1 /*
2  * Copyright 2013 Advanced Micro Devices, Inc.
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 COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23 
24 #include "drmP.h"
25 #include "radeon.h"
26 #include "cikd.h"
27 #include "r600_dpm.h"
28 #include "kv_dpm.h"
29 #include "radeon_asic.h"
30 #include <linux/seq_file.h>
31 
32 #define KV_MAX_DEEPSLEEP_DIVIDER_ID     5
33 #define KV_MINIMUM_ENGINE_CLOCK         800
34 #define SMC_RAM_END                     0x40000
35 
36 static void kv_init_graphics_levels(struct radeon_device *rdev);
37 static int kv_calculate_ds_divider(struct radeon_device *rdev);
38 static int kv_calculate_nbps_level_settings(struct radeon_device *rdev);
39 static int kv_calculate_dpm_settings(struct radeon_device *rdev);
40 static void kv_enable_new_levels(struct radeon_device *rdev);
41 static void kv_program_nbps_index_settings(struct radeon_device *rdev,
42 					   struct radeon_ps *new_rps);
43 static int kv_set_enabled_level(struct radeon_device *rdev, u32 level);
44 static int kv_set_enabled_levels(struct radeon_device *rdev);
45 static int kv_force_dpm_highest(struct radeon_device *rdev);
46 static int kv_force_dpm_lowest(struct radeon_device *rdev);
47 static void kv_apply_state_adjust_rules(struct radeon_device *rdev,
48 					struct radeon_ps *new_rps,
49 					struct radeon_ps *old_rps);
50 static int kv_set_thermal_temperature_range(struct radeon_device *rdev,
51 					    int min_temp, int max_temp);
52 static int kv_init_fps_limits(struct radeon_device *rdev);
53 
54 void kv_dpm_powergate_uvd(struct radeon_device *rdev, bool gate);
55 static void kv_dpm_powergate_vce(struct radeon_device *rdev, bool gate);
56 static void kv_dpm_powergate_samu(struct radeon_device *rdev, bool gate);
57 static void kv_dpm_powergate_acp(struct radeon_device *rdev, bool gate);
58 
59 extern void cik_enter_rlc_safe_mode(struct radeon_device *rdev);
60 extern void cik_exit_rlc_safe_mode(struct radeon_device *rdev);
61 extern void cik_update_cg(struct radeon_device *rdev,
62 			  u32 block, bool enable);
63 
64 static const struct kv_lcac_config_values sx_local_cac_cfg_kv[] =
65 {
66 	{  0,       4,        1    },
67 	{  1,       4,        1    },
68 	{  2,       5,        1    },
69 	{  3,       4,        2    },
70 	{  4,       1,        1    },
71 	{  5,       5,        2    },
72 	{  6,       6,        1    },
73 	{  7,       9,        2    },
74 	{ 0xffffffff }
75 };
76 
77 static const struct kv_lcac_config_values mc0_local_cac_cfg_kv[] =
78 {
79 	{  0,       4,        1    },
80 	{ 0xffffffff }
81 };
82 
83 static const struct kv_lcac_config_values mc1_local_cac_cfg_kv[] =
84 {
85 	{  0,       4,        1    },
86 	{ 0xffffffff }
87 };
88 
89 static const struct kv_lcac_config_values mc2_local_cac_cfg_kv[] =
90 {
91 	{  0,       4,        1    },
92 	{ 0xffffffff }
93 };
94 
95 static const struct kv_lcac_config_values mc3_local_cac_cfg_kv[] =
96 {
97 	{  0,       4,        1    },
98 	{ 0xffffffff }
99 };
100 
101 static const struct kv_lcac_config_values cpl_local_cac_cfg_kv[] =
102 {
103 	{  0,       4,        1    },
104 	{  1,       4,        1    },
105 	{  2,       5,        1    },
106 	{  3,       4,        1    },
107 	{  4,       1,        1    },
108 	{  5,       5,        1    },
109 	{  6,       6,        1    },
110 	{  7,       9,        1    },
111 	{  8,       4,        1    },
112 	{  9,       2,        1    },
113 	{  10,      3,        1    },
114 	{  11,      6,        1    },
115 	{  12,      8,        2    },
116 	{  13,      1,        1    },
117 	{  14,      2,        1    },
118 	{  15,      3,        1    },
119 	{  16,      1,        1    },
120 	{  17,      4,        1    },
121 	{  18,      3,        1    },
122 	{  19,      1,        1    },
123 	{  20,      8,        1    },
124 	{  21,      5,        1    },
125 	{  22,      1,        1    },
126 	{  23,      1,        1    },
127 	{  24,      4,        1    },
128 	{  27,      6,        1    },
129 	{  28,      1,        1    },
130 	{ 0xffffffff }
131 };
132 
133 static const struct kv_lcac_config_reg sx0_cac_config_reg[] =
134 {
135 	{ 0xc0400d00, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
136 };
137 
138 static const struct kv_lcac_config_reg mc0_cac_config_reg[] =
139 {
140 	{ 0xc0400d30, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
141 };
142 
143 static const struct kv_lcac_config_reg mc1_cac_config_reg[] =
144 {
145 	{ 0xc0400d3c, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
146 };
147 
148 static const struct kv_lcac_config_reg mc2_cac_config_reg[] =
149 {
150 	{ 0xc0400d48, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
151 };
152 
153 static const struct kv_lcac_config_reg mc3_cac_config_reg[] =
154 {
155 	{ 0xc0400d54, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
156 };
157 
158 static const struct kv_lcac_config_reg cpl_cac_config_reg[] =
159 {
160 	{ 0xc0400d80, 0x003e0000, 17, 0x3fc00000, 22, 0x0001fffe, 1, 0x00000001, 0 }
161 };
162 
163 static const struct kv_pt_config_reg didt_config_kv[] =
164 {
165 	{ 0x10, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
166 	{ 0x10, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
167 	{ 0x10, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
168 	{ 0x10, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
169 	{ 0x11, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
170 	{ 0x11, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
171 	{ 0x11, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
172 	{ 0x11, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
173 	{ 0x12, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
174 	{ 0x12, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
175 	{ 0x12, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
176 	{ 0x12, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
177 	{ 0x2, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND },
178 	{ 0x2, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND },
179 	{ 0x2, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND },
180 	{ 0x1, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND },
181 	{ 0x1, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND },
182 	{ 0x0, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND },
183 	{ 0x30, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
184 	{ 0x30, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
185 	{ 0x30, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
186 	{ 0x30, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
187 	{ 0x31, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
188 	{ 0x31, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
189 	{ 0x31, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
190 	{ 0x31, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
191 	{ 0x32, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
192 	{ 0x32, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
193 	{ 0x32, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
194 	{ 0x32, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
195 	{ 0x22, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND },
196 	{ 0x22, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND },
197 	{ 0x22, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND },
198 	{ 0x21, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND },
199 	{ 0x21, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND },
200 	{ 0x20, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND },
201 	{ 0x50, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
202 	{ 0x50, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
203 	{ 0x50, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
204 	{ 0x50, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
205 	{ 0x51, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
206 	{ 0x51, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
207 	{ 0x51, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
208 	{ 0x51, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
209 	{ 0x52, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
210 	{ 0x52, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
211 	{ 0x52, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
212 	{ 0x52, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
213 	{ 0x42, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND },
214 	{ 0x42, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND },
215 	{ 0x42, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND },
216 	{ 0x41, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND },
217 	{ 0x41, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND },
218 	{ 0x40, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND },
219 	{ 0x70, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
220 	{ 0x70, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
221 	{ 0x70, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
222 	{ 0x70, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
223 	{ 0x71, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
224 	{ 0x71, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
225 	{ 0x71, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
226 	{ 0x71, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
227 	{ 0x72, 0x000000ff, 0, 0x0, KV_CONFIGREG_DIDT_IND },
228 	{ 0x72, 0x0000ff00, 8, 0x0, KV_CONFIGREG_DIDT_IND },
229 	{ 0x72, 0x00ff0000, 16, 0x0, KV_CONFIGREG_DIDT_IND },
230 	{ 0x72, 0xff000000, 24, 0x0, KV_CONFIGREG_DIDT_IND },
231 	{ 0x62, 0x00003fff, 0, 0x4, KV_CONFIGREG_DIDT_IND },
232 	{ 0x62, 0x03ff0000, 16, 0x80, KV_CONFIGREG_DIDT_IND },
233 	{ 0x62, 0x78000000, 27, 0x3, KV_CONFIGREG_DIDT_IND },
234 	{ 0x61, 0x0000ffff, 0, 0x3FFF, KV_CONFIGREG_DIDT_IND },
235 	{ 0x61, 0xffff0000, 16, 0x3FFF, KV_CONFIGREG_DIDT_IND },
236 	{ 0x60, 0x00000001, 0, 0x0, KV_CONFIGREG_DIDT_IND },
237 	{ 0xFFFFFFFF }
238 };
239 
240 static struct kv_ps *kv_get_ps(struct radeon_ps *rps)
241 {
242 	struct kv_ps *ps = rps->ps_priv;
243 
244 	return ps;
245 }
246 
247 static struct kv_power_info *kv_get_pi(struct radeon_device *rdev)
248 {
249 	struct kv_power_info *pi = rdev->pm.dpm.priv;
250 
251 	return pi;
252 }
253 
254 #if 0
255 static void kv_program_local_cac_table(struct radeon_device *rdev,
256 				       const struct kv_lcac_config_values *local_cac_table,
257 				       const struct kv_lcac_config_reg *local_cac_reg)
258 {
259 	u32 i, count, data;
260 	const struct kv_lcac_config_values *values = local_cac_table;
261 
262 	while (values->block_id != 0xffffffff) {
263 		count = values->signal_id;
264 		for (i = 0; i < count; i++) {
265 			data = ((values->block_id << local_cac_reg->block_shift) &
266 				local_cac_reg->block_mask);
267 			data |= ((i << local_cac_reg->signal_shift) &
268 				 local_cac_reg->signal_mask);
269 			data |= ((values->t << local_cac_reg->t_shift) &
270 				 local_cac_reg->t_mask);
271 			data |= ((1 << local_cac_reg->enable_shift) &
272 				 local_cac_reg->enable_mask);
273 			WREG32_SMC(local_cac_reg->cntl, data);
274 		}
275 		values++;
276 	}
277 }
278 #endif
279 
280 static int kv_program_pt_config_registers(struct radeon_device *rdev,
281 					  const struct kv_pt_config_reg *cac_config_regs)
282 {
283 	const struct kv_pt_config_reg *config_regs = cac_config_regs;
284 	u32 data;
285 	u32 cache = 0;
286 
287 	if (config_regs == NULL)
288 		return -EINVAL;
289 
290 	while (config_regs->offset != 0xFFFFFFFF) {
291 		if (config_regs->type == KV_CONFIGREG_CACHE) {
292 			cache |= ((config_regs->value << config_regs->shift) & config_regs->mask);
293 		} else {
294 			switch (config_regs->type) {
295 			case KV_CONFIGREG_SMC_IND:
296 				data = RREG32_SMC(config_regs->offset);
297 				break;
298 			case KV_CONFIGREG_DIDT_IND:
299 				data = RREG32_DIDT(config_regs->offset);
300 				break;
301 			default:
302 				data = RREG32(config_regs->offset << 2);
303 				break;
304 			}
305 
306 			data &= ~config_regs->mask;
307 			data |= ((config_regs->value << config_regs->shift) & config_regs->mask);
308 			data |= cache;
309 			cache = 0;
310 
311 			switch (config_regs->type) {
312 			case KV_CONFIGREG_SMC_IND:
313 				WREG32_SMC(config_regs->offset, data);
314 				break;
315 			case KV_CONFIGREG_DIDT_IND:
316 				WREG32_DIDT(config_regs->offset, data);
317 				break;
318 			default:
319 				WREG32(config_regs->offset << 2, data);
320 				break;
321 			}
322 		}
323 		config_regs++;
324 	}
325 
326 	return 0;
327 }
328 
329 static void kv_do_enable_didt(struct radeon_device *rdev, bool enable)
330 {
331 	struct kv_power_info *pi = kv_get_pi(rdev);
332 	u32 data;
333 
334 	if (pi->caps_sq_ramping) {
335 		data = RREG32_DIDT(DIDT_SQ_CTRL0);
336 		if (enable)
337 			data |= DIDT_CTRL_EN;
338 		else
339 			data &= ~DIDT_CTRL_EN;
340 		WREG32_DIDT(DIDT_SQ_CTRL0, data);
341 	}
342 
343 	if (pi->caps_db_ramping) {
344 		data = RREG32_DIDT(DIDT_DB_CTRL0);
345 		if (enable)
346 			data |= DIDT_CTRL_EN;
347 		else
348 			data &= ~DIDT_CTRL_EN;
349 		WREG32_DIDT(DIDT_DB_CTRL0, data);
350 	}
351 
352 	if (pi->caps_td_ramping) {
353 		data = RREG32_DIDT(DIDT_TD_CTRL0);
354 		if (enable)
355 			data |= DIDT_CTRL_EN;
356 		else
357 			data &= ~DIDT_CTRL_EN;
358 		WREG32_DIDT(DIDT_TD_CTRL0, data);
359 	}
360 
361 	if (pi->caps_tcp_ramping) {
362 		data = RREG32_DIDT(DIDT_TCP_CTRL0);
363 		if (enable)
364 			data |= DIDT_CTRL_EN;
365 		else
366 			data &= ~DIDT_CTRL_EN;
367 		WREG32_DIDT(DIDT_TCP_CTRL0, data);
368 	}
369 }
370 
371 static int kv_enable_didt(struct radeon_device *rdev, bool enable)
372 {
373 	struct kv_power_info *pi = kv_get_pi(rdev);
374 	int ret;
375 
376 	if (pi->caps_sq_ramping ||
377 	    pi->caps_db_ramping ||
378 	    pi->caps_td_ramping ||
379 	    pi->caps_tcp_ramping) {
380 		cik_enter_rlc_safe_mode(rdev);
381 
382 		if (enable) {
383 			ret = kv_program_pt_config_registers(rdev, didt_config_kv);
384 			if (ret) {
385 				cik_exit_rlc_safe_mode(rdev);
386 				return ret;
387 			}
388 		}
389 
390 		kv_do_enable_didt(rdev, enable);
391 
392 		cik_exit_rlc_safe_mode(rdev);
393 	}
394 
395 	return 0;
396 }
397 
398 #if 0
399 static void kv_initialize_hardware_cac_manager(struct radeon_device *rdev)
400 {
401 	struct kv_power_info *pi = kv_get_pi(rdev);
402 
403 	if (pi->caps_cac) {
404 		WREG32_SMC(LCAC_SX0_OVR_SEL, 0);
405 		WREG32_SMC(LCAC_SX0_OVR_VAL, 0);
406 		kv_program_local_cac_table(rdev, sx_local_cac_cfg_kv, sx0_cac_config_reg);
407 
408 		WREG32_SMC(LCAC_MC0_OVR_SEL, 0);
409 		WREG32_SMC(LCAC_MC0_OVR_VAL, 0);
410 		kv_program_local_cac_table(rdev, mc0_local_cac_cfg_kv, mc0_cac_config_reg);
411 
412 		WREG32_SMC(LCAC_MC1_OVR_SEL, 0);
413 		WREG32_SMC(LCAC_MC1_OVR_VAL, 0);
414 		kv_program_local_cac_table(rdev, mc1_local_cac_cfg_kv, mc1_cac_config_reg);
415 
416 		WREG32_SMC(LCAC_MC2_OVR_SEL, 0);
417 		WREG32_SMC(LCAC_MC2_OVR_VAL, 0);
418 		kv_program_local_cac_table(rdev, mc2_local_cac_cfg_kv, mc2_cac_config_reg);
419 
420 		WREG32_SMC(LCAC_MC3_OVR_SEL, 0);
421 		WREG32_SMC(LCAC_MC3_OVR_VAL, 0);
422 		kv_program_local_cac_table(rdev, mc3_local_cac_cfg_kv, mc3_cac_config_reg);
423 
424 		WREG32_SMC(LCAC_CPL_OVR_SEL, 0);
425 		WREG32_SMC(LCAC_CPL_OVR_VAL, 0);
426 		kv_program_local_cac_table(rdev, cpl_local_cac_cfg_kv, cpl_cac_config_reg);
427 	}
428 }
429 #endif
430 
431 static int kv_enable_smc_cac(struct radeon_device *rdev, bool enable)
432 {
433 	struct kv_power_info *pi = kv_get_pi(rdev);
434 	int ret = 0;
435 
436 	if (pi->caps_cac) {
437 		if (enable) {
438 			ret = kv_notify_message_to_smu(rdev, PPSMC_MSG_EnableCac);
439 			if (ret)
440 				pi->cac_enabled = false;
441 			else
442 				pi->cac_enabled = true;
443 		} else if (pi->cac_enabled) {
444 			kv_notify_message_to_smu(rdev, PPSMC_MSG_DisableCac);
445 			pi->cac_enabled = false;
446 		}
447 	}
448 
449 	return ret;
450 }
451 
452 static int kv_process_firmware_header(struct radeon_device *rdev)
453 {
454 	struct kv_power_info *pi = kv_get_pi(rdev);
455 	u32 tmp;
456 	int ret;
457 
458 	ret = kv_read_smc_sram_dword(rdev, SMU7_FIRMWARE_HEADER_LOCATION +
459 				     offsetof(SMU7_Firmware_Header, DpmTable),
460 				     &tmp, pi->sram_end);
461 
462 	if (ret == 0)
463 		pi->dpm_table_start = tmp;
464 
465 	ret = kv_read_smc_sram_dword(rdev, SMU7_FIRMWARE_HEADER_LOCATION +
466 				     offsetof(SMU7_Firmware_Header, SoftRegisters),
467 				     &tmp, pi->sram_end);
468 
469 	if (ret == 0)
470 		pi->soft_regs_start = tmp;
471 
472 	return ret;
473 }
474 
475 static int kv_enable_dpm_voltage_scaling(struct radeon_device *rdev)
476 {
477 	struct kv_power_info *pi = kv_get_pi(rdev);
478 	int ret;
479 
480 	pi->graphics_voltage_change_enable = 1;
481 
482 	ret = kv_copy_bytes_to_smc(rdev,
483 				   pi->dpm_table_start +
484 				   offsetof(SMU7_Fusion_DpmTable, GraphicsVoltageChangeEnable),
485 				   &pi->graphics_voltage_change_enable,
486 				   sizeof(u8), pi->sram_end);
487 
488 	return ret;
489 }
490 
491 static int kv_set_dpm_interval(struct radeon_device *rdev)
492 {
493 	struct kv_power_info *pi = kv_get_pi(rdev);
494 	int ret;
495 
496 	pi->graphics_interval = 1;
497 
498 	ret = kv_copy_bytes_to_smc(rdev,
499 				   pi->dpm_table_start +
500 				   offsetof(SMU7_Fusion_DpmTable, GraphicsInterval),
501 				   &pi->graphics_interval,
502 				   sizeof(u8), pi->sram_end);
503 
504 	return ret;
505 }
506 
507 static int kv_set_dpm_boot_state(struct radeon_device *rdev)
508 {
509 	struct kv_power_info *pi = kv_get_pi(rdev);
510 	int ret;
511 
512 	ret = kv_copy_bytes_to_smc(rdev,
513 				   pi->dpm_table_start +
514 				   offsetof(SMU7_Fusion_DpmTable, GraphicsBootLevel),
515 				   &pi->graphics_boot_level,
516 				   sizeof(u8), pi->sram_end);
517 
518 	return ret;
519 }
520 
521 static void kv_program_vc(struct radeon_device *rdev)
522 {
523 	WREG32_SMC(CG_FTV_0, 0x3FFFC100);
524 }
525 
526 static void kv_clear_vc(struct radeon_device *rdev)
527 {
528 	WREG32_SMC(CG_FTV_0, 0);
529 }
530 
531 static int kv_set_divider_value(struct radeon_device *rdev,
532 				u32 index, u32 sclk)
533 {
534 	struct kv_power_info *pi = kv_get_pi(rdev);
535 	struct atom_clock_dividers dividers;
536 	int ret;
537 
538 	ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
539 					     sclk, false, &dividers);
540 	if (ret)
541 		return ret;
542 
543 	pi->graphics_level[index].SclkDid = (u8)dividers.post_div;
544 	pi->graphics_level[index].SclkFrequency = cpu_to_be32(sclk);
545 
546 	return 0;
547 }
548 
549 static u16 kv_convert_8bit_index_to_voltage(struct radeon_device *rdev,
550 					    u16 voltage)
551 {
552 	return 6200 - (voltage * 25);
553 }
554 
555 static u16 kv_convert_2bit_index_to_voltage(struct radeon_device *rdev,
556 					    u32 vid_2bit)
557 {
558 	struct kv_power_info *pi = kv_get_pi(rdev);
559 	u32 vid_8bit = sumo_convert_vid2_to_vid7(rdev,
560 						 &pi->sys_info.vid_mapping_table,
561 						 vid_2bit);
562 
563 	return kv_convert_8bit_index_to_voltage(rdev, (u16)vid_8bit);
564 }
565 
566 
567 static int kv_set_vid(struct radeon_device *rdev, u32 index, u32 vid)
568 {
569 	struct kv_power_info *pi = kv_get_pi(rdev);
570 
571 	pi->graphics_level[index].VoltageDownH = (u8)pi->voltage_drop_t;
572 	pi->graphics_level[index].MinVddNb =
573 		cpu_to_be32(kv_convert_2bit_index_to_voltage(rdev, vid));
574 
575 	return 0;
576 }
577 
578 static int kv_set_at(struct radeon_device *rdev, u32 index, u32 at)
579 {
580 	struct kv_power_info *pi = kv_get_pi(rdev);
581 
582 	pi->graphics_level[index].AT = cpu_to_be16((u16)at);
583 
584 	return 0;
585 }
586 
587 static void kv_dpm_power_level_enable(struct radeon_device *rdev,
588 				      u32 index, bool enable)
589 {
590 	struct kv_power_info *pi = kv_get_pi(rdev);
591 
592 	pi->graphics_level[index].EnabledForActivity = enable ? 1 : 0;
593 }
594 
595 static void kv_start_dpm(struct radeon_device *rdev)
596 {
597 	u32 tmp = RREG32_SMC(GENERAL_PWRMGT);
598 
599 	tmp |= GLOBAL_PWRMGT_EN;
600 	WREG32_SMC(GENERAL_PWRMGT, tmp);
601 
602 	kv_smc_dpm_enable(rdev, true);
603 }
604 
605 static void kv_stop_dpm(struct radeon_device *rdev)
606 {
607 	kv_smc_dpm_enable(rdev, false);
608 }
609 
610 static void kv_start_am(struct radeon_device *rdev)
611 {
612 	u32 sclk_pwrmgt_cntl = RREG32_SMC(SCLK_PWRMGT_CNTL);
613 
614 	sclk_pwrmgt_cntl &= ~(RESET_SCLK_CNT | RESET_BUSY_CNT);
615 	sclk_pwrmgt_cntl |= DYNAMIC_PM_EN;
616 
617 	WREG32_SMC(SCLK_PWRMGT_CNTL, sclk_pwrmgt_cntl);
618 }
619 
620 static void kv_reset_am(struct radeon_device *rdev)
621 {
622 	u32 sclk_pwrmgt_cntl = RREG32_SMC(SCLK_PWRMGT_CNTL);
623 
624 	sclk_pwrmgt_cntl |= (RESET_SCLK_CNT | RESET_BUSY_CNT);
625 
626 	WREG32_SMC(SCLK_PWRMGT_CNTL, sclk_pwrmgt_cntl);
627 }
628 
629 static int kv_freeze_sclk_dpm(struct radeon_device *rdev, bool freeze)
630 {
631 	return kv_notify_message_to_smu(rdev, freeze ?
632 					PPSMC_MSG_SCLKDPM_FreezeLevel : PPSMC_MSG_SCLKDPM_UnfreezeLevel);
633 }
634 
635 static int kv_force_lowest_valid(struct radeon_device *rdev)
636 {
637 	return kv_force_dpm_lowest(rdev);
638 }
639 
640 static int kv_unforce_levels(struct radeon_device *rdev)
641 {
642 	if (rdev->family == CHIP_KABINI)
643 		return kv_notify_message_to_smu(rdev, PPSMC_MSG_NoForcedLevel);
644 	else
645 		return kv_set_enabled_levels(rdev);
646 }
647 
648 static int kv_update_sclk_t(struct radeon_device *rdev)
649 {
650 	struct kv_power_info *pi = kv_get_pi(rdev);
651 	u32 low_sclk_interrupt_t = 0;
652 	int ret = 0;
653 
654 	if (pi->caps_sclk_throttle_low_notification) {
655 		low_sclk_interrupt_t = cpu_to_be32(pi->low_sclk_interrupt_t);
656 
657 		ret = kv_copy_bytes_to_smc(rdev,
658 					   pi->dpm_table_start +
659 					   offsetof(SMU7_Fusion_DpmTable, LowSclkInterruptT),
660 					   (u8 *)&low_sclk_interrupt_t,
661 					   sizeof(u32), pi->sram_end);
662 	}
663 	return ret;
664 }
665 
666 static int kv_program_bootup_state(struct radeon_device *rdev)
667 {
668 	struct kv_power_info *pi = kv_get_pi(rdev);
669 	u32 i;
670 	struct radeon_clock_voltage_dependency_table *table =
671 		&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
672 
673 	if (table && table->count) {
674 		for (i = pi->graphics_dpm_level_count - 1; i > 0; i--) {
675 			if (table->entries[i].clk == pi->boot_pl.sclk)
676 				break;
677 		}
678 
679 		pi->graphics_boot_level = (u8)i;
680 		kv_dpm_power_level_enable(rdev, i, true);
681 	} else {
682 		struct sumo_sclk_voltage_mapping_table *table =
683 			&pi->sys_info.sclk_voltage_mapping_table;
684 
685 		if (table->num_max_dpm_entries == 0)
686 			return -EINVAL;
687 
688 		for (i = pi->graphics_dpm_level_count - 1; i > 0; i--) {
689 			if (table->entries[i].sclk_frequency == pi->boot_pl.sclk)
690 				break;
691 		}
692 
693 		pi->graphics_boot_level = (u8)i;
694 		kv_dpm_power_level_enable(rdev, i, true);
695 	}
696 	return 0;
697 }
698 
699 static int kv_enable_auto_thermal_throttling(struct radeon_device *rdev)
700 {
701 	struct kv_power_info *pi = kv_get_pi(rdev);
702 	int ret;
703 
704 	pi->graphics_therm_throttle_enable = 1;
705 
706 	ret = kv_copy_bytes_to_smc(rdev,
707 				   pi->dpm_table_start +
708 				   offsetof(SMU7_Fusion_DpmTable, GraphicsThermThrottleEnable),
709 				   &pi->graphics_therm_throttle_enable,
710 				   sizeof(u8), pi->sram_end);
711 
712 	return ret;
713 }
714 
715 static int kv_upload_dpm_settings(struct radeon_device *rdev)
716 {
717 	struct kv_power_info *pi = kv_get_pi(rdev);
718 	int ret;
719 
720 	ret = kv_copy_bytes_to_smc(rdev,
721 				   pi->dpm_table_start +
722 				   offsetof(SMU7_Fusion_DpmTable, GraphicsLevel),
723 				   (u8 *)&pi->graphics_level,
724 				   sizeof(SMU7_Fusion_GraphicsLevel) * SMU7_MAX_LEVELS_GRAPHICS,
725 				   pi->sram_end);
726 
727 	if (ret)
728 		return ret;
729 
730 	ret = kv_copy_bytes_to_smc(rdev,
731 				   pi->dpm_table_start +
732 				   offsetof(SMU7_Fusion_DpmTable, GraphicsDpmLevelCount),
733 				   &pi->graphics_dpm_level_count,
734 				   sizeof(u8), pi->sram_end);
735 
736 	return ret;
737 }
738 
739 static u32 kv_get_clock_difference(u32 a, u32 b)
740 {
741 	return (a >= b) ? a - b : b - a;
742 }
743 
744 static u32 kv_get_clk_bypass(struct radeon_device *rdev, u32 clk)
745 {
746 	struct kv_power_info *pi = kv_get_pi(rdev);
747 	u32 value;
748 
749 	if (pi->caps_enable_dfs_bypass) {
750 		if (kv_get_clock_difference(clk, 40000) < 200)
751 			value = 3;
752 		else if (kv_get_clock_difference(clk, 30000) < 200)
753 			value = 2;
754 		else if (kv_get_clock_difference(clk, 20000) < 200)
755 			value = 7;
756 		else if (kv_get_clock_difference(clk, 15000) < 200)
757 			value = 6;
758 		else if (kv_get_clock_difference(clk, 10000) < 200)
759 			value = 8;
760 		else
761 			value = 0;
762 	} else {
763 		value = 0;
764 	}
765 
766 	return value;
767 }
768 
769 static int kv_populate_uvd_table(struct radeon_device *rdev)
770 {
771 	struct kv_power_info *pi = kv_get_pi(rdev);
772 	struct radeon_uvd_clock_voltage_dependency_table *table =
773 		&rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table;
774 	struct atom_clock_dividers dividers;
775 	int ret;
776 	u32 i;
777 
778 	if (table == NULL || table->count == 0)
779 		return 0;
780 
781 	pi->uvd_level_count = 0;
782 	for (i = 0; i < table->count; i++) {
783 		if (pi->high_voltage_t &&
784 		    (pi->high_voltage_t < table->entries[i].v))
785 			break;
786 
787 		pi->uvd_level[i].VclkFrequency = cpu_to_be32(table->entries[i].vclk);
788 		pi->uvd_level[i].DclkFrequency = cpu_to_be32(table->entries[i].dclk);
789 		pi->uvd_level[i].MinVddNb = cpu_to_be16(table->entries[i].v);
790 
791 		pi->uvd_level[i].VClkBypassCntl =
792 			(u8)kv_get_clk_bypass(rdev, table->entries[i].vclk);
793 		pi->uvd_level[i].DClkBypassCntl =
794 			(u8)kv_get_clk_bypass(rdev, table->entries[i].dclk);
795 
796 		ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
797 						     table->entries[i].vclk, false, &dividers);
798 		if (ret)
799 			return ret;
800 		pi->uvd_level[i].VclkDivider = (u8)dividers.post_div;
801 
802 		ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
803 						     table->entries[i].dclk, false, &dividers);
804 		if (ret)
805 			return ret;
806 		pi->uvd_level[i].DclkDivider = (u8)dividers.post_div;
807 
808 		pi->uvd_level_count++;
809 	}
810 
811 	ret = kv_copy_bytes_to_smc(rdev,
812 				   pi->dpm_table_start +
813 				   offsetof(SMU7_Fusion_DpmTable, UvdLevelCount),
814 				   (u8 *)&pi->uvd_level_count,
815 				   sizeof(u8), pi->sram_end);
816 	if (ret)
817 		return ret;
818 
819 	pi->uvd_interval = 1;
820 
821 	ret = kv_copy_bytes_to_smc(rdev,
822 				   pi->dpm_table_start +
823 				   offsetof(SMU7_Fusion_DpmTable, UVDInterval),
824 				   &pi->uvd_interval,
825 				   sizeof(u8), pi->sram_end);
826 	if (ret)
827 		return ret;
828 
829 	ret = kv_copy_bytes_to_smc(rdev,
830 				   pi->dpm_table_start +
831 				   offsetof(SMU7_Fusion_DpmTable, UvdLevel),
832 				   (u8 *)&pi->uvd_level,
833 				   sizeof(SMU7_Fusion_UvdLevel) * SMU7_MAX_LEVELS_UVD,
834 				   pi->sram_end);
835 
836 	return ret;
837 
838 }
839 
840 static int kv_populate_vce_table(struct radeon_device *rdev)
841 {
842 	struct kv_power_info *pi = kv_get_pi(rdev);
843 	int ret;
844 	u32 i;
845 	struct radeon_vce_clock_voltage_dependency_table *table =
846 		&rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
847 	struct atom_clock_dividers dividers;
848 
849 	if (table == NULL || table->count == 0)
850 		return 0;
851 
852 	pi->vce_level_count = 0;
853 	for (i = 0; i < table->count; i++) {
854 		if (pi->high_voltage_t &&
855 		    pi->high_voltage_t < table->entries[i].v)
856 			break;
857 
858 		pi->vce_level[i].Frequency = cpu_to_be32(table->entries[i].evclk);
859 		pi->vce_level[i].MinVoltage = cpu_to_be16(table->entries[i].v);
860 
861 		pi->vce_level[i].ClkBypassCntl =
862 			(u8)kv_get_clk_bypass(rdev, table->entries[i].evclk);
863 
864 		ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
865 						     table->entries[i].evclk, false, &dividers);
866 		if (ret)
867 			return ret;
868 		pi->vce_level[i].Divider = (u8)dividers.post_div;
869 
870 		pi->vce_level_count++;
871 	}
872 
873 	ret = kv_copy_bytes_to_smc(rdev,
874 				   pi->dpm_table_start +
875 				   offsetof(SMU7_Fusion_DpmTable, VceLevelCount),
876 				   (u8 *)&pi->vce_level_count,
877 				   sizeof(u8),
878 				   pi->sram_end);
879 	if (ret)
880 		return ret;
881 
882 	pi->vce_interval = 1;
883 
884 	ret = kv_copy_bytes_to_smc(rdev,
885 				   pi->dpm_table_start +
886 				   offsetof(SMU7_Fusion_DpmTable, VCEInterval),
887 				   (u8 *)&pi->vce_interval,
888 				   sizeof(u8),
889 				   pi->sram_end);
890 	if (ret)
891 		return ret;
892 
893 	ret = kv_copy_bytes_to_smc(rdev,
894 				   pi->dpm_table_start +
895 				   offsetof(SMU7_Fusion_DpmTable, VceLevel),
896 				   (u8 *)&pi->vce_level,
897 				   sizeof(SMU7_Fusion_ExtClkLevel) * SMU7_MAX_LEVELS_VCE,
898 				   pi->sram_end);
899 
900 	return ret;
901 }
902 
903 static int kv_populate_samu_table(struct radeon_device *rdev)
904 {
905 	struct kv_power_info *pi = kv_get_pi(rdev);
906 	struct radeon_clock_voltage_dependency_table *table =
907 		&rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table;
908 	struct atom_clock_dividers dividers;
909 	int ret;
910 	u32 i;
911 
912 	if (table == NULL || table->count == 0)
913 		return 0;
914 
915 	pi->samu_level_count = 0;
916 	for (i = 0; i < table->count; i++) {
917 		if (pi->high_voltage_t &&
918 		    pi->high_voltage_t < table->entries[i].v)
919 			break;
920 
921 		pi->samu_level[i].Frequency = cpu_to_be32(table->entries[i].clk);
922 		pi->samu_level[i].MinVoltage = cpu_to_be16(table->entries[i].v);
923 
924 		pi->samu_level[i].ClkBypassCntl =
925 			(u8)kv_get_clk_bypass(rdev, table->entries[i].clk);
926 
927 		ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
928 						     table->entries[i].clk, false, &dividers);
929 		if (ret)
930 			return ret;
931 		pi->samu_level[i].Divider = (u8)dividers.post_div;
932 
933 		pi->samu_level_count++;
934 	}
935 
936 	ret = kv_copy_bytes_to_smc(rdev,
937 				   pi->dpm_table_start +
938 				   offsetof(SMU7_Fusion_DpmTable, SamuLevelCount),
939 				   (u8 *)&pi->samu_level_count,
940 				   sizeof(u8),
941 				   pi->sram_end);
942 	if (ret)
943 		return ret;
944 
945 	pi->samu_interval = 1;
946 
947 	ret = kv_copy_bytes_to_smc(rdev,
948 				   pi->dpm_table_start +
949 				   offsetof(SMU7_Fusion_DpmTable, SAMUInterval),
950 				   (u8 *)&pi->samu_interval,
951 				   sizeof(u8),
952 				   pi->sram_end);
953 	if (ret)
954 		return ret;
955 
956 	ret = kv_copy_bytes_to_smc(rdev,
957 				   pi->dpm_table_start +
958 				   offsetof(SMU7_Fusion_DpmTable, SamuLevel),
959 				   (u8 *)&pi->samu_level,
960 				   sizeof(SMU7_Fusion_ExtClkLevel) * SMU7_MAX_LEVELS_SAMU,
961 				   pi->sram_end);
962 	if (ret)
963 		return ret;
964 
965 	return ret;
966 }
967 
968 
969 static int kv_populate_acp_table(struct radeon_device *rdev)
970 {
971 	struct kv_power_info *pi = kv_get_pi(rdev);
972 	struct radeon_clock_voltage_dependency_table *table =
973 		&rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table;
974 	struct atom_clock_dividers dividers;
975 	int ret;
976 	u32 i;
977 
978 	if (table == NULL || table->count == 0)
979 		return 0;
980 
981 	pi->acp_level_count = 0;
982 	for (i = 0; i < table->count; i++) {
983 		pi->acp_level[i].Frequency = cpu_to_be32(table->entries[i].clk);
984 		pi->acp_level[i].MinVoltage = cpu_to_be16(table->entries[i].v);
985 
986 		ret = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
987 						     table->entries[i].clk, false, &dividers);
988 		if (ret)
989 			return ret;
990 		pi->acp_level[i].Divider = (u8)dividers.post_div;
991 
992 		pi->acp_level_count++;
993 	}
994 
995 	ret = kv_copy_bytes_to_smc(rdev,
996 				   pi->dpm_table_start +
997 				   offsetof(SMU7_Fusion_DpmTable, AcpLevelCount),
998 				   (u8 *)&pi->acp_level_count,
999 				   sizeof(u8),
1000 				   pi->sram_end);
1001 	if (ret)
1002 		return ret;
1003 
1004 	pi->acp_interval = 1;
1005 
1006 	ret = kv_copy_bytes_to_smc(rdev,
1007 				   pi->dpm_table_start +
1008 				   offsetof(SMU7_Fusion_DpmTable, ACPInterval),
1009 				   (u8 *)&pi->acp_interval,
1010 				   sizeof(u8),
1011 				   pi->sram_end);
1012 	if (ret)
1013 		return ret;
1014 
1015 	ret = kv_copy_bytes_to_smc(rdev,
1016 				   pi->dpm_table_start +
1017 				   offsetof(SMU7_Fusion_DpmTable, AcpLevel),
1018 				   (u8 *)&pi->acp_level,
1019 				   sizeof(SMU7_Fusion_ExtClkLevel) * SMU7_MAX_LEVELS_ACP,
1020 				   pi->sram_end);
1021 	if (ret)
1022 		return ret;
1023 
1024 	return ret;
1025 }
1026 
1027 static void kv_calculate_dfs_bypass_settings(struct radeon_device *rdev)
1028 {
1029 	struct kv_power_info *pi = kv_get_pi(rdev);
1030 	u32 i;
1031 	struct radeon_clock_voltage_dependency_table *table =
1032 		&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
1033 
1034 	if (table && table->count) {
1035 		for (i = 0; i < pi->graphics_dpm_level_count; i++) {
1036 			if (pi->caps_enable_dfs_bypass) {
1037 				if (kv_get_clock_difference(table->entries[i].clk, 40000) < 200)
1038 					pi->graphics_level[i].ClkBypassCntl = 3;
1039 				else if (kv_get_clock_difference(table->entries[i].clk, 30000) < 200)
1040 					pi->graphics_level[i].ClkBypassCntl = 2;
1041 				else if (kv_get_clock_difference(table->entries[i].clk, 26600) < 200)
1042 					pi->graphics_level[i].ClkBypassCntl = 7;
1043 				else if (kv_get_clock_difference(table->entries[i].clk , 20000) < 200)
1044 					pi->graphics_level[i].ClkBypassCntl = 6;
1045 				else if (kv_get_clock_difference(table->entries[i].clk , 10000) < 200)
1046 					pi->graphics_level[i].ClkBypassCntl = 8;
1047 				else
1048 					pi->graphics_level[i].ClkBypassCntl = 0;
1049 			} else {
1050 				pi->graphics_level[i].ClkBypassCntl = 0;
1051 			}
1052 		}
1053 	} else {
1054 		struct sumo_sclk_voltage_mapping_table *table =
1055 			&pi->sys_info.sclk_voltage_mapping_table;
1056 		for (i = 0; i < pi->graphics_dpm_level_count; i++) {
1057 			if (pi->caps_enable_dfs_bypass) {
1058 				if (kv_get_clock_difference(table->entries[i].sclk_frequency, 40000) < 200)
1059 					pi->graphics_level[i].ClkBypassCntl = 3;
1060 				else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 30000) < 200)
1061 					pi->graphics_level[i].ClkBypassCntl = 2;
1062 				else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 26600) < 200)
1063 					pi->graphics_level[i].ClkBypassCntl = 7;
1064 				else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 20000) < 200)
1065 					pi->graphics_level[i].ClkBypassCntl = 6;
1066 				else if (kv_get_clock_difference(table->entries[i].sclk_frequency, 10000) < 200)
1067 					pi->graphics_level[i].ClkBypassCntl = 8;
1068 				else
1069 					pi->graphics_level[i].ClkBypassCntl = 0;
1070 			} else {
1071 				pi->graphics_level[i].ClkBypassCntl = 0;
1072 			}
1073 		}
1074 	}
1075 }
1076 
1077 static int kv_enable_ulv(struct radeon_device *rdev, bool enable)
1078 {
1079 	return kv_notify_message_to_smu(rdev, enable ?
1080 					PPSMC_MSG_EnableULV : PPSMC_MSG_DisableULV);
1081 }
1082 
1083 static void kv_reset_acp_boot_level(struct radeon_device *rdev)
1084 {
1085 	struct kv_power_info *pi = kv_get_pi(rdev);
1086 
1087 	pi->acp_boot_level = 0xff;
1088 }
1089 
1090 static void kv_update_current_ps(struct radeon_device *rdev,
1091 				 struct radeon_ps *rps)
1092 {
1093 	struct kv_ps *new_ps = kv_get_ps(rps);
1094 	struct kv_power_info *pi = kv_get_pi(rdev);
1095 
1096 	pi->current_rps = *rps;
1097 	pi->current_ps = *new_ps;
1098 	pi->current_rps.ps_priv = &pi->current_ps;
1099 }
1100 
1101 static void kv_update_requested_ps(struct radeon_device *rdev,
1102 				   struct radeon_ps *rps)
1103 {
1104 	struct kv_ps *new_ps = kv_get_ps(rps);
1105 	struct kv_power_info *pi = kv_get_pi(rdev);
1106 
1107 	pi->requested_rps = *rps;
1108 	pi->requested_ps = *new_ps;
1109 	pi->requested_rps.ps_priv = &pi->requested_ps;
1110 }
1111 
1112 void kv_dpm_enable_bapm(struct radeon_device *rdev, bool enable)
1113 {
1114 	struct kv_power_info *pi = kv_get_pi(rdev);
1115 	int ret;
1116 
1117 	if (pi->bapm_enable) {
1118 		ret = kv_smc_bapm_enable(rdev, enable);
1119 		if (ret)
1120 			DRM_ERROR("kv_smc_bapm_enable failed\n");
1121 	}
1122 }
1123 
1124 int kv_dpm_enable(struct radeon_device *rdev)
1125 {
1126 	struct kv_power_info *pi = kv_get_pi(rdev);
1127 	int ret;
1128 
1129 	ret = kv_process_firmware_header(rdev);
1130 	if (ret) {
1131 		DRM_ERROR("kv_process_firmware_header failed\n");
1132 		return ret;
1133 	}
1134 	kv_init_fps_limits(rdev);
1135 	kv_init_graphics_levels(rdev);
1136 	ret = kv_program_bootup_state(rdev);
1137 	if (ret) {
1138 		DRM_ERROR("kv_program_bootup_state failed\n");
1139 		return ret;
1140 	}
1141 	kv_calculate_dfs_bypass_settings(rdev);
1142 	ret = kv_upload_dpm_settings(rdev);
1143 	if (ret) {
1144 		DRM_ERROR("kv_upload_dpm_settings failed\n");
1145 		return ret;
1146 	}
1147 	ret = kv_populate_uvd_table(rdev);
1148 	if (ret) {
1149 		DRM_ERROR("kv_populate_uvd_table failed\n");
1150 		return ret;
1151 	}
1152 	ret = kv_populate_vce_table(rdev);
1153 	if (ret) {
1154 		DRM_ERROR("kv_populate_vce_table failed\n");
1155 		return ret;
1156 	}
1157 	ret = kv_populate_samu_table(rdev);
1158 	if (ret) {
1159 		DRM_ERROR("kv_populate_samu_table failed\n");
1160 		return ret;
1161 	}
1162 	ret = kv_populate_acp_table(rdev);
1163 	if (ret) {
1164 		DRM_ERROR("kv_populate_acp_table failed\n");
1165 		return ret;
1166 	}
1167 	kv_program_vc(rdev);
1168 #if 0
1169 	kv_initialize_hardware_cac_manager(rdev);
1170 #endif
1171 	kv_start_am(rdev);
1172 	if (pi->enable_auto_thermal_throttling) {
1173 		ret = kv_enable_auto_thermal_throttling(rdev);
1174 		if (ret) {
1175 			DRM_ERROR("kv_enable_auto_thermal_throttling failed\n");
1176 			return ret;
1177 		}
1178 	}
1179 	ret = kv_enable_dpm_voltage_scaling(rdev);
1180 	if (ret) {
1181 		DRM_ERROR("kv_enable_dpm_voltage_scaling failed\n");
1182 		return ret;
1183 	}
1184 	ret = kv_set_dpm_interval(rdev);
1185 	if (ret) {
1186 		DRM_ERROR("kv_set_dpm_interval failed\n");
1187 		return ret;
1188 	}
1189 	ret = kv_set_dpm_boot_state(rdev);
1190 	if (ret) {
1191 		DRM_ERROR("kv_set_dpm_boot_state failed\n");
1192 		return ret;
1193 	}
1194 	ret = kv_enable_ulv(rdev, true);
1195 	if (ret) {
1196 		DRM_ERROR("kv_enable_ulv failed\n");
1197 		return ret;
1198 	}
1199 	kv_start_dpm(rdev);
1200 	ret = kv_enable_didt(rdev, true);
1201 	if (ret) {
1202 		DRM_ERROR("kv_enable_didt failed\n");
1203 		return ret;
1204 	}
1205 	ret = kv_enable_smc_cac(rdev, true);
1206 	if (ret) {
1207 		DRM_ERROR("kv_enable_smc_cac failed\n");
1208 		return ret;
1209 	}
1210 
1211 	kv_reset_acp_boot_level(rdev);
1212 
1213 	ret = kv_smc_bapm_enable(rdev, false);
1214 	if (ret) {
1215 		DRM_ERROR("kv_smc_bapm_enable failed\n");
1216 		return ret;
1217 	}
1218 
1219 	kv_update_current_ps(rdev, rdev->pm.dpm.boot_ps);
1220 
1221 	return ret;
1222 }
1223 
1224 int kv_dpm_late_enable(struct radeon_device *rdev)
1225 {
1226 	int ret = 0;
1227 
1228 	if (rdev->irq.installed &&
1229 	    r600_is_internal_thermal_sensor(rdev->pm.int_thermal_type)) {
1230 		ret = kv_set_thermal_temperature_range(rdev, R600_TEMP_RANGE_MIN, R600_TEMP_RANGE_MAX);
1231 		if (ret) {
1232 			DRM_ERROR("kv_set_thermal_temperature_range failed\n");
1233 			return ret;
1234 		}
1235 		rdev->irq.dpm_thermal = true;
1236 		radeon_irq_set(rdev);
1237 	}
1238 
1239 	/* powerdown unused blocks for now */
1240 	kv_dpm_powergate_acp(rdev, true);
1241 	kv_dpm_powergate_samu(rdev, true);
1242 	kv_dpm_powergate_vce(rdev, true);
1243 	kv_dpm_powergate_uvd(rdev, true);
1244 
1245 	return ret;
1246 }
1247 
1248 void kv_dpm_disable(struct radeon_device *rdev)
1249 {
1250 	kv_smc_bapm_enable(rdev, false);
1251 
1252 	/* powerup blocks */
1253 	kv_dpm_powergate_acp(rdev, false);
1254 	kv_dpm_powergate_samu(rdev, false);
1255 	kv_dpm_powergate_vce(rdev, false);
1256 	kv_dpm_powergate_uvd(rdev, false);
1257 
1258 	kv_enable_smc_cac(rdev, false);
1259 	kv_enable_didt(rdev, false);
1260 	kv_clear_vc(rdev);
1261 	kv_stop_dpm(rdev);
1262 	kv_enable_ulv(rdev, false);
1263 	kv_reset_am(rdev);
1264 
1265 	kv_update_current_ps(rdev, rdev->pm.dpm.boot_ps);
1266 }
1267 
1268 #if 0
1269 static int kv_write_smc_soft_register(struct radeon_device *rdev,
1270 				      u16 reg_offset, u32 value)
1271 {
1272 	struct kv_power_info *pi = kv_get_pi(rdev);
1273 
1274 	return kv_copy_bytes_to_smc(rdev, pi->soft_regs_start + reg_offset,
1275 				    (u8 *)&value, sizeof(u16), pi->sram_end);
1276 }
1277 
1278 static int kv_read_smc_soft_register(struct radeon_device *rdev,
1279 				     u16 reg_offset, u32 *value)
1280 {
1281 	struct kv_power_info *pi = kv_get_pi(rdev);
1282 
1283 	return kv_read_smc_sram_dword(rdev, pi->soft_regs_start + reg_offset,
1284 				      value, pi->sram_end);
1285 }
1286 #endif
1287 
1288 static void kv_init_sclk_t(struct radeon_device *rdev)
1289 {
1290 	struct kv_power_info *pi = kv_get_pi(rdev);
1291 
1292 	pi->low_sclk_interrupt_t = 0;
1293 }
1294 
1295 static int kv_init_fps_limits(struct radeon_device *rdev)
1296 {
1297 	struct kv_power_info *pi = kv_get_pi(rdev);
1298 	int ret = 0;
1299 
1300 	if (pi->caps_fps) {
1301 		u16 tmp;
1302 
1303 		tmp = 45;
1304 		pi->fps_high_t = cpu_to_be16(tmp);
1305 		ret = kv_copy_bytes_to_smc(rdev,
1306 					   pi->dpm_table_start +
1307 					   offsetof(SMU7_Fusion_DpmTable, FpsHighT),
1308 					   (u8 *)&pi->fps_high_t,
1309 					   sizeof(u16), pi->sram_end);
1310 
1311 		tmp = 30;
1312 		pi->fps_low_t = cpu_to_be16(tmp);
1313 
1314 		ret = kv_copy_bytes_to_smc(rdev,
1315 					   pi->dpm_table_start +
1316 					   offsetof(SMU7_Fusion_DpmTable, FpsLowT),
1317 					   (u8 *)&pi->fps_low_t,
1318 					   sizeof(u16), pi->sram_end);
1319 
1320 	}
1321 	return ret;
1322 }
1323 
1324 static void kv_init_powergate_state(struct radeon_device *rdev)
1325 {
1326 	struct kv_power_info *pi = kv_get_pi(rdev);
1327 
1328 	pi->uvd_power_gated = false;
1329 	pi->vce_power_gated = false;
1330 	pi->samu_power_gated = false;
1331 	pi->acp_power_gated = false;
1332 
1333 }
1334 
1335 static int kv_enable_uvd_dpm(struct radeon_device *rdev, bool enable)
1336 {
1337 	return kv_notify_message_to_smu(rdev, enable ?
1338 					PPSMC_MSG_UVDDPM_Enable : PPSMC_MSG_UVDDPM_Disable);
1339 }
1340 
1341 static int kv_enable_vce_dpm(struct radeon_device *rdev, bool enable)
1342 {
1343 	return kv_notify_message_to_smu(rdev, enable ?
1344 					PPSMC_MSG_VCEDPM_Enable : PPSMC_MSG_VCEDPM_Disable);
1345 }
1346 
1347 static int kv_enable_samu_dpm(struct radeon_device *rdev, bool enable)
1348 {
1349 	return kv_notify_message_to_smu(rdev, enable ?
1350 					PPSMC_MSG_SAMUDPM_Enable : PPSMC_MSG_SAMUDPM_Disable);
1351 }
1352 
1353 static int kv_enable_acp_dpm(struct radeon_device *rdev, bool enable)
1354 {
1355 	return kv_notify_message_to_smu(rdev, enable ?
1356 					PPSMC_MSG_ACPDPM_Enable : PPSMC_MSG_ACPDPM_Disable);
1357 }
1358 
1359 static int kv_update_uvd_dpm(struct radeon_device *rdev, bool gate)
1360 {
1361 	struct kv_power_info *pi = kv_get_pi(rdev);
1362 	struct radeon_uvd_clock_voltage_dependency_table *table =
1363 		&rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table;
1364 	int ret;
1365 
1366 	if (!gate) {
1367 		if (!pi->caps_uvd_dpm || table->count || pi->caps_stable_p_state)
1368 			pi->uvd_boot_level = table->count - 1;
1369 		else
1370 			pi->uvd_boot_level = 0;
1371 
1372 		ret = kv_copy_bytes_to_smc(rdev,
1373 					   pi->dpm_table_start +
1374 					   offsetof(SMU7_Fusion_DpmTable, UvdBootLevel),
1375 					   (uint8_t *)&pi->uvd_boot_level,
1376 					   sizeof(u8), pi->sram_end);
1377 		if (ret)
1378 			return ret;
1379 
1380 		if (!pi->caps_uvd_dpm ||
1381 		    pi->caps_stable_p_state)
1382 			kv_send_msg_to_smc_with_parameter(rdev,
1383 							  PPSMC_MSG_UVDDPM_SetEnabledMask,
1384 							  (1 << pi->uvd_boot_level));
1385 	}
1386 
1387 	return kv_enable_uvd_dpm(rdev, !gate);
1388 }
1389 
1390 static u8 kv_get_vce_boot_level(struct radeon_device *rdev)
1391 {
1392 	u8 i;
1393 	struct radeon_vce_clock_voltage_dependency_table *table =
1394 		&rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
1395 
1396 	for (i = 0; i < table->count; i++) {
1397 		if (table->entries[i].evclk >= 0) /* XXX */
1398 			break;
1399 	}
1400 
1401 	return i;
1402 }
1403 
1404 static int kv_update_vce_dpm(struct radeon_device *rdev,
1405 			     struct radeon_ps *radeon_new_state,
1406 			     struct radeon_ps *radeon_current_state)
1407 {
1408 	struct kv_power_info *pi = kv_get_pi(rdev);
1409 	struct radeon_vce_clock_voltage_dependency_table *table =
1410 		&rdev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table;
1411 	int ret;
1412 
1413 	if (radeon_new_state->evclk > 0 && radeon_current_state->evclk == 0) {
1414 		kv_dpm_powergate_vce(rdev, false);
1415 		/* turn the clocks on when encoding */
1416 		cik_update_cg(rdev, RADEON_CG_BLOCK_VCE, false);
1417 		if (pi->caps_stable_p_state)
1418 			pi->vce_boot_level = table->count - 1;
1419 		else
1420 			pi->vce_boot_level = kv_get_vce_boot_level(rdev);
1421 
1422 		ret = kv_copy_bytes_to_smc(rdev,
1423 					   pi->dpm_table_start +
1424 					   offsetof(SMU7_Fusion_DpmTable, VceBootLevel),
1425 					   (u8 *)&pi->vce_boot_level,
1426 					   sizeof(u8),
1427 					   pi->sram_end);
1428 		if (ret)
1429 			return ret;
1430 
1431 		if (pi->caps_stable_p_state)
1432 			kv_send_msg_to_smc_with_parameter(rdev,
1433 							  PPSMC_MSG_VCEDPM_SetEnabledMask,
1434 							  (1 << pi->vce_boot_level));
1435 
1436 		kv_enable_vce_dpm(rdev, true);
1437 	} else if (radeon_new_state->evclk == 0 && radeon_current_state->evclk > 0) {
1438 		kv_enable_vce_dpm(rdev, false);
1439 		/* turn the clocks off when not encoding */
1440 		cik_update_cg(rdev, RADEON_CG_BLOCK_VCE, true);
1441 		kv_dpm_powergate_vce(rdev, true);
1442 	}
1443 
1444 	return 0;
1445 }
1446 
1447 static int kv_update_samu_dpm(struct radeon_device *rdev, bool gate)
1448 {
1449 	struct kv_power_info *pi = kv_get_pi(rdev);
1450 	struct radeon_clock_voltage_dependency_table *table =
1451 		&rdev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table;
1452 	int ret;
1453 
1454 	if (!gate) {
1455 		if (pi->caps_stable_p_state)
1456 			pi->samu_boot_level = table->count - 1;
1457 		else
1458 			pi->samu_boot_level = 0;
1459 
1460 		ret = kv_copy_bytes_to_smc(rdev,
1461 					   pi->dpm_table_start +
1462 					   offsetof(SMU7_Fusion_DpmTable, SamuBootLevel),
1463 					   (u8 *)&pi->samu_boot_level,
1464 					   sizeof(u8),
1465 					   pi->sram_end);
1466 		if (ret)
1467 			return ret;
1468 
1469 		if (pi->caps_stable_p_state)
1470 			kv_send_msg_to_smc_with_parameter(rdev,
1471 							  PPSMC_MSG_SAMUDPM_SetEnabledMask,
1472 							  (1 << pi->samu_boot_level));
1473 	}
1474 
1475 	return kv_enable_samu_dpm(rdev, !gate);
1476 }
1477 
1478 static u8 kv_get_acp_boot_level(struct radeon_device *rdev)
1479 {
1480 	u8 i;
1481 	struct radeon_clock_voltage_dependency_table *table =
1482 		&rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table;
1483 
1484 	for (i = 0; i < table->count; i++) {
1485 		if (table->entries[i].clk >= 0) /* XXX */
1486 			break;
1487 	}
1488 
1489 	if (i >= table->count)
1490 		i = table->count - 1;
1491 
1492 	return i;
1493 }
1494 
1495 static void kv_update_acp_boot_level(struct radeon_device *rdev)
1496 {
1497 	struct kv_power_info *pi = kv_get_pi(rdev);
1498 	u8 acp_boot_level;
1499 
1500 	if (!pi->caps_stable_p_state) {
1501 		acp_boot_level = kv_get_acp_boot_level(rdev);
1502 		if (acp_boot_level != pi->acp_boot_level) {
1503 			pi->acp_boot_level = acp_boot_level;
1504 			kv_send_msg_to_smc_with_parameter(rdev,
1505 							  PPSMC_MSG_ACPDPM_SetEnabledMask,
1506 							  (1 << pi->acp_boot_level));
1507 		}
1508 	}
1509 }
1510 
1511 static int kv_update_acp_dpm(struct radeon_device *rdev, bool gate)
1512 {
1513 	struct kv_power_info *pi = kv_get_pi(rdev);
1514 	struct radeon_clock_voltage_dependency_table *table =
1515 		&rdev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table;
1516 	int ret;
1517 
1518 	if (!gate) {
1519 		if (pi->caps_stable_p_state)
1520 			pi->acp_boot_level = table->count - 1;
1521 		else
1522 			pi->acp_boot_level = kv_get_acp_boot_level(rdev);
1523 
1524 		ret = kv_copy_bytes_to_smc(rdev,
1525 					   pi->dpm_table_start +
1526 					   offsetof(SMU7_Fusion_DpmTable, AcpBootLevel),
1527 					   (u8 *)&pi->acp_boot_level,
1528 					   sizeof(u8),
1529 					   pi->sram_end);
1530 		if (ret)
1531 			return ret;
1532 
1533 		if (pi->caps_stable_p_state)
1534 			kv_send_msg_to_smc_with_parameter(rdev,
1535 							  PPSMC_MSG_ACPDPM_SetEnabledMask,
1536 							  (1 << pi->acp_boot_level));
1537 	}
1538 
1539 	return kv_enable_acp_dpm(rdev, !gate);
1540 }
1541 
1542 void kv_dpm_powergate_uvd(struct radeon_device *rdev, bool gate)
1543 {
1544 	struct kv_power_info *pi = kv_get_pi(rdev);
1545 
1546 	if (pi->uvd_power_gated == gate)
1547 		return;
1548 
1549 	pi->uvd_power_gated = gate;
1550 
1551 	if (gate) {
1552 		if (pi->caps_uvd_pg) {
1553 			uvd_v1_0_stop(rdev);
1554 			cik_update_cg(rdev, RADEON_CG_BLOCK_UVD, false);
1555 		}
1556 		kv_update_uvd_dpm(rdev, gate);
1557 		if (pi->caps_uvd_pg)
1558 			kv_notify_message_to_smu(rdev, PPSMC_MSG_UVDPowerOFF);
1559 	} else {
1560 		if (pi->caps_uvd_pg) {
1561 			kv_notify_message_to_smu(rdev, PPSMC_MSG_UVDPowerON);
1562 			uvd_v4_2_resume(rdev);
1563 			uvd_v1_0_start(rdev);
1564 			cik_update_cg(rdev, RADEON_CG_BLOCK_UVD, true);
1565 		}
1566 		kv_update_uvd_dpm(rdev, gate);
1567 	}
1568 }
1569 
1570 static void kv_dpm_powergate_vce(struct radeon_device *rdev, bool gate)
1571 {
1572 	struct kv_power_info *pi = kv_get_pi(rdev);
1573 
1574 	if (pi->vce_power_gated == gate)
1575 		return;
1576 
1577 	pi->vce_power_gated = gate;
1578 
1579 	if (gate) {
1580 		if (pi->caps_vce_pg) {
1581 			/* XXX do we need a vce_v1_0_stop() ?  */
1582 			kv_notify_message_to_smu(rdev, PPSMC_MSG_VCEPowerOFF);
1583 		}
1584 	} else {
1585 		if (pi->caps_vce_pg) {
1586 			kv_notify_message_to_smu(rdev, PPSMC_MSG_VCEPowerON);
1587 			vce_v2_0_resume(rdev);
1588 			vce_v1_0_start(rdev);
1589 		}
1590 	}
1591 }
1592 
1593 static void kv_dpm_powergate_samu(struct radeon_device *rdev, bool gate)
1594 {
1595 	struct kv_power_info *pi = kv_get_pi(rdev);
1596 
1597 	if (pi->samu_power_gated == gate)
1598 		return;
1599 
1600 	pi->samu_power_gated = gate;
1601 
1602 	if (gate) {
1603 		kv_update_samu_dpm(rdev, true);
1604 		if (pi->caps_samu_pg)
1605 			kv_notify_message_to_smu(rdev, PPSMC_MSG_SAMPowerOFF);
1606 	} else {
1607 		if (pi->caps_samu_pg)
1608 			kv_notify_message_to_smu(rdev, PPSMC_MSG_SAMPowerON);
1609 		kv_update_samu_dpm(rdev, false);
1610 	}
1611 }
1612 
1613 static void kv_dpm_powergate_acp(struct radeon_device *rdev, bool gate)
1614 {
1615 	struct kv_power_info *pi = kv_get_pi(rdev);
1616 
1617 	if (pi->acp_power_gated == gate)
1618 		return;
1619 
1620 	if (rdev->family == CHIP_KABINI)
1621 		return;
1622 
1623 	pi->acp_power_gated = gate;
1624 
1625 	if (gate) {
1626 		kv_update_acp_dpm(rdev, true);
1627 		if (pi->caps_acp_pg)
1628 			kv_notify_message_to_smu(rdev, PPSMC_MSG_ACPPowerOFF);
1629 	} else {
1630 		if (pi->caps_acp_pg)
1631 			kv_notify_message_to_smu(rdev, PPSMC_MSG_ACPPowerON);
1632 		kv_update_acp_dpm(rdev, false);
1633 	}
1634 }
1635 
1636 static void kv_set_valid_clock_range(struct radeon_device *rdev,
1637 				     struct radeon_ps *new_rps)
1638 {
1639 	struct kv_ps *new_ps = kv_get_ps(new_rps);
1640 	struct kv_power_info *pi = kv_get_pi(rdev);
1641 	u32 i;
1642 	struct radeon_clock_voltage_dependency_table *table =
1643 		&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
1644 
1645 	if (table && table->count) {
1646 		for (i = 0; i < pi->graphics_dpm_level_count; i++) {
1647 			if ((table->entries[i].clk >= new_ps->levels[0].sclk) ||
1648 			    (i == (pi->graphics_dpm_level_count - 1))) {
1649 				pi->lowest_valid = i;
1650 				break;
1651 			}
1652 		}
1653 
1654 		for (i = pi->graphics_dpm_level_count - 1; i > 0; i--) {
1655 			if (table->entries[i].clk <= new_ps->levels[new_ps->num_levels - 1].sclk)
1656 				break;
1657 		}
1658 		pi->highest_valid = i;
1659 
1660 		if (pi->lowest_valid > pi->highest_valid) {
1661 			if ((new_ps->levels[0].sclk - table->entries[pi->highest_valid].clk) >
1662 			    (table->entries[pi->lowest_valid].clk - new_ps->levels[new_ps->num_levels - 1].sclk))
1663 				pi->highest_valid = pi->lowest_valid;
1664 			else
1665 				pi->lowest_valid =  pi->highest_valid;
1666 		}
1667 	} else {
1668 		struct sumo_sclk_voltage_mapping_table *table =
1669 			&pi->sys_info.sclk_voltage_mapping_table;
1670 
1671 		for (i = 0; i < (int)pi->graphics_dpm_level_count; i++) {
1672 			if (table->entries[i].sclk_frequency >= new_ps->levels[0].sclk ||
1673 			    i == (int)(pi->graphics_dpm_level_count - 1)) {
1674 				pi->lowest_valid = i;
1675 				break;
1676 			}
1677 		}
1678 
1679 		for (i = pi->graphics_dpm_level_count - 1; i > 0; i--) {
1680 			if (table->entries[i].sclk_frequency <=
1681 			    new_ps->levels[new_ps->num_levels - 1].sclk)
1682 				break;
1683 		}
1684 		pi->highest_valid = i;
1685 
1686 		if (pi->lowest_valid > pi->highest_valid) {
1687 			if ((new_ps->levels[0].sclk -
1688 			     table->entries[pi->highest_valid].sclk_frequency) >
1689 			    (table->entries[pi->lowest_valid].sclk_frequency -
1690 			     new_ps->levels[new_ps->num_levels -1].sclk))
1691 				pi->highest_valid = pi->lowest_valid;
1692 			else
1693 				pi->lowest_valid =  pi->highest_valid;
1694 		}
1695 	}
1696 }
1697 
1698 static int kv_update_dfs_bypass_settings(struct radeon_device *rdev,
1699 					 struct radeon_ps *new_rps)
1700 {
1701 	struct kv_ps *new_ps = kv_get_ps(new_rps);
1702 	struct kv_power_info *pi = kv_get_pi(rdev);
1703 	int ret = 0;
1704 	u8 clk_bypass_cntl;
1705 
1706 	if (pi->caps_enable_dfs_bypass) {
1707 		clk_bypass_cntl = new_ps->need_dfs_bypass ?
1708 			pi->graphics_level[pi->graphics_boot_level].ClkBypassCntl : 0;
1709 		ret = kv_copy_bytes_to_smc(rdev,
1710 					   (pi->dpm_table_start +
1711 					    offsetof(SMU7_Fusion_DpmTable, GraphicsLevel) +
1712 					    (pi->graphics_boot_level * sizeof(SMU7_Fusion_GraphicsLevel)) +
1713 					    offsetof(SMU7_Fusion_GraphicsLevel, ClkBypassCntl)),
1714 					   &clk_bypass_cntl,
1715 					   sizeof(u8), pi->sram_end);
1716 	}
1717 
1718 	return ret;
1719 }
1720 
1721 static int kv_enable_nb_dpm(struct radeon_device *rdev)
1722 {
1723 	struct kv_power_info *pi = kv_get_pi(rdev);
1724 	int ret = 0;
1725 
1726 	if (pi->enable_nb_dpm && !pi->nb_dpm_enabled) {
1727 		ret = kv_notify_message_to_smu(rdev, PPSMC_MSG_NBDPM_Enable);
1728 		if (ret == 0)
1729 			pi->nb_dpm_enabled = true;
1730 	}
1731 
1732 	return ret;
1733 }
1734 
1735 int kv_dpm_force_performance_level(struct radeon_device *rdev,
1736 				   enum radeon_dpm_forced_level level)
1737 {
1738 	int ret;
1739 
1740 	if (level == RADEON_DPM_FORCED_LEVEL_HIGH) {
1741 		ret = kv_force_dpm_highest(rdev);
1742 		if (ret)
1743 			return ret;
1744 	} else if (level == RADEON_DPM_FORCED_LEVEL_LOW) {
1745 		ret = kv_force_dpm_lowest(rdev);
1746 		if (ret)
1747 			return ret;
1748 	} else if (level == RADEON_DPM_FORCED_LEVEL_AUTO) {
1749 		ret = kv_unforce_levels(rdev);
1750 		if (ret)
1751 			return ret;
1752 	}
1753 
1754 	rdev->pm.dpm.forced_level = level;
1755 
1756 	return 0;
1757 }
1758 
1759 int kv_dpm_pre_set_power_state(struct radeon_device *rdev)
1760 {
1761 	struct kv_power_info *pi = kv_get_pi(rdev);
1762 	struct radeon_ps requested_ps = *rdev->pm.dpm.requested_ps;
1763 	struct radeon_ps *new_ps = &requested_ps;
1764 
1765 	kv_update_requested_ps(rdev, new_ps);
1766 
1767 	kv_apply_state_adjust_rules(rdev,
1768 				    &pi->requested_rps,
1769 				    &pi->current_rps);
1770 
1771 	return 0;
1772 }
1773 
1774 int kv_dpm_set_power_state(struct radeon_device *rdev)
1775 {
1776 	struct kv_power_info *pi = kv_get_pi(rdev);
1777 	struct radeon_ps *new_ps = &pi->requested_rps;
1778 	struct radeon_ps *old_ps = &pi->current_rps;
1779 	int ret;
1780 
1781 	if (pi->bapm_enable) {
1782 		ret = kv_smc_bapm_enable(rdev, rdev->pm.dpm.ac_power);
1783 		if (ret) {
1784 			DRM_ERROR("kv_smc_bapm_enable failed\n");
1785 			return ret;
1786 		}
1787 	}
1788 
1789 	if (rdev->family == CHIP_KABINI) {
1790 		if (pi->enable_dpm) {
1791 			kv_set_valid_clock_range(rdev, new_ps);
1792 			kv_update_dfs_bypass_settings(rdev, new_ps);
1793 			ret = kv_calculate_ds_divider(rdev);
1794 			if (ret) {
1795 				DRM_ERROR("kv_calculate_ds_divider failed\n");
1796 				return ret;
1797 			}
1798 			kv_calculate_nbps_level_settings(rdev);
1799 			kv_calculate_dpm_settings(rdev);
1800 			kv_force_lowest_valid(rdev);
1801 			kv_enable_new_levels(rdev);
1802 			kv_upload_dpm_settings(rdev);
1803 			kv_program_nbps_index_settings(rdev, new_ps);
1804 			kv_unforce_levels(rdev);
1805 			kv_set_enabled_levels(rdev);
1806 			kv_force_lowest_valid(rdev);
1807 			kv_unforce_levels(rdev);
1808 
1809 			ret = kv_update_vce_dpm(rdev, new_ps, old_ps);
1810 			if (ret) {
1811 				DRM_ERROR("kv_update_vce_dpm failed\n");
1812 				return ret;
1813 			}
1814 			kv_update_sclk_t(rdev);
1815 		}
1816 	} else {
1817 		if (pi->enable_dpm) {
1818 			kv_set_valid_clock_range(rdev, new_ps);
1819 			kv_update_dfs_bypass_settings(rdev, new_ps);
1820 			ret = kv_calculate_ds_divider(rdev);
1821 			if (ret) {
1822 				DRM_ERROR("kv_calculate_ds_divider failed\n");
1823 				return ret;
1824 			}
1825 			kv_calculate_nbps_level_settings(rdev);
1826 			kv_calculate_dpm_settings(rdev);
1827 			kv_freeze_sclk_dpm(rdev, true);
1828 			kv_upload_dpm_settings(rdev);
1829 			kv_program_nbps_index_settings(rdev, new_ps);
1830 			kv_freeze_sclk_dpm(rdev, false);
1831 			kv_set_enabled_levels(rdev);
1832 			ret = kv_update_vce_dpm(rdev, new_ps, old_ps);
1833 			if (ret) {
1834 				DRM_ERROR("kv_update_vce_dpm failed\n");
1835 				return ret;
1836 			}
1837 			kv_update_acp_boot_level(rdev);
1838 			kv_update_sclk_t(rdev);
1839 			kv_enable_nb_dpm(rdev);
1840 		}
1841 	}
1842 
1843 	return 0;
1844 }
1845 
1846 void kv_dpm_post_set_power_state(struct radeon_device *rdev)
1847 {
1848 	struct kv_power_info *pi = kv_get_pi(rdev);
1849 	struct radeon_ps *new_ps = &pi->requested_rps;
1850 
1851 	kv_update_current_ps(rdev, new_ps);
1852 }
1853 
1854 void kv_dpm_setup_asic(struct radeon_device *rdev)
1855 {
1856 	sumo_take_smu_control(rdev, true);
1857 	kv_init_powergate_state(rdev);
1858 	kv_init_sclk_t(rdev);
1859 }
1860 
1861 void kv_dpm_reset_asic(struct radeon_device *rdev)
1862 {
1863 	struct kv_power_info *pi = kv_get_pi(rdev);
1864 
1865 	if (rdev->family == CHIP_KABINI) {
1866 		kv_force_lowest_valid(rdev);
1867 		kv_init_graphics_levels(rdev);
1868 		kv_program_bootup_state(rdev);
1869 		kv_upload_dpm_settings(rdev);
1870 		kv_force_lowest_valid(rdev);
1871 		kv_unforce_levels(rdev);
1872 	} else {
1873 		kv_init_graphics_levels(rdev);
1874 		kv_program_bootup_state(rdev);
1875 		kv_freeze_sclk_dpm(rdev, true);
1876 		kv_upload_dpm_settings(rdev);
1877 		kv_freeze_sclk_dpm(rdev, false);
1878 		kv_set_enabled_level(rdev, pi->graphics_boot_level);
1879 	}
1880 }
1881 
1882 //XXX use sumo_dpm_display_configuration_changed
1883 
1884 static void kv_construct_max_power_limits_table(struct radeon_device *rdev,
1885 						struct radeon_clock_and_voltage_limits *table)
1886 {
1887 	struct kv_power_info *pi = kv_get_pi(rdev);
1888 
1889 	if (pi->sys_info.sclk_voltage_mapping_table.num_max_dpm_entries > 0) {
1890 		int idx = pi->sys_info.sclk_voltage_mapping_table.num_max_dpm_entries - 1;
1891 		table->sclk =
1892 			pi->sys_info.sclk_voltage_mapping_table.entries[idx].sclk_frequency;
1893 		table->vddc =
1894 			kv_convert_2bit_index_to_voltage(rdev,
1895 							 pi->sys_info.sclk_voltage_mapping_table.entries[idx].vid_2bit);
1896 	}
1897 
1898 	table->mclk = pi->sys_info.nbp_memory_clock[0];
1899 }
1900 
1901 static void kv_patch_voltage_values(struct radeon_device *rdev)
1902 {
1903 	int i;
1904 	struct radeon_uvd_clock_voltage_dependency_table *table =
1905 		&rdev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table;
1906 
1907 	if (table->count) {
1908 		for (i = 0; i < table->count; i++)
1909 			table->entries[i].v =
1910 				kv_convert_8bit_index_to_voltage(rdev,
1911 								 table->entries[i].v);
1912 	}
1913 
1914 }
1915 
1916 static void kv_construct_boot_state(struct radeon_device *rdev)
1917 {
1918 	struct kv_power_info *pi = kv_get_pi(rdev);
1919 
1920 	pi->boot_pl.sclk = pi->sys_info.bootup_sclk;
1921 	pi->boot_pl.vddc_index = pi->sys_info.bootup_nb_voltage_index;
1922 	pi->boot_pl.ds_divider_index = 0;
1923 	pi->boot_pl.ss_divider_index = 0;
1924 	pi->boot_pl.allow_gnb_slow = 1;
1925 	pi->boot_pl.force_nbp_state = 0;
1926 	pi->boot_pl.display_wm = 0;
1927 	pi->boot_pl.vce_wm = 0;
1928 }
1929 
1930 static int kv_force_dpm_highest(struct radeon_device *rdev)
1931 {
1932 	int ret;
1933 	u32 enable_mask, i;
1934 
1935 	ret = kv_dpm_get_enable_mask(rdev, &enable_mask);
1936 	if (ret)
1937 		return ret;
1938 
1939 	for (i = SMU7_MAX_LEVELS_GRAPHICS - 1; i > 0; i--) {
1940 		if (enable_mask & (1 << i))
1941 			break;
1942 	}
1943 
1944 	if (rdev->family == CHIP_KABINI)
1945 		return kv_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_DPM_ForceState, i);
1946 	else
1947 		return kv_set_enabled_level(rdev, i);
1948 }
1949 
1950 static int kv_force_dpm_lowest(struct radeon_device *rdev)
1951 {
1952 	int ret;
1953 	u32 enable_mask, i;
1954 
1955 	ret = kv_dpm_get_enable_mask(rdev, &enable_mask);
1956 	if (ret)
1957 		return ret;
1958 
1959 	for (i = 0; i < SMU7_MAX_LEVELS_GRAPHICS; i++) {
1960 		if (enable_mask & (1 << i))
1961 			break;
1962 	}
1963 
1964 	if (rdev->family == CHIP_KABINI)
1965 		return kv_send_msg_to_smc_with_parameter(rdev, PPSMC_MSG_DPM_ForceState, i);
1966 	else
1967 		return kv_set_enabled_level(rdev, i);
1968 }
1969 
1970 static u8 kv_get_sleep_divider_id_from_clock(struct radeon_device *rdev,
1971 					     u32 sclk, u32 min_sclk_in_sr)
1972 {
1973 	struct kv_power_info *pi = kv_get_pi(rdev);
1974 	u32 i;
1975 	u32 temp;
1976 	u32 min = (min_sclk_in_sr > KV_MINIMUM_ENGINE_CLOCK) ?
1977 		min_sclk_in_sr : KV_MINIMUM_ENGINE_CLOCK;
1978 
1979 	if (sclk < min)
1980 		return 0;
1981 
1982 	if (!pi->caps_sclk_ds)
1983 		return 0;
1984 
1985 	for (i = KV_MAX_DEEPSLEEP_DIVIDER_ID; i > 0; i--) {
1986 		temp = sclk / sumo_get_sleep_divider_from_id(i);
1987 		if (temp >= min)
1988 			break;
1989 	}
1990 
1991 	return (u8)i;
1992 }
1993 
1994 static int kv_get_high_voltage_limit(struct radeon_device *rdev, int *limit)
1995 {
1996 	struct kv_power_info *pi = kv_get_pi(rdev);
1997 	struct radeon_clock_voltage_dependency_table *table =
1998 		&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
1999 	int i;
2000 
2001 	if (table && table->count) {
2002 		for (i = table->count - 1; i >= 0; i--) {
2003 			if (pi->high_voltage_t &&
2004 			    (kv_convert_8bit_index_to_voltage(rdev, table->entries[i].v) <=
2005 			     pi->high_voltage_t)) {
2006 				*limit = i;
2007 				return 0;
2008 			}
2009 		}
2010 	} else {
2011 		struct sumo_sclk_voltage_mapping_table *table =
2012 			&pi->sys_info.sclk_voltage_mapping_table;
2013 
2014 		for (i = table->num_max_dpm_entries - 1; i >= 0; i--) {
2015 			if (pi->high_voltage_t &&
2016 			    (kv_convert_2bit_index_to_voltage(rdev, table->entries[i].vid_2bit) <=
2017 			     pi->high_voltage_t)) {
2018 				*limit = i;
2019 				return 0;
2020 			}
2021 		}
2022 	}
2023 
2024 	*limit = 0;
2025 	return 0;
2026 }
2027 
2028 static void kv_apply_state_adjust_rules(struct radeon_device *rdev,
2029 					struct radeon_ps *new_rps,
2030 					struct radeon_ps *old_rps)
2031 {
2032 	struct kv_ps *ps = kv_get_ps(new_rps);
2033 	struct kv_power_info *pi = kv_get_pi(rdev);
2034 	u32 min_sclk = 10000; /* ??? */
2035 	u32 sclk, mclk = 0;
2036 	int i, limit;
2037 	bool force_high;
2038 	struct radeon_clock_voltage_dependency_table *table =
2039 		&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
2040 	u32 stable_p_state_sclk = 0;
2041 	struct radeon_clock_and_voltage_limits *max_limits =
2042 		&rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
2043 
2044 	if (new_rps->vce_active) {
2045 		new_rps->evclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].evclk;
2046 		new_rps->ecclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].ecclk;
2047 	} else {
2048 		new_rps->evclk = 0;
2049 		new_rps->ecclk = 0;
2050 	}
2051 
2052 	mclk = max_limits->mclk;
2053 	sclk = min_sclk;
2054 
2055 	if (pi->caps_stable_p_state) {
2056 		stable_p_state_sclk = (max_limits->sclk * 75) / 100;
2057 
2058 		for (i = table->count - 1; i >= 0; i++) {
2059 			if (stable_p_state_sclk >= table->entries[i].clk) {
2060 				stable_p_state_sclk = table->entries[i].clk;
2061 				break;
2062 			}
2063 		}
2064 
2065 		if (i > 0)
2066 			stable_p_state_sclk = table->entries[0].clk;
2067 
2068 		sclk = stable_p_state_sclk;
2069 	}
2070 
2071 	if (new_rps->vce_active) {
2072 		if (sclk < rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].sclk)
2073 			sclk = rdev->pm.dpm.vce_states[rdev->pm.dpm.vce_level].sclk;
2074 	}
2075 
2076 	ps->need_dfs_bypass = true;
2077 
2078 	for (i = 0; i < ps->num_levels; i++) {
2079 		if (ps->levels[i].sclk < sclk)
2080 			ps->levels[i].sclk = sclk;
2081 	}
2082 
2083 	if (table && table->count) {
2084 		for (i = 0; i < ps->num_levels; i++) {
2085 			if (pi->high_voltage_t &&
2086 			    (pi->high_voltage_t <
2087 			     kv_convert_8bit_index_to_voltage(rdev, ps->levels[i].vddc_index))) {
2088 				kv_get_high_voltage_limit(rdev, &limit);
2089 				ps->levels[i].sclk = table->entries[limit].clk;
2090 			}
2091 		}
2092 	} else {
2093 		struct sumo_sclk_voltage_mapping_table *table =
2094 			&pi->sys_info.sclk_voltage_mapping_table;
2095 
2096 		for (i = 0; i < ps->num_levels; i++) {
2097 			if (pi->high_voltage_t &&
2098 			    (pi->high_voltage_t <
2099 			     kv_convert_8bit_index_to_voltage(rdev, ps->levels[i].vddc_index))) {
2100 				kv_get_high_voltage_limit(rdev, &limit);
2101 				ps->levels[i].sclk = table->entries[limit].sclk_frequency;
2102 			}
2103 		}
2104 	}
2105 
2106 	if (pi->caps_stable_p_state) {
2107 		for (i = 0; i < ps->num_levels; i++) {
2108 			ps->levels[i].sclk = stable_p_state_sclk;
2109 		}
2110 	}
2111 
2112 	pi->video_start = new_rps->dclk || new_rps->vclk ||
2113 		new_rps->evclk || new_rps->ecclk;
2114 
2115 	if ((new_rps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) ==
2116 	    ATOM_PPLIB_CLASSIFICATION_UI_BATTERY)
2117 		pi->battery_state = true;
2118 	else
2119 		pi->battery_state = false;
2120 
2121 	if (rdev->family == CHIP_KABINI) {
2122 		ps->dpm0_pg_nb_ps_lo = 0x1;
2123 		ps->dpm0_pg_nb_ps_hi = 0x0;
2124 		ps->dpmx_nb_ps_lo = 0x1;
2125 		ps->dpmx_nb_ps_hi = 0x0;
2126 	} else {
2127 		ps->dpm0_pg_nb_ps_lo = 0x3;
2128 		ps->dpm0_pg_nb_ps_hi = 0x0;
2129 		ps->dpmx_nb_ps_lo = 0x3;
2130 		ps->dpmx_nb_ps_hi = 0x0;
2131 
2132 		if (pi->sys_info.nb_dpm_enable) {
2133 			force_high = (mclk >= pi->sys_info.nbp_memory_clock[3]) ||
2134 				pi->video_start || (rdev->pm.dpm.new_active_crtc_count >= 3) ||
2135 				pi->disable_nb_ps3_in_battery;
2136 			ps->dpm0_pg_nb_ps_lo = force_high ? 0x2 : 0x3;
2137 			ps->dpm0_pg_nb_ps_hi = 0x2;
2138 			ps->dpmx_nb_ps_lo = force_high ? 0x2 : 0x3;
2139 			ps->dpmx_nb_ps_hi = 0x2;
2140 		}
2141 	}
2142 }
2143 
2144 static void kv_dpm_power_level_enabled_for_throttle(struct radeon_device *rdev,
2145 						    u32 index, bool enable)
2146 {
2147 	struct kv_power_info *pi = kv_get_pi(rdev);
2148 
2149 	pi->graphics_level[index].EnabledForThrottle = enable ? 1 : 0;
2150 }
2151 
2152 static int kv_calculate_ds_divider(struct radeon_device *rdev)
2153 {
2154 	struct kv_power_info *pi = kv_get_pi(rdev);
2155 	u32 sclk_in_sr = 10000; /* ??? */
2156 	u32 i;
2157 
2158 	if (pi->lowest_valid > pi->highest_valid)
2159 		return -EINVAL;
2160 
2161 	for (i = pi->lowest_valid; i <= pi->highest_valid; i++) {
2162 		pi->graphics_level[i].DeepSleepDivId =
2163 			kv_get_sleep_divider_id_from_clock(rdev,
2164 							   be32_to_cpu(pi->graphics_level[i].SclkFrequency),
2165 							   sclk_in_sr);
2166 	}
2167 	return 0;
2168 }
2169 
2170 static int kv_calculate_nbps_level_settings(struct radeon_device *rdev)
2171 {
2172 	struct kv_power_info *pi = kv_get_pi(rdev);
2173 	u32 i;
2174 	bool force_high;
2175 	struct radeon_clock_and_voltage_limits *max_limits =
2176 		&rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac;
2177 	u32 mclk = max_limits->mclk;
2178 
2179 	if (pi->lowest_valid > pi->highest_valid)
2180 		return -EINVAL;
2181 
2182 	if (rdev->family == CHIP_KABINI) {
2183 		for (i = pi->lowest_valid; i <= pi->highest_valid; i++) {
2184 			pi->graphics_level[i].GnbSlow = 1;
2185 			pi->graphics_level[i].ForceNbPs1 = 0;
2186 			pi->graphics_level[i].UpH = 0;
2187 		}
2188 
2189 		if (!pi->sys_info.nb_dpm_enable)
2190 			return 0;
2191 
2192 		force_high = ((mclk >= pi->sys_info.nbp_memory_clock[3]) ||
2193 			      (rdev->pm.dpm.new_active_crtc_count >= 3) || pi->video_start);
2194 
2195 		if (force_high) {
2196 			for (i = pi->lowest_valid; i <= pi->highest_valid; i++)
2197 				pi->graphics_level[i].GnbSlow = 0;
2198 		} else {
2199 			if (pi->battery_state)
2200 				pi->graphics_level[0].ForceNbPs1 = 1;
2201 
2202 			pi->graphics_level[1].GnbSlow = 0;
2203 			pi->graphics_level[2].GnbSlow = 0;
2204 			pi->graphics_level[3].GnbSlow = 0;
2205 			pi->graphics_level[4].GnbSlow = 0;
2206 		}
2207 	} else {
2208 		for (i = pi->lowest_valid; i <= pi->highest_valid; i++) {
2209 			pi->graphics_level[i].GnbSlow = 1;
2210 			pi->graphics_level[i].ForceNbPs1 = 0;
2211 			pi->graphics_level[i].UpH = 0;
2212 		}
2213 
2214 		if (pi->sys_info.nb_dpm_enable && pi->battery_state) {
2215 			pi->graphics_level[pi->lowest_valid].UpH = 0x28;
2216 			pi->graphics_level[pi->lowest_valid].GnbSlow = 0;
2217 			if (pi->lowest_valid != pi->highest_valid)
2218 				pi->graphics_level[pi->lowest_valid].ForceNbPs1 = 1;
2219 		}
2220 	}
2221 	return 0;
2222 }
2223 
2224 static int kv_calculate_dpm_settings(struct radeon_device *rdev)
2225 {
2226 	struct kv_power_info *pi = kv_get_pi(rdev);
2227 	u32 i;
2228 
2229 	if (pi->lowest_valid > pi->highest_valid)
2230 		return -EINVAL;
2231 
2232 	for (i = pi->lowest_valid; i <= pi->highest_valid; i++)
2233 		pi->graphics_level[i].DisplayWatermark = (i == pi->highest_valid) ? 1 : 0;
2234 
2235 	return 0;
2236 }
2237 
2238 static void kv_init_graphics_levels(struct radeon_device *rdev)
2239 {
2240 	struct kv_power_info *pi = kv_get_pi(rdev);
2241 	u32 i;
2242 	struct radeon_clock_voltage_dependency_table *table =
2243 		&rdev->pm.dpm.dyn_state.vddc_dependency_on_sclk;
2244 
2245 	if (table && table->count) {
2246 		u32 vid_2bit;
2247 
2248 		pi->graphics_dpm_level_count = 0;
2249 		for (i = 0; i < table->count; i++) {
2250 			if (pi->high_voltage_t &&
2251 			    (pi->high_voltage_t <
2252 			     kv_convert_8bit_index_to_voltage(rdev, table->entries[i].v)))
2253 				break;
2254 
2255 			kv_set_divider_value(rdev, i, table->entries[i].clk);
2256 			vid_2bit = sumo_convert_vid7_to_vid2(rdev,
2257 							     &pi->sys_info.vid_mapping_table,
2258 							     table->entries[i].v);
2259 			kv_set_vid(rdev, i, vid_2bit);
2260 			kv_set_at(rdev, i, pi->at[i]);
2261 			kv_dpm_power_level_enabled_for_throttle(rdev, i, true);
2262 			pi->graphics_dpm_level_count++;
2263 		}
2264 	} else {
2265 		struct sumo_sclk_voltage_mapping_table *table =
2266 			&pi->sys_info.sclk_voltage_mapping_table;
2267 
2268 		pi->graphics_dpm_level_count = 0;
2269 		for (i = 0; i < table->num_max_dpm_entries; i++) {
2270 			if (pi->high_voltage_t &&
2271 			    pi->high_voltage_t <
2272 			    kv_convert_2bit_index_to_voltage(rdev, table->entries[i].vid_2bit))
2273 				break;
2274 
2275 			kv_set_divider_value(rdev, i, table->entries[i].sclk_frequency);
2276 			kv_set_vid(rdev, i, table->entries[i].vid_2bit);
2277 			kv_set_at(rdev, i, pi->at[i]);
2278 			kv_dpm_power_level_enabled_for_throttle(rdev, i, true);
2279 			pi->graphics_dpm_level_count++;
2280 		}
2281 	}
2282 
2283 	for (i = 0; i < SMU7_MAX_LEVELS_GRAPHICS; i++)
2284 		kv_dpm_power_level_enable(rdev, i, false);
2285 }
2286 
2287 static void kv_enable_new_levels(struct radeon_device *rdev)
2288 {
2289 	struct kv_power_info *pi = kv_get_pi(rdev);
2290 	u32 i;
2291 
2292 	for (i = 0; i < SMU7_MAX_LEVELS_GRAPHICS; i++) {
2293 		if (i >= pi->lowest_valid && i <= pi->highest_valid)
2294 			kv_dpm_power_level_enable(rdev, i, true);
2295 	}
2296 }
2297 
2298 static int kv_set_enabled_level(struct radeon_device *rdev, u32 level)
2299 {
2300 	u32 new_mask = (1 << level);
2301 
2302 	return kv_send_msg_to_smc_with_parameter(rdev,
2303 						 PPSMC_MSG_SCLKDPM_SetEnabledMask,
2304 						 new_mask);
2305 }
2306 
2307 static int kv_set_enabled_levels(struct radeon_device *rdev)
2308 {
2309 	struct kv_power_info *pi = kv_get_pi(rdev);
2310 	u32 i, new_mask = 0;
2311 
2312 	for (i = pi->lowest_valid; i <= pi->highest_valid; i++)
2313 		new_mask |= (1 << i);
2314 
2315 	return kv_send_msg_to_smc_with_parameter(rdev,
2316 						 PPSMC_MSG_SCLKDPM_SetEnabledMask,
2317 						 new_mask);
2318 }
2319 
2320 static void kv_program_nbps_index_settings(struct radeon_device *rdev,
2321 					   struct radeon_ps *new_rps)
2322 {
2323 	struct kv_ps *new_ps = kv_get_ps(new_rps);
2324 	struct kv_power_info *pi = kv_get_pi(rdev);
2325 	u32 nbdpmconfig1;
2326 
2327 	if (rdev->family == CHIP_KABINI)
2328 		return;
2329 
2330 	if (pi->sys_info.nb_dpm_enable) {
2331 		nbdpmconfig1 = RREG32_SMC(NB_DPM_CONFIG_1);
2332 		nbdpmconfig1 &= ~(Dpm0PgNbPsLo_MASK | Dpm0PgNbPsHi_MASK |
2333 				  DpmXNbPsLo_MASK | DpmXNbPsHi_MASK);
2334 		nbdpmconfig1 |= (Dpm0PgNbPsLo(new_ps->dpm0_pg_nb_ps_lo) |
2335 				 Dpm0PgNbPsHi(new_ps->dpm0_pg_nb_ps_hi) |
2336 				 DpmXNbPsLo(new_ps->dpmx_nb_ps_lo) |
2337 				 DpmXNbPsHi(new_ps->dpmx_nb_ps_hi));
2338 		WREG32_SMC(NB_DPM_CONFIG_1, nbdpmconfig1);
2339 	}
2340 }
2341 
2342 static int kv_set_thermal_temperature_range(struct radeon_device *rdev,
2343 					    int min_temp, int max_temp)
2344 {
2345 	int low_temp = 0 * 1000;
2346 	int high_temp = 255 * 1000;
2347 	u32 tmp;
2348 
2349 	if (low_temp < min_temp)
2350 		low_temp = min_temp;
2351 	if (high_temp > max_temp)
2352 		high_temp = max_temp;
2353 	if (high_temp < low_temp) {
2354 		DRM_ERROR("invalid thermal range: %d - %d\n", low_temp, high_temp);
2355 		return -EINVAL;
2356 	}
2357 
2358 	tmp = RREG32_SMC(CG_THERMAL_INT_CTRL);
2359 	tmp &= ~(DIG_THERM_INTH_MASK | DIG_THERM_INTL_MASK);
2360 	tmp |= (DIG_THERM_INTH(49 + (high_temp / 1000)) |
2361 		DIG_THERM_INTL(49 + (low_temp / 1000)));
2362 	WREG32_SMC(CG_THERMAL_INT_CTRL, tmp);
2363 
2364 	rdev->pm.dpm.thermal.min_temp = low_temp;
2365 	rdev->pm.dpm.thermal.max_temp = high_temp;
2366 
2367 	return 0;
2368 }
2369 
2370 union igp_info {
2371 	struct _ATOM_INTEGRATED_SYSTEM_INFO info;
2372 	struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_2;
2373 	struct _ATOM_INTEGRATED_SYSTEM_INFO_V5 info_5;
2374 	struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 info_6;
2375 	struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_7 info_7;
2376 	struct _ATOM_INTEGRATED_SYSTEM_INFO_V1_8 info_8;
2377 };
2378 
2379 static int kv_parse_sys_info_table(struct radeon_device *rdev)
2380 {
2381 	struct kv_power_info *pi = kv_get_pi(rdev);
2382 	struct radeon_mode_info *mode_info = &rdev->mode_info;
2383 	int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
2384 	union igp_info *igp_info;
2385 	u8 frev, crev;
2386 	u16 data_offset;
2387 	int i;
2388 
2389 	if (atom_parse_data_header(mode_info->atom_context, index, NULL,
2390 				   &frev, &crev, &data_offset)) {
2391 		igp_info = (union igp_info *)(mode_info->atom_context->bios +
2392 					      data_offset);
2393 
2394 		if (crev != 8) {
2395 			DRM_ERROR("Unsupported IGP table: %d %d\n", frev, crev);
2396 			return -EINVAL;
2397 		}
2398 		pi->sys_info.bootup_sclk = le32_to_cpu(igp_info->info_8.ulBootUpEngineClock);
2399 		pi->sys_info.bootup_uma_clk = le32_to_cpu(igp_info->info_8.ulBootUpUMAClock);
2400 		pi->sys_info.bootup_nb_voltage_index =
2401 			le16_to_cpu(igp_info->info_8.usBootUpNBVoltage);
2402 		if (igp_info->info_8.ucHtcTmpLmt == 0)
2403 			pi->sys_info.htc_tmp_lmt = 203;
2404 		else
2405 			pi->sys_info.htc_tmp_lmt = igp_info->info_8.ucHtcTmpLmt;
2406 		if (igp_info->info_8.ucHtcHystLmt == 0)
2407 			pi->sys_info.htc_hyst_lmt = 5;
2408 		else
2409 			pi->sys_info.htc_hyst_lmt = igp_info->info_8.ucHtcHystLmt;
2410 		if (pi->sys_info.htc_tmp_lmt <= pi->sys_info.htc_hyst_lmt) {
2411 			DRM_ERROR("The htcTmpLmt should be larger than htcHystLmt.\n");
2412 		}
2413 
2414 		if (le32_to_cpu(igp_info->info_8.ulSystemConfig) & (1 << 3))
2415 			pi->sys_info.nb_dpm_enable = true;
2416 		else
2417 			pi->sys_info.nb_dpm_enable = false;
2418 
2419 		for (i = 0; i < KV_NUM_NBPSTATES; i++) {
2420 			pi->sys_info.nbp_memory_clock[i] =
2421 				le32_to_cpu(igp_info->info_8.ulNbpStateMemclkFreq[i]);
2422 			pi->sys_info.nbp_n_clock[i] =
2423 				le32_to_cpu(igp_info->info_8.ulNbpStateNClkFreq[i]);
2424 		}
2425 		if (le32_to_cpu(igp_info->info_8.ulGPUCapInfo) &
2426 		    SYS_INFO_GPUCAPS__ENABEL_DFS_BYPASS)
2427 			pi->caps_enable_dfs_bypass = true;
2428 
2429 		sumo_construct_sclk_voltage_mapping_table(rdev,
2430 							  &pi->sys_info.sclk_voltage_mapping_table,
2431 							  igp_info->info_8.sAvail_SCLK);
2432 
2433 		sumo_construct_vid_mapping_table(rdev,
2434 						 &pi->sys_info.vid_mapping_table,
2435 						 igp_info->info_8.sAvail_SCLK);
2436 
2437 		kv_construct_max_power_limits_table(rdev,
2438 						    &rdev->pm.dpm.dyn_state.max_clock_voltage_on_ac);
2439 	}
2440 	return 0;
2441 }
2442 
2443 union power_info {
2444 	struct _ATOM_POWERPLAY_INFO info;
2445 	struct _ATOM_POWERPLAY_INFO_V2 info_2;
2446 	struct _ATOM_POWERPLAY_INFO_V3 info_3;
2447 	struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
2448 	struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
2449 	struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
2450 };
2451 
2452 union pplib_clock_info {
2453 	struct _ATOM_PPLIB_R600_CLOCK_INFO r600;
2454 	struct _ATOM_PPLIB_RS780_CLOCK_INFO rs780;
2455 	struct _ATOM_PPLIB_EVERGREEN_CLOCK_INFO evergreen;
2456 	struct _ATOM_PPLIB_SUMO_CLOCK_INFO sumo;
2457 };
2458 
2459 union pplib_power_state {
2460 	struct _ATOM_PPLIB_STATE v1;
2461 	struct _ATOM_PPLIB_STATE_V2 v2;
2462 };
2463 
2464 static void kv_patch_boot_state(struct radeon_device *rdev,
2465 				struct kv_ps *ps)
2466 {
2467 	struct kv_power_info *pi = kv_get_pi(rdev);
2468 
2469 	ps->num_levels = 1;
2470 	ps->levels[0] = pi->boot_pl;
2471 }
2472 
2473 static void kv_parse_pplib_non_clock_info(struct radeon_device *rdev,
2474 					  struct radeon_ps *rps,
2475 					  struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info,
2476 					  u8 table_rev)
2477 {
2478 	struct kv_ps *ps = kv_get_ps(rps);
2479 
2480 	rps->caps = le32_to_cpu(non_clock_info->ulCapsAndSettings);
2481 	rps->class = le16_to_cpu(non_clock_info->usClassification);
2482 	rps->class2 = le16_to_cpu(non_clock_info->usClassification2);
2483 
2484 	if (ATOM_PPLIB_NONCLOCKINFO_VER1 < table_rev) {
2485 		rps->vclk = le32_to_cpu(non_clock_info->ulVCLK);
2486 		rps->dclk = le32_to_cpu(non_clock_info->ulDCLK);
2487 	} else {
2488 		rps->vclk = 0;
2489 		rps->dclk = 0;
2490 	}
2491 
2492 	if (rps->class & ATOM_PPLIB_CLASSIFICATION_BOOT) {
2493 		rdev->pm.dpm.boot_ps = rps;
2494 		kv_patch_boot_state(rdev, ps);
2495 	}
2496 	if (rps->class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
2497 		rdev->pm.dpm.uvd_ps = rps;
2498 }
2499 
2500 static void kv_parse_pplib_clock_info(struct radeon_device *rdev,
2501 				      struct radeon_ps *rps, int index,
2502 					union pplib_clock_info *clock_info)
2503 {
2504 	struct kv_power_info *pi = kv_get_pi(rdev);
2505 	struct kv_ps *ps = kv_get_ps(rps);
2506 	struct kv_pl *pl = &ps->levels[index];
2507 	u32 sclk;
2508 
2509 	sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
2510 	sclk |= clock_info->sumo.ucEngineClockHigh << 16;
2511 	pl->sclk = sclk;
2512 	pl->vddc_index = clock_info->sumo.vddcIndex;
2513 
2514 	ps->num_levels = index + 1;
2515 
2516 	if (pi->caps_sclk_ds) {
2517 		pl->ds_divider_index = 5;
2518 		pl->ss_divider_index = 5;
2519 	}
2520 }
2521 
2522 static int kv_parse_power_table(struct radeon_device *rdev)
2523 {
2524 	struct radeon_mode_info *mode_info = &rdev->mode_info;
2525 	struct _ATOM_PPLIB_NONCLOCK_INFO *non_clock_info;
2526 	union pplib_power_state *power_state;
2527 	int i, j, k, non_clock_array_index, clock_array_index;
2528 	union pplib_clock_info *clock_info;
2529 	struct _StateArray *state_array;
2530 	struct _ClockInfoArray *clock_info_array;
2531 	struct _NonClockInfoArray *non_clock_info_array;
2532 	union power_info *power_info;
2533 	int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
2534         u16 data_offset;
2535 	u8 frev, crev;
2536 	u8 *power_state_offset;
2537 	struct kv_ps *ps;
2538 
2539 	if (!atom_parse_data_header(mode_info->atom_context, index, NULL,
2540 				   &frev, &crev, &data_offset))
2541 		return -EINVAL;
2542 	power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
2543 
2544 	state_array = (struct _StateArray *)
2545 		(mode_info->atom_context->bios + data_offset +
2546 		 le16_to_cpu(power_info->pplib.usStateArrayOffset));
2547 	clock_info_array = (struct _ClockInfoArray *)
2548 		(mode_info->atom_context->bios + data_offset +
2549 		 le16_to_cpu(power_info->pplib.usClockInfoArrayOffset));
2550 	non_clock_info_array = (struct _NonClockInfoArray *)
2551 		(mode_info->atom_context->bios + data_offset +
2552 		 le16_to_cpu(power_info->pplib.usNonClockInfoArrayOffset));
2553 
2554 	rdev->pm.dpm.ps = kzalloc(sizeof(struct radeon_ps) *
2555 				  state_array->ucNumEntries, GFP_KERNEL);
2556 	if (!rdev->pm.dpm.ps)
2557 		return -ENOMEM;
2558 	power_state_offset = (u8 *)state_array->states;
2559 	for (i = 0; i < state_array->ucNumEntries; i++) {
2560 		u8 *idx;
2561 		power_state = (union pplib_power_state *)power_state_offset;
2562 		non_clock_array_index = power_state->v2.nonClockInfoIndex;
2563 		non_clock_info = (struct _ATOM_PPLIB_NONCLOCK_INFO *)
2564 			&non_clock_info_array->nonClockInfo[non_clock_array_index];
2565 		if (!rdev->pm.power_state[i].clock_info)
2566 			return -EINVAL;
2567 		ps = kzalloc(sizeof(struct kv_ps), GFP_KERNEL);
2568 		if (ps == NULL) {
2569 			kfree(rdev->pm.dpm.ps);
2570 			return -ENOMEM;
2571 		}
2572 		rdev->pm.dpm.ps[i].ps_priv = ps;
2573 		k = 0;
2574 		idx = (u8 *)&power_state->v2.clockInfoIndex[0];
2575 		for (j = 0; j < power_state->v2.ucNumDPMLevels; j++) {
2576 			clock_array_index = idx[j];
2577 			if (clock_array_index >= clock_info_array->ucNumEntries)
2578 				continue;
2579 			if (k >= SUMO_MAX_HARDWARE_POWERLEVELS)
2580 				break;
2581 			clock_info = (union pplib_clock_info *)
2582 				((u8 *)&clock_info_array->clockInfo[0] +
2583 				 (clock_array_index * clock_info_array->ucEntrySize));
2584 			kv_parse_pplib_clock_info(rdev,
2585 						  &rdev->pm.dpm.ps[i], k,
2586 						  clock_info);
2587 			k++;
2588 		}
2589 		kv_parse_pplib_non_clock_info(rdev, &rdev->pm.dpm.ps[i],
2590 					      non_clock_info,
2591 					      non_clock_info_array->ucEntrySize);
2592 		power_state_offset += 2 + power_state->v2.ucNumDPMLevels;
2593 	}
2594 	rdev->pm.dpm.num_ps = state_array->ucNumEntries;
2595 
2596 	/* fill in the vce power states */
2597 	for (i = 0; i < RADEON_MAX_VCE_LEVELS; i++) {
2598 		u32 sclk;
2599 		clock_array_index = rdev->pm.dpm.vce_states[i].clk_idx;
2600 		clock_info = (union pplib_clock_info *)
2601 			&clock_info_array->clockInfo[clock_array_index * clock_info_array->ucEntrySize];
2602 		sclk = le16_to_cpu(clock_info->sumo.usEngineClockLow);
2603 		sclk |= clock_info->sumo.ucEngineClockHigh << 16;
2604 		rdev->pm.dpm.vce_states[i].sclk = sclk;
2605 		rdev->pm.dpm.vce_states[i].mclk = 0;
2606 	}
2607 
2608 	return 0;
2609 }
2610 
2611 int kv_dpm_init(struct radeon_device *rdev)
2612 {
2613 	struct kv_power_info *pi;
2614 	int ret, i;
2615 
2616 	pi = kzalloc(sizeof(struct kv_power_info), GFP_KERNEL);
2617 	if (pi == NULL)
2618 		return -ENOMEM;
2619 	rdev->pm.dpm.priv = pi;
2620 
2621 	ret = r600_get_platform_caps(rdev);
2622 	if (ret)
2623 		return ret;
2624 
2625 	ret = r600_parse_extended_power_table(rdev);
2626 	if (ret)
2627 		return ret;
2628 
2629 	for (i = 0; i < SUMO_MAX_HARDWARE_POWERLEVELS; i++)
2630 		pi->at[i] = TRINITY_AT_DFLT;
2631 
2632         pi->sram_end = SMC_RAM_END;
2633 
2634 	if (rdev->family == CHIP_KABINI)
2635 		pi->high_voltage_t = 4001;
2636 
2637 	pi->enable_nb_dpm = true;
2638 
2639 	pi->caps_power_containment = true;
2640 	pi->caps_cac = true;
2641 	pi->enable_didt = false;
2642 	if (pi->enable_didt) {
2643 		pi->caps_sq_ramping = true;
2644 		pi->caps_db_ramping = true;
2645 		pi->caps_td_ramping = true;
2646 		pi->caps_tcp_ramping = true;
2647 	}
2648 
2649 	pi->caps_sclk_ds = true;
2650 	pi->enable_auto_thermal_throttling = true;
2651 	pi->disable_nb_ps3_in_battery = false;
2652 	pi->bapm_enable = false;
2653 	pi->voltage_drop_t = 0;
2654 	pi->caps_sclk_throttle_low_notification = false;
2655 	pi->caps_fps = false; /* true? */
2656 	pi->caps_uvd_pg = true;
2657 	pi->caps_uvd_dpm = true;
2658 	pi->caps_vce_pg = false; /* XXX true */
2659 	pi->caps_samu_pg = false;
2660 	pi->caps_acp_pg = false;
2661 	pi->caps_stable_p_state = false;
2662 
2663 	ret = kv_parse_sys_info_table(rdev);
2664 	if (ret)
2665 		return ret;
2666 
2667 	kv_patch_voltage_values(rdev);
2668 	kv_construct_boot_state(rdev);
2669 
2670 	ret = kv_parse_power_table(rdev);
2671 	if (ret)
2672 		return ret;
2673 
2674 	pi->enable_dpm = true;
2675 
2676 	return 0;
2677 }
2678 
2679 void kv_dpm_debugfs_print_current_performance_level(struct radeon_device *rdev,
2680 						    struct seq_file *m)
2681 {
2682 	struct kv_power_info *pi = kv_get_pi(rdev);
2683 	u32 current_index =
2684 		(RREG32_SMC(TARGET_AND_CURRENT_PROFILE_INDEX) & CURR_SCLK_INDEX_MASK) >>
2685 		CURR_SCLK_INDEX_SHIFT;
2686 	u32 sclk, tmp;
2687 	u16 vddc;
2688 
2689 	if (current_index >= SMU__NUM_SCLK_DPM_STATE) {
2690 		seq_printf(m, "invalid dpm profile %d\n", current_index);
2691 	} else {
2692 		sclk = be32_to_cpu(pi->graphics_level[current_index].SclkFrequency);
2693 		tmp = (RREG32_SMC(SMU_VOLTAGE_STATUS) & SMU_VOLTAGE_CURRENT_LEVEL_MASK) >>
2694 			SMU_VOLTAGE_CURRENT_LEVEL_SHIFT;
2695 		vddc = kv_convert_8bit_index_to_voltage(rdev, (u16)tmp);
2696 		seq_printf(m, "power level %d    sclk: %u vddc: %u\n",
2697 			   current_index, sclk, vddc);
2698 	}
2699 }
2700 
2701 void kv_dpm_print_power_state(struct radeon_device *rdev,
2702 			      struct radeon_ps *rps)
2703 {
2704 	int i;
2705 	struct kv_ps *ps = kv_get_ps(rps);
2706 
2707 	r600_dpm_print_class_info(rps->class, rps->class2);
2708 	r600_dpm_print_cap_info(rps->caps);
2709 	printk("\tuvd    vclk: %d dclk: %d\n", rps->vclk, rps->dclk);
2710 	for (i = 0; i < ps->num_levels; i++) {
2711 		struct kv_pl *pl = &ps->levels[i];
2712 		printk("\t\tpower level %d    sclk: %u vddc: %u\n",
2713 		       i, pl->sclk,
2714 		       kv_convert_8bit_index_to_voltage(rdev, pl->vddc_index));
2715 	}
2716 	r600_dpm_print_ps_status(rdev, rps);
2717 }
2718 
2719 void kv_dpm_fini(struct radeon_device *rdev)
2720 {
2721 	int i;
2722 
2723 	for (i = 0; i < rdev->pm.dpm.num_ps; i++) {
2724 		kfree(rdev->pm.dpm.ps[i].ps_priv);
2725 	}
2726 	kfree(rdev->pm.dpm.ps);
2727 	kfree(rdev->pm.dpm.priv);
2728 	r600_free_extended_power_table(rdev);
2729 }
2730 
2731 void kv_dpm_display_configuration_changed(struct radeon_device *rdev)
2732 {
2733 
2734 }
2735 
2736 u32 kv_dpm_get_sclk(struct radeon_device *rdev, bool low)
2737 {
2738 	struct kv_power_info *pi = kv_get_pi(rdev);
2739 	struct kv_ps *requested_state = kv_get_ps(&pi->requested_rps);
2740 
2741 	if (low)
2742 		return requested_state->levels[0].sclk;
2743 	else
2744 		return requested_state->levels[requested_state->num_levels - 1].sclk;
2745 }
2746 
2747 u32 kv_dpm_get_mclk(struct radeon_device *rdev, bool low)
2748 {
2749 	struct kv_power_info *pi = kv_get_pi(rdev);
2750 
2751 	return pi->sys_info.bootup_uma_clk;
2752 }
2753 
2754