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