Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 2 | |
Tristan Corrick | 05b7524 | 2018-12-06 22:47:42 +1300 | [diff] [blame] | 3 | #include <assert.h> |
| 4 | #include <commonlib/helpers.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 5 | #include <console/console.h> |
| 6 | #include <device/device.h> |
| 7 | #include <device/pci.h> |
Kyösti Mälkki | df128a5 | 2019-09-21 18:35:37 +0300 | [diff] [blame] | 8 | #include <device/pci_def.h> |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 9 | #include <device/pciexp.h> |
| 10 | #include <device/pci_ids.h> |
Patrick Rudolph | e56189c | 2018-04-18 10:11:59 +0200 | [diff] [blame] | 11 | #include <device/pci_ops.h> |
Angel Pons | 2178b72 | 2020-05-31 00:55:35 +0200 | [diff] [blame] | 12 | #include "iobp.h" |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 13 | #include "pch.h" |
Patrick Rudolph | 273a8dc | 2016-02-06 18:07:59 +0100 | [diff] [blame] | 14 | #include <southbridge/intel/common/gpio.h> |
Tristan Corrick | 05b7524 | 2018-12-06 22:47:42 +1300 | [diff] [blame] | 15 | #include <stdint.h> |
Kyösti Mälkki | 12b121c | 2019-08-18 16:33:39 +0300 | [diff] [blame] | 16 | #include "chip.h" |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 17 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 18 | #define MAX_NUM_ROOT_PORTS 8 |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 19 | |
| 20 | struct root_port_config { |
| 21 | /* RPFN is a write-once register so keep a copy until it is written */ |
| 22 | u32 orig_rpfn; |
| 23 | u32 new_rpfn; |
| 24 | u32 pin_ownership; |
| 25 | u32 strpfusecfg1; |
| 26 | u32 strpfusecfg2; |
| 27 | u32 strpfusecfg3; |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 28 | u32 b0d28f0_32c; |
| 29 | u32 b0d28f4_32c; |
| 30 | u32 b0d28f5_32c; |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 31 | int coalesce; |
| 32 | int gbe_port; |
| 33 | int num_ports; |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 34 | struct device *ports[MAX_NUM_ROOT_PORTS]; |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | static struct root_port_config rpc; |
| 38 | |
| 39 | static inline int max_root_ports(void) |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 40 | { |
Tristan Corrick | d3f01b2 | 2018-12-06 22:46:58 +1300 | [diff] [blame] | 41 | if (pch_is_lp() || pch_silicon_id() == PCI_DEVICE_ID_INTEL_LPT_H81) |
| 42 | return 6; |
| 43 | |
| 44 | return 8; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 45 | } |
| 46 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 47 | static inline int root_port_is_first(struct device *dev) |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 48 | { |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 49 | return PCI_FUNC(dev->path.pci.devfn) == 0; |
| 50 | } |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 51 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 52 | static inline int root_port_is_last(struct device *dev) |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 53 | { |
| 54 | return PCI_FUNC(dev->path.pci.devfn) == (rpc.num_ports - 1); |
| 55 | } |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 56 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 57 | /* Root ports are numbered 1..N in the documentation. */ |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 58 | static inline int root_port_number(struct device *dev) |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 59 | { |
| 60 | return PCI_FUNC(dev->path.pci.devfn) + 1; |
| 61 | } |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 62 | |
Tristan Corrick | 05b7524 | 2018-12-06 22:47:42 +1300 | [diff] [blame] | 63 | static bool is_rp_enabled(int rp) |
| 64 | { |
| 65 | ASSERT(rp > 0 && rp <= ARRAY_SIZE(rpc.ports)); |
| 66 | |
| 67 | if (rpc.ports[rp - 1] == NULL) |
| 68 | return false; |
| 69 | |
| 70 | return rpc.ports[rp - 1]->enabled; |
| 71 | } |
| 72 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 73 | static void root_port_config_update_gbe_port(void) |
| 74 | { |
| 75 | /* Is the Gbe Port enabled? */ |
| 76 | if (!((rpc.strpfusecfg1 >> 19) & 1)) |
| 77 | return; |
| 78 | |
| 79 | if (pch_is_lp()) { |
| 80 | switch ((rpc.strpfusecfg1 >> 16) & 0x7) { |
| 81 | case 0: |
| 82 | rpc.gbe_port = 3; |
| 83 | break; |
| 84 | case 1: |
| 85 | rpc.gbe_port = 4; |
| 86 | break; |
| 87 | case 2: |
| 88 | case 3: |
| 89 | case 4: |
| 90 | case 5: |
| 91 | /* Lanes 0-4 of Root Port 5. */ |
| 92 | rpc.gbe_port = 5; |
| 93 | break; |
| 94 | default: |
| 95 | printk(BIOS_DEBUG, "Invalid GbE Port Selection.\n"); |
| 96 | } |
| 97 | } else { |
| 98 | /* Non-LP has 1:1 mapping with root ports. */ |
| 99 | rpc.gbe_port = ((rpc.strpfusecfg1 >> 16) & 0x7) + 1; |
| 100 | } |
| 101 | } |
| 102 | |
Angel Pons | 12404e0 | 2020-08-04 00:26:45 +0200 | [diff] [blame] | 103 | static void update_num_ports(void) |
| 104 | { |
| 105 | /* |
| 106 | * According to existing code in 'root_port_check_disable()', which does |
| 107 | * not agree with the confusing information on the datasheets, the last |
| 108 | * visible function depends on the strapped root port width as follows: |
| 109 | * |
| 110 | * +-----+----+----+----+----+ |
| 111 | * | RPC | #5 | #6 | #7 | #8 | |
| 112 | * +-----+----+----+----+----+ |
| 113 | * | 0 | x1 | x1 | x1 | x1 | |
| 114 | * | 1 | x2 | | x1 | x1 | |
| 115 | * | 2 | x2 | | x2 | | |
| 116 | * | 3 | x4 | | | | |
| 117 | * +-----+----+----+----+----+ |
| 118 | */ |
| 119 | switch ((rpc.strpfusecfg2 >> 14) & 0x3) { |
| 120 | case 0: |
| 121 | case 1: |
| 122 | break; |
| 123 | case 2: |
| 124 | rpc.num_ports = MIN(rpc.num_ports, 7); |
| 125 | break; |
| 126 | case 3: |
| 127 | rpc.num_ports = MIN(rpc.num_ports, 5); |
| 128 | break; |
| 129 | } |
| 130 | |
| 131 | printk(BIOS_DEBUG, "Adjusted number of PCIe root ports to %d as per strpfusecfg2\n", |
| 132 | rpc.num_ports); |
| 133 | } |
| 134 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 135 | static void root_port_init_config(struct device *dev) |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 136 | { |
| 137 | int rp; |
| 138 | |
| 139 | if (root_port_is_first(dev)) { |
| 140 | rpc.orig_rpfn = RCBA32(RPFN); |
| 141 | rpc.new_rpfn = rpc.orig_rpfn; |
| 142 | rpc.num_ports = max_root_ports(); |
| 143 | rpc.gbe_port = -1; |
| 144 | |
| 145 | rpc.pin_ownership = pci_read_config32(dev, 0x410); |
| 146 | root_port_config_update_gbe_port(); |
| 147 | |
| 148 | if (dev->chip_info != NULL) { |
| 149 | struct southbridge_intel_lynxpoint_config *config; |
| 150 | |
| 151 | config = dev->chip_info; |
| 152 | rpc.coalesce = config->pcie_port_coalesce; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | rp = root_port_number(dev); |
| 157 | if (rp > rpc.num_ports) { |
| 158 | printk(BIOS_ERR, "Found Root Port %d, expecting %d\n", |
| 159 | rp, rpc.num_ports); |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | /* Read the fuse configuration and pin ownership. */ |
| 164 | switch (rp) { |
| 165 | case 1: |
| 166 | rpc.strpfusecfg1 = pci_read_config32(dev, 0xfc); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 167 | rpc.b0d28f0_32c = pci_read_config32(dev, 0x32c); |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 168 | break; |
| 169 | case 5: |
| 170 | rpc.strpfusecfg2 = pci_read_config32(dev, 0xfc); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 171 | rpc.b0d28f4_32c = pci_read_config32(dev, 0x32c); |
Angel Pons | 12404e0 | 2020-08-04 00:26:45 +0200 | [diff] [blame] | 172 | |
| 173 | if (!pch_is_lp()) |
| 174 | update_num_ports(); |
| 175 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 176 | break; |
| 177 | case 6: |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 178 | rpc.b0d28f5_32c = pci_read_config32(dev, 0x32c); |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 179 | rpc.strpfusecfg3 = pci_read_config32(dev, 0xfc); |
| 180 | break; |
| 181 | default: |
| 182 | break; |
| 183 | } |
| 184 | |
| 185 | /* Cache pci device. */ |
| 186 | rpc.ports[rp - 1] = dev; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /* Update devicetree with new Root Port function number assignment */ |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 190 | static void pch_pcie_device_set_func(int index, int pci_func) |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 191 | { |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 192 | struct device *dev; |
Martin Roth | ff744bf | 2019-10-23 21:46:03 -0600 | [diff] [blame] | 193 | unsigned int new_devfn; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 194 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 195 | dev = rpc.ports[index]; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 196 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 197 | /* Set the new PCI function field for this Root Port. */ |
| 198 | rpc.new_rpfn &= ~RPFN_FNMASK(index); |
| 199 | rpc.new_rpfn |= RPFN_FNSET(index, pci_func); |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 200 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 201 | /* Determine the new devfn for this port */ |
| 202 | new_devfn = PCI_DEVFN(PCH_PCIE_DEV_SLOT, pci_func); |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 203 | |
Tristan Corrick | 05b7524 | 2018-12-06 22:47:42 +1300 | [diff] [blame] | 204 | if (dev && dev->path.pci.devfn != new_devfn) { |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 205 | printk(BIOS_DEBUG, |
| 206 | "PCH: PCIe map %02x.%1x -> %02x.%1x\n", |
| 207 | PCI_SLOT(dev->path.pci.devfn), |
| 208 | PCI_FUNC(dev->path.pci.devfn), |
| 209 | PCI_SLOT(new_devfn), PCI_FUNC(new_devfn)); |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 210 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 211 | dev->path.pci.devfn = new_devfn; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 215 | static void pcie_enable_clock_gating(void) |
| 216 | { |
| 217 | int i; |
| 218 | int is_lp; |
| 219 | int enabled_ports; |
| 220 | |
| 221 | is_lp = pch_is_lp(); |
| 222 | enabled_ports = 0; |
| 223 | |
| 224 | for (i = 0; i < rpc.num_ports; i++) { |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 225 | struct device *dev; |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 226 | int rp; |
| 227 | |
| 228 | dev = rpc.ports[i]; |
Tristan Corrick | 05b7524 | 2018-12-06 22:47:42 +1300 | [diff] [blame] | 229 | if (!dev) |
| 230 | continue; |
| 231 | |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 232 | rp = root_port_number(dev); |
| 233 | |
Tristan Corrick | 05b7524 | 2018-12-06 22:47:42 +1300 | [diff] [blame] | 234 | if (!is_rp_enabled(rp)) { |
Ryan Salsamendi | 3f2fe18 | 2017-07-04 13:14:16 -0700 | [diff] [blame] | 235 | |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 236 | /* Configure shared resource clock gating. */ |
| 237 | if (rp == 1 || rp == 5 || (rp == 6 && is_lp)) |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 238 | pci_or_config8(dev, 0xe1, 0x3c); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 239 | |
| 240 | if (!is_lp) { |
Tristan Corrick | 05b7524 | 2018-12-06 22:47:42 +1300 | [diff] [blame] | 241 | if (rp == 1 && !is_rp_enabled(2) && |
| 242 | !is_rp_enabled(3) && !is_rp_enabled(4)) { |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 243 | pci_or_config8(dev, 0xe2, 1); |
| 244 | pci_or_config8(dev, 0xe1, 1 << 7); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 245 | } |
Tristan Corrick | 05b7524 | 2018-12-06 22:47:42 +1300 | [diff] [blame] | 246 | if (rp == 5 && !is_rp_enabled(6) && |
| 247 | !is_rp_enabled(7) && !is_rp_enabled(8)) { |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 248 | pci_or_config8(dev, 0xe2, 1); |
| 249 | pci_or_config8(dev, 0xe1, 1 << 7); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 250 | } |
| 251 | continue; |
| 252 | } |
| 253 | |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 254 | pci_or_config8(dev, 0xe2, 3 << 4); |
| 255 | pci_or_config32(dev, 0x420, 1 << 31); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 256 | |
| 257 | /* Per-Port CLKREQ# handling. */ |
| 258 | if (is_lp && gpio_is_native(18 + rp - 1)) |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 259 | pci_or_config32(dev, 0x420, 3 << 29); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 260 | |
| 261 | /* Enable static clock gating. */ |
Tristan Corrick | 05b7524 | 2018-12-06 22:47:42 +1300 | [diff] [blame] | 262 | if (rp == 1 && !is_rp_enabled(2) && |
| 263 | !is_rp_enabled(3) && !is_rp_enabled(4)) { |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 264 | pci_or_config8(dev, 0xe2, 1); |
| 265 | pci_or_config8(dev, 0xe1, 1 << 7); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 266 | } else if (rp == 5 || rp == 6) { |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 267 | pci_or_config8(dev, 0xe2, 1); |
| 268 | pci_or_config8(dev, 0xe1, 1 << 7); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 269 | } |
| 270 | continue; |
| 271 | } |
| 272 | |
| 273 | enabled_ports++; |
| 274 | |
| 275 | /* Enable dynamic clock gating. */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 276 | pci_or_config8(dev, 0xe1, 0x03); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 277 | |
| 278 | if (is_lp) { |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 279 | pci_or_config8(dev, 0xe2, 1 << 6); |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 280 | pci_update_config8(dev, 0xe8, ~(3 << 2), (2 << 2)); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /* Update PECR1 register. */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 284 | pci_or_config8(dev, 0xe8, 1); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 285 | |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 286 | /* FIXME: Are we supposed to update this register with a constant boolean? */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 287 | pci_update_config8(dev, 0x324, ~(1 << 5), (1 < 5)); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 288 | |
| 289 | /* Per-Port CLKREQ# handling. */ |
| 290 | if (is_lp && gpio_is_native(18 + rp - 1)) |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 291 | pci_or_config32(dev, 0x420, 3 << 29); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 292 | |
| 293 | /* Configure shared resource clock gating. */ |
| 294 | if (rp == 1 || rp == 5 || (rp == 6 && is_lp)) |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 295 | pci_or_config8(dev, 0xe1, 0x3c); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 296 | } |
| 297 | |
Tristan Corrick | 05b7524 | 2018-12-06 22:47:42 +1300 | [diff] [blame] | 298 | if (!enabled_ports && is_lp && rpc.ports[0]) |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 299 | pci_or_config8(rpc.ports[0], 0xe1, 1 << 6); |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 300 | } |
| 301 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 302 | static void root_port_commit_config(void) |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 303 | { |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 304 | int i; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 305 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 306 | /* If the first root port is disabled the coalesce ports. */ |
Tristan Corrick | 05b7524 | 2018-12-06 22:47:42 +1300 | [diff] [blame] | 307 | if (!is_rp_enabled(1)) |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 308 | rpc.coalesce = 1; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 309 | |
Aaron Durbin | 1c4289d | 2013-06-21 14:06:11 -0500 | [diff] [blame] | 310 | /* Perform clock gating configuration. */ |
| 311 | pcie_enable_clock_gating(); |
| 312 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 313 | for (i = 0; i < rpc.num_ports; i++) { |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 314 | struct device *dev; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 315 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 316 | dev = rpc.ports[i]; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 317 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 318 | if (dev == NULL) { |
| 319 | printk(BIOS_ERR, "Root Port %d device is NULL?\n", i+1); |
| 320 | continue; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 321 | } |
| 322 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 323 | if (dev->enabled) |
| 324 | continue; |
| 325 | |
| 326 | printk(BIOS_DEBUG, "%s: Disabling device\n", dev_path(dev)); |
| 327 | |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 328 | /* Ensure memory, io, and bus master are all disabled */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 329 | pci_and_config16(dev, PCI_COMMAND, |
| 330 | ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO)); |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 331 | |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 332 | /* Disable this device if possible */ |
| 333 | pch_disable_devfn(dev); |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 334 | } |
| 335 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 336 | if (rpc.coalesce) { |
| 337 | int current_func; |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 338 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 339 | /* For all Root Ports N enabled ports get assigned the lower |
| 340 | * PCI function number. The disabled ones get upper PCI |
| 341 | * function numbers. */ |
| 342 | current_func = 0; |
| 343 | for (i = 0; i < rpc.num_ports; i++) { |
Tristan Corrick | 05b7524 | 2018-12-06 22:47:42 +1300 | [diff] [blame] | 344 | if (!is_rp_enabled(i + 1)) |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 345 | continue; |
| 346 | pch_pcie_device_set_func(i, current_func); |
| 347 | current_func++; |
| 348 | } |
| 349 | |
| 350 | /* Allocate the disabled devices' PCI function number. */ |
| 351 | for (i = 0; i < rpc.num_ports; i++) { |
Tristan Corrick | 05b7524 | 2018-12-06 22:47:42 +1300 | [diff] [blame] | 352 | if (is_rp_enabled(i + 1)) |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 353 | continue; |
| 354 | pch_pcie_device_set_func(i, current_func); |
| 355 | current_func++; |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | printk(BIOS_SPEW, "PCH: RPFN 0x%08x -> 0x%08x\n", |
| 360 | rpc.orig_rpfn, rpc.new_rpfn); |
| 361 | RCBA32(RPFN) = rpc.new_rpfn; |
| 362 | } |
| 363 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 364 | static void root_port_mark_disable(struct device *dev) |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 365 | { |
| 366 | /* Mark device as disabled. */ |
| 367 | dev->enabled = 0; |
| 368 | /* Mark device to be hidden. */ |
| 369 | rpc.new_rpfn |= RPFN_HIDE(PCI_FUNC(dev->path.pci.devfn)); |
| 370 | } |
| 371 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 372 | static void root_port_check_disable(struct device *dev) |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 373 | { |
| 374 | int rp; |
| 375 | int is_lp; |
| 376 | |
| 377 | /* Device already disabled. */ |
| 378 | if (!dev->enabled) { |
| 379 | root_port_mark_disable(dev); |
| 380 | return; |
| 381 | } |
| 382 | |
| 383 | rp = root_port_number(dev); |
| 384 | |
| 385 | /* Is the GbE port mapped to this Root Port? */ |
| 386 | if (rp == rpc.gbe_port) { |
| 387 | root_port_mark_disable(dev); |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | is_lp = pch_is_lp(); |
| 392 | |
| 393 | /* Check Root Port Configuration. */ |
| 394 | switch (rp) { |
| 395 | case 2: |
| 396 | /* Root Port 2 is disabled for all lane configurations |
| 397 | * but config 00b (4x1 links). */ |
| 398 | if ((rpc.strpfusecfg1 >> 14) & 0x3) { |
| 399 | root_port_mark_disable(dev); |
| 400 | return; |
| 401 | } |
| 402 | break; |
| 403 | case 3: |
| 404 | /* Root Port 3 is disabled in config 11b (1x4 links). */ |
| 405 | if (((rpc.strpfusecfg1 >> 14) & 0x3) == 0x3) { |
| 406 | root_port_mark_disable(dev); |
| 407 | return; |
| 408 | } |
| 409 | break; |
| 410 | case 4: |
| 411 | /* Root Port 4 is disabled in configs 11b (1x4 links) |
| 412 | * and 10b (2x2 links). */ |
| 413 | if ((rpc.strpfusecfg1 >> 14) & 0x2) { |
| 414 | root_port_mark_disable(dev); |
| 415 | return; |
| 416 | } |
| 417 | break; |
| 418 | case 6: |
| 419 | if (is_lp) |
| 420 | break; |
| 421 | /* Root Port 6 is disabled for all lane configurations |
| 422 | * but config 00b (4x1 links). */ |
| 423 | if ((rpc.strpfusecfg2 >> 14) & 0x3) { |
| 424 | root_port_mark_disable(dev); |
| 425 | return; |
| 426 | } |
| 427 | break; |
| 428 | case 7: |
| 429 | if (is_lp) |
| 430 | break; |
Tristan Corrick | baa4c07 | 2018-12-06 22:47:21 +1300 | [diff] [blame] | 431 | /* Root Port 7 is disabled in config 11b (1x4 links). */ |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 432 | if (((rpc.strpfusecfg2 >> 14) & 0x3) == 0x3) { |
| 433 | root_port_mark_disable(dev); |
| 434 | return; |
| 435 | } |
| 436 | break; |
| 437 | case 8: |
| 438 | if (is_lp) |
| 439 | break; |
| 440 | /* Root Port 8 is disabled in configs 11b (1x4 links) |
| 441 | * and 10b (2x2 links). */ |
| 442 | if ((rpc.strpfusecfg2 >> 14) & 0x2) { |
| 443 | root_port_mark_disable(dev); |
| 444 | return; |
| 445 | } |
| 446 | break; |
| 447 | } |
| 448 | |
| 449 | /* Check Pin Ownership. */ |
| 450 | if (is_lp) { |
| 451 | switch (rp) { |
| 452 | case 1: |
| 453 | /* Bit 0 is Root Port 1 ownership. */ |
| 454 | if ((rpc.pin_ownership & 0x1) == 0) { |
| 455 | root_port_mark_disable(dev); |
| 456 | return; |
| 457 | } |
| 458 | break; |
| 459 | case 2: |
| 460 | /* Bit 2 is Root Port 2 ownership. */ |
| 461 | if ((rpc.pin_ownership & 0x4) == 0) { |
| 462 | root_port_mark_disable(dev); |
| 463 | return; |
| 464 | } |
| 465 | break; |
| 466 | case 6: |
| 467 | /* Bits 7:4 are Root Port 6 pin-lane ownership. */ |
| 468 | if ((rpc.pin_ownership & 0xf0) == 0) { |
| 469 | root_port_mark_disable(dev); |
| 470 | return; |
| 471 | } |
| 472 | break; |
| 473 | } |
| 474 | } else { |
| 475 | switch (rp) { |
| 476 | case 1: |
| 477 | /* Bits 4 and 0 are Root Port 1 ownership. */ |
| 478 | if ((rpc.pin_ownership & 0x11) == 0) { |
| 479 | root_port_mark_disable(dev); |
| 480 | return; |
| 481 | } |
| 482 | break; |
| 483 | case 2: |
| 484 | /* Bits 5 and 2 are Root Port 2 ownership. */ |
| 485 | if ((rpc.pin_ownership & 0x24) == 0) { |
| 486 | root_port_mark_disable(dev); |
| 487 | return; |
| 488 | } |
| 489 | break; |
| 490 | } |
Aaron Durbin | 60f8208 | 2013-06-19 13:28:04 -0500 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 494 | static void pcie_add_0x0202000_iobp(u32 reg) |
| 495 | { |
| 496 | u32 reg32; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 497 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 498 | reg32 = pch_iobp_read(reg); |
| 499 | reg32 += (0x2 << 16) | (0x2 << 8); |
| 500 | pch_iobp_write(reg, reg32); |
| 501 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 502 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 503 | static void pch_pcie_early(struct device *dev) |
| 504 | { |
Duncan Laurie | 249a03b | 2013-08-09 09:06:41 -0700 | [diff] [blame] | 505 | struct southbridge_intel_lynxpoint_config *config = dev->chip_info; |
Angel Pons | 2aaf7c0 | 2020-09-24 18:03:18 +0200 | [diff] [blame] | 506 | int do_aspm = 0; |
| 507 | int rp = root_port_number(dev); |
| 508 | int is_lp = pch_is_lp(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 509 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 510 | if (is_lp) { |
| 511 | switch (rp) { |
| 512 | case 1: |
| 513 | case 2: |
| 514 | case 3: |
| 515 | case 4: |
Angel Pons | 2aaf7c0 | 2020-09-24 18:03:18 +0200 | [diff] [blame] | 516 | /* |
| 517 | * Bits 31:28 of b0d28f0 0x32c register correspond to |
| 518 | * Root Ports 4:1. |
| 519 | */ |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 520 | do_aspm = !!(rpc.b0d28f0_32c & (1 << (28 + rp - 1))); |
| 521 | break; |
| 522 | case 5: |
Angel Pons | 2aaf7c0 | 2020-09-24 18:03:18 +0200 | [diff] [blame] | 523 | /* |
| 524 | * Bit 28 of b0d28f4 0x32c register correspond to |
| 525 | * Root Ports 4:1. |
| 526 | */ |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 527 | do_aspm = !!(rpc.b0d28f4_32c & (1 << 28)); |
| 528 | break; |
| 529 | case 6: |
Angel Pons | 2aaf7c0 | 2020-09-24 18:03:18 +0200 | [diff] [blame] | 530 | /* |
| 531 | * Bit 28 of b0d28f5 0x32c register correspond to |
| 532 | * Root Ports 4:1. |
| 533 | */ |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 534 | do_aspm = !!(rpc.b0d28f5_32c & (1 << 28)); |
| 535 | break; |
| 536 | } |
| 537 | } else { |
| 538 | switch (rp) { |
| 539 | case 1: |
| 540 | case 2: |
| 541 | case 3: |
| 542 | case 4: |
Angel Pons | 2aaf7c0 | 2020-09-24 18:03:18 +0200 | [diff] [blame] | 543 | /* |
| 544 | * Bits 31:28 of b0d28f0 0x32c register correspond to |
| 545 | * Root Ports 4:1. |
| 546 | */ |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 547 | do_aspm = !!(rpc.b0d28f0_32c & (1 << (28 + rp - 1))); |
| 548 | break; |
| 549 | case 5: |
| 550 | case 6: |
| 551 | case 7: |
| 552 | case 8: |
Angel Pons | 2aaf7c0 | 2020-09-24 18:03:18 +0200 | [diff] [blame] | 553 | /* |
| 554 | * Bits 31:28 of b0d28f4 0x32c register correspond to |
| 555 | * Root Ports 8:5. |
| 556 | */ |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 557 | do_aspm = !!(rpc.b0d28f4_32c & (1 << (28 + rp - 5))); |
| 558 | break; |
| 559 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 560 | } |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 561 | |
Duncan Laurie | 249a03b | 2013-08-09 09:06:41 -0700 | [diff] [blame] | 562 | /* Allow ASPM to be forced on in devicetree */ |
| 563 | if (config && (config->pcie_port_force_aspm & (1 << (rp - 1)))) |
| 564 | do_aspm = 1; |
| 565 | |
| 566 | printk(BIOS_DEBUG, "PCIe Root Port %d ASPM is %sabled\n", |
| 567 | rp, do_aspm ? "en" : "dis"); |
| 568 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 569 | if (do_aspm) { |
| 570 | /* Set ASPM bits in MPC2 register. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 571 | pci_update_config32(dev, 0xd4, ~(0x3 << 2), (1 << 4) | (0x2 << 2)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 572 | |
| 573 | /* Set unique clock exit latency in MPC register. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 574 | pci_update_config32(dev, 0xd8, ~(0x7 << 18), (0x7 << 18)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 575 | |
| 576 | /* Set L1 exit latency in LCAP register. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 577 | pci_update_config32(dev, 0x4c, ~(0x7 << 15), (0x4 << 15)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 578 | |
| 579 | if (is_lp) { |
| 580 | switch (rp) { |
| 581 | case 1: |
| 582 | pcie_add_0x0202000_iobp(0xe9002440); |
| 583 | break; |
| 584 | case 2: |
| 585 | pcie_add_0x0202000_iobp(0xe9002640); |
| 586 | break; |
| 587 | case 3: |
| 588 | pcie_add_0x0202000_iobp(0xe9000840); |
| 589 | break; |
| 590 | case 4: |
| 591 | pcie_add_0x0202000_iobp(0xe9000a40); |
| 592 | break; |
| 593 | case 5: |
| 594 | pcie_add_0x0202000_iobp(0xe9000c40); |
| 595 | pcie_add_0x0202000_iobp(0xe9000e40); |
| 596 | pcie_add_0x0202000_iobp(0xe9001040); |
| 597 | pcie_add_0x0202000_iobp(0xe9001240); |
| 598 | break; |
| 599 | case 6: |
| 600 | /* Update IOBP based on lane ownership. */ |
| 601 | if (rpc.pin_ownership & (1 << 4)) |
| 602 | pcie_add_0x0202000_iobp(0xea002040); |
| 603 | if (rpc.pin_ownership & (1 << 5)) |
| 604 | pcie_add_0x0202000_iobp(0xea002240); |
| 605 | if (rpc.pin_ownership & (1 << 6)) |
| 606 | pcie_add_0x0202000_iobp(0xea002440); |
| 607 | if (rpc.pin_ownership & (1 << 7)) |
| 608 | pcie_add_0x0202000_iobp(0xea002640); |
| 609 | break; |
| 610 | } |
| 611 | } else { |
| 612 | switch (rp) { |
| 613 | case 1: |
| 614 | if ((rpc.pin_ownership & 0x3) == 1) |
| 615 | pcie_add_0x0202000_iobp(0xe9002e40); |
| 616 | else |
| 617 | pcie_add_0x0202000_iobp(0xea002040); |
| 618 | break; |
| 619 | case 2: |
| 620 | if ((rpc.pin_ownership & 0xc) == 0x4) |
| 621 | pcie_add_0x0202000_iobp(0xe9002c40); |
| 622 | else |
| 623 | pcie_add_0x0202000_iobp(0xea002240); |
| 624 | break; |
| 625 | case 3: |
| 626 | pcie_add_0x0202000_iobp(0xe9002a40); |
| 627 | break; |
| 628 | case 4: |
| 629 | pcie_add_0x0202000_iobp(0xe9002840); |
| 630 | break; |
| 631 | case 5: |
| 632 | pcie_add_0x0202000_iobp(0xe9002640); |
| 633 | break; |
| 634 | case 6: |
| 635 | pcie_add_0x0202000_iobp(0xe9002440); |
| 636 | break; |
| 637 | case 7: |
| 638 | pcie_add_0x0202000_iobp(0xe9002240); |
| 639 | break; |
| 640 | case 8: |
| 641 | pcie_add_0x0202000_iobp(0xe9002040); |
| 642 | break; |
| 643 | } |
| 644 | } |
| 645 | |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 646 | pci_and_config32(dev, 0x338, ~(1 << 26)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | /* Enable LTR in Root Port. */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 650 | pci_or_config32(dev, 0x64, 1 << 11); |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 651 | pci_update_config32(dev, 0x68, ~(1 << 10), (1 << 10)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 652 | |
Angel Pons | 2aaf7c0 | 2020-09-24 18:03:18 +0200 | [diff] [blame] | 653 | pci_update_config32(dev, 0x318, ~(0xffff << 16), (0x1414 << 16)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 654 | |
| 655 | /* Set L1 exit latency in LCAP register. */ |
| 656 | if (!do_aspm && (pci_read_config8(dev, 0xf5) & 0x1)) |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 657 | pci_update_config32(dev, 0x4c, ~(0x7 << 15), (0x4 << 15)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 658 | else |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 659 | pci_update_config32(dev, 0x4c, ~(0x7 << 15), (0x2 << 15)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 660 | |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 661 | pci_update_config32(dev, 0x314, 0, 0x743a361b); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 662 | |
| 663 | /* Set Common Clock Exit Latency in MPC register. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 664 | pci_update_config32(dev, 0xd8, ~(0x7 << 15), (0x3 << 15)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 665 | |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 666 | pci_update_config32(dev, 0x33c, ~0x00ffffff, 0x854c74); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 667 | |
Matt DeVillier | 1aeccd1 | 2020-10-07 13:18:55 -0500 | [diff] [blame] | 668 | /* Set Invalid Receive Range Check Enable in MPC register. */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 669 | pci_or_config32(dev, 0xd8, 1 << 25); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 670 | |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 671 | pci_and_config8(dev, 0xf5, 0x3f); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 672 | |
| 673 | if (rp == 1 || rp == 5 || (is_lp && rp == 6)) |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 674 | pci_and_config8(dev, 0xf7, ~0x0c); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 675 | |
| 676 | /* Set EOI forwarding disable. */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 677 | pci_or_config32(dev, 0xd4, 1 << 1); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 678 | |
Matt DeVillier | 7f63353 | 2020-10-07 13:11:58 -0500 | [diff] [blame] | 679 | /* Set AER Extended Cap ID to 01h and Next Cap Pointer to 200h. */ |
| 680 | if (CONFIG(PCIEXP_AER)) |
| 681 | pci_update_config32(dev, 0x100, ~0xfffff, (1 << 29) | 0x10001); |
| 682 | else |
| 683 | pci_update_config32(dev, 0x100, ~0xfffff, (1 << 29)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 684 | |
Matt DeVillier | 54e1f59 | 2020-10-07 13:17:09 -0500 | [diff] [blame] | 685 | /* Set L1 Sub-State Cap ID to 1Eh and Next Cap Pointer to None. */ |
| 686 | if (CONFIG(PCIEXP_L1_SUB_STATE)) |
| 687 | pci_update_config32(dev, 0x200, ~0xfffff, 0x001e); |
| 688 | else |
| 689 | pci_update_config32(dev, 0x200, ~0xfffff, 0); |
| 690 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 691 | if (is_lp) |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 692 | pci_or_config32(dev, 0x100, 1 << 29); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 693 | |
| 694 | /* Read and write back write-once capability registers. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 695 | pci_update_config32(dev, 0x34, ~0, 0); |
| 696 | pci_update_config32(dev, 0x40, ~0, 0); |
| 697 | pci_update_config32(dev, 0x80, ~0, 0); |
| 698 | pci_update_config32(dev, 0x90, ~0, 0); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 699 | } |
| 700 | |
Angel Pons | 2aaf7c0 | 2020-09-24 18:03:18 +0200 | [diff] [blame] | 701 | static void pch_pcie_init(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 702 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 703 | printk(BIOS_DEBUG, "Initializing PCH PCIe bridge.\n"); |
| 704 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 705 | /* Enable SERR */ |
Elyes HAOUAS | 73ae076 | 2020-04-28 10:13:05 +0200 | [diff] [blame] | 706 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_SERR); |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 707 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 708 | /* Enable Bus Master */ |
Elyes HAOUAS | 73ae076 | 2020-04-28 10:13:05 +0200 | [diff] [blame] | 709 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 710 | |
| 711 | /* Set Cache Line Size to 0x10 */ |
| 712 | // This has no effect but the OS might expect it |
| 713 | pci_write_config8(dev, 0x0c, 0x10); |
| 714 | |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 715 | pci_and_config16(dev, PCI_BRIDGE_CONTROL, ~PCI_BRIDGE_CTL_PARITY); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 716 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 717 | /* Clear errors in status registers */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 718 | pci_update_config16(dev, 0x06, ~0, 0); |
| 719 | pci_update_config16(dev, 0x1e, ~0, 0); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 720 | } |
| 721 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 722 | static void pch_pcie_enable(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 723 | { |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 724 | /* Add this device to the root port config structure. */ |
| 725 | root_port_init_config(dev); |
| 726 | |
| 727 | /* Check to see if this Root Port should be disabled. */ |
| 728 | root_port_check_disable(dev); |
| 729 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 730 | /* Power Management init before enumeration */ |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 731 | if (dev->enabled) |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 732 | pch_pcie_early(dev); |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 733 | |
| 734 | /* |
| 735 | * When processing the last PCIe root port we can now |
| 736 | * update the Root Port Function Number and Hide register. |
| 737 | */ |
| 738 | if (root_port_is_last(dev)) |
| 739 | root_port_commit_config(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 740 | } |
| 741 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 742 | static struct device_operations device_ops = { |
| 743 | .read_resources = pci_bus_read_resources, |
| 744 | .set_resources = pci_dev_set_resources, |
| 745 | .enable_resources = pci_bus_enable_resources, |
Angel Pons | 2aaf7c0 | 2020-09-24 18:03:18 +0200 | [diff] [blame] | 746 | .init = pch_pcie_init, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 747 | .enable = pch_pcie_enable, |
| 748 | .scan_bus = pciexp_scan_bridge, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 749 | .ops_pci = &pci_dev_ops_pci, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 750 | }; |
| 751 | |
Duncan Laurie | 74c0d05 | 2012-12-17 11:31:40 -0800 | [diff] [blame] | 752 | static const unsigned short pci_device_ids[] = { |
| 753 | /* Lynxpoint Mobile */ |
| 754 | 0x8c10, 0x8c12, 0x8c14, 0x8c16, 0x8c18, 0x8c1a, 0x8c1c, 0x8c1e, |
| 755 | /* Lynxpoint Low Power */ |
| 756 | 0x9c10, 0x9c12, 0x9c14, 0x9c16, 0x9c18, 0x9c1a, |
| 757 | 0 |
| 758 | }; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 759 | |
| 760 | static const struct pci_driver pch_pcie __pci_driver = { |
| 761 | .ops = &device_ops, |
| 762 | .vendor = PCI_VENDOR_ID_INTEL, |
| 763 | .devices = pci_device_ids, |
| 764 | }; |