blob: daa5aedf1588bb06a45730129bbd7c0de1f43ab0 [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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010018 * Foundation, Inc.
Patrick Georgi2efc8802012-11-06 11:03:53 +010019 */
20
21#include <types.h>
22#include <string.h>
23#include <console/console.h>
24#include <arch/acpi.h>
25#include <arch/acpigen.h>
26#include <device/device.h>
27#include <device/pci.h>
28#include <device/pci_ids.h>
Vladimir Serbinenko33769a52014-08-30 22:39:20 +020029#include <cbmem.h>
30#include <arch/acpigen.h>
31#include <cpu/cpu.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010032#include "gm45.h"
33
34unsigned long acpi_fill_mcfg(unsigned long current)
35{
36 device_t dev;
37 u32 pciexbar = 0;
38 u32 pciexbar_reg;
39 int max_buses;
40
41 dev = dev_find_device(0x8086, 0x2a40, 0);
42 if (!dev)
43 return current;
44
45 pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO);
46
47 // MMCFG not supported or not enabled.
48 if (!(pciexbar_reg & (1 << 0)))
49 return current;
50
51 switch ((pciexbar_reg >> 1) & 3) {
52 case 0: // 256MB
53 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28));
54 max_buses = 256;
55 break;
56 case 1: // 128M
57 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
58 max_buses = 128;
59 break;
60 case 2: // 64M
61 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26));
62 max_buses = 64;
63 break;
64 default: // RSVD
65 return current;
66 }
67
68 if (!pciexbar)
69 return current;
70
71 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current,
72 pciexbar, 0x0, 0x0, max_buses - 1);
73
74 return current;
75}
76
Vladimir Serbinenko8d70e942014-11-09 13:22:27 +010077static unsigned long acpi_fill_dmar(unsigned long current)
Patrick Georgi2efc8802012-11-06 11:03:53 +010078{
79 int me_active = (dev_find_slot(0, PCI_DEVFN(3, 0)) != NULL);
80 int stepping = pci_read_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), PCI_CLASS_REVISION);
81
82 unsigned long tmp = current;
83 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE1);
84 current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x1b, 0);
85 acpi_dmar_drhd_fixup(tmp, current);
86
87 if (stepping != STEPPING_B2) {
88 tmp = current;
89 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE2);
90 current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x2, 0);
91 current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x2, 1);
92 acpi_dmar_drhd_fixup(tmp, current);
93 }
94
95 if (me_active) {
96 tmp = current;
97 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE3);
98 current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x3, 0);
99 current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x3, 1);
100 current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x3, 2);
101 current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x3, 3);
102 acpi_dmar_drhd_fixup(tmp, current);
103 }
104
105 current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, 0, IOMMU_BASE4);
106
107 /* TODO: reserve GTT for 0.2.0 and 0.2.1? */
108 return current;
109}
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200110
111#define ALIGN_CURRENT current = (ALIGN(current, 16))
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200112unsigned long northbridge_write_acpi_tables(device_t device,
113 unsigned long start,
114 struct acpi_rsdp *rsdp)
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200115{
116 unsigned long current;
117#if CONFIG_IOMMU
118 acpi_dmar_t *dmar;
119#endif
120
121 current = start;
122
123#if CONFIG_IOMMU
124 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
125 dmar = (acpi_dmar_t *) current;
Vladimir Serbinenko8d70e942014-11-09 13:22:27 +0100126 acpi_create_dmar(dmar, acpi_fill_dmar);
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200127 current += dmar->header.length;
128 ALIGN_CURRENT;
129 acpi_add_table(rsdp, dmar);
130#endif
131
132 ALIGN_CURRENT;
133
134 printk(BIOS_DEBUG, "current = %lx\n", current);
135
136 return current;
137}