Angel Pons | f94ac9a | 2020-04-05 15:46:48 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
| 4 | #include <acpi/acpigen.h> |
Angel Pons | a472e33 | 2020-10-26 00:08:47 +0100 | [diff] [blame] | 5 | #include <arch/ioapic.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 6 | #include <arch/smp/mpspec.h> |
Angel Pons | 9d733de | 2020-11-23 13:15:19 +0100 | [diff] [blame] | 7 | #include <cpu/intel/haswell/haswell.h> |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 8 | #include <device/pci_ops.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 9 | #include <console/console.h> |
| 10 | #include <types.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 11 | #include <cpu/x86/msr.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 12 | #include <cpu/intel/turbo.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 13 | #include <soc/acpi.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 14 | #include <soc/iomap.h> |
| 15 | #include <soc/lpc.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 16 | #include <soc/pci_devs.h> |
| 17 | #include <soc/pm.h> |
Matt DeVillier | 0f49bbc | 2018-02-19 17:35:55 -0600 | [diff] [blame] | 18 | #include <soc/systemagent.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 19 | #include <soc/intel/broadwell/chip.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 20 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 21 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 22 | { |
| 23 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current, |
Angel Pons | 9debbd6 | 2021-01-28 12:42:53 +0100 | [diff] [blame] | 24 | CONFIG_MMCONF_BASE_ADDRESS, 0, 0, |
| 25 | CONFIG_MMCONF_BUS_NUMBER - 1); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 26 | return current; |
| 27 | } |
| 28 | |
Matt DeVillier | 0f49bbc | 2018-02-19 17:35:55 -0600 | [diff] [blame] | 29 | static unsigned long acpi_fill_dmar(unsigned long current) |
| 30 | { |
Kyösti Mälkki | 903b40a | 2019-07-03 07:25:59 +0300 | [diff] [blame] | 31 | struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD); |
Angel Pons | a8753e9 | 2021-04-17 14:34:37 +0200 | [diff] [blame^] | 32 | const u32 gfxvtbar = mchbar_read32(GFXVTBAR) & ~0xfff; |
| 33 | const u32 vtvc0bar = mchbar_read32(VTVC0BAR) & ~0xfff; |
| 34 | const bool gfxvten = mchbar_read32(GFXVTBAR) & 0x1; |
| 35 | const bool vtvc0en = mchbar_read32(VTVC0BAR) & 0x1; |
Matt DeVillier | 0f49bbc | 2018-02-19 17:35:55 -0600 | [diff] [blame] | 36 | |
| 37 | /* iGFX has to be enabled; GFXVTBAR set, enabled, in 32-bit space */ |
Angel Pons | 37799b3 | 2020-08-03 12:17:22 +0200 | [diff] [blame] | 38 | const bool emit_igd = |
| 39 | igfx_dev && igfx_dev->enabled && |
| 40 | gfxvtbar && gfxvten && |
Angel Pons | a8753e9 | 2021-04-17 14:34:37 +0200 | [diff] [blame^] | 41 | !mchbar_read32(GFXVTBAR + 4); |
Angel Pons | 37799b3 | 2020-08-03 12:17:22 +0200 | [diff] [blame] | 42 | |
| 43 | /* First, add DRHD entries */ |
| 44 | if (emit_igd) { |
| 45 | const unsigned long tmp = current; |
Matt DeVillier | 0f49bbc | 2018-02-19 17:35:55 -0600 | [diff] [blame] | 46 | |
| 47 | current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar); |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 48 | current += acpi_create_dmar_ds_pci(current, 0, 2, 0); |
Matt DeVillier | 0f49bbc | 2018-02-19 17:35:55 -0600 | [diff] [blame] | 49 | |
| 50 | acpi_dmar_drhd_fixup(tmp, current); |
| 51 | } |
| 52 | |
| 53 | /* VTVC0BAR has to be set, enabled, and in 32-bit space */ |
Angel Pons | a8753e9 | 2021-04-17 14:34:37 +0200 | [diff] [blame^] | 54 | if (vtvc0bar && vtvc0en && !mchbar_read32(VTVC0BAR + 4)) { |
Matt DeVillier | 0f49bbc | 2018-02-19 17:35:55 -0600 | [diff] [blame] | 55 | const unsigned long tmp = current; |
| 56 | current += acpi_create_dmar_drhd(current, |
| 57 | DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar); |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 58 | current += acpi_create_dmar_ds_ioapic(current, |
Matt DeVillier | 0f49bbc | 2018-02-19 17:35:55 -0600 | [diff] [blame] | 59 | 2, PCH_IOAPIC_PCI_BUS, PCH_IOAPIC_PCI_SLOT, 0); |
| 60 | size_t i; |
| 61 | for (i = 0; i < 8; ++i) |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 62 | current += acpi_create_dmar_ds_msi_hpet(current, |
Matt DeVillier | 0f49bbc | 2018-02-19 17:35:55 -0600 | [diff] [blame] | 63 | 0, PCH_HPET_PCI_BUS, |
| 64 | PCH_HPET_PCI_SLOT, i); |
| 65 | acpi_dmar_drhd_fixup(tmp, current); |
| 66 | } |
| 67 | |
Angel Pons | 37799b3 | 2020-08-03 12:17:22 +0200 | [diff] [blame] | 68 | /* Then, add RMRR entries after all DRHD entries */ |
| 69 | if (emit_igd) { |
| 70 | const unsigned long tmp = current; |
| 71 | |
| 72 | current += acpi_create_dmar_rmrr(current, 0, |
| 73 | sa_get_gsm_base(), sa_get_tolud_base() - 1); |
| 74 | current += acpi_create_dmar_ds_pci(current, 0, 2, 0); |
| 75 | acpi_dmar_rmrr_fixup(tmp, current); |
| 76 | } |
| 77 | |
Matt DeVillier | 0f49bbc | 2018-02-19 17:35:55 -0600 | [diff] [blame] | 78 | return current; |
| 79 | } |
| 80 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 81 | unsigned long northbridge_write_acpi_tables(const struct device *const dev, |
Matt DeVillier | 0f49bbc | 2018-02-19 17:35:55 -0600 | [diff] [blame] | 82 | unsigned long current, |
| 83 | struct acpi_rsdp *const rsdp) |
| 84 | { |
| 85 | /* Create DMAR table only if we have VT-d capability. */ |
| 86 | const u32 capid0_a = pci_read_config32(dev, CAPID0_A); |
| 87 | if (capid0_a & VTD_DISABLE) |
| 88 | return current; |
| 89 | |
| 90 | acpi_dmar_t *const dmar = (acpi_dmar_t *)current; |
| 91 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
| 92 | acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar); |
| 93 | current += dmar->header.length; |
| 94 | current = acpi_align_current(current); |
| 95 | acpi_add_table(rsdp, dmar); |
| 96 | |
| 97 | return current; |
| 98 | } |