blob: c3757b0bd3d40e46a12c3421de93be80d18a99cf [file] [log] [blame]
Lee Leahyb0005132015-05-12 18:19:47 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2009 coresystems GmbH
5 * Copyright (C) 2014 Google Inc.
Pratik Prajapati07cbd762019-01-11 14:00:40 -08006 * Copyright (C) 2015-2019 Intel Corporation.
Lee Leahyb0005132015-05-12 18:19:47 -07007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Lee Leahyb0005132015-05-12 18:19:47 -070016 */
17
18#include <arch/acpi.h>
19#include <arch/acpigen.h>
robbie zhangb45dde02015-10-01 17:21:33 -070020#include <arch/cpu.h>
Duncan Lauriedb54a672015-09-04 14:19:35 -070021#include <arch/ioapic.h>
Lee Leahyb0005132015-05-12 18:19:47 -070022#include <arch/smp/mpspec.h>
23#include <cbmem.h>
24#include <console/console.h>
25#include <cpu/x86/smm.h>
Lee Leahyb0005132015-05-12 18:19:47 -070026#include <cpu/x86/msr.h>
27#include <cpu/x86/tsc.h>
Matt Delco9084c3c2018-07-27 14:17:29 -070028#include <cpu/intel/common/common.h>
Lee Leahyb0005132015-05-12 18:19:47 -070029#include <cpu/intel/turbo.h>
30#include <ec/google/chromeec/ec.h>
Barnali Sarkar0a203d12017-05-04 18:02:17 +053031#include <intelblocks/cpulib.h>
Ravi Sarawadi1483d1f2017-09-28 17:06:01 -070032#include <intelblocks/lpc_lib.h>
Pratik Prajapati418535e2017-10-11 16:12:21 -070033#include <intelblocks/sgx.h>
Duncan Laurie93bbd412017-11-11 20:03:29 -080034#include <intelblocks/uart.h>
Nico Huberc37b0e32017-09-18 20:03:46 +020035#include <intelblocks/systemagent.h>
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -070036#include <soc/intel/common/acpi.h>
Lee Leahyb0005132015-05-12 18:19:47 -070037#include <soc/acpi.h>
38#include <soc/cpu.h>
39#include <soc/iomap.h>
Lee Leahyb0005132015-05-12 18:19:47 -070040#include <soc/msr.h>
41#include <soc/pci_devs.h>
42#include <soc/pm.h>
Naresh G Solankia2d40622016-08-30 20:47:13 +053043#include <soc/ramstage.h>
Nico Huberc37b0e32017-09-18 20:03:46 +020044#include <soc/systemagent.h>
robbie zhangb45dde02015-10-01 17:21:33 -070045#include <string.h>
46#include <types.h>
47#include <vendorcode/google/chromeos/gnvs.h>
Duncan Laurie3d3b76b2016-02-25 08:45:43 -080048#include <wrdd.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +020049#include <device/pci_ops.h>
Lee Leahyb0005132015-05-12 18:19:47 -070050
Elyes HAOUASc3385072019-03-21 15:38:06 +010051#include "chip.h"
52
Lee Leahyb0005132015-05-12 18:19:47 -070053/*
Lee Leahy1d14b3e2015-05-12 18:23:27 -070054 * List of suported C-states in this processor.
Lee Leahyb0005132015-05-12 18:19:47 -070055 */
56enum {
Lee Leahy1d14b3e2015-05-12 18:23:27 -070057 C_STATE_C0, /* 0 */
58 C_STATE_C1, /* 1 */
59 C_STATE_C1E, /* 2 */
60 C_STATE_C3, /* 3 */
61 C_STATE_C6_SHORT_LAT, /* 4 */
62 C_STATE_C6_LONG_LAT, /* 5 */
63 C_STATE_C7_SHORT_LAT, /* 6 */
64 C_STATE_C7_LONG_LAT, /* 7 */
65 C_STATE_C7S_SHORT_LAT, /* 8 */
66 C_STATE_C7S_LONG_LAT, /* 9 */
67 C_STATE_C8, /* 10 */
68 C_STATE_C9, /* 11 */
69 C_STATE_C10, /* 12 */
Lee Leahyb0005132015-05-12 18:19:47 -070070 NUM_C_STATES
71};
Lee Leahy1d14b3e2015-05-12 18:23:27 -070072#define MWAIT_RES(state, sub_state) \
73 { \
74 .addrl = (((state) << 4) | (sub_state)), \
75 .space_id = ACPI_ADDRESS_SPACE_FIXED, \
76 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \
77 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \
78 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \
Lee Leahyb0005132015-05-12 18:19:47 -070079 }
80
81static acpi_cstate_t cstate_map[NUM_C_STATES] = {
82 [C_STATE_C0] = { },
83 [C_STATE_C1] = {
84 .latency = 0,
robbie zhangc16b1fd2015-09-11 14:25:15 -070085 .power = C1_POWER,
Lee Leahy1d14b3e2015-05-12 18:23:27 -070086 .resource = MWAIT_RES(0, 0),
Lee Leahyb0005132015-05-12 18:19:47 -070087 },
88 [C_STATE_C1E] = {
89 .latency = 0,
robbie zhangc16b1fd2015-09-11 14:25:15 -070090 .power = C1_POWER,
Lee Leahy1d14b3e2015-05-12 18:23:27 -070091 .resource = MWAIT_RES(0, 1),
Lee Leahyb0005132015-05-12 18:19:47 -070092 },
93 [C_STATE_C3] = {
94 .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
robbie zhangc16b1fd2015-09-11 14:25:15 -070095 .power = C3_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -070096 .resource = MWAIT_RES(1, 0),
97 },
98 [C_STATE_C6_SHORT_LAT] = {
99 .latency = C_STATE_LATENCY_FROM_LAT_REG(1),
robbie zhangc16b1fd2015-09-11 14:25:15 -0700100 .power = C6_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -0700101 .resource = MWAIT_RES(2, 0),
102 },
103 [C_STATE_C6_LONG_LAT] = {
104 .latency = C_STATE_LATENCY_FROM_LAT_REG(2),
robbie zhangc16b1fd2015-09-11 14:25:15 -0700105 .power = C6_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -0700106 .resource = MWAIT_RES(2, 1),
107 },
108 [C_STATE_C7_SHORT_LAT] = {
109 .latency = C_STATE_LATENCY_FROM_LAT_REG(1),
robbie zhangc16b1fd2015-09-11 14:25:15 -0700110 .power = C7_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -0700111 .resource = MWAIT_RES(3, 0),
112 },
113 [C_STATE_C7_LONG_LAT] = {
114 .latency = C_STATE_LATENCY_FROM_LAT_REG(2),
robbie zhangc16b1fd2015-09-11 14:25:15 -0700115 .power = C7_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -0700116 .resource = MWAIT_RES(3, 1),
117 },
118 [C_STATE_C7S_SHORT_LAT] = {
119 .latency = C_STATE_LATENCY_FROM_LAT_REG(1),
robbie zhangc16b1fd2015-09-11 14:25:15 -0700120 .power = C7_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -0700121 .resource = MWAIT_RES(3, 2),
122 },
123 [C_STATE_C7S_LONG_LAT] = {
124 .latency = C_STATE_LATENCY_FROM_LAT_REG(2),
robbie zhangc16b1fd2015-09-11 14:25:15 -0700125 .power = C7_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -0700126 .resource = MWAIT_RES(3, 3),
127 },
128 [C_STATE_C8] = {
129 .latency = C_STATE_LATENCY_FROM_LAT_REG(3),
robbie zhangc16b1fd2015-09-11 14:25:15 -0700130 .power = C8_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -0700131 .resource = MWAIT_RES(4, 0),
132 },
133 [C_STATE_C9] = {
134 .latency = C_STATE_LATENCY_FROM_LAT_REG(4),
robbie zhangc16b1fd2015-09-11 14:25:15 -0700135 .power = C9_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -0700136 .resource = MWAIT_RES(5, 0),
137 },
138 [C_STATE_C10] = {
139 .latency = C_STATE_LATENCY_FROM_LAT_REG(5),
robbie zhangc16b1fd2015-09-11 14:25:15 -0700140 .power = C10_POWER,
Lee Leahyb0005132015-05-12 18:19:47 -0700141 .resource = MWAIT_RES(6, 0),
142 },
143};
144
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700145static int cstate_set_s0ix[] = {
Lee Leahyb0005132015-05-12 18:19:47 -0700146 C_STATE_C1E,
147 C_STATE_C7S_LONG_LAT,
148 C_STATE_C10
149};
150
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700151static int cstate_set_non_s0ix[] = {
Lee Leahyb0005132015-05-12 18:19:47 -0700152 C_STATE_C1E,
153 C_STATE_C3,
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700154 C_STATE_C7S_LONG_LAT,
Lee Leahyb0005132015-05-12 18:19:47 -0700155};
156
157static int get_cores_per_package(void)
158{
159 struct cpuinfo_x86 c;
160 struct cpuid_result result;
161 int cores = 1;
162
163 get_fms(&c, cpuid_eax(1));
164 if (c.x86 != 6)
165 return 1;
166
167 result = cpuid_ext(0xb, 1);
168 cores = result.ebx & 0xff;
169
170 return cores;
171}
172
Duncan Lauriedb54a672015-09-04 14:19:35 -0700173static void acpi_create_gnvs(global_nvs_t *gnvs)
Lee Leahyb0005132015-05-12 18:19:47 -0700174{
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300175 const struct soc_intel_skylake_config *config = config_of_path(PCH_DEVFN_LPC);
Duncan Laurie7fce30c2015-09-04 13:53:14 -0700176
Lee Leahyb0005132015-05-12 18:19:47 -0700177 /* Set unknown wake source */
178 gnvs->pm1i = -1;
179
180 /* CPU core count */
181 gnvs->pcnt = dev_count_cpu();
182
Julius Wernercd49cce2019-03-05 16:53:33 -0800183#if CONFIG(CONSOLE_CBMEM)
Lee Leahyb0005132015-05-12 18:19:47 -0700184 /* Update the mem console pointer. */
185 gnvs->cbmc = (u32)cbmem_find(CBMEM_ID_CONSOLE);
186#endif
187
Julius Wernercd49cce2019-03-05 16:53:33 -0800188#if CONFIG(CHROMEOS)
Lee Leahyb0005132015-05-12 18:19:47 -0700189 /* Initialize Verified Boot data */
Joel Kitching6fbd8742018-08-23 14:56:25 +0800190 chromeos_init_chromeos_acpi(&(gnvs->chromeos));
Julius Wernercd49cce2019-03-05 16:53:33 -0800191#if CONFIG(EC_GOOGLE_CHROMEEC)
Lee Leahyb0005132015-05-12 18:19:47 -0700192 gnvs->chromeos.vbt2 = google_ec_running_ro() ?
193 ACTIVE_ECFW_RO : ACTIVE_ECFW_RW;
194#endif
195 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
196#endif
Duncan Laurie7fce30c2015-09-04 13:53:14 -0700197
198 /* Enable DPTF based on mainboard configuration */
199 gnvs->dpte = config->dptf_enable;
Duncan Laurie3d3b76b2016-02-25 08:45:43 -0800200
201 /* Fill in the Wifi Region id */
202 gnvs->cid1 = wifi_regulatory_domain();
Furquan Shaikh3bfe3402016-10-18 14:25:25 -0700203
204 /* Set USB2/USB3 wake enable bitmaps. */
205 gnvs->u2we = config->usb2_wake_enable_bitmap;
206 gnvs->u3we = config->usb3_wake_enable_bitmap;
Pratik Prajapati418535e2017-10-11 16:12:21 -0700207
Julius Wernercd49cce2019-03-05 16:53:33 -0800208 if (CONFIG(SOC_INTEL_COMMON_BLOCK_SGX))
Pratik Prajapati418535e2017-10-11 16:12:21 -0700209 sgx_fill_gnvs(gnvs);
Lee Leahyb0005132015-05-12 18:19:47 -0700210}
211
Lee Leahyb0005132015-05-12 18:19:47 -0700212unsigned long acpi_fill_mcfg(unsigned long current)
213{
214 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current,
Duncan Laurie50f06a12018-03-02 14:56:38 -0800215 CONFIG_MMCONF_BASE_ADDRESS, 0, 0,
Duncan Lauriefd50b7c2018-03-02 14:47:11 -0800216 (CONFIG_SA_PCIEX_LENGTH >> 20) - 1);
Lee Leahyb0005132015-05-12 18:19:47 -0700217 return current;
218}
219
Duncan Lauriedb54a672015-09-04 14:19:35 -0700220unsigned long acpi_fill_madt(unsigned long current)
221{
222 /* Local APICs */
223 current = acpi_create_madt_lapics(current);
224
225 /* IOAPIC */
226 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *) current,
227 2, IO_APIC_ADDR, 0);
228
229 return acpi_madt_irq_overrides(current);
230}
231
Duncan Laurie135c2c42016-10-17 19:47:51 -0700232void acpi_fill_fadt(acpi_fadt_t *fadt)
Lee Leahyb0005132015-05-12 18:19:47 -0700233{
234 const uint16_t pmbase = ACPI_BASE_ADDRESS;
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300235 config_t *config = config_of_path(SA_DEVFN_ROOT);
Lee Leahyb0005132015-05-12 18:19:47 -0700236
Werner Zeh00d250e2017-04-26 07:03:10 +0200237 /* Use ACPI 3.0 revision */
Marc Jonesf9ea7ed2018-08-22 18:59:26 -0600238 fadt->header.revision = get_acpi_table_revision(FADT);
Duncan Laurie135c2c42016-10-17 19:47:51 -0700239
Lee Leahyb0005132015-05-12 18:19:47 -0700240 fadt->sci_int = acpi_sci_irq();
241 fadt->smi_cmd = APM_CNT;
242 fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
243 fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
244 fadt->s4bios_req = 0x0;
245 fadt->pstate_cnt = 0;
246
247 fadt->pm1a_evt_blk = pmbase + PM1_STS;
248 fadt->pm1b_evt_blk = 0x0;
249 fadt->pm1a_cnt_blk = pmbase + PM1_CNT;
250 fadt->pm1b_cnt_blk = 0x0;
251 fadt->pm2_cnt_blk = pmbase + PM2_CNT;
Duncan Laurie662b6cb2018-01-30 09:58:07 -0800252 fadt->pm_tmr_blk = pmbase + PM1_TMR;
Lee Leahyb0005132015-05-12 18:19:47 -0700253 fadt->gpe0_blk = pmbase + GPE0_STS(0);
254 fadt->gpe1_blk = 0;
255
256 fadt->pm1_evt_len = 4;
257 fadt->pm1_cnt_len = 2;
258 fadt->pm2_cnt_len = 1;
Duncan Laurie662b6cb2018-01-30 09:58:07 -0800259 fadt->pm_tmr_len = 4;
Aaron Durbin71e0ac82015-08-07 23:00:22 -0500260 /* There are 4 GPE0 STS/EN pairs each 32 bits wide. */
261 fadt->gpe0_blk_len = 2 * GPE0_REG_MAX * sizeof(uint32_t);
Lee Leahyb0005132015-05-12 18:19:47 -0700262 fadt->gpe1_blk_len = 0;
263 fadt->gpe1_base = 0;
264 fadt->cst_cnt = 0;
265 fadt->p_lvl2_lat = 1;
266 fadt->p_lvl3_lat = 87;
267 fadt->flush_size = 1024;
268 fadt->flush_stride = 16;
269 fadt->duty_offset = 1;
270 fadt->duty_width = 0;
271 fadt->day_alrm = 0xd;
272 fadt->mon_alrm = 0x00;
273 fadt->century = 0x00;
Paul Menzel8ca2af12019-02-08 15:19:20 +0100274 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_FREE;
Julius Wernercd49cce2019-03-05 16:53:33 -0800275 if (!CONFIG(NO_FADT_8042))
Jenny TC2864f852017-02-09 16:01:59 +0530276 fadt->iapc_boot_arch |= ACPI_FADT_8042;
Lee Leahyb0005132015-05-12 18:19:47 -0700277
278 fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED |
279 ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON |
280 ACPI_FADT_RESET_REGISTER | ACPI_FADT_SEALED_CASE |
281 ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_PLATFORM_CLOCK;
282
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300283 if (config->s0ix_enable)
Haridhar Kalvala1cedc7e2018-06-07 10:52:31 +0530284 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
285
Lee Leahyb0005132015-05-12 18:19:47 -0700286 fadt->reset_reg.space_id = 1;
287 fadt->reset_reg.bit_width = 8;
288 fadt->reset_reg.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100289 fadt->reset_reg.access_size = 0;
Lee Leahyb0005132015-05-12 18:19:47 -0700290 fadt->reset_reg.addrl = 0xcf9;
291 fadt->reset_reg.addrh = 0;
292 fadt->reset_value = 6;
293
294 fadt->x_pm1a_evt_blk.space_id = 1;
295 fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8;
296 fadt->x_pm1a_evt_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100297 fadt->x_pm1a_evt_blk.access_size = 0;
Lee Leahyb0005132015-05-12 18:19:47 -0700298 fadt->x_pm1a_evt_blk.addrl = pmbase + PM1_STS;
299 fadt->x_pm1a_evt_blk.addrh = 0x0;
300
301 fadt->x_pm1b_evt_blk.space_id = 1;
302 fadt->x_pm1b_evt_blk.bit_width = 0;
303 fadt->x_pm1b_evt_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100304 fadt->x_pm1b_evt_blk.access_size = 0;
Lee Leahyb0005132015-05-12 18:19:47 -0700305 fadt->x_pm1b_evt_blk.addrl = 0x0;
306 fadt->x_pm1b_evt_blk.addrh = 0x0;
307
308 fadt->x_pm1a_cnt_blk.space_id = 1;
309 fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8;
310 fadt->x_pm1a_cnt_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100311 fadt->x_pm1a_cnt_blk.access_size = 0;
Lee Leahyb0005132015-05-12 18:19:47 -0700312 fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT;
313 fadt->x_pm1a_cnt_blk.addrh = 0x0;
314
315 fadt->x_pm1b_cnt_blk.space_id = 1;
316 fadt->x_pm1b_cnt_blk.bit_width = 0;
317 fadt->x_pm1b_cnt_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100318 fadt->x_pm1b_cnt_blk.access_size = 0;
Lee Leahyb0005132015-05-12 18:19:47 -0700319 fadt->x_pm1b_cnt_blk.addrl = 0x0;
320 fadt->x_pm1b_cnt_blk.addrh = 0x0;
321
322 fadt->x_pm2_cnt_blk.space_id = 1;
323 fadt->x_pm2_cnt_blk.bit_width = fadt->pm2_cnt_len * 8;
324 fadt->x_pm2_cnt_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100325 fadt->x_pm2_cnt_blk.access_size = 0;
Lee Leahyb0005132015-05-12 18:19:47 -0700326 fadt->x_pm2_cnt_blk.addrl = pmbase + PM2_CNT;
327 fadt->x_pm2_cnt_blk.addrh = 0x0;
328
Duncan Laurie662b6cb2018-01-30 09:58:07 -0800329 fadt->x_pm_tmr_blk.space_id = 1;
330 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
331 fadt->x_pm_tmr_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100332 fadt->x_pm_tmr_blk.access_size = 0;
Duncan Laurie662b6cb2018-01-30 09:58:07 -0800333 fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
334 fadt->x_pm_tmr_blk.addrh = 0x0;
Lee Leahyb0005132015-05-12 18:19:47 -0700335
336 fadt->x_gpe0_blk.space_id = 0;
337 fadt->x_gpe0_blk.bit_width = 0;
338 fadt->x_gpe0_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100339 fadt->x_gpe0_blk.access_size = 0;
Lee Leahyb0005132015-05-12 18:19:47 -0700340 fadt->x_gpe0_blk.addrl = 0;
341 fadt->x_gpe0_blk.addrh = 0;
342
343 fadt->x_gpe1_blk.space_id = 1;
344 fadt->x_gpe1_blk.bit_width = 0;
345 fadt->x_gpe1_blk.bit_offset = 0;
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100346 fadt->x_gpe1_blk.access_size = 0;
Lee Leahyb0005132015-05-12 18:19:47 -0700347 fadt->x_gpe1_blk.addrl = 0x0;
348 fadt->x_gpe1_blk.addrh = 0x0;
349}
350
Jacob Garber9172b692019-06-26 16:18:16 -0600351static void write_c_state_entries(acpi_cstate_t *map, const int *set, size_t max_c_state)
Lee Leahyb0005132015-05-12 18:19:47 -0700352{
Jacob Garber9172b692019-06-26 16:18:16 -0600353 for (size_t i = 0; i < max_c_state; i++) {
Lee Leahyb0005132015-05-12 18:19:47 -0700354 memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t));
355 map[i].ctype = i + 1;
356 }
357
358 /* Generate C-state tables */
Jacob Garber9172b692019-06-26 16:18:16 -0600359 acpigen_write_CST_package(map, max_c_state);
360}
361
362static void generate_c_state_entries(int s0ix_enable)
363{
364 if (s0ix_enable) {
365 acpi_cstate_t map[ARRAY_SIZE(cstate_set_s0ix)];
366 write_c_state_entries(map, cstate_set_s0ix, ARRAY_SIZE(map));
367 } else {
368 acpi_cstate_t map[ARRAY_SIZE(cstate_set_non_s0ix)];
369 write_c_state_entries(map, cstate_set_non_s0ix, ARRAY_SIZE(map));
370 }
Lee Leahyb0005132015-05-12 18:19:47 -0700371}
372
373static int calculate_power(int tdp, int p1_ratio, int ratio)
374{
375 u32 m;
376 u32 power;
377
378 /*
379 * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2
380 *
381 * Power = (ratio / p1_ratio) * m * tdp
382 */
383
384 m = (110000 - ((p1_ratio - ratio) * 625)) / 11;
385 m = (m * m) / 1000;
386
387 power = ((ratio * 100000 / p1_ratio) / 100);
388 power *= (m / 100) * (tdp / 1000);
389 power /= 1000;
390
391 return (int)power;
392}
393
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700394static void generate_p_state_entries(int core, int cores_per_package)
Lee Leahyb0005132015-05-12 18:19:47 -0700395{
396 int ratio_min, ratio_max, ratio_turbo, ratio_step;
397 int coord_type, power_max, power_unit, num_entries;
398 int ratio, power, clock, clock_max;
399 msr_t msr;
400
401 /* Determine P-state coordination type from MISC_PWR_MGMT[0] */
402 msr = rdmsr(MSR_MISC_PWR_MGMT);
403 if (msr.lo & MISC_PWR_MGMT_EIST_HW_DIS)
404 coord_type = SW_ANY;
405 else
406 coord_type = HW_ALL;
407
408 /* Get bus ratio limits and calculate clock speeds */
409 msr = rdmsr(MSR_PLATFORM_INFO);
410 ratio_min = (msr.hi >> (40-32)) & 0xff; /* Max Efficiency Ratio */
411
412 /* Determine if this CPU has configurable TDP */
413 if (cpu_config_tdp_levels()) {
414 /* Set max ratio to nominal TDP ratio */
415 msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
416 ratio_max = msr.lo & 0xff;
417 } else {
418 /* Max Non-Turbo Ratio */
419 ratio_max = (msr.lo >> 8) & 0xff;
420 }
Aamir Bohra1041d392017-06-02 11:56:14 +0530421 clock_max = ratio_max * CONFIG_CPU_BCLK_MHZ;
Lee Leahyb0005132015-05-12 18:19:47 -0700422
423 /* Calculate CPU TDP in mW */
424 msr = rdmsr(MSR_PKG_POWER_SKU_UNIT);
425 power_unit = 2 << ((msr.lo & 0xf) - 1);
426 msr = rdmsr(MSR_PKG_POWER_SKU);
427 power_max = ((msr.lo & 0x7fff) / power_unit) * 1000;
428
429 /* Write _PCT indicating use of FFixedHW */
430 acpigen_write_empty_PCT();
431
432 /* Write _PPC with no limit on supported P-state */
433 acpigen_write_PPC_NVS();
434
435 /* Write PSD indicating configured coordination type */
436 acpigen_write_PSD_package(core, 1, coord_type);
437
438 /* Add P-state entries in _PSS table */
439 acpigen_write_name("_PSS");
440
441 /* Determine ratio points */
442 ratio_step = PSS_RATIO_STEP;
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700443 num_entries = ((ratio_max - ratio_min) / ratio_step) + 1;
444 if (num_entries > PSS_MAX_ENTRIES) {
445 ratio_step += 1;
446 num_entries = ((ratio_max - ratio_min) / ratio_step) + 1;
Lee Leahyb0005132015-05-12 18:19:47 -0700447 }
448
449 /* P[T] is Turbo state if enabled */
450 if (get_turbo_state() == TURBO_ENABLED) {
451 /* _PSS package count including Turbo */
452 acpigen_write_package(num_entries + 2);
453
454 msr = rdmsr(MSR_TURBO_RATIO_LIMIT);
455 ratio_turbo = msr.lo & 0xff;
456
457 /* Add entry for Turbo ratio */
458 acpigen_write_PSS_package(
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700459 clock_max + 1, /* MHz */
460 power_max, /* mW */
461 PSS_LATENCY_TRANSITION, /* lat1 */
462 PSS_LATENCY_BUSMASTER, /* lat2 */
463 ratio_turbo << 8, /* control */
464 ratio_turbo << 8); /* status */
Lee Leahyb0005132015-05-12 18:19:47 -0700465 } else {
466 /* _PSS package count without Turbo */
467 acpigen_write_package(num_entries + 1);
468 }
469
470 /* First regular entry is max non-turbo ratio */
471 acpigen_write_PSS_package(
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700472 clock_max, /* MHz */
473 power_max, /* mW */
474 PSS_LATENCY_TRANSITION, /* lat1 */
475 PSS_LATENCY_BUSMASTER, /* lat2 */
476 ratio_max << 8, /* control */
477 ratio_max << 8); /* status */
Lee Leahyb0005132015-05-12 18:19:47 -0700478
479 /* Generate the remaining entries */
480 for (ratio = ratio_min + ((num_entries - 1) * ratio_step);
481 ratio >= ratio_min; ratio -= ratio_step) {
482
483 /* Calculate power at this ratio */
484 power = calculate_power(power_max, ratio_max, ratio);
Aamir Bohra1041d392017-06-02 11:56:14 +0530485 clock = ratio * CONFIG_CPU_BCLK_MHZ;
Lee Leahyb0005132015-05-12 18:19:47 -0700486
487 acpigen_write_PSS_package(
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700488 clock, /* MHz */
489 power, /* mW */
490 PSS_LATENCY_TRANSITION, /* lat1 */
491 PSS_LATENCY_BUSMASTER, /* lat2 */
492 ratio << 8, /* control */
493 ratio << 8); /* status */
Lee Leahyb0005132015-05-12 18:19:47 -0700494 }
495
496 /* Fix package length */
497 acpigen_pop_len();
498}
499
Elyes HAOUAS143fb462018-05-25 12:56:45 +0200500void generate_cpu_entries(struct device *device)
Lee Leahyb0005132015-05-12 18:19:47 -0700501{
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700502 int core_id, cpu_id, pcontrol_blk = ACPI_BASE_ADDRESS, plen = 6;
Lee Leahyb0005132015-05-12 18:19:47 -0700503 int totalcores = dev_count_cpu();
504 int cores_per_package = get_cores_per_package();
505 int numcpus = totalcores/cores_per_package;
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300506 config_t *config = config_of_path(SA_DEVFN_ROOT);
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700507 int is_s0ix_enable = config->s0ix_enable;
Lee Leahyb0005132015-05-12 18:19:47 -0700508
509 printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n",
510 numcpus, cores_per_package);
511
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300512 if (config->eist_enable && config->speed_shift_enable) {
Matt Delco9084c3c2018-07-27 14:17:29 -0700513 struct cppc_config cppc_config;
514 cpu_init_cppc_config(&cppc_config, 2 /* version 2 */);
515 acpigen_write_CPPC_package(&cppc_config);
516 }
517
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700518 for (cpu_id = 0; cpu_id < numcpus; cpu_id++) {
519 for (core_id = 0; core_id < cores_per_package; core_id++) {
520 if (core_id > 0) {
Lee Leahyb0005132015-05-12 18:19:47 -0700521 pcontrol_blk = 0;
522 plen = 0;
523 }
524
525 /* Generate processor \_PR.CPUx */
526 acpigen_write_processor(
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700527 cpu_id*cores_per_package+core_id,
Lee Leahyb0005132015-05-12 18:19:47 -0700528 pcontrol_blk, plen);
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700529 /* Generate C-state tables */
Jacob Garber9172b692019-06-26 16:18:16 -0600530 generate_c_state_entries(is_s0ix_enable);
Lee Leahyb0005132015-05-12 18:19:47 -0700531
Matt Delco9084c3c2018-07-27 14:17:29 -0700532 if (config->eist_enable) {
Subrata Banik6b45ee42017-05-12 11:43:57 +0530533 /* Generate P-state tables */
534 generate_p_state_entries(core_id,
535 cores_per_package);
Matt Delco9084c3c2018-07-27 14:17:29 -0700536 if (config->speed_shift_enable)
537 acpigen_write_CPPC_method();
538 }
Lee Leahyb0005132015-05-12 18:19:47 -0700539 acpigen_pop_len();
540 }
541 }
Arthur Heymans8afc1352018-11-28 12:07:19 +0100542
543 /* PPKG is usually used for thermal management
544 of the first and only package. */
545 acpigen_write_processor_package("PPKG", 0, cores_per_package);
546
547 /* Add a method to notify processor nodes */
548 acpigen_write_processor_cnot(cores_per_package);
Lee Leahyb0005132015-05-12 18:19:47 -0700549}
550
Nico Huberc37b0e32017-09-18 20:03:46 +0200551static unsigned long acpi_fill_dmar(unsigned long current)
552{
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300553 struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD);
Nico Huberc37b0e32017-09-18 20:03:46 +0200554 const u32 gfx_vtbar = MCHBAR32(GFXVTBAR) & ~0xfff;
555 const bool gfxvten = MCHBAR32(GFXVTBAR) & 1;
556
557 /* iGFX has to be enabled, GFXVTBAR set and in 32-bit space. */
558 if (igfx_dev && igfx_dev->enabled && gfxvten &&
559 gfx_vtbar && !MCHBAR32(GFXVTBAR + 4)) {
Matt DeVilliercbe73ea2018-06-25 14:40:53 -0500560 unsigned long tmp = current;
Nico Huberc37b0e32017-09-18 20:03:46 +0200561
562 current += acpi_create_dmar_drhd(current, 0, 0, gfx_vtbar);
Matt DeVillier7866d492018-03-29 14:59:57 +0200563 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
Nico Huberc37b0e32017-09-18 20:03:46 +0200564
565 acpi_dmar_drhd_fixup(tmp, current);
Matt DeVilliercbe73ea2018-06-25 14:40:53 -0500566
567 /* Add RMRR entry */
568 tmp = current;
569
570 current += acpi_create_dmar_rmrr(current, 0,
571 sa_get_gsm_base(), sa_get_tolud_base() - 1);
572 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
573 acpi_dmar_rmrr_fixup(tmp, current);
Nico Huberc37b0e32017-09-18 20:03:46 +0200574 }
575
Nico Huberc37b0e32017-09-18 20:03:46 +0200576 const u32 vtvc0bar = MCHBAR32(VTVC0BAR) & ~0xfff;
577 const bool vtvc0en = MCHBAR32(VTVC0BAR) & 1;
578
579 /* General VTBAR has to be set and in 32-bit space. */
Angel Ponsef879a82019-08-30 19:42:23 +0200580 if (vtvc0bar && vtvc0en && !MCHBAR32(VTVC0BAR + 4)) {
Nico Huberc37b0e32017-09-18 20:03:46 +0200581 const unsigned long tmp = current;
582
Angel Ponsef879a82019-08-30 19:42:23 +0200583 current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
Nico Huberc37b0e32017-09-18 20:03:46 +0200584
Angel Ponsef879a82019-08-30 19:42:23 +0200585 current += acpi_create_dmar_ds_ioapic(current, 2, V_P2SB_IBDF_BUS,
586 V_P2SB_IBDF_DEV, V_P2SB_IBDF_FUN);
Nico Huberc37b0e32017-09-18 20:03:46 +0200587
Angel Ponsef879a82019-08-30 19:42:23 +0200588 current += acpi_create_dmar_ds_msi_hpet(current, 0, V_P2SB_HBDF_BUS,
589 V_P2SB_HBDF_DEV, V_P2SB_HBDF_FUN);
Nico Huberc37b0e32017-09-18 20:03:46 +0200590
591 acpi_dmar_drhd_fixup(tmp, current);
592 }
593
594 return current;
595}
596
597unsigned long northbridge_write_acpi_tables(struct device *const dev,
598 unsigned long current,
599 struct acpi_rsdp *const rsdp)
600{
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300601 const struct soc_intel_skylake_config *const config = config_of(dev);
Nico Huberc37b0e32017-09-18 20:03:46 +0200602 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
603
604 /* Create DMAR table only if we have VT-d capability. */
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300605 if (config->ignore_vtd || !soc_is_vtd_capable())
Nico Huberc37b0e32017-09-18 20:03:46 +0200606 return current;
607
608 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
609 acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar);
610 current += dmar->header.length;
611 current = acpi_align_current(current);
612 acpi_add_table(rsdp, dmar);
613
614 return current;
615}
616
Lee Leahyb0005132015-05-12 18:19:47 -0700617unsigned long acpi_madt_irq_overrides(unsigned long current)
618{
619 int sci = acpi_sci_irq();
620 acpi_madt_irqoverride_t *irqovr;
621 uint16_t flags = MP_IRQ_TRIGGER_LEVEL;
622
623 /* INT_SRC_OVR */
624 irqovr = (void *)current;
625 current += acpi_create_madt_irqoverride(irqovr, 0, 0, 2, 0);
626
627 if (sci >= 20)
628 flags |= MP_IRQ_POLARITY_LOW;
629 else
630 flags |= MP_IRQ_POLARITY_HIGH;
631
632 /* SCI */
633 irqovr = (void *)current;
634 current += acpi_create_madt_irqoverride(irqovr, 0, sci, sci, flags);
635
636 return current;
637}
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700638
Elyes HAOUAS143fb462018-05-25 12:56:45 +0200639unsigned long southbridge_write_acpi_tables(struct device *device,
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700640 unsigned long current,
641 struct acpi_rsdp *rsdp)
642{
Duncan Laurie93bbd412017-11-11 20:03:29 -0800643 current = acpi_write_dbg2_pci_uart(rsdp, current,
Subrata Banikafa07f72018-05-24 12:21:06 +0530644 uart_get_device(),
Duncan Laurie93bbd412017-11-11 20:03:29 -0800645 ACPI_ACCESS_SIZE_DWORD_ACCESS);
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700646 current = acpi_write_hpet(device, current, rsdp);
Aaron Durbin07a1b282015-12-10 17:07:38 -0600647 return acpi_align_current(current);
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700648}
649
Elyes HAOUAS143fb462018-05-25 12:56:45 +0200650void southbridge_inject_dsdt(struct device *device)
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700651{
652 global_nvs_t *gnvs;
653
654 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
655 if (!gnvs) {
Lee Leahyf4c4ab92017-03-16 17:08:03 -0700656 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700657 if (gnvs)
658 memset(gnvs, 0, sizeof(*gnvs));
659 }
660
661 if (gnvs) {
662 acpi_create_gnvs(gnvs);
Duncan Lauriedb54a672015-09-04 14:19:35 -0700663 acpi_mainboard_gnvs(gnvs);
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700664 /* And tell SMI about it */
665 smm_setup_structures(gnvs, NULL, NULL);
666
667 /* Add it to DSDT. */
668 acpigen_write_scope("\\");
669 acpigen_write_name_dword("NVSA", (u32) gnvs);
670 acpigen_pop_len();
671 }
672}
673
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700674/* Save wake source information for calculating ACPI _SWS values */
675int soc_fill_acpi_wake(uint32_t *pm1, uint32_t **gpe0)
676{
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300677 const struct soc_intel_skylake_config *config = config_of_path(PCH_DEVFN_LPC);
Naresh G Solankia1b35472015-12-11 18:13:02 +0530678 struct chipset_power_state *ps;
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700679 static uint32_t gpe0_sts[GPE0_REG_MAX];
680 uint32_t pm1_en;
Duncan Laurie95f90202016-10-25 20:07:22 -0700681 uint32_t gpe0_std;
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700682 int i;
Aaron Durbin64606ce2016-10-27 09:53:17 -0500683 const int last_index = GPE0_REG_MAX - 1;
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700684
Naresh G Solankia1b35472015-12-11 18:13:02 +0530685 ps = cbmem_find(CBMEM_ID_POWER_STATE);
686 if (ps == NULL)
687 return -1;
688
Duncan Laurie95f90202016-10-25 20:07:22 -0700689 pm1_en = ps->pm1_en;
690 gpe0_std = ps->gpe0_en[3];
691
692 /*
693 * Chipset state in the suspend well (but not RTC) is lost in Deep S3
694 * so enable Deep S3 wake events that are configured by the mainboard
695 */
Duncan Laurie1fe32d62017-04-10 21:02:13 -0700696 if (ps->prev_sleep_state == ACPI_S3 &&
697 (config->deep_s3_enable_ac || config->deep_s3_enable_dc)) {
Duncan Laurie95f90202016-10-25 20:07:22 -0700698 pm1_en |= PWRBTN_STS; /* Always enabled as wake source */
699 if (config->deep_sx_config & DSX_EN_LAN_WAKE_PIN)
700 gpe0_std |= LAN_WAK_EN;
701 if (config->deep_sx_config & DSX_EN_WAKE_PIN)
702 pm1_en |= PCIEXPWAK_STS;
703 }
704
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700705 *pm1 = ps->pm1_sts & pm1_en;
706
707 /* Mask off GPE0 status bits that are not enabled */
708 *gpe0 = &gpe0_sts[0];
Aaron Durbin64606ce2016-10-27 09:53:17 -0500709 for (i = 0; i < last_index; i++)
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700710 gpe0_sts[i] = ps->gpe0_sts[i] & ps->gpe0_en[i];
Aaron Durbin64606ce2016-10-27 09:53:17 -0500711 gpe0_sts[last_index] = ps->gpe0_sts[last_index] & gpe0_std;
Duncan Lauriea1c8b34d2015-09-08 16:12:44 -0700712
713 return GPE0_REG_MAX;
714}
715
Aaron Durbin64031672018-04-21 14:45:32 -0600716__weak void acpi_mainboard_gnvs(global_nvs_t *gnvs)
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700717{
718}
Naresh G Solankia2d40622016-08-30 20:47:13 +0530719
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600720const char *soc_acpi_name(const struct device *dev)
Naresh G Solankia2d40622016-08-30 20:47:13 +0530721{
722 if (dev->path.type == DEVICE_PATH_DOMAIN)
723 return "PCI0";
724
Duncan Lauriebf713b02018-05-07 15:33:18 -0700725 if (dev->path.type == DEVICE_PATH_USB) {
726 switch (dev->path.usb.port_type) {
727 case 0:
728 /* Root Hub */
729 return "RHUB";
730 case 2:
731 /* USB2 ports */
732 switch (dev->path.usb.port_id) {
733 case 0: return "HS01";
734 case 1: return "HS02";
735 case 2: return "HS03";
736 case 3: return "HS04";
737 case 4: return "HS05";
738 case 5: return "HS06";
739 case 6: return "HS07";
740 case 7: return "HS08";
741 case 8: return "HS09";
742 case 9: return "HS10";
743 }
744 break;
745 case 3:
746 /* USB3 ports */
747 switch (dev->path.usb.port_id) {
748 case 0: return "SS01";
749 case 1: return "SS02";
750 case 2: return "SS03";
751 case 3: return "SS04";
752 case 4: return "SS05";
753 case 5: return "SS06";
754 }
755 break;
756 }
757 return NULL;
758 }
759
Naresh G Solankia2d40622016-08-30 20:47:13 +0530760 if (dev->path.type != DEVICE_PATH_PCI)
761 return NULL;
762
763 switch (dev->path.pci.devfn) {
764 case SA_DEVFN_ROOT: return "MCHC";
765 case SA_DEVFN_IGD: return "GFX0";
766 case PCH_DEVFN_ISH: return "ISHB";
767 case PCH_DEVFN_XHCI: return "XHCI";
768 case PCH_DEVFN_USBOTG: return "XDCI";
769 case PCH_DEVFN_THERMAL: return "THRM";
770 case PCH_DEVFN_CIO: return "ICIO";
771 case PCH_DEVFN_I2C0: return "I2C0";
772 case PCH_DEVFN_I2C1: return "I2C1";
773 case PCH_DEVFN_I2C2: return "I2C2";
774 case PCH_DEVFN_I2C3: return "I2C3";
Subrata Banik2ee54db2017-03-05 12:37:00 +0530775 case PCH_DEVFN_CSE: return "CSE1";
776 case PCH_DEVFN_CSE_2: return "CSE2";
777 case PCH_DEVFN_CSE_IDER: return "CSED";
778 case PCH_DEVFN_CSE_KT: return "CSKT";
779 case PCH_DEVFN_CSE_3: return "CSE3";
Naresh G Solankia2d40622016-08-30 20:47:13 +0530780 case PCH_DEVFN_SATA: return "SATA";
781 case PCH_DEVFN_UART2: return "UAR2";
782 case PCH_DEVFN_I2C4: return "I2C4";
783 case PCH_DEVFN_I2C5: return "I2C5";
784 case PCH_DEVFN_PCIE1: return "RP01";
785 case PCH_DEVFN_PCIE2: return "RP02";
786 case PCH_DEVFN_PCIE3: return "RP03";
787 case PCH_DEVFN_PCIE4: return "RP04";
788 case PCH_DEVFN_PCIE5: return "RP05";
789 case PCH_DEVFN_PCIE6: return "RP06";
790 case PCH_DEVFN_PCIE7: return "RP07";
791 case PCH_DEVFN_PCIE8: return "RP08";
792 case PCH_DEVFN_PCIE9: return "RP09";
793 case PCH_DEVFN_PCIE10: return "RP10";
794 case PCH_DEVFN_PCIE11: return "RP11";
795 case PCH_DEVFN_PCIE12: return "RP12";
Maxim Polyakovc6f2b612019-08-23 15:22:21 +0300796 case PCH_DEVFN_PCIE13: return "RP13";
797 case PCH_DEVFN_PCIE14: return "RP14";
798 case PCH_DEVFN_PCIE15: return "RP15";
799 case PCH_DEVFN_PCIE16: return "RP16";
Naresh G Solankia2d40622016-08-30 20:47:13 +0530800 case PCH_DEVFN_UART0: return "UAR0";
801 case PCH_DEVFN_UART1: return "UAR1";
802 case PCH_DEVFN_GSPI0: return "SPI0";
803 case PCH_DEVFN_GSPI1: return "SPI1";
804 case PCH_DEVFN_EMMC: return "EMMC";
805 case PCH_DEVFN_SDIO: return "SDIO";
806 case PCH_DEVFN_SDCARD: return "SDXC";
807 case PCH_DEVFN_LPC: return "LPCB";
808 case PCH_DEVFN_P2SB: return "P2SB";
809 case PCH_DEVFN_PMC: return "PMC_";
810 case PCH_DEVFN_HDA: return "HDAS";
811 case PCH_DEVFN_SMBUS: return "SBUS";
812 case PCH_DEVFN_SPI: return "FSPI";
813 case PCH_DEVFN_GBE: return "IGBE";
814 case PCH_DEVFN_TRACEHUB:return "THUB";
815 }
816
817 return NULL;
818}
Furquan Shaikha6f0b272017-05-23 11:53:47 -0700819
820static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num)
821{
822 /* op (gpio_num) */
823 acpigen_emit_namestring(op);
824 acpigen_write_integer(gpio_num);
825 return 0;
826}
827
828static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num)
829{
830 /* Store (op (gpio_num), Local0) */
831 acpigen_write_store();
832 acpigen_soc_gpio_op(op, gpio_num);
833 acpigen_emit_byte(LOCAL0_OP);
834 return 0;
835}
836
837int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
838{
839 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GRXS", gpio_num);
840}
841
842int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
843{
844 return acpigen_soc_get_gpio_state("\\_SB.PCI0.GTXS", gpio_num);
845}
846
847int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
848{
849 return acpigen_soc_gpio_op("\\_SB.PCI0.STXS", gpio_num);
850}
851
852int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
853{
854 return acpigen_soc_gpio_op("\\_SB.PCI0.CTXS", gpio_num);
855}