blob: 445995a91bc7703accce1f30486550811eadd406 [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
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
22#include <types.h>
23#include <string.h>
24#include <console/console.h>
25#include <arch/acpi.h>
26#include <arch/acpigen.h>
27#include <device/device.h>
28#include <device/pci.h>
29#include <device/pci_ids.h>
Vladimir Serbinenko33769a52014-08-30 22:39:20 +020030#include <cbmem.h>
31#include <arch/acpigen.h>
32#include <cpu/cpu.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010033#include "gm45.h"
34
35unsigned long acpi_fill_mcfg(unsigned long current)
36{
37 device_t dev;
38 u32 pciexbar = 0;
39 u32 pciexbar_reg;
40 int max_buses;
41
42 dev = dev_find_device(0x8086, 0x2a40, 0);
43 if (!dev)
44 return current;
45
46 pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO);
47
48 // MMCFG not supported or not enabled.
49 if (!(pciexbar_reg & (1 << 0)))
50 return current;
51
52 switch ((pciexbar_reg >> 1) & 3) {
53 case 0: // 256MB
54 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28));
55 max_buses = 256;
56 break;
57 case 1: // 128M
58 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
59 max_buses = 128;
60 break;
61 case 2: // 64M
62 pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26));
63 max_buses = 64;
64 break;
65 default: // RSVD
66 return current;
67 }
68
69 if (!pciexbar)
70 return current;
71
72 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current,
73 pciexbar, 0x0, 0x0, max_buses - 1);
74
75 return current;
76}
77
78unsigned long acpi_fill_dmar(unsigned long current)
79{
80 int me_active = (dev_find_slot(0, PCI_DEVFN(3, 0)) != NULL);
81 int stepping = pci_read_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), PCI_CLASS_REVISION);
82
83 unsigned long tmp = current;
84 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE1);
85 current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x1b, 0);
86 acpi_dmar_drhd_fixup(tmp, current);
87
88 if (stepping != STEPPING_B2) {
89 tmp = current;
90 current += acpi_create_dmar_drhd(current, 0, 0, IOMMU_BASE2);
91 current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x2, 0);
92 current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x2, 1);
93 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);
99 current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x3, 0);
100 current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x3, 1);
101 current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x3, 2);
102 current += acpi_create_dmar_drhd_ds_pci(current, 0, 0x3, 3);
103 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
112#define ALIGN_CURRENT current = (ALIGN(current, 16))
113unsigned long northbridge_write_acpi_tables(unsigned long start, struct acpi_rsdp *rsdp)
114{
115 unsigned long current;
116#if CONFIG_IOMMU
117 acpi_dmar_t *dmar;
118#endif
119
120 current = start;
121
122#if CONFIG_IOMMU
123 printk(BIOS_DEBUG, "ACPI: * DMAR\n");
124 dmar = (acpi_dmar_t *) current;
125 acpi_create_dmar(dmar);
126 current += dmar->header.length;
127 ALIGN_CURRENT;
128 acpi_add_table(rsdp, dmar);
129#endif
130
131 ALIGN_CURRENT;
132
133 printk(BIOS_DEBUG, "current = %lx\n", current);
134
135 return current;
136}