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