Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation; version 2 of |
| 8 | * the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <console/console.h> |
| 17 | #include <device/device.h> |
| 18 | #include <device/pci.h> |
Kyösti Mälkki | df128a5 | 2019-09-21 18:35:37 +0300 | [diff] [blame] | 19 | #include <device/pci_def.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> |
Kyösti Mälkki | 12b121c | 2019-08-18 16:33:39 +0300 | [diff] [blame] | 25 | |
| 26 | #include "chip.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)); |
Patrick Rudolph | 4f8b108 | 2019-07-14 11:54:58 +0200 | [diff] [blame] | 119 | if (RCBA32(CIR9) & (1 << 16)) { |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 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 | |
Kyösti Mälkki | df128a5 | 2019-09-21 18:35:37 +0300 | [diff] [blame] | 235 | reg16 = pci_read_config16(dev, PCI_BRIDGE_CONTROL); |
| 236 | reg16 &= ~PCI_BRIDGE_CTL_PARITY; |
| 237 | reg16 |= PCI_BRIDGE_CTL_NO_ISA; |
| 238 | pci_write_config16(dev, PCI_BRIDGE_CONTROL, reg16); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 239 | |
| 240 | #ifdef EVEN_MORE_DEBUG |
| 241 | reg32 = pci_read_config32(dev, 0x20); |
| 242 | printk(BIOS_SPEW, " MBL = 0x%08x\n", reg32); |
| 243 | reg32 = pci_read_config32(dev, 0x24); |
| 244 | printk(BIOS_SPEW, " PMBL = 0x%08x\n", reg32); |
| 245 | reg32 = pci_read_config32(dev, 0x28); |
| 246 | printk(BIOS_SPEW, " PMBU32 = 0x%08x\n", reg32); |
| 247 | reg32 = pci_read_config32(dev, 0x2c); |
| 248 | printk(BIOS_SPEW, " PMLU32 = 0x%08x\n", reg32); |
| 249 | #endif |
| 250 | |
| 251 | /* Clear errors in status registers */ |
| 252 | reg16 = pci_read_config16(dev, 0x06); |
| 253 | //reg16 |= 0xf900; |
| 254 | pci_write_config16(dev, 0x06, reg16); |
| 255 | |
| 256 | reg16 = pci_read_config16(dev, 0x1e); |
| 257 | //reg16 |= 0xf900; |
| 258 | pci_write_config16(dev, 0x1e, reg16); |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 259 | |
| 260 | /* Enable expresscard hotplug events. */ |
| 261 | if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) { |
| 262 | pci_write_config32(dev, 0xd8, |
| 263 | pci_read_config32(dev, 0xd8) |
| 264 | | (1 << 30)); |
| 265 | pci_write_config16(dev, 0x42, 0x142); |
| 266 | } |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 267 | } |
| 268 | |
Elyes HAOUAS | 4aec340 | 2018-05-25 08:29:27 +0200 | [diff] [blame] | 269 | static void pch_pcie_enable(struct device *dev) |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 270 | { |
| 271 | /* Power Management init before enumeration */ |
| 272 | pch_pcie_pm_early(dev); |
| 273 | } |
| 274 | |
Elyes HAOUAS | 4aec340 | 2018-05-25 08:29:27 +0200 | [diff] [blame] | 275 | static void pch_pciexp_scan_bridge(struct device *dev) |
Marc Jones | 4adc8cd | 2012-10-31 16:24:37 -0600 | [diff] [blame] | 276 | { |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 277 | struct southbridge_intel_bd82x6x_config *config = dev->chip_info; |
Marc Jones | 4adc8cd | 2012-10-31 16:24:37 -0600 | [diff] [blame] | 278 | |
| 279 | /* Normal PCIe Scan */ |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 280 | pciexp_scan_bridge(dev); |
Marc Jones | 4adc8cd | 2012-10-31 16:24:37 -0600 | [diff] [blame] | 281 | |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 282 | if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) { |
| 283 | intel_acpi_pcie_hotplug_scan_slot(dev->link_list); |
| 284 | } |
| 285 | |
Marc Jones | 4adc8cd | 2012-10-31 16:24:37 -0600 | [diff] [blame] | 286 | /* Late Power Management init after bridge device enumeration */ |
| 287 | pch_pcie_pm_late(dev); |
Marc Jones | 4adc8cd | 2012-10-31 16:24:37 -0600 | [diff] [blame] | 288 | } |
| 289 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 290 | static const char *pch_pcie_acpi_name(const struct device *dev) |
Patrick Rudolph | 604f698 | 2017-06-07 09:46:52 +0200 | [diff] [blame] | 291 | { |
| 292 | ASSERT(dev); |
| 293 | |
| 294 | if (PCI_SLOT(dev->path.pci.devfn) == 0x1c) { |
| 295 | static const char *names[] = { "RP01", |
| 296 | "RP02", |
| 297 | "RP03", |
| 298 | "RP04", |
| 299 | "RP05", |
| 300 | "RP06", |
| 301 | "RP07", |
| 302 | "RP08"}; |
| 303 | |
| 304 | return names[PCI_FUNC(dev->path.pci.devfn)]; |
| 305 | } |
| 306 | |
| 307 | return NULL; |
| 308 | } |
| 309 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 310 | static struct pci_operations pci_ops = { |
Subrata Banik | 15ccbf0 | 2019-03-20 15:09:44 +0530 | [diff] [blame] | 311 | .set_subsystem = pci_dev_set_subsystem, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 312 | }; |
| 313 | |
| 314 | static struct device_operations device_ops = { |
| 315 | .read_resources = pci_bus_read_resources, |
| 316 | .set_resources = pci_dev_set_resources, |
| 317 | .enable_resources = pci_bus_enable_resources, |
| 318 | .init = pci_init, |
| 319 | .enable = pch_pcie_enable, |
Marc Jones | 4adc8cd | 2012-10-31 16:24:37 -0600 | [diff] [blame] | 320 | .scan_bus = pch_pciexp_scan_bridge, |
Patrick Rudolph | 604f698 | 2017-06-07 09:46:52 +0200 | [diff] [blame] | 321 | .acpi_name = pch_pcie_acpi_name, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 322 | .ops_pci = &pci_ops, |
| 323 | }; |
| 324 | |
Stefan Reinauer | 9a380ab | 2012-06-22 13:16:11 -0700 | [diff] [blame] | 325 | static const unsigned short pci_device_ids[] = { 0x1c10, 0x1c12, 0x1c14, 0x1c16, |
| 326 | 0x1c18, 0x1c1a, 0x1c1c, 0x1c1e, |
| 327 | 0x1e10, 0x1e12, 0x1e14, 0x1e16, |
| 328 | 0x1e18, 0x1e1a, 0x1e1c, 0x1e1e, |
| 329 | 0 }; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 330 | |
Stefan Reinauer | 9a380ab | 2012-06-22 13:16:11 -0700 | [diff] [blame] | 331 | static const struct pci_driver pch_pcie __pci_driver = { |
| 332 | .ops = &device_ops, |
| 333 | .vendor = PCI_VENDOR_ID_INTEL, |
| 334 | .devices = pci_device_ids, |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 335 | }; |