Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2009 coresystems GmbH |
| 5 | * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <arch/acpi.h> |
| 19 | #include <arch/io.h> |
| 20 | #include <stdint.h> |
| 21 | #include <delay.h> |
| 22 | #include <cpu/intel/model_206ax/model_206ax.h> |
Duncan Laurie | 77dbbac | 2012-06-25 09:51:59 -0700 | [diff] [blame] | 23 | #include <cpu/x86/msr.h> |
Aaron Durbin | c6f2722 | 2013-04-03 09:56:57 -0500 | [diff] [blame] | 24 | #include <cpu/x86/mtrr.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 25 | #include <device/device.h> |
| 26 | #include <device/pci.h> |
| 27 | #include <device/pci_ids.h> |
| 28 | #include <device/hypertransport.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <string.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 31 | #include <cpu/cpu.h> |
Stefan Reinauer | bb11e60 | 2012-05-10 12:15:18 -0700 | [diff] [blame] | 32 | #include <cbmem.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 33 | #include "chip.h" |
| 34 | #include "sandybridge.h" |
Vladimir Serbinenko | c16e9dfa | 2015-05-29 16:18:01 +0200 | [diff] [blame] | 35 | #include <cpu/intel/smm/gen1/smi.h> |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 36 | |
| 37 | static int bridge_revision_id = -1; |
| 38 | |
Kyösti Mälkki | f7bfc34 | 2013-10-18 11:02:46 +0300 | [diff] [blame] | 39 | /* IGD UMA memory */ |
| 40 | static uint64_t uma_memory_base = 0; |
| 41 | static uint64_t uma_memory_size = 0; |
| 42 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 43 | int bridge_silicon_revision(void) |
| 44 | { |
| 45 | if (bridge_revision_id < 0) { |
| 46 | uint8_t stepping = cpuid_eax(1) & 0xf; |
| 47 | uint8_t bridge_id = pci_read_config16( |
| 48 | dev_find_slot(0, PCI_DEVFN(0, 0)), |
| 49 | PCI_DEVICE_ID) & 0xf0; |
| 50 | bridge_revision_id = bridge_id | stepping; |
| 51 | } |
| 52 | return bridge_revision_id; |
| 53 | } |
| 54 | |
| 55 | /* Reserve everything between A segment and 1MB: |
| 56 | * |
| 57 | * 0xa0000 - 0xbffff: legacy VGA |
| 58 | * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel) |
| 59 | * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI |
| 60 | */ |
| 61 | static const int legacy_hole_base_k = 0xa0000 / 1024; |
| 62 | static const int legacy_hole_size_k = 384; |
| 63 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 64 | static int get_pcie_bar(u32 *base, u32 *len) |
| 65 | { |
| 66 | device_t dev; |
| 67 | u32 pciexbar_reg; |
| 68 | |
| 69 | *base = 0; |
| 70 | *len = 0; |
| 71 | |
| 72 | dev = dev_find_slot(0, PCI_DEVFN(0, 0)); |
| 73 | if (!dev) |
| 74 | return 0; |
| 75 | |
| 76 | pciexbar_reg = pci_read_config32(dev, PCIEXBAR); |
| 77 | |
| 78 | if (!(pciexbar_reg & (1 << 0))) |
| 79 | return 0; |
| 80 | |
| 81 | switch ((pciexbar_reg >> 1) & 3) { |
| 82 | case 0: // 256MB |
| 83 | *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)); |
| 84 | *len = 256 * 1024 * 1024; |
| 85 | return 1; |
| 86 | case 1: // 128M |
| 87 | *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)); |
| 88 | *len = 128 * 1024 * 1024; |
| 89 | return 1; |
| 90 | case 2: // 64M |
| 91 | *base = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26)); |
| 92 | *len = 64 * 1024 * 1024; |
| 93 | return 1; |
| 94 | } |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 99 | static void add_fixed_resources(struct device *dev, int index) |
| 100 | { |
| 101 | struct resource *resource; |
| 102 | u32 pcie_config_base, pcie_config_size; |
| 103 | |
Kyösti Mälkki | 7f189cc | 2012-07-27 13:12:03 +0300 | [diff] [blame] | 104 | mmio_resource(dev, index++, uma_memory_base >> 10, uma_memory_size >> 10); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 105 | |
| 106 | if (get_pcie_bar(&pcie_config_base, &pcie_config_size)) { |
| 107 | printk(BIOS_DEBUG, "Adding PCIe config bar base=0x%08x " |
| 108 | "size=0x%x\n", pcie_config_base, pcie_config_size); |
Kyösti Mälkki | 1ec5e74 | 2012-07-26 23:51:20 +0300 | [diff] [blame] | 109 | resource = new_resource(dev, index++); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 110 | resource->base = (resource_t) pcie_config_base; |
| 111 | resource->size = (resource_t) pcie_config_size; |
| 112 | resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE | |
| 113 | IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 114 | } |
Kyösti Mälkki | 1ec5e74 | 2012-07-26 23:51:20 +0300 | [diff] [blame] | 115 | |
Aaron Durbin | c965076 | 2013-03-22 22:03:09 -0500 | [diff] [blame] | 116 | mmio_resource(dev, index++, legacy_hole_base_k, |
| 117 | (0xc0000 >> 10) - legacy_hole_base_k); |
| 118 | reserved_ram_resource(dev, index++, 0xc0000 >> 10, |
| 119 | (0x100000 - 0xc0000) >> 10); |
Kyösti Mälkki | 1ec5e74 | 2012-07-26 23:51:20 +0300 | [diff] [blame] | 120 | |
| 121 | #if CONFIG_CHROMEOS_RAMOOPS |
Aaron Durbin | c965076 | 2013-03-22 22:03:09 -0500 | [diff] [blame] | 122 | reserved_ram_resource(dev, index++, |
| 123 | CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10, |
Kyösti Mälkki | 1ec5e74 | 2012-07-26 23:51:20 +0300 | [diff] [blame] | 124 | CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10); |
| 125 | #endif |
| 126 | |
Nico Huber | 593e7de | 2015-11-04 15:46:00 +0100 | [diff] [blame] | 127 | if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) { |
| 128 | /* Required for SandyBridge sighting 3715511 */ |
| 129 | bad_ram_resource(dev, index++, 0x20000000 >> 10, 0x00200000 >> 10); |
| 130 | bad_ram_resource(dev, index++, 0x40000000 >> 10, 0x00200000 >> 10); |
| 131 | } |
Nico Huber | bb9469c | 2015-10-21 11:49:23 +0200 | [diff] [blame] | 132 | |
| 133 | /* Reserve IOMMU BARs */ |
| 134 | const u32 capid0_a = pci_read_config32(dev, 0xe4); |
| 135 | if (!(capid0_a & (1 << 23))) { |
| 136 | mmio_resource(dev, index++, IOMMU_BASE1 >> 10, 4); |
| 137 | mmio_resource(dev, index++, IOMMU_BASE2 >> 10, 4); |
| 138 | } |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 139 | } |
| 140 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 141 | static void pci_domain_set_resources(device_t dev) |
| 142 | { |
| 143 | uint64_t tom, me_base, touud; |
| 144 | uint32_t tseg_base, uma_size, tolud; |
| 145 | uint16_t ggc; |
| 146 | unsigned long long tomk; |
| 147 | |
| 148 | /* Total Memory 2GB example: |
| 149 | * |
| 150 | * 00000000 0000MB-1992MB 1992MB RAM (writeback) |
| 151 | * 7c800000 1992MB-2000MB 8MB TSEG (SMRR) |
| 152 | * 7d000000 2000MB-2002MB 2MB GFX GTT (uncached) |
| 153 | * 7d200000 2002MB-2034MB 32MB GFX UMA (uncached) |
| 154 | * 7f200000 2034MB TOLUD |
| 155 | * 7f800000 2040MB MEBASE |
| 156 | * 7f800000 2040MB-2048MB 8MB ME UMA (uncached) |
| 157 | * 80000000 2048MB TOM |
| 158 | * 100000000 4096MB-4102MB 6MB RAM (writeback) |
| 159 | * |
| 160 | * Total Memory 4GB example: |
| 161 | * |
| 162 | * 00000000 0000MB-2768MB 2768MB RAM (writeback) |
| 163 | * ad000000 2768MB-2776MB 8MB TSEG (SMRR) |
| 164 | * ad800000 2776MB-2778MB 2MB GFX GTT (uncached) |
| 165 | * ada00000 2778MB-2810MB 32MB GFX UMA (uncached) |
| 166 | * afa00000 2810MB TOLUD |
| 167 | * ff800000 4088MB MEBASE |
| 168 | * ff800000 4088MB-4096MB 8MB ME UMA (uncached) |
| 169 | * 100000000 4096MB TOM |
| 170 | * 100000000 4096MB-5374MB 1278MB RAM (writeback) |
| 171 | * 14fe00000 5368MB TOUUD |
| 172 | */ |
| 173 | |
| 174 | /* Top of Upper Usable DRAM, including remap */ |
| 175 | touud = pci_read_config32(dev, TOUUD+4); |
| 176 | touud <<= 32; |
| 177 | touud |= pci_read_config32(dev, TOUUD); |
| 178 | |
| 179 | /* Top of Lower Usable DRAM */ |
| 180 | tolud = pci_read_config32(dev, TOLUD); |
| 181 | |
| 182 | /* Top of Memory - does not account for any UMA */ |
| 183 | tom = pci_read_config32(dev, 0xa4); |
| 184 | tom <<= 32; |
| 185 | tom |= pci_read_config32(dev, 0xa0); |
| 186 | |
| 187 | printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n", |
| 188 | touud, tolud, tom); |
| 189 | |
| 190 | /* ME UMA needs excluding if total memory <4GB */ |
| 191 | me_base = pci_read_config32(dev, 0x74); |
| 192 | me_base <<= 32; |
| 193 | me_base |= pci_read_config32(dev, 0x70); |
| 194 | |
| 195 | printk(BIOS_DEBUG, "MEBASE 0x%llx\n", me_base); |
| 196 | |
Patrick Rudolph | 240766a | 2015-10-15 15:33:25 +0200 | [diff] [blame] | 197 | uma_memory_base = tolud; |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 198 | tomk = tolud >> 10; |
| 199 | if (me_base == tolud) { |
| 200 | /* ME is from MEBASE-TOM */ |
| 201 | uma_size = (tom - me_base) >> 10; |
| 202 | /* Increment TOLUD to account for ME as RAM */ |
| 203 | tolud += uma_size << 10; |
| 204 | /* UMA starts at old TOLUD */ |
| 205 | uma_memory_base = tomk * 1024ULL; |
| 206 | uma_memory_size = uma_size * 1024ULL; |
| 207 | printk(BIOS_DEBUG, "ME UMA base 0x%llx size %uM\n", |
| 208 | me_base, uma_size >> 10); |
| 209 | } |
| 210 | |
| 211 | /* Graphics memory comes next */ |
| 212 | ggc = pci_read_config16(dev, GGC); |
| 213 | if (!(ggc & 2)) { |
| 214 | printk(BIOS_DEBUG, "IGD decoded, subtracting "); |
| 215 | |
| 216 | /* Graphics memory */ |
| 217 | uma_size = ((ggc >> 3) & 0x1f) * 32 * 1024ULL; |
| 218 | printk(BIOS_DEBUG, "%uM UMA", uma_size >> 10); |
| 219 | tomk -= uma_size; |
| 220 | uma_memory_base = tomk * 1024ULL; |
| 221 | uma_memory_size += uma_size * 1024ULL; |
| 222 | |
| 223 | /* GTT Graphics Stolen Memory Size (GGMS) */ |
| 224 | uma_size = ((ggc >> 8) & 0x3) * 1024ULL; |
| 225 | tomk -= uma_size; |
| 226 | uma_memory_base = tomk * 1024ULL; |
| 227 | uma_memory_size += uma_size * 1024ULL; |
| 228 | printk(BIOS_DEBUG, " and %uM GTT\n", uma_size >> 10); |
| 229 | } |
| 230 | |
| 231 | /* Calculate TSEG size from its base which must be below GTT */ |
| 232 | tseg_base = pci_read_config32(dev, 0xb8); |
| 233 | uma_size = (uma_memory_base - tseg_base) >> 10; |
| 234 | tomk -= uma_size; |
| 235 | uma_memory_base = tomk * 1024ULL; |
| 236 | uma_memory_size += uma_size * 1024ULL; |
| 237 | printk(BIOS_DEBUG, "TSEG base 0x%08x size %uM\n", |
| 238 | tseg_base, uma_size >> 10); |
| 239 | |
| 240 | printk(BIOS_INFO, "Available memory below 4GB: %lluM\n", tomk >> 10); |
| 241 | |
| 242 | /* Report the memory regions */ |
| 243 | ram_resource(dev, 3, 0, legacy_hole_base_k); |
| 244 | ram_resource(dev, 4, legacy_hole_base_k + legacy_hole_size_k, |
| 245 | (tomk - (legacy_hole_base_k + legacy_hole_size_k))); |
| 246 | |
| 247 | /* |
| 248 | * If >= 4GB installed then memory from TOLUD to 4GB |
| 249 | * is remapped above TOM, TOUUD will account for both |
| 250 | */ |
| 251 | touud >>= 10; /* Convert to KB */ |
| 252 | if (touud > 4096 * 1024) { |
| 253 | ram_resource(dev, 5, 4096 * 1024, touud - (4096 * 1024)); |
| 254 | printk(BIOS_INFO, "Available memory above 4GB: %lluM\n", |
| 255 | (touud >> 10) - 4096); |
| 256 | } |
| 257 | |
| 258 | add_fixed_resources(dev, 6); |
| 259 | |
| 260 | assign_resources(dev->link_list); |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | /* TODO We could determine how many PCIe busses we need in |
| 264 | * the bar. For now that number is hardcoded to a max of 64. |
| 265 | * See e7525/northbridge.c for an example. |
| 266 | */ |
| 267 | static struct device_operations pci_domain_ops = { |
| 268 | .read_resources = pci_domain_read_resources, |
| 269 | .set_resources = pci_domain_set_resources, |
| 270 | .enable_resources = NULL, |
| 271 | .init = NULL, |
| 272 | .scan_bus = pci_domain_scan_bus, |
Kyösti Mälkki | 872c922 | 2013-07-03 09:44:28 +0300 | [diff] [blame] | 273 | .ops_pci_bus = pci_bus_default_ops, |
Nico Huber | 9d9ce0d | 2015-10-26 12:59:49 +0100 | [diff] [blame] | 274 | .write_acpi_tables = northbridge_write_acpi_tables, |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 275 | }; |
| 276 | |
| 277 | static void mc_read_resources(device_t dev) |
| 278 | { |
| 279 | struct resource *resource; |
| 280 | |
| 281 | pci_dev_read_resources(dev); |
| 282 | |
| 283 | /* So, this is one of the big mysteries in the coreboot resource |
| 284 | * allocator. This resource should make sure that the address space |
| 285 | * of the PCIe memory mapped config space bar. But it does not. |
| 286 | */ |
| 287 | |
| 288 | /* We use 0xcf as an unused index for our PCIe bar so that we find it again */ |
| 289 | resource = new_resource(dev, 0xcf); |
| 290 | resource->base = DEFAULT_PCIEXBAR; |
| 291 | resource->size = 64 * 1024 * 1024; /* 64MB hard coded PCIe config space */ |
| 292 | resource->flags = |
| 293 | IORESOURCE_MEM | IORESOURCE_FIXED | IORESOURCE_STORED | |
| 294 | IORESOURCE_ASSIGNED; |
| 295 | printk(BIOS_DEBUG, "Adding PCIe enhanced config space BAR 0x%08lx-0x%08lx.\n", |
| 296 | (unsigned long)(resource->base), (unsigned long)(resource->base + resource->size)); |
| 297 | } |
| 298 | |
| 299 | static void mc_set_resources(device_t dev) |
| 300 | { |
| 301 | struct resource *resource; |
| 302 | |
| 303 | /* Report the PCIe BAR */ |
| 304 | resource = find_resource(dev, 0xcf); |
| 305 | if (resource) { |
| 306 | report_resource_stored(dev, resource, "<mmconfig>"); |
| 307 | } |
| 308 | |
| 309 | /* And call the normal set_resources */ |
| 310 | pci_dev_set_resources(dev); |
| 311 | } |
| 312 | |
| 313 | static void intel_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 314 | { |
| 315 | if (!vendor || !device) { |
| 316 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 317 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 318 | } else { |
| 319 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 320 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | static void northbridge_dmi_init(struct device *dev) |
| 325 | { |
| 326 | u32 reg32; |
| 327 | |
| 328 | /* Clear error status bits */ |
| 329 | DMIBAR32(0x1c4) = 0xffffffff; |
| 330 | DMIBAR32(0x1d0) = 0xffffffff; |
| 331 | |
| 332 | /* Steps prior to DMI ASPM */ |
Vincent Palatin | 0ff99b7 | 2012-03-28 16:10:29 -0700 | [diff] [blame] | 333 | if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) { |
| 334 | reg32 = DMIBAR32(0x250); |
| 335 | reg32 &= ~((1 << 22)|(1 << 20)); |
| 336 | reg32 |= (1 << 21); |
| 337 | DMIBAR32(0x250) = reg32; |
| 338 | } |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 339 | |
| 340 | reg32 = DMIBAR32(0x238); |
| 341 | reg32 |= (1 << 29); |
| 342 | DMIBAR32(0x238) = reg32; |
| 343 | |
| 344 | if (bridge_silicon_revision() >= SNB_STEP_D0) { |
| 345 | reg32 = DMIBAR32(0x1f8); |
| 346 | reg32 |= (1 << 16); |
| 347 | DMIBAR32(0x1f8) = reg32; |
| 348 | } else if (bridge_silicon_revision() >= SNB_STEP_D1) { |
| 349 | reg32 = DMIBAR32(0x1f8); |
| 350 | reg32 &= ~(1 << 26); |
| 351 | reg32 |= (1 << 16); |
| 352 | DMIBAR32(0x1f8) = reg32; |
| 353 | |
| 354 | reg32 = DMIBAR32(0x1fc); |
| 355 | reg32 |= (1 << 12) | (1 << 23); |
| 356 | DMIBAR32(0x1fc) = reg32; |
| 357 | } |
| 358 | |
| 359 | /* Enable ASPM on SNB link, should happen before PCH link */ |
Vincent Palatin | 0ff99b7 | 2012-03-28 16:10:29 -0700 | [diff] [blame] | 360 | if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) { |
| 361 | reg32 = DMIBAR32(0xd04); |
| 362 | reg32 |= (1 << 4); |
| 363 | DMIBAR32(0xd04) = reg32; |
| 364 | } |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 365 | |
| 366 | reg32 = DMIBAR32(0x88); |
| 367 | reg32 |= (1 << 1) | (1 << 0); |
| 368 | DMIBAR32(0x88) = reg32; |
| 369 | } |
| 370 | |
Patrick Rudolph | 3660c0f | 2015-07-28 08:01:02 +0200 | [diff] [blame] | 371 | /* Disable unused PEG devices based on devicetree */ |
| 372 | static void disable_peg(void) |
| 373 | { |
| 374 | struct device *dev; |
| 375 | u32 reg; |
| 376 | |
| 377 | dev = dev_find_slot(0, PCI_DEVFN(0, 0)); |
| 378 | reg = pci_read_config32(dev, DEVEN); |
| 379 | |
| 380 | dev = dev_find_slot(0, PCI_DEVFN(1, 2)); |
Nico Huber | 2dc15e9 | 2016-02-04 18:59:48 +0100 | [diff] [blame] | 381 | if (!dev || !dev->enabled) { |
Patrick Rudolph | 3660c0f | 2015-07-28 08:01:02 +0200 | [diff] [blame] | 382 | printk(BIOS_DEBUG, "Disabling PEG12.\n"); |
| 383 | reg &= ~DEVEN_PEG12; |
| 384 | } |
| 385 | dev = dev_find_slot(0, PCI_DEVFN(1, 1)); |
Nico Huber | 2dc15e9 | 2016-02-04 18:59:48 +0100 | [diff] [blame] | 386 | if (!dev || !dev->enabled) { |
Patrick Rudolph | 3660c0f | 2015-07-28 08:01:02 +0200 | [diff] [blame] | 387 | printk(BIOS_DEBUG, "Disabling PEG11.\n"); |
| 388 | reg &= ~DEVEN_PEG11; |
| 389 | } |
| 390 | dev = dev_find_slot(0, PCI_DEVFN(1, 0)); |
Nico Huber | 2dc15e9 | 2016-02-04 18:59:48 +0100 | [diff] [blame] | 391 | if (!dev || !dev->enabled) { |
Patrick Rudolph | 3660c0f | 2015-07-28 08:01:02 +0200 | [diff] [blame] | 392 | printk(BIOS_DEBUG, "Disabling PEG10.\n"); |
| 393 | reg &= ~DEVEN_PEG10; |
| 394 | } |
| 395 | dev = dev_find_slot(0, PCI_DEVFN(2, 0)); |
Nico Huber | 2dc15e9 | 2016-02-04 18:59:48 +0100 | [diff] [blame] | 396 | if (!dev || !dev->enabled) { |
Patrick Rudolph | 3660c0f | 2015-07-28 08:01:02 +0200 | [diff] [blame] | 397 | printk(BIOS_DEBUG, "Disabling IGD.\n"); |
| 398 | reg &= ~DEVEN_IGD; |
| 399 | } |
| 400 | dev = dev_find_slot(0, PCI_DEVFN(6, 0)); |
Nico Huber | 2dc15e9 | 2016-02-04 18:59:48 +0100 | [diff] [blame] | 401 | if (!dev || !dev->enabled) { |
Patrick Rudolph | 3660c0f | 2015-07-28 08:01:02 +0200 | [diff] [blame] | 402 | printk(BIOS_DEBUG, "Disabling PEG60.\n"); |
| 403 | reg &= ~DEVEN_PEG60; |
| 404 | } |
| 405 | |
| 406 | dev = dev_find_slot(0, PCI_DEVFN(0, 0)); |
| 407 | pci_write_config32(dev, DEVEN, reg); |
| 408 | if (!(reg & (DEVEN_PEG60 | DEVEN_PEG10 | DEVEN_PEG11 | DEVEN_PEG12))) { |
| 409 | /* Set the PEG clock gating bit. |
| 410 | * Disables the IO clock on all PEG devices. */ |
| 411 | MCHBAR32(0x7010) = MCHBAR32(0x7010) | 0x01; |
| 412 | printk(BIOS_DEBUG, "Disabling PEG IO clock.\n"); |
| 413 | } |
| 414 | } |
| 415 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 416 | static void northbridge_init(struct device *dev) |
| 417 | { |
| 418 | u8 bios_reset_cpl; |
Duncan Laurie | fe7b5d2 | 2012-06-23 20:14:07 -0700 | [diff] [blame] | 419 | u32 bridge_type; |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 420 | |
| 421 | northbridge_dmi_init(dev); |
| 422 | |
Duncan Laurie | fe7b5d2 | 2012-06-23 20:14:07 -0700 | [diff] [blame] | 423 | bridge_type = MCHBAR32(0x5f10); |
| 424 | bridge_type &= ~0xff; |
| 425 | |
| 426 | if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) { |
| 427 | /* Enable Power Aware Interrupt Routing */ |
| 428 | u8 pair = MCHBAR8(0x5418); |
| 429 | pair &= ~0xf; /* Clear 3:0 */ |
| 430 | pair |= 0x4; /* Fixed Priority */ |
| 431 | MCHBAR8(0x5418) = pair; |
| 432 | |
| 433 | /* 30h for IvyBridge */ |
| 434 | bridge_type |= 0x30; |
| 435 | } else { |
| 436 | /* 20h for Sandybridge */ |
| 437 | bridge_type |= 0x20; |
| 438 | } |
| 439 | MCHBAR32(0x5f10) = bridge_type; |
| 440 | |
Patrick Rudolph | aad34cd | 2015-10-21 18:05:01 +0200 | [diff] [blame] | 441 | /* Turn off unused devices. Has to be done before |
| 442 | * setting BIOS_RESET_CPL. |
| 443 | */ |
| 444 | disable_peg(); |
| 445 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 446 | /* |
| 447 | * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU |
| 448 | * that BIOS has initialized memory and power management |
| 449 | */ |
| 450 | bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL); |
| 451 | bios_reset_cpl |= 1; |
| 452 | MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl; |
| 453 | printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n"); |
| 454 | |
| 455 | /* Configure turbo power limits 1ms after reset complete bit */ |
| 456 | mdelay(1); |
| 457 | set_power_limits(28); |
| 458 | |
Duncan Laurie | 77dbbac | 2012-06-25 09:51:59 -0700 | [diff] [blame] | 459 | /* |
| 460 | * CPUs with configurable TDP also need power limits set |
| 461 | * in MCHBAR. Use same values from MSR_PKG_POWER_LIMIT. |
| 462 | */ |
| 463 | if (cpu_config_tdp_levels()) { |
| 464 | msr_t msr = rdmsr(MSR_PKG_POWER_LIMIT); |
| 465 | MCHBAR32(0x59A0) = msr.lo; |
| 466 | MCHBAR32(0x59A4) = msr.hi; |
| 467 | } |
| 468 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 469 | /* Set here before graphics PM init */ |
| 470 | MCHBAR32(0x5500) = 0x00100001; |
| 471 | } |
| 472 | |
Vladimir Serbinenko | c16e9dfa | 2015-05-29 16:18:01 +0200 | [diff] [blame] | 473 | static u32 northbridge_get_base_reg(device_t dev, int reg) |
| 474 | { |
| 475 | u32 value; |
| 476 | |
| 477 | value = pci_read_config32(dev, reg); |
| 478 | /* Base registers are at 1MiB granularity. */ |
| 479 | value &= ~((1 << 20) - 1); |
| 480 | return value; |
| 481 | } |
| 482 | |
Nico Huber | 6f8b7df | 2016-10-08 18:42:46 +0200 | [diff] [blame] | 483 | u32 northbridge_get_tseg_base(void) |
Vladimir Serbinenko | c16e9dfa | 2015-05-29 16:18:01 +0200 | [diff] [blame] | 484 | { |
Nico Huber | 6f8b7df | 2016-10-08 18:42:46 +0200 | [diff] [blame] | 485 | const device_t dev = dev_find_slot(0, PCI_DEVFN(0, 0)); |
Vladimir Serbinenko | c16e9dfa | 2015-05-29 16:18:01 +0200 | [diff] [blame] | 486 | |
Nico Huber | 6f8b7df | 2016-10-08 18:42:46 +0200 | [diff] [blame] | 487 | return northbridge_get_base_reg(dev, TSEG); |
Vladimir Serbinenko | c16e9dfa | 2015-05-29 16:18:01 +0200 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | void northbridge_write_smram(u8 smram) |
| 491 | { |
| 492 | pci_write_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), SMRAM, smram); |
| 493 | } |
| 494 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 495 | static struct pci_operations intel_pci_ops = { |
| 496 | .set_subsystem = intel_set_subsystem, |
| 497 | }; |
| 498 | |
| 499 | static struct device_operations mc_ops = { |
| 500 | .read_resources = mc_read_resources, |
| 501 | .set_resources = mc_set_resources, |
| 502 | .enable_resources = pci_dev_enable_resources, |
| 503 | .init = northbridge_init, |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 504 | .scan_bus = 0, |
| 505 | .ops_pci = &intel_pci_ops, |
Vladimir Serbinenko | 0a66991 | 2014-10-05 14:34:17 +0200 | [diff] [blame] | 506 | .acpi_fill_ssdt_generator = generate_cpu_entries, |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 507 | }; |
| 508 | |
Walter Murphy | 496f4a0 | 2012-04-23 11:08:03 -0700 | [diff] [blame] | 509 | static const struct pci_driver mc_driver_0100 __pci_driver = { |
| 510 | .ops = &mc_ops, |
| 511 | .vendor = PCI_VENDOR_ID_INTEL, |
| 512 | .device = 0x0100, |
| 513 | }; |
| 514 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 515 | static const struct pci_driver mc_driver __pci_driver = { |
| 516 | .ops = &mc_ops, |
| 517 | .vendor = PCI_VENDOR_ID_INTEL, |
| 518 | .device = 0x0104, /* Sandy bridge */ |
| 519 | }; |
| 520 | |
Damien Zammit | 3517038 | 2014-10-29 00:11:53 +1100 | [diff] [blame] | 521 | static const struct pci_driver mc_driver_150 __pci_driver = { |
| 522 | .ops = &mc_ops, |
| 523 | .vendor = PCI_VENDOR_ID_INTEL, |
| 524 | .device = 0x0150, /* Ivy bridge */ |
| 525 | }; |
| 526 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 527 | static const struct pci_driver mc_driver_1 __pci_driver = { |
| 528 | .ops = &mc_ops, |
| 529 | .vendor = PCI_VENDOR_ID_INTEL, |
| 530 | .device = 0x0154, /* Ivy bridge */ |
| 531 | }; |
| 532 | |
| 533 | static void cpu_bus_init(device_t dev) |
| 534 | { |
| 535 | initialize_cpus(dev->link_list); |
| 536 | } |
| 537 | |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 538 | static struct device_operations cpu_bus_ops = { |
Edward O'Callaghan | 9f74462 | 2014-10-31 08:12:34 +1100 | [diff] [blame] | 539 | .read_resources = DEVICE_NOOP, |
| 540 | .set_resources = DEVICE_NOOP, |
| 541 | .enable_resources = DEVICE_NOOP, |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 542 | .init = cpu_bus_init, |
| 543 | .scan_bus = 0, |
| 544 | }; |
| 545 | |
| 546 | static void enable_dev(device_t dev) |
| 547 | { |
| 548 | /* Set the operations if it is a special bus type */ |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 549 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 550 | dev->ops = &pci_domain_ops; |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 551 | } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 552 | dev->ops = &cpu_bus_ops; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | struct chip_operations northbridge_intel_sandybridge_ops = { |
Damien Zammit | 3517038 | 2014-10-29 00:11:53 +1100 | [diff] [blame] | 557 | CHIP_NAME("Intel SandyBridge/IvyBridge integrated Northbridge") |
Stefan Reinauer | 00636b0 | 2012-04-04 00:08:51 +0200 | [diff] [blame] | 558 | .enable_dev = enable_dev, |
| 559 | }; |