Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * 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. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 18 | * Foundation, Inc. |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <console/console.h> |
| 22 | #include <device/device.h> |
| 23 | #include <device/pci.h> |
| 24 | #include <device/pciexp.h> |
| 25 | #include <device/pci_ids.h> |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 26 | #include <southbridge/intel/common/pciehp.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 27 | #include "pch.h" |
| 28 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 29 | static void pch_pcie_pm_early(struct device *dev) |
| 30 | { |
| 31 | u16 link_width_p0, link_width_p4; |
| 32 | u8 slot_power_limit = 10; /* 10W for x1 */ |
| 33 | u32 reg32; |
| 34 | u8 reg8; |
| 35 | |
Duncan Laurie | 4aca5d7 | 2012-04-27 10:58:22 -0700 | [diff] [blame] | 36 | reg32 = RCBA32(RPC); |
| 37 | |
| 38 | /* Port 0-3 link aggregation from PCIEPCS1[1:0] soft strap */ |
| 39 | switch (reg32 & 3) { |
| 40 | case 3: |
| 41 | link_width_p0 = 4; |
| 42 | break; |
| 43 | case 1: |
| 44 | case 2: |
| 45 | link_width_p0 = 2; |
| 46 | break; |
| 47 | case 0: |
| 48 | default: |
| 49 | link_width_p0 = 1; |
| 50 | } |
| 51 | |
| 52 | /* Port 4-7 link aggregation from PCIEPCS2[1:0] soft strap */ |
| 53 | switch ((reg32 >> 2) & 3) { |
| 54 | case 3: |
| 55 | link_width_p4 = 4; |
| 56 | break; |
| 57 | case 1: |
| 58 | case 2: |
| 59 | link_width_p4 = 2; |
| 60 | break; |
| 61 | case 0: |
| 62 | default: |
| 63 | link_width_p4 = 1; |
| 64 | } |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 65 | |
| 66 | /* Enable dynamic clock gating where needed */ |
| 67 | reg8 = pci_read_config8(dev, 0xe1); |
| 68 | switch (PCI_FUNC(dev->path.pci.devfn)) { |
| 69 | case 0: /* Port 0 */ |
| 70 | if (link_width_p0 == 4) |
| 71 | slot_power_limit = 40; /* 40W for x4 */ |
| 72 | else if (link_width_p0 == 2) |
| 73 | slot_power_limit = 20; /* 20W for x2 */ |
Duncan Laurie | 4aca5d7 | 2012-04-27 10:58:22 -0700 | [diff] [blame] | 74 | reg8 |= 0x3f; |
| 75 | break; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 76 | case 4: /* Port 4 */ |
| 77 | if (link_width_p4 == 4) |
| 78 | slot_power_limit = 40; /* 40W for x4 */ |
| 79 | else if (link_width_p4 == 2) |
| 80 | slot_power_limit = 20; /* 20W for x2 */ |
| 81 | reg8 |= 0x3f; |
| 82 | break; |
| 83 | case 1: /* Port 1 only if Port 0 is x1 */ |
| 84 | if (link_width_p0 == 1) |
| 85 | reg8 |= 0x3; |
| 86 | break; |
| 87 | case 2: /* Port 2 only if Port 0 is x1 or x2 */ |
| 88 | case 3: /* Port 3 only if Port 0 is x1 or x2 */ |
| 89 | if (link_width_p0 <= 2) |
| 90 | reg8 |= 0x3; |
| 91 | break; |
| 92 | case 5: /* Port 5 only if Port 4 is x1 */ |
| 93 | if (link_width_p4 == 1) |
| 94 | reg8 |= 0x3; |
| 95 | break; |
| 96 | case 6: /* Port 7 only if Port 4 is x1 or x2 */ |
| 97 | case 7: /* Port 7 only if Port 4 is x1 or x2 */ |
| 98 | if (link_width_p4 <= 2) |
| 99 | reg8 |= 0x3; |
| 100 | break; |
| 101 | } |
| 102 | pci_write_config8(dev, 0xe1, reg8); |
| 103 | |
| 104 | /* Set 0xE8[0] = 1 */ |
| 105 | reg32 = pci_read_config32(dev, 0xe8); |
| 106 | reg32 |= 1; |
| 107 | pci_write_config32(dev, 0xe8, reg32); |
| 108 | |
| 109 | /* Adjust Common Clock exit latency */ |
| 110 | reg32 = pci_read_config32(dev, 0xd8); |
| 111 | reg32 &= ~(1 << 17); |
| 112 | reg32 |= (1 << 16) | (1 << 15); |
| 113 | reg32 &= ~(1 << 31); /* Disable PME# SCI for native PME handling */ |
| 114 | pci_write_config32(dev, 0xd8, reg32); |
| 115 | |
| 116 | /* Adjust ASPM L1 exit latency */ |
| 117 | reg32 = pci_read_config32(dev, 0x4c); |
| 118 | reg32 &= ~((1 << 17) | (1 << 16) | (1 << 15)); |
| 119 | if (RCBA32(0x2320) & (1 << 16)) { |
| 120 | /* If RCBA+2320[15]=1 set ASPM L1 to 8-16us */ |
| 121 | reg32 |= (1 << 17); |
| 122 | } else { |
| 123 | /* Else set ASPM L1 to 2-4us */ |
| 124 | reg32 |= (1 << 16); |
| 125 | } |
| 126 | pci_write_config32(dev, 0x4c, reg32); |
| 127 | |
| 128 | /* Set slot power limit as configured above */ |
| 129 | reg32 = pci_read_config32(dev, 0x54); |
| 130 | reg32 &= ~((1 << 15) | (1 << 16)); /* 16:15 = Slot power scale */ |
| 131 | reg32 &= ~(0xff << 7); /* 14:7 = Slot power limit */ |
| 132 | reg32 |= (slot_power_limit << 7); |
| 133 | pci_write_config32(dev, 0x54, reg32); |
| 134 | } |
| 135 | |
| 136 | static void pch_pcie_pm_late(struct device *dev) |
| 137 | { |
Marc Jones | 4adc8cd | 2012-10-31 16:24:37 -0600 | [diff] [blame] | 138 | struct southbridge_intel_bd82x6x_config *config = dev->chip_info; |
| 139 | enum aspm_type apmc = 0; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 140 | u32 reg32; |
| 141 | |
| 142 | /* Set 0x314 = 0x743a361b */ |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 143 | pci_write_config32(dev, 0x314, 0x743a361b); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 144 | |
| 145 | /* Set 0x318[31:16] = 0x1414 */ |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 146 | reg32 = pci_read_config32(dev, 0x318); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 147 | reg32 &= 0x0000ffff; |
| 148 | reg32 |= 0x14140000; |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 149 | pci_write_config32(dev, 0x318, reg32); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 150 | |
| 151 | /* Set 0x324[5] = 1 */ |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 152 | reg32 = pci_read_config32(dev, 0x324); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 153 | reg32 |= (1 << 5); |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 154 | pci_write_config32(dev, 0x324, reg32); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 155 | |
| 156 | /* Set 0x330[7:0] = 0x40 */ |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 157 | reg32 = pci_read_config32(dev, 0x330); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 158 | reg32 &= ~(0xff); |
| 159 | reg32 |= 0x40; |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 160 | pci_write_config32(dev, 0x330, reg32); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 161 | |
| 162 | /* Set 0x33C[24:0] = 0x854c74 */ |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 163 | reg32 = pci_read_config32(dev, 0x33c); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 164 | reg32 &= 0xff000000; |
| 165 | reg32 |= 0x00854c74; |
Kyösti Mälkki | fd98c65 | 2013-07-26 08:50:53 +0300 | [diff] [blame] | 166 | pci_write_config32(dev, 0x33c, reg32); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 167 | |
| 168 | /* No IO-APIC, Disable EOI forwarding */ |
| 169 | reg32 = pci_read_config32(dev, 0xd4); |
| 170 | reg32 |= (1 << 1); |
| 171 | pci_write_config32(dev, 0xd4, reg32); |
| 172 | |
Marc Jones | 4adc8cd | 2012-10-31 16:24:37 -0600 | [diff] [blame] | 173 | /* Check for a rootport ASPM override */ |
| 174 | switch (PCI_FUNC(dev->path.pci.devfn)) { |
| 175 | case 0: |
| 176 | apmc = config->pcie_aspm_f0; |
| 177 | break; |
| 178 | case 1: |
| 179 | apmc = config->pcie_aspm_f1; |
| 180 | break; |
| 181 | case 2: |
| 182 | apmc = config->pcie_aspm_f2; |
| 183 | break; |
| 184 | case 3: |
| 185 | apmc = config->pcie_aspm_f3; |
| 186 | break; |
| 187 | case 4: |
| 188 | apmc = config->pcie_aspm_f4; |
| 189 | break; |
| 190 | case 5: |
| 191 | apmc = config->pcie_aspm_f5; |
| 192 | break; |
| 193 | case 6: |
| 194 | apmc = config->pcie_aspm_f6; |
| 195 | break; |
| 196 | case 7: |
| 197 | apmc = config->pcie_aspm_f7; |
| 198 | break; |
| 199 | } |
| 200 | |
| 201 | /* Setup the override or get the real ASPM setting */ |
| 202 | if (apmc) { |
| 203 | reg32 = pci_read_config32(dev, 0xd4); |
| 204 | reg32 |= (apmc << 2) | (1 << 4); |
| 205 | pci_write_config32(dev, 0xd4, reg32); |
| 206 | } else { |
| 207 | apmc = pci_read_config32(dev, 0x50) & 3; |
| 208 | } |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 209 | |
| 210 | /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */ |
| 211 | if (apmc == PCIE_ASPM_BOTH) { |
| 212 | reg32 = pci_read_config32(dev, 0xe8); |
| 213 | reg32 |= (1 << 1); |
| 214 | pci_write_config32(dev, 0xe8, reg32); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | static void pci_init(struct device *dev) |
| 219 | { |
| 220 | u16 reg16; |
| 221 | u32 reg32; |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 222 | struct southbridge_intel_bd82x6x_config *config = dev->chip_info; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 223 | |
| 224 | printk(BIOS_DEBUG, "Initializing PCH PCIe bridge.\n"); |
| 225 | |
| 226 | /* Enable Bus Master */ |
| 227 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 228 | reg32 |= PCI_COMMAND_MASTER; |
| 229 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 230 | |
| 231 | /* Set Cache Line Size to 0x10 */ |
| 232 | // This has no effect but the OS might expect it |
| 233 | pci_write_config8(dev, 0x0c, 0x10); |
| 234 | |
| 235 | reg16 = pci_read_config16(dev, 0x3e); |
| 236 | reg16 &= ~(1 << 0); /* disable parity error response */ |
| 237 | // reg16 &= ~(1 << 1); /* disable SERR */ |
| 238 | reg16 |= (1 << 2); /* ISA enable */ |
| 239 | pci_write_config16(dev, 0x3e, reg16); |
| 240 | |
| 241 | #ifdef EVEN_MORE_DEBUG |
| 242 | reg32 = pci_read_config32(dev, 0x20); |
| 243 | printk(BIOS_SPEW, " MBL = 0x%08x\n", reg32); |
| 244 | reg32 = pci_read_config32(dev, 0x24); |
| 245 | printk(BIOS_SPEW, " PMBL = 0x%08x\n", reg32); |
| 246 | reg32 = pci_read_config32(dev, 0x28); |
| 247 | printk(BIOS_SPEW, " PMBU32 = 0x%08x\n", reg32); |
| 248 | reg32 = pci_read_config32(dev, 0x2c); |
| 249 | printk(BIOS_SPEW, " PMLU32 = 0x%08x\n", reg32); |
| 250 | #endif |
| 251 | |
| 252 | /* Clear errors in status registers */ |
| 253 | reg16 = pci_read_config16(dev, 0x06); |
| 254 | //reg16 |= 0xf900; |
| 255 | pci_write_config16(dev, 0x06, reg16); |
| 256 | |
| 257 | reg16 = pci_read_config16(dev, 0x1e); |
| 258 | //reg16 |= 0xf900; |
| 259 | pci_write_config16(dev, 0x1e, reg16); |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 260 | |
| 261 | /* Enable expresscard hotplug events. */ |
| 262 | if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) { |
| 263 | pci_write_config32(dev, 0xd8, |
| 264 | pci_read_config32(dev, 0xd8) |
| 265 | | (1 << 30)); |
| 266 | pci_write_config16(dev, 0x42, 0x142); |
| 267 | } |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | static void pch_pcie_enable(device_t dev) |
| 271 | { |
| 272 | /* Power Management init before enumeration */ |
| 273 | pch_pcie_pm_early(dev); |
| 274 | } |
| 275 | |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame^] | 276 | static void pch_pciexp_scan_bridge(device_t dev) |
Marc Jones | 4adc8cd | 2012-10-31 16:24:37 -0600 | [diff] [blame] | 277 | { |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 278 | struct southbridge_intel_bd82x6x_config *config = dev->chip_info; |
Marc Jones | 4adc8cd | 2012-10-31 16:24:37 -0600 | [diff] [blame] | 279 | |
| 280 | /* Normal PCIe Scan */ |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame^] | 281 | pciexp_scan_bridge(dev); |
Marc Jones | 4adc8cd | 2012-10-31 16:24:37 -0600 | [diff] [blame] | 282 | |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 283 | if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) { |
| 284 | intel_acpi_pcie_hotplug_scan_slot(dev->link_list); |
| 285 | } |
| 286 | |
Marc Jones | 4adc8cd | 2012-10-31 16:24:37 -0600 | [diff] [blame] | 287 | /* Late Power Management init after bridge device enumeration */ |
| 288 | pch_pcie_pm_late(dev); |
Marc Jones | 4adc8cd | 2012-10-31 16:24:37 -0600 | [diff] [blame] | 289 | } |
| 290 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 291 | static void pcie_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 292 | { |
| 293 | /* NOTE: This is not the default position! */ |
| 294 | if (!vendor || !device) { |
| 295 | pci_write_config32(dev, 0x94, |
| 296 | pci_read_config32(dev, 0)); |
| 297 | } else { |
| 298 | pci_write_config32(dev, 0x94, |
| 299 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | static struct pci_operations pci_ops = { |
| 304 | .set_subsystem = pcie_set_subsystem, |
| 305 | }; |
| 306 | |
| 307 | static struct device_operations device_ops = { |
| 308 | .read_resources = pci_bus_read_resources, |
| 309 | .set_resources = pci_dev_set_resources, |
| 310 | .enable_resources = pci_bus_enable_resources, |
| 311 | .init = pci_init, |
| 312 | .enable = pch_pcie_enable, |
Marc Jones | 4adc8cd | 2012-10-31 16:24:37 -0600 | [diff] [blame] | 313 | .scan_bus = pch_pciexp_scan_bridge, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 314 | .ops_pci = &pci_ops, |
| 315 | }; |
| 316 | |
Stefan Reinauer | 9a380ab | 2012-06-22 13:16:11 -0700 | [diff] [blame] | 317 | static const unsigned short pci_device_ids[] = { 0x1c10, 0x1c12, 0x1c14, 0x1c16, |
| 318 | 0x1c18, 0x1c1a, 0x1c1c, 0x1c1e, |
| 319 | 0x1e10, 0x1e12, 0x1e14, 0x1e16, |
| 320 | 0x1e18, 0x1e1a, 0x1e1c, 0x1e1e, |
| 321 | 0 }; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 322 | |
Stefan Reinauer | 9a380ab | 2012-06-22 13:16:11 -0700 | [diff] [blame] | 323 | static const struct pci_driver pch_pcie __pci_driver = { |
| 324 | .ops = &device_ops, |
| 325 | .vendor = PCI_VENDOR_ID_INTEL, |
| 326 | .devices = pci_device_ids, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 327 | }; |