blob: 9f027343e49e084f5757de7f17ad90e17a6db4a7 [file] [log] [blame]
Aaron Durbin76c37002012-10-30 09:03:43 -05001/*
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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <console/console.h>
22#include <arch/acpi.h>
23#include <arch/io.h>
24#include <stdint.h>
25#include <delay.h>
26#include <cpu/intel/haswell/haswell.h>
27#include <cpu/x86/msr.h>
28#include <device/device.h>
29#include <device/pci.h>
30#include <device/pci_ids.h>
31#include <device/hypertransport.h>
32#include <stdlib.h>
33#include <string.h>
34#include <cpu/cpu.h>
Aaron Durbin1fef1f52012-12-19 17:15:43 -060035#include <cpu/x86/smm.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050036#include <boot/tables.h>
37#include <cbmem.h>
Aaron Durbinbf396ff2013-02-11 21:50:35 -060038#include <romstage_handoff.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050039#include "chip.h"
40#include "haswell.h"
41
42static int bridge_revision_id = -1;
43
44int bridge_silicon_revision(void)
45{
46 if (bridge_revision_id < 0) {
47 uint8_t stepping = cpuid_eax(1) & 0xf;
48 uint8_t bridge_id = pci_read_config16(
49 dev_find_slot(0, PCI_DEVFN(0, 0)),
50 PCI_DEVICE_ID) & 0xf0;
51 bridge_revision_id = bridge_id | stepping;
52 }
53 return bridge_revision_id;
54}
55
Aaron Durbinc12ef972012-12-18 14:22:49 -060056static int get_pcie_bar(device_t dev, unsigned int index, u32 *base, u32 *len)
Aaron Durbin76c37002012-10-30 09:03:43 -050057{
Aaron Durbin76c37002012-10-30 09:03:43 -050058 u32 pciexbar_reg;
59
60 *base = 0;
61 *len = 0;
62
Aaron Durbinc12ef972012-12-18 14:22:49 -060063 pciexbar_reg = pci_read_config32(dev, index);
Aaron Durbin76c37002012-10-30 09:03:43 -050064
65 if (!(pciexbar_reg & (1 << 0)))
66 return 0;
67
68 switch ((pciexbar_reg >> 1) & 3) {
69 case 0: // 256MB
70 *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28));
71 *len = 256 * 1024 * 1024;
72 return 1;
73 case 1: // 128M
74 *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
75 *len = 128 * 1024 * 1024;
76 return 1;
77 case 2: // 64M
78 *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26));
79 *len = 64 * 1024 * 1024;
80 return 1;
81 }
82
83 return 0;
84}
85
Aaron Durbin76c37002012-10-30 09:03:43 -050086static void pci_domain_set_resources(device_t dev)
87{
Aaron Durbin76c37002012-10-30 09:03:43 -050088 assign_resources(dev->link_list);
Aaron Durbin76c37002012-10-30 09:03:43 -050089}
90
91 /* TODO We could determine how many PCIe busses we need in
92 * the bar. For now that number is hardcoded to a max of 64.
93 * See e7525/northbridge.c for an example.
94 */
95static struct device_operations pci_domain_ops = {
96 .read_resources = pci_domain_read_resources,
97 .set_resources = pci_domain_set_resources,
98 .enable_resources = NULL,
99 .init = NULL,
100 .scan_bus = pci_domain_scan_bus,
Kyösti Mälkki872c9222013-07-03 09:44:28 +0300101 .ops_pci_bus = pci_bus_default_ops,
Aaron Durbin76c37002012-10-30 09:03:43 -0500102};
103
Aaron Durbinc12ef972012-12-18 14:22:49 -0600104static int get_bar(device_t dev, unsigned int index, u32 *base, u32 *len)
Aaron Durbin76c37002012-10-30 09:03:43 -0500105{
Aaron Durbinc12ef972012-12-18 14:22:49 -0600106 u32 bar;
Aaron Durbin76c37002012-10-30 09:03:43 -0500107
Aaron Durbinc12ef972012-12-18 14:22:49 -0600108 bar = pci_read_config32(dev, index);
Aaron Durbin76c37002012-10-30 09:03:43 -0500109
Aaron Durbinc12ef972012-12-18 14:22:49 -0600110 /* If not enabled don't report it. */
111 if (!(bar & 0x1))
112 return 0;
Aaron Durbin76c37002012-10-30 09:03:43 -0500113
Aaron Durbinc12ef972012-12-18 14:22:49 -0600114 /* Knock down the enable bit. */
115 *base = bar & ~1;
116
117 return 1;
Aaron Durbin76c37002012-10-30 09:03:43 -0500118}
119
Aaron Durbinc12ef972012-12-18 14:22:49 -0600120/* There are special BARs that actually are programmed in the MCHBAR. These
121 * Intel special features, but they do consume resources that need to be
122 * accounted for. */
123static int get_bar_in_mchbar(device_t dev, unsigned int index, u32 *base,
124 u32 *len)
Aaron Durbin76c37002012-10-30 09:03:43 -0500125{
Aaron Durbinc12ef972012-12-18 14:22:49 -0600126 u32 bar;
Aaron Durbin76c37002012-10-30 09:03:43 -0500127
Aaron Durbinc12ef972012-12-18 14:22:49 -0600128 bar = MCHBAR32(index);
129
130 /* If not enabled don't report it. */
131 if (!(bar & 0x1))
132 return 0;
133
134 /* Knock down the enable bit. */
135 *base = bar & ~1;
136
137 return 1;
138}
139
140struct fixed_mmio_descriptor {
141 unsigned int index;
142 u32 size;
143 int (*get_resource)(device_t dev, unsigned int index,
144 u32 *base, u32 *size);
145 const char *description;
146};
147
148#define SIZE_KB(x) ((x)*1024)
149struct fixed_mmio_descriptor mc_fixed_resources[] = {
150 { PCIEXBAR, SIZE_KB(0), get_pcie_bar, "PCIEXBAR" },
151 { MCHBAR, SIZE_KB(32), get_bar, "MCHBAR" },
152 { DMIBAR, SIZE_KB(4), get_bar, "DMIBAR" },
153 { EPBAR, SIZE_KB(4), get_bar, "EPBAR" },
154 { 0x5420, SIZE_KB(4), get_bar_in_mchbar, "GDXCBAR" },
155 { 0x5408, SIZE_KB(16), get_bar_in_mchbar, "EDRAMBAR" },
156};
157#undef SIZE_KB
158
159/*
160 * Add all known fixed MMIO ranges that hang off the host bridge/memory
161 * controller device.
162 */
163static void mc_add_fixed_mmio_resources(device_t dev)
164{
165 int i;
166
167 for (i = 0; i < ARRAY_SIZE(mc_fixed_resources); i++) {
168 u32 base;
169 u32 size;
170 struct resource *resource;
171 unsigned int index;
172
173 size = mc_fixed_resources[i].size;
174 index = mc_fixed_resources[i].index;
175 if (!mc_fixed_resources[i].get_resource(dev, index,
176 &base, &size))
177 continue;
178
179 resource = new_resource(dev, mc_fixed_resources[i].index);
180 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED |
181 IORESOURCE_STORED | IORESOURCE_RESERVE |
182 IORESOURCE_ASSIGNED;
183 resource->base = base;
184 resource->size = size;
185 printk(BIOS_DEBUG, "%s: Adding %s @ %x 0x%08lx-0x%08lx.\n",
186 __func__, mc_fixed_resources[i].description, index,
187 (unsigned long)base, (unsigned long)(base + size - 1));
188 }
189}
190
191/* Host Memory Map:
192 *
193 * +--------------------------+ TOUUD
194 * | |
195 * +--------------------------+ 4GiB
196 * | PCI Address Space |
197 * +--------------------------+ TOLUD (also maps into MC address space)
198 * | iGD |
199 * +--------------------------+ BDSM
200 * | GTT |
201 * +--------------------------+ BGSM
202 * | TSEG |
203 * +--------------------------+ TSEGMB
204 * | Usage DRAM |
205 * +--------------------------+ 0
206 *
207 * Some of the base registers above can be equal making the size of those
208 * regions 0. The reason is because the memory controller internally subtracts
209 * the base registers from each other to determine sizes of the regions. In
210 * other words, the memory map is in a fixed order no matter what.
211 */
212
213struct map_entry {
214 int reg;
215 int is_64_bit;
216 int is_limit;
217 const char *description;
218};
219
220static void read_map_entry(device_t dev, struct map_entry *entry,
221 uint64_t *result)
222{
223 uint64_t value;
224 uint64_t mask;
225
226 /* All registers are on a 1MiB granularity. */
227 mask = ((1ULL<<20)-1);
228 mask = ~mask;
229
230 value = 0;
231
232 if (entry->is_64_bit) {
233 value = pci_read_config32(dev, entry->reg + 4);
234 value <<= 32;
Aaron Durbin76c37002012-10-30 09:03:43 -0500235 }
236
Aaron Durbinc12ef972012-12-18 14:22:49 -0600237 value |= pci_read_config32(dev, entry->reg);
238 value &= mask;
239
240 if (entry->is_limit)
241 value |= ~mask;
242
243 *result = value;
244}
245
246#define MAP_ENTRY(reg_, is_64_, is_limit_, desc_) \
247 { \
248 .reg = reg_, \
249 .is_64_bit = is_64_, \
250 .is_limit = is_limit_, \
251 .description = desc_, \
252 }
253
254#define MAP_ENTRY_BASE_64(reg_, desc_) \
255 MAP_ENTRY(reg_, 1, 0, desc_)
256#define MAP_ENTRY_LIMIT_64(reg_, desc_) \
257 MAP_ENTRY(reg_, 1, 1, desc_)
258#define MAP_ENTRY_BASE_32(reg_, desc_) \
259 MAP_ENTRY(reg_, 0, 0, desc_)
260
261enum {
262 TOM_REG,
263 TOUUD_REG,
264 MESEG_BASE_REG,
265 MESEG_LIMIT_REG,
266 REMAP_BASE_REG,
267 REMAP_LIMIT_REG,
268 TOLUD_REG,
269 BGSM_REG,
270 BDSM_REG,
271 TSEG_REG,
272 // Must be last.
273 NUM_MAP_ENTRIES
274};
275
276static struct map_entry memory_map[NUM_MAP_ENTRIES] = {
277 [TOM_REG] = MAP_ENTRY_BASE_64(TOM, "TOM"),
278 [TOUUD_REG] = MAP_ENTRY_BASE_64(TOUUD, "TOUUD"),
279 [MESEG_BASE_REG] = MAP_ENTRY_BASE_64(MESEG_BASE, "MESEG_BASE"),
280 [MESEG_LIMIT_REG] = MAP_ENTRY_LIMIT_64(MESEG_LIMIT, "MESEG_LIMIT"),
281 [REMAP_BASE_REG] = MAP_ENTRY_BASE_64(REMAPBASE, "REMAP_BASE"),
282 [REMAP_LIMIT_REG] = MAP_ENTRY_LIMIT_64(REMAPLIMIT, "REMAP_LIMIT"),
283 [TOLUD_REG] = MAP_ENTRY_BASE_32(TOLUD, "TOLUD"),
Aaron Durbin15702602012-12-21 22:18:58 -0600284 [BDSM_REG] = MAP_ENTRY_BASE_32(BDSM, "BDSM"),
285 [BGSM_REG] = MAP_ENTRY_BASE_32(BGSM, "BGSM"),
Aaron Durbinc12ef972012-12-18 14:22:49 -0600286 [TSEG_REG] = MAP_ENTRY_BASE_32(TSEG, "TESGMB"),
287};
288
289static void mc_read_map_entries(device_t dev, uint64_t *values)
290{
291 int i;
292 for (i = 0; i < NUM_MAP_ENTRIES; i++) {
293 read_map_entry(dev, &memory_map[i], &values[i]);
294 }
295}
296
297static void mc_report_map_entries(device_t dev, uint64_t *values)
298{
299 int i;
300 for (i = 0; i < NUM_MAP_ENTRIES; i++) {
301 printk(BIOS_DEBUG, "MC MAP: %s: 0x%llx\n",
302 memory_map[i].description, values[i]);
303 }
304 /* One can validate the BDSM and BGSM against the GGC. */
305 printk(BIOS_DEBUG, "MC MAP: GGC: 0x%x\n", pci_read_config16(dev, GGC));
306}
307
308static void mc_add_dram_resources(device_t dev)
309{
310 unsigned long base_k, size_k;
Aaron Durbin27435d32013-06-03 09:46:56 -0500311 unsigned long touud_k;
Aaron Durbinc12ef972012-12-18 14:22:49 -0600312 unsigned long index;
313 struct resource *resource;
314 uint64_t mc_values[NUM_MAP_ENTRIES];
315
316 /* Read in the MAP registers and report their values. */
317 mc_read_map_entries(dev, &mc_values[0]);
318 mc_report_map_entries(dev, &mc_values[0]);
319
320 /*
Aaron Durbin1fef1f52012-12-19 17:15:43 -0600321 * These are the host memory ranges that should be added:
322 * - 0 -> SMM_DEFAULT_BASE : cacheable
323 * - SMM_DEFAULT_BASE -> SMM_DEFAULT_BASE + SMM_DEFAULT_SIZE :
324 * cacheable and reserved
325 * - SMM_DEFAULT_BASE + SMM_DEFAULT_SIZE -> 0xa0000 : cacheable
Aaron Durbinc12ef972012-12-18 14:22:49 -0600326 * - 0xc0000 -> TSEG : cacheable
Aaron Durbine6c3b1d2012-12-21 21:22:07 -0600327 * - TESG -> BGSM: cacheable with standard MTRRs and reserved
328 * - BGSM -> TOLUD: not cacheable with standard MTRRs and reserved
Aaron Durbinc12ef972012-12-18 14:22:49 -0600329 * - 4GiB -> TOUUD: cacheable
330 *
Aaron Durbin1fef1f52012-12-19 17:15:43 -0600331 * The default SMRAM space is reserved so that the range doesn't
332 * have to be saved during S3 Resume. Once marked reserved the OS
333 * cannot use the memory. This is a bit of an odd place to reserve
334 * the region, but the CPU devices don't have dev_ops->read_resources()
335 * called on them.
336 *
Aaron Durbinc12ef972012-12-18 14:22:49 -0600337 * The range 0xa0000 -> 0xc0000 does not have any resources
338 * associated with it to handle legacy VGA memory. If this range
339 * is not omitted the mtrr code will setup the area as cacheable
340 * causing VGA access to not work.
341 *
Aaron Durbine6c3b1d2012-12-21 21:22:07 -0600342 * The TSEG region is mapped as cacheable so that one can perform
343 * SMRAM relocation faster. Once the SMRR is enabled the SMRR takes
344 * precedence over the existing MTRRs covering this region.
345 *
Aaron Durbin1fef1f52012-12-19 17:15:43 -0600346 * It should be noted that cacheable entry types need to be added in
347 * order. The reason is that the current MTRR code assumes this and
348 * falls over itself if it isn't.
349 *
Aaron Durbinc12ef972012-12-18 14:22:49 -0600350 * The resource index starts low and should not meet or exceed
Aaron Durbin1fef1f52012-12-19 17:15:43 -0600351 * PCI_BASE_ADDRESS_0.
Aaron Durbinc12ef972012-12-18 14:22:49 -0600352 */
353 index = 0;
354
Aaron Durbin1fef1f52012-12-19 17:15:43 -0600355 /* 0 - > SMM_DEFAULT_BASE */
Aaron Durbinc12ef972012-12-18 14:22:49 -0600356 base_k = 0;
Aaron Durbin1fef1f52012-12-19 17:15:43 -0600357 size_k = SMM_DEFAULT_BASE >> 10;
Aaron Durbinc12ef972012-12-18 14:22:49 -0600358 ram_resource(dev, index++, base_k, size_k);
359
Aaron Durbin1fef1f52012-12-19 17:15:43 -0600360 /* SMM_DEFAULT_BASE -> SMM_DEFAULT_BASE + SMM_DEFAULT_SIZE */
361 resource = new_resource(dev, index++);
362 resource->base = SMM_DEFAULT_BASE;
363 resource->size = SMM_DEFAULT_SIZE;
364 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED |
365 IORESOURCE_CACHEABLE | IORESOURCE_STORED |
366 IORESOURCE_RESERVE | IORESOURCE_ASSIGNED;
367
368 /* SMM_DEFAULT_BASE + SMM_DEFAULT_SIZE -> 0xa0000 */
369 base_k = (SMM_DEFAULT_BASE + SMM_DEFAULT_SIZE) >> 10;
370 size_k = (0xa0000 >> 10) - base_k;
371 ram_resource(dev, index++, base_k, size_k);
372
373 /* 0xc0000 -> TSEG */
Aaron Durbinc12ef972012-12-18 14:22:49 -0600374 base_k = 0xc0000 >> 10;
375 size_k = (unsigned long)(mc_values[TSEG_REG] >> 10) - base_k;
376 ram_resource(dev, index++, base_k, size_k);
377
Aaron Durbine6c3b1d2012-12-21 21:22:07 -0600378 /* TSEG -> BGSM */
Aaron Durbinc12ef972012-12-18 14:22:49 -0600379 resource = new_resource(dev, index++);
380 resource->base = mc_values[TSEG_REG];
Aaron Durbine6c3b1d2012-12-21 21:22:07 -0600381 resource->size = mc_values[BGSM_REG] - resource->base;
382 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED |
383 IORESOURCE_STORED | IORESOURCE_RESERVE |
384 IORESOURCE_ASSIGNED | IORESOURCE_CACHEABLE;
385
386 /* BGSM -> TOLUD */
387 resource = new_resource(dev, index++);
388 resource->base = mc_values[BGSM_REG];
Aaron Durbinc12ef972012-12-18 14:22:49 -0600389 resource->size = mc_values[TOLUD_REG] - resource->base;
390 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED |
391 IORESOURCE_STORED | IORESOURCE_RESERVE |
392 IORESOURCE_ASSIGNED;
393
394 /* 4GiB -> TOUUD */
395 base_k = 4096 * 1024; /* 4GiB */
Aaron Durbin27435d32013-06-03 09:46:56 -0500396 touud_k = mc_values[TOUUD_REG] >> 10;
397 size_k = touud_k - base_k;
398 if (touud_k > base_k)
Aaron Durbin5c66f082013-01-08 10:10:33 -0600399 ram_resource(dev, index++, base_k, size_k);
Aaron Durbinc12ef972012-12-18 14:22:49 -0600400
Aaron Durbinc9650762013-03-22 22:03:09 -0500401 /* Reserve everything between A segment and 1MB:
402 *
403 * 0xa0000 - 0xbffff: legacy VGA
404 * 0xc0000 - 0xfffff: RAM
405 */
406 mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
407 reserved_ram_resource(dev, index++, (0xc0000 >> 10),
408 (0x100000 - 0xc0000) >> 10);
Aaron Durbinc12ef972012-12-18 14:22:49 -0600409#if CONFIG_CHROMEOS_RAMOOPS
Aaron Durbinc9650762013-03-22 22:03:09 -0500410 reserved_ram_resource(dev, index++,
411 CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10,
Aaron Durbinc12ef972012-12-18 14:22:49 -0600412 CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10);
413#endif
Aaron Durbinc12ef972012-12-18 14:22:49 -0600414}
415
416static void mc_read_resources(device_t dev)
417{
418 /* Read standard PCI resources. */
419 pci_dev_read_resources(dev);
420
421 /* Add all fixed MMIO resources. */
422 mc_add_fixed_mmio_resources(dev);
423
424 /* Calculate and add DRAM resources. */
425 mc_add_dram_resources(dev);
Aaron Durbin76c37002012-10-30 09:03:43 -0500426}
427
428static void intel_set_subsystem(device_t dev, unsigned vendor, unsigned device)
429{
430 if (!vendor || !device) {
431 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
432 pci_read_config32(dev, PCI_VENDOR_ID));
433 } else {
434 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
435 ((device & 0xffff) << 16) | (vendor & 0xffff));
436 }
437}
438
439static void northbridge_dmi_init(struct device *dev)
440{
441 u32 reg32;
442
443 /* Clear error status bits */
444 DMIBAR32(0x1c4) = 0xffffffff;
445 DMIBAR32(0x1d0) = 0xffffffff;
446
447 /* Steps prior to DMI ASPM */
448 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
449 reg32 = DMIBAR32(0x250);
450 reg32 &= ~((1 << 22)|(1 << 20));
451 reg32 |= (1 << 21);
452 DMIBAR32(0x250) = reg32;
453 }
454
455 reg32 = DMIBAR32(0x238);
456 reg32 |= (1 << 29);
457 DMIBAR32(0x238) = reg32;
458
459 if (bridge_silicon_revision() >= SNB_STEP_D0) {
460 reg32 = DMIBAR32(0x1f8);
461 reg32 |= (1 << 16);
462 DMIBAR32(0x1f8) = reg32;
463 } else if (bridge_silicon_revision() >= SNB_STEP_D1) {
464 reg32 = DMIBAR32(0x1f8);
465 reg32 &= ~(1 << 26);
466 reg32 |= (1 << 16);
467 DMIBAR32(0x1f8) = reg32;
468
469 reg32 = DMIBAR32(0x1fc);
470 reg32 |= (1 << 12) | (1 << 23);
471 DMIBAR32(0x1fc) = reg32;
472 }
473
474 /* Enable ASPM on SNB link, should happen before PCH link */
475 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) {
476 reg32 = DMIBAR32(0xd04);
477 reg32 |= (1 << 4);
478 DMIBAR32(0xd04) = reg32;
479 }
480
481 reg32 = DMIBAR32(0x88);
482 reg32 |= (1 << 1) | (1 << 0);
483 DMIBAR32(0x88) = reg32;
484}
485
486static void northbridge_init(struct device *dev)
487{
488 u8 bios_reset_cpl;
489 u32 bridge_type;
490
491 northbridge_dmi_init(dev);
492
493 bridge_type = MCHBAR32(0x5f10);
494 bridge_type &= ~0xff;
495
496 if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) {
497 /* Enable Power Aware Interrupt Routing */
498 u8 pair = MCHBAR8(0x5418);
499 pair &= ~0xf; /* Clear 3:0 */
500 pair |= 0x4; /* Fixed Priority */
501 MCHBAR8(0x5418) = pair;
502
503 /* 30h for IvyBridge */
504 bridge_type |= 0x30;
505 } else {
506 /* 20h for Sandybridge */
507 bridge_type |= 0x20;
508 }
509 MCHBAR32(0x5f10) = bridge_type;
510
511 /*
512 * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU
513 * that BIOS has initialized memory and power management
514 */
515 bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL);
516 bios_reset_cpl |= 1;
517 MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl;
518 printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n");
519
520 /* Configure turbo power limits 1ms after reset complete bit */
521 mdelay(1);
522 set_power_limits(28);
523
524 /*
525 * CPUs with configurable TDP also need power limits set
526 * in MCHBAR. Use same values from MSR_PKG_POWER_LIMIT.
527 */
528 if (cpu_config_tdp_levels()) {
529 msr_t msr = rdmsr(MSR_PKG_POWER_LIMIT);
530 MCHBAR32(0x59A0) = msr.lo;
531 MCHBAR32(0x59A4) = msr.hi;
532 }
533
534 /* Set here before graphics PM init */
535 MCHBAR32(0x5500) = 0x00100001;
536}
537
Aaron Durbinc0cbd6e2013-03-13 13:51:20 -0500538void *cbmem_top(void)
539{
540 u32 reg;
541
542 /* The top the reserve regions fall just below the TSEG region. */
543 reg = pci_read_config32(dev_find_slot(0, PCI_DEVFN(0, 0)), TSEG);
544
545 return (void *)(reg & ~((1 << 20) - 1));
546}
547
Aaron Durbin76c37002012-10-30 09:03:43 -0500548static void northbridge_enable(device_t dev)
549{
550#if CONFIG_HAVE_ACPI_RESUME
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600551 struct romstage_handoff *handoff;
552
553 handoff = cbmem_find(CBMEM_ID_ROMSTAGE_INFO);
554
555 if (handoff == NULL) {
Aaron Durbin76c37002012-10-30 09:03:43 -0500556 printk(BIOS_DEBUG, "Unknown boot method, assuming normal.\n");
Aaron Durbinbf396ff2013-02-11 21:50:35 -0600557 acpi_slp_type = 0;
558 } else if (handoff->s3_resume) {
559 printk(BIOS_DEBUG, "S3 Resume.\n");
560 acpi_slp_type = 3;
561 } else {
562 printk(BIOS_DEBUG, "Normal boot.\n");
563 acpi_slp_type = 0;
Aaron Durbin76c37002012-10-30 09:03:43 -0500564 }
565#endif
566}
567
568static struct pci_operations intel_pci_ops = {
569 .set_subsystem = intel_set_subsystem,
570};
571
572static struct device_operations mc_ops = {
573 .read_resources = mc_read_resources,
Aaron Durbinc12ef972012-12-18 14:22:49 -0600574 .set_resources = pci_dev_set_resources,
Aaron Durbin76c37002012-10-30 09:03:43 -0500575 .enable_resources = pci_dev_enable_resources,
576 .init = northbridge_init,
577 .enable = northbridge_enable,
578 .scan_bus = 0,
579 .ops_pci = &intel_pci_ops,
580};
581
Aaron Durbinc1989c42012-12-11 17:13:17 -0600582static const struct pci_driver mc_driver_hsw_mobile __pci_driver = {
Aaron Durbin76c37002012-10-30 09:03:43 -0500583 .ops = &mc_ops,
584 .vendor = PCI_VENDOR_ID_INTEL,
Aaron Durbin21efd8c2013-01-17 09:39:39 -0600585 .device = PCI_DEVICE_ID_HSW_MOBILE,
Aaron Durbin76c37002012-10-30 09:03:43 -0500586};
587
Duncan Lauriedf7be712012-12-17 11:22:57 -0800588static const struct pci_driver mc_driver_hsw_ult __pci_driver = {
589 .ops = &mc_ops,
590 .vendor = PCI_VENDOR_ID_INTEL,
Aaron Durbin21efd8c2013-01-17 09:39:39 -0600591 .device = PCI_DEVICE_ID_HSW_ULT,
Duncan Lauriedf7be712012-12-17 11:22:57 -0800592};
593
Aaron Durbin76c37002012-10-30 09:03:43 -0500594static void cpu_bus_init(device_t dev)
595{
Aaron Durbin7af20692013-01-14 14:54:41 -0600596 bsp_init_and_start_aps(dev->link_list);
Aaron Durbin76c37002012-10-30 09:03:43 -0500597}
598
599static void cpu_bus_noop(device_t dev)
600{
601}
602
603static struct device_operations cpu_bus_ops = {
604 .read_resources = cpu_bus_noop,
605 .set_resources = cpu_bus_noop,
606 .enable_resources = cpu_bus_noop,
607 .init = cpu_bus_init,
608 .scan_bus = 0,
609};
610
611static void enable_dev(device_t dev)
612{
613 /* Set the operations if it is a special bus type */
614 if (dev->path.type == DEVICE_PATH_DOMAIN) {
615 dev->ops = &pci_domain_ops;
616 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
617 dev->ops = &cpu_bus_ops;
618 }
619}
620
621struct chip_operations northbridge_intel_haswell_ops = {
622 CHIP_NAME("Intel i7 (Haswell) integrated Northbridge")
623 .enable_dev = enable_dev,
624};