blob: c7914a0a45f389560ecbdd6ac2f990c7e6928f8f [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>
20#include <arch/acpi.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020021#include <device/device.h>
22#include <device/pci.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020023#include "sandybridge.h"
Nico Huber9d9ce0d2015-10-26 12:59:49 +010024#include <southbridge/intel/bd82x6x/pch.h>
Stefan Reinauer00636b02012-04-04 00:08:51 +020025
26unsigned long acpi_fill_mcfg(unsigned long current)
27{
Stefan Reinauer00636b02012-04-04 00:08:51 +020028 u32 pciexbar = 0;
29 u32 pciexbar_reg;
30 int max_buses;
31
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030032 struct device *const dev = pcidev_on_root(0, 0);
Vagiz Trakhanove200c1c2017-09-28 15:01:06 +000033
Stefan Reinauer00636b02012-04-04 00:08:51 +020034 if (!dev)
35 return current;
36
37 pciexbar_reg=pci_read_config32(dev, PCIEXBAR);
38
39 // MMCFG not supported or not enabled.
40 if (!(pciexbar_reg & (1 << 0)))
41 return current;
42
43 switch ((pciexbar_reg >> 1) & 3) {
44 case 0: // 256MB
45 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28));
46 max_buses = 256;
47 break;
48 case 1: // 128M
49 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
50 max_buses = 128;
51 break;
52 case 2: // 64M
53 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26));
54 max_buses = 64;
55 break;
56 default: // RSVD
57 return current;
58 }
59
60 if (!pciexbar)
61 return current;
62
63 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current,
64 pciexbar, 0x0, 0x0, max_buses - 1);
65
66 return current;
67}
68
Nico Huber9d9ce0d2015-10-26 12:59:49 +010069static unsigned long acpi_fill_dmar(unsigned long current)
70{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030071 const struct device *const igfx = pcidev_on_root(2, 0);
Nico Huber9d9ce0d2015-10-26 12:59:49 +010072
73 if (igfx && igfx->enabled) {
74 const unsigned long tmp = current;
75 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE1);
Matt DeVillier7866d492018-03-29 14:59:57 +020076 current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
77 current += acpi_create_dmar_ds_pci(current, 0, 2, 1);
Nico Huber9d9ce0d2015-10-26 12:59:49 +010078 acpi_dmar_drhd_fixup(tmp, current);
79 }
80
81 const unsigned long tmp = current;
82 current += acpi_create_dmar_drhd(current,
83 DRHD_INCLUDE_PCI_ALL, 0, IOMMU_BASE2);
Matt DeVillier7866d492018-03-29 14:59:57 +020084 current += acpi_create_dmar_ds_ioapic(current,
Nico Huber9d9ce0d2015-10-26 12:59:49 +010085 2, PCH_IOAPIC_PCI_BUS, PCH_IOAPIC_PCI_SLOT, 0);
86 size_t i;
87 for (i = 0; i < 8; ++i)
Matt DeVillier7866d492018-03-29 14:59:57 +020088 current += acpi_create_dmar_ds_msi_hpet(current,
Nico Huber9d9ce0d2015-10-26 12:59:49 +010089 0, PCH_HPET_PCI_BUS, PCH_HPET_PCI_SLOT, i);
90 acpi_dmar_drhd_fixup(tmp, current);
91
92 return current;
93}
94
Nico Huber9d9ce0d2015-10-26 12:59:49 +010095unsigned long northbridge_write_acpi_tables(struct device *const dev,
96 unsigned long current,
97 struct acpi_rsdp *const rsdp)
98{
99 const u32 capid0_a = pci_read_config32(dev, 0xe4);
100 if (capid0_a & (1 << 23))
101 return current;
102
103 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
104 acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
105 acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar);
106 current += dmar->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -0600107 current = acpi_align_current(current);
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100108 acpi_add_table(rsdp, dmar);
109
Aaron Durbin07a1b282015-12-10 17:07:38 -0600110 current = acpi_align_current(current);
Nico Huber9d9ce0d2015-10-26 12:59:49 +0100111
112 printk(BIOS_DEBUG, "current = %lx\n", current);
113
114 return current;
115}