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