blob: 20b60e9a0d475df58fa169fdd03571ab8c0e41d6 [file] [log] [blame]
Angel Pons3bd1e3d2020-04-05 15:47:17 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Lee Leahyb0005132015-05-12 18:19:47 -07003
Furquan Shaikh76cedd22020-05-02 10:24:23 -07004#include <acpi/acpi.h>
5#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>
13#include <cpu/x86/tsc.h>
Matt Delco9084c3c2018-07-27 14:17:29 -070014#include <cpu/intel/common/common.h>
Lee Leahyb0005132015-05-12 18:19:47 -070015#include <cpu/intel/turbo.h>
16#include <ec/google/chromeec/ec.h>
Barnali Sarkar0a203d12017-05-04 18:02:17 +053017#include <intelblocks/cpulib.h>
Ravi Sarawadi1483d1f2017-09-28 17:06:01 -070018#include <intelblocks/lpc_lib.h>
Pratik Prajapati418535e2017-10-11 16:12:21 -070019#include <intelblocks/sgx.h>
Duncan Laurie93bbd412017-11-11 20:03:29 -080020#include <intelblocks/uart.h>
Nico Huberc37b0e32017-09-18 20:03:46 +020021#include <intelblocks/systemagent.h>
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -070022#include <soc/intel/common/acpi.h>
Lee Leahyb0005132015-05-12 18:19:47 -070023#include <soc/acpi.h>
24#include <soc/cpu.h>
25#include <soc/iomap.h>
Lee Leahyb0005132015-05-12 18:19:47 -070026#include <soc/msr.h>
27#include <soc/pci_devs.h>
28#include <soc/pm.h>
Naresh G Solankia2d40622016-08-30 20:47:13 +053029#include <soc/ramstage.h>
Nico Huberc37b0e32017-09-18 20:03:46 +020030#include <soc/systemagent.h>
robbie zhangb45dde02015-10-01 17:21:33 -070031#include <string.h>
32#include <types.h>
33#include <vendorcode/google/chromeos/gnvs.h>
Duncan Laurie3d3b76b2016-02-25 08:45:43 -080034#include <wrdd.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +020035#include <device/pci_ops.h>
Lee Leahyb0005132015-05-12 18:19:47 -070036
Elyes HAOUASc3385072019-03-21 15:38:06 +010037#include "chip.h"
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
Duncan Lauriedb54a672015-09-04 14:19:35 -0700159static void acpi_create_gnvs(global_nvs_t *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
Julius Wernercd49cce2019-03-05 16:53:33 -0800169#if CONFIG(CONSOLE_CBMEM)
Lee Leahyb0005132015-05-12 18:19:47 -0700170 /* Update the mem console pointer. */
171 gnvs->cbmc = (u32)cbmem_find(CBMEM_ID_CONSOLE);
172#endif
173
Julius Wernercd49cce2019-03-05 16:53:33 -0800174#if CONFIG(CHROMEOS)
Lee Leahyb0005132015-05-12 18:19:47 -0700175 /* Initialize Verified Boot data */
Joel Kitching6fbd8742018-08-23 14:56:25 +0800176 chromeos_init_chromeos_acpi(&(gnvs->chromeos));
Julius Wernercd49cce2019-03-05 16:53:33 -0800177#if CONFIG(EC_GOOGLE_CHROMEEC)
Lee Leahyb0005132015-05-12 18:19:47 -0700178 gnvs->chromeos.vbt2 = google_ec_running_ro() ?
179 ACTIVE_ECFW_RO : ACTIVE_ECFW_RW;
180#endif
181 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
182#endif
Duncan Laurie7fce30c2015-09-04 13:53:14 -0700183
184 /* Enable DPTF based on mainboard configuration */
185 gnvs->dpte = config->dptf_enable;
Duncan Laurie3d3b76b2016-02-25 08:45:43 -0800186
187 /* Fill in the Wifi Region id */
188 gnvs->cid1 = wifi_regulatory_domain();
Furquan Shaikh3bfe3402016-10-18 14:25:25 -0700189
190 /* Set USB2/USB3 wake enable bitmaps. */
191 gnvs->u2we = config->usb2_wake_enable_bitmap;
192 gnvs->u3we = config->usb3_wake_enable_bitmap;
Pratik Prajapati418535e2017-10-11 16:12:21 -0700193
Michael Niewöhner7736bfc2019-10-22 23:05:06 +0200194 if (CONFIG(SOC_INTEL_COMMON_BLOCK_SGX_ENABLE))
Pratik Prajapati418535e2017-10-11 16:12:21 -0700195 sgx_fill_gnvs(gnvs);
Subrata Banikb6df6b02020-01-03 15:29:02 +0530196
197 /* Fill in Above 4GB MMIO resource */
198 sa_fill_gnvs(gnvs);
Lee Leahyb0005132015-05-12 18:19:47 -0700199}
200
Lee Leahyb0005132015-05-12 18:19:47 -0700201unsigned long acpi_fill_mcfg(unsigned long current)
202{
203 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current,
Duncan Laurie50f06a12018-03-02 14:56:38 -0800204 CONFIG_MMCONF_BASE_ADDRESS, 0, 0,
Duncan Lauriefd50b7c2018-03-02 14:47:11 -0800205 (CONFIG_SA_PCIEX_LENGTH >> 20) - 1);
Lee Leahyb0005132015-05-12 18:19:47 -0700206 return current;
207}
208
Duncan Lauriedb54a672015-09-04 14:19:35 -0700209unsigned long acpi_fill_madt(unsigned long current)
210{
211 /* Local APICs */
212 current = acpi_create_madt_lapics(current);
213
214 /* IOAPIC */
215 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
216 2, IO_APIC_ADDR, 0);
217
218 return acpi_madt_irq_overrides(current);
219}
220
Duncan Laurie135c2c42016-10-17 19:47:51 -0700221void acpi_fill_fadt(acpi_fadt_t *fadt)
Lee Leahyb0005132015-05-12 18:19:47 -0700222{
223 const uint16_t pmbase = ACPI_BASE_ADDRESS;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300224 config_t *config = config_of_soc();
Lee Leahyb0005132015-05-12 18:19:47 -0700225
Marc Jonesf9ea7ed2018-08-22 18:59:26 -0600226 fadt->header.revision = get_acpi_table_revision(FADT);
Duncan Laurie135c2c42016-10-17 19:47:51 -0700227
Lee Leahyb0005132015-05-12 18:19:47 -0700228 fadt->sci_int = acpi_sci_irq();
229 fadt->smi_cmd = APM_CNT;
230 fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
231 fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
232 fadt->s4bios_req = 0x0;
233 fadt->pstate_cnt = 0;
234
235 fadt->pm1a_evt_blk = pmbase + PM1_STS;
236 fadt->pm1b_evt_blk = 0x0;
237 fadt->pm1a_cnt_blk = pmbase + PM1_CNT;
238 fadt->pm1b_cnt_blk = 0x0;
239 fadt->pm2_cnt_blk = pmbase + PM2_CNT;
Duncan Laurie662b6cb2018-01-30 09:58:07 -0800240 fadt->pm_tmr_blk = pmbase + PM1_TMR;
Lee Leahyb0005132015-05-12 18:19:47 -0700241 fadt->gpe0_blk = pmbase + GPE0_STS(0);
242 fadt->gpe1_blk = 0;
243
244 fadt->pm1_evt_len = 4;
245 fadt->pm1_cnt_len = 2;
246 fadt->pm2_cnt_len = 1;
Duncan Laurie662b6cb2018-01-30 09:58:07 -0800247 fadt->pm_tmr_len = 4;
Aaron Durbin71e0ac82015-08-07 23:00:22 -0500248 /* There are 4 GPE0 STS/EN pairs each 32 bits wide. */
249 fadt->gpe0_blk_len = 2 * GPE0_REG_MAX * sizeof(uint32_t);
Lee Leahyb0005132015-05-12 18:19:47 -0700250 fadt->gpe1_blk_len = 0;
251 fadt->gpe1_base = 0;
252 fadt->cst_cnt = 0;
253 fadt->p_lvl2_lat = 1;
254 fadt->p_lvl3_lat = 87;
255 fadt->flush_size = 1024;
256 fadt->flush_stride = 16;
257 fadt->duty_offset = 1;
258 fadt->duty_width = 0;
259 fadt->day_alrm = 0xd;
260 fadt->mon_alrm = 0x00;
261 fadt->century = 0x00;
Paul Menzel8ca2af12019-02-08 15:19:20 +0100262 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_FREE;
Julius Wernercd49cce2019-03-05 16:53:33 -0800263 if (!CONFIG(NO_FADT_8042))
Jenny TC2864f852017-02-09 16:01:59 +0530264 fadt->iapc_boot_arch |= ACPI_FADT_8042;
Lee Leahyb0005132015-05-12 18:19:47 -0700265
266 fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED |
267 ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON |
268 ACPI_FADT_RESET_REGISTER | ACPI_FADT_SEALED_CASE |
269 ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_PLATFORM_CLOCK;
270
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300271 if (config->s0ix_enable)
Haridhar Kalvala1cedc7e2018-06-07 10:52:31 +0530272 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
273
Lee Leahyb0005132015-05-12 18:19:47 -0700274 fadt->reset_reg.space_id = 1;
275 fadt->reset_reg.bit_width = 8;
276 fadt->reset_reg.bit_offset = 0;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100277 fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Lee Leahyb0005132015-05-12 18:19:47 -0700278 fadt->reset_reg.addrl = 0xcf9;
279 fadt->reset_reg.addrh = 0;
280 fadt->reset_value = 6;
281
282 fadt->x_pm1a_evt_blk.space_id = 1;
283 fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8;
284 fadt->x_pm1a_evt_blk.bit_offset = 0;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100285 fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Lee Leahyb0005132015-05-12 18:19:47 -0700286 fadt->x_pm1a_evt_blk.addrl = pmbase + PM1_STS;
287 fadt->x_pm1a_evt_blk.addrh = 0x0;
288
289 fadt->x_pm1b_evt_blk.space_id = 1;
290 fadt->x_pm1b_evt_blk.bit_width = 0;
291 fadt->x_pm1b_evt_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100292 fadt->x_pm1b_evt_blk.access_size = 0;
Lee Leahyb0005132015-05-12 18:19:47 -0700293 fadt->x_pm1b_evt_blk.addrl = 0x0;
294 fadt->x_pm1b_evt_blk.addrh = 0x0;
295
296 fadt->x_pm1a_cnt_blk.space_id = 1;
297 fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8;
298 fadt->x_pm1a_cnt_blk.bit_offset = 0;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100299 fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
Lee Leahyb0005132015-05-12 18:19:47 -0700300 fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT;
301 fadt->x_pm1a_cnt_blk.addrh = 0x0;
302
303 fadt->x_pm1b_cnt_blk.space_id = 1;
304 fadt->x_pm1b_cnt_blk.bit_width = 0;
305 fadt->x_pm1b_cnt_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100306 fadt->x_pm1b_cnt_blk.access_size = 0;
Lee Leahyb0005132015-05-12 18:19:47 -0700307 fadt->x_pm1b_cnt_blk.addrl = 0x0;
308 fadt->x_pm1b_cnt_blk.addrh = 0x0;
309
310 fadt->x_pm2_cnt_blk.space_id = 1;
311 fadt->x_pm2_cnt_blk.bit_width = fadt->pm2_cnt_len * 8;
312 fadt->x_pm2_cnt_blk.bit_offset = 0;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100313 fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Lee Leahyb0005132015-05-12 18:19:47 -0700314 fadt->x_pm2_cnt_blk.addrl = pmbase + PM2_CNT;
315 fadt->x_pm2_cnt_blk.addrh = 0x0;
316
Duncan Laurie662b6cb2018-01-30 09:58:07 -0800317 fadt->x_pm_tmr_blk.space_id = 1;
318 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
319 fadt->x_pm_tmr_blk.bit_offset = 0;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100320 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Duncan Laurie662b6cb2018-01-30 09:58:07 -0800321 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
322 fadt->x_pm_tmr_blk.addrh = 0x0;
Lee Leahyb0005132015-05-12 18:19:47 -0700323
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100324 /*
325 * Windows 10 requires x_gpe0_blk to be set starting with FADT revision 5.
326 * The bit_width field intentionally overflows here.
327 * The OSPM can instead use the values in `fadt->gpe0_blk{,_len}`, which
328 * seems to work fine on Linux 5.0 and Windows 10.
329 */
330 fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO;
331 fadt->x_gpe0_blk.bit_width = fadt->gpe0_blk_len * 8;
Lee Leahyb0005132015-05-12 18:19:47 -0700332 fadt->x_gpe0_blk.bit_offset = 0;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100333 fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
334 fadt->x_gpe0_blk.addrl = fadt->gpe0_blk;
Lee Leahyb0005132015-05-12 18:19:47 -0700335 fadt->x_gpe0_blk.addrh = 0;
336
337 fadt->x_gpe1_blk.space_id = 1;
338 fadt->x_gpe1_blk.bit_width = 0;
339 fadt->x_gpe1_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100340 fadt->x_gpe1_blk.access_size = 0;
Lee Leahyb0005132015-05-12 18:19:47 -0700341 fadt->x_gpe1_blk.addrl = 0x0;
342 fadt->x_gpe1_blk.addrh = 0x0;
343}
344
Jacob Garber9172b692019-06-26 16:18:16 -0600345static void write_c_state_entries(acpi_cstate_t *map, const int *set, size_t max_c_state)
Lee Leahyb0005132015-05-12 18:19:47 -0700346{
Jacob Garber9172b692019-06-26 16:18:16 -0600347 for (size_t i = 0; i < max_c_state; i++) {
Lee Leahyb0005132015-05-12 18:19:47 -0700348 memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t));
349 map[i].ctype = i + 1;
350 }
351
352 /* Generate C-state tables */
Jacob Garber9172b692019-06-26 16:18:16 -0600353 acpigen_write_CST_package(map, max_c_state);
354}
355
356static void generate_c_state_entries(int s0ix_enable)
357{
358 if (s0ix_enable) {
359 acpi_cstate_t map[ARRAY_SIZE(cstate_set_s0ix)];
360 write_c_state_entries(map, cstate_set_s0ix, ARRAY_SIZE(map));
361 } else {
362 acpi_cstate_t map[ARRAY_SIZE(cstate_set_non_s0ix)];
363 write_c_state_entries(map, cstate_set_non_s0ix, ARRAY_SIZE(map));
364 }
Lee Leahyb0005132015-05-12 18:19:47 -0700365}
366
367static int calculate_power(int tdp, int p1_ratio, int ratio)
368{
369 u32 m;
370 u32 power;
371
372 /*
373 * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2
374 *
375 * Power = (ratio / p1_ratio) * m * tdp
376 */
377
378 m = (110000 - ((p1_ratio - ratio) * 625)) / 11;
379 m = (m * m) / 1000;
380
381 power = ((ratio * 100000 / p1_ratio) / 100);
382 power *= (m / 100) * (tdp / 1000);
383 power /= 1000;
384
385 return (int)power;
386}
387
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700388static void generate_p_state_entries(int core, int cores_per_package)
Lee Leahyb0005132015-05-12 18:19:47 -0700389{
390 int ratio_min, ratio_max, ratio_turbo, ratio_step;
391 int coord_type, power_max, power_unit, num_entries;
392 int ratio, power, clock, clock_max;
393 msr_t msr;
394
395 /* Determine P-state coordination type from MISC_PWR_MGMT[0] */
396 msr = rdmsr(MSR_MISC_PWR_MGMT);
397 if (msr.lo & MISC_PWR_MGMT_EIST_HW_DIS)
398 coord_type = SW_ANY;
399 else
400 coord_type = HW_ALL;
401
402 /* Get bus ratio limits and calculate clock speeds */
403 msr = rdmsr(MSR_PLATFORM_INFO);
404 ratio_min = (msr.hi >> (40-32)) & 0xff; /* Max Efficiency Ratio */
405
406 /* Determine if this CPU has configurable TDP */
407 if (cpu_config_tdp_levels()) {
408 /* Set max ratio to nominal TDP ratio */
409 msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
410 ratio_max = msr.lo & 0xff;
411 } else {
412 /* Max Non-Turbo Ratio */
413 ratio_max = (msr.lo >> 8) & 0xff;
414 }
Aamir Bohra1041d392017-06-02 11:56:14 +0530415 clock_max = ratio_max * CONFIG_CPU_BCLK_MHZ;
Lee Leahyb0005132015-05-12 18:19:47 -0700416
417 /* Calculate CPU TDP in mW */
418 msr = rdmsr(MSR_PKG_POWER_SKU_UNIT);
419 power_unit = 2 << ((msr.lo & 0xf) - 1);
420 msr = rdmsr(MSR_PKG_POWER_SKU);
421 power_max = ((msr.lo & 0x7fff) / power_unit) * 1000;
422
423 /* Write _PCT indicating use of FFixedHW */
424 acpigen_write_empty_PCT();
425
426 /* Write _PPC with no limit on supported P-state */
427 acpigen_write_PPC_NVS();
428
429 /* Write PSD indicating configured coordination type */
430 acpigen_write_PSD_package(core, 1, coord_type);
431
432 /* Add P-state entries in _PSS table */
433 acpigen_write_name("_PSS");
434
435 /* Determine ratio points */
436 ratio_step = PSS_RATIO_STEP;
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700437 num_entries = ((ratio_max - ratio_min) / ratio_step) + 1;
438 if (num_entries > PSS_MAX_ENTRIES) {
439 ratio_step += 1;
440 num_entries = ((ratio_max - ratio_min) / ratio_step) + 1;
Lee Leahyb0005132015-05-12 18:19:47 -0700441 }
442
443 /* P[T] is Turbo state if enabled */
444 if (get_turbo_state() == TURBO_ENABLED) {
445 /* _PSS package count including Turbo */
446 acpigen_write_package(num_entries + 2);
447
448 msr = rdmsr(MSR_TURBO_RATIO_LIMIT);
449 ratio_turbo = msr.lo & 0xff;
450
451 /* Add entry for Turbo ratio */
452 acpigen_write_PSS_package(
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700453 clock_max + 1, /* MHz */
454 power_max, /* mW */
455 PSS_LATENCY_TRANSITION, /* lat1 */
456 PSS_LATENCY_BUSMASTER, /* lat2 */
457 ratio_turbo << 8, /* control */
458 ratio_turbo << 8); /* status */
Lee Leahyb0005132015-05-12 18:19:47 -0700459 } else {
460 /* _PSS package count without Turbo */
461 acpigen_write_package(num_entries + 1);
462 }
463
464 /* First regular entry is max non-turbo ratio */
465 acpigen_write_PSS_package(
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700466 clock_max, /* MHz */
467 power_max, /* mW */
468 PSS_LATENCY_TRANSITION, /* lat1 */
469 PSS_LATENCY_BUSMASTER, /* lat2 */
470 ratio_max << 8, /* control */
471 ratio_max << 8); /* status */
Lee Leahyb0005132015-05-12 18:19:47 -0700472
473 /* Generate the remaining entries */
474 for (ratio = ratio_min + ((num_entries - 1) * ratio_step);
475 ratio >= ratio_min; ratio -= ratio_step) {
476
477 /* Calculate power at this ratio */
478 power = calculate_power(power_max, ratio_max, ratio);
Aamir Bohra1041d392017-06-02 11:56:14 +0530479 clock = ratio * CONFIG_CPU_BCLK_MHZ;
Lee Leahyb0005132015-05-12 18:19:47 -0700480
481 acpigen_write_PSS_package(
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700482 clock, /* MHz */
483 power, /* mW */
484 PSS_LATENCY_TRANSITION, /* lat1 */
485 PSS_LATENCY_BUSMASTER, /* lat2 */
486 ratio << 8, /* control */
487 ratio << 8); /* status */
Lee Leahyb0005132015-05-12 18:19:47 -0700488 }
489
490 /* Fix package length */
491 acpigen_pop_len();
492}
493
Furquan Shaikh7536a392020-04-24 21:59:21 -0700494void generate_cpu_entries(const struct device *device)
Lee Leahyb0005132015-05-12 18:19:47 -0700495{
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700496 int core_id, cpu_id, pcontrol_blk = ACPI_BASE_ADDRESS, plen = 6;
Lee Leahyb0005132015-05-12 18:19:47 -0700497 int totalcores = dev_count_cpu();
498 int cores_per_package = get_cores_per_package();
499 int numcpus = totalcores/cores_per_package;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300500 config_t *config = config_of_soc();
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700501 int is_s0ix_enable = config->s0ix_enable;
Lee Leahyb0005132015-05-12 18:19:47 -0700502
503 printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n",
504 numcpus, cores_per_package);
505
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300506 if (config->eist_enable && config->speed_shift_enable) {
Matt Delco9084c3c2018-07-27 14:17:29 -0700507 struct cppc_config cppc_config;
508 cpu_init_cppc_config(&cppc_config, 2 /* version 2 */);
509 acpigen_write_CPPC_package(&cppc_config);
510 }
511
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700512 for (cpu_id = 0; cpu_id < numcpus; cpu_id++) {
513 for (core_id = 0; core_id < cores_per_package; core_id++) {
514 if (core_id > 0) {
Lee Leahyb0005132015-05-12 18:19:47 -0700515 pcontrol_blk = 0;
516 plen = 0;
517 }
518
Christian Walterbe3979c2019-12-18 15:07:59 +0100519 /* Generate processor \_SB.CPUx */
Lee Leahyb0005132015-05-12 18:19:47 -0700520 acpigen_write_processor(
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700521 cpu_id*cores_per_package+core_id,
Lee Leahyb0005132015-05-12 18:19:47 -0700522 pcontrol_blk, plen);
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700523 /* Generate C-state tables */
Jacob Garber9172b692019-06-26 16:18:16 -0600524 generate_c_state_entries(is_s0ix_enable);
Lee Leahyb0005132015-05-12 18:19:47 -0700525
Matt Delco9084c3c2018-07-27 14:17:29 -0700526 if (config->eist_enable) {
Subrata Banik6b45ee42017-05-12 11:43:57 +0530527 /* Generate P-state tables */
528 generate_p_state_entries(core_id,
529 cores_per_package);
Matt Delco9084c3c2018-07-27 14:17:29 -0700530 if (config->speed_shift_enable)
531 acpigen_write_CPPC_method();
532 }
Lee Leahyb0005132015-05-12 18:19:47 -0700533 acpigen_pop_len();
534 }
535 }
Arthur Heymans8afc1352018-11-28 12:07:19 +0100536
537 /* PPKG is usually used for thermal management
538 of the first and only package. */
539 acpigen_write_processor_package("PPKG", 0, cores_per_package);
540
541 /* Add a method to notify processor nodes */
542 acpigen_write_processor_cnot(cores_per_package);
Lee Leahyb0005132015-05-12 18:19:47 -0700543}
544
Nico Huberc37b0e32017-09-18 20:03:46 +0200545static unsigned long acpi_fill_dmar(unsigned long current)
546{
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300547 struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD);
Nico Huberc37b0e32017-09-18 20:03:46 +0200548 const u32 gfx_vtbar = MCHBAR32(GFXVTBAR) & ~0xfff;
549 const bool gfxvten = MCHBAR32(GFXVTBAR) & 1;
550
551 /* iGFX has to be enabled, GFXVTBAR set and in 32-bit space. */
552 if (igfx_dev && igfx_dev->enabled && gfxvten &&
553 gfx_vtbar && !MCHBAR32(GFXVTBAR + 4)) {
Matt DeVilliercbe73ea2018-06-25 14:40:53 -0500554 unsigned long tmp = current;
Nico Huberc37b0e32017-09-18 20:03:46 +0200555
556 current += acpi_create_dmar_drhd(current, 0, 0, gfx_vtbar);
Matt DeVillier7866d492018-03-29 14:59:57 +0200557 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
Nico Huberc37b0e32017-09-18 20:03:46 +0200558
559 acpi_dmar_drhd_fixup(tmp, current);
Matt DeVilliercbe73ea2018-06-25 14:40:53 -0500560
561 /* Add RMRR entry */
562 tmp = current;
563
564 current += acpi_create_dmar_rmrr(current, 0,
565 sa_get_gsm_base(), sa_get_tolud_base() - 1);
566 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
567 acpi_dmar_rmrr_fixup(tmp, current);
Nico Huberc37b0e32017-09-18 20:03:46 +0200568 }
569
Nico Huberc37b0e32017-09-18 20:03:46 +0200570 const u32 vtvc0bar = MCHBAR32(VTVC0BAR) & ~0xfff;
571 const bool vtvc0en = MCHBAR32(VTVC0BAR) & 1;
572
573 /* General VTBAR has to be set and in 32-bit space. */
Angel Ponsef879a82019-08-30 19:42:23 +0200574 if (vtvc0bar && vtvc0en && !MCHBAR32(VTVC0BAR + 4)) {
Nico Huberc37b0e32017-09-18 20:03:46 +0200575 const unsigned long tmp = current;
576
Angel Ponsef879a82019-08-30 19:42:23 +0200577 current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
Nico Huberc37b0e32017-09-18 20:03:46 +0200578
Angel Ponsef879a82019-08-30 19:42:23 +0200579 current += acpi_create_dmar_ds_ioapic(current, 2, V_P2SB_IBDF_BUS,
580 V_P2SB_IBDF_DEV, V_P2SB_IBDF_FUN);
Nico Huberc37b0e32017-09-18 20:03:46 +0200581
Angel Ponsef879a82019-08-30 19:42:23 +0200582 current += acpi_create_dmar_ds_msi_hpet(current, 0, V_P2SB_HBDF_BUS,
583 V_P2SB_HBDF_DEV, V_P2SB_HBDF_FUN);
Nico Huberc37b0e32017-09-18 20:03:46 +0200584
585 acpi_dmar_drhd_fixup(tmp, current);
586 }
587
588 return current;
589}
590
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700591unsigned long northbridge_write_acpi_tables(const struct device *const dev,
Nico Huberc37b0e32017-09-18 20:03:46 +0200592 unsigned long current,
593 struct acpi_rsdp *const rsdp)
594{
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300595 const struct soc_intel_skylake_config *const config = config_of(dev);
Nico Huberc37b0e32017-09-18 20:03:46 +0200596 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
597
598 /* Create DMAR table only if we have VT-d capability. */
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300599 if (config->ignore_vtd || !soc_is_vtd_capable())
Nico Huberc37b0e32017-09-18 20:03:46 +0200600 return current;
601
602 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
603 acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar);
604 current += dmar->header.length;
605 current = acpi_align_current(current);
606 acpi_add_table(rsdp, dmar);
607
608 return current;
609}
610
Lee Leahyb0005132015-05-12 18:19:47 -0700611unsigned long acpi_madt_irq_overrides(unsigned long current)
612{
613 int sci = acpi_sci_irq();
614 acpi_madt_irqoverride_t *irqovr;
615 uint16_t flags = MP_IRQ_TRIGGER_LEVEL;
616
617 /* INT_SRC_OVR */
618 irqovr = (void *)current;
619 current += acpi_create_madt_irqoverride(irqovr, 0, 0, 2, 0);
620
621 if (sci >= 20)
622 flags |= MP_IRQ_POLARITY_LOW;
623 else
624 flags |= MP_IRQ_POLARITY_HIGH;
625
626 /* SCI */
627 irqovr = (void *)current;
628 current += acpi_create_madt_irqoverride(irqovr, 0, sci, sci, flags);
629
630 return current;
631}
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700632
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700633unsigned long southbridge_write_acpi_tables(const struct device *device,
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700634 unsigned long current,
635 struct acpi_rsdp *rsdp)
636{
Duncan Laurie93bbd412017-11-11 20:03:29 -0800637 current = acpi_write_dbg2_pci_uart(rsdp, current,
Subrata Banikafa07f72018-05-24 12:21:06 +0530638 uart_get_device(),
Duncan Laurie93bbd412017-11-11 20:03:29 -0800639 ACPI_ACCESS_SIZE_DWORD_ACCESS);
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700640 current = acpi_write_hpet(device, current, rsdp);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600641 return acpi_align_current(current);
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700642}
643
Furquan Shaikh338fd9a2020-04-24 22:57:05 -0700644void southbridge_inject_dsdt(const struct device *device)
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700645{
646 global_nvs_t *gnvs;
647
648 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
649 if (!gnvs) {
Lee Leahyf4c4ab92017-03-16 17:08:03 -0700650 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700651 if (gnvs)
652 memset(gnvs, 0, sizeof(*gnvs));
653 }
654
655 if (gnvs) {
656 acpi_create_gnvs(gnvs);
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700657 /* And tell SMI about it */
658 smm_setup_structures(gnvs, NULL, NULL);
659
660 /* Add it to DSDT. */
661 acpigen_write_scope("\\");
662 acpigen_write_name_dword("NVSA", (u32) gnvs);
663 acpigen_pop_len();
664 }
665}
666
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700667/* Save wake source information for calculating ACPI _SWS values */
668int soc_fill_acpi_wake(uint32_t *pm1, uint32_t **gpe0)
669{
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300670 const struct soc_intel_skylake_config *config = config_of_soc();
Naresh G Solankia1b35472015-12-11 18:13:02 +0530671 struct chipset_power_state *ps;
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700672 static uint32_t gpe0_sts[GPE0_REG_MAX];
673 uint32_t pm1_en;
Duncan Laurie95f90202016-10-25 20:07:22 -0700674 uint32_t gpe0_std;
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700675 int i;
Aaron Durbin64606ce2016-10-27 09:53:17 -0500676 const int last_index = GPE0_REG_MAX - 1;
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700677
Naresh G Solankia1b35472015-12-11 18:13:02 +0530678 ps = cbmem_find(CBMEM_ID_POWER_STATE);
679 if (ps == NULL)
680 return -1;
681
Duncan Laurie95f90202016-10-25 20:07:22 -0700682 pm1_en = ps->pm1_en;
683 gpe0_std = ps->gpe0_en[3];
684
685 /*
686 * Chipset state in the suspend well (but not RTC) is lost in Deep S3
687 * so enable Deep S3 wake events that are configured by the mainboard
688 */
Duncan Laurie1fe32d62017-04-10 21:02:13 -0700689 if (ps->prev_sleep_state == ACPI_S3 &&
690 (config->deep_s3_enable_ac || config->deep_s3_enable_dc)) {
Duncan Laurie95f90202016-10-25 20:07:22 -0700691 pm1_en |= PWRBTN_STS; /* Always enabled as wake source */
692 if (config->deep_sx_config & DSX_EN_LAN_WAKE_PIN)
693 gpe0_std |= LAN_WAK_EN;
694 if (config->deep_sx_config & DSX_EN_WAKE_PIN)
695 pm1_en |= PCIEXPWAK_STS;
696 }
697
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700698 *pm1 = ps->pm1_sts & pm1_en;
699
700 /* Mask off GPE0 status bits that are not enabled */
701 *gpe0 = &gpe0_sts[0];
Aaron Durbin64606ce2016-10-27 09:53:17 -0500702 for (i = 0; i < last_index; i++)
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700703 gpe0_sts[i] = ps->gpe0_sts[i] & ps->gpe0_en[i];
Aaron Durbin64606ce2016-10-27 09:53:17 -0500704 gpe0_sts[last_index] = ps->gpe0_sts[last_index] & gpe0_std;
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700705
706 return GPE0_REG_MAX;
707}
708
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600709const char *soc_acpi_name(const struct device *dev)
Naresh G Solankia2d40622016-08-30 20:47:13 +0530710{
711 if (dev->path.type == DEVICE_PATH_DOMAIN)
712 return "PCI0";
713
Duncan Lauriebf713b02018-05-07 15:33:18 -0700714 if (dev->path.type == DEVICE_PATH_USB) {
715 switch (dev->path.usb.port_type) {
716 case 0:
717 /* Root Hub */
718 return "RHUB";
719 case 2:
720 /* USB2 ports */
721 switch (dev->path.usb.port_id) {
722 case 0: return "HS01";
723 case 1: return "HS02";
724 case 2: return "HS03";
725 case 3: return "HS04";
726 case 4: return "HS05";
727 case 5: return "HS06";
728 case 6: return "HS07";
729 case 7: return "HS08";
730 case 8: return "HS09";
731 case 9: return "HS10";
732 }
733 break;
734 case 3:
735 /* USB3 ports */
736 switch (dev->path.usb.port_id) {
737 case 0: return "SS01";
738 case 1: return "SS02";
739 case 2: return "SS03";
740 case 3: return "SS04";
741 case 4: return "SS05";
742 case 5: return "SS06";
743 }
744 break;
745 }
746 return NULL;
747 }
748
Naresh G Solankia2d40622016-08-30 20:47:13 +0530749 if (dev->path.type != DEVICE_PATH_PCI)
750 return NULL;
751
Patrick Rudolph45ffee82019-09-26 14:45:29 +0200752 /* Only match devices on the root bus */
753 if (dev->bus && dev->bus->secondary > 0)
754 return NULL;
755
Naresh G Solankia2d40622016-08-30 20:47:13 +0530756 switch (dev->path.pci.devfn) {
757 case SA_DEVFN_ROOT: return "MCHC";
758 case SA_DEVFN_IGD: return "GFX0";
759 case PCH_DEVFN_ISH: return "ISHB";
760 case PCH_DEVFN_XHCI: return "XHCI";
761 case PCH_DEVFN_USBOTG: return "XDCI";
762 case PCH_DEVFN_THERMAL: return "THRM";
763 case PCH_DEVFN_CIO: return "ICIO";
764 case PCH_DEVFN_I2C0: return "I2C0";
765 case PCH_DEVFN_I2C1: return "I2C1";
766 case PCH_DEVFN_I2C2: return "I2C2";
767 case PCH_DEVFN_I2C3: return "I2C3";
Subrata Banik2ee54db2017-03-05 12:37:00 +0530768 case PCH_DEVFN_CSE: return "CSE1";
769 case PCH_DEVFN_CSE_2: return "CSE2";
770 case PCH_DEVFN_CSE_IDER: return "CSED";
771 case PCH_DEVFN_CSE_KT: return "CSKT";
772 case PCH_DEVFN_CSE_3: return "CSE3";
Naresh G Solankia2d40622016-08-30 20:47:13 +0530773 case PCH_DEVFN_SATA: return "SATA";
774 case PCH_DEVFN_UART2: return "UAR2";
775 case PCH_DEVFN_I2C4: return "I2C4";
776 case PCH_DEVFN_I2C5: return "I2C5";
777 case PCH_DEVFN_PCIE1: return "RP01";
778 case PCH_DEVFN_PCIE2: return "RP02";
779 case PCH_DEVFN_PCIE3: return "RP03";
780 case PCH_DEVFN_PCIE4: return "RP04";
781 case PCH_DEVFN_PCIE5: return "RP05";
782 case PCH_DEVFN_PCIE6: return "RP06";
783 case PCH_DEVFN_PCIE7: return "RP07";
784 case PCH_DEVFN_PCIE8: return "RP08";
785 case PCH_DEVFN_PCIE9: return "RP09";
786 case PCH_DEVFN_PCIE10: return "RP10";
787 case PCH_DEVFN_PCIE11: return "RP11";
788 case PCH_DEVFN_PCIE12: return "RP12";
Maxim Polyakovc6f2b612019-08-23 15:22:21 +0300789 case PCH_DEVFN_PCIE13: return "RP13";
790 case PCH_DEVFN_PCIE14: return "RP14";
791 case PCH_DEVFN_PCIE15: return "RP15";
792 case PCH_DEVFN_PCIE16: return "RP16";
Naresh G Solankia2d40622016-08-30 20:47:13 +0530793 case PCH_DEVFN_UART0: return "UAR0";
794 case PCH_DEVFN_UART1: return "UAR1";
795 case PCH_DEVFN_GSPI0: return "SPI0";
796 case PCH_DEVFN_GSPI1: return "SPI1";
797 case PCH_DEVFN_EMMC: return "EMMC";
798 case PCH_DEVFN_SDIO: return "SDIO";
799 case PCH_DEVFN_SDCARD: return "SDXC";
800 case PCH_DEVFN_LPC: return "LPCB";
801 case PCH_DEVFN_P2SB: return "P2SB";
802 case PCH_DEVFN_PMC: return "PMC_";
803 case PCH_DEVFN_HDA: return "HDAS";
804 case PCH_DEVFN_SMBUS: return "SBUS";
805 case PCH_DEVFN_SPI: return "FSPI";
806 case PCH_DEVFN_GBE: return "IGBE";
807 case PCH_DEVFN_TRACEHUB:return "THUB";
808 }
809
810 return NULL;
811}
Furquan Shaikha6f0b272017-05-23 11:53:47 -0700812
813static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num)
814{
815 /* op (gpio_num) */
816 acpigen_emit_namestring(op);
817 acpigen_write_integer(gpio_num);
818 return 0;
819}
820
821static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num)
822{
823 /* Store (op (gpio_num), Local0) */
824 acpigen_write_store();
825 acpigen_soc_gpio_op(op, gpio_num);
826 acpigen_emit_byte(LOCAL0_OP);
827 return 0;
828}
829
830int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
831{
832 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GRXS", gpio_num);
833}
834
835int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
836{
837 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GTXS", gpio_num);
838}
839
840int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
841{
842 return acpigen_soc_gpio_op("\\_SB.PCI0.STXS", gpio_num);
843}
844
845int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
846{
847 return acpigen_soc_gpio_op("\\_SB.PCI0.CTXS", gpio_num);
848}