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