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