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