blob: 1c01d307b2a7dc6f9f69824f3ecf5002fd8b18cb [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.
Patrick Georgi2efc8802012-11-06 11:03:53 +010014 */
15
Arthur Heymans17ad4592018-08-06 15:35:28 +020016#include <cbmem.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010017#include <console/console.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020018#include <device/pci_ops.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010019#include <stdint.h>
20#include <device/device.h>
21#include <device/pci.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010022#include <stdlib.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010023#include <cpu/cpu.h>
24#include <boot/tables.h>
25#include <arch/acpi.h>
Arthur Heymansaade90e2018-01-25 00:33:45 +010026#include <cpu/intel/smm/gen1/smi.h>
Elyes HAOUASa1e22b82019-03-18 22:49:36 +010027
Patrick Georgi2efc8802012-11-06 11:03:53 +010028#include "chip.h"
29#include "gm45.h"
30
Vladimir Serbinenko8c220572014-08-16 14:18:21 +020031/* Reserve segments A and B:
Patrick Georgi2efc8802012-11-06 11:03:53 +010032 *
33 * 0xa0000 - 0xbffff: legacy VGA
Patrick Georgi2efc8802012-11-06 11:03:53 +010034 */
35static const int legacy_hole_base_k = 0xa0000 / 1024;
Vladimir Serbinenko8c220572014-08-16 14:18:21 +020036static const int legacy_hole_size_k = 128;
Patrick Georgi2efc8802012-11-06 11:03:53 +010037
38static int decode_pcie_bar(u32 *const base, u32 *const len)
39{
40 *base = 0;
41 *len = 0;
42
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030043 struct device *dev = pcidev_on_root(0, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010044 if (!dev)
45 return 0;
46
47 const u32 pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO);
48
49 if (!(pciexbar_reg & (1 << 0)))
50 return 0;
51
52 switch ((pciexbar_reg >> 1) & 3) {
53 case 0: /* 256MB */
54 *base = pciexbar_reg & (0x0f << 28);
55 *len = 256 * 1024 * 1024;
56 return 1;
57 case 1: /* 128M */
58 *base = pciexbar_reg & (0x1f << 27);
59 *len = 128 * 1024 * 1024;
60 return 1;
61 case 2: /* 64M */
62 *base = pciexbar_reg & (0x3f << 26);
63 *len = 64 * 1024 * 1024;
64 return 1;
65 }
66
67 return 0;
68}
69
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +010070static void mch_domain_read_resources(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +010071{
72 u64 tom, touud;
Arthur Heymans17ad4592018-08-06 15:35:28 +020073 u32 tomk, tolud, uma_sizek = 0, delta_cbmem;
Patrick Georgi2efc8802012-11-06 11:03:53 +010074 u32 pcie_config_base, pcie_config_size;
75
76 /* Total Memory 2GB example:
77 *
78 * 00000000 0000MB-2014MB 2014MB RAM (writeback)
79 * 7de00000 2014MB-2016MB 2MB GFX GTT (uncached)
80 * 7e000000 2016MB-2048MB 32MB GFX UMA (uncached)
81 * 80000000 2048MB TOLUD
82 * 80000000 2048MB TOM
83 *
84 * Total Memory 4GB example:
85 *
86 * 00000000 0000MB-3038MB 3038MB RAM (writeback)
87 * bde00000 3038MB-3040MB 2MB GFX GTT (uncached)
88 * be000000 3040MB-3072MB 32MB GFX UMA (uncached)
89 * be000000 3072MB TOLUD
90 * 100000000 4096MB TOM
91 * 100000000 4096MB-5120MB 1024MB RAM (writeback)
92 * 140000000 5120MB TOUUD
93 */
94
95 pci_domain_read_resources(dev);
96
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030097 struct device *mch = pcidev_on_root(0, 0);
Arthur Heymans89089312018-06-26 21:01:40 +020098
Patrick Georgi2efc8802012-11-06 11:03:53 +010099 /* Top of Upper Usable DRAM, including remap */
Arthur Heymans89089312018-06-26 21:01:40 +0200100 touud = pci_read_config16(mch, D0F0_TOUUD);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100101 touud <<= 20;
102
103 /* Top of Lower Usable DRAM */
Arthur Heymans89089312018-06-26 21:01:40 +0200104 tolud = pci_read_config16(mch, D0F0_TOLUD) & 0xfff0;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100105 tolud <<= 16;
106
107 /* Top of Memory - does not account for any UMA */
Arthur Heymans89089312018-06-26 21:01:40 +0200108 tom = pci_read_config16(mch, D0F0_TOM) & 0x1ff;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100109 tom <<= 27;
110
111 printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n",
112 touud, tolud, tom);
113
114 tomk = tolud >> 10;
115
116 /* Graphics memory comes next */
Arthur Heymans89089312018-06-26 21:01:40 +0200117 const u16 ggc = pci_read_config16(mch, D0F0_GGC);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100118 if (!(ggc & 2)) {
119 printk(BIOS_DEBUG, "IGD decoded, subtracting ");
120
121 /* Graphics memory */
122 const u32 gms_sizek = decode_igd_memory_size((ggc >> 4) & 0xf);
Arthur Heymans8b766052018-01-24 23:25:13 +0100123 printk(BIOS_DEBUG, "%uM UMA, ", gms_sizek >> 10);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100124 tomk -= gms_sizek;
125
126 /* GTT Graphics Stolen Memory Size (GGMS) */
127 const u32 gsm_sizek = decode_igd_gtt_size((ggc >> 8) & 0xf);
Arthur Heymans8b766052018-01-24 23:25:13 +0100128 printk(BIOS_DEBUG, "%uM GTT", gsm_sizek >> 10);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100129 tomk -= gsm_sizek;
130
131 uma_sizek = gms_sizek + gsm_sizek;
132 }
Arthur Heymans89089312018-06-26 21:01:40 +0200133 const u8 esmramc = pci_read_config8(mch, D0F0_ESMRAMC);
Arthur Heymans8b766052018-01-24 23:25:13 +0100134 const u32 tseg_sizek = decode_tseg_size(esmramc);
135 printk(BIOS_DEBUG, " and %uM TSEG\n", tseg_sizek >> 10);
136 tomk -= tseg_sizek;
137 uma_sizek += tseg_sizek;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100138
Arthur Heymans17ad4592018-08-06 15:35:28 +0200139 /* cbmem_top can be shifted downwards due to alignment.
140 Mark the region between cbmem_top and tomk as unusable */
141 delta_cbmem = tomk - ((uint32_t)cbmem_top() >> 10);
142 tomk -= delta_cbmem;
143 uma_sizek += delta_cbmem;
144
145 printk(BIOS_DEBUG, "Unused RAM between cbmem_top and TOM: 0x%xK\n",
146 delta_cbmem);
147
Nico Huberca3e1212017-10-02 20:07:53 +0200148 printk(BIOS_INFO, "Available memory below 4GB: %uM\n", tomk >> 10);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100149
150 /* Report the memory regions */
151 ram_resource(dev, 3, 0, legacy_hole_base_k);
152 ram_resource(dev, 4, legacy_hole_base_k + legacy_hole_size_k,
Nico Huberca3e1212017-10-02 20:07:53 +0200153 (tomk - (legacy_hole_base_k + legacy_hole_size_k)));
Patrick Georgi2efc8802012-11-06 11:03:53 +0100154
155 /*
156 * If >= 4GB installed then memory from TOLUD to 4GB
157 * is remapped above TOM, TOUUD will account for both
158 */
159 touud >>= 10; /* Convert to KB */
160 if (touud > 4096 * 1024) {
161 ram_resource(dev, 5, 4096 * 1024, touud - (4096 * 1024));
162 printk(BIOS_INFO, "Available memory above 4GB: %lluM\n",
163 (touud >> 10) - 4096);
164 }
165
166 printk(BIOS_DEBUG, "Adding UMA memory area base=0x%llx "
167 "size=0x%llx\n", ((u64)tomk) << 10, ((u64)uma_sizek) << 10);
168 /* Don't use uma_resource() as our UMA touches the PCI hole. */
169 fixed_mem_resource(dev, 6, tomk, uma_sizek, IORESOURCE_RESERVE);
170
171 if (decode_pcie_bar(&pcie_config_base, &pcie_config_size)) {
172 printk(BIOS_DEBUG, "Adding PCIe config bar base=0x%08x "
173 "size=0x%x\n", pcie_config_base, pcie_config_size);
174 fixed_mem_resource(dev, 7, pcie_config_base >> 10,
175 pcie_config_size >> 10, IORESOURCE_RESERVE);
176 }
Patrick Georgi2efc8802012-11-06 11:03:53 +0100177}
178
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100179static void mch_domain_set_resources(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100180{
181 struct resource *resource;
182 int i;
183
184 for (i = 3; i < 8; ++i) {
185 /* Report read resources. */
Vladimir Serbinenko40412c62014-11-12 00:09:20 +0100186 resource = probe_resource(dev, i);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100187 if (resource)
188 report_resource_stored(dev, resource, "");
189 }
190
191 assign_resources(dev->link_list);
192}
193
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100194static void mch_domain_init(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100195{
196 u32 reg32;
197
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300198 struct device *mch = pcidev_on_root(0, 0);
Arthur Heymans89089312018-06-26 21:01:40 +0200199
Patrick Georgi2efc8802012-11-06 11:03:53 +0100200 /* Enable SERR */
Arthur Heymans89089312018-06-26 21:01:40 +0200201 reg32 = pci_read_config32(mch, PCI_COMMAND);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100202 reg32 |= PCI_COMMAND_SERR;
Arthur Heymans89089312018-06-26 21:01:40 +0200203 pci_write_config32(mch, PCI_COMMAND, reg32);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100204}
205
Arthur Heymanse798e6a2017-12-23 23:09:54 +0100206static const char *northbridge_acpi_name(const struct device *dev)
207{
208 if (dev->path.type == DEVICE_PATH_DOMAIN)
209 return "PCI0";
210
211 if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0)
212 return NULL;
213
214 switch (dev->path.pci.devfn) {
215 case PCI_DEVFN(0, 0):
216 return "MCHC";
217 }
218
219 return NULL;
220}
221
Arthur Heymansaade90e2018-01-25 00:33:45 +0100222void northbridge_write_smram(u8 smram)
223{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300224 struct device *dev = pcidev_on_root(0, 0);
Arthur Heymans48fa9222018-11-19 13:08:01 +0100225
226 if (dev == NULL)
227 die("could not find pci 00:00.0!\n");
228
229 pci_write_config8(dev, D0F0_SMRAM, smram);
Arthur Heymansaade90e2018-01-25 00:33:45 +0100230}
231
Patrick Georgi2efc8802012-11-06 11:03:53 +0100232static struct device_operations pci_domain_ops = {
233 .read_resources = mch_domain_read_resources,
234 .set_resources = mch_domain_set_resources,
235 .enable_resources = NULL,
236 .init = mch_domain_init,
237 .scan_bus = pci_domain_scan_bus,
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200238 .write_acpi_tables = northbridge_write_acpi_tables,
239 .acpi_fill_ssdt_generator = generate_cpu_entries,
Arthur Heymanse798e6a2017-12-23 23:09:54 +0100240 .acpi_name = northbridge_acpi_name,
Patrick Georgi2efc8802012-11-06 11:03:53 +0100241};
242
Patrick Georgi2efc8802012-11-06 11:03:53 +0100243static struct device_operations cpu_bus_ops = {
Edward O'Callaghan9f744622014-10-31 08:12:34 +1100244 .read_resources = DEVICE_NOOP,
245 .set_resources = DEVICE_NOOP,
246 .enable_resources = DEVICE_NOOP,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300247 .init = mp_cpu_bus_init,
Patrick Georgi2efc8802012-11-06 11:03:53 +0100248 .scan_bus = 0,
249};
250
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100251static void enable_dev(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100252{
253 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800254 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Patrick Georgi2efc8802012-11-06 11:03:53 +0100255 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800256 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Patrick Georgi2efc8802012-11-06 11:03:53 +0100257 dev->ops = &cpu_bus_ops;
258 }
Patrick Georgi2efc8802012-11-06 11:03:53 +0100259}
260
261static void gm45_init(void *const chip_info)
262{
263 int dev, fn, bit_base;
264
Kyösti Mälkki98a91742018-05-21 21:29:16 +0300265 struct device *const d0f0 = pcidev_on_root(0x0, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100266
267 /* Hide internal functions based on devicetree info. */
268 for (dev = 3; dev > 0; --dev) {
269 switch (dev) {
270 case 3: /* ME */
271 fn = 3;
272 bit_base = 6;
273 break;
274 case 2: /* IGD */
275 fn = 1;
276 bit_base = 3;
277 break;
278 case 1: /* PEG */
279 fn = 0;
280 bit_base = 1;
281 break;
282 }
283 for (; fn >= 0; --fn) {
284 const struct device *const d =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300285 pcidev_on_root(dev, fn);
Nico Huber2dc15e92016-02-04 18:59:48 +0100286 if (!d || d->enabled) continue;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100287 const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN);
288 pci_write_config32(d0f0, D0F0_DEVEN,
289 deven & ~(1 << (bit_base + fn)));
290 }
291 }
292
293 const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN);
294 if (!(deven & (0xf << 6)))
295 pci_write_config32(d0f0, D0F0_DEVEN, deven & ~(1 << 14));
296}
297
298struct chip_operations northbridge_intel_gm45_ops = {
299 CHIP_NAME("Intel GM45 Northbridge")
300 .enable_dev = enable_dev,
301 .init = gm45_init,
302};