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> |
Arthur Heymans | d90154c | 2022-12-02 13:27:35 +0100 | [diff] [blame] | 6 | #include <arch/ioapic.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 7 | #include <arch/smp/mpspec.h> |
Arthur Heymans | ba15a59 | 2021-10-28 10:14:31 +0200 | [diff] [blame] | 8 | #include <cpu/cpu.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 9 | #include <cpu/x86/smm.h> |
| 10 | #include <string.h> |
| 11 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 12 | #include <device/pci_ops.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 13 | #include <cbmem.h> |
Elyes HAOUAS | 20eaef0 | 2019-03-29 17:45:28 +0100 | [diff] [blame] | 14 | #include <console/console.h> |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 15 | #include <intelblocks/acpi.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 16 | #include <soc/acpi.h> |
| 17 | #include <soc/cpu.h> |
Kyösti Mälkki | d6c5714 | 2020-12-21 15:17:01 +0200 | [diff] [blame] | 18 | #include <soc/nvs.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 19 | #include <soc/soc_util.h> |
| 20 | #include <soc/pmc.h> |
| 21 | #include <soc/systemagent.h> |
Julien Viard de Galbert | a0e5046 | 2018-04-05 11:59:07 +0200 | [diff] [blame] | 22 | #include <soc/pci_devs.h> |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 23 | |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 24 | #define CSTATE_RES(address_space, width, offset, address) \ |
| 25 | { \ |
| 26 | .space_id = address_space, \ |
| 27 | .bit_width = width, \ |
| 28 | .bit_offset = offset, \ |
| 29 | .addrl = address, \ |
| 30 | } |
| 31 | |
Angel Pons | e9f10ff | 2021-10-17 13:28:23 +0200 | [diff] [blame] | 32 | static const acpi_cstate_t cstate_map[] = { |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 33 | { |
| 34 | /* C1 */ |
| 35 | .ctype = 1, /* ACPI C1 */ |
| 36 | .latency = 2, |
| 37 | .power = 1000, |
| 38 | .resource = MWAIT_RES(0, 0), |
| 39 | }, |
| 40 | { |
| 41 | .ctype = 2, /* ACPI C2 */ |
| 42 | .latency = 10, |
| 43 | .power = 10, |
| 44 | .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, |
| 45 | ACPI_BASE_ADDRESS + 0x14), |
| 46 | }, |
| 47 | { |
| 48 | .ctype = 3, /* ACPI C3 */ |
| 49 | .latency = 50, |
| 50 | .power = 10, |
| 51 | .resource = CSTATE_RES(ACPI_ADDRESS_SPACE_IO, 8, 0, |
| 52 | ACPI_BASE_ADDRESS + 0x15), |
| 53 | } |
| 54 | }; |
| 55 | |
Kyösti Mälkki | 999e441 | 2020-06-28 21:56:46 +0300 | [diff] [blame] | 56 | void soc_fill_gnvs(struct global_nvs *gnvs) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 57 | { |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 58 | /* Top of Low Memory (start of resource allocation) */ |
Michael Niewöhner | 46e68ac | 2019-11-04 22:07:29 +0100 | [diff] [blame] | 59 | gnvs->tolm = (uintptr_t)cbmem_top(); |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 60 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 61 | /* MMIO Low/High & TSEG base and length */ |
| 62 | gnvs->mmiob = (u32)get_top_of_low_memory(); |
| 63 | gnvs->mmiol = (u32)(get_pciebase() - 1); |
| 64 | gnvs->mmiohb = (u64)get_top_of_upper_memory(); |
Arthur Heymans | ba15a59 | 2021-10-28 10:14:31 +0200 | [diff] [blame] | 65 | gnvs->mmiohl = (u64)(((u64)1 << cpu_phys_address_size()) - 1); |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 66 | gnvs->tsegb = (u32)get_tseg_memory(); |
| 67 | gnvs->tsegl = (u32)(get_top_of_low_memory() - get_tseg_memory()); |
| 68 | } |
| 69 | |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 70 | uint32_t soc_read_sci_irq_select(void) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 71 | { |
Elyes HAOUAS | 2ec4183 | 2018-05-27 17:40:58 +0200 | [diff] [blame] | 72 | struct device *dev = get_pmc_dev(); |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 73 | |
| 74 | if (!dev) |
| 75 | return 0; |
| 76 | |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 77 | return pci_read_config32(dev, PMC_ACPI_CNT); |
| 78 | } |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 79 | |
Angel Pons | e9f10ff | 2021-10-17 13:28:23 +0200 | [diff] [blame] | 80 | const acpi_cstate_t *soc_get_cstate_map(size_t *entries) |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 81 | { |
| 82 | *entries = ARRAY_SIZE(cstate_map); |
| 83 | return cstate_map; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 86 | void soc_fill_fadt(acpi_fadt_t *fadt) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 87 | { |
| 88 | u16 pmbase = get_pmbase(); |
| 89 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 90 | /* Power Control */ |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 91 | fadt->pm2_cnt_blk = pmbase + PM2_CNT; |
| 92 | fadt->pm_tmr_blk = pmbase + PM1_TMR; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 93 | |
| 94 | /* Control Registers - Length */ |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 95 | fadt->pm2_cnt_len = 1; |
| 96 | fadt->pm_tmr_len = 4; |
Kyösti Mälkki | c328a68 | 2019-11-23 07:23:40 +0200 | [diff] [blame] | 97 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 98 | fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042; |
| 99 | |
Kyösti Mälkki | 88decca | 2023-04-28 07:04:34 +0300 | [diff] [blame] | 100 | /* PM Extended Registers */ |
| 101 | fill_fadt_extended_pm_io(fadt); |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 102 | } |
| 103 | |
Julien Viard de Galbert | 595202c | 2018-03-29 14:01:01 +0200 | [diff] [blame] | 104 | static acpi_tstate_t denverton_tss_table[] = { |
| 105 | { 100, 1000, 0, 0x00, 0 }, |
| 106 | { 88, 875, 0, 0x1e, 0 }, |
| 107 | { 75, 750, 0, 0x1c, 0 }, |
| 108 | { 63, 625, 0, 0x1a, 0 }, |
| 109 | { 50, 500, 0, 0x18, 0 }, |
| 110 | { 38, 375, 0, 0x16, 0 }, |
| 111 | { 25, 250, 0, 0x14, 0 }, |
| 112 | { 13, 125, 0, 0x12, 0 }, |
| 113 | }; |
| 114 | |
| 115 | acpi_tstate_t *soc_get_tss_table(int *entries) |
| 116 | { |
| 117 | *entries = ARRAY_SIZE(denverton_tss_table); |
| 118 | return denverton_tss_table; |
| 119 | } |
| 120 | |
| 121 | void soc_power_states_generation(int core_id, int cores_per_package) |
| 122 | { |
| 123 | generate_p_state_entries(core_id, cores_per_package); |
| 124 | |
| 125 | generate_t_state_entries(core_id, cores_per_package); |
| 126 | } |
| 127 | |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 128 | int soc_madt_sci_irq_polarity(int sci) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 129 | { |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 130 | if (sci >= 20) |
| 131 | return MP_IRQ_POLARITY_LOW; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 132 | else |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 133 | return MP_IRQ_POLARITY_HIGH; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 134 | } |
| 135 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 136 | unsigned long southcluster_write_acpi_tables(const struct device *device, |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 137 | unsigned long current, |
| 138 | struct acpi_rsdp *rsdp) |
| 139 | { |
| 140 | acpi_header_t *ssdt2; |
| 141 | |
| 142 | current = acpi_write_hpet(device, current, rsdp); |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 143 | current = (ALIGN_UP(current, 16)); |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 144 | |
| 145 | ssdt2 = (acpi_header_t *)current; |
| 146 | memset(ssdt2, 0, sizeof(acpi_header_t)); |
| 147 | acpi_create_serialio_ssdt(ssdt2); |
| 148 | if (ssdt2->length) { |
| 149 | current += ssdt2->length; |
| 150 | acpi_add_table(rsdp, ssdt2); |
| 151 | printk(BIOS_DEBUG, "ACPI: * SSDT2 @ %p Length %x\n", ssdt2, |
| 152 | ssdt2->length); |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 153 | current = (ALIGN_UP(current, 16)); |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 154 | } else { |
| 155 | ssdt2 = NULL; |
| 156 | printk(BIOS_DEBUG, "ACPI: * SSDT2 not generated.\n"); |
| 157 | } |
| 158 | |
| 159 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 160 | |
| 161 | return current; |
| 162 | } |
| 163 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 164 | __weak void acpi_create_serialio_ssdt(acpi_header_t *ssdt) {} |
Julien Viard de Galbert | a0e5046 | 2018-04-05 11:59:07 +0200 | [diff] [blame] | 165 | |
| 166 | static unsigned long acpi_fill_dmar(unsigned long current) |
| 167 | { |
| 168 | uint64_t vtbar; |
| 169 | unsigned long tmp = current; |
| 170 | |
| 171 | vtbar = read64((void *)(DEFAULT_MCHBAR + MCH_VTBAR_OFFSET)) & MCH_VTBAR_MASK; |
| 172 | printk(BIOS_DEBUG, "DEFVTBAR:0x%llx\n", vtbar); |
| 173 | if (!vtbar) |
| 174 | return current; |
| 175 | |
| 176 | current += acpi_create_dmar_drhd(current, |
| 177 | DRHD_INCLUDE_PCI_ALL, 0, vtbar); |
| 178 | |
Arthur Heymans | d90154c | 2022-12-02 13:27:35 +0100 | [diff] [blame] | 179 | current += acpi_create_dmar_ds_ioapic_from_hw(current, |
| 180 | IO_APIC_ADDR, PCH_IOAPIC_PCI_BUS, PCH_IOAPIC_PCI_SLOT, 0); |
Julien Viard de Galbert | a0e5046 | 2018-04-05 11:59:07 +0200 | [diff] [blame] | 181 | current += acpi_create_dmar_ds_msi_hpet(current, |
| 182 | 0, PCH_HPET_PCI_BUS, PCH_HPET_PCI_SLOT, 0); |
| 183 | |
| 184 | acpi_dmar_drhd_fixup(tmp, current); |
| 185 | |
| 186 | /* Create RMRR; see "VTD PLATFORM CONFIGURATION" in FSP log */ |
| 187 | tmp = current; |
| 188 | current += acpi_create_dmar_rmrr(current, 0, |
| 189 | RMRR_USB_BASE_ADDRESS, |
| 190 | RMRR_USB_LIMIT_ADDRESS); |
| 191 | current += acpi_create_dmar_ds_pci(current, |
| 192 | 0, XHCI_DEV, XHCI_FUNC); |
| 193 | acpi_dmar_rmrr_fixup(tmp, current); |
| 194 | |
| 195 | return current; |
| 196 | } |
| 197 | |
| 198 | unsigned long systemagent_write_acpi_tables(const struct device *dev, |
| 199 | unsigned long current, |
| 200 | struct acpi_rsdp *const rsdp) |
| 201 | { |
| 202 | /* Create DMAR table only if we have VT-d capability. */ |
| 203 | const u32 capid0_a = pci_read_config32(dev, CAPID0_A); |
| 204 | if (capid0_a & VTD_DISABLE) |
| 205 | return current; |
| 206 | |
| 207 | acpi_dmar_t *const dmar = (acpi_dmar_t *)current; |
| 208 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
| 209 | acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar); |
| 210 | current += dmar->header.length; |
| 211 | current = acpi_align_current(current); |
| 212 | acpi_add_table(rsdp, dmar); |
| 213 | |
| 214 | return current; |
| 215 | } |