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