blob: a45f021ccb5722f7d06c15947febb8c0c4ba4f43 [file] [log] [blame]
Angel Ponsf23ae0b2020-04-02 23:48:12 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +02003
4#include <types.h>
5#include <console/console.h>
6#include <arch/acpi.h>
7#include <arch/acpigen.h>
8#include <arch/cpu.h>
9#include <cpu/x86/msr.h>
10#include <cpu/intel/speedstep.h>
11#include <cpu/intel/turbo.h>
12#include <device/device.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020013#include "model_2065x.h"
14#include "chip.h"
15
16static int get_cores_per_package(void)
17{
18 struct cpuinfo_x86 c;
19 struct cpuid_result result;
20 int cores = 1;
21
22 get_fms(&c, cpuid_eax(1));
23 if (c.x86 != 6)
24 return 1;
25
26 result = cpuid_ext(0xb, 1);
27 cores = result.ebx & 0xff;
28
29 return cores;
30}
31
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010032static void generate_cstate_entries(acpi_cstate_t *cstates,
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020033 int c1, int c2, int c3)
34{
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010035 int cstate_count = 0;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020036
37 /* Count number of active C-states */
38 if (c1 > 0)
39 ++cstate_count;
40 if (c2 > 0)
41 ++cstate_count;
42 if (c3 > 0)
43 ++cstate_count;
44 if (!cstate_count)
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010045 return;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020046
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010047 acpigen_write_package(cstate_count + 1);
48 acpigen_write_byte(cstate_count);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020049
50 /* Add an entry if the level is enabled */
51 if (c1 > 0) {
52 cstates[c1].ctype = 1;
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010053 acpigen_write_CST_package_entry(&cstates[c1]);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020054 }
55 if (c2 > 0) {
56 cstates[c2].ctype = 2;
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010057 acpigen_write_CST_package_entry(&cstates[c2]);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020058 }
59 if (c3 > 0) {
60 cstates[c3].ctype = 3;
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010061 acpigen_write_CST_package_entry(&cstates[c3]);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020062 }
63
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010064 acpigen_pop_len();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020065}
66
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010067static void generate_C_state_entries(void)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020068{
69 struct cpu_info *info;
70 struct cpu_driver *cpu;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110071 struct device *lapic;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020072 struct cpu_intel_model_2065x_config *conf = NULL;
73
74 /* Find the SpeedStep CPU in the device tree using magic APIC ID */
75 lapic = dev_find_lapic(SPEEDSTEP_APIC_MAGIC);
76 if (!lapic)
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010077 return;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020078 conf = lapic->chip_info;
79 if (!conf)
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010080 return;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020081
82 /* Find CPU map of supported C-states */
83 info = cpu_info();
84 if (!info)
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010085 return;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020086 cpu = find_cpu_driver(info->cpu);
87 if (!cpu || !cpu->cstates)
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010088 return;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020089
Vladimir Serbinenko80fb8ed2014-11-05 10:28:28 +010090 acpigen_write_method("_CST", 0);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020091
92 /* If running on AC power */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +010093 acpigen_emit_byte(0xa0); /* IfOp */
94 acpigen_write_len_f(); /* PkgLength */
95 acpigen_emit_namestring("PWRS");
96 acpigen_emit_byte(0xa4); /* ReturnOp */
97 generate_cstate_entries(cpu->cstates, conf->c1_acpower,
98 conf->c2_acpower, conf->c3_acpower);
99 acpigen_pop_len();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200100
101 /* Else on battery power */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100102 acpigen_emit_byte(0xa4); /* ReturnOp */
103 generate_cstate_entries(cpu->cstates, conf->c1_battery,
104 conf->c2_battery, conf->c3_battery);
105 acpigen_pop_len();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200106}
107
108static acpi_tstate_t tss_table_fine[] = {
109 { 100, 1000, 0, 0x00, 0 },
110 { 94, 940, 0, 0x1f, 0 },
111 { 88, 880, 0, 0x1e, 0 },
112 { 82, 820, 0, 0x1d, 0 },
113 { 75, 760, 0, 0x1c, 0 },
114 { 69, 700, 0, 0x1b, 0 },
115 { 63, 640, 0, 0x1a, 0 },
116 { 57, 580, 0, 0x19, 0 },
117 { 50, 520, 0, 0x18, 0 },
118 { 44, 460, 0, 0x17, 0 },
119 { 38, 400, 0, 0x16, 0 },
120 { 32, 340, 0, 0x15, 0 },
121 { 25, 280, 0, 0x14, 0 },
122 { 19, 220, 0, 0x13, 0 },
123 { 13, 160, 0, 0x12, 0 },
124};
125
126static acpi_tstate_t tss_table_coarse[] = {
127 { 100, 1000, 0, 0x00, 0 },
128 { 88, 875, 0, 0x1f, 0 },
129 { 75, 750, 0, 0x1e, 0 },
130 { 63, 625, 0, 0x1d, 0 },
131 { 50, 500, 0, 0x1c, 0 },
132 { 38, 375, 0, 0x1b, 0 },
133 { 25, 250, 0, 0x1a, 0 },
134 { 13, 125, 0, 0x19, 0 },
135};
136
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100137static void generate_T_state_entries(int core, int cores_per_package)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200138{
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200139 /* Indicate SW_ALL coordination for T-states */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100140 acpigen_write_TSD_package(core, cores_per_package, SW_ALL);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200141
142 /* Indicate FFixedHW so OS will use MSR */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100143 acpigen_write_empty_PTC();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200144
145 /* Set a T-state limit that can be modified in NVS */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100146 acpigen_write_TPC("\\TLVL");
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200147
148 /*
149 * CPUID.(EAX=6):EAX[5] indicates support
150 * for extended throttle levels.
151 */
152 if (cpuid_eax(6) & (1 << 5))
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100153 acpigen_write_TSS_package(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200154 ARRAY_SIZE(tss_table_fine), tss_table_fine);
155 else
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100156 acpigen_write_TSS_package(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200157 ARRAY_SIZE(tss_table_coarse), tss_table_coarse);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200158}
159
160static int calculate_power(int tdp, int p1_ratio, int ratio)
161{
162 u32 m;
163 u32 power;
164
165 /*
166 * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2
167 *
168 * Power = (ratio / p1_ratio) * m * tdp
169 */
170
171 m = (110000 - ((p1_ratio - ratio) * 625)) / 11;
172 m = (m * m) / 1000;
173
174 power = ((ratio * 100000 / p1_ratio) / 100);
175 power *= (m / 100) * (tdp / 1000);
176 power /= 1000;
177
178 return (int)power;
179}
180
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100181static void generate_P_state_entries(int core, int cores_per_package)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200182{
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200183 int ratio_min, ratio_max, ratio_turbo, ratio_step;
184 int coord_type, power_max, num_entries;
185 int ratio, power, clock, clock_max;
186 msr_t msr;
187
188 /* Determine P-state coordination type from MISC_PWR_MGMT[0] */
189 msr = rdmsr(MSR_MISC_PWR_MGMT);
190 if (msr.lo & MISC_PWR_MGMT_EIST_HW_DIS)
191 coord_type = SW_ANY;
192 else
193 coord_type = HW_ALL;
194
195 /* Get bus ratio limits and calculate clock speeds */
196 msr = rdmsr(MSR_PLATFORM_INFO);
197 ratio_min = (msr.hi >> (40-32)) & 0xff; /* Max Efficiency Ratio */
198
199 /* Determine if this CPU has configurable TDP */
200 if (cpu_config_tdp_levels()) {
201 /* Set max ratio to nominal TDP ratio */
202 msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
203 ratio_max = msr.lo & 0xff;
204 } else {
205 /* Max Non-Turbo Ratio */
206 ratio_max = (msr.lo >> 8) & 0xff;
207 }
Angel Pons95de2312020-02-17 13:08:53 +0100208 clock_max = ratio_max * IRONLAKE_BCLK + ratio_max / 3;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200209
210 /* Calculate CPU TDP in mW */
211 power_max = 25000;
212
213 /* Write _PCT indicating use of FFixedHW */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100214 acpigen_write_empty_PCT();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200215
216 /* Write _PPC with no limit on supported P-state */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100217 acpigen_write_PPC_NVS();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200218
219 /* Write PSD indicating configured coordination type */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100220 acpigen_write_PSD_package(core, cores_per_package, coord_type);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200221
222 /* Add P-state entries in _PSS table */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100223 acpigen_write_name("_PSS");
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200224
225 /* Determine ratio points */
226 ratio_step = PSS_RATIO_STEP;
227 num_entries = (ratio_max - ratio_min) / ratio_step;
228 while (num_entries > PSS_MAX_ENTRIES-1) {
229 ratio_step <<= 1;
230 num_entries >>= 1;
231 }
232
233 /* P[T] is Turbo state if enabled */
234 if (get_turbo_state() == TURBO_ENABLED) {
235 /* _PSS package count including Turbo */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100236 acpigen_write_package(num_entries + 2);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200237
238 msr = rdmsr(MSR_TURBO_RATIO_LIMIT);
239 ratio_turbo = msr.lo & 0xff;
240
241 /* Add entry for Turbo ratio */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100242 acpigen_write_PSS_package(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200243 clock_max + 1, /*MHz*/
244 power_max, /*mW*/
245 PSS_LATENCY_TRANSITION, /*lat1*/
246 PSS_LATENCY_BUSMASTER, /*lat2*/
247 ratio_turbo, /*control*/
248 ratio_turbo); /*status*/
249 } else {
250 /* _PSS package count without Turbo */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100251 acpigen_write_package(num_entries + 1);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200252 }
253
254 /* First regular entry is max non-turbo ratio */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100255 acpigen_write_PSS_package(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200256 clock_max, /*MHz*/
257 power_max, /*mW*/
258 PSS_LATENCY_TRANSITION, /*lat1*/
259 PSS_LATENCY_BUSMASTER, /*lat2*/
260 ratio_max, /*control*/
261 ratio_max); /*status*/
262
263 /* Generate the remaining entries */
264 for (ratio = ratio_min + ((num_entries - 1) * ratio_step);
265 ratio >= ratio_min; ratio -= ratio_step) {
266
267 /* Calculate power at this ratio */
268 power = calculate_power(power_max, ratio_max, ratio);
Angel Pons95de2312020-02-17 13:08:53 +0100269 clock = ratio * IRONLAKE_BCLK + ratio / 3;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200270
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100271 acpigen_write_PSS_package(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200272 clock, /*MHz*/
273 power, /*mW*/
274 PSS_LATENCY_TRANSITION, /*lat1*/
275 PSS_LATENCY_BUSMASTER, /*lat2*/
276 ratio, /*control*/
277 ratio); /*status*/
278 }
279
280 /* Fix package length */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100281 acpigen_pop_len();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200282}
283
Furquan Shaikh7536a392020-04-24 21:59:21 -0700284void generate_cpu_entries(const struct device *device)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200285{
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200286 int coreID, cpuID, pcontrol_blk = PMB0_BASE, plen = 6;
287 int totalcores = dev_count_cpu();
288 int cores_per_package = get_cores_per_package();
289 int numcpus = totalcores/cores_per_package;
290
291 printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n",
292 numcpus, cores_per_package);
293
Martin Roth9944b282014-08-11 11:24:55 -0600294 for (cpuID = 1; cpuID <= numcpus; cpuID++) {
Lee Leahy9d62e7e2017-03-15 17:40:50 -0700295 for (coreID = 1; coreID <= cores_per_package; coreID++) {
296 if (coreID > 1) {
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200297 pcontrol_blk = 0;
298 plen = 0;
299 }
300
Christian Walterbe3979c2019-12-18 15:07:59 +0100301 /* Generate processor \_SB.CPUx */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100302 acpigen_write_processor(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200303 (cpuID-1)*cores_per_package+coreID-1,
304 pcontrol_blk, plen);
305
306 /* Generate P-state tables */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100307 generate_P_state_entries(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200308 cpuID-1, cores_per_package);
309
310 /* Generate C-state tables */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100311 generate_C_state_entries();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200312
313 /* Generate T-state tables */
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100314 generate_T_state_entries(
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200315 cpuID-1, cores_per_package);
316
Vladimir Serbinenko226d7842014-11-04 21:09:23 +0100317 acpigen_pop_len();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200318 }
319 }
Arthur Heymans04008a92018-11-28 12:13:54 +0100320
321 /* PPKG is usually used for thermal management
322 of the first and only package. */
323 acpigen_write_processor_package("PPKG", 0, cores_per_package);
324
325 /* Add a method to notify processor nodes */
326 acpigen_write_processor_cnot(cores_per_package);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200327}
328
329struct chip_operations cpu_intel_model_2065x_ops = {
Angel Pons31b7ee42020-02-17 14:04:28 +0100330 CHIP_NAME("Intel Arrandale CPU")
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200331};