blob: 074e9413fabfdb6491a4d0df4688bf872be2c22b [file] [log] [blame]
Stefan Reinauer00636b02012-04-04 00:08:51 +02001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer00636b02012-04-04 00:08:51 +02004 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; version 2 of
8 * the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Stefan Reinauer00636b02012-04-04 00:08:51 +020014 */
15
16#include <types.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020017#include <console/console.h>
Nico Huberb3234742018-11-17 14:09:25 +010018#include <commonlib/helpers.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020019#include <arch/acpi.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020020#include <device/device.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020021#include <device/pci_ops.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020022#include "sandybridge.h"
Nico Huber9d9ce0d2015-10-26 12:59:49 +010023#include <southbridge/intel/bd82x6x/pch.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020024
25unsigned long acpi_fill_mcfg(unsigned long current)
26{
Stefan Reinauer00636b02012-04-04 00:08:51 +020027 u32 pciexbar = 0;
28 u32 pciexbar_reg;
29 int max_buses;
30
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030031 struct device *const dev = pcidev_on_root(0, 0);
Vagiz Trakhanove200c1c2017-09-28 15:01:06 +000032
Stefan Reinauer00636b02012-04-04 00:08:51 +020033 if (!dev)
34 return current;
35
36 pciexbar_reg=pci_read_config32(dev, PCIEXBAR);
37
38 // MMCFG not supported or not enabled.
39 if (!(pciexbar_reg & (1 << 0)))
40 return current;
41
42 switch ((pciexbar_reg >> 1) & 3) {
43 case 0: // 256MB
44 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28));
45 max_buses = 256;
46 break;
47 case 1: // 128M
48 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
49 max_buses = 128;
50 break;
51 case 2: // 64M
52 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26));
53 max_buses = 64;
54 break;
55 default: // RSVD
56 return current;
57 }
58
59 if (!pciexbar)
60 return current;
61
62 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current,
63 pciexbar, 0x0, 0x0, max_buses - 1);
64
65 return current;
66}
67
Nico Huberb3234742018-11-17 14:09:25 +010068static unsigned long acpi_create_igfx_rmrr(const unsigned long current)
69{
70 const u32 base_mask = ~(u32)(MiB - 1);
71
Kyösti Mälkki19bad302019-02-08 18:42:19 +020072 struct device *const host = pcidev_on_root(0, 0);
Nico Huberb3234742018-11-17 14:09:25 +010073 if (!host)
74 return 0;
75
76 const u32 bgsm = pci_read_config32(host, BGSM) & base_mask;
77 const u32 tolud = pci_read_config32(host, TOLUD) & base_mask;
78 if (!bgsm || !tolud)
79 return 0;
80
81 return acpi_create_dmar_rmrr(current, 0, bgsm, tolud - 1);
82}
83
Nico Huber9d9ce0d2015-10-26 12:59:49 +010084static unsigned long acpi_fill_dmar(unsigned long current)
85{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030086 const struct device *const igfx = pcidev_on_root(2, 0);
Nico Huber9d9ce0d2015-10-26 12:59:49 +010087
88 if (igfx && igfx->enabled) {
Nico Huberb3234742018-11-17 14:09:25 +010089 unsigned long tmp;
90
91 tmp = current;
Nico Huber9d9ce0d2015-10-26 12:59:49 +010092 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE1);
Matt DeVillier7866d492018-03-29 14:59:57 +020093 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
94 current += acpi_create_dmar_ds_pci(current, 0, 2, 1);
Nico Huber9d9ce0d2015-10-26 12:59:49 +010095 acpi_dmar_drhd_fixup(tmp, current);
Nico Huberb3234742018-11-17 14:09:25 +010096
97 tmp = current;
98 current += acpi_create_igfx_rmrr(current);
99 if (current != tmp) {
100 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
101 current += acpi_create_dmar_ds_pci(current, 0, 2, 1);
102 acpi_dmar_rmrr_fixup(tmp, current);
103 }
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100104 }
105
106 const unsigned long tmp = current;
107 current += acpi_create_dmar_drhd(current,
108 DRHD_INCLUDE_PCI_ALL, 0, IOMMU_BASE2);
Matt DeVillier7866d492018-03-29 14:59:57 +0200109 current += acpi_create_dmar_ds_ioapic(current,
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100110 2, PCH_IOAPIC_PCI_BUS, PCH_IOAPIC_PCI_SLOT, 0);
111 size_t i;
112 for (i = 0; i < 8; ++i)
Matt DeVillier7866d492018-03-29 14:59:57 +0200113 current += acpi_create_dmar_ds_msi_hpet(current,
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100114 0, PCH_HPET_PCI_BUS, PCH_HPET_PCI_SLOT, i);
115 acpi_dmar_drhd_fixup(tmp, current);
116
117 return current;
118}
119
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100120unsigned long northbridge_write_acpi_tables(struct device *const dev,
121 unsigned long current,
122 struct acpi_rsdp *const rsdp)
123{
124 const u32 capid0_a = pci_read_config32(dev, 0xe4);
125 if (capid0_a & (1 << 23))
126 return current;
127
128 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
129 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
130 acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar);
131 current += dmar->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -0600132 current = acpi_align_current(current);
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100133 acpi_add_table(rsdp, dmar);
134
Aaron Durbin07a1b282015-12-10 17:07:38 -0600135 current = acpi_align_current(current);
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100136
137 printk(BIOS_DEBUG, "current = %lx\n", current);
138
139 return current;
140}