Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 1 | /* |
| 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 Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 15 | */ |
| 16 | |
Tristan Corrick | bc896cd | 2018-12-17 22:09:50 +1300 | [diff] [blame] | 17 | #include <commonlib/helpers.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 18 | #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 Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 24 | #include <device/device.h> |
| 25 | #include <device/pci.h> |
Tristan Corrick | bc896cd | 2018-12-17 22:09:50 +1300 | [diff] [blame] | 26 | #include <device/pci_def.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 27 | #include <device/pci_ids.h> |
Tristan Corrick | bc896cd | 2018-12-17 22:09:50 +1300 | [diff] [blame] | 28 | #include <device/pci_ops.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 29 | #include <stdlib.h> |
| 30 | #include <string.h> |
Aaron Durbin | 1fef1f5 | 2012-12-19 17:15:43 -0600 | [diff] [blame] | 31 | #include <cpu/x86/smm.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 32 | #include <boot/tables.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 33 | #include "chip.h" |
| 34 | #include "haswell.h" |
| 35 | |
Elyes HAOUAS | 77f7a6e | 2018-05-09 17:47:59 +0200 | [diff] [blame] | 36 | static int get_pcie_bar(struct device *dev, unsigned int index, u32 *base, |
| 37 | u32 *len) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 38 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 39 | u32 pciexbar_reg; |
Ryan Salsamendi | fa0725d | 2017-06-30 17:29:37 -0700 | [diff] [blame] | 40 | u32 mask; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 41 | |
| 42 | *base = 0; |
| 43 | *len = 0; |
| 44 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 45 | pciexbar_reg = pci_read_config32(dev, index); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 46 | |
| 47 | if (!(pciexbar_reg & (1 << 0))) |
| 48 | return 0; |
| 49 | |
| 50 | switch ((pciexbar_reg >> 1) & 3) { |
| 51 | case 0: // 256MB |
Ryan Salsamendi | fa0725d | 2017-06-30 17:29:37 -0700 | [diff] [blame] | 52 | mask = (1UL << 31) | (1 << 30) | (1 << 29) | (1 << 28); |
| 53 | *base = pciexbar_reg & mask; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 54 | *len = 256 * 1024 * 1024; |
| 55 | return 1; |
| 56 | case 1: // 128M |
Ryan Salsamendi | fa0725d | 2017-06-30 17:29:37 -0700 | [diff] [blame] | 57 | mask = (1UL << 31) | (1 << 30) | (1 << 29) | (1 << 28); |
| 58 | mask |= (1 << 27); |
| 59 | *base = pciexbar_reg & mask; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 60 | *len = 128 * 1024 * 1024; |
| 61 | return 1; |
| 62 | case 2: // 64M |
Ryan Salsamendi | fa0725d | 2017-06-30 17:29:37 -0700 | [diff] [blame] | 63 | mask = (1UL << 31) | (1 << 30) | (1 << 29) | (1 << 28); |
| 64 | mask |= (1 << 27) | (1 << 26); |
| 65 | *base = pciexbar_reg & mask; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 66 | *len = 64 * 1024 * 1024; |
| 67 | return 1; |
| 68 | } |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
Elyes HAOUAS | 77f7a6e | 2018-05-09 17:47:59 +0200 | [diff] [blame] | 73 | static void pci_domain_set_resources(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 74 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 75 | assign_resources(dev->link_list); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 76 | } |
| 77 | |
Tristan Corrick | f3127d4 | 2018-10-31 02:25:54 +1300 | [diff] [blame] | 78 | static 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 Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 94 | /* 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 | */ |
| 98 | static 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 Corrick | f3127d4 | 2018-10-31 02:25:54 +1300 | [diff] [blame] | 104 | .acpi_name = northbridge_acpi_name, |
Matt DeVillier | 85d98d9 | 2018-03-04 01:41:23 -0600 | [diff] [blame] | 105 | .write_acpi_tables = northbridge_write_acpi_tables, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 106 | }; |
| 107 | |
Elyes HAOUAS | 77f7a6e | 2018-05-09 17:47:59 +0200 | [diff] [blame] | 108 | static int get_bar(struct device *dev, unsigned int index, u32 *base, u32 *len) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 109 | { |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 110 | u32 bar; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 111 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 112 | bar = pci_read_config32(dev, index); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 113 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 114 | /* If not enabled don't report it. */ |
| 115 | if (!(bar & 0x1)) |
| 116 | return 0; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 117 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 118 | /* Knock down the enable bit. */ |
| 119 | *base = bar & ~1; |
| 120 | |
| 121 | return 1; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 122 | } |
| 123 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 124 | /* 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 HAOUAS | 77f7a6e | 2018-05-09 17:47:59 +0200 | [diff] [blame] | 127 | static int get_bar_in_mchbar(struct device *dev, unsigned int index, |
| 128 | u32 *base, u32 *len) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 129 | { |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 130 | u32 bar; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 131 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 132 | 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 | |
| 144 | struct fixed_mmio_descriptor { |
| 145 | unsigned int index; |
| 146 | u32 size; |
Elyes HAOUAS | 77f7a6e | 2018-05-09 17:47:59 +0200 | [diff] [blame] | 147 | int (*get_resource)(struct device *dev, unsigned int index, |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 148 | u32 *base, u32 *size); |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 149 | const char *description; |
| 150 | }; |
| 151 | |
| 152 | #define SIZE_KB(x) ((x)*1024) |
| 153 | struct 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 HAOUAS | 77f7a6e | 2018-05-09 17:47:59 +0200 | [diff] [blame] | 167 | static void mc_add_fixed_mmio_resources(struct device *dev) |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 168 | { |
| 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 HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 180 | &base, &size)) |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 181 | continue; |
| 182 | |
| 183 | resource = new_resource(dev, mc_fixed_resources[i].index); |
| 184 | resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 185 | IORESOURCE_STORED | IORESOURCE_RESERVE | |
| 186 | IORESOURCE_ASSIGNED; |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 187 | 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 | |
| 217 | struct map_entry { |
| 218 | int reg; |
| 219 | int is_64_bit; |
| 220 | int is_limit; |
| 221 | const char *description; |
| 222 | }; |
| 223 | |
Elyes HAOUAS | 77f7a6e | 2018-05-09 17:47:59 +0200 | [diff] [blame] | 224 | static void read_map_entry(struct device *dev, struct map_entry *entry, |
| 225 | uint64_t *result) |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 226 | { |
| 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 Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 239 | } |
| 240 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 241 | 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 | |
| 265 | enum { |
| 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 | |
| 280 | static 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 Durbin | 1570260 | 2012-12-21 22:18:58 -0600 | [diff] [blame] | 288 | [BDSM_REG] = MAP_ENTRY_BASE_32(BDSM, "BDSM"), |
| 289 | [BGSM_REG] = MAP_ENTRY_BASE_32(BGSM, "BGSM"), |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 290 | [TSEG_REG] = MAP_ENTRY_BASE_32(TSEG, "TESGMB"), |
| 291 | }; |
| 292 | |
Elyes HAOUAS | 77f7a6e | 2018-05-09 17:47:59 +0200 | [diff] [blame] | 293 | static void mc_read_map_entries(struct device *dev, uint64_t *values) |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 294 | { |
| 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 HAOUAS | 77f7a6e | 2018-05-09 17:47:59 +0200 | [diff] [blame] | 301 | static void mc_report_map_entries(struct device *dev, uint64_t *values) |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 302 | { |
| 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 HAOUAS | 77f7a6e | 2018-05-09 17:47:59 +0200 | [diff] [blame] | 312 | static void mc_add_dram_resources(struct device *dev, int *resource_cnt) |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 313 | { |
| 314 | unsigned long base_k, size_k; |
Aaron Durbin | 27435d3 | 2013-06-03 09:46:56 -0500 | [diff] [blame] | 315 | unsigned long touud_k; |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 316 | 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 Durbin | 1fef1f5 | 2012-12-19 17:15:43 -0600 | [diff] [blame] | 325 | * These are the host memory ranges that should be added: |
Aaron Durbin | 6a36004 | 2014-02-13 10:30:42 -0600 | [diff] [blame] | 326 | * - 0 -> 0xa0000: cacheable |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 327 | * - 0xc0000 -> TSEG : cacheable |
Aaron Durbin | e6c3b1d | 2012-12-21 21:22:07 -0600 | [diff] [blame] | 328 | * - TESG -> BGSM: cacheable with standard MTRRs and reserved |
| 329 | * - BGSM -> TOLUD: not cacheable with standard MTRRs and reserved |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 330 | * - 4GiB -> TOUUD: cacheable |
| 331 | * |
Aaron Durbin | 1fef1f5 | 2012-12-19 17:15:43 -0600 | [diff] [blame] | 332 | * 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 Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 338 | * 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 Durbin | e6c3b1d | 2012-12-21 21:22:07 -0600 | [diff] [blame] | 343 | * 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 Durbin | 1fef1f5 | 2012-12-19 17:15:43 -0600 | [diff] [blame] | 347 | * 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 Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 351 | * The resource index starts low and should not meet or exceed |
Aaron Durbin | 1fef1f5 | 2012-12-19 17:15:43 -0600 | [diff] [blame] | 352 | * PCI_BASE_ADDRESS_0. |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 353 | */ |
Matt DeVillier | a51e379 | 2018-03-04 01:44:15 -0600 | [diff] [blame] | 354 | index = *resource_cnt; |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 355 | |
Aaron Durbin | 6a36004 | 2014-02-13 10:30:42 -0600 | [diff] [blame] | 356 | /* 0 - > 0xa0000 */ |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 357 | base_k = 0; |
Aaron Durbin | 1fef1f5 | 2012-12-19 17:15:43 -0600 | [diff] [blame] | 358 | size_k = (0xa0000 >> 10) - base_k; |
| 359 | ram_resource(dev, index++, base_k, size_k); |
| 360 | |
| 361 | /* 0xc0000 -> TSEG */ |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 362 | 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 Durbin | e6c3b1d | 2012-12-21 21:22:07 -0600 | [diff] [blame] | 366 | /* TSEG -> BGSM */ |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 367 | resource = new_resource(dev, index++); |
| 368 | resource->base = mc_values[TSEG_REG]; |
Aaron Durbin | e6c3b1d | 2012-12-21 21:22:07 -0600 | [diff] [blame] | 369 | resource->size = mc_values[BGSM_REG] - resource->base; |
| 370 | resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 371 | IORESOURCE_STORED | IORESOURCE_RESERVE | |
| 372 | IORESOURCE_ASSIGNED | IORESOURCE_CACHEABLE; |
Aaron Durbin | e6c3b1d | 2012-12-21 21:22:07 -0600 | [diff] [blame] | 373 | |
| 374 | /* BGSM -> TOLUD */ |
| 375 | resource = new_resource(dev, index++); |
| 376 | resource->base = mc_values[BGSM_REG]; |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 377 | resource->size = mc_values[TOLUD_REG] - resource->base; |
| 378 | resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 379 | IORESOURCE_STORED | IORESOURCE_RESERVE | |
| 380 | IORESOURCE_ASSIGNED; |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 381 | |
| 382 | /* 4GiB -> TOUUD */ |
| 383 | base_k = 4096 * 1024; /* 4GiB */ |
Aaron Durbin | 27435d3 | 2013-06-03 09:46:56 -0500 | [diff] [blame] | 384 | touud_k = mc_values[TOUUD_REG] >> 10; |
| 385 | size_k = touud_k - base_k; |
| 386 | if (touud_k > base_k) |
Aaron Durbin | 5c66f08 | 2013-01-08 10:10:33 -0600 | [diff] [blame] | 387 | ram_resource(dev, index++, base_k, size_k); |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 388 | |
Aaron Durbin | c965076 | 2013-03-22 22:03:09 -0500 | [diff] [blame] | 389 | /* Reserve everything between A segment and 1MB: |
| 390 | * |
| 391 | * 0xa0000 - 0xbffff: legacy VGA |
| 392 | * 0xc0000 - 0xfffff: RAM |
| 393 | */ |
| 394 | mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10); |
| 395 | reserved_ram_resource(dev, index++, (0xc0000 >> 10), |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 396 | (0x100000 - 0xc0000) >> 10); |
Martin Roth | 3323260 | 2017-06-24 14:48:50 -0600 | [diff] [blame] | 397 | #if IS_ENABLED(CONFIG_CHROMEOS_RAMOOPS) |
Aaron Durbin | c965076 | 2013-03-22 22:03:09 -0500 | [diff] [blame] | 398 | reserved_ram_resource(dev, index++, |
| 399 | CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10, |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 400 | CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10); |
| 401 | #endif |
Matt DeVillier | a51e379 | 2018-03-04 01:44:15 -0600 | [diff] [blame] | 402 | *resource_cnt = index; |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 403 | } |
| 404 | |
Elyes HAOUAS | 77f7a6e | 2018-05-09 17:47:59 +0200 | [diff] [blame] | 405 | static void mc_read_resources(struct device *dev) |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 406 | { |
Matt DeVillier | a51e379 | 2018-03-04 01:44:15 -0600 | [diff] [blame] | 407 | int index = 0; |
| 408 | const bool vtd_capable = |
| 409 | !(pci_read_config32(dev, CAPID0_A) & VTD_DISABLE); |
| 410 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 411 | /* Read standard PCI resources. */ |
| 412 | pci_dev_read_resources(dev); |
| 413 | |
| 414 | /* Add all fixed MMIO resources. */ |
| 415 | mc_add_fixed_mmio_resources(dev); |
| 416 | |
Matt DeVillier | a51e379 | 2018-03-04 01:44:15 -0600 | [diff] [blame] | 417 | /* Add VT-d MMIO resources if capable */ |
| 418 | if (vtd_capable) { |
| 419 | mmio_resource(dev, index++, GFXVT_BASE_ADDRESS / KiB, |
| 420 | GFXVT_BASE_SIZE / KiB); |
| 421 | mmio_resource(dev, index++, VTVC0_BASE_ADDRESS / KiB, |
| 422 | VTVC0_BASE_SIZE / KiB); |
| 423 | } |
| 424 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 425 | /* Calculate and add DRAM resources. */ |
Matt DeVillier | a51e379 | 2018-03-04 01:44:15 -0600 | [diff] [blame] | 426 | mc_add_dram_resources(dev, &index); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 427 | } |
| 428 | |
Tristan Corrick | bc896cd | 2018-12-17 22:09:50 +1300 | [diff] [blame] | 429 | /* |
| 430 | * The Mini-HD audio device is disabled whenever the IGD is. This is |
| 431 | * because it provides audio over the integrated graphics port(s), which |
| 432 | * requires the IGD to be functional. |
| 433 | */ |
| 434 | static void disable_devices(void) |
| 435 | { |
| 436 | static const struct { |
| 437 | const unsigned int devfn; |
| 438 | const u32 mask; |
| 439 | const char *const name; |
| 440 | } nb_devs[] = { |
| 441 | { PCI_DEVFN(1, 2), DEVEN_D1F2EN, "PEG12" }, |
| 442 | { PCI_DEVFN(1, 1), DEVEN_D1F1EN, "PEG11" }, |
| 443 | { PCI_DEVFN(1, 0), DEVEN_D1F0EN, "PEG10" }, |
| 444 | { PCI_DEVFN(2, 0), DEVEN_D2EN | DEVEN_D3EN, "IGD" }, |
| 445 | { PCI_DEVFN(3, 0), DEVEN_D3EN, "Mini-HD audio" }, |
| 446 | { PCI_DEVFN(4, 0), DEVEN_D4EN, "\"device 4\"" }, |
| 447 | { PCI_DEVFN(7, 0), DEVEN_D7EN, "\"device 7\"" }, |
| 448 | }; |
| 449 | |
| 450 | struct device *host_dev = dev_find_slot(0, PCI_DEVFN(0, 0)); |
| 451 | u32 deven; |
| 452 | size_t i; |
| 453 | |
| 454 | if (!host_dev) |
| 455 | return; |
| 456 | |
| 457 | deven = pci_read_config32(host_dev, DEVEN); |
| 458 | |
| 459 | for (i = 0; i < ARRAY_SIZE(nb_devs); i++) { |
| 460 | struct device *dev = dev_find_slot(0, nb_devs[i].devfn); |
| 461 | if (!dev || !dev->enabled) { |
| 462 | printk(BIOS_DEBUG, "Disabling %s.\n", nb_devs[i].name); |
| 463 | deven &= ~nb_devs[i].mask; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | pci_write_config32(host_dev, DEVEN, deven); |
| 468 | } |
| 469 | |
Elyes HAOUAS | b60920d | 2018-09-20 17:38:38 +0200 | [diff] [blame] | 470 | static void intel_set_subsystem(struct device *dev, unsigned int vendor, |
| 471 | unsigned int device) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 472 | { |
| 473 | if (!vendor || !device) { |
| 474 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 475 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 476 | } else { |
| 477 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 478 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 479 | } |
| 480 | } |
| 481 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 482 | static void northbridge_init(struct device *dev) |
| 483 | { |
Duncan Laurie | c70353f | 2013-06-28 14:40:38 -0700 | [diff] [blame] | 484 | u8 bios_reset_cpl, pair; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 485 | |
Duncan Laurie | c70353f | 2013-06-28 14:40:38 -0700 | [diff] [blame] | 486 | /* Enable Power Aware Interrupt Routing */ |
| 487 | pair = MCHBAR8(0x5418); |
| 488 | pair &= ~0x7; /* Clear 2:0 */ |
| 489 | pair |= 0x4; /* Fixed Priority */ |
| 490 | MCHBAR8(0x5418) = pair; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 491 | |
Tristan Corrick | bc896cd | 2018-12-17 22:09:50 +1300 | [diff] [blame] | 492 | disable_devices(); |
| 493 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 494 | /* |
Duncan Laurie | c70353f | 2013-06-28 14:40:38 -0700 | [diff] [blame] | 495 | * Set bits 0+1 of BIOS_RESET_CPL to indicate to the CPU |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 496 | * that BIOS has initialized memory and power management |
| 497 | */ |
| 498 | bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL); |
Duncan Laurie | c70353f | 2013-06-28 14:40:38 -0700 | [diff] [blame] | 499 | bios_reset_cpl |= 3; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 500 | MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl; |
| 501 | printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n"); |
| 502 | |
| 503 | /* Configure turbo power limits 1ms after reset complete bit */ |
| 504 | mdelay(1); |
| 505 | set_power_limits(28); |
| 506 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 507 | /* Set here before graphics PM init */ |
| 508 | MCHBAR32(0x5500) = 0x00100001; |
| 509 | } |
| 510 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 511 | static struct pci_operations intel_pci_ops = { |
| 512 | .set_subsystem = intel_set_subsystem, |
| 513 | }; |
| 514 | |
| 515 | static struct device_operations mc_ops = { |
| 516 | .read_resources = mc_read_resources, |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 517 | .set_resources = pci_dev_set_resources, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 518 | .enable_resources = pci_dev_enable_resources, |
| 519 | .init = northbridge_init, |
Vladimir Serbinenko | 0a66991 | 2014-10-05 14:34:17 +0200 | [diff] [blame] | 520 | .acpi_fill_ssdt_generator = generate_cpu_entries, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 521 | .scan_bus = 0, |
| 522 | .ops_pci = &intel_pci_ops, |
| 523 | }; |
| 524 | |
Tristan Corrick | d385624 | 2018-11-01 03:03:29 +1300 | [diff] [blame] | 525 | static const unsigned short mc_pci_device_ids[] = { |
| 526 | 0x0c00, /* Desktop */ |
| 527 | 0x0c04, /* Mobile */ |
| 528 | 0x0a04, /* ULT */ |
Iru Cai | 0766c98 | 2018-12-17 13:21:36 +0800 | [diff] [blame] | 529 | 0x0c08, /* Server */ |
Tristan Corrick | d385624 | 2018-11-01 03:03:29 +1300 | [diff] [blame] | 530 | 0 |
Tristan Corrick | 4817012 | 2018-10-31 02:21:41 +1300 | [diff] [blame] | 531 | }; |
| 532 | |
Tristan Corrick | d385624 | 2018-11-01 03:03:29 +1300 | [diff] [blame] | 533 | static const struct pci_driver mc_driver_hsw __pci_driver = { |
| 534 | .ops = &mc_ops, |
| 535 | .vendor = PCI_VENDOR_ID_INTEL, |
| 536 | .devices = mc_pci_device_ids, |
Duncan Laurie | df7be71 | 2012-12-17 11:22:57 -0800 | [diff] [blame] | 537 | }; |
| 538 | |
Elyes HAOUAS | 77f7a6e | 2018-05-09 17:47:59 +0200 | [diff] [blame] | 539 | static void cpu_bus_init(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 540 | { |
Aaron Durbin | 7af2069 | 2013-01-14 14:54:41 -0600 | [diff] [blame] | 541 | bsp_init_and_start_aps(dev->link_list); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 542 | } |
| 543 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 544 | static struct device_operations cpu_bus_ops = { |
Edward O'Callaghan | 9f74462 | 2014-10-31 08:12:34 +1100 | [diff] [blame] | 545 | .read_resources = DEVICE_NOOP, |
| 546 | .set_resources = DEVICE_NOOP, |
| 547 | .enable_resources = DEVICE_NOOP, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 548 | .init = cpu_bus_init, |
| 549 | .scan_bus = 0, |
| 550 | }; |
| 551 | |
Elyes HAOUAS | 77f7a6e | 2018-05-09 17:47:59 +0200 | [diff] [blame] | 552 | static void enable_dev(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 553 | { |
| 554 | /* Set the operations if it is a special bus type */ |
| 555 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
| 556 | dev->ops = &pci_domain_ops; |
| 557 | } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
| 558 | dev->ops = &cpu_bus_ops; |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | struct chip_operations northbridge_intel_haswell_ops = { |
| 563 | CHIP_NAME("Intel i7 (Haswell) integrated Northbridge") |
| 564 | .enable_dev = enable_dev, |
| 565 | }; |