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