blob: 6e3bde4bb99c7fb87893406d5a46fb7e57dc83df [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>
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>
Elyes HAOUAS20eaef02019-03-29 17:45:28 +010022
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070023#include "chip.h"
Lance Zhaof51b1272015-11-09 17:06:34 -080024
Hannah Williams0f61da82016-04-18 13:47:08 -070025#define CSTATE_RES(address_space, width, offset, address) \
26 { \
27 .space_id = address_space, \
28 .bit_width = width, \
29 .bit_offset = offset, \
30 .addrl = address, \
31 }
32
Angel Ponse9f10ff2021-10-17 13:28:23 +020033static const acpi_cstate_t cstate_map[] = {
Shaunak Sahabd427802017-07-18 00:19:33 -070034 {
35 /* C1 */
36 .ctype = 1, /* ACPI C1 */
37 .latency = 1,
38 .power = 1000,
39 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_FIXED, 0, 0, 0),
40 },
41 {
42 .ctype = 2, /* ACPI C2 */
43 .latency = 50,
44 .power = 10,
45 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x415),
46 },
47 {
48 .ctype = 3, /* ACPI C3 */
49 .latency = 150,
50 .power = 10,
51 .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x419),
52 }
53};
54
55uint32_t soc_read_sci_irq_select(void)
Lance Zhaof51b1272015-11-09 17:06:34 -080056{
Angel Ponsf585c6e2021-06-25 10:09:35 +020057 return read32p(soc_read_pmc_base() + IRQ_REG);
Lance Zhaof51b1272015-11-09 17:06:34 -080058}
Lance Zhaoe904c7c2015-11-10 19:00:18 -080059
Mario Scheithauer841416f2017-09-18 17:08:48 +020060void soc_write_sci_irq_select(uint32_t scis)
61{
Angel Ponsf585c6e2021-06-25 10:09:35 +020062 write32p(soc_read_pmc_base() + IRQ_REG, scis);
Mario Scheithauer841416f2017-09-18 17:08:48 +020063}
64
Angel Ponse9f10ff2021-10-17 13:28:23 +020065const acpi_cstate_t *soc_get_cstate_map(size_t *entries)
Lance Zhaoe904c7c2015-11-10 19:00:18 -080066{
Shaunak Sahabd427802017-07-18 00:19:33 -070067 *entries = ARRAY_SIZE(cstate_map);
68 return cstate_map;
Lance Zhaoe904c7c2015-11-10 19:00:18 -080069}
70
Kyösti Mälkkic2b0a4f2020-06-28 22:39:59 +030071void soc_fill_gnvs(struct global_nvs *gnvs)
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070072{
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070073 struct soc_intel_apollolake_config *cfg;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +030074 cfg = config_of_soc();
Shaunak Sahacd9e1e42016-07-12 01:22:33 -070075
Aaron Durbin9e815402016-09-13 12:31:57 -050076 /* Enable DPTF based on mainboard configuration */
77 gnvs->dpte = cfg->dptf_enable;
Vaibhav Shankaref8deaf2016-08-23 17:56:17 -070078
79 /* Assign address of PERST_0 if GPIO is defined in devicetree */
80 if (cfg->prt0_gpio != GPIO_PRT0_UDEF)
Shaunak Sahabd427802017-07-18 00:19:33 -070081 gnvs->prt0 = (uintptr_t) gpio_dwx_address(cfg->prt0_gpio);
Venkateswarlu Vinjamuri6dd7b402017-02-24 15:37:30 -080082
Venkateswarlu Vinjamuri99ce8a92017-03-22 18:24:52 -070083 /* Get sdcard cd GPIO portid if GPIO is defined in devicetree.
84 * Get offset of sdcard cd pin.
85 */
86 if (cfg->sdcard_cd_gpio) {
87 gnvs->scdp = gpio_get_pad_portid(cfg->sdcard_cd_gpio);
88 gnvs->scdo = gpio_acpi_pin(cfg->sdcard_cd_gpio);
89 }
Pratik Prajapatid06c7642017-10-11 11:52:16 -070090
Julius Wernercd49cce2019-03-05 16:53:33 -080091 if (CONFIG(SOC_INTEL_COMMON_BLOCK_SGX))
Pratik Prajapatid06c7642017-10-11 11:52:16 -070092 sgx_fill_gnvs(gnvs);
Subrata Banikb6df6b02020-01-03 15:29:02 +053093
94 /* Fill in Above 4GB MMIO resource */
95 sa_fill_gnvs(gnvs);
Shaunak Saha60b46182016-08-02 17:25:13 -070096}
97
Shaunak Sahabd427802017-07-18 00:19:33 -070098int soc_madt_sci_irq_polarity(int sci)
Lance Zhao1bd0c0c2016-04-19 18:04:21 -070099{
Shaunak Sahabd427802017-07-18 00:19:33 -0700100 return MP_IRQ_POLARITY_LOW;
Hannah Williams0f61da82016-04-18 13:47:08 -0700101}
102
Shaunak Sahabd427802017-07-18 00:19:33 -0700103void soc_fill_fadt(acpi_fadt_t *fadt)
Hannah Williams0f61da82016-04-18 13:47:08 -0700104{
Shaunak Saha7210ec02017-12-13 09:37:05 -0800105 const struct soc_intel_apollolake_config *cfg;
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +0300106 cfg = config_of_soc();
Shaunak Saha7210ec02017-12-13 09:37:05 -0800107
Shaunak Sahabd427802017-07-18 00:19:33 -0700108 fadt->pm_tmr_blk = ACPI_BASE_ADDRESS + PM1_TMR;
109
Shaunak Sahabd427802017-07-18 00:19:33 -0700110 fadt->pm_tmr_len = 4;
Shaunak Sahabd427802017-07-18 00:19:33 -0700111
112 fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042;
113
Elyes HAOUAS04071f42020-07-20 17:05:24 +0200114 fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO;
Shaunak Sahabd427802017-07-18 00:19:33 -0700115 fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
116 fadt->x_pm_tmr_blk.addrl = ACPI_BASE_ADDRESS + PM1_TMR;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100117 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
Shaunak Saha7210ec02017-12-13 09:37:05 -0800118
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +0300119 if (cfg->lpss_s0ix_enable)
Shaunak Saha7210ec02017-12-13 09:37:05 -0800120 fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0;
Shaunak Sahabd427802017-07-18 00:19:33 -0700121}
122
Werner Zeh90cc7e22018-12-14 13:26:04 +0100123static unsigned long soc_fill_dmar(unsigned long current)
124{
Werner Zeh90cc7e22018-12-14 13:26:04 +0100125 uint64_t gfxvtbar = MCHBAR64(GFXVTBAR) & VTBAR_MASK;
126 uint64_t defvtbar = MCHBAR64(DEFVTBAR) & VTBAR_MASK;
127 bool gfxvten = MCHBAR32(GFXVTBAR) & VTBAR_ENABLED;
128 bool defvten = MCHBAR32(DEFVTBAR) & VTBAR_ENABLED;
129 unsigned long tmp;
130
131 /* IGD has to be enabled, GFXVTBAR set and enabled. */
Subrata Banik54a34172021-06-09 03:54:58 +0530132 const bool emit_igd = is_devfn_enabled(SA_DEVFN_IGD) && gfxvtbar && gfxvten;
Angel Ponsc05a3f82020-08-03 12:14:20 +0200133
134 /* First, add DRHD entries */
135 if (emit_igd) {
Werner Zeh90cc7e22018-12-14 13:26:04 +0100136 tmp = current;
137
138 current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
139 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
140 acpi_dmar_drhd_fixup(tmp, current);
Werner Zeh90cc7e22018-12-14 13:26:04 +0100141 }
142
143 /* DEFVTBAR has to be set and enabled. */
144 if (defvtbar && defvten) {
145 tmp = current;
Arthur Heymans054026c2020-11-12 21:09:56 +0100146 union p2sb_bdf ibdf = p2sb_get_ioapic_bdf();
Arthur Heymans281868e2020-11-12 21:02:11 +0100147 union p2sb_bdf hbdf = p2sb_get_hpet_bdf();
Werner Zeh90cc7e22018-12-14 13:26:04 +0100148 p2sb_hide();
149
150 current += acpi_create_dmar_drhd(current,
151 DRHD_INCLUDE_PCI_ALL, 0, defvtbar);
152 current += acpi_create_dmar_ds_ioapic(current,
Arthur Heymans054026c2020-11-12 21:09:56 +0100153 2, ibdf.bus, ibdf.dev, ibdf.fn);
Werner Zeh90cc7e22018-12-14 13:26:04 +0100154 current += acpi_create_dmar_ds_msi_hpet(current,
Arthur Heymans281868e2020-11-12 21:02:11 +0100155 0, hbdf.bus, hbdf.dev, hbdf.fn);
Werner Zeh90cc7e22018-12-14 13:26:04 +0100156 acpi_dmar_drhd_fixup(tmp, current);
157 }
158
Angel Ponsc05a3f82020-08-03 12:14:20 +0200159 /* Then, add RMRR entries after all DRHD entries */
160 if (emit_igd) {
161 tmp = current;
162 current += acpi_create_dmar_rmrr(current, 0,
163 sa_get_gsm_base(), sa_get_tolud_base() - 1);
164 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
165 acpi_dmar_rmrr_fixup(tmp, current);
166 }
167
Werner Zeh90cc7e22018-12-14 13:26:04 +0100168 return current;
169}
170
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700171unsigned long sa_write_acpi_tables(const struct device *const dev,
Werner Zeh90cc7e22018-12-14 13:26:04 +0100172 unsigned long current,
173 struct acpi_rsdp *const rsdp)
174{
175 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
176
177 /* Create DMAR table only if virtualization is enabled. Due to some
178 * constraints on Apollo Lake SoC (some stepping affected), VTD could
179 * not be enabled together with IPU. Doing so will override and disable
180 * VTD while leaving CAPID0_A still reporting that VTD is available.
181 * As in this case FSP will lock VTD to disabled state, we need to make
182 * sure that DMAR table generation only happens when at least DEFVTBAR
183 * is enabled. Otherwise the DMAR header will be generated while the
184 * content of the table will be missing.
185 */
186
187 if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE) ||
188 !(MCHBAR32(DEFVTBAR) & VTBAR_ENABLED))
189 return current;
190
191 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
192 acpi_create_dmar(dmar, DMAR_INTR_REMAP, soc_fill_dmar);
193 current += dmar->header.length;
194 current = acpi_align_current(current);
195 acpi_add_table(rsdp, dmar);
196 current = acpi_align_current(current);
197
198 return current;
199}
200
Shaunak Sahabd427802017-07-18 00:19:33 -0700201void soc_power_states_generation(int core_id, int cores_per_package)
202{
203 /* Generate P-state tables */
204 generate_p_state_entries(core_id, cores_per_package);
205
206 /* Generate T-state tables */
207 generate_t_state_entries(core_id, cores_per_package);
Hannah Williams0f61da82016-04-18 13:47:08 -0700208}
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700209
210static void acpigen_soc_get_dw0_in_local5(uintptr_t addr)
211{
212 /*
213 * Store (\_SB.GPC0 (addr), Local5)
214 * \_SB.GPC0 is used to read cfg0 value from dw0. It is defined in
215 * gpiolib.asl.
216 */
217 acpigen_write_store();
218 acpigen_emit_namestring("\\_SB.GPC0");
219 acpigen_write_integer(addr);
220 acpigen_emit_byte(LOCAL5_OP);
221}
222
223static int acpigen_soc_get_gpio_val(unsigned int gpio_num, uint32_t mask)
224{
Lee Leahyd8fb3622017-03-09 10:10:25 -0800225 assert(gpio_num < TOTAL_PADS);
Shaunak Sahabd427802017-07-18 00:19:33 -0700226 uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num);
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700227
228 acpigen_soc_get_dw0_in_local5(addr);
229
230 /* If (And (Local5, mask)) */
231 acpigen_write_if_and(LOCAL5_OP, mask);
232
233 /* Store (One, Local0) */
234 acpigen_write_store_ops(ONE_OP, LOCAL0_OP);
235
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700236 /* Else */
237 acpigen_write_else();
238
239 /* Store (Zero, Local0) */
240 acpigen_write_store_ops(ZERO_OP, LOCAL0_OP);
241
242 acpigen_pop_len(); /* Else */
243
244 return 0;
245}
246
247static int acpigen_soc_set_gpio_val(unsigned int gpio_num, uint32_t val)
248{
Lee Leahyd8fb3622017-03-09 10:10:25 -0800249 assert(gpio_num < TOTAL_PADS);
Shaunak Sahabd427802017-07-18 00:19:33 -0700250 uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num);
Furquan Shaikh00a9e382016-10-20 22:45:26 -0700251
252 acpigen_soc_get_dw0_in_local5(addr);
253
254 if (val) {
255 /* Or (Local5, PAD_CFG0_TX_STATE, Local5) */
256 acpigen_write_or(LOCAL5_OP, PAD_CFG0_TX_STATE, LOCAL5_OP);
257 } else {
258 /* Not (PAD_CFG0_TX_STATE, Local6) */
259 acpigen_write_not(PAD_CFG0_TX_STATE, LOCAL6_OP);
260
261 /* And (Local5, Local6, Local5) */
262 acpigen_write_and(LOCAL5_OP, LOCAL6_OP, LOCAL5_OP);
263 }
264
265 /*
266 * \_SB.SPC0 (addr, Local5)
267 * \_SB.SPC0 is used to write cfg0 value in dw0. It is defined in
268 * gpiolib.asl.
269 */
270 acpigen_emit_namestring("\\_SB.SPC0");
271 acpigen_write_integer(addr);
272 acpigen_emit_byte(LOCAL5_OP);
273
274 return 0;
275}
276
277int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
278{
279 return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_RX_STATE);
280}
281
282int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
283{
284 return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_TX_STATE);
285}
286
287int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
288{
289 return acpigen_soc_set_gpio_val(gpio_num, 1);
290}
291
292int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
293{
294 return acpigen_soc_set_gpio_val(gpio_num, 0);
295}