blob: 791559b518a46fb6e9a4947f8fe12cf9df62d0ce [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>
18#include <arch/io.h>
19#include <stdint.h>
20#include <device/device.h>
21#include <device/pci.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010022#include <stdlib.h>
23#include <string.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010024#include <cpu/cpu.h>
25#include <boot/tables.h>
26#include <arch/acpi.h>
Arthur Heymansaade90e2018-01-25 00:33:45 +010027#include <cpu/intel/smm/gen1/smi.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010028#include "chip.h"
29#include "gm45.h"
Vladimir Serbinenko06667a52014-08-12 09:07:13 +020030#include "arch/acpi.h"
Patrick Georgi2efc8802012-11-06 11:03:53 +010031
Vladimir Serbinenko8c220572014-08-16 14:18:21 +020032/* Reserve segments A and B:
Patrick Georgi2efc8802012-11-06 11:03:53 +010033 *
34 * 0xa0000 - 0xbffff: legacy VGA
Patrick Georgi2efc8802012-11-06 11:03:53 +010035 */
36static const int legacy_hole_base_k = 0xa0000 / 1024;
Vladimir Serbinenko8c220572014-08-16 14:18:21 +020037static const int legacy_hole_size_k = 128;
Patrick Georgi2efc8802012-11-06 11:03:53 +010038
39static int decode_pcie_bar(u32 *const base, u32 *const len)
40{
41 *base = 0;
42 *len = 0;
43
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030044 struct device *dev = pcidev_on_root(0, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010045 if (!dev)
46 return 0;
47
48 const u32 pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO);
49
50 if (!(pciexbar_reg & (1 << 0)))
51 return 0;
52
53 switch ((pciexbar_reg >> 1) & 3) {
54 case 0: /* 256MB */
55 *base = pciexbar_reg & (0x0f << 28);
56 *len = 256 * 1024 * 1024;
57 return 1;
58 case 1: /* 128M */
59 *base = pciexbar_reg & (0x1f << 27);
60 *len = 128 * 1024 * 1024;
61 return 1;
62 case 2: /* 64M */
63 *base = pciexbar_reg & (0x3f << 26);
64 *len = 64 * 1024 * 1024;
65 return 1;
66 }
67
68 return 0;
69}
70
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +010071static void mch_domain_read_resources(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +010072{
73 u64 tom, touud;
Arthur Heymans17ad4592018-08-06 15:35:28 +020074 u32 tomk, tolud, uma_sizek = 0, delta_cbmem;
Patrick Georgi2efc8802012-11-06 11:03:53 +010075 u32 pcie_config_base, pcie_config_size;
76
77 /* Total Memory 2GB example:
78 *
79 * 00000000 0000MB-2014MB 2014MB RAM (writeback)
80 * 7de00000 2014MB-2016MB 2MB GFX GTT (uncached)
81 * 7e000000 2016MB-2048MB 32MB GFX UMA (uncached)
82 * 80000000 2048MB TOLUD
83 * 80000000 2048MB TOM
84 *
85 * Total Memory 4GB example:
86 *
87 * 00000000 0000MB-3038MB 3038MB RAM (writeback)
88 * bde00000 3038MB-3040MB 2MB GFX GTT (uncached)
89 * be000000 3040MB-3072MB 32MB GFX UMA (uncached)
90 * be000000 3072MB TOLUD
91 * 100000000 4096MB TOM
92 * 100000000 4096MB-5120MB 1024MB RAM (writeback)
93 * 140000000 5120MB TOUUD
94 */
95
96 pci_domain_read_resources(dev);
97
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030098 struct device *mch = pcidev_on_root(0, 0);
Arthur Heymans89089312018-06-26 21:01:40 +020099
Patrick Georgi2efc8802012-11-06 11:03:53 +0100100 /* Top of Upper Usable DRAM, including remap */
Arthur Heymans89089312018-06-26 21:01:40 +0200101 touud = pci_read_config16(mch, D0F0_TOUUD);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100102 touud <<= 20;
103
104 /* Top of Lower Usable DRAM */
Arthur Heymans89089312018-06-26 21:01:40 +0200105 tolud = pci_read_config16(mch, D0F0_TOLUD) & 0xfff0;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100106 tolud <<= 16;
107
108 /* Top of Memory - does not account for any UMA */
Arthur Heymans89089312018-06-26 21:01:40 +0200109 tom = pci_read_config16(mch, D0F0_TOM) & 0x1ff;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100110 tom <<= 27;
111
112 printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n",
113 touud, tolud, tom);
114
115 tomk = tolud >> 10;
116
117 /* Graphics memory comes next */
Arthur Heymans89089312018-06-26 21:01:40 +0200118 const u16 ggc = pci_read_config16(mch, D0F0_GGC);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100119 if (!(ggc & 2)) {
120 printk(BIOS_DEBUG, "IGD decoded, subtracting ");
121
122 /* Graphics memory */
123 const u32 gms_sizek = decode_igd_memory_size((ggc >> 4) & 0xf);
Arthur Heymans8b766052018-01-24 23:25:13 +0100124 printk(BIOS_DEBUG, "%uM UMA, ", gms_sizek >> 10);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100125 tomk -= gms_sizek;
126
127 /* GTT Graphics Stolen Memory Size (GGMS) */
128 const u32 gsm_sizek = decode_igd_gtt_size((ggc >> 8) & 0xf);
Arthur Heymans8b766052018-01-24 23:25:13 +0100129 printk(BIOS_DEBUG, "%uM GTT", gsm_sizek >> 10);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100130 tomk -= gsm_sizek;
131
132 uma_sizek = gms_sizek + gsm_sizek;
133 }
Arthur Heymans89089312018-06-26 21:01:40 +0200134 const u8 esmramc = pci_read_config8(mch, D0F0_ESMRAMC);
Arthur Heymans8b766052018-01-24 23:25:13 +0100135 const u32 tseg_sizek = decode_tseg_size(esmramc);
136 printk(BIOS_DEBUG, " and %uM TSEG\n", tseg_sizek >> 10);
137 tomk -= tseg_sizek;
138 uma_sizek += tseg_sizek;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100139
Arthur Heymans17ad4592018-08-06 15:35:28 +0200140 /* cbmem_top can be shifted downwards due to alignment.
141 Mark the region between cbmem_top and tomk as unusable */
142 delta_cbmem = tomk - ((uint32_t)cbmem_top() >> 10);
143 tomk -= delta_cbmem;
144 uma_sizek += delta_cbmem;
145
146 printk(BIOS_DEBUG, "Unused RAM between cbmem_top and TOM: 0x%xK\n",
147 delta_cbmem);
148
Nico Huberca3e1212017-10-02 20:07:53 +0200149 printk(BIOS_INFO, "Available memory below 4GB: %uM\n", tomk >> 10);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100150
151 /* Report the memory regions */
152 ram_resource(dev, 3, 0, legacy_hole_base_k);
153 ram_resource(dev, 4, legacy_hole_base_k + legacy_hole_size_k,
Nico Huberca3e1212017-10-02 20:07:53 +0200154 (tomk - (legacy_hole_base_k + legacy_hole_size_k)));
Patrick Georgi2efc8802012-11-06 11:03:53 +0100155
156 /*
157 * If >= 4GB installed then memory from TOLUD to 4GB
158 * is remapped above TOM, TOUUD will account for both
159 */
160 touud >>= 10; /* Convert to KB */
161 if (touud > 4096 * 1024) {
162 ram_resource(dev, 5, 4096 * 1024, touud - (4096 * 1024));
163 printk(BIOS_INFO, "Available memory above 4GB: %lluM\n",
164 (touud >> 10) - 4096);
165 }
166
167 printk(BIOS_DEBUG, "Adding UMA memory area base=0x%llx "
168 "size=0x%llx\n", ((u64)tomk) << 10, ((u64)uma_sizek) << 10);
169 /* Don't use uma_resource() as our UMA touches the PCI hole. */
170 fixed_mem_resource(dev, 6, tomk, uma_sizek, IORESOURCE_RESERVE);
171
172 if (decode_pcie_bar(&pcie_config_base, &pcie_config_size)) {
173 printk(BIOS_DEBUG, "Adding PCIe config bar base=0x%08x "
174 "size=0x%x\n", pcie_config_base, pcie_config_size);
175 fixed_mem_resource(dev, 7, pcie_config_base >> 10,
176 pcie_config_size >> 10, IORESOURCE_RESERVE);
177 }
Patrick Georgi2efc8802012-11-06 11:03:53 +0100178}
179
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100180static void mch_domain_set_resources(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100181{
182 struct resource *resource;
183 int i;
184
185 for (i = 3; i < 8; ++i) {
186 /* Report read resources. */
Vladimir Serbinenko40412c62014-11-12 00:09:20 +0100187 resource = probe_resource(dev, i);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100188 if (resource)
189 report_resource_stored(dev, resource, "");
190 }
191
192 assign_resources(dev->link_list);
193}
194
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100195static void mch_domain_init(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100196{
197 u32 reg32;
198
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300199 struct device *mch = pcidev_on_root(0, 0);
Arthur Heymans89089312018-06-26 21:01:40 +0200200
Patrick Georgi2efc8802012-11-06 11:03:53 +0100201 /* Enable SERR */
Arthur Heymans89089312018-06-26 21:01:40 +0200202 reg32 = pci_read_config32(mch, PCI_COMMAND);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100203 reg32 |= PCI_COMMAND_SERR;
Arthur Heymans89089312018-06-26 21:01:40 +0200204 pci_write_config32(mch, PCI_COMMAND, reg32);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100205}
206
Arthur Heymanse798e6a2017-12-23 23:09:54 +0100207static const char *northbridge_acpi_name(const struct device *dev)
208{
209 if (dev->path.type == DEVICE_PATH_DOMAIN)
210 return "PCI0";
211
212 if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0)
213 return NULL;
214
215 switch (dev->path.pci.devfn) {
216 case PCI_DEVFN(0, 0):
217 return "MCHC";
218 }
219
220 return NULL;
221}
222
Arthur Heymansaade90e2018-01-25 00:33:45 +0100223void northbridge_write_smram(u8 smram)
224{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300225 struct device *dev = pcidev_on_root(0, 0);
Arthur Heymans48fa9222018-11-19 13:08:01 +0100226
227 if (dev == NULL)
228 die("could not find pci 00:00.0!\n");
229
230 pci_write_config8(dev, D0F0_SMRAM, smram);
Arthur Heymansaade90e2018-01-25 00:33:45 +0100231}
232
Patrick Georgi2efc8802012-11-06 11:03:53 +0100233static struct device_operations pci_domain_ops = {
234 .read_resources = mch_domain_read_resources,
235 .set_resources = mch_domain_set_resources,
236 .enable_resources = NULL,
237 .init = mch_domain_init,
238 .scan_bus = pci_domain_scan_bus,
Vladimir Serbinenko33769a52014-08-30 22:39:20 +0200239 .write_acpi_tables = northbridge_write_acpi_tables,
240 .acpi_fill_ssdt_generator = generate_cpu_entries,
Arthur Heymanse798e6a2017-12-23 23:09:54 +0100241 .acpi_name = northbridge_acpi_name,
Patrick Georgi2efc8802012-11-06 11:03:53 +0100242};
243
244
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100245static void cpu_bus_init(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100246{
Arthur Heymans6336d4c2018-01-25 21:38:25 +0100247 bsp_init_and_start_aps(dev->link_list);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100248}
249
Patrick Georgi2efc8802012-11-06 11:03:53 +0100250static struct device_operations cpu_bus_ops = {
Edward O'Callaghan9f744622014-10-31 08:12:34 +1100251 .read_resources = DEVICE_NOOP,
252 .set_resources = DEVICE_NOOP,
253 .enable_resources = DEVICE_NOOP,
Patrick Georgi2efc8802012-11-06 11:03:53 +0100254 .init = cpu_bus_init,
255 .scan_bus = 0,
256};
257
Elyes HAOUAS6dcdaaf2018-02-09 07:44:31 +0100258static void enable_dev(struct device *dev)
Patrick Georgi2efc8802012-11-06 11:03:53 +0100259{
260 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800261 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Patrick Georgi2efc8802012-11-06 11:03:53 +0100262 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800263 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
Patrick Georgi2efc8802012-11-06 11:03:53 +0100264 dev->ops = &cpu_bus_ops;
265 }
Patrick Georgi2efc8802012-11-06 11:03:53 +0100266}
267
268static void gm45_init(void *const chip_info)
269{
270 int dev, fn, bit_base;
271
Kyösti Mälkki98a91742018-05-21 21:29:16 +0300272 struct device *const d0f0 = pcidev_on_root(0x0, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +0100273
274 /* Hide internal functions based on devicetree info. */
275 for (dev = 3; dev > 0; --dev) {
276 switch (dev) {
277 case 3: /* ME */
278 fn = 3;
279 bit_base = 6;
280 break;
281 case 2: /* IGD */
282 fn = 1;
283 bit_base = 3;
284 break;
285 case 1: /* PEG */
286 fn = 0;
287 bit_base = 1;
288 break;
289 }
290 for (; fn >= 0; --fn) {
291 const struct device *const d =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300292 pcidev_on_root(dev, fn);
Nico Huber2dc15e92016-02-04 18:59:48 +0100293 if (!d || d->enabled) continue;
Patrick Georgi2efc8802012-11-06 11:03:53 +0100294 const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN);
295 pci_write_config32(d0f0, D0F0_DEVEN,
296 deven & ~(1 << (bit_base + fn)));
297 }
298 }
299
300 const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN);
301 if (!(deven & (0xf << 6)))
302 pci_write_config32(d0f0, D0F0_DEVEN, deven & ~(1 << 14));
303}
304
305struct chip_operations northbridge_intel_gm45_ops = {
306 CHIP_NAME("Intel GM45 Northbridge")
307 .enable_dev = enable_dev,
308 .init = gm45_init,
309};