blob: b93518954fd4e58dea6b56505fb890619e14efc5 [file] [log] [blame]
Angel Ponsf94ac9a2020-04-05 15:46:48 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Duncan Lauriec88c54c2014-04-30 16:36:13 -07003
4#include <arch/acpi.h>
5#include <arch/acpigen.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07006#include <arch/smp/mpspec.h>
7#include <cbmem.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +02008#include <device/pci_ops.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07009#include <cpu/x86/smm.h>
10#include <console/console.h>
11#include <types.h>
12#include <string.h>
13#include <arch/cpu.h>
14#include <cpu/x86/msr.h>
15#include <cpu/x86/tsc.h>
16#include <cpu/intel/turbo.h>
17#include <ec/google/chromeec/ec.h>
18#include <vendorcode/google/chromeos/gnvs.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070019#include <soc/acpi.h>
20#include <soc/cpu.h>
21#include <soc/iomap.h>
22#include <soc/lpc.h>
23#include <soc/msr.h>
24#include <soc/pci_devs.h>
25#include <soc/pm.h>
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060026#include <soc/systemagent.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070027#include <soc/intel/broadwell/chip.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070028
29/*
Martin Rothde7ed6f2014-12-07 14:58:18 -070030 * List of supported C-states in this processor. Only the ULT parts support C8,
Duncan Lauriec88c54c2014-04-30 16:36:13 -070031 * C9, and C10.
32 */
33enum {
34 C_STATE_C0, /* 0 */
35 C_STATE_C1, /* 1 */
36 C_STATE_C1E, /* 2 */
37 C_STATE_C3, /* 3 */
38 C_STATE_C6_SHORT_LAT, /* 4 */
39 C_STATE_C6_LONG_LAT, /* 5 */
40 C_STATE_C7_SHORT_LAT, /* 6 */
41 C_STATE_C7_LONG_LAT, /* 7 */
42 C_STATE_C7S_SHORT_LAT, /* 8 */
43 C_STATE_C7S_LONG_LAT, /* 9 */
44 C_STATE_C8, /* 10 */
45 C_STATE_C9, /* 11 */
46 C_STATE_C10, /* 12 */
47 NUM_C_STATES
48};
49
50#define MWAIT_RES(state, sub_state) \
51 { \
52 .addrl = (((state) << 4) | (sub_state)), \
53 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
54 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \
55 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \
56 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \
57 }
58
59static acpi_cstate_t cstate_map[NUM_C_STATES] = {
60 [C_STATE_C0] = { },
61 [C_STATE_C1] = {
62 .latency = 0,
63 .power = 1000,
Lee Leahy26b7cd02017-03-16 18:47:55 -070064 .resource = MWAIT_RES(0, 0),
Duncan Lauriec88c54c2014-04-30 16:36:13 -070065 },
66 [C_STATE_C1E] = {
67 .latency = 0,
68 .power = 1000,
Lee Leahy26b7cd02017-03-16 18:47:55 -070069 .resource = MWAIT_RES(0, 1),
Duncan Lauriec88c54c2014-04-30 16:36:13 -070070 },
71 [C_STATE_C3] = {
72 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
73 .power = 900,
74 .resource = MWAIT_RES(1, 0),
75 },
76 [C_STATE_C6_SHORT_LAT] = {
77 .latency = C_STATE_LATENCY_FROM_LAT_REG(1),
78 .power = 800,
79 .resource = MWAIT_RES(2, 0),
80 },
81 [C_STATE_C6_LONG_LAT] = {
82 .latency = C_STATE_LATENCY_FROM_LAT_REG(2),
83 .power = 800,
84 .resource = MWAIT_RES(2, 1),
85 },
86 [C_STATE_C7_SHORT_LAT] = {
87 .latency = C_STATE_LATENCY_FROM_LAT_REG(1),
88 .power = 700,
89 .resource = MWAIT_RES(3, 0),
90 },
91 [C_STATE_C7_LONG_LAT] = {
92 .latency = C_STATE_LATENCY_FROM_LAT_REG(2),
93 .power = 700,
94 .resource = MWAIT_RES(3, 1),
95 },
96 [C_STATE_C7S_SHORT_LAT] = {
97 .latency = C_STATE_LATENCY_FROM_LAT_REG(1),
98 .power = 700,
99 .resource = MWAIT_RES(3, 2),
100 },
101 [C_STATE_C7S_LONG_LAT] = {
102 .latency = C_STATE_LATENCY_FROM_LAT_REG(2),
103 .power = 700,
104 .resource = MWAIT_RES(3, 3),
105 },
106 [C_STATE_C8] = {
107 .latency = C_STATE_LATENCY_FROM_LAT_REG(3),
108 .power = 600,
109 .resource = MWAIT_RES(4, 0),
110 },
111 [C_STATE_C9] = {
112 .latency = C_STATE_LATENCY_FROM_LAT_REG(4),
113 .power = 500,
114 .resource = MWAIT_RES(5, 0),
115 },
116 [C_STATE_C10] = {
117 .latency = C_STATE_LATENCY_FROM_LAT_REG(5),
118 .power = 400,
119 .resource = MWAIT_RES(6, 0),
120 },
121};
122
123static int cstate_set_s0ix[3] = {
124 C_STATE_C1E,
125 C_STATE_C7S_LONG_LAT,
126 C_STATE_C10
127};
128
129static int cstate_set_non_s0ix[3] = {
130 C_STATE_C1E,
131 C_STATE_C3,
132 C_STATE_C7S_LONG_LAT
133};
134
135static int get_cores_per_package(void)
136{
137 struct cpuinfo_x86 c;
138 struct cpuid_result result;
139 int cores = 1;
140
141 get_fms(&c, cpuid_eax(1));
142 if (c.x86 != 6)
143 return 1;
144
145 result = cpuid_ext(0xb, 1);
146 cores = result.ebx & 0xff;
147
148 return cores;
149}
150
151void acpi_init_gnvs(global_nvs_t *gnvs)
152{
153 /* Set unknown wake source */
154 gnvs->pm1i = -1;
155
156 /* CPU core count */
157 gnvs->pcnt = dev_count_cpu();
158
Julius Wernercd49cce2019-03-05 16:53:33 -0800159#if CONFIG(CONSOLE_CBMEM)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700160 /* Update the mem console pointer. */
161 gnvs->cbmc = (u32)cbmem_find(CBMEM_ID_CONSOLE);
162#endif
163
Julius Wernercd49cce2019-03-05 16:53:33 -0800164#if CONFIG(CHROMEOS)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700165 /* Initialize Verified Boot data */
Joel Kitching6fbd8742018-08-23 14:56:25 +0800166 chromeos_init_chromeos_acpi(&(gnvs->chromeos));
Julius Wernercd49cce2019-03-05 16:53:33 -0800167#if CONFIG(EC_GOOGLE_CHROMEEC)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700168 gnvs->chromeos.vbt2 = google_ec_running_ro() ?
169 ACTIVE_ECFW_RO : ACTIVE_ECFW_RW;
170#endif
171 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
172#endif
173}
174
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700175unsigned long acpi_fill_mcfg(unsigned long current)
176{
177 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current,
178 MCFG_BASE_ADDRESS, 0, 0, 255);
179 return current;
180}
181
182void acpi_fill_in_fadt(acpi_fadt_t *fadt)
183{
184 const uint16_t pmbase = ACPI_BASE_ADDRESS;
185
186 fadt->sci_int = acpi_sci_irq();
187 fadt->smi_cmd = APM_CNT;
188 fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
189 fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
190 fadt->s4bios_req = 0x0;
191 fadt->pstate_cnt = 0;
192
193 fadt->pm1a_evt_blk = pmbase + PM1_STS;
194 fadt->pm1b_evt_blk = 0x0;
195 fadt->pm1a_cnt_blk = pmbase + PM1_CNT;
196 fadt->pm1b_cnt_blk = 0x0;
197 fadt->pm2_cnt_blk = pmbase + PM2_CNT;
198 fadt->pm_tmr_blk = pmbase + PM1_TMR;
199 fadt->gpe0_blk = pmbase + GPE0_STS(0);
200 fadt->gpe1_blk = 0;
201
202 fadt->pm1_evt_len = 4;
203 fadt->pm1_cnt_len = 2;
204 fadt->pm2_cnt_len = 1;
205 fadt->pm_tmr_len = 4;
206 fadt->gpe0_blk_len = 32;
207 fadt->gpe1_blk_len = 0;
208 fadt->gpe1_base = 0;
209 fadt->cst_cnt = 0;
210 fadt->p_lvl2_lat = 1;
211 fadt->p_lvl3_lat = 87;
212 fadt->flush_size = 1024;
213 fadt->flush_stride = 16;
214 fadt->duty_offset = 1;
215 fadt->duty_width = 0;
216 fadt->day_alrm = 0xd;
217 fadt->mon_alrm = 0x00;
218 fadt->century = 0x00;
219 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
220
221 fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED |
222 ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON |
223 ACPI_FADT_RESET_REGISTER | ACPI_FADT_SEALED_CASE |
224 ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_PLATFORM_CLOCK;
225
226 fadt->reset_reg.space_id = 1;
227 fadt->reset_reg.bit_width = 8;
228 fadt->reset_reg.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100229 fadt->reset_reg.access_size = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700230 fadt->reset_reg.addrl = 0xcf9;
231 fadt->reset_reg.addrh = 0;
232 fadt->reset_value = 6;
233
234 fadt->x_pm1a_evt_blk.space_id = 1;
235 fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8;
236 fadt->x_pm1a_evt_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100237 fadt->x_pm1a_evt_blk.access_size = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700238 fadt->x_pm1a_evt_blk.addrl = pmbase + PM1_STS;
239 fadt->x_pm1a_evt_blk.addrh = 0x0;
240
241 fadt->x_pm1b_evt_blk.space_id = 1;
242 fadt->x_pm1b_evt_blk.bit_width = 0;
243 fadt->x_pm1b_evt_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100244 fadt->x_pm1b_evt_blk.access_size = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700245 fadt->x_pm1b_evt_blk.addrl = 0x0;
246 fadt->x_pm1b_evt_blk.addrh = 0x0;
247
248 fadt->x_pm1a_cnt_blk.space_id = 1;
249 fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8;
250 fadt->x_pm1a_cnt_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100251 fadt->x_pm1a_cnt_blk.access_size = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700252 fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT;
253 fadt->x_pm1a_cnt_blk.addrh = 0x0;
254
255 fadt->x_pm1b_cnt_blk.space_id = 1;
256 fadt->x_pm1b_cnt_blk.bit_width = 0;
257 fadt->x_pm1b_cnt_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100258 fadt->x_pm1b_cnt_blk.access_size = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700259 fadt->x_pm1b_cnt_blk.addrl = 0x0;
260 fadt->x_pm1b_cnt_blk.addrh = 0x0;
261
262 fadt->x_pm2_cnt_blk.space_id = 1;
263 fadt->x_pm2_cnt_blk.bit_width = fadt->pm2_cnt_len * 8;
264 fadt->x_pm2_cnt_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100265 fadt->x_pm2_cnt_blk.access_size = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700266 fadt->x_pm2_cnt_blk.addrl = pmbase + PM2_CNT;
267 fadt->x_pm2_cnt_blk.addrh = 0x0;
268
269 fadt->x_pm_tmr_blk.space_id = 1;
270 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
271 fadt->x_pm_tmr_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100272 fadt->x_pm_tmr_blk.access_size = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700273 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
274 fadt->x_pm_tmr_blk.addrh = 0x0;
275
276 fadt->x_gpe0_blk.space_id = 0;
277 fadt->x_gpe0_blk.bit_width = 0;
278 fadt->x_gpe0_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100279 fadt->x_gpe0_blk.access_size = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700280 fadt->x_gpe0_blk.addrl = 0;
281 fadt->x_gpe0_blk.addrh = 0;
282
283 fadt->x_gpe1_blk.space_id = 1;
284 fadt->x_gpe1_blk.bit_width = 0;
285 fadt->x_gpe1_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100286 fadt->x_gpe1_blk.access_size = 0;
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700287 fadt->x_gpe1_blk.addrl = 0x0;
288 fadt->x_gpe1_blk.addrh = 0x0;
289}
290
291static acpi_tstate_t tss_table_fine[] = {
292 { 100, 1000, 0, 0x00, 0 },
293 { 94, 940, 0, 0x1f, 0 },
294 { 88, 880, 0, 0x1e, 0 },
295 { 82, 820, 0, 0x1d, 0 },
296 { 75, 760, 0, 0x1c, 0 },
297 { 69, 700, 0, 0x1b, 0 },
298 { 63, 640, 0, 0x1a, 0 },
299 { 57, 580, 0, 0x19, 0 },
300 { 50, 520, 0, 0x18, 0 },
301 { 44, 460, 0, 0x17, 0 },
302 { 38, 400, 0, 0x16, 0 },
303 { 32, 340, 0, 0x15, 0 },
304 { 25, 280, 0, 0x14, 0 },
305 { 19, 220, 0, 0x13, 0 },
306 { 13, 160, 0, 0x12, 0 },
307};
308
309static acpi_tstate_t tss_table_coarse[] = {
310 { 100, 1000, 0, 0x00, 0 },
311 { 88, 875, 0, 0x1f, 0 },
312 { 75, 750, 0, 0x1e, 0 },
313 { 63, 625, 0, 0x1d, 0 },
314 { 50, 500, 0, 0x1c, 0 },
315 { 38, 375, 0, 0x1b, 0 },
316 { 25, 250, 0, 0x1a, 0 },
317 { 13, 125, 0, 0x19, 0 },
318};
319
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100320static void generate_T_state_entries(int core, int cores_per_package)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700321{
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700322 /* Indicate SW_ALL coordination for T-states */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100323 acpigen_write_TSD_package(core, cores_per_package, SW_ALL);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700324
325 /* Indicate FFixedHW so OS will use MSR */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100326 acpigen_write_empty_PTC();
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700327
328 /* Set a T-state limit that can be modified in NVS */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100329 acpigen_write_TPC("\\TLVL");
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700330
331 /*
332 * CPUID.(EAX=6):EAX[5] indicates support
333 * for extended throttle levels.
334 */
335 if (cpuid_eax(6) & (1 << 5))
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100336 acpigen_write_TSS_package(
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700337 ARRAY_SIZE(tss_table_fine), tss_table_fine);
338 else
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100339 acpigen_write_TSS_package(
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700340 ARRAY_SIZE(tss_table_coarse), tss_table_coarse);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700341}
342
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100343static void generate_C_state_entries(void)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700344{
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700345 acpi_cstate_t map[3];
346 int *set;
347 int i;
348
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300349 config_t *config = config_of_soc();
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300350
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700351 if (config->s0ix_enable)
352 set = cstate_set_s0ix;
353 else
354 set = cstate_set_non_s0ix;
355
356 for (i = 0; i < 3; i++) {
357 memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t));
358 map[i].ctype = i + 1;
359 }
360
361 /* Generate C-state tables */
Vladimir Serbinenko9bb5c5c2014-11-09 03:51:32 +0100362 acpigen_write_CST_package(map, ARRAY_SIZE(map));
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700363}
364
365static int calculate_power(int tdp, int p1_ratio, int ratio)
366{
367 u32 m;
368 u32 power;
369
370 /*
371 * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2
372 *
373 * Power = (ratio / p1_ratio) * m * tdp
374 */
375
376 m = (110000 - ((p1_ratio - ratio) * 625)) / 11;
377 m = (m * m) / 1000;
378
379 power = ((ratio * 100000 / p1_ratio) / 100);
380 power *= (m / 100) * (tdp / 1000);
381 power /= 1000;
382
383 return (int)power;
384}
385
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100386static void generate_P_state_entries(int core, int cores_per_package)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700387{
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700388 int ratio_min, ratio_max, ratio_turbo, ratio_step;
389 int coord_type, power_max, power_unit, num_entries;
390 int ratio, power, clock, clock_max;
391 msr_t msr;
392
393 /* Determine P-state coordination type from MISC_PWR_MGMT[0] */
394 msr = rdmsr(MSR_MISC_PWR_MGMT);
395 if (msr.lo & MISC_PWR_MGMT_EIST_HW_DIS)
396 coord_type = SW_ANY;
397 else
398 coord_type = HW_ALL;
399
400 /* Get bus ratio limits and calculate clock speeds */
401 msr = rdmsr(MSR_PLATFORM_INFO);
402 ratio_min = (msr.hi >> (40-32)) & 0xff; /* Max Efficiency Ratio */
403
404 /* Determine if this CPU has configurable TDP */
405 if (cpu_config_tdp_levels()) {
406 /* Set max ratio to nominal TDP ratio */
407 msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
408 ratio_max = msr.lo & 0xff;
409 } else {
410 /* Max Non-Turbo Ratio */
411 ratio_max = (msr.lo >> 8) & 0xff;
412 }
413 clock_max = ratio_max * CPU_BCLK;
414
415 /* Calculate CPU TDP in mW */
416 msr = rdmsr(MSR_PKG_POWER_SKU_UNIT);
417 power_unit = 2 << ((msr.lo & 0xf) - 1);
418 msr = rdmsr(MSR_PKG_POWER_SKU);
419 power_max = ((msr.lo & 0x7fff) / power_unit) * 1000;
420
421 /* Write _PCT indicating use of FFixedHW */
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100422 acpigen_write_empty_PCT();
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700423
424 /* Write _PPC with no limit on supported P-state */
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100425 acpigen_write_PPC_NVS();
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700426
427 /* Write PSD indicating configured coordination type */
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100428 acpigen_write_PSD_package(core, 1, coord_type);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700429
430 /* Add P-state entries in _PSS table */
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100431 acpigen_write_name("_PSS");
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700432
433 /* Determine ratio points */
434 ratio_step = PSS_RATIO_STEP;
435 num_entries = (ratio_max - ratio_min) / ratio_step;
436 while (num_entries > PSS_MAX_ENTRIES-1) {
437 ratio_step <<= 1;
438 num_entries >>= 1;
439 }
440
441 /* P[T] is Turbo state if enabled */
442 if (get_turbo_state() == TURBO_ENABLED) {
443 /* _PSS package count including Turbo */
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100444 acpigen_write_package(num_entries + 2);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700445
446 msr = rdmsr(MSR_TURBO_RATIO_LIMIT);
447 ratio_turbo = msr.lo & 0xff;
448
449 /* Add entry for Turbo ratio */
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100450 acpigen_write_PSS_package(
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700451 clock_max + 1, /*MHz*/
452 power_max, /*mW*/
453 PSS_LATENCY_TRANSITION, /*lat1*/
454 PSS_LATENCY_BUSMASTER, /*lat2*/
455 ratio_turbo << 8, /*control*/
456 ratio_turbo << 8); /*status*/
457 } else {
458 /* _PSS package count without Turbo */
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100459 acpigen_write_package(num_entries + 1);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700460 }
461
462 /* First regular entry is max non-turbo ratio */
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100463 acpigen_write_PSS_package(
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700464 clock_max, /*MHz*/
465 power_max, /*mW*/
466 PSS_LATENCY_TRANSITION, /*lat1*/
467 PSS_LATENCY_BUSMASTER, /*lat2*/
468 ratio_max << 8, /*control*/
469 ratio_max << 8); /*status*/
470
471 /* Generate the remaining entries */
472 for (ratio = ratio_min + ((num_entries - 1) * ratio_step);
473 ratio >= ratio_min; ratio -= ratio_step) {
474
475 /* Calculate power at this ratio */
476 power = calculate_power(power_max, ratio_max, ratio);
477 clock = ratio * CPU_BCLK;
478
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100479 acpigen_write_PSS_package(
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700480 clock, /*MHz*/
481 power, /*mW*/
482 PSS_LATENCY_TRANSITION, /*lat1*/
483 PSS_LATENCY_BUSMASTER, /*lat2*/
484 ratio << 8, /*control*/
485 ratio << 8); /*status*/
486 }
487
488 /* Fix package length */
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100489 acpigen_pop_len();
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700490}
491
Elyes HAOUAS040aff22018-05-27 16:30:36 +0200492void generate_cpu_entries(struct device *device)
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700493{
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700494 int coreID, cpuID, pcontrol_blk = ACPI_BASE_ADDRESS, plen = 6;
495 int totalcores = dev_count_cpu();
496 int cores_per_package = get_cores_per_package();
497 int numcpus = totalcores/cores_per_package;
498
499 printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n",
500 numcpus, cores_per_package);
501
Lee Leahy26b7cd02017-03-16 18:47:55 -0700502 for (cpuID = 1; cpuID <= numcpus; cpuID++) {
503 for (coreID = 1; coreID <= cores_per_package; coreID++) {
504 if (coreID > 1) {
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700505 pcontrol_blk = 0;
506 plen = 0;
507 }
508
Christian Walterbe3979c2019-12-18 15:07:59 +0100509 /* Generate processor \_SB.CPUx */
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100510 acpigen_write_processor(
Lee Leahy26b7cd02017-03-16 18:47:55 -0700511 (cpuID - 1) * cores_per_package+coreID - 1,
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700512 pcontrol_blk, plen);
513
514 /* Generate P-state tables */
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100515 generate_P_state_entries(
Lee Leahy26b7cd02017-03-16 18:47:55 -0700516 coreID - 1, cores_per_package);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700517
518 /* Generate C-state tables */
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100519 generate_C_state_entries();
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700520
521 /* Generate T-state tables */
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100522 generate_T_state_entries(
Lee Leahy26b7cd02017-03-16 18:47:55 -0700523 cpuID - 1, cores_per_package);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700524
Vladimir Serbinenkob219da82014-11-09 03:29:30 +0100525 acpigen_pop_len();
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700526 }
527 }
Arthur Heymansf7d1c8d2018-11-28 12:22:59 +0100528
529 /* PPKG is usually used for thermal management
530 of the first and only package. */
531 acpigen_write_processor_package("PPKG", 0, cores_per_package);
532
533 /* Add a method to notify processor nodes */
534 acpigen_write_processor_cnot(cores_per_package);
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700535}
536
Matt DeVillier0f49bbc2018-02-19 17:35:55 -0600537static unsigned long acpi_fill_dmar(unsigned long current)
538{
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300539 struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD);
Matt DeVillier0f49bbc2018-02-19 17:35:55 -0600540 const u32 gfxvtbar = MCHBAR32(GFXVTBAR) & ~0xfff;
541 const u32 vtvc0bar = MCHBAR32(VTVC0BAR) & ~0xfff;
542 const bool gfxvten = MCHBAR32(GFXVTBAR) & 0x1;
543 const bool vtvc0en = MCHBAR32(VTVC0BAR) & 0x1;
544
545 /* iGFX has to be enabled; GFXVTBAR set, enabled, in 32-bit space */
546 if (igfx_dev && igfx_dev->enabled && gfxvtbar
547 && gfxvten && !MCHBAR32(GFXVTBAR + 4)) {
Matt DeVillier42d16602018-07-04 16:32:21 -0500548 unsigned long tmp = current;
Matt DeVillier0f49bbc2018-02-19 17:35:55 -0600549
550 current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
Matt DeVillier7866d492018-03-29 14:59:57 +0200551 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
Matt DeVillier0f49bbc2018-02-19 17:35:55 -0600552
553 acpi_dmar_drhd_fixup(tmp, current);
Matt DeVillier42d16602018-07-04 16:32:21 -0500554
555 /* Add RMRR entry */
556 tmp = current;
557
558 current += acpi_create_dmar_rmrr(current, 0,
559 sa_get_gsm_base(), sa_get_tolud_base() - 1);
560 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
561 acpi_dmar_rmrr_fixup(tmp, current);
Matt DeVillier0f49bbc2018-02-19 17:35:55 -0600562 }
563
564 /* VTVC0BAR has to be set, enabled, and in 32-bit space */
565 if (vtvc0bar && vtvc0en && !MCHBAR32(VTVC0BAR + 4)) {
566 const unsigned long tmp = current;
567 current += acpi_create_dmar_drhd(current,
568 DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
Matt DeVillier7866d492018-03-29 14:59:57 +0200569 current += acpi_create_dmar_ds_ioapic(current,
Matt DeVillier0f49bbc2018-02-19 17:35:55 -0600570 2, PCH_IOAPIC_PCI_BUS, PCH_IOAPIC_PCI_SLOT, 0);
571 size_t i;
572 for (i = 0; i < 8; ++i)
Matt DeVillier7866d492018-03-29 14:59:57 +0200573 current += acpi_create_dmar_ds_msi_hpet(current,
Matt DeVillier0f49bbc2018-02-19 17:35:55 -0600574 0, PCH_HPET_PCI_BUS,
575 PCH_HPET_PCI_SLOT, i);
576 acpi_dmar_drhd_fixup(tmp, current);
577 }
578
579 return current;
580}
581
582unsigned long northbridge_write_acpi_tables(struct device *const dev,
583 unsigned long current,
584 struct acpi_rsdp *const rsdp)
585{
586 /* Create DMAR table only if we have VT-d capability. */
587 const u32 capid0_a = pci_read_config32(dev, CAPID0_A);
588 if (capid0_a & VTD_DISABLE)
589 return current;
590
591 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
592 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
593 acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar);
594 current += dmar->header.length;
595 current = acpi_align_current(current);
596 acpi_add_table(rsdp, dmar);
597
598 return current;
599}
600
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700601unsigned long acpi_madt_irq_overrides(unsigned long current)
602{
603 int sci = acpi_sci_irq();
604 acpi_madt_irqoverride_t *irqovr;
605 uint16_t flags = MP_IRQ_TRIGGER_LEVEL;
606
607 /* INT_SRC_OVR */
608 irqovr = (void *)current;
609 current += acpi_create_madt_irqoverride(irqovr, 0, 0, 2, 0);
610
611 if (sci >= 20)
612 flags |= MP_IRQ_POLARITY_LOW;
613 else
614 flags |= MP_IRQ_POLARITY_HIGH;
615
616 /* SCI */
617 irqovr = (void *)current;
618 current += acpi_create_madt_irqoverride(irqovr, 0, sci, sci, flags);
619
Duncan Lauriec88c54c2014-04-30 16:36:13 -0700620 return current;
621}