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