blob: 96a142a89eeb64f29e54dff2108225dddd653915 [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Lance Zhaof51b1272015-11-09 17:06:34 -08002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +03004#include <acpi/acpi_gnvs.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07005#include <acpi/acpigen.h>
Elyes HAOUAS20eaef02019-03-29 17:45:28 +01006#include <console/console.h>
Felix Singer6c3a89c2020-07-26 09:26:52 +02007#include <device/device.h>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02008#include <device/mmio.h>
Lance Zhao2fc82d62015-11-16 18:33:21 -08009#include <arch/smp/mpspec.h>
Elyes HAOUAScd4fe0f2019-03-29 17:12:15 +010010#include <assert.h>
Werner Zeh90cc7e22018-12-14 13:26:04 +010011#include <device/pci_ops.h>
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070012#include <cbmem.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070013#include <gpio.h>
14#include <intelblocks/acpi.h>
15#include <intelblocks/pmclib.h>
Pratik Prajapatid06c7642017-10-11 11:52:16 -070016#include <intelblocks/sgx.h>
Werner Zeh90cc7e22018-12-14 13:26:04 +010017#include <intelblocks/p2sb.h>
Lance Zhaoe904c7c2015-11-10 19:00:18 -080018#include <soc/iomap.h>
19#include <soc/pm.h>
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070020#include <soc/nvs.h>
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070021#include <soc/pci_devs.h>
Werner Zeh90cc7e22018-12-14 13:26:04 +010022#include <soc/systemagent.h>
Aaron Durbin9e815402016-09-13 12:31:57 -050023#include <string.h>
Elyes HAOUAS20eaef02019-03-29 17:45:28 +010024
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070025#include "chip.h"
Lance Zhaof51b1272015-11-09 17:06:34 -080026
Hannah Williams0f61da82016-04-18 13:47:08 -070027#define CSTATE_RES(address_space, width, offset, address) \
28 { \
29 .space_id = address_space, \
30 .bit_width = width, \
31 .bit_offset = offset, \
32 .addrl = address, \
33 }
34
Shaunak Sahabd427802017-07-18 00:19:33 -070035static acpi_cstate_t cstate_map[] = {
36 {
37 /* C1 */
38 .ctype = 1, /* ACPI C1 */
39 .latency = 1,
40 .power = 1000,
41 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_FIXED, 0, 0, 0),
42 },
43 {
44 .ctype = 2, /* ACPI C2 */
45 .latency = 50,
46 .power = 10,
47 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x415),
48 },
49 {
50 .ctype = 3, /* ACPI C3 */
51 .latency = 150,
52 .power = 10,
53 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x419),
54 }
55};
56
57uint32_t soc_read_sci_irq_select(void)
Lance Zhaof51b1272015-11-09 17:06:34 -080058{
Shaunak Sahabd427802017-07-18 00:19:33 -070059 uintptr_t pmc_bar = soc_read_pmc_base();
60 return read32((void *)pmc_bar + IRQ_REG);
Lance Zhaof51b1272015-11-09 17:06:34 -080061}
Lance Zhaoe904c7c2015-11-10 19:00:18 -080062
Mario Scheithauer841416f2017-09-18 17:08:48 +020063void soc_write_sci_irq_select(uint32_t scis)
64{
65 uintptr_t pmc_bar = soc_read_pmc_base();
66 write32((void *)pmc_bar + IRQ_REG, scis);
67}
68
Shaunak Sahabd427802017-07-18 00:19:33 -070069acpi_cstate_t *soc_get_cstate_map(size_t *entries)
Lance Zhaoe904c7c2015-11-10 19:00:18 -080070{
Shaunak Sahabd427802017-07-18 00:19:33 -070071 *entries = ARRAY_SIZE(cstate_map);
72 return cstate_map;
Lance Zhaoe904c7c2015-11-10 19:00:18 -080073}
74
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +030075void acpi_create_gnvs(struct global_nvs *gnvs)
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070076{
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070077 struct soc_intel_apollolake_config *cfg;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +030078 cfg = config_of_soc();
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070079
Aaron Durbin9e815402016-09-13 12:31:57 -050080 /* Clear out GNVS. */
81 memset(gnvs, 0, sizeof(*gnvs));
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070082
Julius Wernercd49cce2019-03-05 16:53:33 -080083 if (CONFIG(CONSOLE_CBMEM))
Shaunak Sahabd427802017-07-18 00:19:33 -070084 gnvs->cbmc = (uintptr_t) cbmem_find(CBMEM_ID_CONSOLE);
Furquan Shaikhd01f5a02016-06-13 22:23:49 -070085
Julius Wernercd49cce2019-03-05 16:53:33 -080086 if (CONFIG(CHROMEOS)) {
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070087 /* Initialize Verified Boot data */
Joel Kitching6fbd8742018-08-23 14:56:25 +080088 chromeos_init_chromeos_acpi(&gnvs->chromeos);
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070089 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
90 }
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070091
Shaunak Saha60b46182016-08-02 17:25:13 -070092 /* Set unknown wake source */
93 gnvs->pm1i = ~0ULL;
Aaron Durbin9e815402016-09-13 12:31:57 -050094
Duncan Laurie1d359b52016-09-21 18:30:44 -070095 /* CPU core count */
96 gnvs->pcnt = dev_count_cpu();
97
Aaron Durbin9e815402016-09-13 12:31:57 -050098 /* Enable DPTF based on mainboard configuration */
99 gnvs->dpte = cfg->dptf_enable;
Vaibhav Shankaref8deaf2016-08-23 17:56:17 -0700100
101 /* Assign address of PERST_0 if GPIO is defined in devicetree */
102 if (cfg->prt0_gpio != GPIO_PRT0_UDEF)
Shaunak Sahabd427802017-07-18 00:19:33 -0700103 gnvs->prt0 = (uintptr_t) gpio_dwx_address(cfg->prt0_gpio);
Venkateswarlu Vinjamuri6dd7b402017-02-24 15:37:30 -0800104
Venkateswarlu Vinjamuri99ce8a92017-03-22 18:24:52 -0700105 /* Get sdcard cd GPIO portid if GPIO is defined in devicetree.
106 * Get offset of sdcard cd pin.
107 */
108 if (cfg->sdcard_cd_gpio) {
109 gnvs->scdp = gpio_get_pad_portid(cfg->sdcard_cd_gpio);
110 gnvs->scdo = gpio_acpi_pin(cfg->sdcard_cd_gpio);
111 }
Pratik Prajapatid06c7642017-10-11 11:52:16 -0700112
Julius Wernercd49cce2019-03-05 16:53:33 -0800113 if (CONFIG(SOC_INTEL_COMMON_BLOCK_SGX))
Pratik Prajapatid06c7642017-10-11 11:52:16 -0700114 sgx_fill_gnvs(gnvs);
Subrata Banikb6df6b02020-01-03 15:29:02 +0530115
116 /* Fill in Above 4GB MMIO resource */
117 sa_fill_gnvs(gnvs);
Shaunak Saha60b46182016-08-02 17:25:13 -0700118}
119
Shaunak Sahabd427802017-07-18 00:19:33 -0700120uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
121 const struct chipset_power_state *ps)
Shaunak Saha60b46182016-08-02 17:25:13 -0700122{
Shaunak Saha60b46182016-08-02 17:25:13 -0700123 /*
Shaunak Saha60b46182016-08-02 17:25:13 -0700124 * WAK_STS bit is set when the system is in one of the sleep states
125 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
126 * this bit, the PMC will transition the system to the ON state and
127 * can only be set by hardware and can only be cleared by writing a one
128 * to this bit position.
129 */
Shaunak Saha60b46182016-08-02 17:25:13 -0700130
Shaunak Sahabd427802017-07-18 00:19:33 -0700131 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
132 return generic_pm1_en;
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700133}
134
Shaunak Sahabd427802017-07-18 00:19:33 -0700135int soc_madt_sci_irq_polarity(int sci)
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700136{
Shaunak Sahabd427802017-07-18 00:19:33 -0700137 return MP_IRQ_POLARITY_LOW;
Hannah Williams0f61da82016-04-18 13:47:08 -0700138}
139
Shaunak Sahabd427802017-07-18 00:19:33 -0700140void soc_fill_fadt(acpi_fadt_t *fadt)
Hannah Williams0f61da82016-04-18 13:47:08 -0700141{
Shaunak Saha7210ec02017-12-13 09:37:05 -0800142 const struct soc_intel_apollolake_config *cfg;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300143 cfg = config_of_soc();
Shaunak Saha7210ec02017-12-13 09:37:05 -0800144
Shaunak Sahabd427802017-07-18 00:19:33 -0700145 fadt->pm_tmr_blk = ACPI_BASE_ADDRESS + PM1_TMR;
146
147 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
148 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
149
150 fadt->pm_tmr_len = 4;
151 fadt->duty_width = 3;
152
153 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
154
Elyes HAOUAS04071f42020-07-20 17:05:24 +0200155 fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO;
Shaunak Sahabd427802017-07-18 00:19:33 -0700156 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
157 fadt->x_pm_tmr_blk.addrl = ACPI_BASE_ADDRESS + PM1_TMR;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100158 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Shaunak Saha7210ec02017-12-13 09:37:05 -0800159
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300160 if (cfg->lpss_s0ix_enable)
Shaunak Saha7210ec02017-12-13 09:37:05 -0800161 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
Shaunak Sahabd427802017-07-18 00:19:33 -0700162}
163
Werner Zeh90cc7e22018-12-14 13:26:04 +0100164static unsigned long soc_fill_dmar(unsigned long current)
165{
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300166 struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD);
Werner Zeh90cc7e22018-12-14 13:26:04 +0100167 uint64_t gfxvtbar = MCHBAR64(GFXVTBAR) & VTBAR_MASK;
168 uint64_t defvtbar = MCHBAR64(DEFVTBAR) & VTBAR_MASK;
169 bool gfxvten = MCHBAR32(GFXVTBAR) & VTBAR_ENABLED;
170 bool defvten = MCHBAR32(DEFVTBAR) & VTBAR_ENABLED;
171 unsigned long tmp;
172
173 /* IGD has to be enabled, GFXVTBAR set and enabled. */
Felix Singer6c3a89c2020-07-26 09:26:52 +0200174 if (is_dev_enabled(igfx_dev) && gfxvtbar && gfxvten) {
Werner Zeh90cc7e22018-12-14 13:26:04 +0100175 tmp = current;
176
177 current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
178 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
179 acpi_dmar_drhd_fixup(tmp, current);
180
181 /* Add RMRR entry */
182 tmp = current;
183 current += acpi_create_dmar_rmrr(current, 0,
184 sa_get_gsm_base(), sa_get_tolud_base() - 1);
185 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
186 acpi_dmar_rmrr_fixup(tmp, current);
187 }
188
189 /* DEFVTBAR has to be set and enabled. */
190 if (defvtbar && defvten) {
191 tmp = current;
192 /*
193 * P2SB may already be hidden. There's no clear rule, when.
194 * It is needed to get bus, device and function for IOAPIC and
195 * HPET device which is stored in P2SB device. So unhide it to
196 * get the info and hide it again when done.
197 */
198 p2sb_unhide();
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300199 struct device *p2sb_dev = pcidev_path_on_root(PCH_DEVFN_P2SB);
Werner Zeh90cc7e22018-12-14 13:26:04 +0100200 uint16_t ibdf = pci_read_config16(p2sb_dev, PCH_P2SB_IBDF);
201 uint16_t hbdf = pci_read_config16(p2sb_dev, PCH_P2SB_HBDF);
202 p2sb_hide();
203
204 current += acpi_create_dmar_drhd(current,
205 DRHD_INCLUDE_PCI_ALL, 0, defvtbar);
206 current += acpi_create_dmar_ds_ioapic(current,
207 2, ibdf >> 8, PCI_SLOT(ibdf), PCI_FUNC(ibdf));
208 current += acpi_create_dmar_ds_msi_hpet(current,
209 0, hbdf >> 8, PCI_SLOT(hbdf), PCI_FUNC(hbdf));
210 acpi_dmar_drhd_fixup(tmp, current);
211 }
212
213 return current;
214}
215
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700216unsigned long sa_write_acpi_tables(const struct device *const dev,
Werner Zeh90cc7e22018-12-14 13:26:04 +0100217 unsigned long current,
218 struct acpi_rsdp *const rsdp)
219{
220 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
221
222 /* Create DMAR table only if virtualization is enabled. Due to some
223 * constraints on Apollo Lake SoC (some stepping affected), VTD could
224 * not be enabled together with IPU. Doing so will override and disable
225 * VTD while leaving CAPID0_A still reporting that VTD is available.
226 * As in this case FSP will lock VTD to disabled state, we need to make
227 * sure that DMAR table generation only happens when at least DEFVTBAR
228 * is enabled. Otherwise the DMAR header will be generated while the
229 * content of the table will be missing.
230 */
231
232 if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE) ||
233 !(MCHBAR32(DEFVTBAR) & VTBAR_ENABLED))
234 return current;
235
236 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
237 acpi_create_dmar(dmar, DMAR_INTR_REMAP, soc_fill_dmar);
238 current += dmar->header.length;
239 current = acpi_align_current(current);
240 acpi_add_table(rsdp, dmar);
241 current = acpi_align_current(current);
242
243 return current;
244}
245
Shaunak Sahabd427802017-07-18 00:19:33 -0700246void soc_power_states_generation(int core_id, int cores_per_package)
247{
248 /* Generate P-state tables */
249 generate_p_state_entries(core_id, cores_per_package);
250
251 /* Generate T-state tables */
252 generate_t_state_entries(core_id, cores_per_package);
Hannah Williams0f61da82016-04-18 13:47:08 -0700253}
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700254
255static void acpigen_soc_get_dw0_in_local5(uintptr_t addr)
256{
257 /*
258 * Store (\_SB.GPC0 (addr), Local5)
259 * \_SB.GPC0 is used to read cfg0 value from dw0. It is defined in
260 * gpiolib.asl.
261 */
262 acpigen_write_store();
263 acpigen_emit_namestring("\\_SB.GPC0");
264 acpigen_write_integer(addr);
265 acpigen_emit_byte(LOCAL5_OP);
266}
267
268static int acpigen_soc_get_gpio_val(unsigned int gpio_num, uint32_t mask)
269{
Lee Leahyd8fb3622017-03-09 10:10:25 -0800270 assert(gpio_num < TOTAL_PADS);
Shaunak Sahabd427802017-07-18 00:19:33 -0700271 uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num);
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700272
273 acpigen_soc_get_dw0_in_local5(addr);
274
275 /* If (And (Local5, mask)) */
276 acpigen_write_if_and(LOCAL5_OP, mask);
277
278 /* Store (One, Local0) */
279 acpigen_write_store_ops(ONE_OP, LOCAL0_OP);
280
281 acpigen_pop_len(); /* If */
282
283 /* Else */
284 acpigen_write_else();
285
286 /* Store (Zero, Local0) */
287 acpigen_write_store_ops(ZERO_OP, LOCAL0_OP);
288
289 acpigen_pop_len(); /* Else */
290
291 return 0;
292}
293
294static int acpigen_soc_set_gpio_val(unsigned int gpio_num, uint32_t val)
295{
Lee Leahyd8fb3622017-03-09 10:10:25 -0800296 assert(gpio_num < TOTAL_PADS);
Shaunak Sahabd427802017-07-18 00:19:33 -0700297 uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num);
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700298
299 acpigen_soc_get_dw0_in_local5(addr);
300
301 if (val) {
302 /* Or (Local5, PAD_CFG0_TX_STATE, Local5) */
303 acpigen_write_or(LOCAL5_OP, PAD_CFG0_TX_STATE, LOCAL5_OP);
304 } else {
305 /* Not (PAD_CFG0_TX_STATE, Local6) */
306 acpigen_write_not(PAD_CFG0_TX_STATE, LOCAL6_OP);
307
308 /* And (Local5, Local6, Local5) */
309 acpigen_write_and(LOCAL5_OP, LOCAL6_OP, LOCAL5_OP);
310 }
311
312 /*
313 * \_SB.SPC0 (addr, Local5)
314 * \_SB.SPC0 is used to write cfg0 value in dw0. It is defined in
315 * gpiolib.asl.
316 */
317 acpigen_emit_namestring("\\_SB.SPC0");
318 acpigen_write_integer(addr);
319 acpigen_emit_byte(LOCAL5_OP);
320
321 return 0;
322}
323
324int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
325{
326 return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_RX_STATE);
327}
328
329int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
330{
331 return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_TX_STATE);
332}
333
334int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
335{
336 return acpigen_soc_set_gpio_val(gpio_num, 1);
337}
338
339int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
340{
341 return acpigen_soc_set_gpio_val(gpio_num, 0);
342}