blob: fcdb683320c165278b91af5b0a53362f98bd09b6 [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
Tristan Corrickbc896cd2018-12-17 22:09:50 +130017#include <commonlib/helpers.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050018#include <console/console.h>
19#include <arch/acpi.h>
20#include <arch/io.h>
21#include <stdint.h>
22#include <delay.h>
23#include <cpu/intel/haswell/haswell.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050024#include <device/device.h>
25#include <device/pci.h>
Tristan Corrickbc896cd2018-12-17 22:09:50 +130026#include <device/pci_def.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050027#include <device/pci_ids.h>
Tristan Corrickbc896cd2018-12-17 22:09:50 +130028#include <device/pci_ops.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050029#include <stdlib.h>
30#include <string.h>
Aaron Durbin1fef1f52012-12-19 17:15:43 -060031#include <cpu/x86/smm.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050032#include <boot/tables.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050033#include "chip.h"
34#include "haswell.h"
35
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +020036static int get_pcie_bar(struct device *dev, unsigned int index, u32 *base,
37 u32 *len)
Aaron Durbin76c37002012-10-30 09:03:43 -050038{
Aaron Durbin76c37002012-10-30 09:03:43 -050039 u32 pciexbar_reg;
Ryan Salsamendifa0725d2017-06-30 17:29:37 -070040 u32 mask;
Aaron Durbin76c37002012-10-30 09:03:43 -050041
42 *base = 0;
43 *len = 0;
44
Aaron Durbinc12ef972012-12-18 14:22:49 -060045 pciexbar_reg = pci_read_config32(dev, index);
Aaron Durbin76c37002012-10-30 09:03:43 -050046
47 if (!(pciexbar_reg & (1 << 0)))
48 return 0;
49
50 switch ((pciexbar_reg >> 1) & 3) {
51 case 0: // 256MB
Ryan Salsamendifa0725d2017-06-30 17:29:37 -070052 mask = (1UL << 31) | (1 << 30) | (1 << 29) | (1 << 28);
53 *base = pciexbar_reg & mask;
Aaron Durbin76c37002012-10-30 09:03:43 -050054 *len = 256 * 1024 * 1024;
55 return 1;
56 case 1: // 128M
Ryan Salsamendifa0725d2017-06-30 17:29:37 -070057 mask = (1UL << 31) | (1 << 30) | (1 << 29) | (1 << 28);
58 mask |= (1 << 27);
59 *base = pciexbar_reg & mask;
Aaron Durbin76c37002012-10-30 09:03:43 -050060 *len = 128 * 1024 * 1024;
61 return 1;
62 case 2: // 64M
Ryan Salsamendifa0725d2017-06-30 17:29:37 -070063 mask = (1UL << 31) | (1 << 30) | (1 << 29) | (1 << 28);
64 mask |= (1 << 27) | (1 << 26);
65 *base = pciexbar_reg & mask;
Aaron Durbin76c37002012-10-30 09:03:43 -050066 *len = 64 * 1024 * 1024;
67 return 1;
68 }
69
70 return 0;
71}
72
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +020073static void pci_domain_set_resources(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -050074{
Aaron Durbin76c37002012-10-30 09:03:43 -050075 assign_resources(dev->link_list);
Aaron Durbin76c37002012-10-30 09:03:43 -050076}
77
Tristan Corrickf3127d42018-10-31 02:25:54 +130078static const char *northbridge_acpi_name(const struct device *dev)
79{
80 if (dev->path.type == DEVICE_PATH_DOMAIN)
81 return "PCI0";
82
83 if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0)
84 return NULL;
85
86 switch (dev->path.pci.devfn) {
87 case PCI_DEVFN(0, 0):
88 return "MCHC";
89 }
90
91 return NULL;
92}
93
Aaron Durbin76c37002012-10-30 09:03:43 -050094 /* TODO We could determine how many PCIe busses we need in
95 * the bar. For now that number is hardcoded to a max of 64.
96 * See e7525/northbridge.c for an example.
97 */
98static struct device_operations pci_domain_ops = {
99 .read_resources = pci_domain_read_resources,
100 .set_resources = pci_domain_set_resources,
101 .enable_resources = NULL,
102 .init = NULL,
103 .scan_bus = pci_domain_scan_bus,
Tristan Corrickf3127d42018-10-31 02:25:54 +1300104 .acpi_name = northbridge_acpi_name,
Matt DeVillier85d98d92018-03-04 01:41:23 -0600105 .write_acpi_tables = northbridge_write_acpi_tables,
Aaron Durbin76c37002012-10-30 09:03:43 -0500106};
107
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200108static int get_bar(struct device *dev, unsigned int index, u32 *base, u32 *len)
Aaron Durbin76c37002012-10-30 09:03:43 -0500109{
Aaron Durbinc12ef972012-12-18 14:22:49 -0600110 u32 bar;
Aaron Durbin76c37002012-10-30 09:03:43 -0500111
Aaron Durbinc12ef972012-12-18 14:22:49 -0600112 bar = pci_read_config32(dev, index);
Aaron Durbin76c37002012-10-30 09:03:43 -0500113
Aaron Durbinc12ef972012-12-18 14:22:49 -0600114 /* If not enabled don't report it. */
115 if (!(bar & 0x1))
116 return 0;
Aaron Durbin76c37002012-10-30 09:03:43 -0500117
Aaron Durbinc12ef972012-12-18 14:22:49 -0600118 /* Knock down the enable bit. */
119 *base = bar & ~1;
120
121 return 1;
Aaron Durbin76c37002012-10-30 09:03:43 -0500122}
123
Aaron Durbinc12ef972012-12-18 14:22:49 -0600124/* There are special BARs that actually are programmed in the MCHBAR. These
125 * Intel special features, but they do consume resources that need to be
126 * accounted for. */
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200127static int get_bar_in_mchbar(struct device *dev, unsigned int index,
128 u32 *base, u32 *len)
Aaron Durbin76c37002012-10-30 09:03:43 -0500129{
Aaron Durbinc12ef972012-12-18 14:22:49 -0600130 u32 bar;
Aaron Durbin76c37002012-10-30 09:03:43 -0500131
Aaron Durbinc12ef972012-12-18 14:22:49 -0600132 bar = MCHBAR32(index);
133
134 /* If not enabled don't report it. */
135 if (!(bar & 0x1))
136 return 0;
137
138 /* Knock down the enable bit. */
139 *base = bar & ~1;
140
141 return 1;
142}
143
144struct fixed_mmio_descriptor {
145 unsigned int index;
146 u32 size;
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200147 int (*get_resource)(struct device *dev, unsigned int index,
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200148 u32 *base, u32 *size);
Aaron Durbinc12ef972012-12-18 14:22:49 -0600149 const char *description;
150};
151
152#define SIZE_KB(x) ((x)*1024)
153struct fixed_mmio_descriptor mc_fixed_resources[] = {
154 { PCIEXBAR, SIZE_KB(0), get_pcie_bar, "PCIEXBAR" },
155 { MCHBAR, SIZE_KB(32), get_bar, "MCHBAR" },
156 { DMIBAR, SIZE_KB(4), get_bar, "DMIBAR" },
157 { EPBAR, SIZE_KB(4), get_bar, "EPBAR" },
158 { 0x5420, SIZE_KB(4), get_bar_in_mchbar, "GDXCBAR" },
159 { 0x5408, SIZE_KB(16), get_bar_in_mchbar, "EDRAMBAR" },
160};
161#undef SIZE_KB
162
163/*
164 * Add all known fixed MMIO ranges that hang off the host bridge/memory
165 * controller device.
166 */
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200167static void mc_add_fixed_mmio_resources(struct device *dev)
Aaron Durbinc12ef972012-12-18 14:22:49 -0600168{
169 int i;
170
171 for (i = 0; i < ARRAY_SIZE(mc_fixed_resources); i++) {
172 u32 base;
173 u32 size;
174 struct resource *resource;
175 unsigned int index;
176
177 size = mc_fixed_resources[i].size;
178 index = mc_fixed_resources[i].index;
179 if (!mc_fixed_resources[i].get_resource(dev, index,
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200180 &base, &size))
Aaron Durbinc12ef972012-12-18 14:22:49 -0600181 continue;
182
183 resource = new_resource(dev, mc_fixed_resources[i].index);
184 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED |
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200185 IORESOURCE_STORED | IORESOURCE_RESERVE |
186 IORESOURCE_ASSIGNED;
Aaron Durbinc12ef972012-12-18 14:22:49 -0600187 resource->base = base;
188 resource->size = size;
189 printk(BIOS_DEBUG, "%s: Adding %s @ %x 0x%08lx-0x%08lx.\n",
190 __func__, mc_fixed_resources[i].description, index,
191 (unsigned long)base, (unsigned long)(base + size - 1));
192 }
193}
194
195/* Host Memory Map:
196 *
197 * +--------------------------+ TOUUD
198 * | |
199 * +--------------------------+ 4GiB
200 * | PCI Address Space |
201 * +--------------------------+ TOLUD (also maps into MC address space)
202 * | iGD |
203 * +--------------------------+ BDSM
204 * | GTT |
205 * +--------------------------+ BGSM
206 * | TSEG |
207 * +--------------------------+ TSEGMB
208 * | Usage DRAM |
209 * +--------------------------+ 0
210 *
211 * Some of the base registers above can be equal making the size of those
212 * regions 0. The reason is because the memory controller internally subtracts
213 * the base registers from each other to determine sizes of the regions. In
214 * other words, the memory map is in a fixed order no matter what.
215 */
216
217struct map_entry {
218 int reg;
219 int is_64_bit;
220 int is_limit;
221 const char *description;
222};
223
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200224static void read_map_entry(struct device *dev, struct map_entry *entry,
225 uint64_t *result)
Aaron Durbinc12ef972012-12-18 14:22:49 -0600226{
227 uint64_t value;
228 uint64_t mask;
229
230 /* All registers are on a 1MiB granularity. */
231 mask = ((1ULL<<20)-1);
232 mask = ~mask;
233
234 value = 0;
235
236 if (entry->is_64_bit) {
237 value = pci_read_config32(dev, entry->reg + 4);
238 value <<= 32;
Aaron Durbin76c37002012-10-30 09:03:43 -0500239 }
240
Aaron Durbinc12ef972012-12-18 14:22:49 -0600241 value |= pci_read_config32(dev, entry->reg);
242 value &= mask;
243
244 if (entry->is_limit)
245 value |= ~mask;
246
247 *result = value;
248}
249
250#define MAP_ENTRY(reg_, is_64_, is_limit_, desc_) \
251 { \
252 .reg = reg_, \
253 .is_64_bit = is_64_, \
254 .is_limit = is_limit_, \
255 .description = desc_, \
256 }
257
258#define MAP_ENTRY_BASE_64(reg_, desc_) \
259 MAP_ENTRY(reg_, 1, 0, desc_)
260#define MAP_ENTRY_LIMIT_64(reg_, desc_) \
261 MAP_ENTRY(reg_, 1, 1, desc_)
262#define MAP_ENTRY_BASE_32(reg_, desc_) \
263 MAP_ENTRY(reg_, 0, 0, desc_)
264
265enum {
266 TOM_REG,
267 TOUUD_REG,
268 MESEG_BASE_REG,
269 MESEG_LIMIT_REG,
270 REMAP_BASE_REG,
271 REMAP_LIMIT_REG,
272 TOLUD_REG,
273 BGSM_REG,
274 BDSM_REG,
275 TSEG_REG,
276 // Must be last.
277 NUM_MAP_ENTRIES
278};
279
280static struct map_entry memory_map[NUM_MAP_ENTRIES] = {
281 [TOM_REG] = MAP_ENTRY_BASE_64(TOM, "TOM"),
282 [TOUUD_REG] = MAP_ENTRY_BASE_64(TOUUD, "TOUUD"),
283 [MESEG_BASE_REG] = MAP_ENTRY_BASE_64(MESEG_BASE, "MESEG_BASE"),
284 [MESEG_LIMIT_REG] = MAP_ENTRY_LIMIT_64(MESEG_LIMIT, "MESEG_LIMIT"),
285 [REMAP_BASE_REG] = MAP_ENTRY_BASE_64(REMAPBASE, "REMAP_BASE"),
286 [REMAP_LIMIT_REG] = MAP_ENTRY_LIMIT_64(REMAPLIMIT, "REMAP_LIMIT"),
287 [TOLUD_REG] = MAP_ENTRY_BASE_32(TOLUD, "TOLUD"),
Aaron Durbin15702602012-12-21 22:18:58 -0600288 [BDSM_REG] = MAP_ENTRY_BASE_32(BDSM, "BDSM"),
289 [BGSM_REG] = MAP_ENTRY_BASE_32(BGSM, "BGSM"),
Aaron Durbinc12ef972012-12-18 14:22:49 -0600290 [TSEG_REG] = MAP_ENTRY_BASE_32(TSEG, "TESGMB"),
291};
292
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200293static void mc_read_map_entries(struct device *dev, uint64_t *values)
Aaron Durbinc12ef972012-12-18 14:22:49 -0600294{
295 int i;
296 for (i = 0; i < NUM_MAP_ENTRIES; i++) {
297 read_map_entry(dev, &memory_map[i], &values[i]);
298 }
299}
300
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200301static void mc_report_map_entries(struct device *dev, uint64_t *values)
Aaron Durbinc12ef972012-12-18 14:22:49 -0600302{
303 int i;
304 for (i = 0; i < NUM_MAP_ENTRIES; i++) {
305 printk(BIOS_DEBUG, "MC MAP: %s: 0x%llx\n",
306 memory_map[i].description, values[i]);
307 }
308 /* One can validate the BDSM and BGSM against the GGC. */
309 printk(BIOS_DEBUG, "MC MAP: GGC: 0x%x\n", pci_read_config16(dev, GGC));
310}
311
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200312static void mc_add_dram_resources(struct device *dev, int *resource_cnt)
Aaron Durbinc12ef972012-12-18 14:22:49 -0600313{
314 unsigned long base_k, size_k;
Aaron Durbin27435d32013-06-03 09:46:56 -0500315 unsigned long touud_k;
Aaron Durbinc12ef972012-12-18 14:22:49 -0600316 unsigned long index;
317 struct resource *resource;
318 uint64_t mc_values[NUM_MAP_ENTRIES];
319
320 /* Read in the MAP registers and report their values. */
321 mc_read_map_entries(dev, &mc_values[0]);
322 mc_report_map_entries(dev, &mc_values[0]);
323
324 /*
Aaron Durbin1fef1f52012-12-19 17:15:43 -0600325 * These are the host memory ranges that should be added:
Aaron Durbin6a360042014-02-13 10:30:42 -0600326 * - 0 -> 0xa0000: cacheable
Aaron Durbinc12ef972012-12-18 14:22:49 -0600327 * - 0xc0000 -> TSEG : cacheable
Aaron Durbine6c3b1d2012-12-21 21:22:07 -0600328 * - TESG -> BGSM: cacheable with standard MTRRs and reserved
329 * - BGSM -> TOLUD: not cacheable with standard MTRRs and reserved
Aaron Durbinc12ef972012-12-18 14:22:49 -0600330 * - 4GiB -> TOUUD: cacheable
331 *
Aaron Durbin1fef1f52012-12-19 17:15:43 -0600332 * The default SMRAM space is reserved so that the range doesn't
333 * have to be saved during S3 Resume. Once marked reserved the OS
334 * cannot use the memory. This is a bit of an odd place to reserve
335 * the region, but the CPU devices don't have dev_ops->read_resources()
336 * called on them.
337 *
Aaron Durbinc12ef972012-12-18 14:22:49 -0600338 * The range 0xa0000 -> 0xc0000 does not have any resources
339 * associated with it to handle legacy VGA memory. If this range
340 * is not omitted the mtrr code will setup the area as cacheable
341 * causing VGA access to not work.
342 *
Aaron Durbine6c3b1d2012-12-21 21:22:07 -0600343 * The TSEG region is mapped as cacheable so that one can perform
344 * SMRAM relocation faster. Once the SMRR is enabled the SMRR takes
345 * precedence over the existing MTRRs covering this region.
346 *
Aaron Durbin1fef1f52012-12-19 17:15:43 -0600347 * It should be noted that cacheable entry types need to be added in
348 * order. The reason is that the current MTRR code assumes this and
349 * falls over itself if it isn't.
350 *
Aaron Durbinc12ef972012-12-18 14:22:49 -0600351 * The resource index starts low and should not meet or exceed
Aaron Durbin1fef1f52012-12-19 17:15:43 -0600352 * PCI_BASE_ADDRESS_0.
Aaron Durbinc12ef972012-12-18 14:22:49 -0600353 */
Matt DeVilliera51e3792018-03-04 01:44:15 -0600354 index = *resource_cnt;
Aaron Durbinc12ef972012-12-18 14:22:49 -0600355
Aaron Durbin6a360042014-02-13 10:30:42 -0600356 /* 0 - > 0xa0000 */
Aaron Durbinc12ef972012-12-18 14:22:49 -0600357 base_k = 0;
Aaron Durbin1fef1f52012-12-19 17:15:43 -0600358 size_k = (0xa0000 >> 10) - base_k;
359 ram_resource(dev, index++, base_k, size_k);
360
361 /* 0xc0000 -> TSEG */
Aaron Durbinc12ef972012-12-18 14:22:49 -0600362 base_k = 0xc0000 >> 10;
363 size_k = (unsigned long)(mc_values[TSEG_REG] >> 10) - base_k;
364 ram_resource(dev, index++, base_k, size_k);
365
Aaron Durbine6c3b1d2012-12-21 21:22:07 -0600366 /* TSEG -> BGSM */
Aaron Durbinc12ef972012-12-18 14:22:49 -0600367 resource = new_resource(dev, index++);
368 resource->base = mc_values[TSEG_REG];
Aaron Durbine6c3b1d2012-12-21 21:22:07 -0600369 resource->size = mc_values[BGSM_REG] - resource->base;
370 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED |
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200371 IORESOURCE_STORED | IORESOURCE_RESERVE |
372 IORESOURCE_ASSIGNED | IORESOURCE_CACHEABLE;
Aaron Durbine6c3b1d2012-12-21 21:22:07 -0600373
Tristan Corrickc5d367b2018-12-17 22:10:07 +1300374 /* BGSM -> TOLUD. If the IGD is disabled, BGSM can equal TOLUD */
375 if (mc_values[BGSM_REG] != mc_values[TOLUD_REG]) {
376 resource = new_resource(dev, index++);
377 resource->base = mc_values[BGSM_REG];
378 resource->size = mc_values[TOLUD_REG] - resource->base;
379 resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED |
380 IORESOURCE_STORED | IORESOURCE_RESERVE |
381 IORESOURCE_ASSIGNED;
382 }
Aaron Durbinc12ef972012-12-18 14:22:49 -0600383
384 /* 4GiB -> TOUUD */
385 base_k = 4096 * 1024; /* 4GiB */
Aaron Durbin27435d32013-06-03 09:46:56 -0500386 touud_k = mc_values[TOUUD_REG] >> 10;
387 size_k = touud_k - base_k;
388 if (touud_k > base_k)
Aaron Durbin5c66f082013-01-08 10:10:33 -0600389 ram_resource(dev, index++, base_k, size_k);
Aaron Durbinc12ef972012-12-18 14:22:49 -0600390
Aaron Durbinc9650762013-03-22 22:03:09 -0500391 /* Reserve everything between A segment and 1MB:
392 *
393 * 0xa0000 - 0xbffff: legacy VGA
394 * 0xc0000 - 0xfffff: RAM
395 */
396 mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10);
397 reserved_ram_resource(dev, index++, (0xc0000 >> 10),
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +0200398 (0x100000 - 0xc0000) >> 10);
Martin Roth33232602017-06-24 14:48:50 -0600399#if IS_ENABLED(CONFIG_CHROMEOS_RAMOOPS)
Aaron Durbinc9650762013-03-22 22:03:09 -0500400 reserved_ram_resource(dev, index++,
401 CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10,
Aaron Durbinc12ef972012-12-18 14:22:49 -0600402 CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10);
403#endif
Matt DeVilliera51e3792018-03-04 01:44:15 -0600404 *resource_cnt = index;
Aaron Durbinc12ef972012-12-18 14:22:49 -0600405}
406
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200407static void mc_read_resources(struct device *dev)
Aaron Durbinc12ef972012-12-18 14:22:49 -0600408{
Matt DeVilliera51e3792018-03-04 01:44:15 -0600409 int index = 0;
410 const bool vtd_capable =
411 !(pci_read_config32(dev, CAPID0_A) & VTD_DISABLE);
412
Aaron Durbinc12ef972012-12-18 14:22:49 -0600413 /* Read standard PCI resources. */
414 pci_dev_read_resources(dev);
415
416 /* Add all fixed MMIO resources. */
417 mc_add_fixed_mmio_resources(dev);
418
Matt DeVilliera51e3792018-03-04 01:44:15 -0600419 /* Add VT-d MMIO resources if capable */
420 if (vtd_capable) {
421 mmio_resource(dev, index++, GFXVT_BASE_ADDRESS / KiB,
422 GFXVT_BASE_SIZE / KiB);
423 mmio_resource(dev, index++, VTVC0_BASE_ADDRESS / KiB,
424 VTVC0_BASE_SIZE / KiB);
425 }
426
Aaron Durbinc12ef972012-12-18 14:22:49 -0600427 /* Calculate and add DRAM resources. */
Matt DeVilliera51e3792018-03-04 01:44:15 -0600428 mc_add_dram_resources(dev, &index);
Aaron Durbin76c37002012-10-30 09:03:43 -0500429}
430
Tristan Corrickbc896cd2018-12-17 22:09:50 +1300431/*
432 * The Mini-HD audio device is disabled whenever the IGD is. This is
433 * because it provides audio over the integrated graphics port(s), which
434 * requires the IGD to be functional.
435 */
436static void disable_devices(void)
437{
438 static const struct {
439 const unsigned int devfn;
440 const u32 mask;
441 const char *const name;
442 } nb_devs[] = {
443 { PCI_DEVFN(1, 2), DEVEN_D1F2EN, "PEG12" },
444 { PCI_DEVFN(1, 1), DEVEN_D1F1EN, "PEG11" },
445 { PCI_DEVFN(1, 0), DEVEN_D1F0EN, "PEG10" },
446 { PCI_DEVFN(2, 0), DEVEN_D2EN | DEVEN_D3EN, "IGD" },
447 { PCI_DEVFN(3, 0), DEVEN_D3EN, "Mini-HD audio" },
448 { PCI_DEVFN(4, 0), DEVEN_D4EN, "\"device 4\"" },
449 { PCI_DEVFN(7, 0), DEVEN_D7EN, "\"device 7\"" },
450 };
451
452 struct device *host_dev = dev_find_slot(0, PCI_DEVFN(0, 0));
453 u32 deven;
454 size_t i;
455
456 if (!host_dev)
457 return;
458
459 deven = pci_read_config32(host_dev, DEVEN);
460
461 for (i = 0; i < ARRAY_SIZE(nb_devs); i++) {
462 struct device *dev = dev_find_slot(0, nb_devs[i].devfn);
463 if (!dev || !dev->enabled) {
464 printk(BIOS_DEBUG, "Disabling %s.\n", nb_devs[i].name);
465 deven &= ~nb_devs[i].mask;
466 }
467 }
468
469 pci_write_config32(host_dev, DEVEN, deven);
470}
471
Elyes HAOUASb60920d2018-09-20 17:38:38 +0200472static void intel_set_subsystem(struct device *dev, unsigned int vendor,
473 unsigned int device)
Aaron Durbin76c37002012-10-30 09:03:43 -0500474{
475 if (!vendor || !device) {
476 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
477 pci_read_config32(dev, PCI_VENDOR_ID));
478 } else {
479 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
480 ((device & 0xffff) << 16) | (vendor & 0xffff));
481 }
482}
483
Aaron Durbin76c37002012-10-30 09:03:43 -0500484static void northbridge_init(struct device *dev)
485{
Duncan Lauriec70353f2013-06-28 14:40:38 -0700486 u8 bios_reset_cpl, pair;
Aaron Durbin76c37002012-10-30 09:03:43 -0500487
Duncan Lauriec70353f2013-06-28 14:40:38 -0700488 /* Enable Power Aware Interrupt Routing */
489 pair = MCHBAR8(0x5418);
490 pair &= ~0x7; /* Clear 2:0 */
491 pair |= 0x4; /* Fixed Priority */
492 MCHBAR8(0x5418) = pair;
Aaron Durbin76c37002012-10-30 09:03:43 -0500493
Tristan Corrickbc896cd2018-12-17 22:09:50 +1300494 disable_devices();
495
Aaron Durbin76c37002012-10-30 09:03:43 -0500496 /*
Duncan Lauriec70353f2013-06-28 14:40:38 -0700497 * Set bits 0+1 of BIOS_RESET_CPL to indicate to the CPU
Aaron Durbin76c37002012-10-30 09:03:43 -0500498 * that BIOS has initialized memory and power management
499 */
500 bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL);
Duncan Lauriec70353f2013-06-28 14:40:38 -0700501 bios_reset_cpl |= 3;
Aaron Durbin76c37002012-10-30 09:03:43 -0500502 MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl;
503 printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n");
504
505 /* Configure turbo power limits 1ms after reset complete bit */
506 mdelay(1);
507 set_power_limits(28);
508
Aaron Durbin76c37002012-10-30 09:03:43 -0500509 /* Set here before graphics PM init */
510 MCHBAR32(0x5500) = 0x00100001;
511}
512
Aaron Durbin76c37002012-10-30 09:03:43 -0500513static struct pci_operations intel_pci_ops = {
514 .set_subsystem = intel_set_subsystem,
515};
516
517static struct device_operations mc_ops = {
518 .read_resources = mc_read_resources,
Aaron Durbinc12ef972012-12-18 14:22:49 -0600519 .set_resources = pci_dev_set_resources,
Aaron Durbin76c37002012-10-30 09:03:43 -0500520 .enable_resources = pci_dev_enable_resources,
521 .init = northbridge_init,
Vladimir Serbinenko0a669912014-10-05 14:34:17 +0200522 .acpi_fill_ssdt_generator = generate_cpu_entries,
Aaron Durbin76c37002012-10-30 09:03:43 -0500523 .scan_bus = 0,
524 .ops_pci = &intel_pci_ops,
525};
526
Tristan Corrickd3856242018-11-01 03:03:29 +1300527static const unsigned short mc_pci_device_ids[] = {
528 0x0c00, /* Desktop */
529 0x0c04, /* Mobile */
530 0x0a04, /* ULT */
Iru Cai0766c982018-12-17 13:21:36 +0800531 0x0c08, /* Server */
Tristan Corrickd3856242018-11-01 03:03:29 +1300532 0
Tristan Corrick48170122018-10-31 02:21:41 +1300533};
534
Tristan Corrickd3856242018-11-01 03:03:29 +1300535static const struct pci_driver mc_driver_hsw __pci_driver = {
536 .ops = &mc_ops,
537 .vendor = PCI_VENDOR_ID_INTEL,
538 .devices = mc_pci_device_ids,
Duncan Lauriedf7be712012-12-17 11:22:57 -0800539};
540
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200541static void cpu_bus_init(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500542{
Aaron Durbin7af20692013-01-14 14:54:41 -0600543 bsp_init_and_start_aps(dev->link_list);
Aaron Durbin76c37002012-10-30 09:03:43 -0500544}
545
Aaron Durbin76c37002012-10-30 09:03:43 -0500546static struct device_operations cpu_bus_ops = {
Edward O'Callaghan9f744622014-10-31 08:12:34 +1100547 .read_resources = DEVICE_NOOP,
548 .set_resources = DEVICE_NOOP,
549 .enable_resources = DEVICE_NOOP,
Aaron Durbin76c37002012-10-30 09:03:43 -0500550 .init = cpu_bus_init,
551 .scan_bus = 0,
552};
553
Elyes HAOUAS77f7a6e2018-05-09 17:47:59 +0200554static void enable_dev(struct device *dev)
Aaron Durbin76c37002012-10-30 09:03:43 -0500555{
556 /* Set the operations if it is a special bus type */
557 if (dev->path.type == DEVICE_PATH_DOMAIN) {
558 dev->ops = &pci_domain_ops;
559 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
560 dev->ops = &cpu_bus_ops;
561 }
562}
563
564struct chip_operations northbridge_intel_haswell_ops = {
565 CHIP_NAME("Intel i7 (Haswell) integrated Northbridge")
566 .enable_dev = enable_dev,
567};