blob: 8a4f64c809aad17fa38ae2786161ccceb40e18fc [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>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020020#include <device/pci_ops.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010021#include <stdint.h>
22#include <delay.h>
23#include <cpu/intel/model_2065x/model_2065x.h>
24#include <cpu/x86/msr.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010025#include <device/device.h>
26#include <device/pci.h>
27#include <device/pci_ids.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010028#include <stdlib.h>
29#include <string.h>
30#include <cpu/cpu.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010031#include "chip.h"
32#include "nehalem.h"
Vladimir Serbinenko0f9aa1c2015-05-29 16:52:50 +020033#include <cpu/intel/smm/gen1/smi.h>
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010034
35static int bridge_revision_id = -1;
36
37int bridge_silicon_revision(void)
38{
39 if (bridge_revision_id < 0) {
40 uint8_t stepping = cpuid_eax(1) & 0xf;
41 uint8_t bridge_id =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +030042 pci_read_config16(pcidev_on_root(0, 0),
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010043 PCI_DEVICE_ID) & 0xf0;
44 bridge_revision_id = bridge_id | stepping;
45 }
46 return bridge_revision_id;
47}
48
49/* Reserve everything between A segment and 1MB:
50 *
51 * 0xa0000 - 0xbffff: legacy VGA
52 * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel)
53 * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI
54 */
55static const int legacy_hole_base_k = 0xa0000 / 1024;
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010056
57static void add_fixed_resources(struct device *dev, int index)
58{
59 struct resource *resource;
60
61 /* 0xe0000000-0xf0000000 PCIe config.
62 0xfed10000-0xfed14000 MCH
63 0xfed17000-0xfed18000 HECI
64 0xfed18000-0xfed19000 DMI
65 0xfed19000-0xfed1a000 EPBAR
66 0xfed1c000-0xfed20000 RCBA
67 0xfed90000-0xfed94000 IOMMU
68 0xff800000-0xffffffff ROM. */
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010069
70 resource = new_resource(dev, index++);
71 resource->base = (resource_t) 0xfed00000;
72 resource->size = (resource_t) 0x00100000;
73 resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE |
74 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
75
76 mmio_resource(dev, index++, legacy_hole_base_k,
77 (0xc0000 >> 10) - legacy_hole_base_k);
78 reserved_ram_resource(dev, index++, 0xc0000 >> 10,
79 (0x100000 - 0xc0000) >> 10);
80
Julius Wernercd49cce2019-03-05 16:53:33 -080081#if CONFIG(CHROMEOS_RAMOOPS)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010082 reserved_ram_resource(dev, index++,
83 CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10,
84 CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10);
85#endif
86}
87
Elyes HAOUAS706aabc2018-02-09 08:49:32 +010088static void pci_domain_set_resources(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +010089{
90 assign_resources(dev->link_list);
91}
92
Julius Wernercd49cce2019-03-05 16:53:33 -080093#if CONFIG(HAVE_ACPI_TABLES)
Patrick Rudolph5c3452b2018-05-15 11:37:26 +020094static const char *northbridge_acpi_name(const struct device *dev)
95{
96 if (dev->path.type == DEVICE_PATH_DOMAIN)
97 return "PCI0";
98
99 if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0)
100 return NULL;
101
102 switch (dev->path.pci.devfn) {
103 case PCI_DEVFN(0, 0):
104 return "MCHC";
105 }
106
107 return NULL;
108}
109#endif
110
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100111static struct device_operations pci_domain_ops = {
112 .read_resources = pci_domain_read_resources,
113 .set_resources = pci_domain_set_resources,
114 .enable_resources = NULL,
115 .init = NULL,
116 .scan_bus = pci_domain_scan_bus,
Julius Wernercd49cce2019-03-05 16:53:33 -0800117#if CONFIG(HAVE_ACPI_TABLES)
Patrick Rudolph5c3452b2018-05-15 11:37:26 +0200118 .acpi_name = northbridge_acpi_name,
119#endif
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100120};
121
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100122static void mc_read_resources(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100123{
124 uint32_t tseg_base;
125 uint64_t TOUUD;
126 uint16_t reg16;
127
128 pci_dev_read_resources(dev);
129
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200130 mmconf_resource(dev, 0x50);
131
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300132 tseg_base = pci_read_config32(pcidev_on_root(0, 0), TSEG);
133 TOUUD = pci_read_config16(pcidev_on_root(0, 0),
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100134 D0F0_TOUUD);
135
136 printk(BIOS_DEBUG, "ram_before_4g_top: 0x%x\n", tseg_base);
137 printk(BIOS_DEBUG, "TOUUD: 0x%x\n", (unsigned)TOUUD);
138
139 /* Report the memory regions */
140 ram_resource(dev, 3, 0, 640);
141 ram_resource(dev, 4, 768, ((tseg_base >> 10) - 768));
142
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100143 mmio_resource(dev, 5, tseg_base >> 10, CONFIG_SMM_TSEG_SIZE >> 10);
144
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300145 reg16 = pci_read_config16(pcidev_on_root(0, 0), D0F0_GGC);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100146 const int uma_sizes_gtt[16] =
147 { 0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 3, 4, 42, 42, 42, 42 };
148 /* Igd memory */
149 const int uma_sizes_igd[16] = {
150 0, 0, 0, 0, 0, 32, 48, 64, 128, 256, 96, 160, 224, 352, 256, 512
151 };
152 u32 igd_base, gtt_base;
153 int uma_size_igd, uma_size_gtt;
154
155 uma_size_igd = uma_sizes_igd[(reg16 >> 4) & 0xF];
156 uma_size_gtt = uma_sizes_gtt[(reg16 >> 8) & 0xF];
157
158 igd_base =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300159 pci_read_config32(pcidev_on_root(0, 0), D0F0_IGD_BASE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100160 gtt_base =
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300161 pci_read_config32(pcidev_on_root(0, 0), D0F0_GTT_BASE);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100162 mmio_resource(dev, 6, gtt_base >> 10, uma_size_gtt << 10);
163 mmio_resource(dev, 7, igd_base >> 10, uma_size_igd << 10);
164
165 if (TOUUD > 4096)
166 ram_resource(dev, 8, (4096 << 10), ((TOUUD - 4096) << 10));
167
168 /* This memory is not DMA-capable. */
169 if (TOUUD >= 8192 - 64)
170 bad_ram_resource(dev, 9, 0x1fc000000ULL >> 10, 0x004000000 >> 10);
171
172 add_fixed_resources(dev, 10);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100173}
174
Nico Huber6f8b7df2016-10-08 18:42:46 +0200175u32 northbridge_get_tseg_base(void)
Vladimir Serbinenko0f9aa1c2015-05-29 16:52:50 +0200176{
Kyösti Mälkkic70eed12018-05-22 02:18:00 +0300177 struct device *dev = pcidev_on_root(0, 0);
Vladimir Serbinenko0f9aa1c2015-05-29 16:52:50 +0200178
Nico Huber6f8b7df2016-10-08 18:42:46 +0200179 return pci_read_config32(dev, TSEG) & ~1;
Vladimir Serbinenko0f9aa1c2015-05-29 16:52:50 +0200180}
181
Arthur Heymansaade90e2018-01-25 00:33:45 +0100182u32 northbridge_get_tseg_size(void)
183{
184 return CONFIG_SMM_TSEG_SIZE;
185}
186
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100187static void mc_set_resources(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100188{
189 /* And call the normal set_resources */
190 pci_dev_set_resources(dev);
191}
192
Elyes HAOUASb60920d2018-09-20 17:38:38 +0200193static void intel_set_subsystem(struct device *dev, unsigned int vendor,
194 unsigned int device)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100195{
196 if (!vendor || !device) {
197 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
198 pci_read_config32(dev, PCI_VENDOR_ID));
199 } else {
200 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
201 ((device & 0xffff) << 16) | (vendor &
202 0xffff));
203 }
204}
205
206static void northbridge_dmi_init(struct device *dev)
207{
208 u32 reg32;
209
210 /* Clear error status bits */
211 DMIBAR32(0x1c4) = 0xffffffff;
212 DMIBAR32(0x1d0) = 0xffffffff;
213
214 /* Steps prior to DMI ASPM */
215 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
216 reg32 = DMIBAR32(0x250);
217 reg32 &= ~((1 << 22) | (1 << 20));
218 reg32 |= (1 << 21);
219 DMIBAR32(0x250) = reg32;
220 }
221
222 reg32 = DMIBAR32(0x238);
223 reg32 |= (1 << 29);
224 DMIBAR32(0x238) = reg32;
225
226 if (bridge_silicon_revision() >= SNB_STEP_D0) {
227 reg32 = DMIBAR32(0x1f8);
228 reg32 |= (1 << 16);
229 DMIBAR32(0x1f8) = reg32;
230 } else if (bridge_silicon_revision() >= SNB_STEP_D1) {
231 reg32 = DMIBAR32(0x1f8);
232 reg32 &= ~(1 << 26);
233 reg32 |= (1 << 16);
234 DMIBAR32(0x1f8) = reg32;
235
236 reg32 = DMIBAR32(0x1fc);
237 reg32 |= (1 << 12) | (1 << 23);
238 DMIBAR32(0x1fc) = reg32;
239 }
240
241 /* Enable ASPM on SNB link, should happen before PCH link */
242 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
243 reg32 = DMIBAR32(0xd04);
244 reg32 |= (1 << 4);
245 DMIBAR32(0xd04) = reg32;
246 }
247
248 reg32 = DMIBAR32(0x88);
249 reg32 |= (1 << 1) | (1 << 0);
250 DMIBAR32(0x88) = reg32;
251}
252
253static void northbridge_init(struct device *dev)
254{
255 u8 bios_reset_cpl;
256 u32 bridge_type;
257
258 northbridge_dmi_init(dev);
259
260 bridge_type = MCHBAR32(0x5f10);
261 bridge_type &= ~0xff;
262
263 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
264 /* Enable Power Aware Interrupt Routing */
265 u8 pair = MCHBAR8(0x5418);
266 pair &= ~0xf; /* Clear 3:0 */
267 pair |= 0x4; /* Fixed Priority */
268 MCHBAR8(0x5418) = pair;
269
270 /* 30h for IvyBridge */
271 bridge_type |= 0x30;
272 } else {
273 /* 20h for Sandybridge */
274 bridge_type |= 0x20;
275 }
276 MCHBAR32(0x5f10) = bridge_type;
277
278 /*
279 * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU
280 * that BIOS has initialized memory and power management
281 */
282 bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL);
283 bios_reset_cpl |= 1;
284 MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl;
285 printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n");
286
287 /* Configure turbo power limits 1ms after reset complete bit */
288 mdelay(1);
289#ifdef DISABLED
290 set_power_limits(28);
291
292 /*
293 * CPUs with configurable TDP also need power limits set
294 * in MCHBAR. Use same values from MSR_PKG_POWER_LIMIT.
295 */
296 if (cpu_config_tdp_levels()) {
297 msr_t msr = rdmsr(MSR_PKG_POWER_LIMIT);
298 MCHBAR32(0x59A0) = msr.lo;
299 MCHBAR32(0x59A4) = msr.hi;
300 }
301#endif
302 /* Set here before graphics PM init */
303 MCHBAR32(0x5500) = 0x00100001;
304}
305
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100306static struct pci_operations intel_pci_ops = {
307 .set_subsystem = intel_set_subsystem,
308};
309
310static struct device_operations mc_ops = {
311 .read_resources = mc_read_resources,
312 .set_resources = mc_set_resources,
313 .enable_resources = pci_dev_enable_resources,
314 .init = northbridge_init,
Vladimir Serbinenko0a669912014-10-05 14:34:17 +0200315 .acpi_fill_ssdt_generator = generate_cpu_entries,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100316 .scan_bus = 0,
317 .ops_pci = &intel_pci_ops,
318};
319
320static const struct pci_driver mc_driver_44 __pci_driver = {
321 .ops = &mc_ops,
322 .vendor = PCI_VENDOR_ID_INTEL,
323 .device = 0x0044, /* Nehalem */
324};
325
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100326static void cpu_bus_init(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100327{
328 initialize_cpus(dev->link_list);
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100329}
330
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100331static struct device_operations cpu_bus_ops = {
Edward O'Callaghan9f744622014-10-31 08:12:34 +1100332 .read_resources = DEVICE_NOOP,
333 .set_resources = DEVICE_NOOP,
334 .enable_resources = DEVICE_NOOP,
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100335 .init = cpu_bus_init,
336 .scan_bus = 0,
337};
338
Elyes HAOUAS706aabc2018-02-09 08:49:32 +0100339static void enable_dev(struct device *dev)
Vladimir Serbinenkoc6f6be02013-11-12 22:32:08 +0100340{
341 /* Set the operations if it is a special bus type */
342 if (dev->path.type == DEVICE_PATH_DOMAIN) {
343 dev->ops = &pci_domain_ops;
344 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
345 dev->ops = &cpu_bus_ops;
346 }
347}
348
349struct chip_operations northbridge_intel_nehalem_ops = {
350 CHIP_NAME("Intel i7 (Nehalem) integrated Northbridge")
351 .enable_dev = enable_dev,
352};