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