blob: 9484cd9fab10ce17ce55200ebd2ef65dcb07e5d9 [file] [log] [blame]
Patrick Georgi2efc8802012-11-06 11:03:53 +01001/*
2 * This file is part of the coreboot project.
3 *
Patrick Georgi2efc8802012-11-06 11:03:53 +01004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Patrick Georgi2efc8802012-11-06 11:03:53 +010013 */
14
Arthur Heymans17ad4592018-08-06 15:35:28 +020015#include <cbmem.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010016#include <console/console.h>
Elyes HAOUAS748caed2019-12-19 17:02:08 +010017#include <device/pci_def.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>
Patrick Georgi2efc8802012-11-06 11:03:53 +010021#include <boot/tables.h>
22#include <arch/acpi.h>
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030023#include <cpu/intel/smm_reloc.h>
Elyes HAOUASa1e22b82019-03-18 22:49:36 +010024
Patrick Georgi2efc8802012-11-06 11:03:53 +010025#include "chip.h"
26#include "gm45.h"
27
Vladimir Serbinenko8c220572014-08-16 14:18:21 +020028/* Reserve segments A and B:
Patrick Georgi2efc8802012-11-06 11:03:53 +010029 *
30 * 0xa0000 - 0xbffff: legacy VGA
Patrick Georgi2efc8802012-11-06 11:03:53 +010031 */
32static const int legacy_hole_base_k = 0xa0000 / 1024;
Vladimir Serbinenko8c220572014-08-16 14:18:21 +020033static const int legacy_hole_size_k = 128;
Patrick Georgi2efc8802012-11-06 11:03:53 +010034
35static int decode_pcie_bar(u32 *const base, u32 *const len)
36{
37 *base = 0;
38 *len = 0;
39
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030040 struct device *dev = pcidev_on_root(0, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010041 if (!dev)
42 return 0;
43
44 const u32 pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO);
45
46 if (!(pciexbar_reg & (1 << 0)))
47 return 0;
48
49 switch ((pciexbar_reg >> 1) & 3) {
50 case 0: /* 256MB */
51 *base = pciexbar_reg & (0x0f << 28);
52 *len = 256 * 1024 * 1024;
53 return 1;
54 case 1: /* 128M */
55 *base = pciexbar_reg & (0x1f << 27);
56 *len = 128 * 1024 * 1024;
57 return 1;
58 case 2: /* 64M */
59 *base = pciexbar_reg & (0x3f << 26);
60 *len = 64 * 1024 * 1024;
61 return 1;
62 }
63
64 return 0;
65}
66
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +010067static void mch_domain_read_resources(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +010068{
69 u64 tom, touud;
Arthur Heymans17ad4592018-08-06 15:35:28 +020070 u32 tomk, tolud, uma_sizek = 0, delta_cbmem;
Patrick Georgi2efc8802012-11-06 11:03:53 +010071 u32 pcie_config_base, pcie_config_size;
72
73 /* Total Memory 2GB example:
74 *
75 * 00000000 0000MB-2014MB 2014MB RAM (writeback)
76 * 7de00000 2014MB-2016MB 2MB GFX GTT (uncached)
77 * 7e000000 2016MB-2048MB 32MB GFX UMA (uncached)
78 * 80000000 2048MB TOLUD
79 * 80000000 2048MB TOM
80 *
81 * Total Memory 4GB example:
82 *
83 * 00000000 0000MB-3038MB 3038MB RAM (writeback)
84 * bde00000 3038MB-3040MB 2MB GFX GTT (uncached)
85 * be000000 3040MB-3072MB 32MB GFX UMA (uncached)
86 * be000000 3072MB TOLUD
87 * 100000000 4096MB TOM
88 * 100000000 4096MB-5120MB 1024MB RAM (writeback)
89 * 140000000 5120MB TOUUD
90 */
91
92 pci_domain_read_resources(dev);
93
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030094 struct device *mch = pcidev_on_root(0, 0);
Arthur Heymans89089312018-06-26 21:01:40 +020095
Patrick Georgi2efc8802012-11-06 11:03:53 +010096 /* Top of Upper Usable DRAM, including remap */
Arthur Heymans89089312018-06-26 21:01:40 +020097 touud = pci_read_config16(mch, D0F0_TOUUD);
Patrick Georgi2efc8802012-11-06 11:03:53 +010098 touud <<= 20;
99
100 /* Top of Lower Usable DRAM */
Arthur Heymans89089312018-06-26 21:01:40 +0200101 tolud = pci_read_config16(mch, D0F0_TOLUD) & 0xfff0;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100102 tolud <<= 16;
103
104 /* Top of Memory - does not account for any UMA */
Arthur Heymans89089312018-06-26 21:01:40 +0200105 tom = pci_read_config16(mch, D0F0_TOM) & 0x1ff;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100106 tom <<= 27;
107
108 printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n",
109 touud, tolud, tom);
110
111 tomk = tolud >> 10;
112
113 /* Graphics memory comes next */
Arthur Heymans89089312018-06-26 21:01:40 +0200114 const u16 ggc = pci_read_config16(mch, D0F0_GGC);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100115 if (!(ggc & 2)) {
116 printk(BIOS_DEBUG, "IGD decoded, subtracting ");
117
118 /* Graphics memory */
119 const u32 gms_sizek = decode_igd_memory_size((ggc >> 4) & 0xf);
Arthur Heymans8b766052018-01-24 23:25:13 +0100120 printk(BIOS_DEBUG, "%uM UMA, ", gms_sizek >> 10);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100121 tomk -= gms_sizek;
122
123 /* GTT Graphics Stolen Memory Size (GGMS) */
124 const u32 gsm_sizek = decode_igd_gtt_size((ggc >> 8) & 0xf);
Arthur Heymans8b766052018-01-24 23:25:13 +0100125 printk(BIOS_DEBUG, "%uM GTT", gsm_sizek >> 10);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100126 tomk -= gsm_sizek;
127
128 uma_sizek = gms_sizek + gsm_sizek;
129 }
Arthur Heymans89089312018-06-26 21:01:40 +0200130 const u8 esmramc = pci_read_config8(mch, D0F0_ESMRAMC);
Arthur Heymans8b766052018-01-24 23:25:13 +0100131 const u32 tseg_sizek = decode_tseg_size(esmramc);
132 printk(BIOS_DEBUG, " and %uM TSEG\n", tseg_sizek >> 10);
133 tomk -= tseg_sizek;
134 uma_sizek += tseg_sizek;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100135
Arthur Heymans17ad4592018-08-06 15:35:28 +0200136 /* cbmem_top can be shifted downwards due to alignment.
137 Mark the region between cbmem_top and tomk as unusable */
138 delta_cbmem = tomk - ((uint32_t)cbmem_top() >> 10);
139 tomk -= delta_cbmem;
140 uma_sizek += delta_cbmem;
141
142 printk(BIOS_DEBUG, "Unused RAM between cbmem_top and TOM: 0x%xK\n",
143 delta_cbmem);
144
Nico Huberca3e1212017-10-02 20:07:53 +0200145 printk(BIOS_INFO, "Available memory below 4GB: %uM\n", tomk >> 10);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100146
147 /* Report the memory regions */
148 ram_resource(dev, 3, 0, legacy_hole_base_k);
149 ram_resource(dev, 4, legacy_hole_base_k + legacy_hole_size_k,
Nico Huberca3e1212017-10-02 20:07:53 +0200150 (tomk - (legacy_hole_base_k + legacy_hole_size_k)));
Patrick Georgi2efc8802012-11-06 11:03:53 +0100151
152 /*
153 * If >= 4GB installed then memory from TOLUD to 4GB
154 * is remapped above TOM, TOUUD will account for both
155 */
156 touud >>= 10; /* Convert to KB */
157 if (touud > 4096 * 1024) {
158 ram_resource(dev, 5, 4096 * 1024, touud - (4096 * 1024));
159 printk(BIOS_INFO, "Available memory above 4GB: %lluM\n",
160 (touud >> 10) - 4096);
161 }
162
163 printk(BIOS_DEBUG, "Adding UMA memory area base=0x%llx "
164 "size=0x%llx\n", ((u64)tomk) << 10, ((u64)uma_sizek) << 10);
165 /* Don't use uma_resource() as our UMA touches the PCI hole. */
166 fixed_mem_resource(dev, 6, tomk, uma_sizek, IORESOURCE_RESERVE);
167
168 if (decode_pcie_bar(&pcie_config_base, &pcie_config_size)) {
169 printk(BIOS_DEBUG, "Adding PCIe config bar base=0x%08x "
170 "size=0x%x\n", pcie_config_base, pcie_config_size);
171 fixed_mem_resource(dev, 7, pcie_config_base >> 10,
172 pcie_config_size >> 10, IORESOURCE_RESERVE);
173 }
Patrick Georgi2efc8802012-11-06 11:03:53 +0100174}
175
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100176static void mch_domain_set_resources(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100177{
178 struct resource *resource;
179 int i;
180
181 for (i = 3; i < 8; ++i) {
182 /* Report read resources. */
Vladimir Serbinenko40412c62014-11-12 00:09:20 +0100183 resource = probe_resource(dev, i);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100184 if (resource)
185 report_resource_stored(dev, resource, "");
186 }
187
188 assign_resources(dev->link_list);
189}
190
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100191static void mch_domain_init(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100192{
193 u32 reg32;
194
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300195 struct device *mch = pcidev_on_root(0, 0);
Arthur Heymans89089312018-06-26 21:01:40 +0200196
Patrick Georgi2efc8802012-11-06 11:03:53 +0100197 /* Enable SERR */
Arthur Heymans89089312018-06-26 21:01:40 +0200198 reg32 = pci_read_config32(mch, PCI_COMMAND);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100199 reg32 |= PCI_COMMAND_SERR;
Arthur Heymans89089312018-06-26 21:01:40 +0200200 pci_write_config32(mch, PCI_COMMAND, reg32);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100201}
202
Arthur Heymanse798e6a2017-12-23 23:09:54 +0100203static const char *northbridge_acpi_name(const struct device *dev)
204{
205 if (dev->path.type == DEVICE_PATH_DOMAIN)
206 return "PCI0";
207
208 if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0)
209 return NULL;
210
211 switch (dev->path.pci.devfn) {
212 case PCI_DEVFN(0, 0):
213 return "MCHC";
214 }
215
216 return NULL;
217}
218
Arthur Heymansaade90e2018-01-25 00:33:45 +0100219void northbridge_write_smram(u8 smram)
220{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300221 struct device *dev = pcidev_on_root(0, 0);
Arthur Heymans48fa9222018-11-19 13:08:01 +0100222
223 if (dev == NULL)
224 die("could not find pci 00:00.0!\n");
225
226 pci_write_config8(dev, D0F0_SMRAM, smram);
Arthur Heymansaade90e2018-01-25 00:33:45 +0100227}
228
Patrick Georgi2efc8802012-11-06 11:03:53 +0100229static struct device_operations pci_domain_ops = {
230 .read_resources = mch_domain_read_resources,
231 .set_resources = mch_domain_set_resources,
232 .enable_resources = NULL,
233 .init = mch_domain_init,
234 .scan_bus = pci_domain_scan_bus,
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200235 .write_acpi_tables = northbridge_write_acpi_tables,
Nico Huber68680dd2020-03-31 17:34:52 +0200236 .acpi_fill_ssdt = generate_cpu_entries,
Arthur Heymanse798e6a2017-12-23 23:09:54 +0100237 .acpi_name = northbridge_acpi_name,
Patrick Georgi2efc8802012-11-06 11:03:53 +0100238};
239
Patrick Georgi2efc8802012-11-06 11:03:53 +0100240static struct device_operations cpu_bus_ops = {
Edward O'Callaghan9f744622014-10-31 08:12:34 +1100241 .read_resources = DEVICE_NOOP,
242 .set_resources = DEVICE_NOOP,
243 .enable_resources = DEVICE_NOOP,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300244 .init = mp_cpu_bus_init,
Patrick Georgi2efc8802012-11-06 11:03:53 +0100245 .scan_bus = 0,
246};
247
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100248static void enable_dev(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100249{
250 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800251 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Patrick Georgi2efc8802012-11-06 11:03:53 +0100252 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800253 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Patrick Georgi2efc8802012-11-06 11:03:53 +0100254 dev->ops = &cpu_bus_ops;
255 }
Patrick Georgi2efc8802012-11-06 11:03:53 +0100256}
257
258static void gm45_init(void *const chip_info)
259{
260 int dev, fn, bit_base;
261
Kyösti Mälkki98a91742018-05-21 21:29:16 +0300262 struct device *const d0f0 = pcidev_on_root(0x0, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100263
264 /* Hide internal functions based on devicetree info. */
265 for (dev = 3; dev > 0; --dev) {
266 switch (dev) {
267 case 3: /* ME */
268 fn = 3;
269 bit_base = 6;
270 break;
271 case 2: /* IGD */
272 fn = 1;
273 bit_base = 3;
274 break;
275 case 1: /* PEG */
276 fn = 0;
277 bit_base = 1;
278 break;
279 }
280 for (; fn >= 0; --fn) {
281 const struct device *const d =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300282 pcidev_on_root(dev, fn);
Nico Huber2dc15e92016-02-04 18:59:48 +0100283 if (!d || d->enabled) continue;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100284 const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN);
285 pci_write_config32(d0f0, D0F0_DEVEN,
286 deven & ~(1 << (bit_base + fn)));
287 }
288 }
289
290 const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN);
291 if (!(deven & (0xf << 6)))
292 pci_write_config32(d0f0, D0F0_DEVEN, deven & ~(1 << 14));
293}
294
295struct chip_operations northbridge_intel_gm45_ops = {
296 CHIP_NAME("Intel GM45 Northbridge")
297 .enable_dev = enable_dev,
298 .init = gm45_init,
299};