Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
Elyes HAOUAS | a1e22b8 | 2019-03-18 22:49:36 +0100 | [diff] [blame] | 15 | |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 16 | #include <arch/acpigen.h> |
| 17 | #include <arch/ioapic.h> |
| 18 | #include <arch/smp/mpspec.h> |
| 19 | #include <bootstate.h> |
| 20 | #include <cbmem.h> |
Patrick Rudolph | f677d17 | 2018-10-01 19:17:11 +0200 | [diff] [blame] | 21 | #include <cf9_reset.h> |
Elyes HAOUAS | 20eaef0 | 2019-03-29 17:45:28 +0100 | [diff] [blame] | 22 | #include <console/console.h> |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 23 | #include <cpu/intel/turbo.h> |
| 24 | #include <cpu/x86/msr.h> |
| 25 | #include <cpu/x86/smm.h> |
| 26 | #include <intelblocks/acpi.h> |
| 27 | #include <intelblocks/msr.h> |
| 28 | #include <intelblocks/pmclib.h> |
Duncan Laurie | 93bbd41 | 2017-11-11 20:03:29 -0800 | [diff] [blame] | 29 | #include <intelblocks/uart.h> |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 30 | #include <soc/gpio.h> |
| 31 | #include <soc/iomap.h> |
| 32 | #include <soc/nvs.h> |
| 33 | #include <soc/pm.h> |
Elyes HAOUAS | a1e22b8 | 2019-03-18 22:49:36 +0100 | [diff] [blame] | 34 | #include <string.h> |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 35 | |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 36 | __attribute__((weak)) unsigned long acpi_fill_mcfg(unsigned long current) |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 37 | { |
| 38 | /* PCI Segment Group 0, Start Bus Number 0, End Bus Number is 255 */ |
| 39 | current += acpi_create_mcfg_mmconfig((void *)current, |
| 40 | CONFIG_MMCONF_BASE_ADDRESS, 0, 0, |
Duncan Laurie | fd50b7c | 2018-03-02 14:47:11 -0800 | [diff] [blame] | 41 | (CONFIG_SA_PCIEX_LENGTH >> 20) - 1); |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 42 | return current; |
| 43 | } |
| 44 | |
| 45 | static int acpi_sci_irq(void) |
| 46 | { |
| 47 | int sci_irq = 9; |
| 48 | uint32_t scis; |
| 49 | |
| 50 | scis = soc_read_sci_irq_select(); |
| 51 | scis &= SCI_IRQ_SEL; |
| 52 | scis >>= SCI_IRQ_ADJUST; |
| 53 | |
| 54 | /* Determine how SCI is routed. */ |
| 55 | switch (scis) { |
| 56 | case SCIS_IRQ9: |
| 57 | case SCIS_IRQ10: |
| 58 | case SCIS_IRQ11: |
| 59 | sci_irq = scis - SCIS_IRQ9 + 9; |
| 60 | break; |
| 61 | case SCIS_IRQ20: |
| 62 | case SCIS_IRQ21: |
| 63 | case SCIS_IRQ22: |
| 64 | case SCIS_IRQ23: |
| 65 | sci_irq = scis - SCIS_IRQ20 + 20; |
| 66 | break; |
| 67 | default: |
| 68 | printk(BIOS_DEBUG, "Invalid SCI route! Defaulting to IRQ9.\n"); |
| 69 | sci_irq = 9; |
| 70 | break; |
| 71 | } |
| 72 | |
| 73 | printk(BIOS_DEBUG, "SCI is IRQ%d\n", sci_irq); |
| 74 | return sci_irq; |
| 75 | } |
| 76 | |
| 77 | static unsigned long acpi_madt_irq_overrides(unsigned long current) |
| 78 | { |
| 79 | int sci = acpi_sci_irq(); |
| 80 | uint16_t flags = MP_IRQ_TRIGGER_LEVEL; |
| 81 | |
| 82 | /* INT_SRC_OVR */ |
| 83 | current += acpi_create_madt_irqoverride((void *)current, 0, 0, 2, 0); |
| 84 | |
| 85 | flags |= soc_madt_sci_irq_polarity(sci); |
| 86 | |
| 87 | /* SCI */ |
| 88 | current += |
| 89 | acpi_create_madt_irqoverride((void *)current, 0, sci, sci, flags); |
| 90 | |
| 91 | return current; |
| 92 | } |
| 93 | |
| 94 | unsigned long acpi_fill_madt(unsigned long current) |
| 95 | { |
| 96 | /* Local APICs */ |
| 97 | current = acpi_create_madt_lapics(current); |
| 98 | |
| 99 | /* IOAPIC */ |
| 100 | current += acpi_create_madt_ioapic((void *)current, 2, IO_APIC_ADDR, 0); |
| 101 | |
| 102 | return acpi_madt_irq_overrides(current); |
| 103 | } |
| 104 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 105 | __weak void soc_fill_fadt(acpi_fadt_t *fadt) |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 106 | { |
| 107 | } |
| 108 | |
| 109 | void acpi_fill_fadt(acpi_fadt_t *fadt) |
| 110 | { |
| 111 | const uint16_t pmbase = ACPI_BASE_ADDRESS; |
| 112 | |
Marc Jones | f9ea7ed | 2018-08-22 18:59:26 -0600 | [diff] [blame] | 113 | fadt->header.revision = get_acpi_table_revision(FADT); |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 114 | |
| 115 | fadt->sci_int = acpi_sci_irq(); |
| 116 | fadt->smi_cmd = APM_CNT; |
| 117 | fadt->acpi_enable = APM_CNT_ACPI_ENABLE; |
| 118 | fadt->acpi_disable = APM_CNT_ACPI_DISABLE; |
| 119 | fadt->s4bios_req = 0x0; |
| 120 | fadt->pstate_cnt = 0; |
| 121 | |
| 122 | fadt->pm1a_evt_blk = pmbase + PM1_STS; |
| 123 | fadt->pm1b_evt_blk = 0x0; |
| 124 | fadt->pm1a_cnt_blk = pmbase + PM1_CNT; |
| 125 | fadt->pm1b_cnt_blk = 0x0; |
| 126 | |
| 127 | fadt->gpe0_blk = pmbase + GPE0_STS(0); |
| 128 | |
| 129 | fadt->pm1_evt_len = 4; |
| 130 | fadt->pm1_cnt_len = 2; |
| 131 | |
| 132 | /* GPE0 STS/EN pairs each 32 bits wide. */ |
| 133 | fadt->gpe0_blk_len = 2 * GPE0_REG_MAX * sizeof(uint32_t); |
| 134 | |
| 135 | fadt->flush_size = 0x400; /* twice of cache size */ |
| 136 | fadt->flush_stride = 0x10; /* Cache line width */ |
| 137 | fadt->duty_offset = 1; |
| 138 | fadt->day_alrm = 0xd; |
| 139 | |
| 140 | fadt->flags = ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED | |
| 141 | ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON | |
| 142 | ACPI_FADT_RESET_REGISTER | ACPI_FADT_SEALED_CASE | |
| 143 | ACPI_FADT_S4_RTC_WAKE | ACPI_FADT_PLATFORM_CLOCK; |
| 144 | |
| 145 | fadt->reset_reg.space_id = 1; |
| 146 | fadt->reset_reg.bit_width = 8; |
| 147 | fadt->reset_reg.addrl = RST_CNT; |
Patrick Rudolph | c02bda0 | 2020-02-28 10:19:41 +0100 | [diff] [blame^] | 148 | fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 149 | fadt->reset_value = RST_CPU | SYS_RST; |
| 150 | |
| 151 | fadt->x_pm1a_evt_blk.space_id = 1; |
| 152 | fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8; |
| 153 | fadt->x_pm1a_evt_blk.addrl = pmbase + PM1_STS; |
Patrick Rudolph | c02bda0 | 2020-02-28 10:19:41 +0100 | [diff] [blame^] | 154 | fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 155 | |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 156 | |
| 157 | fadt->x_pm1b_evt_blk.space_id = 1; |
| 158 | |
| 159 | fadt->x_pm1a_cnt_blk.space_id = 1; |
| 160 | fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8; |
| 161 | fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT; |
Patrick Rudolph | c02bda0 | 2020-02-28 10:19:41 +0100 | [diff] [blame^] | 162 | fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 163 | |
| 164 | fadt->x_pm1b_cnt_blk.space_id = 1; |
| 165 | |
Patrick Rudolph | c02bda0 | 2020-02-28 10:19:41 +0100 | [diff] [blame^] | 166 | /* |
| 167 | * Windows 10 requires x_gpe0_blk to be set starting with FADT revision 5. |
| 168 | * The bit_width field intentionally overflows here. |
| 169 | * The OSPM can instead use the values in `fadt->gpe0_blk{,_len}`, which |
| 170 | * seems to work fine on Linux 5.0 and Windows 10. |
| 171 | */ |
| 172 | fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 173 | fadt->x_gpe0_blk.bit_width = fadt->gpe0_blk_len * 8; |
| 174 | fadt->x_gpe0_blk.bit_offset = 0; |
| 175 | fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 176 | fadt->x_gpe0_blk.addrl = fadt->gpe0_blk; |
| 177 | fadt->x_gpe0_blk.addrh = 0; |
| 178 | |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 179 | fadt->x_gpe1_blk.space_id = 1; |
| 180 | |
| 181 | soc_fill_fadt(fadt); |
| 182 | } |
| 183 | |
Elyes HAOUAS | 68c851b | 2018-06-12 22:06:09 +0200 | [diff] [blame] | 184 | unsigned long southbridge_write_acpi_tables(struct device *device, |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 185 | unsigned long current, |
| 186 | struct acpi_rsdp *rsdp) |
| 187 | { |
Duncan Laurie | 93bbd41 | 2017-11-11 20:03:29 -0800 | [diff] [blame] | 188 | current = acpi_write_dbg2_pci_uart(rsdp, current, |
Subrata Banik | afa07f7 | 2018-05-24 12:21:06 +0530 | [diff] [blame] | 189 | uart_get_device(), |
Duncan Laurie | 93bbd41 | 2017-11-11 20:03:29 -0800 | [diff] [blame] | 190 | ACPI_ACCESS_SIZE_DWORD_ACCESS); |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 191 | return acpi_write_hpet(device, current, rsdp); |
| 192 | } |
| 193 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 194 | __weak |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 195 | uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en, |
| 196 | const struct chipset_power_state *ps) |
| 197 | { |
| 198 | return generic_pm1_en; |
| 199 | } |
| 200 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 201 | #if CONFIG(SOC_INTEL_COMMON_ACPI_WAKE_SOURCE) |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 202 | /* |
| 203 | * Save wake source information for calculating ACPI _SWS values |
| 204 | * |
| 205 | * @pm1: PM1_STS register with only enabled events set |
| 206 | * @gpe0: GPE0_STS registers with only enabled events set |
| 207 | * |
| 208 | * return the number of registers in the gpe0 array or -1 if nothing |
| 209 | * is provided by this function. |
| 210 | */ |
| 211 | |
| 212 | static int acpi_fill_wake(uint32_t *pm1, uint32_t **gpe0) |
| 213 | { |
| 214 | struct chipset_power_state *ps; |
| 215 | static uint32_t gpe0_sts[GPE0_REG_MAX]; |
| 216 | uint32_t pm1_en; |
| 217 | int i; |
| 218 | |
| 219 | ps = cbmem_find(CBMEM_ID_POWER_STATE); |
| 220 | if (ps == NULL) |
| 221 | return -1; |
| 222 | |
| 223 | /* |
| 224 | * PM1_EN to check the basic wake events which can happen through |
| 225 | * powerbtn or any other wake source like lidopen, key board press etc. |
| 226 | */ |
| 227 | pm1_en = ps->pm1_en; |
| 228 | |
| 229 | pm1_en = acpi_fill_soc_wake(pm1_en, ps); |
| 230 | |
| 231 | *pm1 = ps->pm1_sts & pm1_en; |
| 232 | |
| 233 | /* Mask off GPE0 status bits that are not enabled */ |
| 234 | *gpe0 = &gpe0_sts[0]; |
| 235 | for (i = 0; i < GPE0_REG_MAX; i++) |
| 236 | gpe0_sts[i] = ps->gpe0_sts[i] & ps->gpe0_en[i]; |
| 237 | |
| 238 | return GPE0_REG_MAX; |
| 239 | } |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 240 | #endif |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 241 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 242 | __weak void acpi_create_gnvs(struct global_nvs_t *gnvs) |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 243 | { |
| 244 | } |
| 245 | |
Elyes HAOUAS | 68c851b | 2018-06-12 22:06:09 +0200 | [diff] [blame] | 246 | void southbridge_inject_dsdt(struct device *device) |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 247 | { |
| 248 | struct global_nvs_t *gnvs; |
| 249 | |
| 250 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 251 | if (!gnvs) { |
| 252 | gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs)); |
| 253 | if (gnvs) |
| 254 | memset(gnvs, 0, sizeof(*gnvs)); |
| 255 | } |
| 256 | |
| 257 | if (gnvs) { |
| 258 | acpi_create_gnvs(gnvs); |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 259 | /* And tell SMI about it */ |
| 260 | smm_setup_structures(gnvs, NULL, NULL); |
| 261 | |
| 262 | /* Add it to DSDT. */ |
| 263 | acpigen_write_scope("\\"); |
| 264 | acpigen_write_name_dword("NVSA", (uintptr_t) gnvs); |
| 265 | acpigen_pop_len(); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | static int calculate_power(int tdp, int p1_ratio, int ratio) |
| 270 | { |
| 271 | u32 m; |
| 272 | u32 power; |
| 273 | |
| 274 | /* |
| 275 | * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2 |
| 276 | * |
| 277 | * Power = (ratio / p1_ratio) * m * tdp |
| 278 | */ |
| 279 | |
| 280 | m = (110000 - ((p1_ratio - ratio) * 625)) / 11; |
| 281 | m = (m * m) / 1000; |
| 282 | |
| 283 | power = ((ratio * 100000 / p1_ratio) / 100); |
| 284 | power *= (m / 100) * (tdp / 1000); |
| 285 | power /= 1000; |
| 286 | |
| 287 | return power; |
| 288 | } |
| 289 | |
| 290 | static int get_cores_per_package(void) |
| 291 | { |
| 292 | struct cpuinfo_x86 c; |
| 293 | struct cpuid_result result; |
| 294 | int cores = 1; |
| 295 | |
| 296 | get_fms(&c, cpuid_eax(1)); |
| 297 | if (c.x86 != 6) |
| 298 | return 1; |
| 299 | |
| 300 | result = cpuid_ext(0xb, 1); |
| 301 | cores = result.ebx & 0xff; |
| 302 | |
| 303 | return cores; |
| 304 | } |
| 305 | |
| 306 | static void generate_c_state_entries(void) |
| 307 | { |
| 308 | acpi_cstate_t *c_state_map; |
| 309 | size_t entries; |
| 310 | |
| 311 | c_state_map = soc_get_cstate_map(&entries); |
| 312 | |
| 313 | /* Generate C-state tables */ |
| 314 | acpigen_write_CST_package(c_state_map, entries); |
| 315 | } |
| 316 | |
| 317 | void generate_p_state_entries(int core, int cores_per_package) |
| 318 | { |
| 319 | int ratio_min, ratio_max, ratio_turbo, ratio_step; |
| 320 | int coord_type, power_max, num_entries; |
| 321 | int ratio, power, clock, clock_max; |
Julien Viard de Galbert | c2540a9 | 2018-11-06 09:28:03 +0100 | [diff] [blame] | 322 | bool turbo; |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 323 | |
| 324 | coord_type = cpu_get_coord_type(); |
| 325 | ratio_min = cpu_get_min_ratio(); |
| 326 | ratio_max = cpu_get_max_ratio(); |
| 327 | clock_max = (ratio_max * cpu_get_bus_clock()) / KHz; |
Julien Viard de Galbert | c2540a9 | 2018-11-06 09:28:03 +0100 | [diff] [blame] | 328 | turbo = (get_turbo_state() == TURBO_ENABLED); |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 329 | |
| 330 | /* Calculate CPU TDP in mW */ |
| 331 | power_max = cpu_get_power_max(); |
| 332 | |
| 333 | /* Write _PCT indicating use of FFixedHW */ |
| 334 | acpigen_write_empty_PCT(); |
| 335 | |
| 336 | /* Write _PPC with no limit on supported P-state */ |
| 337 | acpigen_write_PPC_NVS(); |
| 338 | /* Write PSD indicating configured coordination type */ |
| 339 | acpigen_write_PSD_package(core, 1, coord_type); |
| 340 | |
| 341 | /* Add P-state entries in _PSS table */ |
| 342 | acpigen_write_name("_PSS"); |
| 343 | |
| 344 | /* Determine ratio points */ |
| 345 | ratio_step = PSS_RATIO_STEP; |
Julien Viard de Galbert | c2540a9 | 2018-11-06 09:28:03 +0100 | [diff] [blame] | 346 | do { |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 347 | num_entries = ((ratio_max - ratio_min) / ratio_step) + 1; |
Julien Viard de Galbert | c2540a9 | 2018-11-06 09:28:03 +0100 | [diff] [blame] | 348 | if (((ratio_max - ratio_min) % ratio_step) > 0) |
| 349 | num_entries += 1; |
| 350 | if (turbo) |
| 351 | num_entries += 1; |
| 352 | if (num_entries > PSS_MAX_ENTRIES) |
| 353 | ratio_step += 1; |
| 354 | } while (num_entries > PSS_MAX_ENTRIES); |
| 355 | |
| 356 | /* _PSS package count depends on Turbo */ |
| 357 | acpigen_write_package(num_entries); |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 358 | |
| 359 | /* P[T] is Turbo state if enabled */ |
Julien Viard de Galbert | c2540a9 | 2018-11-06 09:28:03 +0100 | [diff] [blame] | 360 | if (turbo) { |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 361 | ratio_turbo = cpu_get_max_turbo_ratio(); |
| 362 | |
| 363 | /* Add entry for Turbo ratio */ |
| 364 | acpigen_write_PSS_package(clock_max + 1, /* MHz */ |
| 365 | power_max, /* mW */ |
| 366 | PSS_LATENCY_TRANSITION,/* lat1 */ |
| 367 | PSS_LATENCY_BUSMASTER,/* lat2 */ |
| 368 | ratio_turbo << 8, /* control */ |
| 369 | ratio_turbo << 8); /* status */ |
Julien Viard de Galbert | c2540a9 | 2018-11-06 09:28:03 +0100 | [diff] [blame] | 370 | num_entries -= 1; |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | /* First regular entry is max non-turbo ratio */ |
| 374 | acpigen_write_PSS_package(clock_max, /* MHz */ |
| 375 | power_max, /* mW */ |
| 376 | PSS_LATENCY_TRANSITION,/* lat1 */ |
| 377 | PSS_LATENCY_BUSMASTER,/* lat2 */ |
| 378 | ratio_max << 8, /* control */ |
| 379 | ratio_max << 8); /* status */ |
Julien Viard de Galbert | c2540a9 | 2018-11-06 09:28:03 +0100 | [diff] [blame] | 380 | num_entries -= 1; |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 381 | |
| 382 | /* Generate the remaining entries */ |
| 383 | for (ratio = ratio_min + ((num_entries - 1) * ratio_step); |
| 384 | ratio >= ratio_min; ratio -= ratio_step) { |
| 385 | |
| 386 | /* Calculate power at this ratio */ |
| 387 | power = calculate_power(power_max, ratio_max, ratio); |
| 388 | clock = (ratio * cpu_get_bus_clock()) / KHz; |
| 389 | |
| 390 | acpigen_write_PSS_package(clock, /* MHz */ |
| 391 | power, /* mW */ |
| 392 | PSS_LATENCY_TRANSITION,/* lat1 */ |
| 393 | PSS_LATENCY_BUSMASTER,/* lat2 */ |
| 394 | ratio << 8, /* control */ |
| 395 | ratio << 8); /* status */ |
| 396 | } |
| 397 | /* Fix package length */ |
| 398 | acpigen_pop_len(); |
| 399 | } |
| 400 | |
Julien Viard de Galbert | 595202c | 2018-03-29 14:01:01 +0200 | [diff] [blame] | 401 | __attribute__ ((weak)) acpi_tstate_t *soc_get_tss_table(int *entries) |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 402 | { |
| 403 | *entries = 0; |
| 404 | return NULL; |
| 405 | } |
| 406 | |
| 407 | void generate_t_state_entries(int core, int cores_per_package) |
| 408 | { |
| 409 | acpi_tstate_t *soc_tss_table; |
| 410 | int entries; |
| 411 | |
| 412 | soc_tss_table = soc_get_tss_table(&entries); |
| 413 | if (entries == 0) |
| 414 | return; |
| 415 | |
| 416 | /* Indicate SW_ALL coordination for T-states */ |
| 417 | acpigen_write_TSD_package(core, cores_per_package, SW_ALL); |
| 418 | |
| 419 | /* Indicate FixedHW so OS will use MSR */ |
| 420 | acpigen_write_empty_PTC(); |
| 421 | |
| 422 | /* Set NVS controlled T-state limit */ |
| 423 | acpigen_write_TPC("\\TLVL"); |
| 424 | |
| 425 | /* Write TSS table for MSR access */ |
| 426 | acpigen_write_TSS_package(entries, soc_tss_table); |
| 427 | } |
| 428 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 429 | __weak void soc_power_states_generation(int core_id, |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 430 | int cores_per_package) |
| 431 | { |
| 432 | } |
| 433 | |
Elyes HAOUAS | 68c851b | 2018-06-12 22:06:09 +0200 | [diff] [blame] | 434 | void generate_cpu_entries(struct device *device) |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 435 | { |
| 436 | int core_id, cpu_id, pcontrol_blk = ACPI_BASE_ADDRESS; |
| 437 | int plen = 6; |
| 438 | int totalcores = dev_count_cpu(); |
| 439 | int cores_per_package = get_cores_per_package(); |
| 440 | int numcpus = totalcores / cores_per_package; |
| 441 | |
| 442 | printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n", |
| 443 | numcpus, cores_per_package); |
| 444 | |
| 445 | for (cpu_id = 0; cpu_id < numcpus; cpu_id++) { |
| 446 | for (core_id = 0; core_id < cores_per_package; core_id++) { |
| 447 | if (core_id > 0) { |
| 448 | pcontrol_blk = 0; |
| 449 | plen = 0; |
| 450 | } |
| 451 | |
Christian Walter | be3979c | 2019-12-18 15:07:59 +0100 | [diff] [blame] | 452 | /* Generate processor \_SB.CPUx */ |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 453 | acpigen_write_processor((cpu_id) * cores_per_package + |
| 454 | core_id, pcontrol_blk, plen); |
| 455 | |
| 456 | /* Generate C-state tables */ |
| 457 | generate_c_state_entries(); |
| 458 | |
| 459 | /* Soc specific power states generation */ |
| 460 | soc_power_states_generation(core_id, cores_per_package); |
| 461 | |
| 462 | acpigen_pop_len(); |
| 463 | } |
| 464 | } |
Arthur Heymans | 0ac555e | 2018-11-28 12:25:54 +0100 | [diff] [blame] | 465 | /* PPKG is usually used for thermal management |
| 466 | of the first and only package. */ |
| 467 | acpigen_write_processor_package("PPKG", 0, cores_per_package); |
| 468 | |
| 469 | /* Add a method to notify processor nodes */ |
| 470 | acpigen_write_processor_cnot(cores_per_package); |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 473 | #if CONFIG(SOC_INTEL_COMMON_ACPI_WAKE_SOURCE) |
Shaunak Saha | bd42780 | 2017-07-18 00:19:33 -0700 | [diff] [blame] | 474 | /* Save wake source data for ACPI _SWS methods in NVS */ |
| 475 | static void acpi_save_wake_source(void *unused) |
| 476 | { |
| 477 | global_nvs_t *gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 478 | uint32_t pm1, *gpe0; |
| 479 | int gpe_reg, gpe_reg_count; |
| 480 | int reg_size = sizeof(uint32_t) * 8; |
| 481 | |
| 482 | if (!gnvs) |
| 483 | return; |
| 484 | |
| 485 | gnvs->pm1i = -1; |
| 486 | gnvs->gpei = -1; |
| 487 | |
| 488 | gpe_reg_count = acpi_fill_wake(&pm1, &gpe0); |
| 489 | if (gpe_reg_count < 0) |
| 490 | return; |
| 491 | |
| 492 | /* Scan for first set bit in PM1 */ |
| 493 | for (gnvs->pm1i = 0; gnvs->pm1i < reg_size; gnvs->pm1i++) { |
| 494 | if (pm1 & 1) |
| 495 | break; |
| 496 | pm1 >>= 1; |
| 497 | } |
| 498 | |
| 499 | /* If unable to determine then return -1 */ |
| 500 | if (gnvs->pm1i >= 16) |
| 501 | gnvs->pm1i = -1; |
| 502 | |
| 503 | /* Scan for first set bit in GPE registers */ |
| 504 | for (gpe_reg = 0; gpe_reg < gpe_reg_count; gpe_reg++) { |
| 505 | uint32_t gpe = gpe0[gpe_reg]; |
| 506 | int start = gpe_reg * reg_size; |
| 507 | int end = start + reg_size; |
| 508 | |
| 509 | if (gpe == 0) { |
| 510 | if (!gnvs->gpei) |
| 511 | gnvs->gpei = end; |
| 512 | continue; |
| 513 | } |
| 514 | |
| 515 | for (gnvs->gpei = start; gnvs->gpei < end; gnvs->gpei++) { |
| 516 | if (gpe & 1) |
| 517 | break; |
| 518 | gpe >>= 1; |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | /* If unable to determine then return -1 */ |
| 523 | if (gnvs->gpei >= gpe_reg_count * reg_size) |
| 524 | gnvs->gpei = -1; |
| 525 | |
| 526 | printk(BIOS_DEBUG, "ACPI _SWS is PM1 Index %lld GPE Index %lld\n", |
| 527 | (long long)gnvs->pm1i, (long long)gnvs->gpei); |
| 528 | } |
| 529 | |
| 530 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, acpi_save_wake_source, NULL); |
| 531 | |
| 532 | #endif |