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