blob: da2bfc8af2032cef940bfd79a073580906c7433c [file] [log] [blame]
Aaron Durbindf214402015-12-14 16:44:26 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2015 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 */
16
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080017#include <device/pci_ids.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +020018#include <device/pci_ops.h>
Rizwan Qureshi1222a732016-08-23 14:31:23 +053019#include <fsp/api.h>
20#include <soc/ramstage.h>
Aaron Durbindf214402015-12-14 16:44:26 -060021#include <soc/vr_config.h>
Patrick Rudolph50aebaf82019-08-14 10:07:38 +020022#include <console/console.h>
Patrick Rudolph69e826d2019-08-14 10:23:30 +020023#include <intelblocks/cpulib.h>
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080024
Aaron Durbindf214402015-12-14 16:44:26 -060025/* Default values for domain configuration. PSI3 and PSI4 are disabled. */
26static const struct vr_config default_configs[NUM_VR_DOMAINS] = {
27 [VR_SYSTEM_AGENT] = {
28 .vr_config_enable = 1,
29 .psi1threshold = VR_CFG_AMP(20),
30 .psi2threshold = VR_CFG_AMP(4),
31 .psi3threshold = VR_CFG_AMP(1),
32 .psi3enable = 0,
33 .psi4enable = 0,
34 .imon_slope = 0x0,
35 .imon_offset = 0x0,
36 .icc_max = VR_CFG_AMP(7),
37 .voltage_limit = 1520,
38 },
39 [VR_IA_CORE] = {
40 .vr_config_enable = 1,
41 .psi1threshold = VR_CFG_AMP(20),
42 .psi2threshold = VR_CFG_AMP(5),
43 .psi3threshold = VR_CFG_AMP(1),
44 .psi3enable = 0,
45 .psi4enable = 0,
46 .imon_slope = 0x0,
47 .imon_offset = 0x0,
48 .icc_max = VR_CFG_AMP(34),
49 .voltage_limit = 1520,
50 },
Aaron Durbindf214402015-12-14 16:44:26 -060051 [VR_GT_UNSLICED] = {
52 .vr_config_enable = 1,
53 .psi1threshold = VR_CFG_AMP(20),
54 .psi2threshold = VR_CFG_AMP(5),
55 .psi3threshold = VR_CFG_AMP(1),
56 .psi3enable = 0,
57 .psi4enable = 0,
58 .imon_slope = 0x0,
59 .imon_offset = 0x0,
60 .icc_max = VR_CFG_AMP(35),
61 .voltage_limit = 1520,
62 },
63 [VR_GT_SLICED] = {
64 .vr_config_enable = 1,
65 .psi1threshold = VR_CFG_AMP(20),
66 .psi2threshold = VR_CFG_AMP(5),
67 .psi3threshold = VR_CFG_AMP(1),
68 .psi3enable = 0,
69 .psi4enable = 0,
70 .imon_slope = 0x0,
71 .imon_offset = 0x0,
72 .icc_max = VR_CFG_AMP(35),
73 .voltage_limit = 1520,
74 },
75};
76
Patrick Rudolph50aebaf82019-08-14 10:07:38 +020077static uint16_t get_sku_icc_max(int domain)
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080078{
Patrick Rudolph69e826d2019-08-14 10:23:30 +020079 const uint16_t tdp = cpu_get_power_max();
80
Maxim Polyakov24ba8502019-08-29 18:40:19 +030081 static uint16_t mch_id = 0, igd_id = 0;
Patrick Rudolph50aebaf82019-08-14 10:07:38 +020082 if (!mch_id) {
83 struct device *dev = pcidev_path_on_root(SA_DEVFN_ROOT);
Maxim Polyakov24ba8502019-08-29 18:40:19 +030084 mch_id = dev ? pci_read_config16(dev, PCI_DEVICE_ID) : 0xffff;
Patrick Rudolph50aebaf82019-08-14 10:07:38 +020085 }
86 if (!igd_id) {
87 struct device *dev = pcidev_path_on_root(SA_DEVFN_IGD);
Maxim Polyakov24ba8502019-08-29 18:40:19 +030088 igd_id = dev ? pci_read_config16(dev, PCI_DEVICE_ID) : 0xffff;
Patrick Rudolph50aebaf82019-08-14 10:07:38 +020089 }
Gaggery Tsaie1a75d42018-01-02 12:13:40 +080090
Patrick Rudolph50aebaf82019-08-14 10:07:38 +020091 /*
Patrick Rudolph69e826d2019-08-14 10:23:30 +020092 * Iccmax table from Doc #559100 Section 7.2 DC Specifications, the
93 * Iccmax is the same among KBL-Y but KBL-U/R.
94 * Addendum for AML-Y #594883, IccMax for IA core is 28A.
Maxim Polyakov24ba8502019-08-29 18:40:19 +030095 * KBL-S #335195, KBL-H #335190, SKL-S #332687, SKL-H #332986,
96 * SKL-U/Y #332990
97 *
98 * Platform Segment SA IA GT (GT/GTx)
99 * ---------------------------------------------------------------------
100 * KBL/SKL-S (95W) quad 11.1 100 45
101 * SKL-S (80W) quad 11.1 82 45
102 * KBL/SKL-S (65W) quad 11.1 79 45
103 * SKL-S (45W) quad 11.1 70 0
104 * KBL/SKL-S (35W) quad 11.1 66 35
105 * SKL-S (25W) quad 11.1 55 35
106 *
107 * KBL/SKL-S (54W) dual 11.1 58 48
108 * KBL/SKL-S (51W) dual 11.1 45 48
109 * KBL/SKL-S (35W) dual 11.1 40 48
110 *
111 * SKL-H + OPC (65W) GT4 quad 8 74 105/24
112 * SKL-H + OPC (45W) GT4 quad 8 74 94/20
113 * SKL-H + OPC (35W) GT4 quad 8 66 94/20
114 *
115 * SKL-H (35W) GT2 dual 11.1 60 55
116 *
117 * KBL/SKL-H (45W) GT2 quad 11.1 68 55
118 * KBL-H (18W) GT2 quad 6.6 60 55
119 *
120 * SKL-U + OPC (28W) GT3 dual 5.1 32 57/19
121 * SKL-U + OPC (15W) GT3 dual 5.1 29 57/19
122 * SKL-U (15W) GT2 dual 4.5 29 31
123 *
124 * KBL-U/R + OPC (28W) GT3 dual 5.1 32 57/19
125 * KBL-U/R + OPC (15W) GT3 dual 5.1 32 57/19
126 *
127 * KBL-U/R (15W) GT2 quad 6 64 31
128 * KBL-U/R (15W) GT1/2 dual 4.5 32 31
129 * KBL-U/R (15W) GT2 quad 4.5 29 31
130 *
131 * SKL/KBL-Y (6W) 4.1 24 24
132 * SKL/KBL-Y (4.5W) 4.1 24 24
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200133 */
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800134
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200135 switch (mch_id) {
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300136 case PCI_DEVICE_ID_INTEL_SKL_ID_S_2: /* fallthrough */
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200137 case PCI_DEVICE_ID_INTEL_KBL_ID_S: {
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300138 uint16_t icc_max[NUM_VR_DOMAINS] = VR_CFG_ALL_DOMAINS_ICC(11.1, 40, 48, 48);
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200139 if (tdp >= 54)
140 icc_max[VR_IA_CORE] = VR_CFG_AMP(58);
141 else if (tdp >= 51)
142 icc_max[VR_IA_CORE] = VR_CFG_AMP(45);
143
144 return icc_max[domain];
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200145 }
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300146 case PCI_DEVICE_ID_INTEL_SKL_ID_S_4: /* fallthrough */
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200147 case PCI_DEVICE_ID_INTEL_KBL_ID_DT_2: /* fallthrough */
148 case PCI_DEVICE_ID_INTEL_KBL_ID_DT: {
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300149 uint16_t icc_max[NUM_VR_DOMAINS] = VR_CFG_ALL_DOMAINS_ICC(11.1, 55, 45, 45);
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200150 if (tdp >= 91)
151 icc_max[VR_IA_CORE] = VR_CFG_AMP(100);
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300152 else if (tdp >= 80)
153 icc_max[VR_IA_CORE] = VR_CFG_AMP(82);
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200154 else if (tdp >= 65)
155 icc_max[VR_IA_CORE] = VR_CFG_AMP(79);
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300156 else if (tdp >= 45) {
157 icc_max[VR_IA_CORE] = VR_CFG_AMP(70);
158 icc_max[VR_GT_SLICED] = 0;
159 icc_max[VR_GT_UNSLICED] = 0;
160 } else if (tdp >= 25) {
161 if (tdp >= 35)
162 icc_max[VR_IA_CORE] = VR_CFG_AMP(66);
163
Maxim Polyakovb4383fc2019-08-29 16:51:37 +0300164 icc_max[VR_GT_SLICED] = VR_CFG_AMP(35);
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300165 icc_max[VR_GT_UNSLICED] = VR_CFG_AMP(35);
Maxim Polyakovb4383fc2019-08-29 16:51:37 +0300166 }
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200167
168 return icc_max[domain];
169 }
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300170 case PCI_DEVICE_ID_INTEL_SKL_ID_H_4: {
171 uint16_t icc_max[NUM_VR_DOMAINS] = VR_CFG_ALL_DOMAINS_ICC(11.1, 60, 94, 20);
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200172 if (tdp >= 45) {
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300173 icc_max[VR_IA_CORE] = VR_CFG_AMP(74);
174 if (tdp >= 65) {
175 icc_max[VR_GT_SLICED] = VR_CFG_AMP(105);
176 icc_max[VR_GT_UNSLICED] = VR_CFG_AMP(24);
177 }
178 }
179 return icc_max[domain];
180 }
181 case PCI_DEVICE_ID_INTEL_SKL_ID_H_2: /* fallthrough */
182 case PCI_DEVICE_ID_INTEL_SKL_ID_H_EM: /* fallthrough */
183 case PCI_DEVICE_ID_INTEL_KBL_ID_H: {
184 uint16_t icc_max[NUM_VR_DOMAINS] = VR_CFG_ALL_DOMAINS_ICC(6.6, 60, 55, 55);
185 if (tdp >= 35) {
186 if (tdp >= 45)
187 icc_max[VR_IA_CORE] = VR_CFG_AMP(68);
188
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200189 icc_max[VR_SYSTEM_AGENT] = VR_CFG_AMP(11.1);
Patrick Rudolph69e826d2019-08-14 10:23:30 +0200190 }
191
192 return icc_max[domain];
193 }
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300194 case PCI_DEVICE_ID_INTEL_SKL_ID_U: {
195 uint16_t icc_max[NUM_VR_DOMAINS] = VR_CFG_ALL_DOMAINS_ICC(5.1, 29, 57, 19);
196 if (tdp >= 28)
197 icc_max[VR_IA_CORE] = VR_CFG_AMP(32);
198 else if (igd_id != PCI_DEVICE_ID_INTEL_SKL_GT3E_SULTM_1) {
199 const uint16_t icc_max_gt2[NUM_VR_DOMAINS] =
200 VR_CFG_ALL_DOMAINS_ICC(4.5, 29, 31, 31);
201
202 return icc_max_gt2[domain];
203 }
204 return icc_max[domain];
205 }
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200206 case PCI_DEVICE_ID_INTEL_KBL_U_R: {
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300207 const uint16_t icc_max[NUM_VR_DOMAINS] =
208 VR_CFG_ALL_DOMAINS_ICC(6, 64, 31, 31);
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200209 return icc_max[domain];
210 }
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300211 case PCI_DEVICE_ID_INTEL_SKL_ID_Y: /* fallthrough */
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200212 case PCI_DEVICE_ID_INTEL_KBL_ID_Y: {
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300213 uint16_t icc_max[NUM_VR_DOMAINS] = VR_CFG_ALL_DOMAINS_ICC(4.1, 24, 24, 24);
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800214
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200215 if (igd_id == PCI_DEVICE_ID_INTEL_AML_GT2_ULX)
216 icc_max[VR_IA_CORE] = VR_CFG_AMP(28);
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800217
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200218 return icc_max[domain];
219 }
220 case PCI_DEVICE_ID_INTEL_KBL_ID_U: {
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300221 uint16_t icc_max[NUM_VR_DOMAINS] = VR_CFG_ALL_DOMAINS_ICC(4.5, 32, 31, 31);
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800222
Maxim Polyakov9d68cb22019-10-03 17:07:21 +0300223 if ((igd_id == PCI_DEVICE_ID_INTEL_KBL_GT3E_SULTM_1) ||
224 (igd_id == PCI_DEVICE_ID_INTEL_KBL_GT3E_SULTM_2))
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200225 icc_max[VR_IA_CORE] = VR_CFG_AMP(29);
226
227 return icc_max[domain];
228 }
229 default:
Maxim Polyakov5f257602019-10-27 15:01:27 +0300230 printk(BIOS_ERR, "ERROR: Unknown MCH (0x%x) in VR-config\n", mch_id);
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200231 }
232 return 0;
Gaggery Tsaie1a75d42018-01-02 12:13:40 +0800233}
234
Patrick Rudolph9a016232019-08-14 12:10:48 +0200235static uint16_t get_sku_ac_dc_loadline(const int domain)
236{
237 static uint16_t mch_id = 0, igd_id = 0;
238 if (!mch_id) {
239 struct device *dev = pcidev_path_on_root(SA_DEVFN_ROOT);
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300240 mch_id = dev ? pci_read_config16(dev, PCI_DEVICE_ID) : 0xffff;
Patrick Rudolph9a016232019-08-14 12:10:48 +0200241 }
242 if (!igd_id) {
243 struct device *dev = pcidev_path_on_root(SA_DEVFN_IGD);
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300244 igd_id = dev ? pci_read_config16(dev, PCI_DEVICE_ID) : 0xffff;
Patrick Rudolph9a016232019-08-14 12:10:48 +0200245 }
246
247 switch (mch_id) {
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300248 case PCI_DEVICE_ID_INTEL_SKL_ID_S_2: /* fallthrough */
249 case PCI_DEVICE_ID_INTEL_SKL_ID_S_4: /* fallthrough */
250 case PCI_DEVICE_ID_INTEL_KBL_ID_S: /* fallthrough */
251 case PCI_DEVICE_ID_INTEL_KBL_ID_DT: /* fallthrough */
Patrick Rudolph9a016232019-08-14 12:10:48 +0200252 case PCI_DEVICE_ID_INTEL_KBL_ID_DT_2: {
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300253 /* SA Loadline is not specified */
254 const uint16_t loadline[NUM_VR_DOMAINS] =
255 VR_CFG_ALL_DOMAINS_LOADLINE(0, 2.1, 3.1, 3.1);
Patrick Rudolph9a016232019-08-14 12:10:48 +0200256 return loadline[domain];
257 }
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300258 case PCI_DEVICE_ID_INTEL_SKL_ID_H_2: /* fallthrough */
259 case PCI_DEVICE_ID_INTEL_SKL_ID_H_EM: /* fallthrough */
260 case PCI_DEVICE_ID_INTEL_SKL_ID_H_4: /* fallthrough */
Patrick Rudolph9a016232019-08-14 12:10:48 +0200261 case PCI_DEVICE_ID_INTEL_KBL_ID_H: {
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300262 const uint16_t loadline[NUM_VR_DOMAINS] =
263 VR_CFG_ALL_DOMAINS_LOADLINE(10, 1.8, 2.65, 2.65);
264
265 if (igd_id == PCI_DEVICE_ID_INTEL_SKL_GT4_SHALM) {
266 const uint16_t loadline_gt4[NUM_VR_DOMAINS] =
267 VR_CFG_ALL_DOMAINS_LOADLINE(6, 1.6, 1.4, 6);
268 return loadline_gt4[domain];
269 }
Patrick Rudolph9a016232019-08-14 12:10:48 +0200270
271 return loadline[domain];
272 }
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300273 case PCI_DEVICE_ID_INTEL_SKL_ID_Y: /* fallthrough */
Patrick Rudolph9a016232019-08-14 12:10:48 +0200274 case PCI_DEVICE_ID_INTEL_KBL_ID_Y: {
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300275 uint16_t loadline[NUM_VR_DOMAINS] =
276 VR_CFG_ALL_DOMAINS_LOADLINE(18, 5.9, 5.7, 5.7);
Patrick Rudolph9a016232019-08-14 12:10:48 +0200277
278 if (igd_id == PCI_DEVICE_ID_INTEL_AML_GT2_ULX)
279 loadline[VR_IA_CORE] = VR_CFG_MOHMS(4);
280
281 return loadline[domain];
282 }
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300283 case PCI_DEVICE_ID_INTEL_SKL_ID_U: /* fallthrough */
284 case PCI_DEVICE_ID_INTEL_KBL_U_R: /* fallthrough */
Patrick Rudolph9a016232019-08-14 12:10:48 +0200285 case PCI_DEVICE_ID_INTEL_KBL_ID_U: {
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300286 uint16_t loadline[NUM_VR_DOMAINS] =
287 VR_CFG_ALL_DOMAINS_LOADLINE(10.3, 2.4, 3.1, 3.1);
Patrick Rudolph9a016232019-08-14 12:10:48 +0200288
Maxim Polyakov24ba8502019-08-29 18:40:19 +0300289 if ((igd_id == PCI_DEVICE_ID_INTEL_SKL_GT3E_SULTM_1) ||
290 (igd_id == PCI_DEVICE_ID_INTEL_SKL_GT3E_SULTM_2) ||
291 (igd_id == PCI_DEVICE_ID_INTEL_KBL_GT3E_SULTM_1) ||
Maxim Polyakov9d68cb22019-10-03 17:07:21 +0300292 (igd_id == PCI_DEVICE_ID_INTEL_KBL_GT3E_SULTM_2)) {
Maxim Polyakov72359132019-10-03 16:50:04 +0300293 loadline[VR_GT_UNSLICED] = VR_CFG_MOHMS(2);
Patrick Rudolph9a016232019-08-14 12:10:48 +0200294 loadline[VR_GT_SLICED] = VR_CFG_MOHMS(6);
295 }
296
297 return loadline[domain];
298 }
299 default:
Maxim Polyakov5f257602019-10-27 15:01:27 +0300300 printk(BIOS_ERR, "ERROR: Unknown MCH (0x%x) in VR-config\n", mch_id);
Patrick Rudolph9a016232019-08-14 12:10:48 +0200301 }
302 return 0;
303}
Patrick Rudolph9a016232019-08-14 12:10:48 +0200304
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530305void fill_vr_domain_config(void *params,
306 int domain, const struct vr_config *chip_cfg)
Aaron Durbindf214402015-12-14 16:44:26 -0600307{
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530308 FSP_SIL_UPD *vr_params = (FSP_SIL_UPD *)params;
Aaron Durbindf214402015-12-14 16:44:26 -0600309 const struct vr_config *cfg;
310
311 if (domain < 0 || domain >= NUM_VR_DOMAINS)
312 return;
313
314 /* Use device tree override if requested. */
315 if (chip_cfg->vr_config_enable)
316 cfg = chip_cfg;
317 else
318 cfg = &default_configs[domain];
319
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530320 vr_params->VrConfigEnable[domain] = cfg->vr_config_enable;
321 vr_params->Psi1Threshold[domain] = cfg->psi1threshold;
322 vr_params->Psi2Threshold[domain] = cfg->psi2threshold;
323 vr_params->Psi3Threshold[domain] = cfg->psi3threshold;
324 vr_params->Psi3Enable[domain] = cfg->psi3enable;
325 vr_params->Psi4Enable[domain] = cfg->psi4enable;
326 vr_params->ImonSlope[domain] = cfg->imon_slope;
327 vr_params->ImonOffset[domain] = cfg->imon_offset;
Patrick Rudolph50aebaf82019-08-14 10:07:38 +0200328 /* If board provided non-zero value, use it. */
329 if (cfg->icc_max)
330 vr_params->IccMax[domain] = cfg->icc_max;
331 else
332 vr_params->IccMax[domain] = get_sku_icc_max(domain);
Rizwan Qureshi1222a732016-08-23 14:31:23 +0530333 vr_params->VrVoltageLimit[domain] = cfg->voltage_limit;
Duncan Laurie86db4692017-03-14 16:40:06 -0700334
Patrick Rudolph9a016232019-08-14 12:10:48 +0200335 if (cfg->ac_loadline)
336 vr_params->AcLoadline[domain] = cfg->ac_loadline;
337 else
338 vr_params->AcLoadline[domain] = get_sku_ac_dc_loadline(domain);
339 if (cfg->dc_loadline)
340 vr_params->DcLoadline[domain] = cfg->dc_loadline;
341 else
342 vr_params->DcLoadline[domain] = get_sku_ac_dc_loadline(domain);
Aaron Durbindf214402015-12-14 16:44:26 -0600343}