blob: bd2f719654869377d0d744e2f0de7234f360b545 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin76c37002012-10-30 09:03:43 -05002
3#include <types.h>
Aaron Durbin76c37002012-10-30 09:03:43 -05004#include <console/console.h>
Angel Ponsf4fa1e12020-08-03 14:12:13 +02005#include <commonlib/helpers.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07006#include <acpi/acpi.h>
Bill XIEb184e6e2023-01-29 09:55:19 +08007#include <arch/ioapic.h>
Aaron Durbin76c37002012-10-30 09:03:43 -05008#include <device/device.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02009#include <device/pci_ops.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050010#include "haswell.h"
Matt DeVillier85d98d92018-03-04 01:41:23 -060011#include <southbridge/intel/lynxpoint/pch.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050012
Matt DeVillier85d98d92018-03-04 01:41:23 -060013static unsigned long acpi_fill_dmar(unsigned long current)
14{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030015 struct device *const igfx_dev = pcidev_on_root(2, 0);
Angel Pons2e397ae2021-03-26 12:35:57 +010016 const u32 gfxvtbar = mchbar_read32(GFXVTBAR) & ~0xfff;
17 const u32 vtvc0bar = mchbar_read32(VTVC0BAR) & ~0xfff;
18 const bool gfxvten = mchbar_read32(GFXVTBAR) & 0x1;
19 const bool vtvc0en = mchbar_read32(VTVC0BAR) & 0x1;
Matt DeVillier85d98d92018-03-04 01:41:23 -060020
21 /* iGFX has to be enabled; GFXVTBAR set, enabled, in 32-bit space */
Angel Pons849104f2020-10-29 21:39:52 +010022 const bool emit_igd =
23 igfx_dev && igfx_dev->enabled &&
24 gfxvtbar && gfxvten &&
Angel Pons2e397ae2021-03-26 12:35:57 +010025 !mchbar_read32(GFXVTBAR + 4);
Angel Pons1db5bc72020-01-15 00:49:03 +010026
Angel Pons849104f2020-10-29 21:39:52 +010027 /* First, add DRHD entries */
28 if (emit_igd) {
Matt DeVillier85d98d92018-03-04 01:41:23 -060029 const unsigned long tmp = current;
30
Shuo Liuf3aaa0e2024-06-25 18:50:06 +080031 current += acpi_create_dmar_drhd_4k(current, 0, 0, gfxvtbar);
Matt DeVillier7866d492018-03-29 14:59:57 +020032 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
Matt DeVillier85d98d92018-03-04 01:41:23 -060033
34 acpi_dmar_drhd_fixup(tmp, current);
35 }
36
37 /* VTVC0BAR has to be set, enabled, and in 32-bit space */
Angel Pons2e397ae2021-03-26 12:35:57 +010038 if (vtvc0bar && vtvc0en && !mchbar_read32(VTVC0BAR + 4)) {
Matt DeVillier85d98d92018-03-04 01:41:23 -060039 const unsigned long tmp = current;
Shuo Liuf3aaa0e2024-06-25 18:50:06 +080040 current += acpi_create_dmar_drhd_4k(current, DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
Bill XIEb184e6e2023-01-29 09:55:19 +080041 current += acpi_create_dmar_ds_ioapic_from_hw(current, IO_APIC_ADDR,
42 PCH_IOAPIC_PCI_BUS,
43 PCH_IOAPIC_PCI_SLOT, 0);
Angel Pons1db5bc72020-01-15 00:49:03 +010044
Matt DeVillier85d98d92018-03-04 01:41:23 -060045 size_t i;
46 for (i = 0; i < 8; ++i)
Angel Pons1db5bc72020-01-15 00:49:03 +010047 current += acpi_create_dmar_ds_msi_hpet(current, 0, PCH_HPET_PCI_BUS,
48 PCH_HPET_PCI_SLOT, i);
Matt DeVillier85d98d92018-03-04 01:41:23 -060049 acpi_dmar_drhd_fixup(tmp, current);
50 }
51
Angel Pons849104f2020-10-29 21:39:52 +010052 /* Then, add RMRR entries after all DRHD entries */
53 if (emit_igd) {
54 const unsigned long tmp = current;
55
56 const struct device *sa_dev = pcidev_on_root(0, 0);
57
58 /* Bit 0 is lock bit, not part of address */
59 const u32 tolud = pci_read_config32(sa_dev, TOLUD) & ~1;
60 const u32 bgsm = pci_read_config32(sa_dev, BGSM) & ~1;
61
62 current += acpi_create_dmar_rmrr(current, 0, bgsm, tolud - 1);
63 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
64 acpi_dmar_rmrr_fixup(tmp, current);
65 }
66
Matt DeVillier85d98d92018-03-04 01:41:23 -060067 return current;
68}
69
Furquan Shaikh0f007d82020-04-24 06:41:18 -070070unsigned long northbridge_write_acpi_tables(const struct device *const dev,
71 unsigned long current,
Matt DeVillier85d98d92018-03-04 01:41:23 -060072 struct acpi_rsdp *const rsdp)
73{
74 /* Create DMAR table only if we have VT-d capability. */
75 const u32 capid0_a = pci_read_config32(dev, CAPID0_A);
76 if (capid0_a & VTD_DISABLE)
77 return current;
78
79 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
80 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
81 acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar);
82 current += dmar->header.length;
83 current = acpi_align_current(current);
84 acpi_add_table(rsdp, dmar);
85
86 return current;
87}