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 | |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 84 | void soc_fill_fadt(acpi_fadt_t *fadt) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 85 | { |
| 86 | u16 pmbase = get_pmbase(); |
| 87 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 88 | /* Power Control */ |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 89 | fadt->pm2_cnt_blk = pmbase + PM2_CNT; |
| 90 | fadt->pm_tmr_blk = pmbase + PM1_TMR; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 91 | |
| 92 | /* Control Registers - Length */ |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 93 | fadt->pm2_cnt_len = 1; |
| 94 | fadt->pm_tmr_len = 4; |
Kyösti Mälkki | c328a68 | 2019-11-23 07:23:40 +0200 | [diff] [blame] | 95 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 96 | fadt->iapc_boot_arch = ACPI_FADT_LEGACY_DEVICES | ACPI_FADT_8042; |
| 97 | |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 98 | /* PM2 Control Registers */ |
| 99 | fadt->x_pm2_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 100 | fadt->x_pm2_cnt_blk.bit_width = 8; |
| 101 | fadt->x_pm2_cnt_blk.bit_offset = 0; |
| 102 | fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS; |
| 103 | fadt->x_pm2_cnt_blk.addrl = fadt->pm2_cnt_blk; |
| 104 | fadt->x_pm2_cnt_blk.addrh = 0x00; |
| 105 | |
| 106 | /* PM1 Timer Register */ |
| 107 | fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO; |
| 108 | fadt->x_pm_tmr_blk.bit_width = 32; |
| 109 | fadt->x_pm_tmr_blk.bit_offset = 0; |
| 110 | fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS; |
| 111 | fadt->x_pm_tmr_blk.addrl = fadt->pm_tmr_blk; |
| 112 | fadt->x_pm_tmr_blk.addrh = 0x00; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 113 | } |
| 114 | |
Julien Viard de Galbert | 595202c | 2018-03-29 14:01:01 +0200 | [diff] [blame] | 115 | static acpi_tstate_t denverton_tss_table[] = { |
| 116 | { 100, 1000, 0, 0x00, 0 }, |
| 117 | { 88, 875, 0, 0x1e, 0 }, |
| 118 | { 75, 750, 0, 0x1c, 0 }, |
| 119 | { 63, 625, 0, 0x1a, 0 }, |
| 120 | { 50, 500, 0, 0x18, 0 }, |
| 121 | { 38, 375, 0, 0x16, 0 }, |
| 122 | { 25, 250, 0, 0x14, 0 }, |
| 123 | { 13, 125, 0, 0x12, 0 }, |
| 124 | }; |
| 125 | |
| 126 | acpi_tstate_t *soc_get_tss_table(int *entries) |
| 127 | { |
| 128 | *entries = ARRAY_SIZE(denverton_tss_table); |
| 129 | return denverton_tss_table; |
| 130 | } |
| 131 | |
| 132 | void soc_power_states_generation(int core_id, int cores_per_package) |
| 133 | { |
| 134 | generate_p_state_entries(core_id, cores_per_package); |
| 135 | |
| 136 | generate_t_state_entries(core_id, cores_per_package); |
| 137 | } |
| 138 | |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 139 | int soc_madt_sci_irq_polarity(int sci) |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 140 | { |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 141 | if (sci >= 20) |
| 142 | return MP_IRQ_POLARITY_LOW; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 143 | else |
Julien Viard de Galbert | cf2b72f | 2018-04-05 11:24:45 +0200 | [diff] [blame] | 144 | return MP_IRQ_POLARITY_HIGH; |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 145 | } |
| 146 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 147 | unsigned long southcluster_write_acpi_tables(const struct device *device, |
Mariusz Szafranski | a404133 | 2017-08-02 17:28:17 +0200 | [diff] [blame] | 148 | unsigned long current, |
| 149 | struct acpi_rsdp *rsdp) |
| 150 | { |
| 151 | acpi_header_t *ssdt2; |
| 152 | |
| 153 | current = acpi_write_hpet(device, current, rsdp); |
| 154 | current = (ALIGN(current, 16)); |
| 155 | |
| 156 | ssdt2 = (acpi_header_t *)current; |
| 157 | memset(ssdt2, 0, sizeof(acpi_header_t)); |
| 158 | acpi_create_serialio_ssdt(ssdt2); |
| 159 | if (ssdt2->length) { |
| 160 | current += ssdt2->length; |
| 161 | acpi_add_table(rsdp, ssdt2); |
| 162 | printk(BIOS_DEBUG, "ACPI: * SSDT2 @ %p Length %x\n", ssdt2, |
| 163 | ssdt2->length); |
| 164 | current = (ALIGN(current, 16)); |
| 165 | } else { |
| 166 | ssdt2 = NULL; |
| 167 | printk(BIOS_DEBUG, "ACPI: * SSDT2 not generated.\n"); |
| 168 | } |
| 169 | |
| 170 | printk(BIOS_DEBUG, "current = %lx\n", current); |
| 171 | |
| 172 | return current; |
| 173 | } |
| 174 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 175 | __weak void acpi_create_serialio_ssdt(acpi_header_t *ssdt) {} |
Julien Viard de Galbert | a0e5046 | 2018-04-05 11:59:07 +0200 | [diff] [blame] | 176 | |
| 177 | static unsigned long acpi_fill_dmar(unsigned long current) |
| 178 | { |
| 179 | uint64_t vtbar; |
| 180 | unsigned long tmp = current; |
| 181 | |
| 182 | vtbar = read64((void *)(DEFAULT_MCHBAR + MCH_VTBAR_OFFSET)) & MCH_VTBAR_MASK; |
| 183 | printk(BIOS_DEBUG, "DEFVTBAR:0x%llx\n", vtbar); |
| 184 | if (!vtbar) |
| 185 | return current; |
| 186 | |
| 187 | current += acpi_create_dmar_drhd(current, |
| 188 | DRHD_INCLUDE_PCI_ALL, 0, vtbar); |
| 189 | |
| 190 | current += acpi_create_dmar_ds_ioapic(current, |
| 191 | 2, PCH_IOAPIC_PCI_BUS, PCH_IOAPIC_PCI_SLOT, 0); |
| 192 | current += acpi_create_dmar_ds_msi_hpet(current, |
| 193 | 0, PCH_HPET_PCI_BUS, PCH_HPET_PCI_SLOT, 0); |
| 194 | |
| 195 | acpi_dmar_drhd_fixup(tmp, current); |
| 196 | |
| 197 | /* Create RMRR; see "VTD PLATFORM CONFIGURATION" in FSP log */ |
| 198 | tmp = current; |
| 199 | current += acpi_create_dmar_rmrr(current, 0, |
| 200 | RMRR_USB_BASE_ADDRESS, |
| 201 | RMRR_USB_LIMIT_ADDRESS); |
| 202 | current += acpi_create_dmar_ds_pci(current, |
| 203 | 0, XHCI_DEV, XHCI_FUNC); |
| 204 | acpi_dmar_rmrr_fixup(tmp, current); |
| 205 | |
| 206 | return current; |
| 207 | } |
| 208 | |
| 209 | unsigned long systemagent_write_acpi_tables(const struct device *dev, |
| 210 | unsigned long current, |
| 211 | struct acpi_rsdp *const rsdp) |
| 212 | { |
| 213 | /* Create DMAR table only if we have VT-d capability. */ |
| 214 | const u32 capid0_a = pci_read_config32(dev, CAPID0_A); |
| 215 | if (capid0_a & VTD_DISABLE) |
| 216 | return current; |
| 217 | |
| 218 | acpi_dmar_t *const dmar = (acpi_dmar_t *)current; |
| 219 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
| 220 | acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar); |
| 221 | current += dmar->header.length; |
| 222 | current = acpi_align_current(current); |
| 223 | acpi_add_table(rsdp, dmar); |
| 224 | |
| 225 | return current; |
| 226 | } |