blob: 467c6c195ebb01cb6bdc0be65b1347500c43fc7f [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>
18#include <string.h>
19#include <console/console.h>
20#include <arch/acpi.h>
21#include <arch/acpigen.h>
22#include <device/device.h>
23#include <device/pci.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010024#include "gm45.h"
25
26unsigned long acpi_fill_mcfg(unsigned long current)
27{
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +010028 struct device *dev;
Patrick Georgi2efc8802012-11-06 11:03:53 +010029 u32 pciexbar = 0;
30 u32 pciexbar_reg;
31 int max_buses;
32
33 dev = dev_find_device(0x8086, 0x2a40, 0);
34 if (!dev)
35 return current;
36
37 pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO);
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
Vladimir Serbinenko8d70e942014-11-09 13:22:27 +010069static unsigned long acpi_fill_dmar(unsigned long current)
Patrick Georgi2efc8802012-11-06 11:03:53 +010070{
Damien Zammit88af3722016-08-27 00:35:48 +100071 int me_active = (dev_find_slot(0, PCI_DEVFN(3, 0)) != NULL) &&
72 (pci_read_config8(dev_find_slot(0, PCI_DEVFN(3, 0)), PCI_CLASS_REVISION) != 0xff);
Patrick Georgi2efc8802012-11-06 11:03:53 +010073 int stepping = pci_read_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), PCI_CLASS_REVISION);
74
75 unsigned long tmp = current;
76 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE1);
Matt DeVillier7866d492018-03-29 14:59:57 +020077 current += acpi_create_dmar_ds_pci(current, 0, 0x1b, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010078 acpi_dmar_drhd_fixup(tmp, current);
79
80 if (stepping != STEPPING_B2) {
81 tmp = current;
82 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE2);
Matt DeVillier7866d492018-03-29 14:59:57 +020083 current += acpi_create_dmar_ds_pci(current, 0, 0x2, 0);
84 current += acpi_create_dmar_ds_pci(current, 0, 0x2, 1);
Patrick Georgi2efc8802012-11-06 11:03:53 +010085 acpi_dmar_drhd_fixup(tmp, current);
86 }
87
88 if (me_active) {
89 tmp = current;
90 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE3);
Matt DeVillier7866d492018-03-29 14:59:57 +020091 current += acpi_create_dmar_ds_pci(current, 0, 0x3, 0);
92 current += acpi_create_dmar_ds_pci(current, 0, 0x3, 1);
93 current += acpi_create_dmar_ds_pci(current, 0, 0x3, 2);
94 current += acpi_create_dmar_ds_pci(current, 0, 0x3, 3);
Patrick Georgi2efc8802012-11-06 11:03:53 +010095 acpi_dmar_drhd_fixup(tmp, current);
96 }
97
98 current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, 0, IOMMU_BASE4);
99
100 /* TODO: reserve GTT for 0.2.0 and 0.2.1? */
101 return current;
102}
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200103
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100104unsigned long northbridge_write_acpi_tables(struct device *device,
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200105 unsigned long start,
106 struct acpi_rsdp *rsdp)
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200107{
108 unsigned long current;
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200109 acpi_dmar_t *dmar;
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200110
111 current = start;
112
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200113 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
114 dmar = (acpi_dmar_t *) current;
Nico Hubere561f352015-10-26 11:51:25 +0100115 acpi_create_dmar(dmar, 0, acpi_fill_dmar);
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200116 current += dmar->header.length;
Aaron Durbin07a1b282015-12-10 17:07:38 -0600117 current = acpi_align_current(current);
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200118 acpi_add_table(rsdp, dmar);
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200119
Aaron Durbin07a1b282015-12-10 17:07:38 -0600120 current = acpi_align_current(current);
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200121
122 printk(BIOS_DEBUG, "current = %lx\n", current);
123
124 return current;
125}