Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -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. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <arch/acpi.h> |
| 18 | #include <arch/acpigen.h> |
| 19 | #include <arch/io.h> |
| 20 | #include <arch/smp/mpspec.h> |
| 21 | #include <cbmem.h> |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 22 | #include <device/pci_ops.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 23 | #include <cpu/x86/smm.h> |
| 24 | #include <console/console.h> |
| 25 | #include <types.h> |
| 26 | #include <string.h> |
| 27 | #include <arch/cpu.h> |
| 28 | #include <cpu/x86/msr.h> |
| 29 | #include <cpu/x86/tsc.h> |
| 30 | #include <cpu/intel/turbo.h> |
| 31 | #include <ec/google/chromeec/ec.h> |
| 32 | #include <vendorcode/google/chromeos/gnvs.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 33 | #include <soc/acpi.h> |
| 34 | #include <soc/cpu.h> |
| 35 | #include <soc/iomap.h> |
| 36 | #include <soc/lpc.h> |
| 37 | #include <soc/msr.h> |
| 38 | #include <soc/pci_devs.h> |
| 39 | #include <soc/pm.h> |
Matt DeVillier | 0f49bbc | 2018-02-19 17:35:55 -0600 | [diff] [blame] | 40 | #include <soc/systemagent.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 41 | #include <soc/intel/broadwell/chip.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 42 | |
| 43 | /* |
Martin Roth | de7ed6f | 2014-12-07 14:58:18 -0700 | [diff] [blame] | 44 | * List of supported C-states in this processor. Only the ULT parts support C8, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 45 | * C9, and C10. |
| 46 | */ |
| 47 | enum { |
| 48 | C_STATE_C0, /* 0 */ |
| 49 | C_STATE_C1, /* 1 */ |
| 50 | C_STATE_C1E, /* 2 */ |
| 51 | C_STATE_C3, /* 3 */ |
| 52 | C_STATE_C6_SHORT_LAT, /* 4 */ |
| 53 | C_STATE_C6_LONG_LAT, /* 5 */ |
| 54 | C_STATE_C7_SHORT_LAT, /* 6 */ |
| 55 | C_STATE_C7_LONG_LAT, /* 7 */ |
| 56 | C_STATE_C7S_SHORT_LAT, /* 8 */ |
| 57 | C_STATE_C7S_LONG_LAT, /* 9 */ |
| 58 | C_STATE_C8, /* 10 */ |
| 59 | C_STATE_C9, /* 11 */ |
| 60 | C_STATE_C10, /* 12 */ |
| 61 | NUM_C_STATES |
| 62 | }; |
| 63 | |
| 64 | #define MWAIT_RES(state, sub_state) \ |
| 65 | { \ |
| 66 | .addrl = (((state) << 4) | (sub_state)), \ |
| 67 | .space_id = ACPI_ADDRESS_SPACE_FIXED, \ |
| 68 | .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \ |
| 69 | .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \ |
| 70 | .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \ |
| 71 | } |
| 72 | |
| 73 | static acpi_cstate_t cstate_map[NUM_C_STATES] = { |
| 74 | [C_STATE_C0] = { }, |
| 75 | [C_STATE_C1] = { |
| 76 | .latency = 0, |
| 77 | .power = 1000, |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 78 | .resource = MWAIT_RES(0, 0), |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 79 | }, |
| 80 | [C_STATE_C1E] = { |
| 81 | .latency = 0, |
| 82 | .power = 1000, |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 83 | .resource = MWAIT_RES(0, 1), |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 84 | }, |
| 85 | [C_STATE_C3] = { |
| 86 | .latency = C_STATE_LATENCY_FROM_LAT_REG(0), |
| 87 | .power = 900, |
| 88 | .resource = MWAIT_RES(1, 0), |
| 89 | }, |
| 90 | [C_STATE_C6_SHORT_LAT] = { |
| 91 | .latency = C_STATE_LATENCY_FROM_LAT_REG(1), |
| 92 | .power = 800, |
| 93 | .resource = MWAIT_RES(2, 0), |
| 94 | }, |
| 95 | [C_STATE_C6_LONG_LAT] = { |
| 96 | .latency = C_STATE_LATENCY_FROM_LAT_REG(2), |
| 97 | .power = 800, |
| 98 | .resource = MWAIT_RES(2, 1), |
| 99 | }, |
| 100 | [C_STATE_C7_SHORT_LAT] = { |
| 101 | .latency = C_STATE_LATENCY_FROM_LAT_REG(1), |
| 102 | .power = 700, |
| 103 | .resource = MWAIT_RES(3, 0), |
| 104 | }, |
| 105 | [C_STATE_C7_LONG_LAT] = { |
| 106 | .latency = C_STATE_LATENCY_FROM_LAT_REG(2), |
| 107 | .power = 700, |
| 108 | .resource = MWAIT_RES(3, 1), |
| 109 | }, |
| 110 | [C_STATE_C7S_SHORT_LAT] = { |
| 111 | .latency = C_STATE_LATENCY_FROM_LAT_REG(1), |
| 112 | .power = 700, |
| 113 | .resource = MWAIT_RES(3, 2), |
| 114 | }, |
| 115 | [C_STATE_C7S_LONG_LAT] = { |
| 116 | .latency = C_STATE_LATENCY_FROM_LAT_REG(2), |
| 117 | .power = 700, |
| 118 | .resource = MWAIT_RES(3, 3), |
| 119 | }, |
| 120 | [C_STATE_C8] = { |
| 121 | .latency = C_STATE_LATENCY_FROM_LAT_REG(3), |
| 122 | .power = 600, |
| 123 | .resource = MWAIT_RES(4, 0), |
| 124 | }, |
| 125 | [C_STATE_C9] = { |
| 126 | .latency = C_STATE_LATENCY_FROM_LAT_REG(4), |
| 127 | .power = 500, |
| 128 | .resource = MWAIT_RES(5, 0), |
| 129 | }, |
| 130 | [C_STATE_C10] = { |
| 131 | .latency = C_STATE_LATENCY_FROM_LAT_REG(5), |
| 132 | .power = 400, |
| 133 | .resource = MWAIT_RES(6, 0), |
| 134 | }, |
| 135 | }; |
| 136 | |
| 137 | static int cstate_set_s0ix[3] = { |
| 138 | C_STATE_C1E, |
| 139 | C_STATE_C7S_LONG_LAT, |
| 140 | C_STATE_C10 |
| 141 | }; |
| 142 | |
| 143 | static int cstate_set_non_s0ix[3] = { |
| 144 | C_STATE_C1E, |
| 145 | C_STATE_C3, |
| 146 | C_STATE_C7S_LONG_LAT |
| 147 | }; |
| 148 | |
| 149 | static int get_cores_per_package(void) |
| 150 | { |
| 151 | struct cpuinfo_x86 c; |
| 152 | struct cpuid_result result; |
| 153 | int cores = 1; |
| 154 | |
| 155 | get_fms(&c, cpuid_eax(1)); |
| 156 | if (c.x86 != 6) |
| 157 | return 1; |
| 158 | |
| 159 | result = cpuid_ext(0xb, 1); |
| 160 | cores = result.ebx & 0xff; |
| 161 | |
| 162 | return cores; |
| 163 | } |
| 164 | |
| 165 | void acpi_init_gnvs(global_nvs_t *gnvs) |
| 166 | { |
| 167 | /* Set unknown wake source */ |
| 168 | gnvs->pm1i = -1; |
| 169 | |
| 170 | /* CPU core count */ |
| 171 | gnvs->pcnt = dev_count_cpu(); |
| 172 | |
Martin Roth | e6ff159 | 2017-06-24 21:34:29 -0600 | [diff] [blame] | 173 | #if IS_ENABLED(CONFIG_CONSOLE_CBMEM) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 174 | /* Update the mem console pointer. */ |
| 175 | gnvs->cbmc = (u32)cbmem_find(CBMEM_ID_CONSOLE); |
| 176 | #endif |
| 177 | |
Martin Roth | e6ff159 | 2017-06-24 21:34:29 -0600 | [diff] [blame] | 178 | #if IS_ENABLED(CONFIG_CHROMEOS) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 179 | /* Initialize Verified Boot data */ |
| 180 | chromeos_init_vboot(&(gnvs->chromeos)); |
Martin Roth | e6ff159 | 2017-06-24 21:34:29 -0600 | [diff] [blame] | 181 | #if IS_ENABLED(CONFIG_EC_GOOGLE_CHROMEEC) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 182 | gnvs->chromeos.vbt2 = google_ec_running_ro() ? |
| 183 | ACTIVE_ECFW_RO : ACTIVE_ECFW_RW; |
| 184 | #endif |
| 185 | gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO; |
| 186 | #endif |
| 187 | } |
| 188 | |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 189 | void acpi_create_intel_hpet(acpi_hpet_t *hpet) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 190 | { |
| 191 | acpi_header_t *header = &(hpet->header); |
| 192 | acpi_addr_t *addr = &(hpet->addr); |
| 193 | |
| 194 | memset((void *) hpet, 0, sizeof(acpi_hpet_t)); |
| 195 | |
| 196 | /* fill out header fields */ |
| 197 | memcpy(header->signature, "HPET", 4); |
| 198 | memcpy(header->oem_id, OEM_ID, 6); |
| 199 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 200 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 201 | |
| 202 | header->length = sizeof(acpi_hpet_t); |
| 203 | header->revision = 1; |
| 204 | |
| 205 | /* fill out HPET address */ |
| 206 | addr->space_id = 0; /* Memory */ |
| 207 | addr->bit_width = 64; |
| 208 | addr->bit_offset = 0; |
| 209 | addr->addrl = (unsigned long long)HPET_BASE_ADDRESS & 0xffffffff; |
| 210 | addr->addrh = (unsigned long long)HPET_BASE_ADDRESS >> 32; |
| 211 | |
| 212 | hpet->id = 0x8086a201; /* Intel */ |
| 213 | hpet->number = 0x00; |
| 214 | hpet->min_tick = 0x0080; |
| 215 | |
| 216 | header->checksum = |
| 217 | acpi_checksum((void *) hpet, sizeof(acpi_hpet_t)); |
| 218 | } |
| 219 | |
| 220 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 221 | { |
| 222 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current, |
| 223 | MCFG_BASE_ADDRESS, 0, 0, 255); |
| 224 | return current; |
| 225 | } |
| 226 | |
| 227 | void acpi_fill_in_fadt(acpi_fadt_t *fadt) |
| 228 | { |
| 229 | const uint16_t pmbase = ACPI_BASE_ADDRESS; |
| 230 | |
| 231 | fadt->sci_int = acpi_sci_irq(); |
| 232 | fadt->smi_cmd = APM_CNT; |
| 233 | fadt->acpi_enable = APM_CNT_ACPI_ENABLE; |
| 234 | fadt->acpi_disable = APM_CNT_ACPI_DISABLE; |
| 235 | fadt->s4bios_req = 0x0; |
| 236 | fadt->pstate_cnt = 0; |
| 237 | |
| 238 | fadt->pm1a_evt_blk = pmbase + PM1_STS; |
| 239 | fadt->pm1b_evt_blk = 0x0; |
| 240 | fadt->pm1a_cnt_blk = pmbase + PM1_CNT; |
| 241 | fadt->pm1b_cnt_blk = 0x0; |
| 242 | fadt->pm2_cnt_blk = pmbase + PM2_CNT; |
| 243 | fadt->pm_tmr_blk = pmbase + PM1_TMR; |
| 244 | fadt->gpe0_blk = pmbase + GPE0_STS(0); |
| 245 | fadt->gpe1_blk = 0; |
| 246 | |
| 247 | fadt->pm1_evt_len = 4; |
| 248 | fadt->pm1_cnt_len = 2; |
| 249 | fadt->pm2_cnt_len = 1; |
| 250 | fadt->pm_tmr_len = 4; |
| 251 | fadt->gpe0_blk_len = 32; |
| 252 | fadt->gpe1_blk_len = 0; |
| 253 | fadt->gpe1_base = 0; |
| 254 | fadt->cst_cnt = 0; |
| 255 | fadt->p_lvl2_lat = 1; |
| 256 | fadt->p_lvl3_lat = 87; |
| 257 | fadt->flush_size = 1024; |
| 258 | fadt->flush_stride = 16; |
| 259 | fadt->duty_offset = 1; |
| 260 | fadt->duty_width = 0; |
| 261 | fadt->day_alrm = 0xd; |
| 262 | fadt->mon_alrm = 0x00; |
| 263 | fadt->century = 0x00; |
| 264 | fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042; |
| 265 | |
| 266 | fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED | |
| 267 | ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON | |
| 268 | ACPI_FADT_RESET_REGISTER | ACPI_FADT_SEALED_CASE | |
| 269 | ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_PLATFORM_CLOCK; |
| 270 | |
| 271 | fadt->reset_reg.space_id = 1; |
| 272 | fadt->reset_reg.bit_width = 8; |
| 273 | fadt->reset_reg.bit_offset = 0; |
| 274 | fadt->reset_reg.resv = 0; |
| 275 | fadt->reset_reg.addrl = 0xcf9; |
| 276 | fadt->reset_reg.addrh = 0; |
| 277 | fadt->reset_value = 6; |
| 278 | |
| 279 | fadt->x_pm1a_evt_blk.space_id = 1; |
| 280 | fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8; |
| 281 | fadt->x_pm1a_evt_blk.bit_offset = 0; |
| 282 | fadt->x_pm1a_evt_blk.resv = 0; |
| 283 | fadt->x_pm1a_evt_blk.addrl = pmbase + PM1_STS; |
| 284 | fadt->x_pm1a_evt_blk.addrh = 0x0; |
| 285 | |
| 286 | fadt->x_pm1b_evt_blk.space_id = 1; |
| 287 | fadt->x_pm1b_evt_blk.bit_width = 0; |
| 288 | fadt->x_pm1b_evt_blk.bit_offset = 0; |
| 289 | fadt->x_pm1b_evt_blk.resv = 0; |
| 290 | fadt->x_pm1b_evt_blk.addrl = 0x0; |
| 291 | fadt->x_pm1b_evt_blk.addrh = 0x0; |
| 292 | |
| 293 | fadt->x_pm1a_cnt_blk.space_id = 1; |
| 294 | fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8; |
| 295 | fadt->x_pm1a_cnt_blk.bit_offset = 0; |
| 296 | fadt->x_pm1a_cnt_blk.resv = 0; |
| 297 | fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT; |
| 298 | fadt->x_pm1a_cnt_blk.addrh = 0x0; |
| 299 | |
| 300 | fadt->x_pm1b_cnt_blk.space_id = 1; |
| 301 | fadt->x_pm1b_cnt_blk.bit_width = 0; |
| 302 | fadt->x_pm1b_cnt_blk.bit_offset = 0; |
| 303 | fadt->x_pm1b_cnt_blk.resv = 0; |
| 304 | fadt->x_pm1b_cnt_blk.addrl = 0x0; |
| 305 | fadt->x_pm1b_cnt_blk.addrh = 0x0; |
| 306 | |
| 307 | fadt->x_pm2_cnt_blk.space_id = 1; |
| 308 | fadt->x_pm2_cnt_blk.bit_width = fadt->pm2_cnt_len * 8; |
| 309 | fadt->x_pm2_cnt_blk.bit_offset = 0; |
| 310 | fadt->x_pm2_cnt_blk.resv = 0; |
| 311 | fadt->x_pm2_cnt_blk.addrl = pmbase + PM2_CNT; |
| 312 | fadt->x_pm2_cnt_blk.addrh = 0x0; |
| 313 | |
| 314 | fadt->x_pm_tmr_blk.space_id = 1; |
| 315 | fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8; |
| 316 | fadt->x_pm_tmr_blk.bit_offset = 0; |
| 317 | fadt->x_pm_tmr_blk.resv = 0; |
| 318 | fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR; |
| 319 | fadt->x_pm_tmr_blk.addrh = 0x0; |
| 320 | |
| 321 | fadt->x_gpe0_blk.space_id = 0; |
| 322 | fadt->x_gpe0_blk.bit_width = 0; |
| 323 | fadt->x_gpe0_blk.bit_offset = 0; |
| 324 | fadt->x_gpe0_blk.resv = 0; |
| 325 | fadt->x_gpe0_blk.addrl = 0; |
| 326 | fadt->x_gpe0_blk.addrh = 0; |
| 327 | |
| 328 | fadt->x_gpe1_blk.space_id = 1; |
| 329 | fadt->x_gpe1_blk.bit_width = 0; |
| 330 | fadt->x_gpe1_blk.bit_offset = 0; |
| 331 | fadt->x_gpe1_blk.resv = 0; |
| 332 | fadt->x_gpe1_blk.addrl = 0x0; |
| 333 | fadt->x_gpe1_blk.addrh = 0x0; |
| 334 | } |
| 335 | |
| 336 | static acpi_tstate_t tss_table_fine[] = { |
| 337 | { 100, 1000, 0, 0x00, 0 }, |
| 338 | { 94, 940, 0, 0x1f, 0 }, |
| 339 | { 88, 880, 0, 0x1e, 0 }, |
| 340 | { 82, 820, 0, 0x1d, 0 }, |
| 341 | { 75, 760, 0, 0x1c, 0 }, |
| 342 | { 69, 700, 0, 0x1b, 0 }, |
| 343 | { 63, 640, 0, 0x1a, 0 }, |
| 344 | { 57, 580, 0, 0x19, 0 }, |
| 345 | { 50, 520, 0, 0x18, 0 }, |
| 346 | { 44, 460, 0, 0x17, 0 }, |
| 347 | { 38, 400, 0, 0x16, 0 }, |
| 348 | { 32, 340, 0, 0x15, 0 }, |
| 349 | { 25, 280, 0, 0x14, 0 }, |
| 350 | { 19, 220, 0, 0x13, 0 }, |
| 351 | { 13, 160, 0, 0x12, 0 }, |
| 352 | }; |
| 353 | |
| 354 | static acpi_tstate_t tss_table_coarse[] = { |
| 355 | { 100, 1000, 0, 0x00, 0 }, |
| 356 | { 88, 875, 0, 0x1f, 0 }, |
| 357 | { 75, 750, 0, 0x1e, 0 }, |
| 358 | { 63, 625, 0, 0x1d, 0 }, |
| 359 | { 50, 500, 0, 0x1c, 0 }, |
| 360 | { 38, 375, 0, 0x1b, 0 }, |
| 361 | { 25, 250, 0, 0x1a, 0 }, |
| 362 | { 13, 125, 0, 0x19, 0 }, |
| 363 | }; |
| 364 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 365 | static void generate_T_state_entries(int core, int cores_per_package) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 366 | { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 367 | /* Indicate SW_ALL coordination for T-states */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 368 | acpigen_write_TSD_package(core, cores_per_package, SW_ALL); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 369 | |
| 370 | /* Indicate FFixedHW so OS will use MSR */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 371 | acpigen_write_empty_PTC(); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 372 | |
| 373 | /* Set a T-state limit that can be modified in NVS */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 374 | acpigen_write_TPC("\\TLVL"); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 375 | |
| 376 | /* |
| 377 | * CPUID.(EAX=6):EAX[5] indicates support |
| 378 | * for extended throttle levels. |
| 379 | */ |
| 380 | if (cpuid_eax(6) & (1 << 5)) |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 381 | acpigen_write_TSS_package( |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 382 | ARRAY_SIZE(tss_table_fine), tss_table_fine); |
| 383 | else |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 384 | acpigen_write_TSS_package( |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 385 | ARRAY_SIZE(tss_table_coarse), tss_table_coarse); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 388 | static void generate_C_state_entries(void) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 389 | { |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 390 | struct device *dev = SA_DEV_ROOT; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 391 | config_t *config = dev->chip_info; |
| 392 | acpi_cstate_t map[3]; |
| 393 | int *set; |
| 394 | int i; |
| 395 | |
| 396 | if (config->s0ix_enable) |
| 397 | set = cstate_set_s0ix; |
| 398 | else |
| 399 | set = cstate_set_non_s0ix; |
| 400 | |
| 401 | for (i = 0; i < 3; i++) { |
| 402 | memcpy(&map[i], &cstate_map[set[i]], sizeof(acpi_cstate_t)); |
| 403 | map[i].ctype = i + 1; |
| 404 | } |
| 405 | |
| 406 | /* Generate C-state tables */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 407 | acpigen_write_CST_package(map, ARRAY_SIZE(map)); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | static int calculate_power(int tdp, int p1_ratio, int ratio) |
| 411 | { |
| 412 | u32 m; |
| 413 | u32 power; |
| 414 | |
| 415 | /* |
| 416 | * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2 |
| 417 | * |
| 418 | * Power = (ratio / p1_ratio) * m * tdp |
| 419 | */ |
| 420 | |
| 421 | m = (110000 - ((p1_ratio - ratio) * 625)) / 11; |
| 422 | m = (m * m) / 1000; |
| 423 | |
| 424 | power = ((ratio * 100000 / p1_ratio) / 100); |
| 425 | power *= (m / 100) * (tdp / 1000); |
| 426 | power /= 1000; |
| 427 | |
| 428 | return (int)power; |
| 429 | } |
| 430 | |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 431 | static void generate_P_state_entries(int core, int cores_per_package) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 432 | { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 433 | int ratio_min, ratio_max, ratio_turbo, ratio_step; |
| 434 | int coord_type, power_max, power_unit, num_entries; |
| 435 | int ratio, power, clock, clock_max; |
| 436 | msr_t msr; |
| 437 | |
| 438 | /* Determine P-state coordination type from MISC_PWR_MGMT[0] */ |
| 439 | msr = rdmsr(MSR_MISC_PWR_MGMT); |
| 440 | if (msr.lo & MISC_PWR_MGMT_EIST_HW_DIS) |
| 441 | coord_type = SW_ANY; |
| 442 | else |
| 443 | coord_type = HW_ALL; |
| 444 | |
| 445 | /* Get bus ratio limits and calculate clock speeds */ |
| 446 | msr = rdmsr(MSR_PLATFORM_INFO); |
| 447 | ratio_min = (msr.hi >> (40-32)) & 0xff; /* Max Efficiency Ratio */ |
| 448 | |
| 449 | /* Determine if this CPU has configurable TDP */ |
| 450 | if (cpu_config_tdp_levels()) { |
| 451 | /* Set max ratio to nominal TDP ratio */ |
| 452 | msr = rdmsr(MSR_CONFIG_TDP_NOMINAL); |
| 453 | ratio_max = msr.lo & 0xff; |
| 454 | } else { |
| 455 | /* Max Non-Turbo Ratio */ |
| 456 | ratio_max = (msr.lo >> 8) & 0xff; |
| 457 | } |
| 458 | clock_max = ratio_max * CPU_BCLK; |
| 459 | |
| 460 | /* Calculate CPU TDP in mW */ |
| 461 | msr = rdmsr(MSR_PKG_POWER_SKU_UNIT); |
| 462 | power_unit = 2 << ((msr.lo & 0xf) - 1); |
| 463 | msr = rdmsr(MSR_PKG_POWER_SKU); |
| 464 | power_max = ((msr.lo & 0x7fff) / power_unit) * 1000; |
| 465 | |
| 466 | /* Write _PCT indicating use of FFixedHW */ |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 467 | acpigen_write_empty_PCT(); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 468 | |
| 469 | /* Write _PPC with no limit on supported P-state */ |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 470 | acpigen_write_PPC_NVS(); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 471 | |
| 472 | /* Write PSD indicating configured coordination type */ |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 473 | acpigen_write_PSD_package(core, 1, coord_type); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 474 | |
| 475 | /* Add P-state entries in _PSS table */ |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 476 | acpigen_write_name("_PSS"); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 477 | |
| 478 | /* Determine ratio points */ |
| 479 | ratio_step = PSS_RATIO_STEP; |
| 480 | num_entries = (ratio_max - ratio_min) / ratio_step; |
| 481 | while (num_entries > PSS_MAX_ENTRIES-1) { |
| 482 | ratio_step <<= 1; |
| 483 | num_entries >>= 1; |
| 484 | } |
| 485 | |
| 486 | /* P[T] is Turbo state if enabled */ |
| 487 | if (get_turbo_state() == TURBO_ENABLED) { |
| 488 | /* _PSS package count including Turbo */ |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 489 | acpigen_write_package(num_entries + 2); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 490 | |
| 491 | msr = rdmsr(MSR_TURBO_RATIO_LIMIT); |
| 492 | ratio_turbo = msr.lo & 0xff; |
| 493 | |
| 494 | /* Add entry for Turbo ratio */ |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 495 | acpigen_write_PSS_package( |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 496 | clock_max + 1, /*MHz*/ |
| 497 | power_max, /*mW*/ |
| 498 | PSS_LATENCY_TRANSITION, /*lat1*/ |
| 499 | PSS_LATENCY_BUSMASTER, /*lat2*/ |
| 500 | ratio_turbo << 8, /*control*/ |
| 501 | ratio_turbo << 8); /*status*/ |
| 502 | } else { |
| 503 | /* _PSS package count without Turbo */ |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 504 | acpigen_write_package(num_entries + 1); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | /* First regular entry is max non-turbo ratio */ |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 508 | acpigen_write_PSS_package( |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 509 | clock_max, /*MHz*/ |
| 510 | power_max, /*mW*/ |
| 511 | PSS_LATENCY_TRANSITION, /*lat1*/ |
| 512 | PSS_LATENCY_BUSMASTER, /*lat2*/ |
| 513 | ratio_max << 8, /*control*/ |
| 514 | ratio_max << 8); /*status*/ |
| 515 | |
| 516 | /* Generate the remaining entries */ |
| 517 | for (ratio = ratio_min + ((num_entries - 1) * ratio_step); |
| 518 | ratio >= ratio_min; ratio -= ratio_step) { |
| 519 | |
| 520 | /* Calculate power at this ratio */ |
| 521 | power = calculate_power(power_max, ratio_max, ratio); |
| 522 | clock = ratio * CPU_BCLK; |
| 523 | |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 524 | acpigen_write_PSS_package( |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 525 | clock, /*MHz*/ |
| 526 | power, /*mW*/ |
| 527 | PSS_LATENCY_TRANSITION, /*lat1*/ |
| 528 | PSS_LATENCY_BUSMASTER, /*lat2*/ |
| 529 | ratio << 8, /*control*/ |
| 530 | ratio << 8); /*status*/ |
| 531 | } |
| 532 | |
| 533 | /* Fix package length */ |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 534 | acpigen_pop_len(); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 537 | void generate_cpu_entries(struct device *device) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 538 | { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 539 | int coreID, cpuID, pcontrol_blk = ACPI_BASE_ADDRESS, plen = 6; |
| 540 | int totalcores = dev_count_cpu(); |
| 541 | int cores_per_package = get_cores_per_package(); |
| 542 | int numcpus = totalcores/cores_per_package; |
| 543 | |
| 544 | printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n", |
| 545 | numcpus, cores_per_package); |
| 546 | |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 547 | for (cpuID = 1; cpuID <= numcpus; cpuID++) { |
| 548 | for (coreID = 1; coreID <= cores_per_package; coreID++) { |
| 549 | if (coreID > 1) { |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 550 | pcontrol_blk = 0; |
| 551 | plen = 0; |
| 552 | } |
| 553 | |
| 554 | /* Generate processor \_PR.CPUx */ |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 555 | acpigen_write_processor( |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 556 | (cpuID - 1) * cores_per_package+coreID - 1, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 557 | pcontrol_blk, plen); |
| 558 | |
| 559 | /* Generate P-state tables */ |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 560 | generate_P_state_entries( |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 561 | coreID - 1, cores_per_package); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 562 | |
| 563 | /* Generate C-state tables */ |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 564 | generate_C_state_entries(); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 565 | |
| 566 | /* Generate T-state tables */ |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 567 | generate_T_state_entries( |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 568 | cpuID - 1, cores_per_package); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 569 | |
Vladimir Serbinenko | b219da8 | 2014-11-09 03:29:30 +0100 | [diff] [blame] | 570 | acpigen_pop_len(); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | } |
| 574 | |
Matt DeVillier | 0f49bbc | 2018-02-19 17:35:55 -0600 | [diff] [blame] | 575 | static unsigned long acpi_fill_dmar(unsigned long current) |
| 576 | { |
| 577 | struct device *const igfx_dev = dev_find_slot(0, SA_DEVFN_IGD); |
| 578 | const u32 gfxvtbar = MCHBAR32(GFXVTBAR) & ~0xfff; |
| 579 | const u32 vtvc0bar = MCHBAR32(VTVC0BAR) & ~0xfff; |
| 580 | const bool gfxvten = MCHBAR32(GFXVTBAR) & 0x1; |
| 581 | const bool vtvc0en = MCHBAR32(VTVC0BAR) & 0x1; |
| 582 | |
| 583 | /* iGFX has to be enabled; GFXVTBAR set, enabled, in 32-bit space */ |
| 584 | if (igfx_dev && igfx_dev->enabled && gfxvtbar |
| 585 | && gfxvten && !MCHBAR32(GFXVTBAR + 4)) { |
| 586 | const unsigned long tmp = current; |
| 587 | |
| 588 | current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar); |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame^] | 589 | current += acpi_create_dmar_ds_pci(current, 0, 2, 0); |
Matt DeVillier | 0f49bbc | 2018-02-19 17:35:55 -0600 | [diff] [blame] | 590 | |
| 591 | acpi_dmar_drhd_fixup(tmp, current); |
| 592 | } |
| 593 | |
| 594 | /* VTVC0BAR has to be set, enabled, and in 32-bit space */ |
| 595 | if (vtvc0bar && vtvc0en && !MCHBAR32(VTVC0BAR + 4)) { |
| 596 | const unsigned long tmp = current; |
| 597 | current += acpi_create_dmar_drhd(current, |
| 598 | DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar); |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame^] | 599 | current += acpi_create_dmar_ds_ioapic(current, |
Matt DeVillier | 0f49bbc | 2018-02-19 17:35:55 -0600 | [diff] [blame] | 600 | 2, PCH_IOAPIC_PCI_BUS, PCH_IOAPIC_PCI_SLOT, 0); |
| 601 | size_t i; |
| 602 | for (i = 0; i < 8; ++i) |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame^] | 603 | current += acpi_create_dmar_ds_msi_hpet(current, |
Matt DeVillier | 0f49bbc | 2018-02-19 17:35:55 -0600 | [diff] [blame] | 604 | 0, PCH_HPET_PCI_BUS, |
| 605 | PCH_HPET_PCI_SLOT, i); |
| 606 | acpi_dmar_drhd_fixup(tmp, current); |
| 607 | } |
| 608 | |
| 609 | return current; |
| 610 | } |
| 611 | |
| 612 | unsigned long northbridge_write_acpi_tables(struct device *const dev, |
| 613 | unsigned long current, |
| 614 | struct acpi_rsdp *const rsdp) |
| 615 | { |
| 616 | /* Create DMAR table only if we have VT-d capability. */ |
| 617 | const u32 capid0_a = pci_read_config32(dev, CAPID0_A); |
| 618 | if (capid0_a & VTD_DISABLE) |
| 619 | return current; |
| 620 | |
| 621 | acpi_dmar_t *const dmar = (acpi_dmar_t *)current; |
| 622 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
| 623 | acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar); |
| 624 | current += dmar->header.length; |
| 625 | current = acpi_align_current(current); |
| 626 | acpi_add_table(rsdp, dmar); |
| 627 | |
| 628 | return current; |
| 629 | } |
| 630 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 631 | unsigned long acpi_madt_irq_overrides(unsigned long current) |
| 632 | { |
| 633 | int sci = acpi_sci_irq(); |
| 634 | acpi_madt_irqoverride_t *irqovr; |
| 635 | uint16_t flags = MP_IRQ_TRIGGER_LEVEL; |
| 636 | |
| 637 | /* INT_SRC_OVR */ |
| 638 | irqovr = (void *)current; |
| 639 | current += acpi_create_madt_irqoverride(irqovr, 0, 0, 2, 0); |
| 640 | |
| 641 | if (sci >= 20) |
| 642 | flags |= MP_IRQ_POLARITY_LOW; |
| 643 | else |
| 644 | flags |= MP_IRQ_POLARITY_HIGH; |
| 645 | |
| 646 | /* SCI */ |
| 647 | irqovr = (void *)current; |
| 648 | current += acpi_create_madt_irqoverride(irqovr, 0, sci, sci, flags); |
| 649 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 650 | return current; |
| 651 | } |