blob: e93d0362f4101acb6fadecac1427933f6f0bb24f [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 modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Patrick Georgi2efc8802012-11-06 11:03:53 +010018 */
19
20#include <console/console.h>
21#include <arch/io.h>
22#include <stdint.h>
23#include <device/device.h>
24#include <device/pci.h>
25#include <device/pci_ids.h>
26#include <device/hypertransport.h>
27#include <stdlib.h>
28#include <string.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010029#include <cpu/cpu.h>
30#include <boot/tables.h>
31#include <arch/acpi.h>
32#include <cbmem.h>
33#include "chip.h"
34#include "gm45.h"
Vladimir Serbinenko06667a52014-08-12 09:07:13 +020035#include "arch/acpi.h"
Patrick Georgi2efc8802012-11-06 11:03:53 +010036
Vladimir Serbinenko8c220572014-08-16 14:18:21 +020037/* Reserve segments A and B:
Patrick Georgi2efc8802012-11-06 11:03:53 +010038 *
39 * 0xa0000 - 0xbffff: legacy VGA
Patrick Georgi2efc8802012-11-06 11:03:53 +010040 */
41static const int legacy_hole_base_k = 0xa0000 / 1024;
Vladimir Serbinenko8c220572014-08-16 14:18:21 +020042static const int legacy_hole_size_k = 128;
Patrick Georgi2efc8802012-11-06 11:03:53 +010043
44static int decode_pcie_bar(u32 *const base, u32 *const len)
45{
46 *base = 0;
47 *len = 0;
48
49 const device_t dev = dev_find_slot(0, PCI_DEVFN(0, 0));
50 if (!dev)
51 return 0;
52
53 const u32 pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO);
54
55 if (!(pciexbar_reg & (1 << 0)))
56 return 0;
57
58 switch ((pciexbar_reg >> 1) & 3) {
59 case 0: /* 256MB */
60 *base = pciexbar_reg & (0x0f << 28);
61 *len = 256 * 1024 * 1024;
62 return 1;
63 case 1: /* 128M */
64 *base = pciexbar_reg & (0x1f << 27);
65 *len = 128 * 1024 * 1024;
66 return 1;
67 case 2: /* 64M */
68 *base = pciexbar_reg & (0x3f << 26);
69 *len = 64 * 1024 * 1024;
70 return 1;
71 }
72
73 return 0;
74}
75
76static void mch_domain_read_resources(device_t dev)
77{
78 u64 tom, touud;
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +020079 u32 tomk, tolud, uma_sizek = 0, usable_tomk;
Patrick Georgi2efc8802012-11-06 11:03:53 +010080 u32 pcie_config_base, pcie_config_size;
81
82 /* Total Memory 2GB example:
83 *
84 * 00000000 0000MB-2014MB 2014MB RAM (writeback)
85 * 7de00000 2014MB-2016MB 2MB GFX GTT (uncached)
86 * 7e000000 2016MB-2048MB 32MB GFX UMA (uncached)
87 * 80000000 2048MB TOLUD
88 * 80000000 2048MB TOM
89 *
90 * Total Memory 4GB example:
91 *
92 * 00000000 0000MB-3038MB 3038MB RAM (writeback)
93 * bde00000 3038MB-3040MB 2MB GFX GTT (uncached)
94 * be000000 3040MB-3072MB 32MB GFX UMA (uncached)
95 * be000000 3072MB TOLUD
96 * 100000000 4096MB TOM
97 * 100000000 4096MB-5120MB 1024MB RAM (writeback)
98 * 140000000 5120MB TOUUD
99 */
100
101 pci_domain_read_resources(dev);
102
103 /* Top of Upper Usable DRAM, including remap */
104 touud = pci_read_config16(dev, D0F0_TOUUD);
105 touud <<= 20;
106
107 /* Top of Lower Usable DRAM */
108 tolud = pci_read_config16(dev, D0F0_TOLUD) & 0xfff0;
109 tolud <<= 16;
110
111 /* Top of Memory - does not account for any UMA */
112 tom = pci_read_config16(dev, D0F0_TOM) & 0x1ff;
113 tom <<= 27;
114
115 printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n",
116 touud, tolud, tom);
117
118 tomk = tolud >> 10;
119
120 /* Graphics memory comes next */
121 const u16 ggc = pci_read_config16(dev, D0F0_GGC);
122 if (!(ggc & 2)) {
123 printk(BIOS_DEBUG, "IGD decoded, subtracting ");
124
125 /* Graphics memory */
126 const u32 gms_sizek = decode_igd_memory_size((ggc >> 4) & 0xf);
127 printk(BIOS_DEBUG, "%uM UMA", gms_sizek >> 10);
128 tomk -= gms_sizek;
129
130 /* GTT Graphics Stolen Memory Size (GGMS) */
131 const u32 gsm_sizek = decode_igd_gtt_size((ggc >> 8) & 0xf);
132 printk(BIOS_DEBUG, " and %uM GTT\n", gsm_sizek >> 10);
133 tomk -= gsm_sizek;
134
135 uma_sizek = gms_sizek + gsm_sizek;
136 }
137
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +0200138 usable_tomk = ALIGN_DOWN(tomk, 64 << 10);
139 if (tomk - usable_tomk > (16 << 10))
140 usable_tomk = tomk;
141
142 printk(BIOS_INFO, "Available memory below 4GB: %uM\n", usable_tomk >> 10);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100143
144 /* Report the memory regions */
145 ram_resource(dev, 3, 0, legacy_hole_base_k);
146 ram_resource(dev, 4, legacy_hole_base_k + legacy_hole_size_k,
Vladimir Serbinenko56ae8a02014-08-16 10:59:02 +0200147 (usable_tomk - (legacy_hole_base_k + legacy_hole_size_k)));
Patrick Georgi2efc8802012-11-06 11:03:53 +0100148
149 /*
150 * If >= 4GB installed then memory from TOLUD to 4GB
151 * is remapped above TOM, TOUUD will account for both
152 */
153 touud >>= 10; /* Convert to KB */
154 if (touud > 4096 * 1024) {
155 ram_resource(dev, 5, 4096 * 1024, touud - (4096 * 1024));
156 printk(BIOS_INFO, "Available memory above 4GB: %lluM\n",
157 (touud >> 10) - 4096);
158 }
159
160 printk(BIOS_DEBUG, "Adding UMA memory area base=0x%llx "
161 "size=0x%llx\n", ((u64)tomk) << 10, ((u64)uma_sizek) << 10);
162 /* Don't use uma_resource() as our UMA touches the PCI hole. */
163 fixed_mem_resource(dev, 6, tomk, uma_sizek, IORESOURCE_RESERVE);
164
165 if (decode_pcie_bar(&pcie_config_base, &pcie_config_size)) {
166 printk(BIOS_DEBUG, "Adding PCIe config bar base=0x%08x "
167 "size=0x%x\n", pcie_config_base, pcie_config_size);
168 fixed_mem_resource(dev, 7, pcie_config_base >> 10,
169 pcie_config_size >> 10, IORESOURCE_RESERVE);
170 }
Patrick Georgi2efc8802012-11-06 11:03:53 +0100171}
172
173static void mch_domain_set_resources(device_t dev)
174{
175 struct resource *resource;
176 int i;
177
178 for (i = 3; i < 8; ++i) {
179 /* Report read resources. */
180 resource = find_resource(dev, i);
181 if (resource)
182 report_resource_stored(dev, resource, "");
183 }
184
185 assign_resources(dev->link_list);
186}
187
188static void mch_domain_init(device_t dev)
189{
190 u32 reg32;
191
192 /* Enable SERR */
193 reg32 = pci_read_config32(dev, PCI_COMMAND);
194 reg32 |= PCI_COMMAND_SERR;
195 pci_write_config32(dev, PCI_COMMAND, reg32);
196}
197
198static struct device_operations pci_domain_ops = {
199 .read_resources = mch_domain_read_resources,
200 .set_resources = mch_domain_set_resources,
201 .enable_resources = NULL,
202 .init = mch_domain_init,
203 .scan_bus = pci_domain_scan_bus,
Kyösti Mälkki872c9222013-07-03 09:44:28 +0300204 .ops_pci_bus = pci_bus_default_ops,
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200205 .write_acpi_tables = northbridge_write_acpi_tables,
206 .acpi_fill_ssdt_generator = generate_cpu_entries,
Patrick Georgi2efc8802012-11-06 11:03:53 +0100207};
208
209
210static void cpu_bus_init(device_t dev)
211{
212 initialize_cpus(dev->link_list);
213}
214
215static void cpu_bus_noop(device_t dev)
216{
217}
218
219static struct device_operations cpu_bus_ops = {
220 .read_resources = cpu_bus_noop,
221 .set_resources = cpu_bus_noop,
222 .enable_resources = cpu_bus_noop,
223 .init = cpu_bus_init,
224 .scan_bus = 0,
225};
226
227
228static void enable_dev(device_t dev)
229{
230 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800231 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Patrick Georgi2efc8802012-11-06 11:03:53 +0100232 dev->ops = &pci_domain_ops;
Vladimir Serbinenko79c4ab62014-08-13 23:06:48 +0200233#if CONFIG_HAVE_ACPI_RESUME
234 switch (pci_read_config32(dev_find_slot(0, PCI_DEVFN(0, 0)), /*D0F0_SKPD*/0xdc)) {
235 case SKPAD_NORMAL_BOOT_MAGIC:
236 printk(BIOS_DEBUG, "Normal boot.\n");
237 acpi_slp_type=0;
238 break;
239 case SKPAD_ACPI_S3_MAGIC:
240 printk(BIOS_DEBUG, "S3 Resume.\n");
241 acpi_slp_type=3;
242 break;
243 default:
244 printk(BIOS_DEBUG, "Unknown boot method, assuming normal.\n");
245 acpi_slp_type=0;
246 break;
247 }
248#endif
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800249 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Patrick Georgi2efc8802012-11-06 11:03:53 +0100250 dev->ops = &cpu_bus_ops;
251 }
Patrick Georgi2efc8802012-11-06 11:03:53 +0100252}
253
254static void gm45_init(void *const chip_info)
255{
256 int dev, fn, bit_base;
257
258 struct device *const d0f0 = dev_find_slot(0, 0);
259
260 /* Hide internal functions based on devicetree info. */
261 for (dev = 3; dev > 0; --dev) {
262 switch (dev) {
263 case 3: /* ME */
264 fn = 3;
265 bit_base = 6;
266 break;
267 case 2: /* IGD */
268 fn = 1;
269 bit_base = 3;
270 break;
271 case 1: /* PEG */
272 fn = 0;
273 bit_base = 1;
274 break;
275 }
276 for (; fn >= 0; --fn) {
277 const struct device *const d =
278 dev_find_slot(0, PCI_DEVFN(dev, fn));
279 if (!d || d->enabled) continue;
280 const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN);
281 pci_write_config32(d0f0, D0F0_DEVEN,
282 deven & ~(1 << (bit_base + fn)));
283 }
284 }
285
286 const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN);
287 if (!(deven & (0xf << 6)))
288 pci_write_config32(d0f0, D0F0_DEVEN, deven & ~(1 << 14));
289}
290
291struct chip_operations northbridge_intel_gm45_ops = {
292 CHIP_NAME("Intel GM45 Northbridge")
293 .enable_dev = enable_dev,
294 .init = gm45_init,
295};