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