blob: ecbc43f170bf3bef74294752b917d193ec63ff01 [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,
yanyang1e85c7d62016-02-06 13:28:47 +0800451 const PPTable_Generic_SubTable_Header * pTable
yanyang1c82baa22015-08-18 15:28:32 +0800452 )
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);
yanyang1c82baa22015-08-18 15:28:32 +0800458
yanyang1e85c7d62016-02-06 13:28:47 +0800459 if (pTable->ucRevId < 1) {
460 const ATOM_Tonga_PCIE_Table *atom_pcie_table = (ATOM_Tonga_PCIE_Table *)pTable;
461 PP_ASSERT_WITH_CODE((atom_pcie_table->ucNumEntries != 0),
462 "Invalid PowerPlay Table!", return -1);
yanyang1c82baa22015-08-18 15:28:32 +0800463
yanyang1e85c7d62016-02-06 13:28:47 +0800464 table_size = sizeof(uint32_t) +
465 sizeof(phm_ppt_v1_pcie_record) * atom_pcie_table->ucNumEntries;
yanyang1c82baa22015-08-18 15:28:32 +0800466
yanyang1e85c7d62016-02-06 13:28:47 +0800467 pcie_table = (phm_ppt_v1_pcie_table *)kzalloc(table_size, GFP_KERNEL);
yanyang1c82baa22015-08-18 15:28:32 +0800468
yanyang1e85c7d62016-02-06 13:28:47 +0800469 if (pcie_table == NULL)
470 return -ENOMEM;
yanyang1c82baa22015-08-18 15:28:32 +0800471
yanyang1e85c7d62016-02-06 13:28:47 +0800472 memset(pcie_table, 0x00, table_size);
yanyang1c82baa22015-08-18 15:28:32 +0800473
yanyang1e85c7d62016-02-06 13:28:47 +0800474 /*
475 * Make sure the number of pcie entries are less than or equal to sclk dpm levels.
476 * Since first PCIE entry is for ULV, #pcie has to be <= SclkLevel + 1.
477 */
478 pcie_count = (pp_table_information->vdd_dep_on_sclk->count) + 1;
479 if ((uint32_t)atom_pcie_table->ucNumEntries <= pcie_count)
480 pcie_count = (uint32_t)atom_pcie_table->ucNumEntries;
481 else
482 printk(KERN_ERR "[ powerplay ] Number of Pcie Entries exceed the number of SCLK Dpm Levels! \
483 Disregarding the excess entries... \n");
yanyang1c82baa22015-08-18 15:28:32 +0800484
yanyang1e85c7d62016-02-06 13:28:47 +0800485 pcie_table->count = pcie_count;
486
487 for (i = 0; i < pcie_count; i++) {
488 pcie_table->entries[i].gen_speed =
489 atom_pcie_table->entries[i].ucPCIEGenSpeed;
490 pcie_table->entries[i].lane_width =
491 atom_pcie_table->entries[i].usPCIELaneWidth;
492 }
493
494 *pp_tonga_pcie_table = pcie_table;
495 } else {
496 /* Ellesmere/Baffin and newer. */
497 const ATOM_Ellesmere_PCIE_Table *atom_pcie_table = (ATOM_Ellesmere_PCIE_Table *)pTable;
498 PP_ASSERT_WITH_CODE((atom_pcie_table->ucNumEntries != 0),
499 "Invalid PowerPlay Table!", return -1);
500
501 table_size = sizeof(uint32_t) +
502 sizeof(phm_ppt_v1_pcie_record) * atom_pcie_table->ucNumEntries;
503
504 pcie_table = (phm_ppt_v1_pcie_table *)kzalloc(table_size, GFP_KERNEL);
505
506 if (pcie_table == NULL)
507 return -ENOMEM;
508
509 memset(pcie_table, 0x00, table_size);
510
511 /*
512 * Make sure the number of pcie entries are less than or equal to sclk dpm levels.
513 * Since first PCIE entry is for ULV, #pcie has to be <= SclkLevel + 1.
514 */
515 pcie_count = (pp_table_information->vdd_dep_on_sclk->count) + 1;
516 if ((uint32_t)atom_pcie_table->ucNumEntries <= pcie_count)
517 pcie_count = (uint32_t)atom_pcie_table->ucNumEntries;
518 else
519 printk(KERN_ERR "[ powerplay ] Number of Pcie Entries exceed the number of SCLK Dpm Levels! \
520 Disregarding the excess entries... \n");
521
522 pcie_table->count = pcie_count;
523
524 for (i = 0; i < pcie_count; i++) {
525 pcie_table->entries[i].gen_speed =
526 atom_pcie_table->entries[i].ucPCIEGenSpeed;
527 pcie_table->entries[i].lane_width =
528 atom_pcie_table->entries[i].usPCIELaneWidth;
529 pcie_table->entries[i].pcie_sclk =
530 atom_pcie_table->entries[i].ulPCIE_Sclk;
531 }
532
533 *pp_tonga_pcie_table = pcie_table;
yanyang1c82baa22015-08-18 15:28:32 +0800534 }
535
yanyang1c82baa22015-08-18 15:28:32 +0800536 return 0;
537}
538
539static int get_cac_tdp_table(
540 struct pp_hwmgr *hwmgr,
541 struct phm_cac_tdp_table **cac_tdp_table,
542 const PPTable_Generic_SubTable_Header * table
543 )
544{
545 uint32_t table_size;
546 struct phm_cac_tdp_table *tdp_table;
547
548 table_size = sizeof(uint32_t) + sizeof(struct phm_cac_tdp_table);
549 tdp_table = kzalloc(table_size, GFP_KERNEL);
550
551 if (NULL == tdp_table)
Rex Zhuc15c8d72016-01-06 16:48:38 +0800552 return -ENOMEM;
yanyang1c82baa22015-08-18 15:28:32 +0800553
554 memset(tdp_table, 0x00, table_size);
555
556 hwmgr->dyn_state.cac_dtp_table = kzalloc(table_size, GFP_KERNEL);
557
Colin Ian Kinga82d3972016-03-18 16:47:29 +0000558 if (NULL == hwmgr->dyn_state.cac_dtp_table) {
559 kfree(tdp_table);
Rex Zhuc15c8d72016-01-06 16:48:38 +0800560 return -ENOMEM;
Colin Ian Kinga82d3972016-03-18 16:47:29 +0000561 }
yanyang1c82baa22015-08-18 15:28:32 +0800562
563 memset(hwmgr->dyn_state.cac_dtp_table, 0x00, table_size);
564
565 if (table->ucRevId < 3) {
566 const ATOM_Tonga_PowerTune_Table *tonga_table =
567 (ATOM_Tonga_PowerTune_Table *)table;
568 tdp_table->usTDP = tonga_table->usTDP;
569 tdp_table->usConfigurableTDP =
570 tonga_table->usConfigurableTDP;
571 tdp_table->usTDC = tonga_table->usTDC;
572 tdp_table->usBatteryPowerLimit =
573 tonga_table->usBatteryPowerLimit;
574 tdp_table->usSmallPowerLimit =
575 tonga_table->usSmallPowerLimit;
576 tdp_table->usLowCACLeakage =
577 tonga_table->usLowCACLeakage;
578 tdp_table->usHighCACLeakage =
579 tonga_table->usHighCACLeakage;
580 tdp_table->usMaximumPowerDeliveryLimit =
581 tonga_table->usMaximumPowerDeliveryLimit;
582 tdp_table->usDefaultTargetOperatingTemp =
583 tonga_table->usTjMax;
584 tdp_table->usTargetOperatingTemp =
585 tonga_table->usTjMax; /*Set the initial temp to the same as default */
586 tdp_table->usPowerTuneDataSetID =
587 tonga_table->usPowerTuneDataSetID;
588 tdp_table->usSoftwareShutdownTemp =
589 tonga_table->usSoftwareShutdownTemp;
590 tdp_table->usClockStretchAmount =
591 tonga_table->usClockStretchAmount;
592 } else { /* Fiji and newer */
593 const ATOM_Fiji_PowerTune_Table *fijitable =
594 (ATOM_Fiji_PowerTune_Table *)table;
595 tdp_table->usTDP = fijitable->usTDP;
596 tdp_table->usConfigurableTDP = fijitable->usConfigurableTDP;
597 tdp_table->usTDC = fijitable->usTDC;
598 tdp_table->usBatteryPowerLimit = fijitable->usBatteryPowerLimit;
599 tdp_table->usSmallPowerLimit = fijitable->usSmallPowerLimit;
600 tdp_table->usLowCACLeakage = fijitable->usLowCACLeakage;
601 tdp_table->usHighCACLeakage = fijitable->usHighCACLeakage;
602 tdp_table->usMaximumPowerDeliveryLimit =
603 fijitable->usMaximumPowerDeliveryLimit;
604 tdp_table->usDefaultTargetOperatingTemp =
605 fijitable->usTjMax;
606 tdp_table->usTargetOperatingTemp =
607 fijitable->usTjMax; /*Set the initial temp to the same as default */
608 tdp_table->usPowerTuneDataSetID =
609 fijitable->usPowerTuneDataSetID;
610 tdp_table->usSoftwareShutdownTemp =
611 fijitable->usSoftwareShutdownTemp;
612 tdp_table->usClockStretchAmount =
613 fijitable->usClockStretchAmount;
614 tdp_table->usTemperatureLimitHotspot =
615 fijitable->usTemperatureLimitHotspot;
616 tdp_table->usTemperatureLimitLiquid1 =
617 fijitable->usTemperatureLimitLiquid1;
618 tdp_table->usTemperatureLimitLiquid2 =
619 fijitable->usTemperatureLimitLiquid2;
620 tdp_table->usTemperatureLimitVrVddc =
621 fijitable->usTemperatureLimitVrVddc;
622 tdp_table->usTemperatureLimitVrMvdd =
623 fijitable->usTemperatureLimitVrMvdd;
624 tdp_table->usTemperatureLimitPlx =
625 fijitable->usTemperatureLimitPlx;
626 tdp_table->ucLiquid1_I2C_address =
627 fijitable->ucLiquid1_I2C_address;
628 tdp_table->ucLiquid2_I2C_address =
629 fijitable->ucLiquid2_I2C_address;
630 tdp_table->ucLiquid_I2C_Line =
631 fijitable->ucLiquid_I2C_Line;
632 tdp_table->ucVr_I2C_address = fijitable->ucVr_I2C_address;
633 tdp_table->ucVr_I2C_Line = fijitable->ucVr_I2C_Line;
634 tdp_table->ucPlx_I2C_address = fijitable->ucPlx_I2C_address;
635 tdp_table->ucPlx_I2C_Line = fijitable->ucPlx_I2C_Line;
636 }
637
638 *cac_tdp_table = tdp_table;
639
640 return 0;
641}
642
643static int get_mm_clock_voltage_table(
644 struct pp_hwmgr *hwmgr,
645 phm_ppt_v1_mm_clock_voltage_dependency_table **tonga_mm_table,
646 const ATOM_Tonga_MM_Dependency_Table * mm_dependency_table
647 )
648{
649 uint32_t table_size, i;
650 const ATOM_Tonga_MM_Dependency_Record *mm_dependency_record;
651 phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table;
652
653 PP_ASSERT_WITH_CODE((0 != mm_dependency_table->ucNumEntries),
654 "Invalid PowerPlay Table!", return -1);
655 table_size = sizeof(uint32_t) +
656 sizeof(phm_ppt_v1_mm_clock_voltage_dependency_record)
657 * mm_dependency_table->ucNumEntries;
658 mm_table = (phm_ppt_v1_mm_clock_voltage_dependency_table *)
659 kzalloc(table_size, GFP_KERNEL);
660
661 if (NULL == mm_table)
Rex Zhuc15c8d72016-01-06 16:48:38 +0800662 return -ENOMEM;
yanyang1c82baa22015-08-18 15:28:32 +0800663
664 memset(mm_table, 0x00, table_size);
665
666 mm_table->count = mm_dependency_table->ucNumEntries;
667
668 for (i = 0; i < mm_dependency_table->ucNumEntries; i++) {
669 mm_dependency_record = &mm_dependency_table->entries[i];
670 mm_table->entries[i].vddcInd = mm_dependency_record->ucVddcInd;
671 mm_table->entries[i].vddgfx_offset = mm_dependency_record->usVddgfxOffset;
672 mm_table->entries[i].aclk = mm_dependency_record->ulAClk;
673 mm_table->entries[i].samclock = mm_dependency_record->ulSAMUClk;
674 mm_table->entries[i].eclk = mm_dependency_record->ulEClk;
675 mm_table->entries[i].vclk = mm_dependency_record->ulVClk;
676 mm_table->entries[i].dclk = mm_dependency_record->ulDClk;
677 }
678
679 *tonga_mm_table = mm_table;
680
681 return 0;
682}
683
684/**
685 * Private Function used during initialization.
686 * Initialize clock voltage dependency
687 * @param hwmgr Pointer to the hardware manager.
688 * @param powerplay_table Pointer to the PowerPlay Table.
689 */
690static int init_clock_voltage_dependency(
691 struct pp_hwmgr *hwmgr,
692 const ATOM_Tonga_POWERPLAYTABLE *powerplay_table
693 )
694{
695 int result = 0;
696 struct phm_ppt_v1_information *pp_table_information =
697 (struct phm_ppt_v1_information *)(hwmgr->pptable);
698
699 const ATOM_Tonga_MM_Dependency_Table *mm_dependency_table =
700 (const ATOM_Tonga_MM_Dependency_Table *)(((unsigned long) powerplay_table) +
701 le16_to_cpu(powerplay_table->usMMDependencyTableOffset));
702 const PPTable_Generic_SubTable_Header *pPowerTuneTable =
703 (const PPTable_Generic_SubTable_Header *)(((unsigned long) powerplay_table) +
704 le16_to_cpu(powerplay_table->usPowerTuneTableOffset));
705 const ATOM_Tonga_MCLK_Dependency_Table *mclk_dep_table =
706 (const ATOM_Tonga_MCLK_Dependency_Table *)(((unsigned long) powerplay_table) +
707 le16_to_cpu(powerplay_table->usMclkDependencyTableOffset));
708 const ATOM_Tonga_SCLK_Dependency_Table *sclk_dep_table =
709 (const ATOM_Tonga_SCLK_Dependency_Table *)(((unsigned long) powerplay_table) +
710 le16_to_cpu(powerplay_table->usSclkDependencyTableOffset));
711 const ATOM_Tonga_Hard_Limit_Table *pHardLimits =
712 (const ATOM_Tonga_Hard_Limit_Table *)(((unsigned long) powerplay_table) +
713 le16_to_cpu(powerplay_table->usHardLimitTableOffset));
yanyang1e85c7d62016-02-06 13:28:47 +0800714 const PPTable_Generic_SubTable_Header *pcie_table =
715 (const PPTable_Generic_SubTable_Header *)(((unsigned long) powerplay_table) +
yanyang1c82baa22015-08-18 15:28:32 +0800716 le16_to_cpu(powerplay_table->usPCIETableOffset));
717
718 pp_table_information->vdd_dep_on_sclk = NULL;
719 pp_table_information->vdd_dep_on_mclk = NULL;
720 pp_table_information->mm_dep_table = NULL;
721 pp_table_information->pcie_table = NULL;
722
723 if (powerplay_table->usMMDependencyTableOffset != 0)
724 result = get_mm_clock_voltage_table(hwmgr,
725 &pp_table_information->mm_dep_table, mm_dependency_table);
726
727 if (result == 0 && powerplay_table->usPowerTuneTableOffset != 0)
728 result = get_cac_tdp_table(hwmgr,
729 &pp_table_information->cac_dtp_table, pPowerTuneTable);
730
731 if (result == 0 && powerplay_table->usSclkDependencyTableOffset != 0)
732 result = get_sclk_voltage_dependency_table(hwmgr,
733 &pp_table_information->vdd_dep_on_sclk, sclk_dep_table);
734
735 if (result == 0 && powerplay_table->usMclkDependencyTableOffset != 0)
736 result = get_mclk_voltage_dependency_table(hwmgr,
737 &pp_table_information->vdd_dep_on_mclk, mclk_dep_table);
738
739 if (result == 0 && powerplay_table->usPCIETableOffset != 0)
740 result = get_pcie_table(hwmgr,
741 &pp_table_information->pcie_table, pcie_table);
742
743 if (result == 0 && powerplay_table->usHardLimitTableOffset != 0)
744 result = get_hard_limits(hwmgr,
745 &pp_table_information->max_clock_voltage_on_dc, pHardLimits);
746
747 hwmgr->dyn_state.max_clock_voltage_on_dc.sclk =
748 pp_table_information->max_clock_voltage_on_dc.sclk;
749 hwmgr->dyn_state.max_clock_voltage_on_dc.mclk =
750 pp_table_information->max_clock_voltage_on_dc.mclk;
751 hwmgr->dyn_state.max_clock_voltage_on_dc.vddc =
752 pp_table_information->max_clock_voltage_on_dc.vddc;
753 hwmgr->dyn_state.max_clock_voltage_on_dc.vddci =
754 pp_table_information->max_clock_voltage_on_dc.vddci;
755
756 if (result == 0 && (NULL != pp_table_information->vdd_dep_on_mclk)
757 && (0 != pp_table_information->vdd_dep_on_mclk->count))
758 result = get_valid_clk(hwmgr, &pp_table_information->valid_mclk_values,
759 pp_table_information->vdd_dep_on_mclk);
760
761 if (result == 0 && (NULL != pp_table_information->vdd_dep_on_sclk)
762 && (0 != pp_table_information->vdd_dep_on_sclk->count))
763 result = get_valid_clk(hwmgr, &pp_table_information->valid_sclk_values,
764 pp_table_information->vdd_dep_on_sclk);
765
766 return result;
767}
768
769/** Retrieves the (signed) Overdrive limits from VBIOS.
770 * The max engine clock, memory clock and max temperature come from the firmware info table.
771 *
772 * The information is placed into the platform descriptor.
773 *
774 * @param hwmgr source of the VBIOS table and owner of the platform descriptor to be updated.
775 * @param powerplay_table the address of the PowerPlay table.
776 *
777 * @return 1 as long as the firmware info table was present and of a supported version.
778 */
779static int init_over_drive_limits(
780 struct pp_hwmgr *hwmgr,
781 const ATOM_Tonga_POWERPLAYTABLE *powerplay_table)
782{
783 hwmgr->platform_descriptor.overdriveLimit.engineClock =
784 le16_to_cpu(powerplay_table->ulMaxODEngineClock);
785 hwmgr->platform_descriptor.overdriveLimit.memoryClock =
786 le16_to_cpu(powerplay_table->ulMaxODMemoryClock);
787
788 hwmgr->platform_descriptor.minOverdriveVDDC = 0;
789 hwmgr->platform_descriptor.maxOverdriveVDDC = 0;
790 hwmgr->platform_descriptor.overdriveVDDCStep = 0;
791
792 if (hwmgr->platform_descriptor.overdriveLimit.engineClock > 0 \
793 && hwmgr->platform_descriptor.overdriveLimit.memoryClock > 0) {
794 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
795 PHM_PlatformCaps_ACOverdriveSupport);
796 }
797
798 return 0;
799}
800
801/**
802 * Private Function used during initialization.
803 * Inspect the PowerPlay table for obvious signs of corruption.
804 * @param hwmgr Pointer to the hardware manager.
805 * @param powerplay_table Pointer to the PowerPlay Table.
806 * @exception This implementation always returns 1.
807 */
808static int init_thermal_controller(
809 struct pp_hwmgr *hwmgr,
810 const ATOM_Tonga_POWERPLAYTABLE *powerplay_table
811 )
812{
813 const PPTable_Generic_SubTable_Header *fan_table;
814 ATOM_Tonga_Thermal_Controller *thermal_controller;
815
816 thermal_controller = (ATOM_Tonga_Thermal_Controller *)
817 (((unsigned long)powerplay_table) +
818 le16_to_cpu(powerplay_table->usThermalControllerOffset));
819 PP_ASSERT_WITH_CODE((0 != powerplay_table->usThermalControllerOffset),
820 "Thermal controller table not set!", return -1);
821
822 hwmgr->thermal_controller.ucType = thermal_controller->ucType;
823 hwmgr->thermal_controller.ucI2cLine = thermal_controller->ucI2cLine;
824 hwmgr->thermal_controller.ucI2cAddress = thermal_controller->ucI2cAddress;
825
826 hwmgr->thermal_controller.fanInfo.bNoFan =
827 (0 != (thermal_controller->ucFanParameters & ATOM_TONGA_PP_FANPARAMETERS_NOFAN));
828
829 hwmgr->thermal_controller.fanInfo.ucTachometerPulsesPerRevolution =
830 thermal_controller->ucFanParameters &
831 ATOM_TONGA_PP_FANPARAMETERS_TACHOMETER_PULSES_PER_REVOLUTION_MASK;
832
833 hwmgr->thermal_controller.fanInfo.ulMinRPM
834 = thermal_controller->ucFanMinRPM * 100UL;
835 hwmgr->thermal_controller.fanInfo.ulMaxRPM
836 = thermal_controller->ucFanMaxRPM * 100UL;
837
838 set_hw_cap(
839 hwmgr,
840 ATOM_TONGA_PP_THERMALCONTROLLER_NONE != hwmgr->thermal_controller.ucType,
841 PHM_PlatformCaps_ThermalController
842 );
843
844 if (0 == powerplay_table->usFanTableOffset)
Alex Deucher283b1a82015-12-14 10:46:52 -0500845 return 0;
yanyang1c82baa22015-08-18 15:28:32 +0800846
847 fan_table = (const PPTable_Generic_SubTable_Header *)
848 (((unsigned long)powerplay_table) +
849 le16_to_cpu(powerplay_table->usFanTableOffset));
850
851 PP_ASSERT_WITH_CODE((0 != powerplay_table->usFanTableOffset),
852 "Fan table not set!", return -1);
853 PP_ASSERT_WITH_CODE((0 < fan_table->ucRevId),
854 "Unsupported fan table format!", return -1);
855
856 hwmgr->thermal_controller.advanceFanControlParameters.ulCycleDelay
857 = 100000;
858 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
859 PHM_PlatformCaps_MicrocodeFanControl);
860
861 if (fan_table->ucRevId < 8) {
862 const ATOM_Tonga_Fan_Table *tonga_fan_table =
863 (ATOM_Tonga_Fan_Table *)fan_table;
864 hwmgr->thermal_controller.advanceFanControlParameters.ucTHyst
865 = tonga_fan_table->ucTHyst;
866 hwmgr->thermal_controller.advanceFanControlParameters.usTMin
867 = tonga_fan_table->usTMin;
868 hwmgr->thermal_controller.advanceFanControlParameters.usTMed
869 = tonga_fan_table->usTMed;
870 hwmgr->thermal_controller.advanceFanControlParameters.usTHigh
871 = tonga_fan_table->usTHigh;
872 hwmgr->thermal_controller.advanceFanControlParameters.usPWMMin
873 = tonga_fan_table->usPWMMin;
874 hwmgr->thermal_controller.advanceFanControlParameters.usPWMMed
875 = tonga_fan_table->usPWMMed;
876 hwmgr->thermal_controller.advanceFanControlParameters.usPWMHigh
877 = tonga_fan_table->usPWMHigh;
878 hwmgr->thermal_controller.advanceFanControlParameters.usTMax
879 = 10900; /* hard coded */
880 hwmgr->thermal_controller.advanceFanControlParameters.usTMax
881 = tonga_fan_table->usTMax;
882 hwmgr->thermal_controller.advanceFanControlParameters.ucFanControlMode
883 = tonga_fan_table->ucFanControlMode;
884 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM
885 = tonga_fan_table->usFanPWMMax;
886 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultFanOutputSensitivity
887 = 4836;
888 hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity
889 = tonga_fan_table->usFanOutputSensitivity;
890 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanRPM
891 = tonga_fan_table->usFanRPMMax;
892 hwmgr->thermal_controller.advanceFanControlParameters.ulMinFanSCLKAcousticLimit
893 = (tonga_fan_table->ulMinFanSCLKAcousticLimit / 100); /* PPTable stores it in 10Khz unit for 2 decimal places. SMC wants MHz. */
894 hwmgr->thermal_controller.advanceFanControlParameters.ucTargetTemperature
895 = tonga_fan_table->ucTargetTemperature;
896 hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit
897 = tonga_fan_table->ucMinimumPWMLimit;
898 } else {
899 const ATOM_Fiji_Fan_Table *fiji_fan_table =
900 (ATOM_Fiji_Fan_Table *)fan_table;
901 hwmgr->thermal_controller.advanceFanControlParameters.ucTHyst
902 = fiji_fan_table->ucTHyst;
903 hwmgr->thermal_controller.advanceFanControlParameters.usTMin
904 = fiji_fan_table->usTMin;
905 hwmgr->thermal_controller.advanceFanControlParameters.usTMed
906 = fiji_fan_table->usTMed;
907 hwmgr->thermal_controller.advanceFanControlParameters.usTHigh
908 = fiji_fan_table->usTHigh;
909 hwmgr->thermal_controller.advanceFanControlParameters.usPWMMin
910 = fiji_fan_table->usPWMMin;
911 hwmgr->thermal_controller.advanceFanControlParameters.usPWMMed
912 = fiji_fan_table->usPWMMed;
913 hwmgr->thermal_controller.advanceFanControlParameters.usPWMHigh
914 = fiji_fan_table->usPWMHigh;
915 hwmgr->thermal_controller.advanceFanControlParameters.usTMax
916 = fiji_fan_table->usTMax;
917 hwmgr->thermal_controller.advanceFanControlParameters.ucFanControlMode
918 = fiji_fan_table->ucFanControlMode;
919 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanPWM
920 = fiji_fan_table->usFanPWMMax;
921 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultFanOutputSensitivity
922 = 4836;
923 hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity
924 = fiji_fan_table->usFanOutputSensitivity;
925 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultMaxFanRPM
926 = fiji_fan_table->usFanRPMMax;
927 hwmgr->thermal_controller.advanceFanControlParameters.ulMinFanSCLKAcousticLimit
928 = (fiji_fan_table->ulMinFanSCLKAcousticLimit / 100); /* PPTable stores it in 10Khz unit for 2 decimal places. SMC wants MHz. */
929 hwmgr->thermal_controller.advanceFanControlParameters.ucTargetTemperature
930 = fiji_fan_table->ucTargetTemperature;
931 hwmgr->thermal_controller.advanceFanControlParameters.ucMinimumPWMLimit
932 = fiji_fan_table->ucMinimumPWMLimit;
933
934 hwmgr->thermal_controller.advanceFanControlParameters.usFanGainEdge
935 = fiji_fan_table->usFanGainEdge;
936 hwmgr->thermal_controller.advanceFanControlParameters.usFanGainHotspot
937 = fiji_fan_table->usFanGainHotspot;
938 hwmgr->thermal_controller.advanceFanControlParameters.usFanGainLiquid
939 = fiji_fan_table->usFanGainLiquid;
940 hwmgr->thermal_controller.advanceFanControlParameters.usFanGainVrVddc
941 = fiji_fan_table->usFanGainVrVddc;
942 hwmgr->thermal_controller.advanceFanControlParameters.usFanGainVrMvdd
943 = fiji_fan_table->usFanGainVrMvdd;
944 hwmgr->thermal_controller.advanceFanControlParameters.usFanGainPlx
945 = fiji_fan_table->usFanGainPlx;
946 hwmgr->thermal_controller.advanceFanControlParameters.usFanGainHbm
947 = fiji_fan_table->usFanGainHbm;
948 }
949
950 return 0;
951}
952
953/**
954 * Private Function used during initialization.
955 * Inspect the PowerPlay table for obvious signs of corruption.
956 * @param hwmgr Pointer to the hardware manager.
957 * @param powerplay_table Pointer to the PowerPlay Table.
958 * @exception 2 if the powerplay table is incorrect.
959 */
960static int check_powerplay_tables(
961 struct pp_hwmgr *hwmgr,
962 const ATOM_Tonga_POWERPLAYTABLE *powerplay_table
963 )
964{
965 const ATOM_Tonga_State_Array *state_arrays;
966
967 state_arrays = (ATOM_Tonga_State_Array *)(((unsigned long)powerplay_table) +
968 le16_to_cpu(powerplay_table->usStateArrayOffset));
969
970 PP_ASSERT_WITH_CODE((ATOM_Tonga_TABLE_REVISION_TONGA <=
971 powerplay_table->sHeader.ucTableFormatRevision),
972 "Unsupported PPTable format!", return -1);
973 PP_ASSERT_WITH_CODE((0 != powerplay_table->usStateArrayOffset),
974 "State table is not set!", return -1);
975 PP_ASSERT_WITH_CODE((0 < powerplay_table->sHeader.usStructureSize),
976 "Invalid PowerPlay Table!", return -1);
977 PP_ASSERT_WITH_CODE((0 < state_arrays->ucNumEntries),
978 "Invalid PowerPlay Table!", return -1);
979
980 return 0;
981}
982
983int tonga_pp_tables_initialize(struct pp_hwmgr *hwmgr)
984{
985 int result = 0;
986 const ATOM_Tonga_POWERPLAYTABLE *powerplay_table;
987
988 hwmgr->pptable = kzalloc(sizeof(struct phm_ppt_v1_information), GFP_KERNEL);
989
Alex Deucher1d5498c2015-12-11 12:12:32 -0500990 PP_ASSERT_WITH_CODE((NULL != hwmgr->pptable),
Rex Zhuc15c8d72016-01-06 16:48:38 +0800991 "Failed to allocate hwmgr->pptable!", return -ENOMEM);
yanyang1c82baa22015-08-18 15:28:32 +0800992
993 memset(hwmgr->pptable, 0x00, sizeof(struct phm_ppt_v1_information));
994
995 powerplay_table = get_powerplay_table(hwmgr);
996
997 PP_ASSERT_WITH_CODE((NULL != powerplay_table),
998 "Missing PowerPlay Table!", return -1);
999
1000 result = check_powerplay_tables(hwmgr, powerplay_table);
1001
Alex Deucher1d5498c2015-12-11 12:12:32 -05001002 PP_ASSERT_WITH_CODE((result == 0),
1003 "check_powerplay_tables failed", return result);
yanyang1c82baa22015-08-18 15:28:32 +08001004
Alex Deucher1d5498c2015-12-11 12:12:32 -05001005 result = set_platform_caps(hwmgr,
1006 le32_to_cpu(powerplay_table->ulPlatformCaps));
yanyang1c82baa22015-08-18 15:28:32 +08001007
Alex Deucher1d5498c2015-12-11 12:12:32 -05001008 PP_ASSERT_WITH_CODE((result == 0),
1009 "set_platform_caps failed", return result);
yanyang1c82baa22015-08-18 15:28:32 +08001010
Alex Deucher1d5498c2015-12-11 12:12:32 -05001011 result = init_thermal_controller(hwmgr, powerplay_table);
yanyang1c82baa22015-08-18 15:28:32 +08001012
Alex Deucher1d5498c2015-12-11 12:12:32 -05001013 PP_ASSERT_WITH_CODE((result == 0),
1014 "init_thermal_controller failed", return result);
1015
1016 result = init_over_drive_limits(hwmgr, powerplay_table);
1017
1018 PP_ASSERT_WITH_CODE((result == 0),
1019 "init_over_drive_limits failed", return result);
1020
1021 result = init_clock_voltage_dependency(hwmgr, powerplay_table);
1022
1023 PP_ASSERT_WITH_CODE((result == 0),
1024 "init_clock_voltage_dependency failed", return result);
1025
1026 result = init_dpm_2_parameters(hwmgr, powerplay_table);
1027
1028 PP_ASSERT_WITH_CODE((result == 0),
1029 "init_dpm_2_parameters failed", return result);
yanyang1c82baa22015-08-18 15:28:32 +08001030
1031 return result;
1032}
1033
1034int tonga_pp_tables_uninitialize(struct pp_hwmgr *hwmgr)
1035{
1036 int result = 0;
1037 struct phm_ppt_v1_information *pp_table_information =
1038 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1039
1040 if (NULL != hwmgr->soft_pp_table) {
1041 kfree(hwmgr->soft_pp_table);
1042 hwmgr->soft_pp_table = NULL;
1043 }
1044
1045 if (NULL != pp_table_information->vdd_dep_on_sclk)
1046 pp_table_information->vdd_dep_on_sclk = NULL;
1047
1048 if (NULL != pp_table_information->vdd_dep_on_mclk)
1049 pp_table_information->vdd_dep_on_mclk = NULL;
1050
1051 if (NULL != pp_table_information->valid_mclk_values)
1052 pp_table_information->valid_mclk_values = NULL;
1053
1054 if (NULL != pp_table_information->valid_sclk_values)
1055 pp_table_information->valid_sclk_values = NULL;
1056
1057 if (NULL != pp_table_information->vddc_lookup_table)
1058 pp_table_information->vddc_lookup_table = NULL;
1059
1060 if (NULL != pp_table_information->vddgfx_lookup_table)
1061 pp_table_information->vddgfx_lookup_table = NULL;
1062
1063 if (NULL != pp_table_information->mm_dep_table)
1064 pp_table_information->mm_dep_table = NULL;
1065
1066 if (NULL != pp_table_information->cac_dtp_table)
1067 pp_table_information->cac_dtp_table = NULL;
1068
1069 if (NULL != hwmgr->dyn_state.cac_dtp_table)
1070 hwmgr->dyn_state.cac_dtp_table = NULL;
1071
1072 if (NULL != pp_table_information->ppm_parameter_table)
1073 pp_table_information->ppm_parameter_table = NULL;
1074
1075 if (NULL != pp_table_information->pcie_table)
1076 pp_table_information->pcie_table = NULL;
1077
1078 if (NULL != hwmgr->pptable) {
1079 kfree(hwmgr->pptable);
1080 hwmgr->pptable = NULL;
1081 }
1082
1083 return result;
1084}
1085
1086const struct pp_table_func tonga_pptable_funcs = {
1087 .pptable_init = tonga_pp_tables_initialize,
1088 .pptable_fini = tonga_pp_tables_uninitialize,
1089};
1090
1091int tonga_get_number_of_powerplay_table_entries(struct pp_hwmgr *hwmgr)
1092{
1093 const ATOM_Tonga_State_Array * state_arrays;
1094 const ATOM_Tonga_POWERPLAYTABLE *pp_table = get_powerplay_table(hwmgr);
1095
1096 PP_ASSERT_WITH_CODE((NULL != pp_table),
1097 "Missing PowerPlay Table!", return -1);
1098 PP_ASSERT_WITH_CODE((pp_table->sHeader.ucTableFormatRevision >=
1099 ATOM_Tonga_TABLE_REVISION_TONGA),
1100 "Incorrect PowerPlay table revision!", return -1);
1101
1102 state_arrays = (ATOM_Tonga_State_Array *)(((unsigned long)pp_table) +
1103 le16_to_cpu(pp_table->usStateArrayOffset));
1104
1105 return (uint32_t)(state_arrays->ucNumEntries);
1106}
1107
1108/**
1109* Private function to convert flags stored in the BIOS to software flags in PowerPlay.
1110*/
1111static uint32_t make_classification_flags(struct pp_hwmgr *hwmgr,
1112 uint16_t classification, uint16_t classification2)
1113{
1114 uint32_t result = 0;
1115
1116 if (classification & ATOM_PPLIB_CLASSIFICATION_BOOT)
1117 result |= PP_StateClassificationFlag_Boot;
1118
1119 if (classification & ATOM_PPLIB_CLASSIFICATION_THERMAL)
1120 result |= PP_StateClassificationFlag_Thermal;
1121
1122 if (classification & ATOM_PPLIB_CLASSIFICATION_LIMITEDPOWERSOURCE)
1123 result |= PP_StateClassificationFlag_LimitedPowerSource;
1124
1125 if (classification & ATOM_PPLIB_CLASSIFICATION_REST)
1126 result |= PP_StateClassificationFlag_Rest;
1127
1128 if (classification & ATOM_PPLIB_CLASSIFICATION_FORCED)
1129 result |= PP_StateClassificationFlag_Forced;
1130
1131 if (classification & ATOM_PPLIB_CLASSIFICATION_ACPI)
1132 result |= PP_StateClassificationFlag_ACPI;
1133
1134 if (classification2 & ATOM_PPLIB_CLASSIFICATION2_LIMITEDPOWERSOURCE_2)
1135 result |= PP_StateClassificationFlag_LimitedPowerSource_2;
1136
1137 return result;
1138}
1139
1140/**
1141* Create a Power State out of an entry in the PowerPlay table.
1142* This function is called by the hardware back-end.
1143* @param hwmgr Pointer to the hardware manager.
1144* @param entry_index The index of the entry to be extracted from the table.
1145* @param power_state The address of the PowerState instance being created.
1146* @return -1 if the entry cannot be retrieved.
1147*/
1148int tonga_get_powerplay_table_entry(struct pp_hwmgr *hwmgr,
1149 uint32_t entry_index, struct pp_power_state *power_state,
1150 int (*call_back_func)(struct pp_hwmgr *, void *,
1151 struct pp_power_state *, void *, uint32_t))
1152{
1153 int result = 0;
1154 const ATOM_Tonga_State_Array * state_arrays;
1155 const ATOM_Tonga_State *state_entry;
1156 const ATOM_Tonga_POWERPLAYTABLE *pp_table = get_powerplay_table(hwmgr);
1157
1158 PP_ASSERT_WITH_CODE((NULL != pp_table), "Missing PowerPlay Table!", return -1;);
1159 power_state->classification.bios_index = entry_index;
1160
1161 if (pp_table->sHeader.ucTableFormatRevision >=
1162 ATOM_Tonga_TABLE_REVISION_TONGA) {
1163 state_arrays = (ATOM_Tonga_State_Array *)(((unsigned long)pp_table) +
1164 le16_to_cpu(pp_table->usStateArrayOffset));
1165
1166 PP_ASSERT_WITH_CODE((0 < pp_table->usStateArrayOffset),
1167 "Invalid PowerPlay Table State Array Offset.", return -1);
1168 PP_ASSERT_WITH_CODE((0 < state_arrays->ucNumEntries),
1169 "Invalid PowerPlay Table State Array.", return -1);
1170 PP_ASSERT_WITH_CODE((entry_index <= state_arrays->ucNumEntries),
1171 "Invalid PowerPlay Table State Array Entry.", return -1);
1172
1173 state_entry = &(state_arrays->states[entry_index]);
1174
1175 result = call_back_func(hwmgr, (void *)state_entry, power_state,
1176 (void *)pp_table,
1177 make_classification_flags(hwmgr,
1178 le16_to_cpu(state_entry->usClassification),
1179 le16_to_cpu(state_entry->usClassification2)));
1180 }
1181
1182 if (!result && (power_state->classification.flags &
1183 PP_StateClassificationFlag_Boot))
1184 result = hwmgr->hwmgr_func->patch_boot_state(hwmgr, &(power_state->hardware));
1185
1186 return result;
1187}