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