blob: 2b9e1553d3478cdfe23b50edff669bc457397828 [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.
Aaron Durbin76c37002012-10-30 09:03:43 -050015 */
16
17#include <console/console.h>
18#include <arch/acpi.h>
19#include <arch/io.h>
20#include <stdint.h>
21#include <delay.h>
22#include <cpu/intel/haswell/haswell.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050023#include <device/device.h>
24#include <device/pci.h>
25#include <device/pci_ids.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050026#include <stdlib.h>
27#include <string.h>
28#include <cpu/cpu.h>
Aaron Durbin1fef1f52012-12-19 17:15:43 -060029#include <cpu/x86/smm.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050030#include <boot/tables.h>
31#include <cbmem.h>
32#include "chip.h"
33#include "haswell.h"
34
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +020035static int get_pcie_bar(struct device *dev, unsigned int index, u32 *base,
36 u32 *len)
Aaron Durbin76c37002012-10-30 09:03:43 -050037{
Aaron Durbin76c37002012-10-30 09:03:43 -050038 u32 pciexbar_reg;
Ryan Salsamendifa0725d2017-06-30 17:29:37 -070039 u32 mask;
Aaron Durbin76c37002012-10-30 09:03:43 -050040
41 *base = 0;
42 *len = 0;
43
Aaron Durbinc12ef972012-12-18 14:22:49 -060044 pciexbar_reg = pci_read_config32(dev, index);
Aaron Durbin76c37002012-10-30 09:03:43 -050045
46 if (!(pciexbar_reg & (1 << 0)))
47 return 0;
48
49 switch ((pciexbar_reg >> 1) & 3) {
50 case 0: // 256MB
Ryan Salsamendifa0725d2017-06-30 17:29:37 -070051 mask = (1UL << 31) | (1 << 30) | (1 << 29) | (1 << 28);
52 *base = pciexbar_reg & mask;
Aaron Durbin76c37002012-10-30 09:03:43 -050053 *len = 256 * 1024 * 1024;
54 return 1;
55 case 1: // 128M
Ryan Salsamendifa0725d2017-06-30 17:29:37 -070056 mask = (1UL << 31) | (1 << 30) | (1 << 29) | (1 << 28);
57 mask |= (1 << 27);
58 *base = pciexbar_reg & mask;
Aaron Durbin76c37002012-10-30 09:03:43 -050059 *len = 128 * 1024 * 1024;
60 return 1;
61 case 2: // 64M
Ryan Salsamendifa0725d2017-06-30 17:29:37 -070062 mask = (1UL << 31) | (1 << 30) | (1 << 29) | (1 << 28);
63 mask |= (1 << 27) | (1 << 26);
64 *base = pciexbar_reg & mask;
Aaron Durbin76c37002012-10-30 09:03:43 -050065 *len = 64 * 1024 * 1024;
66 return 1;
67 }
68
69 return 0;
70}
71
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +020072static void pci_domain_set_resources(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -050073{
Aaron Durbin76c37002012-10-30 09:03:43 -050074 assign_resources(dev->link_list);
Aaron Durbin76c37002012-10-30 09:03:43 -050075}
76
Tristan Corrickf3127d42018-10-31 02:25:54 +130077static const char *northbridge_acpi_name(const struct device *dev)
78{
79 if (dev->path.type == DEVICE_PATH_DOMAIN)
80 return "PCI0";
81
82 if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0)
83 return NULL;
84
85 switch (dev->path.pci.devfn) {
86 case PCI_DEVFN(0, 0):
87 return "MCHC";
88 }
89
90 return NULL;
91}
92
Aaron Durbin76c37002012-10-30 09:03:43 -050093 /* TODO We could determine how many PCIe busses we need in
94 * the bar. For now that number is hardcoded to a max of 64.
95 * See e7525/northbridge.c for an example.
96 */
97static struct device_operations pci_domain_ops = {
98 .read_resources = pci_domain_read_resources,
99 .set_resources = pci_domain_set_resources,
100 .enable_resources = NULL,
101 .init = NULL,
102 .scan_bus = pci_domain_scan_bus,
Tristan Corrickf3127d42018-10-31 02:25:54 +1300103 .acpi_name = northbridge_acpi_name,
Matt DeVillier85d98d92018-03-04 01:41:23 -0600104 .write_acpi_tables = northbridge_write_acpi_tables,
Aaron Durbin76c37002012-10-30 09:03:43 -0500105};
106
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200107static int get_bar(struct device *dev, unsigned int index, u32 *base, u32 *len)
Aaron Durbin76c37002012-10-30 09:03:43 -0500108{
Aaron Durbinc12ef972012-12-18 14:22:49 -0600109 u32 bar;
Aaron Durbin76c37002012-10-30 09:03:43 -0500110
Aaron Durbinc12ef972012-12-18 14:22:49 -0600111 bar = pci_read_config32(dev, index);
Aaron Durbin76c37002012-10-30 09:03:43 -0500112
Aaron Durbinc12ef972012-12-18 14:22:49 -0600113 /* If not enabled don't report it. */
114 if (!(bar & 0x1))
115 return 0;
Aaron Durbin76c37002012-10-30 09:03:43 -0500116
Aaron Durbinc12ef972012-12-18 14:22:49 -0600117 /* Knock down the enable bit. */
118 *base = bar & ~1;
119
120 return 1;
Aaron Durbin76c37002012-10-30 09:03:43 -0500121}
122
Aaron Durbinc12ef972012-12-18 14:22:49 -0600123/* There are special BARs that actually are programmed in the MCHBAR. These
124 * Intel special features, but they do consume resources that need to be
125 * accounted for. */
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200126static int get_bar_in_mchbar(struct device *dev, unsigned int index,
127 u32 *base, u32 *len)
Aaron Durbin76c37002012-10-30 09:03:43 -0500128{
Aaron Durbinc12ef972012-12-18 14:22:49 -0600129 u32 bar;
Aaron Durbin76c37002012-10-30 09:03:43 -0500130
Aaron Durbinc12ef972012-12-18 14:22:49 -0600131 bar = MCHBAR32(index);
132
133 /* If not enabled don't report it. */
134 if (!(bar & 0x1))
135 return 0;
136
137 /* Knock down the enable bit. */
138 *base = bar & ~1;
139
140 return 1;
141}
142
143struct fixed_mmio_descriptor {
144 unsigned int index;
145 u32 size;
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200146 int (*get_resource)(struct device *dev, unsigned int index,
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200147 u32 *base, u32 *size);
Aaron Durbinc12ef972012-12-18 14:22:49 -0600148 const char *description;
149};
150
151#define SIZE_KB(x) ((x)*1024)
152struct fixed_mmio_descriptor mc_fixed_resources[] = {
153 { PCIEXBAR, SIZE_KB(0), get_pcie_bar, "PCIEXBAR" },
154 { MCHBAR, SIZE_KB(32), get_bar, "MCHBAR" },
155 { DMIBAR, SIZE_KB(4), get_bar, "DMIBAR" },
156 { EPBAR, SIZE_KB(4), get_bar, "EPBAR" },
157 { 0x5420, SIZE_KB(4), get_bar_in_mchbar, "GDXCBAR" },
158 { 0x5408, SIZE_KB(16), get_bar_in_mchbar, "EDRAMBAR" },
159};
160#undef SIZE_KB
161
162/*
163 * Add all known fixed MMIO ranges that hang off the host bridge/memory
164 * controller device.
165 */
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200166static void mc_add_fixed_mmio_resources(struct device *dev)
Aaron Durbinc12ef972012-12-18 14:22:49 -0600167{
168 int i;
169
170 for (i = 0; i < ARRAY_SIZE(mc_fixed_resources); i++) {
171 u32 base;
172 u32 size;
173 struct resource *resource;
174 unsigned int index;
175
176 size = mc_fixed_resources[i].size;
177 index = mc_fixed_resources[i].index;
178 if (!mc_fixed_resources[i].get_resource(dev, index,
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200179 &base, &size))
Aaron Durbinc12ef972012-12-18 14:22:49 -0600180 continue;
181
182 resource = new_resource(dev, mc_fixed_resources[i].index);
183 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED |
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200184 IORESOURCE_STORED | IORESOURCE_RESERVE |
185 IORESOURCE_ASSIGNED;
Aaron Durbinc12ef972012-12-18 14:22:49 -0600186 resource->base = base;
187 resource->size = size;
188 printk(BIOS_DEBUG, "%s: Adding %s @ %x 0x%08lx-0x%08lx.\n",
189 __func__, mc_fixed_resources[i].description, index,
190 (unsigned long)base, (unsigned long)(base + size - 1));
191 }
192}
193
194/* Host Memory Map:
195 *
196 * +--------------------------+ TOUUD
197 * | |
198 * +--------------------------+ 4GiB
199 * | PCI Address Space |
200 * +--------------------------+ TOLUD (also maps into MC address space)
201 * | iGD |
202 * +--------------------------+ BDSM
203 * | GTT |
204 * +--------------------------+ BGSM
205 * | TSEG |
206 * +--------------------------+ TSEGMB
207 * | Usage DRAM |
208 * +--------------------------+ 0
209 *
210 * Some of the base registers above can be equal making the size of those
211 * regions 0. The reason is because the memory controller internally subtracts
212 * the base registers from each other to determine sizes of the regions. In
213 * other words, the memory map is in a fixed order no matter what.
214 */
215
216struct map_entry {
217 int reg;
218 int is_64_bit;
219 int is_limit;
220 const char *description;
221};
222
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200223static void read_map_entry(struct device *dev, struct map_entry *entry,
224 uint64_t *result)
Aaron Durbinc12ef972012-12-18 14:22:49 -0600225{
226 uint64_t value;
227 uint64_t mask;
228
229 /* All registers are on a 1MiB granularity. */
230 mask = ((1ULL<<20)-1);
231 mask = ~mask;
232
233 value = 0;
234
235 if (entry->is_64_bit) {
236 value = pci_read_config32(dev, entry->reg + 4);
237 value <<= 32;
Aaron Durbin76c37002012-10-30 09:03:43 -0500238 }
239
Aaron Durbinc12ef972012-12-18 14:22:49 -0600240 value |= pci_read_config32(dev, entry->reg);
241 value &= mask;
242
243 if (entry->is_limit)
244 value |= ~mask;
245
246 *result = value;
247}
248
249#define MAP_ENTRY(reg_, is_64_, is_limit_, desc_) \
250 { \
251 .reg = reg_, \
252 .is_64_bit = is_64_, \
253 .is_limit = is_limit_, \
254 .description = desc_, \
255 }
256
257#define MAP_ENTRY_BASE_64(reg_, desc_) \
258 MAP_ENTRY(reg_, 1, 0, desc_)
259#define MAP_ENTRY_LIMIT_64(reg_, desc_) \
260 MAP_ENTRY(reg_, 1, 1, desc_)
261#define MAP_ENTRY_BASE_32(reg_, desc_) \
262 MAP_ENTRY(reg_, 0, 0, desc_)
263
264enum {
265 TOM_REG,
266 TOUUD_REG,
267 MESEG_BASE_REG,
268 MESEG_LIMIT_REG,
269 REMAP_BASE_REG,
270 REMAP_LIMIT_REG,
271 TOLUD_REG,
272 BGSM_REG,
273 BDSM_REG,
274 TSEG_REG,
275 // Must be last.
276 NUM_MAP_ENTRIES
277};
278
279static struct map_entry memory_map[NUM_MAP_ENTRIES] = {
280 [TOM_REG] = MAP_ENTRY_BASE_64(TOM, "TOM"),
281 [TOUUD_REG] = MAP_ENTRY_BASE_64(TOUUD, "TOUUD"),
282 [MESEG_BASE_REG] = MAP_ENTRY_BASE_64(MESEG_BASE, "MESEG_BASE"),
283 [MESEG_LIMIT_REG] = MAP_ENTRY_LIMIT_64(MESEG_LIMIT, "MESEG_LIMIT"),
284 [REMAP_BASE_REG] = MAP_ENTRY_BASE_64(REMAPBASE, "REMAP_BASE"),
285 [REMAP_LIMIT_REG] = MAP_ENTRY_LIMIT_64(REMAPLIMIT, "REMAP_LIMIT"),
286 [TOLUD_REG] = MAP_ENTRY_BASE_32(TOLUD, "TOLUD"),
Aaron Durbin15702602012-12-21 22:18:58 -0600287 [BDSM_REG] = MAP_ENTRY_BASE_32(BDSM, "BDSM"),
288 [BGSM_REG] = MAP_ENTRY_BASE_32(BGSM, "BGSM"),
Aaron Durbinc12ef972012-12-18 14:22:49 -0600289 [TSEG_REG] = MAP_ENTRY_BASE_32(TSEG, "TESGMB"),
290};
291
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200292static void mc_read_map_entries(struct device *dev, uint64_t *values)
Aaron Durbinc12ef972012-12-18 14:22:49 -0600293{
294 int i;
295 for (i = 0; i < NUM_MAP_ENTRIES; i++) {
296 read_map_entry(dev, &memory_map[i], &values[i]);
297 }
298}
299
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200300static void mc_report_map_entries(struct device *dev, uint64_t *values)
Aaron Durbinc12ef972012-12-18 14:22:49 -0600301{
302 int i;
303 for (i = 0; i < NUM_MAP_ENTRIES; i++) {
304 printk(BIOS_DEBUG, "MC MAP: %s: 0x%llx\n",
305 memory_map[i].description, values[i]);
306 }
307 /* One can validate the BDSM and BGSM against the GGC. */
308 printk(BIOS_DEBUG, "MC MAP: GGC: 0x%x\n", pci_read_config16(dev, GGC));
309}
310
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200311static void mc_add_dram_resources(struct device *dev, int *resource_cnt)
Aaron Durbinc12ef972012-12-18 14:22:49 -0600312{
313 unsigned long base_k, size_k;
Aaron Durbin27435d32013-06-03 09:46:56 -0500314 unsigned long touud_k;
Aaron Durbinc12ef972012-12-18 14:22:49 -0600315 unsigned long index;
316 struct resource *resource;
317 uint64_t mc_values[NUM_MAP_ENTRIES];
318
319 /* Read in the MAP registers and report their values. */
320 mc_read_map_entries(dev, &mc_values[0]);
321 mc_report_map_entries(dev, &mc_values[0]);
322
323 /*
Aaron Durbin1fef1f52012-12-19 17:15:43 -0600324 * These are the host memory ranges that should be added:
Aaron Durbin6a360042014-02-13 10:30:42 -0600325 * - 0 -> 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 */
Matt DeVilliera51e3792018-03-04 01:44:15 -0600353 index = *resource_cnt;
Aaron Durbinc12ef972012-12-18 14:22:49 -0600354
Aaron Durbin6a360042014-02-13 10:30:42 -0600355 /* 0 - > 0xa0000 */
Aaron Durbinc12ef972012-12-18 14:22:49 -0600356 base_k = 0;
Aaron Durbin1fef1f52012-12-19 17:15:43 -0600357 size_k = (0xa0000 >> 10) - base_k;
358 ram_resource(dev, index++, base_k, size_k);
359
360 /* 0xc0000 -> TSEG */
Aaron Durbinc12ef972012-12-18 14:22:49 -0600361 base_k = 0xc0000 >> 10;
362 size_k = (unsigned long)(mc_values[TSEG_REG] >> 10) - base_k;
363 ram_resource(dev, index++, base_k, size_k);
364
Aaron Durbine6c3b1d2012-12-21 21:22:07 -0600365 /* TSEG -> BGSM */
Aaron Durbinc12ef972012-12-18 14:22:49 -0600366 resource = new_resource(dev, index++);
367 resource->base = mc_values[TSEG_REG];
Aaron Durbine6c3b1d2012-12-21 21:22:07 -0600368 resource->size = mc_values[BGSM_REG] - resource->base;
369 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED |
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200370 IORESOURCE_STORED | IORESOURCE_RESERVE |
371 IORESOURCE_ASSIGNED | IORESOURCE_CACHEABLE;
Aaron Durbine6c3b1d2012-12-21 21:22:07 -0600372
373 /* BGSM -> TOLUD */
374 resource = new_resource(dev, index++);
375 resource->base = mc_values[BGSM_REG];
Aaron Durbinc12ef972012-12-18 14:22:49 -0600376 resource->size = mc_values[TOLUD_REG] - resource->base;
377 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED |
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200378 IORESOURCE_STORED | IORESOURCE_RESERVE |
379 IORESOURCE_ASSIGNED;
Aaron Durbinc12ef972012-12-18 14:22:49 -0600380
381 /* 4GiB -> TOUUD */
382 base_k = 4096 * 1024; /* 4GiB */
Aaron Durbin27435d32013-06-03 09:46:56 -0500383 touud_k = mc_values[TOUUD_REG] >> 10;
384 size_k = touud_k - base_k;
385 if (touud_k > base_k)
Aaron Durbin5c66f082013-01-08 10:10:33 -0600386 ram_resource(dev, index++, base_k, size_k);
Aaron Durbinc12ef972012-12-18 14:22:49 -0600387
Aaron Durbinc9650762013-03-22 22:03:09 -0500388 /* Reserve everything between A segment and 1MB:
389 *
390 * 0xa0000 - 0xbffff: legacy VGA
391 * 0xc0000 - 0xfffff: RAM
392 */
393 mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
394 reserved_ram_resource(dev, index++, (0xc0000 >> 10),
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200395 (0x100000 - 0xc0000) >> 10);
Martin Roth33232602017-06-24 14:48:50 -0600396#if IS_ENABLED(CONFIG_CHROMEOS_RAMOOPS)
Aaron Durbinc9650762013-03-22 22:03:09 -0500397 reserved_ram_resource(dev, index++,
398 CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10,
Aaron Durbinc12ef972012-12-18 14:22:49 -0600399 CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10);
400#endif
Matt DeVilliera51e3792018-03-04 01:44:15 -0600401 *resource_cnt = index;
Aaron Durbinc12ef972012-12-18 14:22:49 -0600402}
403
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200404static void mc_read_resources(struct device *dev)
Aaron Durbinc12ef972012-12-18 14:22:49 -0600405{
Matt DeVilliera51e3792018-03-04 01:44:15 -0600406 int index = 0;
407 const bool vtd_capable =
408 !(pci_read_config32(dev, CAPID0_A) & VTD_DISABLE);
409
Aaron Durbinc12ef972012-12-18 14:22:49 -0600410 /* Read standard PCI resources. */
411 pci_dev_read_resources(dev);
412
413 /* Add all fixed MMIO resources. */
414 mc_add_fixed_mmio_resources(dev);
415
Matt DeVilliera51e3792018-03-04 01:44:15 -0600416 /* Add VT-d MMIO resources if capable */
417 if (vtd_capable) {
418 mmio_resource(dev, index++, GFXVT_BASE_ADDRESS / KiB,
419 GFXVT_BASE_SIZE / KiB);
420 mmio_resource(dev, index++, VTVC0_BASE_ADDRESS / KiB,
421 VTVC0_BASE_SIZE / KiB);
422 }
423
Aaron Durbinc12ef972012-12-18 14:22:49 -0600424 /* Calculate and add DRAM resources. */
Matt DeVilliera51e3792018-03-04 01:44:15 -0600425 mc_add_dram_resources(dev, &index);
Aaron Durbin76c37002012-10-30 09:03:43 -0500426}
427
Elyes HAOUASb60920d2018-09-20 17:38:38 +0200428static void intel_set_subsystem(struct device *dev, unsigned int vendor,
429 unsigned int device)
Aaron Durbin76c37002012-10-30 09:03:43 -0500430{
431 if (!vendor || !device) {
432 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
433 pci_read_config32(dev, PCI_VENDOR_ID));
434 } else {
435 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
436 ((device & 0xffff) << 16) | (vendor & 0xffff));
437 }
438}
439
Aaron Durbin76c37002012-10-30 09:03:43 -0500440static void northbridge_init(struct device *dev)
441{
Duncan Lauriec70353f2013-06-28 14:40:38 -0700442 u8 bios_reset_cpl, pair;
Aaron Durbin76c37002012-10-30 09:03:43 -0500443
Duncan Lauriec70353f2013-06-28 14:40:38 -0700444 /* Enable Power Aware Interrupt Routing */
445 pair = MCHBAR8(0x5418);
446 pair &= ~0x7; /* Clear 2:0 */
447 pair |= 0x4; /* Fixed Priority */
448 MCHBAR8(0x5418) = pair;
Aaron Durbin76c37002012-10-30 09:03:43 -0500449
450 /*
Duncan Lauriec70353f2013-06-28 14:40:38 -0700451 * Set bits 0+1 of BIOS_RESET_CPL to indicate to the CPU
Aaron Durbin76c37002012-10-30 09:03:43 -0500452 * that BIOS has initialized memory and power management
453 */
454 bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL);
Duncan Lauriec70353f2013-06-28 14:40:38 -0700455 bios_reset_cpl |= 3;
Aaron Durbin76c37002012-10-30 09:03:43 -0500456 MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl;
457 printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n");
458
459 /* Configure turbo power limits 1ms after reset complete bit */
460 mdelay(1);
461 set_power_limits(28);
462
Aaron Durbin76c37002012-10-30 09:03:43 -0500463 /* Set here before graphics PM init */
464 MCHBAR32(0x5500) = 0x00100001;
465}
466
Aaron Durbin76c37002012-10-30 09:03:43 -0500467static struct pci_operations intel_pci_ops = {
468 .set_subsystem = intel_set_subsystem,
469};
470
471static struct device_operations mc_ops = {
472 .read_resources = mc_read_resources,
Aaron Durbinc12ef972012-12-18 14:22:49 -0600473 .set_resources = pci_dev_set_resources,
Aaron Durbin76c37002012-10-30 09:03:43 -0500474 .enable_resources = pci_dev_enable_resources,
475 .init = northbridge_init,
Vladimir Serbinenko0a669912014-10-05 14:34:17 +0200476 .acpi_fill_ssdt_generator = generate_cpu_entries,
Aaron Durbin76c37002012-10-30 09:03:43 -0500477 .scan_bus = 0,
478 .ops_pci = &intel_pci_ops,
479};
480
Tristan Corrickd3856242018-11-01 03:03:29 +1300481static const unsigned short mc_pci_device_ids[] = {
482 0x0c00, /* Desktop */
483 0x0c04, /* Mobile */
484 0x0a04, /* ULT */
485 0
Tristan Corrick48170122018-10-31 02:21:41 +1300486};
487
Tristan Corrickd3856242018-11-01 03:03:29 +1300488static const struct pci_driver mc_driver_hsw __pci_driver = {
489 .ops = &mc_ops,
490 .vendor = PCI_VENDOR_ID_INTEL,
491 .devices = mc_pci_device_ids,
Duncan Lauriedf7be712012-12-17 11:22:57 -0800492};
493
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200494static void cpu_bus_init(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500495{
Aaron Durbin7af20692013-01-14 14:54:41 -0600496 bsp_init_and_start_aps(dev->link_list);
Aaron Durbin76c37002012-10-30 09:03:43 -0500497}
498
Aaron Durbin76c37002012-10-30 09:03:43 -0500499static struct device_operations cpu_bus_ops = {
Edward O'Callaghan9f744622014-10-31 08:12:34 +1100500 .read_resources = DEVICE_NOOP,
501 .set_resources = DEVICE_NOOP,
502 .enable_resources = DEVICE_NOOP,
Aaron Durbin76c37002012-10-30 09:03:43 -0500503 .init = cpu_bus_init,
504 .scan_bus = 0,
505};
506
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200507static void enable_dev(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500508{
509 /* Set the operations if it is a special bus type */
510 if (dev->path.type == DEVICE_PATH_DOMAIN) {
511 dev->ops = &pci_domain_ops;
512 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
513 dev->ops = &cpu_bus_ops;
514 }
515}
516
517struct chip_operations northbridge_intel_haswell_ops = {
518 CHIP_NAME("Intel i7 (Haswell) integrated Northbridge")
519 .enable_dev = enable_dev,
520};