blob: c2743189fb1c982e0ded2eac2625fc49a0f068f3 [file] [log] [blame]
Stefan Reinauer00636b02012-04-04 00:08:51 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2009 coresystems GmbH
Stefan Reinauere5a0a5d2012-09-19 10:51:48 -07005 * Copyright (C) 2012 The Chromium OS Authors
Stefan Reinauer00636b02012-04-04 00:08:51 +02006 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Stefan Reinauer00636b02012-04-04 00:08:51 +020016 */
17
18#include <types.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020019#include <console/console.h>
Nico Huberb3234742018-11-17 14:09:25 +010020#include <commonlib/helpers.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020021#include <arch/acpi.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020022#include <device/device.h>
23#include <device/pci.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020024#include "sandybridge.h"
Nico Huber9d9ce0d2015-10-26 12:59:49 +010025#include <southbridge/intel/bd82x6x/pch.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020026
27unsigned long acpi_fill_mcfg(unsigned long current)
28{
Stefan Reinauer00636b02012-04-04 00:08:51 +020029 u32 pciexbar = 0;
30 u32 pciexbar_reg;
31 int max_buses;
32
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030033 struct device *const dev = pcidev_on_root(0, 0);
Vagiz Trakhanove200c1c2017-09-28 15:01:06 +000034
Stefan Reinauer00636b02012-04-04 00:08:51 +020035 if (!dev)
36 return current;
37
38 pciexbar_reg=pci_read_config32(dev, PCIEXBAR);
39
40 // MMCFG not supported or not enabled.
41 if (!(pciexbar_reg & (1 << 0)))
42 return current;
43
44 switch ((pciexbar_reg >> 1) & 3) {
45 case 0: // 256MB
46 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28));
47 max_buses = 256;
48 break;
49 case 1: // 128M
50 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
51 max_buses = 128;
52 break;
53 case 2: // 64M
54 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26));
55 max_buses = 64;
56 break;
57 default: // RSVD
58 return current;
59 }
60
61 if (!pciexbar)
62 return current;
63
64 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current,
65 pciexbar, 0x0, 0x0, max_buses - 1);
66
67 return current;
68}
69
Nico Huberb3234742018-11-17 14:09:25 +010070static unsigned long acpi_create_igfx_rmrr(const unsigned long current)
71{
72 const u32 base_mask = ~(u32)(MiB - 1);
73
Kyösti Mälkki19bad302019-02-08 18:42:19 +020074 struct device *const host = pcidev_on_root(0, 0);
Nico Huberb3234742018-11-17 14:09:25 +010075 if (!host)
76 return 0;
77
78 const u32 bgsm = pci_read_config32(host, BGSM) & base_mask;
79 const u32 tolud = pci_read_config32(host, TOLUD) & base_mask;
80 if (!bgsm || !tolud)
81 return 0;
82
83 return acpi_create_dmar_rmrr(current, 0, bgsm, tolud - 1);
84}
85
Nico Huber9d9ce0d2015-10-26 12:59:49 +010086static unsigned long acpi_fill_dmar(unsigned long current)
87{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030088 const struct device *const igfx = pcidev_on_root(2, 0);
Nico Huber9d9ce0d2015-10-26 12:59:49 +010089
90 if (igfx && igfx->enabled) {
Nico Huberb3234742018-11-17 14:09:25 +010091 unsigned long tmp;
92
93 tmp = current;
Nico Huber9d9ce0d2015-10-26 12:59:49 +010094 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE1);
Matt DeVillier7866d492018-03-29 14:59:57 +020095 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
96 current += acpi_create_dmar_ds_pci(current, 0, 2, 1);
Nico Huber9d9ce0d2015-10-26 12:59:49 +010097 acpi_dmar_drhd_fixup(tmp, current);
Nico Huberb3234742018-11-17 14:09:25 +010098
99 tmp = current;
100 current += acpi_create_igfx_rmrr(current);
101 if (current != tmp) {
102 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
103 current += acpi_create_dmar_ds_pci(current, 0, 2, 1);
104 acpi_dmar_rmrr_fixup(tmp, current);
105 }
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100106 }
107
108 const unsigned long tmp = current;
109 current += acpi_create_dmar_drhd(current,
110 DRHD_INCLUDE_PCI_ALL, 0, IOMMU_BASE2);
Matt DeVillier7866d492018-03-29 14:59:57 +0200111 current += acpi_create_dmar_ds_ioapic(current,
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100112 2, PCH_IOAPIC_PCI_BUS, PCH_IOAPIC_PCI_SLOT, 0);
113 size_t i;
114 for (i = 0; i < 8; ++i)
Matt DeVillier7866d492018-03-29 14:59:57 +0200115 current += acpi_create_dmar_ds_msi_hpet(current,
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100116 0, PCH_HPET_PCI_BUS, PCH_HPET_PCI_SLOT, i);
117 acpi_dmar_drhd_fixup(tmp, current);
118
119 return current;
120}
121
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100122unsigned long northbridge_write_acpi_tables(struct device *const dev,
123 unsigned long current,
124 struct acpi_rsdp *const rsdp)
125{
126 const u32 capid0_a = pci_read_config32(dev, 0xe4);
127 if (capid0_a & (1 << 23))
128 return current;
129
130 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
131 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
132 acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar);
133 current += dmar->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -0600134 current = acpi_align_current(current);
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100135 acpi_add_table(rsdp, dmar);
136
Aaron Durbin07a1b282015-12-10 17:07:38 -0600137 current = acpi_align_current(current);
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100138
139 printk(BIOS_DEBUG, "current = %lx\n", current);
140
141 return current;
142}