blob: b3dbe16b7560054861f748bb20bf5eef15441f03 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgi2efc8802012-11-06 11:03:53 +01002
Arthur Heymans17ad4592018-08-06 15:35:28 +02003#include <cbmem.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +01004#include <console/console.h>
Elyes HAOUAS748caed2019-12-19 17:02:08 +01005#include <device/pci_def.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02006#include <device/pci_ops.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +01007#include <stdint.h>
8#include <device/device.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +01009#include <boot/tables.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070010#include <acpi/acpi.h>
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030011#include <cpu/intel/smm_reloc.h>
Elyes HAOUASa1e22b82019-03-18 22:49:36 +010012
Patrick Georgi2efc8802012-11-06 11:03:53 +010013#include "chip.h"
14#include "gm45.h"
15
Vladimir Serbinenko8c220572014-08-16 14:18:21 +020016/* Reserve segments A and B:
Patrick Georgi2efc8802012-11-06 11:03:53 +010017 *
18 * 0xa0000 - 0xbffff: legacy VGA
Patrick Georgi2efc8802012-11-06 11:03:53 +010019 */
20static const int legacy_hole_base_k = 0xa0000 / 1024;
Vladimir Serbinenko8c220572014-08-16 14:18:21 +020021static const int legacy_hole_size_k = 128;
Patrick Georgi2efc8802012-11-06 11:03:53 +010022
23static int decode_pcie_bar(u32 *const base, u32 *const len)
24{
25 *base = 0;
26 *len = 0;
27
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030028 struct device *dev = pcidev_on_root(0, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010029 if (!dev)
30 return 0;
31
32 const u32 pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO);
33
34 if (!(pciexbar_reg & (1 << 0)))
35 return 0;
36
37 switch ((pciexbar_reg >> 1) & 3) {
38 case 0: /* 256MB */
39 *base = pciexbar_reg & (0x0f << 28);
40 *len = 256 * 1024 * 1024;
41 return 1;
42 case 1: /* 128M */
43 *base = pciexbar_reg & (0x1f << 27);
44 *len = 128 * 1024 * 1024;
45 return 1;
46 case 2: /* 64M */
47 *base = pciexbar_reg & (0x3f << 26);
48 *len = 64 * 1024 * 1024;
49 return 1;
50 }
51
52 return 0;
53}
54
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +010055static void mch_domain_read_resources(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +010056{
57 u64 tom, touud;
Arthur Heymans17ad4592018-08-06 15:35:28 +020058 u32 tomk, tolud, uma_sizek = 0, delta_cbmem;
Patrick Georgi2efc8802012-11-06 11:03:53 +010059 u32 pcie_config_base, pcie_config_size;
60
61 /* Total Memory 2GB example:
62 *
63 * 00000000 0000MB-2014MB 2014MB RAM (writeback)
64 * 7de00000 2014MB-2016MB 2MB GFX GTT (uncached)
65 * 7e000000 2016MB-2048MB 32MB GFX UMA (uncached)
66 * 80000000 2048MB TOLUD
67 * 80000000 2048MB TOM
68 *
69 * Total Memory 4GB example:
70 *
71 * 00000000 0000MB-3038MB 3038MB RAM (writeback)
72 * bde00000 3038MB-3040MB 2MB GFX GTT (uncached)
73 * be000000 3040MB-3072MB 32MB GFX UMA (uncached)
74 * be000000 3072MB TOLUD
75 * 100000000 4096MB TOM
76 * 100000000 4096MB-5120MB 1024MB RAM (writeback)
77 * 140000000 5120MB TOUUD
78 */
79
80 pci_domain_read_resources(dev);
81
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030082 struct device *mch = pcidev_on_root(0, 0);
Arthur Heymans89089312018-06-26 21:01:40 +020083
Patrick Georgi2efc8802012-11-06 11:03:53 +010084 /* Top of Upper Usable DRAM, including remap */
Arthur Heymans89089312018-06-26 21:01:40 +020085 touud = pci_read_config16(mch, D0F0_TOUUD);
Patrick Georgi2efc8802012-11-06 11:03:53 +010086 touud <<= 20;
87
88 /* Top of Lower Usable DRAM */
Arthur Heymans89089312018-06-26 21:01:40 +020089 tolud = pci_read_config16(mch, D0F0_TOLUD) & 0xfff0;
Patrick Georgi2efc8802012-11-06 11:03:53 +010090 tolud <<= 16;
91
92 /* Top of Memory - does not account for any UMA */
Arthur Heymans89089312018-06-26 21:01:40 +020093 tom = pci_read_config16(mch, D0F0_TOM) & 0x1ff;
Patrick Georgi2efc8802012-11-06 11:03:53 +010094 tom <<= 27;
95
96 printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n",
97 touud, tolud, tom);
98
99 tomk = tolud >> 10;
100
101 /* Graphics memory comes next */
Arthur Heymans89089312018-06-26 21:01:40 +0200102 const u16 ggc = pci_read_config16(mch, D0F0_GGC);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100103 if (!(ggc & 2)) {
104 printk(BIOS_DEBUG, "IGD decoded, subtracting ");
105
106 /* Graphics memory */
107 const u32 gms_sizek = decode_igd_memory_size((ggc >> 4) & 0xf);
Arthur Heymans8b766052018-01-24 23:25:13 +0100108 printk(BIOS_DEBUG, "%uM UMA, ", gms_sizek >> 10);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100109 tomk -= gms_sizek;
110
111 /* GTT Graphics Stolen Memory Size (GGMS) */
112 const u32 gsm_sizek = decode_igd_gtt_size((ggc >> 8) & 0xf);
Arthur Heymans8b766052018-01-24 23:25:13 +0100113 printk(BIOS_DEBUG, "%uM GTT", gsm_sizek >> 10);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100114 tomk -= gsm_sizek;
115
116 uma_sizek = gms_sizek + gsm_sizek;
117 }
Arthur Heymans89089312018-06-26 21:01:40 +0200118 const u8 esmramc = pci_read_config8(mch, D0F0_ESMRAMC);
Arthur Heymans8b766052018-01-24 23:25:13 +0100119 const u32 tseg_sizek = decode_tseg_size(esmramc);
120 printk(BIOS_DEBUG, " and %uM TSEG\n", tseg_sizek >> 10);
121 tomk -= tseg_sizek;
122 uma_sizek += tseg_sizek;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100123
Arthur Heymans17ad4592018-08-06 15:35:28 +0200124 /* cbmem_top can be shifted downwards due to alignment.
125 Mark the region between cbmem_top and tomk as unusable */
126 delta_cbmem = tomk - ((uint32_t)cbmem_top() >> 10);
127 tomk -= delta_cbmem;
128 uma_sizek += delta_cbmem;
129
130 printk(BIOS_DEBUG, "Unused RAM between cbmem_top and TOM: 0x%xK\n",
131 delta_cbmem);
132
Nico Huberca3e1212017-10-02 20:07:53 +0200133 printk(BIOS_INFO, "Available memory below 4GB: %uM\n", tomk >> 10);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100134
135 /* Report the memory regions */
136 ram_resource(dev, 3, 0, legacy_hole_base_k);
137 ram_resource(dev, 4, legacy_hole_base_k + legacy_hole_size_k,
Nico Huberca3e1212017-10-02 20:07:53 +0200138 (tomk - (legacy_hole_base_k + legacy_hole_size_k)));
Patrick Georgi2efc8802012-11-06 11:03:53 +0100139
140 /*
141 * If >= 4GB installed then memory from TOLUD to 4GB
142 * is remapped above TOM, TOUUD will account for both
143 */
144 touud >>= 10; /* Convert to KB */
145 if (touud > 4096 * 1024) {
146 ram_resource(dev, 5, 4096 * 1024, touud - (4096 * 1024));
147 printk(BIOS_INFO, "Available memory above 4GB: %lluM\n",
148 (touud >> 10) - 4096);
149 }
150
151 printk(BIOS_DEBUG, "Adding UMA memory area base=0x%llx "
152 "size=0x%llx\n", ((u64)tomk) << 10, ((u64)uma_sizek) << 10);
153 /* Don't use uma_resource() as our UMA touches the PCI hole. */
154 fixed_mem_resource(dev, 6, tomk, uma_sizek, IORESOURCE_RESERVE);
155
156 if (decode_pcie_bar(&pcie_config_base, &pcie_config_size)) {
157 printk(BIOS_DEBUG, "Adding PCIe config bar base=0x%08x "
158 "size=0x%x\n", pcie_config_base, pcie_config_size);
159 fixed_mem_resource(dev, 7, pcie_config_base >> 10,
160 pcie_config_size >> 10, IORESOURCE_RESERVE);
161 }
Patrick Georgi2efc8802012-11-06 11:03:53 +0100162}
163
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100164static void mch_domain_set_resources(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100165{
166 struct resource *resource;
167 int i;
168
169 for (i = 3; i < 8; ++i) {
170 /* Report read resources. */
Vladimir Serbinenko40412c62014-11-12 00:09:20 +0100171 resource = probe_resource(dev, i);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100172 if (resource)
173 report_resource_stored(dev, resource, "");
174 }
175
176 assign_resources(dev->link_list);
177}
178
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100179static void mch_domain_init(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100180{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300181 struct device *mch = pcidev_on_root(0, 0);
Arthur Heymans89089312018-06-26 21:01:40 +0200182
Patrick Georgi2efc8802012-11-06 11:03:53 +0100183 /* Enable SERR */
Elyes HAOUAS5ac723e2020-04-29 09:09:12 +0200184 pci_or_config16(mch, PCI_COMMAND, PCI_COMMAND_SERR);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100185}
186
Arthur Heymanse798e6a2017-12-23 23:09:54 +0100187static const char *northbridge_acpi_name(const struct device *dev)
188{
189 if (dev->path.type == DEVICE_PATH_DOMAIN)
190 return "PCI0";
191
192 if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0)
193 return NULL;
194
195 switch (dev->path.pci.devfn) {
196 case PCI_DEVFN(0, 0):
197 return "MCHC";
198 }
199
200 return NULL;
201}
202
Arthur Heymansaade90e2018-01-25 00:33:45 +0100203void northbridge_write_smram(u8 smram)
204{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300205 struct device *dev = pcidev_on_root(0, 0);
Arthur Heymans48fa9222018-11-19 13:08:01 +0100206
207 if (dev == NULL)
208 die("could not find pci 00:00.0!\n");
209
210 pci_write_config8(dev, D0F0_SMRAM, smram);
Arthur Heymansaade90e2018-01-25 00:33:45 +0100211}
212
Patrick Georgi2efc8802012-11-06 11:03:53 +0100213static struct device_operations pci_domain_ops = {
214 .read_resources = mch_domain_read_resources,
215 .set_resources = mch_domain_set_resources,
Patrick Georgi2efc8802012-11-06 11:03:53 +0100216 .init = mch_domain_init,
217 .scan_bus = pci_domain_scan_bus,
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200218 .write_acpi_tables = northbridge_write_acpi_tables,
Nico Huber68680dd2020-03-31 17:34:52 +0200219 .acpi_fill_ssdt = generate_cpu_entries,
Arthur Heymanse798e6a2017-12-23 23:09:54 +0100220 .acpi_name = northbridge_acpi_name,
Patrick Georgi2efc8802012-11-06 11:03:53 +0100221};
222
Patrick Georgi2efc8802012-11-06 11:03:53 +0100223static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200224 .read_resources = noop_read_resources,
225 .set_resources = noop_set_resources,
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300226 .init = mp_cpu_bus_init,
Patrick Georgi2efc8802012-11-06 11:03:53 +0100227};
228
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100229static void enable_dev(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100230{
231 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800232 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Patrick Georgi2efc8802012-11-06 11:03:53 +0100233 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800234 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Patrick Georgi2efc8802012-11-06 11:03:53 +0100235 dev->ops = &cpu_bus_ops;
236 }
Patrick Georgi2efc8802012-11-06 11:03:53 +0100237}
238
239static void gm45_init(void *const chip_info)
240{
241 int dev, fn, bit_base;
242
Kyösti Mälkki98a91742018-05-21 21:29:16 +0300243 struct device *const d0f0 = pcidev_on_root(0x0, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100244
245 /* Hide internal functions based on devicetree info. */
246 for (dev = 3; dev > 0; --dev) {
247 switch (dev) {
248 case 3: /* ME */
249 fn = 3;
250 bit_base = 6;
251 break;
252 case 2: /* IGD */
253 fn = 1;
254 bit_base = 3;
255 break;
256 case 1: /* PEG */
257 fn = 0;
258 bit_base = 1;
259 break;
260 }
261 for (; fn >= 0; --fn) {
262 const struct device *const d =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300263 pcidev_on_root(dev, fn);
Nico Huber2dc15e92016-02-04 18:59:48 +0100264 if (!d || d->enabled) continue;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100265 const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN);
266 pci_write_config32(d0f0, D0F0_DEVEN,
267 deven & ~(1 << (bit_base + fn)));
268 }
269 }
270
271 const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN);
272 if (!(deven & (0xf << 6)))
273 pci_write_config32(d0f0, D0F0_DEVEN, deven & ~(1 << 14));
274}
275
276struct chip_operations northbridge_intel_gm45_ops = {
277 CHIP_NAME("Intel GM45 Northbridge")
278 .enable_dev = enable_dev,
279 .init = gm45_init,
280};