Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [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 | * Copyright (C) 2013 Vladimir Serbinenko |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <console/console.h> |
| 19 | #include <arch/acpi.h> |
| 20 | #include <arch/io.h> |
| 21 | #include <stdint.h> |
| 22 | #include <delay.h> |
| 23 | #include <cpu/intel/model_2065x/model_2065x.h> |
| 24 | #include <cpu/x86/msr.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 25 | #include <device/device.h> |
| 26 | #include <device/pci.h> |
| 27 | #include <device/pci_ids.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
| 30 | #include <cpu/cpu.h> |
| 31 | #include <cbmem.h> |
| 32 | #include "chip.h" |
| 33 | #include "nehalem.h" |
Vladimir Serbinenko | 0f9aa1c | 2015-05-29 16:52:50 +0200 | [diff] [blame] | 34 | #include <cpu/intel/smm/gen1/smi.h> |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 35 | |
| 36 | static int bridge_revision_id = -1; |
| 37 | |
| 38 | int bridge_silicon_revision(void) |
| 39 | { |
| 40 | if (bridge_revision_id < 0) { |
| 41 | uint8_t stepping = cpuid_eax(1) & 0xf; |
| 42 | uint8_t bridge_id = |
| 43 | pci_read_config16(dev_find_slot(0, PCI_DEVFN(0, 0)), |
| 44 | PCI_DEVICE_ID) & 0xf0; |
| 45 | bridge_revision_id = bridge_id | stepping; |
| 46 | } |
| 47 | return bridge_revision_id; |
| 48 | } |
| 49 | |
| 50 | /* Reserve everything between A segment and 1MB: |
| 51 | * |
| 52 | * 0xa0000 - 0xbffff: legacy VGA |
| 53 | * 0xc0000 - 0xcffff: VGA OPROM (needed by kernel) |
| 54 | * 0xe0000 - 0xfffff: SeaBIOS, if used, otherwise DMI |
| 55 | */ |
| 56 | static const int legacy_hole_base_k = 0xa0000 / 1024; |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 57 | |
| 58 | static void add_fixed_resources(struct device *dev, int index) |
| 59 | { |
| 60 | struct resource *resource; |
| 61 | |
| 62 | /* 0xe0000000-0xf0000000 PCIe config. |
| 63 | 0xfed10000-0xfed14000 MCH |
| 64 | 0xfed17000-0xfed18000 HECI |
| 65 | 0xfed18000-0xfed19000 DMI |
| 66 | 0xfed19000-0xfed1a000 EPBAR |
| 67 | 0xfed1c000-0xfed20000 RCBA |
| 68 | 0xfed90000-0xfed94000 IOMMU |
| 69 | 0xff800000-0xffffffff ROM. */ |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 70 | |
| 71 | resource = new_resource(dev, index++); |
| 72 | resource->base = (resource_t) 0xfed00000; |
| 73 | resource->size = (resource_t) 0x00100000; |
| 74 | resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE | |
| 75 | IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 76 | |
| 77 | mmio_resource(dev, index++, legacy_hole_base_k, |
| 78 | (0xc0000 >> 10) - legacy_hole_base_k); |
| 79 | reserved_ram_resource(dev, index++, 0xc0000 >> 10, |
| 80 | (0x100000 - 0xc0000) >> 10); |
| 81 | |
Martin Roth | 3323260 | 2017-06-24 14:48:50 -0600 | [diff] [blame] | 82 | #if IS_ENABLED(CONFIG_CHROMEOS_RAMOOPS) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 83 | reserved_ram_resource(dev, index++, |
| 84 | CONFIG_CHROMEOS_RAMOOPS_RAM_START >> 10, |
| 85 | CONFIG_CHROMEOS_RAMOOPS_RAM_SIZE >> 10); |
| 86 | #endif |
| 87 | } |
| 88 | |
Elyes HAOUAS | 706aabc | 2018-02-09 08:49:32 +0100 | [diff] [blame] | 89 | static void pci_domain_set_resources(struct device *dev) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 90 | { |
| 91 | assign_resources(dev->link_list); |
| 92 | } |
| 93 | |
Patrick Rudolph | 5c3452b | 2018-05-15 11:37:26 +0200 | [diff] [blame] | 94 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
| 95 | static const char *northbridge_acpi_name(const struct device *dev) |
| 96 | { |
| 97 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 98 | return "PCI0"; |
| 99 | |
| 100 | if (dev->path.type != DEVICE_PATH_PCI || dev->bus->secondary != 0) |
| 101 | return NULL; |
| 102 | |
| 103 | switch (dev->path.pci.devfn) { |
| 104 | case PCI_DEVFN(0, 0): |
| 105 | return "MCHC"; |
| 106 | } |
| 107 | |
| 108 | return NULL; |
| 109 | } |
| 110 | #endif |
| 111 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 112 | static struct device_operations pci_domain_ops = { |
| 113 | .read_resources = pci_domain_read_resources, |
| 114 | .set_resources = pci_domain_set_resources, |
| 115 | .enable_resources = NULL, |
| 116 | .init = NULL, |
| 117 | .scan_bus = pci_domain_scan_bus, |
Patrick Rudolph | 5c3452b | 2018-05-15 11:37:26 +0200 | [diff] [blame] | 118 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
| 119 | .acpi_name = northbridge_acpi_name, |
| 120 | #endif |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 121 | }; |
| 122 | |
Elyes HAOUAS | 706aabc | 2018-02-09 08:49:32 +0100 | [diff] [blame] | 123 | static void mc_read_resources(struct device *dev) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 124 | { |
| 125 | uint32_t tseg_base; |
| 126 | uint64_t TOUUD; |
| 127 | uint16_t reg16; |
| 128 | |
| 129 | pci_dev_read_resources(dev); |
| 130 | |
Kyösti Mälkki | e25b5ef | 2016-12-02 08:56:05 +0200 | [diff] [blame] | 131 | mmconf_resource(dev, 0x50); |
| 132 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 133 | tseg_base = pci_read_config32(dev_find_slot(0, PCI_DEVFN(0, 0)), TSEG); |
| 134 | TOUUD = pci_read_config16(dev_find_slot(0, PCI_DEVFN(0, 0)), |
| 135 | D0F0_TOUUD); |
| 136 | |
| 137 | printk(BIOS_DEBUG, "ram_before_4g_top: 0x%x\n", tseg_base); |
| 138 | printk(BIOS_DEBUG, "TOUUD: 0x%x\n", (unsigned)TOUUD); |
| 139 | |
| 140 | /* Report the memory regions */ |
| 141 | ram_resource(dev, 3, 0, 640); |
| 142 | ram_resource(dev, 4, 768, ((tseg_base >> 10) - 768)); |
| 143 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 144 | mmio_resource(dev, 5, tseg_base >> 10, CONFIG_SMM_TSEG_SIZE >> 10); |
| 145 | |
| 146 | reg16 = pci_read_config16(dev_find_slot(0, PCI_DEVFN(0, 0)), D0F0_GGC); |
| 147 | const int uma_sizes_gtt[16] = |
| 148 | { 0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 3, 4, 42, 42, 42, 42 }; |
| 149 | /* Igd memory */ |
| 150 | const int uma_sizes_igd[16] = { |
| 151 | 0, 0, 0, 0, 0, 32, 48, 64, 128, 256, 96, 160, 224, 352, 256, 512 |
| 152 | }; |
| 153 | u32 igd_base, gtt_base; |
| 154 | int uma_size_igd, uma_size_gtt; |
| 155 | |
| 156 | uma_size_igd = uma_sizes_igd[(reg16 >> 4) & 0xF]; |
| 157 | uma_size_gtt = uma_sizes_gtt[(reg16 >> 8) & 0xF]; |
| 158 | |
| 159 | igd_base = |
| 160 | pci_read_config32(dev_find_slot(0, PCI_DEVFN(0, 0)), D0F0_IGD_BASE); |
| 161 | gtt_base = |
| 162 | pci_read_config32(dev_find_slot(0, PCI_DEVFN(0, 0)), D0F0_GTT_BASE); |
| 163 | mmio_resource(dev, 6, gtt_base >> 10, uma_size_gtt << 10); |
| 164 | mmio_resource(dev, 7, igd_base >> 10, uma_size_igd << 10); |
| 165 | |
| 166 | if (TOUUD > 4096) |
| 167 | ram_resource(dev, 8, (4096 << 10), ((TOUUD - 4096) << 10)); |
| 168 | |
| 169 | /* This memory is not DMA-capable. */ |
| 170 | if (TOUUD >= 8192 - 64) |
| 171 | bad_ram_resource(dev, 9, 0x1fc000000ULL >> 10, 0x004000000 >> 10); |
| 172 | |
| 173 | add_fixed_resources(dev, 10); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 174 | } |
| 175 | |
Nico Huber | 6f8b7df | 2016-10-08 18:42:46 +0200 | [diff] [blame] | 176 | u32 northbridge_get_tseg_base(void) |
Vladimir Serbinenko | 0f9aa1c | 2015-05-29 16:52:50 +0200 | [diff] [blame] | 177 | { |
Elyes HAOUAS | 706aabc | 2018-02-09 08:49:32 +0100 | [diff] [blame] | 178 | struct device *dev = dev_find_slot(0, PCI_DEVFN(0, 0)); |
Vladimir Serbinenko | 0f9aa1c | 2015-05-29 16:52:50 +0200 | [diff] [blame] | 179 | |
Nico Huber | 6f8b7df | 2016-10-08 18:42:46 +0200 | [diff] [blame] | 180 | return pci_read_config32(dev, TSEG) & ~1; |
Vladimir Serbinenko | 0f9aa1c | 2015-05-29 16:52:50 +0200 | [diff] [blame] | 181 | } |
| 182 | |
Elyes HAOUAS | 706aabc | 2018-02-09 08:49:32 +0100 | [diff] [blame] | 183 | static void mc_set_resources(struct device *dev) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 184 | { |
| 185 | /* And call the normal set_resources */ |
| 186 | pci_dev_set_resources(dev); |
| 187 | } |
| 188 | |
Elyes HAOUAS | 706aabc | 2018-02-09 08:49:32 +0100 | [diff] [blame] | 189 | static void intel_set_subsystem(struct device *dev, unsigned vendor, unsigned device) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 190 | { |
| 191 | if (!vendor || !device) { |
| 192 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 193 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 194 | } else { |
| 195 | pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, |
| 196 | ((device & 0xffff) << 16) | (vendor & |
| 197 | 0xffff)); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | static void northbridge_dmi_init(struct device *dev) |
| 202 | { |
| 203 | u32 reg32; |
| 204 | |
| 205 | /* Clear error status bits */ |
| 206 | DMIBAR32(0x1c4) = 0xffffffff; |
| 207 | DMIBAR32(0x1d0) = 0xffffffff; |
| 208 | |
| 209 | /* Steps prior to DMI ASPM */ |
| 210 | if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) { |
| 211 | reg32 = DMIBAR32(0x250); |
| 212 | reg32 &= ~((1 << 22) | (1 << 20)); |
| 213 | reg32 |= (1 << 21); |
| 214 | DMIBAR32(0x250) = reg32; |
| 215 | } |
| 216 | |
| 217 | reg32 = DMIBAR32(0x238); |
| 218 | reg32 |= (1 << 29); |
| 219 | DMIBAR32(0x238) = reg32; |
| 220 | |
| 221 | if (bridge_silicon_revision() >= SNB_STEP_D0) { |
| 222 | reg32 = DMIBAR32(0x1f8); |
| 223 | reg32 |= (1 << 16); |
| 224 | DMIBAR32(0x1f8) = reg32; |
| 225 | } else if (bridge_silicon_revision() >= SNB_STEP_D1) { |
| 226 | reg32 = DMIBAR32(0x1f8); |
| 227 | reg32 &= ~(1 << 26); |
| 228 | reg32 |= (1 << 16); |
| 229 | DMIBAR32(0x1f8) = reg32; |
| 230 | |
| 231 | reg32 = DMIBAR32(0x1fc); |
| 232 | reg32 |= (1 << 12) | (1 << 23); |
| 233 | DMIBAR32(0x1fc) = reg32; |
| 234 | } |
| 235 | |
| 236 | /* Enable ASPM on SNB link, should happen before PCH link */ |
| 237 | if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_SNB) { |
| 238 | reg32 = DMIBAR32(0xd04); |
| 239 | reg32 |= (1 << 4); |
| 240 | DMIBAR32(0xd04) = reg32; |
| 241 | } |
| 242 | |
| 243 | reg32 = DMIBAR32(0x88); |
| 244 | reg32 |= (1 << 1) | (1 << 0); |
| 245 | DMIBAR32(0x88) = reg32; |
| 246 | } |
| 247 | |
| 248 | static void northbridge_init(struct device *dev) |
| 249 | { |
| 250 | u8 bios_reset_cpl; |
| 251 | u32 bridge_type; |
| 252 | |
| 253 | northbridge_dmi_init(dev); |
| 254 | |
| 255 | bridge_type = MCHBAR32(0x5f10); |
| 256 | bridge_type &= ~0xff; |
| 257 | |
| 258 | if ((bridge_silicon_revision() & BASE_REV_MASK) == BASE_REV_IVB) { |
| 259 | /* Enable Power Aware Interrupt Routing */ |
| 260 | u8 pair = MCHBAR8(0x5418); |
| 261 | pair &= ~0xf; /* Clear 3:0 */ |
| 262 | pair |= 0x4; /* Fixed Priority */ |
| 263 | MCHBAR8(0x5418) = pair; |
| 264 | |
| 265 | /* 30h for IvyBridge */ |
| 266 | bridge_type |= 0x30; |
| 267 | } else { |
| 268 | /* 20h for Sandybridge */ |
| 269 | bridge_type |= 0x20; |
| 270 | } |
| 271 | MCHBAR32(0x5f10) = bridge_type; |
| 272 | |
| 273 | /* |
| 274 | * Set bit 0 of BIOS_RESET_CPL to indicate to the CPU |
| 275 | * that BIOS has initialized memory and power management |
| 276 | */ |
| 277 | bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL); |
| 278 | bios_reset_cpl |= 1; |
| 279 | MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl; |
| 280 | printk(BIOS_DEBUG, "Set BIOS_RESET_CPL\n"); |
| 281 | |
| 282 | /* Configure turbo power limits 1ms after reset complete bit */ |
| 283 | mdelay(1); |
| 284 | #ifdef DISABLED |
| 285 | set_power_limits(28); |
| 286 | |
| 287 | /* |
| 288 | * CPUs with configurable TDP also need power limits set |
| 289 | * in MCHBAR. Use same values from MSR_PKG_POWER_LIMIT. |
| 290 | */ |
| 291 | if (cpu_config_tdp_levels()) { |
| 292 | msr_t msr = rdmsr(MSR_PKG_POWER_LIMIT); |
| 293 | MCHBAR32(0x59A0) = msr.lo; |
| 294 | MCHBAR32(0x59A4) = msr.hi; |
| 295 | } |
| 296 | #endif |
| 297 | /* Set here before graphics PM init */ |
| 298 | MCHBAR32(0x5500) = 0x00100001; |
| 299 | } |
| 300 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 301 | static struct pci_operations intel_pci_ops = { |
| 302 | .set_subsystem = intel_set_subsystem, |
| 303 | }; |
| 304 | |
| 305 | static struct device_operations mc_ops = { |
| 306 | .read_resources = mc_read_resources, |
| 307 | .set_resources = mc_set_resources, |
| 308 | .enable_resources = pci_dev_enable_resources, |
| 309 | .init = northbridge_init, |
Vladimir Serbinenko | 0a66991 | 2014-10-05 14:34:17 +0200 | [diff] [blame] | 310 | .acpi_fill_ssdt_generator = generate_cpu_entries, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 311 | .scan_bus = 0, |
| 312 | .ops_pci = &intel_pci_ops, |
| 313 | }; |
| 314 | |
| 315 | static const struct pci_driver mc_driver_44 __pci_driver = { |
| 316 | .ops = &mc_ops, |
| 317 | .vendor = PCI_VENDOR_ID_INTEL, |
| 318 | .device = 0x0044, /* Nehalem */ |
| 319 | }; |
| 320 | |
Elyes HAOUAS | 706aabc | 2018-02-09 08:49:32 +0100 | [diff] [blame] | 321 | static void cpu_bus_init(struct device *dev) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 322 | { |
| 323 | initialize_cpus(dev->link_list); |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 324 | } |
| 325 | |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 326 | static struct device_operations cpu_bus_ops = { |
Edward O'Callaghan | 9f74462 | 2014-10-31 08:12:34 +1100 | [diff] [blame] | 327 | .read_resources = DEVICE_NOOP, |
| 328 | .set_resources = DEVICE_NOOP, |
| 329 | .enable_resources = DEVICE_NOOP, |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 330 | .init = cpu_bus_init, |
| 331 | .scan_bus = 0, |
| 332 | }; |
| 333 | |
Elyes HAOUAS | 706aabc | 2018-02-09 08:49:32 +0100 | [diff] [blame] | 334 | static void enable_dev(struct device *dev) |
Vladimir Serbinenko | c6f6be0 | 2013-11-12 22:32:08 +0100 | [diff] [blame] | 335 | { |
| 336 | /* Set the operations if it is a special bus type */ |
| 337 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
| 338 | dev->ops = &pci_domain_ops; |
| 339 | } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
| 340 | dev->ops = &cpu_bus_ops; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | struct chip_operations northbridge_intel_nehalem_ops = { |
| 345 | CHIP_NAME("Intel i7 (Nehalem) integrated Northbridge") |
| 346 | .enable_dev = enable_dev, |
| 347 | }; |