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 | |
| 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> |
| 23 | #include <cpu/x86/msr.h> |
| 24 | #include <device/device.h> |
| 25 | #include <device/pci.h> |
| 26 | #include <device/pci_ids.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
| 29 | #include <cpu/cpu.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> |
| 32 | #include <cbmem.h> |
| 33 | #include "chip.h" |
| 34 | #include "haswell.h" |
| 35 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 36 | static int get_pcie_bar(device_t dev, unsigned int index, u32 *base, 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 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 72 | static void pci_domain_set_resources(device_t dev) |
| 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 | |
| 77 | /* TODO We could determine how many PCIe busses we need in |
| 78 | * the bar. For now that number is hardcoded to a max of 64. |
| 79 | * See e7525/northbridge.c for an example. |
| 80 | */ |
| 81 | static struct device_operations pci_domain_ops = { |
| 82 | .read_resources = pci_domain_read_resources, |
| 83 | .set_resources = pci_domain_set_resources, |
| 84 | .enable_resources = NULL, |
| 85 | .init = NULL, |
| 86 | .scan_bus = pci_domain_scan_bus, |
Kyösti Mälkki | 872c922 | 2013-07-03 09:44:28 +0300 | [diff] [blame] | 87 | .ops_pci_bus = pci_bus_default_ops, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 88 | }; |
| 89 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 90 | static int get_bar(device_t dev, unsigned int index, u32 *base, u32 *len) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 91 | { |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 92 | u32 bar; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 93 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 94 | bar = pci_read_config32(dev, index); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 95 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 96 | /* If not enabled don't report it. */ |
| 97 | if (!(bar & 0x1)) |
| 98 | return 0; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 99 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 100 | /* Knock down the enable bit. */ |
| 101 | *base = bar & ~1; |
| 102 | |
| 103 | return 1; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 104 | } |
| 105 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 106 | /* There are special BARs that actually are programmed in the MCHBAR. These |
| 107 | * Intel special features, but they do consume resources that need to be |
| 108 | * accounted for. */ |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 109 | static int get_bar_in_mchbar(device_t dev, unsigned int index, u32 *base, u32 *len) |
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 | u32 bar; |
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 | bar = MCHBAR32(index); |
| 114 | |
| 115 | /* If not enabled don't report it. */ |
| 116 | if (!(bar & 0x1)) |
| 117 | return 0; |
| 118 | |
| 119 | /* Knock down the enable bit. */ |
| 120 | *base = bar & ~1; |
| 121 | |
| 122 | return 1; |
| 123 | } |
| 124 | |
| 125 | struct fixed_mmio_descriptor { |
| 126 | unsigned int index; |
| 127 | u32 size; |
| 128 | int (*get_resource)(device_t dev, unsigned int index, |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 129 | u32 *base, u32 *size); |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 130 | const char *description; |
| 131 | }; |
| 132 | |
| 133 | #define SIZE_KB(x) ((x)*1024) |
| 134 | struct fixed_mmio_descriptor mc_fixed_resources[] = { |
| 135 | { PCIEXBAR, SIZE_KB(0), get_pcie_bar, "PCIEXBAR" }, |
| 136 | { MCHBAR, SIZE_KB(32), get_bar, "MCHBAR" }, |
| 137 | { DMIBAR, SIZE_KB(4), get_bar, "DMIBAR" }, |
| 138 | { EPBAR, SIZE_KB(4), get_bar, "EPBAR" }, |
| 139 | { 0x5420, SIZE_KB(4), get_bar_in_mchbar, "GDXCBAR" }, |
| 140 | { 0x5408, SIZE_KB(16), get_bar_in_mchbar, "EDRAMBAR" }, |
| 141 | }; |
| 142 | #undef SIZE_KB |
| 143 | |
| 144 | /* |
| 145 | * Add all known fixed MMIO ranges that hang off the host bridge/memory |
| 146 | * controller device. |
| 147 | */ |
| 148 | static void mc_add_fixed_mmio_resources(device_t dev) |
| 149 | { |
| 150 | int i; |
| 151 | |
| 152 | for (i = 0; i < ARRAY_SIZE(mc_fixed_resources); i++) { |
| 153 | u32 base; |
| 154 | u32 size; |
| 155 | struct resource *resource; |
| 156 | unsigned int index; |
| 157 | |
| 158 | size = mc_fixed_resources[i].size; |
| 159 | index = mc_fixed_resources[i].index; |
| 160 | if (!mc_fixed_resources[i].get_resource(dev, index, |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 161 | &base, &size)) |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 162 | continue; |
| 163 | |
| 164 | resource = new_resource(dev, mc_fixed_resources[i].index); |
| 165 | resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 166 | IORESOURCE_STORED | IORESOURCE_RESERVE | |
| 167 | IORESOURCE_ASSIGNED; |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 168 | resource->base = base; |
| 169 | resource->size = size; |
| 170 | printk(BIOS_DEBUG, "%s: Adding %s @ %x 0x%08lx-0x%08lx.\n", |
| 171 | __func__, mc_fixed_resources[i].description, index, |
| 172 | (unsigned long)base, (unsigned long)(base + size - 1)); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | /* Host Memory Map: |
| 177 | * |
| 178 | * +--------------------------+ TOUUD |
| 179 | * | | |
| 180 | * +--------------------------+ 4GiB |
| 181 | * | PCI Address Space | |
| 182 | * +--------------------------+ TOLUD (also maps into MC address space) |
| 183 | * | iGD | |
| 184 | * +--------------------------+ BDSM |
| 185 | * | GTT | |
| 186 | * +--------------------------+ BGSM |
| 187 | * | TSEG | |
| 188 | * +--------------------------+ TSEGMB |
| 189 | * | Usage DRAM | |
| 190 | * +--------------------------+ 0 |
| 191 | * |
| 192 | * Some of the base registers above can be equal making the size of those |
| 193 | * regions 0. The reason is because the memory controller internally subtracts |
| 194 | * the base registers from each other to determine sizes of the regions. In |
| 195 | * other words, the memory map is in a fixed order no matter what. |
| 196 | */ |
| 197 | |
| 198 | struct map_entry { |
| 199 | int reg; |
| 200 | int is_64_bit; |
| 201 | int is_limit; |
| 202 | const char *description; |
| 203 | }; |
| 204 | |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 205 | static void read_map_entry(device_t dev, struct map_entry *entry, uint64_t *result) |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 206 | { |
| 207 | uint64_t value; |
| 208 | uint64_t mask; |
| 209 | |
| 210 | /* All registers are on a 1MiB granularity. */ |
| 211 | mask = ((1ULL<<20)-1); |
| 212 | mask = ~mask; |
| 213 | |
| 214 | value = 0; |
| 215 | |
| 216 | if (entry->is_64_bit) { |
| 217 | value = pci_read_config32(dev, entry->reg + 4); |
| 218 | value <<= 32; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 219 | } |
| 220 | |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 221 | value |= pci_read_config32(dev, entry->reg); |
| 222 | value &= mask; |
| 223 | |
| 224 | if (entry->is_limit) |
| 225 | value |= ~mask; |
| 226 | |
| 227 | *result = value; |
| 228 | } |
| 229 | |
| 230 | #define MAP_ENTRY(reg_, is_64_, is_limit_, desc_) \ |
| 231 | { \ |
| 232 | .reg = reg_, \ |
| 233 | .is_64_bit = is_64_, \ |
| 234 | .is_limit = is_limit_, \ |
| 235 | .description = desc_, \ |
| 236 | } |
| 237 | |
| 238 | #define MAP_ENTRY_BASE_64(reg_, desc_) \ |
| 239 | MAP_ENTRY(reg_, 1, 0, desc_) |
| 240 | #define MAP_ENTRY_LIMIT_64(reg_, desc_) \ |
| 241 | MAP_ENTRY(reg_, 1, 1, desc_) |
| 242 | #define MAP_ENTRY_BASE_32(reg_, desc_) \ |
| 243 | MAP_ENTRY(reg_, 0, 0, desc_) |
| 244 | |
| 245 | enum { |
| 246 | TOM_REG, |
| 247 | TOUUD_REG, |
| 248 | MESEG_BASE_REG, |
| 249 | MESEG_LIMIT_REG, |
| 250 | REMAP_BASE_REG, |
| 251 | REMAP_LIMIT_REG, |
| 252 | TOLUD_REG, |
| 253 | BGSM_REG, |
| 254 | BDSM_REG, |
| 255 | TSEG_REG, |
| 256 | // Must be last. |
| 257 | NUM_MAP_ENTRIES |
| 258 | }; |
| 259 | |
| 260 | static struct map_entry memory_map[NUM_MAP_ENTRIES] = { |
| 261 | [TOM_REG] = MAP_ENTRY_BASE_64(TOM, "TOM"), |
| 262 | [TOUUD_REG] = MAP_ENTRY_BASE_64(TOUUD, "TOUUD"), |
| 263 | [MESEG_BASE_REG] = MAP_ENTRY_BASE_64(MESEG_BASE, "MESEG_BASE"), |
| 264 | [MESEG_LIMIT_REG] = MAP_ENTRY_LIMIT_64(MESEG_LIMIT, "MESEG_LIMIT"), |
| 265 | [REMAP_BASE_REG] = MAP_ENTRY_BASE_64(REMAPBASE, "REMAP_BASE"), |
| 266 | [REMAP_LIMIT_REG] = MAP_ENTRY_LIMIT_64(REMAPLIMIT, "REMAP_LIMIT"), |
| 267 | [TOLUD_REG] = MAP_ENTRY_BASE_32(TOLUD, "TOLUD"), |
Aaron Durbin | 1570260 | 2012-12-21 22:18:58 -0600 | [diff] [blame] | 268 | [BDSM_REG] = MAP_ENTRY_BASE_32(BDSM, "BDSM"), |
| 269 | [BGSM_REG] = MAP_ENTRY_BASE_32(BGSM, "BGSM"), |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 270 | [TSEG_REG] = MAP_ENTRY_BASE_32(TSEG, "TESGMB"), |
| 271 | }; |
| 272 | |
| 273 | static void mc_read_map_entries(device_t dev, uint64_t *values) |
| 274 | { |
| 275 | int i; |
| 276 | for (i = 0; i < NUM_MAP_ENTRIES; i++) { |
| 277 | read_map_entry(dev, &memory_map[i], &values[i]); |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | static void mc_report_map_entries(device_t dev, uint64_t *values) |
| 282 | { |
| 283 | int i; |
| 284 | for (i = 0; i < NUM_MAP_ENTRIES; i++) { |
| 285 | printk(BIOS_DEBUG, "MC MAP: %s: 0x%llx\n", |
| 286 | memory_map[i].description, values[i]); |
| 287 | } |
| 288 | /* One can validate the BDSM and BGSM against the GGC. */ |
| 289 | printk(BIOS_DEBUG, "MC MAP: GGC: 0x%x\n", pci_read_config16(dev, GGC)); |
| 290 | } |
| 291 | |
| 292 | static void mc_add_dram_resources(device_t dev) |
| 293 | { |
| 294 | unsigned long base_k, size_k; |
Aaron Durbin | 27435d3 | 2013-06-03 09:46:56 -0500 | [diff] [blame] | 295 | unsigned long touud_k; |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 296 | unsigned long index; |
| 297 | struct resource *resource; |
| 298 | uint64_t mc_values[NUM_MAP_ENTRIES]; |
| 299 | |
| 300 | /* Read in the MAP registers and report their values. */ |
| 301 | mc_read_map_entries(dev, &mc_values[0]); |
| 302 | mc_report_map_entries(dev, &mc_values[0]); |
| 303 | |
| 304 | /* |
Aaron Durbin | 1fef1f5 | 2012-12-19 17:15:43 -0600 | [diff] [blame] | 305 | * These are the host memory ranges that should be added: |
Aaron Durbin | 6a36004 | 2014-02-13 10:30:42 -0600 | [diff] [blame] | 306 | * - 0 -> 0xa0000: cacheable |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 307 | * - 0xc0000 -> TSEG : cacheable |
Aaron Durbin | e6c3b1d | 2012-12-21 21:22:07 -0600 | [diff] [blame] | 308 | * - TESG -> BGSM: cacheable with standard MTRRs and reserved |
| 309 | * - BGSM -> TOLUD: not cacheable with standard MTRRs and reserved |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 310 | * - 4GiB -> TOUUD: cacheable |
| 311 | * |
Aaron Durbin | 1fef1f5 | 2012-12-19 17:15:43 -0600 | [diff] [blame] | 312 | * The default SMRAM space is reserved so that the range doesn't |
| 313 | * have to be saved during S3 Resume. Once marked reserved the OS |
| 314 | * cannot use the memory. This is a bit of an odd place to reserve |
| 315 | * the region, but the CPU devices don't have dev_ops->read_resources() |
| 316 | * called on them. |
| 317 | * |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 318 | * The range 0xa0000 -> 0xc0000 does not have any resources |
| 319 | * associated with it to handle legacy VGA memory. If this range |
| 320 | * is not omitted the mtrr code will setup the area as cacheable |
| 321 | * causing VGA access to not work. |
| 322 | * |
Aaron Durbin | e6c3b1d | 2012-12-21 21:22:07 -0600 | [diff] [blame] | 323 | * The TSEG region is mapped as cacheable so that one can perform |
| 324 | * SMRAM relocation faster. Once the SMRR is enabled the SMRR takes |
| 325 | * precedence over the existing MTRRs covering this region. |
| 326 | * |
Aaron Durbin | 1fef1f5 | 2012-12-19 17:15:43 -0600 | [diff] [blame] | 327 | * It should be noted that cacheable entry types need to be added in |
| 328 | * order. The reason is that the current MTRR code assumes this and |
| 329 | * falls over itself if it isn't. |
| 330 | * |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 331 | * The resource index starts low and should not meet or exceed |
Aaron Durbin | 1fef1f5 | 2012-12-19 17:15:43 -0600 | [diff] [blame] | 332 | * PCI_BASE_ADDRESS_0. |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 333 | */ |
| 334 | index = 0; |
| 335 | |
Aaron Durbin | 6a36004 | 2014-02-13 10:30:42 -0600 | [diff] [blame] | 336 | /* 0 - > 0xa0000 */ |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 337 | base_k = 0; |
Aaron Durbin | 1fef1f5 | 2012-12-19 17:15:43 -0600 | [diff] [blame] | 338 | size_k = (0xa0000 >> 10) - base_k; |
| 339 | ram_resource(dev, index++, base_k, size_k); |
| 340 | |
| 341 | /* 0xc0000 -> TSEG */ |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 342 | base_k = 0xc0000 >> 10; |
| 343 | size_k = (unsigned long)(mc_values[TSEG_REG] >> 10) - base_k; |
| 344 | ram_resource(dev, index++, base_k, size_k); |
| 345 | |
Aaron Durbin | e6c3b1d | 2012-12-21 21:22:07 -0600 | [diff] [blame] | 346 | /* TSEG -> BGSM */ |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 347 | resource = new_resource(dev, index++); |
| 348 | resource->base = mc_values[TSEG_REG]; |
Aaron Durbin | e6c3b1d | 2012-12-21 21:22:07 -0600 | [diff] [blame] | 349 | resource->size = mc_values[BGSM_REG] - resource->base; |
| 350 | resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 351 | IORESOURCE_STORED | IORESOURCE_RESERVE | |
| 352 | IORESOURCE_ASSIGNED | IORESOURCE_CACHEABLE; |
Aaron Durbin | e6c3b1d | 2012-12-21 21:22:07 -0600 | [diff] [blame] | 353 | |
| 354 | /* BGSM -> TOLUD */ |
| 355 | resource = new_resource(dev, index++); |
| 356 | resource->base = mc_values[BGSM_REG]; |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 357 | resource->size = mc_values[TOLUD_REG] - resource->base; |
| 358 | resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 359 | IORESOURCE_STORED | IORESOURCE_RESERVE | |
| 360 | IORESOURCE_ASSIGNED; |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 361 | |
| 362 | /* 4GiB -> TOUUD */ |
| 363 | base_k = 4096 * 1024; /* 4GiB */ |
Aaron Durbin | 27435d3 | 2013-06-03 09:46:56 -0500 | [diff] [blame] | 364 | touud_k = mc_values[TOUUD_REG] >> 10; |
| 365 | size_k = touud_k - base_k; |
| 366 | if (touud_k > base_k) |
Aaron Durbin | 5c66f08 | 2013-01-08 10:10:33 -0600 | [diff] [blame] | 367 | ram_resource(dev, index++, base_k, size_k); |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 368 | |
Aaron Durbin | c965076 | 2013-03-22 22:03:09 -0500 | [diff] [blame] | 369 | /* Reserve everything between A segment and 1MB: |
| 370 | * |
| 371 | * 0xa0000 - 0xbffff: legacy VGA |
| 372 | * 0xc0000 - 0xfffff: RAM |
| 373 | */ |
| 374 | mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10); |
| 375 | reserved_ram_resource(dev, index++, (0xc0000 >> 10), |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 376 | (0x100000 - 0xc0000) >> 10); |
Martin Roth | 3323260 | 2017-06-24 14:48:50 -0600 | [diff] [blame] | 377 | #if IS_ENABLED(CONFIG_CHROMEOS_RAMOOPS) |
Aaron Durbin | c965076 | 2013-03-22 22:03:09 -0500 | [diff] [blame] | 378 | reserved_ram_resource(dev, index++, |
| 379 | CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10, |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 380 | CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10); |
| 381 | #endif |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | static void mc_read_resources(device_t dev) |
| 385 | { |
| 386 | /* Read standard PCI resources. */ |
| 387 | pci_dev_read_resources(dev); |
| 388 | |
| 389 | /* Add all fixed MMIO resources. */ |
| 390 | mc_add_fixed_mmio_resources(dev); |
| 391 | |
| 392 | /* Calculate and add DRAM resources. */ |
| 393 | mc_add_dram_resources(dev); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | static void intel_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 397 | { |
| 398 | if (!vendor || !device) { |
| 399 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 400 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 401 | } else { |
| 402 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 403 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 404 | } |
| 405 | } |
| 406 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 407 | static void northbridge_init(struct device *dev) |
| 408 | { |
Duncan Laurie | c70353f | 2013-06-28 14:40:38 -0700 | [diff] [blame] | 409 | u8 bios_reset_cpl, pair; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 410 | |
Duncan Laurie | c70353f | 2013-06-28 14:40:38 -0700 | [diff] [blame] | 411 | /* Enable Power Aware Interrupt Routing */ |
| 412 | pair = MCHBAR8(0x5418); |
| 413 | pair &= ~0x7; /* Clear 2:0 */ |
| 414 | pair |= 0x4; /* Fixed Priority */ |
| 415 | MCHBAR8(0x5418) = pair; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 416 | |
| 417 | /* |
Duncan Laurie | c70353f | 2013-06-28 14:40:38 -0700 | [diff] [blame] | 418 | * 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] | 419 | * that BIOS has initialized memory and power management |
| 420 | */ |
| 421 | bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL); |
Duncan Laurie | c70353f | 2013-06-28 14:40:38 -0700 | [diff] [blame] | 422 | bios_reset_cpl |= 3; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 423 | MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl; |
| 424 | printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n"); |
| 425 | |
| 426 | /* Configure turbo power limits 1ms after reset complete bit */ |
| 427 | mdelay(1); |
| 428 | set_power_limits(28); |
| 429 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 430 | /* Set here before graphics PM init */ |
| 431 | MCHBAR32(0x5500) = 0x00100001; |
| 432 | } |
| 433 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 434 | static struct pci_operations intel_pci_ops = { |
| 435 | .set_subsystem = intel_set_subsystem, |
| 436 | }; |
| 437 | |
| 438 | static struct device_operations mc_ops = { |
| 439 | .read_resources = mc_read_resources, |
Aaron Durbin | c12ef97 | 2012-12-18 14:22:49 -0600 | [diff] [blame] | 440 | .set_resources = pci_dev_set_resources, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 441 | .enable_resources = pci_dev_enable_resources, |
| 442 | .init = northbridge_init, |
Vladimir Serbinenko | 0a66991 | 2014-10-05 14:34:17 +0200 | [diff] [blame] | 443 | .acpi_fill_ssdt_generator = generate_cpu_entries, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 444 | .scan_bus = 0, |
| 445 | .ops_pci = &intel_pci_ops, |
| 446 | }; |
| 447 | |
Aaron Durbin | c1989c4 | 2012-12-11 17:13:17 -0600 | [diff] [blame] | 448 | static const struct pci_driver mc_driver_hsw_mobile __pci_driver = { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 449 | .ops = &mc_ops, |
| 450 | .vendor = PCI_VENDOR_ID_INTEL, |
Aaron Durbin | 21efd8c | 2013-01-17 09:39:39 -0600 | [diff] [blame] | 451 | .device = PCI_DEVICE_ID_HSW_MOBILE, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 452 | }; |
| 453 | |
Duncan Laurie | df7be71 | 2012-12-17 11:22:57 -0800 | [diff] [blame] | 454 | static const struct pci_driver mc_driver_hsw_ult __pci_driver = { |
| 455 | .ops = &mc_ops, |
| 456 | .vendor = PCI_VENDOR_ID_INTEL, |
Aaron Durbin | 21efd8c | 2013-01-17 09:39:39 -0600 | [diff] [blame] | 457 | .device = PCI_DEVICE_ID_HSW_ULT, |
Duncan Laurie | df7be71 | 2012-12-17 11:22:57 -0800 | [diff] [blame] | 458 | }; |
| 459 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 460 | static void cpu_bus_init(device_t dev) |
| 461 | { |
Aaron Durbin | 7af2069 | 2013-01-14 14:54:41 -0600 | [diff] [blame] | 462 | bsp_init_and_start_aps(dev->link_list); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 463 | } |
| 464 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 465 | static struct device_operations cpu_bus_ops = { |
Edward O'Callaghan | 9f74462 | 2014-10-31 08:12:34 +1100 | [diff] [blame] | 466 | .read_resources = DEVICE_NOOP, |
| 467 | .set_resources = DEVICE_NOOP, |
| 468 | .enable_resources = DEVICE_NOOP, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 469 | .init = cpu_bus_init, |
| 470 | .scan_bus = 0, |
| 471 | }; |
| 472 | |
| 473 | static void enable_dev(device_t dev) |
| 474 | { |
| 475 | /* Set the operations if it is a special bus type */ |
| 476 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
| 477 | dev->ops = &pci_domain_ops; |
| 478 | } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
| 479 | dev->ops = &cpu_bus_ops; |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | struct chip_operations northbridge_intel_haswell_ops = { |
| 484 | CHIP_NAME("Intel i7 (Haswell) integrated Northbridge") |
| 485 | .enable_dev = enable_dev, |
| 486 | }; |