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