blob: 2406dc5ca52cb3f6edafa249153b42d0c5f47cb8 [file] [log] [blame]
Angel Pons3bd1e3d2020-04-05 15:47:17 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahyb0005132015-05-12 18:19:47 -07002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +03004#include <acpi/acpi_gnvs.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07005#include <acpi/acpigen.h>
robbie zhangb45dde02015-10-01 17:21:33 -07006#include <arch/cpu.h>
Duncan Lauriedb54a672015-09-04 14:19:35 -07007#include <arch/ioapic.h>
Lee Leahyb0005132015-05-12 18:19:47 -07008#include <arch/smp/mpspec.h>
9#include <cbmem.h>
10#include <console/console.h>
11#include <cpu/x86/smm.h>
Lee Leahyb0005132015-05-12 18:19:47 -070012#include <cpu/x86/msr.h>
Matt Delco9084c3c2018-07-27 14:17:29 -070013#include <cpu/intel/common/common.h>
Lee Leahyb0005132015-05-12 18:19:47 -070014#include <cpu/intel/turbo.h>
Barnali Sarkar0a203d12017-05-04 18:02:17 +053015#include <intelblocks/cpulib.h>
Ravi Sarawadi1483d1f2017-09-28 17:06:01 -070016#include <intelblocks/lpc_lib.h>
Pratik Prajapati418535e2017-10-11 16:12:21 -070017#include <intelblocks/sgx.h>
Duncan Laurie93bbd412017-11-11 20:03:29 -080018#include <intelblocks/uart.h>
Nico Huberc37b0e32017-09-18 20:03:46 +020019#include <intelblocks/systemagent.h>
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -070020#include <soc/intel/common/acpi.h>
Lee Leahyb0005132015-05-12 18:19:47 -070021#include <soc/acpi.h>
22#include <soc/cpu.h>
23#include <soc/iomap.h>
Lee Leahyb0005132015-05-12 18:19:47 -070024#include <soc/msr.h>
Kyösti Mälkkid6c57142020-12-21 15:17:01 +020025#include <soc/nvs.h>
Lee Leahyb0005132015-05-12 18:19:47 -070026#include <soc/pci_devs.h>
27#include <soc/pm.h>
Naresh G Solankia2d40622016-08-30 20:47:13 +053028#include <soc/ramstage.h>
Nico Huberc37b0e32017-09-18 20:03:46 +020029#include <soc/systemagent.h>
robbie zhangb45dde02015-10-01 17:21:33 -070030#include <string.h>
31#include <types.h>
Duncan Laurie3d3b76b2016-02-25 08:45:43 -080032#include <wrdd.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +020033#include <device/pci_ops.h>
Lee Leahyb0005132015-05-12 18:19:47 -070034
Elyes HAOUASc3385072019-03-21 15:38:06 +010035#include "chip.h"
36
Michael Niewöhnerd5a45472020-10-15 00:27:59 +020037#define CPUID_6_EAX_ISST (1 << 7)
38
Lee Leahyb0005132015-05-12 18:19:47 -070039/*
Lee Leahy1d14b3e2015-05-12 18:23:27 -070040 * List of suported C-states in this processor.
Lee Leahyb0005132015-05-12 18:19:47 -070041 */
42enum {
Lee Leahy1d14b3e2015-05-12 18:23:27 -070043 C_STATE_C0, /* 0 */
44 C_STATE_C1, /* 1 */
45 C_STATE_C1E, /* 2 */
46 C_STATE_C3, /* 3 */
47 C_STATE_C6_SHORT_LAT, /* 4 */
48 C_STATE_C6_LONG_LAT, /* 5 */
49 C_STATE_C7_SHORT_LAT, /* 6 */
50 C_STATE_C7_LONG_LAT, /* 7 */
51 C_STATE_C7S_SHORT_LAT, /* 8 */
52 C_STATE_C7S_LONG_LAT, /* 9 */
53 C_STATE_C8, /* 10 */
54 C_STATE_C9, /* 11 */
55 C_STATE_C10, /* 12 */
Lee Leahyb0005132015-05-12 18:19:47 -070056 NUM_C_STATES
57};
Lee Leahy1d14b3e2015-05-12 18:23:27 -070058#define MWAIT_RES(state, sub_state) \
59 { \
60 .addrl = (((state) << 4) | (sub_state)), \
61 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
62 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \
63 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \
64 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \
Lee Leahyb0005132015-05-12 18:19:47 -070065 }
66
67static acpi_cstate_t cstate_map[NUM_C_STATES] = {
68 [C_STATE_C0] = { },
69 [C_STATE_C1] = {
70 .latency = 0,
robbie zhangc16b1fd2015-09-11 14:25:15 -070071 .power = C1_POWER,
Lee Leahy1d14b3e2015-05-12 18:23:27 -070072 .resource = MWAIT_RES(0, 0),
Lee Leahyb0005132015-05-12 18:19:47 -070073 },
74 [C_STATE_C1E] = {
75 .latency = 0,
robbie zhangc16b1fd2015-09-11 14:25:15 -070076 .power = C1_POWER,
Lee Leahy1d14b3e2015-05-12 18:23:27 -070077 .resource = MWAIT_RES(0, 1),
Lee Leahyb0005132015-05-12 18:19:47 -070078 },
79 [C_STATE_C3] = {
80 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
robbie zhangc16b1fd2015-09-11 14:25:15 -070081 .power = C3_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -070082 .resource = MWAIT_RES(1, 0),
83 },
84 [C_STATE_C6_SHORT_LAT] = {
85 .latency = C_STATE_LATENCY_FROM_LAT_REG(1),
robbie zhangc16b1fd2015-09-11 14:25:15 -070086 .power = C6_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -070087 .resource = MWAIT_RES(2, 0),
88 },
89 [C_STATE_C6_LONG_LAT] = {
90 .latency = C_STATE_LATENCY_FROM_LAT_REG(2),
robbie zhangc16b1fd2015-09-11 14:25:15 -070091 .power = C6_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -070092 .resource = MWAIT_RES(2, 1),
93 },
94 [C_STATE_C7_SHORT_LAT] = {
95 .latency = C_STATE_LATENCY_FROM_LAT_REG(1),
robbie zhangc16b1fd2015-09-11 14:25:15 -070096 .power = C7_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -070097 .resource = MWAIT_RES(3, 0),
98 },
99 [C_STATE_C7_LONG_LAT] = {
100 .latency = C_STATE_LATENCY_FROM_LAT_REG(2),
robbie zhangc16b1fd2015-09-11 14:25:15 -0700101 .power = C7_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -0700102 .resource = MWAIT_RES(3, 1),
103 },
104 [C_STATE_C7S_SHORT_LAT] = {
105 .latency = C_STATE_LATENCY_FROM_LAT_REG(1),
robbie zhangc16b1fd2015-09-11 14:25:15 -0700106 .power = C7_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -0700107 .resource = MWAIT_RES(3, 2),
108 },
109 [C_STATE_C7S_LONG_LAT] = {
110 .latency = C_STATE_LATENCY_FROM_LAT_REG(2),
robbie zhangc16b1fd2015-09-11 14:25:15 -0700111 .power = C7_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -0700112 .resource = MWAIT_RES(3, 3),
113 },
114 [C_STATE_C8] = {
115 .latency = C_STATE_LATENCY_FROM_LAT_REG(3),
robbie zhangc16b1fd2015-09-11 14:25:15 -0700116 .power = C8_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -0700117 .resource = MWAIT_RES(4, 0),
118 },
119 [C_STATE_C9] = {
120 .latency = C_STATE_LATENCY_FROM_LAT_REG(4),
robbie zhangc16b1fd2015-09-11 14:25:15 -0700121 .power = C9_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -0700122 .resource = MWAIT_RES(5, 0),
123 },
124 [C_STATE_C10] = {
125 .latency = C_STATE_LATENCY_FROM_LAT_REG(5),
robbie zhangc16b1fd2015-09-11 14:25:15 -0700126 .power = C10_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -0700127 .resource = MWAIT_RES(6, 0),
128 },
129};
130
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700131static int cstate_set_s0ix[] = {
Lee Leahyb0005132015-05-12 18:19:47 -0700132 C_STATE_C1E,
133 C_STATE_C7S_LONG_LAT,
134 C_STATE_C10
135};
136
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700137static int cstate_set_non_s0ix[] = {
Lee Leahyb0005132015-05-12 18:19:47 -0700138 C_STATE_C1E,
139 C_STATE_C3,
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700140 C_STATE_C7S_LONG_LAT,
Lee Leahyb0005132015-05-12 18:19:47 -0700141};
142
143static int get_cores_per_package(void)
144{
145 struct cpuinfo_x86 c;
146 struct cpuid_result result;
147 int cores = 1;
148
149 get_fms(&c, cpuid_eax(1));
150 if (c.x86 != 6)
151 return 1;
152
153 result = cpuid_ext(0xb, 1);
154 cores = result.ebx & 0xff;
155
156 return cores;
157}
158
Kyösti Mälkkic2b0a4f2020-06-28 22:39:59 +0300159void soc_fill_gnvs(struct global_nvs *gnvs)
Lee Leahyb0005132015-05-12 18:19:47 -0700160{
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300161 const struct soc_intel_skylake_config *config = config_of_soc();
Duncan Laurie7fce30c2015-09-04 13:53:14 -0700162
Lee Leahyb0005132015-05-12 18:19:47 -0700163 /* Set unknown wake source */
164 gnvs->pm1i = -1;
165
166 /* CPU core count */
167 gnvs->pcnt = dev_count_cpu();
168
Duncan Laurie7fce30c2015-09-04 13:53:14 -0700169 /* Enable DPTF based on mainboard configuration */
170 gnvs->dpte = config->dptf_enable;
Duncan Laurie3d3b76b2016-02-25 08:45:43 -0800171
172 /* Fill in the Wifi Region id */
173 gnvs->cid1 = wifi_regulatory_domain();
Furquan Shaikh3bfe3402016-10-18 14:25:25 -0700174
175 /* Set USB2/USB3 wake enable bitmaps. */
176 gnvs->u2we = config->usb2_wake_enable_bitmap;
177 gnvs->u3we = config->usb3_wake_enable_bitmap;
Pratik Prajapati418535e2017-10-11 16:12:21 -0700178
Michael Niewöhner7736bfc2019-10-22 23:05:06 +0200179 if (CONFIG(SOC_INTEL_COMMON_BLOCK_SGX_ENABLE))
Pratik Prajapati418535e2017-10-11 16:12:21 -0700180 sgx_fill_gnvs(gnvs);
Subrata Banikb6df6b02020-01-03 15:29:02 +0530181
182 /* Fill in Above 4GB MMIO resource */
183 sa_fill_gnvs(gnvs);
Lee Leahyb0005132015-05-12 18:19:47 -0700184}
185
Lee Leahyb0005132015-05-12 18:19:47 -0700186unsigned long acpi_fill_mcfg(unsigned long current)
187{
188 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current,
Duncan Laurie50f06a12018-03-02 14:56:38 -0800189 CONFIG_MMCONF_BASE_ADDRESS, 0, 0,
Duncan Lauriefd50b7c2018-03-02 14:47:11 -0800190 (CONFIG_SA_PCIEX_LENGTH >> 20) - 1);
Lee Leahyb0005132015-05-12 18:19:47 -0700191 return current;
192}
193
Duncan Lauriedb54a672015-09-04 14:19:35 -0700194unsigned long acpi_fill_madt(unsigned long current)
195{
196 /* Local APICs */
197 current = acpi_create_madt_lapics(current);
198
199 /* IOAPIC */
200 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
201 2, IO_APIC_ADDR, 0);
202
203 return acpi_madt_irq_overrides(current);
204}
205
Jacob Garber9172b692019-06-26 16:18:16 -0600206static void write_c_state_entries(acpi_cstate_t *map, const int *set, size_t max_c_state)
Lee Leahyb0005132015-05-12 18:19:47 -0700207{
Jacob Garber9172b692019-06-26 16:18:16 -0600208 for (size_t i = 0; i < max_c_state; i++) {
Lee Leahyb0005132015-05-12 18:19:47 -0700209 memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t));
210 map[i].ctype = i + 1;
211 }
212
213 /* Generate C-state tables */
Jacob Garber9172b692019-06-26 16:18:16 -0600214 acpigen_write_CST_package(map, max_c_state);
215}
216
217static void generate_c_state_entries(int s0ix_enable)
218{
219 if (s0ix_enable) {
220 acpi_cstate_t map[ARRAY_SIZE(cstate_set_s0ix)];
221 write_c_state_entries(map, cstate_set_s0ix, ARRAY_SIZE(map));
222 } else {
223 acpi_cstate_t map[ARRAY_SIZE(cstate_set_non_s0ix)];
224 write_c_state_entries(map, cstate_set_non_s0ix, ARRAY_SIZE(map));
225 }
Lee Leahyb0005132015-05-12 18:19:47 -0700226}
227
228static int calculate_power(int tdp, int p1_ratio, int ratio)
229{
230 u32 m;
231 u32 power;
232
233 /*
234 * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2
235 *
236 * Power = (ratio / p1_ratio) * m * tdp
237 */
238
239 m = (110000 - ((p1_ratio - ratio) * 625)) / 11;
240 m = (m * m) / 1000;
241
242 power = ((ratio * 100000 / p1_ratio) / 100);
243 power *= (m / 100) * (tdp / 1000);
244 power /= 1000;
245
246 return (int)power;
247}
248
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700249static void generate_p_state_entries(int core, int cores_per_package)
Lee Leahyb0005132015-05-12 18:19:47 -0700250{
251 int ratio_min, ratio_max, ratio_turbo, ratio_step;
252 int coord_type, power_max, power_unit, num_entries;
253 int ratio, power, clock, clock_max;
254 msr_t msr;
255
256 /* Determine P-state coordination type from MISC_PWR_MGMT[0] */
257 msr = rdmsr(MSR_MISC_PWR_MGMT);
258 if (msr.lo & MISC_PWR_MGMT_EIST_HW_DIS)
259 coord_type = SW_ANY;
260 else
261 coord_type = HW_ALL;
262
263 /* Get bus ratio limits and calculate clock speeds */
264 msr = rdmsr(MSR_PLATFORM_INFO);
265 ratio_min = (msr.hi >> (40-32)) & 0xff; /* Max Efficiency Ratio */
266
267 /* Determine if this CPU has configurable TDP */
268 if (cpu_config_tdp_levels()) {
269 /* Set max ratio to nominal TDP ratio */
270 msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
271 ratio_max = msr.lo & 0xff;
272 } else {
273 /* Max Non-Turbo Ratio */
274 ratio_max = (msr.lo >> 8) & 0xff;
275 }
Aamir Bohra1041d392017-06-02 11:56:14 +0530276 clock_max = ratio_max * CONFIG_CPU_BCLK_MHZ;
Lee Leahyb0005132015-05-12 18:19:47 -0700277
278 /* Calculate CPU TDP in mW */
279 msr = rdmsr(MSR_PKG_POWER_SKU_UNIT);
280 power_unit = 2 << ((msr.lo & 0xf) - 1);
281 msr = rdmsr(MSR_PKG_POWER_SKU);
282 power_max = ((msr.lo & 0x7fff) / power_unit) * 1000;
283
284 /* Write _PCT indicating use of FFixedHW */
285 acpigen_write_empty_PCT();
286
287 /* Write _PPC with no limit on supported P-state */
288 acpigen_write_PPC_NVS();
289
290 /* Write PSD indicating configured coordination type */
291 acpigen_write_PSD_package(core, 1, coord_type);
292
293 /* Add P-state entries in _PSS table */
294 acpigen_write_name("_PSS");
295
296 /* Determine ratio points */
297 ratio_step = PSS_RATIO_STEP;
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700298 num_entries = ((ratio_max - ratio_min) / ratio_step) + 1;
299 if (num_entries > PSS_MAX_ENTRIES) {
300 ratio_step += 1;
301 num_entries = ((ratio_max - ratio_min) / ratio_step) + 1;
Lee Leahyb0005132015-05-12 18:19:47 -0700302 }
303
304 /* P[T] is Turbo state if enabled */
305 if (get_turbo_state() == TURBO_ENABLED) {
306 /* _PSS package count including Turbo */
307 acpigen_write_package(num_entries + 2);
308
309 msr = rdmsr(MSR_TURBO_RATIO_LIMIT);
310 ratio_turbo = msr.lo & 0xff;
311
312 /* Add entry for Turbo ratio */
313 acpigen_write_PSS_package(
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700314 clock_max + 1, /* MHz */
315 power_max, /* mW */
316 PSS_LATENCY_TRANSITION, /* lat1 */
317 PSS_LATENCY_BUSMASTER, /* lat2 */
318 ratio_turbo << 8, /* control */
319 ratio_turbo << 8); /* status */
Lee Leahyb0005132015-05-12 18:19:47 -0700320 } else {
321 /* _PSS package count without Turbo */
322 acpigen_write_package(num_entries + 1);
323 }
324
325 /* First regular entry is max non-turbo ratio */
326 acpigen_write_PSS_package(
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700327 clock_max, /* MHz */
328 power_max, /* mW */
329 PSS_LATENCY_TRANSITION, /* lat1 */
330 PSS_LATENCY_BUSMASTER, /* lat2 */
331 ratio_max << 8, /* control */
332 ratio_max << 8); /* status */
Lee Leahyb0005132015-05-12 18:19:47 -0700333
334 /* Generate the remaining entries */
335 for (ratio = ratio_min + ((num_entries - 1) * ratio_step);
336 ratio >= ratio_min; ratio -= ratio_step) {
337
338 /* Calculate power at this ratio */
339 power = calculate_power(power_max, ratio_max, ratio);
Aamir Bohra1041d392017-06-02 11:56:14 +0530340 clock = ratio * CONFIG_CPU_BCLK_MHZ;
Lee Leahyb0005132015-05-12 18:19:47 -0700341
342 acpigen_write_PSS_package(
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700343 clock, /* MHz */
344 power, /* mW */
345 PSS_LATENCY_TRANSITION, /* lat1 */
346 PSS_LATENCY_BUSMASTER, /* lat2 */
347 ratio << 8, /* control */
348 ratio << 8); /* status */
Lee Leahyb0005132015-05-12 18:19:47 -0700349 }
350
351 /* Fix package length */
352 acpigen_pop_len();
353}
354
Michael Niewöhnerb20aac02020-10-14 19:30:46 +0200355static void generate_cppc_entries(int core_id)
356{
357 /* Generate GCPC table in first logical core */
358 if (core_id == 0) {
359 struct cppc_config cppc_config;
360 cpu_init_cppc_config(&cppc_config, CPPC_VERSION_2);
361 acpigen_write_CPPC_package(&cppc_config);
362 }
363
364 /* Write _CST entry for each logical core */
365 acpigen_write_CPPC_method();
366}
367
Furquan Shaikh7536a392020-04-24 21:59:21 -0700368void generate_cpu_entries(const struct device *device)
Lee Leahyb0005132015-05-12 18:19:47 -0700369{
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700370 int core_id, cpu_id, pcontrol_blk = ACPI_BASE_ADDRESS, plen = 6;
Lee Leahyb0005132015-05-12 18:19:47 -0700371 int totalcores = dev_count_cpu();
372 int cores_per_package = get_cores_per_package();
373 int numcpus = totalcores/cores_per_package;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300374 config_t *config = config_of_soc();
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700375 int is_s0ix_enable = config->s0ix_enable;
Michael Niewöhnerb20aac02020-10-14 19:30:46 +0200376 const bool isst_supported = cpuid_eax(6) & CPUID_6_EAX_ISST;
Lee Leahyb0005132015-05-12 18:19:47 -0700377
378 printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n",
379 numcpus, cores_per_package);
380
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700381 for (cpu_id = 0; cpu_id < numcpus; cpu_id++) {
382 for (core_id = 0; core_id < cores_per_package; core_id++) {
383 if (core_id > 0) {
Lee Leahyb0005132015-05-12 18:19:47 -0700384 pcontrol_blk = 0;
385 plen = 0;
386 }
387
Christian Walterbe3979c2019-12-18 15:07:59 +0100388 /* Generate processor \_SB.CPUx */
Lee Leahyb0005132015-05-12 18:19:47 -0700389 acpigen_write_processor(
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700390 cpu_id*cores_per_package+core_id,
Lee Leahyb0005132015-05-12 18:19:47 -0700391 pcontrol_blk, plen);
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700392 /* Generate C-state tables */
Jacob Garber9172b692019-06-26 16:18:16 -0600393 generate_c_state_entries(is_s0ix_enable);
Lee Leahyb0005132015-05-12 18:19:47 -0700394
Matt Delco9084c3c2018-07-27 14:17:29 -0700395 if (config->eist_enable) {
Subrata Banik6b45ee42017-05-12 11:43:57 +0530396 /* Generate P-state tables */
397 generate_p_state_entries(core_id,
398 cores_per_package);
Matt Delco9084c3c2018-07-27 14:17:29 -0700399 }
Michael Niewöhner30c5d212020-08-03 15:01:18 +0200400
Michael Niewöhnerb20aac02020-10-14 19:30:46 +0200401 if (isst_supported)
402 generate_cppc_entries(core_id);
Michael Niewöhner30c5d212020-08-03 15:01:18 +0200403
Lee Leahyb0005132015-05-12 18:19:47 -0700404 acpigen_pop_len();
405 }
406 }
Arthur Heymans8afc1352018-11-28 12:07:19 +0100407
408 /* PPKG is usually used for thermal management
409 of the first and only package. */
410 acpigen_write_processor_package("PPKG", 0, cores_per_package);
411
412 /* Add a method to notify processor nodes */
413 acpigen_write_processor_cnot(cores_per_package);
Lee Leahyb0005132015-05-12 18:19:47 -0700414}
415
Nico Huberc37b0e32017-09-18 20:03:46 +0200416static unsigned long acpi_fill_dmar(unsigned long current)
417{
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300418 struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD);
Nico Huberc37b0e32017-09-18 20:03:46 +0200419 const u32 gfx_vtbar = MCHBAR32(GFXVTBAR) & ~0xfff;
420 const bool gfxvten = MCHBAR32(GFXVTBAR) & 1;
421
422 /* iGFX has to be enabled, GFXVTBAR set and in 32-bit space. */
Angel Pons96a80132020-08-03 12:29:41 +0200423 const bool emit_igd =
424 igfx_dev && igfx_dev->enabled &&
425 gfx_vtbar && gfxvten &&
426 !MCHBAR32(GFXVTBAR + 4);
427
428 /* First, add DRHD entries */
429 if (emit_igd) {
430 const unsigned long tmp = current;
Nico Huberc37b0e32017-09-18 20:03:46 +0200431
432 current += acpi_create_dmar_drhd(current, 0, 0, gfx_vtbar);
Matt DeVillier7866d492018-03-29 14:59:57 +0200433 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
Nico Huberc37b0e32017-09-18 20:03:46 +0200434
435 acpi_dmar_drhd_fixup(tmp, current);
436 }
437
Nico Huberc37b0e32017-09-18 20:03:46 +0200438 const u32 vtvc0bar = MCHBAR32(VTVC0BAR) & ~0xfff;
439 const bool vtvc0en = MCHBAR32(VTVC0BAR) & 1;
440
441 /* General VTBAR has to be set and in 32-bit space. */
Angel Ponsef879a82019-08-30 19:42:23 +0200442 if (vtvc0bar && vtvc0en && !MCHBAR32(VTVC0BAR + 4)) {
Nico Huberc37b0e32017-09-18 20:03:46 +0200443 const unsigned long tmp = current;
444
Angel Ponsef879a82019-08-30 19:42:23 +0200445 current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
Nico Huberc37b0e32017-09-18 20:03:46 +0200446
Angel Ponsef879a82019-08-30 19:42:23 +0200447 current += acpi_create_dmar_ds_ioapic(current, 2, V_P2SB_IBDF_BUS,
448 V_P2SB_IBDF_DEV, V_P2SB_IBDF_FUN);
Nico Huberc37b0e32017-09-18 20:03:46 +0200449
Angel Ponsef879a82019-08-30 19:42:23 +0200450 current += acpi_create_dmar_ds_msi_hpet(current, 0, V_P2SB_HBDF_BUS,
451 V_P2SB_HBDF_DEV, V_P2SB_HBDF_FUN);
Nico Huberc37b0e32017-09-18 20:03:46 +0200452
453 acpi_dmar_drhd_fixup(tmp, current);
454 }
455
Angel Pons96a80132020-08-03 12:29:41 +0200456 /* Then, add RMRR entries after all DRHD entries */
457 if (emit_igd) {
458 const unsigned long tmp = current;
459
460 current += acpi_create_dmar_rmrr(current, 0,
461 sa_get_gsm_base(), sa_get_tolud_base() - 1);
462 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
463 acpi_dmar_rmrr_fixup(tmp, current);
464 }
465
Nico Huberc37b0e32017-09-18 20:03:46 +0200466 return current;
467}
468
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700469unsigned long northbridge_write_acpi_tables(const struct device *const dev,
Nico Huberc37b0e32017-09-18 20:03:46 +0200470 unsigned long current,
471 struct acpi_rsdp *const rsdp)
472{
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300473 const struct soc_intel_skylake_config *const config = config_of(dev);
Nico Huberc37b0e32017-09-18 20:03:46 +0200474 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
475
476 /* Create DMAR table only if we have VT-d capability. */
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300477 if (config->ignore_vtd || !soc_is_vtd_capable())
Nico Huberc37b0e32017-09-18 20:03:46 +0200478 return current;
479
480 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
481 acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar);
482 current += dmar->header.length;
483 current = acpi_align_current(current);
484 acpi_add_table(rsdp, dmar);
485
486 return current;
487}
488
Lee Leahyb0005132015-05-12 18:19:47 -0700489unsigned long acpi_madt_irq_overrides(unsigned long current)
490{
491 int sci = acpi_sci_irq();
492 acpi_madt_irqoverride_t *irqovr;
493 uint16_t flags = MP_IRQ_TRIGGER_LEVEL;
494
495 /* INT_SRC_OVR */
496 irqovr = (void *)current;
497 current += acpi_create_madt_irqoverride(irqovr, 0, 0, 2, 0);
498
499 if (sci >= 20)
500 flags |= MP_IRQ_POLARITY_LOW;
501 else
502 flags |= MP_IRQ_POLARITY_HIGH;
503
504 /* SCI */
505 irqovr = (void *)current;
506 current += acpi_create_madt_irqoverride(irqovr, 0, sci, sci, flags);
507
Michael Niewöhner14512f92020-11-23 15:53:28 +0100508 /* NMI */
509 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 0xff, 5, 1);
510
Lee Leahyb0005132015-05-12 18:19:47 -0700511 return current;
512}
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700513
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700514unsigned long southbridge_write_acpi_tables(const struct device *device,
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700515 unsigned long current,
516 struct acpi_rsdp *rsdp)
517{
Duncan Laurie93bbd412017-11-11 20:03:29 -0800518 current = acpi_write_dbg2_pci_uart(rsdp, current,
Subrata Banikafa07f72018-05-24 12:21:06 +0530519 uart_get_device(),
Duncan Laurie93bbd412017-11-11 20:03:29 -0800520 ACPI_ACCESS_SIZE_DWORD_ACCESS);
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700521 current = acpi_write_hpet(device, current, rsdp);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600522 return acpi_align_current(current);
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700523}
524
Furquan Shaikh338fd9a2020-04-24 22:57:05 -0700525void southbridge_inject_dsdt(const struct device *device)
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700526{
Kyösti Mälkki9f441df2020-06-28 12:29:13 +0300527 struct global_nvs *gnvs = acpi_get_gnvs();
528 if (!gnvs)
529 return;
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700530
Kyösti Mälkkic2b0a4f2020-06-28 22:39:59 +0300531 soc_fill_gnvs(gnvs);
Kyösti Mälkki9f441df2020-06-28 12:29:13 +0300532 acpi_inject_nvsa();
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700533}
534
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700535/* Save wake source information for calculating ACPI _SWS values */
536int soc_fill_acpi_wake(uint32_t *pm1, uint32_t **gpe0)
537{
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300538 const struct soc_intel_skylake_config *config = config_of_soc();
Naresh G Solankia1b35472015-12-11 18:13:02 +0530539 struct chipset_power_state *ps;
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700540 static uint32_t gpe0_sts[GPE0_REG_MAX];
541 uint32_t pm1_en;
Duncan Laurie95f90202016-10-25 20:07:22 -0700542 uint32_t gpe0_std;
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700543 int i;
Aaron Durbin64606ce2016-10-27 09:53:17 -0500544 const int last_index = GPE0_REG_MAX - 1;
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700545
Naresh G Solankia1b35472015-12-11 18:13:02 +0530546 ps = cbmem_find(CBMEM_ID_POWER_STATE);
547 if (ps == NULL)
548 return -1;
549
Duncan Laurie95f90202016-10-25 20:07:22 -0700550 pm1_en = ps->pm1_en;
551 gpe0_std = ps->gpe0_en[3];
552
553 /*
554 * Chipset state in the suspend well (but not RTC) is lost in Deep S3
555 * so enable Deep S3 wake events that are configured by the mainboard
556 */
Duncan Laurie1fe32d62017-04-10 21:02:13 -0700557 if (ps->prev_sleep_state == ACPI_S3 &&
558 (config->deep_s3_enable_ac || config->deep_s3_enable_dc)) {
Duncan Laurie95f90202016-10-25 20:07:22 -0700559 pm1_en |= PWRBTN_STS; /* Always enabled as wake source */
560 if (config->deep_sx_config & DSX_EN_LAN_WAKE_PIN)
561 gpe0_std |= LAN_WAK_EN;
562 if (config->deep_sx_config & DSX_EN_WAKE_PIN)
563 pm1_en |= PCIEXPWAK_STS;
564 }
565
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700566 *pm1 = ps->pm1_sts & pm1_en;
567
568 /* Mask off GPE0 status bits that are not enabled */
569 *gpe0 = &gpe0_sts[0];
Aaron Durbin64606ce2016-10-27 09:53:17 -0500570 for (i = 0; i < last_index; i++)
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700571 gpe0_sts[i] = ps->gpe0_sts[i] & ps->gpe0_en[i];
Aaron Durbin64606ce2016-10-27 09:53:17 -0500572 gpe0_sts[last_index] = ps->gpe0_sts[last_index] & gpe0_std;
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700573
574 return GPE0_REG_MAX;
575}
576
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600577const char *soc_acpi_name(const struct device *dev)
Naresh G Solankia2d40622016-08-30 20:47:13 +0530578{
579 if (dev->path.type == DEVICE_PATH_DOMAIN)
580 return "PCI0";
581
Duncan Lauriebf713b02018-05-07 15:33:18 -0700582 if (dev->path.type == DEVICE_PATH_USB) {
583 switch (dev->path.usb.port_type) {
584 case 0:
585 /* Root Hub */
586 return "RHUB";
587 case 2:
588 /* USB2 ports */
589 switch (dev->path.usb.port_id) {
590 case 0: return "HS01";
591 case 1: return "HS02";
592 case 2: return "HS03";
593 case 3: return "HS04";
594 case 4: return "HS05";
595 case 5: return "HS06";
596 case 6: return "HS07";
597 case 7: return "HS08";
598 case 8: return "HS09";
599 case 9: return "HS10";
600 }
601 break;
602 case 3:
603 /* USB3 ports */
604 switch (dev->path.usb.port_id) {
605 case 0: return "SS01";
606 case 1: return "SS02";
607 case 2: return "SS03";
608 case 3: return "SS04";
609 case 4: return "SS05";
610 case 5: return "SS06";
611 }
612 break;
613 }
614 return NULL;
615 }
616
Naresh G Solankia2d40622016-08-30 20:47:13 +0530617 if (dev->path.type != DEVICE_PATH_PCI)
618 return NULL;
619
Benjamin Doron2875df12020-08-06 19:13:09 +0000620 /* Match functions 0 and 1 for possible GPUs on a secondary bus */
621 if (dev->bus && dev->bus->secondary > 0) {
622 switch (PCI_FUNC(dev->path.pci.devfn)) {
623 case 0: return "DEV0";
624 case 1: return "DEV1";
625 }
Patrick Rudolph45ffee82019-09-26 14:45:29 +0200626 return NULL;
Benjamin Doron2875df12020-08-06 19:13:09 +0000627 }
Patrick Rudolph45ffee82019-09-26 14:45:29 +0200628
Naresh G Solankia2d40622016-08-30 20:47:13 +0530629 switch (dev->path.pci.devfn) {
630 case SA_DEVFN_ROOT: return "MCHC";
Benjamin Doron2875df12020-08-06 19:13:09 +0000631 case SA_DEVFN_PEG0: return "PEGP";
Naresh G Solankia2d40622016-08-30 20:47:13 +0530632 case SA_DEVFN_IGD: return "GFX0";
633 case PCH_DEVFN_ISH: return "ISHB";
634 case PCH_DEVFN_XHCI: return "XHCI";
635 case PCH_DEVFN_USBOTG: return "XDCI";
636 case PCH_DEVFN_THERMAL: return "THRM";
637 case PCH_DEVFN_CIO: return "ICIO";
638 case PCH_DEVFN_I2C0: return "I2C0";
639 case PCH_DEVFN_I2C1: return "I2C1";
640 case PCH_DEVFN_I2C2: return "I2C2";
641 case PCH_DEVFN_I2C3: return "I2C3";
Subrata Banik2ee54db2017-03-05 12:37:00 +0530642 case PCH_DEVFN_CSE: return "CSE1";
643 case PCH_DEVFN_CSE_2: return "CSE2";
644 case PCH_DEVFN_CSE_IDER: return "CSED";
645 case PCH_DEVFN_CSE_KT: return "CSKT";
646 case PCH_DEVFN_CSE_3: return "CSE3";
Naresh G Solankia2d40622016-08-30 20:47:13 +0530647 case PCH_DEVFN_SATA: return "SATA";
648 case PCH_DEVFN_UART2: return "UAR2";
649 case PCH_DEVFN_I2C4: return "I2C4";
650 case PCH_DEVFN_I2C5: return "I2C5";
651 case PCH_DEVFN_PCIE1: return "RP01";
652 case PCH_DEVFN_PCIE2: return "RP02";
653 case PCH_DEVFN_PCIE3: return "RP03";
654 case PCH_DEVFN_PCIE4: return "RP04";
655 case PCH_DEVFN_PCIE5: return "RP05";
656 case PCH_DEVFN_PCIE6: return "RP06";
657 case PCH_DEVFN_PCIE7: return "RP07";
658 case PCH_DEVFN_PCIE8: return "RP08";
659 case PCH_DEVFN_PCIE9: return "RP09";
660 case PCH_DEVFN_PCIE10: return "RP10";
661 case PCH_DEVFN_PCIE11: return "RP11";
662 case PCH_DEVFN_PCIE12: return "RP12";
Maxim Polyakovc6f2b612019-08-23 15:22:21 +0300663 case PCH_DEVFN_PCIE13: return "RP13";
664 case PCH_DEVFN_PCIE14: return "RP14";
665 case PCH_DEVFN_PCIE15: return "RP15";
666 case PCH_DEVFN_PCIE16: return "RP16";
Naresh G Solankia2d40622016-08-30 20:47:13 +0530667 case PCH_DEVFN_UART0: return "UAR0";
668 case PCH_DEVFN_UART1: return "UAR1";
669 case PCH_DEVFN_GSPI0: return "SPI0";
670 case PCH_DEVFN_GSPI1: return "SPI1";
671 case PCH_DEVFN_EMMC: return "EMMC";
672 case PCH_DEVFN_SDIO: return "SDIO";
673 case PCH_DEVFN_SDCARD: return "SDXC";
Naresh G Solankia2d40622016-08-30 20:47:13 +0530674 case PCH_DEVFN_P2SB: return "P2SB";
675 case PCH_DEVFN_PMC: return "PMC_";
676 case PCH_DEVFN_HDA: return "HDAS";
677 case PCH_DEVFN_SMBUS: return "SBUS";
678 case PCH_DEVFN_SPI: return "FSPI";
679 case PCH_DEVFN_GBE: return "IGBE";
680 case PCH_DEVFN_TRACEHUB:return "THUB";
681 }
682
683 return NULL;
684}
Furquan Shaikha6f0b272017-05-23 11:53:47 -0700685
686static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num)
687{
688 /* op (gpio_num) */
689 acpigen_emit_namestring(op);
690 acpigen_write_integer(gpio_num);
691 return 0;
692}
693
694static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num)
695{
696 /* Store (op (gpio_num), Local0) */
697 acpigen_write_store();
698 acpigen_soc_gpio_op(op, gpio_num);
699 acpigen_emit_byte(LOCAL0_OP);
700 return 0;
701}
702
703int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
704{
705 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GRXS", gpio_num);
706}
707
708int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
709{
710 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GTXS", gpio_num);
711}
712
713int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
714{
715 return acpigen_soc_gpio_op("\\_SB.PCI0.STXS", gpio_num);
716}
717
718int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
719{
720 return acpigen_soc_gpio_op("\\_SB.PCI0.CTXS", gpio_num);
721}