Angel Pons | 80d9238 | 2020-04-05 15:47:00 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Kyösti Mälkki | 0c1dd9c | 2020-06-17 23:37:49 +0300 | [diff] [blame] | 4 | #include <acpi/acpi_gnvs.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 5 | #include <acpi/acpigen.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 6 | #include <arch/smp/mpspec.h> |
| 7 | #include <cpu/x86/smm.h> |
| 8 | #include <string.h> |
| 9 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 10 | #include <device/pci_ops.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 11 | #include <cbmem.h> |
Elyes HAOUAS | 20eaef0 | 2019-03-29 17:45:28 +0100 | [diff] [blame] | 12 | #include <console/console.h> |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 13 | #include <intelblocks/acpi.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 14 | #include <soc/acpi.h> |
| 15 | #include <soc/cpu.h> |
Kyösti Mälkki | d6c5714 | 2020-12-21 15:17:01 +0200 | [diff] [blame] | 16 | #include <soc/nvs.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 17 | #include <soc/soc_util.h> |
| 18 | #include <soc/pmc.h> |
| 19 | #include <soc/systemagent.h> |
Julien Viard de Galbert | a0e5046 | 2018-04-05 11:59:07 +0200 | [diff] [blame] | 20 | #include <soc/pci_devs.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 21 | |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 22 | #define MWAIT_RES(state, sub_state) \ |
| 23 | { \ |
| 24 | .addrl = (((state) << 4) | (sub_state)), \ |
| 25 | .space_id = ACPI_ADDRESS_SPACE_FIXED, \ |
| 26 | .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL, \ |
| 27 | .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT, \ |
| 28 | .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD, \ |
| 29 | } |
| 30 | |
| 31 | #define CSTATE_RES(address_space, width, offset, address) \ |
| 32 | { \ |
| 33 | .space_id = address_space, \ |
| 34 | .bit_width = width, \ |
| 35 | .bit_offset = offset, \ |
| 36 | .addrl = address, \ |
| 37 | } |
| 38 | |
| 39 | static acpi_cstate_t cstate_map[] = { |
| 40 | { |
| 41 | /* C1 */ |
| 42 | .ctype = 1, /* ACPI C1 */ |
| 43 | .latency = 2, |
| 44 | .power = 1000, |
| 45 | .resource = MWAIT_RES(0, 0), |
| 46 | }, |
| 47 | { |
| 48 | .ctype = 2, /* ACPI C2 */ |
| 49 | .latency = 10, |
| 50 | .power = 10, |
| 51 | .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, |
| 52 | ACPI_BASE_ADDRESS + 0x14), |
| 53 | }, |
| 54 | { |
| 55 | .ctype = 3, /* ACPI C3 */ |
| 56 | .latency = 50, |
| 57 | .power = 10, |
| 58 | .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, |
| 59 | ACPI_BASE_ADDRESS + 0x15), |
| 60 | } |
| 61 | }; |
| 62 | |
Kyösti Mälkki | 999e441 | 2020-06-28 21:56:46 +0300 | [diff] [blame^] | 63 | void soc_fill_gnvs(struct global_nvs *gnvs) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 64 | { |
| 65 | /* CPU core count */ |
| 66 | gnvs->pcnt = dev_count_cpu(); |
| 67 | |
| 68 | /* Top of Low Memory (start of resource allocation) */ |
Michael Niewöhner | 46e68ac | 2019-11-04 22:07:29 +0100 | [diff] [blame] | 69 | gnvs->tolm = (uintptr_t)cbmem_top(); |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 70 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 71 | /* MMIO Low/High & TSEG base and length */ |
| 72 | gnvs->mmiob = (u32)get_top_of_low_memory(); |
| 73 | gnvs->mmiol = (u32)(get_pciebase() - 1); |
| 74 | gnvs->mmiohb = (u64)get_top_of_upper_memory(); |
| 75 | gnvs->mmiohl = (u64)(((u64)1 << CONFIG_CPU_ADDR_BITS) - 1); |
| 76 | gnvs->tsegb = (u32)get_tseg_memory(); |
| 77 | gnvs->tsegl = (u32)(get_top_of_low_memory() - get_tseg_memory()); |
| 78 | } |
| 79 | |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 80 | uint32_t soc_read_sci_irq_select(void) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 81 | { |
Elyes HAOUAS | 2ec4183 | 2018-05-27 17:40:58 +0200 | [diff] [blame] | 82 | struct device *dev = get_pmc_dev(); |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 83 | |
| 84 | if (!dev) |
| 85 | return 0; |
| 86 | |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 87 | return pci_read_config32(dev, PMC_ACPI_CNT); |
| 88 | } |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 89 | |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 90 | acpi_cstate_t *soc_get_cstate_map(size_t *entries) |
| 91 | { |
| 92 | *entries = ARRAY_SIZE(cstate_map); |
| 93 | return cstate_map; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 97 | { |
| 98 | u32 pciexbar_reg; |
| 99 | int max_buses; |
| 100 | |
| 101 | pciexbar_reg = get_pciebase(); |
| 102 | max_buses = get_pcielength(); |
| 103 | |
| 104 | if (!pciexbar_reg) |
| 105 | return current; |
| 106 | |
| 107 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current, |
| 108 | pciexbar_reg, 0x0, 0x0, |
| 109 | (u8)(max_buses - 1)); |
| 110 | |
| 111 | return current; |
| 112 | } |
| 113 | |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 114 | void soc_fill_fadt(acpi_fadt_t *fadt) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 115 | { |
| 116 | u16 pmbase = get_pmbase(); |
| 117 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 118 | /* Power Control */ |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 119 | fadt->pm2_cnt_blk = pmbase + PM2_CNT; |
| 120 | fadt->pm_tmr_blk = pmbase + PM1_TMR; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 121 | |
| 122 | /* Control Registers - Length */ |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 123 | fadt->pm2_cnt_len = 1; |
| 124 | fadt->pm_tmr_len = 4; |
| 125 | fadt->gpe0_blk_len = 8; |
Kyösti Mälkki | c328a68 | 2019-11-23 07:23:40 +0200 | [diff] [blame] | 126 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 127 | fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED; |
| 128 | fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 129 | fadt->duty_offset = 1; |
| 130 | fadt->duty_width = 0; |
| 131 | |
| 132 | /* RTC Registers */ |
| 133 | fadt->day_alrm = 0x0D; |
| 134 | fadt->mon_alrm = 0x00; |
| 135 | fadt->century = 0x00; |
| 136 | fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042; |
| 137 | |
Angel Pons | a208c6c | 2020-07-13 00:02:34 +0200 | [diff] [blame] | 138 | fadt->flags |= ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED | |
| 139 | ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON | |
Angel Pons | 79572e4 | 2020-07-13 00:17:43 +0200 | [diff] [blame] | 140 | ACPI_FADT_SLEEP_TYPE | ACPI_FADT_S4_RTC_WAKE | |
| 141 | ACPI_FADT_PLATFORM_CLOCK; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 142 | |
| 143 | /* PM1 Status & PM1 Enable */ |
| 144 | fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 145 | fadt->x_pm1a_evt_blk.bit_width = 32; |
| 146 | fadt->x_pm1a_evt_blk.bit_offset = 0; |
Angel Pons | 12a4d05 | 2020-07-14 01:31:27 +0200 | [diff] [blame] | 147 | fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 148 | fadt->x_pm1a_evt_blk.addrl = fadt->pm1a_evt_blk; |
| 149 | fadt->x_pm1a_evt_blk.addrh = 0x00; |
| 150 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 151 | /* PM1 Control Registers */ |
| 152 | fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 153 | fadt->x_pm1a_cnt_blk.bit_width = 16; |
| 154 | fadt->x_pm1a_cnt_blk.bit_offset = 0; |
| 155 | fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS; |
| 156 | fadt->x_pm1a_cnt_blk.addrl = fadt->pm1a_cnt_blk; |
| 157 | fadt->x_pm1a_cnt_blk.addrh = 0x00; |
| 158 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 159 | /* PM2 Control Registers */ |
| 160 | fadt->x_pm2_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 161 | fadt->x_pm2_cnt_blk.bit_width = 8; |
| 162 | fadt->x_pm2_cnt_blk.bit_offset = 0; |
| 163 | fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
| 164 | fadt->x_pm2_cnt_blk.addrl = fadt->pm2_cnt_blk; |
| 165 | fadt->x_pm2_cnt_blk.addrh = 0x00; |
| 166 | |
| 167 | /* PM1 Timer Register */ |
| 168 | fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 169 | fadt->x_pm_tmr_blk.bit_width = 32; |
| 170 | fadt->x_pm_tmr_blk.bit_offset = 0; |
| 171 | fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 172 | fadt->x_pm_tmr_blk.addrl = fadt->pm_tmr_blk; |
| 173 | fadt->x_pm_tmr_blk.addrh = 0x00; |
| 174 | |
| 175 | /* General-Purpose Event Registers */ |
| 176 | fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 177 | fadt->x_gpe0_blk.bit_width = 64; /* EventStatus + EventEnable */ |
| 178 | fadt->x_gpe0_blk.bit_offset = 0; |
Angel Pons | a23aff3 | 2020-06-21 20:47:54 +0200 | [diff] [blame] | 179 | fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 180 | fadt->x_gpe0_blk.addrl = fadt->gpe0_blk; |
| 181 | fadt->x_gpe0_blk.addrh = 0x00; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 182 | } |
| 183 | |
Julien Viard de Galbert | 595202c | 2018-03-29 14:01:01 +0200 | [diff] [blame] | 184 | static acpi_tstate_t denverton_tss_table[] = { |
| 185 | { 100, 1000, 0, 0x00, 0 }, |
| 186 | { 88, 875, 0, 0x1e, 0 }, |
| 187 | { 75, 750, 0, 0x1c, 0 }, |
| 188 | { 63, 625, 0, 0x1a, 0 }, |
| 189 | { 50, 500, 0, 0x18, 0 }, |
| 190 | { 38, 375, 0, 0x16, 0 }, |
| 191 | { 25, 250, 0, 0x14, 0 }, |
| 192 | { 13, 125, 0, 0x12, 0 }, |
| 193 | }; |
| 194 | |
| 195 | acpi_tstate_t *soc_get_tss_table(int *entries) |
| 196 | { |
| 197 | *entries = ARRAY_SIZE(denverton_tss_table); |
| 198 | return denverton_tss_table; |
| 199 | } |
| 200 | |
| 201 | void soc_power_states_generation(int core_id, int cores_per_package) |
| 202 | { |
| 203 | generate_p_state_entries(core_id, cores_per_package); |
| 204 | |
| 205 | generate_t_state_entries(core_id, cores_per_package); |
| 206 | } |
| 207 | |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 208 | int soc_madt_sci_irq_polarity(int sci) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 209 | { |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 210 | if (sci >= 20) |
| 211 | return MP_IRQ_POLARITY_LOW; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 212 | else |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 213 | return MP_IRQ_POLARITY_HIGH; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 214 | } |
| 215 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 216 | unsigned long southcluster_write_acpi_tables(const struct device *device, |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 217 | unsigned long current, |
| 218 | struct acpi_rsdp *rsdp) |
| 219 | { |
| 220 | acpi_header_t *ssdt2; |
| 221 | |
| 222 | current = acpi_write_hpet(device, current, rsdp); |
| 223 | current = (ALIGN(current, 16)); |
| 224 | |
| 225 | ssdt2 = (acpi_header_t *)current; |
| 226 | memset(ssdt2, 0, sizeof(acpi_header_t)); |
| 227 | acpi_create_serialio_ssdt(ssdt2); |
| 228 | if (ssdt2->length) { |
| 229 | current += ssdt2->length; |
| 230 | acpi_add_table(rsdp, ssdt2); |
| 231 | printk(BIOS_DEBUG, "ACPI: * SSDT2 @ %p Length %x\n", ssdt2, |
| 232 | ssdt2->length); |
| 233 | current = (ALIGN(current, 16)); |
| 234 | } else { |
| 235 | ssdt2 = NULL; |
| 236 | printk(BIOS_DEBUG, "ACPI: * SSDT2 not generated.\n"); |
| 237 | } |
| 238 | |
| 239 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 240 | |
| 241 | return current; |
| 242 | } |
| 243 | |
Furquan Shaikh | 338fd9a | 2020-04-24 22:57:05 -0700 | [diff] [blame] | 244 | void southcluster_inject_dsdt(const struct device *device) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 245 | { |
Kyösti Mälkki | 9f441df | 2020-06-28 12:29:13 +0300 | [diff] [blame] | 246 | struct global_nvs *gnvs = acpi_get_gnvs(); |
| 247 | if (!gnvs) |
| 248 | return; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 249 | |
Kyösti Mälkki | 999e441 | 2020-06-28 21:56:46 +0300 | [diff] [blame^] | 250 | soc_fill_gnvs(gnvs); |
Kyösti Mälkki | a9766c7 | 2020-06-29 02:56:49 +0300 | [diff] [blame] | 251 | mainboard_fill_gnvs(gnvs); |
Kyösti Mälkki | 9f441df | 2020-06-28 12:29:13 +0300 | [diff] [blame] | 252 | acpi_inject_nvsa(); |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 253 | } |
| 254 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 255 | __weak void acpi_create_serialio_ssdt(acpi_header_t *ssdt) {} |
Julien Viard de Galbert | a0e5046 | 2018-04-05 11:59:07 +0200 | [diff] [blame] | 256 | |
| 257 | static unsigned long acpi_fill_dmar(unsigned long current) |
| 258 | { |
| 259 | uint64_t vtbar; |
| 260 | unsigned long tmp = current; |
| 261 | |
| 262 | vtbar = read64((void *)(DEFAULT_MCHBAR + MCH_VTBAR_OFFSET)) & MCH_VTBAR_MASK; |
| 263 | printk(BIOS_DEBUG, "DEFVTBAR:0x%llx\n", vtbar); |
| 264 | if (!vtbar) |
| 265 | return current; |
| 266 | |
| 267 | current += acpi_create_dmar_drhd(current, |
| 268 | DRHD_INCLUDE_PCI_ALL, 0, vtbar); |
| 269 | |
| 270 | current += acpi_create_dmar_ds_ioapic(current, |
| 271 | 2, PCH_IOAPIC_PCI_BUS, PCH_IOAPIC_PCI_SLOT, 0); |
| 272 | current += acpi_create_dmar_ds_msi_hpet(current, |
| 273 | 0, PCH_HPET_PCI_BUS, PCH_HPET_PCI_SLOT, 0); |
| 274 | |
| 275 | acpi_dmar_drhd_fixup(tmp, current); |
| 276 | |
| 277 | /* Create RMRR; see "VTD PLATFORM CONFIGURATION" in FSP log */ |
| 278 | tmp = current; |
| 279 | current += acpi_create_dmar_rmrr(current, 0, |
| 280 | RMRR_USB_BASE_ADDRESS, |
| 281 | RMRR_USB_LIMIT_ADDRESS); |
| 282 | current += acpi_create_dmar_ds_pci(current, |
| 283 | 0, XHCI_DEV, XHCI_FUNC); |
| 284 | acpi_dmar_rmrr_fixup(tmp, current); |
| 285 | |
| 286 | return current; |
| 287 | } |
| 288 | |
| 289 | unsigned long systemagent_write_acpi_tables(const struct device *dev, |
| 290 | unsigned long current, |
| 291 | struct acpi_rsdp *const rsdp) |
| 292 | { |
| 293 | /* Create DMAR table only if we have VT-d capability. */ |
| 294 | const u32 capid0_a = pci_read_config32(dev, CAPID0_A); |
| 295 | if (capid0_a & VTD_DISABLE) |
| 296 | return current; |
| 297 | |
| 298 | acpi_dmar_t *const dmar = (acpi_dmar_t *)current; |
| 299 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
| 300 | acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar); |
| 301 | current += dmar->header.length; |
| 302 | current = acpi_align_current(current); |
| 303 | acpi_add_table(rsdp, dmar); |
| 304 | |
| 305 | return current; |
| 306 | } |