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