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