Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <console/console.h> |
| 16 | #include <arch/acpi.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 17 | #include <device/pci_ops.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 18 | #include <stdint.h> |
| 19 | #include <delay.h> |
| 20 | #include <device/device.h> |
| 21 | #include <device/pci.h> |
| 22 | #include <device/pci_ids.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 23 | #include <vendorcode/google/chromeos/chromeos.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 24 | #include <soc/cpu.h> |
| 25 | #include <soc/iomap.h> |
| 26 | #include <soc/pci_devs.h> |
| 27 | #include <soc/ramstage.h> |
| 28 | #include <soc/systemagent.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 29 | |
Duncan Laurie | 84b9cf4 | 2014-07-31 10:46:57 -0700 | [diff] [blame] | 30 | u8 systemagent_revision(void) |
| 31 | { |
Kyösti Mälkki | 71756c21 | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 32 | struct device *sa_dev = pcidev_path_on_root(SA_DEVFN_ROOT); |
| 33 | return pci_read_config8(sa_dev, PCI_REVISION_ID); |
Duncan Laurie | 84b9cf4 | 2014-07-31 10:46:57 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Matt DeVillier | 42d1660 | 2018-07-04 16:32:21 -0500 | [diff] [blame] | 36 | uintptr_t sa_get_tolud_base(void) |
| 37 | { |
Kyösti Mälkki | 71756c21 | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 38 | struct device *sa_dev = pcidev_path_on_root(SA_DEVFN_ROOT); |
Matt DeVillier | 42d1660 | 2018-07-04 16:32:21 -0500 | [diff] [blame] | 39 | /* Bit 0 is lock bit, not part of address */ |
Kyösti Mälkki | 71756c21 | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 40 | return pci_read_config32(sa_dev, TOLUD) & ~1; |
Matt DeVillier | 42d1660 | 2018-07-04 16:32:21 -0500 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | uintptr_t sa_get_gsm_base(void) |
| 44 | { |
Kyösti Mälkki | 71756c21 | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 45 | struct device *sa_dev = pcidev_path_on_root(SA_DEVFN_ROOT); |
Matt DeVillier | 42d1660 | 2018-07-04 16:32:21 -0500 | [diff] [blame] | 46 | /* Bit 0 is lock bit, not part of address */ |
Kyösti Mälkki | 71756c21 | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 47 | return pci_read_config32(sa_dev, BGSM) & ~1; |
Matt DeVillier | 42d1660 | 2018-07-04 16:32:21 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 50 | static int get_pcie_bar(struct device *dev, unsigned int index, u32 *base, |
| 51 | u32 *len) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 52 | { |
| 53 | u32 pciexbar_reg; |
| 54 | |
| 55 | *base = 0; |
| 56 | *len = 0; |
| 57 | |
| 58 | pciexbar_reg = pci_read_config32(dev, index); |
| 59 | |
| 60 | if (!(pciexbar_reg & (1 << 0))) |
| 61 | return 0; |
| 62 | |
| 63 | switch ((pciexbar_reg >> 1) & 3) { |
| 64 | case 0: // 256MB |
| 65 | *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)| |
| 66 | (1 << 28)); |
| 67 | *len = 256 * 1024 * 1024; |
| 68 | return 1; |
| 69 | case 1: // 128M |
| 70 | *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)| |
| 71 | (1 << 28)|(1 << 27)); |
| 72 | *len = 128 * 1024 * 1024; |
| 73 | return 1; |
| 74 | case 2: // 64M |
| 75 | *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)| |
| 76 | (1 << 28)|(1 << 27)|(1 << 26)); |
| 77 | *len = 64 * 1024 * 1024; |
| 78 | return 1; |
| 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 84 | 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] | 85 | { |
| 86 | u32 bar; |
| 87 | |
| 88 | bar = pci_read_config32(dev, index); |
| 89 | |
| 90 | /* If not enabled don't report it. */ |
| 91 | if (!(bar & 0x1)) |
| 92 | return 0; |
| 93 | |
| 94 | /* Knock down the enable bit. */ |
| 95 | *base = bar & ~1; |
| 96 | |
| 97 | return 1; |
| 98 | } |
| 99 | |
| 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 | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 103 | 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] | 104 | u32 *len) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 105 | { |
| 106 | u32 bar; |
| 107 | |
| 108 | bar = MCHBAR32(index); |
| 109 | |
| 110 | /* If not enabled don't report it. */ |
| 111 | if (!(bar & 0x1)) |
| 112 | return 0; |
| 113 | |
| 114 | /* Knock down the enable bit. */ |
| 115 | *base = bar & ~1; |
| 116 | |
| 117 | return 1; |
| 118 | } |
| 119 | |
| 120 | struct fixed_mmio_descriptor { |
| 121 | unsigned int index; |
| 122 | u32 size; |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 123 | int (*get_resource)(struct device *dev, unsigned int index, |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 124 | u32 *base, u32 *size); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 125 | const char *description; |
| 126 | }; |
| 127 | |
| 128 | struct fixed_mmio_descriptor mc_fixed_resources[] = { |
| 129 | { PCIEXBAR, 0, get_pcie_bar, "PCIEXBAR" }, |
| 130 | { MCHBAR, MCH_BASE_SIZE, get_bar, "MCHBAR" }, |
| 131 | { DMIBAR, DMI_BASE_SIZE, get_bar, "DMIBAR" }, |
| 132 | { EPBAR, EP_BASE_SIZE, get_bar, "EPBAR" }, |
| 133 | { GDXCBAR, GDXC_BASE_SIZE, get_bar_in_mchbar, "GDXCBAR" }, |
| 134 | { EDRAMBAR, EDRAM_BASE_SIZE, get_bar_in_mchbar, "EDRAMBAR" }, |
| 135 | }; |
| 136 | |
| 137 | /* |
| 138 | * Add all known fixed MMIO ranges that hang off the host bridge/memory |
| 139 | * controller device. |
| 140 | */ |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 141 | static void mc_add_fixed_mmio_resources(struct device *dev) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 142 | { |
| 143 | int i; |
| 144 | |
| 145 | for (i = 0; i < ARRAY_SIZE(mc_fixed_resources); i++) { |
| 146 | u32 base; |
| 147 | u32 size; |
| 148 | struct resource *resource; |
| 149 | unsigned int index; |
| 150 | |
| 151 | size = mc_fixed_resources[i].size; |
| 152 | index = mc_fixed_resources[i].index; |
| 153 | if (!mc_fixed_resources[i].get_resource(dev, index, |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 154 | &base, &size)) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 155 | continue; |
| 156 | |
| 157 | resource = new_resource(dev, mc_fixed_resources[i].index); |
| 158 | resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 159 | IORESOURCE_STORED | IORESOURCE_RESERVE | |
| 160 | IORESOURCE_ASSIGNED; |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 161 | resource->base = base; |
| 162 | resource->size = size; |
| 163 | printk(BIOS_DEBUG, "%s: Adding %s @ %x 0x%08lx-0x%08lx.\n", |
| 164 | __func__, mc_fixed_resources[i].description, index, |
| 165 | (unsigned long)base, (unsigned long)(base + size - 1)); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | /* Host Memory Map: |
| 170 | * |
| 171 | * +--------------------------+ TOUUD |
| 172 | * | | |
| 173 | * +--------------------------+ 4GiB |
| 174 | * | PCI Address Space | |
| 175 | * +--------------------------+ TOLUD (also maps into MC address space) |
| 176 | * | iGD | |
| 177 | * +--------------------------+ BDSM |
| 178 | * | GTT | |
| 179 | * +--------------------------+ BGSM |
| 180 | * | TSEG | |
| 181 | * +--------------------------+ TSEGMB |
| 182 | * | Usage DRAM | |
| 183 | * +--------------------------+ 0 |
| 184 | * |
| 185 | * Some of the base registers above can be equal making the size of those |
| 186 | * regions 0. The reason is because the memory controller internally subtracts |
| 187 | * the base registers from each other to determine sizes of the regions. In |
| 188 | * other words, the memory map is in a fixed order no matter what. |
| 189 | */ |
| 190 | |
| 191 | struct map_entry { |
| 192 | int reg; |
| 193 | int is_64_bit; |
| 194 | int is_limit; |
| 195 | const char *description; |
| 196 | }; |
| 197 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 198 | static void read_map_entry(struct device *dev, struct map_entry *entry, |
Lee Leahy | 26b7cd0 | 2017-03-16 18:47:55 -0700 | [diff] [blame] | 199 | uint64_t *result) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [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; |
| 213 | } |
| 214 | |
| 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"), |
| 262 | [BDSM_REG] = MAP_ENTRY_BASE_32(BDSM, "BDSM"), |
| 263 | [BGSM_REG] = MAP_ENTRY_BASE_32(BGSM, "BGSM"), |
| 264 | [TSEG_REG] = MAP_ENTRY_BASE_32(TSEG, "TESGMB"), |
| 265 | }; |
| 266 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 267 | static void mc_read_map_entries(struct device *dev, uint64_t *values) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 268 | { |
| 269 | int i; |
Lee Leahy | 8a9c7dc | 2017-03-17 10:43:25 -0700 | [diff] [blame] | 270 | for (i = 0; i < NUM_MAP_ENTRIES; i++) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 271 | read_map_entry(dev, &memory_map[i], &values[i]); |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 274 | static void mc_report_map_entries(struct device *dev, uint64_t *values) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 275 | { |
| 276 | int i; |
| 277 | for (i = 0; i < NUM_MAP_ENTRIES; i++) { |
| 278 | printk(BIOS_DEBUG, "MC MAP: %s: 0x%llx\n", |
| 279 | memory_map[i].description, values[i]); |
| 280 | } |
| 281 | /* One can validate the BDSM and BGSM against the GGC. */ |
| 282 | printk(BIOS_DEBUG, "MC MAP: GGC: 0x%x\n", pci_read_config16(dev, GGC)); |
| 283 | } |
| 284 | |
Elyes HAOUAS | 040aff2 | 2018-05-27 16:30:36 +0200 | [diff] [blame] | 285 | static void mc_add_dram_resources(struct device *dev, int *resource_cnt) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 286 | { |
| 287 | unsigned long base_k, size_k; |
| 288 | unsigned long touud_k; |
| 289 | unsigned long index; |
| 290 | struct resource *resource; |
| 291 | uint64_t mc_values[NUM_MAP_ENTRIES]; |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 292 | unsigned long dpr_size = 0; |
| 293 | u32 dpr_reg; |
Kyösti Mälkki | 71756c21 | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 294 | struct device *sa_dev = pcidev_path_on_root(SA_DEVFN_ROOT); |
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 | */ |
Kyösti Mälkki | 71756c21 | 2019-07-12 13:10:19 +0300 | [diff] [blame] | 306 | dpr_reg = pci_read_config32(sa_dev, DPR); |
Duncan Laurie | 6168027 | 2014-05-05 12:42:35 -0500 | [diff] [blame] | 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 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 387 | if (CONFIG(CHROMEOS)) |
Frans Hendriks | ef05dc8 | 2018-11-27 10:35:16 +0100 | [diff] [blame] | 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 | }; |