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