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