Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 2 | |
| 3 | #include <types.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 4 | #include <console/console.h> |
Angel Pons | f4fa1e1 | 2020-08-03 14:12:13 +0200 | [diff] [blame^] | 5 | #include <commonlib/helpers.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 6 | #include <acpi/acpi.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 7 | #include <device/device.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 8 | #include <device/pci_ops.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 9 | #include "haswell.h" |
Matt DeVillier | 85d98d9 | 2018-03-04 01:41:23 -0600 | [diff] [blame] | 10 | #include <southbridge/intel/lynxpoint/pch.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 11 | |
| 12 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 13 | { |
Angel Pons | f4fa1e1 | 2020-08-03 14:12:13 +0200 | [diff] [blame^] | 14 | u32 length, pciexbar; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 15 | |
Angel Pons | f4fa1e1 | 2020-08-03 14:12:13 +0200 | [diff] [blame^] | 16 | if (!decode_pcie_bar(&pciexbar, &length)) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 17 | return current; |
| 18 | |
Angel Pons | f4fa1e1 | 2020-08-03 14:12:13 +0200 | [diff] [blame^] | 19 | const int max_buses = length / MiB; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 20 | |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 21 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current, pciexbar, 0, 0, |
| 22 | max_buses - 1); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 23 | |
| 24 | return current; |
| 25 | } |
Matt DeVillier | 85d98d9 | 2018-03-04 01:41:23 -0600 | [diff] [blame] | 26 | |
| 27 | static unsigned long acpi_fill_dmar(unsigned long current) |
| 28 | { |
Kyösti Mälkki | c70eed1 | 2018-05-22 02:18:00 +0300 | [diff] [blame] | 29 | struct device *const igfx_dev = pcidev_on_root(2, 0); |
Matt DeVillier | 85d98d9 | 2018-03-04 01:41:23 -0600 | [diff] [blame] | 30 | const u32 gfxvtbar = MCHBAR32(GFXVTBAR) & ~0xfff; |
| 31 | const u32 vtvc0bar = MCHBAR32(VTVC0BAR) & ~0xfff; |
| 32 | const bool gfxvten = MCHBAR32(GFXVTBAR) & 0x1; |
| 33 | const bool vtvc0en = MCHBAR32(VTVC0BAR) & 0x1; |
| 34 | |
| 35 | /* iGFX has to be enabled; GFXVTBAR set, enabled, in 32-bit space */ |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 36 | if (igfx_dev && igfx_dev->enabled && gfxvtbar && gfxvten && !MCHBAR32(GFXVTBAR + 4)) { |
| 37 | |
Matt DeVillier | 85d98d9 | 2018-03-04 01:41:23 -0600 | [diff] [blame] | 38 | const unsigned long tmp = current; |
| 39 | |
| 40 | current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar); |
Matt DeVillier | 7866d49 | 2018-03-29 14:59:57 +0200 | [diff] [blame] | 41 | current += acpi_create_dmar_ds_pci(current, 0, 2, 0); |
Matt DeVillier | 85d98d9 | 2018-03-04 01:41:23 -0600 | [diff] [blame] | 42 | |
| 43 | acpi_dmar_drhd_fixup(tmp, current); |
| 44 | } |
| 45 | |
| 46 | /* VTVC0BAR has to be set, enabled, and in 32-bit space */ |
| 47 | if (vtvc0bar && vtvc0en && !MCHBAR32(VTVC0BAR + 4)) { |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 48 | |
Matt DeVillier | 85d98d9 | 2018-03-04 01:41:23 -0600 | [diff] [blame] | 49 | const unsigned long tmp = current; |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 50 | current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar); |
| 51 | current += acpi_create_dmar_ds_ioapic(current, 2, PCH_IOAPIC_PCI_BUS, |
| 52 | PCH_IOAPIC_PCI_SLOT, 0); |
| 53 | |
Matt DeVillier | 85d98d9 | 2018-03-04 01:41:23 -0600 | [diff] [blame] | 54 | size_t i; |
| 55 | for (i = 0; i < 8; ++i) |
Angel Pons | 1db5bc7 | 2020-01-15 00:49:03 +0100 | [diff] [blame] | 56 | current += acpi_create_dmar_ds_msi_hpet(current, 0, PCH_HPET_PCI_BUS, |
| 57 | PCH_HPET_PCI_SLOT, i); |
Matt DeVillier | 85d98d9 | 2018-03-04 01:41:23 -0600 | [diff] [blame] | 58 | acpi_dmar_drhd_fixup(tmp, current); |
| 59 | } |
| 60 | |
| 61 | return current; |
| 62 | } |
| 63 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 64 | unsigned long northbridge_write_acpi_tables(const struct device *const dev, |
| 65 | unsigned long current, |
Matt DeVillier | 85d98d9 | 2018-03-04 01:41:23 -0600 | [diff] [blame] | 66 | struct acpi_rsdp *const rsdp) |
| 67 | { |
| 68 | /* Create DMAR table only if we have VT-d capability. */ |
| 69 | const u32 capid0_a = pci_read_config32(dev, CAPID0_A); |
| 70 | if (capid0_a & VTD_DISABLE) |
| 71 | return current; |
| 72 | |
| 73 | acpi_dmar_t *const dmar = (acpi_dmar_t *)current; |
| 74 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
| 75 | acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar); |
| 76 | current += dmar->header.length; |
| 77 | current = acpi_align_current(current); |
| 78 | acpi_add_table(rsdp, dmar); |
| 79 | |
| 80 | return current; |
| 81 | } |