blob: 6208c9c739d411d501b59d33ea054cab6431fca0 [file] [log] [blame]
Lance Zhaof51b1272015-11-09 17:06:34 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2016 Intel Corp.
Werner Zeh90cc7e22018-12-14 13:26:04 +01005 * Copyright (C) 2017-2019 Siemens AG
Lance Zhaoe904c7c2015-11-10 19:00:18 -08006 * (Written by Lance Zhao <lijian.zhao@intel.com> for Intel Corp.)
Lance Zhaof51b1272015-11-09 17:06:34 -08007 *
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; either version 2 of the License, or
11 * (at your option) any later version.
Martin Rothebabfad2016-04-10 11:09:16 -060012 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Lance Zhaof51b1272015-11-09 17:06:34 -080017 */
18
19#include <arch/acpi.h>
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070020#include <arch/acpigen.h>
Elyes HAOUAS20eaef02019-03-29 17:45:28 +010021#include <console/console.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +020022#include <device/mmio.h>
Lance Zhao2fc82d62015-11-16 18:33:21 -080023#include <arch/smp/mpspec.h>
Elyes HAOUAScd4fe0f2019-03-29 17:12:15 +010024#include <assert.h>
Werner Zeh90cc7e22018-12-14 13:26:04 +010025#include <device/pci_ops.h>
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070026#include <cbmem.h>
Lance Zhaoe904c7c2015-11-10 19:00:18 -080027#include <cpu/x86/smm.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070028#include <gpio.h>
29#include <intelblocks/acpi.h>
30#include <intelblocks/pmclib.h>
Pratik Prajapatid06c7642017-10-11 11:52:16 -070031#include <intelblocks/sgx.h>
Werner Zeh90cc7e22018-12-14 13:26:04 +010032#include <intelblocks/p2sb.h>
Lance Zhaoe904c7c2015-11-10 19:00:18 -080033#include <soc/iomap.h>
34#include <soc/pm.h>
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070035#include <soc/nvs.h>
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070036#include <soc/pci_devs.h>
Werner Zeh90cc7e22018-12-14 13:26:04 +010037#include <soc/systemagent.h>
Aaron Durbin9e815402016-09-13 12:31:57 -050038#include <string.h>
Elyes HAOUAS20eaef02019-03-29 17:45:28 +010039
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070040#include "chip.h"
Lance Zhaof51b1272015-11-09 17:06:34 -080041
Hannah Williams0f61da82016-04-18 13:47:08 -070042#define CSTATE_RES(address_space, width, offset, address) \
43 { \
44 .space_id = address_space, \
45 .bit_width = width, \
46 .bit_offset = offset, \
47 .addrl = address, \
48 }
49
Shaunak Sahabd427802017-07-18 00:19:33 -070050static acpi_cstate_t cstate_map[] = {
51 {
52 /* C1 */
53 .ctype = 1, /* ACPI C1 */
54 .latency = 1,
55 .power = 1000,
56 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_FIXED, 0, 0, 0),
57 },
58 {
59 .ctype = 2, /* ACPI C2 */
60 .latency = 50,
61 .power = 10,
62 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x415),
63 },
64 {
65 .ctype = 3, /* ACPI C3 */
66 .latency = 150,
67 .power = 10,
68 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x419),
69 }
70};
71
72uint32_t soc_read_sci_irq_select(void)
Lance Zhaof51b1272015-11-09 17:06:34 -080073{
Shaunak Sahabd427802017-07-18 00:19:33 -070074 uintptr_t pmc_bar = soc_read_pmc_base();
75 return read32((void *)pmc_bar + IRQ_REG);
Lance Zhaof51b1272015-11-09 17:06:34 -080076}
Lance Zhaoe904c7c2015-11-10 19:00:18 -080077
Mario Scheithauer841416f2017-09-18 17:08:48 +020078void soc_write_sci_irq_select(uint32_t scis)
79{
80 uintptr_t pmc_bar = soc_read_pmc_base();
81 write32((void *)pmc_bar + IRQ_REG, scis);
82}
83
Shaunak Sahabd427802017-07-18 00:19:33 -070084acpi_cstate_t *soc_get_cstate_map(size_t *entries)
Lance Zhaoe904c7c2015-11-10 19:00:18 -080085{
Shaunak Sahabd427802017-07-18 00:19:33 -070086 *entries = ARRAY_SIZE(cstate_map);
87 return cstate_map;
Lance Zhaoe904c7c2015-11-10 19:00:18 -080088}
89
Shaunak Sahabd427802017-07-18 00:19:33 -070090void acpi_create_gnvs(struct global_nvs_t *gnvs)
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070091{
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070092 struct soc_intel_apollolake_config *cfg;
Subrata Banik2ee54db2017-03-05 12:37:00 +053093 struct device *dev = SA_DEV_ROOT;
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070094
Aaron Durbin9e815402016-09-13 12:31:57 -050095 /* Clear out GNVS. */
96 memset(gnvs, 0, sizeof(*gnvs));
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070097
Julius Wernercd49cce2019-03-05 16:53:33 -080098 if (CONFIG(CONSOLE_CBMEM))
Shaunak Sahabd427802017-07-18 00:19:33 -070099 gnvs->cbmc = (uintptr_t) cbmem_find(CBMEM_ID_CONSOLE);
Furquan Shaikhd01f5a02016-06-13 22:23:49 -0700100
Julius Wernercd49cce2019-03-05 16:53:33 -0800101 if (CONFIG(CHROMEOS)) {
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700102 /* Initialize Verified Boot data */
Joel Kitching6fbd8742018-08-23 14:56:25 +0800103 chromeos_init_chromeos_acpi(&gnvs->chromeos);
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700104 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
105 }
Shaunak Sahacd9e1e42016-07-12 01:22:33 -0700106
Shaunak Saha60b46182016-08-02 17:25:13 -0700107 /* Set unknown wake source */
108 gnvs->pm1i = ~0ULL;
Aaron Durbin9e815402016-09-13 12:31:57 -0500109
Duncan Laurie1d359b52016-09-21 18:30:44 -0700110 /* CPU core count */
111 gnvs->pcnt = dev_count_cpu();
112
Aaron Durbin9e815402016-09-13 12:31:57 -0500113 if (!dev || !dev->chip_info) {
114 printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n");
115 return;
116 }
117 cfg = dev->chip_info;
118
119 /* Enable DPTF based on mainboard configuration */
120 gnvs->dpte = cfg->dptf_enable;
Vaibhav Shankaref8deaf2016-08-23 17:56:17 -0700121
122 /* Assign address of PERST_0 if GPIO is defined in devicetree */
123 if (cfg->prt0_gpio != GPIO_PRT0_UDEF)
Shaunak Sahabd427802017-07-18 00:19:33 -0700124 gnvs->prt0 = (uintptr_t) gpio_dwx_address(cfg->prt0_gpio);
Venkateswarlu Vinjamuri6dd7b402017-02-24 15:37:30 -0800125
Venkateswarlu Vinjamuri99ce8a92017-03-22 18:24:52 -0700126 /* Get sdcard cd GPIO portid if GPIO is defined in devicetree.
127 * Get offset of sdcard cd pin.
128 */
129 if (cfg->sdcard_cd_gpio) {
130 gnvs->scdp = gpio_get_pad_portid(cfg->sdcard_cd_gpio);
131 gnvs->scdo = gpio_acpi_pin(cfg->sdcard_cd_gpio);
132 }
Pratik Prajapatid06c7642017-10-11 11:52:16 -0700133
Julius Wernercd49cce2019-03-05 16:53:33 -0800134 if (CONFIG(SOC_INTEL_COMMON_BLOCK_SGX))
Pratik Prajapatid06c7642017-10-11 11:52:16 -0700135 sgx_fill_gnvs(gnvs);
Shaunak Saha60b46182016-08-02 17:25:13 -0700136}
137
Shaunak Sahabd427802017-07-18 00:19:33 -0700138uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
139 const struct chipset_power_state *ps)
Shaunak Saha60b46182016-08-02 17:25:13 -0700140{
Shaunak Saha60b46182016-08-02 17:25:13 -0700141 /*
Shaunak Saha60b46182016-08-02 17:25:13 -0700142 * WAK_STS bit is set when the system is in one of the sleep states
143 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
144 * this bit, the PMC will transition the system to the ON state and
145 * can only be set by hardware and can only be cleared by writing a one
146 * to this bit position.
147 */
Shaunak Saha60b46182016-08-02 17:25:13 -0700148
Shaunak Sahabd427802017-07-18 00:19:33 -0700149 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
150 return generic_pm1_en;
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700151}
152
Shaunak Sahabd427802017-07-18 00:19:33 -0700153int soc_madt_sci_irq_polarity(int sci)
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700154{
Shaunak Sahabd427802017-07-18 00:19:33 -0700155 return MP_IRQ_POLARITY_LOW;
Hannah Williams0f61da82016-04-18 13:47:08 -0700156}
157
Shaunak Sahabd427802017-07-18 00:19:33 -0700158void soc_fill_fadt(acpi_fadt_t *fadt)
Hannah Williams0f61da82016-04-18 13:47:08 -0700159{
Shaunak Saha7210ec02017-12-13 09:37:05 -0800160 const struct soc_intel_apollolake_config *cfg;
161 struct device *dev = SA_DEV_ROOT;
162
Shaunak Sahabd427802017-07-18 00:19:33 -0700163 fadt->pm_tmr_blk = ACPI_BASE_ADDRESS + PM1_TMR;
164
165 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
166 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
167
168 fadt->pm_tmr_len = 4;
169 fadt->duty_width = 3;
170
171 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
172
173 fadt->x_pm_tmr_blk.space_id = 1;
174 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
175 fadt->x_pm_tmr_blk.addrl = ACPI_BASE_ADDRESS + PM1_TMR;
Shaunak Saha7210ec02017-12-13 09:37:05 -0800176
177 if (!dev || !dev->chip_info) {
178 printk(BIOS_ERR, "BUG! Could not find SOC devicetree config\n");
179 return;
180 }
Elyes HAOUAS88607a42018-10-05 10:36:45 +0200181 cfg = dev->chip_info;
Shaunak Saha7210ec02017-12-13 09:37:05 -0800182
183 if(cfg->lpss_s0ix_enable)
184 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
Shaunak Sahabd427802017-07-18 00:19:33 -0700185}
186
Werner Zeh90cc7e22018-12-14 13:26:04 +0100187static unsigned long soc_fill_dmar(unsigned long current)
188{
189 struct device *const igfx_dev = dev_find_slot(0, SA_DEVFN_IGD);
190 uint64_t gfxvtbar = MCHBAR64(GFXVTBAR) & VTBAR_MASK;
191 uint64_t defvtbar = MCHBAR64(DEFVTBAR) & VTBAR_MASK;
192 bool gfxvten = MCHBAR32(GFXVTBAR) & VTBAR_ENABLED;
193 bool defvten = MCHBAR32(DEFVTBAR) & VTBAR_ENABLED;
194 unsigned long tmp;
195
196 /* IGD has to be enabled, GFXVTBAR set and enabled. */
197 if (igfx_dev && igfx_dev->enabled && gfxvtbar && gfxvten) {
198 tmp = current;
199
200 current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
201 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
202 acpi_dmar_drhd_fixup(tmp, current);
203
204 /* Add RMRR entry */
205 tmp = current;
206 current += acpi_create_dmar_rmrr(current, 0,
207 sa_get_gsm_base(), sa_get_tolud_base() - 1);
208 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
209 acpi_dmar_rmrr_fixup(tmp, current);
210 }
211
212 /* DEFVTBAR has to be set and enabled. */
213 if (defvtbar && defvten) {
214 tmp = current;
215 /*
216 * P2SB may already be hidden. There's no clear rule, when.
217 * It is needed to get bus, device and function for IOAPIC and
218 * HPET device which is stored in P2SB device. So unhide it to
219 * get the info and hide it again when done.
220 */
221 p2sb_unhide();
222 struct device *p2sb_dev = dev_find_slot(0, PCH_DEVFN_P2SB);
223 uint16_t ibdf = pci_read_config16(p2sb_dev, PCH_P2SB_IBDF);
224 uint16_t hbdf = pci_read_config16(p2sb_dev, PCH_P2SB_HBDF);
225 p2sb_hide();
226
227 current += acpi_create_dmar_drhd(current,
228 DRHD_INCLUDE_PCI_ALL, 0, defvtbar);
229 current += acpi_create_dmar_ds_ioapic(current,
230 2, ibdf >> 8, PCI_SLOT(ibdf), PCI_FUNC(ibdf));
231 current += acpi_create_dmar_ds_msi_hpet(current,
232 0, hbdf >> 8, PCI_SLOT(hbdf), PCI_FUNC(hbdf));
233 acpi_dmar_drhd_fixup(tmp, current);
234 }
235
236 return current;
237}
238
239unsigned long sa_write_acpi_tables(struct device *const dev,
240 unsigned long current,
241 struct acpi_rsdp *const rsdp)
242{
243 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
244
245 /* Create DMAR table only if virtualization is enabled. Due to some
246 * constraints on Apollo Lake SoC (some stepping affected), VTD could
247 * not be enabled together with IPU. Doing so will override and disable
248 * VTD while leaving CAPID0_A still reporting that VTD is available.
249 * As in this case FSP will lock VTD to disabled state, we need to make
250 * sure that DMAR table generation only happens when at least DEFVTBAR
251 * is enabled. Otherwise the DMAR header will be generated while the
252 * content of the table will be missing.
253 */
254
255 if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE) ||
256 !(MCHBAR32(DEFVTBAR) & VTBAR_ENABLED))
257 return current;
258
259 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
260 acpi_create_dmar(dmar, DMAR_INTR_REMAP, soc_fill_dmar);
261 current += dmar->header.length;
262 current = acpi_align_current(current);
263 acpi_add_table(rsdp, dmar);
264 current = acpi_align_current(current);
265
266 return current;
267}
268
Shaunak Sahabd427802017-07-18 00:19:33 -0700269void soc_power_states_generation(int core_id, int cores_per_package)
270{
271 /* Generate P-state tables */
272 generate_p_state_entries(core_id, cores_per_package);
273
274 /* Generate T-state tables */
275 generate_t_state_entries(core_id, cores_per_package);
Hannah Williams0f61da82016-04-18 13:47:08 -0700276}
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700277
278static void acpigen_soc_get_dw0_in_local5(uintptr_t addr)
279{
280 /*
281 * Store (\_SB.GPC0 (addr), Local5)
282 * \_SB.GPC0 is used to read cfg0 value from dw0. It is defined in
283 * gpiolib.asl.
284 */
285 acpigen_write_store();
286 acpigen_emit_namestring("\\_SB.GPC0");
287 acpigen_write_integer(addr);
288 acpigen_emit_byte(LOCAL5_OP);
289}
290
291static int acpigen_soc_get_gpio_val(unsigned int gpio_num, uint32_t mask)
292{
Lee Leahyd8fb3622017-03-09 10:10:25 -0800293 assert(gpio_num < TOTAL_PADS);
Shaunak Sahabd427802017-07-18 00:19:33 -0700294 uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num);
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700295
296 acpigen_soc_get_dw0_in_local5(addr);
297
298 /* If (And (Local5, mask)) */
299 acpigen_write_if_and(LOCAL5_OP, mask);
300
301 /* Store (One, Local0) */
302 acpigen_write_store_ops(ONE_OP, LOCAL0_OP);
303
304 acpigen_pop_len(); /* If */
305
306 /* Else */
307 acpigen_write_else();
308
309 /* Store (Zero, Local0) */
310 acpigen_write_store_ops(ZERO_OP, LOCAL0_OP);
311
312 acpigen_pop_len(); /* Else */
313
314 return 0;
315}
316
317static int acpigen_soc_set_gpio_val(unsigned int gpio_num, uint32_t val)
318{
Lee Leahyd8fb3622017-03-09 10:10:25 -0800319 assert(gpio_num < TOTAL_PADS);
Shaunak Sahabd427802017-07-18 00:19:33 -0700320 uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num);
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700321
322 acpigen_soc_get_dw0_in_local5(addr);
323
324 if (val) {
325 /* Or (Local5, PAD_CFG0_TX_STATE, Local5) */
326 acpigen_write_or(LOCAL5_OP, PAD_CFG0_TX_STATE, LOCAL5_OP);
327 } else {
328 /* Not (PAD_CFG0_TX_STATE, Local6) */
329 acpigen_write_not(PAD_CFG0_TX_STATE, LOCAL6_OP);
330
331 /* And (Local5, Local6, Local5) */
332 acpigen_write_and(LOCAL5_OP, LOCAL6_OP, LOCAL5_OP);
333 }
334
335 /*
336 * \_SB.SPC0 (addr, Local5)
337 * \_SB.SPC0 is used to write cfg0 value in dw0. It is defined in
338 * gpiolib.asl.
339 */
340 acpigen_emit_namestring("\\_SB.SPC0");
341 acpigen_write_integer(addr);
342 acpigen_emit_byte(LOCAL5_OP);
343
344 return 0;
345}
346
347int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
348{
349 return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_RX_STATE);
350}
351
352int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
353{
354 return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_TX_STATE);
355}
356
357int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
358{
359 return acpigen_soc_set_gpio_val(gpio_num, 1);
360}
361
362int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
363{
364 return acpigen_soc_set_gpio_val(gpio_num, 0);
365}