Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2009 coresystems GmbH |
| 5 | * Copyright (C) 2014 Google Inc. |
| 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. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <arch/acpi.h> |
| 19 | #include <arch/io.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame^] | 20 | #include <device/pci_ops.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 21 | #include <stdint.h> |
| 22 | #include <delay.h> |
| 23 | #include <device/device.h> |
| 24 | #include <device/pci.h> |
| 25 | #include <device/pci_ids.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <string.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 28 | #include <vendorcode/google/chromeos/chromeos.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 29 | #include <soc/cpu.h> |
| 30 | #include <soc/iomap.h> |
| 31 | #include <soc/pci_devs.h> |
| 32 | #include <soc/ramstage.h> |
| 33 | #include <soc/systemagent.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 34 | |
Duncan Laurie | 84b9cf4 | 2014-07-31 10:46:57 -0700 | [diff] [blame] | 35 | u8 systemagent_revision(void) |
| 36 | { |
| 37 | return pci_read_config8(SA_DEV_ROOT, PCI_REVISION_ID); |
| 38 | } |
| 39 | |
Matt DeVillier | 42d1660 | 2018-07-04 16:32:21 -0500 | [diff] [blame] | 40 | uintptr_t sa_get_tolud_base(void) |
| 41 | { |
| 42 | /* Bit 0 is lock bit, not part of address */ |
| 43 | return pci_read_config32(SA_DEV_ROOT, TOLUD) & ~1; |
| 44 | } |
| 45 | |
| 46 | uintptr_t sa_get_gsm_base(void) |
| 47 | { |
| 48 | /* Bit 0 is lock bit, not part of address */ |
| 49 | return pci_read_config32(SA_DEV_ROOT, BGSM) & ~1; |
| 50 | } |
| 51 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 52 | static int get_pcie_bar(struct device *dev, unsigned int index, u32 *base, |
| 53 | u32 *len) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 54 | { |
| 55 | u32 pciexbar_reg; |
| 56 | |
| 57 | *base = 0; |
| 58 | *len = 0; |
| 59 | |
| 60 | pciexbar_reg = pci_read_config32(dev, index); |
| 61 | |
| 62 | if (!(pciexbar_reg & (1 << 0))) |
| 63 | return 0; |
| 64 | |
| 65 | switch ((pciexbar_reg >> 1) & 3) { |
| 66 | case 0: // 256MB |
| 67 | *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)| |
| 68 | (1 << 28)); |
| 69 | *len = 256 * 1024 * 1024; |
| 70 | return 1; |
| 71 | case 1: // 128M |
| 72 | *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)| |
| 73 | (1 << 28)|(1 << 27)); |
| 74 | *len = 128 * 1024 * 1024; |
| 75 | return 1; |
| 76 | case 2: // 64M |
| 77 | *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)| |
| 78 | (1 << 28)|(1 << 27)|(1 << 26)); |
| 79 | *len = 64 * 1024 * 1024; |
| 80 | return 1; |
| 81 | } |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 86 | static int get_bar(struct device *dev, unsigned int index, u32 *base, u32 *len) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 87 | { |
| 88 | u32 bar; |
| 89 | |
| 90 | bar = pci_read_config32(dev, index); |
| 91 | |
| 92 | /* If not enabled don't report it. */ |
| 93 | if (!(bar & 0x1)) |
| 94 | return 0; |
| 95 | |
| 96 | /* Knock down the enable bit. */ |
| 97 | *base = bar & ~1; |
| 98 | |
| 99 | return 1; |
| 100 | } |
| 101 | |
| 102 | /* There are special BARs that actually are programmed in the MCHBAR. These |
| 103 | * Intel special features, but they do consume resources that need to be |
| 104 | * accounted for. */ |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 105 | static int get_bar_in_mchbar(struct device *dev, unsigned int index, u32 *base, |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 106 | u32 *len) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 107 | { |
| 108 | u32 bar; |
| 109 | |
| 110 | bar = MCHBAR32(index); |
| 111 | |
| 112 | /* If not enabled don't report it. */ |
| 113 | if (!(bar & 0x1)) |
| 114 | return 0; |
| 115 | |
| 116 | /* Knock down the enable bit. */ |
| 117 | *base = bar & ~1; |
| 118 | |
| 119 | return 1; |
| 120 | } |
| 121 | |
| 122 | struct fixed_mmio_descriptor { |
| 123 | unsigned int index; |
| 124 | u32 size; |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 125 | int (*get_resource)(struct device *dev, unsigned int index, |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 126 | u32 *base, u32 *size); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 127 | const char *description; |
| 128 | }; |
| 129 | |
| 130 | struct fixed_mmio_descriptor mc_fixed_resources[] = { |
| 131 | { PCIEXBAR, 0, get_pcie_bar, "PCIEXBAR" }, |
| 132 | { MCHBAR, MCH_BASE_SIZE, get_bar, "MCHBAR" }, |
| 133 | { DMIBAR, DMI_BASE_SIZE, get_bar, "DMIBAR" }, |
| 134 | { EPBAR, EP_BASE_SIZE, get_bar, "EPBAR" }, |
| 135 | { GDXCBAR, GDXC_BASE_SIZE, get_bar_in_mchbar, "GDXCBAR" }, |
| 136 | { EDRAMBAR, EDRAM_BASE_SIZE, get_bar_in_mchbar, "EDRAMBAR" }, |
| 137 | }; |
| 138 | |
| 139 | /* |
| 140 | * Add all known fixed MMIO ranges that hang off the host bridge/memory |
| 141 | * controller device. |
| 142 | */ |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 143 | static void mc_add_fixed_mmio_resources(struct device *dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 144 | { |
| 145 | int i; |
| 146 | |
| 147 | for (i = 0; i < ARRAY_SIZE(mc_fixed_resources); i++) { |
| 148 | u32 base; |
| 149 | u32 size; |
| 150 | struct resource *resource; |
| 151 | unsigned int index; |
| 152 | |
| 153 | size = mc_fixed_resources[i].size; |
| 154 | index = mc_fixed_resources[i].index; |
| 155 | if (!mc_fixed_resources[i].get_resource(dev, index, |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 156 | &base, &size)) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 157 | continue; |
| 158 | |
| 159 | resource = new_resource(dev, mc_fixed_resources[i].index); |
| 160 | resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 161 | IORESOURCE_STORED | IORESOURCE_RESERVE | |
| 162 | IORESOURCE_ASSIGNED; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 163 | resource->base = base; |
| 164 | resource->size = size; |
| 165 | printk(BIOS_DEBUG, "%s: Adding %s @ %x 0x%08lx-0x%08lx.\n", |
| 166 | __func__, mc_fixed_resources[i].description, index, |
| 167 | (unsigned long)base, (unsigned long)(base + size - 1)); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | /* Host Memory Map: |
| 172 | * |
| 173 | * +--------------------------+ TOUUD |
| 174 | * | | |
| 175 | * +--------------------------+ 4GiB |
| 176 | * | PCI Address Space | |
| 177 | * +--------------------------+ TOLUD (also maps into MC address space) |
| 178 | * | iGD | |
| 179 | * +--------------------------+ BDSM |
| 180 | * | GTT | |
| 181 | * +--------------------------+ BGSM |
| 182 | * | TSEG | |
| 183 | * +--------------------------+ TSEGMB |
| 184 | * | Usage DRAM | |
| 185 | * +--------------------------+ 0 |
| 186 | * |
| 187 | * Some of the base registers above can be equal making the size of those |
| 188 | * regions 0. The reason is because the memory controller internally subtracts |
| 189 | * the base registers from each other to determine sizes of the regions. In |
| 190 | * other words, the memory map is in a fixed order no matter what. |
| 191 | */ |
| 192 | |
| 193 | struct map_entry { |
| 194 | int reg; |
| 195 | int is_64_bit; |
| 196 | int is_limit; |
| 197 | const char *description; |
| 198 | }; |
| 199 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 200 | static void read_map_entry(struct device *dev, struct map_entry *entry, |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 201 | uint64_t *result) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 202 | { |
| 203 | uint64_t value; |
| 204 | uint64_t mask; |
| 205 | |
| 206 | /* All registers are on a 1MiB granularity. */ |
| 207 | mask = ((1ULL<<20)-1); |
| 208 | mask = ~mask; |
| 209 | |
| 210 | value = 0; |
| 211 | |
| 212 | if (entry->is_64_bit) { |
| 213 | value = pci_read_config32(dev, entry->reg + 4); |
| 214 | value <<= 32; |
| 215 | } |
| 216 | |
| 217 | value |= pci_read_config32(dev, entry->reg); |
| 218 | value &= mask; |
| 219 | |
| 220 | if (entry->is_limit) |
| 221 | value |= ~mask; |
| 222 | |
| 223 | *result = value; |
| 224 | } |
| 225 | |
| 226 | #define MAP_ENTRY(reg_, is_64_, is_limit_, desc_) \ |
| 227 | { \ |
| 228 | .reg = reg_, \ |
| 229 | .is_64_bit = is_64_, \ |
| 230 | .is_limit = is_limit_, \ |
| 231 | .description = desc_, \ |
| 232 | } |
| 233 | |
| 234 | #define MAP_ENTRY_BASE_64(reg_, desc_) \ |
| 235 | MAP_ENTRY(reg_, 1, 0, desc_) |
| 236 | #define MAP_ENTRY_LIMIT_64(reg_, desc_) \ |
| 237 | MAP_ENTRY(reg_, 1, 1, desc_) |
| 238 | #define MAP_ENTRY_BASE_32(reg_, desc_) \ |
| 239 | MAP_ENTRY(reg_, 0, 0, desc_) |
| 240 | |
| 241 | enum { |
| 242 | TOM_REG, |
| 243 | TOUUD_REG, |
| 244 | MESEG_BASE_REG, |
| 245 | MESEG_LIMIT_REG, |
| 246 | REMAP_BASE_REG, |
| 247 | REMAP_LIMIT_REG, |
| 248 | TOLUD_REG, |
| 249 | BGSM_REG, |
| 250 | BDSM_REG, |
| 251 | TSEG_REG, |
| 252 | // Must be last. |
| 253 | NUM_MAP_ENTRIES |
| 254 | }; |
| 255 | |
| 256 | static struct map_entry memory_map[NUM_MAP_ENTRIES] = { |
| 257 | [TOM_REG] = MAP_ENTRY_BASE_64(TOM, "TOM"), |
| 258 | [TOUUD_REG] = MAP_ENTRY_BASE_64(TOUUD, "TOUUD"), |
| 259 | [MESEG_BASE_REG] = MAP_ENTRY_BASE_64(MESEG_BASE, "MESEG_BASE"), |
| 260 | [MESEG_LIMIT_REG] = MAP_ENTRY_LIMIT_64(MESEG_LIMIT, "MESEG_LIMIT"), |
| 261 | [REMAP_BASE_REG] = MAP_ENTRY_BASE_64(REMAPBASE, "REMAP_BASE"), |
| 262 | [REMAP_LIMIT_REG] = MAP_ENTRY_LIMIT_64(REMAPLIMIT, "REMAP_LIMIT"), |
| 263 | [TOLUD_REG] = MAP_ENTRY_BASE_32(TOLUD, "TOLUD"), |
| 264 | [BDSM_REG] = MAP_ENTRY_BASE_32(BDSM, "BDSM"), |
| 265 | [BGSM_REG] = MAP_ENTRY_BASE_32(BGSM, "BGSM"), |
| 266 | [TSEG_REG] = MAP_ENTRY_BASE_32(TSEG, "TESGMB"), |
| 267 | }; |
| 268 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 269 | static void mc_read_map_entries(struct device *dev, uint64_t *values) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 270 | { |
| 271 | int i; |
Lee Leahy | 8a9c7dc | 2017-03-17 10:43:25 -0700 | [diff] [blame] | 272 | for (i = 0; i < NUM_MAP_ENTRIES; i++) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 273 | read_map_entry(dev, &memory_map[i], &values[i]); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 276 | static void mc_report_map_entries(struct device *dev, uint64_t *values) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 277 | { |
| 278 | int i; |
| 279 | for (i = 0; i < NUM_MAP_ENTRIES; i++) { |
| 280 | printk(BIOS_DEBUG, "MC MAP: %s: 0x%llx\n", |
| 281 | memory_map[i].description, values[i]); |
| 282 | } |
| 283 | /* One can validate the BDSM and BGSM against the GGC. */ |
| 284 | printk(BIOS_DEBUG, "MC MAP: GGC: 0x%x\n", pci_read_config16(dev, GGC)); |
| 285 | } |
| 286 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 287 | static void mc_add_dram_resources(struct device *dev, int *resource_cnt) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 288 | { |
| 289 | unsigned long base_k, size_k; |
| 290 | unsigned long touud_k; |
| 291 | unsigned long index; |
| 292 | struct resource *resource; |
| 293 | uint64_t mc_values[NUM_MAP_ENTRIES]; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 294 | unsigned long dpr_size = 0; |
| 295 | u32 dpr_reg; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 296 | |
| 297 | /* Read in the MAP registers and report their values. */ |
| 298 | mc_read_map_entries(dev, &mc_values[0]); |
| 299 | mc_report_map_entries(dev, &mc_values[0]); |
| 300 | |
| 301 | /* |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 302 | * DMA Protected Range can be reserved below TSEG for PCODE patch |
| 303 | * or TXT/BootGuard related data. Rather than report a base address |
| 304 | * the DPR register reports the TOP of the region, which is the same |
| 305 | * as TSEG base. The region size is reported in MiB in bits 11:4. |
| 306 | */ |
| 307 | dpr_reg = pci_read_config32(SA_DEV_ROOT, DPR); |
| 308 | if (dpr_reg & DPR_EPM) { |
| 309 | dpr_size = (dpr_reg & DPR_SIZE_MASK) << 16; |
| 310 | printk(BIOS_INFO, "DPR SIZE: 0x%lx\n", dpr_size); |
| 311 | } |
| 312 | |
| 313 | /* |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 314 | * These are the host memory ranges that should be added: |
| 315 | * - 0 -> 0xa0000: cacheable |
| 316 | * - 0xc0000 -> TSEG : cacheable |
| 317 | * - TESG -> BGSM: cacheable with standard MTRRs and reserved |
| 318 | * - BGSM -> TOLUD: not cacheable with standard MTRRs and reserved |
| 319 | * - 4GiB -> TOUUD: cacheable |
| 320 | * |
| 321 | * The default SMRAM space is reserved so that the range doesn't |
| 322 | * have to be saved during S3 Resume. Once marked reserved the OS |
| 323 | * cannot use the memory. This is a bit of an odd place to reserve |
| 324 | * the region, but the CPU devices don't have dev_ops->read_resources() |
| 325 | * called on them. |
| 326 | * |
| 327 | * The range 0xa0000 -> 0xc0000 does not have any resources |
| 328 | * associated with it to handle legacy VGA memory. If this range |
| 329 | * is not omitted the mtrr code will setup the area as cacheable |
| 330 | * causing VGA access to not work. |
| 331 | * |
| 332 | * The TSEG region is mapped as cacheable so that one can perform |
| 333 | * SMRAM relocation faster. Once the SMRR is enabled the SMRR takes |
| 334 | * precedence over the existing MTRRs covering this region. |
| 335 | * |
| 336 | * It should be noted that cacheable entry types need to be added in |
| 337 | * order. The reason is that the current MTRR code assumes this and |
| 338 | * falls over itself if it isn't. |
| 339 | * |
| 340 | * The resource index starts low and should not meet or exceed |
| 341 | * PCI_BASE_ADDRESS_0. |
| 342 | */ |
Matt DeVillier | 81a6f10 | 2018-02-19 17:33:48 -0600 | [diff] [blame] | 343 | index = *resource_cnt; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 344 | |
| 345 | /* 0 - > 0xa0000 */ |
| 346 | base_k = 0; |
| 347 | size_k = (0xa0000 >> 10) - base_k; |
| 348 | ram_resource(dev, index++, base_k, size_k); |
| 349 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 350 | /* 0xc0000 -> TSEG - DPR */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 351 | base_k = 0xc0000 >> 10; |
| 352 | size_k = (unsigned long)(mc_values[TSEG_REG] >> 10) - base_k; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 353 | size_k -= dpr_size >> 10; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 354 | ram_resource(dev, index++, base_k, size_k); |
| 355 | |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 356 | /* TSEG - DPR -> BGSM */ |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 357 | resource = new_resource(dev, index++); |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 358 | resource->base = mc_values[TSEG_REG] - dpr_size; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 359 | resource->size = mc_values[BGSM_REG] - resource->base; |
| 360 | resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 361 | IORESOURCE_STORED | IORESOURCE_RESERVE | |
| 362 | IORESOURCE_ASSIGNED | IORESOURCE_CACHEABLE; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 363 | |
| 364 | /* BGSM -> TOLUD */ |
| 365 | resource = new_resource(dev, index++); |
| 366 | resource->base = mc_values[BGSM_REG]; |
| 367 | resource->size = mc_values[TOLUD_REG] - resource->base; |
| 368 | resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 369 | IORESOURCE_STORED | IORESOURCE_RESERVE | |
| 370 | IORESOURCE_ASSIGNED; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 371 | |
| 372 | /* 4GiB -> TOUUD */ |
| 373 | base_k = 4096 * 1024; /* 4GiB */ |
| 374 | touud_k = mc_values[TOUUD_REG] >> 10; |
| 375 | size_k = touud_k - base_k; |
| 376 | if (touud_k > base_k) |
| 377 | ram_resource(dev, index++, base_k, size_k); |
| 378 | |
| 379 | /* Reserve everything between A segment and 1MB: |
| 380 | * |
| 381 | * 0xa0000 - 0xbffff: legacy VGA |
| 382 | * 0xc0000 - 0xfffff: RAM |
| 383 | */ |
| 384 | mmio_resource(dev, index++, (0xa0000 >> 10), (0xc0000 - 0xa0000) >> 10); |
| 385 | reserved_ram_resource(dev, index++, (0xc0000 >> 10), |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 386 | (0x100000 - 0xc0000) >> 10); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 387 | |
Frans Hendriks | ef05dc8 | 2018-11-27 10:35:16 +0100 | [diff] [blame] | 388 | if (IS_ENABLED(CONFIG_CHROMEOS)) |
| 389 | chromeos_reserve_ram_oops(dev, index++); |
Matt DeVillier | 81a6f10 | 2018-02-19 17:33:48 -0600 | [diff] [blame] | 390 | |
| 391 | *resource_cnt = index; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 394 | static void systemagent_read_resources(struct device *dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 395 | { |
Matt DeVillier | 81a6f10 | 2018-02-19 17:33:48 -0600 | [diff] [blame] | 396 | int index = 0; |
| 397 | const bool vtd_capable = |
| 398 | !(pci_read_config32(dev, CAPID0_A) & VTD_DISABLE); |
| 399 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 400 | /* Read standard PCI resources. */ |
| 401 | pci_dev_read_resources(dev); |
| 402 | |
| 403 | /* Add all fixed MMIO resources. */ |
| 404 | mc_add_fixed_mmio_resources(dev); |
| 405 | |
Matt DeVillier | 81a6f10 | 2018-02-19 17:33:48 -0600 | [diff] [blame] | 406 | /* Add VT-d MMIO resources if capable */ |
| 407 | if (vtd_capable) { |
| 408 | mmio_resource(dev, index++, GFXVT_BASE_ADDRESS / KiB, |
| 409 | GFXVT_BASE_SIZE / KiB); |
| 410 | mmio_resource(dev, index++, VTVC0_BASE_ADDRESS / KiB, |
| 411 | VTVC0_BASE_SIZE / KiB); |
| 412 | } |
| 413 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 414 | /* Calculate and add DRAM resources. */ |
Matt DeVillier | 81a6f10 | 2018-02-19 17:33:48 -0600 | [diff] [blame] | 415 | mc_add_dram_resources(dev, &index); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | static void systemagent_init(struct device *dev) |
| 419 | { |
| 420 | u8 bios_reset_cpl, pair; |
| 421 | |
| 422 | /* Enable Power Aware Interrupt Routing */ |
| 423 | pair = MCHBAR8(MCH_PAIR); |
| 424 | pair &= ~0x7; /* Clear 2:0 */ |
| 425 | pair |= 0x4; /* Fixed Priority */ |
| 426 | MCHBAR8(MCH_PAIR) = pair; |
| 427 | |
| 428 | /* |
| 429 | * Set bits 0+1 of BIOS_RESET_CPL to indicate to the CPU |
| 430 | * that BIOS has initialized memory and power management |
| 431 | */ |
| 432 | bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL); |
| 433 | bios_reset_cpl |= 3; |
| 434 | MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl; |
| 435 | printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n"); |
| 436 | |
| 437 | /* Configure turbo power limits 1ms after reset complete bit */ |
| 438 | mdelay(1); |
| 439 | set_power_limits(28); |
| 440 | } |
| 441 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 442 | static struct device_operations systemagent_ops = { |
Elyes HAOUAS | 1d19127 | 2018-11-27 12:23:48 +0100 | [diff] [blame] | 443 | .read_resources = systemagent_read_resources, |
| 444 | .acpi_fill_ssdt_generator = generate_cpu_entries, |
| 445 | .set_resources = pci_dev_set_resources, |
| 446 | .enable_resources = pci_dev_enable_resources, |
| 447 | .init = systemagent_init, |
Marc Jones | a6354a1 | 2014-12-26 22:11:14 -0700 | [diff] [blame] | 448 | .ops_pci = &broadwell_pci_ops, |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 449 | }; |
| 450 | |
| 451 | static const unsigned short systemagent_ids[] = { |
| 452 | 0x0a04, /* Haswell ULT */ |
| 453 | 0x1604, /* Broadwell-U/Y */ |
| 454 | 0x1610, /* Broadwell-H Desktop */ |
| 455 | 0x1614, /* Broadwell-H Mobile */ |
| 456 | 0 |
| 457 | }; |
| 458 | |
| 459 | static const struct pci_driver systemagent_driver __pci_driver = { |
| 460 | .ops = &systemagent_ops, |
| 461 | .vendor = PCI_VENDOR_ID_INTEL, |
| 462 | .devices = systemagent_ids |
| 463 | }; |