blob: 696012c78e3ef324c5e34436c1db3eff8c1a9e00 [file] [log] [blame]
Jammy Zhou3bace352015-07-21 21:18:15 +08001/*
2 * Copyright 2015 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#include <linux/types.h>
24#include <linux/kernel.h>
25#include <linux/slab.h>
26
27#include "processpptables.h"
28#include <atom-types.h>
29#include <atombios.h>
Alex Deuchera71e06d2015-12-11 12:32:55 -050030#include "pp_debug.h"
Jammy Zhou3bace352015-07-21 21:18:15 +080031#include "pptable.h"
32#include "power_state.h"
33#include "hwmgr.h"
34#include "hardwaremanager.h"
35
36
37#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V2 12
38#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V3 14
39#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V4 16
40#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V5 18
41#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V6 20
42#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V7 22
43#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V8 24
44#define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V9 26
45
46#define NUM_BITS_CLOCK_INFO_ARRAY_INDEX 6
47
48static uint16_t get_vce_table_offset(struct pp_hwmgr *hwmgr,
49 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
50{
51 uint16_t vce_table_offset = 0;
52
53 if (le16_to_cpu(powerplay_table->usTableSize) >=
54 sizeof(ATOM_PPLIB_POWERPLAYTABLE3)) {
55 const ATOM_PPLIB_POWERPLAYTABLE3 *powerplay_table3 =
56 (const ATOM_PPLIB_POWERPLAYTABLE3 *)powerplay_table;
57
58 if (powerplay_table3->usExtendendedHeaderOffset > 0) {
59 const ATOM_PPLIB_EXTENDEDHEADER *extended_header =
60 (const ATOM_PPLIB_EXTENDEDHEADER *)
61 (((unsigned long)powerplay_table3) +
62 le16_to_cpu(powerplay_table3->usExtendendedHeaderOffset));
63 if (le16_to_cpu(extended_header->usSize) >=
64 SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V2)
65 vce_table_offset = le16_to_cpu(extended_header->usVCETableOffset);
66 }
67 }
68
69 return vce_table_offset;
70}
71
72static uint16_t get_vce_clock_info_array_offset(struct pp_hwmgr *hwmgr,
73 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
74{
75 uint16_t table_offset = get_vce_table_offset(hwmgr,
76 powerplay_table);
77
78 if (table_offset > 0)
79 return table_offset + 1;
80
81 return 0;
82}
83
84static uint16_t get_vce_clock_info_array_size(struct pp_hwmgr *hwmgr,
85 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
86{
87 uint16_t table_offset = get_vce_clock_info_array_offset(hwmgr,
88 powerplay_table);
89 uint16_t table_size = 0;
90
91 if (table_offset > 0) {
92 const VCEClockInfoArray *p = (const VCEClockInfoArray *)
93 (((unsigned long) powerplay_table) + table_offset);
94 table_size = sizeof(uint8_t) + p->ucNumEntries * sizeof(VCEClockInfo);
95 }
96
97 return table_size;
98}
99
100static uint16_t get_vce_clock_voltage_limit_table_offset(struct pp_hwmgr *hwmgr,
101 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
102{
103 uint16_t table_offset = get_vce_clock_info_array_offset(hwmgr,
104 powerplay_table);
105
106 if (table_offset > 0)
107 return table_offset + get_vce_clock_info_array_size(hwmgr,
108 powerplay_table);
109
110 return 0;
111}
112
113static uint16_t get_vce_clock_voltage_limit_table_size(struct pp_hwmgr *hwmgr,
114 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
115{
116 uint16_t table_offset = get_vce_clock_voltage_limit_table_offset(hwmgr, powerplay_table);
117 uint16_t table_size = 0;
118
119 if (table_offset > 0) {
120 const ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table *ptable =
121 (const ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table *)(((unsigned long) powerplay_table) + table_offset);
122
123 table_size = sizeof(uint8_t) + ptable->numEntries * sizeof(ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record);
124 }
125 return table_size;
126}
127
128static uint16_t get_vce_state_table_offset(struct pp_hwmgr *hwmgr, const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
129{
130 uint16_t table_offset = get_vce_clock_voltage_limit_table_offset(hwmgr, powerplay_table);
131
132 if (table_offset > 0)
133 return table_offset + get_vce_clock_voltage_limit_table_size(hwmgr, powerplay_table);
134
135 return 0;
136}
137
138static const ATOM_PPLIB_VCE_State_Table *get_vce_state_table(
139 struct pp_hwmgr *hwmgr,
140 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
141{
142 uint16_t table_offset = get_vce_state_table_offset(hwmgr, powerplay_table);
143
144 if (table_offset > 0)
145 return (const ATOM_PPLIB_VCE_State_Table *)(((unsigned long) powerplay_table) + table_offset);
146
147 return NULL;
148}
149
150static uint16_t get_uvd_table_offset(struct pp_hwmgr *hwmgr,
151 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
152{
153 uint16_t uvd_table_offset = 0;
154
155 if (le16_to_cpu(powerplay_table->usTableSize) >=
156 sizeof(ATOM_PPLIB_POWERPLAYTABLE3)) {
157 const ATOM_PPLIB_POWERPLAYTABLE3 *powerplay_table3 =
158 (const ATOM_PPLIB_POWERPLAYTABLE3 *)powerplay_table;
159 if (powerplay_table3->usExtendendedHeaderOffset > 0) {
160 const ATOM_PPLIB_EXTENDEDHEADER *extended_header =
161 (const ATOM_PPLIB_EXTENDEDHEADER *)
162 (((unsigned long)powerplay_table3) +
163 le16_to_cpu(powerplay_table3->usExtendendedHeaderOffset));
164 if (le16_to_cpu(extended_header->usSize) >=
165 SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V3)
166 uvd_table_offset = le16_to_cpu(extended_header->usUVDTableOffset);
167 }
168 }
169 return uvd_table_offset;
170}
171
172static uint16_t get_uvd_clock_info_array_offset(struct pp_hwmgr *hwmgr,
173 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
174{
175 uint16_t table_offset = get_uvd_table_offset(hwmgr,
176 powerplay_table);
177
178 if (table_offset > 0)
179 return table_offset + 1;
180 return 0;
181}
182
183static uint16_t get_uvd_clock_info_array_size(struct pp_hwmgr *hwmgr,
184 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
185{
186 uint16_t table_offset = get_uvd_clock_info_array_offset(hwmgr,
187 powerplay_table);
188 uint16_t table_size = 0;
189
190 if (table_offset > 0) {
191 const UVDClockInfoArray *p = (const UVDClockInfoArray *)
192 (((unsigned long) powerplay_table)
193 + table_offset);
194 table_size = sizeof(UCHAR) +
195 p->ucNumEntries * sizeof(UVDClockInfo);
196 }
197
198 return table_size;
199}
200
201static uint16_t get_uvd_clock_voltage_limit_table_offset(
202 struct pp_hwmgr *hwmgr,
203 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
204{
205 uint16_t table_offset = get_uvd_clock_info_array_offset(hwmgr,
206 powerplay_table);
207
208 if (table_offset > 0)
209 return table_offset +
210 get_uvd_clock_info_array_size(hwmgr, powerplay_table);
211
212 return 0;
213}
214
215static uint16_t get_samu_table_offset(struct pp_hwmgr *hwmgr,
216 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
217{
218 uint16_t samu_table_offset = 0;
219
220 if (le16_to_cpu(powerplay_table->usTableSize) >=
221 sizeof(ATOM_PPLIB_POWERPLAYTABLE3)) {
222 const ATOM_PPLIB_POWERPLAYTABLE3 *powerplay_table3 =
223 (const ATOM_PPLIB_POWERPLAYTABLE3 *)powerplay_table;
224 if (powerplay_table3->usExtendendedHeaderOffset > 0) {
225 const ATOM_PPLIB_EXTENDEDHEADER *extended_header =
226 (const ATOM_PPLIB_EXTENDEDHEADER *)
227 (((unsigned long)powerplay_table3) +
228 le16_to_cpu(powerplay_table3->usExtendendedHeaderOffset));
229 if (le16_to_cpu(extended_header->usSize) >=
230 SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V4)
231 samu_table_offset = le16_to_cpu(extended_header->usSAMUTableOffset);
232 }
233 }
234
235 return samu_table_offset;
236}
237
238static uint16_t get_samu_clock_voltage_limit_table_offset(
239 struct pp_hwmgr *hwmgr,
240 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
241{
242 uint16_t table_offset = get_samu_table_offset(hwmgr,
243 powerplay_table);
244
245 if (table_offset > 0)
246 return table_offset + 1;
247
248 return 0;
249}
250
251static uint16_t get_acp_table_offset(struct pp_hwmgr *hwmgr,
252 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
253{
254 uint16_t acp_table_offset = 0;
255
256 if (le16_to_cpu(powerplay_table->usTableSize) >=
257 sizeof(ATOM_PPLIB_POWERPLAYTABLE3)) {
258 const ATOM_PPLIB_POWERPLAYTABLE3 *powerplay_table3 =
259 (const ATOM_PPLIB_POWERPLAYTABLE3 *)powerplay_table;
260 if (powerplay_table3->usExtendendedHeaderOffset > 0) {
261 const ATOM_PPLIB_EXTENDEDHEADER *pExtendedHeader =
262 (const ATOM_PPLIB_EXTENDEDHEADER *)
263 (((unsigned long)powerplay_table3) +
264 le16_to_cpu(powerplay_table3->usExtendendedHeaderOffset));
265 if (le16_to_cpu(pExtendedHeader->usSize) >=
266 SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V6)
267 acp_table_offset = le16_to_cpu(pExtendedHeader->usACPTableOffset);
268 }
269 }
270
271 return acp_table_offset;
272}
273
274static uint16_t get_acp_clock_voltage_limit_table_offset(
275 struct pp_hwmgr *hwmgr,
276 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
277{
278 uint16_t tableOffset = get_acp_table_offset(hwmgr, powerplay_table);
279
280 if (tableOffset > 0)
281 return tableOffset + 1;
282
283 return 0;
284}
285
286static uint16_t get_cacp_tdp_table_offset(
287 struct pp_hwmgr *hwmgr,
288 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
289{
290 uint16_t cacTdpTableOffset = 0;
291
292 if (le16_to_cpu(powerplay_table->usTableSize) >=
293 sizeof(ATOM_PPLIB_POWERPLAYTABLE3)) {
294 const ATOM_PPLIB_POWERPLAYTABLE3 *powerplay_table3 =
295 (const ATOM_PPLIB_POWERPLAYTABLE3 *)powerplay_table;
296 if (powerplay_table3->usExtendendedHeaderOffset > 0) {
297 const ATOM_PPLIB_EXTENDEDHEADER *pExtendedHeader =
298 (const ATOM_PPLIB_EXTENDEDHEADER *)
299 (((unsigned long)powerplay_table3) +
300 le16_to_cpu(powerplay_table3->usExtendendedHeaderOffset));
301 if (le16_to_cpu(pExtendedHeader->usSize) >=
302 SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V7)
303 cacTdpTableOffset = le16_to_cpu(pExtendedHeader->usPowerTuneTableOffset);
304 }
305 }
306
307 return cacTdpTableOffset;
308}
309
310static int get_cac_tdp_table(struct pp_hwmgr *hwmgr,
311 struct phm_cac_tdp_table **ptable,
312 const ATOM_PowerTune_Table *table,
313 uint16_t us_maximum_power_delivery_limit)
314{
315 unsigned long table_size;
316 struct phm_cac_tdp_table *tdp_table;
317
318 table_size = sizeof(unsigned long) + sizeof(struct phm_cac_tdp_table);
319
320 tdp_table = kzalloc(table_size, GFP_KERNEL);
321 if (NULL == tdp_table)
322 return -ENOMEM;
323
324 tdp_table->usTDP = le16_to_cpu(table->usTDP);
325 tdp_table->usConfigurableTDP = le16_to_cpu(table->usConfigurableTDP);
326 tdp_table->usTDC = le16_to_cpu(table->usTDC);
327 tdp_table->usBatteryPowerLimit = le16_to_cpu(table->usBatteryPowerLimit);
328 tdp_table->usSmallPowerLimit = le16_to_cpu(table->usSmallPowerLimit);
329 tdp_table->usLowCACLeakage = le16_to_cpu(table->usLowCACLeakage);
330 tdp_table->usHighCACLeakage = le16_to_cpu(table->usHighCACLeakage);
331 tdp_table->usMaximumPowerDeliveryLimit = us_maximum_power_delivery_limit;
332
333 *ptable = tdp_table;
334
335 return 0;
336}
337
338static uint16_t get_sclk_vdd_gfx_table_offset(struct pp_hwmgr *hwmgr,
339 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
340{
341 uint16_t sclk_vdd_gfx_table_offset = 0;
342
343 if (le16_to_cpu(powerplay_table->usTableSize) >=
344 sizeof(ATOM_PPLIB_POWERPLAYTABLE3)) {
345 const ATOM_PPLIB_POWERPLAYTABLE3 *powerplay_table3 =
346 (const ATOM_PPLIB_POWERPLAYTABLE3 *)powerplay_table;
347 if (powerplay_table3->usExtendendedHeaderOffset > 0) {
348 const ATOM_PPLIB_EXTENDEDHEADER *pExtendedHeader =
349 (const ATOM_PPLIB_EXTENDEDHEADER *)
350 (((unsigned long)powerplay_table3) +
351 le16_to_cpu(powerplay_table3->usExtendendedHeaderOffset));
352 if (le16_to_cpu(pExtendedHeader->usSize) >=
353 SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V8)
354 sclk_vdd_gfx_table_offset =
355 le16_to_cpu(pExtendedHeader->usSclkVddgfxTableOffset);
356 }
357 }
358
359 return sclk_vdd_gfx_table_offset;
360}
361
362static uint16_t get_sclk_vdd_gfx_clock_voltage_dependency_table_offset(
363 struct pp_hwmgr *hwmgr,
364 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
365{
366 uint16_t tableOffset = get_sclk_vdd_gfx_table_offset(hwmgr, powerplay_table);
367
368 if (tableOffset > 0)
369 return tableOffset;
370
371 return 0;
372}
373
374
375static int get_clock_voltage_dependency_table(struct pp_hwmgr *hwmgr,
376 struct phm_clock_voltage_dependency_table **ptable,
377 const ATOM_PPLIB_Clock_Voltage_Dependency_Table *table)
378{
379
380 unsigned long table_size, i;
381 struct phm_clock_voltage_dependency_table *dep_table;
382
383 table_size = sizeof(unsigned long) +
384 sizeof(struct phm_clock_voltage_dependency_table)
385 * table->ucNumEntries;
386
387 dep_table = kzalloc(table_size, GFP_KERNEL);
388 if (NULL == dep_table)
389 return -ENOMEM;
390
391 dep_table->count = (unsigned long)table->ucNumEntries;
392
393 for (i = 0; i < dep_table->count; i++) {
394 dep_table->entries[i].clk =
395 ((unsigned long)table->entries[i].ucClockHigh << 16) |
396 le16_to_cpu(table->entries[i].usClockLow);
397 dep_table->entries[i].v =
398 (unsigned long)le16_to_cpu(table->entries[i].usVoltage);
399 }
400
401 *ptable = dep_table;
402
403 return 0;
404}
405
406static int get_valid_clk(struct pp_hwmgr *hwmgr,
407 struct phm_clock_array **ptable,
408 const struct phm_clock_voltage_dependency_table *table)
409{
410 unsigned long table_size, i;
411 struct phm_clock_array *clock_table;
412
413 table_size = sizeof(unsigned long) + sizeof(unsigned long) * table->count;
414 clock_table = kzalloc(table_size, GFP_KERNEL);
415 if (NULL == clock_table)
416 return -ENOMEM;
417
418 clock_table->count = (unsigned long)table->count;
419
420 for (i = 0; i < clock_table->count; i++)
421 clock_table->values[i] = (unsigned long)table->entries[i].clk;
422
423 *ptable = clock_table;
424
425 return 0;
426}
427
428static int get_clock_voltage_limit(struct pp_hwmgr *hwmgr,
429 struct phm_clock_and_voltage_limits *limits,
430 const ATOM_PPLIB_Clock_Voltage_Limit_Table *table)
431{
432 limits->sclk = ((unsigned long)table->entries[0].ucSclkHigh << 16) |
433 le16_to_cpu(table->entries[0].usSclkLow);
434 limits->mclk = ((unsigned long)table->entries[0].ucMclkHigh << 16) |
435 le16_to_cpu(table->entries[0].usMclkLow);
436 limits->vddc = (unsigned long)le16_to_cpu(table->entries[0].usVddc);
437 limits->vddci = (unsigned long)le16_to_cpu(table->entries[0].usVddci);
438
439 return 0;
440}
441
442
443static void set_hw_cap(struct pp_hwmgr *hwmgr, bool enable,
444 enum phm_platform_caps cap)
445{
446 if (enable)
447 phm_cap_set(hwmgr->platform_descriptor.platformCaps, cap);
448 else
449 phm_cap_unset(hwmgr->platform_descriptor.platformCaps, cap);
450}
451
452static int set_platform_caps(struct pp_hwmgr *hwmgr,
453 unsigned long powerplay_caps)
454{
455 set_hw_cap(
456 hwmgr,
457 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_POWERPLAY),
458 PHM_PlatformCaps_PowerPlaySupport
459 );
460
461 set_hw_cap(
462 hwmgr,
463 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_SBIOSPOWERSOURCE),
464 PHM_PlatformCaps_BiosPowerSourceControl
465 );
466
467 set_hw_cap(
468 hwmgr,
469 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_ASPM_L0s),
470 PHM_PlatformCaps_EnableASPML0s
471 );
472
473 set_hw_cap(
474 hwmgr,
475 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_ASPM_L1),
476 PHM_PlatformCaps_EnableASPML1
477 );
478
479 set_hw_cap(
480 hwmgr,
481 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_BACKBIAS),
482 PHM_PlatformCaps_EnableBackbias
483 );
484
485 set_hw_cap(
486 hwmgr,
487 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_HARDWAREDC),
488 PHM_PlatformCaps_AutomaticDCTransition
489 );
490
491 set_hw_cap(
492 hwmgr,
493 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_GEMINIPRIMARY),
494 PHM_PlatformCaps_GeminiPrimary
495 );
496
497 set_hw_cap(
498 hwmgr,
499 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_STEPVDDC),
500 PHM_PlatformCaps_StepVddc
501 );
502
503 set_hw_cap(
504 hwmgr,
505 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_VOLTAGECONTROL),
506 PHM_PlatformCaps_EnableVoltageControl
507 );
508
509 set_hw_cap(
510 hwmgr,
511 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_SIDEPORTCONTROL),
512 PHM_PlatformCaps_EnableSideportControl
513 );
514
515 set_hw_cap(
516 hwmgr,
517 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_TURNOFFPLL_ASPML1),
518 PHM_PlatformCaps_TurnOffPll_ASPML1
519 );
520
521 set_hw_cap(
522 hwmgr,
523 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_HTLINKCONTROL),
524 PHM_PlatformCaps_EnableHTLinkControl
525 );
526
527 set_hw_cap(
528 hwmgr,
529 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_MVDDCONTROL),
530 PHM_PlatformCaps_EnableMVDDControl
531 );
532
533 set_hw_cap(
534 hwmgr,
535 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_VDDCI_CONTROL),
536 PHM_PlatformCaps_ControlVDDCI
537 );
538
539 set_hw_cap(
540 hwmgr,
541 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_REGULATOR_HOT),
542 PHM_PlatformCaps_RegulatorHot
543 );
544
545 set_hw_cap(
546 hwmgr,
547 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_GOTO_BOOT_ON_ALERT),
548 PHM_PlatformCaps_BootStateOnAlert
549 );
550
551 set_hw_cap(
552 hwmgr,
553 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_DONT_WAIT_FOR_VBLANK_ON_ALERT),
554 PHM_PlatformCaps_DontWaitForVBlankOnAlert
555 );
556
557 set_hw_cap(
558 hwmgr,
559 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_BACO),
560 PHM_PlatformCaps_BACO
561 );
562
563 set_hw_cap(
564 hwmgr,
565 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_NEW_CAC_VOLTAGE),
566 PHM_PlatformCaps_NewCACVoltage
567 );
568
569 set_hw_cap(
570 hwmgr,
571 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_REVERT_GPIO5_POLARITY),
572 PHM_PlatformCaps_RevertGPIO5Polarity
573 );
574
575 set_hw_cap(
576 hwmgr,
577 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_OUTPUT_THERMAL2GPIO17),
578 PHM_PlatformCaps_Thermal2GPIO17
579 );
580
581 set_hw_cap(
582 hwmgr,
583 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_VRHOT_GPIO_CONFIGURABLE),
584 PHM_PlatformCaps_VRHotGPIOConfigurable
585 );
586
587 set_hw_cap(
588 hwmgr,
589 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_TEMP_INVERSION),
590 PHM_PlatformCaps_TempInversion
591 );
592
593 set_hw_cap(
594 hwmgr,
595 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_EVV),
596 PHM_PlatformCaps_EVV
597 );
598
599 set_hw_cap(
600 hwmgr,
601 0 != (powerplay_caps & ATOM_PP_PLATFORM_COMBINE_PCC_WITH_THERMAL_SIGNAL),
602 PHM_PlatformCaps_CombinePCCWithThermalSignal
603 );
604
605 set_hw_cap(
606 hwmgr,
607 0 != (powerplay_caps & ATOM_PP_PLATFORM_LOAD_POST_PRODUCTION_FIRMWARE),
608 PHM_PlatformCaps_LoadPostProductionFirmware
609 );
610
611 set_hw_cap(
612 hwmgr,
613 0 != (powerplay_caps & ATOM_PP_PLATFORM_CAP_DISABLE_USING_ACTUAL_TEMPERATURE_FOR_POWER_CALC),
614 PHM_PlatformCaps_DisableUsingActualTemperatureForPowerCalc
615 );
616
617 return 0;
618}
619
620static PP_StateClassificationFlags make_classification_flags(
621 struct pp_hwmgr *hwmgr,
622 USHORT classification,
623 USHORT classification2)
624{
625 PP_StateClassificationFlags result = 0;
626
627 if (classification & ATOM_PPLIB_CLASSIFICATION_BOOT)
628 result |= PP_StateClassificationFlag_Boot;
629
630 if (classification & ATOM_PPLIB_CLASSIFICATION_THERMAL)
631 result |= PP_StateClassificationFlag_Thermal;
632
633 if (classification &
634 ATOM_PPLIB_CLASSIFICATION_LIMITEDPOWERSOURCE)
635 result |= PP_StateClassificationFlag_LimitedPowerSource;
636
637 if (classification & ATOM_PPLIB_CLASSIFICATION_REST)
638 result |= PP_StateClassificationFlag_Rest;
639
640 if (classification & ATOM_PPLIB_CLASSIFICATION_FORCED)
641 result |= PP_StateClassificationFlag_Forced;
642
643 if (classification & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
644 result |= PP_StateClassificationFlag_3DPerformance;
645
646
647 if (classification & ATOM_PPLIB_CLASSIFICATION_OVERDRIVETEMPLATE)
648 result |= PP_StateClassificationFlag_ACOverdriveTemplate;
649
650 if (classification & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
651 result |= PP_StateClassificationFlag_Uvd;
652
653 if (classification & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
654 result |= PP_StateClassificationFlag_UvdHD;
655
656 if (classification & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
657 result |= PP_StateClassificationFlag_UvdSD;
658
659 if (classification & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
660 result |= PP_StateClassificationFlag_HD2;
661
662 if (classification & ATOM_PPLIB_CLASSIFICATION_ACPI)
663 result |= PP_StateClassificationFlag_ACPI;
664
665 if (classification2 & ATOM_PPLIB_CLASSIFICATION2_LIMITEDPOWERSOURCE_2)
666 result |= PP_StateClassificationFlag_LimitedPowerSource_2;
667
668
669 if (classification2 & ATOM_PPLIB_CLASSIFICATION2_ULV)
670 result |= PP_StateClassificationFlag_ULV;
671
672 if (classification2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
673 result |= PP_StateClassificationFlag_UvdMVC;
674
675 return result;
676}
677
678static int init_non_clock_fields(struct pp_hwmgr *hwmgr,
679 struct pp_power_state *ps,
680 uint8_t version,
681 const ATOM_PPLIB_NONCLOCK_INFO *pnon_clock_info) {
682 unsigned long rrr_index;
683 unsigned long tmp;
684
685 ps->classification.ui_label = (le16_to_cpu(pnon_clock_info->usClassification) &
686 ATOM_PPLIB_CLASSIFICATION_UI_MASK) >> ATOM_PPLIB_CLASSIFICATION_UI_SHIFT;
687 ps->classification.flags = make_classification_flags(hwmgr,
688 le16_to_cpu(pnon_clock_info->usClassification),
689 le16_to_cpu(pnon_clock_info->usClassification2));
690
691 ps->classification.temporary_state = false;
692 ps->classification.to_be_deleted = false;
693 tmp = le32_to_cpu(pnon_clock_info->ulCapsAndSettings) &
694 ATOM_PPLIB_SINGLE_DISPLAY_ONLY;
695
696 ps->validation.singleDisplayOnly = (0 != tmp);
697
698 tmp = le32_to_cpu(pnon_clock_info->ulCapsAndSettings) &
699 ATOM_PPLIB_DISALLOW_ON_DC;
700
701 ps->validation.disallowOnDC = (0 != tmp);
702
703 ps->pcie.lanes = ((le32_to_cpu(pnon_clock_info->ulCapsAndSettings) &
704 ATOM_PPLIB_PCIE_LINK_WIDTH_MASK) >>
705 ATOM_PPLIB_PCIE_LINK_WIDTH_SHIFT) + 1;
706
707 ps->pcie.lanes = 0;
708
709 ps->display.disableFrameModulation = false;
710
711 rrr_index = (le32_to_cpu(pnon_clock_info->ulCapsAndSettings) &
712 ATOM_PPLIB_LIMITED_REFRESHRATE_VALUE_MASK) >>
713 ATOM_PPLIB_LIMITED_REFRESHRATE_VALUE_SHIFT;
714
715 if (rrr_index != ATOM_PPLIB_LIMITED_REFRESHRATE_UNLIMITED) {
716 static const uint8_t look_up[(ATOM_PPLIB_LIMITED_REFRESHRATE_VALUE_MASK >> ATOM_PPLIB_LIMITED_REFRESHRATE_VALUE_SHIFT) + 1] = \
717 { 0, 50, 0 };
718
719 ps->display.refreshrateSource = PP_RefreshrateSource_Explicit;
720 ps->display.explicitRefreshrate = look_up[rrr_index];
721 ps->display.limitRefreshrate = true;
722
723 if (ps->display.explicitRefreshrate == 0)
724 ps->display.limitRefreshrate = false;
725 } else
726 ps->display.limitRefreshrate = false;
727
728 tmp = le32_to_cpu(pnon_clock_info->ulCapsAndSettings) &
729 ATOM_PPLIB_ENABLE_VARIBRIGHT;
730
731 ps->display.enableVariBright = (0 != tmp);
732
733 tmp = le32_to_cpu(pnon_clock_info->ulCapsAndSettings) &
734 ATOM_PPLIB_SWSTATE_MEMORY_DLL_OFF;
735
736 ps->memory.dllOff = (0 != tmp);
737
Dan Carpenter7c9574f2016-01-04 23:44:24 +0300738 ps->memory.m3arb = (le32_to_cpu(pnon_clock_info->ulCapsAndSettings) &
739 ATOM_PPLIB_M3ARB_MASK) >> ATOM_PPLIB_M3ARB_SHIFT;
Jammy Zhou3bace352015-07-21 21:18:15 +0800740
741 ps->temperatures.min = PP_TEMPERATURE_UNITS_PER_CENTIGRADES *
742 pnon_clock_info->ucMinTemperature;
743
744 ps->temperatures.max = PP_TEMPERATURE_UNITS_PER_CENTIGRADES *
745 pnon_clock_info->ucMaxTemperature;
746
747 tmp = le32_to_cpu(pnon_clock_info->ulCapsAndSettings) &
748 ATOM_PPLIB_SOFTWARE_DISABLE_LOADBALANCING;
749
750 ps->software.disableLoadBalancing = tmp;
751
752 tmp = le32_to_cpu(pnon_clock_info->ulCapsAndSettings) &
753 ATOM_PPLIB_SOFTWARE_ENABLE_SLEEP_FOR_TIMESTAMPS;
754
755 ps->software.enableSleepForTimestamps = (0 != tmp);
756
757 ps->validation.supportedPowerLevels = pnon_clock_info->ucRequiredPower;
758
759 if (ATOM_PPLIB_NONCLOCKINFO_VER1 < version) {
760 ps->uvd_clocks.VCLK = pnon_clock_info->ulVCLK;
761 ps->uvd_clocks.DCLK = pnon_clock_info->ulDCLK;
762 } else {
763 ps->uvd_clocks.VCLK = 0;
764 ps->uvd_clocks.DCLK = 0;
765 }
766
767 return 0;
768}
769
770static ULONG size_of_entry_v2(ULONG num_dpm_levels)
771{
772 return (sizeof(UCHAR) + sizeof(UCHAR) +
773 (num_dpm_levels * sizeof(UCHAR)));
774}
775
776static const ATOM_PPLIB_STATE_V2 *get_state_entry_v2(
777 const StateArray * pstate_arrays,
778 ULONG entry_index)
779{
780 ULONG i;
781 const ATOM_PPLIB_STATE_V2 *pstate;
782
783 pstate = pstate_arrays->states;
784 if (entry_index <= pstate_arrays->ucNumEntries) {
785 for (i = 0; i < entry_index; i++)
786 pstate = (ATOM_PPLIB_STATE_V2 *)(
787 (unsigned long)pstate +
788 size_of_entry_v2(pstate->ucNumDPMLevels));
789 }
790 return pstate;
791}
792
793
794static const ATOM_PPLIB_POWERPLAYTABLE *get_powerplay_table(
795 struct pp_hwmgr *hwmgr)
796{
Eric Huangcf17039f2016-05-31 17:02:43 -0400797 const void *table_addr = hwmgr->soft_pp_table;
Jammy Zhou3bace352015-07-21 21:18:15 +0800798 uint8_t frev, crev;
799 uint16_t size;
800
Eric Huangcf17039f2016-05-31 17:02:43 -0400801 if (!table_addr) {
802 table_addr = cgs_atom_get_data_table(hwmgr->device,
803 GetIndexIntoMasterTable(DATA, PowerPlayInfo),
804 &size, &frev, &crev);
Jammy Zhou3bace352015-07-21 21:18:15 +0800805
Eric Huangcf17039f2016-05-31 17:02:43 -0400806 hwmgr->soft_pp_table = table_addr;
807 hwmgr->soft_pp_table_size = size;
808 }
Jammy Zhou3bace352015-07-21 21:18:15 +0800809
810 return (const ATOM_PPLIB_POWERPLAYTABLE *)table_addr;
811}
812
813
814int pp_tables_get_num_of_entries(struct pp_hwmgr *hwmgr,
815 unsigned long *num_of_entries)
816{
817 const StateArray *pstate_arrays;
818 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table = get_powerplay_table(hwmgr);
819
820 if (powerplay_table == NULL)
821 return -1;
822
823 if (powerplay_table->sHeader.ucTableFormatRevision >= 6) {
824 pstate_arrays = (StateArray *)(((unsigned long)powerplay_table) +
825 le16_to_cpu(powerplay_table->usStateArrayOffset));
826
827 *num_of_entries = (unsigned long)(pstate_arrays->ucNumEntries);
828 } else
829 *num_of_entries = (unsigned long)(powerplay_table->ucNumStates);
830
831 return 0;
832}
833
834int pp_tables_get_entry(struct pp_hwmgr *hwmgr,
835 unsigned long entry_index,
836 struct pp_power_state *ps,
837 pp_tables_hw_clock_info_callback func)
838{
839 int i;
840 const StateArray *pstate_arrays;
841 const ATOM_PPLIB_STATE_V2 *pstate_entry_v2;
842 const ATOM_PPLIB_NONCLOCK_INFO *pnon_clock_info;
843 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table = get_powerplay_table(hwmgr);
844 int result = 0;
845 int res = 0;
846
847 const ClockInfoArray *pclock_arrays;
848
849 const NonClockInfoArray *pnon_clock_arrays;
850
851 const ATOM_PPLIB_STATE *pstate_entry;
852
853 if (powerplay_table == NULL)
854 return -1;
855
856 ps->classification.bios_index = entry_index;
857
858 if (powerplay_table->sHeader.ucTableFormatRevision >= 6) {
859 pstate_arrays = (StateArray *)(((unsigned long)powerplay_table) +
860 le16_to_cpu(powerplay_table->usStateArrayOffset));
861
862 if (entry_index > pstate_arrays->ucNumEntries)
863 return -1;
864
865 pstate_entry_v2 = get_state_entry_v2(pstate_arrays, entry_index);
866 pclock_arrays = (ClockInfoArray *)(((unsigned long)powerplay_table) +
867 le16_to_cpu(powerplay_table->usClockInfoArrayOffset));
868
869 pnon_clock_arrays = (NonClockInfoArray *)(((unsigned long)powerplay_table) +
870 le16_to_cpu(powerplay_table->usNonClockInfoArrayOffset));
871
872 pnon_clock_info = (ATOM_PPLIB_NONCLOCK_INFO *)((unsigned long)(pnon_clock_arrays->nonClockInfo) +
873 (pstate_entry_v2->nonClockInfoIndex * pnon_clock_arrays->ucEntrySize));
874
875 result = init_non_clock_fields(hwmgr, ps, pnon_clock_arrays->ucEntrySize, pnon_clock_info);
876
877 for (i = 0; i < pstate_entry_v2->ucNumDPMLevels; i++) {
878 const void *pclock_info = (const void *)(
879 (unsigned long)(pclock_arrays->clockInfo) +
880 (pstate_entry_v2->clockInfoIndex[i] * pclock_arrays->ucEntrySize));
881 res = func(hwmgr, &ps->hardware, i, pclock_info);
882 if ((0 == result) && (0 != res))
883 result = res;
884 }
885 } else {
886 if (entry_index > powerplay_table->ucNumStates)
887 return -1;
888
889 pstate_entry = (ATOM_PPLIB_STATE *)((unsigned long)powerplay_table + powerplay_table->usStateArrayOffset +
890 entry_index * powerplay_table->ucStateEntrySize);
891
892 pnon_clock_info = (ATOM_PPLIB_NONCLOCK_INFO *)((unsigned long)powerplay_table +
893 le16_to_cpu(powerplay_table->usNonClockInfoArrayOffset) +
894 pstate_entry->ucNonClockStateIndex *
895 powerplay_table->ucNonClockSize);
896
897 result = init_non_clock_fields(hwmgr, ps,
898 powerplay_table->ucNonClockSize,
899 pnon_clock_info);
900
901 for (i = 0; i < powerplay_table->ucStateEntrySize-1; i++) {
902 const void *pclock_info = (const void *)((unsigned long)powerplay_table +
903 le16_to_cpu(powerplay_table->usClockInfoArrayOffset) +
904 pstate_entry->ucClockStateIndices[i] *
905 powerplay_table->ucClockInfoSize);
906
907 int res = func(hwmgr, &ps->hardware, i, pclock_info);
908
909 if ((0 == result) && (0 != res))
910 result = res;
911 }
912 }
913
914 if ((0 == result) &&
915 (0 != (ps->classification.flags & PP_StateClassificationFlag_Boot)))
916 result = hwmgr->hwmgr_func->patch_boot_state(hwmgr, &(ps->hardware));
917
918 return result;
919}
920
921
922
923static int init_powerplay_tables(
924 struct pp_hwmgr *hwmgr,
925 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table
926)
927{
928 return 0;
929}
930
931
932static int init_thermal_controller(
933 struct pp_hwmgr *hwmgr,
934 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
935{
936 return 0;
937}
938
939static int init_overdrive_limits_V1_4(struct pp_hwmgr *hwmgr,
940 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table,
941 const ATOM_FIRMWARE_INFO_V1_4 *fw_info)
942{
943 hwmgr->platform_descriptor.overdriveLimit.engineClock =
944 le32_to_cpu(fw_info->ulASICMaxEngineClock);
945
946 hwmgr->platform_descriptor.overdriveLimit.memoryClock =
947 le32_to_cpu(fw_info->ulASICMaxMemoryClock);
948
949 hwmgr->platform_descriptor.maxOverdriveVDDC =
950 le32_to_cpu(fw_info->ul3DAccelerationEngineClock) & 0x7FF;
951
952 hwmgr->platform_descriptor.minOverdriveVDDC =
953 le16_to_cpu(fw_info->usBootUpVDDCVoltage);
954
955 hwmgr->platform_descriptor.maxOverdriveVDDC =
956 le16_to_cpu(fw_info->usBootUpVDDCVoltage);
957
958 hwmgr->platform_descriptor.overdriveVDDCStep = 0;
959 return 0;
960}
961
962static int init_overdrive_limits_V2_1(struct pp_hwmgr *hwmgr,
963 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table,
964 const ATOM_FIRMWARE_INFO_V2_1 *fw_info)
965{
966 const ATOM_PPLIB_POWERPLAYTABLE3 *powerplay_table3;
967 const ATOM_PPLIB_EXTENDEDHEADER *header;
968
969 if (le16_to_cpu(powerplay_table->usTableSize) <
970 sizeof(ATOM_PPLIB_POWERPLAYTABLE3))
971 return 0;
972
973 powerplay_table3 = (const ATOM_PPLIB_POWERPLAYTABLE3 *)powerplay_table;
974
975 if (0 == powerplay_table3->usExtendendedHeaderOffset)
976 return 0;
977
978 header = (ATOM_PPLIB_EXTENDEDHEADER *)(((unsigned long) powerplay_table) +
979 le16_to_cpu(powerplay_table3->usExtendendedHeaderOffset));
980
981 hwmgr->platform_descriptor.overdriveLimit.engineClock = le32_to_cpu(header->ulMaxEngineClock);
982 hwmgr->platform_descriptor.overdriveLimit.memoryClock = le32_to_cpu(header->ulMaxMemoryClock);
983
984
985 hwmgr->platform_descriptor.minOverdriveVDDC = 0;
986 hwmgr->platform_descriptor.maxOverdriveVDDC = 0;
987 hwmgr->platform_descriptor.overdriveVDDCStep = 0;
988
989 return 0;
990}
991
992static int init_overdrive_limits(struct pp_hwmgr *hwmgr,
993 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
994{
995 int result;
996 uint8_t frev, crev;
997 uint16_t size;
998
999 const ATOM_COMMON_TABLE_HEADER *fw_info = NULL;
1000
1001 hwmgr->platform_descriptor.overdriveLimit.engineClock = 0;
1002 hwmgr->platform_descriptor.overdriveLimit.memoryClock = 0;
1003 hwmgr->platform_descriptor.minOverdriveVDDC = 0;
1004 hwmgr->platform_descriptor.maxOverdriveVDDC = 0;
1005
1006 /* We assume here that fw_info is unchanged if this call fails.*/
1007 fw_info = cgs_atom_get_data_table(hwmgr->device,
1008 GetIndexIntoMasterTable(DATA, FirmwareInfo),
1009 &size, &frev, &crev);
1010
1011 if ((fw_info->ucTableFormatRevision == 1)
1012 && (fw_info->usStructureSize >= sizeof(ATOM_FIRMWARE_INFO_V1_4)))
1013 result = init_overdrive_limits_V1_4(hwmgr,
1014 powerplay_table,
1015 (const ATOM_FIRMWARE_INFO_V1_4 *)fw_info);
1016
1017 else if ((fw_info->ucTableFormatRevision == 2)
1018 && (fw_info->usStructureSize >= sizeof(ATOM_FIRMWARE_INFO_V2_1)))
1019 result = init_overdrive_limits_V2_1(hwmgr,
1020 powerplay_table,
1021 (const ATOM_FIRMWARE_INFO_V2_1 *)fw_info);
1022
1023 if (hwmgr->platform_descriptor.overdriveLimit.engineClock > 0
1024 && hwmgr->platform_descriptor.overdriveLimit.memoryClock > 0
1025 && !phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1026 PHM_PlatformCaps_OverdriveDisabledByPowerBudget))
1027 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1028 PHM_PlatformCaps_ACOverdriveSupport);
1029
1030 return result;
1031}
1032
1033static int get_uvd_clock_voltage_limit_table(struct pp_hwmgr *hwmgr,
1034 struct phm_uvd_clock_voltage_dependency_table **ptable,
1035 const ATOM_PPLIB_UVD_Clock_Voltage_Limit_Table *table,
1036 const UVDClockInfoArray *array)
1037{
1038 unsigned long table_size, i;
1039 struct phm_uvd_clock_voltage_dependency_table *uvd_table;
1040
1041 table_size = sizeof(unsigned long) +
1042 sizeof(struct phm_uvd_clock_voltage_dependency_table) *
1043 table->numEntries;
1044
1045 uvd_table = kzalloc(table_size, GFP_KERNEL);
1046 if (NULL == uvd_table)
1047 return -ENOMEM;
1048
1049 uvd_table->count = table->numEntries;
1050
1051 for (i = 0; i < table->numEntries; i++) {
1052 const UVDClockInfo *entry =
1053 &array->entries[table->entries[i].ucUVDClockInfoIndex];
1054 uvd_table->entries[i].v = (unsigned long)le16_to_cpu(table->entries[i].usVoltage);
1055 uvd_table->entries[i].vclk = ((unsigned long)entry->ucVClkHigh << 16)
1056 | le16_to_cpu(entry->usVClkLow);
1057 uvd_table->entries[i].dclk = ((unsigned long)entry->ucDClkHigh << 16)
1058 | le16_to_cpu(entry->usDClkLow);
1059 }
1060
1061 *ptable = uvd_table;
1062
1063 return 0;
1064}
1065
1066static int get_vce_clock_voltage_limit_table(struct pp_hwmgr *hwmgr,
1067 struct phm_vce_clock_voltage_dependency_table **ptable,
1068 const ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table *table,
1069 const VCEClockInfoArray *array)
1070{
1071 unsigned long table_size, i;
1072 struct phm_vce_clock_voltage_dependency_table *vce_table = NULL;
1073
1074 table_size = sizeof(unsigned long) +
1075 sizeof(struct phm_vce_clock_voltage_dependency_table)
1076 * table->numEntries;
1077
1078 vce_table = kzalloc(table_size, GFP_KERNEL);
1079 if (NULL == vce_table)
1080 return -ENOMEM;
1081
1082 vce_table->count = table->numEntries;
1083 for (i = 0; i < table->numEntries; i++) {
1084 const VCEClockInfo *entry = &array->entries[table->entries[i].ucVCEClockInfoIndex];
1085
1086 vce_table->entries[i].v = (unsigned long)le16_to_cpu(table->entries[i].usVoltage);
1087 vce_table->entries[i].evclk = ((unsigned long)entry->ucEVClkHigh << 16)
1088 | le16_to_cpu(entry->usEVClkLow);
1089 vce_table->entries[i].ecclk = ((unsigned long)entry->ucECClkHigh << 16)
1090 | le16_to_cpu(entry->usECClkLow);
1091 }
1092
1093 *ptable = vce_table;
1094
1095 return 0;
1096}
1097
1098static int get_samu_clock_voltage_limit_table(struct pp_hwmgr *hwmgr,
1099 struct phm_samu_clock_voltage_dependency_table **ptable,
1100 const ATOM_PPLIB_SAMClk_Voltage_Limit_Table *table)
1101{
1102 unsigned long table_size, i;
1103 struct phm_samu_clock_voltage_dependency_table *samu_table;
1104
1105 table_size = sizeof(unsigned long) +
1106 sizeof(struct phm_samu_clock_voltage_dependency_table) *
1107 table->numEntries;
1108
1109 samu_table = kzalloc(table_size, GFP_KERNEL);
1110 if (NULL == samu_table)
1111 return -ENOMEM;
1112
1113 samu_table->count = table->numEntries;
1114
1115 for (i = 0; i < table->numEntries; i++) {
1116 samu_table->entries[i].v = (unsigned long)le16_to_cpu(table->entries[i].usVoltage);
1117 samu_table->entries[i].samclk = ((unsigned long)table->entries[i].ucSAMClockHigh << 16)
1118 | le16_to_cpu(table->entries[i].usSAMClockLow);
1119 }
1120
1121 *ptable = samu_table;
1122
1123 return 0;
1124}
1125
1126static int get_acp_clock_voltage_limit_table(struct pp_hwmgr *hwmgr,
1127 struct phm_acp_clock_voltage_dependency_table **ptable,
1128 const ATOM_PPLIB_ACPClk_Voltage_Limit_Table *table)
1129{
1130 unsigned table_size, i;
1131 struct phm_acp_clock_voltage_dependency_table *acp_table;
1132
1133 table_size = sizeof(unsigned long) +
1134 sizeof(struct phm_acp_clock_voltage_dependency_table) *
1135 table->numEntries;
1136
1137 acp_table = kzalloc(table_size, GFP_KERNEL);
1138 if (NULL == acp_table)
1139 return -ENOMEM;
1140
1141 acp_table->count = (unsigned long)table->numEntries;
1142
1143 for (i = 0; i < table->numEntries; i++) {
1144 acp_table->entries[i].v = (unsigned long)le16_to_cpu(table->entries[i].usVoltage);
1145 acp_table->entries[i].acpclk = ((unsigned long)table->entries[i].ucACPClockHigh << 16)
1146 | le16_to_cpu(table->entries[i].usACPClockLow);
1147 }
1148
1149 *ptable = acp_table;
1150
1151 return 0;
1152}
1153
1154static int init_clock_voltage_dependency(struct pp_hwmgr *hwmgr,
1155 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
1156{
1157 ATOM_PPLIB_Clock_Voltage_Dependency_Table *table;
1158 ATOM_PPLIB_Clock_Voltage_Limit_Table *limit_table;
1159 int result = 0;
1160
1161 uint16_t vce_clock_info_array_offset;
1162 uint16_t uvd_clock_info_array_offset;
1163 uint16_t table_offset;
1164
1165 hwmgr->dyn_state.vddc_dependency_on_sclk = NULL;
1166 hwmgr->dyn_state.vddci_dependency_on_mclk = NULL;
1167 hwmgr->dyn_state.vddc_dependency_on_mclk = NULL;
1168 hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;
1169 hwmgr->dyn_state.mvdd_dependency_on_mclk = NULL;
Alex Deucher9c0bad92015-11-13 23:51:40 -05001170 hwmgr->dyn_state.vce_clock_voltage_dependency_table = NULL;
1171 hwmgr->dyn_state.uvd_clock_voltage_dependency_table = NULL;
Jammy Zhou3bace352015-07-21 21:18:15 +08001172 hwmgr->dyn_state.samu_clock_voltage_dependency_table = NULL;
1173 hwmgr->dyn_state.acp_clock_voltage_dependency_table = NULL;
1174 hwmgr->dyn_state.ppm_parameter_table = NULL;
1175 hwmgr->dyn_state.vdd_gfx_dependency_on_sclk = NULL;
1176
1177 vce_clock_info_array_offset = get_vce_clock_info_array_offset(
1178 hwmgr, powerplay_table);
1179 table_offset = get_vce_clock_voltage_limit_table_offset(hwmgr,
1180 powerplay_table);
1181 if (vce_clock_info_array_offset > 0 && table_offset > 0) {
1182 const VCEClockInfoArray *array = (const VCEClockInfoArray *)
1183 (((unsigned long) powerplay_table) +
1184 vce_clock_info_array_offset);
1185 const ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table *table =
1186 (const ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table *)
1187 (((unsigned long) powerplay_table) + table_offset);
1188 result = get_vce_clock_voltage_limit_table(hwmgr,
Alex Deucher9c0bad92015-11-13 23:51:40 -05001189 &hwmgr->dyn_state.vce_clock_voltage_dependency_table,
Jammy Zhou3bace352015-07-21 21:18:15 +08001190 table, array);
1191 }
1192
1193 uvd_clock_info_array_offset = get_uvd_clock_info_array_offset(hwmgr, powerplay_table);
1194 table_offset = get_uvd_clock_voltage_limit_table_offset(hwmgr, powerplay_table);
1195
1196 if (uvd_clock_info_array_offset > 0 && table_offset > 0) {
1197 const UVDClockInfoArray *array = (const UVDClockInfoArray *)
1198 (((unsigned long) powerplay_table) +
1199 uvd_clock_info_array_offset);
1200 const ATOM_PPLIB_UVD_Clock_Voltage_Limit_Table *ptable =
1201 (const ATOM_PPLIB_UVD_Clock_Voltage_Limit_Table *)
1202 (((unsigned long) powerplay_table) + table_offset);
1203 result = get_uvd_clock_voltage_limit_table(hwmgr,
Alex Deucher9c0bad92015-11-13 23:51:40 -05001204 &hwmgr->dyn_state.uvd_clock_voltage_dependency_table, ptable, array);
Jammy Zhou3bace352015-07-21 21:18:15 +08001205 }
1206
1207 table_offset = get_samu_clock_voltage_limit_table_offset(hwmgr,
1208 powerplay_table);
1209
1210 if (table_offset > 0) {
1211 const ATOM_PPLIB_SAMClk_Voltage_Limit_Table *ptable =
1212 (const ATOM_PPLIB_SAMClk_Voltage_Limit_Table *)
1213 (((unsigned long) powerplay_table) + table_offset);
1214 result = get_samu_clock_voltage_limit_table(hwmgr,
1215 &hwmgr->dyn_state.samu_clock_voltage_dependency_table, ptable);
1216 }
1217
1218 table_offset = get_acp_clock_voltage_limit_table_offset(hwmgr,
1219 powerplay_table);
1220
1221 if (table_offset > 0) {
1222 const ATOM_PPLIB_ACPClk_Voltage_Limit_Table *ptable =
1223 (const ATOM_PPLIB_ACPClk_Voltage_Limit_Table *)
1224 (((unsigned long) powerplay_table) + table_offset);
1225 result = get_acp_clock_voltage_limit_table(hwmgr,
1226 &hwmgr->dyn_state.acp_clock_voltage_dependency_table, ptable);
1227 }
1228
1229 table_offset = get_cacp_tdp_table_offset(hwmgr, powerplay_table);
1230 if (table_offset > 0) {
1231 UCHAR rev_id = *(UCHAR *)(((unsigned long)powerplay_table) + table_offset);
1232
1233 if (rev_id > 0) {
1234 const ATOM_PPLIB_POWERTUNE_Table_V1 *tune_table =
1235 (const ATOM_PPLIB_POWERTUNE_Table_V1 *)
1236 (((unsigned long) powerplay_table) + table_offset);
1237 result = get_cac_tdp_table(hwmgr, &hwmgr->dyn_state.cac_dtp_table,
1238 &tune_table->power_tune_table,
1239 le16_to_cpu(tune_table->usMaximumPowerDeliveryLimit));
1240 hwmgr->dyn_state.cac_dtp_table->usDefaultTargetOperatingTemp =
1241 le16_to_cpu(tune_table->usTjMax);
1242 } else {
1243 const ATOM_PPLIB_POWERTUNE_Table *tune_table =
1244 (const ATOM_PPLIB_POWERTUNE_Table *)
1245 (((unsigned long) powerplay_table) + table_offset);
1246 result = get_cac_tdp_table(hwmgr,
1247 &hwmgr->dyn_state.cac_dtp_table,
1248 &tune_table->power_tune_table, 255);
1249 }
1250 }
1251
1252 if (le16_to_cpu(powerplay_table->usTableSize) >=
1253 sizeof(ATOM_PPLIB_POWERPLAYTABLE4)) {
1254 const ATOM_PPLIB_POWERPLAYTABLE4 *powerplay_table4 =
1255 (const ATOM_PPLIB_POWERPLAYTABLE4 *)powerplay_table;
1256 if (0 != powerplay_table4->usVddcDependencyOnSCLKOffset) {
1257 table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
1258 (((unsigned long) powerplay_table4) +
1259 powerplay_table4->usVddcDependencyOnSCLKOffset);
1260 result = get_clock_voltage_dependency_table(hwmgr,
1261 &hwmgr->dyn_state.vddc_dependency_on_sclk, table);
1262 }
1263
1264 if (result == 0 && (0 != powerplay_table4->usVddciDependencyOnMCLKOffset)) {
1265 table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
1266 (((unsigned long) powerplay_table4) +
1267 powerplay_table4->usVddciDependencyOnMCLKOffset);
1268 result = get_clock_voltage_dependency_table(hwmgr,
1269 &hwmgr->dyn_state.vddci_dependency_on_mclk, table);
1270 }
1271
1272 if (result == 0 && (0 != powerplay_table4->usVddcDependencyOnMCLKOffset)) {
1273 table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
1274 (((unsigned long) powerplay_table4) +
1275 powerplay_table4->usVddcDependencyOnMCLKOffset);
1276 result = get_clock_voltage_dependency_table(hwmgr,
1277 &hwmgr->dyn_state.vddc_dependency_on_mclk, table);
1278 }
1279
1280 if (result == 0 && (0 != powerplay_table4->usMaxClockVoltageOnDCOffset)) {
1281 limit_table = (ATOM_PPLIB_Clock_Voltage_Limit_Table *)
1282 (((unsigned long) powerplay_table4) +
1283 powerplay_table4->usMaxClockVoltageOnDCOffset);
1284 result = get_clock_voltage_limit(hwmgr,
1285 &hwmgr->dyn_state.max_clock_voltage_on_dc, limit_table);
1286 }
1287
1288 if (result == 0 && (NULL != hwmgr->dyn_state.vddc_dependency_on_mclk) &&
1289 (0 != hwmgr->dyn_state.vddc_dependency_on_mclk->count))
1290 result = get_valid_clk(hwmgr, &hwmgr->dyn_state.valid_mclk_values,
1291 hwmgr->dyn_state.vddc_dependency_on_mclk);
1292
1293 if(result == 0 && (NULL != hwmgr->dyn_state.vddc_dependency_on_sclk) &&
1294 (0 != hwmgr->dyn_state.vddc_dependency_on_sclk->count))
1295 result = get_valid_clk(hwmgr,
1296 &hwmgr->dyn_state.valid_sclk_values,
1297 hwmgr->dyn_state.vddc_dependency_on_sclk);
1298
1299 if (result == 0 && (0 != powerplay_table4->usMvddDependencyOnMCLKOffset)) {
1300 table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
1301 (((unsigned long) powerplay_table4) +
1302 powerplay_table4->usMvddDependencyOnMCLKOffset);
1303 result = get_clock_voltage_dependency_table(hwmgr,
1304 &hwmgr->dyn_state.mvdd_dependency_on_mclk, table);
1305 }
1306 }
1307
1308 table_offset = get_sclk_vdd_gfx_clock_voltage_dependency_table_offset(hwmgr,
1309 powerplay_table);
1310
1311 if (table_offset > 0) {
1312 table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
1313 (((unsigned long) powerplay_table) + table_offset);
1314 result = get_clock_voltage_dependency_table(hwmgr,
1315 &hwmgr->dyn_state.vdd_gfx_dependency_on_sclk, table);
1316 }
1317
1318 return result;
1319}
1320
1321static int get_cac_leakage_table(struct pp_hwmgr *hwmgr,
1322 struct phm_cac_leakage_table **ptable,
1323 const ATOM_PPLIB_CAC_Leakage_Table *table)
1324{
1325 struct phm_cac_leakage_table *cac_leakage_table;
1326 unsigned long table_size, i;
1327
Rex Zhuc15c8d72016-01-06 16:48:38 +08001328 if (hwmgr == NULL || table == NULL || ptable == NULL)
1329 return -EINVAL;
1330
Jammy Zhou3bace352015-07-21 21:18:15 +08001331 table_size = sizeof(ULONG) +
1332 (sizeof(struct phm_cac_leakage_table) * table->ucNumEntries);
1333
1334 cac_leakage_table = kzalloc(table_size, GFP_KERNEL);
1335
Rex Zhuc15c8d72016-01-06 16:48:38 +08001336 if (cac_leakage_table == NULL)
1337 return -ENOMEM;
1338
Jammy Zhou3bace352015-07-21 21:18:15 +08001339 cac_leakage_table->count = (ULONG)table->ucNumEntries;
1340
1341 for (i = 0; i < cac_leakage_table->count; i++) {
1342 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1343 PHM_PlatformCaps_EVV)) {
1344 cac_leakage_table->entries[i].Vddc1 = le16_to_cpu(table->entries[i].usVddc1);
1345 cac_leakage_table->entries[i].Vddc2 = le16_to_cpu(table->entries[i].usVddc2);
1346 cac_leakage_table->entries[i].Vddc3 = le16_to_cpu(table->entries[i].usVddc3);
1347 } else {
1348 cac_leakage_table->entries[i].Vddc = le16_to_cpu(table->entries[i].usVddc);
1349 cac_leakage_table->entries[i].Leakage = le32_to_cpu(table->entries[i].ulLeakageValue);
1350 }
1351 }
1352
1353 *ptable = cac_leakage_table;
1354
1355 return 0;
1356}
1357
1358static int get_platform_power_management_table(struct pp_hwmgr *hwmgr,
1359 ATOM_PPLIB_PPM_Table *atom_ppm_table)
1360{
Rex Zhuc15c8d72016-01-06 16:48:38 +08001361 struct phm_ppm_table *ptr = kzalloc(sizeof(struct phm_ppm_table), GFP_KERNEL);
Jammy Zhou3bace352015-07-21 21:18:15 +08001362
1363 if (NULL == ptr)
1364 return -ENOMEM;
1365
1366 ptr->ppm_design = atom_ppm_table->ucPpmDesign;
1367 ptr->cpu_core_number = le16_to_cpu(atom_ppm_table->usCpuCoreNumber);
1368 ptr->platform_tdp = le32_to_cpu(atom_ppm_table->ulPlatformTDP);
1369 ptr->small_ac_platform_tdp = le32_to_cpu(atom_ppm_table->ulSmallACPlatformTDP);
1370 ptr->platform_tdc = le32_to_cpu(atom_ppm_table->ulPlatformTDC);
1371 ptr->small_ac_platform_tdc = le32_to_cpu(atom_ppm_table->ulSmallACPlatformTDC);
1372 ptr->apu_tdp = le32_to_cpu(atom_ppm_table->ulApuTDP);
1373 ptr->dgpu_tdp = le32_to_cpu(atom_ppm_table->ulDGpuTDP);
1374 ptr->dgpu_ulv_power = le32_to_cpu(atom_ppm_table->ulDGpuUlvPower);
1375 ptr->tj_max = le32_to_cpu(atom_ppm_table->ulTjmax);
1376 hwmgr->dyn_state.ppm_parameter_table = ptr;
1377
1378 return 0;
1379}
1380
1381static int init_dpm2_parameters(struct pp_hwmgr *hwmgr,
1382 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
1383{
1384 int result = 0;
1385
1386 if (le16_to_cpu(powerplay_table->usTableSize) >=
1387 sizeof(ATOM_PPLIB_POWERPLAYTABLE5)) {
1388 const ATOM_PPLIB_POWERPLAYTABLE5 *ptable5 =
1389 (const ATOM_PPLIB_POWERPLAYTABLE5 *)powerplay_table;
1390 const ATOM_PPLIB_POWERPLAYTABLE4 *ptable4 =
1391 (const ATOM_PPLIB_POWERPLAYTABLE4 *)
1392 (&ptable5->basicTable4);
1393 const ATOM_PPLIB_POWERPLAYTABLE3 *ptable3 =
1394 (const ATOM_PPLIB_POWERPLAYTABLE3 *)
1395 (&ptable4->basicTable3);
1396 const ATOM_PPLIB_EXTENDEDHEADER *extended_header;
1397 uint16_t table_offset;
1398 ATOM_PPLIB_PPM_Table *atom_ppm_table;
1399
1400 hwmgr->platform_descriptor.TDPLimit = le32_to_cpu(ptable5->ulTDPLimit);
1401 hwmgr->platform_descriptor.nearTDPLimit = le32_to_cpu(ptable5->ulNearTDPLimit);
1402
1403 hwmgr->platform_descriptor.TDPODLimit = le16_to_cpu(ptable5->usTDPODLimit);
1404 hwmgr->platform_descriptor.TDPAdjustment = 0;
1405
1406 hwmgr->platform_descriptor.VidAdjustment = 0;
1407 hwmgr->platform_descriptor.VidAdjustmentPolarity = 0;
1408 hwmgr->platform_descriptor.VidMinLimit = 0;
1409 hwmgr->platform_descriptor.VidMaxLimit = 1500000;
1410 hwmgr->platform_descriptor.VidStep = 6250;
1411
1412 hwmgr->platform_descriptor.nearTDPLimitAdjusted = le32_to_cpu(ptable5->ulNearTDPLimit);
1413
1414 if (hwmgr->platform_descriptor.TDPODLimit != 0)
1415 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1416 PHM_PlatformCaps_PowerControl);
1417
1418 hwmgr->platform_descriptor.SQRampingThreshold = le32_to_cpu(ptable5->ulSQRampingThreshold);
1419
1420 hwmgr->platform_descriptor.CACLeakage = le32_to_cpu(ptable5->ulCACLeakage);
1421
1422 hwmgr->dyn_state.cac_leakage_table = NULL;
1423
1424 if (0 != ptable5->usCACLeakageTableOffset) {
1425 const ATOM_PPLIB_CAC_Leakage_Table *pCAC_leakage_table =
1426 (ATOM_PPLIB_CAC_Leakage_Table *)(((unsigned long)ptable5) +
1427 le16_to_cpu(ptable5->usCACLeakageTableOffset));
1428 result = get_cac_leakage_table(hwmgr,
1429 &hwmgr->dyn_state.cac_leakage_table, pCAC_leakage_table);
1430 }
1431
1432 hwmgr->platform_descriptor.LoadLineSlope = le16_to_cpu(ptable5->usLoadLineSlope);
1433
1434 hwmgr->dyn_state.ppm_parameter_table = NULL;
1435
1436 if (0 != ptable3->usExtendendedHeaderOffset) {
1437 extended_header = (const ATOM_PPLIB_EXTENDEDHEADER *)
1438 (((unsigned long)powerplay_table) +
1439 le16_to_cpu(ptable3->usExtendendedHeaderOffset));
1440 if ((extended_header->usPPMTableOffset > 0) &&
1441 le16_to_cpu(extended_header->usSize) >=
1442 SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V5) {
1443 table_offset = le16_to_cpu(extended_header->usPPMTableOffset);
1444 atom_ppm_table = (ATOM_PPLIB_PPM_Table *)
1445 (((unsigned long)powerplay_table) + table_offset);
1446 if (0 == get_platform_power_management_table(hwmgr, atom_ppm_table))
1447 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1448 PHM_PlatformCaps_EnablePlatformPowerManagement);
1449 }
1450 }
1451 }
1452 return result;
1453}
1454
1455static int init_phase_shedding_table(struct pp_hwmgr *hwmgr,
1456 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table)
1457{
1458 if (le16_to_cpu(powerplay_table->usTableSize) >=
1459 sizeof(ATOM_PPLIB_POWERPLAYTABLE4)) {
1460 const ATOM_PPLIB_POWERPLAYTABLE4 *powerplay_table4 =
1461 (const ATOM_PPLIB_POWERPLAYTABLE4 *)powerplay_table;
1462
1463 if (0 != powerplay_table4->usVddcPhaseShedLimitsTableOffset) {
1464 const ATOM_PPLIB_PhaseSheddingLimits_Table *ptable =
1465 (ATOM_PPLIB_PhaseSheddingLimits_Table *)
1466 (((unsigned long)powerplay_table4) +
1467 le16_to_cpu(powerplay_table4->usVddcPhaseShedLimitsTableOffset));
1468 struct phm_phase_shedding_limits_table *table;
1469 unsigned long size, i;
1470
1471
1472 size = sizeof(unsigned long) +
1473 (sizeof(struct phm_phase_shedding_limits_table) *
1474 ptable->ucNumEntries);
1475
1476 table = kzalloc(size, GFP_KERNEL);
1477
Rex Zhuc15c8d72016-01-06 16:48:38 +08001478 if (table == NULL)
1479 return -ENOMEM;
1480
Jammy Zhou3bace352015-07-21 21:18:15 +08001481 table->count = (unsigned long)ptable->ucNumEntries;
1482
1483 for (i = 0; i < table->count; i++) {
1484 table->entries[i].Voltage = (unsigned long)le16_to_cpu(ptable->entries[i].usVoltage);
1485 table->entries[i].Sclk = ((unsigned long)ptable->entries[i].ucSclkHigh << 16)
1486 | le16_to_cpu(ptable->entries[i].usSclkLow);
1487 table->entries[i].Mclk = ((unsigned long)ptable->entries[i].ucMclkHigh << 16)
1488 | le16_to_cpu(ptable->entries[i].usMclkLow);
1489 }
1490 hwmgr->dyn_state.vddc_phase_shed_limits_table = table;
1491 }
1492 }
1493
1494 return 0;
1495}
1496
1497int get_number_of_vce_state_table_entries(
1498 struct pp_hwmgr *hwmgr)
1499{
1500 const ATOM_PPLIB_POWERPLAYTABLE *table =
1501 get_powerplay_table(hwmgr);
1502 const ATOM_PPLIB_VCE_State_Table *vce_table =
1503 get_vce_state_table(hwmgr, table);
1504
1505 if (vce_table > 0)
1506 return vce_table->numEntries;
1507
1508 return 0;
1509}
1510
1511int get_vce_state_table_entry(struct pp_hwmgr *hwmgr,
1512 unsigned long i,
1513 struct PP_VCEState *vce_state,
1514 void **clock_info,
1515 unsigned long *flag)
1516{
1517 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table = get_powerplay_table(hwmgr);
1518
1519 const ATOM_PPLIB_VCE_State_Table *vce_state_table = get_vce_state_table(hwmgr, powerplay_table);
1520
1521 unsigned short vce_clock_info_array_offset = get_vce_clock_info_array_offset(hwmgr, powerplay_table);
1522
1523 const VCEClockInfoArray *vce_clock_info_array = (const VCEClockInfoArray *)(((unsigned long) powerplay_table) + vce_clock_info_array_offset);
1524
1525 const ClockInfoArray *clock_arrays = (ClockInfoArray *)(((unsigned long)powerplay_table) + powerplay_table->usClockInfoArrayOffset);
1526
1527 const ATOM_PPLIB_VCE_State_Record *record = &vce_state_table->entries[i];
1528
1529 const VCEClockInfo *vce_clock_info = &vce_clock_info_array->entries[record->ucVCEClockInfoIndex];
1530
1531 unsigned long clockInfoIndex = record->ucClockInfoIndex & 0x3F;
1532
1533 *flag = (record->ucClockInfoIndex >> NUM_BITS_CLOCK_INFO_ARRAY_INDEX);
1534
1535 vce_state->evclk = ((uint32_t)vce_clock_info->ucEVClkHigh << 16) | vce_clock_info->usEVClkLow;
1536 vce_state->ecclk = ((uint32_t)vce_clock_info->ucECClkHigh << 16) | vce_clock_info->usECClkLow;
1537
1538 *clock_info = (void *)((unsigned long)(clock_arrays->clockInfo) + (clockInfoIndex * clock_arrays->ucEntrySize));
1539
1540 return 0;
1541}
1542
1543
1544static int pp_tables_initialize(struct pp_hwmgr *hwmgr)
1545{
1546 int result;
1547 const ATOM_PPLIB_POWERPLAYTABLE *powerplay_table;
1548
Alex Deucher9c0bad92015-11-13 23:51:40 -05001549 hwmgr->need_pp_table_upload = true;
1550
Jammy Zhou3bace352015-07-21 21:18:15 +08001551 powerplay_table = get_powerplay_table(hwmgr);
1552
1553 result = init_powerplay_tables(hwmgr, powerplay_table);
1554
Alex Deuchera71e06d2015-12-11 12:32:55 -05001555 PP_ASSERT_WITH_CODE((result == 0),
1556 "init_powerplay_tables failed", return result);
1557
1558 result = set_platform_caps(hwmgr,
Jammy Zhou3bace352015-07-21 21:18:15 +08001559 le32_to_cpu(powerplay_table->ulPlatformCaps));
1560
Alex Deuchera71e06d2015-12-11 12:32:55 -05001561 PP_ASSERT_WITH_CODE((result == 0),
1562 "set_platform_caps failed", return result);
Jammy Zhou3bace352015-07-21 21:18:15 +08001563
Alex Deuchera71e06d2015-12-11 12:32:55 -05001564 result = init_thermal_controller(hwmgr, powerplay_table);
Jammy Zhou3bace352015-07-21 21:18:15 +08001565
Alex Deuchera71e06d2015-12-11 12:32:55 -05001566 PP_ASSERT_WITH_CODE((result == 0),
1567 "init_thermal_controller failed", return result);
Jammy Zhou3bace352015-07-21 21:18:15 +08001568
Alex Deuchera71e06d2015-12-11 12:32:55 -05001569 result = init_overdrive_limits(hwmgr, powerplay_table);
Jammy Zhou3bace352015-07-21 21:18:15 +08001570
Alex Deuchera71e06d2015-12-11 12:32:55 -05001571 PP_ASSERT_WITH_CODE((result == 0),
1572 "init_overdrive_limits failed", return result);
1573
1574 result = init_clock_voltage_dependency(hwmgr,
1575 powerplay_table);
1576
1577 PP_ASSERT_WITH_CODE((result == 0),
1578 "init_clock_voltage_dependency failed", return result);
1579
1580 result = init_dpm2_parameters(hwmgr, powerplay_table);
1581
1582 PP_ASSERT_WITH_CODE((result == 0),
1583 "init_dpm2_parameters failed", return result);
1584
1585 result = init_phase_shedding_table(hwmgr, powerplay_table);
1586
1587 PP_ASSERT_WITH_CODE((result == 0),
1588 "init_phase_shedding_table failed", return result);
Jammy Zhou3bace352015-07-21 21:18:15 +08001589
1590 return result;
1591}
1592
1593static int pp_tables_uninitialize(struct pp_hwmgr *hwmgr)
1594{
Jammy Zhou3bace352015-07-21 21:18:15 +08001595 if (NULL != hwmgr->dyn_state.vddc_dependency_on_sclk) {
1596 kfree(hwmgr->dyn_state.vddc_dependency_on_sclk);
1597 hwmgr->dyn_state.vddc_dependency_on_sclk = NULL;
1598 }
1599
1600 if (NULL != hwmgr->dyn_state.vddci_dependency_on_mclk) {
1601 kfree(hwmgr->dyn_state.vddci_dependency_on_mclk);
1602 hwmgr->dyn_state.vddci_dependency_on_mclk = NULL;
1603 }
1604
1605 if (NULL != hwmgr->dyn_state.vddc_dependency_on_mclk) {
1606 kfree(hwmgr->dyn_state.vddc_dependency_on_mclk);
1607 hwmgr->dyn_state.vddc_dependency_on_mclk = NULL;
1608 }
1609
1610 if (NULL != hwmgr->dyn_state.mvdd_dependency_on_mclk) {
1611 kfree(hwmgr->dyn_state.mvdd_dependency_on_mclk);
1612 hwmgr->dyn_state.mvdd_dependency_on_mclk = NULL;
1613 }
1614
1615 if (NULL != hwmgr->dyn_state.valid_mclk_values) {
1616 kfree(hwmgr->dyn_state.valid_mclk_values);
1617 hwmgr->dyn_state.valid_mclk_values = NULL;
1618 }
1619
1620 if (NULL != hwmgr->dyn_state.valid_sclk_values) {
1621 kfree(hwmgr->dyn_state.valid_sclk_values);
1622 hwmgr->dyn_state.valid_sclk_values = NULL;
1623 }
1624
1625 if (NULL != hwmgr->dyn_state.cac_leakage_table) {
1626 kfree(hwmgr->dyn_state.cac_leakage_table);
1627 hwmgr->dyn_state.cac_leakage_table = NULL;
1628 }
1629
1630 if (NULL != hwmgr->dyn_state.vddc_phase_shed_limits_table) {
1631 kfree(hwmgr->dyn_state.vddc_phase_shed_limits_table);
1632 hwmgr->dyn_state.vddc_phase_shed_limits_table = NULL;
1633 }
1634
Alex Deucher9c0bad92015-11-13 23:51:40 -05001635 if (NULL != hwmgr->dyn_state.vce_clock_voltage_dependency_table) {
1636 kfree(hwmgr->dyn_state.vce_clock_voltage_dependency_table);
1637 hwmgr->dyn_state.vce_clock_voltage_dependency_table = NULL;
Jammy Zhou3bace352015-07-21 21:18:15 +08001638 }
1639
Alex Deucher9c0bad92015-11-13 23:51:40 -05001640 if (NULL != hwmgr->dyn_state.uvd_clock_voltage_dependency_table) {
1641 kfree(hwmgr->dyn_state.uvd_clock_voltage_dependency_table);
1642 hwmgr->dyn_state.uvd_clock_voltage_dependency_table = NULL;
Jammy Zhou3bace352015-07-21 21:18:15 +08001643 }
1644
1645 if (NULL != hwmgr->dyn_state.samu_clock_voltage_dependency_table) {
1646 kfree(hwmgr->dyn_state.samu_clock_voltage_dependency_table);
1647 hwmgr->dyn_state.samu_clock_voltage_dependency_table = NULL;
1648 }
1649
1650 if (NULL != hwmgr->dyn_state.acp_clock_voltage_dependency_table) {
1651 kfree(hwmgr->dyn_state.acp_clock_voltage_dependency_table);
1652 hwmgr->dyn_state.acp_clock_voltage_dependency_table = NULL;
1653 }
1654
1655 if (NULL != hwmgr->dyn_state.cac_dtp_table) {
1656 kfree(hwmgr->dyn_state.cac_dtp_table);
1657 hwmgr->dyn_state.cac_dtp_table = NULL;
1658 }
1659
1660 if (NULL != hwmgr->dyn_state.ppm_parameter_table) {
1661 kfree(hwmgr->dyn_state.ppm_parameter_table);
1662 hwmgr->dyn_state.ppm_parameter_table = NULL;
1663 }
1664
1665 if (NULL != hwmgr->dyn_state.vdd_gfx_dependency_on_sclk) {
1666 kfree(hwmgr->dyn_state.vdd_gfx_dependency_on_sclk);
1667 hwmgr->dyn_state.vdd_gfx_dependency_on_sclk = NULL;
1668 }
1669
1670 if (NULL != hwmgr->dyn_state.vq_budgeting_table) {
1671 kfree(hwmgr->dyn_state.vq_budgeting_table);
1672 hwmgr->dyn_state.vq_budgeting_table = NULL;
1673 }
1674
1675 return 0;
1676}
1677
1678const struct pp_table_func pptable_funcs = {
1679 .pptable_init = pp_tables_initialize,
1680 .pptable_fini = pp_tables_uninitialize,
1681 .pptable_get_number_of_vce_state_table_entries =
1682 get_number_of_vce_state_table_entries,
1683 .pptable_get_vce_state_table_entry =
1684 get_vce_state_table_entry,
1685};
1686