blob: 00e6807bd5c7649f71382ac84f409800ff3ab5a7 [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>
Matt DeVillier80f95b52021-09-13 17:53:05 -05004#include <acpi/acpi_gnvs.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07005#include <acpi/acpigen.h>
Angel Ponsa472e332020-10-26 00:08:47 +01006#include <arch/ioapic.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -07007#include <arch/smp/mpspec.h>
Angel Pons9d733de2020-11-23 13:15:19 +01008#include <cpu/intel/haswell/haswell.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +02009#include <device/pci_ops.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070010#include <console/console.h>
Angel Pons6672dff2021-06-15 13:46:26 +020011#include <device/device.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070012#include <types.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070013#include <cpu/x86/msr.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070014#include <cpu/intel/turbo.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070015#include <soc/acpi.h>
Matt DeVillier80f95b52021-09-13 17:53:05 -050016#include <soc/device_nvs.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070017#include <soc/iomap.h>
18#include <soc/lpc.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070019#include <soc/pci_devs.h>
20#include <soc/pm.h>
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060021#include <soc/systemagent.h>
Julius Werner4ee4bd52014-10-20 13:46:39 -070022#include <soc/intel/broadwell/chip.h>
Duncan Lauriec88c54c2014-04-30 16:36:13 -070023
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060024static unsigned long acpi_fill_dmar(unsigned long current)
25{
Kyösti Mälkki903b40a2019-07-03 07:25:59 +030026 struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD);
Angel Ponsa8753e92021-04-17 14:34:37 +020027 const u32 gfxvtbar = mchbar_read32(GFXVTBAR) & ~0xfff;
28 const u32 vtvc0bar = mchbar_read32(VTVC0BAR) & ~0xfff;
29 const bool gfxvten = mchbar_read32(GFXVTBAR) & 0x1;
30 const bool vtvc0en = mchbar_read32(VTVC0BAR) & 0x1;
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060031
32 /* iGFX has to be enabled; GFXVTBAR set, enabled, in 32-bit space */
Angel Pons37799b32020-08-03 12:17:22 +020033 const bool emit_igd =
34 igfx_dev && igfx_dev->enabled &&
35 gfxvtbar && gfxvten &&
Angel Ponsa8753e92021-04-17 14:34:37 +020036 !mchbar_read32(GFXVTBAR + 4);
Angel Pons37799b32020-08-03 12:17:22 +020037
38 /* First, add DRHD entries */
39 if (emit_igd) {
40 const unsigned long tmp = current;
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060041
42 current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
Matt DeVillier7866d492018-03-29 14:59:57 +020043 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060044
45 acpi_dmar_drhd_fixup(tmp, current);
46 }
47
48 /* VTVC0BAR has to be set, enabled, and in 32-bit space */
Angel Ponsa8753e92021-04-17 14:34:37 +020049 if (vtvc0bar && vtvc0en && !mchbar_read32(VTVC0BAR + 4)) {
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060050 const unsigned long tmp = current;
51 current += acpi_create_dmar_drhd(current,
52 DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
Matt DeVillier7866d492018-03-29 14:59:57 +020053 current += acpi_create_dmar_ds_ioapic(current,
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060054 2, PCH_IOAPIC_PCI_BUS, PCH_IOAPIC_PCI_SLOT, 0);
55 size_t i;
56 for (i = 0; i < 8; ++i)
Matt DeVillier7866d492018-03-29 14:59:57 +020057 current += acpi_create_dmar_ds_msi_hpet(current,
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060058 0, PCH_HPET_PCI_BUS,
59 PCH_HPET_PCI_SLOT, i);
60 acpi_dmar_drhd_fixup(tmp, current);
61 }
62
Angel Pons37799b32020-08-03 12:17:22 +020063 /* Then, add RMRR entries after all DRHD entries */
64 if (emit_igd) {
65 const unsigned long tmp = current;
66
Angel Pons6672dff2021-06-15 13:46:26 +020067 const struct device *sa_dev = pcidev_on_root(0, 0);
68
69 /* Bit 0 is lock bit, not part of address */
70 const u32 tolud = pci_read_config32(sa_dev, TOLUD) & ~1;
71 const u32 bgsm = pci_read_config32(sa_dev, BGSM) & ~1;
72
73 current += acpi_create_dmar_rmrr(current, 0, bgsm, tolud - 1);
Angel Pons37799b32020-08-03 12:17:22 +020074 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
75 acpi_dmar_rmrr_fixup(tmp, current);
76 }
77
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060078 return current;
79}
80
Furquan Shaikh0f007d82020-04-24 06:41:18 -070081unsigned long northbridge_write_acpi_tables(const struct device *const dev,
Matt DeVillier0f49bbc2018-02-19 17:35:55 -060082 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}
Matt DeVillier80f95b52021-09-13 17:53:05 -050099
100size_t size_of_dnvs(void)
101{
102 return sizeof(struct device_nvs);
103}