blob: ef152db213e39f066a51e21e4a38058963c13d4b [file] [log] [blame]
Patrick Georgi2efc8802012-11-06 11:03:53 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2009 coresystems GmbH
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Patrick Georgi2efc8802012-11-06 11:03:53 +010015 */
16
17#include <types.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010018#include <console/console.h>
19#include <arch/acpi.h>
20#include <arch/acpigen.h>
21#include <device/device.h>
22#include <device/pci.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020023#include <device/pci_ops.h>
Elyes HAOUASa1e22b82019-03-18 22:49:36 +010024
Patrick Georgi2efc8802012-11-06 11:03:53 +010025#include "gm45.h"
26
27unsigned long acpi_fill_mcfg(unsigned long current)
28{
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +010029 struct device *dev;
Patrick Georgi2efc8802012-11-06 11:03:53 +010030 u32 pciexbar = 0;
31 u32 pciexbar_reg;
32 int max_buses;
33
34 dev = dev_find_device(0x8086, 0x2a40, 0);
35 if (!dev)
36 return current;
37
38 pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO);
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
Vladimir Serbinenko8d70e942014-11-09 13:22:27 +010070static unsigned long acpi_fill_dmar(unsigned long current)
Patrick Georgi2efc8802012-11-06 11:03:53 +010071{
Arthur Heymans15063e82019-08-12 09:41:42 +020072 const struct device *dev;
73
74 dev = pcidev_on_root(3, 0);
75 int me_active = dev && dev->enabled;
76
Arthur Heymans08456362019-08-12 09:21:30 +020077 dev = pcidev_on_root(2, 0);
78 int igd_active = dev && dev->enabled;
79
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030080 int stepping = pci_read_config8(pcidev_on_root(0, 0),
81 PCI_CLASS_REVISION);
Patrick Georgi2efc8802012-11-06 11:03:53 +010082
83 unsigned long tmp = current;
84 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE1);
Matt DeVillier7866d492018-03-29 14:59:57 +020085 current += acpi_create_dmar_ds_pci(current, 0, 0x1b, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010086 acpi_dmar_drhd_fixup(tmp, current);
87
Arthur Heymans08456362019-08-12 09:21:30 +020088 if (stepping != STEPPING_B2 && igd_active) {
Patrick Georgi2efc8802012-11-06 11:03:53 +010089 tmp = current;
90 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE2);
Matt DeVillier7866d492018-03-29 14:59:57 +020091 current += acpi_create_dmar_ds_pci(current, 0, 0x2, 0);
92 current += acpi_create_dmar_ds_pci(current, 0, 0x2, 1);
Patrick Georgi2efc8802012-11-06 11:03:53 +010093 acpi_dmar_drhd_fixup(tmp, current);
94 }
95
96 if (me_active) {
97 tmp = current;
98 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE3);
Matt DeVillier7866d492018-03-29 14:59:57 +020099 current += acpi_create_dmar_ds_pci(current, 0, 0x3, 0);
100 current += acpi_create_dmar_ds_pci(current, 0, 0x3, 1);
101 current += acpi_create_dmar_ds_pci(current, 0, 0x3, 2);
102 current += acpi_create_dmar_ds_pci(current, 0, 0x3, 3);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100103 acpi_dmar_drhd_fixup(tmp, current);
104 }
105
106 current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, 0, IOMMU_BASE4);
107
108 /* TODO: reserve GTT for 0.2.0 and 0.2.1? */
109 return current;
110}
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200111
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100112unsigned long northbridge_write_acpi_tables(struct device *device,
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200113 unsigned long start,
114 struct acpi_rsdp *rsdp)
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200115{
116 unsigned long current;
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200117 acpi_dmar_t *dmar;
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200118
119 current = start;
120
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200121 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
122 dmar = (acpi_dmar_t *) current;
Nico Hubere561f352015-10-26 11:51:25 +0100123 acpi_create_dmar(dmar, 0, acpi_fill_dmar);
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200124 current += dmar->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -0600125 current = acpi_align_current(current);
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200126 acpi_add_table(rsdp, dmar);
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200127
Aaron Durbin07a1b282015-12-10 17:07:38 -0600128 current = acpi_align_current(current);
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200129
130 printk(BIOS_DEBUG, "current = %lx\n", current);
131
132 return current;
133}