blob: f729f3139e4bbca63fd8e568143faf8df4c73a83 [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;
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +030093 cfg = config_of_path(SA_DEVFN_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 /* Enable DPTF based on mainboard configuration */
114 gnvs->dpte = cfg->dptf_enable;
Vaibhav Shankaref8deaf2016-08-23 17:56:17 -0700115
116 /* Assign address of PERST_0 if GPIO is defined in devicetree */
117 if (cfg->prt0_gpio != GPIO_PRT0_UDEF)
Shaunak Sahabd427802017-07-18 00:19:33 -0700118 gnvs->prt0 = (uintptr_t) gpio_dwx_address(cfg->prt0_gpio);
Venkateswarlu Vinjamuri6dd7b402017-02-24 15:37:30 -0800119
Venkateswarlu Vinjamuri99ce8a92017-03-22 18:24:52 -0700120 /* Get sdcard cd GPIO portid if GPIO is defined in devicetree.
121 * Get offset of sdcard cd pin.
122 */
123 if (cfg->sdcard_cd_gpio) {
124 gnvs->scdp = gpio_get_pad_portid(cfg->sdcard_cd_gpio);
125 gnvs->scdo = gpio_acpi_pin(cfg->sdcard_cd_gpio);
126 }
Pratik Prajapatid06c7642017-10-11 11:52:16 -0700127
Julius Wernercd49cce2019-03-05 16:53:33 -0800128 if (CONFIG(SOC_INTEL_COMMON_BLOCK_SGX))
Pratik Prajapatid06c7642017-10-11 11:52:16 -0700129 sgx_fill_gnvs(gnvs);
Shaunak Saha60b46182016-08-02 17:25:13 -0700130}
131
Shaunak Sahabd427802017-07-18 00:19:33 -0700132uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
133 const struct chipset_power_state *ps)
Shaunak Saha60b46182016-08-02 17:25:13 -0700134{
Shaunak Saha60b46182016-08-02 17:25:13 -0700135 /*
Shaunak Saha60b46182016-08-02 17:25:13 -0700136 * WAK_STS bit is set when the system is in one of the sleep states
137 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
138 * this bit, the PMC will transition the system to the ON state and
139 * can only be set by hardware and can only be cleared by writing a one
140 * to this bit position.
141 */
Shaunak Saha60b46182016-08-02 17:25:13 -0700142
Shaunak Sahabd427802017-07-18 00:19:33 -0700143 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
144 return generic_pm1_en;
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700145}
146
Shaunak Sahabd427802017-07-18 00:19:33 -0700147int soc_madt_sci_irq_polarity(int sci)
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700148{
Shaunak Sahabd427802017-07-18 00:19:33 -0700149 return MP_IRQ_POLARITY_LOW;
Hannah Williams0f61da82016-04-18 13:47:08 -0700150}
151
Shaunak Sahabd427802017-07-18 00:19:33 -0700152void soc_fill_fadt(acpi_fadt_t *fadt)
Hannah Williams0f61da82016-04-18 13:47:08 -0700153{
Shaunak Saha7210ec02017-12-13 09:37:05 -0800154 const struct soc_intel_apollolake_config *cfg;
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300155 cfg = config_of_path(SA_DEVFN_ROOT);
Shaunak Saha7210ec02017-12-13 09:37:05 -0800156
Shaunak Sahabd427802017-07-18 00:19:33 -0700157 fadt->pm_tmr_blk = ACPI_BASE_ADDRESS + PM1_TMR;
158
159 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
160 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
161
162 fadt->pm_tmr_len = 4;
163 fadt->duty_width = 3;
164
165 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
166
167 fadt->x_pm_tmr_blk.space_id = 1;
168 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
169 fadt->x_pm_tmr_blk.addrl = ACPI_BASE_ADDRESS + PM1_TMR;
Shaunak Saha7210ec02017-12-13 09:37:05 -0800170
Shaunak Saha7210ec02017-12-13 09:37:05 -0800171
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300172 if (cfg->lpss_s0ix_enable)
Shaunak Saha7210ec02017-12-13 09:37:05 -0800173 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
Shaunak Sahabd427802017-07-18 00:19:33 -0700174}
175
Werner Zeh90cc7e22018-12-14 13:26:04 +0100176static unsigned long soc_fill_dmar(unsigned long current)
177{
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300178 struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD);
Werner Zeh90cc7e22018-12-14 13:26:04 +0100179 uint64_t gfxvtbar = MCHBAR64(GFXVTBAR) & VTBAR_MASK;
180 uint64_t defvtbar = MCHBAR64(DEFVTBAR) & VTBAR_MASK;
181 bool gfxvten = MCHBAR32(GFXVTBAR) & VTBAR_ENABLED;
182 bool defvten = MCHBAR32(DEFVTBAR) & VTBAR_ENABLED;
183 unsigned long tmp;
184
185 /* IGD has to be enabled, GFXVTBAR set and enabled. */
186 if (igfx_dev && igfx_dev->enabled && gfxvtbar && gfxvten) {
187 tmp = current;
188
189 current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
190 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
191 acpi_dmar_drhd_fixup(tmp, current);
192
193 /* Add RMRR entry */
194 tmp = current;
195 current += acpi_create_dmar_rmrr(current, 0,
196 sa_get_gsm_base(), sa_get_tolud_base() - 1);
197 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
198 acpi_dmar_rmrr_fixup(tmp, current);
199 }
200
201 /* DEFVTBAR has to be set and enabled. */
202 if (defvtbar && defvten) {
203 tmp = current;
204 /*
205 * P2SB may already be hidden. There's no clear rule, when.
206 * It is needed to get bus, device and function for IOAPIC and
207 * HPET device which is stored in P2SB device. So unhide it to
208 * get the info and hide it again when done.
209 */
210 p2sb_unhide();
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300211 struct device *p2sb_dev = pcidev_path_on_root(PCH_DEVFN_P2SB);
Werner Zeh90cc7e22018-12-14 13:26:04 +0100212 uint16_t ibdf = pci_read_config16(p2sb_dev, PCH_P2SB_IBDF);
213 uint16_t hbdf = pci_read_config16(p2sb_dev, PCH_P2SB_HBDF);
214 p2sb_hide();
215
216 current += acpi_create_dmar_drhd(current,
217 DRHD_INCLUDE_PCI_ALL, 0, defvtbar);
218 current += acpi_create_dmar_ds_ioapic(current,
219 2, ibdf >> 8, PCI_SLOT(ibdf), PCI_FUNC(ibdf));
220 current += acpi_create_dmar_ds_msi_hpet(current,
221 0, hbdf >> 8, PCI_SLOT(hbdf), PCI_FUNC(hbdf));
222 acpi_dmar_drhd_fixup(tmp, current);
223 }
224
225 return current;
226}
227
228unsigned long sa_write_acpi_tables(struct device *const dev,
229 unsigned long current,
230 struct acpi_rsdp *const rsdp)
231{
232 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
233
234 /* Create DMAR table only if virtualization is enabled. Due to some
235 * constraints on Apollo Lake SoC (some stepping affected), VTD could
236 * not be enabled together with IPU. Doing so will override and disable
237 * VTD while leaving CAPID0_A still reporting that VTD is available.
238 * As in this case FSP will lock VTD to disabled state, we need to make
239 * sure that DMAR table generation only happens when at least DEFVTBAR
240 * is enabled. Otherwise the DMAR header will be generated while the
241 * content of the table will be missing.
242 */
243
244 if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE) ||
245 !(MCHBAR32(DEFVTBAR) & VTBAR_ENABLED))
246 return current;
247
248 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
249 acpi_create_dmar(dmar, DMAR_INTR_REMAP, soc_fill_dmar);
250 current += dmar->header.length;
251 current = acpi_align_current(current);
252 acpi_add_table(rsdp, dmar);
253 current = acpi_align_current(current);
254
255 return current;
256}
257
Shaunak Sahabd427802017-07-18 00:19:33 -0700258void soc_power_states_generation(int core_id, int cores_per_package)
259{
260 /* Generate P-state tables */
261 generate_p_state_entries(core_id, cores_per_package);
262
263 /* Generate T-state tables */
264 generate_t_state_entries(core_id, cores_per_package);
Hannah Williams0f61da82016-04-18 13:47:08 -0700265}
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700266
267static void acpigen_soc_get_dw0_in_local5(uintptr_t addr)
268{
269 /*
270 * Store (\_SB.GPC0 (addr), Local5)
271 * \_SB.GPC0 is used to read cfg0 value from dw0. It is defined in
272 * gpiolib.asl.
273 */
274 acpigen_write_store();
275 acpigen_emit_namestring("\\_SB.GPC0");
276 acpigen_write_integer(addr);
277 acpigen_emit_byte(LOCAL5_OP);
278}
279
280static int acpigen_soc_get_gpio_val(unsigned int gpio_num, uint32_t mask)
281{
Lee Leahyd8fb3622017-03-09 10:10:25 -0800282 assert(gpio_num < TOTAL_PADS);
Shaunak Sahabd427802017-07-18 00:19:33 -0700283 uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num);
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700284
285 acpigen_soc_get_dw0_in_local5(addr);
286
287 /* If (And (Local5, mask)) */
288 acpigen_write_if_and(LOCAL5_OP, mask);
289
290 /* Store (One, Local0) */
291 acpigen_write_store_ops(ONE_OP, LOCAL0_OP);
292
293 acpigen_pop_len(); /* If */
294
295 /* Else */
296 acpigen_write_else();
297
298 /* Store (Zero, Local0) */
299 acpigen_write_store_ops(ZERO_OP, LOCAL0_OP);
300
301 acpigen_pop_len(); /* Else */
302
303 return 0;
304}
305
306static int acpigen_soc_set_gpio_val(unsigned int gpio_num, uint32_t val)
307{
Lee Leahyd8fb3622017-03-09 10:10:25 -0800308 assert(gpio_num < TOTAL_PADS);
Shaunak Sahabd427802017-07-18 00:19:33 -0700309 uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num);
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700310
311 acpigen_soc_get_dw0_in_local5(addr);
312
313 if (val) {
314 /* Or (Local5, PAD_CFG0_TX_STATE, Local5) */
315 acpigen_write_or(LOCAL5_OP, PAD_CFG0_TX_STATE, LOCAL5_OP);
316 } else {
317 /* Not (PAD_CFG0_TX_STATE, Local6) */
318 acpigen_write_not(PAD_CFG0_TX_STATE, LOCAL6_OP);
319
320 /* And (Local5, Local6, Local5) */
321 acpigen_write_and(LOCAL5_OP, LOCAL6_OP, LOCAL5_OP);
322 }
323
324 /*
325 * \_SB.SPC0 (addr, Local5)
326 * \_SB.SPC0 is used to write cfg0 value in dw0. It is defined in
327 * gpiolib.asl.
328 */
329 acpigen_emit_namestring("\\_SB.SPC0");
330 acpigen_write_integer(addr);
331 acpigen_emit_byte(LOCAL5_OP);
332
333 return 0;
334}
335
336int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
337{
338 return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_RX_STATE);
339}
340
341int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
342{
343 return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_TX_STATE);
344}
345
346int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
347{
348 return acpigen_soc_set_gpio_val(gpio_num, 1);
349}
350
351int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
352{
353 return acpigen_soc_set_gpio_val(gpio_num, 0);
354}