Angel Pons | ae59387 | 2020-04-04 18:50:57 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * ACPI - create the Fixed ACPI Description Tables (FADT) |
| 5 | */ |
| 6 | |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 7 | #include <console/console.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 8 | #include <acpi/acpi.h> |
| 9 | #include <acpi/acpigen.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 10 | #include <device/pci_ops.h> |
| 11 | #include <arch/ioapic.h> |
Raul E Rangel | 93b62e6 | 2020-01-31 12:53:45 -0700 | [diff] [blame] | 12 | #include <arch/smp/mpspec.h> |
Jason Glenesk | 498015d | 2020-12-10 03:28:38 -0800 | [diff] [blame] | 13 | #include <cpu/amd/cpuid.h> |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 14 | #include <cpu/amd/msr.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 15 | #include <cpu/x86/smm.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 16 | #include <device/device.h> |
| 17 | #include <device/pci.h> |
Elyes Haouas | 5e2602a | 2023-01-14 05:46:25 +0100 | [diff] [blame] | 18 | #include <gpio.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 19 | #include <amdblocks/acpimmio.h> |
| 20 | #include <amdblocks/acpi.h> |
Raul E Rangel | 1c88b10 | 2021-02-11 10:35:32 -0700 | [diff] [blame] | 21 | #include <amdblocks/chip.h> |
Felix Held | dd2f3fa | 2021-02-08 22:23:54 +0100 | [diff] [blame] | 22 | #include <amdblocks/cpu.h> |
Felix Held | 604ffa6 | 2021-02-12 00:43:20 +0100 | [diff] [blame] | 23 | #include <amdblocks/ioapic.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 24 | #include <soc/acpi.h> |
| 25 | #include <soc/pci_devs.h> |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 26 | #include <soc/msr.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 27 | #include <soc/southbridge.h> |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 28 | #include <version.h> |
Raul E Rangel | 93b62e6 | 2020-01-31 12:53:45 -0700 | [diff] [blame] | 29 | #include "chip.h" |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 30 | |
| 31 | unsigned long acpi_fill_madt(unsigned long current) |
| 32 | { |
| 33 | /* create all subtables for processors */ |
Kyösti Mälkki | 66b5e1b | 2022-11-12 21:13:45 +0200 | [diff] [blame] | 34 | current = acpi_create_madt_lapics_with_nmis(current); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 35 | |
Kyösti Mälkki | 2e65e9c | 2021-06-16 11:00:40 +0300 | [diff] [blame] | 36 | current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 37 | |
Kyösti Mälkki | 2e65e9c | 2021-06-16 11:00:40 +0300 | [diff] [blame] | 38 | current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, |
| 39 | GNB_IO_APIC_ADDR); |
Jason Glenesk | f459a40 | 2020-09-02 16:49:10 -0700 | [diff] [blame] | 40 | |
Felix Held | 69a957f | 2021-06-17 15:48:25 +0200 | [diff] [blame] | 41 | /* PIT is connected to legacy IRQ 0, but IOAPIC GSI 2 */ |
| 42 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)current, |
| 43 | MP_BUS_ISA, 0, 2, |
| 44 | MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT); |
| 45 | /* SCI IRQ type override */ |
| 46 | current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)current, |
Felix Held | c0ae0ba | 2023-02-27 21:02:48 +0100 | [diff] [blame] | 47 | MP_BUS_ISA, ACPI_SCI_IRQ, ACPI_SCI_IRQ, |
Felix Held | 69a957f | 2021-06-17 15:48:25 +0200 | [diff] [blame] | 48 | MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW); |
Raul E Rangel | 93b62e6 | 2020-01-31 12:53:45 -0700 | [diff] [blame] | 49 | |
Raul E Rangel | ffab5e6 | 2021-02-11 11:07:11 -0700 | [diff] [blame] | 50 | current = acpi_fill_madt_irqoverride(current); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 51 | |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 52 | return current; |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * Reference section 5.2.9 Fixed ACPI Description Table (FADT) |
| 57 | * in the ACPI 3.0b specification. |
| 58 | */ |
Kyösti Mälkki | 61ef71b | 2020-05-30 18:54:39 +0300 | [diff] [blame] | 59 | void acpi_fill_fadt(acpi_fadt_t *fadt) |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 60 | { |
Raul E Rangel | 1c88b10 | 2021-02-11 10:35:32 -0700 | [diff] [blame] | 61 | const struct soc_amd_common_config *cfg = soc_get_common_config(); |
Martin Roth | eca8faa | 2019-12-01 16:49:19 -0700 | [diff] [blame] | 62 | |
Felix Held | 757d645 | 2021-02-04 21:31:49 +0100 | [diff] [blame] | 63 | printk(BIOS_DEBUG, "pm_base: 0x%04x\n", ACPI_IO_BASE); |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 64 | |
Felix Held | c0ae0ba | 2023-02-27 21:02:48 +0100 | [diff] [blame] | 65 | fadt->sci_int = ACPI_SCI_IRQ; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 66 | |
Kyösti Mälkki | 0a9e72e | 2019-08-11 01:22:28 +0300 | [diff] [blame] | 67 | if (permanent_smi_handler()) { |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 68 | fadt->smi_cmd = APM_CNT; |
| 69 | fadt->acpi_enable = APM_CNT_ACPI_ENABLE; |
| 70 | fadt->acpi_disable = APM_CNT_ACPI_DISABLE; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | fadt->pm1a_evt_blk = ACPI_PM_EVT_BLK; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 74 | fadt->pm1a_cnt_blk = ACPI_PM1_CNT_BLK; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 75 | fadt->pm_tmr_blk = ACPI_PM_TMR_BLK; |
| 76 | fadt->gpe0_blk = ACPI_GPE0_BLK; |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 77 | |
| 78 | fadt->pm1_evt_len = 4; /* 32 bits */ |
| 79 | fadt->pm1_cnt_len = 2; /* 16 bits */ |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 80 | fadt->pm_tmr_len = 4; /* 32 bits */ |
| 81 | fadt->gpe0_blk_len = 8; /* 64 bits */ |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 82 | |
Felix Held | 164c5ed | 2022-10-18 00:11:48 +0200 | [diff] [blame] | 83 | fill_fadt_extended_pm_regs(fadt); |
| 84 | |
Felix Held | 54c80e1 | 2023-02-21 17:59:42 +0100 | [diff] [blame] | 85 | /* p_lvl2_lat and p_lvl3_lat match what the AGESA code does, but those values are |
| 86 | overridden by the _CST packages in the processor devices. */ |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 87 | fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED; |
| 88 | fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED; |
Felix Held | 72b92c9 | 2021-11-18 20:41:40 +0100 | [diff] [blame] | 89 | fadt->day_alrm = RTC_DATE_ALARM; |
Martin Roth | eca8faa | 2019-12-01 16:49:19 -0700 | [diff] [blame] | 90 | fadt->iapc_boot_arch = cfg->fadt_boot_arch; /* legacy free default */ |
Martin Roth | eca8faa | 2019-12-01 16:49:19 -0700 | [diff] [blame] | 91 | fadt->flags |= ACPI_FADT_WBINVD | /* See table 5-34 ACPI 6.3 spec */ |
| 92 | ACPI_FADT_C1_SUPPORTED | |
| 93 | ACPI_FADT_S4_RTC_WAKE | |
| 94 | ACPI_FADT_32BIT_TIMER | |
| 95 | ACPI_FADT_PCI_EXPRESS_WAKE | |
| 96 | ACPI_FADT_PLATFORM_CLOCK | |
| 97 | ACPI_FADT_S4_RTC_VALID | |
| 98 | ACPI_FADT_REMOTE_POWER_ON; |
| 99 | fadt->flags |= cfg->fadt_flags; /* additional board-specific flags */ |
Martin Roth | 5c354b9 | 2019-04-22 14:55:16 -0600 | [diff] [blame] | 100 | } |
| 101 | |
Felix Held | 5630506 | 2023-03-22 23:46:34 +0100 | [diff] [blame] | 102 | uint32_t get_pstate_core_freq(union pstate_msr pstate_reg) |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 103 | { |
| 104 | uint32_t core_freq, core_freq_mul, core_freq_div; |
| 105 | bool valid_freq_divisor; |
| 106 | |
| 107 | /* Core frequency multiplier */ |
Felix Held | 659e154 | 2023-03-10 00:00:19 +0100 | [diff] [blame] | 108 | core_freq_mul = pstate_reg.cpu_fid_0_7; |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 109 | |
| 110 | /* Core frequency divisor ID */ |
Felix Held | 659e154 | 2023-03-10 00:00:19 +0100 | [diff] [blame] | 111 | core_freq_div = pstate_reg.cpu_dfs_id; |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 112 | |
| 113 | if (core_freq_div == 0) { |
| 114 | return 0; |
Felix Held | 6ba67ab | 2023-03-23 01:28:28 +0100 | [diff] [blame] | 115 | } else if ((core_freq_div >= PSTATE_DEF_FREQ_DIV_MIN) |
| 116 | && (core_freq_div <= PSTATE_DEF_EIGHTH_STEP_MAX)) { |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 117 | /* Allow 1/8 integer steps for this range */ |
Felix Held | 8194364 | 2023-03-21 16:21:43 +0100 | [diff] [blame] | 118 | valid_freq_divisor = true; |
Felix Held | 6ba67ab | 2023-03-23 01:28:28 +0100 | [diff] [blame] | 119 | } else if ((core_freq_div > PSTATE_DEF_EIGHTH_STEP_MAX) |
| 120 | && (core_freq_div <= PSTATE_DEF_FREQ_DIV_MAX) && !(core_freq_div & 0x1)) { |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 121 | /* Only allow 1/4 integer steps for this range */ |
Felix Held | 8194364 | 2023-03-21 16:21:43 +0100 | [diff] [blame] | 122 | valid_freq_divisor = true; |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 123 | } else { |
Felix Held | 8194364 | 2023-03-21 16:21:43 +0100 | [diff] [blame] | 124 | valid_freq_divisor = false; |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | if (valid_freq_divisor) { |
| 128 | /* 25 * core_freq_mul / (core_freq_div / 8) */ |
| 129 | core_freq = |
Felix Held | 6ba67ab | 2023-03-23 01:28:28 +0100 | [diff] [blame] | 130 | ((PSTATE_DEF_CORE_FREQ_BASE * core_freq_mul * 8) / (core_freq_div)); |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 131 | } else { |
| 132 | printk(BIOS_WARNING, "Undefined core_freq_div %x used. Force to 1.\n", |
| 133 | core_freq_div); |
Felix Held | 6ba67ab | 2023-03-23 01:28:28 +0100 | [diff] [blame] | 134 | core_freq = (PSTATE_DEF_CORE_FREQ_BASE * core_freq_mul); |
Jason Glenesk | bc52143 | 2020-09-14 05:22:47 -0700 | [diff] [blame] | 135 | } |
| 136 | return core_freq; |
| 137 | } |
| 138 | |
Felix Held | 9bb6646 | 2023-03-04 02:33:28 +0100 | [diff] [blame] | 139 | const acpi_cstate_t cstate_cfg_table[] = { |
| 140 | [0] = { |
| 141 | .ctype = 1, |
| 142 | .latency = 1, |
| 143 | .power = 0, |
| 144 | }, |
| 145 | [1] = { |
| 146 | .ctype = 2, |
| 147 | .latency = 400, |
| 148 | .power = 0, |
| 149 | }, |
| 150 | }; |
| 151 | |
| 152 | const acpi_cstate_t *get_cstate_config_data(size_t *size) |
| 153 | { |
| 154 | *size = ARRAY_SIZE(cstate_cfg_table); |
| 155 | return cstate_cfg_table; |
| 156 | } |