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