Lijian Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2009 coresystems GmbH |
| 5 | * Copyright (C) 2014 Google Inc. |
Lijian Zhao | 5ff742c | 2018-12-27 17:01:09 -0800 | [diff] [blame] | 6 | * Copyright (C) 2017-2018 Intel Corporation. |
Lijian Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 7 | * |
| 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; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | */ |
| 17 | |
| 18 | #include <arch/acpi.h> |
| 19 | #include <arch/acpigen.h> |
Lijian Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 20 | #include <arch/smp/mpspec.h> |
| 21 | #include <cbmem.h> |
| 22 | #include <chip.h> |
John Zhao | db3f0e3 | 2019-03-15 16:54:27 -0700 | [diff] [blame^] | 23 | #include <device/mmio.h> |
| 24 | #include <device/pci_ops.h> |
Lijian Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 25 | #include <ec/google/chromeec/ec.h> |
| 26 | #include <intelblocks/cpulib.h> |
| 27 | #include <intelblocks/pmclib.h> |
| 28 | #include <intelblocks/acpi.h> |
John Zhao | db3f0e3 | 2019-03-15 16:54:27 -0700 | [diff] [blame^] | 29 | #include <intelblocks/p2sb.h> |
Lijian Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 30 | #include <soc/cpu.h> |
| 31 | #include <soc/iomap.h> |
| 32 | #include <soc/nvs.h> |
| 33 | #include <soc/pci_devs.h> |
| 34 | #include <soc/pm.h> |
John Zhao | db3f0e3 | 2019-03-15 16:54:27 -0700 | [diff] [blame^] | 35 | #include <soc/systemagent.h> |
Shaunak Saha | 95b6175 | 2017-10-04 23:08:40 -0700 | [diff] [blame] | 36 | #include <string.h> |
Lijian Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 37 | #include <vendorcode/google/chromeos/gnvs.h> |
| 38 | #include <wrdd.h> |
| 39 | |
Shaunak Saha | 95b6175 | 2017-10-04 23:08:40 -0700 | [diff] [blame] | 40 | /* |
| 41 | * List of supported C-states in this processor. |
| 42 | */ |
| 43 | enum { |
| 44 | C_STATE_C0, /* 0 */ |
| 45 | C_STATE_C1, /* 1 */ |
| 46 | C_STATE_C1E, /* 2 */ |
| 47 | C_STATE_C6_SHORT_LAT, /* 3 */ |
| 48 | C_STATE_C6_LONG_LAT, /* 4 */ |
| 49 | C_STATE_C7_SHORT_LAT, /* 5 */ |
| 50 | C_STATE_C7_LONG_LAT, /* 6 */ |
| 51 | C_STATE_C7S_SHORT_LAT, /* 7 */ |
| 52 | C_STATE_C7S_LONG_LAT, /* 8 */ |
| 53 | C_STATE_C8, /* 9 */ |
| 54 | C_STATE_C9, /* 10 */ |
| 55 | C_STATE_C10, /* 11 */ |
| 56 | NUM_C_STATES |
| 57 | }; |
| 58 | |
| 59 | #define MWAIT_RES(state, sub_state) \ |
| 60 | { \ |
| 61 | .addrl = (((state) << 4) | (sub_state)), \ |
| 62 | .space_id = ACPI_ADDRESS_SPACE_FIXED, \ |
| 63 | .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \ |
| 64 | .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \ |
| 65 | .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \ |
| 66 | } |
| 67 | |
| 68 | static const acpi_cstate_t cstate_map[NUM_C_STATES] = { |
| 69 | [C_STATE_C0] = {}, |
| 70 | [C_STATE_C1] = { |
| 71 | .latency = 0, |
| 72 | .power = C1_POWER, |
| 73 | .resource = MWAIT_RES(0, 0), |
| 74 | }, |
| 75 | [C_STATE_C1E] = { |
| 76 | .latency = 0, |
| 77 | .power = C1_POWER, |
| 78 | .resource = MWAIT_RES(0, 1), |
| 79 | }, |
| 80 | [C_STATE_C6_SHORT_LAT] = { |
| 81 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 82 | .power = C6_POWER, |
| 83 | .resource = MWAIT_RES(2, 0), |
| 84 | }, |
| 85 | [C_STATE_C6_LONG_LAT] = { |
| 86 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 87 | .power = C6_POWER, |
| 88 | .resource = MWAIT_RES(2, 1), |
| 89 | }, |
| 90 | [C_STATE_C7_SHORT_LAT] = { |
| 91 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 92 | .power = C7_POWER, |
| 93 | .resource = MWAIT_RES(3, 0), |
| 94 | }, |
| 95 | [C_STATE_C7_LONG_LAT] = { |
| 96 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 97 | .power = C7_POWER, |
| 98 | .resource = MWAIT_RES(3, 1), |
| 99 | }, |
| 100 | [C_STATE_C7S_SHORT_LAT] = { |
| 101 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 102 | .power = C7_POWER, |
| 103 | .resource = MWAIT_RES(3, 2), |
| 104 | }, |
| 105 | [C_STATE_C7S_LONG_LAT] = { |
| 106 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 107 | .power = C7_POWER, |
| 108 | .resource = MWAIT_RES(3, 3), |
| 109 | }, |
| 110 | [C_STATE_C8] = { |
| 111 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 112 | .power = C8_POWER, |
| 113 | .resource = MWAIT_RES(4, 0), |
| 114 | }, |
| 115 | [C_STATE_C9] = { |
| 116 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 117 | .power = C9_POWER, |
| 118 | .resource = MWAIT_RES(5, 0), |
| 119 | }, |
| 120 | [C_STATE_C10] = { |
| 121 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 122 | .power = C10_POWER, |
| 123 | .resource = MWAIT_RES(6, 0), |
| 124 | }, |
| 125 | }; |
| 126 | |
Ronak Kanabar | c6c4d00 | 2019-01-30 18:53:14 +0530 | [diff] [blame] | 127 | static int cstate_set_non_s0ix[] = { |
Shaunak Saha | 95b6175 | 2017-10-04 23:08:40 -0700 | [diff] [blame] | 128 | C_STATE_C1E, |
| 129 | C_STATE_C6_LONG_LAT, |
| 130 | C_STATE_C7S_LONG_LAT |
| 131 | }; |
| 132 | |
Ronak Kanabar | c6c4d00 | 2019-01-30 18:53:14 +0530 | [diff] [blame] | 133 | static int cstate_set_s0ix[] = { |
Shaunak Saha | 95b6175 | 2017-10-04 23:08:40 -0700 | [diff] [blame] | 134 | C_STATE_C1E, |
| 135 | C_STATE_C7S_LONG_LAT, |
| 136 | C_STATE_C10 |
| 137 | }; |
| 138 | |
| 139 | acpi_cstate_t *soc_get_cstate_map(size_t *entries) |
| 140 | { |
| 141 | static acpi_cstate_t map[MAX(ARRAY_SIZE(cstate_set_s0ix), |
| 142 | ARRAY_SIZE(cstate_set_non_s0ix))]; |
| 143 | int *set; |
| 144 | int i; |
Elyes HAOUAS | 3c8b5d0 | 2018-05-27 16:57:24 +0200 | [diff] [blame] | 145 | struct device *dev = SA_DEV_ROOT; |
Shaunak Saha | 95b6175 | 2017-10-04 23:08:40 -0700 | [diff] [blame] | 146 | config_t *config = dev->chip_info; |
| 147 | int is_s0ix_enable = config->s0ix_enable; |
| 148 | |
| 149 | if (is_s0ix_enable) { |
| 150 | *entries = ARRAY_SIZE(cstate_set_s0ix); |
| 151 | set = cstate_set_s0ix; |
| 152 | } else { |
| 153 | *entries = ARRAY_SIZE(cstate_set_non_s0ix); |
| 154 | set = cstate_set_non_s0ix; |
| 155 | } |
| 156 | |
| 157 | for (i = 0; i < *entries; i++) { |
| 158 | memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t)); |
| 159 | map[i].ctype = i + 1; |
| 160 | } |
| 161 | return map; |
| 162 | } |
| 163 | |
| 164 | void soc_power_states_generation(int core_id, int cores_per_package) |
| 165 | { |
Elyes HAOUAS | 3c8b5d0 | 2018-05-27 16:57:24 +0200 | [diff] [blame] | 166 | struct device *dev = SA_DEV_ROOT; |
Shaunak Saha | 95b6175 | 2017-10-04 23:08:40 -0700 | [diff] [blame] | 167 | config_t *config = dev->chip_info; |
| 168 | if (config->eist_enable) |
| 169 | /* Generate P-state tables */ |
| 170 | generate_p_state_entries(core_id, cores_per_package); |
| 171 | } |
| 172 | |
Lijian Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 173 | void soc_fill_fadt(acpi_fadt_t *fadt) |
| 174 | { |
| 175 | const uint16_t pmbase = ACPI_BASE_ADDRESS; |
| 176 | const struct device *dev = PCH_DEV_LPC; |
| 177 | const struct soc_intel_cannonlake_config *config = dev->chip_info; |
| 178 | |
Duncan Laurie | 174ca43 | 2018-09-13 16:28:13 +0000 | [diff] [blame] | 179 | if (!config->PmTimerDisabled) { |
| 180 | fadt->pm_tmr_blk = pmbase + PM1_TMR; |
| 181 | fadt->pm_tmr_len = 4; |
| 182 | fadt->x_pm_tmr_blk.space_id = 1; |
| 183 | fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8; |
| 184 | fadt->x_pm_tmr_blk.bit_offset = 0; |
Elyes HAOUAS | 8ee161d | 2019-03-03 12:49:56 +0100 | [diff] [blame] | 185 | fadt->x_pm_tmr_blk.access_size = 0; |
Duncan Laurie | 174ca43 | 2018-09-13 16:28:13 +0000 | [diff] [blame] | 186 | fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR; |
| 187 | fadt->x_pm_tmr_blk.addrh = 0x0; |
| 188 | } |
Lijian Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 189 | |
Duncan Laurie | 174ca43 | 2018-09-13 16:28:13 +0000 | [diff] [blame] | 190 | if (config->s0ix_enable) |
Vaibhav Shankar | 2da6ec4 | 2018-03-19 18:56:38 -0700 | [diff] [blame] | 191 | fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0; |
Lijian Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 192 | } |
| 193 | uint32_t soc_read_sci_irq_select(void) |
| 194 | { |
| 195 | uintptr_t pmc_bar = soc_read_pmc_base(); |
| 196 | return read32((void *)pmc_bar + IRQ_REG); |
| 197 | } |
| 198 | |
| 199 | void acpi_create_gnvs(struct global_nvs_t *gnvs) |
| 200 | { |
| 201 | const struct device *dev = PCH_DEV_LPC; |
| 202 | const struct soc_intel_cannonlake_config *config = dev->chip_info; |
| 203 | |
| 204 | /* Set unknown wake source */ |
| 205 | gnvs->pm1i = -1; |
| 206 | |
| 207 | /* CPU core count */ |
| 208 | gnvs->pcnt = dev_count_cpu(); |
| 209 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 210 | if (CONFIG(CONSOLE_CBMEM)) |
Lijian Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 211 | /* Update the mem console pointer. */ |
| 212 | gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE); |
| 213 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 214 | if (CONFIG(CHROMEOS)) { |
Lijian Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 215 | /* Initialize Verified Boot data */ |
Joel Kitching | 6fbd874 | 2018-08-23 14:56:25 +0800 | [diff] [blame] | 216 | chromeos_init_chromeos_acpi(&(gnvs->chromeos)); |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 217 | if (CONFIG(EC_GOOGLE_CHROMEEC)) { |
Lijian Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 218 | gnvs->chromeos.vbt2 = google_ec_running_ro() ? |
| 219 | ACTIVE_ECFW_RO : ACTIVE_ECFW_RW; |
| 220 | } else |
| 221 | gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO; |
| 222 | } |
| 223 | |
| 224 | /* Enable DPTF based on mainboard configuration */ |
| 225 | gnvs->dpte = config->dptf_enable; |
| 226 | |
| 227 | /* Fill in the Wifi Region id */ |
| 228 | gnvs->cid1 = wifi_regulatory_domain(); |
| 229 | |
| 230 | /* Set USB2/USB3 wake enable bitmaps. */ |
| 231 | gnvs->u2we = config->usb2_wake_enable_bitmap; |
| 232 | gnvs->u3we = config->usb3_wake_enable_bitmap; |
| 233 | } |
| 234 | |
| 235 | uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en, |
| 236 | const struct chipset_power_state *ps) |
| 237 | { |
| 238 | /* |
| 239 | * WAK_STS bit is set when the system is in one of the sleep states |
| 240 | * (via the SLP_EN bit) and an enabled wake event occurs. Upon setting |
| 241 | * this bit, the PMC will transition the system to the ON state and |
| 242 | * can only be set by hardware and can only be cleared by writing a one |
| 243 | * to this bit position. |
| 244 | */ |
| 245 | |
| 246 | generic_pm1_en |= WAK_STS | RTC_EN | PWRBTN_EN; |
| 247 | return generic_pm1_en; |
| 248 | } |
| 249 | |
| 250 | int soc_madt_sci_irq_polarity(int sci) |
| 251 | { |
| 252 | return MP_IRQ_POLARITY_HIGH; |
| 253 | } |
Lijian Zhao | 5ff742c | 2018-12-27 17:01:09 -0800 | [diff] [blame] | 254 | |
| 255 | static int acpigen_soc_gpio_op(const char *op, unsigned int gpio_num) |
| 256 | { |
| 257 | /* op (gpio_num) */ |
| 258 | acpigen_emit_namestring(op); |
| 259 | acpigen_write_integer(gpio_num); |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | static int acpigen_soc_get_gpio_state(const char *op, unsigned int gpio_num) |
| 264 | { |
| 265 | /* Store (op (gpio_num), Local0) */ |
| 266 | acpigen_write_store(); |
| 267 | acpigen_soc_gpio_op(op, gpio_num); |
| 268 | acpigen_emit_byte(LOCAL0_OP); |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | int acpigen_soc_read_rx_gpio(unsigned int gpio_num) |
| 273 | { |
| 274 | return acpigen_soc_get_gpio_state("\\_SB.PCI0.GRXS", gpio_num); |
| 275 | } |
| 276 | |
| 277 | int acpigen_soc_get_tx_gpio(unsigned int gpio_num) |
| 278 | { |
| 279 | return acpigen_soc_get_gpio_state("\\_SB.PCI0.GTXS", gpio_num); |
| 280 | } |
| 281 | |
| 282 | int acpigen_soc_set_tx_gpio(unsigned int gpio_num) |
| 283 | { |
| 284 | return acpigen_soc_gpio_op("\\_SB.PCI0.STXS", gpio_num); |
| 285 | } |
| 286 | |
| 287 | int acpigen_soc_clear_tx_gpio(unsigned int gpio_num) |
| 288 | { |
| 289 | return acpigen_soc_gpio_op("\\_SB.PCI0.CTXS", gpio_num); |
| 290 | } |
John Zhao | db3f0e3 | 2019-03-15 16:54:27 -0700 | [diff] [blame^] | 291 | |
| 292 | static unsigned long soc_fill_dmar(unsigned long current) |
| 293 | { |
| 294 | struct device *const igfx_dev = dev_find_slot(0, SA_DEVFN_IGD); |
| 295 | uint64_t gfxvtbar = MCHBAR64(GFXVTBAR) & VTBAR_MASK; |
| 296 | bool gfxvten = MCHBAR32(GFXVTBAR) & VTBAR_ENABLED; |
| 297 | |
| 298 | if (igfx_dev && igfx_dev->enabled && gfxvtbar && gfxvten) { |
| 299 | unsigned long tmp = current; |
| 300 | |
| 301 | current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar); |
| 302 | current += acpi_create_dmar_ds_pci(current, 0, 2, 0); |
| 303 | |
| 304 | acpi_dmar_drhd_fixup(tmp, current); |
| 305 | |
| 306 | /* Add RMRR entry */ |
| 307 | tmp = current; |
| 308 | current += acpi_create_dmar_rmrr(current, 0, |
| 309 | sa_get_gsm_base(), sa_get_tolud_base() - 1); |
| 310 | current += acpi_create_dmar_ds_pci(current, 0, 2, 0); |
| 311 | acpi_dmar_rmrr_fixup(tmp, current); |
| 312 | } |
| 313 | |
| 314 | struct device *const ipu_dev = dev_find_slot(0, SA_DEVFN_IPU); |
| 315 | uint64_t ipuvtbar = MCHBAR64(IPUVTBAR) & VTBAR_MASK; |
| 316 | bool ipuvten = MCHBAR32(IPUVTBAR) & VTBAR_ENABLED; |
| 317 | |
| 318 | if (ipu_dev && ipu_dev->enabled && ipuvtbar && ipuvten) { |
| 319 | unsigned long tmp = current; |
| 320 | |
| 321 | current += acpi_create_dmar_drhd(current, 0, 0, ipuvtbar); |
| 322 | current += acpi_create_dmar_ds_pci(current, 0, 5, 0); |
| 323 | |
| 324 | acpi_dmar_drhd_fixup(tmp, current); |
| 325 | } |
| 326 | |
| 327 | uint64_t vtvc0bar = MCHBAR64(VTVC0BAR) & VTBAR_MASK; |
| 328 | bool vtvc0en = MCHBAR32(VTVC0BAR) & VTBAR_ENABLED; |
| 329 | |
| 330 | if (vtvc0bar && vtvc0en) { |
| 331 | const unsigned long tmp = current; |
| 332 | |
| 333 | current += acpi_create_dmar_drhd(current, |
| 334 | DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar); |
| 335 | current += acpi_create_dmar_ds_ioapic(current, |
| 336 | 2, V_P2SB_CFG_IBDF_BUS, V_P2SB_CFG_IBDF_DEV, |
| 337 | V_P2SB_CFG_IBDF_FUNC); |
| 338 | current += acpi_create_dmar_ds_msi_hpet(current, |
| 339 | 0, V_P2SB_CFG_HBDF_BUS, V_P2SB_CFG_HBDF_DEV, |
| 340 | V_P2SB_CFG_HBDF_FUNC); |
| 341 | |
| 342 | acpi_dmar_drhd_fixup(tmp, current); |
| 343 | } |
| 344 | |
| 345 | return current; |
| 346 | } |
| 347 | |
| 348 | unsigned long sa_write_acpi_tables(struct device *dev, unsigned long current, |
| 349 | struct acpi_rsdp *rsdp) |
| 350 | { |
| 351 | acpi_dmar_t *const dmar = (acpi_dmar_t *)current; |
| 352 | |
| 353 | /* Create DMAR table only if we have VT-d capability |
| 354 | * and FSP does not override its feature. |
| 355 | */ |
| 356 | if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE) || |
| 357 | !(MCHBAR32(VTVC0BAR) & VTBAR_ENABLED)) |
| 358 | return current; |
| 359 | |
| 360 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
| 361 | acpi_create_dmar(dmar, DMAR_INTR_REMAP, soc_fill_dmar); |
| 362 | current += dmar->header.length; |
| 363 | current = acpi_align_current(current); |
| 364 | acpi_add_table(rsdp, dmar); |
| 365 | |
| 366 | return current; |
| 367 | } |