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