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 | { |
| 505 | int rp; |
| 506 | int do_aspm; |
| 507 | int is_lp; |
Duncan Laurie | 249a03b | 2013-08-09 09:06:41 -0700 | [diff] [blame] | 508 | struct southbridge_intel_lynxpoint_config *config = dev->chip_info; |
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 | rp = root_port_number(dev); |
| 511 | do_aspm = 0; |
| 512 | is_lp = pch_is_lp(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 513 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 514 | if (is_lp) { |
| 515 | switch (rp) { |
| 516 | case 1: |
| 517 | case 2: |
| 518 | case 3: |
| 519 | case 4: |
| 520 | /* Bits 31:28 of b0d28f0 0x32c register correspnd to |
| 521 | * Root Ports 4:1. */ |
| 522 | do_aspm = !!(rpc.b0d28f0_32c & (1 << (28 + rp - 1))); |
| 523 | break; |
| 524 | case 5: |
| 525 | /* Bit 28 of b0d28f4 0x32c register correspnd to |
| 526 | * Root Ports 4:1. */ |
| 527 | do_aspm = !!(rpc.b0d28f4_32c & (1 << 28)); |
| 528 | break; |
| 529 | case 6: |
| 530 | /* Bit 28 of b0d28f5 0x32c register correspnd to |
| 531 | * Root Ports 4:1. */ |
| 532 | do_aspm = !!(rpc.b0d28f5_32c & (1 << 28)); |
| 533 | break; |
| 534 | } |
| 535 | } else { |
| 536 | switch (rp) { |
| 537 | case 1: |
| 538 | case 2: |
| 539 | case 3: |
| 540 | case 4: |
| 541 | /* Bits 31:28 of b0d28f0 0x32c register correspnd to |
| 542 | * Root Ports 4:1. */ |
| 543 | do_aspm = !!(rpc.b0d28f0_32c & (1 << (28 + rp - 1))); |
| 544 | break; |
| 545 | case 5: |
| 546 | case 6: |
| 547 | case 7: |
| 548 | case 8: |
| 549 | /* Bit 31:28 of b0d28f4 0x32c register correspnd to |
| 550 | * Root Ports 8:5. */ |
| 551 | do_aspm = !!(rpc.b0d28f4_32c & (1 << (28 + rp - 5))); |
| 552 | break; |
| 553 | } |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 554 | } |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 555 | |
Duncan Laurie | 249a03b | 2013-08-09 09:06:41 -0700 | [diff] [blame] | 556 | /* Allow ASPM to be forced on in devicetree */ |
| 557 | if (config && (config->pcie_port_force_aspm & (1 << (rp - 1)))) |
| 558 | do_aspm = 1; |
| 559 | |
| 560 | printk(BIOS_DEBUG, "PCIe Root Port %d ASPM is %sabled\n", |
| 561 | rp, do_aspm ? "en" : "dis"); |
| 562 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 563 | if (do_aspm) { |
| 564 | /* Set ASPM bits in MPC2 register. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 565 | pci_update_config32(dev, 0xd4, ~(0x3 << 2), (1 << 4) | (0x2 << 2)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 566 | |
| 567 | /* Set unique clock exit latency in MPC register. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 568 | pci_update_config32(dev, 0xd8, ~(0x7 << 18), (0x7 << 18)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 569 | |
| 570 | /* Set L1 exit latency in LCAP register. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 571 | pci_update_config32(dev, 0x4c, ~(0x7 << 15), (0x4 << 15)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 572 | |
| 573 | if (is_lp) { |
| 574 | switch (rp) { |
| 575 | case 1: |
| 576 | pcie_add_0x0202000_iobp(0xe9002440); |
| 577 | break; |
| 578 | case 2: |
| 579 | pcie_add_0x0202000_iobp(0xe9002640); |
| 580 | break; |
| 581 | case 3: |
| 582 | pcie_add_0x0202000_iobp(0xe9000840); |
| 583 | break; |
| 584 | case 4: |
| 585 | pcie_add_0x0202000_iobp(0xe9000a40); |
| 586 | break; |
| 587 | case 5: |
| 588 | pcie_add_0x0202000_iobp(0xe9000c40); |
| 589 | pcie_add_0x0202000_iobp(0xe9000e40); |
| 590 | pcie_add_0x0202000_iobp(0xe9001040); |
| 591 | pcie_add_0x0202000_iobp(0xe9001240); |
| 592 | break; |
| 593 | case 6: |
| 594 | /* Update IOBP based on lane ownership. */ |
| 595 | if (rpc.pin_ownership & (1 << 4)) |
| 596 | pcie_add_0x0202000_iobp(0xea002040); |
| 597 | if (rpc.pin_ownership & (1 << 5)) |
| 598 | pcie_add_0x0202000_iobp(0xea002240); |
| 599 | if (rpc.pin_ownership & (1 << 6)) |
| 600 | pcie_add_0x0202000_iobp(0xea002440); |
| 601 | if (rpc.pin_ownership & (1 << 7)) |
| 602 | pcie_add_0x0202000_iobp(0xea002640); |
| 603 | break; |
| 604 | } |
| 605 | } else { |
| 606 | switch (rp) { |
| 607 | case 1: |
| 608 | if ((rpc.pin_ownership & 0x3) == 1) |
| 609 | pcie_add_0x0202000_iobp(0xe9002e40); |
| 610 | else |
| 611 | pcie_add_0x0202000_iobp(0xea002040); |
| 612 | break; |
| 613 | case 2: |
| 614 | if ((rpc.pin_ownership & 0xc) == 0x4) |
| 615 | pcie_add_0x0202000_iobp(0xe9002c40); |
| 616 | else |
| 617 | pcie_add_0x0202000_iobp(0xea002240); |
| 618 | break; |
| 619 | case 3: |
| 620 | pcie_add_0x0202000_iobp(0xe9002a40); |
| 621 | break; |
| 622 | case 4: |
| 623 | pcie_add_0x0202000_iobp(0xe9002840); |
| 624 | break; |
| 625 | case 5: |
| 626 | pcie_add_0x0202000_iobp(0xe9002640); |
| 627 | break; |
| 628 | case 6: |
| 629 | pcie_add_0x0202000_iobp(0xe9002440); |
| 630 | break; |
| 631 | case 7: |
| 632 | pcie_add_0x0202000_iobp(0xe9002240); |
| 633 | break; |
| 634 | case 8: |
| 635 | pcie_add_0x0202000_iobp(0xe9002040); |
| 636 | break; |
| 637 | } |
| 638 | } |
| 639 | |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 640 | pci_and_config32(dev, 0x338, ~(1 << 26)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | /* Enable LTR in Root Port. */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 644 | pci_or_config32(dev, 0x64, 1 << 11); |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 645 | pci_update_config32(dev, 0x68, ~(1 << 10), (1 << 10)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 646 | |
Ryan Salsamendi | 0d9b360 | 2017-06-30 17:15:57 -0700 | [diff] [blame] | 647 | pci_update_config32(dev, 0x318, ~(0xffffUL << 16), (0x1414UL << 16)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 648 | |
| 649 | /* Set L1 exit latency in LCAP register. */ |
| 650 | if (!do_aspm && (pci_read_config8(dev, 0xf5) & 0x1)) |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 651 | pci_update_config32(dev, 0x4c, ~(0x7 << 15), (0x4 << 15)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 652 | else |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 653 | pci_update_config32(dev, 0x4c, ~(0x7 << 15), (0x2 << 15)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 654 | |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 655 | pci_update_config32(dev, 0x314, 0, 0x743a361b); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 656 | |
| 657 | /* Set Common Clock Exit Latency in MPC register. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 658 | pci_update_config32(dev, 0xd8, ~(0x7 << 15), (0x3 << 15)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 659 | |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 660 | pci_update_config32(dev, 0x33c, ~0x00ffffff, 0x854c74); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 661 | |
Matt DeVillier | 1aeccd1 | 2020-10-07 13:18:55 -0500 | [diff] [blame] | 662 | /* Set Invalid Receive Range Check Enable in MPC register. */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 663 | pci_or_config32(dev, 0xd8, 1 << 25); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 664 | |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 665 | pci_and_config8(dev, 0xf5, 0x3f); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 666 | |
| 667 | if (rp == 1 || rp == 5 || (is_lp && rp == 6)) |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 668 | pci_and_config8(dev, 0xf7, ~0x0c); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 669 | |
| 670 | /* Set EOI forwarding disable. */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 671 | pci_or_config32(dev, 0xd4, 1 << 1); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 672 | |
Matt DeVillier | 7f63353 | 2020-10-07 13:11:58 -0500 | [diff] [blame] | 673 | /* Set AER Extended Cap ID to 01h and Next Cap Pointer to 200h. */ |
| 674 | if (CONFIG(PCIEXP_AER)) |
| 675 | pci_update_config32(dev, 0x100, ~0xfffff, (1 << 29) | 0x10001); |
| 676 | else |
| 677 | pci_update_config32(dev, 0x100, ~0xfffff, (1 << 29)); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 678 | |
Matt DeVillier | 54e1f59 | 2020-10-07 13:17:09 -0500 | [diff] [blame] | 679 | /* Set L1 Sub-State Cap ID to 1Eh and Next Cap Pointer to None. */ |
| 680 | if (CONFIG(PCIEXP_L1_SUB_STATE)) |
| 681 | pci_update_config32(dev, 0x200, ~0xfffff, 0x001e); |
| 682 | else |
| 683 | pci_update_config32(dev, 0x200, ~0xfffff, 0); |
| 684 | |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 685 | if (is_lp) |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 686 | pci_or_config32(dev, 0x100, 1 << 29); |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 687 | |
| 688 | /* Read and write back write-once capability registers. */ |
Kyösti Mälkki | 48c389e | 2013-07-26 08:53:59 +0300 | [diff] [blame] | 689 | pci_update_config32(dev, 0x34, ~0, 0); |
| 690 | pci_update_config32(dev, 0x40, ~0, 0); |
| 691 | pci_update_config32(dev, 0x80, ~0, 0); |
| 692 | pci_update_config32(dev, 0x90, ~0, 0); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | static void pci_init(struct device *dev) |
| 696 | { |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 697 | printk(BIOS_DEBUG, "Initializing PCH PCIe bridge.\n"); |
| 698 | |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 699 | /* Enable SERR */ |
Elyes HAOUAS | 73ae076 | 2020-04-28 10:13:05 +0200 | [diff] [blame] | 700 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_SERR); |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 701 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 702 | /* Enable Bus Master */ |
Elyes HAOUAS | 73ae076 | 2020-04-28 10:13:05 +0200 | [diff] [blame] | 703 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 704 | |
| 705 | /* Set Cache Line Size to 0x10 */ |
| 706 | // This has no effect but the OS might expect it |
| 707 | pci_write_config8(dev, 0x0c, 0x10); |
| 708 | |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 709 | pci_and_config16(dev, PCI_BRIDGE_CONTROL, ~PCI_BRIDGE_CTL_PARITY); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 710 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 711 | /* Clear errors in status registers */ |
Angel Pons | bf9bc50 | 2020-06-08 00:12:43 +0200 | [diff] [blame] | 712 | pci_update_config16(dev, 0x06, ~0, 0); |
| 713 | pci_update_config16(dev, 0x1e, ~0, 0); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 714 | } |
| 715 | |
Elyes HAOUAS | 7a5f771 | 2018-06-08 17:20:38 +0200 | [diff] [blame] | 716 | static void pch_pcie_enable(struct device *dev) |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 717 | { |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 718 | /* Add this device to the root port config structure. */ |
| 719 | root_port_init_config(dev); |
| 720 | |
| 721 | /* Check to see if this Root Port should be disabled. */ |
| 722 | root_port_check_disable(dev); |
| 723 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 724 | /* Power Management init before enumeration */ |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 725 | if (dev->enabled) |
Stefan Reinauer | ab365af | 2013-12-03 12:13:26 -0800 | [diff] [blame] | 726 | pch_pcie_early(dev); |
Aaron Durbin | c0254e6 | 2013-06-20 01:20:30 -0500 | [diff] [blame] | 727 | |
| 728 | /* |
| 729 | * When processing the last PCIe root port we can now |
| 730 | * update the Root Port Function Number and Hide register. |
| 731 | */ |
| 732 | if (root_port_is_last(dev)) |
| 733 | root_port_commit_config(); |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 734 | } |
| 735 | |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 736 | static struct device_operations device_ops = { |
| 737 | .read_resources = pci_bus_read_resources, |
| 738 | .set_resources = pci_dev_set_resources, |
| 739 | .enable_resources = pci_bus_enable_resources, |
| 740 | .init = pci_init, |
| 741 | .enable = pch_pcie_enable, |
| 742 | .scan_bus = pciexp_scan_bridge, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 743 | .ops_pci = &pci_dev_ops_pci, |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 744 | }; |
| 745 | |
Duncan Laurie | 74c0d05 | 2012-12-17 11:31:40 -0800 | [diff] [blame] | 746 | static const unsigned short pci_device_ids[] = { |
| 747 | /* Lynxpoint Mobile */ |
| 748 | 0x8c10, 0x8c12, 0x8c14, 0x8c16, 0x8c18, 0x8c1a, 0x8c1c, 0x8c1e, |
| 749 | /* Lynxpoint Low Power */ |
| 750 | 0x9c10, 0x9c12, 0x9c14, 0x9c16, 0x9c18, 0x9c1a, |
| 751 | 0 |
| 752 | }; |
Aaron Durbin | 76c3700 | 2012-10-30 09:03:43 -0500 | [diff] [blame] | 753 | |
| 754 | static const struct pci_driver pch_pcie __pci_driver = { |
| 755 | .ops = &device_ops, |
| 756 | .vendor = PCI_VENDOR_ID_INTEL, |
| 757 | .devices = pci_device_ids, |
| 758 | }; |