blob: 290dc1e9287332be4abd1ef0ff43f65a36f96bc3 [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>
Aaron Durbin76c37002012-10-30 09:03:43 -05007#include <device/device.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02008#include <device/pci_ops.h>
Aaron Durbin76c37002012-10-30 09:03:43 -05009#include "haswell.h"
Matt DeVillier85d98d92018-03-04 01:41:23 -060010#include <southbridge/intel/lynxpoint/pch.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050011
Matt DeVillier85d98d92018-03-04 01:41:23 -060012static unsigned long acpi_fill_dmar(unsigned long current)
13{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030014 struct device *const igfx_dev = pcidev_on_root(2, 0);
Angel Pons2e397ae2021-03-26 12:35:57 +010015 const u32 gfxvtbar = mchbar_read32(GFXVTBAR) & ~0xfff;
16 const u32 vtvc0bar = mchbar_read32(VTVC0BAR) & ~0xfff;
17 const bool gfxvten = mchbar_read32(GFXVTBAR) & 0x1;
18 const bool vtvc0en = mchbar_read32(VTVC0BAR) & 0x1;
Matt DeVillier85d98d92018-03-04 01:41:23 -060019
20 /* iGFX has to be enabled; GFXVTBAR set, enabled, in 32-bit space */
Angel Pons849104f2020-10-29 21:39:52 +010021 const bool emit_igd =
22 igfx_dev && igfx_dev->enabled &&
23 gfxvtbar && gfxvten &&
Angel Pons2e397ae2021-03-26 12:35:57 +010024 !mchbar_read32(GFXVTBAR + 4);
Angel Pons1db5bc72020-01-15 00:49:03 +010025
Angel Pons849104f2020-10-29 21:39:52 +010026 /* First, add DRHD entries */
27 if (emit_igd) {
Matt DeVillier85d98d92018-03-04 01:41:23 -060028 const unsigned long tmp = current;
29
30 current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
Matt DeVillier7866d492018-03-29 14:59:57 +020031 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
Matt DeVillier85d98d92018-03-04 01:41:23 -060032
33 acpi_dmar_drhd_fixup(tmp, current);
34 }
35
36 /* VTVC0BAR has to be set, enabled, and in 32-bit space */
Angel Pons2e397ae2021-03-26 12:35:57 +010037 if (vtvc0bar && vtvc0en && !mchbar_read32(VTVC0BAR + 4)) {
Angel Pons1db5bc72020-01-15 00:49:03 +010038
Matt DeVillier85d98d92018-03-04 01:41:23 -060039 const unsigned long tmp = current;
Angel Pons1db5bc72020-01-15 00:49:03 +010040 current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
41 current += acpi_create_dmar_ds_ioapic(current, 2, PCH_IOAPIC_PCI_BUS,
42 PCH_IOAPIC_PCI_SLOT, 0);
43
Matt DeVillier85d98d92018-03-04 01:41:23 -060044 size_t i;
45 for (i = 0; i < 8; ++i)
Angel Pons1db5bc72020-01-15 00:49:03 +010046 current += acpi_create_dmar_ds_msi_hpet(current, 0, PCH_HPET_PCI_BUS,
47 PCH_HPET_PCI_SLOT, i);
Matt DeVillier85d98d92018-03-04 01:41:23 -060048 acpi_dmar_drhd_fixup(tmp, current);
49 }
50
Angel Pons849104f2020-10-29 21:39:52 +010051 /* Then, add RMRR entries after all DRHD entries */
52 if (emit_igd) {
53 const unsigned long tmp = current;
54
55 const struct device *sa_dev = pcidev_on_root(0, 0);
56
57 /* Bit 0 is lock bit, not part of address */
58 const u32 tolud = pci_read_config32(sa_dev, TOLUD) & ~1;
59 const u32 bgsm = pci_read_config32(sa_dev, BGSM) & ~1;
60
61 current += acpi_create_dmar_rmrr(current, 0, bgsm, tolud - 1);
62 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
63 acpi_dmar_rmrr_fixup(tmp, current);
64 }
65
Matt DeVillier85d98d92018-03-04 01:41:23 -060066 return current;
67}
68
Furquan Shaikh0f007d82020-04-24 06:41:18 -070069unsigned long northbridge_write_acpi_tables(const struct device *const dev,
70 unsigned long current,
Matt DeVillier85d98d92018-03-04 01:41:23 -060071 struct acpi_rsdp *const rsdp)
72{
73 /* Create DMAR table only if we have VT-d capability. */
74 const u32 capid0_a = pci_read_config32(dev, CAPID0_A);
75 if (capid0_a & VTD_DISABLE)
76 return current;
77
78 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
79 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
80 acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar);
81 current += dmar->header.length;
82 current = acpi_align_current(current);
83 acpi_add_table(rsdp, dmar);
84
85 return current;
86}