blob: b156481b50e8ee43076abf2de1fdcb8df46f3990 [file] [log] [blame]
yanyang1c82baa22015-08-18 15:28:32 +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/module.h>
24#include <linux/slab.h>
25#include <linux/fb.h>
26
27#include "tonga_processpptables.h"
28#include "ppatomctrl.h"
29#include "atombios.h"
30#include "pp_debug.h"
31#include "hwmgr.h"
32#include "cgs_common.h"
33#include "tonga_pptable.h"
34
35/**
36 * Private Function used during initialization.
37 * @param hwmgr Pointer to the hardware manager.
38 * @param setIt A flag indication if the capability should be set (TRUE) or reset (FALSE).
39 * @param cap Which capability to set/reset.
40 */
41static void set_hw_cap(struct pp_hwmgr *hwmgr, bool setIt, enum phm_platform_caps cap)
42{
43 if (setIt)
44 phm_cap_set(hwmgr->platform_descriptor.platformCaps, cap);
45 else
46 phm_cap_unset(hwmgr->platform_descriptor.platformCaps, cap);
47}
48
49
50/**
51 * Private Function used during initialization.
52 * @param hwmgr Pointer to the hardware manager.
53 * @param powerplay_caps the bit array (from BIOS) of capability bits.
54 * @exception the current implementation always returns 1.
55 */
56static int set_platform_caps(struct pp_hwmgr *hwmgr, uint32_t powerplay_caps)
57{
58 PP_ASSERT_WITH_CODE((~powerplay_caps & ____RETIRE16____),
59 "ATOM_PP_PLATFORM_CAP_ASPM_L1 is not supported!", continue);
60 PP_ASSERT_WITH_CODE((~powerplay_caps & ____RETIRE64____),
61 "ATOM_PP_PLATFORM_CAP_GEMINIPRIMARY is not supported!", continue);
62 PP_ASSERT_WITH_CODE((~powerplay_caps & ____RETIRE512____),
63 "ATOM_PP_PLATFORM_CAP_SIDEPORTCONTROL is not supported!", continue);
64 PP_ASSERT_WITH_CODE((~powerplay_caps & ____RETIRE1024____),
65 "ATOM_PP_PLATFORM_CAP_TURNOFFPLL_ASPML1 is not supported!", continue);
66 PP_ASSERT_WITH_CODE((~powerplay_caps & ____RETIRE2048____),
67 "ATOM_PP_PLATFORM_CAP_HTLINKCONTROL is not supported!", continue);
68
69 set_hw_cap(
70 hwmgr,
71 0 != (powerplay_caps & ATOM_TONGA_PP_PLATFORM_CAP_POWERPLAY),
72 PHM_PlatformCaps_PowerPlaySupport
73 );
74
75 set_hw_cap(
76 hwmgr,
77 0 != (powerplay_caps & ATOM_TONGA_PP_PLATFORM_CAP_SBIOSPOWERSOURCE),
78 PHM_PlatformCaps_BiosPowerSourceControl
79 );
80
81 set_hw_cap(
82 hwmgr,
83 0 != (powerplay_caps & ATOM_TONGA_PP_PLATFORM_CAP_HARDWAREDC),
84 PHM_PlatformCaps_AutomaticDCTransition
85 );
86
87 set_hw_cap(
88 hwmgr,
89 0 != (powerplay_caps & ATOM_TONGA_PP_PLATFORM_CAP_MVDD_CONTROL),
90 PHM_PlatformCaps_EnableMVDDControl
91 );
92
93 set_hw_cap(
94 hwmgr,
95 0 != (powerplay_caps & ATOM_TONGA_PP_PLATFORM_CAP_VDDCI_CONTROL),
96 PHM_PlatformCaps_ControlVDDCI
97 );
98
99 set_hw_cap(
100 hwmgr,
101 0 != (powerplay_caps & ATOM_TONGA_PP_PLATFORM_CAP_VDDGFX_CONTROL),
102 PHM_PlatformCaps_ControlVDDGFX
103 );
104
105 set_hw_cap(
106 hwmgr,
107 0 != (powerplay_caps & ATOM_TONGA_PP_PLATFORM_CAP_BACO),
108 PHM_PlatformCaps_BACO
109 );
110
111 set_hw_cap(
112 hwmgr,
113 0 != (powerplay_caps & ATOM_TONGA_PP_PLATFORM_CAP_DISABLE_VOLTAGE_ISLAND),
114 PHM_PlatformCaps_DisableVoltageIsland
115 );
116
117 set_hw_cap(
118 hwmgr,
119 0 != (powerplay_caps & ATOM_TONGA_PP_PLATFORM_COMBINE_PCC_WITH_THERMAL_SIGNAL),
120 PHM_PlatformCaps_CombinePCCWithThermalSignal
121 );
122
123 set_hw_cap(
124 hwmgr,
125 0 != (powerplay_caps & ATOM_TONGA_PLATFORM_LOAD_POST_PRODUCTION_FIRMWARE),
126 PHM_PlatformCaps_LoadPostProductionFirmware
127 );
128
129 return 0;
130}
131
132/**
133 * Private Function to get the PowerPlay Table Address.
134 */
135const void *get_powerplay_table(struct pp_hwmgr *hwmgr)
136{
137 int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
138
139 u16 size;
140 u8 frev, crev;
141 void *table_address;
142
143 table_address = (ATOM_Tonga_POWERPLAYTABLE *)
144 cgs_atom_get_data_table(hwmgr->device, index, &size, &frev, &crev);
145
146 hwmgr->soft_pp_table = table_address; /*Cache the result in RAM.*/
147
148 return table_address;
149}
150
151static int get_vddc_lookup_table(
152 struct pp_hwmgr *hwmgr,
153 phm_ppt_v1_voltage_lookup_table **lookup_table,
154 const ATOM_Tonga_Voltage_Lookup_Table *vddc_lookup_pp_tables,
155 uint32_t max_levels
156 )
157{
158 uint32_t table_size, i;
159 phm_ppt_v1_voltage_lookup_table *table;
160
161 PP_ASSERT_WITH_CODE((0 != vddc_lookup_pp_tables->ucNumEntries),
162 "Invalid CAC Leakage PowerPlay Table!", return 1);
163
164 table_size = sizeof(uint32_t) +
165 sizeof(phm_ppt_v1_voltage_lookup_record) * max_levels;
166
167 table = (phm_ppt_v1_voltage_lookup_table *)
168 kzalloc(table_size, GFP_KERNEL);
169
170 if (NULL == table)
Rex Zhuc15c8d72016-01-06 16:48:38 +0800171 return -ENOMEM;
yanyang1c82baa22015-08-18 15:28:32 +0800172
173 memset(table, 0x00, table_size);
174
175 table->count = vddc_lookup_pp_tables->ucNumEntries;
176
177 for (i = 0; i < vddc_lookup_pp_tables->ucNumEntries; i++) {
178 table->entries[i].us_calculated = 0;
179 table->entries[i].us_vdd =
180 vddc_lookup_pp_tables->entries[i].usVdd;
181 table->entries[i].us_cac_low =
182 vddc_lookup_pp_tables->entries[i].usCACLow;
183 table->entries[i].us_cac_mid =
184 vddc_lookup_pp_tables->entries[i].usCACMid;
185 table->entries[i].us_cac_high =
186 vddc_lookup_pp_tables->entries[i].usCACHigh;
187 }
188
189 *lookup_table = table;
190
191 return 0;
192}
193
194/**
195 * Private Function used during initialization.
196 * Initialize Platform Power Management Parameter table
197 * @param hwmgr Pointer to the hardware manager.
198 * @param atom_ppm_table Pointer to PPM table in VBIOS
199 */
200static int get_platform_power_management_table(
201 struct pp_hwmgr *hwmgr,
202 ATOM_Tonga_PPM_Table *atom_ppm_table)
203{
204 struct phm_ppm_table *ptr = kzalloc(sizeof(ATOM_Tonga_PPM_Table), GFP_KERNEL);
205 struct phm_ppt_v1_information *pp_table_information =
206 (struct phm_ppt_v1_information *)(hwmgr->pptable);
207
208 if (NULL == ptr)
Rex Zhuc15c8d72016-01-06 16:48:38 +0800209 return -ENOMEM;
yanyang1c82baa22015-08-18 15:28:32 +0800210
211 ptr->ppm_design
212 = atom_ppm_table->ucPpmDesign;
213 ptr->cpu_core_number
214 = atom_ppm_table->usCpuCoreNumber;
215 ptr->platform_tdp
216 = atom_ppm_table->ulPlatformTDP;
217 ptr->small_ac_platform_tdp
218 = atom_ppm_table->ulSmallACPlatformTDP;
219 ptr->platform_tdc
220 = atom_ppm_table->ulPlatformTDC;
221 ptr->small_ac_platform_tdc
222 = atom_ppm_table->ulSmallACPlatformTDC;
223 ptr->apu_tdp
224 = atom_ppm_table->ulApuTDP;
225 ptr->dgpu_tdp
226 = atom_ppm_table->ulDGpuTDP;
227 ptr->dgpu_ulv_power
228 = atom_ppm_table->ulDGpuUlvPower;
229 ptr->tj_max
230 = atom_ppm_table->ulTjmax;
231
232 pp_table_information->ppm_parameter_table = ptr;
233
234 return 0;
235}
236
237/**
238 * Private Function used during initialization.
239 * Initialize TDP limits for DPM2
240 * @param hwmgr Pointer to the hardware manager.
241 * @param powerplay_table Pointer to the PowerPlay Table.
242 */
243static int init_dpm_2_parameters(
244 struct pp_hwmgr *hwmgr,
245 const ATOM_Tonga_POWERPLAYTABLE *powerplay_table
246 )
247{
248 int result = 0;
249 struct phm_ppt_v1_information *pp_table_information = (struct phm_ppt_v1_information *)(hwmgr->pptable);
250 ATOM_Tonga_PPM_Table *atom_ppm_table;
251 uint32_t disable_ppm = 0;
252 uint32_t disable_power_control = 0;
253
254 pp_table_information->us_ulv_voltage_offset =
255 le16_to_cpu(powerplay_table->usUlvVoltageOffset);
256
257 pp_table_information->ppm_parameter_table = NULL;
258 pp_table_information->vddc_lookup_table = NULL;
259 pp_table_information->vddgfx_lookup_table = NULL;
260 /* TDP limits */
261 hwmgr->platform_descriptor.TDPODLimit =
262 le16_to_cpu(powerplay_table->usPowerControlLimit);
263 hwmgr->platform_descriptor.TDPAdjustment = 0;
264 hwmgr->platform_descriptor.VidAdjustment = 0;
265 hwmgr->platform_descriptor.VidAdjustmentPolarity = 0;
266 hwmgr->platform_descriptor.VidMinLimit = 0;
267 hwmgr->platform_descriptor.VidMaxLimit = 1500000;
268 hwmgr->platform_descriptor.VidStep = 6250;
269
270 disable_power_control = 0;
271 if (0 == disable_power_control) {
272 /* enable TDP overdrive (PowerControl) feature as well if supported */
273 if (hwmgr->platform_descriptor.TDPODLimit != 0)
274 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
275 PHM_PlatformCaps_PowerControl);
276 }
277
278 if (0 != powerplay_table->usVddcLookupTableOffset) {
279 const ATOM_Tonga_Voltage_Lookup_Table *pVddcCACTable =
280 (ATOM_Tonga_Voltage_Lookup_Table *)(((unsigned long)powerplay_table) +
281 le16_to_cpu(powerplay_table->usVddcLookupTableOffset));
282
283 result = get_vddc_lookup_table(hwmgr,
284 &pp_table_information->vddc_lookup_table, pVddcCACTable, 16);
285 }
286
287 if (0 != powerplay_table->usVddgfxLookupTableOffset) {
288 const ATOM_Tonga_Voltage_Lookup_Table *pVddgfxCACTable =
289 (ATOM_Tonga_Voltage_Lookup_Table *)(((unsigned long)powerplay_table) +
290 le16_to_cpu(powerplay_table->usVddgfxLookupTableOffset));
291
292 result = get_vddc_lookup_table(hwmgr,
293 &pp_table_information->vddgfx_lookup_table, pVddgfxCACTable, 16);
294 }
295
296 disable_ppm = 0;
297 if (0 == disable_ppm) {
298 atom_ppm_table = (ATOM_Tonga_PPM_Table *)
299 (((unsigned long)powerplay_table) + le16_to_cpu(powerplay_table->usPPMTableOffset));
300
301 if (0 != powerplay_table->usPPMTableOffset) {
302 if (1 == get_platform_power_management_table(hwmgr, atom_ppm_table)) {
303 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
304 PHM_PlatformCaps_EnablePlatformPowerManagement);
305 }
306 }
307 }
308
309 return result;
310}
311
312static int get_valid_clk(
313 struct pp_hwmgr *hwmgr,
314 struct phm_clock_array **clk_table,
315 const phm_ppt_v1_clock_voltage_dependency_table * clk_volt_pp_table
316 )
317{
318 uint32_t table_size, i;
319 struct phm_clock_array *table;
320
321 PP_ASSERT_WITH_CODE((0 != clk_volt_pp_table->count),
322 "Invalid PowerPlay Table!", return -1);
323
324 table_size = sizeof(uint32_t) +
325 sizeof(uint32_t) * clk_volt_pp_table->count;
326
327 table = (struct phm_clock_array *)kzalloc(table_size, GFP_KERNEL);
328
329 if (NULL == table)
Rex Zhuc15c8d72016-01-06 16:48:38 +0800330 return -ENOMEM;
yanyang1c82baa22015-08-18 15:28:32 +0800331
332 memset(table, 0x00, table_size);
333
334 table->count = (uint32_t)clk_volt_pp_table->count;
335
336 for (i = 0; i < table->count; i++)
337 table->values[i] = (uint32_t)clk_volt_pp_table->entries[i].clk;
338
339 *clk_table = table;
340
341 return 0;
342}
343
344static int get_hard_limits(
345 struct pp_hwmgr *hwmgr,
346 struct phm_clock_and_voltage_limits *limits,
347 const ATOM_Tonga_Hard_Limit_Table * limitable
348 )
349{
350 PP_ASSERT_WITH_CODE((0 != limitable->ucNumEntries), "Invalid PowerPlay Table!", return -1);
351
352 /* currently we always take entries[0] parameters */
353 limits->sclk = (uint32_t)limitable->entries[0].ulSCLKLimit;
354 limits->mclk = (uint32_t)limitable->entries[0].ulMCLKLimit;
355 limits->vddc = (uint16_t)limitable->entries[0].usVddcLimit;
356 limits->vddci = (uint16_t)limitable->entries[0].usVddciLimit;
357 limits->vddgfx = (uint16_t)limitable->entries[0].usVddgfxLimit;
358
359 return 0;
360}
361
362static int get_mclk_voltage_dependency_table(
363 struct pp_hwmgr *hwmgr,
364 phm_ppt_v1_clock_voltage_dependency_table **pp_tonga_mclk_dep_table,
365 const ATOM_Tonga_MCLK_Dependency_Table * mclk_dep_table
366 )
367{
368 uint32_t table_size, i;
369 phm_ppt_v1_clock_voltage_dependency_table *mclk_table;
370
371 PP_ASSERT_WITH_CODE((0 != mclk_dep_table->ucNumEntries),
372 "Invalid PowerPlay Table!", return -1);
373
374 table_size = sizeof(uint32_t) + sizeof(phm_ppt_v1_clock_voltage_dependency_record)
375 * mclk_dep_table->ucNumEntries;
376
377 mclk_table = (phm_ppt_v1_clock_voltage_dependency_table *)
378 kzalloc(table_size, GFP_KERNEL);
379
380 if (NULL == mclk_table)
Rex Zhuc15c8d72016-01-06 16:48:38 +0800381 return -ENOMEM;
yanyang1c82baa22015-08-18 15:28:32 +0800382
383 memset(mclk_table, 0x00, table_size);
384
385 mclk_table->count = (uint32_t)mclk_dep_table->ucNumEntries;
386
387 for (i = 0; i < mclk_dep_table->ucNumEntries; i++) {
388 mclk_table->entries[i].vddInd =
389 mclk_dep_table->entries[i].ucVddcInd;
390 mclk_table->entries[i].vdd_offset =
391 mclk_dep_table->entries[i].usVddgfxOffset;
392 mclk_table->entries[i].vddci =
393 mclk_dep_table->entries[i].usVddci;
394 mclk_table->entries[i].mvdd =
395 mclk_dep_table->entries[i].usMvdd;
396 mclk_table->entries[i].clk =
397 mclk_dep_table->entries[i].ulMclk;
398 }
399
400 *pp_tonga_mclk_dep_table = mclk_table;
401
402 return 0;
403}
404
405static int get_sclk_voltage_dependency_table(
406 struct pp_hwmgr *hwmgr,
407 phm_ppt_v1_clock_voltage_dependency_table **pp_tonga_sclk_dep_table,
408 const ATOM_Tonga_SCLK_Dependency_Table * sclk_dep_table
409 )
410{
411 uint32_t table_size, i;
412 phm_ppt_v1_clock_voltage_dependency_table *sclk_table;
413
414 PP_ASSERT_WITH_CODE((0 != sclk_dep_table->ucNumEntries),
415 "Invalid PowerPlay Table!", return -1);
416
417 table_size = sizeof(uint32_t) + sizeof(phm_ppt_v1_clock_voltage_dependency_record)
418 * sclk_dep_table->ucNumEntries;
419
420 sclk_table = (phm_ppt_v1_clock_voltage_dependency_table *)
421 kzalloc(table_size, GFP_KERNEL);
422
423 if (NULL == sclk_table)
Rex Zhuc15c8d72016-01-06 16:48:38 +0800424 return -ENOMEM;
yanyang1c82baa22015-08-18 15:28:32 +0800425
426 memset(sclk_table, 0x00, table_size);
427
428 sclk_table->count = (uint32_t)sclk_dep_table->ucNumEntries;
429
430 for (i = 0; i < sclk_dep_table->ucNumEntries; i++) {
431 sclk_table->entries[i].vddInd =
432 sclk_dep_table->entries[i].ucVddInd;
433 sclk_table->entries[i].vdd_offset =
434 sclk_dep_table->entries[i].usVddcOffset;
435 sclk_table->entries[i].clk =
436 sclk_dep_table->entries[i].ulSclk;
437 sclk_table->entries[i].cks_enable =
438 (((sclk_dep_table->entries[i].ucCKSVOffsetandDisable & 0x80) >> 7) == 0) ? 1 : 0;
439 sclk_table->entries[i].cks_voffset =
440 (sclk_dep_table->entries[i].ucCKSVOffsetandDisable & 0x7F);
441 }
442
443 *pp_tonga_sclk_dep_table = sclk_table;
444
445 return 0;
446}
447
448static int get_pcie_table(
449 struct pp_hwmgr *hwmgr,
450 phm_ppt_v1_pcie_table **pp_tonga_pcie_table,
451 const ATOM_Tonga_PCIE_Table * atom_pcie_table
452 )
453{
454 uint32_t table_size, i, pcie_count;
455 phm_ppt_v1_pcie_table *pcie_table;
456 struct phm_ppt_v1_information *pp_table_information =
457 (struct phm_ppt_v1_information *)(hwmgr->pptable);
458 PP_ASSERT_WITH_CODE((0 != atom_pcie_table->ucNumEntries),
459 "Invalid PowerPlay Table!", return -1);
460
461 table_size = sizeof(uint32_t) +
462 sizeof(phm_ppt_v1_pcie_record) * atom_pcie_table->ucNumEntries;
463
464 pcie_table = (phm_ppt_v1_pcie_table *)kzalloc(table_size, GFP_KERNEL);
465
466 if (NULL == pcie_table)
Rex Zhuc15c8d72016-01-06 16:48:38 +0800467 return -ENOMEM;
yanyang1c82baa22015-08-18 15:28:32 +0800468
469 memset(pcie_table, 0x00, table_size);
470
471 /*
472 * Make sure the number of pcie entries are less than or equal to sclk dpm levels.
473 * Since first PCIE entry is for ULV, #pcie has to be <= SclkLevel + 1.
474 */
475 pcie_count = (pp_table_information->vdd_dep_on_sclk->count) + 1;
476 if ((uint32_t)atom_pcie_table->ucNumEntries <= pcie_count)
477 pcie_count = (uint32_t)atom_pcie_table->ucNumEntries;
478 else
479 printk(KERN_ERR "[ powerplay ] Number of Pcie Entries exceed the number of SCLK Dpm Levels! \
480 Disregarding the excess entries... \n");
481
482 pcie_table->count = pcie_count;
483
484 for (i = 0; i < pcie_count; i++) {
485 pcie_table->entries[i].gen_speed =
486 atom_pcie_table->entries[i].ucPCIEGenSpeed;
487 pcie_table->entries[i].lane_width =
488 atom_pcie_table->entries[i].usPCIELaneWidth;
489 }
490
491 *pp_tonga_pcie_table = pcie_table;
492
493 return 0;
494}
495
496static int get_cac_tdp_table(
497 struct pp_hwmgr *hwmgr,
498 struct phm_cac_tdp_table **cac_tdp_table,
499 const PPTable_Generic_SubTable_Header * table
500 )
501{
502 uint32_t table_size;
503 struct phm_cac_tdp_table *tdp_table;
504
505 table_size = sizeof(uint32_t) + sizeof(struct phm_cac_tdp_table);
506 tdp_table = kzalloc(table_size, GFP_KERNEL);
507
508 if (NULL == tdp_table)
Rex Zhuc15c8d72016-01-06 16:48:38 +0800509 return -ENOMEM;
yanyang1c82baa22015-08-18 15:28:32 +0800510
511 memset(tdp_table, 0x00, table_size);
512
513 hwmgr->dyn_state.cac_dtp_table = kzalloc(table_size, GFP_KERNEL);
514
Colin Ian Kinga82d3972016-03-18 16:47:29 +0000515 if (NULL == hwmgr->dyn_state.cac_dtp_table) {
516 kfree(tdp_table);
Rex Zhuc15c8d72016-01-06 16:48:38 +0800517 return -ENOMEM;
Colin Ian Kinga82d3972016-03-18 16:47:29 +0000518 }
yanyang1c82baa22015-08-18 15:28:32 +0800519
520 memset(hwmgr->dyn_state.cac_dtp_table, 0x00, table_size);
521
522 if (table->ucRevId < 3) {
523 const ATOM_Tonga_PowerTune_Table *tonga_table =
524 (ATOM_Tonga_PowerTune_Table *)table;
525 tdp_table->usTDP = tonga_table->usTDP;
526 tdp_table->usConfigurableTDP =
527 tonga_table->usConfigurableTDP;
528 tdp_table->usTDC = tonga_table->usTDC;
529 tdp_table->usBatteryPowerLimit =
530 tonga_table->usBatteryPowerLimit;
531 tdp_table->usSmallPowerLimit =
532 tonga_table->usSmallPowerLimit;
533 tdp_table->usLowCACLeakage =
534 tonga_table->usLowCACLeakage;
535 tdp_table->usHighCACLeakage =
536 tonga_table->usHighCACLeakage;
537 tdp_table->usMaximumPowerDeliveryLimit =
538 tonga_table->usMaximumPowerDeliveryLimit;
539 tdp_table->usDefaultTargetOperatingTemp =
540 tonga_table->usTjMax;
541 tdp_table->usTargetOperatingTemp =
542 tonga_table->usTjMax; /*Set the initial temp to the same as default */
543 tdp_table->usPowerTuneDataSetID =
544 tonga_table->usPowerTuneDataSetID;
545 tdp_table->usSoftwareShutdownTemp =
546 tonga_table->usSoftwareShutdownTemp;
547 tdp_table->usClockStretchAmount =
548 tonga_table->usClockStretchAmount;
549 } else { /* Fiji and newer */
550 const ATOM_Fiji_PowerTune_Table *fijitable =
551 (ATOM_Fiji_PowerTune_Table *)table;
552 tdp_table->usTDP = fijitable->usTDP;
553 tdp_table->usConfigurableTDP = fijitable->usConfigurableTDP;
554 tdp_table->usTDC = fijitable->usTDC;
555 tdp_table->usBatteryPowerLimit = fijitable->usBatteryPowerLimit;
556 tdp_table->usSmallPowerLimit = fijitable->usSmallPowerLimit;
557 tdp_table->usLowCACLeakage = fijitable->usLowCACLeakage;
558 tdp_table->usHighCACLeakage = fijitable->usHighCACLeakage;
559 tdp_table->usMaximumPowerDeliveryLimit =
560 fijitable->usMaximumPowerDeliveryLimit;
561 tdp_table->usDefaultTargetOperatingTemp =
562 fijitable->usTjMax;
563 tdp_table->usTargetOperatingTemp =
564 fijitable->usTjMax; /*Set the initial temp to the same as default */
565 tdp_table->usPowerTuneDataSetID =
566 fijitable->usPowerTuneDataSetID;
567 tdp_table->usSoftwareShutdownTemp =
568 fijitable->usSoftwareShutdownTemp;
569 tdp_table->usClockStretchAmount =
570 fijitable->usClockStretchAmount;
571 tdp_table->usTemperatureLimitHotspot =
572 fijitable->usTemperatureLimitHotspot;
573 tdp_table->usTemperatureLimitLiquid1 =
574 fijitable->usTemperatureLimitLiquid1;
575 tdp_table->usTemperatureLimitLiquid2 =
576 fijitable->usTemperatureLimitLiquid2;
577 tdp_table->usTemperatureLimitVrVddc =
578 fijitable->usTemperatureLimitVrVddc;
579 tdp_table->usTemperatureLimitVrMvdd =
580 fijitable->usTemperatureLimitVrMvdd;
581 tdp_table->usTemperatureLimitPlx =
582 fijitable->usTemperatureLimitPlx;
583 tdp_table->ucLiquid1_I2C_address =
584 fijitable->ucLiquid1_I2C_address;
585 tdp_table->ucLiquid2_I2C_address =
586 fijitable->ucLiquid2_I2C_address;
587 tdp_table->ucLiquid_I2C_Line =
588 fijitable->ucLiquid_I2C_Line;
589 tdp_table->ucVr_I2C_address = fijitable->ucVr_I2C_address;
590 tdp_table->ucVr_I2C_Line = fijitable->ucVr_I2C_Line;
591 tdp_table->ucPlx_I2C_address = fijitable->ucPlx_I2C_address;
592 tdp_table->ucPlx_I2C_Line = fijitable->ucPlx_I2C_Line;
593 }
594
595 *cac_tdp_table = tdp_table;
596
597 return 0;
598}
599
600static int get_mm_clock_voltage_table(
601 struct pp_hwmgr *hwmgr,
602 phm_ppt_v1_mm_clock_voltage_dependency_table **tonga_mm_table,
603 const ATOM_Tonga_MM_Dependency_Table * mm_dependency_table
604 )
605{
606 uint32_t table_size, i;
607 const ATOM_Tonga_MM_Dependency_Record *mm_dependency_record;
608 phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table;
609
610 PP_ASSERT_WITH_CODE((0 != mm_dependency_table->ucNumEntries),
611 "Invalid PowerPlay Table!", return -1);
612 table_size = sizeof(uint32_t) +
613 sizeof(phm_ppt_v1_mm_clock_voltage_dependency_record)
614 * mm_dependency_table->ucNumEntries;
615 mm_table = (phm_ppt_v1_mm_clock_voltage_dependency_table *)
616 kzalloc(table_size, GFP_KERNEL);
617
618 if (NULL == mm_table)
Rex Zhuc15c8d72016-01-06 16:48:38 +0800619 return -ENOMEM;
yanyang1c82baa22015-08-18 15:28:32 +0800620
621 memset(mm_table, 0x00, table_size);
622
623 mm_table->count = mm_dependency_table->ucNumEntries;
624
625 for (i = 0; i < mm_dependency_table->ucNumEntries; i++) {
626 mm_dependency_record = &mm_dependency_table->entries[i];
627 mm_table->entries[i].vddcInd = mm_dependency_record->ucVddcInd;
628 mm_table->entries[i].vddgfx_offset = mm_dependency_record->usVddgfxOffset;
629 mm_table->entries[i].aclk = mm_dependency_record->ulAClk;
630 mm_table->entries[i].samclock = mm_dependency_record->ulSAMUClk;
631 mm_table->entries[i].eclk = mm_dependency_record->ulEClk;
632 mm_table->entries[i].vclk = mm_dependency_record->ulVClk;
633 mm_table->entries[i].dclk = mm_dependency_record->ulDClk;
634 }
635
636 *tonga_mm_table = mm_table;
637
638 return 0;
639}
640
641/**
642 * Private Function used during initialization.
643 * Initialize clock voltage dependency
644 * @param hwmgr Pointer to the hardware manager.
645 * @param powerplay_table Pointer to the PowerPlay Table.
646 */
647static int init_clock_voltage_dependency(
648 struct pp_hwmgr *hwmgr,
649 const ATOM_Tonga_POWERPLAYTABLE *powerplay_table
650 )
651{
652 int result = 0;
653 struct phm_ppt_v1_information *pp_table_information =
654 (struct phm_ppt_v1_information *)(hwmgr->pptable);
655
656 const ATOM_Tonga_MM_Dependency_Table *mm_dependency_table =
657 (const ATOM_Tonga_MM_Dependency_Table *)(((unsigned long) powerplay_table) +
658 le16_to_cpu(powerplay_table->usMMDependencyTableOffset));
659 const PPTable_Generic_SubTable_Header *pPowerTuneTable =
660 (const PPTable_Generic_SubTable_Header *)(((unsigned long) powerplay_table) +
661 le16_to_cpu(powerplay_table->usPowerTuneTableOffset));
662 const ATOM_Tonga_MCLK_Dependency_Table *mclk_dep_table =
663 (const ATOM_Tonga_MCLK_Dependency_Table *)(((unsigned long) powerplay_table) +
664 le16_to_cpu(powerplay_table->usMclkDependencyTableOffset));
665 const ATOM_Tonga_SCLK_Dependency_Table *sclk_dep_table =
666 (const ATOM_Tonga_SCLK_Dependency_Table *)(((unsigned long) powerplay_table) +
667 le16_to_cpu(powerplay_table->usSclkDependencyTableOffset));
668 const ATOM_Tonga_Hard_Limit_Table *pHardLimits =
669 (const ATOM_Tonga_Hard_Limit_Table *)(((unsigned long) powerplay_table) +
670 le16_to_cpu(powerplay_table->usHardLimitTableOffset));
671 const ATOM_Tonga_PCIE_Table *pcie_table =
672 (const ATOM_Tonga_PCIE_Table *)(((unsigned long) powerplay_table) +
673 le16_to_cpu(powerplay_table->usPCIETableOffset));
674
675 pp_table_information->vdd_dep_on_sclk = NULL;
676 pp_table_information->vdd_dep_on_mclk = NULL;
677 pp_table_information->mm_dep_table = NULL;
678 pp_table_information->pcie_table = NULL;
679
680 if (powerplay_table->usMMDependencyTableOffset != 0)
681 result = get_mm_clock_voltage_table(hwmgr,
682 &pp_table_information->mm_dep_table, mm_dependency_table);
683
684 if (result == 0 && powerplay_table->usPowerTuneTableOffset != 0)
685 result = get_cac_tdp_table(hwmgr,
686 &pp_table_information->cac_dtp_table, pPowerTuneTable);
687
688 if (result == 0 && powerplay_table->usSclkDependencyTableOffset != 0)
689 result = get_sclk_voltage_dependency_table(hwmgr,
690 &pp_table_information->vdd_dep_on_sclk, sclk_dep_table);
691
692 if (result == 0 && powerplay_table->usMclkDependencyTableOffset != 0)
693 result = get_mclk_voltage_dependency_table(hwmgr,
694 &pp_table_information->vdd_dep_on_mclk, mclk_dep_table);
695
696 if (result == 0 && powerplay_table->usPCIETableOffset != 0)
697 result = get_pcie_table(hwmgr,
698 &pp_table_information->pcie_table, pcie_table);
699
700 if (result == 0 && powerplay_table->usHardLimitTableOffset != 0)
701 result = get_hard_limits(hwmgr,
702 &pp_table_information->max_clock_voltage_on_dc, pHardLimits);
703
704 hwmgr->dyn_state.max_clock_voltage_on_dc.sclk =
705 pp_table_information->max_clock_voltage_on_dc.sclk;
706 hwmgr->dyn_state.max_clock_voltage_on_dc.mclk =
707 pp_table_information->max_clock_voltage_on_dc.mclk;
708 hwmgr->dyn_state.max_clock_voltage_on_dc.vddc =
709 pp_table_information->max_clock_voltage_on_dc.vddc;
710 hwmgr->dyn_state.max_clock_voltage_on_dc.vddci =
711 pp_table_information->max_clock_voltage_on_dc.vddci;
712
713 if (result == 0 && (NULL != pp_table_information->vdd_dep_on_mclk)
714 && (0 != pp_table_information->vdd_dep_on_mclk->count))
715 result = get_valid_clk(hwmgr, &pp_table_information->valid_mclk_values,
716 pp_table_information->vdd_dep_on_mclk);
717
718 if (result == 0 && (NULL != pp_table_information->vdd_dep_on_sclk)
719 && (0 != pp_table_information->vdd_dep_on_sclk->count))
720 result = get_valid_clk(hwmgr, &pp_table_information->valid_sclk_values,
721 pp_table_information->vdd_dep_on_sclk);
722
723 return result;
724}
725
726/** Retrieves the (signed) Overdrive limits from VBIOS.
727 * The max engine clock, memory clock and max temperature come from the firmware info table.
728 *
729 * The information is placed into the platform descriptor.
730 *
731 * @param hwmgr source of the VBIOS table and owner of the platform descriptor to be updated.
732 * @param powerplay_table the address of the PowerPlay table.
733 *
734 * @return 1 as long as the firmware info table was present and of a supported version.
735 */
736static int init_over_drive_limits(
737 struct pp_hwmgr *hwmgr,
738 const ATOM_Tonga_POWERPLAYTABLE *powerplay_table)
739{
740 hwmgr->platform_descriptor.overdriveLimit.engineClock =
741 le16_to_cpu(powerplay_table->ulMaxODEngineClock);
742 hwmgr->platform_descriptor.overdriveLimit.memoryClock =
743 le16_to_cpu(powerplay_table->ulMaxODMemoryClock);
744
745 hwmgr->platform_descriptor.minOverdriveVDDC = 0;
746 hwmgr->platform_descriptor.maxOverdriveVDDC = 0;
747 hwmgr->platform_descriptor.overdriveVDDCStep = 0;
748
749 if (hwmgr->platform_descriptor.overdriveLimit.engineClock > 0 \
750 && hwmgr->platform_descriptor.overdriveLimit.memoryClock > 0) {
751 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
752 PHM_PlatformCaps_ACOverdriveSupport);
753 }
754
755 return 0;
756}
757
758/**
759 * Private Function used during initialization.
760 * Inspect the PowerPlay table for obvious signs of corruption.
761 * @param hwmgr Pointer to the hardware manager.
762 * @param powerplay_table Pointer to the PowerPlay Table.
763 * @exception This implementation always returns 1.
764 */
765static int init_thermal_controller(
766 struct pp_hwmgr *hwmgr,
767 const ATOM_Tonga_POWERPLAYTABLE *powerplay_table
768 )
769{
770 const PPTable_Generic_SubTable_Header *fan_table;
771 ATOM_Tonga_Thermal_Controller *thermal_controller;
772
773 thermal_controller = (ATOM_Tonga_Thermal_Controller *)
774 (((unsigned long)powerplay_table) +
775 le16_to_cpu(powerplay_table->usThermalControllerOffset));
776 PP_ASSERT_WITH_CODE((0 != powerplay_table->usThermalControllerOffset),
777 "Thermal controller table not set!", return -1);
778
779 hwmgr->thermal_controller.ucType = thermal_controller->ucType;
780 hwmgr->thermal_controller.ucI2cLine = thermal_controller->ucI2cLine;
781 hwmgr->thermal_controller.ucI2cAddress = thermal_controller->ucI2cAddress;
782
783 hwmgr->thermal_controller.fanInfo.bNoFan =
784 (0 != (thermal_controller->ucFanParameters & ATOM_TONGA_PP_FANPARAMETERS_NOFAN));
785
786 hwmgr->thermal_controller.fanInfo.ucTachometerPulsesPerRevolution =
787 thermal_controller->ucFanParameters &
788 ATOM_TONGA_PP_FANPARAMETERS_TACHOMETER_PULSES_PER_REVOLUTION_MASK;
789
790 hwmgr->thermal_controller.fanInfo.ulMinRPM
791 = thermal_controller->ucFanMinRPM * 100UL;
792 hwmgr->thermal_controller.fanInfo.ulMaxRPM
793 = thermal_controller->ucFanMaxRPM * 100UL;
794
795 set_hw_cap(
796 hwmgr,
797 ATOM_TONGA_PP_THERMALCONTROLLER_NONE != hwmgr->thermal_controller.ucType,
798 PHM_PlatformCaps_ThermalController
799 );
800
801 if (0 == powerplay_table->usFanTableOffset)
Alex Deucher283b1a82015-12-14 10:46:52 -0500802 return 0;
yanyang1c82baa22015-08-18 15:28:32 +0800803
804 fan_table = (const PPTable_Generic_SubTable_Header *)
805 (((unsigned long)powerplay_table) +
806 le16_to_cpu(powerplay_table->usFanTableOffset));
807
808 PP_ASSERT_WITH_CODE((0 != powerplay_table->usFanTableOffset),
809 "Fan table not set!", return -1);
810 PP_ASSERT_WITH_CODE((0 < fan_table->ucRevId),
811 "Unsupported fan table format!", return -1);
812
813 hwmgr->thermal_controller.advanceFanControlParameters.ulCycleDelay
814 = 100000;
815 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
816 PHM_PlatformCaps_MicrocodeFanControl);
817
818 if (fan_table->ucRevId < 8) {
819 const ATOM_Tonga_Fan_Table *tonga_fan_table =
820 (ATOM_Tonga_Fan_Table *)fan_table;
821 hwmgr->thermal_controller.advanceFanControlParameters.ucTHyst
822 = tonga_fan_table->ucTHyst;
823 hwmgr->thermal_controller.advanceFanControlParameters.usTMin
824 = tonga_fan_table->usTMin;
825 hwmgr->thermal_controller.advanceFanControlParameters.usTMed
826 = tonga_fan_table->usTMed;
827 hwmgr->thermal_controller.advanceFanControlParameters.usTHigh
828 = tonga_fan_table->usTHigh;
829 hwmgr->thermal_controller.advanceFanControlParameters.usPWMMin
830 = tonga_fan_table->usPWMMin;
831 hwmgr->thermal_controller.advanceFanControlParameters.usPWMMed
832 = tonga_fan_table->usPWMMed;
833 hwmgr->thermal_controller.advanceFanControlParameters.usPWMHigh
834 = tonga_fan_table->usPWMHigh;
835 hwmgr->thermal_controller.advanceFanControlParameters.usTMax
836 = 10900; /* hard coded */
837 hwmgr->thermal_controller.advanceFanControlParameters.usTMax
838 = tonga_fan_table->usTMax;
839 hwmgr->thermal_controller.advanceFanControlParameters.ucFanControlMode
840 = tonga_fan_table->ucFanControlMode;
841 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM
842 = tonga_fan_table->usFanPWMMax;
843 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultFanOutputSensitivity
844 = 4836;
845 hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity
846 = tonga_fan_table->usFanOutputSensitivity;
847 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanRPM
848 = tonga_fan_table->usFanRPMMax;
849 hwmgr->thermal_controller.advanceFanControlParameters.ulMinFanSCLKAcousticLimit
850 = (tonga_fan_table->ulMinFanSCLKAcousticLimit / 100); /* PPTable stores it in 10Khz unit for 2 decimal places. SMC wants MHz. */
851 hwmgr->thermal_controller.advanceFanControlParameters.ucTargetTemperature
852 = tonga_fan_table->ucTargetTemperature;
853 hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit
854 = tonga_fan_table->ucMinimumPWMLimit;
855 } else {
856 const ATOM_Fiji_Fan_Table *fiji_fan_table =
857 (ATOM_Fiji_Fan_Table *)fan_table;
858 hwmgr->thermal_controller.advanceFanControlParameters.ucTHyst
859 = fiji_fan_table->ucTHyst;
860 hwmgr->thermal_controller.advanceFanControlParameters.usTMin
861 = fiji_fan_table->usTMin;
862 hwmgr->thermal_controller.advanceFanControlParameters.usTMed
863 = fiji_fan_table->usTMed;
864 hwmgr->thermal_controller.advanceFanControlParameters.usTHigh
865 = fiji_fan_table->usTHigh;
866 hwmgr->thermal_controller.advanceFanControlParameters.usPWMMin
867 = fiji_fan_table->usPWMMin;
868 hwmgr->thermal_controller.advanceFanControlParameters.usPWMMed
869 = fiji_fan_table->usPWMMed;
870 hwmgr->thermal_controller.advanceFanControlParameters.usPWMHigh
871 = fiji_fan_table->usPWMHigh;
872 hwmgr->thermal_controller.advanceFanControlParameters.usTMax
873 = fiji_fan_table->usTMax;
874 hwmgr->thermal_controller.advanceFanControlParameters.ucFanControlMode
875 = fiji_fan_table->ucFanControlMode;
876 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM
877 = fiji_fan_table->usFanPWMMax;
878 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultFanOutputSensitivity
879 = 4836;
880 hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity
881 = fiji_fan_table->usFanOutputSensitivity;
882 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanRPM
883 = fiji_fan_table->usFanRPMMax;
884 hwmgr->thermal_controller.advanceFanControlParameters.ulMinFanSCLKAcousticLimit
885 = (fiji_fan_table->ulMinFanSCLKAcousticLimit / 100); /* PPTable stores it in 10Khz unit for 2 decimal places. SMC wants MHz. */
886 hwmgr->thermal_controller.advanceFanControlParameters.ucTargetTemperature
887 = fiji_fan_table->ucTargetTemperature;
888 hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit
889 = fiji_fan_table->ucMinimumPWMLimit;
890
891 hwmgr->thermal_controller.advanceFanControlParameters.usFanGainEdge
892 = fiji_fan_table->usFanGainEdge;
893 hwmgr->thermal_controller.advanceFanControlParameters.usFanGainHotspot
894 = fiji_fan_table->usFanGainHotspot;
895 hwmgr->thermal_controller.advanceFanControlParameters.usFanGainLiquid
896 = fiji_fan_table->usFanGainLiquid;
897 hwmgr->thermal_controller.advanceFanControlParameters.usFanGainVrVddc
898 = fiji_fan_table->usFanGainVrVddc;
899 hwmgr->thermal_controller.advanceFanControlParameters.usFanGainVrMvdd
900 = fiji_fan_table->usFanGainVrMvdd;
901 hwmgr->thermal_controller.advanceFanControlParameters.usFanGainPlx
902 = fiji_fan_table->usFanGainPlx;
903 hwmgr->thermal_controller.advanceFanControlParameters.usFanGainHbm
904 = fiji_fan_table->usFanGainHbm;
905 }
906
907 return 0;
908}
909
910/**
911 * Private Function used during initialization.
912 * Inspect the PowerPlay table for obvious signs of corruption.
913 * @param hwmgr Pointer to the hardware manager.
914 * @param powerplay_table Pointer to the PowerPlay Table.
915 * @exception 2 if the powerplay table is incorrect.
916 */
917static int check_powerplay_tables(
918 struct pp_hwmgr *hwmgr,
919 const ATOM_Tonga_POWERPLAYTABLE *powerplay_table
920 )
921{
922 const ATOM_Tonga_State_Array *state_arrays;
923
924 state_arrays = (ATOM_Tonga_State_Array *)(((unsigned long)powerplay_table) +
925 le16_to_cpu(powerplay_table->usStateArrayOffset));
926
927 PP_ASSERT_WITH_CODE((ATOM_Tonga_TABLE_REVISION_TONGA <=
928 powerplay_table->sHeader.ucTableFormatRevision),
929 "Unsupported PPTable format!", return -1);
930 PP_ASSERT_WITH_CODE((0 != powerplay_table->usStateArrayOffset),
931 "State table is not set!", return -1);
932 PP_ASSERT_WITH_CODE((0 < powerplay_table->sHeader.usStructureSize),
933 "Invalid PowerPlay Table!", return -1);
934 PP_ASSERT_WITH_CODE((0 < state_arrays->ucNumEntries),
935 "Invalid PowerPlay Table!", return -1);
936
937 return 0;
938}
939
940int tonga_pp_tables_initialize(struct pp_hwmgr *hwmgr)
941{
942 int result = 0;
943 const ATOM_Tonga_POWERPLAYTABLE *powerplay_table;
944
945 hwmgr->pptable = kzalloc(sizeof(struct phm_ppt_v1_information), GFP_KERNEL);
946
Alex Deucher1d5498c2015-12-11 12:12:32 -0500947 PP_ASSERT_WITH_CODE((NULL != hwmgr->pptable),
Rex Zhuc15c8d72016-01-06 16:48:38 +0800948 "Failed to allocate hwmgr->pptable!", return -ENOMEM);
yanyang1c82baa22015-08-18 15:28:32 +0800949
950 memset(hwmgr->pptable, 0x00, sizeof(struct phm_ppt_v1_information));
951
952 powerplay_table = get_powerplay_table(hwmgr);
953
954 PP_ASSERT_WITH_CODE((NULL != powerplay_table),
955 "Missing PowerPlay Table!", return -1);
956
957 result = check_powerplay_tables(hwmgr, powerplay_table);
958
Alex Deucher1d5498c2015-12-11 12:12:32 -0500959 PP_ASSERT_WITH_CODE((result == 0),
960 "check_powerplay_tables failed", return result);
yanyang1c82baa22015-08-18 15:28:32 +0800961
Alex Deucher1d5498c2015-12-11 12:12:32 -0500962 result = set_platform_caps(hwmgr,
963 le32_to_cpu(powerplay_table->ulPlatformCaps));
yanyang1c82baa22015-08-18 15:28:32 +0800964
Alex Deucher1d5498c2015-12-11 12:12:32 -0500965 PP_ASSERT_WITH_CODE((result == 0),
966 "set_platform_caps failed", return result);
yanyang1c82baa22015-08-18 15:28:32 +0800967
Alex Deucher1d5498c2015-12-11 12:12:32 -0500968 result = init_thermal_controller(hwmgr, powerplay_table);
yanyang1c82baa22015-08-18 15:28:32 +0800969
Alex Deucher1d5498c2015-12-11 12:12:32 -0500970 PP_ASSERT_WITH_CODE((result == 0),
971 "init_thermal_controller failed", return result);
972
973 result = init_over_drive_limits(hwmgr, powerplay_table);
974
975 PP_ASSERT_WITH_CODE((result == 0),
976 "init_over_drive_limits failed", return result);
977
978 result = init_clock_voltage_dependency(hwmgr, powerplay_table);
979
980 PP_ASSERT_WITH_CODE((result == 0),
981 "init_clock_voltage_dependency failed", return result);
982
983 result = init_dpm_2_parameters(hwmgr, powerplay_table);
984
985 PP_ASSERT_WITH_CODE((result == 0),
986 "init_dpm_2_parameters failed", return result);
yanyang1c82baa22015-08-18 15:28:32 +0800987
988 return result;
989}
990
991int tonga_pp_tables_uninitialize(struct pp_hwmgr *hwmgr)
992{
993 int result = 0;
994 struct phm_ppt_v1_information *pp_table_information =
995 (struct phm_ppt_v1_information *)(hwmgr->pptable);
996
997 if (NULL != hwmgr->soft_pp_table) {
998 kfree(hwmgr->soft_pp_table);
999 hwmgr->soft_pp_table = NULL;
1000 }
1001
1002 if (NULL != pp_table_information->vdd_dep_on_sclk)
1003 pp_table_information->vdd_dep_on_sclk = NULL;
1004
1005 if (NULL != pp_table_information->vdd_dep_on_mclk)
1006 pp_table_information->vdd_dep_on_mclk = NULL;
1007
1008 if (NULL != pp_table_information->valid_mclk_values)
1009 pp_table_information->valid_mclk_values = NULL;
1010
1011 if (NULL != pp_table_information->valid_sclk_values)
1012 pp_table_information->valid_sclk_values = NULL;
1013
1014 if (NULL != pp_table_information->vddc_lookup_table)
1015 pp_table_information->vddc_lookup_table = NULL;
1016
1017 if (NULL != pp_table_information->vddgfx_lookup_table)
1018 pp_table_information->vddgfx_lookup_table = NULL;
1019
1020 if (NULL != pp_table_information->mm_dep_table)
1021 pp_table_information->mm_dep_table = NULL;
1022
1023 if (NULL != pp_table_information->cac_dtp_table)
1024 pp_table_information->cac_dtp_table = NULL;
1025
1026 if (NULL != hwmgr->dyn_state.cac_dtp_table)
1027 hwmgr->dyn_state.cac_dtp_table = NULL;
1028
1029 if (NULL != pp_table_information->ppm_parameter_table)
1030 pp_table_information->ppm_parameter_table = NULL;
1031
1032 if (NULL != pp_table_information->pcie_table)
1033 pp_table_information->pcie_table = NULL;
1034
1035 if (NULL != hwmgr->pptable) {
1036 kfree(hwmgr->pptable);
1037 hwmgr->pptable = NULL;
1038 }
1039
1040 return result;
1041}
1042
1043const struct pp_table_func tonga_pptable_funcs = {
1044 .pptable_init = tonga_pp_tables_initialize,
1045 .pptable_fini = tonga_pp_tables_uninitialize,
1046};
1047
1048int tonga_get_number_of_powerplay_table_entries(struct pp_hwmgr *hwmgr)
1049{
1050 const ATOM_Tonga_State_Array * state_arrays;
1051 const ATOM_Tonga_POWERPLAYTABLE *pp_table = get_powerplay_table(hwmgr);
1052
1053 PP_ASSERT_WITH_CODE((NULL != pp_table),
1054 "Missing PowerPlay Table!", return -1);
1055 PP_ASSERT_WITH_CODE((pp_table->sHeader.ucTableFormatRevision >=
1056 ATOM_Tonga_TABLE_REVISION_TONGA),
1057 "Incorrect PowerPlay table revision!", return -1);
1058
1059 state_arrays = (ATOM_Tonga_State_Array *)(((unsigned long)pp_table) +
1060 le16_to_cpu(pp_table->usStateArrayOffset));
1061
1062 return (uint32_t)(state_arrays->ucNumEntries);
1063}
1064
1065/**
1066* Private function to convert flags stored in the BIOS to software flags in PowerPlay.
1067*/
1068static uint32_t make_classification_flags(struct pp_hwmgr *hwmgr,
1069 uint16_t classification, uint16_t classification2)
1070{
1071 uint32_t result = 0;
1072
1073 if (classification & ATOM_PPLIB_CLASSIFICATION_BOOT)
1074 result |= PP_StateClassificationFlag_Boot;
1075
1076 if (classification & ATOM_PPLIB_CLASSIFICATION_THERMAL)
1077 result |= PP_StateClassificationFlag_Thermal;
1078
1079 if (classification & ATOM_PPLIB_CLASSIFICATION_LIMITEDPOWERSOURCE)
1080 result |= PP_StateClassificationFlag_LimitedPowerSource;
1081
1082 if (classification & ATOM_PPLIB_CLASSIFICATION_REST)
1083 result |= PP_StateClassificationFlag_Rest;
1084
1085 if (classification & ATOM_PPLIB_CLASSIFICATION_FORCED)
1086 result |= PP_StateClassificationFlag_Forced;
1087
1088 if (classification & ATOM_PPLIB_CLASSIFICATION_ACPI)
1089 result |= PP_StateClassificationFlag_ACPI;
1090
1091 if (classification2 & ATOM_PPLIB_CLASSIFICATION2_LIMITEDPOWERSOURCE_2)
1092 result |= PP_StateClassificationFlag_LimitedPowerSource_2;
1093
1094 return result;
1095}
1096
1097/**
1098* Create a Power State out of an entry in the PowerPlay table.
1099* This function is called by the hardware back-end.
1100* @param hwmgr Pointer to the hardware manager.
1101* @param entry_index The index of the entry to be extracted from the table.
1102* @param power_state The address of the PowerState instance being created.
1103* @return -1 if the entry cannot be retrieved.
1104*/
1105int tonga_get_powerplay_table_entry(struct pp_hwmgr *hwmgr,
1106 uint32_t entry_index, struct pp_power_state *power_state,
1107 int (*call_back_func)(struct pp_hwmgr *, void *,
1108 struct pp_power_state *, void *, uint32_t))
1109{
1110 int result = 0;
1111 const ATOM_Tonga_State_Array * state_arrays;
1112 const ATOM_Tonga_State *state_entry;
1113 const ATOM_Tonga_POWERPLAYTABLE *pp_table = get_powerplay_table(hwmgr);
1114
1115 PP_ASSERT_WITH_CODE((NULL != pp_table), "Missing PowerPlay Table!", return -1;);
1116 power_state->classification.bios_index = entry_index;
1117
1118 if (pp_table->sHeader.ucTableFormatRevision >=
1119 ATOM_Tonga_TABLE_REVISION_TONGA) {
1120 state_arrays = (ATOM_Tonga_State_Array *)(((unsigned long)pp_table) +
1121 le16_to_cpu(pp_table->usStateArrayOffset));
1122
1123 PP_ASSERT_WITH_CODE((0 < pp_table->usStateArrayOffset),
1124 "Invalid PowerPlay Table State Array Offset.", return -1);
1125 PP_ASSERT_WITH_CODE((0 < state_arrays->ucNumEntries),
1126 "Invalid PowerPlay Table State Array.", return -1);
1127 PP_ASSERT_WITH_CODE((entry_index <= state_arrays->ucNumEntries),
1128 "Invalid PowerPlay Table State Array Entry.", return -1);
1129
1130 state_entry = &(state_arrays->states[entry_index]);
1131
1132 result = call_back_func(hwmgr, (void *)state_entry, power_state,
1133 (void *)pp_table,
1134 make_classification_flags(hwmgr,
1135 le16_to_cpu(state_entry->usClassification),
1136 le16_to_cpu(state_entry->usClassification2)));
1137 }
1138
1139 if (!result && (power_state->classification.flags &
1140 PP_StateClassificationFlag_Boot))
1141 result = hwmgr->hwmgr_func->patch_boot_state(hwmgr, &(power_state->hardware));
1142
1143 return result;
1144}