Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 4 | #include <acpi/acpi_gnvs.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 5 | #include <acpi/acpigen.h> |
Elyes HAOUAS | 20eaef0 | 2019-03-29 17:45:28 +0100 | [diff] [blame] | 6 | #include <console/console.h> |
Felix Singer | 6c3a89c | 2020-07-26 09:26:52 +0200 | [diff] [blame] | 7 | #include <device/device.h> |
Kyösti Mälkki | 13f6650 | 2019-03-03 08:01:05 +0200 | [diff] [blame] | 8 | #include <device/mmio.h> |
Lance Zhao | 2fc82d6 | 2015-11-16 18:33:21 -0800 | [diff] [blame] | 9 | #include <arch/smp/mpspec.h> |
Elyes HAOUAS | cd4fe0f | 2019-03-29 17:12:15 +0100 | [diff] [blame] | 10 | #include <assert.h> |
Werner Zeh | 90cc7e2 | 2018-12-14 13:26:04 +0100 | [diff] [blame] | 11 | #include <device/pci_ops.h> |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 12 | #include <gpio.h> |
| 13 | #include <intelblocks/acpi.h> |
| 14 | #include <intelblocks/pmclib.h> |
Werner Zeh | 90cc7e2 | 2018-12-14 13:26:04 +0100 | [diff] [blame] | 15 | #include <intelblocks/p2sb.h> |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 16 | #include <soc/iomap.h> |
| 17 | #include <soc/pm.h> |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 18 | #include <soc/nvs.h> |
Shaunak Saha | cd9e1e4 | 2016-07-12 01:22:33 -0700 | [diff] [blame] | 19 | #include <soc/pci_devs.h> |
Werner Zeh | 90cc7e2 | 2018-12-14 13:26:04 +0100 | [diff] [blame] | 20 | #include <soc/systemagent.h> |
Elyes HAOUAS | 20eaef0 | 2019-03-29 17:45:28 +0100 | [diff] [blame] | 21 | |
Shaunak Saha | cd9e1e4 | 2016-07-12 01:22:33 -0700 | [diff] [blame] | 22 | #include "chip.h" |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 23 | |
Hannah Williams | 0f61da8 | 2016-04-18 13:47:08 -0700 | [diff] [blame] | 24 | #define CSTATE_RES(address_space, width, offset, address) \ |
| 25 | { \ |
| 26 | .space_id = address_space, \ |
| 27 | .bit_width = width, \ |
| 28 | .bit_offset = offset, \ |
| 29 | .addrl = address, \ |
| 30 | } |
| 31 | |
Angel Pons | e9f10ff | 2021-10-17 13:28:23 +0200 | [diff] [blame] | 32 | static const acpi_cstate_t cstate_map[] = { |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 33 | { |
| 34 | /* C1 */ |
| 35 | .ctype = 1, /* ACPI C1 */ |
| 36 | .latency = 1, |
| 37 | .power = 1000, |
| 38 | .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_FIXED, 0, 0, 0), |
| 39 | }, |
| 40 | { |
| 41 | .ctype = 2, /* ACPI C2 */ |
| 42 | .latency = 50, |
| 43 | .power = 10, |
| 44 | .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x415), |
| 45 | }, |
| 46 | { |
| 47 | .ctype = 3, /* ACPI C3 */ |
| 48 | .latency = 150, |
| 49 | .power = 10, |
| 50 | .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, 0x419), |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | uint32_t soc_read_sci_irq_select(void) |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 55 | { |
Angel Pons | f585c6e | 2021-06-25 10:09:35 +0200 | [diff] [blame] | 56 | return read32p(soc_read_pmc_base() + IRQ_REG); |
Lance Zhao | f51b127 | 2015-11-09 17:06:34 -0800 | [diff] [blame] | 57 | } |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 58 | |
Mario Scheithauer | 841416f | 2017-09-18 17:08:48 +0200 | [diff] [blame] | 59 | void soc_write_sci_irq_select(uint32_t scis) |
| 60 | { |
Angel Pons | f585c6e | 2021-06-25 10:09:35 +0200 | [diff] [blame] | 61 | write32p(soc_read_pmc_base() + IRQ_REG, scis); |
Mario Scheithauer | 841416f | 2017-09-18 17:08:48 +0200 | [diff] [blame] | 62 | } |
| 63 | |
Angel Pons | e9f10ff | 2021-10-17 13:28:23 +0200 | [diff] [blame] | 64 | const acpi_cstate_t *soc_get_cstate_map(size_t *entries) |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 65 | { |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 66 | *entries = ARRAY_SIZE(cstate_map); |
| 67 | return cstate_map; |
Lance Zhao | e904c7c | 2015-11-10 19:00:18 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Kyösti Mälkki | c2b0a4f | 2020-06-28 22:39:59 +0300 | [diff] [blame] | 70 | void soc_fill_gnvs(struct global_nvs *gnvs) |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 71 | { |
Shaunak Saha | cd9e1e4 | 2016-07-12 01:22:33 -0700 | [diff] [blame] | 72 | struct soc_intel_apollolake_config *cfg; |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 73 | cfg = config_of_soc(); |
Shaunak Saha | cd9e1e4 | 2016-07-12 01:22:33 -0700 | [diff] [blame] | 74 | |
Aaron Durbin | 9e81540 | 2016-09-13 12:31:57 -0500 | [diff] [blame] | 75 | /* Enable DPTF based on mainboard configuration */ |
| 76 | gnvs->dpte = cfg->dptf_enable; |
Vaibhav Shankar | ef8deaf | 2016-08-23 17:56:17 -0700 | [diff] [blame] | 77 | |
| 78 | /* Assign address of PERST_0 if GPIO is defined in devicetree */ |
| 79 | if (cfg->prt0_gpio != GPIO_PRT0_UDEF) |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 80 | gnvs->prt0 = (uintptr_t) gpio_dwx_address(cfg->prt0_gpio); |
Venkateswarlu Vinjamuri | 6dd7b40 | 2017-02-24 15:37:30 -0800 | [diff] [blame] | 81 | |
Venkateswarlu Vinjamuri | 99ce8a9 | 2017-03-22 18:24:52 -0700 | [diff] [blame] | 82 | /* Get sdcard cd GPIO portid if GPIO is defined in devicetree. |
| 83 | * Get offset of sdcard cd pin. |
| 84 | */ |
| 85 | if (cfg->sdcard_cd_gpio) { |
| 86 | gnvs->scdp = gpio_get_pad_portid(cfg->sdcard_cd_gpio); |
| 87 | gnvs->scdo = gpio_acpi_pin(cfg->sdcard_cd_gpio); |
| 88 | } |
Shaunak Saha | 60b4618 | 2016-08-02 17:25:13 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 91 | int soc_madt_sci_irq_polarity(int sci) |
Lance Zhao | 1bd0c0c | 2016-04-19 18:04:21 -0700 | [diff] [blame] | 92 | { |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 93 | return MP_IRQ_POLARITY_LOW; |
Hannah Williams | 0f61da8 | 2016-04-18 13:47:08 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 96 | void soc_fill_fadt(acpi_fadt_t *fadt) |
Hannah Williams | 0f61da8 | 2016-04-18 13:47:08 -0700 | [diff] [blame] | 97 | { |
Shaunak Saha | 7210ec0 | 2017-12-13 09:37:05 -0800 | [diff] [blame] | 98 | const struct soc_intel_apollolake_config *cfg; |
Kyösti Mälkki | d5f645c | 2019-09-28 00:20:27 +0300 | [diff] [blame] | 99 | cfg = config_of_soc(); |
Shaunak Saha | 7210ec0 | 2017-12-13 09:37:05 -0800 | [diff] [blame] | 100 | |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 101 | fadt->pm_tmr_blk = ACPI_BASE_ADDRESS + PM1_TMR; |
| 102 | |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 103 | fadt->pm_tmr_len = 4; |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 104 | |
| 105 | fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042; |
| 106 | |
Elyes HAOUAS | 04071f4 | 2020-07-20 17:05:24 +0200 | [diff] [blame] | 107 | fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 108 | fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8; |
| 109 | fadt->x_pm_tmr_blk.addrl = ACPI_BASE_ADDRESS + PM1_TMR; |
Patrick Rudolph | c02bda0 | 2020-02-28 10:19:41 +0100 | [diff] [blame] | 110 | fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
Shaunak Saha | 7210ec0 | 2017-12-13 09:37:05 -0800 | [diff] [blame] | 111 | |
Kyösti Mälkki | 28dc7dc | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 112 | if (cfg->lpss_s0ix_enable) |
Shaunak Saha | 7210ec0 | 2017-12-13 09:37:05 -0800 | [diff] [blame] | 113 | fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0; |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Werner Zeh | 90cc7e2 | 2018-12-14 13:26:04 +0100 | [diff] [blame] | 116 | static unsigned long soc_fill_dmar(unsigned long current) |
| 117 | { |
Werner Zeh | 90cc7e2 | 2018-12-14 13:26:04 +0100 | [diff] [blame] | 118 | uint64_t gfxvtbar = MCHBAR64(GFXVTBAR) & VTBAR_MASK; |
| 119 | uint64_t defvtbar = MCHBAR64(DEFVTBAR) & VTBAR_MASK; |
| 120 | bool gfxvten = MCHBAR32(GFXVTBAR) & VTBAR_ENABLED; |
| 121 | bool defvten = MCHBAR32(DEFVTBAR) & VTBAR_ENABLED; |
| 122 | unsigned long tmp; |
| 123 | |
| 124 | /* IGD has to be enabled, GFXVTBAR set and enabled. */ |
Subrata Banik | 54a3417 | 2021-06-09 03:54:58 +0530 | [diff] [blame] | 125 | const bool emit_igd = is_devfn_enabled(SA_DEVFN_IGD) && gfxvtbar && gfxvten; |
Angel Pons | c05a3f8 | 2020-08-03 12:14:20 +0200 | [diff] [blame] | 126 | |
| 127 | /* First, add DRHD entries */ |
| 128 | if (emit_igd) { |
Werner Zeh | 90cc7e2 | 2018-12-14 13:26:04 +0100 | [diff] [blame] | 129 | tmp = current; |
| 130 | |
| 131 | current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar); |
| 132 | current += acpi_create_dmar_ds_pci(current, 0, 2, 0); |
| 133 | acpi_dmar_drhd_fixup(tmp, current); |
Werner Zeh | 90cc7e2 | 2018-12-14 13:26:04 +0100 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /* DEFVTBAR has to be set and enabled. */ |
| 137 | if (defvtbar && defvten) { |
| 138 | tmp = current; |
Arthur Heymans | 054026c | 2020-11-12 21:09:56 +0100 | [diff] [blame] | 139 | union p2sb_bdf ibdf = p2sb_get_ioapic_bdf(); |
Arthur Heymans | 281868e | 2020-11-12 21:02:11 +0100 | [diff] [blame] | 140 | union p2sb_bdf hbdf = p2sb_get_hpet_bdf(); |
Werner Zeh | 90cc7e2 | 2018-12-14 13:26:04 +0100 | [diff] [blame] | 141 | p2sb_hide(); |
| 142 | |
| 143 | current += acpi_create_dmar_drhd(current, |
| 144 | DRHD_INCLUDE_PCI_ALL, 0, defvtbar); |
| 145 | current += acpi_create_dmar_ds_ioapic(current, |
Arthur Heymans | 054026c | 2020-11-12 21:09:56 +0100 | [diff] [blame] | 146 | 2, ibdf.bus, ibdf.dev, ibdf.fn); |
Werner Zeh | 90cc7e2 | 2018-12-14 13:26:04 +0100 | [diff] [blame] | 147 | current += acpi_create_dmar_ds_msi_hpet(current, |
Arthur Heymans | 281868e | 2020-11-12 21:02:11 +0100 | [diff] [blame] | 148 | 0, hbdf.bus, hbdf.dev, hbdf.fn); |
Werner Zeh | 90cc7e2 | 2018-12-14 13:26:04 +0100 | [diff] [blame] | 149 | acpi_dmar_drhd_fixup(tmp, current); |
| 150 | } |
| 151 | |
Angel Pons | c05a3f8 | 2020-08-03 12:14:20 +0200 | [diff] [blame] | 152 | /* Then, add RMRR entries after all DRHD entries */ |
| 153 | if (emit_igd) { |
| 154 | tmp = current; |
| 155 | current += acpi_create_dmar_rmrr(current, 0, |
| 156 | sa_get_gsm_base(), sa_get_tolud_base() - 1); |
| 157 | current += acpi_create_dmar_ds_pci(current, 0, 2, 0); |
| 158 | acpi_dmar_rmrr_fixup(tmp, current); |
| 159 | } |
| 160 | |
Werner Zeh | 90cc7e2 | 2018-12-14 13:26:04 +0100 | [diff] [blame] | 161 | return current; |
| 162 | } |
| 163 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 164 | unsigned long sa_write_acpi_tables(const struct device *const dev, |
Werner Zeh | 90cc7e2 | 2018-12-14 13:26:04 +0100 | [diff] [blame] | 165 | unsigned long current, |
| 166 | struct acpi_rsdp *const rsdp) |
| 167 | { |
| 168 | acpi_dmar_t *const dmar = (acpi_dmar_t *)current; |
| 169 | |
| 170 | /* Create DMAR table only if virtualization is enabled. Due to some |
| 171 | * constraints on Apollo Lake SoC (some stepping affected), VTD could |
| 172 | * not be enabled together with IPU. Doing so will override and disable |
| 173 | * VTD while leaving CAPID0_A still reporting that VTD is available. |
| 174 | * As in this case FSP will lock VTD to disabled state, we need to make |
| 175 | * sure that DMAR table generation only happens when at least DEFVTBAR |
| 176 | * is enabled. Otherwise the DMAR header will be generated while the |
| 177 | * content of the table will be missing. |
| 178 | */ |
| 179 | |
| 180 | if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE) || |
| 181 | !(MCHBAR32(DEFVTBAR) & VTBAR_ENABLED)) |
| 182 | return current; |
| 183 | |
| 184 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
| 185 | acpi_create_dmar(dmar, DMAR_INTR_REMAP, soc_fill_dmar); |
| 186 | current += dmar->header.length; |
| 187 | current = acpi_align_current(current); |
| 188 | acpi_add_table(rsdp, dmar); |
| 189 | current = acpi_align_current(current); |
| 190 | |
| 191 | return current; |
| 192 | } |
| 193 | |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 194 | void soc_power_states_generation(int core_id, int cores_per_package) |
| 195 | { |
| 196 | /* Generate P-state tables */ |
| 197 | generate_p_state_entries(core_id, cores_per_package); |
| 198 | |
| 199 | /* Generate T-state tables */ |
| 200 | generate_t_state_entries(core_id, cores_per_package); |
Hannah Williams | 0f61da8 | 2016-04-18 13:47:08 -0700 | [diff] [blame] | 201 | } |
Furquan Shaikh | 00a9e38 | 2016-10-20 22:45:26 -0700 | [diff] [blame] | 202 | |
| 203 | static void acpigen_soc_get_dw0_in_local5(uintptr_t addr) |
| 204 | { |
| 205 | /* |
| 206 | * Store (\_SB.GPC0 (addr), Local5) |
| 207 | * \_SB.GPC0 is used to read cfg0 value from dw0. It is defined in |
| 208 | * gpiolib.asl. |
| 209 | */ |
| 210 | acpigen_write_store(); |
| 211 | acpigen_emit_namestring("\\_SB.GPC0"); |
| 212 | acpigen_write_integer(addr); |
| 213 | acpigen_emit_byte(LOCAL5_OP); |
| 214 | } |
| 215 | |
| 216 | static int acpigen_soc_get_gpio_val(unsigned int gpio_num, uint32_t mask) |
| 217 | { |
Lee Leahy | d8fb362 | 2017-03-09 10:10:25 -0800 | [diff] [blame] | 218 | assert(gpio_num < TOTAL_PADS); |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 219 | uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num); |
Furquan Shaikh | 00a9e38 | 2016-10-20 22:45:26 -0700 | [diff] [blame] | 220 | |
| 221 | acpigen_soc_get_dw0_in_local5(addr); |
| 222 | |
| 223 | /* If (And (Local5, mask)) */ |
| 224 | acpigen_write_if_and(LOCAL5_OP, mask); |
| 225 | |
| 226 | /* Store (One, Local0) */ |
| 227 | acpigen_write_store_ops(ONE_OP, LOCAL0_OP); |
| 228 | |
Furquan Shaikh | 00a9e38 | 2016-10-20 22:45:26 -0700 | [diff] [blame] | 229 | /* Else */ |
| 230 | acpigen_write_else(); |
| 231 | |
| 232 | /* Store (Zero, Local0) */ |
| 233 | acpigen_write_store_ops(ZERO_OP, LOCAL0_OP); |
| 234 | |
| 235 | acpigen_pop_len(); /* Else */ |
| 236 | |
| 237 | return 0; |
| 238 | } |
| 239 | |
| 240 | static int acpigen_soc_set_gpio_val(unsigned int gpio_num, uint32_t val) |
| 241 | { |
Lee Leahy | d8fb362 | 2017-03-09 10:10:25 -0800 | [diff] [blame] | 242 | assert(gpio_num < TOTAL_PADS); |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 243 | uintptr_t addr = (uintptr_t) gpio_dwx_address(gpio_num); |
Furquan Shaikh | 00a9e38 | 2016-10-20 22:45:26 -0700 | [diff] [blame] | 244 | |
| 245 | acpigen_soc_get_dw0_in_local5(addr); |
| 246 | |
| 247 | if (val) { |
| 248 | /* Or (Local5, PAD_CFG0_TX_STATE, Local5) */ |
| 249 | acpigen_write_or(LOCAL5_OP, PAD_CFG0_TX_STATE, LOCAL5_OP); |
| 250 | } else { |
| 251 | /* Not (PAD_CFG0_TX_STATE, Local6) */ |
| 252 | acpigen_write_not(PAD_CFG0_TX_STATE, LOCAL6_OP); |
| 253 | |
| 254 | /* And (Local5, Local6, Local5) */ |
| 255 | acpigen_write_and(LOCAL5_OP, LOCAL6_OP, LOCAL5_OP); |
| 256 | } |
| 257 | |
| 258 | /* |
| 259 | * \_SB.SPC0 (addr, Local5) |
| 260 | * \_SB.SPC0 is used to write cfg0 value in dw0. It is defined in |
| 261 | * gpiolib.asl. |
| 262 | */ |
| 263 | acpigen_emit_namestring("\\_SB.SPC0"); |
| 264 | acpigen_write_integer(addr); |
| 265 | acpigen_emit_byte(LOCAL5_OP); |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | int acpigen_soc_read_rx_gpio(unsigned int gpio_num) |
| 271 | { |
| 272 | return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_RX_STATE); |
| 273 | } |
| 274 | |
| 275 | int acpigen_soc_get_tx_gpio(unsigned int gpio_num) |
| 276 | { |
| 277 | return acpigen_soc_get_gpio_val(gpio_num, PAD_CFG0_TX_STATE); |
| 278 | } |
| 279 | |
| 280 | int acpigen_soc_set_tx_gpio(unsigned int gpio_num) |
| 281 | { |
| 282 | return acpigen_soc_set_gpio_val(gpio_num, 1); |
| 283 | } |
| 284 | |
| 285 | int acpigen_soc_clear_tx_gpio(unsigned int gpio_num) |
| 286 | { |
| 287 | return acpigen_soc_set_gpio_val(gpio_num, 0); |
| 288 | } |