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