Felix Held | 8602495 | 2021-02-03 23:44:28 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | /* ACPI - create the Fixed ACPI Description Tables (FADT) */ |
| 4 | |
| 5 | #include <acpi/acpi.h> |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 6 | #include <acpi/acpigen.h> |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 7 | #include <amdblocks/acpi.h> |
Felix Held | 8f7f4bf | 2022-08-03 22:10:05 +0200 | [diff] [blame] | 8 | #include <amdblocks/cppc.h> |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 9 | #include <amdblocks/cpu.h> |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 10 | #include <amdblocks/acpimmio.h> |
Raul E Rangel | 65819cd | 2021-02-16 10:37:46 -0700 | [diff] [blame] | 11 | #include <amdblocks/ioapic.h> |
| 12 | #include <arch/ioapic.h> |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 13 | #include <arch/smp/mpspec.h> |
| 14 | #include <console/console.h> |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 15 | #include <cpu/amd/cpuid.h> |
| 16 | #include <cpu/amd/msr.h> |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 17 | #include <cpu/x86/smm.h> |
| 18 | #include <soc/acpi.h> |
| 19 | #include <soc/iomap.h> |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 20 | #include <soc/msr.h> |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 21 | #include <types.h> |
| 22 | #include "chip.h" |
Felix Held | 8602495 | 2021-02-03 23:44:28 +0100 | [diff] [blame] | 23 | |
| 24 | unsigned long acpi_fill_madt(unsigned long current) |
| 25 | { |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 26 | /* create all subtables for processors */ |
Kyösti Mälkki | 66b5e1b | 2022-11-12 21:13:45 +0200 | [diff] [blame] | 27 | current = acpi_create_madt_lapics_with_nmis(current); |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 28 | |
Kyösti Mälkki | 2e65e9c | 2021-06-16 11:00:40 +0300 | [diff] [blame] | 29 | current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR); |
Raul E Rangel | 65819cd | 2021-02-16 10:37:46 -0700 | [diff] [blame] | 30 | |
Kyösti Mälkki | 2e65e9c | 2021-06-16 11:00:40 +0300 | [diff] [blame] | 31 | current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, |
| 32 | GNB_IO_APIC_ADDR); |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 33 | |
Felix Held | 69a957f | 2021-06-17 15:48:25 +0200 | [diff] [blame] | 34 | /* PIT is connected to legacy IRQ 0, but IOAPIC GSI 2 */ |
| 35 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)current, |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 36 | MP_BUS_ISA, 0, 2, |
| 37 | MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT); |
Felix Held | 69a957f | 2021-06-17 15:48:25 +0200 | [diff] [blame] | 38 | /* SCI IRQ type override */ |
| 39 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)current, |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 40 | MP_BUS_ISA, ACPI_SCI_IRQ, ACPI_SCI_IRQ, |
| 41 | MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW); |
Raul E Rangel | 9bce1fe | 2021-02-11 11:28:52 -0700 | [diff] [blame] | 42 | current = acpi_fill_madt_irqoverride(current); |
| 43 | |
Felix Held | 8602495 | 2021-02-03 23:44:28 +0100 | [diff] [blame] | 44 | return current; |
| 45 | } |
| 46 | |
| 47 | /* |
| 48 | * Reference section 5.2.9 Fixed ACPI Description Table (FADT) |
| 49 | * in the ACPI 3.0b specification. |
| 50 | */ |
| 51 | void acpi_fill_fadt(acpi_fadt_t *fadt) |
| 52 | { |
Jason Glenesk | fff318f | 2021-03-10 02:47:05 -0800 | [diff] [blame] | 53 | const struct soc_amd_cezanne_config *cfg = config_of_soc(); |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 54 | |
| 55 | printk(BIOS_DEBUG, "pm_base: 0x%04x\n", ACPI_IO_BASE); |
| 56 | |
| 57 | fadt->sci_int = ACPI_SCI_IRQ; |
| 58 | |
| 59 | if (permanent_smi_handler()) { |
| 60 | fadt->smi_cmd = APM_CNT; |
| 61 | fadt->acpi_enable = APM_CNT_ACPI_ENABLE; |
| 62 | fadt->acpi_disable = APM_CNT_ACPI_DISABLE; |
| 63 | } |
| 64 | |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 65 | fadt->pm1a_evt_blk = ACPI_PM_EVT_BLK; |
| 66 | fadt->pm1a_cnt_blk = ACPI_PM1_CNT_BLK; |
| 67 | fadt->pm_tmr_blk = ACPI_PM_TMR_BLK; |
| 68 | fadt->gpe0_blk = ACPI_GPE0_BLK; |
| 69 | |
| 70 | fadt->pm1_evt_len = 4; /* 32 bits */ |
| 71 | fadt->pm1_cnt_len = 2; /* 16 bits */ |
| 72 | fadt->pm_tmr_len = 4; /* 32 bits */ |
| 73 | fadt->gpe0_blk_len = 8; /* 64 bits */ |
| 74 | |
Felix Held | 164c5ed | 2022-10-18 00:11:48 +0200 | [diff] [blame] | 75 | fill_fadt_extended_pm_regs(fadt); |
| 76 | |
Felix Held | 54c80e1 | 2023-02-21 17:59:42 +0100 | [diff] [blame] | 77 | /* p_lvl2_lat and p_lvl3_lat match what the AGESA code does, but those values are |
| 78 | overridden by the _CST packages in the processor devices. */ |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 79 | fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED; |
| 80 | fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED; |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 81 | fadt->day_alrm = RTC_DATE_ALARM; |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 82 | fadt->century = RTC_ALT_CENTURY; |
Jason Glenesk | fff318f | 2021-03-10 02:47:05 -0800 | [diff] [blame] | 83 | fadt->iapc_boot_arch = cfg->common_config.fadt_boot_arch; /* legacy free default */ |
Raul E Rangel | 12c6a58 | 2021-02-10 16:45:49 -0700 | [diff] [blame] | 84 | fadt->flags |= ACPI_FADT_WBINVD | /* See table 5-34 ACPI 6.3 spec */ |
| 85 | ACPI_FADT_C1_SUPPORTED | |
| 86 | ACPI_FADT_S4_RTC_WAKE | |
| 87 | ACPI_FADT_32BIT_TIMER | |
| 88 | ACPI_FADT_PCI_EXPRESS_WAKE | |
| 89 | ACPI_FADT_PLATFORM_CLOCK | |
| 90 | ACPI_FADT_S4_RTC_VALID | |
| 91 | ACPI_FADT_REMOTE_POWER_ON; |
Jason Glenesk | fff318f | 2021-03-10 02:47:05 -0800 | [diff] [blame] | 92 | if (cfg->s0ix_enable) |
| 93 | fadt->flags |= ACPI_FADT_LOW_PWR_IDLE_S0; |
| 94 | |
| 95 | fadt->flags |= cfg->common_config.fadt_flags; /* additional board-specific flags */ |
Felix Held | 8602495 | 2021-02-03 23:44:28 +0100 | [diff] [blame] | 96 | } |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 97 | |
Felix Held | e4fc7b0 | 2023-03-07 02:32:11 +0100 | [diff] [blame] | 98 | uint32_t get_pstate_core_freq(msr_t pstate_def) |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 99 | { |
| 100 | uint32_t core_freq, core_freq_mul, core_freq_div; |
| 101 | bool valid_freq_divisor; |
Felix Held | da02a82 | 2023-03-10 00:00:47 +0100 | [diff] [blame^] | 102 | union pstate_msr pstate_reg; |
| 103 | |
| 104 | pstate_reg.raw = pstate_def.raw; |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 105 | |
| 106 | /* Core frequency multiplier */ |
Felix Held | da02a82 | 2023-03-10 00:00:47 +0100 | [diff] [blame^] | 107 | core_freq_mul = pstate_reg.cpu_fid_0_7; |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 108 | |
| 109 | /* Core frequency divisor ID */ |
Felix Held | da02a82 | 2023-03-10 00:00:47 +0100 | [diff] [blame^] | 110 | core_freq_div = pstate_reg.cpu_dfs_id; |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 111 | |
| 112 | if (core_freq_div == 0) { |
| 113 | return 0; |
| 114 | } else if ((core_freq_div >= PSTATE_DEF_LO_FREQ_DIV_MIN) |
| 115 | && (core_freq_div <= PSTATE_DEF_LO_EIGHTH_STEP_MAX)) { |
| 116 | /* Allow 1/8 integer steps for this range */ |
| 117 | valid_freq_divisor = 1; |
| 118 | } else if ((core_freq_div > PSTATE_DEF_LO_EIGHTH_STEP_MAX) |
| 119 | && (core_freq_div <= PSTATE_DEF_LO_FREQ_DIV_MAX) && !(core_freq_div & 0x1)) { |
| 120 | /* Only allow 1/4 integer steps for this range */ |
| 121 | valid_freq_divisor = 1; |
| 122 | } else { |
| 123 | valid_freq_divisor = 0; |
| 124 | } |
| 125 | |
| 126 | if (valid_freq_divisor) { |
| 127 | /* 25 * core_freq_mul / (core_freq_div / 8) */ |
| 128 | core_freq = |
| 129 | ((PSTATE_DEF_LO_CORE_FREQ_BASE * core_freq_mul * 8) / (core_freq_div)); |
| 130 | } else { |
| 131 | printk(BIOS_WARNING, "Undefined core_freq_div %x used. Force to 1.\n", |
| 132 | core_freq_div); |
| 133 | core_freq = (PSTATE_DEF_LO_CORE_FREQ_BASE * core_freq_mul); |
| 134 | } |
| 135 | return core_freq; |
| 136 | } |
| 137 | |
Felix Held | e4fc7b0 | 2023-03-07 02:32:11 +0100 | [diff] [blame] | 138 | uint32_t get_pstate_core_power(msr_t pstate_def) |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 139 | { |
| 140 | uint32_t voltage_in_uvolts, core_vid, current_value_amps, current_divisor, power_in_mw; |
Felix Held | da02a82 | 2023-03-10 00:00:47 +0100 | [diff] [blame^] | 141 | union pstate_msr pstate_reg; |
| 142 | |
| 143 | pstate_reg.raw = pstate_def.raw; |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 144 | |
| 145 | /* Core voltage ID */ |
Felix Held | da02a82 | 2023-03-10 00:00:47 +0100 | [diff] [blame^] | 146 | core_vid = pstate_reg.cpu_vid_0_7; |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 147 | |
| 148 | /* Current value in amps */ |
Felix Held | da02a82 | 2023-03-10 00:00:47 +0100 | [diff] [blame^] | 149 | current_value_amps = pstate_reg.idd_value; |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 150 | |
| 151 | /* Current divisor */ |
Felix Held | da02a82 | 2023-03-10 00:00:47 +0100 | [diff] [blame^] | 152 | current_divisor = pstate_reg.idd_div; |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 153 | |
| 154 | /* Voltage */ |
| 155 | if ((core_vid >= 0xF8) && (core_vid <= 0xFF)) { |
| 156 | /* Voltage off for VID codes 0xF8 to 0xFF */ |
| 157 | voltage_in_uvolts = 0; |
| 158 | } else { |
| 159 | voltage_in_uvolts = |
| 160 | SERIAL_VID_MAX_MICROVOLTS - (SERIAL_VID_DECODE_MICROVOLTS * core_vid); |
| 161 | } |
| 162 | |
| 163 | /* Power in mW */ |
Zheng Bao | 62cd5e8 | 2022-08-25 17:11:38 +0800 | [diff] [blame] | 164 | power_in_mw = (voltage_in_uvolts) / 10 * current_value_amps; |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 165 | |
| 166 | switch (current_divisor) { |
| 167 | case 0: |
Zheng Bao | 62cd5e8 | 2022-08-25 17:11:38 +0800 | [diff] [blame] | 168 | power_in_mw = power_in_mw / 100L; |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 169 | break; |
| 170 | case 1: |
Zheng Bao | 62cd5e8 | 2022-08-25 17:11:38 +0800 | [diff] [blame] | 171 | power_in_mw = power_in_mw / 1000L; |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 172 | break; |
| 173 | case 2: |
Zheng Bao | 62cd5e8 | 2022-08-25 17:11:38 +0800 | [diff] [blame] | 174 | power_in_mw = power_in_mw / 10000L; |
Jason Glenesk | 79542fa | 2021-03-10 03:50:57 -0800 | [diff] [blame] | 175 | break; |
| 176 | case 3: |
| 177 | /* current_divisor is set to an undefined value.*/ |
| 178 | printk(BIOS_WARNING, "Undefined current_divisor set for enabled P-state .\n"); |
| 179 | power_in_mw = 0; |
| 180 | break; |
| 181 | } |
| 182 | |
| 183 | return power_in_mw; |
| 184 | } |
| 185 | |
Felix Held | ceafcae | 2023-03-07 00:00:15 +0100 | [diff] [blame] | 186 | const acpi_cstate_t cstate_cfg_table[] = { |
| 187 | [0] = { |
| 188 | .ctype = 1, |
| 189 | .latency = 1, |
| 190 | .power = 0, |
| 191 | }, |
| 192 | [1] = { |
| 193 | .ctype = 2, |
| 194 | .latency = 0x12, |
| 195 | .power = 0, |
| 196 | }, |
| 197 | [2] = { |
| 198 | .ctype = 3, |
| 199 | .latency = 350, |
| 200 | .power = 0, |
| 201 | }, |
| 202 | }; |
| 203 | |
| 204 | const acpi_cstate_t *get_cstate_config_data(size_t *size) |
| 205 | { |
| 206 | *size = ARRAY_SIZE(cstate_cfg_table); |
| 207 | return cstate_cfg_table; |
| 208 | } |