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