blob: 1c7a04a703cdb6c8f12efb69d8927c0119c2e996 [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>
Kyösti Mälkki13f66502019-03-03 08:01:05 +02007#include <device/mmio.h>
Lance Zhao2fc82d62015-11-16 18:33:21 -08008#include <arch/smp/mpspec.h>
Elyes HAOUAScd4fe0f2019-03-29 17:12:15 +01009#include <assert.h>
Werner Zeh90cc7e22018-12-14 13:26:04 +010010#include <device/pci_ops.h>
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070011#include <cbmem.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070012#include <gpio.h>
13#include <intelblocks/acpi.h>
14#include <intelblocks/pmclib.h>
Pratik Prajapatid06c7642017-10-11 11:52:16 -070015#include <intelblocks/sgx.h>
Werner Zeh90cc7e22018-12-14 13:26:04 +010016#include <intelblocks/p2sb.h>
Lance Zhaoe904c7c2015-11-10 19:00:18 -080017#include <soc/iomap.h>
18#include <soc/pm.h>
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070019#include <soc/nvs.h>
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070020#include <soc/pci_devs.h>
Werner Zeh90cc7e22018-12-14 13:26:04 +010021#include <soc/systemagent.h>
Aaron Durbin9e815402016-09-13 12:31:57 -050022#include <string.h>
Elyes HAOUAS20eaef02019-03-29 17:45:28 +010023
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070024#include "chip.h"
Lance Zhaof51b1272015-11-09 17:06:34 -080025
Hannah Williams0f61da82016-04-18 13:47:08 -070026#define CSTATE_RES(address_space, width, offset, address) \
27 { \
28 .space_id = address_space, \
29 .bit_width = width, \
30 .bit_offset = offset, \
31 .addrl = address, \
32 }
33
Shaunak Sahabd427802017-07-18 00:19:33 -070034static acpi_cstate_t cstate_map[] = {
35 {
36 /* C1 */
37 .ctype = 1, /* ACPI C1 */
38 .latency = 1,
39 .power = 1000,
40 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_FIXED, 0, 0, 0),
41 },
42 {
43 .ctype = 2, /* ACPI C2 */
44 .latency = 50,
45 .power = 10,
46 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x415),
47 },
48 {
49 .ctype = 3, /* ACPI C3 */
50 .latency = 150,
51 .power = 10,
52 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x419),
53 }
54};
55
56uint32_t soc_read_sci_irq_select(void)
Lance Zhaof51b1272015-11-09 17:06:34 -080057{
Shaunak Sahabd427802017-07-18 00:19:33 -070058 uintptr_t pmc_bar = soc_read_pmc_base();
59 return read32((void *)pmc_bar + IRQ_REG);
Lance Zhaof51b1272015-11-09 17:06:34 -080060}
Lance Zhaoe904c7c2015-11-10 19:00:18 -080061
Mario Scheithauer841416f2017-09-18 17:08:48 +020062void soc_write_sci_irq_select(uint32_t scis)
63{
64 uintptr_t pmc_bar = soc_read_pmc_base();
65 write32((void *)pmc_bar + IRQ_REG, scis);
66}
67
Shaunak Sahabd427802017-07-18 00:19:33 -070068acpi_cstate_t *soc_get_cstate_map(size_t *entries)
Lance Zhaoe904c7c2015-11-10 19:00:18 -080069{
Shaunak Sahabd427802017-07-18 00:19:33 -070070 *entries = ARRAY_SIZE(cstate_map);
71 return cstate_map;
Lance Zhaoe904c7c2015-11-10 19:00:18 -080072}
73
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +030074void acpi_create_gnvs(struct global_nvs *gnvs)
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070075{
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070076 struct soc_intel_apollolake_config *cfg;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +030077 cfg = config_of_soc();
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070078
Aaron Durbin9e815402016-09-13 12:31:57 -050079 /* Clear out GNVS. */
80 memset(gnvs, 0, sizeof(*gnvs));
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070081
Julius Wernercd49cce2019-03-05 16:53:33 -080082 if (CONFIG(CONSOLE_CBMEM))
Shaunak Sahabd427802017-07-18 00:19:33 -070083 gnvs->cbmc = (uintptr_t) cbmem_find(CBMEM_ID_CONSOLE);
Furquan Shaikhd01f5a02016-06-13 22:23:49 -070084
Julius Wernercd49cce2019-03-05 16:53:33 -080085 if (CONFIG(CHROMEOS)) {
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070086 /* Initialize Verified Boot data */
Joel Kitching6fbd8742018-08-23 14:56:25 +080087 chromeos_init_chromeos_acpi(&gnvs->chromeos);
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070088 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
89 }
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070090
Shaunak Saha60b46182016-08-02 17:25:13 -070091 /* Set unknown wake source */
92 gnvs->pm1i = ~0ULL;
Aaron Durbin9e815402016-09-13 12:31:57 -050093
Duncan Laurie1d359b52016-09-21 18:30:44 -070094 /* CPU core count */
95 gnvs->pcnt = dev_count_cpu();
96
Aaron Durbin9e815402016-09-13 12:31:57 -050097 /* Enable DPTF based on mainboard configuration */
98 gnvs->dpte = cfg->dptf_enable;
Vaibhav Shankaref8deaf2016-08-23 17:56:17 -070099
100 /* Assign address of PERST_0 if GPIO is defined in devicetree */
101 if (cfg->prt0_gpio != GPIO_PRT0_UDEF)
Shaunak Sahabd427802017-07-18 00:19:33 -0700102 gnvs->prt0 = (uintptr_t) gpio_dwx_address(cfg->prt0_gpio);
Venkateswarlu Vinjamuri6dd7b402017-02-24 15:37:30 -0800103
Venkateswarlu Vinjamuri99ce8a92017-03-22 18:24:52 -0700104 /* Get sdcard cd GPIO portid if GPIO is defined in devicetree.
105 * Get offset of sdcard cd pin.
106 */
107 if (cfg->sdcard_cd_gpio) {
108 gnvs->scdp = gpio_get_pad_portid(cfg->sdcard_cd_gpio);
109 gnvs->scdo = gpio_acpi_pin(cfg->sdcard_cd_gpio);
110 }
Pratik Prajapatid06c7642017-10-11 11:52:16 -0700111
Julius Wernercd49cce2019-03-05 16:53:33 -0800112 if (CONFIG(SOC_INTEL_COMMON_BLOCK_SGX))
Pratik Prajapatid06c7642017-10-11 11:52:16 -0700113 sgx_fill_gnvs(gnvs);
Subrata Banikb6df6b02020-01-03 15:29:02 +0530114
115 /* Fill in Above 4GB MMIO resource */
116 sa_fill_gnvs(gnvs);
Shaunak Saha60b46182016-08-02 17:25:13 -0700117}
118
Shaunak Sahabd427802017-07-18 00:19:33 -0700119uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
120 const struct chipset_power_state *ps)
Shaunak Saha60b46182016-08-02 17:25:13 -0700121{
Shaunak Saha60b46182016-08-02 17:25:13 -0700122 /*
Shaunak Saha60b46182016-08-02 17:25:13 -0700123 * WAK_STS bit is set when the system is in one of the sleep states
124 * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting
125 * this bit, the PMC will transition the system to the ON state and
126 * can only be set by hardware and can only be cleared by writing a one
127 * to this bit position.
128 */
Shaunak Saha60b46182016-08-02 17:25:13 -0700129
Shaunak Sahabd427802017-07-18 00:19:33 -0700130 generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN;
131 return generic_pm1_en;
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700132}
133
Shaunak Sahabd427802017-07-18 00:19:33 -0700134int soc_madt_sci_irq_polarity(int sci)
Lance Zhao1bd0c0c2016-04-19 18:04:21 -0700135{
Shaunak Sahabd427802017-07-18 00:19:33 -0700136 return MP_IRQ_POLARITY_LOW;
Hannah Williams0f61da82016-04-18 13:47:08 -0700137}
138
Shaunak Sahabd427802017-07-18 00:19:33 -0700139void soc_fill_fadt(acpi_fadt_t *fadt)
Hannah Williams0f61da82016-04-18 13:47:08 -0700140{
Shaunak Saha7210ec02017-12-13 09:37:05 -0800141 const struct soc_intel_apollolake_config *cfg;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300142 cfg = config_of_soc();
Shaunak Saha7210ec02017-12-13 09:37:05 -0800143
Shaunak Sahabd427802017-07-18 00:19:33 -0700144 fadt->pm_tmr_blk = ACPI_BASE_ADDRESS + PM1_TMR;
145
146 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
147 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
148
149 fadt->pm_tmr_len = 4;
150 fadt->duty_width = 3;
151
152 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
153
154 fadt->x_pm_tmr_blk.space_id = 1;
155 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
156 fadt->x_pm_tmr_blk.addrl = ACPI_BASE_ADDRESS + PM1_TMR;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100157 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Shaunak Saha7210ec02017-12-13 09:37:05 -0800158
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300159 if (cfg->lpss_s0ix_enable)
Shaunak Saha7210ec02017-12-13 09:37:05 -0800160 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
Shaunak Sahabd427802017-07-18 00:19:33 -0700161}
162
Werner Zeh90cc7e22018-12-14 13:26:04 +0100163static unsigned long soc_fill_dmar(unsigned long current)
164{
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300165 struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD);
Werner Zeh90cc7e22018-12-14 13:26:04 +0100166 uint64_t gfxvtbar = MCHBAR64(GFXVTBAR) & VTBAR_MASK;
167 uint64_t defvtbar = MCHBAR64(DEFVTBAR) & VTBAR_MASK;
168 bool gfxvten = MCHBAR32(GFXVTBAR) & VTBAR_ENABLED;
169 bool defvten = MCHBAR32(DEFVTBAR) & VTBAR_ENABLED;
170 unsigned long tmp;
171
172 /* IGD has to be enabled, GFXVTBAR set and enabled. */
173 if (igfx_dev && igfx_dev->enabled && gfxvtbar && gfxvten) {
174 tmp = current;
175
176 current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
177 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
178 acpi_dmar_drhd_fixup(tmp, current);
179
180 /* Add RMRR entry */
181 tmp = current;
182 current += acpi_create_dmar_rmrr(current, 0,
183 sa_get_gsm_base(), sa_get_tolud_base() - 1);
184 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
185 acpi_dmar_rmrr_fixup(tmp, current);
186 }
187
188 /* DEFVTBAR has to be set and enabled. */
189 if (defvtbar && defvten) {
190 tmp = current;
191 /*
192 * P2SB may already be hidden. There's no clear rule, when.
193 * It is needed to get bus, device and function for IOAPIC and
194 * HPET device which is stored in P2SB device. So unhide it to
195 * get the info and hide it again when done.
196 */
197 p2sb_unhide();
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300198 struct device *p2sb_dev = pcidev_path_on_root(PCH_DEVFN_P2SB);
Werner Zeh90cc7e22018-12-14 13:26:04 +0100199 uint16_t ibdf = pci_read_config16(p2sb_dev, PCH_P2SB_IBDF);
200 uint16_t hbdf = pci_read_config16(p2sb_dev, PCH_P2SB_HBDF);
201 p2sb_hide();
202
203 current += acpi_create_dmar_drhd(current,
204 DRHD_INCLUDE_PCI_ALL, 0, defvtbar);
205 current += acpi_create_dmar_ds_ioapic(current,
206 2, ibdf >> 8, PCI_SLOT(ibdf), PCI_FUNC(ibdf));
207 current += acpi_create_dmar_ds_msi_hpet(current,
208 0, hbdf >> 8, PCI_SLOT(hbdf), PCI_FUNC(hbdf));
209 acpi_dmar_drhd_fixup(tmp, current);
210 }
211
212 return current;
213}
214
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700215unsigned long sa_write_acpi_tables(const struct device *const dev,
Werner Zeh90cc7e22018-12-14 13:26:04 +0100216 unsigned long current,
217 struct acpi_rsdp *const rsdp)
218{
219 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
220
221 /* Create DMAR table only if virtualization is enabled. Due to some
222 * constraints on Apollo Lake SoC (some stepping affected), VTD could
223 * not be enabled together with IPU. Doing so will override and disable
224 * VTD while leaving CAPID0_A still reporting that VTD is available.
225 * As in this case FSP will lock VTD to disabled state, we need to make
226 * sure that DMAR table generation only happens when at least DEFVTBAR
227 * is enabled. Otherwise the DMAR header will be generated while the
228 * content of the table will be missing.
229 */
230
231 if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE) ||
232 !(MCHBAR32(DEFVTBAR) & VTBAR_ENABLED))
233 return current;
234
235 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
236 acpi_create_dmar(dmar, DMAR_INTR_REMAP, soc_fill_dmar);
237 current += dmar->header.length;
238 current = acpi_align_current(current);
239 acpi_add_table(rsdp, dmar);
240 current = acpi_align_current(current);
241
242 return current;
243}
244
Shaunak Sahabd427802017-07-18 00:19:33 -0700245void soc_power_states_generation(int core_id, int cores_per_package)
246{
247 /* Generate P-state tables */
248 generate_p_state_entries(core_id, cores_per_package);
249
250 /* Generate T-state tables */
251 generate_t_state_entries(core_id, cores_per_package);
Hannah Williams0f61da82016-04-18 13:47:08 -0700252}
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700253
254static void acpigen_soc_get_dw0_in_local5(uintptr_t addr)
255{
256 /*
257 * Store (\_SB.GPC0 (addr), Local5)
258 * \_SB.GPC0 is used to read cfg0 value from dw0. It is defined in
259 * gpiolib.asl.
260 */
261 acpigen_write_store();
262 acpigen_emit_namestring("\\_SB.GPC0");
263 acpigen_write_integer(addr);
264 acpigen_emit_byte(LOCAL5_OP);
265}
266
267static int acpigen_soc_get_gpio_val(unsigned int gpio_num, uint32_t mask)
268{
Lee Leahyd8fb3622017-03-09 10:10:25 -0800269 assert(gpio_num < TOTAL_PADS);
Shaunak Sahabd427802017-07-18 00:19:33 -0700270 uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num);
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700271
272 acpigen_soc_get_dw0_in_local5(addr);
273
274 /* If (And (Local5, mask)) */
275 acpigen_write_if_and(LOCAL5_OP, mask);
276
277 /* Store (One, Local0) */
278 acpigen_write_store_ops(ONE_OP, LOCAL0_OP);
279
280 acpigen_pop_len(); /* If */
281
282 /* Else */
283 acpigen_write_else();
284
285 /* Store (Zero, Local0) */
286 acpigen_write_store_ops(ZERO_OP, LOCAL0_OP);
287
288 acpigen_pop_len(); /* Else */
289
290 return 0;
291}
292
293static int acpigen_soc_set_gpio_val(unsigned int gpio_num, uint32_t val)
294{
Lee Leahyd8fb3622017-03-09 10:10:25 -0800295 assert(gpio_num < TOTAL_PADS);
Shaunak Sahabd427802017-07-18 00:19:33 -0700296 uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num);
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700297
298 acpigen_soc_get_dw0_in_local5(addr);
299
300 if (val) {
301 /* Or (Local5, PAD_CFG0_TX_STATE, Local5) */
302 acpigen_write_or(LOCAL5_OP, PAD_CFG0_TX_STATE, LOCAL5_OP);
303 } else {
304 /* Not (PAD_CFG0_TX_STATE, Local6) */
305 acpigen_write_not(PAD_CFG0_TX_STATE, LOCAL6_OP);
306
307 /* And (Local5, Local6, Local5) */
308 acpigen_write_and(LOCAL5_OP, LOCAL6_OP, LOCAL5_OP);
309 }
310
311 /*
312 * \_SB.SPC0 (addr, Local5)
313 * \_SB.SPC0 is used to write cfg0 value in dw0. It is defined in
314 * gpiolib.asl.
315 */
316 acpigen_emit_namestring("\\_SB.SPC0");
317 acpigen_write_integer(addr);
318 acpigen_emit_byte(LOCAL5_OP);
319
320 return 0;
321}
322
323int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
324{
325 return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_RX_STATE);
326}
327
328int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
329{
330 return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_TX_STATE);
331}
332
333int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
334{
335 return acpigen_soc_set_gpio_val(gpio_num, 1);
336}
337
338int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
339{
340 return acpigen_soc_set_gpio_val(gpio_num, 0);
341}