blob: 43ec6ed6bdce08d08324892979940651851f73f4 [file] [log] [blame]
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2009 coresystems GmbH
5 * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
6 * Copyright (C) 2013 Vladimir Serbinenko
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010016 */
17
18#include <console/console.h>
19#include <arch/acpi.h>
20#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020021#include <device/pci_ops.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010022#include <stdint.h>
23#include <delay.h>
24#include <cpu/intel/model_2065x/model_2065x.h>
25#include <cpu/x86/msr.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010026#include <device/device.h>
27#include <device/pci.h>
28#include <device/pci_ids.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010029#include <stdlib.h>
30#include <string.h>
31#include <cpu/cpu.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010032#include "chip.h"
33#include "nehalem.h"
Vladimir Serbinenko0f9aa1c2015-05-29 16:52:50 +020034#include <cpu/intel/smm/gen1/smi.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010035
36static int bridge_revision_id = -1;
37
38int bridge_silicon_revision(void)
39{
40 if (bridge_revision_id < 0) {
41 uint8_t stepping = cpuid_eax(1) & 0xf;
42 uint8_t bridge_id =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030043 pci_read_config16(pcidev_on_root(0, 0),
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010044 PCI_DEVICE_ID) & 0xf0;
45 bridge_revision_id = bridge_id | stepping;
46 }
47 return bridge_revision_id;
48}
49
50/* Reserve everything between A segment and 1MB:
51 *
52 * 0xa0000 - 0xbffff: legacy VGA
53 * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel)
54 * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI
55 */
56static const int legacy_hole_base_k = 0xa0000 / 1024;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010057
58static void add_fixed_resources(struct device *dev, int index)
59{
60 struct resource *resource;
61
62 /* 0xe0000000-0xf0000000 PCIe config.
63 0xfed10000-0xfed14000 MCH
64 0xfed17000-0xfed18000 HECI
65 0xfed18000-0xfed19000 DMI
66 0xfed19000-0xfed1a000 EPBAR
67 0xfed1c000-0xfed20000 RCBA
68 0xfed90000-0xfed94000 IOMMU
69 0xff800000-0xffffffff ROM. */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010070
71 resource = new_resource(dev, index++);
72 resource->base = (resource_t) 0xfed00000;
73 resource->size = (resource_t) 0x00100000;
74 resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE |
75 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
76
77 mmio_resource(dev, index++, legacy_hole_base_k,
78 (0xc0000 >> 10) - legacy_hole_base_k);
79 reserved_ram_resource(dev, index++, 0xc0000 >> 10,
80 (0x100000 - 0xc0000) >> 10);
81
Martin Roth33232602017-06-24 14:48:50 -060082#if IS_ENABLED(CONFIG_CHROMEOS_RAMOOPS)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010083 reserved_ram_resource(dev, index++,
84 CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10,
85 CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10);
86#endif
87}
88
Elyes HAOUAS706aabc2018-02-09 08:49:32 +010089static void pci_domain_set_resources(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010090{
91 assign_resources(dev->link_list);
92}
93
Patrick Rudolph5c3452b2018-05-15 11:37:26 +020094#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
95static const char *northbridge_acpi_name(const struct device *dev)
96{
97 if (dev->path.type == DEVICE_PATH_DOMAIN)
98 return "PCI0";
99
100 if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0)
101 return NULL;
102
103 switch (dev->path.pci.devfn) {
104 case PCI_DEVFN(0, 0):
105 return "MCHC";
106 }
107
108 return NULL;
109}
110#endif
111
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100112static struct device_operations pci_domain_ops = {
113 .read_resources = pci_domain_read_resources,
114 .set_resources = pci_domain_set_resources,
115 .enable_resources = NULL,
116 .init = NULL,
117 .scan_bus = pci_domain_scan_bus,
Patrick Rudolph5c3452b2018-05-15 11:37:26 +0200118#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
119 .acpi_name = northbridge_acpi_name,
120#endif
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100121};
122
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100123static void mc_read_resources(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100124{
125 uint32_t tseg_base;
126 uint64_t TOUUD;
127 uint16_t reg16;
128
129 pci_dev_read_resources(dev);
130
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200131 mmconf_resource(dev, 0x50);
132
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300133 tseg_base = pci_read_config32(pcidev_on_root(0, 0), TSEG);
134 TOUUD = pci_read_config16(pcidev_on_root(0, 0),
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100135 D0F0_TOUUD);
136
137 printk(BIOS_DEBUG, "ram_before_4g_top: 0x%x\n", tseg_base);
138 printk(BIOS_DEBUG, "TOUUD: 0x%x\n", (unsigned)TOUUD);
139
140 /* Report the memory regions */
141 ram_resource(dev, 3, 0, 640);
142 ram_resource(dev, 4, 768, ((tseg_base >> 10) - 768));
143
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100144 mmio_resource(dev, 5, tseg_base >> 10, CONFIG_SMM_TSEG_SIZE >> 10);
145
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300146 reg16 = pci_read_config16(pcidev_on_root(0, 0), D0F0_GGC);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100147 const int uma_sizes_gtt[16] =
148 { 0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 3, 4, 42, 42, 42, 42 };
149 /* Igd memory */
150 const int uma_sizes_igd[16] = {
151 0, 0, 0, 0, 0, 32, 48, 64, 128, 256, 96, 160, 224, 352, 256, 512
152 };
153 u32 igd_base, gtt_base;
154 int uma_size_igd, uma_size_gtt;
155
156 uma_size_igd = uma_sizes_igd[(reg16 >> 4) & 0xF];
157 uma_size_gtt = uma_sizes_gtt[(reg16 >> 8) & 0xF];
158
159 igd_base =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300160 pci_read_config32(pcidev_on_root(0, 0), D0F0_IGD_BASE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100161 gtt_base =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300162 pci_read_config32(pcidev_on_root(0, 0), D0F0_GTT_BASE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100163 mmio_resource(dev, 6, gtt_base >> 10, uma_size_gtt << 10);
164 mmio_resource(dev, 7, igd_base >> 10, uma_size_igd << 10);
165
166 if (TOUUD > 4096)
167 ram_resource(dev, 8, (4096 << 10), ((TOUUD - 4096) << 10));
168
169 /* This memory is not DMA-capable. */
170 if (TOUUD >= 8192 - 64)
171 bad_ram_resource(dev, 9, 0x1fc000000ULL >> 10, 0x004000000 >> 10);
172
173 add_fixed_resources(dev, 10);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100174}
175
Nico Huber6f8b7df2016-10-08 18:42:46 +0200176u32 northbridge_get_tseg_base(void)
Vladimir Serbinenko0f9aa1c2015-05-29 16:52:50 +0200177{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300178 struct device *dev = pcidev_on_root(0, 0);
Vladimir Serbinenko0f9aa1c2015-05-29 16:52:50 +0200179
Nico Huber6f8b7df2016-10-08 18:42:46 +0200180 return pci_read_config32(dev, TSEG) & ~1;
Vladimir Serbinenko0f9aa1c2015-05-29 16:52:50 +0200181}
182
Arthur Heymansaade90e2018-01-25 00:33:45 +0100183u32 northbridge_get_tseg_size(void)
184{
185 return CONFIG_SMM_TSEG_SIZE;
186}
187
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100188static void mc_set_resources(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100189{
190 /* And call the normal set_resources */
191 pci_dev_set_resources(dev);
192}
193
Elyes HAOUASb60920d2018-09-20 17:38:38 +0200194static void intel_set_subsystem(struct device *dev, unsigned int vendor,
195 unsigned int device)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100196{
197 if (!vendor || !device) {
198 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
199 pci_read_config32(dev, PCI_VENDOR_ID));
200 } else {
201 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
202 ((device & 0xffff) << 16) | (vendor &
203 0xffff));
204 }
205}
206
207static void northbridge_dmi_init(struct device *dev)
208{
209 u32 reg32;
210
211 /* Clear error status bits */
212 DMIBAR32(0x1c4) = 0xffffffff;
213 DMIBAR32(0x1d0) = 0xffffffff;
214
215 /* Steps prior to DMI ASPM */
216 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
217 reg32 = DMIBAR32(0x250);
218 reg32 &= ~((1 << 22) | (1 << 20));
219 reg32 |= (1 << 21);
220 DMIBAR32(0x250) = reg32;
221 }
222
223 reg32 = DMIBAR32(0x238);
224 reg32 |= (1 << 29);
225 DMIBAR32(0x238) = reg32;
226
227 if (bridge_silicon_revision() >= SNB_STEP_D0) {
228 reg32 = DMIBAR32(0x1f8);
229 reg32 |= (1 << 16);
230 DMIBAR32(0x1f8) = reg32;
231 } else if (bridge_silicon_revision() >= SNB_STEP_D1) {
232 reg32 = DMIBAR32(0x1f8);
233 reg32 &= ~(1 << 26);
234 reg32 |= (1 << 16);
235 DMIBAR32(0x1f8) = reg32;
236
237 reg32 = DMIBAR32(0x1fc);
238 reg32 |= (1 << 12) | (1 << 23);
239 DMIBAR32(0x1fc) = reg32;
240 }
241
242 /* Enable ASPM on SNB link, should happen before PCH link */
243 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
244 reg32 = DMIBAR32(0xd04);
245 reg32 |= (1 << 4);
246 DMIBAR32(0xd04) = reg32;
247 }
248
249 reg32 = DMIBAR32(0x88);
250 reg32 |= (1 << 1) | (1 << 0);
251 DMIBAR32(0x88) = reg32;
252}
253
254static void northbridge_init(struct device *dev)
255{
256 u8 bios_reset_cpl;
257 u32 bridge_type;
258
259 northbridge_dmi_init(dev);
260
261 bridge_type = MCHBAR32(0x5f10);
262 bridge_type &= ~0xff;
263
264 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
265 /* Enable Power Aware Interrupt Routing */
266 u8 pair = MCHBAR8(0x5418);
267 pair &= ~0xf; /* Clear 3:0 */
268 pair |= 0x4; /* Fixed Priority */
269 MCHBAR8(0x5418) = pair;
270
271 /* 30h for IvyBridge */
272 bridge_type |= 0x30;
273 } else {
274 /* 20h for Sandybridge */
275 bridge_type |= 0x20;
276 }
277 MCHBAR32(0x5f10) = bridge_type;
278
279 /*
280 * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU
281 * that BIOS has initialized memory and power management
282 */
283 bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL);
284 bios_reset_cpl |= 1;
285 MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl;
286 printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n");
287
288 /* Configure turbo power limits 1ms after reset complete bit */
289 mdelay(1);
290#ifdef DISABLED
291 set_power_limits(28);
292
293 /*
294 * CPUs with configurable TDP also need power limits set
295 * in MCHBAR. Use same values from MSR_PKG_POWER_LIMIT.
296 */
297 if (cpu_config_tdp_levels()) {
298 msr_t msr = rdmsr(MSR_PKG_POWER_LIMIT);
299 MCHBAR32(0x59A0) = msr.lo;
300 MCHBAR32(0x59A4) = msr.hi;
301 }
302#endif
303 /* Set here before graphics PM init */
304 MCHBAR32(0x5500) = 0x00100001;
305}
306
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100307static struct pci_operations intel_pci_ops = {
308 .set_subsystem = intel_set_subsystem,
309};
310
311static struct device_operations mc_ops = {
312 .read_resources = mc_read_resources,
313 .set_resources = mc_set_resources,
314 .enable_resources = pci_dev_enable_resources,
315 .init = northbridge_init,
Vladimir Serbinenko0a669912014-10-05 14:34:17 +0200316 .acpi_fill_ssdt_generator = generate_cpu_entries,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100317 .scan_bus = 0,
318 .ops_pci = &intel_pci_ops,
319};
320
321static const struct pci_driver mc_driver_44 __pci_driver = {
322 .ops = &mc_ops,
323 .vendor = PCI_VENDOR_ID_INTEL,
324 .device = 0x0044, /* Nehalem */
325};
326
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100327static void cpu_bus_init(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100328{
329 initialize_cpus(dev->link_list);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100330}
331
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100332static struct device_operations cpu_bus_ops = {
Edward O'Callaghan9f744622014-10-31 08:12:34 +1100333 .read_resources = DEVICE_NOOP,
334 .set_resources = DEVICE_NOOP,
335 .enable_resources = DEVICE_NOOP,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100336 .init = cpu_bus_init,
337 .scan_bus = 0,
338};
339
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100340static void enable_dev(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100341{
342 /* Set the operations if it is a special bus type */
343 if (dev->path.type == DEVICE_PATH_DOMAIN) {
344 dev->ops = &pci_domain_ops;
345 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
346 dev->ops = &cpu_bus_ops;
347 }
348}
349
350struct chip_operations northbridge_intel_nehalem_ops = {
351 CHIP_NAME("Intel i7 (Nehalem) integrated Northbridge")
352 .enable_dev = enable_dev,
353};