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