blob: 67b193e1f703bded751cd69309d5cbb7afb3473f [file] [log] [blame]
Angel Ponsf94ac9a2020-04-05 15:46:48 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Duncan Lauriec88c54c2014-04-30 16:36:13 -07002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpi.h>
4#include <acpi/acpigen.h>
Angel Ponsa472e332020-10-26 00:08:47 +01005#include <arch/ioapic.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07006#include <arch/smp/mpspec.h>
Angel Pons9d733de2020-11-23 13:15:19 +01007#include <cpu/intel/haswell/haswell.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +02008#include <device/pci_ops.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07009#include <console/console.h>
Angel Pons6672dff2021-06-15 13:46:26 +020010#include <device/device.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070011#include <types.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070012#include <cpu/x86/msr.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070013#include <cpu/intel/turbo.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070014#include <soc/acpi.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070015#include <soc/iomap.h>
16#include <soc/lpc.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070017#include <soc/pci_devs.h>
18#include <soc/pm.h>
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060019#include <soc/systemagent.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070020#include <soc/intel/broadwell/chip.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070021
Duncan Lauriec88c54c2014-04-30 16:36:13 -070022unsigned long acpi_fill_mcfg(unsigned long current)
23{
24 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current,
Angel Pons9debbd62021-01-28 12:42:53 +010025 CONFIG_MMCONF_BASE_ADDRESS, 0, 0,
26 CONFIG_MMCONF_BUS_NUMBER - 1);
Duncan Lauriec88c54c2014-04-30 16:36:13 -070027 return current;
28}
29
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060030static unsigned long acpi_fill_dmar(unsigned long current)
31{
Kyösti Mälkki903b40a2019-07-03 07:25:59 +030032 struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD);
Angel Ponsa8753e92021-04-17 14:34:37 +020033 const u32 gfxvtbar = mchbar_read32(GFXVTBAR) & ~0xfff;
34 const u32 vtvc0bar = mchbar_read32(VTVC0BAR) & ~0xfff;
35 const bool gfxvten = mchbar_read32(GFXVTBAR) & 0x1;
36 const bool vtvc0en = mchbar_read32(VTVC0BAR) & 0x1;
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060037
38 /* iGFX has to be enabled; GFXVTBAR set, enabled, in 32-bit space */
Angel Pons37799b32020-08-03 12:17:22 +020039 const bool emit_igd =
40 igfx_dev && igfx_dev->enabled &&
41 gfxvtbar && gfxvten &&
Angel Ponsa8753e92021-04-17 14:34:37 +020042 !mchbar_read32(GFXVTBAR + 4);
Angel Pons37799b32020-08-03 12:17:22 +020043
44 /* First, add DRHD entries */
45 if (emit_igd) {
46 const unsigned long tmp = current;
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060047
48 current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
Matt DeVillier7866d492018-03-29 14:59:57 +020049 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060050
51 acpi_dmar_drhd_fixup(tmp, current);
52 }
53
54 /* VTVC0BAR has to be set, enabled, and in 32-bit space */
Angel Ponsa8753e92021-04-17 14:34:37 +020055 if (vtvc0bar && vtvc0en && !mchbar_read32(VTVC0BAR + 4)) {
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060056 const unsigned long tmp = current;
57 current += acpi_create_dmar_drhd(current,
58 DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
Matt DeVillier7866d492018-03-29 14:59:57 +020059 current += acpi_create_dmar_ds_ioapic(current,
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060060 2, PCH_IOAPIC_PCI_BUS, PCH_IOAPIC_PCI_SLOT, 0);
61 size_t i;
62 for (i = 0; i < 8; ++i)
Matt DeVillier7866d492018-03-29 14:59:57 +020063 current += acpi_create_dmar_ds_msi_hpet(current,
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060064 0, PCH_HPET_PCI_BUS,
65 PCH_HPET_PCI_SLOT, i);
66 acpi_dmar_drhd_fixup(tmp, current);
67 }
68
Angel Pons37799b32020-08-03 12:17:22 +020069 /* Then, add RMRR entries after all DRHD entries */
70 if (emit_igd) {
71 const unsigned long tmp = current;
72
Angel Pons6672dff2021-06-15 13:46:26 +020073 const struct device *sa_dev = pcidev_on_root(0, 0);
74
75 /* Bit 0 is lock bit, not part of address */
76 const u32 tolud = pci_read_config32(sa_dev, TOLUD) & ~1;
77 const u32 bgsm = pci_read_config32(sa_dev, BGSM) & ~1;
78
79 current += acpi_create_dmar_rmrr(current, 0, bgsm, tolud - 1);
Angel Pons37799b32020-08-03 12:17:22 +020080 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
81 acpi_dmar_rmrr_fixup(tmp, current);
82 }
83
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060084 return current;
85}
86
Furquan Shaikh0f007d82020-04-24 06:41:18 -070087unsigned long northbridge_write_acpi_tables(const struct device *const dev,
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060088 unsigned long current,
89 struct acpi_rsdp *const rsdp)
90{
91 /* Create DMAR table only if we have VT-d capability. */
92 const u32 capid0_a = pci_read_config32(dev, CAPID0_A);
93 if (capid0_a & VTD_DISABLE)
94 return current;
95
96 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
97 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
98 acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar);
99 current += dmar->header.length;
100 current = acpi_align_current(current);
101 acpi_add_table(rsdp, dmar);
102
103 return current;
104}